21个文件已修改
4个文件已添加
671 ■■■■■ 已修改文件
src/main/java/com/whyc/controller/AlmParamController.java 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/dto/Param/AlmAnalyseDto.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/BaojigroupPowerMapper.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/BattalarmDataMapper.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/BatttestdataInfMapper.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/DevalarmDataMapper.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/DeviceStateMapper.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/PwrdevAlarmMapper.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/db_user/BaojigroupPower.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/BaoJiGroupPowerService.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/BattRealdataIdService.java 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/BattalarmDataService.java 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/BatttestdataInfService.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/DevalarmDataService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/DeviceStateService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/LeaderHomeService.java 94 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/MonitorService.java 230 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/PwrdevAlarmService.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/webSocket/MonitorSocket.java 75 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/BaojigroupPowerMapper.xml 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/BattalarmDataMapper.xml 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/BatttestdataInfMapper.xml 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/DevalarmDataMapper.xml 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/DeviceStateMapper.xml 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/PwrdevAlarmMapper.xml 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/AlmParamController.java
@@ -2,6 +2,7 @@
import com.whyc.constant.*;
import com.whyc.dto.AlarmParam;
import com.whyc.dto.Param.AlmAnalyseDto;
import com.whyc.dto.Param.ParamAlmDto;
import com.whyc.dto.Real.AlmDto;
import com.whyc.dto.Response;
@@ -9,16 +10,16 @@
import com.whyc.pojo.db_param.BattAlmparam;
import com.whyc.pojo.db_param.DevAlmparam;
import com.whyc.pojo.db_pwrdev_alarm.PwrdevAlarmParam;
import com.whyc.service.BattAlmparamService;
import com.whyc.service.DevAlmparamService;
import com.whyc.service.PwrdevAlarmParamService;
import com.whyc.service.*;
import com.whyc.util.ActionUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@RestController
@@ -33,6 +34,12 @@
    @Autowired
    private PwrdevAlarmParamService pwrAlmparamService;
    @Autowired
    private BattalarmDataService battalarmDataService;
    @Autowired
    private BattRealdataIdService battRealdataIdService;
    /*@PostMapping("getBattAlmParam")
@@ -111,4 +118,18 @@
        return new Response<List<AlarmParam>>().set(1,list);
    }
    @PostMapping("getBattAlmAnalyse")
    @ApiOperation("预警分析管理-电池告警")
    public Response getBattAlmAnalyse(@RequestBody AlmAnalyseDto dto){
        Integer uid=ActionUtil.getUser().getId();
        dto.setUid(uid);
        return battalarmDataService.getBattAlmAnalyse(dto);
    }
    @GetMapping("getBattHisRealInAlm")
    @ApiOperation("电池告警点击具体告警信息查看从告警开始时间到现在的历史实时数据")
    public Response getBattHisRealInAlm(@RequestParam Integer battgroupId,@RequestParam String startTime,@RequestParam(required = false) Integer monNum) throws ParseException, InterruptedException {
        return battRealdataIdService.getBattHisRealInAlm(battgroupId,startTime,monNum);
    }
}
src/main/java/com/whyc/dto/Param/AlmAnalyseDto.java
New file
@@ -0,0 +1,20 @@
package com.whyc.dto.Param;
import lombok.Data;
import java.util.List;
@Data
public class AlmAnalyseDto {
    private String provice;
    private String city;
    private String country;
    private Integer stationId;
    private Integer powerId;
    private Integer battgroupId;
    private List<Integer> almIdList;
    private Integer uid;
    private Integer pageNum;
    private Integer pageSize;
    private Integer almLevel;
}
src/main/java/com/whyc/mapper/BaojigroupPowerMapper.java
@@ -20,4 +20,7 @@
    List<PowerInf> getPowerList(@Param("id") int id);
    //查询其他的组,包含的所有站点
    List<BaojigroupPower> getStationIdListWithDischargePlanFlag();
    List<BaojigroupPower> getListByUserId(Integer userId);
}
src/main/java/com/whyc/mapper/BattalarmDataMapper.java
@@ -1,6 +1,7 @@
package com.whyc.mapper;
import com.whyc.dto.AlarmDto;
import com.whyc.dto.Param.AlmAnalyseDto;
import com.whyc.dto.Real.AlmDto;
import com.whyc.pojo.db_alarm.BattalarmData;
import com.whyc.pojo.web_site.AlarmInspection;
@@ -13,6 +14,11 @@
    List<AlarmInspection> getListGreatThan(Long battAlarmId);
    List<AlarmDto> getListByUserId(Integer userId);
    List<AlarmDto> getListByUserId(Integer userId, Integer almLevel);
    List<BattalarmData> getMonAlarm(Integer userId);
    List<AlarmDto> getListByUserId(Integer userId);
    //预警分析管理
    List<BattalarmData> getBattAlmAnalyse(AlmAnalyseDto dto);
}
src/main/java/com/whyc/mapper/BatttestdataInfMapper.java
@@ -16,4 +16,5 @@
    List<BatttestdataInf> getListByUserId(Integer userId);
    int getHrDisCount(Integer userId, Date startTime, Date endTime);
}
src/main/java/com/whyc/mapper/DevalarmDataMapper.java
@@ -2,7 +2,6 @@
import com.whyc.dto.AlarmDto;
import com.whyc.dto.Real.AlmDto;
import com.whyc.pojo.db_alarm.BattalarmData;
import com.whyc.pojo.db_alarm.DevalarmData;
import com.whyc.pojo.web_site.AlarmInspection;
@@ -14,6 +13,6 @@
    List<AlarmInspection> getListGreatThan(Long devAlarmId);
    List<AlarmDto> getListByUserId(Integer userId);
    List<AlarmDto> getListByUserId(Integer userId, Integer almLevel);
}
src/main/java/com/whyc/mapper/DeviceStateMapper.java
@@ -9,4 +9,7 @@
public interface DeviceStateMapper extends CustomMapper<DeviceState>{
    //设备工作状态统计
    List<DeviceState> getDeviceStateStatistic(@Param("stic") DeviceStateStic stic);
    List<DeviceState> getListByUserId(Integer userId);
}
src/main/java/com/whyc/mapper/PwrdevAlarmMapper.java
@@ -13,6 +13,6 @@
    List<AlarmInspection> getListGreatThan(Long id);
    List<AlarmDto> getListByUserId(Integer userId);
    List<AlarmDto> getListByUserId(Integer userId, Integer alarmLevel);
}
src/main/java/com/whyc/pojo/db_user/BaojigroupPower.java
@@ -52,5 +52,8 @@
    @TableField(exist = false)
    private String powerName;
    @TableField(exist = false)
    private String baoJiGroupName;
}
src/main/java/com/whyc/service/BaoJiGroupPowerService.java
New file
@@ -0,0 +1,20 @@
package com.whyc.service;
import com.whyc.mapper.BaojigroupPowerMapper;
import com.whyc.pojo.db_user.BaojigroupPower;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class BaoJiGroupPowerService {
    @Autowired
    private BaojigroupPowerMapper mapper;
    public List<BaojigroupPower> getListByUserId(Integer userId) {
        return mapper.getListByUserId(userId);
    }
}
src/main/java/com/whyc/service/BattRealdataIdService.java
@@ -217,6 +217,44 @@
        latch.await(10, TimeUnit.MINUTES);
        List dataListSorted = dataList.stream().sorted(Comparator.comparing(RealDateDTO::getRecordTime)).collect(Collectors.toList());
        return new Response().set(1, dataListSorted);
    }
    //电池告警点击具体告警信息查看从告警开始时间到现在的历史实时数据
    public Response getBattHisRealInAlm(Integer battgroupId, String startTime, Integer monNum) throws ParseException, InterruptedException {
        List<RealDateDTO> dataList = new LinkedList<>();
        List<List<Date>> monthTimeList = DateUtil.getMonthTime(ThreadLocalUtil.parse(startTime,1),new Date());
        ThreadPoolExecutor pool = ThreadPoolExecutorFactory.getPoolExecutor();
        CountDownLatch latch = new CountDownLatch(monthTimeList.size());
        for (int i = 0; i < monthTimeList.size(); i++) {
            int finalI = i;
            pool.execute(() -> {
                int finalII = finalI;
                BattRealdataId realdata = new BattRealdataId();
                realdata.setRecordTime(monthTimeList.get(finalII).get(0));
                realdata.setRecordTime1(monthTimeList.get(finalII).get(1));
                String table = battgroupId + "_" + ThreadLocalUtil.format(realdata.getRecordTime(),2);
                realdata.setTableName(table);//表名时间格式部分
                //判断表是否存在
                int tableNum = subTablePageInfoService.judgeTable_realdata(table);
                List<RealDateDTO> list = new ArrayList();
                if (tableNum > 0) {
                    //获取指定时间段内最大最小recordNum确保数据的完整
                    List recordNums= subTablePageInfoService.getMaxAndMinRecordNum(realdata);
                    Integer maxRecordNum= 0;
                    Integer minRecordNum= 0;
                    if(recordNums.size()>0){
                        maxRecordNum=(Integer)recordNums.get(0);
                        minRecordNum=(Integer)recordNums.get(1);
                    }
                    list = subTablePageInfoService.getBattRealDataHis(realdata,1,maxRecordNum,minRecordNum);
                }
                dataList.addAll(list);
                latch.countDown();
            });
            sleep(200);
        }
        latch.await(10, TimeUnit.MINUTES);
        List dataListSorted = dataList.stream().sorted(Comparator.comparing(RealDateDTO::getRecordTime)).collect(Collectors.toList());
        return new Response().set(1, dataListSorted);
    }
}
src/main/java/com/whyc/service/BattalarmDataService.java
@@ -7,8 +7,8 @@
import com.github.pagehelper.PageInfo;
import com.whyc.constant.BattAlarmIdEnum;
import com.whyc.constant.BattSingalIdEnum;
import com.whyc.constant.DevAlarmEnum;
import com.whyc.dto.AlarmDto;
import com.whyc.dto.Param.AlmAnalyseDto;
import com.whyc.dto.Real.AlmDto;
import com.whyc.dto.Response;
import com.whyc.mapper.BattalarmDataMapper;
@@ -74,8 +74,8 @@
        return listGreatThan;
    }
    public List<AlarmDto> getListByUserId(Integer userId) {
        return mapper.getListByUserId(userId);
    public List<AlarmDto> getListByUserId(Integer userId, Integer almLevel) {
        return mapper.getListByUserId(userId,almLevel);
    }
    public List<Long> getNumListInDB(List<Long> battAlarmNumList) {
@@ -84,4 +84,18 @@
        query.in("num",battAlarmNumList);
        return mapper.selectList(query).stream().map(BattalarmData::getNum).collect(Collectors.toList());
    }
    public List<BattalarmData> getMonAlarm(Integer userId) {
        return mapper.getMonAlarm(userId);
    }
    //预警分析管理
    public Response getBattAlmAnalyse(AlmAnalyseDto dto) {
        PageHelper .startPage(dto.getPageNum(),dto.getPageSize());
        List<BattalarmData> list=mapper.getBattAlmAnalyse(dto);
        list.forEach(data->{
            data.setAlmName(BattSingalIdEnum.getValue(data.getAlmSignalId()));
        });
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list!=null,pageInfo,"电池告警分析");
    }
}
src/main/java/com/whyc/service/BatttestdataInfService.java
@@ -591,7 +591,7 @@
            }
            //找这次放电的指定一笔数据
            List<BatttestdataId> idDataList=battTestdataIdService.getLastDataByBattgroupId(tinf.getBattgroupId(),tinf.getTestRecordCount(),1);
            if(idDataList!=null&&idDataList.size()>=0){
            if(idDataList!=null&&idDataList.size()>0){
                BatttestdataId idData=idDataList.get(0);
                dto.setOnlineVol(idData.getOnlineVol());
                dto.setGroupCurr(idData.getTestCurr());
@@ -976,4 +976,8 @@
    public List<BatttestdataInf> getListByUserId(Integer userId) {
        return mapper.getListByUserId(userId);
    }
    public int getHrDisCount(Integer userId, Date startTime, Date endTime) {
        return mapper.getHrDisCount(userId, startTime, endTime);
    }
}
src/main/java/com/whyc/service/DevalarmDataService.java
@@ -81,7 +81,7 @@
        return mapper.selectList(query).stream().map(DevalarmData::getNum).collect(Collectors.toList());
    }
    public List<AlarmDto> getListByUserId(Integer userId) {
        return mapper.getListByUserId(userId);
    public List<AlarmDto> getListByUserId(Integer userId,Integer almLevel) {
        return mapper.getListByUserId(userId,almLevel);
    }
}
src/main/java/com/whyc/service/DeviceStateService.java
@@ -38,4 +38,8 @@
        Map<Integer,String> map= DevStateEnum.getOpInfo();
        return new Response().setII(1,true,map,"获取设备工作类型(下拉)");
    }
    public List<DeviceState> getListByUserId(Integer userId) {
        return mapper.getListByUserId(userId);
    }
}
src/main/java/com/whyc/service/LeaderHomeService.java
@@ -1,6 +1,5 @@
package com.whyc.service;
import com.sun.org.glassfish.gmbal.NameValue;
import com.whyc.constant.BattSingalIdEnum;
import com.whyc.constant.Capperformance;
import com.whyc.constant.DevAlarmEnum;
@@ -18,6 +17,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadPoolExecutor;
@@ -60,7 +61,6 @@
    private BatttestdataIdService battTestDataIdService;
    public Response getAll(Integer userId) {
        Response response = new Response();
        Map<String,Object> map = new HashMap<>();
@@ -89,9 +89,9 @@
            testDataInfoStatistics(userId, map);
            latch.countDown();
        });
        //TODO 设备数量信息统计
        //10类基础资产信息统计
        poolExecutor.execute(() -> {
            //deviceInfoStatistics(userId, map);
            deviceInfoStatistics(userId, map);
            latch.countDown();
        });
@@ -109,10 +109,73 @@
        return response;
    }
    private void deviceInfoStatistics(Integer userId, Map<String, Object> map) {
        NameValueIntDto baseDto = new NameValueIntDto();
        int powerCount = powerInfService.getListByUserId(userId).size();
        map.put("powerCount", powerCount);
        List<BattInf> battInfList = battInfService.getListByUserId(userId);
        int battCount = battInfList.size();
        Map<Integer, List<BattInf>> devIdMap = battInfList.stream().collect(Collectors.groupingBy(BattInf::getDevId));
        map.put("devCount", devIdMap.size());
        map.put("battCount",battCount);
        int monCountTotal = 0;
        for (int i = 0; i < battCount; i++) {
            int monCount = battInfList.get(i).getMoncount().intValue();
            monCountTotal += monCount;
        }
        map.put("monCount", monCountTotal);
        LocalDateTime now = LocalDateTime.now();
        //本年第一天
        LocalDateTime yearStart = now.withDayOfYear(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
        Date yearStartTime = DateUtil.convertToDate(yearStart);
        //去年的第一天
        LocalDateTime lastYearStart = now.minusYears(1).withDayOfYear(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
        //去年的最后一天
        int lastYear = now.minusYears(1).getYear();
        LocalDate lastDayOfLastYear = LocalDate.of(lastYear, 12, 31);
        LocalDateTime lastYearEnd = lastDayOfLastYear.atTime(LocalTime.MAX);
        Date lastYearStartTime = DateUtil.convertToDate(lastYearStart);
        Date lastYearEndTime = DateUtil.convertToDate(lastYearEnd);
        //本年已放电电池数量
        //本年未放电电池数量
        //去年已放电电池数量
        //去年未放电电池数量
        int hrDisBattCount = battTestDataInfService.getHrDisCount(userId,yearStartTime,null);
        int hrNoDisBattCount = battCount - hrDisBattCount;
        int hrDisBattCountLastYear = battTestDataInfService.getHrDisCount(userId,lastYearStartTime,lastYearEndTime);
        int hrNoDisBattCountLastYear = battCount - hrDisBattCountLastYear;
        map.put("hrDisBattCount", hrDisBattCount);
        map.put("hrNoDisBattCount", hrNoDisBattCount);
        map.put("hrDisBattCountLastYear", hrDisBattCountLastYear);
        map.put("hrNoDisBattCountLastYear", hrNoDisBattCountLastYear);
        //本年优良劣化损坏数量
        List<BattCapInfoDto> battCapInfoList = getBattCapInfo(battInfList,yearStartTime,null);
        long battGoodCount = battCapInfoList.stream().filter(battCapInfo -> battCapInfo.getPerformance().equals(Capperformance.BATTSTATE_1.getStateName())).count();
        long battBadCount = battCapInfoList.stream().filter(battCapInfo -> battCapInfo.getPerformance().equals(Capperformance.BATTSTATE_2.getStateName())).count();
        long battDamageCount = battCapInfoList.stream().filter(battCapInfo -> battCapInfo.getPerformance().equals(Capperformance.BATTSTATE_3.getStateName())).count();
        //去年优良劣化损坏数量
        List<BattCapInfoDto> battCapInfoListLastYear = getBattCapInfo(battInfList,lastYearStartTime,lastYearEndTime);
        long battGoodCountLastYear = battCapInfoListLastYear.stream().filter(battCapInfo -> battCapInfo.getPerformance().equals(Capperformance.BATTSTATE_1.getStateName())).count();
        long battBadCountLastYear = battCapInfoListLastYear.stream().filter(battCapInfo -> battCapInfo.getPerformance().equals(Capperformance.BATTSTATE_2.getStateName())).count();
        long battDamageCountLastYear = battCapInfoListLastYear.stream().filter(battCapInfo -> battCapInfo.getPerformance().equals(Capperformance.BATTSTATE_3.getStateName())).count();
        map.put("battGoodCount", battGoodCount);
        map.put("battBadCount", battBadCount);
        map.put("battDamageCount", battDamageCount);
        map.put("battGoodCountLastYear", battGoodCountLastYear);
        map.put("battBadCountLastYear", battBadCountLastYear);
        map.put("battDamageCountLastYear", battDamageCountLastYear);
        //TODO 优良电源数量
        map.put("powerGoodCount","优良判定标准待确定" );
    }
    private void alarmRealtimeStatistics(Integer userId, Map<String, Object> map) {
        //电池告警信息统计
        List<AlarmDto> battAlarmListNew = new ArrayList<>();
        List<AlarmDto> battAlarmList = battAlarmService.getListByUserId(userId);
        List<AlarmDto> battAlarmList = battAlarmService.getListByUserId(userId, null);
        //合并单体告警的告警信息,对AlarmDto中AlmId 在17~28之间的进行合并.
        Map<String, List<AlarmDto>> mergeMap = battAlarmList.stream()
                .filter(alarm -> alarm.getAlmId() >= 17 && alarm.getAlmId() <= 28)
@@ -141,7 +204,7 @@
        });
        //设备告警信息统计
        List<AlarmDto> devAlarmList = devAlarmService.getListByUserId(userId);
        List<AlarmDto> devAlarmList = devAlarmService.getListByUserId(userId,null);
        //对告警名称赋值
        devAlarmList.forEach(alarmDto -> {
            alarmDto.setAlmName(DevAlarmEnum.getValue(alarmDto.getAlmId()));
@@ -149,7 +212,7 @@
        //电源告警信息统计
        List<AlarmDto> powerAlarmListNew = new ArrayList<>();
        List<AlarmDto> powerAlarmList = powerAlarmService.getListByUserId(userId);
        List<AlarmDto> powerAlarmList = powerAlarmService.getListByUserId(userId,null);
        //整流器总故障合并
        //ALARM_3300001(3300001,"整流器1总故障告警"),
        //    ALARM_3300002(3300002,"整流器2总故障告警"),
@@ -625,7 +688,7 @@
    }
    private void testDataInfoStatistics(Integer userId, Map<String, Object> map) {
    protected void testDataInfoStatistics(Integer userId, Map<String, Object> map) {
        List<BatttestdataInf> testInfList = battTestDataInfService.getListByUserId(userId);
        //过滤出本月的
        LocalDateTime startOfMonth = DateUtil.getStartOfMonth();
@@ -702,7 +765,7 @@
        return testInfOfMonth;
    }
    private void batteryInfoStatistics(Integer userId, Map<String, Object> map) {
    protected void batteryInfoStatistics(Integer userId, Map<String, Object> map) {
        List<BattInf> battInfList = battInfService.getListByUserId(userId);
        Map<String, List<BattInf>> brandMap = battInfList.stream().collect(Collectors.groupingBy(BattInf::getProduct));
        Map<Float, List<BattInf>> volMap = battInfList.stream().collect(Collectors.groupingBy(BattInf::getMonvolstd));
@@ -722,7 +785,7 @@
        map.put("battGroupInfo_vol",volList);
    }
    private void powerInfoStatistics(Integer userId, Map<String, Object> map) {
    protected void powerInfoStatistics(Integer userId, Map<String, Object> map) {
        List<PowerInf> powerInfList = powerInfService.getListByUserId(userId);
        Map<String, List<PowerInf>> brandMap = powerInfList.stream().collect(Collectors.groupingBy(PowerInf::getCompany));
        Map<Integer, List<PowerInf>> typeMap = powerInfList.stream().collect(Collectors.groupingBy(PowerInf::getPowerType));
@@ -792,7 +855,7 @@
        battInf.setProduct(brand);
        //查询满足条件的蓄电池列表
        List<BattInf> battInfList = battInfService.getListByCondition(userId,battInf);
        List<BattCapInfoDto> battCapInfoList = getBattCapInfo(battInfList);
        List<BattCapInfoDto> battCapInfoList = getBattCapInfo(battInfList,null,null);
        //data,和data2分别返回 统计数量和 站点优良,劣化,损坏 前二的信息
        List<NameValueIntDto> data = new ArrayList<>();
        List<NameValueListDto> data2 = new ArrayList<>();
@@ -836,7 +899,7 @@
        battInf.setInuseTime(inuseTimeStart);
        //查询满足条件的蓄电池列表
        List<BattInf> battInfList = battInfService.getListByCondition(userId,battInf);
        List<BattCapInfoDto> battCapInfoList = getBattCapInfo(battInfList);
        List<BattCapInfoDto> battCapInfoList = getBattCapInfo(battInfList,null,null);
        //data,根据品牌分组统计百分比
        Map<String, List<BattCapInfoDto>> brandMap = battCapInfoList.stream().collect(Collectors.groupingBy(BattCapInfoDto::getProduct));
@@ -943,7 +1006,7 @@
        battInf.setProduct(brand);
        //查询满足条件的蓄电池列表
        List<BattInf> battInfList = battInfService.getListByCondition(userId,battInf);
        List<BattCapInfoDto> battCapInfoList = getBattCapInfo(battInfList);
        List<BattCapInfoDto> battCapInfoList = getBattCapInfo(battInfList,null,null);
        //data,TODO 投运时间的维度参数,先固定变量,后续从数据库获取
        //time1和time2的单位为年
@@ -1055,7 +1118,7 @@
    }
    public List<BattCapInfoDto> getBattCapInfo(List<BattInf> battInfList) {
    public List<BattCapInfoDto> getBattCapInfo(List<BattInf> battInfList,Date startTime, Date endTime) {
        //获取核容优劣,损坏参数
        List<AppParam> paramList=appParamService.getHrParam();
        Float badValue=0f;
@@ -1086,7 +1149,8 @@
            capInfo.setInuseTime(battInf.getInuseTime());
            //2.获取电池组在给定时间段的放电记录(指定时间段的标准核容放电)
            BatttestdataInf testInf = battTestDataInfService.getLastStandardTestDataByTime(battInf.getBattgroupId(), battInf.getInuseTime(),null);
            //BatttestdataInf testInf = battTestDataInfService.getLastStandardTestDataByTime(battInf.getBattgroupId(), battInf.getInuseTime(),null);
            BatttestdataInf testInf = battTestDataInfService.getLastStandardTestDataByTime(battInf.getBattgroupId(), startTime,endTime);
            if (testInf == null) {
                capInfo.setRealCap(0f);
                capInfo.setCapPercentage("0");
src/main/java/com/whyc/service/MonitorService.java
New file
@@ -0,0 +1,230 @@
package com.whyc.service;
import com.whyc.constant.BattAlarmIdEnum;
import com.whyc.dto.NameValueIntDto;
import com.whyc.dto.Response;
import com.whyc.factory.ThreadPoolExecutorFactory;
import com.whyc.pojo.db_alarm.BattalarmData;
import com.whyc.pojo.db_ram_db.DeviceState;
import com.whyc.pojo.db_station.BattInf;
import com.whyc.pojo.db_station.StationInf;
import com.whyc.pojo.db_user.BaojigroupPower;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors;
@Service
public class MonitorService {
    @Autowired
    private LeaderHomeService leaderHomeService;
    @Autowired
    private StationInfService stationInfService;
    @Autowired
    private PowerInfService powerInfService;
    @Autowired
    private BattInfService battInfService;
    @Autowired
    private PwrdevAlarmService powerAlarmService;
    @Autowired
    private DevalarmDataService devAlarmDataService;
    @Autowired
    private BattalarmDataService battAlarmDataService;
    @Autowired
    private DeviceStateService deviceStateService;
    @Autowired
    private BaoJiGroupPowerService baoJiGroupPowerService;
    public Response getAll(Integer userId) {
        Response response = new Response();
        Map<String,Object> map = new HashMap<>();
        CountDownLatch latch = new CountDownLatch(9);
        ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor();
        //TODO 交流告警统计 待明确告警分类
        poolExecutor.execute(() -> {
            //acAlarmStatistics(userId, map);
            latch.countDown();
        });
        //资产信息统计
        poolExecutor.execute(() -> {
            assetsInfoStatistics(userId, map);
            latch.countDown();
        });
        //蓄电池核容信息统计
        poolExecutor.execute(() -> {
            leaderHomeService.testDataInfoStatistics(userId, map);
            latch.countDown();
        });
        //电池品牌信息统计
        poolExecutor.execute(() -> {
            leaderHomeService.batteryInfoStatistics(userId, map);
            latch.countDown();
        });
        //电源品牌信息统计
        poolExecutor.execute(() -> {
            leaderHomeService.powerInfoStatistics(userId, map);
            latch.countDown();
        });
        //TODO 电源告警信息统计 待明确告警分类
        poolExecutor.execute(() -> {
            //powerAlarmStatistics(userId, map);
            latch.countDown();
        });
        //单节蓄电池告警统计
        poolExecutor.execute(() -> {
            battMonAlarmStatistics(userId, map);
            latch.countDown();
        });
        //设备实时状态统计
        poolExecutor.execute(() -> {
            deviceStatusStatistics(userId, map);
            latch.countDown();
        });
        //班组统计 及 告警统计
        poolExecutor.execute(() -> {
            baoJiAndAlarmStatistics(userId, map);
            latch.countDown();
        });
        return response;
    }
    private void baoJiAndAlarmStatistics(Integer userId, Map<String, Object> map) {
        List<NameValueIntDto> baoJiGroupStationDtoList = new ArrayList<>();
        //获取管理的所有班组和站点
        List<BaojigroupPower> baoJiGroupStationList =baoJiGroupPowerService.getListByUserId(userId);
        Map<String, List<BaojigroupPower>> baoJiGroupStationMap = baoJiGroupStationList.stream().collect(Collectors.groupingBy(BaojigroupPower::getBaoJiGroupName));
        baoJiGroupStationMap.forEach((baoJiGroupName, stationList) -> {
            NameValueIntDto baoJiGroupStationDto = new NameValueIntDto();
            baoJiGroupStationDto.setName(baoJiGroupName);
            baoJiGroupStationDto.setValue(stationList.size());
            baoJiGroupStationDtoList.add(baoJiGroupStationDto);
        });
        map.put("baoJiStationStatistics", baoJiGroupStationDtoList);
        List<NameValueIntDto> alarmStatisticsList = new ArrayList<>();
        long powerAlarmCount = powerAlarmService.getListByUserId(userId, 1).stream().count();
        long devAlarmCount = devAlarmDataService.getListByUserId(userId, 1).stream().count();
        long battAlarmCount = battAlarmDataService.getListByUserId(userId, 1).stream().count();
        NameValueIntDto powerAlarmDto = new NameValueIntDto("电源监测", (int) powerAlarmCount);
        alarmStatisticsList.add(powerAlarmDto);
        NameValueIntDto devAlarmDto = new NameValueIntDto("设备监测", (int) devAlarmCount);
        alarmStatisticsList.add(devAlarmDto);
        NameValueIntDto battAlarmDto = new NameValueIntDto("电池监测", (int) battAlarmCount);
        alarmStatisticsList.add(battAlarmDto);
        map.put("alarmStatistics", alarmStatisticsList);
    }
    private void deviceStatusStatistics(Integer userId, Map<String, Object> map) {
        List<DeviceState> deviceStateList =deviceStateService.getListByUserId(userId);
        long chargeCount = deviceStateList.stream().filter(deviceState -> deviceState.getDevWorkstate() == 0).count();
        long hrChargeCount = deviceStateList.stream().filter(deviceState -> deviceState.getDevWorkstate() == 1).count();
        long hrDischargeCount = deviceStateList.stream().filter(deviceState -> deviceState.getDevWorkstate() == 2).count();
        long powerOffDischargeCount = deviceStateList.stream().filter(deviceState -> deviceState.getDevWorkstate() == 3).count();
        long resTestCount = deviceStateList.stream().filter(deviceState -> deviceState.getDevWorkstate() == 4).count();
        List<NameValueIntDto> nameValueList = new ArrayList<>();
        NameValueIntDto chargeCountDto = new NameValueIntDto("直连充电", (int) chargeCount);
        nameValueList.add(chargeCountDto);
        NameValueIntDto hrChargeCountDto = new NameValueIntDto("核容充电", (int) hrChargeCount);
        nameValueList.add(hrChargeCountDto);
        NameValueIntDto hrDischargeCountDto = new NameValueIntDto("核容放电", (int) hrDischargeCount);
        nameValueList.add(hrDischargeCountDto);
        NameValueIntDto powerOffDischargeCountDto = new NameValueIntDto("停电放电", (int) powerOffDischargeCount);
        nameValueList.add(powerOffDischargeCountDto);
        NameValueIntDto resTestCountDto = new NameValueIntDto("内阻测试", (int) resTestCount);
        nameValueList.add(resTestCountDto);
        map.put("deviceStatusStatistics", nameValueList);
    }
    private void battMonAlarmStatistics(Integer userId, Map<String, Object> map) {
        List<NameValueIntDto> nameValueList = new ArrayList<>();
        List<BattalarmData> battAlarmDataList = battAlarmDataService.getMonAlarm(userId);
        //获取电压异常告警
        List<BattalarmData> monVolAlarmList = battAlarmDataList.stream()
                .filter(alarm -> alarm.getAlmId().intValue() == BattAlarmIdEnum.ALARM_119005.getStateId()).collect(Collectors.toList());
        Map<String, List<BattalarmData>> monVolAlarmMap = monVolAlarmList.stream().collect(
                Collectors.groupingBy(alarm -> alarm.getBattgroupId() + "_" + alarm.getMonNum()));
        nameValueList.add(new NameValueIntDto("电压", monVolAlarmMap.size()));
        //获取内阻异常告警
        List<BattalarmData> monResAlarmList = battAlarmDataList.stream()
                .filter(alarm -> alarm.getAlmId().intValue() == BattAlarmIdEnum.ALARM_119007.getStateId()).collect(Collectors.toList());
        Map<String, List<BattalarmData>> monResAlarmMap = monResAlarmList.stream().collect(
                Collectors.groupingBy(alarm -> alarm.getBattgroupId() + "_" + alarm.getMonNum()));
        nameValueList.add(new NameValueIntDto("内阻", monResAlarmMap.size()));
        //获取温度异常告警
        List<BattalarmData> monTmpAlarmList = battAlarmDataList.stream()
                .filter(alarm -> alarm.getAlmId().intValue() == BattAlarmIdEnum.ALARM_119006.getStateId()).collect(Collectors.toList());
        Map<String, List<BattalarmData>> monTmpAlarmMap = monTmpAlarmList.stream().collect(
                Collectors.groupingBy(alarm -> alarm.getBattgroupId() + "_" + alarm.getMonNum()));
        nameValueList.add(new NameValueIntDto("温度", monTmpAlarmMap.size()));
        map.put("battMonAlarmStatistics", nameValueList);
    }
    private void assetsInfoStatistics(Integer userId, Map<String, Object> map) {
        List<NameValueIntDto> nameValueList = new ArrayList<>();
        List<StationInf> stationInfList =stationInfService.getListByUserId(userId);
        int stationCount = stationInfList.size();
        NameValueIntDto stationCountDto = new NameValueIntDto();
        stationCountDto.setName("站点数量");
        stationCountDto.setValue(stationCount);
        int powerCount = powerInfService.getListByUserId(userId).size();
        NameValueIntDto powerCountDto = new NameValueIntDto();
        powerCountDto.setName("电源数量");
        powerCountDto.setValue(powerCount);
        List<BattInf> battInfList = battInfService.getListByUserId(userId);
        int battCount = battInfList.size();
        Map<Integer, List<BattInf>> devIdMap = battInfList.stream().collect(Collectors.groupingBy(BattInf::getDevId));
        NameValueIntDto devCountDto = new NameValueIntDto();
        devCountDto.setName("设备数量");
        devCountDto.setValue(devIdMap.size());
        NameValueIntDto battCountDto = new NameValueIntDto();
        battCountDto.setName("电池数量");
        battCountDto.setValue(battCount);
        nameValueList.add(stationCountDto);
        nameValueList.add(powerCountDto);
        nameValueList.add(devCountDto);
        nameValueList.add(battCountDto);
        map.put("assetsInfoStatistics", nameValueList);
    }
}
src/main/java/com/whyc/service/PwrdevAlarmService.java
@@ -81,7 +81,7 @@
        return mapper.selectList(query).stream().map(PwrdevAlarm::getNum).collect(Collectors.toList());
    }
    public List<AlarmDto> getListByUserId(Integer userId) {
        return mapper.getListByUserId(userId);
    public List<AlarmDto> getListByUserId(Integer userId,Integer alarmLevel) {
        return mapper.getListByUserId(userId,alarmLevel);
    }
}
src/main/java/com/whyc/webSocket/MonitorSocket.java
New file
@@ -0,0 +1,75 @@
package com.whyc.webSocket;
import com.whyc.config.WebSocketConfig;
import com.whyc.dto.Response;
import com.whyc.pojo.db_user.User;
import com.whyc.service.LeaderHomeService;
import com.whyc.service.MonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpSession;
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
/**
 * 运行监控界面
 */
@Component
@ServerEndpoint(value = "/monitor",encoders = WebSocketEncoder.class,configurator = WebSocketConfig.class)
public class MonitorSocket {
    private Session session;
    private Thread thread;
    private static MonitorService monitorService;
    @Autowired
    public void setMonitorService(MonitorService monitorService) {
        MonitorSocket.monitorService = monitorService;
    }
    @OnOpen
    public void onOpen(Session session, EndpointConfig config){
        this.session = session;
        HttpSession httpSession = (HttpSession) config.getUserProperties().get("httpSession");
        User user = (User) httpSession.getAttribute("user");
        Integer userId = user.getId();
        Thread thread = new Thread() {
            @Override
            public void run() {
                try {
                    while (!currentThread().isInterrupted()) {
                        Response response = monitorService.getAll(userId);
                        session.getBasicRemote().sendObject(new Response().set(1, response));
                        sleep(4000);
                    }
                } catch (Exception e) {
                    this.interrupt();
                }
            }
        };
        thread.start();
        this.thread = thread;
    }
    @OnClose
    public void onClose(CloseReason closeReason) throws IOException {
        System.err.println("closeReason = " + closeReason);
        if(session.isOpen()){
            session.close();
        }
    }
    @OnError
    public void onError(Throwable error) throws IOException {
        error.printStackTrace();
        thread.isInterrupted();
        if(session.isOpen()){
            session.close();
        }
    }
}
src/main/resources/mapper/BaojigroupPowerMapper.xml
@@ -56,4 +56,17 @@
          and gb.power_id = p.power_id
          and g.team_flag = 1
    </select>
    <select id="getListByUserId" resultType="com.whyc.pojo.db_user.BaojigroupPower">
        SELECT distinct gb.baoji_group_id,gb.station_id,g.baoji_group_name as baoJiGroupName,b.station_name
        FROM db_user.tb_baojigroup g,db_user.tb_baojigroup_power gb,db_station.tb_station_inf b
        where g.baoji_group_id = gb.baoji_group_id 0
        and gb.station_id = b.station_id
        and g.team_flag = 1
        and gb.station_id in (
            select distinct  station_id from db_user.tb_baojigroup_usr bu,db_user.tb_baojigroup_power bp
            where bu.baoji_group_id = bp.baoji_group_id
            and bu.uid = #{userId}
        )
        order by g.baoji_group_name
    </select>
</mapper>
src/main/resources/mapper/BattalarmDataMapper.xml
@@ -53,9 +53,13 @@
    </select>
    <select id="getListByUserId" resultType="com.whyc.dto.AlarmDto">
        select bd.mon_num,bd.alm_signal_id as alm_id,bd.alm_id as alm_id_origin,bd.alm_level,bd.alm_start_time,
        bd.num as alm_num,bi.battgroup_id,bi.battgroup_name,bi.dev_id,bi.dev_name,si.station_id,si.station_name from db_alarm.tb_battalarm_data bd,db_station.tb_batt_inf bi,db_station.tb_station_inf si
        bd.num as alm_num,bi.battgroup_id,bi.battgroup_name,bi.dev_id,bi.dev_name,si.station_id,si.station_name
        from db_alarm.tb_battalarm_data bd,db_station.tb_batt_inf bi,db_station.tb_station_inf si
        where bd.battgroup_id=bi.battgroup_id
        and bi.station_id=si.station_id
        <if test="almLevel !=null">
            and bd.alm_level=#{almLevel}
        </if>
        and bd.battgroup_id in(
            select distinct battgroup_id from db_user.tb_baojigroup_usr bu,db_user.tb_baojigroup_power bp,db_station.tb_batt_inf bi
            where bu.baoji_group_id = bp.baoji_group_id
@@ -63,4 +67,59 @@
            and bu.uid = #{userId}
        )
    </select>
    <select id="getMonAlarm" resultType="com.whyc.pojo.db_alarm.BattalarmData">
        select bd.battgroup_id,bd.mon_num,bd.alm_signal_id,bd.alm_id,from db_alarm.tb_battalarm_data bd
        where bd.alm_id in (119005,119006,119007)
        and bd.battgroup_id in(
        select distinct battgroup_id from db_user.tb_baojigroup_usr bu,db_user.tb_baojigroup_power bp,db_station.tb_batt_inf bi
        where bu.baoji_group_id = bp.baoji_group_id
        and bp.station_id = bi.station_id
        and bu.uid = #{userId}
        )
    </select>
    <select id="getBattAlmAnalyse" resultType="com.whyc.pojo.db_alarm.BattalarmData">
        select tb_battalarm_data.*,tb_batt_inf.battgroup_name,tb_station_inf.station_name,tb_station_inf.provice,tb_station_inf.city,tb_station_inf.country,tb_station_inf.full_name
        from db_alarm.tb_battalarm_data,db_station.tb_batt_inf,db_station.tb_station_inf
        <where>
            tb_battalarm_data.battgroup_id=tb_batt_inf.battgroup_id
            and tb_batt_inf.station_id=tb_station_inf.station_id
            <if test="provice!=null">
                and tb_station_inf.provice=#{provice}
            </if>
            <if test="city!=null">
                and tb_station_inf.city=#{city}
            </if>
            <if test="country!=null">
                and tb_station_inf.country=#{country}
            </if>
            <if test="stationId!=null">
                and tb_station_inf.station_id=#{stationId}
            </if>
            <if test="stationId!=null">
                and tb_station_inf.station_id=#{stationId}
            </if>
            <if test="battgroupId!=null">
                and tb_battalarm_data.battgroup_id=#{battgroupId}
            </if>
            <!--<if test="almIds!=null">
                <if test="almIds.size==0">
                    and tb_battalarm_data.alm_id =0
                </if>
                <if test="almIds.size>0">
                    and tb_battalarm_data.alm_id in
                    <foreach collection="almIds" item="almId" open="(" separator="," close=")">
                        #{almId}
                    </foreach>
                </if>
            </if>-->
            <if test="uid>100">
                and tb_batt_inf.station_id in(
                select distinct station_id from db_user.tb_baojigroup_power,db_user.tb_baojigroup_usr
                where   tb_baojigroup_power.baoji_group_id=tb_baojigroup_usr.baoji_group_id
                and tb_baojigroup_usr.uid=#{uid}
                )
            </if>
        </where>
    </select>
</mapper>
src/main/resources/mapper/BatttestdataInfMapper.xml
@@ -71,4 +71,21 @@
        )
    </select>
    <select id="getHrDisCount" resultType="java.lang.Integer">
        select distinct battgroup_id from db_batt_testdata.tb_batttestdata_inf
        where test_type=3
        and test_starttype=3 and test_timelong >=7200
        <if test="startTime!=null">
            and test_starttime >= #{startTime}
        </if>
        <if test="endTime!=null">
            and test_starttime &lt;= #{endTime}
        </if>
        and battgroup_id in(
        select distinct battgroup_id from db_user.tb_baojigroup_usr bu,db_user.tb_baojigroup_power bp,db_station.tb_batt_inf bi
        where bu.baoji_group_id = bp.baoji_group_id
        and bp.station_id = bi.station_id
        and bu.uid = #{userId}
        )
    </select>
</mapper>
src/main/resources/mapper/DevalarmDataMapper.xml
@@ -53,6 +53,9 @@
        select distinct dd.*,dd.num as alm_num,bi.dev_id,bi.dev_name,si.station_id,si.station_name from db_alarm.tb_devalarm_data dd,db_station.tb_batt_inf bi,db_station.tb_station_inf si
        where dd.dev_id=bi.dev_id
        and bi.station_id=si.station_id
        <if test="almLevel != null">
            and dd.alm_level=#{almLevel}
        </if>
        and dd.dev_id in (
            select distinct dev_id from db_user.tb_baojigroup_usr bu,db_user.tb_baojigroup_power bp,db_station.tb_batt_inf bi
            where bu.baoji_group_id = bp.baoji_group_id
src/main/resources/mapper/DeviceStateMapper.xml
@@ -35,4 +35,13 @@
            order by tb_device_state.dev_id asc
        </where>
    </select>
    <select id="getListByUserId" resultType="com.whyc.pojo.db_ram_db.DeviceState">
        select distinct dev_id,dev_workstate from db_ram_db.tb_device_state
        where dev_id in(
            select distinct dev_id from db_user.tb_baojigroup_usr bu,db_user.tb_baojigroup_power bp,db_station.tb_batt_inf bi
            where bu.baoji_group_id = bp.baoji_group_id
            and bp.station_id = bi.station_id
            and bu.uid = #{userId}
        )
    </select>
</mapper>
src/main/resources/mapper/PwrdevAlarmMapper.xml
@@ -54,6 +54,9 @@
        select pa.*,pa.num as alm_num,pi.power_name,pi.power_id,si.station_id,si.station_name from db_pwrdev_alarm.tb_pwrdev_alarm pa,db_station.tb_power_inf pi,db_station.tb_station_inf si
        where pa.power_id=pi.power_id
        and pi.station_id=si.station_id
        <if test="alarmLevel !=null">
            and pa.alm_level=#{alarmLevel}
        </if>
        and pa.power_id in (
            select distinct power_id from db_user.tb_baojigroup_usr bu,db_user.tb_baojigroup_power bp
            where bu.baoji_group_id = bp.baoji_group_id