|
|
@@ -49,27 +49,34 @@ public class AccessControlService {
|
|
|
public void save(AccessControl accessControl) {
|
|
|
AccessControl oldOne = accessControlRepository.findByIpAndPort(accessControl.getIp(),
|
|
|
accessControl.getPort());
|
|
|
+ boolean isNew = StringUtils.isEmpty(accessControl.getId());
|
|
|
if (null != oldOne) {
|
|
|
- if (StringUtils.isEmpty(accessControl.getId())) {
|
|
|
+ if (isNew) {
|
|
|
accessControl.setId(oldOne.getId());
|
|
|
} else if (!accessControl.getId().equals(oldOne.getId())) {
|
|
|
ExceptionCode.ERROR_IP_PORT_EXIST.occur();
|
|
|
}
|
|
|
- accessControlRepository.update(accessControl);
|
|
|
+ } else {
|
|
|
+ if (isNew) {
|
|
|
+ accessControl.setId(RandomUtils.randomString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isNew) {
|
|
|
+ // 调用设备接口监听
|
|
|
+ deviceApi.add(accessControl);
|
|
|
+ accessControlRepository.save(accessControl);
|
|
|
+ } else {
|
|
|
+ oldOne = accessControlRepository.findById(accessControl.getId());
|
|
|
if (!oldOne.getIp().equals(accessControl.getIp()) || oldOne.getPort() != accessControl.getPort() ||
|
|
|
!oldOne.getUsername().equals(accessControl.getUsername()) ||
|
|
|
- !oldOne.getPassword().equals(accessControl.getPassword())) {
|
|
|
- // 先调用设备接口停止监听
|
|
|
- deviceApi.remove(accessControl);
|
|
|
+ !oldOne.getPassword().equals(accessControl.getPassword())) {
|
|
|
// 调用设备接口监听
|
|
|
deviceApi.add(accessControl);
|
|
|
+ // 调用设备接口停止监听
|
|
|
+ deviceApi.remove(oldOne);
|
|
|
}
|
|
|
-
|
|
|
- } else {
|
|
|
- accessControl.setId(RandomUtils.randomString());
|
|
|
- accessControlRepository.save(accessControl);
|
|
|
- // 调用设备接口监听
|
|
|
- deviceApi.add(accessControl);
|
|
|
+ accessControlRepository.update(accessControl);
|
|
|
}
|
|
|
}
|
|
|
|