From a57dceb3e6bc02e28a86f4de66f593706452c2b4 Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期六, 07 十一月 2026 14:53:09 +0800
Subject: [PATCH] refactor: 需求10/23 改为基于 ERP 实现,修正此前 ERP 可用性误判
---
/dev/null | 183 ------------------------------
sql/mysql/erp_menus_restore_20261107.sql | 28 ++++
yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/api/sale/ErpSaleOrderApi.java | 9 +
yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/api/sale/ErpSaleOrderApiImpl.java | 10 +
sql/mysql/after_sale_cancellation_order_link_20261107.sql | 14 ++
yudao-module-aftersales/src/main/java/cn/iocoder/yudao/module/aftersales/service/cancellation/AfterSaleCancellationService.java | 70 ++++++++---
yudao-module-aftersales/src/main/java/cn/iocoder/yudao/module/aftersales/controller/admin/cancellation/vo/AfterSaleCancellationSaveReqVO.java | 6
yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/controller/admin/statistics/SrmStatisticsController.java | 27 ----
yudao-module-aftersales/src/main/java/cn/iocoder/yudao/module/aftersales/dal/dataobject/cancellation/AfterSaleCancellationDO.java | 2
9 files changed, 121 insertions(+), 228 deletions(-)
diff --git a/sql/mysql/after_sale_cancellation_order_link_20261107.sql b/sql/mysql/after_sale_cancellation_order_link_20261107.sql
new file mode 100644
index 0000000..9c206dd
--- /dev/null
+++ b/sql/mysql/after_sale_cancellation_order_link_20261107.sql
@@ -0,0 +1,14 @@
+-- 閫�鍗曞彈鐞嗗崟鏀寔鍏宠仈 ERP 閿�鍞鍗曪紝瀹℃壒閫氳繃鑱斿姩浣滃簾
+SET @c := (SELECT COUNT(*) FROM information_schema.COLUMNS
+ WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='after_sale_cancellation' AND COLUMN_NAME='sale_order_id');
+SET @s := IF(@c=0,
+ 'ALTER TABLE after_sale_cancellation ADD COLUMN sale_order_id BIGINT DEFAULT NULL COMMENT ''ERP 閿�鍞鍗曠紪鍙�'' AFTER contract_id',
+ 'SELECT 1');
+PREPARE st FROM @s; EXECUTE st; DEALLOCATE PREPARE st;
+
+SET @i := (SELECT COUNT(*) FROM information_schema.STATISTICS
+ WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='after_sale_cancellation' AND INDEX_NAME='idx_after_sale_cancellation_order');
+SET @s2 := IF(@i=0,
+ 'ALTER TABLE after_sale_cancellation ADD KEY idx_after_sale_cancellation_order (sale_order_id, deleted)',
+ 'SELECT 1');
+PREPARE st2 FROM @s2; EXECUTE st2; DEALLOCATE PREPARE st2;
diff --git a/sql/mysql/erp_menus_restore_20261107.sql b/sql/mysql/erp_menus_restore_20261107.sql
new file mode 100644
index 0000000..add49c5
--- /dev/null
+++ b/sql/mysql/erp_menus_restore_20261107.sql
@@ -0,0 +1,28 @@
+-- ERP 瀹為檯宸插惎鐢紙閿�鍞�/閲囪喘/浠樻璁㈠崟鎺ュ彛鍧囧彲鐢級锛屾挙閿�姝ゅ墠鐨� ERP 鍋滅敤涓庤彍鍗曢殣钘忥紝
+-- 骞舵妸銆岄噰璐垚鏈垎鏋愩�嶆敼涓� ERP 閲囪喘璁㈠崟鍙e緞鐨勯〉闈€��
+
+-- 1) 鎭㈠閲囪喘绠$悊涓� ERP 瀛愯彍鍗曞惎鐢紙鎾ら攢璇垽鍋滅敤锛�
+UPDATE system_menu SET status = 0
+WHERE CAST(deleted AS UNSIGNED)=0 AND parent_id = 2602 AND component LIKE 'erp/%';
+
+-- 2) 鎭㈠浠撳簱澶у睆锛堢嚎涓婁负鍚敤鐘舵�侊級
+UPDATE system_menu SET status = 0, visible = b'1'
+WHERE CAST(deleted AS UNSIGNED)=0 AND component = 'bi/warehouse/index';
+
+-- 3) 閲囪喘鎴愭湰鍒嗘瀽鏀规寚鍚� ERP 椤甸潰锛屽苟涓婃寕鍒般�岄噰璐鐞嗐�嶄笅锛堝師鎸傚湪 SRM 涓嬶級
+UPDATE system_menu SET component = 'erp/purchase/statistics/price-analysis',
+ component_name = 'ErpPurchasePriceAnalysis',
+ name = '閲囪喘鎴愭湰鍒嗘瀽',
+ parent_id = 2602, sort = 10,
+ status = 0, visible = b'1'
+WHERE CAST(deleted AS UNSIGNED)=0
+ AND component IN ('srm/statistics/cost-analysis','erp/purchase/statistics/price-analysis');
+
+-- 4) 纭鑿滃崟鎺堟潈
+INSERT INTO system_role_menu (role_id, menu_id, creator, create_time, updater, update_time, deleted)
+SELECT rm.role_id, m.id, '1', NOW(), '1', NOW(), b'0'
+FROM (SELECT DISTINCT role_id FROM system_role_menu WHERE menu_id = 602524 AND CAST(deleted AS UNSIGNED)=0) rm
+CROSS JOIN (SELECT id FROM system_menu
+ WHERE component='erp/purchase/statistics/price-analysis' AND CAST(deleted AS UNSIGNED)=0) m
+WHERE NOT EXISTS (SELECT 1 FROM system_role_menu x
+ WHERE x.role_id=rm.role_id AND x.menu_id=m.id AND CAST(x.deleted AS UNSIGNED)=0);
\ No newline at end of file
diff --git a/yudao-module-aftersales/src/main/java/cn/iocoder/yudao/module/aftersales/controller/admin/cancellation/vo/AfterSaleCancellationSaveReqVO.java b/yudao-module-aftersales/src/main/java/cn/iocoder/yudao/module/aftersales/controller/admin/cancellation/vo/AfterSaleCancellationSaveReqVO.java
index 148148d..ff6e6f0 100644
--- a/yudao-module-aftersales/src/main/java/cn/iocoder/yudao/module/aftersales/controller/admin/cancellation/vo/AfterSaleCancellationSaveReqVO.java
+++ b/yudao-module-aftersales/src/main/java/cn/iocoder/yudao/module/aftersales/controller/admin/cancellation/vo/AfterSaleCancellationSaveReqVO.java
@@ -27,7 +27,11 @@
@Schema(description = "CRM 鍚堝悓缂栧彿")
private Long contractId;
- @Schema(description = "閿�鍞鍗曞彿锛堟棤 ERP 鏃跺彲涓虹┖锛�")
+ @Schema(description = "ERP 閿�鍞鍗曠紪鍙凤紱濉啓鍚庡鎵归�氳繃浼氳仈鍔ㄤ綔搴�")
+ @Positive
+ private Long saleOrderId;
+
+ @Schema(description = "閿�鍞鍗曞彿锛堜粎灞曠ず锛岄�夊~锛�")
@Size(max = 64)
private String saleOrderNo;
diff --git a/yudao-module-aftersales/src/main/java/cn/iocoder/yudao/module/aftersales/dal/dataobject/cancellation/AfterSaleCancellationDO.java b/yudao-module-aftersales/src/main/java/cn/iocoder/yudao/module/aftersales/dal/dataobject/cancellation/AfterSaleCancellationDO.java
index 7fb3f46..0e8af61 100644
--- a/yudao-module-aftersales/src/main/java/cn/iocoder/yudao/module/aftersales/dal/dataobject/cancellation/AfterSaleCancellationDO.java
+++ b/yudao-module-aftersales/src/main/java/cn/iocoder/yudao/module/aftersales/dal/dataobject/cancellation/AfterSaleCancellationDO.java
@@ -32,6 +32,8 @@
private Long ticketId;
private Long customerId;
private Long contractId;
+ /** ERP 閿�鍞鍗曠紪鍙凤紱濉啓鍚庡鎵归�氳繃浼氳仈鍔ㄤ綔搴燂紙鍙� MPS 璁″垝鎷︽埅绾︽潫锛� */
+ private Long saleOrderId;
private String saleOrderNo;
/** 閫�璐х被鍨嬶細1 閫�娆鹃��璐� 2 鎹㈣揣 3 浠呴��娆� */
private Integer returnType;
diff --git a/yudao-module-aftersales/src/main/java/cn/iocoder/yudao/module/aftersales/service/cancellation/AfterSaleCancellationService.java b/yudao-module-aftersales/src/main/java/cn/iocoder/yudao/module/aftersales/service/cancellation/AfterSaleCancellationService.java
index f7ea701..582bc7c 100644
--- a/yudao-module-aftersales/src/main/java/cn/iocoder/yudao/module/aftersales/service/cancellation/AfterSaleCancellationService.java
+++ b/yudao-module-aftersales/src/main/java/cn/iocoder/yudao/module/aftersales/service/cancellation/AfterSaleCancellationService.java
@@ -12,6 +12,7 @@
import cn.iocoder.yudao.module.aftersales.dal.redis.no.AfterSaleNoRedisDAO;
import cn.iocoder.yudao.module.aftersales.service.returnobj.AfterSaleReturnService;
import cn.iocoder.yudao.module.crm.api.contract.CrmContractApi;
+import cn.iocoder.yudao.module.erp.api.sale.ErpSaleOrderApi;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DuplicateKeyException;
@@ -22,6 +23,7 @@
import java.util.Objects;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.invalidParamException;
import static cn.iocoder.yudao.module.aftersales.enums.ErrorCodeConstants.*;
/**
@@ -53,6 +55,7 @@
@Resource private AfterSaleNoRedisDAO noRedisDAO;
@Resource private AfterSaleReturnService returnService;
@Resource private CrmContractApi crmContractApi;
+ @Resource private ErpSaleOrderApi erpSaleOrderApi;
public PageResult<AfterSaleCancellationDO> page(PageParam page, String code, String type,
Integer status, Long customerId) {
@@ -133,7 +136,10 @@
}
/**
- * 瀹℃壒锛氶�氳繃鍚庢墽琛屼笅娓稿姩浣滐紱椹冲洖蹇呴』濉剰瑙併��
+ * 瀹℃壒锛氶┏鍥炲繀椤诲~鎰忚锛涢�氳繃鏃跺厛鎵ц涓嬫父鍔ㄤ綔锛屽叏閮ㄦ垚鍔熸墠钀藉鎵圭粨璁恒��
+ *
+ * <p>涓嬫父澶辫触锛堝閿�鍞鍗曚粛鏈夊叧鑱旂敓浜ц鍒掞級浼氭暣浣撳洖婊氾紝鍙楃悊鍗曚繚鎸併�屽緟瀹℃壒銆嶏紝
+ * 鐢辫皟鐢ㄦ柟鐪嬪埌鍏蜂綋鍘熷洜锛岄伩鍏嶅嚭鐜般�屽鎵归�氳繃浜嗕絾涓氬姟娌℃墽琛屻�嶇殑涓嶄竴鑷寸姸鎬併��
*
* @return 閫氳繃鏃剁敓鎴愮殑閫�璐у崟缂栧彿锛堥潪閫�璐х被鍨嬩负 null锛�
*/
@@ -146,27 +152,47 @@
AfterSaleCancellationDO task = get(req.getId());
if (!Objects.equals(task.getStatus(), ST_PENDING)) throw exception(CANCELLATION_APPROVE_FAIL_STATUS);
- int target = Boolean.TRUE.equals(req.getApproved()) ? ST_APPROVED : ST_REJECTED;
+ // 椹冲洖锛氬彧鏀圭姸鎬侊紝涓嶆墽琛屼笅娓�
+ if (!Boolean.TRUE.equals(req.getApproved())) {
+ if (mapper.update(null, new LambdaUpdateWrapper<AfterSaleCancellationDO>()
+ .eq(AfterSaleCancellationDO::getId, task.getId())
+ .eq(AfterSaleCancellationDO::getStatus, ST_PENDING)
+ .set(AfterSaleCancellationDO::getStatus, ST_REJECTED)
+ .set(AfterSaleCancellationDO::getApproverId, userId)
+ .set(AfterSaleCancellationDO::getApprovalTime, LocalDateTime.now())
+ .set(AfterSaleCancellationDO::getApprovalRemark, req.getRemark())) != 1) {
+ throw exception(CANCELLATION_APPROVE_FAIL_STATUS);
+ }
+ return null;
+ }
+
+ // 閫氳繃锛氬厛鎵ц涓嬫父鍔ㄤ綔锛堝紓甯哥洿鎺ユ姏鍑猴紝浜嬪姟鍥炴粴锛屽崟鎹粛涓哄緟瀹℃壒锛�
+ Long returnId = executeDownstream(task, userId);
+
+ // 涓嬫父鎴愬姛鍚庡啀钀藉鎵圭粨璁�
if (mapper.update(null, new LambdaUpdateWrapper<AfterSaleCancellationDO>()
.eq(AfterSaleCancellationDO::getId, task.getId())
.eq(AfterSaleCancellationDO::getStatus, ST_PENDING)
- .set(AfterSaleCancellationDO::getStatus, target)
+ .set(AfterSaleCancellationDO::getStatus, ST_APPROVED)
.set(AfterSaleCancellationDO::getApproverId, userId)
.set(AfterSaleCancellationDO::getApprovalTime, LocalDateTime.now())
- .set(AfterSaleCancellationDO::getApprovalRemark, req.getRemark())) != 1) {
+ .set(AfterSaleCancellationDO::getApprovalRemark, req.getRemark())
+ .set(AfterSaleCancellationDO::getExecuted, 1)) != 1) {
throw exception(CANCELLATION_APPROVE_FAIL_STATUS);
}
-
- if (!Boolean.TRUE.equals(req.getApproved())) return null;
- return executeDownstream(task, userId);
+ return returnId;
}
- /** 瀹℃壒閫氳繃鍚庣殑涓嬫父鍔ㄤ綔锛涘け璐ユ椂璁板綍鍘熷洜浣嗕笉鍥炴粴瀹℃壒缁撹锛屼究浜庝汉宸ヨˉ鍋氥�� */
+ /**
+ * 瀹℃壒閫氳繃鍚庣殑涓嬫父鍔ㄤ綔銆�
+ *
+ * <p>涓嶅悶寮傚父锛氫换涓�姝ュけ璐ョ洿鎺ユ姏鍑猴紝鐢� {@link #approve} 鐨勪簨鍔℃暣浣撳洖婊氾紝
+ * 淇濊瘉銆屽鎵归�氳繃銆嶄笌銆屼笅娓稿凡鎵ц銆嶆案杩滀竴鑷淬��
+ */
private Long executeDownstream(AfterSaleCancellationDO task, Long userId) {
Long returnId = null;
String remark;
- boolean ok = true;
- try {
+ {
switch (task.getType()) {
case "RETURN" -> {
var vo = new AfterSaleReturnSaveReqVO();
@@ -175,23 +201,31 @@
vo.setReturnType(task.getReturnType() == null ? 1 : task.getReturnType());
vo.setReturnReason(task.getReason());
returnId = returnService.createReturn(vo, userId);
- remark = "宸茬敓鎴愰��璐у崟 " + returnId;
+ if (task.getSaleOrderId() != null) {
+ erpSaleOrderApi.cancelSaleOrder(task.getSaleOrderId()).getCheckedData();
+ remark = "宸茬敓鎴愰��璐у崟 " + returnId
+ + "锛屽苟浣滃簾閿�鍞鍗� " + task.getSaleOrderId();
+ } else {
+ remark = "宸茬敓鎴愰��璐у崟 " + returnId;
+ }
}
case "CONTRACT_TERMINATE" -> {
crmContractApi.updateContractStatus(task.getContractId(), CRM_CONTRACT_INVALID).getCheckedData();
- remark = "宸蹭綔搴� CRM 鍚堝悓 " + task.getContractId();
+ // 鑻ュ叧鑱� ERP 閿�鍞鍗曪紝涓�骞朵綔搴燂紙浼氳鏈彇娑堢殑 MPS 璁″垝鎷︽埅锛�
+ if (task.getSaleOrderId() != null) {
+ erpSaleOrderApi.cancelSaleOrder(task.getSaleOrderId()).getCheckedData();
+ remark = "宸蹭綔搴� CRM 鍚堝悓 " + task.getContractId()
+ + "锛屽苟浣滃簾閿�鍞鍗� " + task.getSaleOrderId();
+ } else {
+ remark = "宸蹭綔搴� CRM 鍚堝悓 " + task.getContractId();
+ }
}
case "CONTRACT_CHANGE" -> remark = "鍙樻洿鍙楃悊宸查�氳繃锛汣RM 鍚堝悓鍐呭璇锋寜闄勪欢鍚屾缁存姢";
- default -> { ok = false; remark = "鏈煡鍙楃悊绫诲瀷锛�" + task.getType(); }
+ default -> throw invalidParamException("鏈煡鍙楃悊绫诲瀷锛�" + task.getType());
}
- } catch (Exception e) {
- ok = false;
- remark = "涓嬫父鎵ц澶辫触锛�" + e.getMessage();
- log.warn("閫�鍗曞彈鐞哰{}]涓嬫父鍔ㄤ綔澶辫触锛歿}", task.getCode(), e.getMessage());
}
var update = new AfterSaleCancellationDO();
update.setId(task.getId());
- update.setExecuted(ok ? 1 : 0);
update.setExecuteRemark(remark);
if (returnId != null) update.setReturnId(returnId);
mapper.updateById(update);
diff --git a/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/api/sale/ErpSaleOrderApi.java b/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/api/sale/ErpSaleOrderApi.java
index 714f17c..4576334 100644
--- a/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/api/sale/ErpSaleOrderApi.java
+++ b/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/api/sale/ErpSaleOrderApi.java
@@ -83,4 +83,13 @@
*/
CommonResult<Boolean> updateOrderOutStatusTo(Long orderId, Integer outStatus);
+ /**
+ * 浣滃簾閿�鍞鍗曪紙渚涘敭鍚�/閫�鍗曟祦绋嬭仈鍔級
+ *
+ * <p>璁㈠崟宸插瓨鍦ㄦ湭鍙栨秷鐨� MPS 璁″垝鏃朵細鎶涘嚭涓氬姟寮傚父锛岀敱璋冪敤鏂规彁绀虹敤鎴峰厛澶勭悊璁″垝銆�
+ *
+ * @param orderId 璁㈠崟缂栧彿
+ */
+ CommonResult<Boolean> cancelSaleOrder(Long orderId);
+
}
diff --git a/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/api/sale/ErpSaleOrderApiImpl.java b/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/api/sale/ErpSaleOrderApiImpl.java
index bd0354a..910376c 100644
--- a/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/api/sale/ErpSaleOrderApiImpl.java
+++ b/yudao-module-erp/src/main/java/cn/iocoder/yudao/module/erp/api/sale/ErpSaleOrderApiImpl.java
@@ -138,4 +138,14 @@
return success(true);
}
+ @Override
+ public CommonResult<Boolean> cancelSaleOrder(Long orderId) {
+ if (orderId == null) {
+ return success(false);
+ }
+ // 澶嶇敤 Service 鐨勪綔搴熼�昏緫锛氬惈鐘舵�佹牎楠屻�佸嚭搴撳崟鏍¢獙銆佹湭鍙栨秷 MPS 璁″垝鎷︽埅
+ saleOrderService.cancelSaleOrder(orderId);
+ return success(true);
+ }
+
}
diff --git a/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/controller/admin/statistics/SrmStatisticsController.java b/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/controller/admin/statistics/SrmStatisticsController.java
index c6eddaa..487652d 100644
--- a/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/controller/admin/statistics/SrmStatisticsController.java
+++ b/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/controller/admin/statistics/SrmStatisticsController.java
@@ -1,13 +1,8 @@
package cn.iocoder.yudao.module.srm.controller.admin.statistics;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
-import cn.iocoder.yudao.framework.common.pojo.PageParam;
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.module.srm.controller.admin.statistics.vo.SrmCostAnalysisRespVO;
import cn.iocoder.yudao.module.srm.controller.admin.statistics.vo.SrmTenderStatisticsRespVO;
-import cn.iocoder.yudao.module.srm.service.statistics.SrmCostAnalysisService;
import cn.iocoder.yudao.module.srm.service.statistics.SrmStatisticsService;
-import jakarta.validation.Valid;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
@@ -25,8 +20,6 @@
@Resource
private SrmStatisticsService statisticsService;
- @Resource
- private SrmCostAnalysisService costAnalysisService;
@GetMapping("/tender")
@Operation(summary = "鑾峰彇鎷涙爣缁熻鏁版嵁")
@@ -35,22 +28,4 @@
return success(statisticsService.getTenderStatistics(year));
}
- @GetMapping("/cost-analysis")
- @Operation(summary = "閲囪喘鎴愭湰鍒嗘瀽",
- description = "鍩轰簬 SRM 鎷涙爣闇�姹傞噺涓庝緵搴斿晢鎶ヤ环鑱氬悎锛氶噰璐噺銆佸姞鏉冨潎浠枫�佹渶浣�/鏈�楂樹环銆佷环鏍煎彉鍔紱涓嶄緷璧� ERP")
- @PreAuthorize("@ss.hasPermission('srm:statistics:query')")
- public CommonResult<PageResult<SrmCostAnalysisRespVO>> getCostAnalysis(
- @Valid PageParam page,
- @RequestParam(value = "productName", required = false) String productName) {
- return success(costAnalysisService.page(page, productName));
- }
-
- @GetMapping("/cost-trend")
- @Operation(summary = "鐗╂枡浠锋牸瓒嬪娍", description = "鎸夋湀姹囨�昏鐗╂枡鐨勫钩鍧囨姤浠�")
- @PreAuthorize("@ss.hasPermission('srm:statistics:query')")
- public CommonResult<java.util.List<SrmCostAnalysisRespVO.TrendPoint>> getCostTrend(
- @RequestParam("productId") Long productId) {
- return success(costAnalysisService.trend(productId));
- }
-
-}
+}
\ No newline at end of file
diff --git a/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/controller/admin/statistics/vo/SrmCostAnalysisRespVO.java b/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/controller/admin/statistics/vo/SrmCostAnalysisRespVO.java
deleted file mode 100644
index 952c701..0000000
--- a/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/controller/admin/statistics/vo/SrmCostAnalysisRespVO.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package cn.iocoder.yudao.module.srm.controller.admin.statistics.vo;
-
-import io.swagger.v3.oas.annotations.media.Schema;
-import lombok.Data;
-
-import java.math.BigDecimal;
-import java.time.LocalDateTime;
-import java.util.List;
-
-/**
- * 閲囪喘鎴愭湰鍒嗘瀽 Response VO銆�
- *
- * <p>鏁版嵁鏉ユ簮锛歋RM 鎷涙爣鐗╂枡闇�姹傦紙鏁伴噺銆侀浼板崟浠凤級+ 渚涘簲鍟嗘姤浠凤紙鍚◣鍗曚环銆佺◣鐜囷級銆�
- * 涓嶄緷璧� ERP 閲囪喘璁㈠崟锛岄�傜敤浜庢湭鍚敤 ERP 鐨勯」鐩��
- */
-@Schema(description = "绠$悊鍚庡彴 - 閲囪喘鎴愭湰鍒嗘瀽 Response VO")
-@Data
-public class SrmCostAnalysisRespVO {
-
- @Schema(description = "鐗╂枡缂栧彿")
- private Long productId;
- @Schema(description = "鐗╂枡缂栫爜")
- private String productCode;
- @Schema(description = "鐗╂枡鍚嶇О")
- private String productName;
- @Schema(description = "瑙勬牸")
- private String productSpec;
- @Schema(description = "鍗曚綅")
- private String unit;
-
- @Schema(description = "閲囪喘闇�姹傞噺")
- private BigDecimal totalQuantity;
- @Schema(description = "鎶ヤ环娆℃暟")
- private Integer quoteCount;
- @Schema(description = "鍙備笌鎶ヤ环鐨勪緵搴斿晢鏁�")
- private Integer supplierCount;
-
- @Schema(description = "鍔犳潈骞冲潎鎶ヤ环锛堟寜闇�姹傞噺鍔犳潈锛�")
- private BigDecimal weightedAvgPrice;
- @Schema(description = "鏈�浣庢姤浠�")
- private BigDecimal minPrice;
- @Schema(description = "鏈�楂樻姤浠�")
- private BigDecimal maxPrice;
- @Schema(description = "棰勪及鍗曚环")
- private BigDecimal estimatedPrice;
- @Schema(description = "鐩稿棰勪及浠风殑鍋忓樊鐜囷紙%锛�")
- private BigDecimal deviationRate;
-
- @Schema(description = "鏈�杩戞姤浠锋椂闂�")
- private LocalDateTime lastQuoteTime;
- @Schema(description = "浠锋牸鍙樺姩锛堟渶杩戜袱娆℃姤浠峰樊锛�")
- private BigDecimal priceChange;
-
- @Schema(description = "鎶ヤ环鏄庣粏")
- private List<QuoteItem> quotes;
-
- @Schema(description = "鎶ヤ环鏄庣粏椤�")
- @Data
- public static class QuoteItem {
- @Schema(description = "渚涘簲鍟嗙紪鍙�")
- private Long supplierId;
- @Schema(description = "渚涘簲鍟嗗悕绉�")
- private String supplierName;
- @Schema(description = "鎶ヤ环鍗曚环")
- private BigDecimal quotePrice;
- @Schema(description = "绋庣巼锛�%锛�")
- private BigDecimal taxRate;
- @Schema(description = "浜ゆ湡锛堝ぉ锛�")
- private Integer deliveryCycle;
- @Schema(description = "鎶ヤ环鏃堕棿")
- private LocalDateTime quoteTime;
- }
-
- @Schema(description = "浠锋牸瓒嬪娍鐐�")
- @Data
- public static class TrendPoint {
- @Schema(description = "鏈堜唤 yyyy-MM")
- private String month;
- @Schema(description = "骞冲潎鎶ヤ环")
- private BigDecimal avgPrice;
- @Schema(description = "鎶ヤ环娆℃暟")
- private Integer count;
- }
-}
diff --git a/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/service/statistics/SrmCostAnalysisService.java b/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/service/statistics/SrmCostAnalysisService.java
deleted file mode 100644
index 68ecc54..0000000
--- a/yudao-module-srm/src/main/java/cn/iocoder/yudao/module/srm/service/statistics/SrmCostAnalysisService.java
+++ /dev/null
@@ -1,183 +0,0 @@
-package cn.iocoder.yudao.module.srm.service.statistics;
-
-import cn.iocoder.yudao.framework.common.pojo.PageParam;
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
-import cn.iocoder.yudao.module.srm.controller.admin.statistics.vo.SrmCostAnalysisRespVO;
-import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierDO;
-import cn.iocoder.yudao.module.srm.dal.dataobject.SrmSupplierQuoteDO;
-import cn.iocoder.yudao.module.srm.dal.dataobject.SrmTenderMaterialDO;
-import cn.iocoder.yudao.module.srm.dal.mysql.SrmSupplierMapper;
-import cn.iocoder.yudao.module.srm.dal.mysql.SrmSupplierQuoteMapper;
-import cn.iocoder.yudao.module.srm.dal.mysql.SrmTenderMaterialMapper;
-import jakarta.annotation.Resource;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Service;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.time.LocalDateTime;
-import java.time.YearMonth;
-import java.util.*;
-import java.util.stream.Collectors;
-
-/**
- * 閲囪喘鎴愭湰鍒嗘瀽锛堝熀浜� SRM 鎷涙爣闇�姹備笌渚涘簲鍟嗘姤浠凤級銆�
- *
- * <p>鍙e緞璇存槑锛�
- * <ul>
- * <li>閲囪喘闇�姹傞噺鍙栨嫑鏍囩墿鏂欓渶姹傛暟閲忓悎璁★紱</li>
- * <li>鍔犳潈鍧囦环 = 危(鎶ヤ环鍗曚环 脳 闇�姹傛暟閲�) / 危(闇�姹傛暟閲�)锛屽渚涘簲鍟嗘姤浠蜂竴骞惰鍏ワ紱</li>
- * <li>浠锋牸鍙樺姩 = 鏈�杩戜袱娆℃姤浠蜂箣宸紱涓嶈冻涓ゆ鏃朵负绌猴紱</li>
- * <li>涓嶄緷璧� ERP 閲囪喘璁㈠崟锛屾湭鍚敤 ERP 鐨勯」鐩悓鏍峰彲鐢ㄣ��</li>
- * </ul>
- */
-@Slf4j
-@Service
-public class SrmCostAnalysisService {
-
- @Resource private SrmTenderMaterialMapper tenderMaterialMapper;
- @Resource private SrmSupplierQuoteMapper supplierQuoteMapper;
- @Resource private SrmSupplierMapper supplierMapper;
-
- public PageResult<SrmCostAnalysisRespVO> page(PageParam page, String productName) {
- List<SrmTenderMaterialDO> materials = tenderMaterialMapper.selectList(
- new LambdaQueryWrapperX<SrmTenderMaterialDO>()
- .likeIfPresent(SrmTenderMaterialDO::getProductName, productName));
- if (materials.isEmpty()) return PageResult.empty();
-
- // 鎸夌墿鏂欒仛鍚堬紙鍚屼竴鐗╂枡鍙兘鍑虹幇鍦ㄥ涓嫑鏍囬」鐩級
- Map<String, List<SrmTenderMaterialDO>> grouped = materials.stream()
- .filter(m -> m.getProductId() != null || m.getProductName() != null)
- .collect(Collectors.groupingBy(
- m -> m.getProductId() != null ? "ID:" + m.getProductId() : "NAME:" + m.getProductName(),
- LinkedHashMap::new, Collectors.toList()));
-
- List<SrmCostAnalysisRespVO> rows = new ArrayList<>();
- for (var entry : grouped.entrySet()) {
- List<SrmTenderMaterialDO> group = entry.getValue();
- SrmTenderMaterialDO first = group.get(0);
- Set<Long> materialIds = group.stream().map(SrmTenderMaterialDO::getId)
- .filter(Objects::nonNull).collect(Collectors.toSet());
- if (materialIds.isEmpty()) continue;
-
- List<SrmSupplierQuoteDO> quotes = supplierQuoteMapper.selectList(
- new LambdaQueryWrapperX<SrmSupplierQuoteDO>()
- .in(SrmSupplierQuoteDO::getTenderMaterialId, materialIds));
- if (quotes.isEmpty()) continue;
-
- // 闇�姹傛暟閲忔槧灏�
- Map<Long, BigDecimal> qtyMap = group.stream()
- .filter(m -> m.getId() != null)
- .collect(Collectors.toMap(SrmTenderMaterialDO::getId,
- m -> m.getQuantity() == null ? BigDecimal.ZERO : m.getQuantity(), (a, b) -> a));
-
- BigDecimal totalQty = qtyMap.values().stream().reduce(BigDecimal.ZERO, BigDecimal::add);
- BigDecimal weightedSum = BigDecimal.ZERO;
- BigDecimal weightQty = BigDecimal.ZERO;
- for (SrmSupplierQuoteDO q : quotes) {
- if (q.getQuotePrice() == null) continue;
- BigDecimal qty = qtyMap.getOrDefault(q.getTenderMaterialId(), BigDecimal.ZERO);
- if (qty.signum() <= 0) continue;
- weightedSum = weightedSum.add(q.getQuotePrice().multiply(qty));
- weightQty = weightQty.add(qty);
- }
-
- var row = new SrmCostAnalysisRespVO();
- row.setProductId(first.getProductId());
- row.setProductCode(first.getProductCode());
- row.setProductName(first.getProductName());
- row.setProductSpec(first.getProductSpec());
- row.setUnit(first.getUnit());
- row.setTotalQuantity(totalQty);
- row.setEstimatedPrice(first.getEstimatedPrice());
- row.setQuoteCount(quotes.size());
- row.setSupplierCount((int) quotes.stream().map(SrmSupplierQuoteDO::getSupplierId)
- .filter(Objects::nonNull).distinct().count());
- row.setWeightedAvgPrice(weightQty.signum() > 0
- ? weightedSum.divide(weightQty, 4, RoundingMode.HALF_UP) : null);
- row.setMinPrice(quotes.stream().map(SrmSupplierQuoteDO::getQuotePrice)
- .filter(Objects::nonNull).min(Comparator.naturalOrder()).orElse(null));
- row.setMaxPrice(quotes.stream().map(SrmSupplierQuoteDO::getQuotePrice)
- .filter(Objects::nonNull).max(Comparator.naturalOrder()).orElse(null));
- if (first.getEstimatedPrice() != null && first.getEstimatedPrice().signum() > 0
- && row.getWeightedAvgPrice() != null) {
- row.setDeviationRate(row.getWeightedAvgPrice().subtract(first.getEstimatedPrice())
- .multiply(BigDecimal.valueOf(100))
- .divide(first.getEstimatedPrice(), 2, RoundingMode.HALF_UP));
- }
-
- // 鎶ヤ环鎺掑簭锛堟寜鍒涘缓鏃堕棿锛�
- List<SrmSupplierQuoteDO> ordered = quotes.stream()
- .filter(q -> q.getQuotePrice() != null)
- .sorted(Comparator.comparing(SrmSupplierQuoteDO::getCreateTime,
- Comparator.nullsFirst(Comparator.naturalOrder())))
- .toList();
- if (!ordered.isEmpty()) {
- row.setLastQuoteTime(ordered.get(ordered.size() - 1).getCreateTime());
- if (ordered.size() >= 2) {
- row.setPriceChange(ordered.get(ordered.size() - 1).getQuotePrice()
- .subtract(ordered.get(ordered.size() - 2).getQuotePrice()));
- }
- }
-
- // 渚涘簲鍟嗗悕绉�
- Set<Long> supplierIds = quotes.stream().map(SrmSupplierQuoteDO::getSupplierId)
- .filter(Objects::nonNull).collect(Collectors.toSet());
- Map<Long, String> supplierNames = supplierIds.isEmpty() ? Map.of()
- : supplierMapper.selectByIds(supplierIds).stream()
- .collect(Collectors.toMap(SrmSupplierDO::getId, SrmSupplierDO::getName, (a, b) -> a));
- row.setQuotes(quotes.stream().map(q -> {
- var item = new SrmCostAnalysisRespVO.QuoteItem();
- item.setSupplierId(q.getSupplierId());
- item.setSupplierName(supplierNames.get(q.getSupplierId()));
- item.setQuotePrice(q.getQuotePrice());
- item.setTaxRate(q.getTaxRate());
- item.setDeliveryCycle(q.getDeliveryCycle());
- item.setQuoteTime(q.getCreateTime());
- return item;
- }).toList());
- rows.add(row);
- }
-
- // 鎵嬪姩鍒嗛〉
- rows.sort((a, b) -> {
- BigDecimal pa = a.getWeightedAvgPrice() == null ? BigDecimal.ZERO : a.getWeightedAvgPrice();
- BigDecimal pb = b.getWeightedAvgPrice() == null ? BigDecimal.ZERO : b.getWeightedAvgPrice();
- return pb.compareTo(pa);
- });
- int total = rows.size();
- int from = Math.min((page.getPageNo() - 1) * page.getPageSize(), total);
- int to = Math.min(from + page.getPageSize(), total);
- return new PageResult<>(rows.subList(from, to), (long) total);
- }
-
- /** 鍗曠墿鏂欐姤浠疯秼鍔匡紙鎸夋湀骞冲潎鎶ヤ环锛� */
- public List<SrmCostAnalysisRespVO.TrendPoint> trend(Long productId) {
- if (productId == null) return List.of();
- List<SrmTenderMaterialDO> materials = tenderMaterialMapper.selectList(
- new LambdaQueryWrapperX<SrmTenderMaterialDO>().eq(SrmTenderMaterialDO::getProductId, productId));
- Set<Long> materialIds = materials.stream().map(SrmTenderMaterialDO::getId)
- .filter(Objects::nonNull).collect(Collectors.toSet());
- if (materialIds.isEmpty()) return List.of();
- List<SrmSupplierQuoteDO> quotes = supplierQuoteMapper.selectList(
- new LambdaQueryWrapperX<SrmSupplierQuoteDO>()
- .in(SrmSupplierQuoteDO::getTenderMaterialId, materialIds));
- Map<YearMonth, List<BigDecimal>> byMonth = new TreeMap<>();
- for (SrmSupplierQuoteDO q : quotes) {
- if (q.getQuotePrice() == null || q.getCreateTime() == null) continue;
- byMonth.computeIfAbsent(YearMonth.from(q.getCreateTime()), k -> new ArrayList<>())
- .add(q.getQuotePrice());
- }
- List<SrmCostAnalysisRespVO.TrendPoint> result = new ArrayList<>();
- byMonth.forEach((month, prices) -> {
- var p = new SrmCostAnalysisRespVO.TrendPoint();
- p.setMonth(month.toString());
- p.setCount(prices.size());
- p.setAvgPrice(prices.stream().reduce(BigDecimal.ZERO, BigDecimal::add)
- .divide(BigDecimal.valueOf(prices.size()), 4, RoundingMode.HALF_UP));
- result.add(p);
- });
- return result;
- }
-}
--
Gitblit v1.9.3