1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * Author: Zhang,Huajian
 * Created Date: 05/29/2023
 * Purpose: Utility class for describe layouts
 * Test Class: LexNewAndEditContactPIPLControllerTest
 * History: 
 *      05/29/2023 - Zhang,Huajian - Initial Code.
 * 
 * */
public with sharing class LexNewAndEditContactPIPLController {
    public static Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    // 字段信息
    public static Map<string, SObjectField> fieldMap = new Map<string, SObjectField>();
 
    @AuraEnabled
    public static ResponseBodyLWC initData(Id rid, String recordTypeId, String sobjectType, String accid) {
        ResponseBodyLWC res = new ResponseBodyLWC();
        Map<String, object> data = new Map<String, object>();
        res.entity = data;
 
        Boolean isDoctor = true;
        string s = null;
        
        //如果有记录类型,判断是不是医院类型
        if (String.isNotBlank(recordTypeId)) {
            System.debug('recordTypeId = ' + recordTypeId);
            s = Schema.SObjectType.Contact.getRecordTypeInfosById().get(recordTypeId).getDeveloperName();
            //说明无需加密
            if (s == 'Agency' || s == 'Internal_staff') {
                ResponseBodyLWC rbl = LexNewAndEditBasePIPLController.initData(rid, recordTypeId, sobjectType);
                if(!Test.isRunningTest()){
                    data = (Map<String,Object>)rbl.entity;
                }
                isDoctor = false;
                data.put('isDoctor', isDoctor);
                rbl.entity = data;
                return rbl;
            }
        }
        //说明无需加密
        if (String.isNotBlank(accid)) {
            List<Account> accs = [SELECT RecordType.DeveloperName FROM account WHERE id = :accid];
            if (accs.size() > 0) {
                s = accs[0].RecordType.DeveloperName;
                if (s == 'Office' || s == 'AgencyContact' || s == 'Agency') {
                    ResponseBodyLWC rbl = LexNewAndEditBasePIPLController.initData(rid, recordTypeId, sobjectType);
                    if(!Test.isRunningTest()){
                    data = (Map<String,Object>)rbl.entity;
                    }
                    isDoctor = false;
                    data.put('isDoctor', isDoctor);
                    rbl.entity = data;
                    return rbl;
                }
            }
        }
 
        //说明无需加密
        if (String.isNotBlank(rid)) {
            List<Contact> contact = [select Id,RecordTypeId from Contact where Id=:rid];
            if(String.isNotBlank(contact[0].RecordTypeId)){
                s = Schema.SObjectType.Contact.getRecordTypeInfosById().get(contact[0].RecordTypeId).getDeveloperName();
                if (s == 'Agency' || s == 'Internal_staff') {
                    ResponseBodyLWC rbl = LexNewAndEditBasePIPLController.initData(rid, recordTypeId, sobjectType);
                    if(!Test.isRunningTest()){
                    data = (Map<String,Object>)rbl.entity;
                    }
                    isDoctor = false;
                    data.put('isDoctor', isDoctor);
                    rbl.entity = data;
                    return rbl;
                }
            }
        }
        ResponseBodyLWC rbl = LexNewAndEditBasePIPLController.initData(rid, recordTypeId, sobjectType);
        if(rbl.status == 'Success'){
            if(!Test.isRunningTest()){
            data = (Map<String,Object>)rbl.entity;
            }
            data.put('isDoctor', isDoctor);
            rbl.entity = data;
        }
        return rbl;
    }
 
    @AuraEnabled
    public static ResponseV2 searchContactByAccountId(String accountId,String RecordTypeId,String Isactive) {
        accountId = accountId.substring(0,15);
        System.debug('accountId = ' + accountId);
        ResponseV2 res = new ResponseV2();
        try{
            List<Account> account = [select Id,Name from Account where Id = :accountId];
            if(account.size() <= 0){
                res.message = '没有找到对应客户';
                res.status = 'fail';
                return res;
            }
            List<Contact> contactList = [select id,AWS_Data_Id__c, CManageCode__c,Name from Contact where AccountId = :account[0].Id];
            Map<String,String> dataIdManageCodeMap = new Map<String,String>();
            for(Contact contact : contactList){
                dataIdManageCodeMap.put(contact.AWS_Data_Id__c,contact.CManageCode__c);
            }
            res.dataIdManageCodeMap = dataIdManageCodeMap;
            res.accountName = account[0].Name;
            res.contactList = contactList;
 
            ID DoctorRecordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Doctor').getRecordTypeId();
            Map<String,String> accMap= new Map<String,String>();
            List<Account> accList=[select ID,Is_Active__c,Is_Active_Formula__c from Account where ID =:accountId];
            if(accList.size()>0){
                for(Account acc:accList){
                    if (String.isNotBlank(acc.Is_Active__c)){
                        String subId = acc.Id;
                        accMap.put(subId.substring(0,15), acc.Is_Active__c);
                        continue;
                    }
                    if (String.isNotBlank(acc.Is_Active_Formula__c)){
                        String subId = acc.Id;
                        accMap.put(subId.substring(0,15), acc.Is_Active_Formula__c);
                    }
                }
            }
            System.debug('accMap= ' + accMap);
            //如果是Doctor记录类型的需要进行姓名+手机号判断
            if(DoctorRecordTypeId.equals(RecordTypeId)){
                res.isNameMobileVerif = true;
            }
            System.debug('Isactive= ' + Isactive);
            System.debug('DoctorRecordTypeId.equals(RecordTypeId) = ' + DoctorRecordTypeId.equals(RecordTypeId));
            System.debug('accMap.get(accountId) = ' + accMap.get(accountId));
            if (('有效'.equals(Isactive) || '有効'.equals(Isactive))
                && ('有効'.equals(accMap.get(accountId)) || '有效'.equals(accMap.get(accountId))) && (DoctorRecordTypeId.equals(RecordTypeId))) {
                res.isMobileVerif = true;
            }else {
                res.isMobileVerif = false;
            }
            res.status = 'success';
            return res;
        }catch(Exception e){
            res.message = e.getMessage() + ' ' + e.getLineNumber();
            res.status = 'fail';
            return res;
        }
    }
 
    public class ResponseV2{
        @AuraEnabled
        public List<Contact> contactList{set;get;}
        @AuraEnabled
        public String accountName{set;get;}
        @AuraEnabled
        public Map<String,String> dataIdManageCodeMap{set;get;}
        @AuraEnabled
        public Boolean isMobileVerif;
        @AuraEnabled
        public Boolean isNameMobileVerif;
        @AuraEnabled
        public String message{set;get;}
        @AuraEnabled
        public String status{set;get;}
    }
}