package com.njcn.device.pms.service.ledgerManger.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.enums.common.ServerEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.EnumUtils;
import com.njcn.device.biz.pojo.dto.*;
import com.njcn.device.biz.pojo.param.DeptGetLineParam;

import com.njcn.device.biz.pojo.po.Overlimit;
import com.njcn.device.biz.utils.COverlimitUtil;
import com.njcn.device.pms.mapper.majornetwork.*;
import com.njcn.device.pms.pojo.dto.PmsMonitorBaseDTO;
import com.njcn.device.pms.pojo.po.*;
import com.njcn.device.pms.service.ledgerManger.DeptLineService;
import com.njcn.device.pms.service.ledgerManger.CommTerminalService;
import com.njcn.redis.utils.RedisUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.enums.DicDataTypeEnum;
import com.njcn.system.pojo.po.DictData;
import com.njcn.user.api.DeptFeignClient;
import com.njcn.user.pojo.dto.DeptDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * pqs
 *
 * @author cdf
 * @date 2023/5/10
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class CommTerminalServiceImpl implements CommTerminalService {

    private final String commTerminal = "commTerminal#";

    private final DeptLineService deptLineService;

    private final DeptFeignClient deptFeignClient;

    private final MonitorMapper monitorMapper;

    private final StatationStatMapper statationStatMapper;

    private final PmsGeneratrixWireMapper pmsGeneratrixWireMapper;

    private final TerminalMapper terminalMapper;

    private final DistributionMonitorMapper distributionMonitorMapper;

    private final DicDataFeignClient dicDataFeignClient;

    private final RedisUtil redisUtil;

    private final OverlimitMapper overlimitMapper;

    private final PowerDistributionareaMapper powerDistributionareaMapper;

    private final PowerClientMapper powerClientMapper;

    private final PowerGenerationUserMapper powerGenerationUserMapper;


    /**
     * 基础获取单位信息
     *
     * @author cdf
     * @date 2023/5/10
     */
    @Override
    public List<DeptGetBase> getDeptChildrenByParent(DeptGetLineParam deptGetLineParam) {
        /*List<DeptGetBase> redisResult = (List<DeptGetBase>) redisUtil.getObjectByKey(commTerminal + deptGetLineParam.getDeptId());
        if (CollectionUtil.isNotEmpty(redisResult)) {
            return redisResult;
        }*/
        List<DeptGetBase> result = new ArrayList<>();
        List<DeptDTO> deptDTOList = deptFeignClient.getDeptDescendantIndexes(deptGetLineParam.getDeptId(), Stream.of(0, 1).collect(Collectors.toList())).getData();
        deptDTOList.forEach(it -> {
            DeptGetBase deptGetBase = new DeptGetBase();
            deptGetBase.setUnitId(it.getCode());
            deptGetBase.setUnitName(it.getName());
            List<String> deptChildren = deptDTOList.stream().filter(deptDTO -> deptDTO.getPids().contains(it.getId())).map(DeptDTO::getCode).collect(Collectors.toList());
            deptChildren.add(it.getCode());
            deptGetBase.setUnitChildrenList(deptChildren);
            deptGetBase.setDeptLevel(it.getPids().split(StrUtil.COMMA).length);
            result.add(deptGetBase);
        });
        //redisUtil.saveByKey(commTerminal + deptGetLineParam.getDeptId(),result);
        return result;
    }


    @Override
    public List<DeptGetChildrenMoreDTO> deptGetLine(DeptGetLineParam deptGetLineParam) {
        List<DeptGetChildrenMoreDTO> result = new ArrayList<>();
        List<DeptGetBase> temDept = getDeptChildrenByParent(deptGetLineParam);
        //电压等级
        List<DictData> voltageDic = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DEV_VOLTAGE.getCode()).getData();
        Map<String, DictData> mapVoltage = voltageDic.stream().collect(Collectors.toMap(DictData::getId, Function.identity()));
        //监测点状态
        DictData dictData = dicDataFeignClient.getDicDataByNameAndTypeName(DicDataTypeEnum.LINE_STATE.getName(), DicDataEnum.RUN.getName()).getData();
        List<Monitor> monitorList = monitorMapper.selectList(new LambdaQueryWrapper<Monitor>().eq(Monitor::getStatus, 1).eq(Monitor::getMonitorState, dictData.getId()));
        Map<String, List<Monitor>> map = monitorList.stream().collect(Collectors.groupingBy(Monitor::getOrgId));

        List<PmsMonitorBaseDTO> pmsMonitorBaseDTOList = distributionMonitorMapper.getDisMonitorAllList(null, 0);
        Map<String, List<PmsMonitorBaseDTO>> mapPms = pmsMonitorBaseDTOList.stream().collect(Collectors.groupingBy(PmsMonitorBaseDTO::getOrgId));

        temDept.forEach(item -> {
            DeptGetChildrenMoreDTO deptGetChildrenMoreDTO = new DeptGetChildrenMoreDTO();
            deptGetChildrenMoreDTO.setUnitId(item.getUnitId());
            deptGetChildrenMoreDTO.setUnitName(item.getUnitName());
            deptGetChildrenMoreDTO.setUnitChildrenList(item.getUnitChildrenList());
            List<String> deptIds = item.getUnitChildrenList();
            if (CollectionUtil.isNotEmpty(deptIds)) {
                List<LineDevGetDTO> lineList = new ArrayList<>();
                List<LineDevGetDTO> lineListPw = new ArrayList<>();
                deptIds.forEach(i -> {
                    if (map.containsKey(i)) {
                        map.get(i).forEach(it -> {
                            LineDevGetDTO lineDevGetDTO = new LineDevGetDTO();
                            lineDevGetDTO.setPointId(it.getId());
                            lineDevGetDTO.setInterval(it.getStatisticalInterval());
                            lineDevGetDTO.setDevId(it.getTerminalId());
                            lineDevGetDTO.setType(1);
                            lineDevGetDTO.setLineType(1);
                            lineDevGetDTO.setLineTag(it.getMonitorTag());
                            lineDevGetDTO.setVoltageLevel(mapVoltage.get(it.getVoltageLevel()).getValue());
                            lineList.add(lineDevGetDTO);
                        });
                    }
                    if (mapPms.containsKey(i)) {
                        mapPms.get(i).forEach(it -> {
                            LineDevGetDTO lineDevGetDTOPms = new LineDevGetDTO();
                            lineDevGetDTOPms.setPointId(it.getMonitorId());
                            lineDevGetDTOPms.setInterval(10);
                            lineDevGetDTOPms.setDevId(it.getTerminalId());
                            lineDevGetDTOPms.setType(1);
                            lineDevGetDTOPms.setLineType(it.getLineType());
                            lineDevGetDTOPms.setVoltageLevel(mapVoltage.get(it.getVoltageLevel()).getValue());
                            lineListPw.add(lineDevGetDTOPms);
                        });
                    }
                });
                deptGetChildrenMoreDTO.setLineBaseList(lineList);
                deptGetChildrenMoreDTO.setPwMonitorIds(lineListPw);
            }
            result.add(deptGetChildrenMoreDTO);
        });
        return result;
    }


    @Override
    public List<DeptGetSubStationDTO> deptSubStation(DeptGetLineParam deptGetLineParam) {
        List<DeptGetSubStationDTO> result = new ArrayList<>();
        List<DeptGetBase> temDept = getDeptChildrenByParent(deptGetLineParam);
        List<StatationStat> statationStatList = statationStatMapper.selectList(new LambdaQueryWrapper<StatationStat>().eq(StatationStat::getStatus, 1));
        Map<String, List<StatationStat>> map = statationStatList.stream().collect(Collectors.groupingBy(StatationStat::getOrgId));

        List<PmsMonitorBaseDTO> pmsMonitorBaseDTOList = distributionMonitorMapper.getDisMonitorAllList(null, 0);
        Map<String, List<PmsMonitorBaseDTO>> mapPms = pmsMonitorBaseDTOList.stream().collect(Collectors.groupingBy(PmsMonitorBaseDTO::getOrgId));


        temDept.forEach(item -> {
            DeptGetSubStationDTO deptGetSubStationDTO = new DeptGetSubStationDTO();
            deptGetSubStationDTO.setUnitId(item.getUnitId());
            deptGetSubStationDTO.setUnitName(item.getUnitName());
            deptGetSubStationDTO.setUnitChildrenList(item.getUnitChildrenList());
            List<String> deptIds = item.getUnitChildrenList();
            if (CollectionUtil.isNotEmpty(deptIds)) {
                List<String> lineList = new ArrayList<>();
                List<String> lineListPw = new ArrayList<>();
                deptIds.forEach(i -> {
                    if (map.containsKey(i)) {
                        lineList.addAll(map.get(i).stream().map(StatationStat::getPowerId).distinct().collect(Collectors.toList()));
                    }
                    if (mapPms.containsKey(i)) {
                        lineListPw.addAll(mapPms.get(i).stream().map(PmsMonitorBaseDTO::getPowerrId).distinct().collect(Collectors.toList()));
                    }
                });
                deptGetSubStationDTO.setStationIds(lineList.stream().distinct().collect(Collectors.toList()));
                deptGetSubStationDTO.setPwStationIds(lineListPw.stream().distinct().collect(Collectors.toList()));

            }
            result.add(deptGetSubStationDTO);
        });
        return result;
    }

    @Override
    public List<DeptGetBusBarDTO> deptBusBar(DeptGetLineParam deptGetLineParam) {
        List<DeptGetBusBarDTO> result = new ArrayList<>();
        List<DeptGetBase> temDept = getDeptChildrenByParent(deptGetLineParam);

        List<GeneratrixWire> generatrixWireList = pmsGeneratrixWireMapper.getGeneratrixWireList();
        Map<String, List<GeneratrixWire>> map = generatrixWireList.stream().collect(Collectors.groupingBy(GeneratrixWire::getOrgId));

        List<PmsMonitorBaseDTO> pmsMonitorBaseDTOList = distributionMonitorMapper.getDisMonitorAllList(null, 0);
        Map<String, List<PmsMonitorBaseDTO>> mapPms = pmsMonitorBaseDTOList.stream().collect(Collectors.groupingBy(PmsMonitorBaseDTO::getOrgId));


        temDept.forEach(item -> {
            DeptGetBusBarDTO deptGetBusBarDTO = new DeptGetBusBarDTO();
            deptGetBusBarDTO.setUnitId(item.getUnitId());
            deptGetBusBarDTO.setUnitName(item.getUnitName());
            deptGetBusBarDTO.setUnitChildrenList(item.getUnitChildrenList());
            List<String> deptIds = item.getUnitChildrenList();
            if (CollectionUtil.isNotEmpty(deptIds)) {
                List<String> lineList = new ArrayList<>();
                List<String> lineListPw = new ArrayList<>();
                deptIds.forEach(i -> {
                    if (map.containsKey(i)) {
                        lineList.addAll(map.get(i).stream().map(GeneratrixWire::getId).collect(Collectors.toList()));
                    }
                    if (mapPms.containsKey(i)) {
                        lineListPw.addAll(mapPms.get(i).stream().map(PmsMonitorBaseDTO::getLineId).collect(Collectors.toList()));
                    }
                });
                deptGetBusBarDTO.setBusBarIds(lineList);
                deptGetBusBarDTO.setPwBusBarIds(lineListPw);
            }
            result.add(deptGetBusBarDTO);
        });
        return result;
    }

    @Override
    public List<DeptGetDeviceDTO> deptGetDevice(DeptGetLineParam deptGetLineParam, Integer type) {
        List<DeptGetDeviceDTO> result = new ArrayList<>();
        List<DeptGetBase> temDept = getDeptChildrenByParent(deptGetLineParam);

        List<Monitor> monitorList = monitorMapper.selectList(new LambdaQueryWrapper<Monitor>().select(Monitor::getId, Monitor::getTerminalId, Monitor::getOrgId).eq(Monitor::getStatus, 1));
        List<String> terminalIds = monitorList.stream().map(Monitor::getTerminalId).distinct().collect(Collectors.toList());
        LambdaQueryWrapper<PmsTerminal> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.in(PmsTerminal::getId, terminalIds);
        List<PmsTerminal> pmsTerminals = terminalMapper.selectList(lambdaQueryWrapper);
        Map<String, List<PmsTerminal>> map = pmsTerminals.stream().collect(Collectors.groupingBy(PmsTerminal::getOrgId));

        List<PmsMonitorBaseDTO> pmsMonitorBaseDTOList = distributionMonitorMapper.getDisMonitorAllList(null, 0);
        List<String> pwTerminalIds = pmsMonitorBaseDTOList.stream().map(PmsMonitorBaseDTO::getTerminalId).distinct().collect(Collectors.toList());
        lambdaQueryWrapper.clear();
        lambdaQueryWrapper.in(PmsTerminal::getId, pwTerminalIds);
        List<PmsTerminal> pwPmsTerminals = terminalMapper.selectList(lambdaQueryWrapper);
        Map<String, List<PmsTerminal>> mapPms = pwPmsTerminals.stream().collect(Collectors.groupingBy(PmsTerminal::getOrgId));

        Map<String, List<Monitor>> monitorMap = new HashMap<>();
        Map<String, List<PmsMonitorBaseDTO>> pwMonitorMap = new HashMap<>();
        if (type == 1) {
            //获取装置接入的监测点
            monitorMap = monitorList.stream().collect(Collectors.groupingBy(Monitor::getTerminalId));
            pwMonitorMap = pmsMonitorBaseDTOList.stream().collect(Collectors.groupingBy(PmsMonitorBaseDTO::getTerminalId));


        }

        Map<String, List<Monitor>> finalMonitorMap = monitorMap;
        Map<String, List<PmsMonitorBaseDTO>> finalPwMonitorMap = pwMonitorMap;
        temDept.forEach(item -> {
            DeptGetDeviceDTO deptGetDeviceDTO = new DeptGetDeviceDTO();
            deptGetDeviceDTO.setUnitId(item.getUnitId());
            deptGetDeviceDTO.setUnitName(item.getUnitName());
            deptGetDeviceDTO.setUnitChildrenList(item.getUnitChildrenList());
            List<String> deptIds = item.getUnitChildrenList();
            if (CollectionUtil.isNotEmpty(deptIds)) {
                List<LineDevGetDTO> devGetDTOList = new ArrayList<>();
                List<LineDevGetDTO> devGetDTOListPw = new ArrayList<>();
                deptIds.forEach(i -> {
                    if (map.containsKey(i)) {
                        map.get(i).forEach(dev -> {
                            LineDevGetDTO lineDevGetDTO = new LineDevGetDTO();
                            lineDevGetDTO.setDevId(dev.getId());
                            lineDevGetDTO.setType(0);
                            lineDevGetDTO.setUpdateTime(dev.getUpdateTime());
                            if(type == 1) {
                                if (finalMonitorMap.containsKey(dev.getId())) {
                                    lineDevGetDTO.setMonitorIds(finalMonitorMap.get(dev.getId()).stream().map(Monitor::getId).distinct().collect(Collectors.toList()));
                                }
                            }
                            devGetDTOList.add(lineDevGetDTO);
                        });
                    }

                    if (mapPms.containsKey(i)) {
                        mapPms.get(i).forEach(dev -> {
                            LineDevGetDTO lineDevGetDTO = new LineDevGetDTO();
                            lineDevGetDTO.setDevId(dev.getId());
                            lineDevGetDTO.setType(1);
                            lineDevGetDTO.setUpdateTime(dev.getUpdateTime());
                            if(type == 1) {
                                if (finalPwMonitorMap.containsKey(dev.getId())) {
                                    lineDevGetDTO.setMonitorIds(finalMonitorMap.get(dev.getId()).stream().map(Monitor::getId).distinct().collect(Collectors.toList()));
                                }
                            }
                            devGetDTOListPw.add(lineDevGetDTO);
                        });
                    }
                });
                deptGetDeviceDTO.setDeviceList(devGetDTOList);
                deptGetDeviceDTO.setPwDeviceList(devGetDTOListPw);
            }
            result.add(deptGetDeviceDTO);
        });
        return result;
    }

    @Override
    public LineDevGetBandDTO substationGetLine(String substationId) {
        LineDevGetBandDTO result = new LineDevGetBandDTO();
        List<Monitor> monitorList = monitorMapper.selectList(new LambdaQueryWrapper<Monitor>().eq(Monitor::getStatus, 1).eq(Monitor::getPowerrId, substationId));
        List<PmsMonitorBaseDTO> pmsMonitorBaseDTOList = distributionMonitorMapper.getDisMonitorAllList(substationId, 1);
        assLineDev(result, monitorList, pmsMonitorBaseDTOList);
        return result;
    }

    @Override
    public LineDevGetBandDTO busBarGetLine(String busBarId) {
        LineDevGetBandDTO result = new LineDevGetBandDTO();
        List<PmsMonitorBaseDTO> pmsMonitorBaseDTOList = distributionMonitorMapper.getDisMonitorAllList(busBarId, 1);
        List<Monitor> monitorList = monitorMapper.selectList(new LambdaQueryWrapper<Monitor>().eq(Monitor::getStatus, 1).eq(Monitor::getLineId, busBarId));
        assLineDev(result, monitorList, pmsMonitorBaseDTOList);
        return result;
    }


    /**
     * 组装信息
     */
    private void assLineDev(LineDevGetBandDTO result, List<Monitor> monitorList, List<PmsMonitorBaseDTO> pmsMonitorBaseDTOList) {
        List<DictData> voltageDic = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DEV_VOLTAGE.getCode()).getData();
        Map<String, DictData> mapVoltage = voltageDic.stream().collect(Collectors.toMap(DictData::getId, Function.identity()));

        if (CollectionUtil.isNotEmpty(monitorList)) {
            List<LineDevGetDTO> temZw = new ArrayList<>();

            monitorList.forEach(item -> {
                LineDevGetDTO lineDevGetDTO = new LineDevGetDTO();
                lineDevGetDTO.setPointId(item.getId());
                lineDevGetDTO.setType(1);
                lineDevGetDTO.setDevId(item.getTerminalId());
                lineDevGetDTO.setVoltageLevel(mapVoltage.get(item.getVoltageLevel()).getValue());
                temZw.add(lineDevGetDTO);
            });
            result.setZwList(temZw);
        }

        if (CollectionUtil.isNotEmpty(pmsMonitorBaseDTOList)) {
            List<LineDevGetDTO> temPw = new ArrayList<>();
            pmsMonitorBaseDTOList.forEach(item -> {
                LineDevGetDTO lineDevGetDTO = new LineDevGetDTO();
                lineDevGetDTO.setPointId(item.getMonitorId());
                lineDevGetDTO.setType(1);
                lineDevGetDTO.setDevId(item.getTerminalId());
                lineDevGetDTO.setVoltageLevel(mapVoltage.get(item.getVoltageLevel()).getValue());
                temPw.add(lineDevGetDTO);
            });
            result.setPwList(temPw);
        }
    }










    /*-------------------------------------------------------------------------------------*/

    /**
     * @author cdf
     * @date 2023/5/10
     */
    @Override
    public List<DeptGetChildrenDTO> deptGetLineList(DeptGetLineParam deptGetLineParam) {
        List<DeptGetChildrenDTO> all = new ArrayList<>();
        List<DeptDTO> deptDTOList = deptFeignClient.getDeptDescendantIndexes(deptGetLineParam.getDeptId(), Stream.of(0, 1).collect(Collectors.toList())).getData();
        getAllChildren(deptGetLineParam.getDeptId(), deptDTOList, all);
        Map<String, List<String>> map = deptLineService.getLineByDeptRelation(filterDataType(deptGetLineParam.getServerName()));
        all.forEach(item -> {
            List<String> itemDeptChildren = item.getDeptChildren();
            if (CollectionUtil.isNotEmpty(itemDeptChildren)) {
                List<String> lineIds = new ArrayList<>();
                itemDeptChildren.forEach(i -> {
                    if (map.containsKey(i)) {
                        lineIds.addAll(map.get(i));
                    }
                });
                item.setLineIds(lineIds);
            }
        });
        return all;
    }

    /**
     * 筛选数据类型
     */
    private Integer filterDataType(String serverName) {
        ServerEnum serverEnum = EnumUtils.getServerEnumByName(serverName);
        switch (serverEnum) {
            case EVENT:
                return 0;
            case HARMONIC:
                return 1;
            default:
                throw new BusinessException(CommonResponseEnum.INVALID_PARAMETER);
        }

    }


    /**
     * 获取指定部门所有子孙部门id
     *
     * @author cdf
     * @date 2023/4/24
     */
    private void getAllChildren(String deptId, List<DeptDTO> deptAllList, List<DeptGetChildrenDTO> res) {
        deptAllList.stream().filter(item -> item.getPid().equals(deptId)).forEach(it -> {
            List<String> deptChildren = deptAllList.stream().filter(deptDTO -> deptDTO.getPids().contains(it.getId())).map(DeptDTO::getId).collect(Collectors.toList());
            deptChildren.add(it.getId());
            DeptGetChildrenDTO generalDeviceDTO = new DeptGetChildrenDTO();
            generalDeviceDTO.setDeptId(it.getId());
            generalDeviceDTO.setDeptName(it.getName());
            generalDeviceDTO.setDeptChildren(deptChildren);
            res.add(generalDeviceDTO);
            getAllChildren(it.getId(), deptAllList, res);
        });
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public String updatePmsOverLimit() {
        List<DictData> dictDataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.DEV_VOLTAGE.getCode()).getData();
        Map<String, DictData> map = dictDataList.stream().collect(Collectors.toMap(DictData::getId, Function.identity()));

        List<Monitor> monitorList = monitorMapper.selectList(new LambdaQueryWrapper<>());

        int count = 0;
        for (Monitor monitor : monitorList) {
            Float voltage = Float.parseFloat(map.get(monitor.getVoltageLevel()).getValue());
            Overlimit overlimit = COverlimitUtil.globalAssemble(voltage, monitor.getUserAgreementCapacity(), monitor.getPowerSupplyEqCapacity(), monitor.getMinShortCircuitCapacity(), 1, 0);
            overlimit.setId(monitor.getId());
            overlimitMapper.deleteById(monitor.getId());
            overlimitMapper.insert(overlimit);
            count++;

        }
        //二类监测点
        List<PowerDistributionarea> powerDistributionareaList = powerDistributionareaMapper.selectList(new LambdaQueryWrapper<>());
        int countArea = 0;
        for (PowerDistributionarea powerDistributionarea : powerDistributionareaList) {
            Float voltage = Float.parseFloat(map.get(powerDistributionarea.getVoltageLevel()).getValue());
            Overlimit overlimit = COverlimitUtil.globalAssemble(voltage, null, null, null, 1, 1);
            overlimit.setId(powerDistributionarea.getId());
            overlimitMapper.deleteById(powerDistributionarea.getId());
            overlimitMapper.insert(overlimit);
            countArea++;
        }
        //三类监测
        List<PowerClient> powerClientList = powerClientMapper.selectList(new LambdaQueryWrapper<>());
        int countClient = 0;
        for (PowerClient powerClient : powerClientList) {
            Float voltage = Float.parseFloat(map.get(powerClient.getVoltageLevel()).getValue());
            Overlimit overlimit = COverlimitUtil.globalAssemble(voltage, null, null, null, 1, 1);
            overlimit.setId(powerClient.getId());
            overlimitMapper.deleteById(powerClient.getId());
            overlimitMapper.insert(overlimit);
            countClient++;
        }

        List<PowerGenerationUser> powerGenerationUserList = powerGenerationUserMapper.selectList(new LambdaQueryWrapper<>());

        for (PowerGenerationUser powerGenerationUser : powerGenerationUserList) {
            Float voltage = Float.parseFloat(map.get(powerGenerationUser.getVoltageLevel()).getValue());
            Overlimit overlimit = COverlimitUtil.globalAssemble(voltage, null, null, null, 1, 1);
            overlimit.setId(powerGenerationUser.getId());
            overlimitMapper.deleteById(powerGenerationUser.getId());
            overlimitMapper.insert(overlimit);
            countClient++;
        }
        return "主网监测点限值更新" + count + "个,台区限值更新" + countArea + "个,发电用电用户" + countClient + "个";
    }

}
