From feedd62ec46b9faada80505387526acf914cf4c5 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期日, 11 十月 2026 22:49:44 +0800
Subject: [PATCH] 海西州-同仁堂 1.添加操作日志生成

---
 yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java |   51 ++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java
index 448dae2..ab35cf8 100644
--- a/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java
+++ b/yudao-module-crm/src/main/java/cn/iocoder/yudao/module/crm/service/contract/CrmContractServiceImpl.java
@@ -10,6 +10,7 @@
 import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
+import cn.iocoder.yudao.framework.operatelog.core.util.OperateLogUtils;
 import cn.iocoder.yudao.module.bpm.api.task.BpmProcessInstanceApi;
 import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
 import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO;
@@ -272,6 +273,8 @@
 
     @Override
     @Transactional(rollbackFor = Exception.class)
+    @LogRecord(type = CRM_CONTRACT_TYPE, subType = CRM_CONTRACT_IMPORT_SUB_TYPE, bizNo = "0",
+            success = CRM_CONTRACT_IMPORT_SUCCESS)
     public CrmContractImportRespVO importContractList(List<CrmContractImportExcelVO> importList) {
         CrmContractImportRespVO respVO = CrmContractImportRespVO.builder()
                 .createList(new ArrayList<>())
@@ -279,6 +282,8 @@
                 .failureList(new LinkedHashMap<>())
                 .build();
         if (CollUtil.isEmpty(importList)) {
+            // 绌烘枃浠朵篃瑕佺粰鏃ュ織鏂囨鍏滃簳锛岄伩鍏� {{#importSummary}} 鍙栦笉鍒板��
+            OperateLogUtils.putImportSummary(respVO.getCreateList(), respVO.getUpdateList(), respVO.getFailureList());
             return respVO;
         }
 
@@ -317,6 +322,8 @@
                 respVO.getFailureList().put(label, resolveImportErrorMessage(ex));
             }
         }
+        // 璁板綍瀵煎叆缁撴灉姹囨�伙紝渚� @LogRecord 鐨� success 鏂囨寮曠敤
+        OperateLogUtils.putImportSummary(respVO.getCreateList(), respVO.getUpdateList(), respVO.getFailureList());
         return respVO;
     }
 
@@ -327,46 +334,58 @@
         CrmContractImportExcelVO head = rows.get(0);
         // 1. 涓昏〃蹇呭~
         if (StrUtil.isBlank(head.getName())) {
-            throw new IllegalArgumentException("鍚堝悓鍚嶇О涓嶈兘涓虹┖");
+            throw new IllegalArgumentException("鍚堝悓鍚嶇О涓嶈兘涓虹┖锛氳濉啓妯℃澘涓琛岀殑銆屽悎鍚屽悕绉般�嶅垪锛�"
+                    + "鑻ュ悓涓�寮犲悎鍚岀殑澶氳浣跨敤浜嗗悎骞跺崟鍏冩牸锛岄渶濉啓鍦ㄥ悎骞跺尯鍩熺殑棣栬");
         }
         if (StrUtil.isBlank(head.getCustomerName())) {
-            throw new IllegalArgumentException("瀹㈡埛鍚嶇О涓嶈兘涓虹┖");
+            throw new IllegalArgumentException("瀹㈡埛鍚嶇О涓嶈兘涓虹┖锛氳濉啓妯℃澘涓琛岀殑銆屽鎴峰悕绉般�嶅垪锛�"
+                    + "鑻ュ悓涓�寮犲悎鍚岀殑澶氳浣跨敤浜嗗悎骞跺崟鍏冩牸锛岄渶濉啓鍦ㄥ悎骞跺尯鍩熺殑棣栬");
         }
         Long customerId = customerIdMap.get(head.getCustomerName().trim());
         if (customerId == null) {
-            throw new IllegalArgumentException("瀹㈡埛涓嶅瓨鍦細" + head.getCustomerName());
+            throw new IllegalArgumentException("瀹㈡埛涓嶅瓨鍦細" + head.getCustomerName()
+                    + "銆傝鍏堝湪銆孋RM 瀹㈡埛绠$悊銆嶄腑鍒涘缓璇ュ鎴凤紙鍚嶇О闇�涓庢ā鏉垮畬鍏ㄤ竴鑷达級锛屾垨淇敼妯℃澘涓殑瀹㈡埛鍚嶇О鍚庨噸鏂板鍏�");
         }
         customerService.validateCustomer(customerId);
 
         // 2. 鏄庣粏
-        List<CrmContractSaveReqVO.Product> products = new ArrayList<>();
+        List<CrmContractProductDO> productDOs = new ArrayList<>();
         for (CrmContractImportExcelVO row : rows) {
             if (StrUtil.isBlank(row.getProductCode())) {
-                throw new IllegalArgumentException("浜у搧缂栫爜涓嶈兘涓虹┖");
+                throw new IllegalArgumentException("浜у搧缂栫爜涓嶈兘涓虹┖锛氳濉啓妯℃澘涓琛岀殑銆屼骇鍝佺紪鐮併�嶅垪");
             }
             CommonResult<MdmItemRespDTO> itemResult = mdmItemApi.getItemByCode(row.getProductCode().trim());
             MdmItemRespDTO item = itemResult == null ? null : itemResult.getData();
             if (item == null) {
-                throw new IllegalArgumentException("浜у搧涓嶅瓨鍦細" + row.getProductCode());
+                throw new IllegalArgumentException("浜у搧涓嶅瓨鍦細" + row.getProductCode()
+                        + "銆傝鍏堝湪銆岀墿鏂欑鐞嗐�嶄腑缁存姢璇ョ墿鏂欙紙缂栫爜闇�涓庢ā鏉垮畬鍏ㄤ竴鑷达級锛屾垨淇敼妯℃澘涓殑浜у搧缂栫爜鍚庨噸鏂板鍏�");
             }
-            if (row.getCount() == null || row.getCount() <= 0) {
-                throw new IllegalArgumentException("浜у搧[" + row.getProductCode() + "]鐨勬暟閲忓繀椤讳负姝f暣鏁�");
+            if (row.getCount() == null) {
+                throw new IllegalArgumentException("浜у搧[" + row.getProductCode()
+                        + "]鐨勬暟閲忎笉鑳戒负绌猴細璇峰~鍐欐ā鏉夸腑璇ヨ鐨勩�屾暟閲忋�嶅垪");
+            }
+            if (row.getCount().compareTo(BigDecimal.ZERO) <= 0) {
+                throw new IllegalArgumentException("浜у搧[" + row.getProductCode() + "]鐨勬暟閲忓繀椤诲ぇ浜� 0锛屽綋鍓嶄负 "
+                        + row.getCount().stripTrailingZeros().toPlainString() + "銆傝淇敼妯℃澘鍚庨噸鏂板鍏�");
             }
             BigDecimal contractPrice = row.getContractPrice() != null ? row.getContractPrice()
                     : (item.getSalesPrice() != null ? item.getSalesPrice() : BigDecimal.ZERO);
-            CrmContractSaveReqVO.Product product = new CrmContractSaveReqVO.Product();
+            CrmContractProductDO product = new CrmContractProductDO();
             product.setItemId(item.getId());
+            product.setItemUnitId(item.getUnitMeasureId());
             product.setItemPrice(item.getSalesPrice() != null ? item.getSalesPrice() : contractPrice);
             product.setContractPrice(contractPrice);
             product.setCount(row.getCount());
-            products.add(product);
+            product.setTotalPrice(MoneyUtils.priceMultiply(contractPrice, row.getCount()));
+            productDOs.add(product);
         }
 
         // 3. 鍚堝悓缂栧彿
         String no = StrUtil.isNotBlank(head.getNo()) ? head.getNo().trim()
                 : noRedisDAO.generate(CrmNoRedisDAO.CONTRACT_NO_PREFIX);
         if (contractMapper.selectByNo(no) != null) {
-            throw new IllegalArgumentException("鍚堝悓缂栧彿宸插瓨鍦細" + no);
+            throw new IllegalArgumentException("鍚堝悓缂栧彿宸插瓨鍦細" + no
+                    + "銆傝淇敼妯℃澘涓殑鍚堝悓缂栧彿锛屾垨鍏堝湪绯荤粺涓垹闄よ缂栧彿鐨勫悎鍚屽悗閲嶆柊瀵煎叆");
         }
 
         // 4. 缁勮涓昏〃锛堣礋璐d汉=鐧诲綍鐢ㄦ埛锛涚姸鎬�=鏈彁浜わ級
@@ -384,7 +403,6 @@
         contract.setAuditStatus(CrmAuditStatusEnum.DRAFT.getStatus());
 
         // 5. 鏄庣粏钀藉簱 + 鑷姩绠椾环
-        List<CrmContractProductDO> productDOs = validateContractProducts(products);
         calculateTotalPrice(contract, productDOs);
         contractMapper.insert(contract);
         productDOs.forEach(product -> product.setContractId(contract.getId()));
@@ -472,7 +490,9 @@
         if (quotation != null) {
             crmSaleQuotationService.clearContractReference(quotation.getId());
         }
-        // 2.2 鍒犻櫎鏁版嵁鏉冮檺
+        // 2.3 鍒犻櫎鍚堝悓浜у搧鏄庣粏
+        contractProductMapper.delete(CrmContractProductDO::getContractId, id);
+        // 2.4 鍒犻櫎鏁版嵁鏉冮檺
         crmPermissionService.deletePermission(CrmBizTypeEnum.CRM_CONTRACT.getType(), id);
 
         // 3. 璁板綍鎿嶄綔鏃ュ織涓婁笅鏂�
@@ -644,6 +664,11 @@
     }
 
     @Override
+    public CrmContractDO getContractByNo(String no) {
+        return contractMapper.selectByNo(no);
+    }
+
+    @Override
     public CrmContractDO validateContract(Long id) {
         return validateContractExists(id);
     }

--
Gitblit v1.9.3