GWY
2022-05-21 a3460549533111815e7f73d6cef601a58031525d
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
public without sharing class RepairTriggerHandler {
    public static void setdate(List<Repair__c> newList, Map<Id, Repair__c> newMap, List<Repair__c> oldList, Map<Id, Repair__c> oldMap) {
        for(Repair__c rep : newList){
            if(rep.RecordTypeId == '0120K000000wOGe'){
           // if(rep.RecordTypeId == '0120l000000WwBL'){
                if(rep.ServicePlace__c == '现场'){
                    if( rep.CustomerRequestDate__c == null || rep.ServiceStartDate__c== null){
                        rep.StartDatenwb__c  = null;
                    }else{
                        Map<String,OlympusCalendar__c> dateMap = calendarUtil.getCalendarMap(rep.CustomerRequestDate__c,rep.ServiceStartDate__c);
                        rep.StartDatenwb__c = (calendarUtil.getNumfromCalendarMap(dateMap,rep.CustomerRequestDate__c,rep.ServiceStartDate__c)-1)+'';
                    }
                }
                               
                if(rep.ServiceType__c=='维修' ){
                    if(rep.ServiceProperty__c =='有偿'){
                       if( rep.QuotationAgreeDate__c == null || rep.CompletionDate__c== null){
                           rep.MaintenanceDatewb__c  = null;
                       }else{
                           Map<String,OlympusCalendar__c> dateMap = calendarUtil.getCalendarMap(rep.QuotationAgreeDate__c,rep.CompletionDate__c);
                           rep.MaintenanceDatewb__c = (calendarUtil.getNumfromCalendarMap(dateMap,rep.QuotationAgreeDate__c,rep.CompletionDate__c)-1)+'';
                       }
                    }else if(rep.ServiceProperty__c =='无偿'){
                       if( rep.ServiceStartDate__c == null || rep.CompletionDate__c== null){
                           rep.MaintenanceDatewb__c  = null;
                       }else{
                           Map<String,OlympusCalendar__c> dateMap = calendarUtil.getCalendarMap(rep.ServiceStartDate__c,rep.CompletionDate__c);
                           rep.MaintenanceDatewb__c = (calendarUtil.getNumfromCalendarMap(dateMap,rep.ServiceStartDate__c,rep.CompletionDate__c)-1)+'';
                       }
                    }else{
                        rep.MaintenanceDatewb__c = null;
                    }
                }else{
                    rep.MaintenanceDatewb__c = null;
                }
                    
                if(rep.ServiceType__c=='维修' ){
                    if(rep.QuotationAgreeDate__c == null ){
                       if( rep.BugDate__c == null || rep.CompletionDate__c == null){
                            rep.Downtime__c = null;
                       }else{
                           Map<String,OlympusCalendar__c> dateMap = calendarUtil.getCalendarMap(rep.BugDate__c,rep.CompletionDate__c);
                           rep.Downtime__c = (calendarUtil.getNumfromCalendarMap(dateMap,rep.BugDate__c,rep.CompletionDate__c)-1)+'';
                       }
                    }else{
                        
                        if(rep.QuotationDate__c == null || rep.QuotationAgreeDate__c == null || rep.BugDate__c == null || rep.CompletionDate__c == null){
                            rep.Downtime__c = null;
                        }else{
                    
                           Integer num1 = 0;
                           Integer num2 = 0;
                       
                           Map<String,OlympusCalendar__c> dateMap = calendarUtil.getCalendarMap(rep.QuotationDate__c,rep.QuotationAgreeDate__c);
                           num1 = calendarUtil.getNumfromCalendarMap(dateMap,rep.QuotationDate__c,rep.QuotationAgreeDate__c)-1;
                       
                           Map<String,OlympusCalendar__c> dateMap1 = calendarUtil.getCalendarMap(rep.BugDate__c,rep.CompletionDate__c);
                           num2 = calendarUtil.getNumfromCalendarMap(dateMap1,rep.BugDate__c,rep.CompletionDate__c)-1;
                       
                           rep.Downtime__c = (num2 - num1)+'';
                       }
                    }                    
                }else{
                    rep.Downtime__c = null;
                }               
            }else if(rep.RecordTypeId == '0120K000000wOGg'){ //else if(rep.RecordTypeId == '0120l000000WwBQ'){
                if(rep.ServicePlace__c == '现场'){
                    if( rep.QuotationAgreeDate__c == null || rep.ReciveRepairDay__c== null){
                        rep.StartDatenwb__c  = null;
                    }else{
                        Map<String,OlympusCalendar__c> dateMap = calendarUtil.getCalendarMap(rep.ReciveRepairDay__c,rep.QuotationAgreeDate__c);
                        rep.StartDatenwb__c = (calendarUtil.getNumfromCalendarMap(dateMap,rep.ReciveRepairDay__c,rep.QuotationAgreeDate__c)-1)+'';
                    }
                }
                               
                if(rep.ServiceType__c=='维修' ||rep.ServiceType__c=='维护' ){
                 
                       if( rep.CompletionDate__c == null || rep.QuotationAgreeDate__c== null){
                           rep.MaintenanceDatewb__c  = null;
                       }else{
                           Map<String,OlympusCalendar__c> dateMap = calendarUtil.getCalendarMap(rep.QuotationAgreeDate__c,rep.CompletionDate__c);
                           rep.MaintenanceDatewb__c = (calendarUtil.getNumfromCalendarMap(dateMap,rep.QuotationAgreeDate__c,rep.CompletionDate__c)-1)+'';
                       }
                }else{
                    rep.MaintenanceDatewb__c = null;
                }
                    
                if(rep.ServiceType__c=='维修'||rep.ServiceType__c=='维护' ){
                    if(rep.ReciveRepairDay__c == null || rep.CompletionDate__c == null ){
                        rep.Downtime__c = null;
                    }else{
                       if( rep.ReciveRepairDay__c ==  rep.CompletionDate__c){
                            rep.Downtime__c ='0';
                       }else{
                           if(rep.QuotationDate__c == null || rep.QuotationAgreeDate__c == null || rep.ReciveRepairDay__c == null || rep.CompletionDate__c == null){
                               rep.Downtime__c = null;
                            }else{
                    
                                Integer num1 = 0;
                                Integer num2 = 0;
                       
                                Map<String,OlympusCalendar__c> dateMap = calendarUtil.getCalendarMap(rep.QuotationDate__c,rep.QuotationAgreeDate__c);
                                num1 = calendarUtil.getNumfromCalendarMap(dateMap,rep.QuotationDate__c,rep.QuotationAgreeDate__c)-1;
                       
                                Map<String,OlympusCalendar__c> dateMap1 = calendarUtil.getCalendarMap(rep.ReciveRepairDay__c,rep.CompletionDate__c);
                                num2 = calendarUtil.getNumfromCalendarMap(dateMap1,rep.ReciveRepairDay__c,rep.CompletionDate__c)-1;
                       
                                rep.Downtime__c = (num2 - num1)+'';
                           }   
                       }                        
                    }                    
                }else{
                    rep.Downtime__c = null;
                }                               
            }
        }    
    }
}