package com.ruoyi.web.controller.checkPoint;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.checkPoint.CheckPointRecord;
import com.ruoyi.system.service.ICheckPointRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 巡更点记录Controller
 *
 * @author boman
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/wuYe/checkPointRecord")
public class CheckPointRecordController extends BaseController {
    @Autowired
    private ICheckPointRecordService checkPointRecordService;

    /**
     * 查询巡更点记录列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:checkPointRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(CheckPointRecord checkPointRecord) {
        startPage();
        List<CheckPointRecord> list = checkPointRecordService.selectCheckPointRecordList(checkPointRecord);
        return getDataTable(list);
    }

    /**
     * 导出巡更点记录列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:checkPointRecord:export')")
    @Log(title = "巡更点记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheckPointRecord checkPointRecord) {
        List<CheckPointRecord> list = checkPointRecordService.selectCheckPointRecordList(checkPointRecord);
        ExcelUtil<CheckPointRecord> util = new ExcelUtil<CheckPointRecord>(CheckPointRecord.class);
        util.exportExcel(response, list, "巡更点记录数据");
    }

    /**
     * 获取巡更点记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:checkPointRecord:query')")
    @GetMapping(value = "/{checkPointRecordId}")
    public AjaxResult getInfo(@PathVariable("checkPointRecordId") Long checkPointRecordId) {
        return success(checkPointRecordService.selectCheckPointRecordByCheckPointRecordId(checkPointRecordId));
    }

    /**
     * 新增巡更点记录
     */
    @PreAuthorize("@ss.hasPermi('wuYe:checkPointRecord:add')")
    @Log(title = "巡更点记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheckPointRecord checkPointRecord) {
        return toAjax(checkPointRecordService.insertCheckPointRecord(checkPointRecord));
    }

    /**
     * 修改巡更点记录
     */
    @PreAuthorize("@ss.hasPermi('wuYe:checkPointRecord:edit')")
    @Log(title = "巡更点记录", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody CheckPointRecord checkPointRecord) {
        return toAjax(checkPointRecordService.updateCheckPointRecord(checkPointRecord));
    }

    /**
     * 删除巡更点记录
     */
    @PreAuthorize("@ss.hasPermi('wuYe:checkPointRecord:remove')")
    @Log(title = "巡更点记录", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{checkPointRecordIds}")
    public AjaxResult remove(@PathVariable Long[] checkPointRecordIds) {
        return toAjax(checkPointRecordService.deleteCheckPointRecordByCheckPointRecordIds(checkPointRecordIds));
    }

    /**
     * 巡更点记录首页统计
     */
    @PreAuthorize("@ss.hasPermi('wuYe:checkPointRecord:count')")
    @PostMapping("/count")
    public AjaxResult count( CheckPointRecord checkPointRecord) {
        return AjaxResult.success(checkPointRecordService.getCheckPointRecordCount(checkPointRecord));
    }
}
