| | |
| | | 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) { |
| | | // 日历查询开始 |
| | |
| | | } |
| | | } |
| | | 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>(); |
| | |
| | | |
| | | |
| | | Map<String, List<Repair__c>> repaMap = new Map<String, List<Repair__c>>(); |
| | | List<Repair__c> repList = [select id, Status1__c, Status2__c, Return_Without_Repair_Reason__c, Contract_status__c, Return_Without_Repair_IF__c, Failure_Occurrence_Date__c, |
| | | List<Repair__c> repList = [select id, Status1__c, Status2__c, Return_Without_Repair_Reason__c, Contract_status__c, Return_Without_Repair_IF__c, Failure_Occurrence_Date__c,CancellationReason__c, |
| | | Delivered_Product__c |
| | | // LJPH-C67A6E gzw 逻辑fix start |
| | | ,FSE_ApplyForRepair_Day__c,Contract_Start_Date__c,Contract_End_Date__c |
| | |
| | | if (rList[0] != null) { |
| | | if (rList[0].Return_Without_Repair_IF__c == true) { |
| | | //判断弃修的逻辑 |
| | | // 20230207“弃修”“修理中”设备判断逻辑修改 start |
| | | if (rList[0].Return_Without_Repair_Reason__c == 'I/F理由、確認' &&(rList[0].CancellationReason__c == '报价单到期' |
| | | || rList[0].CancellationReason__c == '废弃' || rList[0].CancellationReason__c == '购买新品' || rList[0].CancellationReason__c == '零件停产' |
| | | || rList[0].CancellationReason__c == '零件已停止生产' || rList[0].CancellationReason__c == '到其他公司修理' || rList[0].CancellationReason__c == '其他' |
| | | || rList[0].CancellationReason__c == '修理价格高' || rList[0].CancellationReason__c == '坚持继续使用' || rList[0].CancellationReason__c == '无法修理' |
| | | || rList[0].CancellationReason__c == '修理价格太高' || rList[0].CancellationReason__c == '用户坚持继续使用' || rList[0].CancellationReason__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 + '弃修'; |
| | | } |
| | | } else { |
| | | a.Reson_Can_not_Warranty__c = '弃修'; |
| | | } |
| | | } |
| | | // 20230207“弃修”“修理中”设备判断逻辑修改 end |
| | | if (rList[0].Return_Without_Repair_Reason__c == '1.修理价格太高' || rList[0].Return_Without_Repair_Reason__c == '2.到其他公司修理' |
| | | || rList[0].Return_Without_Repair_Reason__c == '4.坚持继续使用' || rList[0].Return_Without_Repair_Reason__c == '3.报价单超期' |
| | | || rList[0].Return_Without_Repair_Reason__c == '5.废弃' || rList[0].Return_Without_Repair_Reason__c == '6.购买新品' |
| | | || 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 + '弃修'; |
| | | } |
| | |
| | | // 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) { |
| | |
| | | } |
| | | // 20210622 SQL优化 End |
| | | |
| | | System.debug('===========> end'); |
| | | } |
| | | |
| | | //wwp 2021/10/15 维修中心赋值新加西安 杭州 成都 start |
| | |
| | | } |
| | | } |
| | | }else if(repair.On_site_repair__c == '办事处修理' || repair.On_site_repair__c== '现场修理'){ |
| | | if(repair.Sales_Branch__c == '上海分公司'){ |
| | | /** 20230313 you DB202303171085 |
| | | if(repair.Sales_Branch__c == '上海分公司'){ |
| | | if (hzProvince.contains(repair.SalesOfficeCode_selection__c)) { |
| | | repair.work_location_select__c = '杭州共通办事处'; |
| | | leakDefaultFlag = false; |
| | | } |
| | | } else if(repair.Sales_Branch__c == '广州分公司'){ |
| | | } else **/ |
| | | if(repair.Sales_Branch__c == '广州分公司'){ |
| | | if (cdProvince.contains(repair.SalesOfficeCode_selection__c)) { |
| | | repair.work_location_select__c = '成都共通办事处'; |
| | | leakDefaultFlag = false; |
| | |
| | | leakDefaultFlag = false; |
| | | } |
| | | }else if(repair.On_site_repair__c == '办事处修理' || repair.On_site_repair__c== '现场修理'){ |
| | | /** 20230313 you DB202303171085 |
| | | if(repair.Contract_Principal_Office__c == '上海RC'){ |
| | | if (hzProvince.contains(repair.SalesOfficeCode_selection__c)) { |
| | | repair.work_location_select__c = '杭州共通办事处'; |
| | | leakDefaultFlag = false; |
| | | } |
| | | } else if(repair.Contract_Principal_Office__c == '广州RC'){ |
| | | } else **/ |
| | | if(repair.Contract_Principal_Office__c == '广州RC'){ |
| | | if (cdProvince.contains(repair.SalesOfficeCode_selection__c)) { |
| | | repair.work_location_select__c = '成都共通办事处'; |
| | | leakDefaultFlag = false; |
| | |
| | | } |
| | | } |
| | | }else if(repair.On_site_repair__c == '办事处修理' || repair.On_site_repair__c== '现场修理'){ |
| | | /** 20230313 you DB202303171085 |
| | | if(repair.Sales_Branch__c == '上海分公司'){ |
| | | //根据修理品返送地为非北京 |
| | | if (hzProvince.contains(repair.SalesOfficeCode_selection__c)) { |
| | | repair.work_location_select__c = '杭州共通办事处'; |
| | | leakDefaultFlag = false; |
| | | } |
| | | } else if(repair.Sales_Branch__c == '广州分公司'){ |
| | | } else **/ |
| | | if(repair.Sales_Branch__c == '广州分公司'){ |
| | | //根据修理品返送地为非北京 |
| | | if (cdProvince.contains(repair.SalesOfficeCode_selection__c)) { |
| | | repair.work_location_select__c = '成都共通办事处'; |
| | |
| | | leakDefaultFlag = false; |
| | | } |
| | | }else if(repair.On_site_repair__c == '办事处修理' || repair.On_site_repair__c== '现场修理'){ |
| | | /** 20230313 you DB202303171085 |
| | | if(middleTable.Maintenance_Contract__r.SalesOfficeCode_selection__c == '上海RC'){ |
| | | if (hzProvince.contains(repair.SalesOfficeCode_selection__c)) { |
| | | repair.work_location_select__c = '杭州共通办事处'; |
| | | leakDefaultFlag = false; |
| | | } |
| | | } else if(middleTable.Maintenance_Contract__r.SalesOfficeCode_selection__c == '广州RC'){ |
| | | } else**/ |
| | | if(middleTable.Maintenance_Contract__r.SalesOfficeCode_selection__c == '广州RC'){ |
| | | if (cdProvince.contains(repair.SalesOfficeCode_selection__c)) { |
| | | repair.work_location_select__c = '成都共通办事处'; |
| | | leakDefaultFlag = false; |
| | |
| | | return repair; |
| | | } |
| | | //add wangweipeng 2021/12/09 end |
| | | //先款后修-修理增加先款标识 thh 20220318 start |
| | | //先款后修-修理增加先款标识 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>(); |
| | | List<Repair__c> updateRepairList = new List<Repair__c>(); |
| | | System.debug('newList1:' + newList); |
| | | for(Repair__c rep : newList){ |
| | | if(rep.Repair_Quotation_Id__c != null){ |
| | | RepairQuotationIdList.add(rep.Repair_Quotation_Id__c); |
| | |
| | | NoRepairQuotationList.add(rep); |
| | | } |
| | | } |
| | | System.debug('RepairQuotationIdList1:' + RepairQuotationIdList); |
| | | System.debug('NoRepairQuotationList1:' + NoRepairQuotationList); |
| | | //同期中的修理修理报价有值时,看报价上的先款标识进行赋值 |
| | | if(RepairQuotationIdList.size() > 0){ |
| | | RepairQuotationList = [select Id, Is_RecognitionModel__c from Repair_Quotation__c where Id IN :RepairQuotationIdList]; |
| | | 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; |
| | | // updateRepairList.add(rep); |
| | | } |
| | | } |
| | | } |
| | |
| | | for(Repair__c rep : newList){ |
| | | if(rep.Dealer__c == dealer.Id){ |
| | | rep.Advance_Payment_Flag__c = dealer.FirstParagraphEnd__c; |
| | | // updateRepairList.add(rep); |
| | | } |
| | | } |
| | | } |
| | | // if(updateRepairList.size() > 0){ |
| | | // update updateRepairList; |
| | | // } |
| | | } |
| | | //先款后修-修理增加先款标识 thh 20220318 end |
| | | //先款后修-修理增加先款标识 thh 20220322 end |
| | | |
| | | public static void CheckUpdate(List<Repair__c> oldList, Map<Id, Repair__c> newMap) { |
| | | System.debug('===========> start'); |
| | |
| | | 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; |
| | | } |
| | |
| | | // 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'); |
| | | |
| | | } |
| | | |
| | | } |