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.fire.domain.BaseCompanyPerson;
import com.usky.fire.domain.MhPostInspect;
import com.usky.fire.service.BaseCompanyPersonService;
import com.usky.fire.service.MhPostInspectService;
import com.usky.fire.service.vo.AlarmFireVo;
import com.usky.fire.service.vo.BaseCompanyPersonVO;
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-08-24
 */
@RestController
@RequestMapping("/baseCompanyPerson")
public class BaseCompanyPersonController {

    @Autowired
    private BaseCompanyPersonService baseCompanyPersonService;

    @Autowired
    private MhPostInspectService mhPostInspectService;

    /**
     * 值班查岗-查岗单位及记录数据查询列表查询接口（闵行支队、企业版）
     *
     * @param companyCode 单位编号
     * @param companyName 单位名称
     * @param pageNum     当前页
     * @param pageSize    每页条数
     * @return
     */
    @GetMapping("postInspectList")
    public ApiResult<CommonPage<BaseCompanyPerson>> postInspectList(@RequestParam(value = "companyCode", required = false) String companyCode,
                                                                    @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(baseCompanyPersonService.baseCompanyPersonList(companyCode, companyName, pageNum, pageSize));
    }

    /**
     * 值班查岗-查岗单位及记录数据查询列表查询接口（闵行支队、企业版）-导出
     *
     * @param companyCode 单位编号
     * @param companyName 单位名称
     * @param exportTitle    文件名
     * @throws IOException
     */
    @PostMapping("postInspectListExport")
    public void export(HttpServletResponse response,
                       @RequestParam(value = "companyCode", required = false) String companyCode,
                       @RequestParam(value = "companyName", required = false) String companyName,
                       @RequestParam(value = "exportTitle") String exportTitle) throws IOException {
        List<BaseCompanyPersonVO> list = baseCompanyPersonService.baseCompanyPersonListExport(companyCode,companyName);
        ExcelUtil<BaseCompanyPersonVO> util = new ExcelUtil<BaseCompanyPersonVO>(BaseCompanyPersonVO.class);
        util.exportExcel(response, list, exportTitle, exportTitle);
    }

    /**
     * 值班查岗-主页面响应时间、查岗次数等统计查询接口（闵行支队、企业版）
     *
     * @return
     */
    @GetMapping("postInspectStatistics")
    public ApiResult<Map<String, Object>> postInspectStatistics() {
        return ApiResult.success(baseCompanyPersonService.postInspectStatistics());
    }


    /**
     * 值班查岗-查岗记录数据列表查询接口（闵行支队、企业版）
     *
     * @param companyId 单位ID
     * @param pageNum   当前页
     * @param pageSize  每页条数
     * @return
     */
    @GetMapping("postInspectRecordList")
    public ApiResult<CommonPage<MhPostInspect>> postInspectRecordList(@RequestParam(value = "companyId") String companyId,
                                                                      @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                                      @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return ApiResult.success(mhPostInspectService.postInspectRecordList(companyId, pageNum, pageSize));
    }

    /**
     * 值班查岗-查岗记录页面响应时间、查岗次数等统计查询接口（闵行支队、企业版）
     *
     * @param companyId 单位ID
     * @return
     */
    @GetMapping("postInspectRecordStatistics")
    public ApiResult<Map<String, Object>> postInspectRecordStatistics(@RequestParam(value = "companyId") String companyId) {
        return ApiResult.success(mhPostInspectService.postInspectRecordStatistics(companyId));
    }

}

