From c0cf736ff001bbaec59b7da6239f4670464952fd Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 12 六月 2025 16:32:05 +0800
Subject: [PATCH] 1.销售模块 2.时区优化

---
 main-business/src/main/java/com/ruoyi/business/service/impl/SalesRecordServiceImpl.java |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/SalesRecordServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/SalesRecordServiceImpl.java
index ae66aa0..118561a 100644
--- a/main-business/src/main/java/com/ruoyi/business/service/impl/SalesRecordServiceImpl.java
+++ b/main-business/src/main/java/com/ruoyi/business/service/impl/SalesRecordServiceImpl.java
@@ -8,7 +8,9 @@
 import com.ruoyi.basic.entity.Customer;
 import com.ruoyi.basic.mapper.CustomerMapper;
 import com.ruoyi.business.dto.SalesRecordDto;
+import com.ruoyi.business.entity.OfficialInventory;
 import com.ruoyi.business.entity.SalesRecord;
+import com.ruoyi.business.mapper.OfficialInventoryMapper;
 import com.ruoyi.business.mapper.SalesRecordMapper;
 import com.ruoyi.business.service.SalesRecordService;
 import com.ruoyi.common.core.domain.entity.SysUser;
@@ -39,6 +41,8 @@
 
     private final CustomerMapper customerMapper;
 
+    private final OfficialInventoryMapper officialInventoryMapper;
+
     @Override
     public IPage<SalesRecord> selectSalesRecordList(Page page, SalesRecordDto salesRecordDto) {
         LambdaQueryWrapper<SalesRecord> queryWrapper = new LambdaQueryWrapper<>();
@@ -52,8 +56,20 @@
         // 鍙傛暟鏍¢獙
         validateSalesRecordDto(salesRecordDto);
 
+        // 鏇存柊姝e紡搴撳緟琛ュ簱鏁伴噺
+        OfficialInventory officialInventory = officialInventoryMapper.selectById(salesRecordDto.getCoalId());
+        if (officialInventory == null) {
+            throw new BaseException("姝e紡搴撶叅绉嶄俊鎭笉瀛樺湪");
+        }
+        if (salesRecordDto.getSaleQuantity().compareTo(officialInventory.getInventoryQuantity()) > 0){
+            throw new BaseException("閿�鍞暟閲忎笉鑳藉ぇ浜庡簱瀛樻暟閲�");
+        }
+        officialInventory.setInventoryQuantity(officialInventory.getInventoryQuantity().subtract(salesRecordDto.getSaleQuantity()));
+        officialInventory.setPendingReplenishment(salesRecordDto.getSaleQuantity());
+        officialInventoryMapper.updateById(officialInventory);
+
         // 鏋勫缓閿�鍞褰曞疄浣�
-        SalesRecord salesRecord = buildSalesRecord(salesRecordDto);
+        SalesRecord salesRecord = buildSalesRecord(salesRecordDto,officialInventory.getCoal());
 
         // 澶勭悊鏂板/鏇存柊閫昏緫
         if (salesRecordDto.getId() == null) {
@@ -73,9 +89,12 @@
         if (dto.getCustomerId() == null) {
             throw new BaseException("瀹㈡埛ID涓嶈兘涓虹┖");
         }
+        if (dto.getCoalId() == null) {
+            throw new BaseException("璇烽�夋嫨涓�鏉$叅绉嶄俊鎭�");
+        }
     }
 
-    private SalesRecord buildSalesRecord(SalesRecordDto dto) {
+    private SalesRecord buildSalesRecord(SalesRecordDto dto,String coal) {
         SalesRecord record = new SalesRecord();
         BeanUtils.copyProperties(dto, record);
 
@@ -109,6 +128,9 @@
             record.setRegistrationDate(existing.getRegistrationDate());
         }
 
+        // 鐓ょ
+        record.setCoal(coal);
+
         return record;
     }
 

--
Gitblit v1.9.3