高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
public with sharing class RepairAgainAnHandler extends Oly_TriggerHandler{
    private Map<Id, RepairAgainAn__c> newMap;
    private Map<Id, RepairAgainAn__c> oldMap;
    private List<RepairAgainAn__c> newList;
    private List<RepairAgainAn__c> oldList;
 
    public RepairAgainAnHandler() {
        this.newMap = (Map<Id, RepairAgainAn__c>) Trigger.newMap;
        this.oldMap = (Map<Id, RepairAgainAn__c>) Trigger.oldMap;
        this.newList = (List<RepairAgainAn__c>) Trigger.new;
        this.oldList = (List<RepairAgainAn__c>) Trigger.old;
    }
 
    protected override void beforeInsert() {
        setPhotoImgText();
    }
    protected override void beforeUpdate() {
        setPhotoImgText();
    }
    public static Set<Id> RA_Ids = new Set<Id>();
    
    private void setPhotoImgText() {
        for (RepairAgainAn__c ra : newList) {
            System.debug('ra.Dectect_Picture1__c2:' + ra.Dectect_Picture1__c);
            // 禁止重复执行
            if (RA_Ids.contains(ra.Id)) continue;
            // 本次报价检测图片1
            if (Trigger.isAfter && Trigger.isInsert && String.isBlank(ra.Dectect_Picture1__c) == false
                    || (Trigger.isUpdate && ((RepairAgainAn__c) oldMap.get(ra.Id)).Dectect_Picture1__c != ra.Dectect_Picture1__c)
                    || (Trigger.isUpdate && String.isBlank(ra.Dectect_Picture1__c) == false && String.isBlank(ra.Dectect_Picture1_URL__c))
            ) {
                String phtTxt = '';
                if (String.isBlank(ra.Dectect_Picture1__c) == false) {
                    Integer pStt = ra.Dectect_Picture1__c.indexOf('<img');
                    if (pStt >= 0) {
                        pStt = ra.Dectect_Picture1__c.indexOf('src="');
                        if (pStt >= 0) {
                            Integer pEnd = ra.Dectect_Picture1__c.indexOf('"', pStt + 5);
                            if (pEnd >= 0) {
                                phtTxt = ra.Dectect_Picture1__c.substring(pStt + 5, pEnd);
                                System.debug('ra.Dectect_Picture1__c1:' + ra.Dectect_Picture1__c);
                                System.debug('phtTxt1:' + phtTxt);
                                //富文本反转义
                                phtTxt = phtTxt.unescapeHtml4();
                                System.debug('phtTxt2:' + phtTxt);
                            }
                        }
                    }
                }
                ra.Dectect_Picture1_URL__c = phtTxt;
                RA_Ids.add(ra.Id);
            }
            // 本次报价检测图片2
            if (Trigger.isAfter && Trigger.isInsert && String.isBlank(ra.Dectect_Picture2__c) == false
                    || (Trigger.isUpdate && ((RepairAgainAn__c) oldMap.get(ra.Id)).Dectect_Picture2__c != ra.Dectect_Picture2__c)
                    || (Trigger.isUpdate && String.isBlank(ra.Dectect_Picture2__c) == false && String.isBlank(ra.Dectect_Picture2_URL__c))
            ) {
                String phtTxt = '';
                if (String.isBlank(ra.Dectect_Picture2__c) == false) {
                    Integer pStt = ra.Dectect_Picture2__c.indexOf('<img');
                    if (pStt >= 0) {
                        pStt = ra.Dectect_Picture2__c.indexOf('src="');
                        if (pStt >= 0) {
                            Integer pEnd = ra.Dectect_Picture2__c.indexOf('"', pStt + 5);
                            if (pEnd >= 0) {
                                phtTxt = ra.Dectect_Picture2__c.substring(pStt + 5, pEnd);
                                //富文本反转义
                                phtTxt = phtTxt.unescapeHtml4();
                            }
                        }
                    }
                }
                ra.Dectect_Picture2_URL__c = phtTxt;
                RA_Ids.add(ra.Id);
            }
            // OSH技术检测图片1
            if (Trigger.isInsert && String.isBlank(ra.OSH_Dectect_Picture1__c) == false
                    || (Trigger.isUpdate && ((RepairAgainAn__c) oldMap.get(ra.Id)).OSH_Dectect_Picture1__c != ra.OSH_Dectect_Picture1__c)
                    || (Trigger.isUpdate && String.isBlank(ra.OSH_Dectect_Picture1__c) == false && String.isBlank(ra.OSH_Dectect_Picture1_URL__c))
            ) {
                String phtTxt = '';
                if (String.isBlank(ra.OSH_Dectect_Picture1__c) == false) {
                    Integer pStt = ra.OSH_Dectect_Picture1__c.indexOf('<img');
                    if (pStt >= 0) {
                        pStt = ra.OSH_Dectect_Picture1__c.indexOf('src="');
                        if (pStt >= 0) {
                            Integer pEnd = ra.OSH_Dectect_Picture1__c.indexOf('"', pStt + 5);
                            if (pEnd >= 0) {
                                phtTxt = ra.OSH_Dectect_Picture1__c.substring(pStt + 5, pEnd);
                                System.debug('ra.OSH_Dectect_Picture1__c1:' + ra.OSH_Dectect_Picture1__c);
                                System.debug('phtTxt3:' + phtTxt);
                                //富文本反转义
                                phtTxt = phtTxt.unescapeHtml4();
                                System.debug('phtTxt4:' + phtTxt);
                            }
                        }
                    }
                }
                ra.OSH_Dectect_Picture1_URL__c = phtTxt;
                RA_Ids.add(ra.Id);
            }
            // OSH技术检测图片2
            if (Trigger.isInsert && String.isBlank(ra.OSH_Dectect_Picture2__c) == false
                    || (Trigger.isUpdate && ((RepairAgainAn__c) oldMap.get(ra.Id)).OSH_Dectect_Picture2__c != ra.OSH_Dectect_Picture2__c)
                    || (Trigger.isUpdate && String.isBlank(ra.OSH_Dectect_Picture2__c) == false && String.isBlank(ra.OSH_Dectect_Picture2_URL__c))
            ) {
                String phtTxt = '';
                if (String.isBlank(ra.OSH_Dectect_Picture2__c) == false) {
                    Integer pStt = ra.OSH_Dectect_Picture2__c.indexOf('<img');
                    if (pStt >= 0) {
                        pStt = ra.OSH_Dectect_Picture2__c.indexOf('src="');
                        if (pStt >= 0) {
                            Integer pEnd = ra.OSH_Dectect_Picture2__c.indexOf('"', pStt + 5);
                            if (pEnd >= 0) {
                                phtTxt = ra.OSH_Dectect_Picture2__c.substring(pStt + 5, pEnd);
                                //富文本反转义
                                phtTxt = phtTxt.unescapeHtml4();
                            }
                        }
                    }
                }
                ra.OSH_Dectect_Picture2_URL__c = phtTxt;
                RA_Ids.add(ra.Id);
            }
            // OSH技术检测图片3
            if (Trigger.isInsert && String.isBlank(ra.OSH_Dectect_Picture3__c) == false
                    || (Trigger.isUpdate && ((RepairAgainAn__c) oldMap.get(ra.Id)).OSH_Dectect_Picture3__c != ra.OSH_Dectect_Picture3__c)
                    || (Trigger.isUpdate && String.isBlank(ra.OSH_Dectect_Picture3__c) == false && String.isBlank(ra.OSH_Dectect_Picture3_URL__c))
            ) {
                String phtTxt = '';
                if (String.isBlank(ra.OSH_Dectect_Picture3__c) == false) {
                    Integer pStt = ra.OSH_Dectect_Picture3__c.indexOf('<img');
                    if (pStt >= 0) {
                        pStt = ra.OSH_Dectect_Picture3__c.indexOf('src="');
                        if (pStt >= 0) {
                            Integer pEnd = ra.OSH_Dectect_Picture3__c.indexOf('"', pStt + 5);
                            if (pEnd >= 0) {
                                phtTxt = ra.OSH_Dectect_Picture3__c.substring(pStt + 5, pEnd);
                                //富文本反转义
                                phtTxt = phtTxt.unescapeHtml4();
                            }
                        }
                    }
                }
                ra.OSH_Dectect_Picture3_URL__c = phtTxt;
                RA_Ids.add(ra.Id);
            }
            // OSH技术检测图片4
            if (Trigger.isInsert && String.isBlank(ra.OSH_Dectect_Picture4__c) == false
                    || (Trigger.isUpdate && ((RepairAgainAn__c) oldMap.get(ra.Id)).OSH_Dectect_Picture4__c != ra.OSH_Dectect_Picture4__c)
                    || (Trigger.isUpdate && String.isBlank(ra.OSH_Dectect_Picture4__c) == false && String.isBlank(ra.OSH_Dectect_Picture4_URL__c))
            ) {
                String phtTxt = '';
                if (String.isBlank(ra.OSH_Dectect_Picture4__c) == false) {
                    Integer pStt = ra.OSH_Dectect_Picture4__c.indexOf('<img');
                    if (pStt >= 0) {
                        pStt = ra.OSH_Dectect_Picture4__c.indexOf('src="');
                        if (pStt >= 0) {
                            Integer pEnd = ra.OSH_Dectect_Picture4__c.indexOf('"', pStt + 5);
                            if (pEnd >= 0) {
                                phtTxt = ra.OSH_Dectect_Picture4__c.substring(pStt + 5, pEnd);
                                //富文本反转义
                                phtTxt = phtTxt.unescapeHtml4();
                            }
                        }
                    }
                }
                ra.OSH_Dectect_Picture4_URL__c = phtTxt;
                RA_Ids.add(ra.Id);
            }
        }
    }
}