111
沙世明
2022-11-22 928399eceec50e3d37ea08669a12789a9410a9d2
force-app/main/default/classes/RepairTrigger.cls
@@ -1,4 +1,50 @@
public without sharing class RepairTrigger {
    public static Boolean isFirst = true;
    public static Integer flagNumber = 1;
    //after insert, after update
    public static void sendEmailByInspectionFailureCause(List<Repair__c> newList, Map<Id, Repair__c> newMap, List<Repair__c> oldList, Map<Id, Repair__c> oldMap){
        if (isFirst) {
            isFirst = false;
            System.debug('sendEmailByInspectionFailureCause==========' + flagNumber++);
            EmailTemplate et=[Select id from EmailTemplate where name = '修理报价信息更新' limit 1];
            List<Id> needUpdateList = new List<Id>();
            for(Repair__c re : newList){
                if( re.PAE_DetermineResults__c == 'PAE' || re.PAE_DetermineResults__c == 'Unknown'){
                    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);
            }
            Messaging.sendEmail(emails);
        }
    }
    // 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) {
        // 日历查询开始
@@ -74,7 +120,7 @@
    public static void UpdateAssert(List<Repair__c> newList, Map<Id, Repair__c> newMap, List<Repair__c> oldList, Map<Id, Repair__c> oldMap) {
        System.debug('===========> start');
        test();
        List<String> productIds = new List<String>();
        if (Trigger.isAfter && (Trigger.isInsert || Trigger.isUpdate)) {
@@ -140,6 +186,9 @@
                                || rList[0].Return_Without_Repair_Reason__c == '8.乾燥') {
                            //ass = assMap.get(rpc.Delivered_Product__c);
                            if (reason != null) {
                                if (reason.contains('修理中')) {
                                    a.Reson_Can_not_Warranty__c = reason.replace('修理中', '');
                                }
                                if (!reason.contains('弃修')) {
                                    a.Reson_Can_not_Warranty__c = reason + '弃修';
                                }
@@ -1228,4 +1277,41 @@
        System.debug('===========> end');
    }
    public static void test(){
        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++;
    }
}