liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
public without sharing class AssessmentReportHandler extends Oly_TriggerHandler {
 
    private Map<Id, AssessmentReport__C> newMap;
    private Map<Id, AssessmentReport__C> oldMap;
    private List<AssessmentReport__C> newList;
    private List<AssessmentReport__C> oldList;
 
 
    public AssessmentReportHandler() {
        this.newMap = (Map<Id, AssessmentReport__C>) Trigger.newMap;
        this.oldMap = (Map<Id, AssessmentReport__C>) Trigger.oldMap;
        this.newList = (List<AssessmentReport__C>) Trigger.new;
        this.oldList = (List<AssessmentReport__C>) Trigger.old;
    }
 
 
    protected override void afterUpdate() {
        SetupFinalGrade();
    }
 
    //设置最终考核成绩到服务技师培训主页面上去
    private void SetupFinalGrade() {
        System.debug( 'SetupFinalGrade start: ' );
        list<AssessmentReport__C> AssessReportlist = new list<AssessmentReport__C>();
        list<Campaign> updateCamlist = new list<Campaign>();
        for (AssessmentReport__C  temAR : newList) {
            AssessmentReport__C oldResult = oldMap.get(temAR.id);
            if (temAR.Status__c !=null &&
                !oldResult.Status__c.equals('批准')
                    && temAR.Status__c.equals('批准')
                    && temAR.Type__c.equals('考核')) {
                AssessReportlist.add(temAR);
                if (temAR.TeachingDate__c != null && temAR.TeachingDate__c.day() >= 15) {
                    updateCamlist.add(new Campaign(id = temAR.Campaign__c, Mailflg_6Month_service__c = 7));
                } else if (temAR.TeachingDate__c != null && temAR.TeachingDate__c.day() <= 15) {
                    updateCamlist.add(new Campaign(id = temAR.Campaign__c, Mailflg_6Month_service__c = 6));
                }
            }
        }
        list<CampaignMember__c> updateCMlist = new list<CampaignMember__c>();
        list<AssessmentReportStaff__c> AssessmentReportStafflist
            = [select id , CampaignMember__c, Grade__c
               from AssessmentReportStaff__c
               where AssessmentReport__c in: AssessReportlist
               and CampaignMember__c != null ];
        for (AssessmentReportStaff__c temARS : AssessmentReportStafflist) {
            CampaignMember__c temCAM =
                new CampaignMember__c(id = temARS.CampaignMember__c,
                                      Grade__c = temARS.Grade__c );
            updateCMlist.add(temCAM);
        }
        if (updateCMlist.size() > 0) {
            update updateCMlist;
        }
        if (updateCamlist.size() > 0) {
            update updateCamlist;
        }
 
 
    }
}