src/main/java/com/whyc/controller/BaoJiGroupController.java
@@ -62,6 +62,13 @@ return new Response<List<BaoJiGroup>>().set(1,baoJiGroupList); } @GetMapping("groupWithStationAndAlarmForScreen") @ApiOperation(value = "大屏下的查询班组管理下的站点及告警") public Response<List<BaoJiGroup>> getGroupWithStationAndAlarmForScreen(){ Long uId = ActionUtil.getUser().getUId(); return service.getGroupWithStationAndAlarmForScreen(uId.intValue()); } @GetMapping("groupWithStationAndAlarm") @ApiOperation(value = "查询班组管理下的站点及告警") public Response<List<BaoJiGroup>> getGroupWithStationAndAlarm(){ src/main/java/com/whyc/mapper/BattalarmDataMapper.java
@@ -77,6 +77,8 @@ int getCapAlarmNum(int userId); int getCountByStationIds(List<String> stationIdList); int getCountByStationIds(List<String> stationIdList, Integer level); List<BattalarmData> getListByStationIds(List<String> stationIdList); } src/main/java/com/whyc/mapper/DevalarmDataMapper.java
@@ -38,5 +38,8 @@ //设备告警机房 int getQualityAnalysisStation(int userId); int getCountByStationIds(List<String> stationIdList); int getCountByStationIds(List<String> stationIdList, Integer level); List<DevalarmData> getListByStationIds(List<String> stationIdList); } src/main/java/com/whyc/mapper/PwrdevAlarmMapper.java
@@ -47,6 +47,8 @@ //电源设备告警机房 int getQualityAnalysisStation(int userId); int getCountByStationIds(List<String> stationIdList); int getCountByStationIds(List<String> stationIdList, Integer level); List<PwrdevAlarm> getListByStationIds(List<String> stationIdList); } src/main/java/com/whyc/pojo/BattalarmData.java
@@ -125,4 +125,7 @@ @TableField(exist = false) private String battgroupname; @TableField(exist = false) private String stationId; } src/main/java/com/whyc/pojo/StationInf.java
@@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.whyc.dto.result.SystemGrdoupBatt; import com.whyc.mapper.PwrdevAlarmMapper; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; @@ -82,4 +83,16 @@ @TableField(exist = false) private Fbs9100State fbs9100State = new Fbs9100State(); @TableField(exist = false) private List<BattalarmData> battAlarmList; @TableField(exist = false) private List<DevalarmData> deviceAlarmList; @TableField(exist = false) private List<PwrdevAlarm> powerAlarmList; @TableField(exist = false) private int alarmFlag; } src/main/java/com/whyc/service/BaoJiGroupService.java
@@ -9,10 +9,7 @@ import com.whyc.mapper.BaoJiGroupUserMapper; import com.whyc.mapper.BaoJiGroupBattGroupMapper; import com.whyc.mapper.CommonMapper; import com.whyc.pojo.BaoJiGroup; import com.whyc.pojo.BaoJiGroupUser; import com.whyc.pojo.BaojiGroupBattGroup; import com.whyc.pojo.StationInf; import com.whyc.pojo.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -120,26 +117,90 @@ return mapper.selectList(query); } public Response getGroupWithStationAndAlarmForScreen(int userId) { try { List<GroupWithStationAndAlarmDTO> list = mapper.getGroupWithStation(userId); list.forEach(item -> { List<StationInf> stationInfList = item.getStationInfList(); List<StationInf> stationInfList2 = stationInfList.stream().collect(Collectors.collectingAndThen( Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(StationInf::getTogetherFlag))), ArrayList::new)); item.setStationInfList(stationInfList2); item.setStationCount(stationInfList2.size()); List<String> stationIdList = stationInfList.stream().map(StationInf::getStationId).collect(Collectors.toList()); //电池 int battAlarmCount = battAlarmDataService.getCountByStationIds(stationIdList,1); item.setBattAlarmCount(battAlarmCount); //设备 int deviceAlarmCount = deviceAlarmDataService.getCountByStationIds(stationIdList,1); item.setDeviceAlarmCount(deviceAlarmCount); //电源 int powerAlarmCount = powerAlarmService.getCountByStationIds(stationIdList,1); item.setPowerAlarmCount(powerAlarmCount); }); return new Response().set(1, list); }catch (Exception e){ return new Response<>().set(1,false,"发生异常:"+e.getCause()); } } public Response getGroupWithStationAndAlarm(int userId) { try { List<GroupWithStationAndAlarmDTO> list = mapper.getGroupWithStation(userId); list.forEach(item -> { List<StationInf> stationInfList = item.getStationInfList(); stationInfList = stationInfList.stream().collect(Collectors.collectingAndThen( Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(StationInf::getTogetherFlag))), ArrayList::new)); item.setStationInfList(stationInfList); item.setStationCount(stationInfList.size()); List<String> stationIdList = stationInfList.stream().map(StationInf::getStationId).collect(Collectors.toList()); //电池 int battAlarmCount = battAlarmDataService.getCountByStationIds(stationIdList); item.setBattAlarmCount(battAlarmCount); List<BattalarmData> battAlarmList = battAlarmDataService.getListByStationIds(stationIdList); //设备 int deviceAlarmCount = deviceAlarmDataService.getCountByStationIds(stationIdList); item.setDeviceAlarmCount(deviceAlarmCount); List<DevalarmData> deviceAlarmList = deviceAlarmDataService.getListByStationIds(stationIdList); //电源 int powerAlarmCount = powerAlarmService.getCountByStationIds(stationIdList); item.setPowerAlarmCount(powerAlarmCount); List<PwrdevAlarm> powerAlarmList = powerAlarmService.getListByStationIds(stationIdList); //遍历每个告警列表,如果与站点相符,则加入到站点里面 for (BattalarmData alarm : battAlarmList) { for (StationInf stationInf : stationInfList) { if(alarm.getStationId().equals(stationInf.getStationId())) { List<BattalarmData> containList = stationInf.getBattAlarmList(); if(containList == null){ containList = new LinkedList<>(); } containList.add(alarm); stationInf.setBattAlarmList(containList); stationInf.setAlarmFlag(1); break; } } } for (DevalarmData alarm : deviceAlarmList) { for (StationInf stationInf : stationInfList) { if(alarm.getStationId().equals(stationInf.getStationId())) { List<DevalarmData> containList = stationInf.getDeviceAlarmList(); if(containList == null){ containList = new LinkedList<>(); } containList.add(alarm); stationInf.setDeviceAlarmList(containList); stationInf.setAlarmFlag(1); break; } } } for (PwrdevAlarm alarm : powerAlarmList) { for (StationInf stationInf : stationInfList) { if(alarm.getStationId().equals(stationInf.getStationId())) { List<PwrdevAlarm> containList = stationInf.getPowerAlarmList(); if(containList == null){ containList = new LinkedList<>(); } containList.add(alarm); stationInf.setPowerAlarmList(containList); stationInf.setAlarmFlag(1); break; } } } }); return new Response().set(1, list); src/main/java/com/whyc/service/BattalarmDataService.java
@@ -594,7 +594,11 @@ return mapper.getCapAlarmNum(userId); } public int getCountByStationIds(List<String> stationIdList) { return mapper.getCountByStationIds(stationIdList); public int getCountByStationIds(List<String> stationIdList, Integer level) { return mapper.getCountByStationIds(stationIdList,level); } public List<BattalarmData> getListByStationIds(List<String> stationIdList) { return mapper.getListByStationIds(stationIdList); } } src/main/java/com/whyc/service/DevalarmDataService.java
@@ -161,7 +161,11 @@ return mapper.getStationList(userId); } public int getCountByStationIds(List<String> stationIdList) { return mapper.getCountByStationIds(stationIdList); public int getCountByStationIds(List<String> stationIdList, Integer level) { return mapper.getCountByStationIds(stationIdList,level); } public List<DevalarmData> getListByStationIds(List<String> stationIdList) { return mapper.getListByStationIds(stationIdList); } } src/main/java/com/whyc/service/PwrdevAlarmService.java
@@ -344,7 +344,11 @@ return mapper.getStationList(userId); } public int getCountByStationIds(List<String> stationIdList) { return mapper.getCountByStationIds(stationIdList); public int getCountByStationIds(List<String> stationIdList, Integer level) { return mapper.getCountByStationIds(stationIdList,level); } public List<PwrdevAlarm> getListByStationIds(List<String> stationIdList) { return mapper.getListByStationIds(stationIdList); } } src/main/java/com/whyc/webSocket/GroupStationSocket.java
New file @@ -0,0 +1,65 @@ package com.whyc.webSocket; import com.whyc.dto.Response; import com.whyc.service.BaoJiGroupService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.websocket.*; import javax.websocket.server.ServerEndpoint; import java.io.IOException; /** * 运维分配-班组管理 */ @Component @ServerEndpoint(value = "/groupStation",encoders = WebSocketEncoder.class) public class GroupStationSocket { private volatile Thread thread; private static final int executeTime = 10000; private static BaoJiGroupService baoJiGroupService; private Session session; @Autowired public void setBaoJiGroupService(BaoJiGroupService baoJiGroupService) { GroupStationSocket.baoJiGroupService = baoJiGroupService; } @OnOpen public void onOpen(Session session){ this.session = session; onMessage(session); } public void onMessage(Session session){ thread = new Thread("Thread_GroupStation") { public void run() { while (!isInterrupted()) { try { if (session.isOpen()) { //推送信息 session.getBasicRemote().sendObject(new Response().set(1,System.currentTimeMillis())); } sleep(executeTime); } catch (Exception e) { interrupt(); } } } }; thread.start(); } @OnClose public void onClose(CloseReason closeReason) throws IOException { session.close(); } @OnError public void onError(Throwable error) throws IOException { session.close(); } } src/main/resources/mapper/BattalarmDataMapper.xml
@@ -481,6 +481,23 @@ from db_battinf.tb_battinf b, db_alarm.tb_battalarm_data d where b.battgroupId = d.battgroupid <if test="level!=null"> and d.alm_level = #{level} and d.alm_severity = 1 </if> and b.StationId in <foreach collection="stationIdList" item="item" separator="," open="(" close=")"> #{item} </foreach> </select> <select id="getListByStationIds" resultType="com.whyc.pojo.BattalarmData"> select distinct d.num,d.battgroupid,b.stationname,b.stationid,b.stationName3,b.stationName1,b.stationName2,b.stationName4,b.stationName5 ,d.monnum,d.alm_level,alm_id,alm_start_time,alm_signal_id,alm_severity from db_battinf.tb_battinf b, db_alarm.tb_battalarm_data d where b.battgroupId = d.battgroupid and b.StationId in <foreach collection="list" item="item" separator="," open="(" close=")"> #{item} src/main/resources/mapper/DevalarmDataMapper.xml
@@ -283,6 +283,22 @@ from db_battinf.tb_battinf b, db_alarm.tb_devalarm_data d where b.FBSDeviceId = d.dev_id <if test="level!=null"> and d.alm_level = #{level} and d.alm_severity = 1 </if> and b.StationId in <foreach collection="stationIdList" item="item" separator="," open="(" close=")"> #{item} </foreach> </select> <select id="getListByStationIds" resultType="com.whyc.pojo.DevalarmData"> select distinct d.num,d.dev_id,b.stationname,b.stationid,b.stationName3,b.stationName1,b.stationName2,b.stationName5 ,d.alm_level,alm_type,alm_start_time,alm_severity from db_battinf.tb_battinf b, db_alarm.tb_devalarm_data d where b.FBSDeviceId = d.dev_id and b.StationId in <foreach collection="list" item="item" separator="," open="(" close=")"> #{item} src/main/resources/mapper/PwrdevAlarmMapper.xml
@@ -354,6 +354,20 @@ from db_pwrdev_inf.tb_pwrdev_inf b, db_pwrdev_alarm.tb_pwrdev_alarm d where b.PowerDeviceId = d.PowerDeviceId <if test="level!=null"> and d.alm_level = #{level} and d.alm_severity = 1 </if> and b.StationId in <foreach collection="stationIdList" item="item" separator="," open="(" close=")"> #{item} </foreach> </select> <select id="getListByStationIds" resultType="com.whyc.pojo.PwrdevAlarm"> select distinct d.*,b.StationName,b.StationName1,b.StationName2,b.StationName3,b.StationName5,b.StationId from db_pwrdev_inf.tb_pwrdev_inf b, db_pwrdev_alarm.tb_pwrdev_alarm d where b.PowerDeviceId = d.PowerDeviceId and b.StationId in <foreach collection="list" item="item" separator="," open="(" close=")"> #{item}