From f41b11c958ef7d0416d194278d1fe7cd1a1e8219 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期三, 24 九月 2025 18:43:19 +0800
Subject: [PATCH] 拉卡拉支付

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpClinicWarehousingServiceImpl.java |  225 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 223 insertions(+), 2 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 65a8f92..122815a 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
@@ -1,10 +1,29 @@
 package com.ruoyi.system.service.impl;
 
-import com.ruoyi.system.model.TErpClinicWarehousing;
-import com.ruoyi.system.mapper.TErpClinicWarehousingMapper;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.ruoyi.common.basic.PageInfo;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.system.mapper.*;
+import com.ruoyi.system.model.*;
+import com.ruoyi.system.query.TErpGoodsQuery;
+import com.ruoyi.system.query.TErpInventoryQuery;
+import com.ruoyi.system.query.ValidityPeriodWarningQuery;
 import com.ruoyi.system.service.TErpClinicWarehousingService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.system.vo.InventoryDetailVo;
+import com.ruoyi.system.vo.PageInventoryListVo;
+import com.ruoyi.system.vo.TErpGoodsVO;
+import com.ruoyi.system.vo.ValidityPeriodWarningVo;
 import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -17,4 +36,206 @@
 @Service
 public class TErpClinicWarehousingServiceImpl extends ServiceImpl<TErpClinicWarehousingMapper, TErpClinicWarehousing> implements TErpClinicWarehousingService {
 
+
+    @Resource
+    private TCrmClinicMapper crmClinicMapper;
+
+    @Resource
+    private TErpClinicInventoryGoodsMapper erpClinicInventoryGoodsMapper;
+
+    @Resource
+    private TErpGoodsMapper erpGoodsMapper;
+
+    @Resource
+    private TErpClinicWarehousingMapper erpClinicWarehousingMapper;
+
+    @Resource
+    private TErpClinicWarehousingBatchMapper erpClinicWarehousingBatchMapper;
+
+    @Resource
+    private TErpClinicOutboundGoodsMapper erpClinicOutboundGoodsMapper;
+
+
+    @Resource
+    private TErpClinicOutboundMapper erpClinicOutboundMapper;
+
+    @Resource
+    private TErpGoodsUnitMapper erpGoodsUnitMapper;
+
+
+    @Resource
+    private TErpGoodsTypeMapper erpGoodsTypeMapper;
+
+
+
+    @Override
+    public PageInfo<PageInventoryListVo> pageInventoryList(TErpInventoryQuery query, SysUser user) {
+        Integer roleType = user.getRoleType();
+        String supplierClinicId = null;
+        if(roleType == 5){
+            // 诊所
+            TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class)
+                    .eq(TCrmClinic::getUserId, user.getUserId())
+                    .last("LIMIT 1"));
+            supplierClinicId =crmClinic.getId();
+        }
+        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()){
+            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));
+        for (PageInventoryListVo pageInventoryListVo : list) {
+            // 盘盈
+            BigDecimal add = BigDecimal.ZERO;
+
+            // 盘亏
+            BigDecimal subtract = BigDecimal.ZERO;
+            List<TErpClinicInventoryGoods> tErpSupplierInventoryGoodsList = tErpSupplierInventoryGoods.stream().filter(t -> t.getInventoryId().equals(pageInventoryListVo.getId())).collect(Collectors.toList());
+            for (TErpClinicInventoryGoods tErpSupplierInventoryGoods1 : tErpSupplierInventoryGoodsList) {
+
+
+                if(tErpSupplierInventoryGoods1!=null){
+                    // 盘盈 查入库
+                    if(tErpSupplierInventoryGoods1.getInventoryType()==1){
+                        TErpClinicWarehousing tErpSupplierWarehousing = erpClinicWarehousingMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingId());
+//                        List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getWarehousingId, tErpSupplierWarehousing.getId()));
+//                        int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum();
+                        String goodsId = tErpSupplierWarehousing.getGoodsId();
+                        TErpGoods goods = erpGoodsMapper.selectById(goodsId);
+                        int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount();
+                        BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(count));
+                        add = add.add(multiply);
+                    }else {
+                        // 盘亏 查出库
+                        TErpClinicOutbound tErpSupplierOutbound = erpClinicOutboundMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingId());
+
+                        List<TErpClinicOutboundGoods> tErpSupplierOutboundGoods = erpClinicOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicOutboundGoods>().eq(TErpClinicOutboundGoods::getOutboundId, tErpSupplierOutbound.getId()));
+                        for (TErpClinicOutboundGoods tErpSupplierOutboundGood : tErpSupplierOutboundGoods) {
+                            TErpClinicWarehousing tErpSupplierWarehousing = erpClinicWarehousingMapper.selectById(tErpSupplierOutboundGood.getWarehousingId());
+                            String goodsId = tErpSupplierWarehousing.getGoodsId();
+                            TErpGoods goods = erpGoodsMapper.selectById(goodsId);
+                            int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount();
+                            BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(count));
+                            add = add.add(multiply);
+                        }
+//                        int sum = tErpSupplierOutboundGoods.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum();
+//                        String goodsId = tErpSupplierOutbound.getGoodsId();
+//                        TErpGoods goods = erpGoodsMapper.selectById(goodsId);
+//                        BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(sum));
+//                        subtract = subtract.add(multiply);
+                    }
+                }
+            }
+            int size = tErpSupplierInventoryGoodsList.stream().map(TErpClinicInventoryGoods::getGoodsId).collect(Collectors.toSet()).size();
+            pageInventoryListVo.setNum(size);
+            pageInventoryListVo.setTotalPrice(add);
+
+        }
+
+        pageInfo.setRecords(list);
+        return pageInfo;
+    }
+
+    @Override
+    public List<InventoryDetailVo> detailInventory(String id, SysUser user) {
+        ArrayList<InventoryDetailVo> inventoryDetailVos = new ArrayList<>();
+
+        List<TErpClinicInventoryGoods> tErpSupplierInventoryGoods = erpClinicInventoryGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicInventoryGoods>().eq(TErpClinicInventoryGoods::getInventoryId, id));
+        if(tErpSupplierInventoryGoods!=null && !tErpSupplierInventoryGoods.isEmpty()){
+            for (TErpClinicInventoryGoods tErpSupplierInventoryGood : tErpSupplierInventoryGoods) {
+                InventoryDetailVo inventoryDetailVo = new InventoryDetailVo();
+                if(tErpSupplierInventoryGood.getInventoryType()==1){
+                    TErpClinicWarehousing tErpSupplierWarehousing = erpClinicWarehousingMapper.selectById(tErpSupplierInventoryGood.getWarehousingId());
+                    String goodsId = tErpSupplierWarehousing.getGoodsId();
+                    TErpGoods goods = erpGoodsMapper.selectById(goodsId);
+                    inventoryDetailVo.setGoodsName(goods.getGoodsName());
+                    TErpGoodsUnit tErpGoodsUnit = erpGoodsUnitMapper.selectById(goods.getPackingUnitId());
+                    inventoryDetailVo.setUnitName(tErpGoodsUnit.getUnitName());
+                    inventoryDetailVo.setWarehouseNo(tErpSupplierWarehousing.getWarehouseNo());
+                    TErpClinicWarehousingBatch tErpSupplierWarehousingBatch = erpClinicWarehousingBatchMapper.selectById(tErpSupplierInventoryGood.getWarehousingBatchId());
+                    inventoryDetailVo.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber());
+
+                    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()){
+                        List<TErpClinicOutboundGoods> tErpSupplierOutboundGoods = erpClinicOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpClinicOutboundGoods>().eq(TErpClinicOutboundGoods::getWarehousingBatchId, collect));
+                        int sum1 = tErpSupplierOutboundGoods.stream().mapToInt(TErpClinicOutboundGoods::getOutboundCount).sum();
+                        sum = sum-sum1;
+                    }
+
+                    // sum = 剩余库存
+                    inventoryDetailVo.setNowCount(sum);
+                    inventoryDetailVo.setInventoryCount(tErpSupplierInventoryGood.getInventoryCount());
+                    inventoryDetailVo.setInventoryType(tErpSupplierInventoryGood.getInventoryType());
+                    inventoryDetailVo.setDamagedCount(tErpSupplierInventoryGood.getDamagedCount());
+                }
+                inventoryDetailVos.add(inventoryDetailVo);
+
+            }
+
+            return inventoryDetailVos;
+
+        }
+
+
+        return Collections.emptyList();
+    }
+
+
+
+    @Override
+    public PageInfo<ValidityPeriodWarningVo> validityPeriodWarning(ValidityPeriodWarningQuery query, SysUser user) {
+        Integer roleType = user.getRoleType();
+        String supplierClinicId = null;
+        if(roleType == 5){
+            // 诊所
+            TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class)
+                    .eq(TCrmClinic::getUserId, user.getUserId())
+                    .last("LIMIT 1"));
+            supplierClinicId =crmClinic.getId();
+        }
+        // 获取当前时间后9个月的时间
+        LocalDateTime nineMonthLater = LocalDateTime.now().plusMonths(9);
+
+        PageInfo<ValidityPeriodWarningVo> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize());
+
+
+
+        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()){
+            return pageInfo;
+        }
+
+
+        List<String> typeIds = list.stream().map(TErpGoods::getTypeId).collect(Collectors.toList());
+        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()));
+                tErpGoodsVO.setTypeName(tErpGoodsVO.getTypeName());
+            }
+        }
+        pageInfo.setRecords(list);
+        return pageInfo;
+    }
 }
+

--
Gitblit v1.7.1