From b03a9514b19665fcfbd4b3138d6d56899496f755 Mon Sep 17 00:00:00 2001
From: whycxzp <perryhsu@163.com>
Date: 星期三, 31 八月 2022 16:22:40 +0800
Subject: [PATCH] 产品新增更新

---
 src/main/java/com/whyc/service/ProductService.java |   46 +++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/whyc/service/ProductService.java b/src/main/java/com/whyc/service/ProductService.java
index 3ae376e..6aadf38 100644
--- a/src/main/java/com/whyc/service/ProductService.java
+++ b/src/main/java/com/whyc/service/ProductService.java
@@ -8,9 +8,7 @@
 import com.whyc.dto.FileUrlDTO;
 import com.whyc.dto.Response;
 import com.whyc.mapper.ProductMapper;
-import com.whyc.pojo.DocUser;
-import com.whyc.pojo.Product;
-import com.whyc.pojo.ProductBom;
+import com.whyc.pojo.*;
 import com.whyc.util.ActionUtil;
 import com.whyc.util.CommonUtil;
 import com.whyc.util.FileUtil;
@@ -32,6 +30,13 @@
 public class ProductService {
     @Autowired(required = false)
     private ProductMapper mapper;
+
+    @Autowired
+    private ProductHistoryService phService;
+
+    @Autowired
+    private MaterialProductHistoryService mphService;
+
 
     //鏌ヨ鍑烘墍鏈夌殑浜у搧淇℃伅(鍒嗛〉鍔犳ā绯婃煡璇�<浜у搧鐨勭紪鐮侊紝鍨嬪彿锛屽悕瀛楋紝瀹氬埗琛ㄧ紪鍙�>
     public Response getAllProduct(String parentCode, String parentName, String parentModel, String customCode, int pageCurr, int pageSize) {
@@ -263,4 +268,39 @@
         });
         return list;
     }
+
+    public Response add(Product product) {
+        String parentCode = product.getParentCode();
+        String customCode = product.getCustomCode();
+        //鏌ヨ浜у搧鏈�鏂扮殑鐗堟湰鍙�
+        ProductHistory latestProduct = phService.getLatestVersion(parentCode, customCode);
+        ProductHistory enabledProduct = phService.getEnabledByParentCodeAndCustomCode(parentCode, customCode);
+        int currentVersion = 0;
+        if (latestProduct != null) {
+            currentVersion = latestProduct.getVersion();
+        }
+        Integer nextVersion = currentVersion + 1;
+        //浜у搧鐗╂枡鍏崇郴杩佺Щ
+        //鏌ヨ鐢熸晥鐗堟湰鐨勫叧鑱斿叧绯�
+        if(latestProduct!=null &&enabledProduct!=null) {
+            List<MaterialProductHistory> mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(parentCode, customCode, enabledProduct.getVersion());
+            if (latestProduct.getVersion().intValue() == enabledProduct.getVersion()) {
+                //鏈�鏂扮増鏈敓鏁�,鍏宠仈鍏崇郴鐗堟湰杩炵潃鐨�
+                mphService.updateVersionBatch(mpList);
+            } else {
+                //鏃х増鏈敓鏁�,鍏宠仈鍏崇郴鐗堟湰涓嶈繛鐫�
+                mpList.forEach(mp -> {
+                    mp.setSVersion(nextVersion);
+                    mp.setEVersion(nextVersion);
+                });
+                mphService.insertBatch(mpList);
+            }
+        }
+
+        //灏嗕骇鍝佹枃浠跺鍒惰嚦姝e紡璺緞
+
+        //鐗╂枡琛ㄤ腑涓嶅瓨鍦ㄧ殑,鍒欐坊鍔犲埌鐗╂枡琛ㄤ腑鍘�(鍖呭惈product杩欎釜鐗╂枡)
+
+        return null;
+    }
 }

--
Gitblit v1.9.1