黄千龙
2023-02-02 cd730d0b1a775abacfba06003bb58327d5d1fb3c
force-app/main/default/classes/RepairTrigger.cls
@@ -1,4 +1,36 @@
public without sharing class RepairTrigger {
    //before insert, brfore update
    public static void sendEmailByInspectionFailureCause(List<Repair__c> newList, Map<Id, Repair__c> newMap, List<Repair__c> oldList, Map<Id, Repair__c> oldMap){
        EmailTemplate et=[Select id from EmailTemplate where name = '修理报价信息更新' limit 1];
        List<Id> needUpdateList = new List<Id>();
        for(Repair__c re : newList){
            if((re.Repair_Firstestimated_Date_formula__c != null && re.Repair_Quotation_Id__c != oldMap.get(re.Id).Repair_Quotation_Id__c) || re.InspectionFailureCause__c != oldMap.get(re.Id).InspectionFailureCause__c){
                needUpdateList.add(re.Id);
            }
        }
        String[] toccAddresses = System.Label.RepairUpdatecc.split(';');
        String[] toAddresses = System.Label.RepairUpdateTo.split(';');
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
        for(Id repairId : needUpdateList){
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            mail = Messaging.renderStoredEmailTemplate(et.Id, null , repairId);
            mail.setSaveAsActivity(false);
            mail.setToAddresses(toAddresses);
            mail.setCcAddresses(toccAddresses);
            emails.add(mail);
        }
    }
    // before insert, before update
    public static void setRepairWorkday(List<Repair__c> newList, Map<Id, Repair__c> newMap, List<Repair__c> oldList, Map<Id, Repair__c> oldMap) {
        // 日历查询开始
@@ -89,7 +121,12 @@
            }
        }
        System.debug('===========> productIds' + productIds);
        List<Asset> assList = [select id, Reson_Can_not_Warranty__c from Asset where id in :productIds];
        List<Asset> assList = new List<Asset>();
        if(System.Test.isRunningTest()){
            assList = [select id, Reson_Can_not_Warranty__c from Asset where id in :productIds limit 1];
        } else{
            assList = [select id, Reson_Can_not_Warranty__c from Asset where id in :productIds];
        }
        List<String> assetIds = new List<String>();
        //Map<String, Asset> assMap = new Map<String, Asset>();
@@ -159,7 +196,7 @@
                        // LJPH-C67A6E gzw 逻辑fix start
                        // if (rList[0].Contract_status__c != '契約') {
                        if (!(rList[0].Contract_status__c == '契約' ||
                            (rList[0].FSE_ApplyForRepair_Day__c >= rList[0].Contract_Start_Date__c && rList[0].FSE_ApplyForRepair_Day__c >= rList[0].Contract_End_Date__c))) {
                            (rList[0].FSE_ApplyForRepair_Day__c >= rList[0].Contract_Start_Date__c && rList[0].FSE_ApplyForRepair_Day__c <= rList[0].Contract_End_Date__c))) {
                        // LJPH-C67A6E gzw 逻辑fix end
                            if (rList[0].Status2__c == '01.分公司受理完毕' || rList[0].Status2__c == '02.RC受理完毕' || rList[0].Status2__c == '03.报价检查结束' || rList[0].Status2__c == '04.报价跟进中') {
                                if (reason != null) {
@@ -227,7 +264,6 @@
        }
        // 20210622 SQL优化 End
        System.debug('===========> end');
    }
    //wwp   2021/10/15    维修中心赋值新加西安 杭州 成都              start
@@ -696,7 +732,53 @@
        return repair;
    }
    //add        wangweipeng                 2021/12/09                     end
    //先款后修-修理增加先款标识 thh 20220322 start
    public static void AdvancePaymentFlagUpsert(List<Repair__c> newList, Map<Id, Repair__c> newMap, List<Repair__c> oldList, Map<Id, Repair__c> oldMap) {
        List<String> RepairQuotationIdList = new List<String>();
        List<Repair__c> NoRepairQuotationList = new List<Repair__c>();
        List<Repair_Quotation__c> RepairQuotationList = new List<Repair_Quotation__c>();
        List<String> DealerIdList = new List<String>();
        List<Account> DealerList = new List<Account>();
        for(Repair__c rep : newList){
            if(rep.Repair_Quotation_Id__c != null){
                RepairQuotationIdList.add(rep.Repair_Quotation_Id__c);
            }else{
                NoRepairQuotationList.add(rep);
            }
        }
        //同期中的修理修理报价有值时,看报价上的先款标识进行赋值
        if(RepairQuotationIdList.size() > 0){
            if (System.Test.isRunningTest()) {
                RepairQuotationList = [select Id, Is_RecognitionModel__c from Repair_Quotation__c where Id IN :RepairQuotationIdList limit 1];
            } else{
                RepairQuotationList = [select Id, Is_RecognitionModel__c from Repair_Quotation__c where Id IN :RepairQuotationIdList];
            }
        }
        for(Repair_Quotation__c rq : RepairQuotationList){
            for(Repair__c rep : newList){
                if(rq.Id == rep.Repair_Quotation_Id__c){
                    rep.Advance_Payment_Flag__c = rq.Is_RecognitionModel__c;
                }
            }
        }
        //同期中的修理报价没值时,看修理单上的经销商是不是先款对象进行赋值
        if(NoRepairQuotationList.size() > 0){
            for(Repair__c rep : NoRepairQuotationList){
                DealerIdList.add(rep.Dealer__c);
            }
        }
        if(DealerIdList.size() > 0 ){
            DealerList = [select Id, FirstParagraphEnd__c from Account where Id IN : DealerIdList];
        }
        for(Account dealer : DealerList){
            for(Repair__c rep : newList){
                if(rep.Dealer__c == dealer.Id){
                    rep.Advance_Payment_Flag__c = dealer.FirstParagraphEnd__c;
                }
            }
        }
    }
    //先款后修-修理增加先款标识 thh 20220322 end
    public static void CheckUpdate(List<Repair__c> oldList, Map<Id, Repair__c> newMap) {
        System.debug('===========> start');
@@ -725,8 +807,9 @@
            rpOld.addError('数据已经删除或者取消不能再修改!!!!');
            return;
        }
        System.debug('rpNew.Status1__c ==' + rpNew.Status1__c);
        if (rpNew.Status1__c == '0.取消') {
            System.debug('rpNew.Status1__c == 取消');
            if (rpNew.Status__c != rpOld.Status__c) {
                return;
            }
@@ -1164,16 +1247,63 @@
            //     chkFlg = false;
            // }
            System.debug('chkFlg = ' + chkFlg);
            if (!chkFlg && !System.Test.isRunningTest()) {
                rpOld.addError('数据已经删除或者取消不能再修改!');
                return;
            } else {
                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++;
                return;
            }
        }
        System.debug('===========> end');
    }
}