|
|
@@ -3,11 +3,13 @@ package com.xunmei.host.iot.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.xunmei.common.core.constant.Constants;
|
|
|
+import com.xunmei.common.core.domain.iot.domain.IotAlarmDefenceArea;
|
|
|
import com.xunmei.host.iot.mapper.SysDeviceMapper;
|
|
|
import com.xunmei.host.iot.service.SysDeviceService;
|
|
|
import com.xunmei.system.api.domain.SysDevice;
|
|
|
import com.xunmei.system.api.domain.iot.IotDeviceInfo;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
@@ -20,6 +22,7 @@ import java.util.List;
|
|
|
public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice> implements SysDeviceService {
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void addDevice(List<IotDeviceInfo> deviceInfoList) {
|
|
|
for (IotDeviceInfo deviceInfo : deviceInfoList) {
|
|
|
final SysDevice sysDevice = getByBusinessDeviceId(deviceInfo.getId());
|
|
|
@@ -34,6 +37,21 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void addDefenceArea(IotAlarmDefenceArea defenceArea) {
|
|
|
+ final SysDevice sysDevice = getByBusinessDeviceId(defenceArea.getId());
|
|
|
+ if (sysDevice == null) {
|
|
|
+ final SysDevice device = buildByDefenceArea(defenceArea);
|
|
|
+ save(device);
|
|
|
+ } else {
|
|
|
+ sysDevice.setDeviceName(defenceArea.getDefenceAreaName());
|
|
|
+ sysDevice.setUpdateTime(new Date());
|
|
|
+ updateById(sysDevice);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public SysDevice getByBusinessDeviceId(Long businessDeviceId) {
|
|
|
LambdaQueryWrapper<SysDevice> lambdaQuery = new LambdaQueryWrapper<>();
|
|
|
lambdaQuery.eq(SysDevice::getBusinessDeviceId, businessDeviceId);
|
|
|
@@ -58,7 +76,20 @@ public class SysDeviceServiceImpl extends ServiceImpl<SysDeviceMapper, SysDevice
|
|
|
sysDevice.setUpdateTime(now);
|
|
|
sysDevice.setBusinessDeviceId(deviceInfo.getId());
|
|
|
return sysDevice;
|
|
|
-
|
|
|
-
|
|
|
+ }
|
|
|
+ private SysDevice buildByDefenceArea(IotAlarmDefenceArea deviceInfo) {
|
|
|
+ final Date now = new Date();
|
|
|
+ SysDevice sysDevice = new SysDevice();
|
|
|
+ sysDevice.setDeviceName(deviceInfo.getDefenceAreaName());
|
|
|
+ sysDevice.setUseTime(now);
|
|
|
+ sysDevice.setDeviceStatus(0);
|
|
|
+ sysDevice.setDelFlag("0");
|
|
|
+ sysDevice.setOrgId(deviceInfo.getOrgId());
|
|
|
+ sysDevice.setOrgName(deviceInfo.getOrgName());
|
|
|
+ sysDevice.setOrgPath(deviceInfo.getOrgPath());
|
|
|
+ sysDevice.setCreateTime(now);
|
|
|
+ sysDevice.setUpdateTime(now);
|
|
|
+ sysDevice.setBusinessDeviceId(deviceInfo.getId());
|
|
|
+ return sysDevice;
|
|
|
}
|
|
|
}
|