From f6f57ba70679a0b050031f3cdf81b5bf5d4cbd60 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期五, 11 七月 2025 15:28:37 +0800
Subject: [PATCH] 1.生产加工优化 2.销售,库存查询优化

---
 main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java
index 5e340eb..d76fcf5 100644
--- a/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java
+++ b/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java
@@ -15,6 +15,7 @@
 import com.ruoyi.business.dto.PendingInventoryDto;
 import com.ruoyi.business.entity.OfficialInventory;
 import com.ruoyi.business.entity.PendingInventory;
+import com.ruoyi.business.entity.SalesRecord;
 import com.ruoyi.business.mapper.OfficialInventoryMapper;
 import com.ruoyi.business.mapper.PendingInventoryMapper;
 import com.ruoyi.business.service.InputInventoryRecordService;
@@ -22,6 +23,7 @@
 import com.ruoyi.business.service.PendingInventoryService;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.system.mapper.SysUserMapper;
 import lombok.RequiredArgsConstructor;
@@ -29,6 +31,8 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.format.DateTimeParseException;
 import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
@@ -65,6 +69,31 @@
     public IPage<PendingInventoryDto> selectPendingInventoryList(Page page, PendingInventoryDto pendingInventoryDto) {
         // 1. 鏋勫缓涓绘煡璇�
         LambdaQueryWrapper<PendingInventory> queryWrapper = new LambdaQueryWrapper<>();
+        if (StringUtils.isNotBlank(pendingInventoryDto.getSearchAll())) {
+            String searchValue = pendingInventoryDto.getSearchAll();
+            // 1. 鍏堝皾璇曚綔涓烘棩鏈熸煡璇�
+            try {
+                LocalDate RegistrationDate = LocalDate.parse(searchValue);
+                queryWrapper.eq(PendingInventory::getRegistrationDate, RegistrationDate);
+            } catch (DateTimeParseException e) {
+                // 2. 濡傛灉涓嶆槸鏃ユ湡锛屽垯浣滀负鐓ょ鍚嶇О鏌ヨ
+                LambdaQueryWrapper<CoalInfo> coalQueryWrapper = new LambdaQueryWrapper<>();
+                coalQueryWrapper.like(CoalInfo::getCoal, searchValue);
+                List<CoalInfo> coalInfos = coalInfoMapper.selectList(coalQueryWrapper);
+                if (!coalInfos.isEmpty()) {
+                    // 鎻愬彇鎵�鏈夊尮閰嶇殑鐓ょID
+                    List<Long> coalIds = coalInfos.stream()
+                            .map(CoalInfo::getId)
+                            .collect(Collectors.toList());
+                    // 浣跨敤in鏌ヨ鍖归厤浠绘剰涓�涓叅绉岻D
+                    queryWrapper.in(PendingInventory::getCoalId, coalIds);
+                } else {
+                    // 3. 濡傛灉鎵句笉鍒扮叅绉嶏紝鍙互杩斿洖绌虹粨鏋�
+                    queryWrapper.eq(PendingInventory::getCoalId, "-1"); // 浣跨敤涓嶅彲鑳藉瓨鍦ㄧ殑ID
+                }
+            }
+        }
+
         queryWrapper.orderByDesc(PendingInventory::getCreateTime);
 
         // 2. 鎵ц涓昏〃鍒嗛〉鏌ヨ
@@ -233,6 +262,7 @@
             BigDecimal left = pendingInventory.getInventoryQuantity().subtract(quantity);
             if (left.compareTo(BigDecimal.ZERO) > 0) {
                 pendingInventory.setInventoryQuantity(left);
+                pendingInventory.setCoalPlanId(pendingInventoryDto.getCoalPlanId());
                 pendingInventoryMapper.updateById(pendingInventory);
             } else {
                 pendingInventoryMapper.deleteById(pendingInventoryDto.getPId());
@@ -242,8 +272,11 @@
                 OfficialInventory officialInventory = new OfficialInventory();
                 BeanUtils.copyProperties(pendingInventory, officialInventory);
                 officialInventory.setId(null);
+                officialInventory.setCoalPlanId(pendingInventoryDto.getCoalPlanId());
                 officialInventory.setPendingId(pendingInventoryDto.getPId());
                 officialInventory.setInventoryQuantity(quantity);
+                officialInventory.setRegistrantId(1L);
+                officialInventory.setSupplierId(pendingInventoryDto.getSupplierId());
                 officialInventoryMapper.insert(officialInventory);
             } else {
                 OfficialInventory officialInventory = officialInventoryMapper.selectById(pendingInventoryDto.getOfficialId());

--
Gitblit v1.9.3