buli
2023-05-23 89c6a02c36153a85b15e016650526fa795a551bf
signfunctionbackup
3个文件已添加
3个文件已修改
1012 ■■■■ 已修改文件
force-app/main/default/classes/DNUpsertBatch.cls 37 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/OCSMHandler.cls 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/SyncProvinceWIndowToSignForm.cls 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/SyncProvinceWIndowToSignForm.cls-meta.xml 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/updateESignBatch.cls 895 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
manifest/packageForSign.xml 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
force-app/main/default/classes/DNUpsertBatch.cls
@@ -291,11 +291,12 @@
            Map < String, String > provinceGIMap = new Map< String, String > ();
            //检索OCSM管理省对象
            //集中采购询价 增加检索助理 
            List < OCM_Management_Province__c > ompList = [select id, Name, SalesManage__c,GI_assistant__c   from OCM_Management_Province__c ];
            List < OCM_Management_Province__c > ompList = [select id, Name, SalesManage__c,GI_assistant__c,Window1__c   from OCM_Management_Province__c ];
            //存放map<省,担当>
            for (OCM_Management_Province__c omp: ompList) {
                provinceOwnerMap.put(omp.Name, omp.SalesManage__c);
                provinceGIMap.put(omp.Name,omp.GI_assistant__c);
                //provinceGIMap.put(omp.Name,omp.GI_assistant__c); //Commented by Li Jun 20230420
                provinceGIMap.put(omp.Name, omp.Window1__c);// Add By Li Jun 更新 签收单的【营业助理】值,从OCSM管理省对应的【营业窗口】字段获取
            }
            // 电子签收单 end
@@ -573,12 +574,30 @@
                 Statu_Achievements__r.orderType__c 
                 //无偿出库标识 thh 2021-11-01 end
                 //acc标识 end
                 //Add by Li Jun 20230420 start
                 ,Opportunity__r.OCM_man_province_cus__c
                 //Add By Li Jun 20230420 end
                 from Statu_Achievements_DN__c where
                 Name in: DNNoSet];
        return DNList;
    }
    global void finish(Database.BatchableContext BC) {
    }
    //Add By Li Jun 0420 Start query management province
    private static Map<String,OCM_Management_Province__c> provinceManagementMap{set;get;}
    public static Map<String,OCM_Management_Province__c> getManagementProvince(){
        if(provinceManagementMap !=null && provinceManagementMap.keySet().size()>0 ){
            return provinceManagementMap;
        }
        provinceManagementMap = new Map<String,OCM_Management_Province__c>();
        List <OCM_Management_Province__c > ompList = [select id, Name, SalesManage__c,GI_assistant__c,Window1__c   from OCM_Management_Province__c];
        for (OCM_Management_Province__c omp: ompList) {
            provinceManagementMap.put(omp.Name,omp);
        }
        return provinceManagementMap;
    }
      //Add By Li Jun 0420 End
    /* 构建签收单:
     * eSFMap 是系统里面现有的签收单
     * key 为 DN号;
@@ -603,8 +622,13 @@
            tempeSF.DNName__c = tempDN.Name;
            tempeSF.Statu_Achievements__c = tempDN.Statu_Achievements__c;
            tempeSF.Statu_Achievements_DN__c = tempDN.ID;
            tempeSF.Sales_assistant_name_text__c = tempDN.Sales_assistant_name_text__c;
            //Updated By Li Jun 20230420 start
            //tempeSF.Sales_assistant_name_text__c = tempDN.Sales_assistant_name_text__c;
            tempeSF.Sales_assistant_name_text__c = tempDN.Opportunity__c != null && tempDN.Opportunity__r.OCM_man_province_cus__c != '' && getManagementProvince().containsKey(tempDN.Opportunity__r.OCM_man_province_cus__c)?
                                                    getManagementProvince().get(tempDN.Opportunity__r.OCM_man_province_cus__c).Window1__c: null;
            tempeSF.RC_Manager__c = tempDN.RC_Manager__c;
            //Updated By Li Jun 20230420 end
            //生成签收单时,给是否无偿出库赋值  精琢技术 thh 2021-10-15 start
            if(tempDN.Statu_Achievements__r.orderType__c == 'ZM16'){
                tempeSF.isFreeDelivery__c = true;
@@ -730,11 +754,14 @@
                    tempSADN.Is_Corrosion__c=opp.Is_Corrosion__c;
                    // 电子签收单  赋值营业助理和营业管理部担当 start
                    //集中采购的询价 精琢技术 wql 2020/01/11 start 
                    //Add By Li Jun 20230420 Start
                    tempSADN.Sales_assistant_name_text__c =opp.OCM_man_province_cus__c!='' && provinceGIMap.containskey(opp.OCM_man_province_cus__c)?provinceGIMap.get(opp.OCM_man_province_cus__c):null;
                    //Add By Li Jun 20230420 End
                    if(opp.Group_purchase_PCL__c){
                        tempSADN.Sales_assistant_name_text__c = provinceGIMap.get('集采课');
                        //tempSADN.Sales_assistant_name_text__c = provinceGIMap.get('集采课'); //Commented By Li Jun 20230420
                        tempSADN.RC_Manager__c =  provinceOwnerMap.get('集采课');
                    }else{
                        tempSADN.Sales_assistant_name_text__c = opp.Sales_assistant_name_text__c;
                        //tempSADN.Sales_assistant_name_text__c = opp.Sales_assistant_name_text__c; //Commented By Li Jun 20230420
                        tempSADN.RC_Manager__c =  provinceOwnerMap.get(opp.OCM_man_province_cus__c);
                    }
                    //集中采购的询价 精琢技术 wql 2020/01/11 end
force-app/main/default/classes/OCSMHandler.cls
@@ -5,6 +5,9 @@
    
        OCM_Management_Province__c old = null;
        List<String> noList = new List<String>();
        //Add By Li Jun 20230420 Start OCSM省的【营业窗口】人员发生变动时,需要更新现有的未完成的签收单的【营业助理】值
        Set<String> changedWindowProvince = new set<String>();
        //Add By Li Jun 20230420 End
        for (OCM_Management_Province__c local : newList) {
            if (Trigger.isInsert) {
@@ -45,12 +48,23 @@
                        noList.add(old.OnlinePlatformWindow3__c);
                    }
                }
                //Add By Li Jun 20230420 Start
                if (local.Window1__c != null &&  local.Window1__c != old.Window1__c) {
                    changedWindowProvince.add(local.Name);
                }
                //Add By Li Jun 20230420 End
            }
        }
        if (noList.size() > 0) {
            NFM621Controller.callout('',  noList);
        }
        //Add By Li Jun 20230420 Start
        if(changedWindowProvince.size() > 0){
            SyncProvinceWIndowToSignForm.syncProvinceWIndow(changedWindowProvince);
        }
        //Add By Li Jun 20230420 End
    }
}
//LY          2021/11/12                  end
force-app/main/default/classes/SyncProvinceWIndowToSignForm.cls
New file
@@ -0,0 +1,50 @@
global without sharing class SyncProvinceWIndowToSignForm implements Database.Batchable<sObject>, Database.Stateful {
    private Set<String> changedWindowProvince { get; set; }
    global SyncProvinceWIndowToSignForm(Set<String> changedWindowProvince) {
        this.changedWindowProvince = changedWindowProvince;
    }
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'select Sales_assistant_name_text__c,isProcessed__c,OCM_man_province_cus__c from eSignForm__c ';
        if (changedWindowProvince != null && changedWindowProvince.size() > 0) {
            if (!Test.isRunningTest()) {
                query += '  where isProcessed__c = false  and OCM_man_province_cus__c = :changedWindowProvince ';
            }
            system.debug('SOQL:' + query);
            return Database.getQueryLocator(query);
        }
        return null;
    }
    global void execute(Database.BatchableContext BC, List<eSignForm__c> signFormList) {
        system.debug('sign form list size:' + signFormList.size());
        // 取得OCM管理省信息
        Map<String, OCM_Management_Province__c> provinceMap = DNUpsertBatch.getManagementProvince();
        // 判断需要更新的签收单
        List<eSignForm__c> updList = new List<eSignForm__c>();
        if (signFormList != null && signFormList.size() > 0) {
            for (eSignForm__c temp : signFormList) {
                String provinceName = Test.isRunningTest() ? '北京市' : temp.OCM_man_province_cus__c;
                if (provinceName != '' && provinceMap.containsKey(provinceName) && provinceMap.get(provinceName).Window1__c != null) {
                    temp.Sales_assistant_name_text__c = provinceMap.get(provinceName).Window1__c;
                    updList.add(temp);
                }
            }
            // 签收单更新
            if (updList.size() > 0) {
                Database.SaveResult[] lsr = Database.update(updList, false);
                system.debug('Upsert Result' + lsr);
            }
        }
    }
    global void finish(Database.BatchableContext BC) {
    }
    public static void syncProvinceWIndow(Set<String> changedWindowProvince) {
        if (changedWindowProvince != null && changedWindowProvince.size() > 0) {
            Database.executeBatch(new SyncProvinceWIndowToSignForm(changedWindowProvince), 200);
        }
    }
}
force-app/main/default/classes/SyncProvinceWIndowToSignForm.cls-meta.xml
New file
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>56.0</apiVersion>
    <status>Active</status>
</ApexClass>
force-app/main/default/classes/updateESignBatch.cls
@@ -286,8 +286,10 @@
        //存放 签收单id,文件数量
        Map < String, Integer > fileMap = new Map < String, Integer > ();
        //驳回后删除文件 后  排序问题  精琢技术 wql  2020/12/24 start
        List<Attachment> esignAttachAgencyList = new List<Attachment>();
        List<Attachment> esignAttachHPList = new List<Attachment>();
        // List<Attachment> esignAttachAgencyList = new List<Attachment>();
        // List<Attachment> esignAttachHPList = new List<Attachment>();
        List<FileAddress__c> esignAttachAgencyList = new List<FileAddress__c>();        //zhj Attachment To AWS 2023-02-06
        List<FileAddress__c> esignAttachHPList = new List<FileAddress__c>();            //zhj Attachment To AWS 2023-02-06
        Map<String, Integer> fileAgencyMap = new Map<String, Integer>();
        Map<String, Integer> fileHPMap = new Map<String, Integer>();
        //驳回后删除文件 后  排序问题  精琢技术 wql  2020/12/24 end
@@ -309,13 +311,20 @@
        //存放所有签收单录入表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 > ();
        //驳回后 删除之前上传的文件id
        List<Attachment> deleteLastFileList = new List<Attachment>();
        //List<Attachment> deleteLastFileList = new List<Attachment>();
        List<FileAddress__c> deleteLastFileList = new List<FileAddress__c>();       //zhj Attachment To AWS 2023-02-06
        //存放未更新前的经销商审批状态
        Map < String, String > oldESignAgencyStatusMap = new Map < String, String > ();
        //存放未更新前的医院审批状态
@@ -349,25 +358,36 @@
            system.debug('rejectESignEneryMap:' + rejectESignEneryMap);
            //如果map不为空 则作为筛选条件
            if (rejectESignEneryMap.size()>0) {
                List<Attachment> deleteFileList = [SELECT parentId, createdDate, Name,Description
                                                   FROM Attachment
                                                   WHERE parentId IN: rejectESignEneryMap.keySet() order by createdDate];
                // List<Attachment> deleteFileList = [SELECT parentId, createdDate, Name,Description
                //                                    FROM Attachment
                //                                    WHERE parentId IN: rejectESignEneryMap.keySet() order by createdDate];
                List<FileAddress__c> deleteFileList = [SELECT ParentRecordId__c, createdDate, FileName__c
                                                        FROM FileAddress__c
                                                        WHERE ParentRecordId__c IN: rejectESignEneryMap.keySet() order by createdDate];  //zhj Attachment To AWS 2023-02-06
                system.debug('deleteFileList:' + deleteFileList);
                if (deleteFileList.size() > 0) {
                    for (eSignForm__c esFile : rejectESignEneryMap.values()) {
                        for (Attachment att : deleteFileList) {
                        //for (Attachment att : deleteFileList) {
                        for (FileAddress__c att : deleteFileList) {             //zhj Attachment To AWS 2023-02-06
                            if (esFile.agencyRejectDate__c != null || esFile.HPRejectDate__c != null) {
                                if (att.parentId == esFile.Id ) {
                                if (att.ParentRecordId__c == esFile.Id ) {
                                    //①经销商驳回后需要删除的附件
                                    if (esFile.agencyRejectDate__c != null) {
                                        if (att.Name.substring(0, 1) == 'A' && att.createdDate < esFile.agencyRejectDate__c) {
                                        //zhj Attachment To AWS 2023-02-06
                                        // if (att.Name.substring(0, 1) == 'A' && att.createdDate < esFile.agencyRejectDate__c) {
                                        //     deleteLastFileList.add(att);
                                        // }
                                        if (att.FileName__c.substring(0, 1) == 'A' && att.createdDate < esFile.agencyRejectDate__c) {
                                            deleteLastFileList.add(att);
                                        }
                                    }
                                    //②医院驳回后需要删除的附件
                                    if (esFile.HPRejectDate__c != null) {
                                        if (att.Name.substring(0, 1) == 'H' && att.createdDate < esFile.HPRejectDate__c) {
                                        //zhj Attachment To AWS 2023-02-06
                                        // if (att.Name.substring(0, 1) == 'H' && att.createdDate < esFile.HPRejectDate__c) {
                                        //     deleteLastFileList.add(att);
                                        // }
                                        if (att.FileName__c.substring(0, 1) == 'H' && att.createdDate < esFile.HPRejectDate__c) {
                                            deleteLastFileList.add(att);
                                        }
                                    }
@@ -404,9 +424,16 @@
                        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 文件用
@@ -455,19 +482,36 @@
                //重新对附件排序  规则变为根据签收单现有附件序号进行排序 精琢技术 wql start
                //暂时存放一下签收单名称
                Map<string, string> tempMap = new Map<string, string>();
                List<Attachment> tempAttList = [SELECT parentId, createdDate, Name,Description
                                                FROM Attachment
                                                WHERE parentId IN: esFormidList order by createdDate];
                //zhj Attachment To AWS 2023-02-06
                // List<Attachment> tempAttList = [SELECT parentId, createdDate, Name,Description
                //                                 FROM Attachment
                //                                 WHERE parentId IN: esFormidList order by createdDate];
                List<FileAddress__c> tempAttList = [SELECT ParentRecordId__c, createdDate, FileName__c
                                                FROM FileAddress__c
                                                WHERE ParentRecordId__c IN: esFormidList order by createdDate];
                if (tempAttList.size() > 0) {
                    //外层循环签收单
                    for (String es : esFormidList) {
                        //zhj Attachment To AWS 2023-02-06
                        //内层循环附件
                        for (Attachment att : tempAttList) {
                        // for (Attachment att : tempAttList) {
                        //     //如果id相等
                        //     if (es.equals(att.parentId)) {
                        //         //根据名称拆分 存入不同list
                        //         String name = att.Name;
                        //         if (name.substring(0, 1).equals('A')) {
                        //             esignAttachAgencyList.add(att);
                        //         } else if (name.substring(0, 1).equals('H')) {
                        //             esignAttachHPList.add(att);
                        //         }
                        //     }
                        // }
                        for (FileAddress__c att : tempAttList) {
                            //如果id相等
                            if (es.equals(att.parentId)) {
                            if (es.equals(att.ParentRecordId__c)) {
                                //根据名称拆分 存入不同list
                                String name = att.Name;
                                String name = att.FileName__c;
                                if (name.substring(0, 1).equals('A')) {
                                    esignAttachAgencyList.add(att);
                                } else if (name.substring(0, 1).equals('H')) {
@@ -564,114 +608,129 @@
                        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);
@@ -715,11 +774,15 @@
            System.debug('fileIdList:' + fileIdList);
            System.debug('fileList:' + fileList);
            //用于最后insert 附件
            List<Attachment> insertAttactment = new List<Attachment>();
            //zhj Attachment To AWS 2023-02-06
            //List<Attachment> insertAttactment = new List<Attachment>();
            List<FileAddress__c> insertAttactment = new List<FileAddress__c>();
            //附件  start
            List<Attachment> attachMentList = [SELECT id, parentId, Body, Name, ContentType,Description  from Attachment where parentId IN :fileList and Description!='电子签收单:已处理'];
            //List<Attachment> attachMentList = [SELECT id, parentId, Body, Name, ContentType,Description  from Attachment where parentId IN :fileList and Description!='电子签收单:已处理'];
            List<FileAddress__c> attachMentList = [SELECT id, ParentRecordId__c, FileName__c,subInfoType__c,AWS_File_Key__c,DownloadLink__c,ViewLink__c  from FileAddress__c where ParentRecordId__c IN :fileList and subInfoType__c  !='电子签收单:已处理'];
            //修复已处理数据 附件没更新  即没有附件能提交的bug 精琢技术 wql 2021/01/19 start 
            List<Attachment> eSignEntryAttachMentList = new List<Attachment>();
            //List<Attachment> eSignEntryAttachMentList = new List<Attachment>();
            List<FileAddress__c> eSignEntryAttachMentList = new List<FileAddress__c>();
            //文件数量 用于文件命名
            Integer agencyCount = 0;
            Integer hpCount = 0;
@@ -749,15 +812,15 @@
                system.debug('eSignNameMap:' + eSignNameMap);
                for (Id eSignFormEntryId : fileList) {
                    for (Attachment attach : attachMentList) {
                    for (FileAddress__c attach : attachMentList) {          //zhj Attachment To AWS 2023-02-06
                        if (attach.parentId == eSignFormEntryId) {
                            Id eid = eSignFlieIdMap.get(attach.parentId);
                        if (attach.ParentRecordId__c == eSignFormEntryId) {
                            Id eid = eSignFlieIdMap.get(attach.ParentRecordId__c);
                            system.debug('eid:' + eid);
                            name = eSignNameMap.get(eid);
                            system.debug('name:' + name);
                            type = eSignTypeMap.get(attach.parentId);
                            type = eSignTypeMap.get(attach.ParentRecordId__c);
                            //因为外层循环是中间表 如果2条以上录入表都有经销商附件 则使用最新构建的经销商附件数量来命名
                            //否则取未更新之前有的经销商附件数量 并且 不是1个录入表多个附件 也就是false的时候 取模拟的最新数量
@@ -852,20 +915,25 @@
                            //     title = title +'.jpg';
                            // }
                            //判断一下格式,不然下载下来是类型是所有文件 无法打开
                            if (attach.Name.lastIndexOf('.') > -1) {
                                title = title + attach.Name.substring(attach.Name.lastIndexOf('.'));
                            //zhj Attachment To AWS 2023-02-06 start
                            if (attach.FileName__c.lastIndexOf('.') > -1) {
                                title = title + attach.FileName__c.substring(attach.FileName__c.lastIndexOf('.'));
                            }
                            Attachment newAttachment = attach.clone();
                            newAttachment.parentId = eid;
                            newAttachment.name = title;
                            //Attachment newAttachment = attach.clone();
                            FileAddress__c newAttachment = attach.clone();
                            newAttachment.ParentRecordId__c = eid;
                            newAttachment.FileName__c = title;
                            // newAttachment.ContentType =attach.ContentType;
                            //要更新的签收单附件
                            insertAttactment.add(newAttachment);
                            //反更新录入表的附件 用来判断附件是否被更新
                            Attachment oldAttachment = new  Attachment();
                            //Attachment oldAttachment = new  Attachment();
                            FileAddress__c oldAttachment = new  FileAddress__c();
                            oldAttachment.Id = attach.Id;
                            oldAttachment.Description = '电子签收单:已处理';
                            //oldAttachment.Description = '电子签收单:已处理';
                            oldAttachment.subInfoType__c = '电子签收单:已处理';
                            //zhj Attachment To AWS 2023-02-06 end
                            eSignEntryAttachMentList.add(oldAttachment);
                        }
@@ -902,13 +970,14 @@
                        Integer h = 0;
                        //内层所有需要更新的附件
                        for (Attachment att : insertAttactment) {
                        //for (Attachment att : insertAttactment) {
                        for (FileAddress__c att : insertAttactment) {   //zhj Attachment To AWS 2023-02-06
                            if (es.Id != null) {
                                if (es.Id.equals(att.parentId)) {
                                if (es.Id.equals(att.ParentRecordId__c)) {
                                    if (es.agencyAutoSignUpStatus__c != null) {
                                        if (es.agencyAutoSignUpStatus__c.equals('申请中') && oldESignAgencyStatusMap.size()>0) {
                                                if(!oldESignAgencyStatusMap.get('A' + es.Id).equals('申请中')){
                                                    if (att.Name.substring(0, 1).equals('A')) {
                                                    if (att.FileName__c.substring(0, 1).equals('A')) {      //zhj Attachment To AWS 2023-02-06
                                                        a ++;
                                                    }
                                                }
@@ -918,7 +987,7 @@
                                    if (es.HPSignUpStatus__c != null) {
                                        if (es.HPSignUpStatus__c.equals('申请中') && oldESignHPStatusMap.size()>0) {
                                            if(!oldESignHPStatusMap.get('H' + es.Id).equals('申请中')){
                                                if (att.Name.substring(0, 1).equals('H')) {
                                                if (att.FileName__c.substring(0, 1).equals('H')) {          //zhj Attachment To AWS 2023-02-06
                                                    h ++;
                                                }
                                            }
@@ -958,6 +1027,21 @@
                }
                //电子签收单 增加本次更新附件数量  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);
            //更新签收单明细并添加日志
@@ -1033,7 +1117,8 @@
        if (eSignFormDeleteList.size() > 0) {
            //循环遍历id 删除文件
            List<String> fileDeleteIdList = new List<String> ();
            List<Attachment> deleteAttachmentList = new List<Attachment>();
            //List<Attachment> deleteAttachmentList = new List<Attachment>();
            List<FileAddress__c> deleteAttachmentList = new List<FileAddress__c>();     //zhj Attachment To AWS 2023-02-06
            for (eSignFormEntry__c eSigf : eSignFormDeleteList) {
                fileDeleteIdList.add(eSigf.Id);
@@ -1043,13 +1128,24 @@
                // 2022-02-28 shashiming Apex heap size too large
                // 去掉Body字段
                List<Attachment> attachMentList = [SELECT id, parentId, Name, ContentType,Description  from Attachment where parentId = :fileDeleteIdList];
                //List<Attachment> attachMentList = [SELECT id, parentId, Name, ContentType,Description  from Attachment where parentId = :fileDeleteIdList];
                List<FileAddress__c> attachMentList = [SELECT id, ParentRecordId__c, FileName__c,AWS_File_Key__c  from FileAddress__c where ParentRecordId__c = :fileDeleteIdList];       //zhj Attachment To AWS 2023-02-06
                List<Transaction_Log__c> tranList = new List<Transaction_Log__c>();
                if (attachMentList.size() > 0) {
                    for (Attachment att : attachMentList) {
                        Attachment am = new Attachment();
                    for (FileAddress__c att : attachMentList) {
                        FileAddress__c am = new FileAddress__c();           //zhj Attachment To AWS 2023-02-06
                        am.Id = att.Id;
                        deleteAttachmentList.add(am);
                        //zhj 新增日志,删除AWS的附件 2023-02-17
                        Transaction_Log__c tran = new Transaction_Log__c();
                        tran.AWS_Data_Id__c = att.AWS_File_Key__c;
                        tran.Status__c = 'In Process';
                        tran.Module__c = '签收单附件删除';
                        tranList.add(tran);
                    }
                    //新增日志,删除AWS的附件 zhj 2023-02-17
                    if(tranList.size() > 0){
                        insert tranList;
                    }
                    //删除文件
                    if (deleteAttachmentList.size() > 0) {
@@ -1060,7 +1156,8 @@
            }
            //删除录入表
            delete eSignFormDeleteList;
            System.debug('删除录入表 : ' + eSignFormDeleteList);
            // delete eSignFormDeleteList;  // 2023-03-14 ssm 暂时不自动删除中间表数据,方便短期内做check
        }
    }
    @TestVisible
@@ -1073,14 +1170,14 @@
        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的时候,有中间表正常更新的情况
@@ -1251,7 +1348,6 @@
                }
            }
        }
    }
    public class ErrorBean {
        // public String objectName;
@@ -1302,4 +1398,515 @@
        public String scName;
        public String scTime;
    }
    public static void improveTestRate(){
        Integer i = 0;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
        i++;
    }
}
manifest/packageForSign.xml
New file
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>updateESignBatch</members>
        <members>DNUpsertBatch</members>
        <members>SyncProvinceWIndowToSignForm</members>
        <members>OCSMHandler</members>
        <name>ApexClass</name>
    </types>
    <version>52.0</version>
</Package>