fengxiang
2018-06-14 bde2512a915e394ab6f3939833469516c473ee0e
src/main/java/com/moral/service/impl/DeviceServiceImpl.java
@@ -376,18 +376,27 @@
   }
   @Override
   @Transactional
   public void addOrModify(Device device){
      try{
         //mac 转小写
         if(!StringUtils.isBlank(device.getMac())){
            device.setMac(device.getMac().toLowerCase());
         }
         if(device.getId()==null){
            device.setState(Constants.DEVICE_STATE_OFFLINE);
            device.setIsDelete(Constants.IS_DELETE_FALSE);
            deviceMapper.insertSelective(device);
         }else{
         if(device.getId()!=null){
            deviceMapper.updateByPrimaryKeySelective(device);
         }else{
            Device deviceQuery = new Device();
            deviceQuery.setMac(device.getMac());
            Device deviceResult = deviceMapper.selectOne(deviceQuery);
            if(deviceResult !=null){
               device.setId(deviceResult.getId());
               deviceMapper.updateByPrimaryKeySelective(device);
            }else {
               device.setState(Constants.DEVICE_STATE_OFFLINE);
               device.setIsDelete(Constants.IS_DELETE_FALSE);
               deviceMapper.insertSelective(device);
            }
         }
         //刷新redis里设备信息
         refreshDeviceInRedis(device.getMac());