/* * 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 schemaMap = Schema.getGlobalDescribe(); // 字段信息 public static Map fieldMap = new Map(); @AuraEnabled public static ResponseBodyLWC initData(Id rid, String recordTypeId, String sobjectType, String accid) { ResponseBodyLWC res = new ResponseBodyLWC(); Map data = new Map(); 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)rbl.entity; } isDoctor = false; data.put('isDoctor', isDoctor); rbl.entity = data; return rbl; } } //说明无需加密 if (String.isNotBlank(accid)) { List 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)rbl.entity; } isDoctor = false; data.put('isDoctor', isDoctor); rbl.entity = data; return rbl; } } } //说明无需加密 if (String.isNotBlank(rid)) { List 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)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)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 = [select Id,Name from Account where Id = :accountId]; if(account.size() <= 0){ res.message = '没有找到对应客户'; res.status = 'fail'; return res; } List contactList = [select id,AWS_Data_Id__c, CManageCode__c,Name from Contact where AccountId = :account[0].Id]; Map dataIdManageCodeMap = new Map(); 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 accMap= new Map(); List 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 contactList{set;get;} @AuraEnabled public String accountName{set;get;} @AuraEnabled public Map dataIdManageCodeMap{set;get;} @AuraEnabled public Boolean isMobileVerif; @AuraEnabled public Boolean isNameMobileVerif; @AuraEnabled public String message{set;get;} @AuraEnabled public String status{set;get;} } }