package com.ruoyi.project.sems.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.sems.domain.*;
import com.ruoyi.project.sems.service.*;
import com.ruoyi.project.system.domain.SysDictData;
import com.ruoyi.project.system.domain.SysPlant;
import com.ruoyi.project.system.service.ISysDictTypeService;
import com.ruoyi.project.system.service.ISysPlantService;
import com.ruoyi.project.system.service.ISysUserService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;

/**
 * 特种设备申请Controller
 *
 * @author ruoyi
 * @date 2021-08-05
 */
@RestController
@RequestMapping("/sems/home")
public class SpecHomeController extends BaseController
{
    @Autowired
    private ITApproveService tApproveService;
    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private HistoryService historyService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private ITSpecdevDtService tSpecdevDtService;
    @Autowired
    private ITSpecdevDzsbService tSpecdevDzsbService;
    @Autowired
    private ITSpecdevGlService tSpecdevGlService;
    @Autowired
    private ITSpecdevYlgdService tSpecdevYlgdService;
    @Autowired
    private ITSpecdevYlrqService tSpecdevYlrqService;
    @Autowired
    private ITSpecdevCcService tSpecdevCcService;
    @Autowired
    private ITApproverFileService tApproverFileService;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private ISysPlantService sysPlantService;
    @Autowired
    private ISysDictTypeService iSysDictTypeService;
    /**
     * 查询装置管理列表
     */
    @GetMapping("/plantList")
    public AjaxResult list(SysPlant sysPlant)
    {
        List<SysPlant> list = sysPlantService.selectSysPlantList(sysPlant);
        return AjaxResult.success(list);
    }

    /**
     * 首页数据
     */
    @RequestMapping(value = "devData")
    public AjaxResult homeData(@RequestBody Map<String, Object> params) {
        logger.info(JSON.toJSONString(params));
        List plantIds = (List) params.get("plantIds");
        List unitIds = (List) params.get("unitIds");
        if (unitIds.size() ==0) {
            unitIds.add("");
        }
        //压力管道
        int ylgdAll = tSpecdevYlgdService.count(new QueryWrapper<TSpecdevYlgd>()
                .in("plant_code",plantIds)
//                .in("unit",unitIds)
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)

        );
        //查询管道长度
//        List<TSpecdevYlgd> gdList = tSpecdevYlgdService.list(new QueryWrapper<TSpecdevYlgd>()
//                        .eq("STATUS" , 1)
//                        .eq("del_flag" , 0)
//                        .in("plant_code",plantIds)
////                        .in("unit",unitIds)
////                .eq(!StringUtils.isBlank((String)params.get("plantName")) , "plant_code" ,params.get("plantName"))
////                        .and(unitIds.size()>0 ,i -> i.in("unit",unitIds).or().in("plant_code",unitIds).or().isNull("unit"))
//        );
//        double allLength = 0;
//        for (int i = 0; i < gdList.size(); i++) {
//            double gdLength = 0;
//            if (!StringUtils.isBlank(gdList.get(i).getLength())) {
//                if (gdList.get(i).getLength().indexOf("\n") > -1) {
//                    String[] arr = gdList.get(i).getLength().split("\n");
//                    for (int j = 0; j < arr.length; j++) {
//                        try {
//                            gdLength += Double.parseDouble(arr[j]);
//                        }catch (NumberFormatException e) {
//                            logger.error(JSON.toJSONString(e));
//                            continue;
//                        }
//                    }
//                }else {
//                    try {
//                        gdLength = Double.parseDouble(gdList.get(i).getLength());
//                    }catch (NumberFormatException e) {
//                        logger.error(JSON.toJSONString(e));
//                    }
//                }
//            }
//            allLength += gdLength;
//        }
        //DecimalFormat df = new DecimalFormat("0.00#");
        //System.out.println(df.format(allLength));
        Map<String, Object> mapylgd = new HashMap<String, Object>();
        mapylgd.put("ylgdAll_num", ylgdAll);
        //mapylgd.put("ylgd_length", df.format(allLength));
        //压力容器
        int ylrqAll = tSpecdevYlrqService.count(new QueryWrapper<TSpecdevYlrq>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
//                 .in("unit",unitIds)
//                .eq(!StringUtils.isBlank((String)params.get("plantName")) , "plant_code" ,params.get("plantName"))
//                .and(unitIds.size()>0 ,i -> i.in("unit",unitIds).or().in("plant_code",unitIds).or().isNull("unit"))
        );
        Map<String, Object> mapylrq = new HashMap<String, Object>();
        mapylrq.put("ylrqAll_num", ylrqAll);
        //锅炉
        int glAll = tSpecdevGlService.count(new QueryWrapper<TSpecdevGl>()
                .eq("STATUS" , 1)
                 .eq("del_flag" , 0)
                .in("plant_code",plantIds)
//                 .in("unit",unitIds)
//                .eq(!StringUtils.isBlank((String)params.get("plantName")) , "plant_code" ,params.get("plantName"))
//                .and(unitIds.size()>0 ,i -> i.in("unit",unitIds).or().in("plant_code",unitIds))
                );
        Map<String, Object> mapgl = new HashMap<String, Object>();
        mapgl.put("glAll_num", glAll);
        //电梯
        int dtAll = tSpecdevDtService.count(new QueryWrapper<TSpecdevDt>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
//                .in("unit",unitIds)
        );
        Map<String, Object> mapdt = new HashMap<String, Object>();
        mapdt.put("dtAll_num", dtAll);
        //吊装设备
        int dzsbAll = tSpecdevDzsbService.count(new QueryWrapper<TSpecdevDzsb>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
//                .in("unit",unitIds)
                .like("CHECK_STRATEGY","强制")
        );
        int dzsbUn = tSpecdevDzsbService.count(new QueryWrapper<TSpecdevDzsb>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
//                .in("unit",unitIds)
                .notLike("CHECK_STRATEGY","强制")
        );

        Map<String, Object> mapdzsb = new HashMap<String, Object>();
        mapdzsb.put("dzsbAll_num", dzsbAll);
        mapdzsb.put("dzsbUn_num", dzsbUn);
        //叉车
        int ccAll = tSpecdevCcService.count(new QueryWrapper<TSpecdevCc>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
//                .in("unit",unitIds)
        );
        Map<String, Object> mapcc = new HashMap<String, Object>();
        mapcc.put("ccAll_num", ccAll);
        Map<String, Object> res = new HashMap<String, Object>();
        res.put("ylgdData", mapylgd);
        res.put("ylrqData", mapylrq);
        res.put("dtData", mapdt);
        res.put("dzsbData", mapdzsb);
        res.put("glData", mapgl);
        res.put("ccData" , mapcc);
        return AjaxResult.success(res);
    }

    @RequestMapping(value="ylgcLength")
    public AjaxResult sumYlgcLength(@RequestBody Map<String, Object> params){
        List plantIds = (List) params.get("plantIds");
//        查询管道长度
//        List<TSpecdevYlgd> gdList = tSpecdevYlgdService.list(new QueryWrapper<TSpecdevYlgd>()
//                        .eq("STATUS" , 1)
//                        .eq("del_flag" , 0)
//                        .in("plant_code",plantIds)
////                        .in("unit",unitIds)
////                .eq(!StringUtils.isBlank((String)params.get("plantName")) , "plant_code" ,params.get("plantName"))
////                        .and(unitIds.size()>0 ,i -> i.in("unit",unitIds).or().in("plant_code",unitIds).or().isNull("unit"))
//        );
        TSpecdevYlgd tSpecdevYlgd = new TSpecdevYlgd();
        tSpecdevYlgd.setPlantCodes(plantIds);
        List<TSpecdevYlgd> gdList = tSpecdevYlgdService.selectYlgdLengthList(tSpecdevYlgd);
        ArrayList<Double> lengthList = new ArrayList<>();
        for (TSpecdevYlgd ylgd : gdList) {
            if (!StringUtils.isBlank(ylgd.getLength())) {
                if (ylgd.getLength().indexOf("\n") > -1) {
                    String[] arr = ylgd.getLength().split("\n");
                    for (int j = 0; j < arr.length; j++) {
                        try {
                            lengthList.add(Double.valueOf(arr[j]));
                        } catch (NumberFormatException e) {

                        }
                    }
                }else {
                    try {
                        lengthList.add(Double.valueOf(ylgd.getLength()));
                    } catch (NumberFormatException e) {

                    }
                }
            }
        }
        double sum = lengthList.stream().mapToDouble(x->x).sum();
        DecimalFormat df = new DecimalFormat("0.00#");
        logger.info("==========sum:"+df.format(sum));
        return AjaxResult.success(df.format(sum));
    }

    /**
     * 压力容器数据
     */
    @RequestMapping(value = "devYlrqData")
    public AjaxResult devYlrqData(@RequestBody Map<String, Object> params) {
        List plantIds = (List) params.get("plantIds");
        List unitIds = (List) params.get("unitIds");
        Calendar now = Calendar.getInstance();
        int year = now.get(Calendar.YEAR);
        Map<String, Object> ylrqData = new HashMap<String, Object>();
        List yearList = new ArrayList();
        List countList = new ArrayList();
        String applySql = "to_char(NEXT_WARN_DATE,'yyyy') = {0}";
        for (int j = 0; j < 5; j++) {
            int num = tSpecdevYlrqService.count(new QueryWrapper<TSpecdevYlrq>()
                    .eq("STATUS" , 1)
                    .eq("del_flag" , 0)
                    .apply(true,applySql,year)
                    .in("plant_code",plantIds)
//                    .in("unit",unitIds)
            );
            yearList.add(year);
            countList.add(num);
            year++;
        }
        ylrqData.put("yearList" , yearList.toArray());
        ylrqData.put("countList" , countList.toArray());

        Map<String, Object> res = new HashMap<String, Object>();
        res.put("ylrqData" , ylrqData);
        return AjaxResult.success(res);
    }

    /**
     * 压力容器数据
     */
    @GetMapping("/devYlrqDataByYear")
    public TableDataInfo devYlrqDataByYear(TSpecdevYlrq tSpecdevYlrq) {
        startPage();
        List<TSpecdevYlrq> list = tSpecdevYlrqService.selectTSpecdevYlrqListByYear(tSpecdevYlrq);
        return getDataTable(list);
    }

    /**
     * 导出特种设备压力容器台账列表
     */
    @GetMapping("/exportYlrq")
    public AjaxResult export(TSpecdevYlrq tSpecdevYlrq)
    {
        List<TSpecdevYlrq> list = tSpecdevYlrqService.selectTSpecdevYlrqListByYear(tSpecdevYlrq);
        ExcelUtil<TSpecdevYlrq> util = new ExcelUtil<TSpecdevYlrq>(TSpecdevYlrq.class);
        return util.exportExcel(list, "specYlrq");
    }
    /**
     * 导出特种设备压力管道台账列表
     */
    @GetMapping("/exportYlgd")
    public AjaxResult export(TSpecdevYlgd tSpecdevYlgd) {
        List<TSpecdevYlgd> list = tSpecdevYlgdService.selectTSpecdevYlgdListByYear(tSpecdevYlgd);
        ExcelUtil<TSpecdevYlgd> util = new ExcelUtil<TSpecdevYlgd>(TSpecdevYlgd.class);
        return util.exportExcel(list, "specYlgd");
    }
    /**
     * 导出特种设备锅炉台账列表
     */
    @GetMapping("/exportGl")
    public AjaxResult export(TSpecdevGl tSpecdevGl)
    {
        List<TSpecdevGl> list = tSpecdevGlService.selectTSpecdevGlListByYear(tSpecdevGl);
        ExcelUtil<TSpecdevGl> util = new ExcelUtil<TSpecdevGl>(TSpecdevGl.class);
        return util.exportExcel(list, "specGl");
    }
    /**
     * 导出特种设备电梯台账列表
     */
    @GetMapping("/exportDt")
    public AjaxResult export(TSpecdevDt tSpecdevDt)
    {
        List<TSpecdevDt> list = tSpecdevDtService.selectTSpecdevDtListByYear(tSpecdevDt);
        ExcelUtil<TSpecdevDt> util = new ExcelUtil<TSpecdevDt>(TSpecdevDt.class);
        return util.exportExcel(list, "specDt");
    }
    /**
     * 导出特种设备吊装设备台账列表
     */
    @GetMapping("/exportDzsb")
    public AjaxResult export(TSpecdevDzsb tSpecdevDzsb)
    {
        List<TSpecdevDzsb> list = tSpecdevDzsbService.selectTSpecdevDzsbListByYear(tSpecdevDzsb);
        ExcelUtil<TSpecdevDzsb> util = new ExcelUtil<TSpecdevDzsb>(TSpecdevDzsb.class);
        return util.exportExcel(list, "specDzsb");
    }
    /**
     * 导出特种设备叉车台账列表
     */
    @GetMapping("/exportCc")
    public AjaxResult export(TSpecdevCc tSpecdevCc)
    {
        List<TSpecdevCc> list = tSpecdevCcService.selectTSpecdevCcListByYear(tSpecdevCc);
        ExcelUtil<TSpecdevCc> util = new ExcelUtil<TSpecdevCc>(TSpecdevCc.class);
        return util.exportExcel(list, "specCc");
    }
    /**
     * 锅炉数据
     */
    @RequestMapping(value = "devGlData")
    public AjaxResult devGlData(@RequestBody Map<String, Object> params) {

        List plantIds = (List) params.get("plantIds");
        List unitIds = (List) params.get("unitIds");
        Calendar now = Calendar.getInstance();
        int year = now.get(Calendar.YEAR);
        Map<String, Object> GlData = new HashMap<String, Object>();
        //内检
        List yearList = new ArrayList();
        List countList = new ArrayList();
        String applySql = "to_char(NEXT_WARN_DATE,'yyyy') = {0}";
        for (int i = 0; i < 5; i++) {
            int num = tSpecdevGlService.count(new QueryWrapper<TSpecdevGl>()
                    .eq("STATUS" , 1)
                    .eq("del_flag" , 0)
                    .apply(true,applySql,year)
                    .in("plant_code",plantIds)
            );
            yearList.add(year);
            countList.add(num);
            year++;
        }
        //外检
        List yearList2 = new ArrayList();
        List countList2 = new ArrayList();
        year = now.get(Calendar.YEAR);
        String applySql2 = "to_char(OUT_NEXT_WARN_DATE,'yyyy') = {0}";
        for (int i = 0; i < 5; i++) {
            int num = tSpecdevGlService.count(new QueryWrapper<TSpecdevGl>()
                    .eq("STATUS" , 1)
                    .eq("del_flag" , 0)
                    .apply(true,applySql2,year)
                    .in("plant_code",plantIds)
            );
            yearList2.add(year);
            countList2.add(num);
            year++;
        }
        GlData.put("yearList" , yearList.toArray());
        GlData.put("countList" , countList.toArray());
        GlData.put("yearList2" , yearList2.toArray());
        GlData.put("countList2" , countList2.toArray());
        Map<String, Object> res = new HashMap<String, Object>();
        res.put("GlData" , GlData);
        return AjaxResult.success(res);
    }

    /**
     * guolu
     */
    @GetMapping("/devGlDataByYear")
    public TableDataInfo devGlDataByYear(TSpecdevGl tSpecdevGl) {
        startPage();
        List<TSpecdevGl> list = tSpecdevGlService.selectTSpecdevGlListByYear(tSpecdevGl);
        return getDataTable(list);
    }

    /**
     * 压力管道数据
     */
    @RequestMapping(value = "devYlgdData")
    public AjaxResult devYlgdData(@RequestBody Map<String, Object> params) {
        List plantIds = (List) params.get("plantIds");
        List unitIds = (List) params.get("unitIds");
        Calendar now = Calendar.getInstance();
        int year = now.get(Calendar.YEAR);
        Map<String, Object> ylrqData = new HashMap<String, Object>();
        List yearList = new ArrayList();
        List countList = new ArrayList();
        String applySql = "to_char(NEXT_WARN_DATE,'yyyy') = {0}";
        for (int i = 0; i < 5; i++) {
            int num = tSpecdevYlgdService.count(new QueryWrapper<TSpecdevYlgd>()
                    .eq("STATUS" , 1)
                    .eq("del_flag" , 0)
//                    .eq(!StringUtils.isBlank((String)params.get("plantName")) , "plant_code" ,params.get("plantName"))
                    .apply(true,applySql,year)
                    .in("plant_code",plantIds)
            );
            yearList.add(year);
            countList.add(num);
            year++;
        }
        ylrqData.put("yearList" , yearList.toArray());
        ylrqData.put("countList" , countList.toArray());
        Map<String, Object> res = new HashMap<String, Object>();
        res.put("ylrqData" , ylrqData);
        return AjaxResult.success(res);
    }

    /**
     * 压力容器数据
     */
    @GetMapping("/devYlgdDataByYear")
    public TableDataInfo devYlgdDataByYear(TSpecdevYlgd tSpecdevYlgd) {
        startPage();
        List<TSpecdevYlgd> list = tSpecdevYlgdService.selectTSpecdevYlgdListByYear(tSpecdevYlgd);
        return getDataTable(list);
    }

    /**
     * 压力容器数据
     */
    @GetMapping("/devDzsbDataByYear")
    public TableDataInfo devDzsbDataByYear(TSpecdevDzsb tSpecdevDzsb) {
        startPage();
        List<TSpecdevDzsb> list = tSpecdevDzsbService.selectTSpecdevDzsbListByYear(tSpecdevDzsb);
        return getDataTable(list);
    }

    /**
     * 压力容器数据
     */
    @GetMapping("/devCcDataByYear")
    public TableDataInfo devCcDataByYear(TSpecdevCc tSpecdevCc) {
        startPage();
        List<TSpecdevCc> list = tSpecdevCcService.selectTSpecdevCcListByYear(tSpecdevCc);
        return getDataTable(list);
    }

    /**
     * 压力容器数据
     */
    @GetMapping("/devDtDataByYear")
    public TableDataInfo devDtDataByYear(TSpecdevDt tSpecdevDt) {
        startPage();
        List<TSpecdevDt> list = tSpecdevDtService.selectTSpecdevDtListByYear(tSpecdevDt);
        return getDataTable(list);
    }

    /**
     * 压力管道数据
     */
    @RequestMapping(value = "devOtherData")
    public AjaxResult devOtherData(@RequestBody Map<String, Object> params) {
        Calendar now = Calendar.getInstance();
        int year = now.get(Calendar.YEAR);
        int month = now.get(Calendar.MONTH) + 1;
        List<DevData> listcc = tSpecdevCcService.otherDevCount(params);
        List<DevData> listdzsb = tSpecdevDzsbService.otherDevCount(params);
        List<DevData> listdt = tSpecdevDtService.otherDevCount(params);
        List ccList = new ArrayList();
        List dzsbList = new ArrayList();
        List dtList = new ArrayList();
        List monthList = new ArrayList();
        for (int i = 0; i < 24; i++) {
            String devDate = year + String.valueOf(month);
            if (month < 10){
                devDate = year + "0" +String.valueOf(month);
            }
            boolean flag = true;
            for (DevData d: listcc
            ) {
                flag = true;
                if (devDate.equals(d.getYearM())){
                    ccList.add(d.getNum());
                    flag = false;
                    break;
                }
            }
            if (flag == true) {
                ccList.add(0);
            }
            for (DevData d: listdzsb
            ) {
                flag = true;
                if (devDate.equals(d.getYearM())){
                    dzsbList.add(d.getNum());
                    flag = false;
                    break;
                }
            }
            if (flag == true) {
                dzsbList.add(0);
            }
            for (DevData d: listdt
            ) {
                flag = true;
                if (devDate.equals(d.getYearM())){
                    dtList.add(d.getNum());
                    flag = false;
                    break;
                }
            }
            if (flag == true) {
                dtList.add(0);
            }
            if (!(ccList.size() == 0 && dzsbList.size() == 0 &&dtList.size() == 0)) {
                monthList.add(devDate);
            }
            if (month == 12){
                year++;
                month = 1;
            }else {
                month ++;
            }
        }
        for (int i = 0; i < 10; i++) {
            if (String.valueOf(ccList.get(0)).equals("0") && String.valueOf(dzsbList.get(0)).equals("0") && String.valueOf(dtList.get(0)).equals("0")) {
                ccList.remove(0);
                dzsbList.remove(0);
                dtList.remove(0);
                monthList.remove(0);
            }else {
                break;
            }
        }
        Map<String, Object> devData = new HashMap<String, Object>();
        devData.put("monthList" , monthList.toArray());
        devData.put("ccList" , ccList.toArray());
        devData.put("dzsbList" , dzsbList.toArray());
        devData.put("dtList" , dtList.toArray());
        Map<String, Object> res = new HashMap<String, Object>();
        res.put("otherDevData" ,devData);
        return AjaxResult.success(res);
    }

    /**
     * 首页申请数据
     */
    @RequestMapping(value = "finishApproveData")
    public AjaxResult finishApproveData(@RequestBody Map<String, Object> params) {
        Calendar now = Calendar.getInstance();
        int year = now.get(Calendar.YEAR);
        params.put("year",year);
        List<ApproveData> list =tApproveService.approveData(params);
        return AjaxResult.success(list);
    }

    /**
     * 数据
     */
    @RequestMapping(value = "devYlrqSafeData")
    public AjaxResult devYlrqSafeData(@RequestBody Map<String, Object> params) {
        List plantIds = (List) params.get("plantIds");
        List unitIds = (List) params.get("unitIds");

        int safe1 = tSpecdevYlrqService.count(new QueryWrapper<TSpecdevYlrq>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
                .in("safe_class","1","1级","1.0","一级","Ⅰ级")
        );
        int safe2 = tSpecdevYlrqService.count(new QueryWrapper<TSpecdevYlrq>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
                .in("safe_class","2","2级","2.0","二级","Ⅱ级")
        );

        int safe3 = tSpecdevYlrqService.count(new QueryWrapper<TSpecdevYlrq>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
                .in("safe_class","3","3级","3.0","三级","Ⅲ级")
        );

        int safe4 = tSpecdevYlrqService.count(new QueryWrapper<TSpecdevYlrq>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
                .in("safe_class","4","4级","4.0","四级","Ⅳ级")
        );
        int safe5 = tSpecdevYlrqService.count(new QueryWrapper<TSpecdevYlrq>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
                .in("safe_class","5","5级","5.0","五级","Ⅴ级")
        );
        int safeall = tSpecdevYlrqService.count(new QueryWrapper<TSpecdevYlrq>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
        );
        int safeNa = safeall - safe1 - safe2- safe3- safe4 - safe5;
        List safeList = new ArrayList();
        safeList.add(safe1);
        safeList.add(safe2);
        safeList.add(safe3);
        safeList.add(safe4);
        safeList.add(safe5);
        safeList.add(safeNa);
        Map<String, Object> res = new HashMap<String, Object>();
        res.put("safeData", safeList);
        return AjaxResult.success(res);
    }

    /**
     * 数据
     */
    @RequestMapping(value = "devYlgdSafeData")
    public AjaxResult devYlgdSafeData(@RequestBody Map<String, Object> params) {
        List plantIds = (List) params.get("plantIds");
        List unitIds = (List) params.get("unitIds");

        int safe1 = tSpecdevYlgdService.count(new QueryWrapper<TSpecdevYlgd>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
                .in("safe_class","1","1级","1.0","一级","Ⅰ级")
        );
        int safe2 = tSpecdevYlgdService.count(new QueryWrapper<TSpecdevYlgd>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
                .in("safe_class","2","2级","2.0","二级","Ⅱ级")
        );
        int safe3 = tSpecdevYlgdService.count(new QueryWrapper<TSpecdevYlgd>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
                .in("safe_class","3","3级","3.0","三级","Ⅲ级")
        );
        int safe4 = tSpecdevYlgdService.count(new QueryWrapper<TSpecdevYlgd>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
                .in("safe_class","4","4级","4.0","四级","Ⅳ级")
        );
        int safeall = tSpecdevYlgdService.count(new QueryWrapper<TSpecdevYlgd>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
        );
        int safeNa = safeall - safe1 - safe2- safe3- safe4;
        List safeList = new ArrayList();
        safeList.add(safe1);
        safeList.add(safe2);
        safeList.add(safe3);
        safeList.add(safe4);
        safeList.add(safeNa);
        Map<String, Object> res = new HashMap<String, Object>();
        res.put("safeData", safeList);
        return AjaxResult.success(res);
    }

    /**
     * 锅炉数据
     */
    @RequestMapping(value = "devGlPerData")
    public AjaxResult devGlPerData(@RequestBody Map<String, Object> params) {
        List plantIds = (List) params.get("plantIds");
        List unitIds = (List) params.get("unitIds");

        int all = tSpecdevGlService.count(new QueryWrapper<TSpecdevGl>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
        );
        int cc = tSpecdevGlService.count(new QueryWrapper<TSpecdevGl>()
                .eq("STATUS" , 1)
                .eq("del_flag" , 0)
                .in("plant_code",plantIds)
                .in("CHECK_CONCLUSION","符合要求","允许运行")
        );
        String per = "0";
        if (all != 0) {
            per = new BigDecimal(cc).multiply(new BigDecimal(100)).divide(new BigDecimal(all), 2, BigDecimal.ROUND_HALF_UP).setScale(1, BigDecimal.ROUND_HALF_DOWN).toString();
        }
        Map<String, Object> res = new HashMap<String, Object>();
        res.put("per" , per);
        return AjaxResult.success(res);
    }

    /**
     * 申请中数据
     */
    @RequestMapping(value = "devApproveData")
    public AjaxResult devApproveData(@RequestBody Map<String, Object> params) {
        List plantIds = (List) params.get("plantIds");
        List unitIds = (List) params.get("unitIds");
        List<String> info = new ArrayList<>();
        List<SysDictData> approveStatus = iSysDictTypeService.selectDictDataByType("spec_approve_status");
        //压力容器申请
            List<TSpecdevYlrq> ylrqList = tSpecdevYlrqService.list(new QueryWrapper<TSpecdevYlrq>()
                    .notIn("APPROVE_STATUS" , 0)
                    .in("plant_code",plantIds)
                    .eq("del_flag" , 0)
            );
        if (ylrqList!= null){
            for (TSpecdevYlrq t: ylrqList
                 ) {
                String as ="";
                for (SysDictData p : approveStatus) {
                    if (p.getDictValue().equals(t.getApproveStatus().toString())) {
                        as = p.getDictLabel();
                    }
                }
                info.add("压力容器:" + t.getDevname() + "-" + as);
            }
        }
        //压力管道申请
        List<TSpecdevYlgd> ylgdList = tSpecdevYlgdService.list(new QueryWrapper<TSpecdevYlgd>()
                .notIn("APPROVE_STATUS" , 0)
                .in("plant_code",plantIds)
                .eq("del_flag" , 0)
        );
        if (ylgdList!= null){
            for (TSpecdevYlgd t: ylgdList
            ) {
                String as ="";
                for (SysDictData p : approveStatus) {
                    if (p.getDictValue().equals(t.getApproveStatus().toString())) {
                        as = p.getDictLabel();
                    }
                }
                info.add("压力管道:" + t.getDevname() + "-" + as);
            }
        }
        //锅炉申请
        List<TSpecdevGl> GlList = tSpecdevGlService.list(new QueryWrapper<TSpecdevGl>()
                .notIn("APPROVE_STATUS" , 0)
                .in("plant_code",plantIds)
                .eq("del_flag" , 0)
        );
        if (GlList!= null){
            for (TSpecdevGl t: GlList
            ) {
                String as ="";
                for (SysDictData p : approveStatus) {
                    if (p.getDictValue().equals(t.getApproveStatus().toString())) {
                        as = p.getDictLabel();
                    }
                }
                info.add("锅炉:" + t.getDevname() + "-" + as);
            }
        }
        //起重机械申请
        List<TSpecdevDzsb> dzsbList = tSpecdevDzsbService.list(new QueryWrapper<TSpecdevDzsb>()
                .notIn("APPROVE_STATUS" , 0)
                .in("plant_code",plantIds)
                .eq("del_flag" , 0)
        );
        if (dzsbList!= null){
            for (TSpecdevDzsb t: dzsbList
            ) {
                String as ="";
                for (SysDictData p : approveStatus) {
                    if (p.getDictValue().equals(t.getApproveStatus().toString())) {
                        as = p.getDictLabel();
                    }
                }
                info.add("起重机械:" + t.getDevname() + "-" + as);
            }
        }
        //电梯申请t
        List<TSpecdevDt> dtList = tSpecdevDtService.list(new QueryWrapper<TSpecdevDt>()
                .notIn("APPROVE_STATUS" , 0)
                .in("plant_code",plantIds)
                .eq("del_flag" , 0)
        );
        if (dtList!= null){
            for (TSpecdevDt t: dtList
            ) {
                String as ="";
                for (SysDictData p : approveStatus) {
                    if (p.getDictValue().equals(t.getApproveStatus().toString())) {
                        as = p.getDictLabel();
                    }
                }
                info.add("电梯:" + t.getDevname() + "-" + as);
            }
        }
        //叉车申请t
        List<TSpecdevCc> ccList = tSpecdevCcService.list(new QueryWrapper<TSpecdevCc>()
                .notIn("APPROVE_STATUS" , 0)
                .in("plant_code",plantIds)
                .eq("del_flag" , 0)
        );
        if (ccList!= null){
            for (TSpecdevCc t: ccList
            ) {
                String as ="";
                for (SysDictData p : approveStatus) {
                    if (p.getDictValue().equals(t.getApproveStatus().toString())) {
                        as = p.getDictLabel();
                    }
                }
                info.add("叉车:" + t.getDevname() + "-" + as);
            }
        }
        return AjaxResult.success(info);
    }

}
