| | |
| | | import com.whyc.pojo.PwrdevAlarmParam; |
| | | import com.whyc.pojo.UserInf; |
| | | import com.whyc.util.ActionUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class PwrdevAlarmService { |
| | |
| | | @Resource |
| | | private PwrdevAlarmParamMapper paramMapper; |
| | | |
| | | @Autowired |
| | | private SubTablePageInfoService subService; |
| | | |
| | | //电源实时告警查询 |
| | | public Response getAllPage(PwrdevAlarm pwrdevAlarm){ |
| | | //分页信息 |
| | |
| | | for (PwrdevAlarm p:list) { |
| | | p.setAlarmName(AlarmDaoFactory.getAllAlarmName(p.getAlmType())); |
| | | if(p.getAlmIndex()!=0){ |
| | | p.setAlarmName(p.getAlarmName().replace("N","第"+p.getAlmIndex()+"路")); |
| | | p.setAlarmName(p.getAlarmName().replace("N",p.getAlmIndex()+"")); |
| | | } |
| | | } |
| | | PageInfo pageInfo=new PageInfo(list); |
| | |
| | | for (PwrdevAlarm p:list) { |
| | | p.setAlarmName(AlarmDaoFactory.getAllAlarmName(p.getAlmType())); |
| | | if(p.getAlmIndex()!=0){ |
| | | p.setAlarmName(p.getAlarmName().replace("N","第"+p.getAlmIndex()+"路")); |
| | | p.setAlarmName(p.getAlarmName().replace("N",p.getAlmIndex()+"")); |
| | | } |
| | | } |
| | | PageInfo pageInfo=new PageInfo(list); |
| | |
| | | } |
| | | adata.setAlarmName(AlarmDaoFactory.getAllAlarmName(adata.getAlmType())); |
| | | if(adata.getAlmIndex()!=0){ |
| | | adata.setAlarmName(adata.getAlarmName().replace("N","第"+adata.getAlmIndex()+"路")); |
| | | adata.setAlarmName(adata.getAlarmName().replace("N",adata.getAlmIndex()+"")); |
| | | } |
| | | } |
| | | return new Response().set(1,list); |
| | |
| | | wrapper.set("alm_is_confirmed",1); |
| | | wrapper.set("alm_confirmed_time",new SimpleDateFormat(ActionUtil.time_yyyyMMddHHmmss).format(new Date())); |
| | | wrapper.eq("num",num); |
| | | int flag=mapper.update(null,wrapper); |
| | | int flag=mapper.update((PwrdevAlarm) ActionUtil.objeNull,wrapper); |
| | | return new Response().set(flag); |
| | | } |
| | | //电源实时取消告警 |
| | |
| | | wrapper.set("alm_is_confirmed",2); |
| | | wrapper.set("alm_confirmed_time",new SimpleDateFormat(ActionUtil.time_yyyyMMddHHmmss).format(new Date())); |
| | | wrapper.eq("num",num); |
| | | int flag=mapper.update(null,wrapper); |
| | | int flag=mapper.update((PwrdevAlarm) ActionUtil.objeNull,wrapper); |
| | | return new Response().set(flag); |
| | | } |
| | | |
| | |
| | | for (Integer num:list) { |
| | | UpdateWrapper wrapper = new UpdateWrapper<>(); |
| | | // 通过num删除 |
| | | wrapper.eq("num",num); |
| | | flag=mapper.delete(wrapper); |
| | | wrapper.eq("num", num); |
| | | flag = mapper.delete(wrapper); |
| | | } |
| | | return new Response().set(flag); |
| | | return new Response().set(flag); |
| | | } |
| | | |
| | | //电源告警个数 |
| | | public Response getAlarmNum() { |
| | | UserInf uinf= ActionUtil.getUser(); |
| | | int powerAlarmNum=mapper.getAlarmNum(uinf.getUId().intValue()); |
| | | return new Response().set(1,powerAlarmNum); |
| | | UserInf uinf = ActionUtil.getUser(); |
| | | int powerAlarmNum = mapper.getAlarmNum(uinf.getUId().intValue()); |
| | | return new Response().set(1, powerAlarmNum); |
| | | } |
| | | |
| | | //电源告警个数 |
| | | public int getAlarmNumByUserId(int userId) { |
| | | return mapper.getAlarmNum(userId); |
| | | } |
| | | //实时1级电源告警个数 |
| | | public int getRealTimeWithLevel1(int userId) { |
| | | return mapper.getRealTimeWithLevel1(userId); |
| | | } |
| | | |
| | | //山西晋源特定接口 |
| | | public int getRealTimeWithLevel1JY() { |
| | | return mapper.getRealTimeWithLevel1JY(); |
| | | } |
| | | |
| | | //首页电源总个数 |
| | | public int getHomeAlarmNum(int uId) { |
| | | int powerAlarmNum = mapper.getAlarmNum(uId); |
| | | return powerAlarmNum; |
| | | } |
| | | |
| | | //通信电源告警--认证送检-配电柜专用 |
| | | public Response getAllPage2(PwrdevAlarm pwrdevAlarm) { |
| | | //分页信息 |
| | | PageHelper.startPage(pwrdevAlarm.getPage().getPageCurr(), pwrdevAlarm.getPage().getPageSize()); |
| | | pwrdevAlarm.setUsrId(ActionUtil.getUser().getUId().intValue()); |
| | | List<PwrdevAlarm> list=mapper.getAllPage2(pwrdevAlarm); |
| | | List<PwrdevAlarm> list = mapper.getAllPage2(pwrdevAlarm); |
| | | List<String> tableList = paramMapper.getParamList(); |
| | | //取第一条记录,即param表 |
| | | String alarmParamTableName = tableList.get(0); |
| | | List<PwrdevAlarmParam> paramList=paramMapper.searchAll(alarmParamTableName); |
| | | //List<PwrdevAlarmParam> paramList = paramMapper.searchAll(alarmParamTableName); |
| | | List<PwrdevAlarmParam> paramList=subService.searchAll(alarmParamTableName); |
| | | for (PwrdevAlarm p:list) { |
| | | int almType = p.getAlmType(); |
| | | AtomicBoolean matchFlag = new AtomicBoolean(false); |
| | |
| | | int alarmIndex = p.getAlmIndex(); |
| | | if(alarmIndex!=0){ |
| | | p.setAlmIndex(alarmIndex); |
| | | p.setAlarmName(p.getAlarmName().replace("N","第"+alarmIndex+"路")); |
| | | p.setAlarmName(p.getAlarmName().replace("N",alarmIndex+"")); |
| | | } |
| | | } |
| | | PageInfo pageInfo=new PageInfo(list); |
| | |
| | | List<String> tableList = paramMapper.getParamList(); |
| | | //取第一条记录,即param表 |
| | | String alarmParamTableName = tableList.get(0); |
| | | List<PwrdevAlarmParam> paramList=paramMapper.searchAll(alarmParamTableName); |
| | | //List<PwrdevAlarmParam> paramList=paramMapper.searchAll(alarmParamTableName); |
| | | List<PwrdevAlarmParam> paramList=subService.searchAll(alarmParamTableName); |
| | | for (PwrdevAlarm p:list) { |
| | | int almType = p.getAlmType(); |
| | | AtomicBoolean matchFlag = new AtomicBoolean(false); |
| | |
| | | int alarmIndex = p.getAlmIndex(); |
| | | if (alarmIndex != 0) { |
| | | p.setAlmIndex(alarmIndex); |
| | | p.setAlarmName(p.getAlarmName().replace("N", "第" + alarmIndex + "路")); |
| | | p.setAlarmName(p.getAlarmName().replace("N", alarmIndex + "")); |
| | | } |
| | | } |
| | | PageInfo pageInfo = new PageInfo(list); |
| | | return new Response().set(1, pageInfo); |
| | | } |
| | | |
| | | |
| | | //通信电源告警--认证送检-配电柜专用-webSocket |
| | | public Response getAllPage2OfWebSocket_pid(PwrdevAlarm pwrdevAlarm) { |
| | | //分页信息 |
| | | PageHelper.startPage(pwrdevAlarm.getPage().getPageCurr(), pwrdevAlarm.getPage().getPageSize()); |
| | | List<PwrdevAlarm> list=mapper.getAllPage2(pwrdevAlarm); |
| | | for (PwrdevAlarm p:list) { |
| | | int almType = p.getAlmType(); |
| | | AtomicBoolean matchFlag = new AtomicBoolean(false); |
| | | String alarmParamTableName="tb_pwrdev_alarm_param_"+p.getPowerDeviceId(); |
| | | List<PwrdevAlarmParam> paramList=subService.searchAll(alarmParamTableName); |
| | | if(paramList!=null){ |
| | | paramList.stream().forEach(param->{ |
| | | if(param.getAlarmId() == almType){ |
| | | p.setAlarmName(param.getAlarmName()); |
| | | matchFlag.set(true); |
| | | return; |
| | | } |
| | | }); |
| | | } |
| | | if (!matchFlag.get()) { |
| | | p.setAlarmName("未知告警类型"); |
| | | } |
| | | int alarmIndex = p.getAlmIndex(); |
| | | if (alarmIndex != 0) { |
| | | p.setAlmIndex(alarmIndex); |
| | | p.setAlarmName(p.getAlarmName().replace("N", alarmIndex + "")); |
| | | } |
| | | } |
| | | PageInfo pageInfo = new PageInfo(list); |
| | | return new Response().set(1, pageInfo); |
| | | } |
| | | /** |
| | | * |
| | | * @param userId |
| | |
| | | * @return |
| | | * @param userId |
| | | */ |
| | | public Response<List> getAcABCAnalysis(int userId){ |
| | | public Response getAcABCAnalysis(int userId){ |
| | | |
| | | //交流A/B/C-过压, |
| | | //交流A/B/C-欠压, |
| | |
| | | resultMap.put("欠压",0); |
| | | resultMap.put("缺相",0); |
| | | resultMap.put("过流",0); |
| | | try { |
| | | List<Integer> types = Arrays.asList( |
| | | AlarmConstant.acIn1_over_volA, |
| | | AlarmConstant.acIn1_over_volB, |
| | | AlarmConstant.acIn1_over_volC, |
| | | AlarmConstant.acIn1_under_volA, |
| | | AlarmConstant.acIn1_under_volB, |
| | | AlarmConstant.acIn1_under_volC, |
| | | AlarmConstant.acIn1_less_A, |
| | | AlarmConstant.acIn1_less_B, |
| | | AlarmConstant.acIn1_less_C, |
| | | AlarmConstant.acb1_over_currA, |
| | | AlarmConstant.acb1_over_currB, |
| | | AlarmConstant.acb1_over_currC); |
| | | |
| | | List<Integer> types = Arrays.asList( |
| | | AlarmConstant.acIn1_over_volA, |
| | | AlarmConstant.acIn1_over_volB, |
| | | AlarmConstant.acIn1_over_volC, |
| | | AlarmConstant.acIn1_under_volA, |
| | | AlarmConstant.acIn1_under_volB, |
| | | AlarmConstant.acIn1_under_volC, |
| | | AlarmConstant.acIn1_less_A, |
| | | AlarmConstant.acIn1_less_B, |
| | | AlarmConstant.acIn1_less_C, |
| | | AlarmConstant.acb1_over_currA, |
| | | AlarmConstant.acb1_over_currB, |
| | | AlarmConstant.acb1_over_currC); |
| | | List<PwrdevAlarm> data = mapper.getAnalysis(userId, types); |
| | | |
| | | List<PwrdevAlarm> data = mapper.getAnalysis(userId,types); |
| | | for (int i = 0; i < data.size(); i++) { |
| | | switch (data.get(i).getAlmType()) { |
| | | case AlarmConstant.acIn1_over_volA: |
| | | case AlarmConstant.acIn1_over_volB: |
| | | case AlarmConstant.acIn1_over_volC: |
| | | resultMap.put("过压", resultMap.get("过压") + data.get(i).getNum().intValue()); |
| | | break; |
| | | case AlarmConstant.acIn1_under_volA: |
| | | case AlarmConstant.acIn1_under_volB: |
| | | case AlarmConstant.acIn1_under_volC: |
| | | resultMap.put("欠压", resultMap.get("欠压") + data.get(i).getNum().intValue()); |
| | | break; |
| | | case AlarmConstant.acIn1_less_A: |
| | | case AlarmConstant.acIn1_less_B: |
| | | case AlarmConstant.acIn1_less_C: |
| | | resultMap.put("缺相", resultMap.get("缺相") + data.get(i).getNum().intValue()); |
| | | break; |
| | | case AlarmConstant.acb1_over_currA: |
| | | case AlarmConstant.acb1_over_currB: |
| | | case AlarmConstant.acb1_over_currC: |
| | | resultMap.put("过流", resultMap.get("过流") + data.get(i).getNum().intValue()); |
| | | break; |
| | | default: |
| | | } |
| | | |
| | | for (int i = 0; i < data.size(); i++) { |
| | | switch (data.get(i).getAlmType()){ |
| | | case AlarmConstant.acIn1_over_volA: |
| | | case AlarmConstant.acIn1_over_volB: |
| | | case AlarmConstant.acIn1_over_volC: |
| | | resultMap.put("过压",resultMap.get("过压")+data.get(i).getNum().intValue()); |
| | | break; |
| | | case AlarmConstant.acIn1_under_volA: |
| | | case AlarmConstant.acIn1_under_volB: |
| | | case AlarmConstant.acIn1_under_volC: |
| | | resultMap.put("欠压",resultMap.get("欠压")+data.get(i).getNum().intValue()); |
| | | break; |
| | | case AlarmConstant.acIn1_less_A: |
| | | case AlarmConstant.acIn1_less_B: |
| | | case AlarmConstant.acIn1_less_C: |
| | | resultMap.put("缺相",resultMap.get("缺相")+data.get(i).getNum().intValue()); |
| | | break; |
| | | case AlarmConstant.acb1_over_currA: |
| | | case AlarmConstant.acb1_over_currB: |
| | | case AlarmConstant.acb1_over_currC: |
| | | resultMap.put("过流",resultMap.get("过流")+data.get(i).getNum().intValue()); |
| | | break; |
| | | default: |
| | | throw new IllegalStateException("Unexpected value: " + data.get(i)); |
| | | } |
| | | |
| | | //告警机房总数和比例 |
| | | HashMap<String, Integer> map2 = new HashMap<>(); |
| | | |
| | | //int alarmStationCount = mapper.getAlarmStationCountSpec(userId,types); |
| | | //int stationCount = infoMapper.getStationCount(userId); |
| | | |
| | | //map2.put("告警机房总数",alarmStationCount); |
| | | //map2.put("告警机房数比例",(int)MathUtil.divide(alarmStationCount,stationCount,2)); |
| | | |
| | | List<Map<String, Integer>> mapList = Arrays.asList(resultMap, map2); |
| | | return new Response<>().setII(1, true, mapList, ""); |
| | | } catch (Exception e) { |
| | | return new Response<>().set(0, false, "发生异常:"+e.getCause()); |
| | | } |
| | | } |
| | | |
| | | //告警机房总数和比例 |
| | | HashMap<String, Integer> map2 = new HashMap<>(); |
| | | //山西晋源特定接口 |
| | | public Response getAcABCAnalysisJY(){ |
| | | |
| | | //int alarmStationCount = mapper.getAlarmStationCountSpec(userId,types); |
| | | //int stationCount = infoMapper.getStationCount(userId); |
| | | //交流A/B/C-过压, |
| | | //交流A/B/C-欠压, |
| | | //交流A/B/C-缺相, |
| | | //交流A/B/C-过流 |
| | | Map<String,Integer> resultMap = new HashMap<>(); |
| | | resultMap.put("过压",0); |
| | | resultMap.put("欠压",0); |
| | | resultMap.put("缺相",0); |
| | | resultMap.put("过流",0); |
| | | try { |
| | | List<Integer> types = Arrays.asList( |
| | | AlarmConstant.acIn1_over_volA, |
| | | AlarmConstant.acIn1_over_volB, |
| | | AlarmConstant.acIn1_over_volC, |
| | | AlarmConstant.acIn1_under_volA, |
| | | AlarmConstant.acIn1_under_volB, |
| | | AlarmConstant.acIn1_under_volC, |
| | | AlarmConstant.acIn1_less_A, |
| | | AlarmConstant.acIn1_less_B, |
| | | AlarmConstant.acIn1_less_C, |
| | | AlarmConstant.acb1_over_currA, |
| | | AlarmConstant.acb1_over_currB, |
| | | AlarmConstant.acb1_over_currC); |
| | | |
| | | //map2.put("告警机房总数",alarmStationCount); |
| | | //map2.put("告警机房数比例",(int)MathUtil.divide(alarmStationCount,stationCount,2)); |
| | | List<PwrdevAlarm> data = mapper.getAnalysisJY(types); |
| | | |
| | | List<Map<String, Integer>> mapList = Arrays.asList(resultMap, map2); |
| | | return new Response<List>().set(1,mapList); |
| | | for (int i = 0; i < data.size(); i++) { |
| | | switch (data.get(i).getAlmType()) { |
| | | case AlarmConstant.acIn1_over_volA: |
| | | case AlarmConstant.acIn1_over_volB: |
| | | case AlarmConstant.acIn1_over_volC: |
| | | resultMap.put("过压", resultMap.get("过压") + data.get(i).getNum().intValue()); |
| | | break; |
| | | case AlarmConstant.acIn1_under_volA: |
| | | case AlarmConstant.acIn1_under_volB: |
| | | case AlarmConstant.acIn1_under_volC: |
| | | resultMap.put("欠压", resultMap.get("欠压") + data.get(i).getNum().intValue()); |
| | | break; |
| | | case AlarmConstant.acIn1_less_A: |
| | | case AlarmConstant.acIn1_less_B: |
| | | case AlarmConstant.acIn1_less_C: |
| | | resultMap.put("缺相", resultMap.get("缺相") + data.get(i).getNum().intValue()); |
| | | break; |
| | | case AlarmConstant.acb1_over_currA: |
| | | case AlarmConstant.acb1_over_currB: |
| | | case AlarmConstant.acb1_over_currC: |
| | | resultMap.put("过流", resultMap.get("过流") + data.get(i).getNum().intValue()); |
| | | break; |
| | | default: |
| | | } |
| | | |
| | | } |
| | | |
| | | //告警机房总数和比例 |
| | | HashMap<String, Integer> map2 = new HashMap<>(); |
| | | List<Map<String, Integer>> mapList = Arrays.asList(resultMap, map2); |
| | | return new Response<>().setII(1, true, mapList, ""); |
| | | } catch (Exception e) { |
| | | return new Response<>().set(0, false, "发生异常:"+e.getCause()); |
| | | } |
| | | } |
| | | |
| | | |
| | | //今日实时告警 |
| | | public Response getPalmToday(int userId) { |
| | | try { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | int ptatolNum = 0; |
| | | Map<String, Integer> pAlmClearMap = new HashMap<>(); |
| | | pAlmClearMap.put("clear0", 0); |
| | | pAlmClearMap.put("clear1", 0); |
| | | List<PwrdevAlarm> pAlmList = mapper.getPalmToday(userId); |
| | | Map<Integer, List<PwrdevAlarm>> pclearedMap = pAlmList.stream().collect(Collectors.groupingBy(PwrdevAlarm::getAlmClearedType)); |
| | | for (Integer cleared : pclearedMap.keySet()) { |
| | | pAlmClearMap.put("clear" + String.valueOf(cleared), pclearedMap.get(cleared).size()); |
| | | ptatolNum += pclearedMap.get(cleared).size(); |
| | | } |
| | | Map<String, Integer> pAlmLevelMap = new HashMap<>(); |
| | | pAlmLevelMap.put("level1", 0); |
| | | pAlmLevelMap.put("level2", 0); |
| | | pAlmLevelMap.put("level3", 0); |
| | | pAlmLevelMap.put("level4", 0); |
| | | Map<Integer, List<PwrdevAlarm>> plevelMap = pAlmList.stream().collect(Collectors.groupingBy(PwrdevAlarm::getAlmLevel)); |
| | | for (Integer level : plevelMap.keySet()) { |
| | | pAlmLevelMap.put("level" + String.valueOf(level), plevelMap.get(level).size()); |
| | | //ptatolNum += plevelMap.get(level).size(); |
| | | } |
| | | map.put("pAlmClearMap", pAlmClearMap); |
| | | map.put("pAlmLevelMap", pAlmLevelMap); |
| | | map.put("ptatolNum", ptatolNum); |
| | | 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<PwrdevAlarm> getListByStationIds(List<String> stationIdList) { |
| | | return mapper.getListByStationIds(stationIdList); |
| | | } |
| | | } |