From bfca7a84bec815da594f1d12558535ed06d2490b Mon Sep 17 00:00:00 2001
From: 沙世明 <shashiming@prec-tech.com>
Date: 星期二, 13 九月 2022 09:57:32 +0800
Subject: [PATCH] 本地提交备份

---
 force-app/main/default/classes/Product2Handler.cls |   53 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/force-app/main/default/classes/Product2Handler.cls b/force-app/main/default/classes/Product2Handler.cls
index 44e5cc5..1596610 100644
--- a/force-app/main/default/classes/Product2Handler.cls
+++ b/force-app/main/default/classes/Product2Handler.cls
@@ -36,25 +36,66 @@
     private void SetCompetitorCode() {
         Boolean SelctFlg = False;
         list<AggregateResult> proList;
+        //甯﹂噺閲囪喘淇敼 start fy
+        list<AggregateResult> proListsc;
+        //甯﹂噺閲囪喘淇敼 end fy
         String strPC = '';
+        //甯﹂噺閲囪喘淇敼 start fy
+        String strPCsc = '';
+        //甯﹂噺閲囪喘淇敼 end fy
         Integer i = 1;
 
+        String ProductRecordTypes = System.Label.ProductRecordTypeID;
+        String[] RecordTypes = String.isNotBlank(ProductRecordTypes) ? ProductRecordTypes.split(',') : null;
+
         for (Product2 nObj : newList) {
-            if (nObj.Competitor_product_dummy__c) {
+            //甯﹂噺閲囪喘淇敼 start fy
+            String RecordTypeString = '';
+            if(nObj.RecordTypeId!=null){
+                RecordTypeString=String.valueof(nObj.RecordTypeId).substring(0,15);
+            }
+            // nObj.Competitor_product_dummy__c=System.Label.ProductRecordTypeID.contains(RecordTypeString);
+            // if (nObj.Competitor_product_dummy__c) {
+            if (System.Label.ProductRecordTypeID.contains(RecordTypeString)) {
                 SelctFlg = True;
             }
+            //甯﹂噺閲囪喘淇敼 end fy
         }
         if (SelctFlg) {
-            proList = [Select Max(ProductCode) PC From Product2 Where ProductCode Like 'SD%'];
+            proList = [Select Max(ProductCode) PC From Product2 Where ProductCode Like 'SD%' and ProductCode!='SD999999'];
             if (proList != null && proList.size() > 0) {
                 strPC = String.valueof(proList[0].get('PC'));
             }
+            //甯﹂噺閲囪喘 start fy
+            proListsc = [Select Max(ProductCode) PC From Product2 Where ProductCode Like 'SC%'];
+            if (proListsc != null && proListsc.size() > 0) {
+                strPCsc = String.valueof(proListsc[0].get('PC'));
+            }
+            //甯﹂噺閲囪喘 end fy
         }
         for (Product2 nObj : newList) {
-            if (nObj.Competitor_product_dummy__c && strPC.length() == 8
-                    && proList != null && proList.size() > 0 ) {
-                Integer num = Integer.valueOf(strPC.SubString(2,strPC.length())) + i;
-                nObj.ProductCode  = 'SD' + String.valueOf(num).leftpad(6,'0');
+            //甯﹂噺閲囪喘 start fy
+            String RecordTypeString = '';
+            if(nObj.RecordTypeId!=null){
+                RecordTypeString=String.valueof(nObj.RecordTypeId).substring(0,15);
+            }
+            // if (nObj.Competitor_product_dummy__c && strPC.length() == 8
+            // if (System.Label.ProductRecordTypeID.contains(RecordTypeString) && strPC.length() == 8
+            if (System.Label.ProductRecordTypeID.contains(RecordTypeString)) {
+            //甯﹂噺閲囪喘 end fy
+                    // && proList != null && proList.size() > 0 ) {
+                // Integer num = Integer.valueOf(strPC.SubString(2,strPC.length())) + i;
+                Integer num = String.isNotBlank(strPC) ? Integer.valueOf(strPC.SubString(2,strPC.length())) + i : i;
+                //甯﹂噺閲囪喘 start fy
+                Integer numsc = String.isNotBlank(strPCsc) ? Integer.valueOf(strPCsc.SubString(2,strPCsc.length())) + i : i;
+                // if(RecordTypeString=='0129D000001NacC'){
+                if(RecordTypes != null && RecordTypes.size() > 1 && RecordTypeString == RecordTypes[1]){
+                    nObj.ProductCode  = 'SC' + String.valueOf(numsc).leftpad(8,'0');
+                }else{
+                    nObj.ProductCode  = 'SD' + String.valueOf(num).leftpad(6,'0');
+                }
+                //甯﹂噺閲囪喘 end fy
+                // nObj.ProductCode  = 'SD' + String.valueOf(num).leftpad(6,'0');
                 i++;
             }
         }

--
Gitblit v1.9.1