| | |
| | | |
| | | @RestResource(urlMapping='/NFM704/*') |
| | | global with sharing class NFM704Rest { |
| | | |
| | | //add Response to aws 20220421 add sushanhu start |
| | | |
| | | static Boolean SFStatus=true; |
| | | static String SFMessage=''; |
| | | //add Response to aws 20220421 add sushanhu end |
| | | global class GeDatas { |
| | | public NFMUtil.Monitoring Monitoring; |
| | | public GeData[] GeData; |
| | |
| | | public static final String LOG_TYPE = 'NFM704'; |
| | | |
| | | global class GeData { |
| | | public String StaffMCode; //SFDC人员管理编码 |
| | | public String StaffMCode; //人员管理编码OBPM |
| | | public String HospitalMCode; //医院管理编码 |
| | | public String OfficeMCode; //科室管理编码 |
| | | public String OfficeMCode; //OBPM科室 |
| | | public String HcpNo; //HPC编码 |
| | | public String HCPLevel; //HCP等级 |
| | | public String Name; //姓名 |
| | | public String Mobile; //电话 |
| | | public String State; //省 |
| | | public String City; //市 |
| | | public String WorkingSeniority; //临床工作年限 |
| | | public String TechnicalTitle; //技术职称 |
| | | public String Speciality; //擅长的手术 |
| | | public String ProfessionalField; //专业领域 |
| | | public String Society1; //学会名称 |
| | | public String EventStatus; //学会职称 // 带有箭头 切割获取EventStatuslist pi改造之后 存*** |
| | | //add for pipl by sushanhu 20220420 start |
| | | // public String HCPLevelEncrypted; //HCP等级密文 //zhj新方案改造 2022-12-07 |
| | | // public String NameEncrypted; //姓名 //zhj新方案改造 2022-12-07 |
| | | // public String MobileEncrypted; //电话 //zhj新方案改造 2022-12-07 |
| | | // public String TechnicalTitleEncrypted; //技术职称 //zhj新方案改造 2022-12-07 |
| | | // public String SpecialityEncrypted; //擅长的手术 //zhj新方案改造 2022-12-07 |
| | | // public String ProfessionalFieldEncrypted; //专业领域 //zhj新方案改造 2022-12-07 |
| | | // public List<String> EventStatusEncryptedList; //学会职称 备注有逻辑 带有箭头 切割获取EventStatuslist 存hash //zhj新方案改造 2022-12-07 |
| | | public String DataId;//AWSDATAID |
| | | //public String WorkingSeniorityEncrypted;//临床工作年限密文 |
| | | //add for pipl by sushanhu 20220420 end //zhj新方案改造 2022-12-07 |
| | | } |
| | | |
| | | @HttpPost |
| | |
| | | //取得接口传输内容 |
| | | String strData = RestContext.request.requestBody.toString(); |
| | | GeDatas ges = (GeDatas) JSON.deserializeStrict(strData, GeDatas.class); |
| | | |
| | | //add Response to aws 20220421 add sushanhu start |
| | | NFMUtil.NFMResponse result = NFMUtil.getNFMResponse(); |
| | | //add Response to aws 20220421 add sushanhu end |
| | | if(ges == null) { |
| | | return; |
| | | } |
| | |
| | | RestResponse res = RestContext.response; |
| | | res.addHeader('Content-Type', 'application/json'); |
| | | res.statusCode = 200; |
| | | String jsonResponse = '{"Result":{"Result": "00", "Message":""}}'; |
| | | // String jsonResponse = '{"Result":{"Result": "00", "Message":""}}'; |
| | | // res.responseBody = blob.valueOf(jsonResponse); |
| | | //updata response toAWS sushanhu for pipl 20220421 start |
| | | result.SFStatus=SFStatus; |
| | | result.SFMessage=SFMessage; |
| | | //String jsonResponse =JSON.serialize(result); |
| | | String jsonResponse ='{"SFMessage":"","staticResponse":{"Result":{"Result":"00","Message":""}},"SFStatus":true}'; |
| | | system.debug('result---'+jsonResponse); |
| | | res.responseBody = blob.valueOf(jsonResponse); |
| | | //updata response toAWS sushanhu for pipl 20220421 end |
| | | return; |
| | | |
| | | } |
| | |
| | | |
| | | Savepoint sp = Database.setSavepoint(); |
| | | |
| | | // 704改善 2023-02-09 ssm start |
| | | // 增加一个标记,当回传数据里,医院管理编码为空时,报错但不重发 |
| | | Boolean error_without_resend = false; |
| | | // 704改善 2023-02-09 ssm end |
| | | |
| | | try{ |
| | | //管理编码List |
| | | List<String> DoctorNoList = new List<String>(); |
| | | |
| | | //待更新的客户人员List |
| | | List<Contact> updateList = new List<Contact>(); |
| | | List<Contact> upsertList = new List<Contact>(); |
| | | |
| | | //科室编码List |
| | | List<String> officeMCodeList = new List<String>(); |
| | | //医院编码List |
| | | List<String> HospitalMCodeList = new List<String>(); |
| | | |
| | | |
| | | for(GeData ged : itemMasterList){ |
| | | String dataComplete = verify(ged); |
| | |
| | | continue; |
| | | } |
| | | DoctorNoList.add(ged.StaffMCode); |
| | | officeMCodeList.add(ged.OfficeMCode); |
| | | //officeMCodeList.add(ged.OfficeMCode); |
| | | HospitalMCodeList.add(ged.HospitalMCode); |
| | | } |
| | | |
| | | system.debug('HospitalMCodeList=============>'+HospitalMCodeList); |
| | | system.debug('DoctorNoList=============>'+DoctorNoList); |
| | | //Map<String, Map<String,Contact>> hospitalMap = new Map<String, Map<String,Contact>>(); |
| | | Map<String, Contact> conListMap = new Map<String, Contact>(); |
| | | List<Contact> conList = [select Id, |
| | | CManageCode__c, //人员管理编码 |
| | | Account.Hospital_Name__c, //医院名称 |
| | | Account.Department_Name__c, //科室名称 |
| | | Name, //姓名 |
| | | Phone, //电话 |
| | | HcpNo__c, //HCP编码 |
| | | Isactive__c, //是否有效 |
| | | UpdateStatus__c //操作类型 |
| | | from Contact WHERE CManageCode__c IN:DoctorNoList order by AccountId]; |
| | | |
| | | Management_Code__c, //医院管理编码 |
| | | CManageCode__c //人员管理编码 |
| | | from Contact WHERE CManageCode__c IN:DoctorNoList |
| | | and CManageCode__c != null]; |
| | | system.debug('conList============>'+conList); |
| | | |
| | | for(Contact con : conList ){ |
| | | |
| | | conListMap.put(con.CManageCode__c, con); |
| | | //hospitalMap.put(con.Management_Code__c,conListMap); |
| | | } |
| | | |
| | | //Management_Code__c |
| | | List<Account> accList = [select Id, Name, Management_Code__c from Account where Management_Code__c in :officeMCodeList]; |
| | | |
| | | List<Account> accList = [select Id, Name,GI_Main__c,Management_Code__c from Account where Management_Code__c in :HospitalMCodeList]; |
| | | system.debug('accList=============>'+accList); |
| | | Map<String, Account> accMap = new Map<String, Account>(); |
| | | |
| | | for(Account acc : accList){ |
| | | accMap.put(acc.Management_Code__c, acc); |
| | | accMap.put(acc.Management_Code__c, acc); |
| | | } |
| | | |
| | | |
| | | for( GeData ged : itemMasterList ){ |
| | | |
| | | Contact con = new Contact(); |
| | | |
| | | logstr += conListMap.get(ged.StaffMCode).Id; |
| | | |
| | | if(conListMap.containsKey(ged.StaffMCode)){ |
| | | |
| | | logstr += '已存在客户人员\n'; |
| | | con.Id = conListMap.get(ged.StaffMCode).Id; |
| | | |
| | | }else { |
| | | logstr += '不存在的客户人员\n'; |
| | | //Map<String, Contact> tempMap = new Map<String, Contact>(); |
| | | if(accMap.containsKey(ged.HospitalMCode)){//医院编码是否存在 是 |
| | | Contact con = new Contact(); |
| | | if(conListMap.containsKey(ged.StaffMCode)){ |
| | | //存在则更新 |
| | | system.debug('更新联系人'); |
| | | logstr += conListMap.get(ged.StaffMCode).Id + '\n'; |
| | | logstr += '已存在客户人员\n'; |
| | | con.Id = conListMap.get(ged.StaffMCode).Id; |
| | | system.debug('request'+conListMap.get(ged.StaffMCode).Management_Code__c.equals(ged.HospitalMCode)); |
| | | if(conListMap.get(ged.StaffMCode).Management_Code__c.equals(ged.HospitalMCode)){//判断联系人上的管理编码和接口传输过来的管理编码是否一致 |
| | | system.debug('request'+conListMap.get(ged.StaffMCode).Management_Code__c.equals(ged.HospitalMCode)); |
| | | }else{ |
| | | con.OBPMHospital__c = accMap.get(ged.HospitalMCode).Id;//接收的管理编码对应的医院写到OBPM医院上 |
| | | } |
| | | con = assignment(ged,con); |
| | | }else{ |
| | | //不存在则新建 |
| | | system.debug('新建联系人'); |
| | | //logstr += '不存在的客户人员\n'; |
| | | con.OwnerId = accMap.get(ged.HospitalMCode).GI_Main__c;//所有人取医院上的消化科担当 |
| | | con.AccountId = accMap.get(ged.HospitalMCode).Id;//新建联系人放到医院下 |
| | | con.LastName = ged.Name; |
| | | // add by sushanhu for pipl 20220420 start |
| | | //con.LastName_Encrypted__c =ged.NameEncrypted; //zhj新方案改造 2022-12-07 |
| | | // add by sushanhu for pipl 20220420 end |
| | | con.FirstName = ''; |
| | | con = assignment(ged,con); |
| | | } |
| | | upsertList.add(con); |
| | | }else{//否 |
| | | // continue; |
| | | logstr += '不存在的医院管理编码:['+accMap.get(ged.HospitalMCode)+']/n'; |
| | | // 704改善 2023-02-09 ssm start |
| | | // 设置标记为true |
| | | error_without_resend = true; |
| | | // 704改善 2023-02-09 ssm end |
| | | throw new ControllerUtil.myException('不存在的医院管理编码:['+accMap.get(ged.HospitalMCode)+']'); |
| | | } |
| | | |
| | | //AccountId |
| | | if( accMap.get(ged.OfficeMCode) != null ){ |
| | | con.AccountId = accMap.get(ged.OfficeMCode).Id; |
| | | }else { |
| | | logstr += '当前科室id有误或不存在'; |
| | | } |
| | | // //AccountId |
| | | // if( accMap.get(ged.OfficeMCode) != null ){ |
| | | // con.AccountId = accMap.get(ged.OfficeMCode).Id; |
| | | // }else { |
| | | // logstr += '当前科室id有误或不存在'; |
| | | // } |
| | | |
| | | con.HcpNo__c = ged.HcpNo; |
| | | con.HCPLevel__c = ged.HCPLevel; |
| | | con.LastName = ged.Name; |
| | | con.MobilePhone = ged.Mobile; |
| | | // con.HcpNo__c = ged.HcpNo; |
| | | // con.HCPLevel__c = ged.HCPLevel; |
| | | // con.LastName = ged.Name; |
| | | // con.MobilePhone = ged.Mobile; |
| | | |
| | | conListMap.put(ged.StaffMCode, con); |
| | | |
| | | // conListMap.put(ged.StaffMCode, con); |
| | | } |
| | | |
| | | if(conListMap.size() > 0 ){ |
| | | system.debug('upsertList==================>'+upsertList); |
| | | if(upsertList.size() > 0 ){ |
| | | // Update updateList; |
| | | UpSert conListMap.values(); |
| | | Oly_TriggerHandler.bypass('ContactTriggerHandler'); |
| | | UpSert upsertList; |
| | | } |
| | | |
| | | rowData.retry_cnt__c = 0; |
| | |
| | | logstr += '\n' + ex.getMessage(); |
| | | iflog.ErrorLog__c = ex.getMessage() + '\n' + ex.getStackTraceString() + '\n' + iflog.ErrorLog__c; |
| | | // 异常重发 |
| | | rowData = NFMUtil.LogAutoSend(rowData, ex, null); |
| | | // 704改善 2023-02-09 ssm start |
| | | if (error_without_resend) { |
| | | // retry_cnt设置为0 |
| | | rowData.retry_cnt__c = 0; |
| | | logstr += '\nend'; |
| | | rowData.ErrorLog__c += ex.getMessage() + '\n' + ex.getStackTraceString() + '\n'; |
| | | iflog.ErrorLog__c += ex.getMessage() + '\n' + ex.getStackTraceString() + '\n'; |
| | | iflog.Log__c += logstr; |
| | | upsert iflog; |
| | | upsert rowData; |
| | | } else { |
| | | rowData = NFMUtil.LogAutoSend(rowData, ex, null); |
| | | } |
| | | // 704改善 2023-02-09 ssm end |
| | | } |
| | | iflog.Log__c = logstr; |
| | | upsert iflog; |
| | | upsert rowData; |
| | | } |
| | | |
| | | public static String verify(GeData ged){ |
| | |
| | | if (ged.HospitalMCode == null) { |
| | | result += 'DataError: 医院管理编码 [ HospitalMCode ] is null!\n'; |
| | | } |
| | | if (ged.OfficeMCode == null) { |
| | | result += 'DataError: 科室管理编码 [ OfficeMCode ] is null!\n'; |
| | | } |
| | | // if (ged.OfficeMCode == null) { |
| | | // result += 'DataError: 科室管理编码 [ OfficeMCode ] is null!\n'; |
| | | // } |
| | | if (ged.HcpNo == null) { |
| | | result += 'DataError: HCP编码 [ HcpNo ] is null!\n'; |
| | | } |
| | |
| | | return result; |
| | | } |
| | | |
| | | public static Contact assignment(GeData ged,Contact con){//联系人数据赋值方法 |
| | | List<String> societyList = Breakup(ged.Society1); |
| | | List<String> eventStatusList = Breakup(ged.EventStatus); |
| | | con.NameOBPM__c = ged.Name;//姓名 |
| | | con.MobileOBPM__c = ged.Mobile;//电话 |
| | | con.stateOBPM__c = ged.State;//省OBPM |
| | | con.CityOBPM__c = ged.City;//市OBPM |
| | | con.HcpNo__c = ged.HcpNo;//HPC编码 |
| | | con.HCPLevel__c = ged.HCPLevel;//HCP等级 |
| | | con.OBPMDepartment__c = ged.OfficeMCode;//OBPM科室 |
| | | con.WorkingSeniorityOBPM__c = ged.WorkingSeniority; //临床工作年限 |
| | | con.TechnicalTitleOBPM__c = ged.TechnicalTitle;//技术职称 |
| | | con.SpecialityOBPM__c = ged.Speciality;//擅长的手术 |
| | | con.ProfessionalField__c = ged.ProfessionalField;//专业领域 |
| | | //add by sushanhu 20220420 for pipl start |
| | | // con.HCPLevel_Encrypted__c = ged.HCPLevelEncrypted; //zhj新方案改造 2022-12-07 |
| | | // con.NameOBPM_Encrypted__c = ged.NameEncrypted; //zhj新方案改造 2022-12-07 |
| | | // con.MobileOBPM_Encrypted__c = ged.MobileEncrypted; //zhj新方案改造 2022-12-07 |
| | | // con.WorkingSeniorityOBPM_Encrypted__c = ged.WorkingSeniorityEncrypted; //zhj新方案改造 2022-12-07 |
| | | // con.TechnicalTitleOBPM_Encrypted__c = ged.TechnicalTitleEncrypted; //zhj新方案改造 2022-12-07 |
| | | // con.ProfessionalField_Encrypted__c = ged.ProfessionalFieldEncrypted; //zhj新方案改造 2022-12-07 |
| | | // con.SpecialityOBPM_Encrypted__c = ged.SpecialityEncrypted; //zhj新方案改造 2022-12-07 |
| | | con.AWS_Data_Id__c = ged.DataId; |
| | | //add by sushanhu 20220420 for pipl end |
| | | |
| | | if(societyList.size()>0){ |
| | | con.Learn_name1__c = societyList[0];//学会名称1 |
| | | } |
| | | if(societyList.size()>1){ |
| | | con.Learn_name2__c = societyList[1];//学会名称2 |
| | | } |
| | | if(societyList.size()>2){ |
| | | con.Learn_name3__c = societyList[2];//学会名称3 |
| | | } |
| | | if(eventStatusList.size()>0){ |
| | | con.Learn_serve1__c = eventStatusList[0];//学会职称1 |
| | | // add by sushanhu for pipl 20220420 start |
| | | //zhj新方案改造 2022-12-07 start |
| | | // if(ged.EventStatusEncryptedList.size()>0){ |
| | | // con.Learn_serve1_Encrypted__c =ged.EventStatusEncryptedList[0]; |
| | | // } |
| | | //zhj新方案改造 2022-12-07 end |
| | | // add by sushanhu for pipl 20220420 end |
| | | } |
| | | if(eventStatusList.size()>1){ |
| | | con.Learn_serve2__c = eventStatusList[1];//学会职称2 |
| | | // add by sushanhu for pipl 20220420 start |
| | | //con.Learn_serve2_Encrypted__c =ged.EventStatusEncryptedList[1]; //zhj新方案改造 2022-12-07 |
| | | // add by sushanhu for pipl 20220420 end |
| | | } |
| | | if(eventStatusList.size()>2){ |
| | | con.Learn_serve3__c = eventStatusList[2];//学会职称3 |
| | | // add by sushanhu for pipl 20220420 start |
| | | //con.Learn_serve3_Encrypted__c =ged.EventStatusEncryptedList[2]; //zhj新方案改造 2022-12-07 |
| | | // add by sushanhu for pipl 20220420 end |
| | | } |
| | | return con; |
| | | } |
| | | |
| | | public static List<String> Breakup (String str){ |
| | | // List<string> over = new List<string>(); |
| | | // over = str.split('↑'); |
| | | List<string> over = str.split('↑'); |
| | | return over; |
| | | } |
| | | } |