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.DemFileLabel;
import com.usky.fire.service.DemFireStatisticsService;
import com.usky.fire.service.vo.DemFireStatisticsExportVO;
import com.usky.fire.service.vo.DemFireStatisticsVo;
import com.usky.fire.service.vo.ParameterVo;
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;

/**
 * <p>
 * 火灾事故说明总表 前端控制器
 * </p>
 *
 * @author JCB
 * @since 2022-09-13
 */
@RestController
@RequestMapping("/demFireAccidentDesc")
public class DemFireAccidentDescController {

    @Autowired
    private DemFireStatisticsService demFireStatisticsService;

    /**
     * 火灾数据管理-列表查询
     *
     * @param fireNumber 火灾序号
     * @param labelId    标签ID
     * @param classifyId     分类ID
     * @param pageNum    当前页
     * @param pageSize   每页条数
     * @return
     */
    @GetMapping("fireAccidentStatistic")
    public ApiResult<CommonPage<Object>> fireAccidentStatistic(@RequestParam(value = "fireNumber", required = false) String fireNumber,
                                                               @RequestParam(value = "labelId", required = false) Integer labelId,
                                                               @RequestParam(value = "classifyId", required = false, defaultValue = "0") Integer classifyId,
                                                               @RequestParam(value = "id", required = false, defaultValue = "0") Integer id,
                                                               @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                               @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return ApiResult.success(demFireStatisticsService.fireAccidentStatistic(fireNumber, labelId, classifyId, id, pageNum, pageSize));
    }

    /**
     * 火灾数据管理-列表查询-导出
     *
     * @param fireNumber 火灾序号
     * @param labelId    标签ID
     * @param classifyId     分类ID
     * @param exportTitle    文件名
     * @throws IOException
     */
    @PostMapping("fireAccidentStatisticExport")
    public void export(HttpServletResponse response,
                       @RequestParam(value = "fireNumber", required = false) String fireNumber,
                       @RequestParam(value = "labelId", required = false) Integer labelId,
                       @RequestParam(value = "classifyId", required = false, defaultValue = "0") Integer classifyId,
                       @RequestParam(value = "exportTitle") String exportTitle) throws IOException {
        List<DemFireStatisticsExportVO> list = demFireStatisticsService.fireAccidentStatisticExport(fireNumber, labelId, classifyId);
        ExcelUtil<DemFireStatisticsExportVO> util = new ExcelUtil<DemFireStatisticsExportVO>(DemFireStatisticsExportVO.class);
        util.exportExcel(response,list,exportTitle,exportTitle);
    }

    /**
     * 火灾数据管理-添加标签
     *
     * @param demFileLabel
     * @return
     */
    @Log(title = "火灾数据-添加标签", businessType = BusinessType.INSERT)
    @PostMapping("addLabel")
    public ApiResult<Void> addLabel(@RequestBody DemFileLabel demFileLabel) {
        demFireStatisticsService.addLabel(demFileLabel);
        return ApiResult.success();
    }

    /**
     * 火灾数据管理-绑定弹窗列表查询
     *
     * @param fireNumber     火灾序号
     * @param fireCauseType1 起火原因
     * @param pageNum        当前页
     * @param pageSize       每页条数
     * @return
     */
    @GetMapping("fireStatisticList")
    public ApiResult<CommonPage<Object>> fireStatisticList(@RequestParam(value = "fireNumber", required = false) String fireNumber,
                                                           @RequestParam(value = "fireCauseType1", required = false) String fireCauseType1,
                                                           @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                           @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return ApiResult.success(demFireStatisticsService.fireStatisticList(fireNumber, fireCauseType1, pageNum, pageSize));
    }

    /**
     * 火灾数据管理-绑定标签
     *
     * @param parameterVo
     * @return
     */
    @Log(title = "火灾数据-绑定标签", businessType = BusinessType.UPDATE)
    @PutMapping("bindingLabel")
    public ApiResult<Void> bindingLabel(@RequestBody ParameterVo parameterVo) {
        demFireStatisticsService.bindingLabel(parameterVo);
        return ApiResult.success();
    }

    /**
     * 火灾数据管理-修改
     *
     * @param demFireStatisticsVo
     * @return
     */
    @Log(title = "火灾数据-修改", businessType = BusinessType.UPDATE)
    @PutMapping("updateDemFireStatistics")
    public ApiResult<Void> updateDemFireStatistics(@RequestBody DemFireStatisticsVo demFireStatisticsVo) {
        demFireStatisticsService.updateDemFireStatistics(demFireStatisticsVo);
        return ApiResult.success();
    }

    /**
     * 火灾数据管理-删除
     *
     * @param id  主键ID
     * @param zid 关联表ID
     * @return
     */
    @Log(title = "火灾数据-删除", businessType = BusinessType.DELETE)
    @DeleteMapping("delDemFireStatistics")
    public ApiResult<Void> delDemFireStatistics(@RequestParam(value = "id") Integer id,
                                                @RequestParam(value = "zid") Integer zid) {
        demFireStatisticsService.delDemFireStatistics(id, zid);
        return ApiResult.success();
    }

    /**
     * 火灾数据管理-标签操作异常抛出
     *
     * @param demFileLabel
     * @return
     */
    @PostMapping("abnormalData")
    public ApiResult<Void> abnormalData(@RequestBody DemFileLabel demFileLabel) {
        demFireStatisticsService.abnormalData(demFileLabel);
        return ApiResult.success();
    }

}

