|
|
@@ -1,6 +1,7 @@
|
|
|
package cn.iocoder.yudao.module.pms.service.maintenance;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
@@ -21,12 +22,16 @@ import cn.iocoder.yudao.module.pms.dal.mysql.iotmaintenancebom.IotMaintenanceBom
|
|
|
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.service.IotDeviceService;
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
|
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -43,6 +48,7 @@ import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.*;
|
|
|
@Validated
|
|
|
public class IotMaintenancePlanServiceImpl implements IotMaintenancePlanService {
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(IotMaintenancePlanServiceImpl.class);
|
|
|
@Resource
|
|
|
private IotMaintenancePlanMapper iotMaintenancePlanMapper;
|
|
|
@Resource
|
|
|
@@ -273,4 +279,77 @@ public class IotMaintenancePlanServiceImpl implements IotMaintenancePlanService
|
|
|
iotMaintenancePlanMapper.updateById(planDO);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void syncMaintenancePlan(List<Long> deviceIds, Long deptId, List<Long> personIds, Map<Long, Long> oldDeptPair) {
|
|
|
+ // 查询当前调拨的设备相关的保养计划 保养计划明细
|
|
|
+ IotMaintenanceBomPageReqVO reqVO = new IotMaintenanceBomPageReqVO();
|
|
|
+ reqVO.setDeviceIds(deviceIds);
|
|
|
+ List<IotMaintenanceBomDO> planBoms = iotMaintenanceBomMapper.selectList(reqVO);
|
|
|
+ // 以设备为维度组装保养项列表
|
|
|
+ List<IotMaintenanceBomDO> relatedDeviceBoms = new ArrayList<>();
|
|
|
+ if (CollUtil.isNotEmpty(planBoms)) {
|
|
|
+ planBoms.forEach(bom -> {
|
|
|
+ relatedDeviceBoms.add(bom);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 查询调拨后的部门是否已经存在保养计划 如果 保养后的部门没有保养计划 则新建保养计划并添加保养项
|
|
|
+ // 如果调拨后的部门有多个保养计划 随机取1个保养计划 将保养项 添加进去
|
|
|
+ IotMaintenancePlanPageReqVO planReqVO = new IotMaintenancePlanPageReqVO();
|
|
|
+ planReqVO.setDeptId(deptId);
|
|
|
+ List<IotMaintenancePlanDO> plans = iotMaintenancePlanMapper.selectList(planReqVO);
|
|
|
+ // 需要新增的保养项集合
|
|
|
+ List<IotMaintenanceBomDO> tobeAddedBoms = new ArrayList<>();
|
|
|
+ if (CollUtil.isNotEmpty(plans)) {
|
|
|
+ IotMaintenancePlanDO specifiedPlan = plans.get(0);
|
|
|
+ // 将集合 relatedDeviceBoms 中的保养项与 新保养计划 建立关联
|
|
|
+ if (CollUtil.isNotEmpty(relatedDeviceBoms)) {
|
|
|
+ relatedDeviceBoms.forEach(bom -> {
|
|
|
+ IotMaintenanceBomDO copy = BeanUtils.toBean(bom, IotMaintenanceBomDO.class);
|
|
|
+ copy.setId(null);
|
|
|
+ copy.setPlanId(specifiedPlan.getId());
|
|
|
+ copy.setDeleted(false);
|
|
|
+ tobeAddedBoms.add(copy);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ DeptDO dept = deptService.getDept(deptId);
|
|
|
+ String no = bizNoRedisDAO.generate(BizNoRedisDAO.MAIN_PLAN_NO_PREFIX);
|
|
|
+ // 调拨后的部门没有保养计划 新增保养计划
|
|
|
+ IotMaintenancePlanDO newPlan = new IotMaintenancePlanDO();
|
|
|
+ newPlan.setDeptId(deptId);
|
|
|
+ newPlan.setSerialNumber(no);
|
|
|
+ newPlan.setName(ObjUtil.isNotEmpty(dept) ? dept.getName() : StrUtil.EMPTY + " - " + "保养计划");
|
|
|
+ newPlan.setResponsiblePerson(CollUtil.isNotEmpty(personIds) ? String.valueOf(personIds.get(0)) : StrUtil.EMPTY);
|
|
|
+ newPlan.setCreator(CollUtil.isNotEmpty(personIds) ? String.valueOf(personIds.get(0)) : StrUtil.EMPTY);
|
|
|
+ newPlan.setCreateTime(LocalDateTime.now());
|
|
|
+ iotMaintenancePlanMapper.insert(newPlan);
|
|
|
+ // 将集合 relatedDeviceBoms 中的保养项与 新保养计划 建立关联
|
|
|
+ if (CollUtil.isNotEmpty(relatedDeviceBoms)) {
|
|
|
+ relatedDeviceBoms.forEach(bom -> {
|
|
|
+ IotMaintenanceBomDO copy = BeanUtils.toBean(bom, IotMaintenanceBomDO.class);
|
|
|
+ copy.setId(null);
|
|
|
+ copy.setPlanId(newPlan.getId());
|
|
|
+ copy.setDeleted(false);
|
|
|
+ tobeAddedBoms.add(copy);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 删除设备调拨前保养计划中的保养项 新增调拨后部门保养计划的保养项
|
|
|
+ // 需要修改(删除)的保养项集合
|
|
|
+ if (CollUtil.isNotEmpty(relatedDeviceBoms)) {
|
|
|
+ relatedDeviceBoms.forEach(bom -> {
|
|
|
+ // 执行数据 删除 操作
|
|
|
+ List<Long> deleteIds = relatedDeviceBoms.stream()
|
|
|
+ .map(IotMaintenanceBomDO::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ iotMaintenanceBomMapper.deleteBatchIds(deleteIds);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 执行数据 新增 操作
|
|
|
+ if (CollUtil.isNotEmpty(tobeAddedBoms)) {
|
|
|
+ iotMaintenanceBomMapper.insertBatch(tobeAddedBoms);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|