From 0d83a54d5f3ae08fe0ee4b3cd3fd72e94e2767e1 Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期二, 14 十月 2025 09:32:13 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java | 147 ++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 132 insertions(+), 15 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java
index 63c6b2b..1ee8e03 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java
@@ -4,8 +4,11 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
+import com.ruoyi.system.dto.OutboundGoodsDto;
+import com.ruoyi.system.dto.OutboundGoodsNextDto;
import com.ruoyi.system.dto.WarehousingGoodsDto;
import com.ruoyi.system.dto.WarehousingGoodsNextDto;
import com.ruoyi.system.mapper.*;
@@ -86,6 +89,8 @@
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);
@@ -170,6 +175,7 @@
}
tErpGoodsWarehouseLastVO.setAllNum(tErpGoodsWarehouseVOS.stream().mapToInt(TErpGoodsWarehouseVO::getNowNum).sum());
tErpGoodsWarehouseLastVO.setAllTotalPrice(tErpGoodsWarehouseVOS.stream().mapToDouble(TErpGoodsWarehouseVO::getUnitAmount).sum());
+ tErpGoodsWarehouseLastVO.setAllTotalPrice(BigDecimal.valueOf(tErpGoodsWarehouseLastVO.getAllTotalPrice()).setScale(2,RoundingMode.HALF_UP).doubleValue());
tErpGoodsWarehouseLastVO.setList(tErpGoodsWarehouseVOS);
tErpGoodsWarehouseLastVO.setWarningInventory(goods.getWarningInventory());
tErpGoodsWarehouseLastVOS.add(tErpGoodsWarehouseLastVO);
@@ -274,11 +280,14 @@
tErpSupplierWarehousing.setGoodsId(dto.getGoodsId());
TErpGoods goods = erpGoodsMapper.selectById(dto.getGoodsId());
tErpSupplierWarehousing.setGoodsName(goods.getGoodsName());
- tErpSupplierWarehousing.setGoodsCount(tErpSupplierWarehousing.getGoodsCount());
- tErpSupplierWarehousing.setUnitAmount(tErpSupplierWarehousing.getUnitAmount());
- tErpSupplierWarehousing.setTotalPrice(tErpSupplierWarehousing.getTotalPrice());
- erpSupplierWarehousingMapper.insert(tErpSupplierWarehousing);
+ tErpSupplierWarehousing.setGoodsCount(dto.getWarehousingNum());
+ tErpSupplierWarehousing.setUnitAmount(dto.getPrice());
+ tErpSupplierWarehousing.setTotalPrice(dto.getTotalPrice());
List<WarehousingGoodsNextDto> warehousingGoodsNextDtos = dto.getWarehousingGoodsNextDtos();
+ int sum = warehousingGoodsNextDtos.stream().mapToInt(WarehousingGoodsNextDto::getWarehousingNum).sum();
+ tErpSupplierWarehousing.setGoodsCount( sum);
+ erpSupplierWarehousingMapper.insert(tErpSupplierWarehousing);
+
for (WarehousingGoodsNextDto warehousingGoodsNextDto : warehousingGoodsNextDtos) {
TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = new TErpSupplierWarehousingBatch();
tErpSupplierWarehousingBatch.setWarehousingId(tErpSupplierWarehousing.getId());
@@ -288,7 +297,7 @@
tErpSupplierWarehousingBatch.setExpiryDate(warehousingGoodsNextDto.getExpiryDate().atStartOfDay());
erpSupplierWarehousingBatchMapper.insert(tErpSupplierWarehousingBatch);
- if(goods.getMaintenanceInterval()!=null){
+ if(goods.getMaintenanceInterval()!=null && !goods.getMaintenanceInterval().isEmpty()){
TErpMaintenanceReminder tErpMaintenanceReminder = new TErpMaintenanceReminder();
tErpMaintenanceReminder.setClinicSupplierId(supplierClinicId);
tErpMaintenanceReminder.setMaintenanceType(1);
@@ -378,32 +387,43 @@
BigDecimal subtract = BigDecimal.ZERO;
List<TErpSupplierInventoryGoods> tErpSupplierInventoryGoodsList = tErpSupplierInventoryGoods.stream().filter(t -> t.getInventoryId().equals(pageInventoryListVo.getId())).collect(Collectors.toList());
for (TErpSupplierInventoryGoods tErpSupplierInventoryGoods1 : tErpSupplierInventoryGoodsList) {
+
+
if(tErpSupplierInventoryGoods1!=null){
// 盘盈 查入库
if(tErpSupplierInventoryGoods1.getInventoryType()==1){
TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingId());
- List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getWarehousingId, tErpSupplierWarehousing.getId()));
- int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum();
+// 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);
- BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(sum));
+// TErpGoods goods = erpGoodsMapper.selectById(goodsId);
+ int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount();
+ BigDecimal multiply = tErpSupplierWarehousing.getUnitAmount().multiply(new BigDecimal(count));
add = add.add(multiply);
}else {
// 盘亏 查出库
TErpSupplierOutbound tErpSupplierOutbound = erpSupplierOutboundMapper.selectById(tErpSupplierInventoryGoods1.getWarehousingId());
List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getOutboundId, tErpSupplierOutbound.getId()));
- 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);
+ for (TErpSupplierOutboundGoods tErpSupplierOutboundGood : tErpSupplierOutboundGoods) {
+ TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(tErpSupplierOutboundGood.getWarehousingId());
+ String goodsId = tErpSupplierWarehousing.getGoodsId();
+// TErpGoods goods = erpGoodsMapper.selectById(goodsId);
+ int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount();
+ BigDecimal multiply = tErpSupplierWarehousing.getUnitAmount().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(TErpSupplierInventoryGoods::getGoodsId).collect(Collectors.toSet()).size();
pageInventoryListVo.setNum(size);
- pageInventoryListVo.setTotalPrice(add.subtract(subtract));
+ pageInventoryListVo.setTotalPrice(add);
}
@@ -444,6 +464,41 @@
inventoryDetailVo.setInventoryCount(tErpSupplierInventoryGood.getInventoryCount());
inventoryDetailVo.setInventoryType(tErpSupplierInventoryGood.getInventoryType());
inventoryDetailVo.setDamagedCount(tErpSupplierInventoryGood.getDamagedCount());
+ }else {
+ TErpSupplierOutbound tErpSupplierOutbound = erpSupplierOutboundMapper.selectById(tErpSupplierInventoryGood.getWarehousingId());
+ List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getOutboundId, tErpSupplierOutbound.getId()));
+ for (TErpSupplierOutboundGoods tErpSupplierOutboundGood : tErpSupplierOutboundGoods) {
+ String warehousingId = tErpSupplierOutboundGood.getWarehousingId();
+ TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(warehousingId);
+ 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());
+
+ TErpSupplierOutboundGoods tErpSupplierOutboundGoods2 = erpSupplierOutboundGoodsMapper.selectById(tErpSupplierInventoryGood.getWarehousingBatchId());
+
+ TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = erpSupplierWarehousingBatchMapper.selectById(tErpSupplierOutboundGoods2.getWarehousingBatchId());
+ inventoryDetailVo.setBatchNumber(tErpSupplierWarehousingBatch.getBatchNumber());
+
+
+ List<TErpSupplierWarehousingBatch> tErpSupplierWarehousingBatches = erpSupplierWarehousingBatchMapper.selectList(new LambdaQueryWrapper<TErpSupplierWarehousingBatch>().eq(TErpSupplierWarehousingBatch::getId, tErpSupplierOutboundGoods2.getWarehousingBatchId()));
+ int sum = tErpSupplierWarehousingBatches.stream().mapToInt(TErpSupplierWarehousingBatch::getWarehousingNumber).sum();
+ List<String> collect = tErpSupplierWarehousingBatches.stream().map(TErpSupplierWarehousingBatch::getId).collect(Collectors.toList());
+ if(!collect.isEmpty()){
+ List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods1 = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().in(TErpSupplierOutboundGoods::getWarehousingBatchId, collect));
+ int sum1 = tErpSupplierOutboundGoods1.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum();
+ sum = sum-sum1;
+ }
+
+ // sum = 剩余库存
+ inventoryDetailVo.setNowCount(sum);
+ inventoryDetailVo.setInventoryCount(tErpSupplierInventoryGood.getInventoryCount());
+ inventoryDetailVo.setInventoryType(tErpSupplierInventoryGood.getInventoryType());
+ inventoryDetailVo.setDamagedCount(tErpSupplierInventoryGood.getDamagedCount());
+ }
+
}
inventoryDetailVos.add(inventoryDetailVo);
@@ -456,4 +511,66 @@
return Collections.emptyList();
}
+
+ @Override
+ public void outbountGoods(OutboundGoodsDto dto, SysUser user) {
+ Integer roleType = user.getRoleType();
+ String supplierClinicId = null;
+ if(roleType == 4){
+ // 供应商
+ TCrmSupplier crmSupplier = crmSupplierMapper.selectOne(Wrappers.lambdaQuery(TCrmSupplier.class)
+ .eq(TCrmSupplier::getUserId, user.getUserId())
+ .last("LIMIT 1"));
+ supplierClinicId =crmSupplier.getId();
+ }
+ if(roleType == 5){
+ // 诊所
+ TCrmClinic crmClinic = crmClinicMapper.selectOne(Wrappers.lambdaQuery(TCrmClinic.class)
+ .eq(TCrmClinic::getUserId, user.getUserId())
+ .last("LIMIT 1"));
+ supplierClinicId =crmClinic.getId();
+ }
+ BigDecimal add = new BigDecimal(0);
+ ArrayList<TErpSupplierOutboundGoods> arrayList = new ArrayList<>();
+ // 1 判断库存是否足够 2添加出库记录 3添加出库子记录
+ List<OutboundGoodsNextDto> outboundGoodsNextDtos = dto.getOutboundGoodsNextDtos();
+ for (OutboundGoodsNextDto outboundGoodsNextDto : outboundGoodsNextDtos) {
+ TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = erpSupplierWarehousingBatchMapper.selectById(outboundGoodsNextDto.getBatchId());
+ List<TErpSupplierOutboundGoods> tErpSupplierOutboundGoods = erpSupplierOutboundGoodsMapper.selectList(new LambdaQueryWrapper<TErpSupplierOutboundGoods>().eq(TErpSupplierOutboundGoods::getWarehousingBatchId, outboundGoodsNextDto.getBatchId()));
+ int sum = tErpSupplierOutboundGoods.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum();
+
+ int count = tErpSupplierWarehousingBatch.getWarehousingNumber() - sum;
+ if(count<outboundGoodsNextDto.getNum()){
+ throw new ServiceException("批次号:"+tErpSupplierWarehousingBatch.getBatchNumber()+"库存不足");
+ }
+ TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(tErpSupplierWarehousingBatch.getWarehousingId());
+// TErpGoods goods = erpGoodsMapper.selectById(tErpSupplierWarehousing.getGoodsId());
+ BigDecimal multiply = tErpSupplierWarehousing.getUnitAmount().multiply(BigDecimal.valueOf(outboundGoodsNextDto.getNum()));
+
+ TErpSupplierOutboundGoods tErpSupplierOutboundGoods1 = new TErpSupplierOutboundGoods();
+ tErpSupplierOutboundGoods1.setWarehousingId(tErpSupplierWarehousing.getId());
+ tErpSupplierOutboundGoods1.setWarehousingBatchId(outboundGoodsNextDto.getBatchId());
+ tErpSupplierOutboundGoods1.setOutboundCount(outboundGoodsNextDto.getNum());
+ tErpSupplierOutboundGoods1.setTotalPrice(multiply);
+ arrayList.add(tErpSupplierOutboundGoods1);
+ add = add.add(multiply);
+ }
+
+ TErpSupplierOutbound tErpSupplierOutbound = new TErpSupplierOutbound();
+ tErpSupplierOutbound.setOutboundType(dto.getOutboundType());
+ tErpSupplierOutbound.setOutboundReason(dto.getOutboundReason());
+ tErpSupplierOutbound.setWarehouseId(dto.getWarehouseId());
+ tErpSupplierOutbound.setSupplierId(supplierClinicId);
+ tErpSupplierOutbound.setTotalMoney(add);
+ String s = DateUtils.dateTimeNow();
+ tErpSupplierOutbound.setOutboundNumber("G" + s);
+ erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
+
+ for (TErpSupplierOutboundGoods tErpSupplierOutboundGoods : arrayList) {
+ tErpSupplierOutboundGoods.setOutboundId(tErpSupplierOutbound.getId());
+ erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods);
+ }
+
+
+ }
}
--
Gitblit v1.7.1