From 0c2b53478d31851147ea397b74b61d424f456bd6 Mon Sep 17 00:00:00 2001 From: tzy <1042411602@qq.com> Date: Sun, 14 Sep 2025 20:03:26 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=87=E8=B4=AD=E8=AE=A2=E5=8D=95=20?= =?UTF-8?q?=E9=87=87=E8=B4=AD=E7=94=B3=E8=AF=B7=E5=8D=95=20=E5=BB=B6?= =?UTF-8?q?=E6=9C=9F=E6=8F=90=E9=86=92=20=E6=8F=90=E5=89=8D=E6=8F=90?= =?UTF-8?q?=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KingdeeWorkCenterDataController.java | 68 ++++++++++- .../domain/dto/PurchaseOrderExcelDTO.java | 56 +++++++++ .../domain/dto/PurchaseRequestExcelDTO.java | 75 ++++++++++++ .../java/com/ruoyi/system/runner/JdUtil.java | 110 ++++++++++++++++++ 4 files changed, 305 insertions(+), 4 deletions(-) create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/PurchaseOrderExcelDTO.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/PurchaseRequestExcelDTO.java 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 92555d6..657b247 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 @@ -26,10 +26,7 @@ import com.ruoyi.common.utils.HttpRequestUtil; import com.ruoyi.common.utils.WxRobotUtil; import com.ruoyi.system.domain.SafetyStock; import com.ruoyi.system.domain.WlStockData; -import com.ruoyi.system.domain.dto.JDInventoryDTO; -import com.ruoyi.system.domain.dto.JDProductionDTO; -import com.ruoyi.system.domain.dto.ProMoDTO; -import com.ruoyi.system.domain.dto.PurchaseOrderDTO; +import com.ruoyi.system.domain.dto.*; import com.ruoyi.system.domain.vo.SafetyStockVo; import com.ruoyi.system.domain.vo.WlStockDataVo; import com.ruoyi.system.mapper.SafetyStockMapper; @@ -834,4 +831,67 @@ public class KingdeeWorkCenterDataController extends BaseController { return R.ok(); } + + @Log(title = "采购订单和采购申请单") + @XxlJob("getMassageDelayDate") + public R getMassageDelayDate1() { + try { + // String robotId = "4d2f037d-0cee-493a-a4ff-1758f67b8069"; + String robotId = "483489b2-b219-468c-851f-f56a34a62d91"; + List list = JdUtil.getPurchaseOrder(); + List list2 = JdUtil.getPurchaseRequestOrder(); + String currentTime = DateUtil.format(new Date(), "yyyy年MM月dd日 HH:mm:ss"); + StringBuilder msg = new StringBuilder(); + msg.append("🏭 采购订单和采购申请更新\n\n") + .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 dataList = result.getData(); + msg.append("- ").append(workCenter).append(" (共").append(dataList.size()).append("条数据)\n"); + + // 生成Excel文件 + String fileName = String.format("%s生产延期数据_%s.xlsx", workCenter, + DateUtil.format(new Date(), "yyyyMMddHHmmss")); + String filePath = FileUtils.getTempDirectoryPath() + File.separator + fileName; + + // 使用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"); + } + } + + msg.append("\n详细数据请查看发送的Excel文件!"); + wxRobotUtil.sendMsgToWeChatGroup(msg.toString(), robotId, true); // @所有人 + + return R.ok(); + + } catch (Exception e) { + log.error("发送工段数据失败", e); + return R.fail("发送工段数据失败:" + e.getMessage()); + } + } + + + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/PurchaseOrderExcelDTO.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/PurchaseOrderExcelDTO.java new file mode 100644 index 0000000..c08eeb6 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/PurchaseOrderExcelDTO.java @@ -0,0 +1,56 @@ +package com.ruoyi.system.domain.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +public class PurchaseOrderExcelDTO { + /** + * 单据编号 + */ + @JsonProperty("FBillNo") + private String FBillNo; + + /** + * 采购日期 + */ + @JsonProperty("FDate") + private String FDate; + + /** + * 供应商名称 + */ + @JsonProperty("FSupplierId.FName") + private String FSupplierIdFName; + + /** + * 物料编码 + */ + @JsonProperty("FMaterialId.FNumber") + private String FMaterialIdFNumber; + + /** + * 物料名称 + */ + @JsonProperty("FMaterialName") + private String FMaterialName; + + /** + * 数量 + */ + @JsonProperty("FQty") + private String FQty; + + /** + * 交货日期 + */ + @JsonProperty("FDeliveryDate") + private String FDeliveryDate; + + /** + * 生产令号 + */ + @JsonProperty("F_UCHN_Text2") + private String FUCHNText2; + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/PurchaseRequestExcelDTO.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/PurchaseRequestExcelDTO.java new file mode 100644 index 0000000..2a6b35c --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/dto/PurchaseRequestExcelDTO.java @@ -0,0 +1,75 @@ +package com.ruoyi.system.domain.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +public class PurchaseRequestExcelDTO { + /** + * 单据编号 + */ + @JsonProperty("FBillNo") + private String FBillNo; + + /** + * 单据类型 + */ + @JsonProperty("FBillTypeID") + private String FBillTypeID; + + /** + * 建议采购日期 + */ + @JsonProperty("FSuggestPurDate") + private String FSuggestPurDate; + + /** + * 建议供应商名称 + */ + @JsonProperty("FSuggestSupplierId.FName") + private String FSuggestSupplierId_FName; + + /** + * 物料编码 + */ + @JsonProperty("FMaterialId.FNumber") + private String FMaterialId_FNumber; + + /** + * 物料名称 + */ + @JsonProperty("FMaterialName") + private String FMaterialName; + + /** + * 计价单位 + */ + @JsonProperty("FPriceUnitId.FName") + private String FPriceUnitId_FName; + + /** + * 申请数量 + */ + @JsonProperty("FReqQty") + private String FReqQty; + + /** + * 到货日期 + */ + @JsonProperty("FArrivalDate") + private String FArrivalDate; + + /** + * 申请日期 + */ + @JsonProperty("FApplicationDate") + private String FApplicationDate; + + /** + * 生产令号 + */ + @JsonProperty("F_UCHN_Text") + private String FUCHNText; + + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/runner/JdUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/runner/JdUtil.java index ac7692e..0d9f18b 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/runner/JdUtil.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/runner/JdUtil.java @@ -2518,4 +2518,114 @@ public class JdUtil { } + public static List getPurchaseOrder() { + K3CloudApi client = new K3CloudApi(); + // 请求参数,要求为json字符串 + JsonObject json = new JsonObject(); + json.addProperty("FormId", "PUR_PurchaseOrder"); + json.addProperty("FieldKeys", "FBillNo,FDate,FSupplierId.FName,FMaterialId.FNumber,FMaterialName,FQty,FDeliveryDate,F_UCHN_Text2"); + // 创建过滤条件 + JsonObject filterObject = new JsonObject(); + JsonArray filterString = new JsonArray(); + filterObject.addProperty("FieldName", "FCloseStatus"); + filterObject.addProperty("Compare", "67"); + filterObject.addProperty("Value", 105); + filterObject.addProperty("Left", ""); + filterObject.addProperty("Right", ""); + filterObject.addProperty("Logic", 0); + filterString.add(filterObject); + + JsonObject filterObject1 = new JsonObject(); + filterObject1.addProperty("FieldName", "FMRPCloseStatus"); + filterObject1.addProperty("Compare", "67"); + filterObject1.addProperty("Value", 105); + filterObject1.addProperty("Left", ""); + filterObject1.addProperty("Right", ""); + filterObject1.addProperty("Logic", 0); + filterString.add(filterObject1); + + JsonObject filterObject2 = new JsonObject(); + filterObject2.addProperty("FieldName", "FDocumentStatus"); + filterObject2.addProperty("Compare", "67"); + filterObject2.addProperty("Value", 105); + filterObject2.addProperty("Left", ""); + filterObject2.addProperty("Right", ""); + filterObject2.addProperty("Logic", 0); + filterString.add(filterObject2); + + json.add("FilterString", filterString); + json.addProperty("OrderString", ""); + json.addProperty("TopRowCount", 0); + json.addProperty("StartRow", 0); + json.addProperty("Limit", 10000); + json.addProperty("SubSystemId", ""); + + String jsonData = json.toString(); + List purcs = null; + try { + // 调用接口 + String resultJson = String.valueOf(client.billQuery(jsonData)); + JsonArray jsonArray = new Gson().fromJson(resultJson, JsonArray.class); + // 使用 ObjectMapper 将 JsonArray 转换为 List + ObjectMapper objectMapper = new ObjectMapper(); + purcs = objectMapper.readValue(jsonArray.toString(), + new TypeReference>() { + }); + } catch (Exception e) { + e.printStackTrace(); // 输出异常日志 + } + + return purcs; // 返回结果 + } + + public static List getPurchaseRequestOrder() { + K3CloudApi client = new K3CloudApi(); + // 请求参数,要求为json字符串 + JsonObject json = new JsonObject(); + json.addProperty("FormId", "PUR_Requisition"); + json.addProperty("FieldKeys", "FBillNo,FBillTypeID,FSuggestPurDate,FSuggestSupplierId.FName,FMaterialId.FNumber,FMaterialName,FPriceUnitId.FName,FReqQty,FArrivalDate,FApplicationDate,F_UCHN_Text"); + // 创建过滤条件 + JsonObject filterObject = new JsonObject(); + JsonArray filterString = new JsonArray(); + filterObject.addProperty("FieldName", "FDocumentStatus"); + filterObject.addProperty("Compare", "67"); + filterObject.addProperty("Value", 105); + filterObject.addProperty("Left", ""); + filterObject.addProperty("Right", ""); + filterObject.addProperty("Logic", 0); + filterString.add(filterObject); + + JsonObject filterObject1 = new JsonObject(); + filterObject1.addProperty("FieldName", "FCloseStatus"); + filterObject1.addProperty("Compare", "67"); + filterObject1.addProperty("Value", 105); + filterObject1.addProperty("Left", ""); + filterObject1.addProperty("Right", ""); + filterObject1.addProperty("Logic", 0); + filterString.add(filterObject1); + + json.add("FilterString", filterString); + json.addProperty("OrderString", ""); + json.addProperty("TopRowCount", 0); + json.addProperty("StartRow", 0); + json.addProperty("Limit", 10000); + json.addProperty("SubSystemId", ""); + + String jsonData = json.toString(); + List purchaseRequestExcelDTOList = null; + try { + // 调用接口 + String resultJson = String.valueOf(client.billQuery(jsonData)); + JsonArray jsonArray = new Gson().fromJson(resultJson, JsonArray.class); + // 使用 ObjectMapper 将 JsonArray 转换为 List + ObjectMapper objectMapper = new ObjectMapper(); + purchaseRequestExcelDTOList = objectMapper.readValue(jsonArray.toString(), + new TypeReference>() { + }); + } catch (Exception e) { + e.printStackTrace(); // 输出异常日志 + } + + return purchaseRequestExcelDTOList; // 返回结果 + } }