From d61b21c50e62298f185ecafa8e0b22f7ee8c4973 Mon Sep 17 00:00:00 2001 From: lyh <925863403@qq.com> Date: 星期四, 21 八月 2025 18:13:17 +0800 Subject: [PATCH] 430报表接口与列表流程添加 --- lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java | 316 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 296 insertions(+), 20 deletions(-) diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java index e6cd5e5..4dd9e26 100644 --- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java +++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java @@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.annotations.Param; import org.apache.shiro.SecurityUtils; import org.flowable.engine.TaskService; import org.flowable.task.api.Task; @@ -23,6 +24,10 @@ import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog; import org.jeecg.modules.eam.constant.*; +import org.jeecg.modules.eam.dto.DailyResponsibleInfo; +import org.jeecg.modules.eam.dto.EamInspectionOrderDetailExport; +import org.jeecg.modules.eam.dto.EamInspectionOrderExport; +import org.jeecg.modules.eam.dto.WeeklyResponsibleInfo; import org.jeecg.modules.eam.request.*; import org.jeecg.modules.system.entity.BaseFactory; import org.jeecg.modules.system.entity.BaseFactoryUser; @@ -49,6 +54,7 @@ import java.time.LocalDate; import java.time.ZoneId; import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -103,9 +109,9 @@ if (sysUser == null) { return page; } - if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) { + if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) { //閫夋嫨浜嗚澶囷紝鏍规嵁璁惧id杩囨护璁惧 - List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(",")); + List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(",")); queryWrapper.in("e.equipment_code", equipArr); } else { //娌℃湁閫夋嫨璁惧锛屾牴鎹腑蹇冭繃婊よ澶� @@ -371,17 +377,19 @@ resultMap.put("itemCode", weekInsDetailResultResponse.getItemCode()); resultMap.put("itemName", weekInsDetailResultResponse.getItemName()); resultMap.put("itemDemand", weekInsDetailResultResponse.getItemDemand()); - // 浣跨敤AtomicInteger浣滀负璁℃暟鍣紝浠�1寮�濮� - AtomicInteger counter = new AtomicInteger(1); Map<Integer, EamWeekInsDetailResultResponse> collect = weekInsDetailResultResponseList .stream() .collect(Collectors.toMap( - // 鍒嗙粍閿細浣跨敤鑷搴忓彿锛堜粠1寮�濮嬶級 - item -> counter.getAndIncrement(), + // 鍒嗙粍閿細浣跨敤planInspectionDate瀛楁钀藉湪鏈湀鐨勫懆鏁� + item -> { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(item.getPlanInspectionDate()); + return calendar.get(Calendar.WEEK_OF_MONTH); + }, // 鍊硷細鐩存帴浣跨敤褰撳墠瀵硅薄 item -> item, - // 鍚堝苟鍑芥暟锛氬綋鍚屼竴搴忓彿鏈夊涓璞℃椂锛堢悊璁轰笂涓嶄細鍙戠敓锛夛紝濡備綍澶勭悊 - (existing, replacement) -> existing, // 鑻ユ湁閲嶅閿紝淇濈暀宸插瓨鍦ㄧ殑瀵硅薄 + // 鍚堝苟鍑芥暟锛氬綋鍚屼竴鍛ㄦ湁澶氫釜瀵硅薄鏃讹紙鏍规嵁闇�姹備笉浼氬彂鐢燂紝浣嗕粛闇�鎻愪緵锛� + (existing, replacement) -> existing, // 鎸囧畾Map鐨勫叿浣撳疄鐜帮紙鍙�夛級 LinkedHashMap::new // 淇濇寔鎻掑叆椤哄簭 )); @@ -437,17 +445,21 @@ if (eamWeekInsDetailUserResponseList == null || eamWeekInsDetailUserResponseList.isEmpty()) { return result; } - // 浣跨敤AtomicInteger浣滀负璁℃暟鍣紝浠�1寮�濮� - AtomicInteger counter = new AtomicInteger(1); Map<Integer, EamWeekInsDetailUserResponse> groupMap = eamWeekInsDetailUserResponseList .stream() .collect(Collectors.toMap( - // 鍒嗙粍閿細浣跨敤鑷搴忓彿锛堜粠1寮�濮嬶級 - item -> counter.getAndIncrement(), - // 鍊硷細鐩存帴浣跨敤褰撳墠瀵硅薄锛堜綔涓哄垵濮嬪�硷級 + // 鍒嗙粍閿細浣跨敤 planInspectionDate 瀛楁钀藉湪鏈湀鐨勫懆鏁� + item -> { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(item.getPlanInspectionDate()); + return calendar.get(Calendar.WEEK_OF_MONTH); + }, + // 鍊硷細鐩存帴浣跨敤褰撳墠瀵硅薄 item -> item, - // 鍚堝苟鍑芥暟锛氬綋鍚屼竴鈥滃ぉ鈥濇湁澶氫釜瀵硅薄鏃讹紝濡備綍澶勭悊锛堣繖閲岀ず渚嬪彇绗竴涓級 - (existing, replacement) -> existing // 鑻ユ湁閲嶅閿紝淇濈暀宸插瓨鍦ㄧ殑瀵硅薄 + // 鍚堝苟鍑芥暟锛氬綋鍚屼竴鍛ㄦ湁澶氫釜瀵硅薄鏃讹紙鏍规嵁闇�姹備笉浼氬彂鐢燂級 + (existing, replacement) -> existing, + // 浣跨敤 LinkedHashMap 淇濇寔鎻掑叆椤哄簭 + LinkedHashMap::new )); Map<String, Object> resultMap = new LinkedHashMap<>(); for (int i = 1; i <= 5; i++) { @@ -510,7 +522,6 @@ weekInspectionDetailList.forEach(weekInspectionDetail -> { weekInspectionDetail.setEquipmentId(eamInspectionOrderRequest.getEquipmentId()); weekInspectionDetail.setStandardId(eamInspectionOrderRequest.getStandardId()); - // TODO 鍛ㄧ偣妫�鏃ユ湡 weekInspectionDetail.setPlanInspectionDate(eamInspectionOrderRequest.getInspectionDate()); }); eamWeekInspectionDetailService.saveBatch(weekInspectionDetailList); @@ -683,9 +694,9 @@ updateEamInspectionOrder(eamInspectionOrder); //鏌ヨ鏁版嵁,杩涜璁惧缁翠慨澶勭悊 - if (eamInspectionOrder.getInspectionStatus().equals(InspectionStatus.WAIT_CONFIRM.name())) { - updateEamInspectionOrderDetail(eamInspectionOrder); - } +// if (eamInspectionOrder.getInspectionStatus().equals(InspectionStatus.WAIT_CONFIRM.name())) { +// updateEamInspectionOrderDetail(eamInspectionOrder); +// } return eamInspectionOrder; } catch (Exception e) { @@ -693,6 +704,270 @@ } } + /** + * 鐢熶骇璁惧鑷富缁存姢鐐规琛ㄦ墦鍗� + * @param ids + * @return + */ + @Override + public List<EamInspectionOrderExport> printInspectionOrder(String ids) { + + List<EamInspectionOrderExport> eamInspectionOrderExports = + this.eamInspectionOrderMapper.queryList(Arrays.asList(ids.split(","))); + + if (eamInspectionOrderExports == null || eamInspectionOrderExports.isEmpty()) { + return null; + } + + eamInspectionOrderExports.forEach(eamInspectionOrderExport -> { + + // 鏃ユ湡澶勭悊 + if (StrUtil.isNotEmpty(eamInspectionOrderExport.getInspectionMonth())){ + if (eamInspectionOrderExport.getInspectionMonth().length() == 1) { + eamInspectionOrderExport.setInspectionMonth("0" + eamInspectionOrderExport.getInspectionMonth()); + } + } + String finalInspectionDate = eamInspectionOrderExport.getInspectionYear()+"-" + eamInspectionOrderExport.getInspectionMonth(); + // 鑾峰彇璇ヨ澶囩殑鏃ョ偣妫�鏄庣粏鏁版嵁 + List<EamInsOrderDetailResultResponse> detailResponseList = + eamInspectionOrderMapper.findInsOrderDetailList( + eamInspectionOrderExport.getEquipmentCode(), + finalInspectionDate + ); + + if (!detailResponseList.isEmpty()) { + // 鎸夐」鐩垎缁勫瓨鍌紙椤圭洰缂栫爜涓簁ey锛� + Map<Integer, EamInspectionOrderDetailExport> detailExportMap = new HashMap<>(); + + // 鍒濆鍖栭」鐩俊鎭紙姣忎釜椤圭洰瀵瑰簲涓�涓�31澶╃姸鎬佺殑瀵硅薄锛� + detailResponseList.forEach(detail -> { + Integer itemCode = detail.getItemCode(); + EamInspectionOrderDetailExport export = detailExportMap.get(itemCode); + + if (export == null) { + // 鍒涘缓鏂扮殑鐐规椤圭洰瀵硅薄 + export = new EamInspectionOrderDetailExport() + .setItemCode(itemCode) + .setItemName(detail.getItemName()) + .setItemDemand(detail.getItemDemand()) + .setDateFlag(new String[31]); // 鍒濆鍖�31澶╃姸鎬佹暟缁� + + detailExportMap.put(itemCode, export); + } + }); + + // 濉厖鍚勯」鐩瘡鏃ョ殑鐐规鐘舵�� + detailResponseList.forEach(detail -> { + Integer itemCode = detail.getItemCode(); + EamInspectionOrderDetailExport export = detailExportMap.get(itemCode); + + try { + Date newinspectionDate = detail.getInspectionDate(); + + // 澶勭悊绌烘棩鏈熸儏鍐� + if (newinspectionDate == null) { + log.warn("妫�娴嬪埌绌烘棩鏈熷��, itemCode: {}"); + return; + } + // 杞崲涓篖ocalDate + LocalDate date = newinspectionDate.toInstant() + .atZone(ZoneId.systemDefault()) + .toLocalDate(); + int day = date.getDayOfMonth(); + // 瀹夊叏璁剧疆鏃ユ湡鐘舵�� + if (day >= 1 && day <= 31) { + String[] dateFlags = export.getDateFlag(); + if (dateFlags == null) { + dateFlags = new String[31]; + export.setDateFlag(dateFlags); + } + if (StrUtil.isNotEmpty(detail.getInspectionResult())){ + switch (detail.getInspectionResult()) { + case "NORMAL": + dateFlags[day - 1] = "鈭�"; + break; + case "ANOMALY": + dateFlags[day - 1] = "脳"; + break; + case "FAULT": + dateFlags[day - 1] = "鈻�"; + break; + case "CLOSE": + dateFlags[day - 1] = "T"; + break; + } + } + } else { + log.warn("闈炴硶鏃ユ湡鍊�: {}, itemCode: {}"); + } + } + catch (DateTimeParseException | NullPointerException e) { + log.error("鏃ユ湡澶勭悊閿欒 - 鍘熷鍊�: {}, 椤圭洰: {}, 閿欒: {}"); + } + }); + // 灏嗙偣妫�椤圭洰闆嗗悎杞崲涓哄垪琛� + List<EamInspectionOrderDetailExport> detailExports = + new ArrayList<>(detailExportMap.values()); + // 璁剧疆鍒颁富瀵煎嚭瀵硅薄涓� + eamInspectionOrderExport.setEamDailyInspectionList(detailExports); + }else { + eamInspectionOrderExport.setEamDailyInspectionList(null); + } + // 鑾峰彇璇ヨ澶囩殑鍛ㄧ偣妫�鏄庣粏鏁版嵁 + List<EamWeekInsDetailResultResponse> eamWeekInsDetailResultResponseList = + eamInspectionOrderMapper.findWeekInsDetailList( + eamInspectionOrderExport.getEquipmentCode(), + finalInspectionDate + ); + if (!eamWeekInsDetailResultResponseList.isEmpty()) { + // 鎸夐」鐩垎缁勫瓨鍌紙椤圭洰缂栫爜涓簁ey锛� + Map<Integer, EamInspectionOrderDetailExport> detailExportMap = new HashMap<>(); + // 鍒濆鍖栭」鐩俊鎭� + eamWeekInsDetailResultResponseList.forEach(detail -> { + Integer itemCode = detail.getItemCode(); + EamInspectionOrderDetailExport export = detailExportMap.get(itemCode); + if (export == null) { + // 鍒涘缓鏂扮殑鐐规椤圭洰瀵硅薄骞跺垵濮嬪寲weekFlag鏁扮粍 + export = new EamInspectionOrderDetailExport() + .setItemCode(itemCode) + .setItemName(detail.getItemName()) + .setItemDemand(detail.getItemDemand()) + .setWeekFlag(new String[5]); // 鏄庣‘鍒濆鍖栭暱搴︿负5 + detailExportMap.put(itemCode, export); + } + }); + // 濉厖鍚勯」鐩瘡鍛ㄧ殑鐐规鐘舵�� + eamWeekInsDetailResultResponseList.forEach(detail -> { + Integer itemCode = detail.getItemCode(); + EamInspectionOrderDetailExport export = detailExportMap.get(itemCode); + + Date newinspectionDate = detail.getPlanInspectionDate(); + if (newinspectionDate == null) { + log.warn("妫�娴嬪埌绌烘棩鏈熷��, itemCode: {}"); + return; + } + + // 璁$畻璇ユ棩鏈熸槸褰撴湀绗嚑鍛� (1-5) + int week = calculateWeekOfMonth(newinspectionDate); + + if (week >= 1 && week <= 5) { + String[] weekFlags = export.getWeekFlag(); + if (weekFlags == null) { + weekFlags = new String[31]; + export.setWeekFlag(weekFlags); + } + if (StrUtil.isNotEmpty(detail.getInspectionResult())){ + switch (detail.getInspectionResult()) { + case "NORMAL": + weekFlags[week - 1] = "鈭�"; + break; + case "ANOMALY": + weekFlags[week - 1] = "脳"; + break; + case "FAULT": + weekFlags[week - 1] = "鈻�"; + break; + case "CLOSE": + weekFlags[week - 1] = "T"; + break; + } + } + } + }); + // 灏嗙偣妫�椤圭洰闆嗗悎杞崲涓哄垪琛� + List<EamInspectionOrderDetailExport> weekDetailExports = + new ArrayList<>(detailExportMap.values()); + // 璁剧疆鍒颁富瀵煎嚭瀵硅薄涓� + eamInspectionOrderExport.setEamWeeklyInspectionList(weekDetailExports); + }else { + eamInspectionOrderExport.setEamWeeklyInspectionList(null); + } + + + // ================== 娣诲姞鏃ョ偣妫�璐d换浜轰俊鎭� ================== + DailyResponsibleInfo dailyResponsible = new DailyResponsibleInfo(); + List<EamInsOrderDetailUserResponse> dailyUserResponses = + eamInspectionOrderMapper.findInspectionOrderDetailUserList( + eamInspectionOrderExport.getEquipmentCode(), + finalInspectionDate + ); + + if (dailyUserResponses != null && !dailyUserResponses.isEmpty()) { + dailyUserResponses.forEach(response -> { + try { + Date date = response.getInspectionDate(); + if (date == null) return; + + LocalDate localDate = date.toInstant() + .atZone(ZoneId.systemDefault()) + .toLocalDate(); + + int day = localDate.getDayOfMonth(); + if (day < 1 || day > 31) return; + + // 鑾峰彇鎿嶄綔鍛樺拰纭浜哄鍚� + String operator = sysDictService.queryTableDictTextByKey( + "sys_user", "realname", "username", response.getOperator()); + String confirmUser = sysDictService.queryTableDictTextByKey( + "sys_user", "realname", "username", response.getConfirmUser()); + + // 璁剧疆璐d换浜轰俊鎭� + dailyResponsible.setResponsibleForDay(day, operator, confirmUser); + } catch (Exception e) { + log.error("澶勭悊鏃ョ偣妫�璐d换浜轰俊鎭嚭閿�: {}"); + } + }); + } + eamInspectionOrderExport.setDailyResponsibleInfo(dailyResponsible); + + // ================== 娣诲姞鍛ㄧ偣妫�璐d换浜轰俊鎭� ================== + WeeklyResponsibleInfo weeklyResponsible = new WeeklyResponsibleInfo(); + List<EamWeekInsDetailUserResponse> weeklyUserResponses = + eamInspectionOrderMapper.findWeekInsOrderDetailUserList( + eamInspectionOrderExport.getEquipmentCode(), + finalInspectionDate + ); + + if (weeklyUserResponses != null && !weeklyUserResponses.isEmpty()) { + weeklyUserResponses.forEach(response -> { + try { + Date date = response.getPlanInspectionDate(); + if (date == null) return; + + // 璁$畻鍛ㄦ暟 + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + int week = calendar.get(Calendar.WEEK_OF_MONTH); + if (week < 1 || week > 5) return; + + // 鑾峰彇鎿嶄綔鍛樺拰纭浜哄鍚� + String operator = sysDictService.queryTableDictTextByKey( + "sys_user", "realname", "username", response.getInspector()); + String confirmUser = sysDictService.queryTableDictTextByKey( + "sys_user", "realname", "username", response.getConfirmUser()); + + // 璁剧疆璐d换浜轰俊鎭� + weeklyResponsible.setResponsibleForWeek(week, operator, confirmUser); + } catch (Exception e) { + log.error("澶勭悊鍛ㄧ偣妫�璐d换浜轰俊鎭嚭閿�: {}"); + } + }); + } + eamInspectionOrderExport.setWeeklyResponsibleInfo(weeklyResponsible); + }); + + return eamInspectionOrderExports; + + } + + /** + * 璁$畻鏃ユ湡鍦ㄥ綋鏈堟槸绗嚑鍛紙1-5锛� + */ + private int calculateWeekOfMonth(Date date) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + return calendar.get(Calendar.WEEK_OF_MONTH); + } private boolean isValidRequest(EamInspectionOrderRequest request) { return StrUtil.isNotBlank(request.getTaskId()) && StrUtil.isNotBlank(request.getDataId()); @@ -754,13 +1029,14 @@ values.put("organization", request.getConfirmComment()); values.put("comment", request.getConfirmComment()); values.put("confirmation", request.getConfirmDealType()); - request.setComment(request.getConfirmComment()); + request.setComment("缁翠慨宸ョ‘璁ょ粨鏉�"); if ("2".equals(request.getConfirmDealType())) { // 缁翠慨宸ラ┏鍥� List<String> usernames = new ArrayList<>(); usernames.add(order.getOperator()); order.setInspectionStatus(InspectionStatus.UNDER_INSPECTION.name()); values.put("NextAssignee", usernames); + request.setComment("缁翠慨宸ラ┏鍥炵粨鏉�"); } } request.setValues(values); -- Gitblit v1.9.3