|
|
@@ -2,29 +2,40 @@ package com.xunmei.iot.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.xunmei.common.core.constant.Constants;
|
|
|
+import com.xunmei.common.core.constant.RedisConstant;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
import com.xunmei.common.core.domain.iot.domain.IotServerProduct;
|
|
|
import com.xunmei.common.core.enums.iot.BaseDeviceTypeEnum;
|
|
|
+import com.xunmei.common.core.utils.DateUtils;
|
|
|
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.EditDvrHostDeviceDto;
|
|
|
import com.xunmei.iot.dto.deviceInfo.IotDeviceInfoPageDto;
|
|
|
import com.xunmei.iot.mapper.IotAlarmSubsystemMapper;
|
|
|
import com.xunmei.iot.mapper.IotDeviceInfoMapper;
|
|
|
import com.xunmei.iot.mapper.IotServerProductMapper;
|
|
|
import com.xunmei.iot.service.IIotDeviceInfoService;
|
|
|
+import com.xunmei.iot.service.IotDeviceInfoExtendService;
|
|
|
import com.xunmei.iot.vo.deviceInfo.DeviceDetailInfoVo;
|
|
|
import com.xunmei.iot.vo.deviceInfo.IotDeviceInfoPageVo;
|
|
|
import com.xunmei.system.api.RemoteOrgService;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
import com.xunmei.system.api.domain.iot.IotDeviceInfo;
|
|
|
+import org.redisson.api.RLock;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.Serializable;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@Service
|
|
|
public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, IotDeviceInfo> implements IIotDeviceInfoService {
|
|
|
@@ -36,6 +47,8 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
|
|
|
@Resource
|
|
|
private IotServerProductMapper productMapper;
|
|
|
+ @Resource
|
|
|
+ private IotDeviceInfoExtendService extendService;
|
|
|
|
|
|
@Override
|
|
|
public TableDataInfo<IotDeviceInfoPageVo> deviceInfoPage(IotDeviceInfoPageDto request) {
|
|
|
@@ -119,4 +132,65 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
wrapper.like(IotServerProduct::getName, type);
|
|
|
return productMapper.selectList(wrapper);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String generalDeviceCode() {
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException("生成设备编码失败");
|
|
|
+ } finally {
|
|
|
+ if (lock.isHeldByCurrentThread()) {
|
|
|
+ lock.unlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ throw new RuntimeException("生成设备编码失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer editDvrHostDevice(EditDvrHostDeviceDto req) {
|
|
|
+ Long deviceId = req.getId();
|
|
|
+ SysOrg sysOrg = orgService.selectOrgById(req.getOrgId(), SecurityConstants.INNER);
|
|
|
+ int effect = 0;
|
|
|
+ if (deviceId == null) {
|
|
|
+ IotDeviceInfo deviceInfo = new IotDeviceInfo();
|
|
|
+ buildDeviceInfo(deviceInfo, req, sysOrg);
|
|
|
+ deviceInfo.setId(IdWorker.getId());
|
|
|
+ deviceInfo.setCreateTime(new Date());
|
|
|
+ deviceInfo.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getId().toString());
|
|
|
+ effect = baseMapper.insert(deviceInfo);
|
|
|
+ deviceId = deviceInfo.getId();
|
|
|
+ } else {
|
|
|
+ IotDeviceInfo deviceInfo = baseMapper.selectById(deviceId);
|
|
|
+ if (deviceInfo != null) {
|
|
|
+ buildDeviceInfo(deviceInfo, req, sysOrg);
|
|
|
+ }
|
|
|
+ effect = baseMapper.updateById(deviceInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ extendService.updateByDeviceId(deviceId, req);
|
|
|
+
|
|
|
+ return effect;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void buildDeviceInfo(IotDeviceInfo deviceInfo, EditDvrHostDeviceDto req, SysOrg sysOrg) {
|
|
|
+ deviceInfo.setDeviceName(req.getDeviceName());
|
|
|
+ deviceInfo.setDeviceType(BaseDeviceTypeEnum.Dvs.getCode());
|
|
|
+ deviceInfo.setDeviceProduct(req.getDeviceProduct());
|
|
|
+ deviceInfo.setDeviceCode(generalDeviceCode());
|
|
|
+ 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());
|
|
|
+ }
|
|
|
}
|