高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
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
global class NewAndEditContactController extends NewAndEditBaseController 
{
    public String unifiedIContactID{set;get;}
    public String staticResourceContactV2 {get; set;}
    
    
    public NewAndEditContactController(ApexPages.StandardController controller) {
        List<String> fieldList = new List<String>(Schema.getGlobalDescribe().get('Contact').getDescribe().fields.getMap().keyset());  
        // Add fields to controller. This is to avoid the SOQL error in visualforce page
        if (!Test.isRunningTest()) {
            controller.addFields(fieldList);
        }
        Init(controller.getRecord());
        String contactId = controller.getRecord().Id;
        if(contactId != null){
            Contact c = [select id,UnifiedI_Contact_ID__c from Contact where Id =:contactId ];
            system.debug('Contact c = '+c);
            unifiedIContactID = c.UnifiedI_Contact_ID__c;
        }else{
            Map<string,string> mso = ApexPages.currentPage().getParameters();
            system.debug('mso='+mso);
            if(mso.containsKey('con4_lkid')){
                controller.getRecord().put('AccountId',mso.get('con4_lkid'));
            }
        }
        system.debug('controller.getRecord()='+controller.getRecord());
        //zhj MEBG新方案改造 2022-11-24 start
        PIHelper.PIIntegration piIntegration = PIHelper.getPIIntegrationInfo('contactV2');
        staticResourceContactV2 = JSON.serialize(piIntegration);
        System.debug('staticResourceContactV2 = ' + staticResourceContactV2);
        //zhj MEBG新方案改造 2022-11-24 end
    }
    
    PageReference RedirectStandardPage(){
        Map<string,string> mso = ApexPages.currentPage().getParameters();
        system.debug(mso);
        PageReference pg = null;
        mso.remove('sfdc.override');
        system.debug('recordId='+recordId);
        if(string.isBlank(recordId)){
            pg = new PageReference('/003/e');
        }else{
            pg = new PageReference('/'+recordId+'/e');
        }
        //pg.getParameters().putAll(mso);
        pg.getParameters().put('RecordType',mso.get('RecordType'));
        pg.getParameters().put('accid',mso.get('accid'));
        pg.getParameters().put('nooverride','1');
        pg.setRedirect(true);
        return pg;
    }
 
    public PageReference PageLoad(){
        system.debug('rtTypeId='+rtTypeId);
        string s = null;
        if(!string.isBlank(rtTypeId)){
            s = Schema.SObjectType.Contact.getRecordTypeInfosById().get(rtTypeId).getDeveloperName();
            if(s == 'Agency' || s == 'Internal_staff'){
                return RedirectStandardPage();
            }
        }
        string accid = ApexPages.currentPage().getParameters().get('accid');
        if(!string.isBlank(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'){
                    return RedirectStandardPage();
                }
            }
            
            
        }
        system.debug('null');
        return null;
    }
    
    @RemoteAction
    global static Response saveContact(String leadJson,String transId,Boolean isNew) {
        return save(new Contact(),leadJson,transId,isNew);
    }
 
    //zhj MEBG新方案改造 2022-11-24 start
    @RemoteAction
    global static ResponseV2 searchContactByAccountId(String accountId,String RecordTypeId,String Isactive) {
        System.debug('accountId = ' + accountId);
        ResponseV2 res = new ResponseV2();
        try{
            Account account = [select Id,Name from Account where Id = :accountId];
            List<Contact> contactList = [select id,AWS_Data_Id__c, CManageCode__c,Name from Contact where AccountId = :account.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.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() + '';
            res.status = 'fail';
            return res;
        }
    }
 
    global class ResponseV2{
        public List<Contact> contactList{set;get;}
        public String accountName{set;get;}
        public Map<String,String> dataIdManageCodeMap{set;get;}
        public Boolean isMobileVerif;
        public Boolean isNameMobileVerif;
        public String message{set;get;}
        public String status{set;get;}
    }
    //zhj MEBG新方案改造 2022-11-24 end
}