|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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()); | 
|---|