张宇恒
2022-12-23 ec47f5ab5923a315bf22e0df5af7371e9668589e
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
trigger AssetImageBeforeTrigger on Asset (before insert, before update) {
    if (trigger.isBefore) {
        for(Asset newS : trigger.new) {
            if (Trigger.isUpdate && newS.Status == '使用中'
                    && String.isBlank(((Asset) Trigger.oldMap.get(newS.Id)).ImageAsset__c)
                    && !String.isBlank(newS.ImageAsset__c)
            ) {
                newS.ImageAssetUploadedTime__c = Datetime.now();
                newS.ImageAssetUploadedBy__c = UserInfo.getUserId();
            }
            if (Trigger.isUpdate && newS.Status == '使用中'
                        && String.isBlank(((Asset) Trigger.oldMap.get(newS.Id)).ImageSerial__c)
                    && !String.isBlank(newS.ImageSerial__c)
            ) {
                newS.ImageSerialUploadedTime__c = Datetime.now();
                newS.ImageSerialUploadedBy__c = UserInfo.getUserId();
            }
 
             System.debug('-------->Start');
            if(Trigger.isUpdate && !String.isBlank(((Asset)Trigger.oldMap.get(newS.Id)).Reson_Can_not_Warranty__c)){
                String reason = ((Asset)Trigger.oldMap.get(newS.Id)).Reson_Can_not_Warranty__c;
 
                System.debug('oldreason'+reason);
                System.debug('reason'+newS.Reson_Can_not_Warranty__c);
                System.debug('Asset_Owner__c'+newS.Asset_Owner__c);
                if(newS.Asset_Owner__c != '病院資産'){
                    if(newS.Reson_Can_not_Warranty__c != null){
                        if(!newS.Reson_Can_not_Warranty__c.contains('备品')){
                            // newS.Reson_Can_not_Warranty__c = reason + '备品';
                            newS.Reson_Can_not_Warranty__c = newS.Reson_Can_not_Warranty__c + '备品';
                        }
                    }else{
                        newS.Reson_Can_not_Warranty__c = '备品';
                    }
                    
                }else{
                    if(newS.Reson_Can_not_Warranty__c != null){
                        if(newS.Reson_Can_not_Warranty__c.contains('备品')){
                            //newS.Reson_Can_not_Warranty__c = reason.replace('备品', '');
                            newS.Reson_Can_not_Warranty__c = newS.Reson_Can_not_Warranty__c.replace('备品', '');
                        }
                    }
                }
                if(newS.Final_Examination_Date__c != null){
                    if(Date.today().addDays(-90) > newS.Final_Examination_Date__c){
                        if(!reason.contains('点检')){
                            newS.Reson_Can_not_Warranty__c = reason + '点检';
                        }
                    }else{
                        if(reason.contains('点检')){
                            newS.Reson_Can_not_Warranty__c = reason.replace('点检', '');
                        }
                    }
                }else{
                    if(reason.contains('点检')){
                        newS.Reson_Can_not_Warranty__c = reason.replace('点检', '');
                    }
                }
                
            }else if(Trigger.isInsert || Trigger.isUpdate && String.isBlank(((Asset)Trigger.oldMap.get(newS.Id)).Reson_Can_not_Warranty__c)){
                if(newS.Asset_Owner__c != '病院資産'){
                    newS.Reson_Can_not_Warranty__c = '备品';
                }else{
                    if(newS.Reson_Can_not_Warranty__c != null){
                        if(newS.Reson_Can_not_Warranty__c.contains('备品')){
                            //newS.Reson_Can_not_Warranty__c = reason.replace('备品', '');
                            newS.Reson_Can_not_Warranty__c = newS.Reson_Can_not_Warranty__c.replace('备品', '');
                        }
                    }
                }
                if(newS.Final_Examination_Date__c != null){
                    if(Date.today().addDays(-90) > newS.Final_Examination_Date__c){
                        newS.Reson_Can_not_Warranty__c = '点检';
                    }
                }
 
            }
            System.debug('-------->End');
        }
    }    
}