From ce531d3bb32f5221b35f9e24d027ef83450ebbc6 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期二, 21 十月 2025 16:58:34 +0800
Subject: [PATCH] 修改bug
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TErpSupplierWarehousingServiceImpl.java | 157 +++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 129 insertions(+), 28 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 49a3e7b..7d9f1ea 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
@@ -3,6 +3,7 @@
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.BaseModel;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
@@ -24,6 +25,8 @@
import com.ruoyi.system.vo.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
@@ -89,6 +92,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);
@@ -173,6 +178,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);
@@ -250,6 +256,7 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class)
public void warehousingGoods(List<WarehousingGoodsDto> dtos, SysUser user) {
Integer roleType = user.getRoleType();
String supplierClinicId = null;
@@ -270,18 +277,49 @@
for (WarehousingGoodsDto dto : dtos) {
TErpSupplierWarehousing tErpSupplierWarehousing = new TErpSupplierWarehousing();
// 当前年月日时分秒
- String time = DateUtils.dateTimeNow();
- tErpSupplierWarehousing.setWarehouseNo("G"+time);
+ // 查询上一个入库单
+ TErpSupplierWarehousing last = erpSupplierWarehousingMapper.selectOne(new LambdaQueryWrapper<TErpSupplierWarehousing>().orderByDesc(TErpSupplierWarehousing::getCreateTime).last("LIMIT 1"));
+ if(last==null){
+ tErpSupplierWarehousing.setWarehouseNo("G"+DateUtils.dateTimeNow()+"00001");
+ }else {
+ String lastProcurementCode = last.getWarehouseNo();
+ String datePart = "G" + DateUtils.dateTimeNow();
+
+ // 直接获取后五位数字并+1,不考虑是否同一天
+ try {
+ String numberPart = lastProcurementCode.substring(Math.max(0, lastProcurementCode.length() - 5));
+ int number = Integer.parseInt(numberPart);
+ if (number < 99999) {
+ number++;
+ } else {
+ number = 2; // 达到99999后重置为00002
+ }
+ tErpSupplierWarehousing.setWarehouseNo(datePart + String.format("%05d", number));
+ } catch (NumberFormatException e) {
+ // 如果解析失败,默认从00001开始
+ tErpSupplierWarehousing.setWarehouseNo(datePart + "00001");
+ }
+
+ }
+
+
tErpSupplierWarehousing.setSupplierId(supplierClinicId);
tErpSupplierWarehousing.setWarehouseId(dto.getWarehouseId());
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);
+ try {
+ erpSupplierWarehousingMapper.insert(tErpSupplierWarehousing);
+ }catch (Exception e){
+ throw new RuntimeException("网络繁忙,请重试");
+ }
+
for (WarehousingGoodsNextDto warehousingGoodsNextDto : warehousingGoodsNextDtos) {
TErpSupplierWarehousingBatch tErpSupplierWarehousingBatch = new TErpSupplierWarehousingBatch();
tErpSupplierWarehousingBatch.setWarehousingId(tErpSupplierWarehousing.getId());
@@ -291,7 +329,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);
@@ -390,9 +428,9 @@
// 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);
+// TErpGoods goods = erpGoodsMapper.selectById(goodsId);
int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount();
- BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(count));
+ BigDecimal multiply = tErpSupplierWarehousing.getUnitAmount().multiply(new BigDecimal(count));
add = add.add(multiply);
}else {
// 盘亏 查出库
@@ -402,9 +440,9 @@
for (TErpSupplierOutboundGoods tErpSupplierOutboundGood : tErpSupplierOutboundGoods) {
TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(tErpSupplierOutboundGood.getWarehousingId());
String goodsId = tErpSupplierWarehousing.getGoodsId();
- TErpGoods goods = erpGoodsMapper.selectById(goodsId);
+// TErpGoods goods = erpGoodsMapper.selectById(goodsId);
int count = tErpSupplierInventoryGoods1.getInventoryCount() - tErpSupplierInventoryGoods1.getDamagedCount();
- BigDecimal multiply = goods.getSalesAmount().multiply(new BigDecimal(count));
+ BigDecimal multiply = tErpSupplierWarehousing.getUnitAmount().multiply(new BigDecimal(count));
add = add.add(multiply);
}
// int sum = tErpSupplierOutboundGoods.stream().mapToInt(TErpSupplierOutboundGoods::getOutboundCount).sum();
@@ -458,6 +496,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);
@@ -472,6 +545,7 @@
}
@Override
+ @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public void outbountGoods(OutboundGoodsDto dto, SysUser user) {
Integer roleType = user.getRoleType();
String supplierClinicId = null;
@@ -503,32 +577,59 @@
throw new ServiceException("批次号:"+tErpSupplierWarehousingBatch.getBatchNumber()+"库存不足");
}
TErpSupplierWarehousing tErpSupplierWarehousing = erpSupplierWarehousingMapper.selectById(tErpSupplierWarehousingBatch.getWarehousingId());
- TErpGoods goods = erpGoodsMapper.selectById(tErpSupplierWarehousing.getGoodsId());
- BigDecimal multiply = goods.getSalesAmount().multiply(BigDecimal.valueOf(outboundGoodsNextDto.getNum()));
+// TErpGoods goods = erpGoodsMapper.selectById(tErpSupplierWarehousing.getGoodsId());
+ BigDecimal multiply = tErpSupplierWarehousing.getUnitAmount().multiply(BigDecimal.valueOf(outboundGoodsNextDto.getNum()));
TErpSupplierOutboundGoods tErpSupplierOutboundGoods1 = new TErpSupplierOutboundGoods();
- tErpSupplierOutboundGoods1.setWarehousingId(dto.getWarehouseId());
+ 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);
+ TErpSupplierOutbound last = erpSupplierOutboundMapper.selectOne(new LambdaQueryWrapper<TErpSupplierOutbound>().orderByDesc(BaseModel::getCreateTime).last("LIMIT 1"));
+ if(last==null){
+ tErpSupplierOutbound.setOutboundNumber("G" + DateUtils.dateTimeNow()+ "00001");
+ }else{
+ String lastProcurementCode = last.getOutboundNumber();
+ String datePart = "G" + DateUtils.dateTimeNow();
+ // 直接获取后五位数字并+1,不考虑是否同一天
+ try {
+ String numberPart = lastProcurementCode.substring(Math.max(0, lastProcurementCode.length() - 5));
+ int number = Integer.parseInt(numberPart);
+ if (number < 99999) {
+ number++;
+ } else {
+ number = 2; // 达到99999后重置为00002
+ }
+ tErpSupplierOutbound.setOutboundNumber(datePart + String.format("%05d", number));
+ } catch (NumberFormatException e) {
+ // 如果解析失败,默认从00001开始
+ tErpSupplierOutbound.setOutboundNumber(datePart + "00001");
+ }
+ }
+ tErpSupplierOutbound.setGoodsId(tErpSupplierWarehousing.getGoodsId());
+ try {
+ erpSupplierOutboundMapper.insert(tErpSupplierOutbound);
+ }catch (Exception e){
+ throw new RuntimeException("网络繁忙,请重试");
+ }
+
+
+ for (TErpSupplierOutboundGoods tErpSupplierOutboundGoods2 : arrayList) {
+ tErpSupplierOutboundGoods2.setOutboundId(tErpSupplierOutbound.getId());
+ erpSupplierOutboundGoodsMapper.insert(tErpSupplierOutboundGoods2);
+ }
+
}
- 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