From a0a32468bd6f5e887938674d3c2cf70cc2f555b8 Mon Sep 17 00:00:00 2001
From: 李白 <7387820+wjli_13439841639@user.noreply.gitee.com>
Date: 星期五, 15 五月 2026 08:33:27 +0800
Subject: [PATCH] 开会后对客商排产计划,销售人员的整体修改1

---
 platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/controller/ProductionPlanController.java |   78 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/controller/ProductionPlanController.java b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/controller/ProductionPlanController.java
index d925735..0530d36 100644
--- a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/controller/ProductionPlanController.java
+++ b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/controller/ProductionPlanController.java
@@ -6,10 +6,17 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.by4cloud.platformx.business.entity.ContractSubjectMatter;
+import com.by4cloud.platformx.business.entity.PlanSubjectMatter;
+import com.by4cloud.platformx.business.service.ContractSubjectMatterService;
+import com.by4cloud.platformx.business.service.PlanSubjectMatterService;
+import com.by4cloud.platformx.business.utils.ContractNumberGenerator;
 import com.by4cloud.platformx.common.core.util.R;
+import com.by4cloud.platformx.common.data.mybatis.BaseModel;
 import com.by4cloud.platformx.common.log.annotation.SysLog;
 import com.by4cloud.platformx.business.entity.ProductionPlan;
 import com.by4cloud.platformx.business.service.ProductionPlanService;
+import com.by4cloud.platformx.common.security.util.SecurityUtils;
 import org.springframework.security.access.prepost.PreAuthorize;
 import com.by4cloud.platformx.common.excel.annotation.ResponseExcel;
 import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@@ -20,8 +27,10 @@
 import lombok.RequiredArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * 鎺掍骇璁″垝
@@ -37,6 +46,8 @@
 public class ProductionPlanController {
 
     private final  ProductionPlanService productionPlanService;
+    //private final ContractSubjectMatterService contractSubjectMatterService;
+    private final PlanSubjectMatterService planSubjectMatterService;
 
     /**
      * 鍒嗛〉鏌ヨ
@@ -53,7 +64,16 @@
         wrapper.eq(productionPlan.getPartyaid()!=null,ProductionPlan::getPartyaid,productionPlan.getPartyaid());
         wrapper.eq(productionPlan.getPartybid()!=null,ProductionPlan::getPartybid,productionPlan.getPartybid());
         wrapper.eq(productionPlan.getStatus()!=null,ProductionPlan::getStatus,productionPlan.getStatus());
-        return R.ok(productionPlanService.page(page, wrapper));
+        Page<ProductionPlan> page1 = productionPlanService.page(page, wrapper);
+        List<ProductionPlan> list = page1.getRecords();
+        for(ProductionPlan plan : list){
+            List<PlanSubjectMatter> metterList = planSubjectMatterService.list(new LambdaQueryWrapper<PlanSubjectMatter>()
+                    .eq(PlanSubjectMatter::getPlanId,plan.getId())
+            );
+            plan.setPlanSubjectMatterList(metterList);
+        }
+        page1.setRecords(list);
+        return R.ok(page1);
     }
 
     /**
@@ -78,7 +98,15 @@
     @GetMapping("/{id}" )
     @PreAuthorize("@pms.hasPermission('business_productionPlan_view')" )
     public R getById(@PathVariable("id" ) Long id) {
-        return R.ok(productionPlanService.getById(id));
+        ProductionPlan productionPlan = productionPlanService.getById(id);
+        if(productionPlan==null){
+            return R.failed("id閿欒锛�");
+        }
+        List<PlanSubjectMatter> list = planSubjectMatterService.list(new LambdaQueryWrapper<PlanSubjectMatter>()
+                .eq(PlanSubjectMatter::getPlanId,productionPlan.getId())
+        );
+        productionPlan.setPlanSubjectMatterList(list);
+        return R.ok(productionPlan);
     }
 
     /**
@@ -91,7 +119,22 @@
     @PostMapping
     @PreAuthorize("@pms.hasPermission('business_productionPlan_add')" )
     public R save(@RequestBody ProductionPlan productionPlan) {
-        return R.ok(productionPlanService.save(productionPlan));
+        if(StrUtil.isEmpty(productionPlan.getProductionPlanName())){
+            return R.failed("鎺掍骇璁″垝鍚嶇О涓嶈兘涓虹┖锛�");
+        }
+        productionPlan.setPartybid(SecurityUtils.getUser().getCompId());
+        productionPlan.setPartyb(SecurityUtils.getUser().getCompName());
+        productionPlan.setProductionPlanNo("p-"+ContractNumberGenerator.generateContractNumber());
+        productionPlanService.save(productionPlan);
+
+        if(productionPlan.getPlanSubjectMatterList()!=null){
+            for(PlanSubjectMatter matter1 : productionPlan.getPlanSubjectMatterList()){
+                matter1.setPlanId(productionPlan.getId());
+            }
+            planSubjectMatterService.saveBatch(productionPlan.getPlanSubjectMatterList());
+        }
+
+        return R.ok(true);
     }
 
     /**
@@ -104,6 +147,35 @@
     @PutMapping
     @PreAuthorize("@pms.hasPermission('business_productionPlan_edit')" )
     public R updateById(@RequestBody ProductionPlan productionPlan) {
+
+        List<PlanSubjectMatter> list = planSubjectMatterService.list(new LambdaQueryWrapper<PlanSubjectMatter>()
+                .eq(PlanSubjectMatter::getPlanId,productionPlan.getId())
+        );
+        List<Long> idsO = new ArrayList<>();
+        if(list!=null){
+            if(!list.isEmpty()){
+                idsO = list.stream().map(BaseModel::getId).collect(Collectors.toList());
+            }
+        }
+
+        if(productionPlan.getPlanSubjectMatterList()!=null){
+            List<Long> idsN = new ArrayList<>();
+            for(PlanSubjectMatter matter : productionPlan.getPlanSubjectMatterList()){
+                if(matter.getId()==null){
+                    matter.setPlanId(productionPlan.getId());
+                }else{
+                    idsN.add(matter.getId());
+                }
+            }
+            planSubjectMatterService.saveOrUpdateBatch(productionPlan.getPlanSubjectMatterList());
+            if(!idsO.isEmpty()) {
+                for (Long id : idsO) {
+                    if (!idsN.contains(id)) {
+                        planSubjectMatterService.removeById(id);
+                    }
+                }
+            }
+        }
         return R.ok(productionPlanService.updateById(productionPlan));
     }
 

--
Gitblit v1.9.1