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.service.PatrolInspectionContentService;
import com.usky.fire.service.vo.PatrolInspectionContentExportVo;
import com.usky.fire.service.vo.PatrolInspectionContentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 巡查自检-巡检内容
 *
 * @author JCB
 * @since 2022-07-15
 */
@RestController
@RequestMapping("/patrolInspectionContent")
public class PatrolInspectionContentController {

    @Autowired
    private PatrolInspectionContentService patrolInspectionContentService;

    /**
     * 巡查自检-巡检内容-列表查询
     *
     * @param contentTitle 内容标题
     * @param pageNum      当前页
     * @param pageSize     每页条数
     * @param id           巡检内容ID
     * @return
     */
    @GetMapping("patrolInspectionContentList")
    public ApiResult<CommonPage<PatrolInspectionContentVo>> patrolInspectionContentList(@RequestParam(value = "contentTitle", required = false) String contentTitle,
                                                                                        @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                                                        @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                                                        @RequestParam(value = "id", required = false, defaultValue = "0") Integer id) {
        return ApiResult.success(patrolInspectionContentService.patrolInspectionContentList(contentTitle, pageNum, pageSize, id));
    }

    /**
     * 巡查自检-巡检内容-新增
     *
     * @param patrolInspectionContentVo
     * @return
     */
    @Log(title = "巡检内容", businessType = BusinessType.INSERT)
    @PostMapping("addPatrolInspectionContent")
    public ApiResult<Void> addPatrolInspectionContent(@RequestBody PatrolInspectionContentVo patrolInspectionContentVo) {
        patrolInspectionContentService.addPatrolInspectionContent(patrolInspectionContentVo);
        return ApiResult.success();
    }

    /**
     * 巡查自检-巡检内容-修改
     *
     * @param patrolInspectionContentVo
     * @return
     */
    @Log(title = "巡检内容", businessType = BusinessType.UPDATE)
    @PostMapping("updatePatrolInspectionContent")
    public ApiResult<Void> updatePatrolInspectionContent(@RequestBody PatrolInspectionContentVo patrolInspectionContentVo) {
        patrolInspectionContentService.updatePatrolInspectionContent(patrolInspectionContentVo);
        return ApiResult.success();
    }

    /**
     * 巡查自检-巡检内容-删除
     *
     * @param id 巡检内容ID
     * @return
     */
    @Log(title = "巡检内容", businessType = BusinessType.DELETE)
    @GetMapping("delPatrolInspectionContent")
    public ApiResult<Void> delPatrolInspectionContent(@RequestParam(value = "id") Integer id) {
        patrolInspectionContentService.delPatrolInspectionContent(id);
        return ApiResult.success();
    }

    /**
     * 巡查自检-巡检内容-导出
     *
     * @param response
     * @param contentTitle 内容标题
     * @param idList       巡检内容ID
     * @return
     * @throws IOException
     */
    @Log(title = "巡检内容", businessType = BusinessType.EXPORT)
    @PostMapping("/contentListExport")
    public void export(HttpServletResponse response,
                       @RequestParam(value = "contentTitle", required = false) String contentTitle,
                       @RequestParam(value = "id", required = false) String idList) throws IOException {
        List<PatrolInspectionContentExportVo> list = patrolInspectionContentService.contentListExport(contentTitle, idList);
        ExcelUtil<PatrolInspectionContentExportVo> util = new ExcelUtil<PatrolInspectionContentExportVo>(PatrolInspectionContentExportVo.class);
        util.exportExcel(response, list, "巡检内容列表", "巡检内容列表");
    }

}

