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

diff --git a/src/main/java/com/ruoyi/consumables/service/impl/ConsumablesInRecordServiceImpl.java b/src/main/java/com/ruoyi/consumables/service/impl/ConsumablesInRecordServiceImpl.java
new file mode 100644
index 0000000..a5f3d21
--- /dev/null
+++ b/src/main/java/com/ruoyi/consumables/service/impl/ConsumablesInRecordServiceImpl.java
@@ -0,0 +1,113 @@
+package com.ruoyi.consumables.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+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.StockInUnQualifiedRecordTypeEnum;
+import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum;
+import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.common.utils.EnumUtil;
+import com.ruoyi.common.utils.OrderUtils;
+import com.ruoyi.common.utils.bean.BeanUtils;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.consumables.dto.ConsumablesInRecordDto;
+import com.ruoyi.consumables.dto.ConsumablesInventoryDto;
+import com.ruoyi.consumables.dto.ConsumablesUnInventoryDto;
+import com.ruoyi.consumables.execl.ConsumablesInRecordExportData;
+import com.ruoyi.consumables.mapper.ConsumablesInRecordMapper;
+import com.ruoyi.consumables.mapper.ConsumablesInventoryMapper;
+import com.ruoyi.consumables.mapper.ConsumablesUnInventoryMapper;
+import com.ruoyi.consumables.pojo.ConsumablesInRecord;
+import com.ruoyi.consumables.pojo.ConsumablesInventory;
+import com.ruoyi.consumables.pojo.ConsumablesUnInventory;
+import com.ruoyi.consumables.service.ConsumablesInRecordService;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+@Service
+@AllArgsConstructor
+public class ConsumablesInRecordServiceImpl extends ServiceImpl<ConsumablesInRecordMapper, ConsumablesInRecord> implements ConsumablesInRecordService {
+
+    private ConsumablesInRecordMapper consumablesInRecordMapper;
+    private ConsumablesInventoryMapper consumablesInventoryMapper;
+    private ConsumablesUnInventoryMapper consumablesUnInventoryMapper;
+
+    @Override
+    public IPage<ConsumablesInRecordDto> listPage(Page page, ConsumablesInRecordDto consumablesInRecordDto) {
+        return consumablesInRecordMapper.listPage(page, consumablesInRecordDto);
+    }
+
+    // 鏂板鍏ュ簱
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int add(ConsumablesInRecordDto consumablesInRecordDto) {
+        String no = OrderUtils.countTodayByCreateTime(consumablesInRecordMapper, "RK");
+        consumablesInRecordDto.setInboundBatches(no);
+        ConsumablesInRecord consumablesInRecord = new ConsumablesInRecord();
+        BeanUtils.copyProperties(consumablesInRecordDto, consumablesInRecord);
+        return consumablesInRecordMapper.insert(consumablesInRecord);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int update(Long id, ConsumablesInRecordDto consumablesInRecordDto) {
+        // 鍒ゆ柇瀵硅薄鏄惁瀛樺湪
+        ConsumablesInRecord consumablesInRecord = consumablesInRecordMapper.selectById(id);
+        if (consumablesInRecord == null){
+            throw new BaseException("璇ュ叆搴撹褰曚笉瀛樺湪,鏃犳硶鏇存柊!!!");
+        }
+
+        String[] ignoreProperties = {"id", "inbound_batches"};//鎺掗櫎id灞炴��
+        BeanUtils.copyProperties(consumablesInRecordDto, consumablesInRecord, ignoreProperties);
+        return consumablesInRecordMapper.updateById(consumablesInRecord);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int batchDelete(List<Long> ids) {
+        for (Long id : ids) {
+            ConsumablesInRecord consumablesInRecord = consumablesInRecordMapper.selectById(id);
+            if (consumablesInRecord.getType().equals("0")) {
+                ConsumablesInventory consumablesInventory = consumablesInventoryMapper.selectOne(new LambdaQueryWrapper<ConsumablesInventory>().eq(ConsumablesInventory::getProductModelId, consumablesInRecord.getProductModelId()));
+                if (consumablesInventory == null) {
+                    throw new BaseException("搴撳瓨璁板綍涓病鏈夊搴旂殑浜у搧,鏃犳硶鍒犻櫎!!!");
+                }else {
+                    ConsumablesInventoryDto consumablesInRecordDto = new ConsumablesInventoryDto();
+                    consumablesInRecordDto.setProductModelId(consumablesInventory.getProductModelId());
+                    consumablesInRecordDto.setQualitity(consumablesInRecord.getConsumablesInNum());
+                    consumablesInventoryMapper.updateSubtractConsumablesInventory(consumablesInRecordDto);
+                }
+            }else if (consumablesInRecord.getType().equals("1")) {
+                ConsumablesUnInventory consumablesUnInventory = consumablesUnInventoryMapper.selectOne(new LambdaQueryWrapper<ConsumablesUnInventory>().eq(ConsumablesUnInventory::getProductModelId, consumablesInRecord.getProductModelId()));
+                if (consumablesUnInventory == null) {
+                    throw new BaseException("搴撳瓨璁板綍涓病鏈夊搴旂殑浜у搧,鏃犳硶鍒犻櫎!!!");
+                }else {
+                    ConsumablesUnInventoryDto consumablesUnInventoryDto = new ConsumablesUnInventoryDto();
+                    consumablesUnInventoryDto.setProductModelId(consumablesUnInventory.getProductModelId());
+                    consumablesUnInventoryDto.setQualitity(consumablesInRecord.getConsumablesInNum());
+                    consumablesUnInventoryMapper.updateSubtractConsumablesUnInventory(consumablesUnInventoryDto);
+                }
+            }
+        }
+        return consumablesInRecordMapper.deleteBatchIds(ids);
+    }
+
+    @Override
+    public void exportConsumablesInRecord(HttpServletResponse response, ConsumablesInRecordDto consumablesInRecordDto) {
+        List<ConsumablesInRecordExportData> list = consumablesInRecordMapper.listConsumablesInRecordExportData(consumablesInRecordDto);
+        for (ConsumablesInRecordExportData consumablesInRecordExportData : list) {
+            if (consumablesInRecordExportData.getType().equals("0")) {
+                consumablesInRecordExportData.setRecordType(EnumUtil.fromCode(StockOutQualifiedRecordTypeEnum.class, Integer.parseInt(consumablesInRecordExportData.getRecordType())).getValue());
+            }else {
+                consumablesInRecordExportData.setRecordType(EnumUtil.fromCode(StockInUnQualifiedRecordTypeEnum.class, Integer.parseInt(consumablesInRecordExportData.getRecordType())).getValue());
+            }
+        }
+        ExcelUtil<ConsumablesInRecordExportData> util = new ExcelUtil<>(ConsumablesInRecordExportData.class);
+        util.exportExcel(response,list, "鍏ュ簱璁板綍淇℃伅");
+    }
+}

--
Gitblit v1.9.3