高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
force-app/main/default/triggers/NFM010UpsertStatuAchievements.trigger
@@ -2,6 +2,11 @@
 * 注残出納表をupsert
 */
trigger NFM010UpsertStatuAchievements on Statu_Achievements__c (after insert, after update) {
    // SWAG-CE55BX 预测优化 start
    if (StaticParameter.EscapeOppandStaTrigger) {
        return;
    }
    // SWAG-CE55BX 预测优化 end
    // CHAN-AZM8SE 2018/8/27 start
    if (Label.update_Statu_Achievements_Journal.equals('true')) {
        return;
@@ -426,6 +431,57 @@
        }
    }
    //20230203 lt DB202301351834  新品发货日赋值  start
    List<String> SIDList = new List<String>();
    List<QIS_Report__c> UpdQISList = new List<QIS_Report__c>();
    if(Trigger.isInsert || Trigger.isUpdate){
        System.debug('---lt123---进判断---');
        for (Statu_Achievements__c sta : Trigger.new){
            if(Trigger.isInsert){
                if(sta.Status_1__c != '退货' && sta.Status_1__c != '无效' && sta.ContractNO__c != null  && sta.DeliveryDate__c != null){
                    if(!SIDList.contains(sta.ContractNO__c)){
                        SIDList.add(sta.ContractNO__c);
                    }
                }
            }else{
                Statu_Achievements__c OldSta = Trigger.oldMap.get(sta.id);
                if(sta.Status_1__c != '退货' && sta.Status_1__c != '无效' && sta.ContractNO__c != null  && sta.DeliveryDate__c != null && (sta.DeliveryDate__c != OldSta.DeliveryDate__c || (System.Label.onlyupdate == '1' && UserInfo.getUserId() == '00510000005sEEMAA2'))){
                    if(!SIDList.contains(sta.ContractNO__c)){
                        SIDList.add(sta.ContractNO__c);
                    }
                }
            }
        }
    }
    System.debug('---lt123---合同编号list---'+SIDList);
    System.debug('---lt123---合同编号listSize---'+SIDList.size());
    if(SIDList.size() > 0 ){
        list<QIS_Report__c> QISList =
            [Select id, NewProDeliveryDate__c, Order_No__c
             From QIS_Report__c
             Where Order_No__c in: SIDList];
        System.debug('---lt123---QISlist---'+QISList);
        System.debug('---lt123---QISlistSize---'+QISList.size());
        if(QISList.size() > 0 ){
            for(QIS_Report__c qiss : QISList){
                for (Statu_Achievements__c sta : Trigger.new){
                    if(qiss.Order_No__c == sta.ContractNO__c){
                        qiss.NewProDeliveryDate__c = sta.DeliveryDate__c;
                        UpdQISList.add(qiss);
                    }
                }
            }
        }
        if(UpdQISList.size() > 0 ){
            update UpdQISList;
        }
    }
    //20230203 lt DB202301351834  新品发货日赋值  end
    // SoNo_DeliveryDate_Text__c にて upsert
    if (stajUpsertMap.size() > 0) {
        ControllerUtil.upsertStatuAchievementsJournalByKey(stajUpsertMap.values());