|
|
@@ -1,6 +1,7 @@
|
|
|
package com.xunmei.iot.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
@@ -15,6 +16,7 @@ import com.xunmei.common.core.utils.StringUtils;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
+import com.xunmei.iot.dto.deviceInfo.EditAlarmHostDeviceDto;
|
|
|
import com.xunmei.iot.dto.deviceInfo.EditDvrHostDeviceDto;
|
|
|
import com.xunmei.iot.dto.deviceInfo.IotDeviceInfoPageDto;
|
|
|
import com.xunmei.iot.mapper.IotAlarmSubsystemMapper;
|
|
|
@@ -134,13 +136,20 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String generalDeviceCode() {
|
|
|
+ public String generalDeviceCode(BaseDeviceTypeEnum typeEnum, JSONObject jsb) {
|
|
|
RedissonClient client = RedisUtils.getClient();
|
|
|
RLock lock = client.getLock(RedisConstant.GENERAL_DEVICE_CODE);
|
|
|
try {
|
|
|
boolean tryLock = lock.tryLock(10, 10, TimeUnit.SECONDS);
|
|
|
if (tryLock) {
|
|
|
- return "PT_" + DateUtils.parseDateToStr("yyyyMMddHHmmssSSS", new Date());
|
|
|
+ switch (typeEnum) {
|
|
|
+ case Dvs:
|
|
|
+ return "PT_" + DateUtils.parseDateToStr("yyyyMMddHHmmssSSS", new Date());
|
|
|
+ case AlarmHost:
|
|
|
+ //DaHuaAlarmHost1729673859287
|
|
|
+ return jsb.getString("deviceProduct") + System.currentTimeMillis();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
} catch (InterruptedException e) {
|
|
|
throw new RuntimeException("生成设备编码失败");
|
|
|
@@ -182,7 +191,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
deviceInfo.setDeviceName(req.getDeviceName());
|
|
|
deviceInfo.setDeviceType(BaseDeviceTypeEnum.Dvs.getCode());
|
|
|
deviceInfo.setDeviceProduct(req.getDeviceProduct());
|
|
|
- deviceInfo.setDeviceCode(generalDeviceCode());
|
|
|
+ if (ObjectUtil.isEmpty(deviceInfo.getDeviceCode())){
|
|
|
+ deviceInfo.setDeviceCode(generalDeviceCode(BaseDeviceTypeEnum.Dvs, null));
|
|
|
+ }
|
|
|
deviceInfo.setDeviceModel(req.getModels());
|
|
|
deviceInfo.setIotToken(req.getIotCode());
|
|
|
deviceInfo.setOrgId(req.getOrgId());
|
|
|
@@ -193,4 +204,38 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
deviceInfo.setOrgName(sysOrg.getShortName());
|
|
|
deviceInfo.setOrgPath(sysOrg.getPath());
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer editAlarmHostDevice(EditAlarmHostDeviceDto req) {
|
|
|
+ Long deviceId = req.getId();
|
|
|
+ SysOrg sysOrg = orgService.selectOrgById(req.getOrgId(), SecurityConstants.INNER);
|
|
|
+ if (deviceId == null) {
|
|
|
+ addAlarmHostDevice(req, sysOrg);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addAlarmHostDevice(EditAlarmHostDeviceDto req, SysOrg sysOrg) {
|
|
|
+ final IotDeviceInfo deviceInfo = new IotDeviceInfo();
|
|
|
+ deviceInfo.setDeviceName(req.getDeviceName());
|
|
|
+ deviceInfo.setDeviceType(BaseDeviceTypeEnum.AlarmHost.getCode());
|
|
|
+ deviceInfo.setDeviceProduct(req.getDeviceProduct());
|
|
|
+ if (ObjectUtil.isEmpty(deviceInfo.getDeviceCode())){
|
|
|
+ final JSONObject object = new JSONObject();
|
|
|
+ object.put("deviceProduct", req.getDeviceProduct()+"_");
|
|
|
+ deviceInfo.setDeviceCode(generalDeviceCode(BaseDeviceTypeEnum.AlarmHost,object));
|
|
|
+ }
|
|
|
+ deviceInfo.setDeviceModel(req.getModels());
|
|
|
+ deviceInfo.setIotToken(req.getIotCode());
|
|
|
+ deviceInfo.setOrgId(req.getOrgId());
|
|
|
+ deviceInfo.setEnable(req.getEnable());
|
|
|
+ deviceInfo.setDeleted(0);
|
|
|
+ deviceInfo.setUpdateTime(new Date());
|
|
|
+ deviceInfo.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getName());
|
|
|
+ deviceInfo.setOrgName(sysOrg.getShortName());
|
|
|
+ deviceInfo.setOrgPath(sysOrg.getPath());
|
|
|
+
|
|
|
+ }
|
|
|
}
|