|
@@ -3,6 +3,8 @@ package com.middle.platform.manage.biz.service;
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
|
+import com.middle.platform.common.constant.Global;
|
|
|
|
|
+import com.middle.platform.common.exception.BusinessException;
|
|
|
import com.middle.platform.manage.biz.domain.req.IotProDevicePara;
|
|
import com.middle.platform.manage.biz.domain.req.IotProDevicePara;
|
|
|
import com.middle.platform.manage.biz.domain.req.IotProjectDevicePara;
|
|
import com.middle.platform.manage.biz.domain.req.IotProjectDevicePara;
|
|
|
import com.middle.platform.manage.biz.domain.vo.IotDeviceVo;
|
|
import com.middle.platform.manage.biz.domain.vo.IotDeviceVo;
|
|
@@ -19,6 +21,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author xucaiqin
|
|
* @author xucaiqin
|
|
@@ -33,6 +36,7 @@ public class IotProjectDeviceService extends ServiceImpl<IotProjectDeviceMapper,
|
|
|
private final IotProjectDeviceLogMapper iotProjectDeviceLogMapper;
|
|
private final IotProjectDeviceLogMapper iotProjectDeviceLogMapper;
|
|
|
|
|
|
|
|
private final IotDeviceMapper iotDeviceMapper;
|
|
private final IotDeviceMapper iotDeviceMapper;
|
|
|
|
|
+ private final IotProjectService iotProjectService;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 项目设备关联查询
|
|
* 项目设备关联查询
|
|
@@ -50,6 +54,17 @@ public class IotProjectDeviceService extends ServiceImpl<IotProjectDeviceMapper,
|
|
|
return new PageRes<>(iotDeviceVos);
|
|
return new PageRes<>(iotDeviceVos);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 设备校验
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param deviceId 设备id
|
|
|
|
|
+ */
|
|
|
|
|
+ private void check(Long deviceId) {
|
|
|
|
|
+ IotDevice iotDevice = iotDeviceMapper.selectById(deviceId);
|
|
|
|
|
+ if (Objects.isNull(iotDevice) || Global.DEL == iotDevice.getDelFlag()) {
|
|
|
|
|
+ throw new BusinessException(deviceId + ":设备不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 新增插入关联设备
|
|
* 新增插入关联设备
|
|
@@ -61,6 +76,12 @@ public class IotProjectDeviceService extends ServiceImpl<IotProjectDeviceMapper,
|
|
|
if (iotProjectDevicePara.getDeviceIds() == null) {
|
|
if (iotProjectDevicePara.getDeviceIds() == null) {
|
|
|
throw new RuntimeException("设备ID集合不能为空");
|
|
throw new RuntimeException("设备ID集合不能为空");
|
|
|
}
|
|
}
|
|
|
|
|
+ //校验项目
|
|
|
|
|
+ iotProjectService.check(iotProjectDevicePara.getProjectId());
|
|
|
|
|
+ //设备校验
|
|
|
|
|
+ for (Long deviceId : iotProjectDevicePara.getDeviceIds()) {
|
|
|
|
|
+ check(deviceId);
|
|
|
|
|
+ }
|
|
|
iotProjectDevicePara.getDeviceIds().forEach(e -> {
|
|
iotProjectDevicePara.getDeviceIds().forEach(e -> {
|
|
|
IotProjectDevice iotProjectDevice = new IotProjectDevice();
|
|
IotProjectDevice iotProjectDevice = new IotProjectDevice();
|
|
|
iotProjectDevice.setDeviceId(e);
|
|
iotProjectDevice.setDeviceId(e);
|
|
@@ -106,21 +127,21 @@ public class IotProjectDeviceService extends ServiceImpl<IotProjectDeviceMapper,
|
|
|
if (!(enableFlag == 1 || enableFlag == 0)) {
|
|
if (!(enableFlag == 1 || enableFlag == 0)) {
|
|
|
throw new RuntimeException("修改状态异常");
|
|
throw new RuntimeException("修改状态异常");
|
|
|
}
|
|
}
|
|
|
|
|
+ //校验设备
|
|
|
|
|
+ check(deviceId);
|
|
|
return iotProjectDeviceMapper.updateById(deviceId, enableFlag);
|
|
return iotProjectDeviceMapper.updateById(deviceId, enableFlag);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 设备解绑
|
|
* 设备解绑
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param id 项目关联设备id
|
|
|
*/
|
|
*/
|
|
|
public Object deleteProDeviceUntie(Long id) {
|
|
public Object deleteProDeviceUntie(Long id) {
|
|
|
IotProjectDevice res = iotProjectDeviceMapper.selectById(id);
|
|
IotProjectDevice res = iotProjectDeviceMapper.selectById(id);
|
|
|
if (res != null) {
|
|
if (res != null) {
|
|
|
IotProjectDeviceLog iotProjectDeviceLog = new IotProjectDeviceLog();
|
|
IotProjectDeviceLog iotProjectDeviceLog = new IotProjectDeviceLog();
|
|
|
BeanUtils.copyProperties(res, iotProjectDeviceLog);
|
|
BeanUtils.copyProperties(res, iotProjectDeviceLog);
|
|
|
- iotProjectDeviceLog.setCreateBy(StpUtil.getLoginIdAsLong());
|
|
|
|
|
- iotProjectDeviceLog.setCreateTime(LocalDateTime.now());
|
|
|
|
|
- iotProjectDeviceLog.setUpdateBy(StpUtil.getLoginIdAsLong());
|
|
|
|
|
- iotProjectDeviceLog.setUpdateTime(LocalDateTime.now());
|
|
|
|
|
iotProjectDeviceLog.setRemark("设备解绑");
|
|
iotProjectDeviceLog.setRemark("设备解绑");
|
|
|
iotProjectDeviceLogMapper.insert(iotProjectDeviceLog);
|
|
iotProjectDeviceLogMapper.insert(iotProjectDeviceLog);
|
|
|
return iotProjectDeviceMapper.deleteProDeviceUntie(id);
|
|
return iotProjectDeviceMapper.deleteProDeviceUntie(id);
|