|
@@ -203,38 +203,31 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
|
|
|
throw new BusinessException("新增门禁设备'" + egDevice.getDeviceName() + "'失败,设备已存在");
|
|
throw new BusinessException("新增门禁设备'" + egDevice.getDeviceName() + "'失败,设备已存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 2. 通过IP校验心跳表,确保设备在线且心跳时间在5分钟内
|
|
|
|
|
- String deviceIp = egDevice.getDeviceIp();
|
|
|
|
|
- if (StringUtils.isNotBlank(deviceIp)) {
|
|
|
|
|
- LambdaQueryWrapper<EgDeviceHeartbeat> heartbeatWrapper = Wrappers.lambdaQuery();
|
|
|
|
|
- heartbeatWrapper.eq(EgDeviceHeartbeat::getIpAddr, deviceIp)
|
|
|
|
|
- .orderByDesc(EgDeviceHeartbeat::getCreateTime)
|
|
|
|
|
- .last("LIMIT 1");
|
|
|
|
|
- EgDeviceHeartbeat heartbeat = egDeviceHeartbeatMapper.selectOne(heartbeatWrapper);
|
|
|
|
|
-
|
|
|
|
|
- // 校验心跳记录存在且时间在5分钟内
|
|
|
|
|
- if (heartbeat == null || heartbeat.getCreateTime() == null
|
|
|
|
|
- || !heartbeat.getCreateTime().isAfter(now.minusMinutes(5))) {
|
|
|
|
|
- throw new BusinessException("设备不在线,请检查设备网络是否正常!");
|
|
|
|
|
|
|
+ // 2. 校验设备IP是否已被绑定
|
|
|
|
|
+ if (StringUtils.isNotBlank(egDevice.getDeviceIp())) {
|
|
|
|
|
+ LambdaQueryWrapper<EgDevice> ipCheckWrapper = Wrappers.lambdaQuery();
|
|
|
|
|
+ ipCheckWrapper.eq(EgDevice::getDeviceIp, egDevice.getDeviceIp())
|
|
|
|
|
+ .eq(EgDevice::getTenantId, SecurityUtils.getTenantId());
|
|
|
|
|
+ EgDevice existingDeviceByIp = this.getOne(ipCheckWrapper);
|
|
|
|
|
+ if (existingDeviceByIp != null) {
|
|
|
|
|
+ throw new BusinessException("设备IP'" + egDevice.getDeviceIp() + "'已被设备'"
|
|
|
|
|
+ + existingDeviceByIp.getDeviceName() + "'绑定,请更换IP或检查设备配置!");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 设置设备编码并校验唯一性
|
|
|
|
|
- String deviceCode = heartbeat.getDeviceCode();
|
|
|
|
|
- egDevice.setDeviceCode(deviceCode);
|
|
|
|
|
-
|
|
|
|
|
- if (StringUtils.isNotBlank(deviceCode)) {
|
|
|
|
|
- LambdaQueryWrapper<EgDevice> codeCheckWrapper = Wrappers.lambdaQuery();
|
|
|
|
|
- codeCheckWrapper.eq(EgDevice::getDeviceCode, deviceCode)
|
|
|
|
|
- .eq(EgDevice::getTenantId, SecurityUtils.getTenantId());
|
|
|
|
|
- EgDevice existingDevice = this.getOne(codeCheckWrapper);
|
|
|
|
|
- if (existingDevice != null) {
|
|
|
|
|
- throw new BusinessException("设备已被设备'" + existingDevice.getDeviceName()
|
|
|
|
|
- + "'注册使用,请检查设备配置或更换设备IP!");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 校验设备编码是否已被绑定
|
|
|
|
|
+ if (StringUtils.isNotBlank(egDevice.getDeviceCode())) {
|
|
|
|
|
+ LambdaQueryWrapper<EgDevice> codeCheckWrapper = Wrappers.lambdaQuery();
|
|
|
|
|
+ codeCheckWrapper.eq(EgDevice::getDeviceCode, egDevice.getDeviceCode())
|
|
|
|
|
+ .eq(EgDevice::getTenantId, SecurityUtils.getTenantId());
|
|
|
|
|
+ EgDevice existingDeviceByCode = this.getOne(codeCheckWrapper);
|
|
|
|
|
+ if (existingDeviceByCode != null) {
|
|
|
|
|
+ throw new BusinessException("设备编码'" + egDevice.getDeviceCode() + "'已被设备'"
|
|
|
|
|
+ + existingDeviceByCode.getDeviceName() + "'绑定,请更换设备编码或检查设备配置!");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 3. 设置设备基本信息
|
|
|
|
|
|
|
+ // 4. 设置设备基本信息
|
|
|
egDevice.setDeviceUuid(UUIDUtils.uuid());
|
|
egDevice.setDeviceUuid(UUIDUtils.uuid());
|
|
|
egDevice.setCreateBy(SecurityUtils.getUsername());
|
|
egDevice.setCreateBy(SecurityUtils.getUsername());
|
|
|
egDevice.setCreateTime(now);
|
|
egDevice.setCreateTime(now);
|
|
@@ -242,10 +235,10 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
|
|
|
egDevice.setOpenMode("人脸");
|
|
egDevice.setOpenMode("人脸");
|
|
|
egDevice.setWorkStatus("4");
|
|
egDevice.setWorkStatus("4");
|
|
|
|
|
|
|
|
- // 4. 保存设备
|
|
|
|
|
|
|
+ // 5. 保存设备
|
|
|
this.save(egDevice);
|
|
this.save(egDevice);
|
|
|
|
|
|
|
|
- // 5. 处理绑定人脸信息
|
|
|
|
|
|
|
+ // 6. 处理绑定人脸信息
|
|
|
String bindFace = egDevice.getBindFace();
|
|
String bindFace = egDevice.getBindFace();
|
|
|
if (StringUtils.isNotBlank(bindFace)) {
|
|
if (StringUtils.isNotBlank(bindFace)) {
|
|
|
String[] fids = bindFace.split(",");
|
|
String[] fids = bindFace.split(",");
|
|
@@ -256,7 +249,7 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 6. 异步调用远程服务添加设备信息,静默处理异常,不影响设备保存成功
|
|
|
|
|
|
|
+ // 7. 异步调用远程服务添加设备信息,静默处理异常,不影响设备保存成功
|
|
|
String deviceUuid = egDevice.getDeviceUuid();
|
|
String deviceUuid = egDevice.getDeviceUuid();
|
|
|
String deviceName = egDevice.getDeviceName();
|
|
String deviceName = egDevice.getDeviceName();
|
|
|
if (StringUtils.isNotBlank(deviceUuid) && StringUtils.isNotBlank(deviceName)) {
|
|
if (StringUtils.isNotBlank(deviceUuid) && StringUtils.isNotBlank(deviceName)) {
|
|
@@ -297,42 +290,32 @@ public class EgDeviceServiceImpl extends AbstractCrudService<EgDeviceMapper, EgD
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if(checkDeviceNameUnique(egDevice)){
|
|
if(checkDeviceNameUnique(egDevice)){
|
|
|
- throw new BusinessException("新增门禁设备'"+egDevice.getDeviceName()+"'失败,设备已存在");
|
|
|
|
|
|
|
+ throw new BusinessException("修改门禁设备'"+egDevice.getDeviceName()+"'失败,设备名称已存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 通过IP校验心跳表中的IP是否一致并且心跳时间必须在五分钟之内
|
|
|
|
|
- if(StringUtils.isNotBlank(egDevice.getDeviceIp())){
|
|
|
|
|
- LambdaQueryWrapper<EgDeviceHeartbeat> heartbeatQueryWrapper = Wrappers.lambdaQuery();
|
|
|
|
|
- heartbeatQueryWrapper.eq(EgDeviceHeartbeat::getIpAddr, egDevice.getDeviceIp())
|
|
|
|
|
- .orderByDesc(EgDeviceHeartbeat::getCreateTime)
|
|
|
|
|
- .last("LIMIT 1");
|
|
|
|
|
- EgDeviceHeartbeat heartbeat = egDeviceHeartbeatMapper.selectOne(heartbeatQueryWrapper);
|
|
|
|
|
-
|
|
|
|
|
- // 如果找不到心跳记录,抛出异常
|
|
|
|
|
- if(heartbeat == null){
|
|
|
|
|
- throw new BusinessException("设备不在线,请检查设备网络是否正常!");
|
|
|
|
|
|
|
+ // 校验设备IP是否已被其他设备绑定(排除当前设备)
|
|
|
|
|
+ if (StringUtils.isNotBlank(egDevice.getDeviceIp())) {
|
|
|
|
|
+ LambdaQueryWrapper<EgDevice> ipCheckWrapper = Wrappers.lambdaQuery();
|
|
|
|
|
+ ipCheckWrapper.eq(EgDevice::getDeviceIp, egDevice.getDeviceIp())
|
|
|
|
|
+ .eq(EgDevice::getTenantId, SecurityUtils.getTenantId())
|
|
|
|
|
+ .ne(EgDevice::getId, egDevice.getId());
|
|
|
|
|
+ EgDevice existingDeviceByIp = this.getOne(ipCheckWrapper);
|
|
|
|
|
+ if (existingDeviceByIp != null) {
|
|
|
|
|
+ throw new BusinessException("设备IP'" + egDevice.getDeviceIp() + "'已被设备'"
|
|
|
|
|
+ + existingDeviceByIp.getDeviceName() + "'绑定,请更换IP或检查设备配置!");
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 检查心跳时间是否在5分钟内
|
|
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
- LocalDateTime heartbeatTime = heartbeat.getCreateTime();
|
|
|
|
|
- if(heartbeatTime == null || !heartbeatTime.isAfter(now.minusMinutes(5))){
|
|
|
|
|
- throw new BusinessException("设备不在线,请检查设备网络是否正常!");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 校验通过
|
|
|
|
|
- egDevice.setDeviceCode(heartbeat.getDeviceCode());
|
|
|
|
|
-
|
|
|
|
|
- // 校验DeviceCode是否已经被其他设备使用(排除当前设备自己)
|
|
|
|
|
- if(StringUtils.isNotBlank(egDevice.getDeviceCode())){
|
|
|
|
|
- LambdaQueryWrapper<EgDevice> deviceCodeCheckQueryWrapper = Wrappers.lambdaQuery();
|
|
|
|
|
- deviceCodeCheckQueryWrapper.eq(EgDevice::getDeviceCode, egDevice.getDeviceCode())
|
|
|
|
|
- .eq(EgDevice::getTenantId, SecurityUtils.getTenantId())
|
|
|
|
|
- .ne(EgDevice::getId, egDevice.getId());
|
|
|
|
|
- EgDevice existingDevice = this.getOne(deviceCodeCheckQueryWrapper);
|
|
|
|
|
- if(existingDevice != null){
|
|
|
|
|
- throw new BusinessException("设备编码'" + egDevice.getDeviceCode() + "'已被设备'" + existingDevice.getDeviceName() + "'使用,请检查设备配置");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 校验设备编码是否已被其他设备绑定(排除当前设备)
|
|
|
|
|
+ if (StringUtils.isNotBlank(egDevice.getDeviceCode())) {
|
|
|
|
|
+ LambdaQueryWrapper<EgDevice> codeCheckWrapper = Wrappers.lambdaQuery();
|
|
|
|
|
+ codeCheckWrapper.eq(EgDevice::getDeviceCode, egDevice.getDeviceCode())
|
|
|
|
|
+ .eq(EgDevice::getTenantId, SecurityUtils.getTenantId())
|
|
|
|
|
+ .ne(EgDevice::getId, egDevice.getId());
|
|
|
|
|
+ EgDevice existingDeviceByCode = this.getOne(codeCheckWrapper);
|
|
|
|
|
+ if (existingDeviceByCode != null) {
|
|
|
|
|
+ throw new BusinessException("设备编码'" + egDevice.getDeviceCode() + "'已被设备'"
|
|
|
|
|
+ + existingDeviceByCode.getDeviceName() + "'绑定,请更换设备编码或检查设备配置!");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|