From f5a94e721ae5a26f817f0df75065b64f1f192eb3 Mon Sep 17 00:00:00 2001
From: Li Jun <buli@deloitte.com.cn>
Date: 星期一, 28 三月 2022 21:43:51 +0800
Subject: [PATCH] PIPLFunctionDeploy0328

---
 force-app/main/default/classes/CM_SearchContactServiceController.cls |   69 ++++++++++++++++++++++++++++++----
 1 files changed, 60 insertions(+), 9 deletions(-)

diff --git a/force-app/main/default/classes/CM_SearchContactServiceController.cls b/force-app/main/default/classes/CM_SearchContactServiceController.cls
index a2ccebe..cebda87 100644
--- a/force-app/main/default/classes/CM_SearchContactServiceController.cls
+++ b/force-app/main/default/classes/CM_SearchContactServiceController.cls
@@ -8,10 +8,36 @@
     private String accountId;
     private String nowValue;
 
+    public String staticResource {get; set;}
+    public String contactAWSIds {set;get;}
+    public String contactsInfo {set;get;}
+    public String awsDataIdArray {set;get;}
+
     public CM_SearchContactServiceController() {
         openLine = Apexpages.currentPage().getParameters().get('line');
         accountId = Apexpages.currentPage().getParameters().get('acc');
         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);
+        PIHelper.PIIntegration contactPIIntegration = PIHelper.getPIIntegrationInfo('Contact');
+        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!='' order by lastmodifieddate desc limit :contactPIIntegration.maxQueryNumber]);
+        }        
+        //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() {
@@ -34,18 +60,38 @@
 
 
     public PageReference searchContact() {
-        String searchStr = 'select Id, Name, Department__c, Type__c, AccountName__c, Supplement__c, Phone ';
+        String searchStr = 'select Id, Name, Department__c, Type__c, AccountName__c, Supplement__c, Phone,AWS_Data_Id__c ';
          searchStr += ', City__c , State__c '; //2018/11/19 HWAG-B399RW 璇诲彇鐪佸拰甯�
         searchStr += '        from Contact ';
-        searchStr += '       where Isactive__c = \'鏈夋晥\' ';
+        searchStr += '       where Isactive__c = \'鏈夋晥\' and AWS_Data_Id__c!=\'\' ';
         searchStr += '         and AccountId = :accountId ';
-        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);
+
+        searchStr += ' order by lastmodifieddate desc limit 500';
 
         List<Contact> searchResult = Database.query(searchStr);
 
@@ -64,8 +110,8 @@
 
     public PageReference editContact() {
         if (conId != null && conId != '') {
-            newCon = [select Id, Name, Department__c, Type__c, Search_LastName__c, Search_FirstName__c, Phone, Supplement__c,
-                             FirstName, LastName
+            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.Search_LastName__c = newCon.LastName;
             newCon.Search_FirstName__c = newCon.FirstName;
@@ -97,6 +143,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