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
@@ -14,6 +14,10 @@ List<AlarmInspection> getListGreatThan(Long battAlarmId); 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/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/BattalarmDataService.java
@@ -7,7 +7,6 @@ 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; @@ -75,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) { @@ -85,6 +84,10 @@ 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()); 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; @@ -176,7 +175,7 @@ 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) @@ -205,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())); @@ -213,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总故障告警"), @@ -689,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(); @@ -766,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)); @@ -786,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)); 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,6 +67,16 @@ 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 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