package com.usky.fire.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usky.common.core.exception.BusinessException;
import com.usky.common.core.util.Arith;
import com.usky.common.mybatis.core.AbstractCrudService;
import com.usky.fire.domain.BaseCompany;
import com.usky.fire.domain.BscEnterpriseScreen;
import com.usky.fire.domain.DemBuildScore;
import com.usky.fire.domain.DemBuildScoreRecord;
import com.usky.fire.mapper.BscEnterpriseScreenMapper;
import com.usky.fire.mapper.PatrolInspectionPlanSiteSonMapper;
import com.usky.fire.service.*;
import com.usky.fire.service.util.OnlineMethod;
import com.usky.fire.service.vo.DataCountVo;
import com.usky.fire.service.vo.DataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;

/**
 * <p>
 * 企业大屏数据统计 服务实现类
 * </p>
 *
 * @author JCB
 * @since 2022-09-06
 */
@Service
public class BscEnterpriseScreenServiceImpl extends AbstractCrudService<BscEnterpriseScreenMapper, BscEnterpriseScreen> implements BscEnterpriseScreenService {

    @Autowired
    private BaseUserCompanyService baseUserCompanyService;

    @Autowired
    private PostInspectService postInspectService;

    @Autowired
    private AlarmFireService alarmFireService;

    @Autowired
    private BaseDeviceService baseDeviceService;

    @Autowired
    private ReservePlanService reservePlanService;

    @Autowired
    private AlarmElectricalFireService alarmElectricalFireService;

    @Autowired
    private DemBuildScoreService demBuildScoreService;

    @Autowired
    private DemBuildScoreRecordService demBuildScoreRecordService;

    @Autowired
    private PatrolInspectionPlanSiteSonMapper patrolInspectionPlanSiteSonMapper;

    @Autowired
    private BaseCompanyService baseCompanyService;

    @Autowired
    private AlarmHydrantWaterService alarmHydrantWaterService;

    @Autowired
    private AlarmSmokeControlService alarmSmokeControlService;

    @Autowired
    private AlarmSprayWaterService alarmSprayWaterService;

    @Autowired
    private AlarmVideoService alarmVideoService;

    @Autowired
    private BaseDeviceStatusService baseDeviceStatusService;

    @Override
    public Object screenDataStatistic(String dataType, String moduleType, String dataType1) {
        String companyId = baseUserCompanyService.companyId();
        if (StringUtils.isBlank(companyId)) {
            throw new BusinessException("用户未绑定联网单位");
        }
        LambdaQueryWrapper<BscEnterpriseScreen> queryWrapper = Wrappers.lambdaQuery();
        switch (moduleType) {
            case "patrolInspection":
                queryWrapper.select(BscEnterpriseScreen::getPatrolInspection);
                break;
            case "postInspect":
                queryWrapper.select(BscEnterpriseScreen::getPostInspect);
                break;
            case "fireAlarm":
                queryWrapper.select(BscEnterpriseScreen::getFireAlarm);
                break;
            case "reservePlan":
                queryWrapper.select(BscEnterpriseScreen::getReservePlan);
                break;
            case "hiddenDanger":
                queryWrapper.select(BscEnterpriseScreen::getHiddenDanger);
                break;
            case "buildScore":
                queryWrapper.select(BscEnterpriseScreen::getBuildScore);
                break;
            default:
                throw new BusinessException("参数错误");
        }
        queryWrapper.eq(BscEnterpriseScreen::getCompanyId, companyId)
                .orderByDesc(BscEnterpriseScreen::getId)
                .last(" limit 1");
        List<BscEnterpriseScreen> list = this.list(queryWrapper);
        Object data = null;
        if (CollectionUtils.isNotEmpty(list)) {
            switch (moduleType) {
                case "patrolInspection":
                    data = list.get(0).getPatrolInspection();
                    break;
                case "postInspect":
                    data = list.get(0).getPostInspect();
                    break;
                case "fireAlarm":
                    data = list.get(0).getFireAlarm();
                    break;
                case "reservePlan":
                    data = list.get(0).getReservePlan();
                    break;
                case "hiddenDanger":
                    data = list.get(0).getHiddenDanger();
                    break;
                case "buildScore":
                    data = list.get(0).getBuildScore();
                    break;
            }
        }
        JSONObject jsonObject = JSONObject.parseObject(data.toString());
        Object disparateData = new Object();
        if (moduleType.equals("patrolInspection")) {
            disparateData = jsonObject.get(dataType1);
        } else {
            disparateData = jsonObject.get(dataType);
        }

        return disparateData;
    }

    @Override
    public void dataSynchro() {
        List<String> streetTownList = new ArrayList<>();
        streetTownList.add("华漕镇");
        streetTownList.add("新虹街道");
        streetTownList.add("七宝镇");
        streetTownList.add("虹桥镇");
        streetTownList.add("古美路街道");
        streetTownList.add("莘庄镇");
        streetTownList.add("梅陇镇");
        streetTownList.add("颛桥镇");
        streetTownList.add("马桥镇");
        streetTownList.add("江川路街道");
        streetTownList.add("吴泾镇");
        streetTownList.add("浦锦街道");
        streetTownList.add("浦江镇");
        List<BaseCompany> baseCompanies = baseCompanyService.companyIdList(streetTownList);
        if (CollectionUtils.isNotEmpty(baseCompanies)) {
            for (int i = 0; i < baseCompanies.size(); i++) {
                Object postInspectStatistics = this.postInspectStatistics(baseCompanies.get(i).getCompanyId());
                Object fireAlarmStatistics = this.fireAlarmStatistics(baseCompanies.get(i).getCompanyId());
                Object reservePlanStatistics = this.reservePlanStatistics(baseCompanies.get(i).getCompanyId());
                Object hiddenDangerStatistics = this.hiddenDangerStatistics(baseCompanies.get(i).getCompanyId());
                Object buildScoreStatistics = this.buildScoreStatistics(baseCompanies.get(i).getCompanyId());
                Object patrolInspectionStatistics = this.patrolInspectionStatistics(baseCompanies.get(i).getCompanyId());
//                List<BscEnterpriseScreen> list = this.bscEnterpriseScreenCount(baseCompanies.get(i).getCompanyId());
                BscEnterpriseScreen bscEnterpriseScreen = new BscEnterpriseScreen();
                bscEnterpriseScreen.setCompanyId(baseCompanies.get(i).getCompanyId());
                bscEnterpriseScreen.setCreateTime(LocalDateTime.now());
                bscEnterpriseScreen.setPatrolInspection(JSON.toJSONString(patrolInspectionStatistics));
                bscEnterpriseScreen.setPostInspect(JSON.toJSONString(postInspectStatistics));
                bscEnterpriseScreen.setFireAlarm(JSON.toJSONString(fireAlarmStatistics));
                bscEnterpriseScreen.setReservePlan(JSON.toJSONString(reservePlanStatistics));
                bscEnterpriseScreen.setHiddenDanger(JSON.toJSONString(hiddenDangerStatistics));
                bscEnterpriseScreen.setBuildScore(JSON.toJSONString(buildScoreStatistics));
                this.save(bscEnterpriseScreen);
            }
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
            long timeStamp = OnlineMethod.getLastPeroid(2, new Date());
            String scoreDate = format.format(timeStamp);
            List<DemBuildScoreRecord> list1 = demBuildScoreRecordService.demBuildScoreRecordListOne(scoreDate, null);
            for (int i = 0; i < list1.size(); i++) {
                int count = demBuildScoreRecordService.demBuildScoreRecordCount(scoreDate, null, null, null);
                int overstepCount = demBuildScoreRecordService.demBuildScoreRecordCount(scoreDate, list1.get(i).getBuildScore(), null, null);
                double faultRatio1 = Arith.div(overstepCount, count, 2) * 100;
                int faultRatio = new Double(faultRatio1).intValue();
                int rank = count - overstepCount;
                List<BscEnterpriseScreen> enterpriseScreensList = this.bscEnterpriseScreenCount(list1.get(i).getCompanyId());
                if (CollectionUtils.isNotEmpty(enterpriseScreensList)) {
                    Map<String, Object> map1 = new HashMap<>();
                    map1.put("value", rank);
                    Map<String, Object> map2 = new HashMap<>();
                    map2.put("value", faultRatio);
                    JSONObject buildScore = JSONObject.parseObject(enterpriseScreensList.get(0).getBuildScore());
                    buildScore.put("data3", map1);
                    buildScore.put("data4", map2);
                    BscEnterpriseScreen bscEnterpriseScreen = new BscEnterpriseScreen();
                    bscEnterpriseScreen.setId(enterpriseScreensList.get(0).getId());
                    bscEnterpriseScreen.setBuildScore(JSON.toJSONString(buildScore));
                    this.updateById(bscEnterpriseScreen);
                }
            }
        }
    }

    @Override
    public List<DataVo> Alarmlist() {
        List<DataVo> list = new ArrayList<>();
        List<DataVo> alarmlist = alarmElectricalFireService.Alarmlist();
        List<DataVo> alarmlist1 = alarmFireService.Alarmlist();
        List<DataVo> alarmlist2 = alarmHydrantWaterService.Alarmlist();
        List<DataVo> alarmlist3 = alarmSmokeControlService.Alarmlist();
        List<DataVo> alarmlist4 = alarmSprayWaterService.Alarmlist();
        List<DataVo> alarmlist5 = alarmVideoService.Alarmlist();
        for (int i = 0; i < alarmlist.size(); i++) {
            list.add(alarmlist.get(i));
        }
        for (int i = 0; i < alarmlist1.size(); i++) {
            list.add(alarmlist1.get(i));
        }
        for (int i = 0; i < alarmlist2.size(); i++) {
            list.add(alarmlist2.get(i));
        }
        for (int i = 0; i < alarmlist3.size(); i++) {
            list.add(alarmlist3.get(i));
        }
        for (int i = 0; i < alarmlist4.size(); i++) {
            list.add(alarmlist4.get(i));
        }
        for (int i = 0; i < alarmlist5.size(); i++) {
            list.add(alarmlist5.get(i));
        }
        Collections.sort(list, new Comparator<DataVo>() {
            @Override
            public int compare(DataVo h1, DataVo h2) {
                return h1.getType1().compareTo(h2.getType1());
            }
        });
        Collections.reverse(list);
        return list;
    }

    @Override
    public List<BscEnterpriseScreen> bscEnterpriseScreenCount(String companyId) {
        LambdaQueryWrapper<BscEnterpriseScreen> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.select(BscEnterpriseScreen::getId, BscEnterpriseScreen::getBuildScore)
                .eq(BscEnterpriseScreen::getCompanyId, companyId)
                .orderByDesc(BscEnterpriseScreen::getId)
                .last(" limit 1");
        List<BscEnterpriseScreen> list = this.list(queryWrapper);
        return list;
    }


    @Override
    public Object postInspectStatistics(String companyId) {
        int uncharCount = postInspectService.postInspectCount(companyId, 0);
        int chagasCount = postInspectService.postInspectCount(companyId, 1);
        int count = chagasCount + uncharCount;
        Map<String, Object> map = new HashMap<>();
        map.put("value", count);
        List<Object> data = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            Map<String, Object> map1 = new HashMap<>();
            if (i == 0) {
                map1.put("name", "应答数");
                map1.put("value", chagasCount);
            } else {
                map1.put("name", "未应答数");
                map1.put("value", uncharCount);
            }
            data.add(map1);
        }
        Map<String, Object> map2 = new HashMap<>();
        map2.put("data", data);
        Map<String, Object> map3 = new HashMap<>();
        map3.put("data1", map);
        map3.put("data2", map2);
        return map3;
    }

    @Override
    public Object fireAlarmStatistics(String companyId) {
        int fireUntreated = alarmFireService.fireAlarmCount(companyId, 0, "2", null, null);
        int fireProcessed = alarmFireService.fireAlarmCount(companyId, 1, "2", null, null);
        int fireCount = fireUntreated + fireProcessed;
        double fireRatio = Arith.div(fireProcessed, fireCount, 2) * 100;
        int faultUntreated = alarmFireService.fireAlarmCount(companyId, 0, "4", null, null);
        int faultProcessed = alarmFireService.fireAlarmCount(companyId, 1, "4", null, null);
        int faultCount = faultUntreated + faultProcessed;
        double faultRatio = Arith.div(faultProcessed, faultCount, 2) * 100;
        int deviceCount = baseDeviceService.deviceCount(companyId, 0);
        int offlineDeviceCount = baseDeviceStatusService.deviceStatusCount(companyId, 0);
        int onlineDeviceCount = deviceCount - offlineDeviceCount;
        double deviceRatio = Arith.div(onlineDeviceCount, deviceCount, 2) * 100;

        Map<String, Object> map1 = new HashMap<>();
        map1.put("min", 1);
        map1.put("max", 100);
        map1.put("label", "火警告警报告");
        map1.put("value", fireRatio);
        map1.put("unit", "%");
        Map<String, Object> map15 = new HashMap<>();
        map15.put("data", map1);

        Map<String, Object> map2 = new HashMap<>();
        map2.put("value", fireCount);

        Map<String, Object> map3 = new HashMap<>();
        map3.put("value", fireUntreated);

        Map<String, Object> map4 = new HashMap<>();
        map4.put("value", fireProcessed);

        List<Object> data = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            Map<String, Object> map5 = new HashMap<>();
            if (i == 1) {
                map5.put("name", "离线");
                map5.put("value", offlineDeviceCount);
            } else {
                map5.put("name", "在线");
                map5.put("value", onlineDeviceCount);
            }
            data.add(map5);
        }
        Map<String, Object> map16 = new HashMap<>();
        map16.put("data", data);

        Map<String, Object> map6 = new HashMap<>();
        map6.put("value", deviceCount);

        Map<String, Object> map7 = new HashMap<>();
        map7.put("value", deviceRatio);

        Map<String, Object> map8 = new HashMap<>();
        map8.put("min", 1);
        map8.put("max", 100);
        map8.put("label", "故障告警报告");
        map8.put("value", faultRatio);
        map8.put("unit", "%");
        Map<String, Object> map17 = new HashMap<>();
        map17.put("data", map8);

        Map<String, Object> map9 = new HashMap<>();
        map9.put("value", faultCount);

        Map<String, Object> map10 = new HashMap<>();
        map10.put("value", faultUntreated);

        Map<String, Object> map11 = new HashMap<>();
        map11.put("value", faultProcessed);

        Map<String, Object> map = new HashMap<>();
        map.put("data1", map15);
        map.put("data2", map2);
        map.put("data3", map3);
        map.put("data4", map4);
        map.put("data5", map17);
        map.put("data6", map9);
        map.put("data7", map10);
        map.put("data8", map11);
        map.put("data9", map16);
        map.put("data10", map6);
        map.put("data11", map7);
        return map;
    }


    @Override
    public Object reservePlanStatistics(String companyId) {
        List<DataCountVo> dataCountVos = reservePlanService.reservePlanCount(companyId);
        List<Object> data = new ArrayList<>();
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        for (int i = 0; i < dataCountVos.size(); i++) {
            if (dataCountVos.get(i).getId() == 1) {
                count1 = dataCountVos.get(i).getListCount();
            } else if (dataCountVos.get(i).getId() == 2) {
                count2 = dataCountVos.get(i).getListCount();
            } else if (dataCountVos.get(i).getId() == 3) {
                count3 = dataCountVos.get(i).getListCount();
            }
        }
        Map<String, Object> map1 = new HashMap<>();
        map1.put("name", "小型火灾扑灭");
        map1.put("value", count1);
        Map<String, Object> map2 = new HashMap<>();
        map2.put("name", "人员疏散场景");
        map2.put("value", count2);
        Map<String, Object> map3 = new HashMap<>();
        map3.put("name", "重点风险处置");
        map3.put("value", count3);
        data.add(map1);
        data.add(map2);
        data.add(map3);
        Map<String, Object> map4 = new HashMap<>();
        map4.put("data", data);
        Map<String, Object> map = new HashMap<>();
        map.put("data1", map4);
        return map;
    }

    @Override
    public Object hiddenDangerStatistics(String companyId) {
        Map<String, Object> fireData = alarmElectricalFireService.alarmFireCount(companyId);
        Map<String, Object> electricalFireData = alarmElectricalFireService.alarmCount(companyId, "alarm_electrical_fire");
        Map<String, Object> hydrantWaterData = alarmElectricalFireService.alarmCount(companyId, "alarm_hydrant_water");
        Map<String, Object> smokeControlData = alarmElectricalFireService.alarmCount(companyId, "alarm_smoke_control");
        Map<String, Object> sprayWaterData = alarmElectricalFireService.alarmCount(companyId, "alarm_spray_water");
        Map<String, Object> videoData = alarmElectricalFireService.alarmCount(companyId, "alarm_video");
        int count = Integer.parseInt(fireData.get("count").toString()) + Integer.parseInt(electricalFireData.get("count").toString())
                + Integer.parseInt(hydrantWaterData.get("count").toString()) + Integer.parseInt(smokeControlData.get("count").toString())
                + Integer.parseInt(sprayWaterData.get("count").toString()) + Integer.parseInt(videoData.get("count").toString());
        Map<String, Object> map1 = new HashMap<>();
        map1.put("value", count);
        List<Object> data1 = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            Map<String, Object> map3 = new HashMap<>();
            Map<String, Object> map4 = new HashMap<>();
            switch (i) {
                case 0:
                    map3.put("name", "火灾");
                    map3.put("value", Integer.parseInt(fireData.get("processed").toString()));
                    map4.put("name", "火灾");
                    map4.put("value", Integer.parseInt(fireData.get("untreated").toString()));
                    break;
                case 1:
                    map3.put("name", "电器火灾");
                    map3.put("value", Integer.parseInt(electricalFireData.get("processed").toString()));
                    map4.put("name", "电器火灾");
                    map4.put("value", Integer.parseInt(electricalFireData.get("untreated").toString()));
                    break;
                case 2:
                    map3.put("name", "视频监控");
                    map3.put("value", Integer.parseInt(videoData.get("processed").toString()));
                    map4.put("name", "视频监控");
                    map4.put("value", Integer.parseInt(videoData.get("untreated").toString()));
                    break;
                case 3:
                    map3.put("name", "自动喷水灭火");
                    map3.put("value", Integer.parseInt(sprayWaterData.get("processed").toString()));
                    map4.put("name", "自动喷水灭火");
                    map4.put("value", Integer.parseInt(sprayWaterData.get("untreated").toString()));
                    break;
                case 4:
                    map3.put("name", "消防给水及消火栓");
                    map3.put("value", Integer.parseInt(hydrantWaterData.get("processed").toString()));
                    map4.put("name", "消防给水及消火栓");
                    map4.put("value", Integer.parseInt(hydrantWaterData.get("untreated").toString()));
                    break;
                case 5:
                    map3.put("name", "防排烟");
                    map3.put("value", Integer.parseInt(smokeControlData.get("processed").toString()));
                    map4.put("name", "防排烟");
                    map4.put("value", Integer.parseInt(smokeControlData.get("untreated").toString()));
                    break;
            }
            map3.put("series", "已处置");
            map3.put("type", "bar");
            map4.put("series", "未处置");
            map4.put("type", "bar");
            data1.add(map3);
            data1.add(map4);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("data1", map1);
        map.put("data2", data1);
        return map;
    }

    @Override
    public Object buildScoreStatistics(String companyId) {
        String LastMonthDate = OnlineMethod.getLastMonth(new Date());
        DecimalFormat df = new DecimalFormat("0.00");
        int deviceDamageCount = 20;
        int fireCount = 0;
        int rectificationCount = 40;
        int buildTypeCount = 10;
        int highRiskCount = 30;
        int hiddenDangerCount = 70;

        List<DemBuildScore> list1 = demBuildScoreService.buildScoreListOne();
        int demBuildScoreRecordsCount = demBuildScoreRecordService.demBuildScoreRecordCount(LastMonthDate, null, null, companyId);
        Double deviceDamageRieo = 0.00;
        Double fireRieo = 0.00;
        Double rectificationRieo = 0.00;
        Double buildTypeRieo = 0.00;
        Double highRiskRieo = 0.00;
        Double hiddenDangerRieo = 0.00;

        Double deviceDamageScore = 0.00;
        Double fireScore = 0.00;
        Double rectificationScore = 0.00;
        Double buildTypeScore = 0.00;
        Double highRiskScore = 0.00;
        Double hiddenDangerScore = 0.00;

        for (int i = 0; i < list1.size(); i++) {
            double sub = 0.0;
            double div = 0.0;
            int riskMax = Integer.parseInt(list1.get(i).getRiskMax());
            int weightProportion = Integer.parseInt(list1.get(i).getWeightProportion());
            switch (list1.get(i).getRiskId()) {
                case 1:
                    deviceDamageRieo = Double.valueOf(df.format((float) deviceDamageCount / riskMax * 100));
                    sub = Arith.sub(100, deviceDamageRieo);
                    div = Arith.div(weightProportion, 100);
                    deviceDamageScore = Arith.mul(sub, div);
                    break;
                case 2:
                    fireRieo = Double.valueOf(df.format((float) fireCount / riskMax * 100));
                    sub = Arith.sub(100, fireRieo);
                    div = Arith.div(weightProportion, 100);
                    fireScore = Arith.mul(sub, div);
//                    fireScore = (100 - fireRieo) * (weightProportion / 100);
                    break;
                case 3:
                    rectificationRieo = Double.valueOf(df.format((float) rectificationCount / riskMax * 100));
                    sub = Arith.sub(100, rectificationRieo);
                    div = Arith.div(weightProportion, 100);
                    rectificationScore = Arith.mul(sub, div);
//                    rectificationScore = (100 - rectificationRieo) * (weightProportion / 100);
                    break;
                case 4:
                    buildTypeRieo = Double.valueOf(df.format((float) buildTypeCount / riskMax * 100));
                    sub = Arith.sub(100, buildTypeRieo);
                    div = Arith.div(weightProportion, 100);
                    buildTypeScore = Arith.mul(sub, div);
//                    buildTypeScore = (100 - buildTypeRieo) * (weightProportion / 100);
                    break;
                case 5:
                    highRiskRieo = Double.valueOf(df.format((float) highRiskCount / riskMax * 100));
                    sub = Arith.sub(100, highRiskRieo);
                    div = Arith.div(weightProportion, 100);
                    highRiskScore = Arith.mul(sub, div);
//                    highRiskScore = (100 - highRiskRieo) * (weightProportion / 100);
                    break;
                case 6:
                    hiddenDangerRieo = Double.valueOf(df.format((float) hiddenDangerCount / riskMax * 100));
                    sub = Arith.sub(100, hiddenDangerRieo);
                    div = Arith.div(weightProportion, 100);
                    hiddenDangerScore = Arith.mul(sub, div);
//                    hiddenDangerScore = (100 - hiddenDangerRieo) * (weightProportion / 100);
                    break;
            }
        }

        Double totalScore1 = deviceDamageScore + fireScore + rectificationScore + buildTypeScore + highRiskScore + hiddenDangerScore;
        int totalScore = totalScore1.intValue();
        List<Object> data1 = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("name", "DataA");
            switch (i) {
                case 0:
                    map1.put("text", "设备状况指数");
                    map1.put("value", deviceDamageRieo);
                    break;
                case 1:
                    map1.put("text", "执法监管安全指数");
                    map1.put("value", rectificationRieo);
                    break;
                case 2:
                    map1.put("text", "历史火灾指数");
                    map1.put("value", fireRieo);
                    break;
                case 3:
                    map1.put("text", "隐患状况指数");
                    map1.put("value", hiddenDangerRieo);
                    break;
                case 4:
                    map1.put("text", "建筑整体风险指");
                    map1.put("value", buildTypeRieo);
                    break;
                case 5:
                    map1.put("text", "场所行业风险指数");
                    map1.put("value", highRiskRieo);
                    break;
            }
            data1.add(map1);
        }

        Map<String, Object> data2 = new HashMap<>();
        data2.put("value", totalScore);

        Map<String, Object> data3 = new HashMap<>();
        data3.put("value", 10);

        Map<String, Object> data4 = new HashMap<>();
        data4.put("value", 80);
        if (demBuildScoreRecordsCount <= 0) {
            DemBuildScoreRecord demBuildScoreRecord = new DemBuildScoreRecord();
            demBuildScoreRecord.setBuildScore(totalScore);
            demBuildScoreRecord.setScoreDate(LastMonthDate);
            demBuildScoreRecord.setCompanyId(companyId);
            demBuildScoreRecordService.demBuildScoreRecordAdd(demBuildScoreRecord);
        }
        List<DemBuildScoreRecord> demBuildScoreRecordsList = demBuildScoreRecordService.demBuildScoreRecordList(companyId, null);
        List<Object> data5 = new ArrayList<>();
        for (int i = 0; i < demBuildScoreRecordsList.size(); i++) {
            Map<String, Object> map3 = new HashMap<>();
            map3.put("name", "得分");
            map3.put("value", demBuildScoreRecordsList.get(demBuildScoreRecordsList.size() - (i + 1)).getBuildScore());
            map3.put("type", demBuildScoreRecordsList.get(demBuildScoreRecordsList.size() - (i + 1)).getScoreDate());
            data5.add(map3);
        }
        Map<String, Object> map2 = new HashMap<>();
        map2.put("data1", data1);
        map2.put("data2", data2);
        map2.put("data3", data3);
        map2.put("data4", data4);
        map2.put("data5", data5);
        return map2;
    }

    @Override
    public Object patrolInspectionStatistics(String companyId) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String sameDay = format.format(new Date());
        String startTime = null;
        String endTime = null;
        int qualifiedCount = 0;
        int undetectedCount = 0;
        List<Integer> seriesDataList1 = new ArrayList<>();
        List<Integer> seriesDataList2 = new ArrayList<>();
        List<Integer> seriesDataList3 = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            if (i == 0) {
                startTime = sameDay;
                endTime = sameDay;
            } else if (i == 1) {
                long timeStamp = OnlineMethod.getLastPeroid(1, new Date());
                startTime = format.format(timeStamp);
                endTime = sameDay;
            } else if (i == 2) {
                long timeStamp = OnlineMethod.getLastPeroid(2, new Date());
                startTime = format.format(timeStamp);
                endTime = sameDay;
            }
            qualifiedCount = patrolInspectionPlanSiteSonMapper.planSonSiteCout(startTime, endTime, 2);
            undetectedCount = patrolInspectionPlanSiteSonMapper.planSonSiteCout(startTime, endTime, 1);
            if (i == 0) {
                seriesDataList1.add(qualifiedCount);
                seriesDataList1.add(undetectedCount);
            } else if (i == 1) {
                seriesDataList2.add(qualifiedCount);
                seriesDataList2.add(undetectedCount);
            } else if (i == 2) {
                seriesDataList3.add(qualifiedCount);
                seriesDataList3.add(undetectedCount);
            }
        }

        List<Object> data1 = new ArrayList<>();
        Map<String, Object> map1 = new HashMap<>();
        map1.put("name", "合格数");
        map1.put("value", seriesDataList1.get(0));
        map1.put("type", "巡检");
        data1.add(map1);
        Map<String, Object> map1A = new HashMap<>();
        map1A.put("name", "漏检数");
        map1A.put("value", seriesDataList1.get(1));
        map1A.put("type", "巡检");
        data1.add(map1A);

        List<Object> data2 = new ArrayList<>();
        Map<String, Object> map2 = new HashMap<>();
        map2.put("name", "合格数");
        map2.put("value", seriesDataList2.get(0));
        map2.put("type", "巡检");
        data2.add(map2);
        Map<String, Object> map2A = new HashMap<>();
        map2A.put("name", "漏检数");
        map2A.put("value", seriesDataList2.get(1));
        map2A.put("type", "巡检");
        data2.add(map2A);

        List<Object> data3 = new ArrayList<>();
        Map<String, Object> map3 = new HashMap<>();
        map3.put("name", "合格数");
        map3.put("value", seriesDataList3.get(0));
        map3.put("type", "巡检");
        data3.add(map3);
        Map<String, Object> map3A = new HashMap<>();
        map3A.put("name", "漏检数");
        map3A.put("value", seriesDataList3.get(1));
        map3A.put("type", "巡检");
        data3.add(map3A);

        Map<String, Object> map = new HashMap<>();
        map.put("data1", data1);
        map.put("data2", data2);
        map.put("data3", data3);
        return map;
    }

}
