From f088078e626e16b28d69cdbcbf514b30f1dcefe7 Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期三, 22 四月 2026 11:51:58 +0800
Subject: [PATCH] refactor(production): 优化生产订单及工单号生成逻辑

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java |   54 ++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index 0e9f52f..07ad60a 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -2,6 +2,7 @@
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.convert.Convert;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.date.LocalDateTimeUtil;
 import cn.hutool.core.lang.Assert;
 import cn.hutool.core.util.StrUtil;
@@ -17,10 +18,13 @@
 import com.deepoove.poi.config.Configure;
 import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
 import com.ruoyi.account.service.AccountIncomeService;
+import com.ruoyi.basic.dto.CustomerPrivatePoolDto;
 import com.ruoyi.basic.mapper.CustomerMapper;
+import com.ruoyi.basic.mapper.CustomerPrivatePoolMapper;
 import com.ruoyi.basic.mapper.ProductMapper;
 import com.ruoyi.basic.mapper.ProductModelMapper;
 import com.ruoyi.basic.pojo.Customer;
+import com.ruoyi.basic.pojo.CustomerPrivatePool;
 import com.ruoyi.common.enums.FileNameType;
 import com.ruoyi.common.enums.SaleEnum;
 import com.ruoyi.common.exception.base.BaseException;
@@ -52,6 +56,7 @@
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.core.script.DefaultRedisScript;
 import org.springframework.stereotype.Service;
@@ -107,21 +112,8 @@
     private final CommonFileServiceImpl commonFileService;
     private final ShippingInfoMapper shippingInfoMapper;
     private final InvoiceLedgerMapper invoiceLedgerMapper;
-    private final SalesLedgerSchedulingMapper salesLedgerSchedulingMapper;
-    private final SalesLedgerWorkMapper salesLedgerWorkMapper;
-    private final SalesLedgerProductionAccountingMapper salesLedgerProductionAccountingMapper;
     private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
     private final InvoiceRegistrationMapper invoiceRegistrationMapper;
-    private final ProductOrderMapper productOrderMapper;
-    private final ProcessRouteMapper processRouteMapper;
-    private final ProductProcessRouteMapper productProcessRouteMapper;
-    private final ProcessRouteItemMapper processRouteItemMapper;
-    private final ProductProcessRouteItemMapper productProcessRouteItemMapper;
-    private final ProductWorkOrderMapper productWorkOrderMapper;
-    private final ProductionProductMainMapper productionProductMainMapper;
-    private final ProductionProductOutputMapper productionProductOutputMapper;
-    private final ProductionProductInputMapper productionProductInputMapper;
-    private final QualityInspectMapper qualityInspectMapper;
     private final RedisTemplate<String, String> redisTemplate;
     @Autowired
     private SysDeptMapper sysDeptMapper;
@@ -135,10 +127,13 @@
     @Autowired
     private ProductStructureMapper productStructureMapper;
     @Autowired
+    @Lazy
     private ProductionProductMainService productionProductMainService;
-    ;
+
     @Autowired
     private SysUserMapper sysUserMapper;
+    @Autowired
+    private CustomerPrivatePoolMapper customerPrivatePoolMapper;
 
     @Override
     public List<SalesLedger> selectSalesLedgerList(SalesLedgerDto salesLedgerDto) {
@@ -485,14 +480,15 @@
         exportProcessContract.setId(id);
         SalesLedger salesLedger = salesLedgerMapper.selectById(id);
         // 鏌ヨ瀹㈡埛鍏徃淇℃伅
-        Customer customer = customerMapper.selectById(salesLedger.getCustomerId());
+        CustomerPrivatePoolDto customerPrivatePoolDto = customerPrivatePoolMapper.selectInfo(salesLedger.getCustomerId());
+
         exportProcessContract.setCreateTime(LocalDateTimeUtil.format(Optional.ofNullable(salesLedger.getExecutionDate()).orElse(LocalDate.now()), "yyyy骞碝M鏈坉d鏃�"));
         exportProcessContract.setRemark(Optional.ofNullable(salesLedger.getRemarks()).orElse("鏃�")); // 澶囨敞
         exportProcessContract.setPlaceOfSinging(Optional.ofNullable(salesLedger.getPlaceOfSinging()).orElse(""));
 
         // 濉啓鐢叉柟淇℃伅
-        ExportProcessContractVo.Customer partyA = ExportProcessContractVo.Customer.getCustomer(customer);
-        exportProcessContract.setPartyAClientName(customer.getCustomerName());
+        ExportProcessContractVo.Customer partyA = ExportProcessContractVo.Customer.getCustomer(customerPrivatePoolDto);
+        exportProcessContract.setPartyAClientName(customerPrivatePoolDto.getCustomerName());
         exportProcessContract.setPartyA(partyA);
 
         // 濉啓涔欐柟淇℃伅
@@ -668,12 +664,13 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public int addOrUpdateSalesLedger(SalesLedgerDto salesLedgerDto) {
-        try {
             // 1. 鏍¢獙瀹㈡埛淇℃伅
-            Customer customer = customerMapper.selectById(salesLedgerDto.getCustomerId());
+            CustomerPrivatePoolDto customer = customerPrivatePoolMapper.selectInfo(salesLedgerDto.getCustomerId());
             if (customer == null) {
                 throw new BaseException("瀹㈡埛涓嶅瓨鍦�");
             }
+            // 蹇呴』濉啓閿�鍞悎鍚屽彿
+//            Assert.notNull(salesLedgerDto.getSalesContractNo(), "閿�鍞悎鍚屽彿涓嶈兘涓虹┖");
 
             // 2. DTO杞珽ntity
             SalesLedger salesLedger = convertToEntity(salesLedgerDto);
@@ -681,10 +678,12 @@
             salesLedger.setTenantId(customer.getTenantId());
             // 3. 鏂板鎴栨洿鏂颁富琛�
             if (salesLedger.getId() == null) {
-                String contractNo = generateSalesContractNo();
+                // 涓虹┖ 鑷姩鐢熸垚
+                String contractNo =StrUtil.isBlank(salesLedgerDto.getSalesContractNo())? generateSalesContractNoBy8Date():salesLedgerDto.getSalesContractNo();
                 salesLedger.setSalesContractNo(contractNo);
                 salesLedgerMapper.insert(salesLedger);
             } else {
+                salesLedger.setSalesContractNo(null);
                 salesLedgerMapper.updateById(salesLedger);
             }
 
@@ -700,6 +699,7 @@
                         SalesLedger.class
                 );
             }
+        try {
 
             // 5. 杩佺Щ涓存椂鏂囦欢鍒版寮忕洰褰�
             if (salesLedgerDto.getTempFileIds() != null && !salesLedgerDto.getTempFileIds().isEmpty()) {
@@ -825,6 +825,20 @@
         return entity;
     }
 
+    public String generateSalesContractNoBy8Date(){
+        String yyMM = DateUtil.format(new Date(), "yyMM");
+        // 鏌ヨ涓�涓湀鏈夊灏戣鍗�
+        Date begin = DateUtil.beginOfMonth(new Date());
+        Date end = DateUtil.endOfMonth(new Date());
+        LambdaQueryWrapper<SalesLedger> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.between(SalesLedger::getEntryDate, begin, end);
+        long count = salesLedgerMapper.selectCount(queryWrapper);
+        Long seq = Optional.of(count).orElse(0L) + 1;
+        return String.format("%s%04d", yyMM, seq);
+    }
+
+
+
     @Transactional(readOnly = true)
     public String generateSalesContractNo() {
         LocalDate currentDate = LocalDate.now();

--
Gitblit v1.9.3