whyclxw
2025-05-28 e16302f9d475c7cc4dd18c5abf1a23cb5502e362
src/main/java/com/whyc/service/Fbs9100StateService.java
@@ -6,6 +6,7 @@
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.constant.DeviceConstant;
import com.whyc.constant.YamlProperties;
import com.whyc.dto.BattTestData;
import com.whyc.dto.Response;
import com.whyc.dto.paramter.FbsStatePar;
@@ -54,7 +55,7 @@
        Fbs9100State fbs9100State = mapper.selectOne(wrapper);
        if (fbs9100State != null) {
            fbs9100State.setNote(new SimpleDateFormat(ActionUtil.time_yyyyMMddHHmmss).format(new Date()));
            if((devId / 10000 == 6183)||(devId / 10000 == 6184)){
            if((devId / 100000 == 6183)||(devId / 100000 == 6184)){
                fbs9100State.setDevLastCaptestStopTypeReason(BattTestData.getStopType_6183_4(fbs9100State.getDevLastCaptestStopType()));
            }else{
                fbs9100State.setDevLastCaptestStopTypeReason(BattTestData.getStopType_9612(fbs9100State.getDevLastCaptestStopType()));
@@ -224,6 +225,11 @@
     * 这个是按照设备ip来统计的.
     * 通讯故障>核容放电>充电>内阻>浮充,
     * 如果一拖二的设备,有两个不同状态,实现状态优先级覆盖
     *
     * 设备的数量统计和设备状态的统计,逻辑是不同的,数据库筛选的时候条件逻辑必定是不同的: TODO
     *  通常情况下,设备数量统计,要排除掉一个设备两个id的一拖二情况;
     *  而设备状态统计,只需要区分一个设备的字段,一个设备有多条记录也是正常合理的,通过状态优先级覆盖来定义整个设备的状态
     *
     * @param userId
     * @param type 1-太原排除蓄电池设备一拖二的第二组状态统计
     * @param type 2-统计所有设备ip的状态
@@ -234,21 +240,38 @@
        Response response = new Response();
        try {
            Map<String, Integer> resultMap = new HashMap<>();
            resultMap.put("在线浮充数量", 0);
            resultMap.put("直连充电数量", 0);
            resultMap.put("预充电数量", 0);
            resultMap.put("核容测试数量", 0);
            resultMap.put("内阻测试数量", 0);
            resultMap.put("通讯故障数量", 0);
            List<Fbs9100State> fbs9100StateList = mapper.getListWithoutZJDYBTSE2(userId,type);
            Map<String, List<Fbs9100State>> deviceMap = fbs9100StateList.stream().collect(Collectors.groupingBy(Fbs9100State::getDevIp));
            //上面的分组字段 只要能区分 不同的设备就行了. 因为如果是一拖二的情况,也可通过后面的状态优先级来覆盖,设备不会重复
            //太供可以通过ip来确定是哪台设备
            Map<String, List<Fbs9100State>> deviceMap = null;
            if(YamlProperties.systemSubType == 3){ //晋源 - 因为所有设备共用一个ip, 所以需要加上devId
                deviceMap = fbs9100StateList.stream().collect(Collectors.groupingBy(state ->  String.format("%s_%s",state.getDevIp(), state.getDevId())));
            }else{ //默认通用
                deviceMap = fbs9100StateList.stream().collect(Collectors.groupingBy(state -> String.valueOf(state.getDevIp())));
            }
            //Map<String, List<Fbs9100State>> deviceMap = fbs9100StateList.stream().collect(Collectors.groupingBy(state ->
            //        String.format("%s_%s",state.getDevIp(), state.getDevId())));
            Set<String> deviceSet = deviceMap.keySet();
            Calendar instance = Calendar.getInstance();
            instance.add(Calendar.MINUTE, -1);
            Date time = instance.getTime();
            //这个遍历里面,是按照groupingBy(字段)来进行分组的,可以存在一个设备多个记录,即出现一拖二的情况. 这个时候按照优先级进行覆盖来定义整个设备的状态
            //上面的分组字段 只要能区分 不同的设备就行了. 因为如果是一拖二的情况,也可通过状态优先级来覆盖
            for (String deviceIp : deviceSet) {
                List<Fbs9100State> fbs9100States = deviceMap.get(deviceIp);
                List<Integer> workStateList = fbs9100States.stream().map(Fbs9100State::getDevWorkstate).collect(Collectors.toList());
                //存在6186设备,这个设备的设备状态值采用的是devAlarmState,所以需要单独处理
                List<Integer> workStateList;
                if(fbs9100States.get(0).getDevId().toString().startsWith("6186")){
                    workStateList = fbs9100States.stream().map(Fbs9100State::getDevAlarmstate).collect(Collectors.toList());
                }else {
                    workStateList = fbs9100States.stream().map(Fbs9100State::getDevWorkstate).collect(Collectors.toList());
                }
                Map<Integer, List<Integer>> workStateMap = workStateList.stream().collect(Collectors.groupingBy(Integer::intValue));
                Set<Integer> workStateSet = workStateMap.keySet();
                boolean commError = false;
@@ -272,7 +295,7 @@
                        resultMap.put("内阻测试数量", resultMap.get("内阻测试数量") + 1);
                    }
                    else if(workStateSet.contains(DeviceConstant.DEV_ONLINE_CHARGE)) {
                        resultMap.put("在线浮充数量", resultMap.get("在线浮充数量") + 1);
                        resultMap.put("直连充电数量", resultMap.get("直连充电数量") + 1);
                    }
                }
@@ -315,7 +338,7 @@
        Response response = new Response();
        try {
            Map<String, Integer> resultMap = new HashMap<>();
            resultMap.put("在线浮充数量", 0);
            resultMap.put("直连充电数量", 0);
            resultMap.put("预充电数量", 0);
            resultMap.put("核容测试数量", 0);
            resultMap.put("内阻测试数量", 0);
@@ -323,14 +346,22 @@
            List<Fbs9100State> fbs9100StateList = mapper.getListWithoutZJDYBTSE2JY(type);
            Map<String, List<Fbs9100State>> deviceMap = fbs9100StateList.stream().collect(Collectors.groupingBy(Fbs9100State::getDevIp));
            //Map<String, List<Fbs9100State>> deviceMap = fbs9100StateList.stream().collect(Collectors.groupingBy(Fbs9100State::getDevIp));
            //JY的设备,ip都一样,所以区分不同的设备,需要通过ip+id
            Map<String, List<Fbs9100State>> deviceMap = fbs9100StateList.stream().collect(Collectors.groupingBy(state ->String.format("%s_%s",state.getDevIp(), state.getDevId())));
            Set<String> deviceSet = deviceMap.keySet();
            Calendar instance = Calendar.getInstance();
            instance.add(Calendar.MINUTE, -1);
            Date time = instance.getTime();
            for (String deviceIp : deviceSet) {
                List<Fbs9100State> fbs9100States = deviceMap.get(deviceIp);
                List<Integer> workStateList = fbs9100States.stream().map(Fbs9100State::getDevWorkstate).collect(Collectors.toList());
                //存在6186设备,这个设备的设备状态值采用的是devAlarmState,所以需要单独处理
                List<Integer> workStateList;
                if(fbs9100States.get(0).getDevId().toString().startsWith("6186")){
                    workStateList = fbs9100States.stream().map(Fbs9100State::getDevAlarmstate).collect(Collectors.toList());
                }else {
                    workStateList = fbs9100States.stream().map(Fbs9100State::getDevWorkstate).collect(Collectors.toList());
                }
                Map<Integer, List<Integer>> workStateMap = workStateList.stream().collect(Collectors.groupingBy(Integer::intValue));
                Set<Integer> workStateSet = workStateMap.keySet();
                boolean commError = false;
@@ -354,7 +385,7 @@
                        resultMap.put("内阻测试数量", resultMap.get("内阻测试数量") + 1);
                    }
                    else if(workStateSet.contains(DeviceConstant.DEV_ONLINE_CHARGE)) {
                        resultMap.put("在线浮充数量", resultMap.get("在线浮充数量") + 1);
                        resultMap.put("直连充电数量", resultMap.get("直连充电数量") + 1);
                    }
                }