| | |
| | | }
|
| | |
|
| | | @Override
|
| | | @Transactional
|
| | | public void addOrModify(Device device){
|
| | | try{
|
| | | //mac 转小写
|
| | | if(!StringUtils.isBlank(device.getMac())){
|
| | | device.setMac(device.getMac().toLowerCase());
|
| | | }
|
| | | if(device.getId()==null){
|
| | | 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);
|
| | | }else{
|
| | | deviceMapper.updateByPrimaryKeySelective(device);
|
| | | }
|
| | | }
|
| | | //刷新redis里设备信息
|
| | | refreshDeviceInRedis(device.getMac());
|