|
@@ -6,11 +6,14 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo.IotDeviceAllotLogPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo.IotDeviceAllotLogSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceallotlog.vo.IotDeviceAllotSaveReqVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotdeviceperson.vo.IotDevicePersonRelationSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdeviceallotlog.IotDeviceAllotLogDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotdeviceallotlog.IotDeviceAllotLogMapper;
|
|
|
+import cn.iocoder.yudao.module.pms.service.iotdeviceperson.IotDevicePersonService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
@@ -35,6 +38,8 @@ public class IotDeviceAllotLogServiceImpl implements IotDeviceAllotLogService {
|
|
|
private IotDeviceAllotLogMapper iotDeviceAllotLogMapper;
|
|
|
@Resource
|
|
|
private IotDeviceMapper iotDeviceMapper;
|
|
|
+ @Resource
|
|
|
+ private IotDevicePersonService iotDevicePersonService;
|
|
|
|
|
|
@Override
|
|
|
public Long createIotDeviceAllotLog(IotDeviceAllotLogSaveReqVO createReqVO) {
|
|
@@ -79,6 +84,7 @@ public class IotDeviceAllotLogServiceImpl implements IotDeviceAllotLogService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Long saveDeviceAllot(List<IotDeviceAllotSaveReqVO> reqVOS) {
|
|
|
// 批量保存设备的状态
|
|
|
if (CollUtil.isEmpty(reqVOS)) {
|
|
@@ -94,6 +100,7 @@ public class IotDeviceAllotLogServiceImpl implements IotDeviceAllotLogService {
|
|
|
.collect(Collectors.toMap(IotDeviceDO::getId, device -> device));
|
|
|
List<IotDeviceAllotLogDO> deviceAllotLogs = new ArrayList<>();
|
|
|
List<IotDeviceDO> tobeUpdatedDevices = new ArrayList<>();
|
|
|
+ List<IotDevicePersonRelationSaveReqVO> personRelations = new ArrayList<>();
|
|
|
reqVOS.forEach(req -> {
|
|
|
if (deviceMap.containsKey(req.getDeviceId()) && !req.getDeptId().equals(deviceMap.get(req.getDeviceId()).getDeptId())) {
|
|
|
IotDeviceAllotLogDO tempDeviceAllot = new IotDeviceAllotLogDO();
|
|
@@ -106,6 +113,14 @@ public class IotDeviceAllotLogServiceImpl implements IotDeviceAllotLogService {
|
|
|
device.setDeptId(req.getDeptId());
|
|
|
tobeUpdatedDevices.add(device);
|
|
|
}
|
|
|
+ // 如果同步选择了设备责任人 需要同步修改相关设备的责任人并记录日志
|
|
|
+ if (CollUtil.isNotEmpty(req.getPersonIds())) {
|
|
|
+ IotDevicePersonRelationSaveReqVO tempReqVO = new IotDevicePersonRelationSaveReqVO();
|
|
|
+ tempReqVO.setDeviceId(req.getDeviceId());
|
|
|
+ tempReqVO.setUserIds(req.getPersonIds());
|
|
|
+ tempReqVO.setReason(req.getReason());
|
|
|
+ personRelations.add(tempReqVO);
|
|
|
+ }
|
|
|
});
|
|
|
if (CollUtil.isNotEmpty(deviceAllotLogs)) {
|
|
|
iotDeviceAllotLogMapper.insertBatch(deviceAllotLogs);
|
|
@@ -114,6 +129,12 @@ public class IotDeviceAllotLogServiceImpl implements IotDeviceAllotLogService {
|
|
|
if (CollUtil.isNotEmpty(tobeUpdatedDevices)) {
|
|
|
iotDeviceMapper.updateBatch(tobeUpdatedDevices);
|
|
|
}
|
|
|
+ // 如果选择了设备责任人 需要同步修改设备责任人并记录 日志
|
|
|
+ if (CollUtil.isNotEmpty(personRelations)) {
|
|
|
+ iotDevicePersonService.saveDevicePersons(personRelations);
|
|
|
+ }
|
|
|
+ // 同步修改 设备相关的 历史工单
|
|
|
+
|
|
|
return 1l;
|
|
|
}
|
|
|
|