From 263b034b4058bb7a36c709278abdc88ca1ba26c1 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期一, 30 三月 2026 18:01:25 +0800
Subject: [PATCH] feat: 生产成本导入数据入库

---
 src/main/java/com/ruoyi/production/service/impl/ProductionSettlementBatchesServiceImpl.java |   88 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 88 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionSettlementBatchesServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionSettlementBatchesServiceImpl.java
new file mode 100644
index 0000000..7a6bcb2
--- /dev/null
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionSettlementBatchesServiceImpl.java
@@ -0,0 +1,88 @@
+package com.ruoyi.production.service.impl;
+
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.production.dto.SettlementImportDto;
+import com.ruoyi.production.pojo.ProductionSettlementBatches;
+import com.ruoyi.production.mapper.ProductionSettlementBatchesMapper;
+import com.ruoyi.production.pojo.ProductionSettlementDetails;
+import com.ruoyi.production.service.IProductionSettlementBatchesService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.production.service.IProductionSettlementDetailsService;
+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 java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * <p>
+ * 鐢熶骇鎴愭湰鏍哥畻鎵规涓昏〃 鏈嶅姟瀹炵幇绫�
+ * </p>
+ *
+ * @author deslrey
+ * @since 2026-03-30
+ */
+@Service
+public class ProductionSettlementBatchesServiceImpl extends ServiceImpl<ProductionSettlementBatchesMapper, ProductionSettlementBatches> implements IProductionSettlementBatchesService {
+
+    @Autowired
+    private IProductionSettlementDetailsService productionSettlementDetailsService;
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void importProductionSettlement(MultipartFile file, LocalDate periodTime, String batchName) {
+        if (file == null || file.isEmpty()) {
+            throw new ServiceException("瀵煎叆澶辫触锛屾枃浠朵笉鑳戒负绌�");
+        }
+
+        List<SettlementImportDto> list;
+        try {
+            ExcelUtil<SettlementImportDto> util = new ExcelUtil<>(SettlementImportDto.class);
+            list = util.importExcel(file.getInputStream());
+        } catch (Exception e) {
+            log.error("瀵煎叆鐢熶骇鎴愭湰鏍哥畻澶辫触", e);
+            throw new ServiceException("瑙f瀽Excel鏂囦欢澶辫触锛�" + e.getMessage());
+        }
+
+        if (StringUtils.isEmpty(list)) {
+            throw new ServiceException("瀵煎叆鏁版嵁涓嶈兘涓虹┖锛�");
+        }
+
+        ProductionSettlementBatches batch = new ProductionSettlementBatches();
+        batch.setBatchName(StringUtils.isNotEmpty(batchName) ? batchName : periodTime + "鎴愭湰鏍哥畻瀵煎叆");
+        batch.setPeriodTime(periodTime != null ? periodTime : LocalDate.now());
+        batch.setStatus(0);
+        batch.setCreateTime(LocalDateTime.now());
+        batch.setCreateUser(SecurityUtils.getUsername());
+        this.save(batch);
+
+        List<ProductionSettlementDetails> detailList = list.stream().map(dto -> {
+            ProductionSettlementDetails detail = new ProductionSettlementDetails();
+            detail.setBatchId(batch.getId());
+            detail.setProductType(dto.getProductType());
+            detail.setCategory(dto.getCategory());
+            detail.setSubjectName(dto.getSubjectName());
+            detail.setBudgetQty(dto.getBudgetQty());
+            detail.setBudgetPrice(dto.getBudgetPrice());
+            detail.setBudgetTotal(dto.getBudgetTotal());
+            detail.setActualQty(BigDecimal.ZERO);
+            detail.setActualPrice(BigDecimal.ZERO);
+            detail.setActualTotal(BigDecimal.ZERO);
+            detail.setDiffQty(BigDecimal.ZERO);
+            detail.setDiffPrice(BigDecimal.ZERO);
+            detail.setDiffTotal(BigDecimal.ZERO);
+
+            return detail;
+        }).collect(Collectors.toList());
+
+        productionSettlementDetailsService.saveBatch(detailList);
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3