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.DemEnforceReportComplaint;
import com.usky.fire.domain.DemEnforceReportLabel;
import com.usky.fire.service.DemEnforceReportComplaintService;
import com.usky.fire.service.DemEnforceReportLabelService;
import com.usky.fire.service.vo.CompanyExportVO;
import com.usky.fire.service.vo.ParameterVo;
import com.usky.fire.service.vo.DemEnforceReportComplaintVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 监督检查举报投诉信息 前端控制器
 * </p>
 *
 * @author JCB
 * @since 2022-09-23
 */
@RestController
@RequestMapping("/demEnforceReportComplaint")
public class DemEnforceReportComplaintController {

    @Autowired
    private DemEnforceReportComplaintService demEnforceReportComplaintService;

    @Autowired
    private DemEnforceReportLabelService demEnforceReportLabelService;

    /**
     * 举报信息管理-列表查询
     *
     * @param serialNumber 流水号
     * @param reportPhone  举报电话
     * @param pageNum      当前页
     * @param pageSize     每页条数
     * @return
     */
    @GetMapping("enforceReportComplaintList")
    public ApiResult<CommonPage<Object>> enforceReportComplaintList(@RequestParam(value = "serialNumber", required = false) String serialNumber,
                                                                    @RequestParam(value = "reportPhone", required = false, defaultValue = "0") String reportPhone,
                                                                    @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(demEnforceReportComplaintService.enforceReportComplaintList(serialNumber, reportPhone, id, pageNum, pageSize));
    }

    /**
     * 举报信息管理-列表查询-导出
     *
     * @param serialNumber 流水号
     * @param reportPhone  举报电话
     * @param exportTitle   导出文件名
     * @throws IOException
     */
    @PostMapping("enforceReportComplaintListExport")
    public void export(HttpServletResponse response,
                @RequestParam(value = "serialNumber", required = false) String serialNumber,
                @RequestParam(value = "reportPhone", required = false) String reportPhone,
                @RequestParam(value = "exportTitle") String exportTitle) throws IOException {
        List<DemEnforceReportComplaintVO> list = demEnforceReportComplaintService.enforceReportComplaintListExport(serialNumber, reportPhone);
        ExcelUtil<DemEnforceReportComplaintVO> util = new ExcelUtil<DemEnforceReportComplaintVO>(DemEnforceReportComplaintVO.class);
        util.exportExcel(response, list, exportTitle, exportTitle);
    }

    /**
     * 举报信息管理-标签添加
     *
     * @param demEnforceReportLabel
     */
    @Log(title = "举报信息管理-添加标签", businessType = BusinessType.INSERT)
    @PostMapping("addLabel")
    public ApiResult<Void> addLabel(@RequestBody DemEnforceReportLabel demEnforceReportLabel) {
        demEnforceReportComplaintService.addLabel(demEnforceReportLabel);
        return ApiResult.success();
    }

    /**
     * 举报信息管理-标签绑定
     *
     * @param parameterVo
     */
    @Log(title = "举报信息管理-绑定标签", businessType = BusinessType.UPDATE)
    @PutMapping("bindLabel")
    public ApiResult<Void> bindLabel(@RequestBody ParameterVo parameterVo) {
        demEnforceReportComplaintService.bindLabel(parameterVo);
        return ApiResult.success();
    }

    /**
     * 举报信息管理-修改
     *
     * @param demEnforceReportComplaint
     */
    @Log(title = "举报信息管理-修改", businessType = BusinessType.UPDATE)
    @PutMapping("updateEnforceReportComplaint")
    public ApiResult<Void> updateEnforceReportComplaint(@RequestBody DemEnforceReportComplaint demEnforceReportComplaint) {
        demEnforceReportComplaintService.updateEnforceReportComplaint(demEnforceReportComplaint);
        return ApiResult.success();
    }

    /**
     * 举报信息管理-删除
     *
     * @param id 主键ID
     */
    @Log(title = "举报信息管理-删除", businessType = BusinessType.DELETE)
    @DeleteMapping("delEnforceReportComplaint")
    public ApiResult<Void> delEnforceReportComplaint(@RequestParam(value = "id") Integer id) {
        demEnforceReportComplaintService.delEnforceReportComplaint(id);
        return ApiResult.success();
    }

    /**
     * 举报信息管理-标签分类下拉框
     *
     * @param fid 父级ID
     * @return
     */
    @GetMapping("enforceReportLabelSelect")
    public ApiResult<List<DemEnforceReportLabel>> enforceReportLabelSelect(@RequestParam(value = "fid", required = false, defaultValue = "0") Integer fid) {
        return ApiResult.success(demEnforceReportLabelService.enforceReportLabelSelect(fid));
    }

    /**
     * 举报信息管理-标签操作异常抛出
     *
     * @param demEnforceReportLabel
     * @return
     */
    @PostMapping("abnormalData")
    public ApiResult<Void> abnormalData(@RequestBody DemEnforceReportLabel demEnforceReportLabel) {
        demEnforceReportComplaintService.abnormalData(demEnforceReportLabel);
        return ApiResult.success();
    }

    /**
     * 举报信息管理-标签删除
     *
     * @param id 主键ID
     * @return
     */
    @Log(title = "标签-删除", businessType = BusinessType.DELETE)
    @DeleteMapping("delEnforceReportLabel")
    public ApiResult<Void> delDemFireStatistics(@RequestParam(value = "id") Integer id) {
        demEnforceReportComplaintService.delEnforceReportLabel(id);
        return ApiResult.success();
    }

}

