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/ConsumablesUnInventoryServiceImpl.java |  125 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 125 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/ruoyi/consumables/service/impl/ConsumablesUnInventoryServiceImpl.java b/src/main/java/com/ruoyi/consumables/service/impl/ConsumablesUnInventoryServiceImpl.java
new file mode 100644
index 0000000..a504657
--- /dev/null
+++ b/src/main/java/com/ruoyi/consumables/service/impl/ConsumablesUnInventoryServiceImpl.java
@@ -0,0 +1,125 @@
+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.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.dto.ConsumablesUnInventoryDto;
+import com.ruoyi.consumables.execl.ConsumablesUnInventoryExportData;
+import com.ruoyi.consumables.mapper.ConsumablesUnInventoryMapper;
+import com.ruoyi.consumables.pojo.ConsumablesUnInventory;
+import com.ruoyi.consumables.service.ConsumablesInRecordService;
+import com.ruoyi.consumables.service.ConsumablesOutRecordService;
+import com.ruoyi.consumables.service.ConsumablesUnInventoryService;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+/**
+ * <p>
+ * 涓嶅悎鏍煎簱瀛樿〃 鏈嶅姟瀹炵幇绫�
+ * </p>
+ *
+ * @author 鑺杞欢锛堟睙鑻忥級鏈夐檺鍏徃
+ * @since 2026-01-22 10:17:45
+ */
+@Service
+@AllArgsConstructor
+public class ConsumablesUnInventoryServiceImpl extends ServiceImpl<ConsumablesUnInventoryMapper, ConsumablesUnInventory> implements ConsumablesUnInventoryService {
+
+    private ConsumablesUnInventoryMapper ConsumablesUnInventoryMapper;
+    private ConsumablesOutRecordService ConsumablesOutRecordService;
+    private ConsumablesInRecordService ConsumablesInRecordService;
+
+    @Override
+    public IPage<ConsumablesUnInventoryDto> pageConsumablesUnInventory(Page page, ConsumablesUnInventoryDto ConsumablesUnInventoryDto) {
+        return ConsumablesUnInventoryMapper.pageConsumablesUnInventory(page, ConsumablesUnInventoryDto);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Integer addConsumablesUnInventory(ConsumablesUnInventoryDto ConsumablesUnInventoryDto) {
+        //鏂板鍏ュ簱璁板綍鍐嶆坊鍔犲簱瀛�
+        ConsumablesInRecordDto ConsumablesInRecordDto = new ConsumablesInRecordDto();
+        ConsumablesInRecordDto.setRecordId(ConsumablesUnInventoryDto.getRecordId());
+        ConsumablesInRecordDto.setRecordType(ConsumablesUnInventoryDto.getRecordType());
+        ConsumablesInRecordDto.setConsumablesInNum(ConsumablesUnInventoryDto.getQualitity());
+        ConsumablesInRecordDto.setProductModelId(ConsumablesUnInventoryDto.getProductModelId());
+        ConsumablesInRecordDto.setType("1");
+        ConsumablesInRecordService.add(ConsumablesInRecordDto);
+        //鍐嶈繘琛屾柊澧炲簱瀛樻暟閲忓簱瀛�
+        //鍏堟煡璇㈠簱瀛樿〃涓殑浜у搧鏄惁瀛樺湪锛屼笉瀛樺湪鏂板锛屽瓨鍦ㄦ洿鏂�
+        ConsumablesUnInventory oldConsumablesUnInventory = ConsumablesUnInventoryMapper.selectOne(new QueryWrapper<ConsumablesUnInventory>().lambda().eq(ConsumablesUnInventory::getProductModelId, ConsumablesUnInventoryDto.getProductModelId()));
+        if (ObjectUtils.isEmpty(oldConsumablesUnInventory)) {
+            ConsumablesUnInventory newConsumablesUnInventory = new ConsumablesUnInventory();
+            newConsumablesUnInventory.setProductModelId(ConsumablesUnInventoryDto.getProductModelId());
+            newConsumablesUnInventory.setQualitity(ConsumablesUnInventoryDto.getQualitity());
+            newConsumablesUnInventory.setVersion(1);
+            newConsumablesUnInventory.setRemark(ConsumablesUnInventoryDto.getRemark());
+            ConsumablesUnInventoryMapper.insert(newConsumablesUnInventory);
+        }else {
+            ConsumablesUnInventoryMapper.updateAddConsumablesUnInventory(ConsumablesUnInventoryDto);
+        }
+        return 1;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Integer subtractConsumablesUnInventory(ConsumablesUnInventoryDto ConsumablesUnInventoryDto) {
+
+        //  鏂板鍑哄簱璁板綍
+        ConsumablesOutRecordDto ConsumablesOutRecordDto = new ConsumablesOutRecordDto();
+        ConsumablesOutRecordDto.setRecordId(ConsumablesUnInventoryDto.getRecordId());
+        ConsumablesOutRecordDto.setRecordType(ConsumablesUnInventoryDto.getRecordType());
+        ConsumablesOutRecordDto.setConsumablesOutNum(ConsumablesUnInventoryDto.getQualitity());
+        ConsumablesOutRecordDto.setProductModelId(ConsumablesUnInventoryDto.getProductModelId());
+        ConsumablesOutRecordDto.setType("1");
+        ConsumablesOutRecordService.add(ConsumablesOutRecordDto);
+        ConsumablesUnInventory oldConsumablesInventory = ConsumablesUnInventoryMapper.selectOne(new QueryWrapper<ConsumablesUnInventory>().lambda().eq(ConsumablesUnInventory::getProductModelId, ConsumablesUnInventoryDto.getProductModelId()));
+        if (ObjectUtils.isEmpty(oldConsumablesInventory)) {
+            throw new RuntimeException("浜у搧搴撳瓨涓嶅瓨鍦�");
+        }else {
+            ConsumablesUnInventoryMapper.updateSubtractConsumablesUnInventory(ConsumablesUnInventoryDto);
+        }
+        return 1;
+    }
+
+    @Override
+    public void exportConsumablesUnInventory(HttpServletResponse response, ConsumablesUnInventoryDto ConsumablesUnInventoryDto) {
+        List<ConsumablesUnInventoryExportData> list = ConsumablesUnInventoryMapper.listConsumablesInventoryExportData(ConsumablesUnInventoryDto);
+        ExcelUtil<ConsumablesUnInventoryExportData> util = new ExcelUtil<>(ConsumablesUnInventoryExportData.class);
+        util.exportExcel(response,list, "涓嶅悎鏍煎簱瀛樹俊鎭�");
+    }
+
+    @Override
+    public Boolean frozenConsumables(ConsumablesInventoryDto ConsumablesInventoryDto) {
+        ConsumablesUnInventory ConsumablesUnInventory = ConsumablesUnInventoryMapper.selectById(ConsumablesInventoryDto.getId());
+        if (ConsumablesUnInventory.getQualitity().compareTo(ConsumablesInventoryDto.getLockedQuantity())<0) {
+            throw new RuntimeException("鍐荤粨鏁伴噺涓嶈兘瓒呰繃搴撳瓨鏁伴噺");
+        }
+        if (ObjectUtils.isEmpty(ConsumablesUnInventory.getLockedQuantity())) {
+            ConsumablesUnInventory.setLockedQuantity(ConsumablesInventoryDto.getLockedQuantity());
+        }else {
+            ConsumablesUnInventory.setLockedQuantity(ConsumablesUnInventory.getLockedQuantity().add(ConsumablesInventoryDto.getLockedQuantity()));
+        }
+        return this.updateById(ConsumablesUnInventory);
+    }
+
+    @Override
+    public Boolean thawConsumables(ConsumablesInventoryDto ConsumablesInventoryDto) {
+        ConsumablesUnInventory ConsumablesUnInventory = ConsumablesUnInventoryMapper.selectById(ConsumablesInventoryDto.getId());
+        if (ConsumablesUnInventory.getLockedQuantity().compareTo(ConsumablesInventoryDto.getLockedQuantity())<0) {
+            throw new RuntimeException("瑙e喕鏁伴噺涓嶈兘瓒呰繃鍐荤粨鏁伴噺");
+        }
+        ConsumablesUnInventory.setLockedQuantity(ConsumablesUnInventory.getLockedQuantity().subtract(ConsumablesInventoryDto.getLockedQuantity()));
+        return this.updateById(ConsumablesUnInventory);
+    }
+}

--
Gitblit v1.9.3