From 1d915922d8197aa5d5dc3e40e3088d983dd6e141 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期五, 13 三月 2026 17:57:59 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_New_kthg' into dev_New_kthg
---
src/main/java/com/ruoyi/consumables/service/impl/ConsumablesInventoryServiceImpl.java | 227 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 227 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ruoyi/consumables/service/impl/ConsumablesInventoryServiceImpl.java b/src/main/java/com/ruoyi/consumables/service/impl/ConsumablesInventoryServiceImpl.java
new file mode 100644
index 0000000..6f30282
--- /dev/null
+++ b/src/main/java/com/ruoyi/consumables/service/impl/ConsumablesInventoryServiceImpl.java
@@ -0,0 +1,227 @@
+package com.ruoyi.consumables.service.impl;
+
+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.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.consumables.dto.ConsumablesInRecordDto;
+import com.ruoyi.consumables.dto.ConsumablesInventoryDto;
+import com.ruoyi.consumables.dto.ConsumablesOutRecordDto;
+import com.ruoyi.consumables.execl.ConsumablesInventoryExportData;
+import com.ruoyi.consumables.mapper.ConsumablesInventoryMapper;
+import com.ruoyi.consumables.pojo.ConsumablesInventory;
+import com.ruoyi.consumables.service.ConsumablesInRecordService;
+import com.ruoyi.consumables.service.ConsumablesInventoryService;
+import com.ruoyi.consumables.service.ConsumablesOutRecordService;
+import com.ruoyi.framework.web.domain.R;
+import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
+import com.ruoyi.sales.pojo.SalesLedgerProduct;
+import com.ruoyi.stock.word.WeighbridgeDocGenerator;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <p>
+ * 搴撳瓨琛� 鏈嶅姟瀹炵幇绫�
+ * </p>
+ *
+ * @author 鑺杞欢锛堟睙鑻忥級鏈夐檺鍏徃
+ * @since 2026-01-21 04:16:36
+ */
+@Service
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
+public class ConsumablesInventoryServiceImpl extends ServiceImpl<ConsumablesInventoryMapper, ConsumablesInventory> implements ConsumablesInventoryService {
+
+ private final ConsumablesInventoryMapper ConsumablesInventoryMapper;
+ private final ConsumablesInRecordService ConsumablesInRecordService;
+ private final ConsumablesOutRecordService ConsumablesOutRecordService;
+ private final SalesLedgerProductMapper salesLedgerProductMapper;
+
+ @Override
+ public IPage<ConsumablesInventoryDto> pageConsumablesInventory(Page page, ConsumablesInventoryDto ConsumablesInventoryDto) {
+ return ConsumablesInventoryMapper.pageConsumablesInventory(page, ConsumablesInventoryDto);
+ }
+
+ //鍏ュ簱璋冪敤
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public Boolean addConsumablesInventory(ConsumablesInventoryDto consumablesInventoryDto) {
+ //鏂板鍏ュ簱璁板綍鍐嶆坊鍔犲簱瀛�
+ ConsumablesInRecordDto consumablesInRecordDto = new ConsumablesInRecordDto();
+ consumablesInRecordDto.setRecordId(consumablesInventoryDto.getRecordId());
+ consumablesInRecordDto.setRecordType(consumablesInventoryDto.getRecordType());
+ consumablesInRecordDto.setConsumablesInNum(consumablesInventoryDto.getNetWeight());
+ consumablesInRecordDto.setWeighingDate(consumablesInventoryDto.getWeighingDate());
+ consumablesInRecordDto.setNetWeight(consumablesInventoryDto.getNetWeight());
+ consumablesInRecordDto.setGrossWeight(consumablesInventoryDto.getGrossWeight());
+ consumablesInRecordDto.setTareWeight(consumablesInventoryDto.getTareWeight());
+ consumablesInRecordDto.setLicensePlateNo(consumablesInventoryDto.getLicensePlateNo());
+ consumablesInRecordDto.setWeighingOperator(consumablesInventoryDto.getWeighingOperator());
+ consumablesInRecordDto.setProductModelId(consumablesInventoryDto.getProductModelId());
+ consumablesInRecordDto.setProductId(consumablesInventoryDto.getProductId());
+ consumablesInRecordDto.setType("0");
+ ConsumablesInRecordService.add(consumablesInRecordDto);
+ //鍐嶈繘琛屾柊澧炲簱瀛樻暟閲忓簱瀛�
+ //鍏堟煡璇㈠簱瀛樿〃涓殑浜у搧鏄惁瀛樺湪锛屼笉瀛樺湪鏂板锛屽瓨鍦ㄦ洿鏂�
+ ConsumablesInventory oldConsumablesInventory = ConsumablesInventoryMapper.selectOne(new QueryWrapper<ConsumablesInventory>().lambda().eq(ConsumablesInventory::getProductModelId, consumablesInventoryDto.getProductModelId()));
+ if (ObjectUtils.isEmpty(oldConsumablesInventory)) {
+ ConsumablesInventory newConsumablesInventory = new ConsumablesInventory();
+ newConsumablesInventory.setProductModelId(consumablesInventoryDto.getProductModelId());
+ newConsumablesInventory.setQualitity(consumablesInventoryDto.getNetWeight());
+ newConsumablesInventory.setVersion(1);
+ newConsumablesInventory.setRemark(consumablesInventoryDto.getRemark());
+ newConsumablesInventory.setLockedQuantity(consumablesInventoryDto.getLockedQuantity());
+ newConsumablesInventory.setWarnNum(consumablesInventoryDto.getWarnNum());
+ ConsumablesInventoryMapper.insert(newConsumablesInventory);
+ } else {
+ consumablesInventoryDto.setQualitity(consumablesInventoryDto.getNetWeight());
+ ConsumablesInventoryMapper.updateAddConsumablesInventory(consumablesInventoryDto);
+ }
+ return true;
+ }
+
+ //鍑哄簱璋冪敤
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public Boolean subtractConsumablesInventory(ConsumablesInventoryDto consumablesInventoryDto) {
+ // 鏂板鍑哄簱璁板綍
+ ConsumablesOutRecordDto consumablesOutRecordDto = new ConsumablesOutRecordDto();
+ consumablesOutRecordDto.setRecordId(consumablesInventoryDto.getRecordId());
+ consumablesOutRecordDto.setRecordType(consumablesInventoryDto.getRecordType());
+ consumablesOutRecordDto.setWeighingDate(consumablesInventoryDto.getWeighingDate());
+ consumablesOutRecordDto.setConsumablesOutNum(consumablesInventoryDto.getNetWeight());
+ consumablesOutRecordDto.setNetWeight(consumablesInventoryDto.getNetWeight());
+ consumablesOutRecordDto.setGrossWeight(consumablesInventoryDto.getGrossWeight());
+ consumablesOutRecordDto.setTareWeight(consumablesInventoryDto.getTareWeight());
+ consumablesOutRecordDto.setWeighingOperator(consumablesInventoryDto.getWeighingOperator());
+ consumablesOutRecordDto.setProductModelId(consumablesInventoryDto.getProductModelId());
+ consumablesOutRecordDto.setLicensePlateNo(consumablesInventoryDto.getLicensePlateNo());
+ consumablesOutRecordDto.setProductId(consumablesInventoryDto.getProductId());
+ consumablesOutRecordDto.setType("0");
+ ConsumablesOutRecordService.add(consumablesOutRecordDto);
+ ConsumablesInventory oldConsumablesInventory = ConsumablesInventoryMapper.selectOne(new QueryWrapper<ConsumablesInventory>().lambda().eq(ConsumablesInventory::getProductModelId, consumablesInventoryDto.getProductModelId()));
+ if (ObjectUtils.isEmpty(oldConsumablesInventory)) {
+ throw new RuntimeException("浜у搧搴撳瓨涓嶅瓨鍦�");
+ }
+ BigDecimal lockedQty = oldConsumablesInventory.getLockedQuantity();
+ if (lockedQty == null) {
+ lockedQty = BigDecimal.ZERO;
+ }
+ if (consumablesInventoryDto.getQualitity().compareTo(oldConsumablesInventory.getQualitity().subtract(lockedQty)) > 0) {
+ throw new RuntimeException("搴撳瓨涓嶈冻鏃犳硶鍑哄簱");
+ }
+
+ ConsumablesInventoryMapper.updateSubtractConsumablesInventory(consumablesInventoryDto);
+ return true;
+ }
+
+ @Override
+ public R importConsumablesInventory(MultipartFile file) {
+ try {
+ // 鏌ヨ鎵�鏈夌殑浜у搧
+ List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectProduct();
+
+ ExcelUtil<ConsumablesInventoryExportData> util = new ExcelUtil<ConsumablesInventoryExportData>(ConsumablesInventoryExportData.class);
+ List<ConsumablesInventoryExportData> list = util.importExcel(file.getInputStream());
+
+ // 璁板綍鏈壘鍒板尮閰嶉」鐨勬暟鎹�
+ List<String> unmatchedRecords = new ArrayList<>();
+
+ list.forEach(dto -> {
+ boolean matched = false;
+ for (SalesLedgerProduct item : salesLedgerProducts) {
+ if (item.getProductCategory().equals(dto.getProductName()) &&
+ item.getSpecificationModel().equals(dto.getModel())) {
+ ConsumablesInventoryDto ConsumablesInventoryDto = new ConsumablesInventoryDto();
+ ConsumablesInventoryDto.setRecordId(0L);
+ ConsumablesInventoryDto.setRecordType(StockInQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_IN.getCode());
+ ConsumablesInventoryDto.setQualitity(dto.getQualitity());
+ ConsumablesInventoryDto.setRemark(dto.getRemark());
+ ConsumablesInventoryDto.setWarnNum(dto.getWarnNum());
+ if (ObjectUtils.isNotEmpty(dto.getLockedQuantity()) && dto.getLockedQuantity().compareTo(dto.getQualitity()) > 0) {
+ throw new RuntimeException("鍐荤粨鏁伴噺涓嶈兘瓒呰繃鏈瀵煎叆鐨勫簱瀛樻暟閲�");
+ }
+ ConsumablesInventoryDto.setLockedQuantity(dto.getLockedQuantity());
+ ConsumablesInventoryDto.setProductModelId(item.getProductModelId());
+ this.addConsumablesInventory(ConsumablesInventoryDto);
+ matched = true;
+ break; // 鎵惧埌鍖归厤椤瑰悗璺冲嚭寰幆
+ }
+ }
+ if (!matched) {
+ // 璁板綍鏈尮閰嶇殑鏁版嵁
+ String unmatchedInfo = String.format("浜у搧鍚嶇О锛�%s锛岃鏍煎瀷鍙凤細%s",
+ dto.getProductName(), dto.getModel());
+ unmatchedRecords.add(unmatchedInfo);
+ }
+ });
+ // 鏋勫缓杩斿洖淇℃伅
+ StringBuilder message = new StringBuilder();
+ if (!unmatchedRecords.isEmpty()) {
+ message.append("浠ヤ笅浜у搧鏈壘鍒板尮閰嶉」锛歕n");
+ for (String record : unmatchedRecords) {
+ message.append(record).append("\n");
+ }
+ throw new RuntimeException(message.toString());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return R.fail("瀵煎叆澶辫触锛�" + e.getMessage());
+ }
+ return R.ok("瀵煎叆鎴愬姛");
+ }
+
+
+ @Override
+ public void exportConsumablesInventory(HttpServletResponse response, ConsumablesInventoryDto ConsumablesInventoryDto) {
+
+ List<ConsumablesInventoryExportData> list = ConsumablesInventoryMapper.listConsumablesInventoryExportData(ConsumablesInventoryDto);
+ ExcelUtil<ConsumablesInventoryExportData> util = new ExcelUtil<>(ConsumablesInventoryExportData.class);
+ util.exportExcel(response, list, "搴撳瓨淇℃伅");
+ }
+
+ @Override
+ public IPage<ConsumablesInRecordDto> consumablesInventoryPage(ConsumablesInventoryDto consumablesInventoryDto, Page page) {
+ return ConsumablesInventoryMapper.ConsumablesInventoryPage(consumablesInventoryDto, page);
+ }
+
+ @Override
+ public IPage<ConsumablesInventoryDto> consumablesInAndOutRecord(ConsumablesInventoryDto consumablesInventoryDto, Page page) {
+ return ConsumablesInventoryMapper.ConsumablesInAndOutRecord(consumablesInventoryDto, page);
+ }
+
+ @Override
+ public Boolean frozenConsumables(ConsumablesInventoryDto ConsumablesInventoryDto) {
+ ConsumablesInventory ConsumablesInventory = ConsumablesInventoryMapper.selectById(ConsumablesInventoryDto.getId());
+ if (ConsumablesInventory.getQualitity().compareTo(ConsumablesInventoryDto.getLockedQuantity()) < 0) {
+ throw new RuntimeException("鍐荤粨鏁伴噺涓嶈兘瓒呰繃搴撳瓨鏁伴噺");
+ }
+ if (ObjectUtils.isEmpty(ConsumablesInventory.getLockedQuantity())) {
+ ConsumablesInventory.setLockedQuantity(ConsumablesInventoryDto.getLockedQuantity());
+ } else {
+ ConsumablesInventory.setLockedQuantity(ConsumablesInventory.getLockedQuantity().add(ConsumablesInventoryDto.getLockedQuantity()));
+ }
+ return this.updateById(ConsumablesInventory);
+ }
+
+ @Override
+ public Boolean thawConsumables(ConsumablesInventoryDto ConsumablesInventoryDto) {
+ ConsumablesInventory ConsumablesInventory = ConsumablesInventoryMapper.selectById(ConsumablesInventoryDto.getId());
+ if (ConsumablesInventory.getLockedQuantity().compareTo(ConsumablesInventoryDto.getLockedQuantity()) < 0) {
+ throw new RuntimeException("瑙e喕鏁伴噺涓嶈兘瓒呰繃鍐荤粨鏁伴噺");
+ }
+ ConsumablesInventory.setLockedQuantity(ConsumablesInventory.getLockedQuantity().subtract(ConsumablesInventoryDto.getLockedQuantity()));
+ return this.updateById(ConsumablesInventory);
+ }
+}
--
Gitblit v1.9.3