From 954be37aa4ba2bcfbc231a50620c4d1ce0be4b41 Mon Sep 17 00:00:00 2001 From: jiangpeng Date: Mon, 22 Jun 2026 19:45:49 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9AMCP=E6=88=90=E6=9C=AC=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E8=A7=84=E5=88=99=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tools/ProjectOrderInfoToolProvider.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/ruoyi-sip/src/main/java/com/ruoyi/sip/llm/tools/ProjectOrderInfoToolProvider.java b/ruoyi-sip/src/main/java/com/ruoyi/sip/llm/tools/ProjectOrderInfoToolProvider.java index 70bc0df0..566b0ee6 100644 --- a/ruoyi-sip/src/main/java/com/ruoyi/sip/llm/tools/ProjectOrderInfoToolProvider.java +++ b/ruoyi-sip/src/main/java/com/ruoyi/sip/llm/tools/ProjectOrderInfoToolProvider.java @@ -42,6 +42,8 @@ public class ProjectOrderInfoToolProvider extends AbstractMcpToolProvider { private static final String INDUSTRY_TYPE_YYS_DICT_TYPE = "bg_yys"; private static final String PROJECT_STAGE_DICT_TYPE = "project_stage"; private static final String NOT_DELIVERED_TEXT = "未配货完成"; + private static final Set SERVICE_MERGE_SOFTWARE_CODES = initCodeSet("0504A14F", "0504A1JX"); + private static final Set SERVICE_MERGE_SERVICE_CODES = initCodeSet("0202A1NU", "0202A1NS", "0202A1NT"); @Autowired private IProjectOrderInfoService projectOrderInfoService; @@ -205,6 +207,7 @@ public class ProjectOrderInfoToolProvider extends AbstractMcpToolProvider { orderShipmentMap, Collections.emptyMap(), true, orderInfo.getOrderCode()); ProductGroupSummary serviceSummary = appendProductFields(item, "service", serviceList, Collections.emptyMap(), serviceCostMap.getOrDefault(orderInfo.getOrderCode(), Collections.emptyMap()), false, orderInfo.getOrderCode()); + mergeSpecifiedServiceToSoftware(item, softwareList, serviceList, softwareSummary, serviceSummary, orderInfo.getOrderCode()); BigDecimal orderAmountWithTax = defaultValue(orderInfo.getShipmentAmount()); BigDecimal discountAmountWithTax = softwareSummary.salesWithTax @@ -569,6 +572,89 @@ public class ProjectOrderInfoToolProvider extends AbstractMcpToolProvider { return summary; } + private void mergeSpecifiedServiceToSoftware(Map item, + List softwareList, + List serviceList, + ProductGroupSummary softwareSummary, + ProductGroupSummary serviceSummary, + String orderCode) { + int softwareIndex = findFirstProductIndex(softwareList, SERVICE_MERGE_SOFTWARE_CODES); + int serviceIndex = findFirstProductIndex(serviceList, SERVICE_MERGE_SERVICE_CODES); + if (softwareIndex < 0 || serviceIndex < 0) { + return; + } + + int softwareFieldIndex = softwareIndex + 1; + int serviceFieldIndex = serviceIndex + 1; + OrderProductBindAmountDto softwareBindAmountDto = projectOrderInfoMapper.selectOrderProductBindAmount( + orderCode, softwareList.get(softwareIndex).getProductBomCode()); + OrderProductBindAmountDto serviceBindAmountDto = projectOrderInfoMapper.selectOrderProductBindAmount( + orderCode, serviceList.get(serviceIndex).getProductBomCode()); + if (!isStocked(item.get("softwareOrderStockingStatus" + softwareFieldIndex)) + || !isStocked(item.get("serviceOrderStockingStatus" + serviceFieldIndex)) + || softwareBindAmountDto == null + || serviceBindAmountDto == null) { + return; + } + + BigDecimal serviceSalesWithTax = amountValue(item.get("serviceSalesAmount" + serviceFieldIndex)); + BigDecimal serviceCostWithTax = defaultValue(serviceBindAmountDto.getCostWithTax()); + BigDecimal serviceCostWithoutTax = defaultValue(serviceBindAmountDto.getCostWithoutTax()); + BigDecimal serviceAmountWithoutTax = defaultValue(serviceBindAmountDto.getAmountWithoutTax()); + BigDecimal serviceGrossProfit = serviceAmountWithoutTax.subtract(serviceCostWithoutTax); + + BigDecimal softwareSalesWithTax = amountValue(item.get("softwareSalesAmount" + softwareFieldIndex)).add(serviceSalesWithTax); + BigDecimal softwareCostWithTax = defaultValue(softwareBindAmountDto.getCostWithTax()).add(serviceCostWithTax); + BigDecimal softwareCostWithoutTax = defaultValue(softwareBindAmountDto.getCostWithoutTax()).add(serviceCostWithoutTax); + BigDecimal softwareAmountWithoutTax = defaultValue(softwareBindAmountDto.getAmountWithoutTax()).add(serviceAmountWithoutTax); + BigDecimal softwareGrossProfit = softwareAmountWithoutTax.subtract(softwareCostWithoutTax); + + item.put("softwareSalesAmount" + softwareFieldIndex, softwareSalesWithTax); + item.put("softwareCostAmount" + softwareFieldIndex, softwareCostWithTax); + item.put("softwareGrossProfit" + softwareFieldIndex, softwareGrossProfit); + item.put("softwareGrossProfitRate" + softwareFieldIndex, percentage(softwareGrossProfit, softwareAmountWithoutTax)); + item.put("serviceSalesAmount" + serviceFieldIndex, BigDecimal.ZERO); + item.put("serviceCostAmount" + serviceFieldIndex, BigDecimal.ZERO); + item.put("serviceGrossProfit" + serviceFieldIndex, BigDecimal.ZERO); + item.put("serviceGrossProfitRate" + serviceFieldIndex, BigDecimal.ZERO); + + softwareSummary.salesWithTax = softwareSummary.salesWithTax.add(serviceSalesWithTax); + softwareSummary.salesWithoutTax = softwareSummary.salesWithoutTax.add(serviceAmountWithoutTax); + softwareSummary.amountWithoutTax = softwareSummary.amountWithoutTax.add(serviceAmountWithoutTax); + softwareSummary.costWithTax = softwareSummary.costWithTax.add(serviceCostWithTax); + softwareSummary.costWithoutTax = softwareSummary.costWithoutTax.add(serviceCostWithoutTax); + softwareSummary.grossProfit = softwareSummary.grossProfit.add(serviceGrossProfit); + softwareSummary.grossProfitRate = percentage(softwareSummary.grossProfit, softwareSummary.amountWithoutTax); + + serviceSummary.salesWithTax = serviceSummary.salesWithTax.subtract(serviceSalesWithTax); + serviceSummary.salesWithoutTax = serviceSummary.salesWithoutTax.subtract(serviceAmountWithoutTax); + serviceSummary.amountWithoutTax = serviceSummary.amountWithoutTax.subtract(serviceAmountWithoutTax); + serviceSummary.costWithTax = serviceSummary.costWithTax.subtract(serviceCostWithTax); + serviceSummary.costWithoutTax = serviceSummary.costWithoutTax.subtract(serviceCostWithoutTax); + serviceSummary.grossProfit = serviceSummary.grossProfit.subtract(serviceGrossProfit); + serviceSummary.grossProfitRate = percentage(serviceSummary.grossProfit, serviceSummary.amountWithoutTax); + } + + private int findFirstProductIndex(List productInfos, Set productCodes) { + if (CollUtil.isEmpty(productInfos)) { + return -1; + } + for (int i = 0; i < productInfos.size(); i++) { + if (productCodes.contains(productInfos.get(i).getProductBomCode())) { + return i; + } + } + return -1; + } + + private boolean isStocked(Object value) { + return Boolean.TRUE.equals(value); + } + + private BigDecimal amountValue(Object value) { + return value instanceof BigDecimal ? (BigDecimal) value : BigDecimal.ZERO; + } + private ProductCostDisplay buildShipmentProductCostDisplay(ProjectProductInfo productInfo, ProductShipmentSummary shipmentSummary) { ProductCostDisplay display = new ProductCostDisplay(); BigDecimal requiredQuantity = BigDecimal.valueOf(productInfo.getQuantity() == null ? 0L : productInfo.getQuantity()); @@ -698,6 +784,12 @@ public class ProjectOrderInfoToolProvider extends AbstractMcpToolProvider { return value == null ? BigDecimal.ZERO : value; } + private static Set initCodeSet(String... codes) { + Set result = new LinkedHashSet<>(); + Collections.addAll(result, codes); + return Collections.unmodifiableSet(result); + } + private String formatDate(Date value) { return value == null ? "" : DateUtil.format(value, "yyyy-MM-dd"); }