whyclxw
2025-05-28 e16302f9d475c7cc4dd18c5abf1a23cb5502e362
src/main/java/com/whyc/service/BattInfService.java
@@ -59,6 +59,9 @@
    @Autowired(required = false)
    private BaoJiGroupBattGroupMapper bjBattMapper;
    @Autowired(required = false)
    private DevalarmDataMapper devAlmMapper;
    public int searchMaxBattgroupId_zj() {
        Integer id = battInfMapper.getMaxBattGroupId_zj();
        if (id == null) {
@@ -167,6 +170,11 @@
    public Response searchStationNameInGroup(Integer uId,String stationName1){
        List<String> list = battInfMapper.getStationNameInGroup(uId,stationName1);
        return new Response().set(1,list,"查询成功");
    }
    public Response searchStationNameInGroup2(Integer uId,String stationName1){
        List<Battinf> list = battInfMapper.getStationNameInGroup2(uId,stationName1);
        return new Response().set(1,list,"查询成功");
    }
@@ -392,7 +400,7 @@
    public List<Battinf> getBattGroupInfoByFBSDeviceId(int fbsDeviceId) {
        QueryWrapper<Battinf> queryWrapper = Wrappers.query();
        queryWrapper.select("BattGroupId","BattGroupName").eq("FBSDeviceId",fbsDeviceId);
        queryWrapper.select("BattGroupId","stationName1","stationName2","stationName3","stationName4","stationName5","BattGroupName","GroupIndexInFBSDevice","MonVolStd","MonCapStd","MonResStd","MonSerStd","MonTmpStd").eq("FBSDeviceId",fbsDeviceId);
        return battInfMapper.selectList(queryWrapper);
    }
@@ -484,7 +492,7 @@
    public String serchExcelName(int battGroupId) {
        Battinf binf = battInfMapper.serchExcelName(battGroupId);
        //String excelName = binf.getStationName1() + "-" + binf.getStationName2() + "-" + binf.getStationName5() + "-" + binf.getStationName3() + "-" + ActionUtil.sdfwithOutday.format(binf.getBattProductDate()).replace("_", "-") + "-" + (int) ((float) binf.getMonCapStd()) + "AH" + "-" + binf.getBattGroupName();
        String excelName = binf.getStationName1() + "-" + binf.getStationName2() + "-" + binf.getStationName5() + "-" + binf.getStationName3()
        String excelName = binf.getStationName1() + "-" + binf.getStationName2() + "-" + binf.getStationName5() + "-" + binf.getStationName3()+ "-" + binf.getStationName4()
                + "-" + ThreadLocalUtil.format(binf.getBattProductDate(),2).replace("_", "-") + "-" + (int) ((float) binf.getMonCapStd()) + "AH" + "-" + binf.getBattGroupName();
        return excelName;
    }
@@ -493,7 +501,7 @@
    public String serchExcelNameA059(int battGroupId, String stateFlag) {
        Battinf binf = battInfMapper.serchExcelName(battGroupId);
        //导出格式:内蒙古自治区-鄂尔多斯市-东胜区-中心局-理士400AH1组-2022-04-21-第1次放电
        String excelName = binf.getStationName1() + "-" + binf.getStationName2() + "-" + binf.getStationName5() + "-" + binf.getStationName3() + "-" +
        String excelName = binf.getStationName1() + "-" + binf.getStationName2() + "-" + binf.getStationName5() + "-" + binf.getStationName3() + "-" + binf.getStationName4() + "-" +
                binf.getBattProducer() + binf.getMonCapStd() + "AH" + (binf.getGroupIndexInFBSDevice() + 1) + "组" + "-" + stateFlag;
        return excelName;
    }
@@ -607,7 +615,7 @@
    public Battinf getBattGroupInfoByBattGroupId(int battGroupId) {
        QueryWrapper<Battinf> queryWrapper = Wrappers.query();
        queryWrapper.select("MonVolStd", "MonCount", "cellShowType","NomCapWH","NomCapAH").eq("BattGroupId", battGroupId);
        queryWrapper.select("MonVolStd", "MonCount", "cellShowType","NomCapWH","NomCapAH","acdc_secuity_flag","Load_curr").eq("BattGroupId", battGroupId);
        return battInfMapper.selectOne(queryWrapper);
    }
@@ -622,6 +630,10 @@
    /**
     * 获取电池,设备,电源,机房站点 计数/管理元首页:基础资源信息
     *
     * 设备的数量统计和设备状态的统计,逻辑是不同的,数据库筛选的时候条件逻辑必定是不同的: TODO
     *  通常情况下,设备数量统计,要排除掉一个设备两个id的一拖二情况;
     *  而设备状态统计,只需要区分一个设备的字段,一个设备有多条记录也是正常合理的,通过状态优先级覆盖来定义整个设备的状态
     *
     * @param userId
     * @return
@@ -647,8 +659,59 @@
        }
    }
    public Response getDevCountMapForSZ(int userId) {
        try {
            Map<String, Object> map = new HashMap<>();
            int battGroupCount = battInfMapper.getBattGroupNum(userId);
            //电池单体总数
            int battGroupMonCount = battInfMapper.getBattGroupMonNum(userId);
            int devCount = battInfMapper.getDevNum(userId);
            int powerNum = powerInfService.getNum(userId);
            List<StationInf> stationInfList = stationInfService.getStationInfList(userId);
            int stationNum = stationInfService.getStation(userId);
            int hrDisNum = testInfService.getHrQuarterZC(userId);
            map.put("battGroupCount", battGroupCount);
            map.put("battGroupMonCount", battGroupMonCount);
            map.put("devCount", devCount);
            map.put("powerNum", powerNum);
            map.put("stationNum",stationNum);
            map.put("stationInfList",stationInfList);
            map.put("checkCapNum",hrDisNum);
            return new Response().setII(1,true, map,"");
        }catch (Exception e){
            return new Response<>().set(1,false,"发生异常:"+e.getCause());
        }
    }
    //山西晋源特定接口
    public Response getDevCountMapJY() {
        try {
            Map<String, Object> map = new HashMap<>();
            int battGroupCount = battInfMapper.getBattGroupNumJY();
            int devCount = battInfMapper.getDevNumJY();
            int powerNum = powerInfService.getNumJY();
            List<StationInf> stationInfList = stationInfService.getStationInfListJY();
            int stationNum = stationInfService.getStationJY();
            int hrDisNum = testInfService.getHrQuarterZCJY();
            map.put("battGroupCount", battGroupCount);
            map.put("devCount", devCount);
            map.put("powerNum", powerNum);
            map.put("stationNum",stationNum);
            map.put("stationInfList",stationInfList);
            map.put("checkCapNum",hrDisNum);
            return new Response().setII(1,true, map,"");
        }catch (Exception e){
            return new Response<>().set(1,false,"发生异常:"+e.getCause());
        }
    }
    //大屏
    public List<Battinf> getBattGroupList(int userId) {
        return battInfMapper.getBattGroupList(userId);
    }
    //山西晋源特定接口
    public List<Battinf> getBattGroupListJY() {
        return battInfMapper.getBattGroupListJY();
    }
    //管理员首页:基础资源信息
@@ -867,4 +930,119 @@
        query.eq("StationId",stationId);
        return battInfMapper.selectList(query);
    }
    //取第一组电池信息
    public Response getPowerHr6159(int devId) {
        QueryWrapper<Battinf> query = Wrappers.query();
        query.eq("FBSDeviceId",devId).last(" limit 1").orderByAsc("battGroupId");
        Battinf binf=battInfMapper.selectOne(query);
        return new Response().setII(1,binf!=null,binf,"取第一组电池信息");
    }
   //keyid绑定设备id
    public Response setKeyIdWithDeviceId(Integer devId, String keyId) {
        //1.检测是否存在keyid的设备
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("KeyID",keyId);
        wrapper.last(" limit 1");
        Battinf binf=battInfMapper.selectOne(wrapper);
        int flag=0;
        if(binf!=null){
            //查询devId对应设备的ip
            QueryWrapper wrapper1=new QueryWrapper();
            wrapper1.eq("FBSDeviceId",devId);
            wrapper1.last(" limit 1");
            Battinf binf1=battInfMapper.selectOne(wrapper1);
            if(binf.getFBSDeviceIp().equals(binf1.getFBSDeviceIp())){
                flag=1;
            }else{
                flag=0;
            }
        }else{
            flag=1;
        }
        if(flag==1){
            UpdateWrapper updateWrapper=new UpdateWrapper();
            updateWrapper.set("KeyID",keyId);
            updateWrapper.eq("FBSDeviceId",devId);
            battInfMapper.update((Battinf) ActionUtil.objeNull,updateWrapper);
            return new Response().set(1,true,"keyid绑定设备id");
        }else {
            return new Response().set(1,false,"改ukey已绑定");
        }
    }
    //插入初始数据
    public void setDefalut( Map<String,Object> map){
        Map<String,Object> mapNum=new HashMap<>();
        mapNum.put("stionNum",0);
        mapNum.put("devNum",0);
        mapNum.put("battNum",0);
        map.put("3",mapNum);
        map.put("5",mapNum);
        map.put("6",mapNum);
        map.put("7",mapNum);
        map.put("8",mapNum);
    }
    //1统计机房个数,设备个数,电池组个数(苏州地铁)
    public Response getAllInfInSz2(Integer userId) {
        Map<String,Object> map=new HashMap<>();
        //setDefalut(map);
        Map<String,Object> allmap=new HashMap<>();
        int stionNum=0;
        int devNum=0;
        int battNum=0;
        try {
            //查询battinf表中所有电池组信息
            List<Battinf> list=battInfMapper.getAllInfInSz2(userId);
            Map<String, List<Battinf>> ListMap = list.stream().collect(Collectors.groupingBy(Battinf::getStationName9));
            for (String stationName9 : ListMap.keySet()) {
                Map<String, Object> battInfoMap = new HashMap<>();
                battInfoMap.put("stionNum",0);
                battInfoMap.put("devNum",0);
                battInfoMap.put("battNum",0);
                List<Battinf> name9List=ListMap.get(stationName9);
                Map<String, List<Battinf>> stationMap = name9List.stream().collect(Collectors.groupingBy(Battinf::getStationId));
                battInfoMap.put("stionNum",stationMap.size());
                stionNum+=stationMap.size();
                Map<Long, List<Battinf>> devMap = name9List.stream().collect(Collectors.groupingBy(Battinf::getFBSDeviceId));
                battInfoMap.put("devNum",devMap.size());
                devNum+=devMap.size();
                Map<Integer, List<Battinf>> battMap = name9List.stream().collect(Collectors.groupingBy(Battinf::getBattGroupId));
                battInfoMap.put("battNum",battMap.size());
                map.put(stationName9,battInfoMap);
                battNum+=battMap.size();
            }
            allmap.put("stionNum",stionNum);
            allmap.put("devNum",devNum);
            allmap.put("battNum",battNum);
            map.put("allmap",allmap);
            return new Response<>().setII(1,true,map,"");
        } catch (Exception e) {
            return new Response<>().set(1,false,"");
        }
    }
    //4.中间地图
    public Response getAllStationInSz2(Integer userId) {
        Map<String,Object> map=new HashMap<>();
        try {
            //查询battinf表中所有机房信息
            List<Battinf> list=battInfMapper.getAllStationInSz2(userId);
            Map<String, List<Battinf>> ListMap = list.stream().collect(Collectors.groupingBy(Battinf::getStationName9));
            for (String stationName9 : ListMap.keySet())  {
                List<Battinf> name9List=ListMap.get(stationName9);
                for (Battinf binf:name9List) {
                    //判断机房下的设备告警是否都存在通讯告警 119020
                    int flag=devAlmMapper.judgeCommErr(binf.getStationId(),119020);
                    if(flag>0){
                        binf.setNote("0");
                    }else{
                        binf.setNote("1");
                    }
                }
                map.put(stationName9,name9List);
            }
            return new Response<>().setII(1,true,map,"");
        } catch (Exception e) {
            return new Response<>().set(1,false,"");
        }
    }
}