| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.paramter.AlarmPar; |
| | | import com.whyc.dto.paramter.DevAlarmPar; |
| | | import com.whyc.mapper.BattDevAlarmDataMapper; |
| | | import com.whyc.mapper.DevalarmDataMapper; |
| | | import com.whyc.pojo.DevalarmData; |
| | | import com.whyc.pojo.UserInf; |
| | | import com.whyc.util.ActionUtil; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class DevalarmDataService { |
| | | |
| | | @Resource |
| | | private DevalarmDataMapper mapper; |
| | | |
| | | @Resource |
| | | private BattDevAlarmDataMapper battDevAlarmDataMapper; |
| | | //设备告警实时查询 |
| | | public Response serchByInfo(AlarmPar par) { |
| | | public Response serchByInfo(DevAlarmPar par) { |
| | | PageHelper.startPage(par.getPage().getPageCurr(),par.getPage().getPageSize()); |
| | | UserInf uinf= ActionUtil.getUser(); |
| | | par.setUId(uinf.getUId().intValue()); |
| | |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().set(1,pageInfo); |
| | | } |
| | | //设备告警实时查询-webSocket |
| | | public Response serchByInfoOfWebSocket(DevAlarmPar par) { |
| | | PageHelper.startPage(par.getPage().getPageCurr(),par.getPage().getPageSize()); |
| | | List list=mapper.serchByInfo(par); |
| | | PageInfo pageInfo=new PageInfo(list); |
| | | return new Response().set(1,pageInfo); |
| | | } |
| | | |
| | | //设备告警实时查询-sendwebSocket |
| | | @Transactional |
| | | public Response getSendDevAlarmOfWebSocket(Integer uId) { |
| | | List<DevalarmData> list=mapper.getSendDevAlarm(uId); |
| | | Date now = new Date(); |
| | | ListIterator<DevalarmData> it = list.listIterator(); |
| | | while (it.hasNext()){ |
| | | DevalarmData adata = it.next(); |
| | | if(adata.getAlmLevel()==1 && adata.getRecordTime()!=null && now.getTime()-adata.getRecordTime().getTime()<24*3600000){ |
| | | it.remove(); |
| | | } |
| | | if(adata.getAlmLevel()==2 && adata.getRecordTime()!=null && now.getTime()-adata.getRecordTime().getTime()<7*24*3600000){ |
| | | it.remove(); |
| | | } |
| | | if(adata.getAlmLevel()==3 && adata.getRecordTime()!=null && now.getTime()-adata.getRecordTime().getTime()<30*7*24*3600000){ |
| | | it.remove(); |
| | | } |
| | | } |
| | | return new Response().set(1,list); |
| | | } |
| | | |
| | | //设备告警确认告警 |
| | | public Response update(int num) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.set("alm_is_confirmed",1); |
| | | wrapper.eq("num",num); |
| | | int flag=mapper.update(null,wrapper); |
| | | return new Response().set(flag); |
| | | } |
| | | //设备告警取消告警 |
| | | public Response cancel(int num) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.set("alm_is_confirmed",0); |
| | | wrapper.eq("num",num); |
| | | int flag=mapper.update(null,wrapper); |
| | | return new Response().set(flag); |
| | | } |
| | | //设备告警删除告警 |
| | | public Response delete(int num) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("num",num); |
| | | int flag=mapper.delete(wrapper); |
| | | return new Response().set(flag); |
| | | } |
| | | |
| | | //设备告警数查询 |
| | | public Response searchNums() { |
| | | UserInf uinf = ActionUtil.getUser(); |
| | | int devAlarmNum = mapper.searchNums(uinf.getUId().intValue()); |
| | | return new Response().set(1, devAlarmNum); |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param userId |
| | | * @param type 1,查询24小时内;0,查询所有 |
| | | * @return |
| | | */ |
| | | public List<DevalarmData> getList(Long userId, int type) { |
| | | return mapper.getList(userId,type); |
| | | } |
| | | |
| | | |
| | | //查询分级告警的个数 |
| | | public Response serchByLevel(int uId) { |
| | | List list = new ArrayList(); |
| | | //分四级查询个数 |
| | | for (int i = 1; i <= 4; i++) { |
| | | int countLevel = mapper.serchByLevel(i, uId); |
| | | list.add(countLevel); |
| | | } |
| | | return new Response().setII(1, list.size() > 0, list, "分级告警数"); |
| | | } |
| | | |
| | | public int getAlarmNum(int userId) { |
| | | return battDevAlarmDataMapper.searchNums(userId); |
| | | } |
| | | |
| | | public int getRealTimeWithLevel1(int userId) { |
| | | return battDevAlarmDataMapper.getRealTimeWithLevel1(userId); |
| | | } |
| | | |
| | | //今日实时告警 |
| | | public Response getDalmToday(int userId) { |
| | | try { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | int dtatolNum = 0; |
| | | Map<String, Integer> dAlmClearMap = new HashMap<>(); |
| | | dAlmClearMap.put("clear0", 0); |
| | | dAlmClearMap.put("clear1", 0); |
| | | List<DevalarmData> dAlmList = mapper.getDalmToday(userId); |
| | | Map<Integer, List<DevalarmData>> dclearedMap = dAlmList.stream().collect(Collectors.groupingBy(DevalarmData::getAlmClearedType)); |
| | | for (Integer cleared : dclearedMap.keySet()) { |
| | | dAlmClearMap.put("clear" + String.valueOf(cleared), dclearedMap.get(cleared).size()); |
| | | dtatolNum += dclearedMap.get(cleared).size(); |
| | | } |
| | | Map<String, Integer> dAlmLevelMap = new HashMap<>(); |
| | | dAlmLevelMap.put("level1", 0); |
| | | dAlmLevelMap.put("level2", 0); |
| | | dAlmLevelMap.put("level3", 0); |
| | | dAlmLevelMap.put("level4", 0); |
| | | Map<Integer, List<DevalarmData>> dlevelMap = dAlmList.stream().collect(Collectors.groupingBy(DevalarmData::getAlmLevel)); |
| | | for (Integer level : dlevelMap.keySet()) { |
| | | dAlmLevelMap.put("level" + String.valueOf(level), dlevelMap.get(level).size()); |
| | | //dtatolNum += dlevelMap.get(level).size(); |
| | | } |
| | | map.put("dAlmClearMap", dAlmClearMap); |
| | | map.put("dAlmLevelMap", dAlmLevelMap); |
| | | map.put("dtatolNum", dtatolNum); |
| | | return new Response().setII(1, true, map, "今日实时告警"); |
| | | } catch (Exception e) { |
| | | return new Response().set(1, false, "出现异常" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | public List<Integer> getStationList(int userId) { |
| | | return mapper.getStationList(userId); |
| | | } |
| | | |
| | | public int getCountByStationIds(List<String> stationIdList, Integer level) { |
| | | return mapper.getCountByStationIds(stationIdList, level); |
| | | } |
| | | |
| | | public List<DevalarmData> getListByStationIds(List<String> stationIdList) { |
| | | return mapper.getListByStationIds(stationIdList); |
| | | } |
| | | |
| | | |
| | | } |