张宇恒
2022-03-21 26d42e9bb57aec5d41276f01cfbe9d8a46d64b95
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
trigger DailyReportSetHospitalCount on Daily_Report__c (after update) {
    /*
    List<String> accParentList = new List<String>();
    List<Date> actDateList1 = new List<Date>();
    List<String> accParentParentList = new List<String>();
    List<Date> actDateList2 = new List<Date>();
    */
    List<String> eIdList = new List<String>();
 
    List<Id> drId = new List<Id>();
    for (Daily_Report__c dr : Trigger.new) {
        if (Trigger.isUpdate) {
            if (Trigger.oldMap.get(dr.Id).get('Status__c') != dr.Status__c) {
                drId.add(dr.Id);
            }
        }
    }
    List<Event__c> ecList = [Select Id, ActivityDate__c, AccountParentId__c, AccountParentParentId__c from Event__c where AccountParentId__c <> null and Daily_Report__c in :drId];
    for (Event__c ec : ecList) {
        // 報告日は現在日時の前後100日以内のみ対応
        Integer days = ec.ActivityDate__c.daysBetween(Date.today());
        if (days >= -ControllerUtil.ReportDayRange && days <= ControllerUtil.ReportDayRange) {
            /*
            accParentList.add(ec.AccountParentId__c);
            actDateList1.add(ec.ActivityDate__c);
            if (!String.isBlank(ec.AccountParentParentId__c)) {
                accParentParentList.add(ec.AccountParentParentId__c);
                actDateList2.add(ec.ActivityDate__c);
            }
            */
            eIdList.add(ec.Id);
        }
    }
    
    // 活動1,2,3を空更新
    List<Activity_History_Daily_Report__c> ahdrList = [select Id from Activity_History_Daily_Report__c where EventC_ID__c in :eIdList];
    List<Event_Oppotunity__c> eoList = [select Id from Event_Oppotunity__c where EventC_ID__c in :eIdList];
    List<Event_Service__c> esList = [select Id from Event_Service__c where EventC_ID__c in :eIdList];
    
    if (ahdrList.size() > 0) update ahdrList;
    if (eoList.size() > 0) update eoList;
    if (esList.size() > 0) update esList;
    
    //ControllerUtil.updateAccountMonth(accParentList, actDateList1, accParentParentList, actDateList2);
}