|
@@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
|
+import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo.IotMaintenanceBomPageReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo.IotMaintenanceBomPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo.IotMaintenanceBomSaveReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo.IotMaintenanceBomSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo.IotTobeMaintenanceBomRespVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmaintenancebom.vo.IotTobeMaintenanceBomRespVO;
|
|
@@ -281,74 +282,77 @@ public class IotMaintenancePlanServiceImpl implements IotMaintenancePlanService
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void syncMaintenancePlan(List<Long> deviceIds, Long deptId, List<Long> personIds, Map<Long, Long> oldDeptPair) {
|
|
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);
|
|
|
|
|
|
|
+ // 需要过滤掉数据权限
|
|
|
|
|
+ DataPermissionUtils.executeIgnore(() -> {
|
|
|
|
|
+ // 查询当前调拨的设备相关的保养计划 保养计划明细
|
|
|
|
|
+ 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);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- } 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 中的保养项与 新保养计划 建立关联
|
|
|
|
|
|
|
+ // 查询调拨后的部门是否已经存在保养计划 如果 保养后的部门没有保养计划 则新建保养计划并添加保养项
|
|
|
|
|
+ // 如果调拨后的部门有多个保养计划 随机取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)) {
|
|
if (CollUtil.isNotEmpty(relatedDeviceBoms)) {
|
|
|
relatedDeviceBoms.forEach(bom -> {
|
|
relatedDeviceBoms.forEach(bom -> {
|
|
|
- IotMaintenanceBomDO copy = BeanUtils.toBean(bom, IotMaintenanceBomDO.class);
|
|
|
|
|
- copy.setId(null);
|
|
|
|
|
- copy.setPlanId(newPlan.getId());
|
|
|
|
|
- copy.setDeleted(false);
|
|
|
|
|
- tobeAddedBoms.add(copy);
|
|
|
|
|
|
|
+ // 执行数据 删除 操作
|
|
|
|
|
+ List<Long> deleteIds = relatedDeviceBoms.stream()
|
|
|
|
|
+ .map(IotMaintenanceBomDO::getId)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ iotMaintenanceBomMapper.deleteBatchIds(deleteIds);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- // 删除设备调拨前保养计划中的保养项 新增调拨后部门保养计划的保养项
|
|
|
|
|
- // 需要修改(删除)的保养项集合
|
|
|
|
|
- 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);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 执行数据 新增 操作
|
|
|
|
|
+ if (CollUtil.isNotEmpty(tobeAddedBoms)) {
|
|
|
|
|
+ iotMaintenanceBomMapper.insertBatch(tobeAddedBoms);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|