| | |
| | | |
| | | //存放所有签收单录入表id |
| | | List < String > luruIsLastSubmitList = new List < String > (); |
| | | |
| | | // 2023-03-16 ssm 优化逻辑,避免同时多设备做系统更新以及医院和经销商在同一批次(15分钟内)上传数据 start |
| | | //判断是否有未处理的录入表 |
| | | Map < Id, eSignFormEntry__c > unprocessedESignEneryMap = new Map < Id, eSignFormEntry__c > (); |
| | | // Map < Id, eSignFormEntry__c > unprocessedESignEneryMap = new Map < Id, eSignFormEntry__c > (); |
| | | Map < Id, List<eSignFormEntry__c> > unprocessedESignEneryMap = new Map < Id, List<eSignFormEntry__c> > (); |
| | | List<eSignFormEntry__c> unprocessedEntries = new List<eSignFormEntry__c>(); |
| | | // Map <Id, eSignFormEntry__c> unprocessedEntries = new Map<Id, eSignFormEntry__c>(); |
| | | // 2023-03-16 ssm 优化逻辑,避免同时多设备做系统更新以及医院和经销商在同一批次(15分钟内)上传数据 start |
| | | |
| | | //用于判断删除驳回的附件的筛选条件 |
| | | Map < Id, eSignForm__c > rejectESignEneryMap = new Map < Id, eSignForm__c > (); |
| | |
| | | eSignStringMap.put(eSignFormEntryWhole.Id, eSignFormEntryWhole); |
| | | //②所有的 用于更新文件(包含已处理未处理的数据 ) |
| | | fileIdList.add(eSignFormEntryWhole.Id); |
| | | if (eSignFormEntryWhole.IsHandled__c == false) { |
| | | // 这里是什么鬼?都不判断一下签收单id的? |
| | | // if (eSignFormEntryWhole.IsHandled__c == false) { |
| | | if (eSignFormEntryWhole.IsHandled__c == false && eSignFormEntryWhole.eSignForm__r.Id == eid) { |
| | | //未处理的 |
| | | unprocessedESignEneryMap.put(eid, eSignFormEntryWhole); |
| | | // 2023-03-16 ssm 优化逻辑,避免同时多设备做系统更新以及医院和经销商在同一批次(15分钟内)上传数据 start |
| | | // unprocessedESignEneryMap.put(eid, eSignFormEntryWhole); |
| | | List<eSignFormEntry__c> entries = unprocessedESignEneryMap.size() > 0 && unprocessedESignEneryMap.keySet().contains(eid) ? unprocessedESignEneryMap.get(eid) : new List<eSignFormEntry__c>(); |
| | | entries.add(eSignFormEntryWhole); |
| | | unprocessedESignEneryMap.put(eid, entries); |
| | | // 2023-03-16 ssm 优化逻辑,避免同时多设备做系统更新以及医院和经销商在同一批次(15分钟内)上传数据 end |
| | | } |
| | | if (eSignFormEntryWhole.eSignForm__r.Id == eid) { |
| | | //存放 签收单id,录入表id 文件用 |
| | |
| | | boolean IsHPSubmit = false; |
| | | //销售渠道 |
| | | String Sales_Root_Formula; |
| | | //录入类型 |
| | | String type; |
| | | //录入类型 |
| | | String type; // 这东西没有用 |
| | | System.debug('lasteSignFormEntryMap:' + lasteSignFormEntryMap); |
| | | if (lasteSignFormEntryMap.containsKey(eSignFormid)) { |
| | | eSignForm.id = eSignFormid; |
| | | // 2023-03-16 ssm 优化逻辑,避免同时多设备做系统更新以及医院和经销商在同一批次(15分钟内)上传数据 start |
| | | //签收单id |
| | | eSignFormEntry__c eSignFormEntry = lasteSignFormEntryMap.get(eSignFormid); |
| | | //如果经销商确认日为空的话 进去判断更新经销商审批状态 |
| | | if (eSignFormEntry.agencyDNSignUpStatus__c != '签收已完成') { |
| | | if (eSignFormEntry.agencyConfirmDateBack__c == null) { |
| | | if (eSignFormEntry.IsSubmit__c == true) { |
| | | eSignForm.agencyAutoSignUpStatus__c = '申请中'; |
| | | eSignForm.agencyReject__c = false; |
| | | } else { |
| | | if (eSignFormEntry.agencyScanDayBack__c != null && eSignFormEntry.IsAgencyScan__c) { |
| | | eSignForm.agencyAutoSignUpStatus__c = '草案中'; |
| | | eSignForm.agencyReject__c = false; |
| | | |
| | | // eSignFormEntry__c eSignFormEntry = lasteSignFormEntryMap.get(eSignFormid); |
| | | for (eSignFormEntry__c eSignFormEntry : unprocessedESignEneryMap.get(eSignFormid)) { |
| | | // 根据录入类型去更新对应的部分数据 |
| | | // entryType__c包含经销商 |
| | | if (String.isNotBlank(eSignFormEntry.entryType__c) && eSignFormEntry.entryType__c.contains('经销商')) { |
| | | //如果经销商确认日为空的话 进去判断更新经销商审批状态 |
| | | if (eSignFormEntry.agencyDNSignUpStatus__c != '签收已完成') { |
| | | if (eSignFormEntry.agencyConfirmDateBack__c == null) { |
| | | if (eSignFormEntry.IsSubmit__c == true) { |
| | | eSignForm.agencyAutoSignUpStatus__c = '申请中'; |
| | | eSignForm.agencyReject__c = false; |
| | | } else { |
| | | if (eSignFormEntry.agencyScanDayBack__c != null && eSignFormEntry.IsAgencyScan__c) { |
| | | // 调整草案中的赋值逻辑,多端操作的情况下有可能先申请后草案 |
| | | // eSignForm.agencyAutoSignUpStatus__c = '草案中'; |
| | | eSignForm.agencyAutoSignUpStatus__c = String.isBlank(eSignForm.agencyAutoSignUpStatus__c) ? '草案中' : eSignForm.agencyAutoSignUpStatus__c; |
| | | eSignForm.agencyReject__c = false; |
| | | } |
| | | } |
| | | } |
| | | //未更新前的经销商审批状态 用于文件累计汇总 |
| | | if(eSignFormEntry.agencyAutoSignUpStatus__c!=null &&eSignFormEntry.agencyAutoSignUpStatus__c!=''){ |
| | | oldESignAgencyStatusMap.put('A' + eSignForm.id, eSignFormEntry.agencyAutoSignUpStatus__c); |
| | | }else{ |
| | | oldESignAgencyStatusMap.put('A' + eSignForm.id, '无'); |
| | | } |
| | | } |
| | | //如果没变化则不更新 |
| | | if (eSignFormEntry.AgencyWorkflowEmailBack__c != eSignFormEntry.AgencyWorkflowEmail__c) { |
| | | //经销商邮件 |
| | | eSignForm.AgencyWorkflowEmail__c = eSignFormEntry.AgencyWorkflowEmailBack__c; |
| | | } |
| | | // 日期更新 |
| | | if (eSignFormEntry.agencyDNSignUpStatus__c != '签收已完成') { |
| | | //经销商扫描日 |
| | | if (eSignFormEntry.agencyScanDayBack__c != null) { |
| | | eSignForm.agencyScanDay__c = eSignFormEntry.agencyScanDayBack__c; |
| | | } |
| | | //经销商签收日 |
| | | if (eSignFormEntry.agencySignUpDateBack__c != null) { |
| | | eSignForm.agencySignUpDate__c = eSignFormEntry.agencySignUpDateBack__c; |
| | | } |
| | | //经销商确认日 |
| | | if (eSignFormEntry.agencyConfirmDateBack__c != null) { |
| | | eSignForm.agencyConfirmDate__c = eSignFormEntry.agencyConfirmDateBack__c; |
| | | } |
| | | } |
| | | } |
| | | //未更新前的经销商审批状态 用于文件累计汇总 |
| | | if(eSignFormEntry.agencyAutoSignUpStatus__c!=null &&eSignFormEntry.agencyAutoSignUpStatus__c!=''){ |
| | | oldESignAgencyStatusMap.put('A' + eSignForm.id, eSignFormEntry.agencyAutoSignUpStatus__c); |
| | | }else{ |
| | | oldESignAgencyStatusMap.put('A' + eSignForm.id, '无'); |
| | | } |
| | | |
| | | } |
| | | if (eSignFormEntry.HPDNSignUpStatus__c != '签收已完成') { |
| | | //如果医院确认日为空的话 进去判断更新医院审批状态 |
| | | if (eSignFormEntry.salesHPManageConfirmDate__c == null) { |
| | | if (eSignFormEntry.IsHPSubmit__c == true) { |
| | | eSignForm.HPSignUpStatus__c = '申请中'; |
| | | eSignForm.HPReject__c = false; |
| | | } else { |
| | | if (eSignFormEntry.HPScanDayBack__c != null && eSignFormEntry.IsHPScan__c) { |
| | | eSignForm.HPSignUpStatus__c = '草案中'; |
| | | eSignForm.HPReject__c = false; |
| | | |
| | | // entryType__c包含医院 |
| | | if (String.isNotBlank(eSignFormEntry.entryType__c) && eSignFormEntry.entryType__c.contains('医院')) { |
| | | if (eSignFormEntry.HPDNSignUpStatus__c != '签收已完成') { |
| | | //如果医院确认日为空的话 进去判断更新医院审批状态 |
| | | if (eSignFormEntry.salesHPManageConfirmDate__c == null) { |
| | | if (eSignFormEntry.IsHPSubmit__c == true) { |
| | | eSignForm.HPSignUpStatus__c = '申请中'; |
| | | eSignForm.HPReject__c = false; |
| | | } else { |
| | | if (eSignFormEntry.HPScanDayBack__c != null && eSignFormEntry.IsHPScan__c) { |
| | | // 调整草案中的赋值逻辑,多端操作的情况下有可能先申请后草案 |
| | | // eSignForm.HPSignUpStatus__c = '草案中'; |
| | | eSignForm.HPSignUpStatus__c = String.isBlank(eSignForm.HPSignUpStatus__c) ? '草案中' : eSignForm.HPSignUpStatus__c; |
| | | eSignForm.HPReject__c = false; |
| | | } |
| | | } |
| | | } |
| | | //未更新前的医院审批状态 用于文件累计汇总 |
| | | if(eSignFormEntry.HPSignUpStatus__c!=null &&eSignFormEntry.HPSignUpStatus__c!=''){ |
| | | oldESignHPStatusMap.put('H' + eSignForm.id, eSignFormEntry.HPSignUpStatus__c); |
| | | }else{ |
| | | oldESignHPStatusMap.put('H' + eSignForm.id, '无'); |
| | | } |
| | | } |
| | | //如果没变化则不更新 |
| | | if (eSignFormEntry.HPWorkflowEmailBack__c != eSignFormEntry.HPWorkflowEmail__c) { |
| | | //医院邮件 |
| | | eSignForm.HPWorkflowEmail__c = eSignFormEntry.HPWorkflowEmailBack__c; |
| | | } |
| | | // 日期更新 |
| | | if (eSignFormEntry.HPDNSignUpStatus__c != '签收已完成') { |
| | | //医院扫描日 |
| | | if (eSignFormEntry.HPScanDayBack__c != null) { |
| | | eSignForm.HPScanDay__c = eSignFormEntry.HPScanDayBack__c; |
| | | } |
| | | //医院签收日 |
| | | if (eSignFormEntry.HPSignUpDateBack__c != null) { |
| | | eSignForm.HPSignUpDate__c = eSignFormEntry.HPSignUpDateBack__c; |
| | | } |
| | | //医院确认日 |
| | | if (eSignFormEntry.HPConfirmDateBack__c != null) { |
| | | eSignForm.HPConfirmDate__c = eSignFormEntry.HPConfirmDateBack__c; |
| | | } |
| | | } |
| | | } |
| | | //未更新前的医院审批状态 用于文件累计汇总 |
| | | if(eSignFormEntry.HPSignUpStatus__c!=null &&eSignFormEntry.HPSignUpStatus__c!=''){ |
| | | oldESignHPStatusMap.put('H' + eSignForm.id, eSignFormEntry.HPSignUpStatus__c); |
| | | }else{ |
| | | oldESignHPStatusMap.put('H' + eSignForm.id, '无'); |
| | | } |
| | | |
| | | } |
| | | //给营业助理赋值 |
| | | //eSignForm.Sales_assistant_name_text__c = eSignFormEntry.Sales_assistant_ID__c;// Commented By Li Jun 20230420 |
| | | //存一个id |
| | | idlast = eSignFormEntry.Id; |
| | | //签收单name用作文件命名 |
| | | name = eSignFormEntry.eSignForm__r.Name; |
| | | //是否经销商提交 |
| | | IsSubmit = eSignFormEntry.IsSubmit__c; |
| | | //是否医院提交 |
| | | IsHPSubmit = eSignFormEntry.IsHPSubmit__c; |
| | | //最后录入表 |
| | | eSignForm.finalUpadteFrom__c = eSignFormEntry.Id; |
| | | //销售渠道 区分直销还是分销 |
| | | Sales_Root_Formula = eSignFormEntry.Sales_Root_Formula__c; |
| | | //录入类型 |
| | | type = eSignFormEntry.entryType__c; // 没有用 |
| | | |
| | | //如果没变化则不更新 |
| | | if (eSignFormEntry.AgencyWorkflowEmailBack__c != eSignFormEntry.AgencyWorkflowEmail__c) { |
| | | //经销商邮件 |
| | | eSignForm.AgencyWorkflowEmail__c = eSignFormEntry.AgencyWorkflowEmailBack__c; |
| | | // 所有没有没有处理的entry都要标记为处理 |
| | | eSignFormEntry.IsHandled__c = true; |
| | | unprocessedEntries.add(eSignFormEntry); |
| | | // unprocessedEntries.put(eSignFormEntry.Id, eSignFormEntry); |
| | | } |
| | | //如果没变化则不更新 |
| | | if (eSignFormEntry.HPWorkflowEmailBack__c != eSignFormEntry.HPWorkflowEmail__c) { |
| | | //医院邮件 |
| | | eSignForm.HPWorkflowEmail__c = eSignFormEntry.HPWorkflowEmailBack__c; |
| | | } |
| | | if (eSignFormEntry.agencyDNSignUpStatus__c != '签收已完成') { |
| | | //经销商扫描日 |
| | | if (eSignFormEntry.agencyScanDayBack__c != null) { |
| | | eSignForm.agencyScanDay__c = eSignFormEntry.agencyScanDayBack__c; |
| | | } |
| | | //经销商签收日 |
| | | if (eSignFormEntry.agencySignUpDateBack__c != null) { |
| | | eSignForm.agencySignUpDate__c = eSignFormEntry.agencySignUpDateBack__c; |
| | | } |
| | | //经销商确认日 |
| | | if (eSignFormEntry.agencyConfirmDateBack__c != null) { |
| | | eSignForm.agencyConfirmDate__c = eSignFormEntry.agencyConfirmDateBack__c; |
| | | } |
| | | } |
| | | |
| | | if (eSignFormEntry.HPDNSignUpStatus__c != '签收已完成') { |
| | | //医院扫描日 |
| | | if (eSignFormEntry.HPScanDayBack__c != null) { |
| | | eSignForm.HPScanDay__c = eSignFormEntry.HPScanDayBack__c; |
| | | } |
| | | //医院签收日 |
| | | if (eSignFormEntry.HPSignUpDateBack__c != null) { |
| | | eSignForm.HPSignUpDate__c = eSignFormEntry.HPSignUpDateBack__c; |
| | | } |
| | | //医院确认日 |
| | | if (eSignFormEntry.HPConfirmDateBack__c != null) { |
| | | eSignForm.HPConfirmDate__c = eSignFormEntry.HPConfirmDateBack__c; |
| | | } |
| | | } |
| | | |
| | | //给营业助理赋值 |
| | | eSignForm.Sales_assistant_name_text__c = eSignFormEntry.Sales_assistant_ID__c; |
| | | //存一个id |
| | | idlast = eSignFormEntry.Id; |
| | | //签收单name用作文件命名 |
| | | name = eSignFormEntry.eSignForm__r.Name; |
| | | //是否经销商提交 |
| | | IsSubmit = eSignFormEntry.IsSubmit__c; |
| | | //是否医院提交 |
| | | IsHPSubmit = eSignFormEntry.IsHPSubmit__c; |
| | | //最后录入表 |
| | | eSignForm.finalUpadteFrom__c = eSignFormEntry.Id; |
| | | //销售渠道 区分直销还是分销 |
| | | Sales_Root_Formula = eSignFormEntry.Sales_Root_Formula__c; |
| | | //录入类型 |
| | | type = eSignFormEntry.entryType__c; |
| | | // 2023-03-16 ssm 优化逻辑,避免同时多设备做系统更新以及医院和经销商在同一批次(15分钟内)上传数据 end |
| | | |
| | | } |
| | | system.debug('签收单对象-----:' + eSignForm); |
| | |
| | | //电子签收单 增加本次更新附件数量 2020/01/07 精琢技术 wql end |
| | | //文件 end |
| | | } |
| | | // 更新签收单录入表 |
| | | if(unprocessedEntries.size() > 0) { |
| | | Database.SaveResult[] lsr = Database.update(unprocessedEntries, false); |
| | | // Database.SaveResult[] lsr = Database.update(unprocessedEntries.values(), false); |
| | | eb.setError(lsr, MAXERRORCNT, eSignFormEntry__c.sObjectType); |
| | | for (Integer tIdx = 0; tIdx < lsr.size(); tIdx++) { |
| | | Database.SaveResult sr = lsr[tIdx]; |
| | | System.debug('sr.isSuccess:' + sr.isSuccess()); |
| | | if (!sr.isSuccess()) { |
| | | Database.Error emsg = sr.getErrors()[0]; |
| | | iflog.ErrorLog__c += 'ERROR ' + unprocessedEntries[tIdx].Id + ' eSignFormEntry__c:' + emsg + '\n'; |
| | | // iflog.ErrorLog__c += 'ERROR ' + unprocessedEntries.values()[tIdx].Id + ' eSignFormEntry__c:' + emsg + '\n'; |
| | | } |
| | | } |
| | | } |
| | | system.debug('更新的签收单:' + eSignFormList); |
| | | //更新签收单明细并添加日志 |
| | | if (eSignFormLuRUList.size() > 0) { |
| | |
| | | } |
| | | //删除录入表 |
| | | System.debug('删除录入表 : ' + eSignFormDeleteList); |
| | | delete eSignFormDeleteList; |
| | | // delete eSignFormDeleteList; // 2023-03-14 ssm 暂时不自动删除中间表数据,方便短期内做check |
| | | } |
| | | } |
| | | @TestVisible |
| | |
| | | |
| | | List < eSignForm__c > eSignFormLastList = new List < eSignForm__c >(); |
| | | //检索OCSM管理省对象 |
| | | List < OCM_Management_Province__c > ompList = [select id, Name, SalesManage__c,GI_assistant__c from OCM_Management_Province__c where Name IN: provinceList]; |
| | | List < OCM_Management_Province__c > ompList = [select id, Name, SalesManage__c,GI_assistant__c,Window1__c from OCM_Management_Province__c where Name IN: provinceList]; |
| | | //存放map<省,担当> |
| | | for (OCM_Management_Province__c omp : ompList) { |
| | | //不用map<String,list>的 原因是 想 ocsm管理省 和签收单 营业担当的顺序保持一致 |
| | | //String salesManage = omp.SalesManage__c+','+omp.SalesManage2__c+','+omp.SalesManage3__c; |
| | | //provinceOwnerMap.put(omp.Name, salesManage); |
| | | provinceOwnerMap.put(omp.Name, omp.SalesManage__c); |
| | | provinceGIMap.put(omp.Name, omp.GI_assistant__c); |
| | | provinceGIMap.put(omp.Name, omp.Window1__c);//Update By Li Jun 20230420 for 签收单营业助理从GI/SP助理改为签收单OCSM省的营业窗口 |
| | | } |
| | | //①为true的时候 是其他没发生变化只有ocsm省上营业担当改变 |
| | | //②为false的时候,有中间表正常更新的情况 |