|
@@ -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]);
|