public with sharing class LexNewAndEditBaseController { public static Map schemaMap = Schema.getGlobalDescribe(); // 字段信息 public static Map fieldMap = new Map(); public static ResponseBodyLWC initData(Id rid, String recordTypeId, String sobjectType) { try { System.debug('rid = ' + rid); System.debug('recordTypeId_20230711 = ' + recordTypeId); System.debug('sobjectType_20230711 =' + sobjectType); fieldMap = schemaMap.get(sobjectType).getDescribe().fields.getMap(); System.debug('fieldMap = ' + fieldMap); System.debug('fieldMap.containsKey(Postal_Code__c): ' + fieldMap.containsKey('Postal_Code__c')); ResponseBodyLWC res = new ResponseBodyLWC(); Map data = new Map(); res.entity = data; if (String.isBlank(recordTypeId)) { data.put('recordTypeId', LayoutDescriberHelper.getDefaultRecordType(sobjectType)); } //deloitte-zhj 2023/07/31 自定义元数据配置titleMap start Map> titleMap = new Map>(); List piLayoutConfigList = [SELECT id,DeveloperName, Layout_Header__c, Sobject_Type__c FROM LEX_PIPL_Layout_Config__mdt]; if(piLayoutConfigList.size() > 0){ for(LEX_PIPL_Layout_Config__mdt piLayoutConfig : piLayoutConfigList){ //titleMap.put(piLayoutConfig.Sobject_Type__c,JSON.deserialize(piLayoutConfig.Layout_Header__c, Map.class)); Map tempMap = (Map)JSON.deserializeUntyped(piLayoutConfig.Layout_Header__c); Map innerMap = new Map(); for (String key : tempMap.keySet()) { innerMap.put(key, (String)tempMap.get(key)); } titleMap.put(piLayoutConfig.Sobject_Type__c, innerMap); } } //deloitte-zhj 2023/07/31 自定义元数据配置titleMap end //编辑 if(!String.isBlank(rid)){ //获取对应对象的字段 List lso = Database.query('select id from RecordType where SobjectType = :sobjectType'); String sql = 'select '; DescribeSObjectResult objectType = rid.getSobjectType().getDescribe(); List objectFields = new List(objectType.fields.getMap().keySet()); sql += String.join(objectFields, ',') +' from '+sobjectType+' where id =\''+rid+'\' limit 1'; System.debug('sql = ' + sql); Sobject leadData = Database.query(sql); System.debug('leadData_20230711 = ' + leadData); if(leadData == null){ return new ResponseBodyLWC('Error',500, 'id不存在', ''); } // if(objectFields.contains('recordtypeid')){ // recordTypeId = (String)leadData.get('RecordTypeId'); // System.debug('recordTypeId_20230711_Debug = ' + recordTypeId); // } List layout = MetaDataUtility.GetRecordTypePageLayout(recordTypeId, sobjectType); System.debug('layout=' + layout); for (Metadata.LayoutSection section : layout) { if(titleMap.containsKey(sobjectType) && titleMap.get(sobjectType).containsKey(section.label)){ section.label = titleMap.get(sobjectType).get(section.label); } } data.put('layout', Json.serialize(reviseMetaLayouts(layout))); data.put('recordTypeId', recordTypeId); System.debug('data.recordTypeId: ' + data.get('recordTypeId')); //获取值 System.debug('leadData = ' + JSON.serialize(leadData)); data.put('data', leadData); }else { List layout = MetaDataUtility.GetRecordTypePageLayout(recordTypeId, sobjectType); System.debug('layout = ' + JSON.serialize(layout)); for (Metadata.LayoutSection section : layout) { if(titleMap.containsKey(sobjectType) && titleMap.get(sobjectType).containsKey(section.label)){ section.label = titleMap.get(sobjectType).get(section.label); } } data.put('layout', Json.serialize(reviseMetaLayouts(layout))); } res.status = 'Success'; res.code = 200; res.msg = ''; return res; } catch (Exception e) { System.debug('error = ' + e.getMessage() + ' line = ' + e.getLineNumber()); if(!Test.isRunningTest()){ return new ResponseBodyLWC('Error', 500, e.getMessage() + ' ' + e.getLineNumber(), ''); }else { return null; } } } public static ResponseBodyLWC queryAccount(String accountTypes, String accountId) { ResponseBodyLWC res = new ResponseBodyLWC(); Map data = new Map(); res.entity = data; System.debug('accountType = ' + accountTypes); System.debug('accountId = ' + accountId); try { List types = (List) 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', System.label.Agency_ID_c); } Map> m = new Map>(); 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', System.label.Agency_ID_c); acc.put('Name', 'Name'); } else { acc = Database.query('select Id,Name from Account where id=\'' + account.get(t) + '\''); } Map n = new Map(); 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 data = new Map(); res.entity = data; System.debug('accountId = ' + accountId); System.debug('searchKeyWord = ' + searchKeyWord); try { List conList = new List(); List noPIContactList = new List(); if (checkNullString(accountId) && checkNullString(searchKeyWord)) { conList = new List(); } else { if (checkNullString(accountId)) { conList = new List(); } else { //2022-5-12 yjk 将科室匹配改为医院匹配查询联系人 statt Account act = [SELECT id, Hospital__c FROM Account WHERE id = :accountId]; conList = new List( [ 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 awsIdToContactMap = new Map(); List conAWSIds = new List(); 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 标准metalayout */ public static List reviseMetaLayouts(List sections) { List result = new List(); 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(item.field == 'Consum_Apply_Equipment_Set__c'){ col.layoutItems.add(item); } if (item.emptySpace != true && (!fieldMap.containsKey(item.field) || !isUpdateable(fieldMap.get(item.field).getDescribe()))) { System.debug(item.field); continue; } // if(!isUpdateable(fieldMap.get(item.field).getDescribe())){ // item.behavior = 'Readonly'; // } col.layoutItems.add(item); } } } return result; } private static Boolean isUpdateable(Schema.DescribeFieldResult dfr) { return (new List{ 'Id', 'Name' }).contains(dfr.getName()) || dfr.isUpdateable(); } }