From be9e92d2c30fdfeed4bdd3a5aea2c84bd93f61f4 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期三, 15 十月 2025 16:23:24 +0800
Subject: [PATCH] bug修改

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpProcurementServiceImpl.java |  105 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 92 insertions(+), 13 deletions(-)

diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpProcurementServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpProcurementServiceImpl.java
index 1a7583f..3033e10 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpProcurementServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpProcurementServiceImpl.java
@@ -44,7 +44,9 @@
 import java.math.RoundingMode;
 import java.security.PrivateKey;
 import java.security.cert.X509Certificate;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -98,6 +100,9 @@
 
     @Resource
     private TErpSupplierOutboundGoodsMapper erpSupplierOutboundGoodsMapper;
+
+    @Resource
+    private TCrmWarehouseMapper crmWarehouseMapper;
 
 
     @Override
@@ -168,15 +173,15 @@
 
 
         Integer roleType = user.getRoleType();
-        String supplierClinicId = null;
+        List<String> supplierClinicId = null;
         if (roleType == 6) {
-            // 供应商
-            TCrmSupplier crmSupplier = crmSupplierMapper.selectOne(Wrappers.lambdaQuery(TCrmSupplier.class)
-                    .eq(TCrmSupplier::getUserId, user.getUserId())
+
+            TCrmWarehouse warehouse = crmWarehouseMapper.selectOne(Wrappers.lambdaQuery(TCrmWarehouse.class)
+                    .eq(TCrmWarehouse::getUserId, user.getUserId())
                     .last("LIMIT 1"));
-            supplierClinicId = crmSupplier.getId();
-
-
+            // 供应商
+            supplierClinicId = crmSupplierMapper.selectList(Wrappers.lambdaQuery(TCrmSupplier.class)
+                    .eq(TCrmSupplier::getWarehouseId, warehouse.getId())).stream().map(TCrmSupplier::getId).collect(Collectors.toList());
             String sTime = null;
             String eTime = null;
             if (query.getTime() != null && !query.getTime().isEmpty()) {
@@ -184,7 +189,11 @@
                 sTime = split[0] + " 00:00:00";
                 eTime = split[1] + " 23:59:59";
             }
+
             PageInfo<TErpProcurementVo> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
+            if(supplierClinicId.isEmpty()){
+                return pageInfo;
+            }
             List<TErpProcurementVo> list = this.baseMapper.pageListWarehouse(query, pageInfo, user, sTime, eTime, supplierClinicId);
 //            if (list.isEmpty()) {
 //                return pageInfo;
@@ -377,7 +386,7 @@
             BigDecimal all = BigDecimal.ZERO;
 
             for (AddProcurementDto addProcurementDto : value) {
-                BigDecimal multiply = addProcurementDto.getSalesAmount().multiply(BigDecimal.valueOf(addProcurementDto.getPurchaseCount()));
+                BigDecimal multiply = addProcurementDto.getGoodsSalesAmount().multiply(BigDecimal.valueOf(addProcurementDto.getPurchaseCount()));
                 all = all.add(multiply);
             }
             tErpProcurement.setPayMoney(all);
@@ -404,7 +413,9 @@
                 tErpProcurementGoods.setQuasiNumber(goods.getQuasiNumber());
 
                 TErpGoodsUnit tErpGoodsUnit = erpGoodsUnitMapper.selectById(goods.getPackingUnitId());
-                tErpProcurementGoods.setUnitName(tErpGoodsUnit.getUnitName());
+                if(tErpGoodsUnit!=null){
+                    tErpProcurementGoods.setUnitName(tErpGoodsUnit.getUnitName());
+                }
                 tErpProcurementGoods.setPurchasePrice(dto.getGoodsSalesAmount());
                 tErpProcurementGoods.setSalesAmount(dto.getSalesAmount());
                 tErpProcurementGoods.setTotalPrice(dto.getGoodsSalesAmount().multiply(new BigDecimal(dto.getPurchaseCount())));
@@ -438,6 +449,13 @@
     public DetailProcurementVO detailProcurement(String clinicSupplierId, SysUser user, String id) {
         DetailProcurementVO detailProcurementVO = new DetailProcurementVO();
         TErpProcurement tErpProcurement = this.getById(id);
+        if (tErpProcurement.getWarehousingUserId()!=null && !tErpProcurement.getWarehousingUserId().isEmpty()) {
+            SysUser sysUser = sysUserMapper.selectUserById(Long.valueOf(tErpProcurement.getWarehousingUserId()));
+            detailProcurementVO.setWarehousingUserName(sysUser.getUserName());
+        }
+        detailProcurementVO.setWarehousingTime(tErpProcurement.getWarehousingTime());
+
+
         detailProcurementVO.setStatus(tErpProcurement.getStatus());
         detailProcurementVO.setCreateTime(tErpProcurement.getCreateTime());
         detailProcurementVO.setSendTime(tErpProcurement.getSendTime());
@@ -460,6 +478,25 @@
             detailProcurementNextVO.setTotalPrice(tErpProcurement.getPayMoney());
             detailProcurementNextVO.setId(tErpProcurementGoods.getId());
             detailProcurementNextVO.setPurchasePrice(tErpProcurementGoods.getPurchasePrice());
+
+            List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getProcurementGoodsId, tErpProcurementGoods.getId()));
+            if(!tErpSupplierOutboundGoods.isEmpty()){
+                ArrayList<DetailProcurementNextThreeVO> detailProcurementNextThreeVOS = new ArrayList<>();
+                List<String> collect = tErpSupplierOutboundGoods.stream().map(TErpSupplierOutboundGoods::getWarehousingBatchId).collect(Collectors.toList());
+                List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectBatchIds(collect);
+                for (TErpSupplierOutboundGoods tErpSupplierOutboundGood : tErpSupplierOutboundGoods) {
+                    List<TErpSupplierWarehousingBatch> collect1 = tErpSupplierWarehousingBatches.stream().filter(e -> e.getId().equals(tErpSupplierOutboundGood.getWarehousingBatchId())).collect(Collectors.toList());
+                    for (TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch : collect1) {
+                        DetailProcurementNextThreeVO detailProcurementNextThreeVO = new DetailProcurementNextThreeVO();
+                        detailProcurementNextThreeVO.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber());
+                        detailProcurementNextThreeVO.setProductionDate(tErpSupplierWarehousingBatch.getProductionDate());
+                        detailProcurementNextThreeVO.setExpirationDate(tErpSupplierWarehousingBatch.getExpiryDate());
+                        detailProcurementNextThreeVO.setNum(tErpSupplierOutboundGood.getOutboundCount());
+                        detailProcurementNextThreeVOS.add(detailProcurementNextThreeVO);
+                    }
+                }
+                detailProcurementNextVO.setDetailProcurementNextThreeVOS(detailProcurementNextThreeVOS);
+            }
             detailProcurementNextVOS.add(detailProcurementNextVO);
         }
         detailProcurementVO.setList(detailProcurementNextVOS);
@@ -468,11 +505,11 @@
 
     @Override
     @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
-    public void detailProcurementSend(String clinicSupplierId, SysUser user, String id) {
+    public void detailProcurementSend(List<String> clinicSupplierId, SysUser user, String id,String logisticsNumber) {
         // 查出这个采购的下级商品
         List<TErpProcurementGoods> list = erpProcurementGoodsService.list(new QueryWrapper<TErpProcurementGoods>().eq("procurement_id", id));
         List<TErpSupplierWarehousing> tErpSupplierWarehousings = erpSupplierWarehousingMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousing>()
-                .eq(TErpSupplierWarehousing::getSupplierId, clinicSupplierId).in(TErpSupplierWarehousing::getGoodsId, list.stream().map(TErpProcurementGoods::getGoodsId).collect(Collectors.toList()))
+                .in(TErpSupplierWarehousing::getSupplierId, clinicSupplierId).in(TErpSupplierWarehousing::getGoodsId, list.stream().map(TErpProcurementGoods::getGoodsId).collect(Collectors.toList()))
                 .orderByAsc(BaseModel::getCreateTime));
 
         if(tErpSupplierWarehousings.isEmpty()){
@@ -516,7 +553,7 @@
                     if(count>=purchaseCount){
                         // 添加出库记录
                         TErpSupplierOutbound tErpSupplierOutbound= new TErpSupplierOutbound();
-                        tErpSupplierOutbound.setSupplierId(clinicSupplierId);
+                        tErpSupplierOutbound.setSupplierId(tErpSupplierWarehousing.getSupplierId());
                         tErpSupplierOutbound.setWarehouseId(tErpSupplierWarehousing.getWarehouseId());
                         tErpSupplierOutbound.setOutboundType(7);
                         //TODO 确定这个是采购价还是销售价格
@@ -530,6 +567,7 @@
                         tErpSupplierOutboundGoods.setWarehousingBatchId(warehousingBatch.getId());
                         tErpSupplierOutboundGoods.setOutboundCount(purchaseCount);
                         tErpSupplierOutboundGoods.setTotalPrice(tErpProcurementGoods.getPurchasePrice().multiply(new BigDecimal(purchaseCount)));
+                        tErpSupplierOutboundGoods.setProcurementGoodsId(tErpProcurementGoods.getId());
                         erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods);
                         continue outer;
                     }
@@ -538,7 +576,7 @@
                         purchaseCount = purchaseCount - count;
                         // 添加出库记录
                         TErpSupplierOutbound tErpSupplierOutbound= new TErpSupplierOutbound();
-                        tErpSupplierOutbound.setSupplierId(clinicSupplierId);
+                        tErpSupplierOutbound.setSupplierId(tErpSupplierWarehousing.getSupplierId());
                         tErpSupplierOutbound.setWarehouseId(tErpSupplierWarehousing.getWarehouseId());
                         tErpSupplierOutbound.setOutboundType(7);
                         //TODO 确定这个是采购价还是销售价格
@@ -552,6 +590,7 @@
                         tErpSupplierOutboundGoods.setWarehousingBatchId(warehousingBatch.getId());
                         tErpSupplierOutboundGoods.setOutboundCount(purchaseCount);
                         tErpSupplierOutboundGoods.setTotalPrice(tErpProcurementGoods.getPurchasePrice().multiply(new BigDecimal(purchaseCount)));
+                        tErpSupplierOutboundGoods.setProcurementGoodsId(tErpProcurementGoods.getId());
                         erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods);
                     }
 
@@ -564,6 +603,11 @@
 
 
         }
+        TErpProcurement byId = this.getById(id);
+        byId.setStatus(4);
+        byId.setSendTime(LocalDateTime.now());
+        byId.setLogisticsNumber(logisticsNumber);
+        this.updateById(byId);
 
     }
 
@@ -577,4 +621,39 @@
         return this.baseMapper.supplierThirtyMoneyProcurementStatistics(supplierAndClinicId, startTime, endTime, roleType);
     }
 
+    @Override
+    public Integer supplierSalesStatisticsTypeCount(String supplierId) {
+        return this.baseMapper.supplierSalesStatisticsTypeCount(supplierId);
+    }
+
+    @Override
+    public Integer supplierSalesStatisticsCount(String supplierId) {
+        return this.baseMapper.supplierSalesStatisticsCount(supplierId);
+    }
+
+    @Override
+    public BigDecimal supplierSalesStatisticsMoney(String supplierId, String startTime, String endTime) {
+        return this.baseMapper.supplierSalesStatisticsMoney(supplierId,startTime, endTime);
+    }
+
+    @Override
+    public List<SupplierSalesStatisticsGoodsTypeVO> supplierSalesStatisticsGoodsType(String supplierId, String startTime, String endTime) {
+        return this.baseMapper.supplierSalesStatisticsGoodsType(supplierId,startTime, endTime);
+    }
+
+    @Override
+    public List<SupplierSalesStatisticsGoodsCountVO> supplierSalesStatisticsGoodsCount(String supplierId, String startTime, String endTime, String goodsName) {
+        return this.baseMapper.supplierSalesStatisticsGoodsCount(supplierId,startTime, endTime,goodsName);
+    }
+
+    @Override
+    public List<SupplierSalesStatisticsGoodsCountVO> supplierSalesStatisticsGoodsCountMonth(String supplierId, String startTime, String endTime, String goodsName) {
+        return this.baseMapper.supplierSalesStatisticsGoodsCountMonth(supplierId,startTime, endTime,goodsName);
+    }
+
+    @Override
+    public List<TErpProcurementGoods> branchAdminStatisticsThree(List<String> clinicIds) {
+        return this.baseMapper.branchAdminStatisticsThree(clinicIds);
+    }
+
 }

--
Gitblit v1.7.1