From 16853a9dc9b801c5a3d1519ee7e41a28cf1e16f8 Mon Sep 17 00:00:00 2001 From: tzy Date: Sun, 14 Sep 2025 20:35:15 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=91=E8=9D=B6=E8=B5=84=E4=BA=A7=E5=8D=A1?= =?UTF-8?q?=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KingdeeWorkCenterDataController.java | 120 +++++++++++++----- 1 file changed, 90 insertions(+), 30 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/KingdeeWorkCenterDataController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/KingdeeWorkCenterDataController.java index 657b247..bf91476 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/KingdeeWorkCenterDataController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/KingdeeWorkCenterDataController.java @@ -24,6 +24,10 @@ import com.google.gson.JsonObject; import com.kingdee.bos.webapi.sdk.K3CloudApi; import com.ruoyi.common.utils.HttpRequestUtil; import com.ruoyi.common.utils.WxRobotUtil; +import com.ruoyi.common.utils.file.SmbUtil; +import com.ruoyi.common.poi.ExcelTemplateProc; +import com.ruoyi.common.poi.DynamicDataMapping; +import com.ruoyi.common.exception.ServiceException; import com.ruoyi.system.domain.SafetyStock; import com.ruoyi.system.domain.WlStockData; import com.ruoyi.system.domain.dto.*; @@ -846,40 +850,49 @@ public class KingdeeWorkCenterDataController extends BaseController { .append("更新时间:").append(currentTime).append("\n\n") .append("🔧 订单数据统计:\n"); - // 获取并统计每个工段的数据 - for (String workCenter : workCenters) { - try { - R> result = getKingdeeDelayData(workCenter); - if (R.isError(result) || CollUtil.isEmpty(result.getData())) { - msg.append("- ").append(workCenter).append(" (无数据)\n"); - continue; - } + // 获取采购订单和采购申请数据 + List purchaseOrderList = JdUtil.getPurchaseOrder(); + List purchaseRequestList = JdUtil.getPurchaseRequestOrder(); + + msg.append("- 采购订单:").append(purchaseOrderList.size()).append("条\n"); + msg.append("- 采购申请:").append(purchaseRequestList.size()).append("条\n"); - List dataList = result.getData(); - msg.append("- ").append(workCenter).append(" (共").append(dataList.size()).append("条数据)\n"); + // 生成Excel文件使用采购模板 + String fileName = String.format("采购订单和申请数据_%s.xlsx", + DateUtil.format(new Date(), "yyyyMMddHHmmss")); + String filePath = FileUtils.getTempDirectoryPath() + File.separator + fileName; - // 生成Excel文件 - String fileName = String.format("%s生产延期数据_%s.xlsx", workCenter, - DateUtil.format(new Date(), "yyyyMMddHHmmss")); - String filePath = FileUtils.getTempDirectoryPath() + File.separator + fileName; + // 准备模板数据 + Map staticDataMap = new HashMap<>(); + staticDataMap.put("currentTime", DateUtil.format(new Date(), "yyyy年MM月dd日 HH:mm:ss")); + staticDataMap.put("purchaseOrderCount", purchaseOrderList.size()); + staticDataMap.put("purchaseRequestCount", purchaseRequestList.size()); - // 使用EasyExcel写入数据 - EasyExcel.write(filePath, KingdeeWorkCenterDataVo.class) - .sheet("工段数据") - .doWrite(BeanUtil.copyToList(dataList, KingdeeWorkCenterDataVo.class)); - - // 发送Excel文件 - File excelFile = new File(filePath); - wxRobotUtil.sendFileToWeChatGroup(excelFile, robotId); - - // 删除临时文件 - FileUtils.deleteQuietly(excelFile); - - } catch (Exception e) { - log.error("获取工段{}数据失败", workCenter, e); - msg.append("- ").append(workCenter).append(" (获取失败: ").append(e.getMessage()).append(")\n"); - } + List dynamicDataMappingList = new ArrayList<>(); + + // 添加采购订单数据 + if (!purchaseOrderList.isEmpty()) { + List> orderDataList = convertPurchaseOrderToMapList(purchaseOrderList); + dynamicDataMappingList.addAll(DynamicDataMapping.createOneDataList("PurchaseOrder", orderDataList)); } + + // 添加采购申请数据 + if (!purchaseRequestList.isEmpty()) { + List> requestDataList = convertPurchaseRequestToMapList(purchaseRequestList); + dynamicDataMappingList.addAll(DynamicDataMapping.createOneDataList("PurchaseRequest", requestDataList)); + } + + // 使用采购模板生成Excel + String templatePath = "EXCEL模板/采购订单模板.xlsx"; + ExcelTemplateProc.doExportExcelByTemplateProc(templatePath, filePath, staticDataMap, dynamicDataMappingList); + + // 发送Excel文件 + File excelFile = new File(filePath); + if (excelFile.exists()) { + wxRobotUtil.sendFileToWeChatGroup(excelFile, robotId); + FileUtils.deleteQuietly(excelFile); + } + msg.append("\n详细数据请查看发送的Excel文件!"); wxRobotUtil.sendMsgToWeChatGroup(msg.toString(), robotId, true); // @所有人 @@ -892,6 +905,53 @@ public class KingdeeWorkCenterDataController extends BaseController { } } + /** + * 转换采购订单数据为Map列表 + */ + private List> convertPurchaseOrderToMapList(List purchaseOrderList) { + List> mapList = new ArrayList<>(); + int index = 1; + for (PurchaseOrderExcelDTO item : purchaseOrderList) { + Map map = new HashMap<>(); + map.put("index", index); + map.put("orderNo", item.getFBillNo()); + map.put("supplierName", item.getFSupplierIdFName()); + map.put("materialCode", item.getFMaterialIdFNumber()); + map.put("materialName", item.getFMaterialName()); + map.put("quantity", item.getFQty()); + map.put("orderDate", item.getFDate()); + map.put("deliveryDate", item.getFDeliveryDate()); + map.put("productionOrderNo", item.getFUCHNText2()); + mapList.add(map); + index++; + } + return mapList; + } + /** + * 转换采购申请数据为Map列表 + */ + private List> convertPurchaseRequestToMapList(List purchaseRequestList) { + List> mapList = new ArrayList<>(); + int index = 1; + for (PurchaseRequestExcelDTO item : purchaseRequestList) { + Map map = new HashMap<>(); + map.put("index", index); + map.put("requestNo", item.getFBillNo()); + map.put("billType", item.getFBillTypeID()); + map.put("suggestPurDate", item.getFSuggestPurDate()); + map.put("suggestSupplier", item.getFSuggestSupplierId_FName()); + map.put("materialCode", item.getFMaterialId_FNumber()); + map.put("materialName", item.getFMaterialName()); + map.put("priceUnit", item.getFPriceUnitId_FName()); + map.put("quantity", item.getFReqQty()); + map.put("arrivalDate", item.getFArrivalDate()); + map.put("applicationDate", item.getFApplicationDate()); + map.put("productionOrderNo", item.getFUCHNText()); + mapList.add(map); + index++; + } + return mapList; + } }