diff --git a/src/main/java/com/dispose/manager/DisposeDeviceManager.java b/src/main/java/com/dispose/manager/DisposeDeviceManager.java index cc072f94..bb18d7cd 100644 --- a/src/main/java/com/dispose/manager/DisposeDeviceManager.java +++ b/src/main/java/com/dispose/manager/DisposeDeviceManager.java @@ -56,12 +56,6 @@ public interface DisposeDeviceManager { */ List getAllNormalDisposeDevices(); - /** - * Gets all dispose devices. - * - * @return the all dispose devices - */ - List getAllDisposeDevices(); /** * Gets dispose device by id. * diff --git a/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java b/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java index ed4e7089..b073adc4 100644 --- a/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java +++ b/src/main/java/com/dispose/manager/impl/DisposeDeviceManagerImpl.java @@ -66,29 +66,6 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager { } } - // 看看系统中有没有存在相同IP+端口地址的设备,有的话返回失败 - DisposeDevice tDev = disposeDeviceMapper.getDeviceByAddrAndType(dev.getIpAddr(), dev.getIpPort(), - dev.getDeviceType().getValue()); - - if (tDev != null) { - // 如果设备是删除状态,则更新设备信息 - if (tDev.getStatus() == ObjectStatus.DELETED) { - // 重置状态 - dev.setStatus(ObjectStatus.NORMAL); - - MulReturnType ret = upgradeDisposeDevice(dev); - - if (ret.getFirstParam() == ErrorCode.ERR_OK) { - // 同步更新缓存中设备状态 - disposeAbilityRouterService.upgradeDisposeDevice(ret.getSecondParam(), dev.getStatus()); - } - - return ret; - } - - return new MulReturnType<>(ErrorCode.ERR_DEVICEEXISTS, tDev.getId()); - } - // 添加设备到数据库 if (disposeDeviceMapper.addNewDisposeDevice(dev) != 1 || dev.getId() == null) { return new MulReturnType<>(ErrorCode.ERR_DATABASE, -1L); @@ -301,16 +278,6 @@ public class DisposeDeviceManagerImpl implements DisposeDeviceManager { .collect(Collectors.toList()); } - /** - * Gets all dispose devices. - * - * @return the all dispose devices - */ - @Override - public List getAllDisposeDevices() { - return disposeDeviceMapper.selectAll(); - } - /** * Gets dispose device by id. * diff --git a/src/main/java/com/dispose/service/DisposeAbilityRouterService.java b/src/main/java/com/dispose/service/DisposeAbilityRouterService.java index e16bed6a..5cda5dab 100644 --- a/src/main/java/com/dispose/service/DisposeAbilityRouterService.java +++ b/src/main/java/com/dispose/service/DisposeAbilityRouterService.java @@ -65,6 +65,13 @@ public interface DisposeAbilityRouterService { */ void upgradeDisposeDevice(Long id, ObjectStatus objStatus); + /** + * Delete dispose device. + * + * @param dev the dev + */ + void deleteDisposeDevice(DisposeDevice dev); + /** * Run period task. */ diff --git a/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java b/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java index 888853a3..8bf20632 100644 --- a/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DisposeAbilityRouterServiceImpl.java @@ -57,7 +57,7 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ */ @PostConstruct private void initDisposeAbility() { - List devList = disposeDeviceManager.getAllDisposeDevices(); + List devList = disposeDeviceManager.getAllNormalDisposeDevices(); devList.forEach(this::addDisposeAbilityDevice); } @@ -111,6 +111,18 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ } } + /** + * Delete dispose device. + * + * @param dev the dev + */ + @Override + public void deleteDisposeDevice(DisposeDevice dev) { + String hashKey = getAbilityDeviceHashKey(dev.getIpAddr(), dev.getIpPort(), + String.valueOf(dev.getDeviceType())); + disposeAbilityMap.remove(hashKey); + } + /** * Gets all ability devices. * @@ -190,7 +202,7 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ @Override public ErrorCode verifyDisposeCapacity(Long deviceId, String disposeIp, DisposeCapacityType capacityType) { //处置平台无处置设备,直接报错 - if(getAllAbilityDevices().size() == 0 ) { + if (getAllAbilityDevices().size() == 0) { return ErrorCode.ERR_NOTFOUNDDEVICE; } @@ -227,10 +239,10 @@ public class DisposeAbilityRouterServiceImpl implements DisposeAbilityRouterServ DisposeDevice dev = disposeDeviceManager.getDisposeDeviceById(v.getDev().getId()); if (dev == null || !dev.getStatus().equals(ObjectStatus.NORMAL)) { - if(!v.getDev().getStatus().equals(ObjectStatus.DELETED)){ - // 如果数据库中设备不存在,那么删除该设备 - v.getDev().setStatus(ObjectStatus.DELETED); - } + String hashKey = getAbilityDeviceHashKey(v.getDev().getIpAddr(), v.getDev().getIpPort(), + String.valueOf(v.getDev().getDeviceType())); + + disposeAbilityMap.remove(hashKey); } else { v.getDev().setStatus(ObjectStatus.NORMAL); diff --git a/src/main/java/com/dispose/service/impl/DisposeDeviceManagerServiceImpl.java b/src/main/java/com/dispose/service/impl/DisposeDeviceManagerServiceImpl.java index e92e62ad..fc9c1b66 100644 --- a/src/main/java/com/dispose/service/impl/DisposeDeviceManagerServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/DisposeDeviceManagerServiceImpl.java @@ -5,6 +5,7 @@ import com.dispose.common.ObjectStatus; import com.dispose.manager.DisposeDeviceManager; import com.dispose.pojo.entity.DisposeDevice; import com.dispose.pojo.po.MulReturnType; +import com.dispose.service.DisposeAbilityRouterService; import com.dispose.service.DisposeDeviceManagerService; import com.github.pagehelper.PageInfo; import lombok.extern.slf4j.Slf4j; @@ -29,6 +30,9 @@ public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerServ @Resource private DisposeDeviceManager disposeDeviceManager; + @Resource + private DisposeAbilityRouterService disposeAbilityRouterService; + /** * Add dispose device list. * @@ -89,11 +93,14 @@ public class DisposeDeviceManagerServiceImpl implements DisposeDeviceManagerServ DisposeDevice dev = new DisposeDevice(); MulReturnType ret = disposeDeviceManager.changeDisposeDeviceStatus(v, - ObjectStatus.DELETED); + ObjectStatus.DELETED); dev.setId(v); dev.setStatus(ret.getSecondParam()); + // 同步更新缓存中设备状态 + disposeAbilityRouterService.deleteDisposeDevice(dev); + rspList.add(new MulReturnType<>(ret.getFirstParam(), dev)); } diff --git a/src/main/resources/mappers/DisposeDevice.xml b/src/main/resources/mappers/DisposeDevice.xml index 8df95439..1ed86469 100644 --- a/src/main/resources/mappers/DisposeDevice.xml +++ b/src/main/resources/mappers/DisposeDevice.xml @@ -80,6 +80,7 @@ LEFT JOIN dispose_capacity c ON d.id = c.deviceId WHERE d.ipAddr = #{ipAddr} AND d.deviceType = #{devType} + AND d.status = ${@com.dispose.common.ObjectStatus@NORMAL.getValue()}