From 7bf754a7835d06f26240c4ca15bc5f83650de377 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 21 九月 2026 20:52:25 +0800
Subject: [PATCH] docs(api): 更新信托基金与代储台账及油品出库相关接口文档
---
src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java | 319 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 314 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java b/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
index ef5e170..158ee93 100644
--- a/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
+++ b/src/main/java/com/ruoyi/stock/service/impl/StockInRecordServiceImpl.java
@@ -4,18 +4,32 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.enums.ReviewStatusEnum;
+import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum;
import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum;
-import com.ruoyi.common.enums.StockInUnQualifiedRecordTypeEnum;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.EnumUtil;
import com.ruoyi.common.utils.OrderUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
+
+import java.time.LocalDateTime;
import com.ruoyi.stock.dto.StockInRecordDto;
import com.ruoyi.stock.dto.StockInventoryDto;
import com.ruoyi.stock.dto.StockUninventoryDto;
import com.ruoyi.stock.execl.StockInRecordExportData;
+import com.ruoyi.production.mapper.ProductionOrderPickMapper;
+import com.ruoyi.production.pojo.ProductionOrderPick;
+import com.ruoyi.procurementrecord.mapper.ReturnManagementMapper;
+import com.ruoyi.procurementrecord.mapper.ReturnSaleProductMapper;
+import com.ruoyi.procurementrecord.pojo.ReturnManagement;
+import com.ruoyi.procurementrecord.pojo.ReturnSaleProduct;
+import com.ruoyi.sales.dto.SalesLedgerDto;
+import com.ruoyi.sales.mapper.SalesLedgerMapper;
+import com.ruoyi.sales.mapper.ShippingInfoMapper;
+import com.ruoyi.sales.pojo.SalesLedger;
+import com.ruoyi.sales.pojo.ShippingInfo;
import com.ruoyi.stock.mapper.StockInRecordMapper;
import com.ruoyi.stock.mapper.StockInventoryMapper;
import com.ruoyi.stock.mapper.StockUninventoryMapper;
@@ -23,11 +37,13 @@
import com.ruoyi.stock.pojo.StockInventory;
import com.ruoyi.stock.pojo.StockUninventory;
import com.ruoyi.stock.service.StockInRecordService;
+import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
-import jakarta.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
import java.util.List;
@Service
@@ -37,6 +53,21 @@
private StockInRecordMapper stockInRecordMapper;
private StockInventoryMapper stockInventoryMapper;
private StockUninventoryMapper stockUninventoryMapper;
+ private ProductionOrderPickMapper productionOrderPickMapper;
+ private ReturnSaleProductMapper returnSaleProductMapper;
+ private ReturnManagementMapper returnManagementMapper;
+ private ShippingInfoMapper shippingInfoMapper;
+ private SalesLedgerMapper salesLedgerMapper;
+
+ /**
+ * 鍏ュ簱绫诲埆锛氫唬鍌ㄥ叆搴撱�傚彧鏈夎繖涓被鍒姹傜粦瀹氶攢鍞鍗�
+ */
+ private static final String INBOUND_CATEGORY_DEPOSIT = "浠e偍鍏ュ簱";
+
+ /**
+ * 閿�鍞彴璐︾殑閿�鍞被鍨嬶細浠e偍銆備唬鍌ㄥ叆搴撳彧鑳界粦杩欎釜绫诲瀷鐨勫彴璐�
+ */
+ private static final String LEDGER_TYPE_DEPOSIT = "浠e偍";
@Override
public IPage<StockInRecordDto> listPage(Page page, StockInRecordDto stockInRecordDto) {
@@ -47,11 +78,49 @@
@Override
@Transactional(rollbackFor = Exception.class)
public int add(StockInRecordDto stockInRecordDto) {
- String no = OrderUtils.countTodayByCreateTime(stockInRecordMapper, "RK","inbound_batches");
+ resolveDepositSalesLedger(stockInRecordDto);
+ LocalDateTime createTime = stockInRecordDto.getCreateTime();
+ if (createTime == null) {
+ createTime = LocalDateTime.now();
+ }
+ String no = OrderUtils.countTodayByCreateTime(stockInRecordMapper, "RK","inbound_batches", createTime);
stockInRecordDto.setInboundBatches(no);
+ stockInRecordDto.setCreateTime(createTime);
StockInRecord stockInRecord = new StockInRecord();
BeanUtils.copyProperties(stockInRecordDto, stockInRecord);
return stockInRecordMapper.insert(stockInRecord);
+ }
+
+ /**
+ * 浠e偍鍏ュ簱锛坕nboundCategory=浠e偍鍏ュ簱锛夊繀椤荤粦瀹氫竴寮犮�屼唬鍌ㄣ�嶇被鍨嬬殑閿�鍞彴璐︼紙閿�鍞鍗曪級銆�
+ * 鍙仛鏍¢獙涓庤惤搴擄紝**涓嶇敤鍙拌处瑕嗙洊**鍏ュ簱鍗曚笂鐨勫鎴�/娌瑰簱/鍌ㄧ綈 鈥斺�� 閭e嚑椤逛粛浠ョ幇鍦哄~鍐欎负鍑嗐��
+ * 闈炰唬鍌ㄥ叆搴撲笉缁戝彴璐︼紝鍗充娇鍓嶇浼犱簡涔熺疆绌猴紝閬垮厤钀戒笅鏃犳剰涔夌殑鍏宠仈銆�
+ */
+ private void resolveDepositSalesLedger(StockInRecordDto stockInRecordDto) {
+ if (!INBOUND_CATEGORY_DEPOSIT.equals(stockInRecordDto.getInboundCategory())) {
+ stockInRecordDto.setSalesLedgerId(null);
+ return;
+ }
+ Long salesLedgerId = stockInRecordDto.getSalesLedgerId();
+ if (salesLedgerId == null) {
+ throw new BaseException("浠e偍鍏ュ簱蹇呴』缁戝畾閿�鍞鍗�");
+ }
+ SalesLedger salesLedger = salesLedgerMapper.selectById(salesLedgerId);
+ if (salesLedger == null) {
+ throw new BaseException("鎵�閫夐攢鍞鍗曚笉瀛樺湪,閿�鍞鍗昳d:" + salesLedgerId);
+ }
+ if (!LEDGER_TYPE_DEPOSIT.equals(salesLedger.getLedgerType())) {
+ throw new BaseException("浠e偍鍏ュ簱鍙兘缁戝畾浠e偍绫诲瀷鐨勯攢鍞鍗�,閿�鍞悎鍚屽彿:" + salesLedger.getSalesContractNo());
+ }
+ }
+
+ @Override
+ public IPage<SalesLedger> listBindableSalesLedger(Page page, SalesLedgerDto salesLedgerDto) {
+ // 璇ユ煡璇㈢敤 /*data_scope*/ 璺宠繃鏁版嵁鏉冮檺锛岃�� MP 榛樿浼氭妸 count 璇彞浼樺寲鎴愩�孲ELECT COUNT(*) FROM sales_ledger
+ // WHERE ...銆嶏紝浼樺寲鍚庢爣璁颁涪澶憋紝count 鍙嶈�岃杩藉姞鏉冮檺鏉′欢锛宼otal 浼氭瘮瀹為檯璁板綍灏戙�傚叧鎺� count 浼樺寲鍚�
+ // count 閫�鍖栨垚銆孲ELECT COUNT(*) FROM (鍘熷彞) TOTAL銆嶏紝鏍囪鍘熸牱淇濈暀
+ page.setOptimizeCountSql(false);
+ return stockInRecordMapper.bindableSalesLedgerPage(page, salesLedgerDto);
}
@Override
@@ -118,13 +187,253 @@
public void exportStockInRecord(HttpServletResponse response, StockInRecordDto stockInRecordDto) {
List<StockInRecordExportData> list = stockInRecordMapper.listStockInRecordExportData(stockInRecordDto);
for (StockInRecordExportData stockInRecordExportData : list) {
- if (stockInRecordExportData.getType().equals("0")) {
+ if (!stockInRecordExportData.getType().equals("0")) {
stockInRecordExportData.setRecordType(EnumUtil.fromCode(StockOutQualifiedRecordTypeEnum.class, Integer.parseInt(stockInRecordExportData.getRecordType())).getValue());
}else {
- stockInRecordExportData.setRecordType(EnumUtil.fromCode(StockInUnQualifiedRecordTypeEnum.class, Integer.parseInt(stockInRecordExportData.getRecordType())).getValue());
+ stockInRecordExportData.setRecordType(EnumUtil.fromCode(StockInQualifiedRecordTypeEnum.class, Integer.parseInt(stockInRecordExportData.getRecordType())).getValue());
}
}
ExcelUtil<StockInRecordExportData> util = new ExcelUtil<>(StockInRecordExportData.class);
util.exportExcel(response,list, "鍏ュ簱璁板綍淇℃伅");
}
+
+ private StockInventory getStockInventory(Long productModelId, String batchNo) {
+ LambdaQueryWrapper<StockInventory> eq = new LambdaQueryWrapper<>();
+ eq.eq(StockInventory::getProductModelId, productModelId);
+ if (StringUtils.isEmpty(batchNo)) {
+ eq.isNull(StockInventory::getBatchNo);
+ } else {
+ eq.eq(StockInventory::getBatchNo, batchNo);
+ }
+ return stockInventoryMapper.selectOne(eq);
+ }
+
+ private StockUninventory getStockUninventory(Long productModelId, String batchNo) {
+ LambdaQueryWrapper<StockUninventory> eq = new LambdaQueryWrapper<>();
+ eq.eq(StockUninventory::getProductModelId, productModelId);
+ if (StringUtils.isEmpty(batchNo)) {
+ eq.isNull(StockUninventory::getBatchNo);
+ } else {
+ eq.eq(StockUninventory::getBatchNo, batchNo);
+ }
+ return stockUninventoryMapper.selectOne(eq);
+ }
+
+ /**
+ * 鍥炴粴鐢熶骇閫�鏂欏叆搴撶殑棰嗘枡璁板綍閫�鏂欐暟閲�
+ * @param stockInRecord 鍏ュ簱璁板綍
+ */
+ private void rollbackFeedReturnQty(StockInRecord stockInRecord) {
+ ProductionOrderPick productionOrderPick = productionOrderPickMapper.selectById(stockInRecord.getRecordId());
+ if (productionOrderPick != null) {
+ BigDecimal returnQty = productionOrderPick.getReturnQty();
+ if (returnQty == null) {
+ returnQty = BigDecimal.ZERO;
+ }
+ BigDecimal newReturnQty = returnQty.subtract(stockInRecord.getStockInNum());
+ if (newReturnQty.compareTo(BigDecimal.ZERO) < 0) {
+ newReturnQty = BigDecimal.ZERO;
+ }
+ productionOrderPick.setReturnQty(newReturnQty);
+ // 閲嶆柊璁$畻瀹為檯鐢ㄩ噺
+ BigDecimal actualQty = productionOrderPick.getQuantity().add(
+ productionOrderPick.getFeedingQty() != null ? productionOrderPick.getFeedingQty() : BigDecimal.ZERO)
+ .subtract(newReturnQty);
+ productionOrderPick.setActualQty(actualQty);
+ productionOrderPick.setReturned(newReturnQty.compareTo(BigDecimal.ZERO) > 0);
+ productionOrderPickMapper.updateById(productionOrderPick);
+ }
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public int batchDeletePending(List<Long> ids) {
+ for (Long id : ids) {
+ StockInRecord stockInRecord = stockInRecordMapper.selectById(id);
+ if (stockInRecord == null) {
+ throw new BaseException("鍏ュ簱璁板綍涓嶅瓨鍦�,鏃犳硶鍒犻櫎!!!");
+ }
+ if (stockInRecord.getApprovalStatus() != null && !ReviewStatusEnum.PENDING_REVIEW.getCode().equals(stockInRecord.getApprovalStatus())) {
+ throw new BaseException("鍙湁寰呭鎵圭姸鎬佺殑璁板綍鎵嶈兘鍒犻櫎,鍏ュ簱鎵规:" + stockInRecord.getInboundBatches());
+ }
+
+ // 濡傛灉鏄敓浜ч��鏂欏叆搴擄紝鍒犻櫎鏃堕渶瑕佸洖婊氶鏂欒褰曠殑閫�鏂欐暟閲�
+ if (StockInQualifiedRecordTypeEnum.FEED_RETURN_IN.getCode().equals(stockInRecord.getRecordType())) {
+ rollbackFeedReturnQty(stockInRecord);
+ }
+ }
+ return stockInRecordMapper.deleteBatchIds(ids);
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public int batchApprove(List<Long> ids, Integer approvalStatus) {
+ if (CollectionUtils.isEmpty(ids)) {
+ throw new BaseException("璇烽�夋嫨鑷冲皯涓�鏉℃暟鎹�");
+ }
+ if (approvalStatus == null || (!ReviewStatusEnum.APPROVED.getCode().equals(approvalStatus) && !ReviewStatusEnum.REJECTED.getCode().equals(approvalStatus))) {
+ throw new BaseException("瀹℃壒鐘舵�佸�兼棤鏁�");
+ }
+ for (Long id : ids) {
+ StockInRecord stockInRecord = stockInRecordMapper.selectById(id);
+ if (stockInRecord == null) {
+ throw new BaseException("鍏ュ簱璁板綍涓嶅瓨鍦�,鏃犳硶瀹℃壒!!!");
+ }
+ if (stockInRecord.getApprovalStatus() != null && !ReviewStatusEnum.PENDING_REVIEW.getCode().equals(stockInRecord.getApprovalStatus())) {
+ throw new BaseException("鍙湁寰呭鎵圭姸鎬佺殑璁板綍鎵嶈兘瀹℃壒,鍏ュ簱鎵规:" + stockInRecord.getInboundBatches());
+ }
+ stockInRecord.setApprovalStatus(approvalStatus);
+ stockInRecordMapper.updateById(stockInRecord);
+
+ // 瀹℃壒椹冲洖鏃讹紝濡傛灉鏄敓浜ч��鏂欏叆搴擄紝闇�瑕佸洖婊氶鏂欒褰曠殑閫�鏂欐暟閲�
+ if (ReviewStatusEnum.REJECTED.getCode().equals(approvalStatus) &&
+ StockInQualifiedRecordTypeEnum.FEED_RETURN_IN.getCode().equals(stockInRecord.getRecordType())) {
+ rollbackFeedReturnQty(stockInRecord);
+ }
+
+ // 瀹℃壒閫氳繃鏃讹紝搴撳瓨澧炲姞
+ if (ReviewStatusEnum.APPROVED.getCode().equals(approvalStatus)) {
+ if ("0".equals(stockInRecord.getType())) {
+ // 鍚堟牸鍏ュ簱 -> 鍏堟煡搴撳瓨锛屽瓨鍦ㄥ垯鏇存柊锛屼笉瀛樺湪鍒欐柊澧�
+ StockInventory stockInventory = getStockInventory(stockInRecord.getProductModelId(), stockInRecord.getBatchNo());
+ StockInventoryDto stockInventoryDto = new StockInventoryDto();
+ stockInventoryDto.setProductModelId(stockInRecord.getProductModelId());
+ stockInventoryDto.setBatchNo(stockInRecord.getBatchNo());
+ stockInventoryDto.setQualitity(stockInRecord.getStockInNum());
+ stockInventoryDto.setRemark(stockInRecord.getRemark());
+ if (stockInventory == null) {
+ try {
+ stockInventoryMapper.insert(new StockInventory() {{
+ setProductModelId(stockInRecord.getProductModelId());
+ setQualitity(stockInRecord.getStockInNum());
+ setBatchNo(stockInRecord.getBatchNo());
+ setRemark(stockInRecord.getRemark());
+ setWarnNum(stockInRecord.getWarnNum());
+ setVersion(1);
+ }});
+ } catch (org.springframework.dao.DuplicateKeyException e) {
+ stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
+ }
+ } else {
+ stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
+ }
+ } else if ("1".equals(stockInRecord.getType())) {
+ // 涓嶅悎鏍煎叆搴� -> 鍏堟煡搴撳瓨锛屽瓨鍦ㄥ垯鏇存柊锛屼笉瀛樺湪鍒欐柊澧�
+ StockUninventory stockUninventory = getStockUninventory(stockInRecord.getProductModelId(), stockInRecord.getBatchNo());
+ StockUninventoryDto stockUninventoryDto = new StockUninventoryDto();
+ stockUninventoryDto.setProductModelId(stockInRecord.getProductModelId());
+ stockUninventoryDto.setBatchNo(stockInRecord.getBatchNo());
+ stockUninventoryDto.setQualitity(stockInRecord.getStockInNum());
+ stockUninventoryDto.setRemark(stockInRecord.getRemark());
+ if (stockUninventory == null) {
+ try {
+ stockUninventoryMapper.insert(new StockUninventory() {{
+ setProductModelId(stockInRecord.getProductModelId());
+ setQualitity(stockInRecord.getStockInNum());
+ setBatchNo(stockInRecord.getBatchNo());
+ setRemark(stockInRecord.getRemark());
+ setVersion(1);
+ }});
+ } catch (org.springframework.dao.DuplicateKeyException e) {
+ stockUninventoryMapper.updateAddStockUnInventory(stockUninventoryDto);
+ }
+ } else {
+ stockUninventoryMapper.updateAddStockUnInventory(stockUninventoryDto);
+ }
+ }
+ // 閿�鍞��璐у叆搴�:鎵e噺閿�鍞彴璐﹀疄闄呭悎鍚岄噾棰�(閫�璐х敓鏁�)
+ handleSalesReturnRefund(stockInRecord);
+ }
+ }
+ return ids.size();
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public int batchReAudit(List<Long> ids) {
+ if (CollectionUtils.isEmpty(ids)) {
+ throw new BaseException("璇烽�夋嫨鑷冲皯涓�鏉℃暟鎹�");
+ }
+
+ for (Long id : ids) {
+ StockInRecord stockInRecord = stockInRecordMapper.selectById(id);
+ if (stockInRecord == null) {
+ throw new BaseException("鍏ュ簱璁板綍涓嶅瓨鍦�,鏃犳硶閲嶆柊瀹℃牳!!!");
+ }
+ // 鍙湁椹冲洖鐘舵�佹墠鑳介噸鏂板鏍�
+ if (!ReviewStatusEnum.REJECTED.getCode().equals(stockInRecord.getApprovalStatus())) {
+ throw new BaseException("鍙湁椹冲洖鐘舵�佺殑璁板綍鎵嶈兘閲嶆柊瀹℃牳,鍏ュ簱鎵规:" + stockInRecord.getInboundBatches());
+ }
+
+ // 濡傛灉鏄敓浜ч��鏂欏叆搴擄紝鎭㈠閫�鏂欐暟閲忥紙鍥犱负椹冲洖鏃跺凡鎵e噺锛�
+ if (StockInQualifiedRecordTypeEnum.FEED_RETURN_IN.getCode().equals(stockInRecord.getRecordType())) {
+ ProductionOrderPick productionOrderPick = productionOrderPickMapper.selectById(stockInRecord.getRecordId());
+ if (productionOrderPick != null) {
+ BigDecimal returnQty = productionOrderPick.getReturnQty();
+ if (returnQty == null) {
+ returnQty = BigDecimal.ZERO;
+ }
+ // 閲嶆柊瀹℃牳鏃舵仮澶嶉��鏂欐暟閲�
+ BigDecimal newReturnQty = returnQty.add(stockInRecord.getStockInNum());
+ productionOrderPick.setReturnQty(newReturnQty);
+ // 閲嶆柊璁$畻瀹為檯鐢ㄩ噺
+ BigDecimal actualQty = productionOrderPick.getQuantity().add(
+ productionOrderPick.getFeedingQty() != null ? productionOrderPick.getFeedingQty() : BigDecimal.ZERO)
+ .subtract(newReturnQty);
+ productionOrderPick.setActualQty(actualQty);
+ productionOrderPick.setReturned(newReturnQty.compareTo(BigDecimal.ZERO) > 0);
+ productionOrderPickMapper.updateById(productionOrderPick);
+ }
+ }
+
+ // 灏嗙姸鎬佹敼涓哄緟瀹℃牳
+ stockInRecord.setApprovalStatus(ReviewStatusEnum.PENDING_REVIEW.getCode());
+ stockInRecordMapper.updateById(stockInRecord);
+ }
+
+ return ids.size();
+ }
+
+ /**
+ * 閿�鍞��璐у叆搴撳鎵归�氳繃鏃�,鎵e噺瀵瑰簲閿�鍞彴璐︾殑瀹為檯鍚堝悓閲戦銆�
+ * 鍏宠仈閾�:stock_in_record.record_id = return_sale_product.id
+ * 鈫� return_management.shipping_id = shipping_info.id
+ * 鈫� shipping_info.sales_ledger_id = sales_ledger.id
+ * 鍙鐞� record_type 涓� 14(鍚堟牸)鎴� 15(涓嶅悎鏍�)鐨勯攢鍞��璐у叆搴撱��
+ */
+ private void handleSalesReturnRefund(StockInRecord stockInRecord) {
+ String recordType = stockInRecord.getRecordType();
+ if (!StockInQualifiedRecordTypeEnum.RETURN_HE_IN.getCode().equals(recordType)
+ && !StockInQualifiedRecordTypeEnum.RETURN_UNSTOCK_IN.getCode().equals(recordType)) {
+ return;
+ }
+ if (stockInRecord.getRecordId() == null) {
+ return;
+ }
+ ReturnSaleProduct rsp = returnSaleProductMapper.selectById(stockInRecord.getRecordId());
+ if (rsp == null || rsp.getReturnManagementId() == null) {
+ return;
+ }
+ ReturnManagement rm = returnManagementMapper.selectById(rsp.getReturnManagementId());
+ if (rm == null || rm.getShippingId() == null) {
+ return;
+ }
+ ShippingInfo shippingInfo = shippingInfoMapper.selectById(rm.getShippingId());
+ if (shippingInfo == null || shippingInfo.getSalesLedgerId() == null) {
+ return;
+ }
+ SalesLedger salesLedger = salesLedgerMapper.selectById(shippingInfo.getSalesLedgerId());
+ if (salesLedger == null || salesLedger.getContractAmount() == null) {
+ return;
+ }
+ BigDecimal refund = rsp.getAmount() != null ? rsp.getAmount() : BigDecimal.ZERO;
+ if (refund.compareTo(BigDecimal.ZERO) == 0) {
+ return;
+ }
+ BigDecimal baseAmount = salesLedger.getNetContractAmount() != null
+ ? salesLedger.getNetContractAmount()
+ : salesLedger.getContractAmount();
+ salesLedger.setNetContractAmount(baseAmount.subtract(refund));
+ salesLedgerMapper.updateById(salesLedger);
+ }
}
--
Gitblit v1.9.3