111
沙世明
2022-11-22 928399eceec50e3d37ea08669a12789a9410a9d2
force-app/main/default/classes/TenderInformationHandler.cls
@@ -47,6 +47,9 @@
        if (!StaticParameter.EscapeOtherUpdateTenOwner) {
            updateTenOwner();
        }
        // 20221011 ljh  SWAG-CK28WT start
        updateTenOwnerJC();
        // 20221011 ljh  SWAG-CK28WT end
        //20220804 you 询价任务
        updateOppotunityBeforeUpdate();
        
@@ -59,7 +62,7 @@
        // updateTenOwner();
    }
    protected override void afterUpdate() {
        addShare();
        addShare();
        //sednMessage(); 20220729 you 招标项目 取消发送邮件通知
        updateWin();
@@ -70,8 +73,8 @@
        //updateOpportunity();//2022-5-18 yjk XLIU-CEJ38N 注释掉 
    }
//修改项目阶段,由 结果变为其他,,相关任务取消
public void updateOppotunityBeforeUpdate() {
    //修改项目阶段,由 结果变为其他,,相关任务取消
    public void updateOppotunityBeforeUpdate() {
        Set<String> Tenids = new Set<String>();//招标项目id,查询link
        Set<String> oppTens = new Set<String>();//招标项目id,查询link
        List<String> oppIds = new List<String>();//询价
@@ -131,12 +134,11 @@
            } 
            update opportunities;   
        }
}
//20220718 you 询价任务 end
    }
    //20220718 you 询价任务 end
    // 20221027 updateOpportunity() 全文搜索过 没有调用的,方法引用已经注释,覆盖率不够方法体也注释(SWAG-CKL5UC),
    //2022-3-29 yjk SWAG-CCL6R7
    private void updateOpportunity(){
    /*private void updateOpportunity(){
        for(Tender_information__c newOne : newList){
            Tender_information__c oldOne = oldMap.get(newOne.id);
            if(oldOne.ResultDate__c == null && newOne.ResultDate__c != null){
@@ -149,8 +151,8 @@
                }
            }
        }
    }
//20220729 you
    }*/
    //20220729 you
    //public void sednMessage() {
    //    //规则条件
    //    //ISCHANGED(InfoType__c) && Text(InfoType__c) = '3:结果' && (Text(IsBid__c) = '是' || ( Text(IsBid__c) = '否' && OpportunityNum__c != null && OpportunityNum__c > 0) )
@@ -462,6 +464,12 @@
        //取值顺序是:所有人,之后是gi助理,接下来是sp助理,接下来是战略科室所有人 所以倒着来
        List<Tender_information__Share> tenShareList = new List<Tender_information__Share>();
        for (Tender_information__c tenc : newList) {
            // 20221013 ljh SWAG-CK28WT start
            // 集采项目 后续共享不需要,只把原来的共享删除
            if(tenc.CentralizedProject__c){
                continue;
            }
            // 20221013 ljh SWAG-CK28WT start
            //一个map为 针对一条招投标计划的共享
            Map<Id, Tender_information__Share> sharemap = new Map<Id, Tender_information__Share>();
            //1.先设置 医院担当的共享
@@ -591,7 +599,7 @@
            tenShareList.addAll(sharemap.values());
        }
        //现在用的是全删全加的方法,没有再判断是否发生改变了
        //删除
        List<Tender_information__Share> beforeShareList =
@@ -618,7 +626,6 @@
        for (OCM_Management_Province__c mp : [SELECT id, Name, GI_assistant__c, SP_assistant__c, SP_assistant__r.IsActive, GI_assistant__r.IsActive, Window2__c, Window2__r.IsActive, Admin_assistant3__c, Admin_assistant3__r.IsActive, TenderAssistant1__c, TenderAssistant1__r.IsActive, TenderAssistant2__c, TenderAssistant2__r.IsActive, Window1__c, Window1__r.IsActive FROM OCM_Management_Province__c]) {
            mpMap.put(mp.Name, mp);
        }
        //设置GI/SP助理  行政助理、备品窗口
        //直接设置 信息负责人(助理) 为GI助理
        for (Tender_information__c info : newList) {
@@ -641,13 +648,17 @@
                            info.GI_assistant__c = ocm.GI_assistant__c;
                        }
                        if (info.InfoOwner__c != ocm.GI_assistant__c) {
                            info.InfoOwner__c = ocm.GI_assistant__c;
                            if(info.CentralizedProject__c == false){ // 20221012 ljh SWAG-CK28WT 添加的if
                                info.InfoOwner__c = ocm.GI_assistant__c;
                            }
                        }
                    }
                    // 增加GI助理为空时的处理,清空招标项目的GI助理和信息负责人(助理) 20210813
                    else if (ocm.GI_assistant__c == null || !ocm.GI_assistant__r.IsActive) {
                        info.GI_assistant__c = null;
                        info.InfoOwner__c = null;
                        if(info.CentralizedProject__c == false){ // 20221012 ljh SWAG-CK28WT 添加的if
                            info.InfoOwner__c = null;
                        }
                    }
                    if (ocm.SP_assistant__r.IsActive && info.SP_assistant__c != ocm.SP_assistant__c) {
                        info.SP_assistant__c = ocm.SP_assistant__c;
@@ -700,12 +711,33 @@
                        || tenDepartList.contains('01210000000QezoAAC')
                        || tenDepartList.contains('01210000000QeztAAC')){
                        System.debug('=====-----'+info.department_selection__c);
                        info.InfoOwner__c = info.SP_assistant__c;
                        if(info.CentralizedProject__c == false){ // 20221012 ljh SWAG-CK28WT 添加的if
                            info.InfoOwner__c = info.SP_assistant__c;
                        }
                    }
                }
                // add 战略科室分类为普外科、泌尿科、妇科、耳鼻喉科时,信息负责人(助理)修改为 SP助理 2021、11、11 fxk end
                // 20221012 ljh SWAG-CK28WT start
                if(info.CentralizedProject__c){
                    // 清除这些人赋值 (就没有权限了)
                    info.GI_assistant__c = null;
                    info.SP_assistant__c = null;
                    info.Window2__c = null;
                    info.TenderAssistant1__c = null;
                    info.TenderAssistant2__c = null;
                    info.YingyeWindow__c = null;
                }
                // 20221012 ljh SWAG-CK28WT end
            }
            // 20221027 ljh SWAG-CKL5UC add start
            // 项目中当结果记录日有值公告记录日为空时,给公告记录日赋值逻辑=结果记录日-15天
            if(info.ResultDate__c != null && info.publicDate__c == null){
                info.publicDate__c = info.ResultDate__c.addDays(-15);
            }
            // 20221027 ljh SWAG-CKL5UC add start
        }
    }
// fxk 2021/8/3 反逻辑删除 Star
    private void updateTenDel() {
@@ -726,6 +758,7 @@
        Map<Id,Tender_information__c> tOldMap = (Map<Id,Tender_information__c>) Trigger.oldMap;
        Map<Id,Tender_information__c> tNewMap = (Map<Id,Tender_information__c>) Trigger.newMap;
        List<Date> cd = new List<Date>();
        System.debug(LoggingLevel.INFO, '*** cd: ' + cd);
        System.debug(LoggingLevel.INFO, '*** tOldMap: ' + tOldMap);
        for(Tender_information__c t:(List<Tender_information__c>) Trigger.new){
            System.debug(LoggingLevel.INFO, '*** 进入for循环: ');
@@ -737,7 +770,10 @@
                System.debug(LoggingLevel.INFO, '*** tOldMap: ' + tOldMap.get(t.Id).relativeDate__c);
                System.debug(LoggingLevel.INFO, '*** t.relativeDate__c: ' + t.relativeDate__c);
                // if(tOldMap.get(t.Id).relativeDate__c != null && t.relativeDate__c != tOldMap.get(t.Id).relativeDate__c){
                if(t.relativeDate__c != null && t.relativeDate__c != tOldMap.get(t.Id).relativeDate__c){
                //lt 20221114 DB202211270805 【紧急】招标项目是否按时关联计算错误 start
                // if(t.relativeDate__c != null && t.relativeDate__c != tOldMap.get(t.Id).relativeDate__c){
                if(((t.OBSAP_relativeTime__c != null || t.relativeTime_F__c != null) && t.Tender_Olympus__c == null) || (t.relativeDate__c != null && t.relativeDate__c != tOldMap.get(t.Id).relativeDate__c)){
                //lt 20221114 DB202211270805 【紧急】招标项目是否按时关联计算错误 end
                    System.debug(LoggingLevel.INFO, '*** 进入if语句: ');
                    String datastr = String.valueOf(t.relativeDate__c);
                    cd.add( Date.valueOf(datastr.substring(0,10)) );
@@ -746,27 +782,41 @@
            }
        }
        Map<Date,String> lm = new Map<Date,String>();
        for(OlympusCalendar__c oc:[SELECT Id,Date__c FROM OlympusCalendar__c WHERE Date__c IN:cd]){
            lm.put(oc.Date__c,oc.Id);
            System.debug(LoggingLevel.INFO, '*** map赋值: ');
        }
        for(Tender_information__c l:(List<Tender_information__c>) Trigger.new){
            if (l.relativeDate__c == null) {
                continue;
        if(cd.size() > 0){
            for(OlympusCalendar__c oc:[SELECT Id,Date__c FROM OlympusCalendar__c WHERE Date__c IN:cd]){
                lm.put(oc.Date__c,oc.Id);
                System.debug(LoggingLevel.INFO, '*** map赋值: ');
            }
            String datastr = String.valueOf(l.relativeDate__c);
            String dt = lm.get(Date.valueOf(datastr.substring(0,10)));
            l.Tender_Olympus__c = dt;
            System.debug(LoggingLevel.INFO, '*** l.Tender_Olympus__c: '+ l.Tender_Olympus__c);
            for(Tender_information__c l:(List<Tender_information__c>) Trigger.new){
                //lt 20221114 DB202211270805 【紧急】招标项目是否按时关联计算错误 start
                // if (l.relativeDate__c == null) {
                //     continue;
                // }
                if (l.relativeDate__c == null && l.OBSAP_relativeTime__c == null) {
                    continue;
                }
                Datetime relativetime = l.OBSAP_relativeTime__c != null ? l.OBSAP_relativeTime__c : l.relativeTime__c;
                // String datastr = String.valueOf(l.relativeDate__c);
                String datastr = String.valueOf(relativetime);
                //lt 20221114 DB202211270805 【紧急】招标项目是否按时关联计算错误 end
                String dt = lm.get(Date.valueOf(datastr.substring(0,10)));
                System.debug(LoggingLevel.INFO, '*** dt: '+ dt);
                l.Tender_Olympus__c = dt;
                System.debug(LoggingLevel.INFO, '*** l.Tender_Olympus__c: '+ l.Tender_Olympus__c);
            }
        }
    }
// fxk 2021/8/3 反逻辑删除 end
// 20210824 中标时修改关联询价的招标项目名和中标时间
    private void updateWin() {
        List<String> tenderIds = new List<String>();
        List<String> lostWinIds = new List<String>();
        // 20221028 ljh SWAG-CKL5UC start
        Map<Id,Tender_information__c>  tendMap = New Map<Id,Tender_information__c>();
        Map<Id,Opportunity> updateOpp = New Map<Id,Opportunity>();
        // 20221028 ljh SWAG-CKL5UC end
        for (Tender_information__c ten : newList) {
            /** 20220614 SWAG-CFD4SU you 更改,询价优先显示项目阶段最新的招标项目信息
            if ('3:结果'.equals(ten.InfoType__c) && !'3:结果'.equals((oldMap.get(ten.Id).InfoType__c))) {
@@ -779,6 +829,13 @@
            if((String.isNotBlank(ten.InfoType__c) && ten.InfoType__c != oldMap.get(ten.Id).InfoType__c) || (String.isNotBlank(ten.subInfoType__c) && ten.subInfoType__c != oldMap.get(ten.Id).subInfoType__c)  || System.Label.TenderToOpp == '1'){
               tenderIds.add(ten.Id);
            }
            // 20221028 ljh SWAG-CKL5UC add start
            // 关联询价的 询价页面创建日晚于招标项目公告记录日,漏单数为1
            // 关联询价的 && 更新有值
            if(ten.OpportunityNum__c > 0 && Trigger.isUpdate && oldMap.get(ten.Id).publicDate__c == null && ten.publicDate__c != null){
                tendMap.put(ten.Id, ten);
            }
            // 20221028 ljh SWAG-CKL5UC add end
            
        }
        if (tenderIds.size() > 0) {
@@ -884,6 +941,22 @@
            }
        }
        **/
        // 20221028 ljh SWAG-CKL5UC add start
        if(tendMap.size() > 0){
            List<Tender_Opportunity_Link__c> links = [select id, Opportunity__c, Tender_information__c, Opportunity__r.Created_Day__c ,Opportunity__r.LeakageNumber__c,Opportunity__r.LeadSource  from Tender_Opportunity_Link__c where Tender_information__c in :tendMap.keySet()];
            for(Tender_Opportunity_Link__c lk:links){
                if(lk.Opportunity__r.Created_Day__c  > tendMap.get(lk.Tender_information__c).publicDate__c && lk.Opportunity__r.LeadSource == '招标网'){
                    Opportunity opp = new Opportunity();
                    opp.Id = lk.Opportunity__c;
                    opp.LeakageNumber__c = 1;
                    updateOpp.put(opp.Id,opp);
                }
            }
        }
        if(updateOpp.size() > 0){
            update updateOpp.values();
        }
        // 20221028 ljh SWAG-CKL5UC add end
    }
    public void updateTenOwner() {
@@ -1176,7 +1249,46 @@
        }
        // StaticParameter.EscapeOtherUpdateTenOwner = true;
    }
    /*
    集采项目导致所有人更新
    **/
    // 20221011 ljh  SWAG-CK28WT
    public void updateTenOwnerJC() {
        //
        String OCSM_province = '市场企划本部';
        Id OwnerIdStr;
        List<OCM_Management_Province__c> ompList = [select Id,TenderAssistant1__c,TenderAssistant1__r.IsActive,TenderAssistant2__c from OCM_Management_Province__c where name =:OCSM_province];
        if(ompList.size() > 0 && ompList[0].TenderAssistant1__r.IsActive){
            OwnerIdStr = ompList[0].TenderAssistant1__c;
        }
        System.debug('zheli00:'+OwnerIdStr);
        for (Tender_information__c nObj : newList) {
            Tender_information__c oObj = oldMap.get(nObj.Id);
            if (nObj.CentralizedProject__c != oObj.CentralizedProject__c) {
                if(nObj.CentralizedProject__c && OwnerIdStr != null){
                    /**
                    本部自动变成市场企划本部,项目助理和所有人都是市场企划本部的人,
                    取OCSM管理省页面维护的市场企划本部,招标项目助理1,
                    */
                    nObj.OwnerId = OwnerIdStr;
                    nObj.InfoOwner__c = OwnerIdStr;
                }else if(!nObj.CentralizedProject__c){
                    /**
                    取消勾选后返回营业部门的省和本部,
                    所有人根据关联医院和战略科室取担当的名字。
                    */
                    updateTenOwner();
                }
            }
            // 如果触发 更新所有人 没有询价则 还是市场企划本部
            if (!StaticParameter.EscapeOtherUpdateTenOwner) {
                if(nObj.CentralizedProject__c && OwnerIdStr != null && (nObj.OpportunityNum__c == 0 || nObj.OpportunityNum__c == null)){
                    nObj.OwnerId = OwnerIdStr;
                    nObj.InfoOwner__c = OwnerIdStr;
                }
            }
        }
    }
    // 中标任务 废标流标时清空中标日
    public void clearConfirmationofAward() {
        List<String> tenders = new List<String>();