xufenglei
2018-02-06 5b0347a811a6c948defb5320e71c43173280dfc2
src/main/java/com/moral/service/impl/MonitorPointServiceImpl.java
@@ -9,11 +9,9 @@
import com.github.pagehelper.PageHelper;
import com.moral.common.bean.Constants;
import com.moral.common.bean.PageBean;
import com.moral.common.util.ExampleUtil;
import com.moral.common.util.MyBatisBaseMapUtil;
import com.moral.common.util.*;
import org.springframework.stereotype.Service;
import com.moral.common.util.ValidateUtil;
import com.moral.entity.MonitorPoint;
import com.moral.mapper.MonitorPointMapper;
import com.moral.service.MonitorPointService;
@@ -24,13 +22,36 @@
public class MonitorPointServiceImpl implements MonitorPointService {
    @Resource
    private MonitorPointMapper monitorPointMapper;
    @Resource
    RedisUtils redisUtils;
    private static Class ENTITY_CLASS = MonitorPoint.class;
    @Override
    public List<MonitorPoint> getMonitorPointsByAreaName(Map<String, Object> parameters) {
        ValidateUtil.notNull(parameters.get("areaName"), "param.is.null");
        return monitorPointMapper.getMonitorPointsByAreaName(parameters);
    }
    @Override
    public List<MonitorPoint> queryWithStateByMap(Map<String, Object> params){
        List<MonitorPoint> monitorPointList = monitorPointMapper.selectByMap(params);
        for(MonitorPoint monitorPoint:monitorPointList){
            loadStateFromRedis(monitorPoint);
        }
        return monitorPointList;
    }
    private void loadStateFromRedis(MonitorPoint monitorPoint){
        StringBuilder key = new StringBuilder();
        key.append("*_").append(monitorPoint.getId()).append("_*");
        List<Map> stateList = redisUtils.getList(key.toString(),Map.class);
        int state = -1;
        if(stateList!=null){
            for (Map deviceState:stateList){
                int s =  Integer.parseInt(deviceState.get("state").toString());
                state = s>state&&s<4?s:state;
            }
        }
        state = state==-1?4:state;
        monitorPoint.setState(state);
    }
    @Override
    public PageBean queryByPageBean(PageBean pageBean) {
        Example example = ExampleUtil.generateExample(ENTITY_CLASS,pageBean);
@@ -47,7 +68,7 @@
        return new PageBean(monitorPointList);
    }
    @Override
   public MonitorPoint selectWithRelationById(Integer id){
   public MonitorPoint queryWithRelationById(Integer id){
         Example example = new Example(ENTITY_CLASS);
         example.or().andEqualTo("id",id);
         List<MonitorPoint> monitorPointList = monitorPointMapper.selectWithAreaNameByExample(example);
@@ -57,6 +78,7 @@
    public void addOrModify(MonitorPoint monitorPoint) {
        try{
            if(monitorPoint.getId()==null){
                monitorPoint.setIsDelete(Constants.IS_DELETE_FALSE);
                monitorPointMapper.insertSelective(monitorPoint);
            }else{
                monitorPointMapper.updateByPrimaryKeySelective(monitorPoint);