| | |
| | | package com.moral.service.impl;
|
| | |
|
| | | import java.util.Arrays;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.stream.Collectors;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | |
| | | public List<MonitorPoint> queryWithStateByMap(Map<String, Object> params){
|
| | | List<MonitorPoint> monitorPointList = monitorPointMapper.selectByMap(params);
|
| | | for(MonitorPoint monitorPoint:monitorPointList){
|
| | | loadStateFromRedis(monitorPoint);
|
| | | Integer state = getStateFromRedis(monitorPoint.getId());
|
| | | monitorPoint.setState(state);
|
| | | }
|
| | | return monitorPointList;
|
| | | }
|
| | | private void loadStateFromRedis(MonitorPoint monitorPoint){
|
| | | private Integer getStateFromRedis(Integer monitorPointId){
|
| | | StringBuilder key = new StringBuilder();
|
| | | key.append("*_").append(monitorPoint.getId()).append("_*");
|
| | | key.append("state_").append(monitorPointId).append("_*");
|
| | | List<Map> stateList = redisUtils.getList(key.toString(),Map.class);
|
| | | int state = -1;
|
| | | if(stateList!=null){
|
| | |
| | | }
|
| | | }
|
| | | state = state==-1?4:state;
|
| | | monitorPoint.setState(state);
|
| | | return state;
|
| | | }
|
| | | @Override
|
| | | public PageBean queryByPageBean(PageBean pageBean) {
|
| | |
| | | List<MonitorPoint> monitorPoints = monitorPointMapper.selectByExample(example);
|
| | | return monitorPoints;
|
| | | }
|
| | |
|
| | | /**
|
| | | *
|
| | | * @param idList
|
| | | * @return {id:,state:}
|
| | | */
|
| | | @Override
|
| | | public List<Map<String, String>> queryMonitroPointsState(List<Integer> idList) {
|
| | | List<Map<String, String>> list = idList.stream().map( id -> {
|
| | | Integer state = getStateFromRedis(id);
|
| | | Map<String,String> stateMap = new HashMap<>();
|
| | | stateMap.put("id",id.toString());
|
| | | stateMap.put("state",state.toString());
|
| | | return stateMap;
|
| | | }).collect(Collectors.toList());
|
| | | return list;
|
| | | }
|
| | | }
|