From 258b69ac258a3cee13792ef8441977e7dae9b7d8 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期一, 02 二月 2026 11:20:20 +0800
Subject: [PATCH] yys  成品入库单价修改,成品库存修改

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

diff --git a/src/main/java/com/ruoyi/production/service/impl/SalesLedgerWorkServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/SalesLedgerWorkServiceImpl.java
index d1aaae9..4ab3c14 100644
--- a/src/main/java/com/ruoyi/production/service/impl/SalesLedgerWorkServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/SalesLedgerWorkServiceImpl.java
@@ -22,12 +22,18 @@
 import com.ruoyi.production.service.SalesLedgerWorkService;
 import com.ruoyi.project.system.domain.SysUser;
 import com.ruoyi.project.system.mapper.SysUserMapper;
+import com.ruoyi.sales.mapper.LossMapper;
+import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
+import com.ruoyi.sales.pojo.Loss;
+import com.ruoyi.sales.pojo.SalesLedgerProduct;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
@@ -47,15 +53,48 @@
 
     private final SysUserMapper sysUserMapper;
 
+    private final LossMapper lossMapper;
+
     private final SalesLedgerProductionAccountingMapper salesLedgerProductionAccountingMapper;
 
     @Override
     public IPage<SalesLedgerWorkDto> listPage(Page page, SalesLedgerWorkDto salesLedgerWorkDto) {
         IPage<SalesLedgerWorkDto> iPage = salesLedgerWorkMapper.listPage(page, salesLedgerWorkDto);
+        List<Loss> losses = lossMapper.selectList(null);
+        if(!CollectionUtils.isEmpty(losses)){
+            iPage.getRecords().forEach(item -> {
+                String[] split = item.getSpecificationModel().split("\\*");
+                if(split.length == 2 && isNumeric(split[1]) && isNumeric(split[0])){
+                    // 璁$畻鎹熻�楋紙100000浠h〃 鎹熻�楃殑 100 鍜� 鍗曚綅杞崲鐨�1000锛�
+                    BigDecimal divide = new BigDecimal(split[0])
+                            .multiply(new BigDecimal(split[1]))
+                            .multiply(item.getFinishedNum())
+                            .multiply(losses.get(0).getRate())
+                            .divide(new BigDecimal(100000), 2, RoundingMode.HALF_UP);
+                    item.setLoss(divide.toString());
+                }
+
+            });
+        }
         return iPage;
     }
 
+    public static boolean isNumeric(String str) {
+        if (str == null || str.isEmpty()) {
+            return false;
+        }
+        // 閬嶅巻瀛楃涓茬殑姣忎釜瀛楃锛屾鏌ユ槸鍚︿负鏁板瓧
+        for (int i = 0; i < str.length(); i++) {
+            if (!Character.isDigit(str.charAt(i))) {
+                return false;
+            }
+        }
+        return true;
+    }
+
     private final ProcurementRecordServiceImpl procurementRecordService;
+
+    private final SalesLedgerProductMapper salesLedgerProductMapper;
 
     @Override
     public int productionReport(ProductionReportDto productionReportDto) {
@@ -84,6 +123,8 @@
                 .process(salesLedgerWork.getProcess())
                 .schedulingDate(LocalDate.parse(productionReportDto.getSchedulingDate(), DateTimeFormatter.ISO_LOCAL_DATE));
         salesLedgerProductionAccountingMapper.insert(builder.build());
+        // 鏌ヨ閿�鍞骇鍝佸崟浠�
+        SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(salesLedgerWork.getSalesLedgerProductId());
         // 鐢熶骇鎶ュ伐鎴愬姛 -> 鍏ュ簱
         LoginUser loginUser = SecurityUtils.getLoginUser();
         ProcurementAddDto procurementRecordOutAdd = new ProcurementAddDto();
@@ -94,6 +135,8 @@
         Details details1 = new Details();
         details1.setInboundQuantity(productionReportDto.getFinishedNum());
         details1.setId(Integer.parseInt(salesLedgerWork.getSalesLedgerProductId().toString()));
+        details1.setTaxInclusiveUnitPrice(salesLedgerProduct != null ? salesLedgerProduct.getTaxInclusiveUnitPrice() : productionReportDto.getUnitPrice());
+        details1.setTotalPrice(details1.getTaxInclusiveUnitPrice().multiply(details1.getInboundQuantity()));
         details.add(details1);
         procurementRecordOutAdd.setDetails(details);
         procurementRecordService.add(procurementRecordOutAdd);

--
Gitblit v1.9.3