From d8c86797adaef6c416efae16586f350ae77bde4b Mon Sep 17 00:00:00 2001
From: 吴羡 <16976746+Xian-TT3@user.noreply.gitee.com>
Date: 星期六, 12 九月 2026 12:43:08 +0800
Subject: [PATCH] feat: 库存入库/出库字段全链路、采购台账申请提交时间、储罐租客信息、油库储罐模块
---
src/main/java/com/ruoyi/stock/service/impl/StockUninventoryServiceImpl.java | 331 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 314 insertions(+), 17 deletions(-)
diff --git a/src/main/java/com/ruoyi/stock/service/impl/StockUninventoryServiceImpl.java b/src/main/java/com/ruoyi/stock/service/impl/StockUninventoryServiceImpl.java
index 06096c5..f30fd88 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockUninventoryServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockUninventoryServiceImpl.java
@@ -1,21 +1,47 @@
package com.ruoyi.stock.service.impl;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.alibaba.fastjson2.JSON;
+import com.ruoyi.basic.mapper.CustomerMapper;
+import com.ruoyi.basic.mapper.OilDepotMapper;
+import com.ruoyi.basic.mapper.ProductModelMapper;
+import com.ruoyi.basic.mapper.TankInfoMapper;
+import com.ruoyi.basic.pojo.Customer;
+import com.ruoyi.basic.pojo.OilDepot;
+import com.ruoyi.basic.pojo.ProductModel;
+import com.ruoyi.basic.pojo.TankInfo;
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.dto.StockInRecordDto;
+import com.ruoyi.stock.dto.StockInventoryDto;
import com.ruoyi.stock.dto.StockOutRecordDto;
import com.ruoyi.stock.dto.StockUninventoryDto;
+import com.ruoyi.stock.execl.StockUnInventoryExportData;
+import com.ruoyi.stock.mapper.StockInventoryMapper;
+import com.ruoyi.stock.mapper.StockUninventoryMapper;
+import com.ruoyi.stock.pojo.StockInRecord;
import com.ruoyi.stock.pojo.StockInventory;
import com.ruoyi.stock.pojo.StockUninventory;
-import com.ruoyi.stock.mapper.StockUninventoryMapper;
import com.ruoyi.stock.service.StockInRecordService;
import com.ruoyi.stock.service.StockOutRecordService;
import com.ruoyi.stock.service.StockUninventoryService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
/**
* <p>
@@ -26,11 +52,18 @@
* @since 2026-01-22 10:17:45
*/
@Service
+@RequiredArgsConstructor
public class StockUninventoryServiceImpl extends ServiceImpl<StockUninventoryMapper, StockUninventory> implements StockUninventoryService {
- private StockUninventoryMapper stockUninventoryMapper;
- private StockOutRecordService stockOutRecordService;
- private StockInRecordService stockInRecordService;
+
+ private final StockUninventoryMapper stockUninventoryMapper;
+ private final StockOutRecordService stockOutRecordService;
+ private final StockInRecordService stockInRecordService;
+ private final ProductModelMapper productModelMapper;
+ private final StockInventoryMapper stockInventoryMapper;
+ private final OilDepotMapper oilDepotMapper;
+ private final TankInfoMapper tankInfoMapper;
+ private final CustomerMapper customerMapper;
@Override
public IPage<StockUninventoryDto> pageStockUninventory(Page page, StockUninventoryDto stockUninventoryDto) {
@@ -40,26 +73,72 @@
@Override
@Transactional(rollbackFor = Exception.class)
public Integer addStockUninventory(StockUninventoryDto stockUninventoryDto) {
+ LambdaQueryWrapper<StockUninventory> wrapper = new LambdaQueryWrapper<>();
+ wrapper.eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId());
+ if (StringUtils.isEmpty(stockUninventoryDto.getBatchNo())) {
+ stockUninventoryDto.setBatchNo(null);
+ wrapper.isNull(StockUninventory::getBatchNo);
+ } else {
+ wrapper.eq(StockUninventory::getBatchNo, stockUninventoryDto.getBatchNo());
+ }
//鏂板鍏ュ簱璁板綍鍐嶆坊鍔犲簱瀛�
StockInRecordDto stockInRecordDto = new StockInRecordDto();
stockInRecordDto.setRecordId(stockUninventoryDto.getRecordId());
stockInRecordDto.setRecordType(stockUninventoryDto.getRecordType());
stockInRecordDto.setStockInNum(stockUninventoryDto.getQualitity());
+ stockInRecordDto.setBatchNo(stockUninventoryDto.getBatchNo());
stockInRecordDto.setProductModelId(stockUninventoryDto.getProductModelId());
stockInRecordDto.setType("1");
- stockInRecordService.add(stockInRecordDto);
- //鍐嶈繘琛屾柊澧炲簱瀛樻暟閲忓簱瀛�
- //鍏堟煡璇㈠簱瀛樿〃涓殑浜у搧鏄惁瀛樺湪锛屼笉瀛樺湪鏂板锛屽瓨鍦ㄦ洿鏂�
- StockUninventory oldStockUnInventory = stockUninventoryMapper.selectOne(new QueryWrapper<StockUninventory>().lambda().eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId()));
- if (ObjectUtils.isEmpty(oldStockUnInventory)) {
- StockUninventory newStockUnInventory = new StockUninventory();
- newStockUnInventory.setProductModelId(stockUninventoryDto.getProductModelId());
- newStockUnInventory.setQualitity(stockUninventoryDto.getQualitity());
- newStockUnInventory.setVersion(1);
- stockUninventoryMapper.insert(newStockUnInventory);
- }else {
- stockUninventoryMapper.updateAddStockUnInventory(stockUninventoryDto);
+ stockInRecordDto.setOilDepotId(stockUninventoryDto.getOilDepotId());
+ stockInRecordDto.setOilDepotName(stockUninventoryDto.getOilDepotName());
+ stockInRecordDto.setInboundCategory(stockUninventoryDto.getInboundCategory());
+ if (stockUninventoryDto.getOilDepotId() != null && StringUtils.isEmpty(stockInRecordDto.getOilDepotName())) {
+ OilDepot oilDepot = oilDepotMapper.selectById(stockUninventoryDto.getOilDepotId());
+ if (oilDepot != null) {
+ stockInRecordDto.setOilDepotName(oilDepot.getDepotName());
+ }
}
+ stockInRecordDto.setTankId(stockUninventoryDto.getTankId());
+ stockInRecordDto.setTankNo(stockUninventoryDto.getTankNo());
+ if (stockUninventoryDto.getTankId() != null && StringUtils.isEmpty(stockInRecordDto.getTankNo())) {
+ TankInfo tankInfo = tankInfoMapper.selectById(stockUninventoryDto.getTankId());
+ if (tankInfo != null) {
+ stockInRecordDto.setTankNo(tankInfo.getTankNo());
+ }
+ }
+ stockInRecordDto.setInboundTime(stockUninventoryDto.getInboundTime());
+ stockInRecordDto.setOilProduct(stockUninventoryDto.getOilProduct());
+ stockInRecordDto.setOriginalQuantity(stockUninventoryDto.getOriginalQuantity());
+ stockInRecordDto.setCustomerId(stockUninventoryDto.getCustomerId());
+ stockInRecordDto.setCustomerName(stockUninventoryDto.getCustomerName());
+ stockInRecordDto.setContactPerson(stockUninventoryDto.getContactPerson());
+ stockInRecordDto.setContactPhone(stockUninventoryDto.getContactPhone());
+ stockInRecordDto.setDriverName(stockUninventoryDto.getDriverName());
+ stockInRecordDto.setDriverPhone(stockUninventoryDto.getDriverPhone());
+ stockInRecordDto.setEscortName(stockUninventoryDto.getEscortName());
+ stockInRecordDto.setEscortPhone(stockUninventoryDto.getEscortPhone());
+ stockInRecordDto.setTruckPlateNo(stockUninventoryDto.getTruckPlateNo());
+ stockInRecordDto.setTrailerPlateNo(stockUninventoryDto.getTrailerPlateNo());
+ stockInRecordDto.setTankInspectionStatus(stockUninventoryDto.getTankInspectionStatus());
+ stockInRecordDto.setUnloadingCranePosition(stockUninventoryDto.getUnloadingCranePosition());
+ stockInRecordDto.setDensity(stockUninventoryDto.getDensity());
+ stockInRecordDto.setUnloadPhotos(stockUninventoryDto.getUnloadPhotos() == null
+ ? null : JSON.toJSONString(stockUninventoryDto.getUnloadPhotos()));
+ stockInRecordDto.setGrossWeight(stockUninventoryDto.getGrossWeight());
+ stockInRecordDto.setTareWeight(stockUninventoryDto.getTareWeight());
+ stockInRecordDto.setNetWeight(stockUninventoryDto.getNetWeight());
+ stockInRecordDto.setLossQuantity(stockUninventoryDto.getLossQuantity());
+ stockInRecordDto.setActualVolume(stockUninventoryDto.getActualVolume());
+ stockInRecordDto.setPoundPhotos(stockUninventoryDto.getPoundPhotos() == null
+ ? null : JSON.toJSONString(stockUninventoryDto.getPoundPhotos()));
+ if (stockUninventoryDto.getCustomerId() != null && StringUtils.isEmpty(stockInRecordDto.getCustomerName())) {
+ Customer customer = customerMapper.selectById(stockUninventoryDto.getCustomerId());
+ if (customer != null) {
+ stockInRecordDto.setCustomerName(customer.getCustomerName());
+ }
+ }
+ stockInRecordService.add(stockInRecordDto);
+ //瀹℃壒鍐嶆坊鍔�
return 1;
}
@@ -73,6 +152,8 @@
stockOutRecordDto.setRecordType(stockUninventoryDto.getRecordType());
stockOutRecordDto.setStockOutNum(stockUninventoryDto.getQualitity());
stockOutRecordDto.setProductModelId(stockUninventoryDto.getProductModelId());
+ stockOutRecordDto.setBatchNo(stockUninventoryDto.getBatchNo());
+ stockOutRecordDto.setType("1");
stockOutRecordService.add(stockOutRecordDto);
StockUninventory oldStockInventory = stockUninventoryMapper.selectOne(new QueryWrapper<StockUninventory>().lambda().eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId()));
if (ObjectUtils.isEmpty(oldStockInventory)) {
@@ -82,4 +163,220 @@
}
return 1;
}
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public Integer addStockInRecordOnly(StockUninventoryDto stockUninventoryDto) {
+ StockInRecordDto stockInRecordDto = new StockInRecordDto();
+ stockInRecordDto.setRecordId(stockUninventoryDto.getRecordId());
+ stockInRecordDto.setRecordType(stockUninventoryDto.getRecordType());
+ stockInRecordDto.setStockInNum(stockUninventoryDto.getQualitity());
+ String batchNo = StringUtils.trim(stockUninventoryDto.getBatchNo());
+ if (StringUtils.isEmpty(batchNo)) {
+ batchNo = generateAutoBatchNo(stockUninventoryDto.getProductModelId());
+ }
+ stockInRecordDto.setBatchNo(batchNo);
+ stockInRecordDto.setProductModelId(stockUninventoryDto.getProductModelId());
+ stockInRecordDto.setType("1");
+ stockInRecordDto.setRemark(stockUninventoryDto.getRemark());
+ stockInRecordDto.setOilDepotId(stockUninventoryDto.getOilDepotId());
+ stockInRecordDto.setOilDepotName(stockUninventoryDto.getOilDepotName());
+ stockInRecordDto.setInboundCategory(stockUninventoryDto.getInboundCategory());
+ if (stockUninventoryDto.getOilDepotId() != null && StringUtils.isEmpty(stockInRecordDto.getOilDepotName())) {
+ OilDepot oilDepot = oilDepotMapper.selectById(stockUninventoryDto.getOilDepotId());
+ if (oilDepot != null) {
+ stockInRecordDto.setOilDepotName(oilDepot.getDepotName());
+ }
+ }
+ stockInRecordDto.setTankId(stockUninventoryDto.getTankId());
+ stockInRecordDto.setTankNo(stockUninventoryDto.getTankNo());
+ if (stockUninventoryDto.getTankId() != null && StringUtils.isEmpty(stockInRecordDto.getTankNo())) {
+ TankInfo tankInfo = tankInfoMapper.selectById(stockUninventoryDto.getTankId());
+ if (tankInfo != null) {
+ stockInRecordDto.setTankNo(tankInfo.getTankNo());
+ }
+ }
+ stockInRecordDto.setInboundTime(stockUninventoryDto.getInboundTime());
+ stockInRecordDto.setOilProduct(stockUninventoryDto.getOilProduct());
+ stockInRecordDto.setOriginalQuantity(stockUninventoryDto.getOriginalQuantity());
+ stockInRecordDto.setCustomerId(stockUninventoryDto.getCustomerId());
+ stockInRecordDto.setCustomerName(stockUninventoryDto.getCustomerName());
+ stockInRecordDto.setContactPerson(stockUninventoryDto.getContactPerson());
+ stockInRecordDto.setContactPhone(stockUninventoryDto.getContactPhone());
+ stockInRecordDto.setDriverName(stockUninventoryDto.getDriverName());
+ stockInRecordDto.setDriverPhone(stockUninventoryDto.getDriverPhone());
+ stockInRecordDto.setEscortName(stockUninventoryDto.getEscortName());
+ stockInRecordDto.setEscortPhone(stockUninventoryDto.getEscortPhone());
+ stockInRecordDto.setTruckPlateNo(stockUninventoryDto.getTruckPlateNo());
+ stockInRecordDto.setTrailerPlateNo(stockUninventoryDto.getTrailerPlateNo());
+ stockInRecordDto.setTankInspectionStatus(stockUninventoryDto.getTankInspectionStatus());
+ stockInRecordDto.setUnloadingCranePosition(stockUninventoryDto.getUnloadingCranePosition());
+ stockInRecordDto.setDensity(stockUninventoryDto.getDensity());
+ stockInRecordDto.setUnloadPhotos(stockUninventoryDto.getUnloadPhotos() == null
+ ? null : JSON.toJSONString(stockUninventoryDto.getUnloadPhotos()));
+ stockInRecordDto.setGrossWeight(stockUninventoryDto.getGrossWeight());
+ stockInRecordDto.setTareWeight(stockUninventoryDto.getTareWeight());
+ stockInRecordDto.setNetWeight(stockUninventoryDto.getNetWeight());
+ stockInRecordDto.setLossQuantity(stockUninventoryDto.getLossQuantity());
+ stockInRecordDto.setActualVolume(stockUninventoryDto.getActualVolume());
+ stockInRecordDto.setPoundPhotos(stockUninventoryDto.getPoundPhotos() == null
+ ? null : JSON.toJSONString(stockUninventoryDto.getPoundPhotos()));
+ if (stockUninventoryDto.getCustomerId() != null && StringUtils.isEmpty(stockInRecordDto.getCustomerName())) {
+ Customer customer = customerMapper.selectById(stockUninventoryDto.getCustomerId());
+ if (customer != null) {
+ stockInRecordDto.setCustomerName(customer.getCustomerName());
+ }
+ }
+ stockInRecordService.add(stockInRecordDto);
+ return 1;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public Integer addStockOutRecordOnly(StockUninventoryDto stockUninventoryDto) {
+ LambdaQueryWrapper<StockUninventory> eq = new LambdaQueryWrapper<>();
+ eq.eq(StockUninventory::getProductModelId, stockUninventoryDto.getProductModelId());
+ if (StringUtils.isEmpty(stockUninventoryDto.getBatchNo())) {
+ eq.isNull(StockUninventory::getBatchNo);
+ } else {
+ eq.eq(StockUninventory::getBatchNo, stockUninventoryDto.getBatchNo());
+ }
+ StockUninventory stockUninventory = stockUninventoryMapper.selectOne(eq);
+ if (stockUninventory == null) {
+ throw new BaseException("搴撳瓨璁板綍涓嶅瓨鍦�");
+ }
+ BigDecimal lockedQty = stockUninventory.getLockedQuantity();
+ if (lockedQty == null) {
+ lockedQty = BigDecimal.ZERO;
+ }
+ BigDecimal pendingOut = stockUninventoryMapper.selectPendingOutQuantity(
+ stockUninventoryDto.getProductModelId(),
+ stockUninventoryDto.getBatchNo(),
+ "1"
+ );
+ if (pendingOut == null) {
+ pendingOut = BigDecimal.ZERO;
+ }
+ BigDecimal availableQty = stockUninventory.getQualitity().subtract(lockedQty).subtract(pendingOut);
+ if (stockUninventoryDto.getQualitity().compareTo(availableQty) > 0) {
+ throw new BaseException("鐢宠鏁伴噺瓒呰繃鍙敤搴撳瓨锛屽綋鍓嶅彲鐢ㄥ簱瀛樹负锛�" + availableQty);
+ }
+ StockOutRecordDto stockOutRecordDto = new StockOutRecordDto();
+ stockOutRecordDto.setRecordId(stockUninventoryDto.getRecordId());
+ stockOutRecordDto.setRecordType(stockUninventoryDto.getRecordType());
+ stockOutRecordDto.setStockOutNum(stockUninventoryDto.getQualitity());
+ stockOutRecordDto.setBatchNo(stockUninventoryDto.getBatchNo());
+ stockOutRecordDto.setProductModelId(stockUninventoryDto.getProductModelId());
+ stockOutRecordDto.setType("1");
+ stockOutRecordDto.setRemark(stockUninventoryDto.getRemark());
+ stockOutRecordService.add(stockOutRecordDto);
+ return 1;
+ }
+
+ @Override
+ public void exportStockUninventory(HttpServletResponse response, StockUninventoryDto stockUninventoryDto) {
+ List<StockUnInventoryExportData> list = stockUninventoryMapper.listStockInventoryExportData(stockUninventoryDto);
+ ExcelUtil<StockUnInventoryExportData> util = new ExcelUtil<>(StockUnInventoryExportData.class);
+ util.exportExcel(response,list, "涓嶅悎鏍煎簱瀛樹俊鎭�");
+ }
+
+ @Override
+ public Boolean frozenStock(StockInventoryDto stockInventoryDto) {
+ StockUninventory stockUninventory = stockUninventoryMapper.selectById(stockInventoryDto.getId());
+ if (stockUninventory.getQualitity().compareTo(stockInventoryDto.getLockedQuantity())<0) {
+ throw new RuntimeException("鍐荤粨鏁伴噺涓嶈兘瓒呰繃搴撳瓨鏁伴噺");
+ }
+ if (ObjectUtils.isEmpty(stockUninventory.getLockedQuantity())) {
+ stockUninventory.setLockedQuantity(stockInventoryDto.getLockedQuantity());
+ }else {
+ stockUninventory.setLockedQuantity(stockUninventory.getLockedQuantity().add(stockInventoryDto.getLockedQuantity()));
+ }
+ return this.updateById(stockUninventory);
+ }
+
+ @Override
+ public Boolean thawStock(StockInventoryDto stockInventoryDto) {
+ StockUninventory stockUninventory = stockUninventoryMapper.selectById(stockInventoryDto.getId());
+ if (stockUninventory.getLockedQuantity().compareTo(stockInventoryDto.getLockedQuantity())<0) {
+ throw new RuntimeException("瑙e喕鏁伴噺涓嶈兘瓒呰繃鍐荤粨鏁伴噺");
+ }
+ stockUninventory.setLockedQuantity(stockUninventory.getLockedQuantity().subtract(stockInventoryDto.getLockedQuantity()));
+ return this.updateById(stockUninventory);
+ }
+
+ //瑙勫垯鐢熸垚锛�20260424-浜у搧缂栧彿-001
+ private String generateAutoBatchNo(Long productModelId) {
+ if (productModelId == null) {
+ throw new ServiceException("浜у搧瑙勬牸ID涓嶈兘涓虹┖");
+ }
+ ProductModel productModel = productModelMapper.selectById(productModelId);
+ if (productModel == null) {
+ throw new ServiceException("浜у搧瑙勬牸涓嶅瓨鍦紝ID=" + productModelId);
+ }
+ String productCode = StringUtils.trim(productModel.getProductCode());
+ if (StringUtils.isEmpty(productCode)) {
+ throw new ServiceException("浜у搧瑙勬牸鏈淮鎶や骇鍝佺紪鐮侊紝ID=" + productModelId);
+ }
+
+ String dateText = LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE);
+ String prefix = dateText + "-" + productCode + "-";
+ int maxSequence = resolveMaxSequence(prefix);
+ int sequence = maxSequence + 1;
+ while (sequence < 1_000_000) {
+ String batchNo = prefix + String.format("%03d", sequence);
+ if (!isBatchNoExists(batchNo)) {
+ return batchNo;
+ }
+ sequence++;
+ }
+ throw new ServiceException("鎵瑰彿搴忓彿瓒呭嚭鑼冨洿锛岃妫�鏌ユ壒鍙锋暟鎹�");
+ }
+
+ private int resolveMaxSequence(String prefix) {
+ int maxSequence = 0;
+ List<StockInventory> stockInventoryList = stockInventoryMapper.selectList(
+ Wrappers.<StockInventory>lambdaQuery()
+ .select(StockInventory::getBatchNo)
+ .likeRight(StockInventory::getBatchNo, prefix));
+ for (StockInventory stockInventory : stockInventoryList) {
+ maxSequence = Math.max(maxSequence, parseSequence(stockInventory.getBatchNo(), prefix));
+ }
+
+ List<StockInRecord> stockInRecordList = stockInRecordService.list(
+ Wrappers.<StockInRecord>lambdaQuery()
+ .select(StockInRecord::getBatchNo)
+ .likeRight(StockInRecord::getBatchNo, prefix));
+ for (StockInRecord stockInRecord : stockInRecordList) {
+ maxSequence = Math.max(maxSequence, parseSequence(stockInRecord.getBatchNo(), prefix));
+ }
+ return maxSequence;
+ }
+
+ private int parseSequence(String batchNo, String prefix) {
+ if (StringUtils.isEmpty(batchNo) || StringUtils.isEmpty(prefix) || !batchNo.startsWith(prefix)) {
+ return 0;
+ }
+ String sequenceText = batchNo.substring(prefix.length());
+ if (StringUtils.isEmpty(sequenceText) || !sequenceText.matches("\\d+")) {
+ return 0;
+ }
+ try {
+ return Integer.parseInt(sequenceText);
+ } catch (NumberFormatException ignored) {
+ return 0;
+ }
+ }
+
+ private boolean isBatchNoExists(String batchNo) {
+ if (StringUtils.isEmpty(batchNo)) {
+ return false;
+ }
+ Long inventoryCount = stockInventoryMapper.selectCount(
+ Wrappers.<StockInventory>lambdaQuery().eq(StockInventory::getBatchNo, batchNo));
+ if (inventoryCount != null && inventoryCount > 0) {
+ return true;
+ }
+ return stockInRecordService.count(
+ Wrappers.<StockInRecord>lambdaQuery().eq(StockInRecord::getBatchNo, batchNo)) > 0;
+ }
}
--
Gitblit v1.9.3