fengxiang
2018-07-12 6d1509ab9e5aa911a6a2cdc2ab5a0887210f0b41
src/main/java/com/moral/service/impl/DeviceServiceImpl.java
@@ -13,6 +13,8 @@
import com.moral.common.exception.BusinessException;
import com.moral.common.util.ExampleUtil;
import com.moral.common.util.RedisUtils;
import com.moral.entity.DeviceVersion;
import com.moral.mapper.DeviceVersionMapper;
import com.moral.mapper.MonitorPointMapper;
import com.moral.mapper.OrganizationMapper;
import org.apache.commons.collections.MapUtils;
@@ -58,6 +60,8 @@
    private Class ENTITY_CLASS = Device.class;
    @Resource
   OrganizationMapper orgMapper;
    @Resource
   DeviceVersionMapper deviceVersionMapper;
   @Resource
   RedisUtils redisUtils;
   @Override
@@ -173,6 +177,7 @@
      simpleDevice.setMac(device.getMac()); // mac
      simpleDevice.setMonitorPointId(device.getMonitorPointId());// 监控地id
      simpleDevice.setOrganizationIds(device.getOrganizationIds());// 组织数组
      simpleDevice.setDeviceVersion(device.getDeviceVersion());
      redisUtils.set(key,simpleDevice);
   }
   private Device getDeviceFromRedis(String mac) {
@@ -310,15 +315,8 @@
    */
   private void refreshDeviceInRedis(String mac){
        if(!StringUtils.isBlank(mac)){
            Device devQuery = new Device();
            devQuery.setMac(mac);
            Device device = deviceMapper.selectOne(devQuery);
            if(device.getMonitorPointId()!=null){
               List<Integer> orgIds = monitorPointMapper.selectOrganizationIds(device.getMonitorPointId());
               device.setOrganizationIds(orgIds);
          }
             String key = "device_"+mac;
             redisUtils.set(key,device);
            Device device = deviceMapper.selectWithOrgIdsByMac(mac);
          setDeviceToRedis(mac,device);
         }else
       {
          log.warn("param mac is null in method [refreshDeviceInRedis]");
@@ -348,12 +346,12 @@
   @Override
   public PageBean queryByPageBean(PageBean pageBean) {
      Example example = ExampleUtil.generateExample(ENTITY_CLASS,pageBean);
      addDeletesToExample(example);
//      addDeletesToExample(example);
      if(pageBean.getPageSize()>0){
         PageHelper.startPage(pageBean.getPageIndex(),pageBean.getPageSize());
      }
      List<Device> organizationList = deviceMapper.selectWithRelationData(example);
      return new PageBean(organizationList);
      List<Device> deviceList = deviceMapper.selectWithRelationData(example);
      return new PageBean(deviceList);
   }
   @Override
@@ -476,4 +474,10 @@
      return deviceMapper.getDevicesByProfession(parameters);
   }
   @Override
   public List<Device> getDevicesByOrganizationId(Map<String, Object> parameters) {
      ValidateUtil.notNull(parameters.get("organizationId"), "param.is.null");
      return deviceMapper.getDevicesByOrganizationId(parameters);
   }
}