|
@@ -12,6 +12,7 @@ import cn.iocoder.yudao.module.pms.controller.admin.maintenance.vo.IotMaintenanc
|
|
import cn.iocoder.yudao.module.pms.controller.admin.maintenance.vo.IotMaintenancePlanSaveReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.maintenance.vo.IotMaintenancePlanSaveReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.maintenance.vo.IotMaintenanceSaveVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.maintenance.vo.IotMaintenanceSaveVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotmaintenancebom.IotMaintenanceBomDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotmaintenancebom.IotMaintenanceBomDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.maintenance.IotMaintenancePlanDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.maintenance.IotMaintenancePlanDO;
|
|
@@ -19,6 +20,7 @@ import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotmaintenancebom.IotMaintenanceBomMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotmaintenancebom.IotMaintenanceBomMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.maintenance.IotMaintenancePlanMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.maintenance.IotMaintenancePlanMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.redis.BizNoRedisDAO;
|
|
import cn.iocoder.yudao.module.pms.dal.redis.BizNoRedisDAO;
|
|
|
|
+import cn.iocoder.yudao.module.pms.service.IotDeviceService;
|
|
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -26,6 +28,7 @@ import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
@@ -50,6 +53,8 @@ public class IotMaintenancePlanServiceImpl implements IotMaintenancePlanService
|
|
private DeptService deptService;
|
|
private DeptService deptService;
|
|
@Resource
|
|
@Resource
|
|
private IotDeviceMapper iotDeviceMapper;
|
|
private IotDeviceMapper iotDeviceMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private IotDeviceService iotDeviceService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -73,8 +78,31 @@ public class IotMaintenancePlanServiceImpl implements IotMaintenancePlanService
|
|
IotMaintenanceBomPageReqVO reqVO = new IotMaintenanceBomPageReqVO();
|
|
IotMaintenanceBomPageReqVO reqVO = new IotMaintenanceBomPageReqVO();
|
|
reqVO.setDeviceIds(new ArrayList<>(deviceIds));
|
|
reqVO.setDeviceIds(new ArrayList<>(deviceIds));
|
|
List<IotMaintenanceBomDO> boms = iotMaintenanceBomMapper.selectList(reqVO);
|
|
List<IotMaintenanceBomDO> boms = iotMaintenanceBomMapper.selectList(reqVO);
|
|
|
|
+ // 需要提示出具体哪些设备已经存在于其它保养计划中
|
|
if (CollUtil.isNotEmpty(boms)) {
|
|
if (CollUtil.isNotEmpty(boms)) {
|
|
- throw exception(IOT_MAINTENANCE_SAME_DEVICE_EXISTS);
|
|
|
|
|
|
+ Set<String> deviceCodes = new HashSet<>();
|
|
|
|
+ Set<Long> existDeviceIds = new HashSet<>();
|
|
|
|
+ boms.forEach(bom -> {
|
|
|
|
+ existDeviceIds.add(bom.getDeviceId());
|
|
|
|
+ });
|
|
|
|
+ // 根据设备id查询设备编码
|
|
|
|
+ // 组装bom关联的设备信息
|
|
|
|
+ Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(new ArrayList<>(existDeviceIds));
|
|
|
|
+ if (CollUtil.isNotEmpty(deviceMap)) {
|
|
|
|
+ deviceMap.forEach((k,v) -> {
|
|
|
|
+ deviceCodes.add(v.getDeviceCode());
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ // 拼接设备编码(如果大于3个,显示前3个并加省略号)
|
|
|
|
+ String deviceCodesString = deviceCodes.stream()
|
|
|
|
+ .limit(3) // 只取前3个元素
|
|
|
|
+ .collect(Collectors.joining(",")); // 用逗号连接
|
|
|
|
+
|
|
|
|
+ // 如果设备编码超过3个,添加省略号
|
|
|
|
+ if (deviceCodes.size() > 3) {
|
|
|
|
+ deviceCodesString += "...";
|
|
|
|
+ }
|
|
|
|
+ throw exception(IOT_MAINTENANCE_SAME_DEVICE_EXISTS, deviceCodesString);
|
|
}
|
|
}
|
|
// 先保存保养计划主表 再根据主表id更新明细
|
|
// 先保存保养计划主表 再根据主表id更新明细
|
|
IotMaintenancePlanSaveReqVO mainPlanSaveVO = createReqVO.getMainPlan();
|
|
IotMaintenancePlanSaveReqVO mainPlanSaveVO = createReqVO.getMainPlan();
|
|
@@ -203,7 +231,27 @@ public class IotMaintenancePlanServiceImpl implements IotMaintenancePlanService
|
|
reqVO.setDeviceIds(new ArrayList<>(deviceIds));
|
|
reqVO.setDeviceIds(new ArrayList<>(deviceIds));
|
|
List<IotMaintenanceBomDO> boms = iotMaintenanceBomMapper.selectList(reqVO);
|
|
List<IotMaintenanceBomDO> boms = iotMaintenanceBomMapper.selectList(reqVO);
|
|
if (CollUtil.isNotEmpty(boms)) {
|
|
if (CollUtil.isNotEmpty(boms)) {
|
|
- throw exception(IOT_MAINTENANCE_SAME_DEVICE_EXISTS);
|
|
|
|
|
|
+ Set<String> deviceCodes = new HashSet<>();
|
|
|
|
+ Set<Long> existDeviceIds = new HashSet<>();
|
|
|
|
+ boms.forEach(bom -> {
|
|
|
|
+ existDeviceIds.add(bom.getDeviceId());
|
|
|
|
+ });
|
|
|
|
+ // 组装bom关联的设备信息
|
|
|
|
+ Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(new ArrayList<>(existDeviceIds));
|
|
|
|
+ if (CollUtil.isNotEmpty(deviceMap)) {
|
|
|
|
+ deviceMap.forEach((k,v) -> {
|
|
|
|
+ deviceCodes.add(v.getDeviceCode());
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ // 拼接设备编码(如果大于3个,显示前3个并加省略号)
|
|
|
|
+ String deviceCodesString = deviceCodes.stream()
|
|
|
|
+ .limit(3) // 只取前3个元素
|
|
|
|
+ .collect(Collectors.joining(",")); // 用逗号连接
|
|
|
|
+ // 如果设备编码超过3个,添加省略号
|
|
|
|
+ if (deviceCodes.size() > 3) {
|
|
|
|
+ deviceCodesString += "...";
|
|
|
|
+ }
|
|
|
|
+ throw exception(IOT_MAINTENANCE_SAME_DEVICE_EXISTS, deviceCodesString);
|
|
}
|
|
}
|
|
IotMaintenancePlanSaveReqVO mainPlanSaveVO = updateReqVO.getMainPlan();
|
|
IotMaintenancePlanSaveReqVO mainPlanSaveVO = updateReqVO.getMainPlan();
|
|
IotMaintenancePlanDO iotMaintenancePlan = BeanUtils.toBean(mainPlanSaveVO, IotMaintenancePlanDO.class);
|
|
IotMaintenancePlanDO iotMaintenancePlan = BeanUtils.toBean(mainPlanSaveVO, IotMaintenancePlanDO.class);
|