From 0c4796706fc9473d069b620321a54b20a119906c Mon Sep 17 00:00:00 2001
From: buli <137736985@qq.com>
Date: 星期二, 11 七月 2023 14:16:44 +0800
Subject: [PATCH] Merge branch 'LEXUpgrade2023-Deloitte'

---
 force-app/main/default/classes/LexNewAndEditBasePIPLController.cls |  215 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 215 insertions(+), 0 deletions(-)

diff --git a/force-app/main/default/classes/LexNewAndEditBasePIPLController.cls b/force-app/main/default/classes/LexNewAndEditBasePIPLController.cls
new file mode 100644
index 0000000..2f1f6eb
--- /dev/null
+++ b/force-app/main/default/classes/LexNewAndEditBasePIPLController.cls
@@ -0,0 +1,215 @@
+public without sharing class LexNewAndEditBasePIPLController {
+    public static Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
+    // 瀛楁淇℃伅
+    public static Map<string, SObjectField> fieldMap = new Map<string, SObjectField>();
+
+    public static ResponseBodyLWC initData(Id rid, String recordTypeId, String sobjectType) {
+        try {
+            System.debug('rid = ' + rid);
+            System.debug('recordTypeId = ' + recordTypeId);
+            System.debug('sobjectType = ' + sobjectType);
+            fieldMap = schemaMap.get(sobjectType).getDescribe().fields.getMap();
+            ResponseBodyLWC res = new ResponseBodyLWC();
+            Map<String, object> data = new Map<String, object>();
+            res.entity = data;
+
+            if (String.isBlank(recordTypeId)) {
+                data.put('recordTypeId', LayoutDescriberHelper.getDefaultRecordType(sobjectType));
+            }
+
+            //缂栬緫
+            if (!String.isBlank(rid)) {
+                //鑾峰彇瀵瑰簲瀵硅薄鐨勫瓧娈�                List<Sobject> lso = Database.query('select id from RecordType where SobjectType = :sobjectType');
+                String sql = 'select ';
+                DescribeSObjectResult objectType = rid.getSobjectType().getDescribe();
+                List<String> objectFields = new List<String>(objectType.fields.getMap().keySet());
+                sql += String.join(objectFields, ',') + ' from ' + sobjectType + ' where id =\'' + rid + '\' limit 1';
+                System.debug('sql = ' + sql);
+                Sobject leadData = Database.query(sql);
+                if (leadData == null) {
+                    return new ResponseBodyLWC('Error', 500, 'id涓嶅瓨鍦�', '');
+                }
+                if (objectFields.contains('recordtypeid')) {
+                    recordTypeId = (String) leadData.get('RecordTypeId');
+                    System.debug('recordTypeId: ' + recordTypeId);
+                }
+                List<Metadata.LayoutSection> layout = MetaDataUtility.GetRecordTypePageLayout(recordTypeId, sobjectType);
+                data.put('layout', Json.serialize(reviseMetaLayouts(layout)));
+                data.put('recordTypeId', recordTypeId);
+                System.debug('data.recordTypeId: ' + data.get('recordTypeId'));
+                data.put('AWSDataId', (String) leadData.get('AWS_Data_Id__c'));
+                //鑾峰彇鍊�
+                System.debug('leadData = ' + JSON.serialize(leadData));
+                data.put('data', leadData);
+            } else {
+                List<Metadata.LayoutSection> layout = MetaDataUtility.GetRecordTypePageLayout(recordTypeId, sobjectType);
+                data.put('layout', Json.serialize(reviseMetaLayouts(layout)));
+            }
+            //鑾峰彇PI瀛楁
+            PIHelper.PIIntegration piIntegration = PIHelper.getPIIntegrationInfo(sobjectType);
+            Map<String, String> AWSToSobjectNonEncryptedMap = new Map<String, String>();
+            List<String> AWSToSobjectNonEncryptedMapKeySet = new List<String>();
+            for (PI_Field_Policy_Detail__c PIDetail : piIntegration.PIDetails) {
+                AWSToSobjectNonEncryptedMap.put(PIDetail.AWS_Field_API__c, PIDetail.SF_Field_API_Name__c);
+                AWSToSobjectNonEncryptedMapKeySet.add(PIDetail.AWS_Field_API__c);
+            }
+            data.put('AWSToSobjectNonEncryptedMap', AWSToSobjectNonEncryptedMap);
+            data.put('AWSToSobjectNonEncryptedMapKeySet', AWSToSobjectNonEncryptedMapKeySet);
+            data.put('staticResource', Json.serialize(PIHelper.getPIIntegrationInfo(sobjectType)));
+            res.status = 'Success';
+            res.code = 200;
+            res.msg = '';
+            return res;
+        } catch (Exception e) {
+            System.debug('error = ' + e.getMessage() + ' line = ' + e.getLineNumber());
+            return new ResponseBodyLWC('Error', 500, e.getMessage() + ' ' + e.getLineNumber(), '');
+        }
+    }
+
+    public static ResponseBodyLWC queryAccount(String accountTypes, String accountId) {
+        ResponseBodyLWC res = new ResponseBodyLWC();
+        Map<String, object> data = new Map<String, object>();
+        res.entity = data;
+        System.debug('accountType = ' + accountTypes);
+        System.debug('accountId = ' + accountId);
+        try {
+            List<Object> types = (List<Object>) JSON.deserializeUntyped(accountTypes);
+            System.debug('types=' + types);
+            String soql = 'select Id,Name,';
+            for (Object t : types) {
+                soql += (String) t + ',';
+            }
+            soql = soql.substring(0, soql.length() - 1);
+            soql += ' from Account where id=\'' + accountId + '\'';
+            System.debug('soql=' + soql);
+            Sobject account = new Account();
+            if (!Test.isRunningTest()) {
+                account = Database.query(soql);
+            } else {
+                account.put('Id', '000000000000000');
+            }
+            Map<String, Map<String, String>> m = new Map<String, Map<String, String>>();
+            System.debug('account=' + account);
+            for (Object ty : types) {
+                String t = (String) ty;
+                if (account.get(t) != null || Test.isRunningTest()) {
+                    Sobject acc = new Account();
+                    if (Test.isRunningTest()) {
+                        acc.put('Id', '000000000000000');
+                        acc.put('Name', 'Name');
+                    } else {
+                        acc = Database.query('select Id,Name from Account where id=\'' + account.get(t) + '\'');
+                    }
+                    Map<String, String> n = new Map<String, String>();
+                    n.put('Id', (String) acc.get('Id'));
+                    n.put('Name', (String) acc.get('Name'));
+                    m.put(t, n);
+                }
+            }
+            System.debug('m=' + m);
+            data.put('m', m);
+            data.put('account', account);
+            res.status = 'Success';
+            res.code = 200;
+            res.msg = '';
+            return res;
+        } catch (Exception e) {
+            return new ResponseBodyLWC('Error', 500, e.getMessage() + ' ' + e.getLineNumber(), '');
+        }
+    }
+
+    public static ResponseBodyLWC searchContactInit(String accountId, String searchKeyWord) {
+        ResponseBodyLWC res = new ResponseBodyLWC();
+        Map<String, object> data = new Map<String, object>();
+        res.entity = data;
+        System.debug('accountId = ' + accountId);
+        System.debug('searchKeyWord = ' + searchKeyWord);
+        try {
+            List<Contact> conList = new List<Contact>();
+            List<Contact> noPIContactList = new List<Contact>();
+            if (checkNullString(accountId) && checkNullString(searchKeyWord)) {
+                conList = new List<Contact>();
+            } else {
+                if (checkNullString(accountId)) {
+                    conList = new List<Contact>();
+                } else {
+                    //2022-5-12 yjk 灏嗙瀹ゅ尮閰嶆敼涓哄尰闄㈠尮閰嶆煡璇㈣仈绯讳汉 statt
+                    Account act = [SELECT id, Hospital__c FROM Account WHERE id = :accountId];
+                    conList = new List<Contact>(
+                        [
+                            SELECT Id, AWS_Data_Id__c, Account.Name
+                            FROM Contact
+                            WHERE Account.Hospital__c = :act.Hospital__c AND AWS_Data_Id__c != ''
+                        ]
+                    );
+                    noPIContactList = AWSServiceTool.getNoPIContact(searchKeyWord, accountId);
+                    //2022-5-12 yjk 灏嗙瀹ゅ尮閰嶆敼涓哄尰闄㈠尮閰嶆煡璇㈣仈绯讳汉 end
+                }
+            }
+            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);
+            }
+            data.put('awsIdToContactMap', awsIdToContactMap);
+            data.put('conAWSIds', conAWSIds);
+            data.put('noPIContactList', noPIContactList);
+            data.put('contactStaticResource', JSON.serialize(PIHelper.getPIIntegrationInfo('Contact')));
+            res.status = 'Success';
+            res.code = 200;
+            res.msg = '';
+            return res;
+        } catch (Exception e) {
+            return new ResponseBodyLWC('Error', 500, e.getMessage() + ' ' + e.getLineNumber(), '');
+        }
+    }
+
+    public static Boolean checkNullString(String inputString) {
+        if (String.isEmpty(inputString) || String.isBlank(inputString)) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     *@description 杞崲layout
+     *@param	sections                        榛樿metalayout
+     *@return	List<Metadata.LayoutSection>	鏍囧噯metalayout
+     */
+    public static List<Metadata.LayoutSection> reviseMetaLayouts(List<Metadata.LayoutSection> sections) {
+        List<Metadata.LayoutSection> result = new List<Metadata.LayoutSection>();
+        if (sections == null) {
+            return null;
+        }
+        for (Metadata.LayoutSection s : sections) {
+            Metadata.LayoutSection section = new Metadata.LayoutSection();
+            section.customLabel = s.customLabel;
+            section.detailHeading = s.detailHeading;
+            section.editHeading = s.editHeading;
+            section.label = s.label;
+            section.style = s.style;
+            result.add(section);
+            for (Metadata.LayoutColumn c : s.layoutColumns) {
+                if (c.layoutItems == null) {
+                    break;
+                }
+                Metadata.LayoutColumn col = new Metadata.LayoutColumn();
+                col.reserved = col.reserved;
+                section.layoutColumns.add(col);
+                for (Metadata.layoutItem item : c.layoutItems) {
+                    if (!fieldMap.containsKey(item.field) || !isUpdateable(fieldMap.get(item.field).getDescribe())) {
+                        System.debug(item.field);
+                        continue;
+                    }
+                    col.layoutItems.add(item);
+                }
+            }
+        }
+        return result;
+    }
+
+    private static Boolean isUpdateable(Schema.DescribeFieldResult dfr) {
+        return (new List<String>{ 'Id', 'Name' }).contains(dfr.getName()) || dfr.isUpdateable();
+    }
+}

--
Gitblit v1.9.1