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.DemAtlInspectDeclare;
import com.usky.fire.service.DemAtlInspectDeclareService;
import com.usky.fire.service.vo.DemAtlInspectDeclareExportVO;
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;
import java.util.Map;

/**
 * <p>
 * 消防安检申报总表 前端控制器
 * </p>
 *
 * @author JCB
 * @since 2022-10-08
 */
@RestController
@RequestMapping("/demAtlInspectDeclare")
public class DemAtlInspectDeclareController {

    @Autowired
    private DemAtlInspectDeclareService demAtlInspectDeclareService;

    /**
     * 行政许可数据-列表查询
     *
     * @param projectCode        项目编号
     * @param declareCompanyName 申请单位
     * @param id                 主键ID
     * @param pageNum            当前页
     * @param pageSize           每页条数
     * @return
     */
    @GetMapping("atlInspectDeclareList")
    public ApiResult<CommonPage<Object>> atlInspectDeclareList(@RequestParam(value = "projectCode", required = false) String projectCode,
                                                               @RequestParam(value = "declareCompanyName", required = false) String declareCompanyName,
                                                               @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(demAtlInspectDeclareService.atlInspectDeclareList(projectCode, declareCompanyName, id, pageNum, pageSize));
    }

    /**
     * 行政许可数据-列表查询-导出
     *
     * @param projectCode        项目编号
     * @param declareCompanyName 申请单位
     * @param id                 主键ID
     * @param exportTitle        文件名
     * @throws IOException
     */
    @PostMapping("atlInspectDeclareListExport")
    public void export(HttpServletResponse response,
                       @RequestParam(value = "projectCode", required = false) String projectCode,
                       @RequestParam(value = "declareCompanyName", required = false) String declareCompanyName,
                       @RequestParam(value = "id", required = false, defaultValue = "0") Integer id,
                       @RequestParam(value = "exportTitle") String exportTitle) throws IOException{
        List<DemAtlInspectDeclareExportVO> list = demAtlInspectDeclareService.atlInspectDeclareListExport(projectCode, declareCompanyName, id);
        ExcelUtil<DemAtlInspectDeclareExportVO> util = new ExcelUtil<DemAtlInspectDeclareExportVO>(DemAtlInspectDeclareExportVO.class);
        util.exportExcel(response, list, exportTitle, exportTitle);
    }

    /**
     * 行政许可数据-修改
     *
     * @param demAtlInspectDeclare
     */
    @Log(title = "行政许可数据-修改", businessType = BusinessType.UPDATE)
    @PutMapping("updateAtlInspectCertificate")
    public ApiResult<Void> updateAtlInspectCertificate(@RequestBody DemAtlInspectDeclare demAtlInspectDeclare) {
        demAtlInspectDeclareService.updateAtlInspectCertificate(demAtlInspectDeclare);
        return ApiResult.success();
    }

    /**
     * 行政许可数据-删除
     *
     * @param id 主键ID
     */
    @Log(title = "行政许可数据-删除", businessType = BusinessType.DELETE)
    @DeleteMapping("delAtlInspectCertificate")
    public ApiResult<Void> delAtlInspectCertificate(@RequestParam(value = "id") Integer id,
                                                    @RequestParam(value = "zid", required = false, defaultValue = "0") Integer zid) {
        demAtlInspectDeclareService.delAtlInspectCertificate(id, zid);
        return ApiResult.success();
    }

}

