2 İşlemeler 28b58fcf8c ... dbc4fdb9a4

Yazar SHA1 Mesaj Tarih
  zhangcl dbc4fdb9a4 Merge remote-tracking branch 'origin/master' 2 gün önce
  zhangcl dc1678abbf pms 保养计划生成工单名称优化 多语言设置 2 gün önce

+ 1 - 0
yudao-module-pms/yudao-module-pms-api/src/main/java/cn/iocoder/yudao/module/pms/enums/ErrorCodeConstant.java

@@ -51,6 +51,7 @@ public interface ErrorCodeConstant{
     ErrorCode IOT_MAIN_WORK_ORDER_BOM_MATERIAL_NOT_EXISTS = new ErrorCode(139,"bom物料不存在");
     ErrorCode IOT_MAINTENANCE_PLAN_NO_EXISTS = new ErrorCode(140,"维修计划不存在");
     ErrorCode IOT_MAIN_WORK_ORDER_NOT_EXISTS = new ErrorCode(141,"保养工单不存在");
+    ErrorCode IOT_MAIN_WORK_ORDER_EXECUTED = new ErrorCode(241,"保养工单已执行");
     ErrorCode IOT_DEVICE_RUN_LOG_NOT_EXISTS = new ErrorCode(142, "设备运行数据记录 中间表不存在");
     ErrorCode DEVICE_NOT_EXISTS = new ErrorCode(143, "延凡设备不存在");
     ErrorCode IOT_OPEATION_MODEL_NOT_EXISTS = new ErrorCode(135, "运行记录模板主不存在");

+ 72 - 7
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/mainworkorder/CreateMainWorkOrderJob.java

@@ -31,6 +31,8 @@ import cn.iocoder.yudao.module.pms.service.iotmainworkorderbom.IotMainWorkOrderB
 import cn.iocoder.yudao.module.pms.service.maintenance.IotMaintenancePlanService;
 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
+import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
+import cn.iocoder.yudao.module.system.service.dept.DeptService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@@ -74,6 +76,8 @@ public class CreateMainWorkOrderJob implements JobHandler {
     private ThreadPoolTaskExecutor pmsThreadPoolTaskExecutor;
     @Resource
     private PmsMessage pmsMessage;
+    @Resource
+    private DeptService deptService;
 
     @Override
     @TenantJob
@@ -123,15 +127,23 @@ public class CreateMainWorkOrderJob implements JobHandler {
         if (CollUtil.isEmpty(deviceIds)) {
             return "没有设备信息";
         }
+        Map<Long, IotDeviceRespVO> deviceMap = new HashMap<>();
+        Map<Long, DeptDO> depts = new HashMap<>();
         if (CollUtil.isNotEmpty(mainBomList)) {
             // 组装bom关联的设备信息
-            Map<Long, IotDeviceRespVO> deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(mainBomList,
+            deviceMap = iotDeviceService.getDeviceMap(convertListByFlatMap(mainBomList,
                     bom -> Stream.of(bom.getDeviceId())));
             if (CollUtil.isNotEmpty(deviceMap)) {
+                Set<Long> deptIds = new HashSet<>();
                 deviceMap.forEach((k,v) -> {
                     deviceCategoryIds.add(v.getAssetClass());
                     deviceCategoryPair.put(k, v.getAssetClass());
+                    deptIds.add(v.getDeptId());
                 });
+                // 根据部门id集合查询对应的部门名称
+                if (CollUtil.isNotEmpty(deptIds)) {
+                    depts = deptService.getDeptMap(deptIds);
+                }
             }
         }
         // 查询所有设备的责任人
@@ -139,6 +151,7 @@ public class CreateMainWorkOrderJob implements JobHandler {
         devicePersonReqVO.setDeviceIds(deviceIds);
         List<IotDevicePersonDO> devicePersons = iotDevicePersonService.getPersonsByDeviceIds(devicePersonReqVO);
         Map<Long, List<Long>> devicePersonPair = new HashMap<>();
+        Map<Long, AdminUserRespDTO> userPair = new HashMap<>();
         if (CollUtil.isNotEmpty(devicePersons)) {
             devicePersonPair = devicePersons.stream()
                     .filter(person -> person.getDeviceId() != null) // 过滤deviceId为null的记录
@@ -149,9 +162,13 @@ public class CreateMainWorkOrderJob implements JobHandler {
                                     Collectors.toList() // 收集为列表
                             )
                     ));
+            Set<Long> personIds = new HashSet<>();
+            // 查询所有设备责任人id对应的责任人姓名(昵称)
+            devicePersons.forEach(dp -> {
+                personIds.add(dp.getPersonId());
+            });
+            userPair = adminUserApi.getUserMap(personIds);
         }
-        // 查询所有设备名称 设备编码集合
-        Map<Long, IotDeviceRespVO> devices = iotDeviceService.getDeviceMap(deviceIds);
         // 查询 保养计划保养明细中已经绑定的 多种累计时长 公里数 属性集合
         List<IotDeviceRunLogRespVO> multipleAccumulatedData = new ArrayList<>();
         if (CollUtil.isNotEmpty(deviceIds) && CollUtil.isNotEmpty(boundedMultiAttrNames)) {
@@ -319,6 +336,9 @@ public class CreateMainWorkOrderJob implements JobHandler {
                 Map<Long, List<Long>> finalDevicePersonPair = devicePersonPair;
                 // 获取当前时间的 yyyy-MM-dd 格式
                 String currentDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern(DateUtils.FORMAT_YEAR_MONTH_DAY));
+                Map<Long, AdminUserRespDTO> finalUserPair = userPair;
+                Map<Long, IotDeviceRespVO> finalDeviceMap = deviceMap;
+                Map<Long, DeptDO> finalDepts = depts;
                 deviceBomPair.forEach((k, v) -> {
                     String[] planIdDeviceIdStrS = k.split("-");
                     // 查询当前设备关联的责任人 如果有多个责任人 需要建立多个对应的工单 但是多个工单 要建立关联关系
@@ -338,10 +358,55 @@ public class CreateMainWorkOrderJob implements JobHandler {
                                 // 查询设备对应的部门
                                 workOrder.setDeptId(plan.getDeptId());
                                 workOrder.setName(plan.getName() + " 工单");
-                                if (devices.containsKey(Long.valueOf(planIdDeviceIdStrS[1]))) {
-                                    workOrder.setDeptId(devices.get(Long.valueOf(planIdDeviceIdStrS[1])).getDeptId());
-                                    workOrder.setName(devices.get(Long.valueOf(planIdDeviceIdStrS[1])).getDeviceCode() + " "
-                                            + devices.get(Long.valueOf(planIdDeviceIdStrS[1])).getDeviceName() + " - " + currentDate + " 保养工单");
+                                if (finalDeviceMap.containsKey(Long.valueOf(planIdDeviceIdStrS[1]))) {
+                                    Long deptId = finalDeviceMap.get(Long.valueOf(planIdDeviceIdStrS[1])).getDeptId();
+                                    workOrder.setDeptId(deptId);
+                                    // 查询 deptId 对应的部门名称
+                                    String deptName = StrUtil.EMPTY;
+                                    String deptCHName = StrUtil.EMPTY;
+                                    String deptENName = StrUtil.EMPTY;
+                                    if (finalDepts.containsKey(deptId)) {
+                                        DeptDO dept = finalDepts.get(deptId);
+                                        deptName = dept.getName();
+                                        // 提取部门英文名称
+                                        String[] deptNameStr = deptName.split("~~");
+                                        deptCHName = (deptNameStr.length > 0) ? deptNameStr[0] : StrUtil.EMPTY;
+                                        deptENName = StrUtil.EMPTY;
+                                        if (deptNameStr.length > 0) {
+                                            for (String s : deptNameStr) {
+                                                if (s.contains("en")) {
+                                                    deptENName = s;
+                                                }
+                                            }
+                                        }
+                                    }
+                                    // 查询 personId 对应的责任人名称(昵称)
+                                    String responsibleName = StrUtil.EMPTY;
+                                    if (finalUserPair.containsKey(personId)) {
+                                        AdminUserRespDTO userDTO = finalUserPair.get(personId);
+                                        responsibleName = userDTO.getNickname();
+                                    }
+                                    // 设备名称 提取英文名称
+                                    String deviceName = finalDeviceMap.get(Long.valueOf(planIdDeviceIdStrS[1])).getDeviceName();
+                                    String[] deviceNameStr = deviceName.split("~~");
+                                    String deviceCHName = (deviceNameStr.length > 0) ? deviceNameStr[0] : StrUtil.EMPTY;
+                                    String deviceENName = StrUtil.EMPTY;
+                                    if (deviceNameStr.length > 0) {
+                                        for (String s : deviceNameStr) {
+                                            if (s.contains("en")) {
+                                                deviceENName = s;
+                                            }
+                                        }
+                                    }
+                                    String workOrderCHName = StrUtil.EMPTY;
+                                    workOrderCHName = deptCHName + "/" + responsibleName + "/"
+                                            + deviceCHName + "/" + currentDate + "-保养工单";
+                                    String workOrderENName = StrUtil.EMPTY;
+                                    if (StrUtil.isNotBlank(deviceENName) && StrUtil.isNotBlank(deptENName)) {
+                                        workOrderENName = deptENName + "/" + responsibleName + "/"
+                                                + deviceENName + "/" + currentDate + "-Maintenance Work Order";
+                                    }
+                                    workOrder.setName(workOrderCHName + "~~en**" + workOrderENName);
                                 } else {
                                     // 如果设备列表没有包含需要保养的设备id 不生成保养工单 提示
                                     System.out.println("不存在数据 - 待保养的设备id:" + planIdDeviceIdStrS[1]);

+ 7 - 2
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotmainworkorder/IotMainWorkOrderServiceImpl.java

@@ -59,6 +59,7 @@ import java.util.stream.Stream;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
+import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_MAIN_WORK_ORDER_EXECUTED;
 import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_MAIN_WORK_ORDER_NOT_EXISTS;
 
 /**
@@ -127,7 +128,11 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
 
     @Override
     public IotMainWorkOrderDO getIotMainWorkOrder(Long id) {
-        return iotMainWorkOrderMapper.selectById(id);
+        IotMainWorkOrderDO workOrder = iotMainWorkOrderMapper.selectById(id);
+        if (ObjUtil.isEmpty(workOrder)) {
+            throw exception(IOT_MAIN_WORK_ORDER_EXECUTED);
+        }
+        return workOrder;
     }
 
     @Override
@@ -1403,7 +1408,7 @@ public class IotMainWorkOrderServiceImpl implements IotMainWorkOrderService {
                 .filter(order -> !order.getId().equals(updateObj.getId()))
                 .collect(Collectors.toList());
 
-        // 如果当前工单已经关闭,需要同时将当前工单的关联工单 一并关闭 是否需要将当前工单选择的物料及费用也复制到 关联工单?
+        // 如果当前工单已经关闭,需要同时将当前工单的关联工单 一并关闭
         if (2 == updateObj.getResult()) {
             if (CollUtil.isNotEmpty(filteredOrders)) {
                 // 将关联工单设置为 已执行 直接删除