From 08892731ebf9a4a6004700d5b3710f7ea3c7b5b5 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期二, 14 十月 2025 18:25:15 +0800
Subject: [PATCH] bug修改

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpClinicWarehousingServiceImpl.java |  181 +++++++++++++++++++++++----------------------
 1 files changed, 92 insertions(+), 89 deletions(-)

diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpClinicWarehousingServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpClinicWarehousingServiceImpl.java
index 742bfa3..587e81a 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpClinicWarehousingServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpClinicWarehousingServiceImpl.java
@@ -80,30 +80,29 @@
     public PageInfo<PageInventoryListVo> pageInventoryList(TErpInventoryQuery query, SysUser user) {
         Integer roleType = user.getRoleType();
         String supplierClinicId = null;
-        if(roleType == 5){
+        if (roleType == 5) {
             // 诊所
             TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class)
                     .eq(TCrmClinic::getUserId, user.getUserId())
                     .last("LIMIT 1"));
-            supplierClinicId =crmClinic.getId();
+            supplierClinicId = crmClinic.getId();
         }
-        String sTime=null;
-        String eTime =null;
-        if(query.getTime()!=null && !query.getTime().isEmpty()){
+        String sTime = null;
+        String eTime = null;
+        if (query.getTime() != null && !query.getTime().isEmpty()) {
             String[] split = query.getTime().split(" - ");
             sTime = split[0] + " 00:00:00";
             eTime = split[1] + " 23:59:59";
         }
         PageInfo<PageInventoryListVo> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
-        List<PageInventoryListVo> list = this.baseMapper.pageInventoryList(pageInfo,query,user,sTime,eTime,supplierClinicId);
-        if(list.isEmpty()){
+        List<PageInventoryListVo> list = this.baseMapper.pageInventoryList(pageInfo, query, user, sTime, eTime, supplierClinicId);
+        if (list.isEmpty()) {
             return pageInfo;
         }
 
 
-
         List<String> collect = list.stream().map(PageInventoryListVo::getId).collect(Collectors.toList());
-        List<TErpClinicInventoryGoods> tErpSupplierInventoryGoods = erpClinicInventoryGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicInventoryGoods>().in(TErpClinicInventoryGoods::getInventoryId,collect));
+        List<TErpClinicInventoryGoods> tErpSupplierInventoryGoods = erpClinicInventoryGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicInventoryGoods>().in(TErpClinicInventoryGoods::getInventoryId, collect));
         for (PageInventoryListVo pageInventoryListVo : list) {
             // 盘盈
             BigDecimal add = BigDecimal.ZERO;
@@ -114,9 +113,9 @@
             for (TErpClinicInventoryGoods tErpSupplierInventoryGoods1 : tErpSupplierInventoryGoodsList) {
 
 
-                if(tErpSupplierInventoryGoods1!=null){
+                if (tErpSupplierInventoryGoods1 != null) {
                     // 盘盈 查入库
-                    if(tErpSupplierInventoryGoods1.getInventoryType()==1){
+                    if (tErpSupplierInventoryGoods1.getInventoryType() == 1) {
                         TErpClinicWarehousingBatch tErpSupplierWarehousing = erpClinicWarehousingBatchMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingBatchId());
 //                        List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getWarehousingId, tErpSupplierWarehousing.getId()));
 //                        int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum();
@@ -125,7 +124,7 @@
                         int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount();
                         BigDecimal multiply = tErpSupplierWarehousing.getSalesAmount().multiply(new BigDecimal(count));
                         add = add.add(multiply);
-                    }else {
+                    } else {
                         // 盘亏 查出库
                         TErpClinicOutbound tErpSupplierOutbound = erpClinicOutboundMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingId());
 
@@ -161,20 +160,20 @@
         ArrayList<InventoryDetailVo> inventoryDetailVos = new ArrayList<>();
 
         List<TErpClinicInventoryGoods> tErpSupplierInventoryGoods = erpClinicInventoryGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicInventoryGoods>().eq(TErpClinicInventoryGoods::getInventoryId, id));
-        if(tErpSupplierInventoryGoods!=null && !tErpSupplierInventoryGoods.isEmpty()){
+        if (tErpSupplierInventoryGoods != null && !tErpSupplierInventoryGoods.isEmpty()) {
             for (TErpClinicInventoryGoods tErpSupplierInventoryGood : tErpSupplierInventoryGoods) {
                 InventoryDetailVo inventoryDetailVo = new InventoryDetailVo();
-                if(tErpSupplierInventoryGood.getInventoryType()==1){
+                if (tErpSupplierInventoryGood.getInventoryType() == 1) {
                     TErpClinicWarehousing tErpSupplierWarehousing = erpClinicWarehousingMapper.selectById(tErpSupplierInventoryGood.getWarehousingId());
                     String goodsId = tErpSupplierInventoryGood.getGoodsId();
                     TErpGoods goods = erpGoodsMapper.selectById(goodsId);
 
-                    if(goods.getGoodsSource()==1){
+                    if (goods.getGoodsSource() == 1) {
                         TCrmSupplier supplier = crmSupplierMapper.selectById(goods.getSupplierClinicId());
-                        if(supplier!=null){
+                        if (supplier != null) {
                             inventoryDetailVo.setSupplierName(supplier.getSupplierName());
                         }
-                    }else {
+                    } else {
                         inventoryDetailVo.setSupplierName(goods.getSupplierName());
                     }
 
@@ -188,10 +187,10 @@
                     List<TErpClinicWarehousingBatch> tErpSupplierWarehousingBatches = erpClinicWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpClinicWarehousingBatch>().eq(TErpClinicWarehousingBatch::getBatchNumber, tErpSupplierWarehousingBatch.getBatchNumber()));
                     int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpClinicWarehousingBatch::getWarehousingNumber).sum();
                     List<String> collect = tErpSupplierWarehousingBatches.stream().map(TErpClinicWarehousingBatch::getId).collect(Collectors.toList());
-                    if(!collect.isEmpty()){
+                    if (!collect.isEmpty()) {
                         List<TErpClinicOutboundGoods> tErpSupplierOutboundGoods = erpClinicOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicOutboundGoods>().eq(TErpClinicOutboundGoods::getWarehousingBatchId, collect));
                         int sum1 = tErpSupplierOutboundGoods.stream().mapToInt(TErpClinicOutboundGoods::getOutboundCount).sum();
-                        sum = sum-sum1;
+                        sum = sum - sum1;
                     }
 
                     // sum = 剩余库存
@@ -199,7 +198,7 @@
                     inventoryDetailVo.setInventoryCount(tErpSupplierInventoryGood.getInventoryCount());
                     inventoryDetailVo.setInventoryType(tErpSupplierInventoryGood.getInventoryType());
                     inventoryDetailVo.setDamagedCount(tErpSupplierInventoryGood.getDamagedCount());
-                }else {
+                } else {
                     TErpClinicOutbound tErpSupplierOutbound = erpClinicOutboundMapper.selectById(tErpSupplierInventoryGood.getWarehousingId());
                     List<TErpClinicOutboundGoods> tErpSupplierOutboundGoods = erpClinicOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicOutboundGoods>().eq(TErpClinicOutboundGoods::getOutboundId, tErpSupplierOutbound.getId()));
                     for (TErpClinicOutboundGoods tErpSupplierOutboundGood : tErpSupplierOutboundGoods) {
@@ -207,12 +206,12 @@
                         TErpClinicWarehousing tErpSupplierWarehousing = erpClinicWarehousingMapper.selectById(warehousingId);
                         String goodsId = tErpSupplierInventoryGood.getGoodsId();
                         TErpGoods goods = erpGoodsMapper.selectById(goodsId);
-                        if(goods.getGoodsSource()==1){
+                        if (goods.getGoodsSource() == 1) {
                             TCrmSupplier supplier = crmSupplierMapper.selectById(goods.getSupplierClinicId());
-                            if(supplier!=null){
+                            if (supplier != null) {
                                 inventoryDetailVo.setSupplierName(supplier.getSupplierName());
                             }
-                        }else {
+                        } else {
                             inventoryDetailVo.setSupplierName(goods.getSupplierName());
                         }
 
@@ -229,10 +228,10 @@
                         List<TErpClinicWarehousingBatch> tErpSupplierWarehousingBatches = erpClinicWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpClinicWarehousingBatch>().eq(TErpClinicWarehousingBatch::getId, outboundGoods.getWarehousingBatchId()));
                         int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpClinicWarehousingBatch::getWarehousingNumber).sum();
                         List<String> collect = tErpSupplierWarehousingBatches.stream().map(TErpClinicWarehousingBatch::getId).collect(Collectors.toList());
-                        if(!collect.isEmpty()){
+                        if (!collect.isEmpty()) {
                             List<TErpClinicOutboundGoods> tErpSupplierOutboundGoods1 = erpClinicOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicOutboundGoods>().in(TErpClinicOutboundGoods::getWarehousingBatchId, collect));
                             int sum1 = tErpSupplierOutboundGoods1.stream().mapToInt(TErpClinicOutboundGoods::getOutboundCount).sum();
-                            sum = sum-sum1;
+                            sum = sum - sum1;
                         }
 
                         // sum = 剩余库存
@@ -256,17 +255,16 @@
     }
 
 
-
     @Override
     public PageInfo<ValidityPeriodWarningVo> validityPeriodWarning(ValidityPeriodWarningQuery query, SysUser user) {
         Integer roleType = user.getRoleType();
         String supplierClinicId = null;
-        if(roleType == 5){
+        if (roleType == 5) {
             // 诊所
             TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class)
                     .eq(TCrmClinic::getUserId, user.getUserId())
                     .last("LIMIT 1"));
-            supplierClinicId =crmClinic.getId();
+            supplierClinicId = crmClinic.getId();
         }
         // 获取当前时间后9个月的时间
         LocalDateTime nineMonthLater = LocalDateTime.now().plusMonths(9);
@@ -274,21 +272,20 @@
         PageInfo<ValidityPeriodWarningVo> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
 
 
-
-        return this.baseMapper.validityPeriodWarning(pageInfo,query,user,nineMonthLater,supplierClinicId);
+        return this.baseMapper.validityPeriodWarning(pageInfo, query, user, nineMonthLater, supplierClinicId);
     }
 
     @Override
     public PageInfo<TErpGoodsVO> pageList(TErpGoodsQuery query, SysUser user) {
         PageInfo<TErpGoodsVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
-        List<TErpGoodsVO> list = this.baseMapper.pageList(query,pageInfo,user);
-        if(list.isEmpty()){
+        List<TErpGoodsVO> list = this.baseMapper.pageList(query, pageInfo, user);
+        if (list.isEmpty()) {
             return pageInfo;
         }
 
 
         List<String> typeIds = list.stream().map(TErpGoods::getTypeId).collect(Collectors.toList());
-        if(!typeIds.isEmpty()){
+        if (!typeIds.isEmpty()) {
             List<TErpGoodsType> typeList = erpGoodsTypeMapper.selectBatchIds(typeIds);
             for (TErpGoodsVO tErpGoodsVO : list) {
                 typeList.stream().filter(t -> t.getId().equals(tErpGoodsVO.getTypeId())).findFirst().ifPresent(t -> tErpGoodsVO.setTypeName(t.getTypeName()));
@@ -298,16 +295,17 @@
         pageInfo.setRecords(list);
         return pageInfo;
     }
+
     @Override
     public List<TErpGoodsVO> pageList1(TErpGoodsQuery query, SysUser user) {
-        List<TErpGoodsVO> list = this.baseMapper.pageList1(query,user);
-        if(list.isEmpty()){
+        List<TErpGoodsVO> list = this.baseMapper.pageList1(query, user);
+        if (list.isEmpty()) {
             return list;
         }
 
 
         List<String> typeIds = list.stream().map(TErpGoods::getTypeId).collect(Collectors.toList());
-        if(!typeIds.isEmpty()){
+        if (!typeIds.isEmpty()) {
             List<TErpGoodsType> typeList = erpGoodsTypeMapper.selectBatchIds(typeIds);
             for (TErpGoodsVO tErpGoodsVO : list) {
                 typeList.stream().filter(t -> t.getId().equals(tErpGoodsVO.getTypeId())).findFirst().ifPresent(t -> tErpGoodsVO.setTypeName(t.getTypeName()));
@@ -320,16 +318,16 @@
     @Override
     public PageInfo<TErpClinicWarehousePageListVO> warehousePageList(TClinicWarehouseQuery query, SysUser user, String supplierClinicId) {
         String time = query.getTime();
-        String sTime =null;
+        String sTime = null;
         String eTime = null;
-        if(time!=null && !time.isEmpty()){
+        if (time != null && !time.isEmpty()) {
             String[] split = time.split(" - ");
             sTime = split[0] + " 00:00:00";
             eTime = split[1] + " 23:59:59";
         }
         PageInfo<TErpClinicWarehousePageListVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
-        List<TErpClinicWarehousePageListVO> list = this.baseMapper.warehousePageList(query,pageInfo,user,supplierClinicId,sTime,eTime);
-        if(list.isEmpty()){
+        List<TErpClinicWarehousePageListVO> list = this.baseMapper.warehousePageList(query, pageInfo, user, supplierClinicId, sTime, eTime);
+        if (list.isEmpty()) {
             return pageInfo;
         }
         List<String> collect = list.stream().map(TErpClinicWarehousePageListVO::getId).collect(Collectors.toList());
@@ -346,15 +344,15 @@
     @Override
     public PageInfo<TErpClinicOutboundPageListVO> outboundPageList(TClinicOutboundQuery query, SysUser user, String supplierClinicId) {
         String time = query.getTime();
-        String sTime =null;
+        String sTime = null;
         String eTime = null;
-        if(time!=null && !time.isEmpty()){
+        if (time != null && !time.isEmpty()) {
             String[] split = time.split(" - ");
             sTime = split[0] + " 00:00:00";
             eTime = split[1] + " 23:59:59";
         }
         PageInfo<TErpClinicOutboundPageListVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
-        List<TErpClinicOutboundPageListVO> list = this.baseMapper.outboundPageList(query,pageInfo,user,supplierClinicId,sTime,eTime);
+        List<TErpClinicOutboundPageListVO> list = this.baseMapper.outboundPageList(query, pageInfo, user, supplierClinicId, sTime, eTime);
         pageInfo.setRecords(list);
         return pageInfo;
     }
@@ -366,53 +364,58 @@
 //        Map<String, List<clinicWarehouseGoodsDto>> collect = dtos.stream().collect(Collectors.groupingBy(clinicWarehouseGoodsDto::getSupplierId));
 
 //        for (Map.Entry<String, List<clinicWarehouseGoodsDto>> stringListEntry : collect.entrySet()) {
-            TErpClinicWarehousing tErpClinicWarehousing = new TErpClinicWarehousing();
-            tErpClinicWarehousing.setClinicId(supplierClinicId);
-            tErpClinicWarehousing.setCreateId(user.getUserId().toString());
-            tErpClinicWarehousing.setWarehouseNo("G"+ DateUtils.dateTimeNow());
-            tErpClinicWarehousing.setCreateTime(LocalDateTime.now());
-            tErpClinicWarehousing.setType(3);
-            tErpClinicWarehousing.setStatus(dtos.getStatus());
-            this.save(tErpClinicWarehousing);
+        TErpClinicWarehousing tErpClinicWarehousing = new TErpClinicWarehousing();
+        tErpClinicWarehousing.setClinicId(supplierClinicId);
+        tErpClinicWarehousing.setCreateId(user.getUserId().toString());
+        tErpClinicWarehousing.setWarehouseNo("G" + DateUtils.dateTimeNow());
+        tErpClinicWarehousing.setCreateTime(LocalDateTime.now());
+        tErpClinicWarehousing.setType(3);
+        tErpClinicWarehousing.setStatus(dtos.getStatus());
+        this.save(tErpClinicWarehousing);
 
-            BigDecimal totalPrice = new BigDecimal(0);
-            for (clinicWarehouseGoodsDto dto : dtos.getDtos()) {
-                TErpClinicWarehousingBatch tErpClinicWarehousingBatch = new TErpClinicWarehousingBatch();
-                tErpClinicWarehousingBatch.setWarehousingId(tErpClinicWarehousing.getId());
-                tErpClinicWarehousingBatch.setWarehousingNumber(dto.getPurchaseCount());
-                tErpClinicWarehousingBatch.setBatchNumber(dto.getBatchNumber());
-                tErpClinicWarehousingBatch.setProductionDate(dto.getProductionDate().atStartOfDay());
-                tErpClinicWarehousingBatch.setExpiryDate(dto.getExpiryDate().atStartOfDay());
-                tErpClinicWarehousingBatch.setGoodsId(dto.getId());
-                TErpGoods goods = erpGoodsMapper.selectById(dto.getId());
-                tErpClinicWarehousingBatch.setGoodsName(goods.getGoodsName());
-                tErpClinicWarehousingBatch.setQuasiNumber(goods.getQuasiNumber());
-                tErpClinicWarehousingBatch.setUnitAmount(dto.getUnitAmount());
-                tErpClinicWarehousingBatch.setSalesAmount(dto.getSalesAmount());
-                if(dto.getSalesAmount()==null){
-                    tErpClinicWarehousingBatch.setSalesAmount(goods.getClinicPurchasePrice());
-                }
-                tErpClinicWarehousingBatch.setPurchaseCount(dto.getPurchaseCount());
-                erpClinicWarehousingBatchMapper.insert(tErpClinicWarehousingBatch);
-
-
-                if(goods.getMaintenanceInterval()!=null && !goods.getMaintenanceInterval().isEmpty()){
-                    TErpMaintenanceReminder tErpMaintenanceReminder = new TErpMaintenanceReminder();
-                    tErpMaintenanceReminder.setClinicSupplierId(supplierClinicId);
-                    tErpMaintenanceReminder.setMaintenanceType(2);
-                    tErpMaintenanceReminder.setWarehousingBatchId(tErpClinicWarehousingBatch.getId());
-                    Integer day = Integer.valueOf(goods.getMaintenanceInterval());
-                    // 当前时间+day天
-                    LocalDateTime time1 = LocalDateTime.now().plusDays(day);
-                    tErpMaintenanceReminder.setMaintenanceTime(time1);
-                    erpMaintenanceReminderMapper.insert(tErpMaintenanceReminder);
-                }
-
-
-                totalPrice = totalPrice.add(dto.getSalesAmount().multiply(new BigDecimal(dto.getPurchaseCount())));
+        BigDecimal totalPrice = new BigDecimal(0);
+        ArrayList<String> names = new ArrayList<>();
+        for (clinicWarehouseGoodsDto dto : dtos.getDtos()) {
+            TErpClinicWarehousingBatch tErpClinicWarehousingBatch = new TErpClinicWarehousingBatch();
+            tErpClinicWarehousingBatch.setWarehousingId(tErpClinicWarehousing.getId());
+            tErpClinicWarehousingBatch.setWarehousingNumber(dto.getPurchaseCount());
+            tErpClinicWarehousingBatch.setBatchNumber(dto.getBatchNumber());
+            tErpClinicWarehousingBatch.setProductionDate(dto.getProductionDate().atStartOfDay());
+            tErpClinicWarehousingBatch.setExpiryDate(dto.getExpiryDate().atStartOfDay());
+            tErpClinicWarehousingBatch.setGoodsId(dto.getId());
+            TErpGoods goods = erpGoodsMapper.selectById(dto.getId());
+            String supplierName = goods.getSupplierName();
+            names.add(supplierName);
+            tErpClinicWarehousingBatch.setGoodsName(goods.getGoodsName());
+            tErpClinicWarehousingBatch.setQuasiNumber(goods.getQuasiNumber());
+            tErpClinicWarehousingBatch.setUnitAmount(dto.getUnitAmount());
+            tErpClinicWarehousingBatch.setSalesAmount(dto.getSalesAmount());
+            if (dto.getSalesAmount() == null) {
+                tErpClinicWarehousingBatch.setSalesAmount(goods.getClinicPurchasePrice());
             }
-            tErpClinicWarehousing.setTotalPrice(totalPrice);
-            this.updateById(tErpClinicWarehousing);
+            tErpClinicWarehousingBatch.setPurchaseCount(dto.getPurchaseCount());
+            erpClinicWarehousingBatchMapper.insert(tErpClinicWarehousingBatch);
+
+
+            if (goods.getMaintenanceInterval() != null && !goods.getMaintenanceInterval().isEmpty()) {
+                TErpMaintenanceReminder tErpMaintenanceReminder = new TErpMaintenanceReminder();
+                tErpMaintenanceReminder.setClinicSupplierId(supplierClinicId);
+                tErpMaintenanceReminder.setMaintenanceType(2);
+                tErpMaintenanceReminder.setWarehousingBatchId(tErpClinicWarehousingBatch.getId());
+                Integer day = Integer.valueOf(goods.getMaintenanceInterval());
+                // 当前时间+day天
+                LocalDateTime time1 = LocalDateTime.now().plusDays(day);
+                tErpMaintenanceReminder.setMaintenanceTime(time1);
+                erpMaintenanceReminderMapper.insert(tErpMaintenanceReminder);
+            }
+
+
+            totalPrice = totalPrice.add(dto.getSalesAmount().multiply(new BigDecimal(dto.getPurchaseCount())));
+        }
+        tErpClinicWarehousing.setTotalPrice(totalPrice);
+        String name = names.stream().collect(Collectors.joining(","));
+        tErpClinicWarehousing.setSupplierName(name);
+        this.updateById(tErpClinicWarehousing);
 
 //        }
 
@@ -423,7 +426,7 @@
         TErpClinicOutbound tErpClinicOutbound = new TErpClinicOutbound();
         tErpClinicOutbound.setClinicId(supplierClinicId);
         tErpClinicOutbound.setCreateId(user.getUserId().toString());
-        tErpClinicOutbound.setOutboundNumber("G"+ DateUtils.dateTimeNow());
+        tErpClinicOutbound.setOutboundNumber("G" + DateUtils.dateTimeNow());
         tErpClinicOutbound.setCreateTime(LocalDateTime.now());
         tErpClinicOutbound.setOutboundType(dto.getOutboundType());
         tErpClinicOutbound.setTotalMoney(dto.getTotalPrice());

--
Gitblit v1.7.1