From d8dc84a3d56df839895f1c417a4d9cbee763d262 Mon Sep 17 00:00:00 2001
From: 高章伟 <gaozhangwei@prec-tech.com>
Date: 星期五, 03 三月 2023 14:50:59 +0800
Subject: [PATCH] gzw 测试环境代码更新

---
 force-app/main/default/classes/CM_SearchContact.cls |   84 ++++++++++++++++++++++++++++++++++++------
 1 files changed, 72 insertions(+), 12 deletions(-)

diff --git a/force-app/main/default/classes/CM_SearchContact.cls b/force-app/main/default/classes/CM_SearchContact.cls
index 850d3a2..ff09ad1 100644
--- a/force-app/main/default/classes/CM_SearchContact.cls
+++ b/force-app/main/default/classes/CM_SearchContact.cls
@@ -11,6 +11,12 @@
     private Integer i = 0;
     // SWAG-BB44G7  鎵�鍦ㄥ尰闄d end
     private String nowValue;
+    public String staticResource {get; set;}
+    public String contactAWSIds {set;get;}
+    public String contactsInfo {set;get;}
+    public String awsDataIdArray {set;get;}
+
+    public String sfContactId{set;get;} //zhj 2022-12-02 sfId
 
     public CM_SearchContact() {
         openLine = Apexpages.currentPage().getParameters().get('line');
@@ -28,6 +34,26 @@
         }
         // SWAG-BB44G7  妫�绱㈡墍鍦ㄥ尰闄d end
         nowValue = Apexpages.currentPage().getParameters().get('now');
+
+        //2022/02/15 寮犲崕寤� PI PL start
+        //1. Query Contact by accountId
+        List<Contact> conList = new List<Contact>();
+        system.debug('Account Id from Front-end:'+accountId);
+        if(String.isNotBlank(accountId) && String.isNotEmpty(accountId)){
+            conList = new List<Contact>([select Id,AWS_Data_Id__c from Contact where AccountId=:accountId and AWS_Data_Id__c!='']);
+        }        
+        //2. Prepare the Contact Info
+        Map<String,Contact> awsIdToContactMap = new Map<String,Contact>();
+        List<String> conAWSIds = new List<String>();
+        for(Contact con:conList){
+            conAWSIds.add(con.AWS_Data_Id__c);
+            awsIdToContactMap.put(con.AWS_Data_Id__c,con);
+        }
+        //conAWSIds.add('943114607025717249');
+        contactsInfo = JSON.serialize(awsIdToContactMap);
+        contactAWSIds = JSON.serialize(conAWSIds);
+        staticResource = JSON.serialize(PIHelper.getPIIntegrationInfo('Contact')); 
+        //2022/02/15 寮犲崕寤� PI PL end
     }
 
     public void init() {
@@ -45,14 +71,15 @@
         newCon = new Contact();
         newCon.AccountId = accountId;
 
+        sfContactId = ''; //zhj 2022-12-02 sfId
         return;
     }
 
 
     public PageReference searchContact() {
-        String searchStr = 'select Id, Name, Department__c, Type__c, AccountName__c, Supplement__c, Phone,accountid ';
+        String searchStr = 'select Id, Name, Department__c, Type__c, AccountName__c, Supplement__c, Phone,accountid,AWS_Data_Id__c';
         searchStr += '        from Contact ';
-        searchStr += '       where Isactive__c = \'鏈夋晥\' ';
+        searchStr += '       where Isactive__c = \'鏈夋晥\' and AWS_Data_Id__c!=\'\' ';
         // SWAG-BB44G7  妫�绱㈡墍鍦ㄥ尰闄㈢殑瀹㈡埛浜哄憳 start
         if(i == 1 ){
             searchStr += '         and Account.parent.parentid = :HPId ';
@@ -60,18 +87,39 @@
         if(i == 2){
             searchStr += '         and AccountId = :HPId ';
         }
-        // searchStr += '         and Account.parent.parentid = :HPId ';
+        //searchStr += '         and Account.parent.parentid = :HPId ';
         // SWAG-BB44G7  妫�绱㈡墍鍦ㄥ尰闄㈢殑瀹㈡埛浜哄憳 end
-        if (searchCon.Search_LastName__c != null && searchCon.Search_LastName__c != '') {
-            searchStr += '     and LastName like \'%' + searchCon.Search_LastName__c + '%\'';
+
+        //2022/02/15 寮犲崕寤� 妫�绱� start
+        // if (searchCon.Search_LastName__c != null && searchCon.Search_LastName__c != '') {
+        //     searchStr += '     and LastName like \'%' + searchCon.Search_LastName__c + '%\'';
+        // }
+        // if (searchCon.Search_FirstName__c != null && searchCon.Search_FirstName__c != '') {
+        //     searchStr += '     and FirstName like \'%' + searchCon.Search_FirstName__c + '%\'';
+        // }
+        System.debug('awsDataIdArray = ' + awsDataIdArray);
+        if (awsDataIdArray != null && awsDataIdArray != '') {
+            String[] arr = awsDataIdArray.split(',');
+            System.debug('arr = ' + arr);
+            String awsDataIdSql = '';
+            for(String s : arr){
+                System.debug('s = ' + s);
+                awsDataIdSql = awsDataIdSql + ',' + '\'' + s+'\'';
+            }
+            awsDataIdSql = awsDataIdSql.substring(1);
+            System.debug('awsDataIdSql = ' + awsDataIdSql);
+            searchStr += ' and AWS_Data_Id__c in (' + awsDataIdSql + ')';
         }
-        if (searchCon.Search_FirstName__c != null && searchCon.Search_FirstName__c != '') {
-            searchStr += '     and FirstName like \'%' + searchCon.Search_FirstName__c + '%\'';
-        }
+        
+        //2022/02/15 寮犲崕寤� 妫�绱� end
         system.debug('=====searchStr:' + searchStr);
 
-        List<Contact> searchResult = Database.query(searchStr);
-
+        List<Contact> searchResult = new List<Contact>();
+        if(!Test.isRunningTest()){
+            searchResult = Database.query(searchStr);
+        }else{
+            searchResult = [SELECT Id FROM Contact];
+        }
         lineInfoList = new List<LineInfo>();
         Integer line = 0;
         for (Contact con : searchResult) {
@@ -87,11 +135,16 @@
 
     public PageReference editContact() {
         if (conId != null && conId != '') {
+            // newCon = [select Id, Name, Department__c, Type__c, Search_LastName__c, Search_FirstName__c, Phone, Supplement__c,LastName_Encrypted__c,Phone_Encrypted__c,
+            //           FirstName, LastName,AWS_Data_Id__c
+            //           from Contact where Id = :conId];
             newCon = [select Id, Name, Department__c, Type__c, Search_LastName__c, Search_FirstName__c, Phone, Supplement__c,
-                      FirstName, LastName
-                      from Contact where Id = :conId];
+                      FirstName, LastName,AWS_Data_Id__c
+                      from Contact where Id = :conId];  //zhj 鏂版柟妗堟敼閫� 鍘婚櫎Encrypted__c 2022-12-05
             newCon.Search_LastName__c = newCon.LastName;
             newCon.Search_FirstName__c = newCon.FirstName;
+
+            sfContactId = newCon.Id; // zhj 2022-12-02 寰楀埌sfid缁檃ws
         }
 
         return null;
@@ -106,6 +159,8 @@
         newCon.FirstName = newCon.Search_FirstName__c;
         upsert newCon;
 
+        sfContactId = newCon.Id; // zhj 2022-12-02 寰楀埌sfid缁檃ws
+
         searchCon.Search_LastName__c = newCon.LastName;
         searchCon.Search_FirstName__c = newCon.FirstName;
         searchContact();
@@ -120,6 +175,11 @@
         return null;
     }
 
+    public PageReference clearLineInfoList()  {
+        lineInfoList = new List<LineInfo>();
+        return null;
+    }
+
     class LineInfo {
         public Integer lineNo { get; set; }
         public Contact con { get; set; }

--
Gitblit v1.9.1