package com.usky.fire.controller.web;


import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.fire.domain.DemEnforceInspectRecord;
import com.usky.fire.service.DemEnforceInspectRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.usky.fire.service.vo.DemEnforceInspectRecordVO;

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

/**
 * <p>
 * 消防监督检查记录 前端控制器
 * </p>
 *
 * @author JCB
 * @since 2022-09-22
 */
@RestController
@RequestMapping("/demEnforceInspectRecord")
public class DemEnforceInspectRecordController {

    @Autowired
    private DemEnforceInspectRecordService demEnforceInspectRecordService;

    /**
     * 执法检查数据-列表查询
     *
     * @param projectCode 项目编号
     * @param companyName 单位编号
     * @param pageNum     当前页
     * @param pageSize    每页条数
     * @return
     */
    @GetMapping("enforceInspectRecordList")
    public ApiResult<CommonPage<Object>> enforceInspectRecordList(@RequestParam(value = "projectCode", required = false) String projectCode,
                                                                  @RequestParam(value = "companyName", required = false) String companyName,
                                                                  @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                                  @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return ApiResult.success(demEnforceInspectRecordService.enforceInspectRecordList(projectCode, companyName, pageNum, pageSize));
    }

    /**
     * 执法检查数据-列表查询-导出
     *
     * @param projectCode 项目编号
     * @param companyName 单位名称
     * @param exportTitle 文件名
     * @throws IOException
     */
    @PostMapping("enforceInspectRecordListExport")
    public void export(HttpServletResponse response,
                       @RequestParam(value = "projectCode", required = false) String projectCode,
                       @RequestParam(value = "companyName", required = false) String companyName,
                       @RequestParam(value = "exportTitle") String exportTitle) throws IOException{
        List<DemEnforceInspectRecordVO> list = demEnforceInspectRecordService.enforceInspectRecordListExport(projectCode, companyName);
        ExcelUtil<DemEnforceInspectRecordVO> util = new ExcelUtil<DemEnforceInspectRecordVO>(DemEnforceInspectRecordVO.class);
        util.exportExcel(response, list, exportTitle, exportTitle);
    }

    /**
     * 执法检查数据-修改
     *
     * @param demEnforceInspectRecord
     * @return
     */
    @Log(title = "执法检查数据-修改", businessType = BusinessType.UPDATE)
    @PutMapping("updateEnforceInspectRecord")
    public ApiResult<Void> updateEnforceInspectRecord(@RequestBody DemEnforceInspectRecord demEnforceInspectRecord) {
        demEnforceInspectRecordService.updateEnforceInspectRecord(demEnforceInspectRecord);
        return ApiResult.success();
    }

    /**
     * 执法检查数据-删除
     *
     * @param id 主键ID
     * @return
     */
    @Log(title = "执法检查数据-删除", businessType = BusinessType.DELETE)
    @DeleteMapping("delEnforceInspectRecord")
    public ApiResult<Void> delEnforceInspectRecord(@RequestParam(value = "id") Integer id) {
        demEnforceInspectRecordService.delEnforceInspectRecord(id);
        return ApiResult.success();
    }

}

