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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
public without sharing class RentalApplyShareHandler extends Oly_TriggerHandler {
 
    private Map<Id, Rental_Apply__c> newMap;
    private Map<Id, Rental_Apply__c> oldMap;
    private List<Rental_Apply__c> newList;
    private List<Rental_Apply__c> oldList;
    public RentalApplyShareHandler() {
 
        this.newMap = (Map<Id, Rental_Apply__c>) Trigger.newMap;
        this.oldMap = (Map<Id, Rental_Apply__c>) Trigger.oldMap;
        this.newList = (List<Rental_Apply__c>) Trigger.new;
        this.oldList = (List<Rental_Apply__c>) Trigger.old;
    }
    protected override void afterInsert() {
        addStrategiccShare();
    }
    protected override void afterUpdate() {
        addStrategiccShare();
    }
 
    protected override void beforeInsert() {
        dataCheck();
    }
    protected override void beforeUpdate() {
        dataCheck();
    }
 
 
    //add by rentx 2020-12-03 start 新建共享数据
    private Rental_Apply__Share makeData(String parentId, String userId) {
        Rental_Apply__Share ras = new Rental_Apply__Share();
        ras.RowCause = 'Manual';
        ras.ParentId = parentId;
        ras.UserOrGroupId = userId;
        ras.AccessLevel = 'Edit';
 
        return ras;
    }
    //add by rentx 2020-12-03 end 新建共享数据
    private void addStrategiccShare() {
        List<Rental_Apply__c> raList = new List<Rental_Apply__c>();
        List<Rental_Apply__Share> delStrategList = new List<Rental_Apply__Share>();
        List<Rental_Apply__Share> addStrategList = new List<Rental_Apply__Share>();
        //20210728 ljh SFDC-C5645S start
        List<Rental_Apply__Share> addStrategListL = new List<Rental_Apply__Share>();
        Set<String> ParentIdSet = new Set<String>();
        Set<String> UserOrGroupIdSet = new Set<String>();
        Set<String> UserOrGroupIdOldSet = new Set<String>();
        Map<String, Rental_Apply__c> PUMap = new Map<String, Rental_Apply__c>();
        Map<String, Rental_Apply__c> RAUMap = new Map<String, Rental_Apply__c>();
        List<String> IsActiveNoList = new List<String>();
        //20210728 ljh SFDC-C5645S end
        for (Rental_Apply__c nObj : newList) {
            if (nObj.Strategic_user__c != null && (Trigger.isInsert || (nObj.ShareFlag__c == true && Trigger.isUpdate))) {
                // 20210924 ljh SFDC-C758NB update substring(0,15) start
                // if (!nObj.Strategic_user__c.equals(nObj.OwnerId)
                if (!String.valueOf(nObj.Strategic_user__c).substring(0,15).equals(String.valueOf(nObj.OwnerId).substring(0,15))
                        && (nObj.Approver_of_Service_Department__c == null 
                            || ( nObj.Approver_of_Service_Department__c != null && !String.valueOf(nObj.Strategic_user__c).substring(0,15).equals(String.valueOf(nObj.Approver_of_Service_Department__c).substring(0,15)) )
                        )
                   ) {
                    // 20210924 ljh SFDC-C758NB update substring(0,15) end
                    Rental_Apply__Share ras = new Rental_Apply__Share(
                        RowCause = 'Manual',
                        ParentId = nObj.Id,
                        UserOrGroupId = nObj.Strategic_user__c,
                        AccessLevel = 'read'
                    );
                    addStrategList.add(ras);
                }
                //20210728 ljh SFDC-C5645S start
                // Rental_Apply__c ra = new Rental_Apply__c();
                // ra.Id = nObj.Id;
                // ra.ShareStrategicUser__c = nObj.Strategic_user__c;
                // raList.add(ra);
                //20210728 ljh SFDC-C5645S end
            }
            //判断战略科室主担当是否发生更改
            if (nObj.ShareFlag__c == true && Trigger.isUpdate) {
                //删除原来的共享
                PUMap.put(nObj.Id, nObj);
                if (String.isNotBlank(nObj.ShareStrategicUser__c)) {
                    ParentIdSet.add(nObj.Id);
                    UserOrGroupIdOldSet.add(nObj.ShareStrategicUser__c);
                }
            }
            if ( nObj.hospitalLeaderGIchange__c || nObj.hospitalLeaderSPchange__c ) {
                // if (nObj.hospitalLeaderGIchange__c) {
                if (nObj.hospitalLeaderGIchange__c)  {
                    PUMap.put(nObj.Id, nObj);
                    if(String.isNotBlank(nobj.Strategic_userFSEGI__c) && !String.valueOf(nObj.OwnerId).substring(0,15).equals(String.valueOf(nObj.Strategic_userFSEGI__c).substring(0,15))){
                        Rental_Apply__Share ras = makeData(nObj.Id, nObj.Strategic_userFSEGI__c);
                        ParentIdSet.add(nObj.Id);
                        UserOrGroupIdSet.add(nObj.Strategic_userFSEGI__c);
                        UserOrGroupIdOldSet.add(nObj.hospitalLeaderGI__c);
                        addStrategListL.add(ras);
                    }
                    
                }
                if (nObj.hospitalLeaderSPchange__c) {
                    PUMap.put(nObj.Id, nObj);
                    if (String.isNotBlank(nobj.Strategic_userFSESP__c) && !String.valueOf(nObj.OwnerId).substring(0,15).equals(String.valueOf(nObj.Strategic_userFSESP__c).substring(0,15))) {
                        Rental_Apply__Share ras = makeData(nObj.Id, nObj.Strategic_userFSESP__c);
                        ParentIdSet.add(nObj.Id);
                        UserOrGroupIdSet.add(nObj.Strategic_userFSESP__c);
                        UserOrGroupIdOldSet.add(nObj.hospitalLeaderSP__c);
                        addStrategListL.add(ras);
                    }
                }
            }
            //20210728 ljh SFDC-C5645S 加入共享前判断用户是否可用 end
        }
        // 20210924 ljh SFDC-C758NB update substring(0,15) end
        if(UserOrGroupIdSet.size() > 0){
            for (User user : [Select Id, Name, IsActive From User WHERE Id in:UserOrGroupIdSet]) {
                //未启用
                if (!user.IsActive) {
                    String  userId = (String)user.Id;
                    userId = userId.substring(0, 15);
                    IsActiveNoList.add(userId);
                }
            }
        }
            //add by rentx 2020-11-26 SFDC-BVA5VJ end
        // System.debug('zheli22:'+UserOrGroupIdOldSet.size()+'~'+ParentIdSet.size());
        if(UserOrGroupIdOldSet.size() > 0 && ParentIdSet.size() > 0 ){
            //删除原来的共享
            delStrategList  = [SELECT Id, ParentId, UserOrGroupId FROM Rental_Apply__Share WHERE  RowCause = 'Manual' AND ParentId in :ParentIdSet AND UserOrGroupId in :UserOrGroupIdOldSet];
            for (Integer m = 0; m < delStrategList.size(); m++) {
                if (PUMap.get(delStrategList[m].ParentId) == null) {
                    delStrategList.remove(m);
                }
            }
            if (delStrategList.size() > 0) {
                // System.debug('zheli11:'+delStrategList);
                delete delStrategList;
            }
        }   
        //增加
        // if (addStrategListL.size() > 0) {
        if (PUMap.size() > 0) {
            //20210728 ljh SFDC-C5645S
            for (Rental_Apply__Share ras : addStrategListL) {
                String temp = (String)ras.UserOrGroupId;
                if ( IsActiveNoList.size() == 0 ||
                        (IsActiveNoList.size() > 0 && !IsActiveNoList.contains(temp.substring(0, 15)))
                   ) {
                    addStrategList.add(ras);
                }
            }
            Set<String>  keySet = PUMap.keySet();
            for(Id key:keySet){
                Rental_Apply__c Ra = PUMap.get(key);
                Rental_Apply__c raU = new Rental_Apply__c();
                if (PUMap.get(key) != null ) {
                    // System.debug('zheli00:'+Ra.hospitalLeaderGIchange__c+'~'+Ra.hospitalLeaderSPchange__c);
                    raU.Id = Ra.Id;
                    // String tempGI = Ra.Strategic_userFSEGI__c;
                    // String tempSP = Ra.Strategic_userFSESP__c;
                    // String tempSU = Ra.ShareStrategicUser__c;
                    if (Ra.hospitalLeaderGIchange__c) {
                        raU.hospitalLeaderGI__c = Ra.Strategic_userFSEGI__c;
                    } 
                    if (Ra.hospitalLeaderSPchange__c) {
                        raU.hospitalLeaderSP__c = Ra.Strategic_userFSESP__c;
                    }
                    if (Ra.ShareFlag__c) {
                        raU.ShareStrategicUser__c = Ra.Strategic_user__c;
                    } 
                    RAUMap.put(raU.Id, raU);
                }
            }
            //20210728 ljh SFDC-C5645S end
        }
        // System.debug('zheli00:'+addStrategList);
        // 共享表
        if (addStrategList.size() > 0) {
            insert addStrategList;
        }
        // 更新
        // 20210924 ljh SFDC-C758NB update 优化 start
        // if (raList.size() > 0) {
        //     // update raList;
        //     for(Rental_Apply__c ra:raList){
        //         if(RAUMap.containsKey(ra.Id)){
        //             RAUMap.get(ra.Id).ShareStrategicUser__c = ra.ShareStrategicUser__c;
        //         }else{
        //             RAUMap.put(ra.Id, ra);
        //         }
        //     }
        // }
        // 20210924 ljh SFDC-C758NB update 优化 end
        
        //更新
        if (RAUMap.size() > 0) {
            System.debug('AAA:'+RAUMap.values());
            update RAUMap.values();
        }
    }
 
    private void dataCheck() {
        System.debug('进入 dataCheck');
        Map<Id, Rental_Apply__c> dataCheckMap = new Map<Id, Rental_Apply__c>();
        List<OPDPlan__c> oPDPlanList = new List<OPDPlan__c>();
        Map<Id, OPDPlan__c> dataOPDMap = new Map<Id, OPDPlan__c>();
        for (Rental_Apply__c newObj : newList) {
 
            Rental_Apply__c oldObj = oldMap == null ? null : oldMap.get(newObj.Id);
            Boolean changeFlag = false;
            if (oldObj == null) {
 
                //新增
                //1.获取 opd计划上记录的 原备品借出申请Id 获取31个相关字段的值 与当前值作比较
                dataCheckMap.put(newObj.OPDPlan__c, newObj);
            } else {
                //应该有一个 补充申请创建 判断
                //变更
                //有31个字段的值不可修改
                if (newObj.SupplementCreated__c) {
                    changeFlag = RentalApplydataCheck(null, newObj, oldObj);
                    if (System.Test.isRunningTest() == false && changeFlag && UserInfo.getUserId()!=System.Label.ByPassTrigger) {
                        newObj.addError('关联的OPD计划为补充OPD计划 不能编辑备品借用信息');
                    }
                    //system.debug('changeFlag---->'+changeFlag);
                }
            }
        }
 
        if (dataCheckMap.size() > 0) {
            //查询 OPD计划
            //zhj 2022-04-19 修改联系电话与直送收货地址的比较改为Encrypt的比较 start
            oPDPlanList = [SELECT Id, Name, supplementaryApplication__c, originalOpdRentalApply__c,
                           OriginalOpdPlanApplication__c,
                           OriginalOpdPlanApplication__r.Name, // 20240104 ljh add
                           OriginalOpdPlanApplication__r.Rental_Apply2__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Person_In_Charge__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.applyUser__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.ApplyPerson_Phone__c ,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Hospital__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Strategic_dept__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Account__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_medical_Staff__c,
                           //OriginalOpdPlanApplication__r.Rental_Apply2__r.Phone_Number_Encrypt__c,
OriginalOpdPlanApplication__r.Rental_Apply2__r.Phone_Number__c,   //deloitte-zhj 20231116 PIPL还原 
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Demo_purpose1__c ,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.demo_purpose2__c ,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Product_category__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.AnimalExerimentFlag__c ,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Campaign__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Demo_purpose_text__c ,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Repair__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Follow_UP_Opp__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.CrinicalTrialName__c ,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.DB_loaner_request__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_demo_detail__c ,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_shipping_day__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_return_day__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Shipment_address__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Dealer__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_received_staff__c ,
                           //OriginalOpdPlanApplication__r.Rental_Apply2__r.Direct_Shippment_Address_Encrypt__c,
OriginalOpdPlanApplication__r.Rental_Apply2__r.Direct_Shippment_Address__c,  //deloitte-zhj 20231116 PIPL还原
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.direct_send__c ,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.pickup_time__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_received_staff_phone__c ,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Post_Code__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.GI_Diff__c ,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Hope_Lonaer_date_Num__c,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Name,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Id,
                           OriginalOpdPlanApplication__r.Rental_Apply2__r.Rental_Apply_Equipment_Set_Cnt__c
                           FROM OPDPlan__c
                           WHERE Id In:dataCheckMap.keySet()
                          ];
            String sqlName = '';
            String newName = '';
            for (OPDPlan__c opd : oPDPlanList) {
                //OPD计划 通过 补充申请创建
                if (opd.supplementaryApplication__c) {
                    dataOPDMap.put(opd.Id, opd);
                    String oldRaName = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Name;
                    sqlName = oldRaName.indexOf('_') >= 0 ? oldRaName.split('_')[0] : oldRaName;
                    sqlName = sqlName + '%';
                }
            }
            if (dataOPDMap.size() > 0) {
                String rootRentalApplyId = null;
                if (String.isNotBlank(sqlName)) {
                    List<Rental_Apply__c> oldRaList = new List<Rental_Apply__c>();
                    oldRaList = [select Id, Name from Rental_Apply__c where Name  like :sqlName order by Name];
                    if (oldRaList.size() > 0) {
                        rootRentalApplyId = oldRaList[0].Id;
                        Integer num = oldRaList.size();
                        newName = sqlName.split('%')[0] + '_' + num;
                    } else {
                        newName = sqlName.split('%')[0] + '_' + 1;
                    }
 
                }
 
                for (Rental_Apply__c newObj : newList) {
 
                    Rental_Apply__c oldObj = oldMap == null ? null : oldMap.get(newObj.Id);
                    Boolean changeFlag = false;
                    if (oldObj == null) {
                        //通过补充申请创建 备品借出申请
                        if (dataOPDMap.containskey(newObj.OPDPlan__c)) {
                            OPDPlan__c opd = dataOPDMap.get(newObj.OPDPlan__c);
                            newObj.Request_return_day__c = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_return_day__c;
                            changeFlag = RentalApplydataCheck(opd, newObj, null);
 
                            if (System.Test.isRunningTest() == false && changeFlag && UserInfo.getUserId()!=System.Label.ByPassTrigger) {
                                newObj.addError('关联的OPD计划为补充OPD计划 不能编辑备品借用信息');
                            }
                            newObj.Old_Rental_Apply__c = opd.OriginalOpdPlanApplication__r.Rental_Apply2__c;
                            // 20231221 ljh 备品智能化理由修改 start
                            // newObj.Split_Apply_Reason__c = '补充借用';
                            newObj.Split_Apply_Reason__c = '追加OPD计划';
                            // 20231221 ljh 备品智能化理由修改 end
                            newObj.SupplementCreated__c = true;
                            newObj.Name = newName;
                            newObj.Root_Rental_Apply__c = rootRentalApplyId;
                            newObj.OriginalOpdPlanApplication__c = opd.OriginalOpdPlanApplication__r.Name; // 20240104 ljh update
                        }
 
                    }
                }
            }
 
        }
    }
 
    private Boolean RentalApplydataCheck(OPDPlan__c opd, Rental_Apply__c newObj, Rental_Apply__c oldObj) {
        //新增
        Boolean changeFlag = false;
        if (opd != null ) {
            Boolean Person_In_Charge = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Person_In_Charge__c != newObj.Person_In_Charge__c;
            system.debug('Person_In_Charge__c--->' + Person_In_Charge);
            Boolean applyUser = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.applyUser__c != newObj.applyUser__c;
            system.debug('applyUser--->' + applyUser);
 
            Boolean ApplyPerson_Phone = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.ApplyPerson_Phone__c != newObj.ApplyPerson_Phone__c;
            system.debug('ApplyPerson_Phone--->' + ApplyPerson_Phone);
 
            boolean Hospital =  opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Hospital__c != newObj.Hospital__c;
            system.debug('Hospital__c--->' + Hospital);
 
            boolean Strategic_dept = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Strategic_dept__c != newObj.Strategic_dept__c;
            system.debug('Strategic_dept__c--->' + Strategic_dept);
 
            boolean Account = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Account__c != newObj.Account__c;
            system.debug('Account__c--->' + Account);
 
            boolean Loaner_medical_Staff = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_medical_Staff__c != newObj.Loaner_medical_Staff__c;
            system.debug('Loaner_medical_Staff__c--->' + Loaner_medical_Staff);
 
            // boolean Phone_number = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Phone_Number_Encrypt__c  != newObj.Phone_Number_Encrypt__c;
            // system.debug('Phone_Number_Encrypt__c--->' + Phone_number);
boolean Phone_number = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Phone_Number__c  != newObj.Phone_Number__c;   //deloitte-zhj 20231116 PIPL还原
            system.debug('Phone_Number__c--->' + Phone_number);
 
            boolean Demo_purpose1 = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Demo_purpose1__c  != newObj.Demo_purpose1__c;
            system.debug('Demo_purpose1__c--->' + Demo_purpose1);
 
            boolean demo_purpose2 = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.demo_purpose2__c  != newObj.demo_purpose2__c;
            system.debug('demo_purpose2__c--->' + demo_purpose2);
 
            boolean Product_category = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Product_category__c != newObj.Product_category__c;
            system.debug('Product_category__c--->' + Product_category);
 
            boolean AnimalExerimentFlag = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.AnimalExerimentFlag__c != newObj.AnimalExerimentFlag__c;
            system.debug('AnimalExerimentFlag__c--->' + AnimalExerimentFlag);
 
            boolean Campaign = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Campaign__c != newObj.Campaign__c;
            system.debug('Campaign__c--->' + Campaign);
 
            boolean Demo_purpose_text = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Demo_purpose_text__c != newObj.Demo_purpose_text__c;
            system.debug('Demo_purpose_text__c--->' + Demo_purpose_text);
 
            boolean Repair = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Repair__c != newObj.Repair__c;
            system.debug('Repair__c--->' + Repair);
 
            boolean Follow_UP_Opp = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Follow_UP_Opp__c != newObj.Follow_UP_Opp__c;
            system.debug('Follow_UP_Opp__c--->' + Follow_UP_Opp);
 
            boolean CrinicalTrialName = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.CrinicalTrialName__c  != newObj.CrinicalTrialName__c;
            system.debug('CrinicalTrialName__c--->' + CrinicalTrialName);
 
            boolean DB_loaner_request = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.DB_loaner_request__c != newObj.DB_loaner_request__c;
            system.debug('DB_loaner_request__c--->' + DB_loaner_request);
 
            boolean Request_demo_detail = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_demo_detail__c  != newObj.Request_demo_detail__c;
            system.debug('Request_demo_detail__c--->' + Request_demo_detail);
 
//boolean Request_shipping_day = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_shipping_day__c != newObj.Request_shipping_day__c;
//system.debug('Request_shipping_day__c--->'+Request_shipping_day);
 
            boolean Request_return_day = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_return_day__c != newObj.Request_return_day__c;
            system.debug('Request_return_day__c--->' + Request_return_day);
 
            boolean Shipment_address = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Shipment_address__c != newObj.Shipment_address__c;
            system.debug('Shipment_address__c--->' + Shipment_address);
 
            boolean Dealer = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Dealer__c != newObj.Dealer__c;
            system.debug('Dealer__c--->' + Dealer);
 
            boolean Loaner_received_staff = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_received_staff__c  != newObj.Loaner_received_staff__c;
            system.debug('Loaner_received_staff__c--->' + Loaner_received_staff);
 
            //deloitte-zhj 20231116 PIPL还原 start
            // String dsaecnew = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Direct_Shippment_Address_Encrypt__c;
            // dsaecnew = String.isBlank(dsaecnew)||String.isEmpty(dsaecnew)?'':dsaecnew.length()>200?dsaecnew.substring(0,200):dsaecnew;
            // String dsaecold = newObj.Direct_Shippment_Address_Encrypt__c;
            // dsaecold =String.isBlank(dsaecold)||String.isEmpty(dsaecold)?'': dsaecold.length()>200?dsaecold.substring(0,200):dsaecold;
// boolean direct_shippment_address = dsaecnew  != dsaecold;
            // system.debug('Direct_Shippment_Address_Encrypt__c--->' + direct_shippment_address);
            String dsaecnew = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Direct_Shippment_Address__c;
            String dsaecold = newObj.Direct_Shippment_Address__c;
            boolean direct_shippment_address = dsaecnew  != dsaecold;
            //deloitte-zhj 20231116 PIPL还原 end
 
            boolean direct_send = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.direct_send__c  != newObj.direct_send__c;
            system.debug('direct_send__c--->' + direct_send);
 
            boolean pickup_time = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.pickup_time__c != newObj.pickup_time__c;
            system.debug('pickup_time__c--->' + pickup_time);
 
            boolean Loaner_received_staff_phone = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_received_staff_phone__c  != newObj.Loaner_received_staff_phone__c;
            system.debug('Loaner_received_staff_phone__c--->' + Loaner_received_staff_phone);
 
            boolean Post_Code = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Post_Code__c  != newObj.Post_Code__c;
            system.debug('Post_Code__c--->' + Post_Code);
 
            boolean GI_Diff = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.GI_Diff__c  != newObj.GI_Diff__c;
            system.debug('GI_Diff__c--->' + GI_Diff);
 
            boolean Hope_Lonaer_date_Num = opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Hope_Lonaer_date_Num__c != newObj.Hope_Lonaer_date_Num__c ;
            system.debug('Hope_Lonaer_date_Num__c--->' + Hope_Lonaer_date_Num);
            changeFlag  =  opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Person_In_Charge__c != newObj.Person_In_Charge__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.applyUser__c != newObj.applyUser__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.ApplyPerson_Phone__c != newObj.ApplyPerson_Phone__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Hospital__c != newObj.Hospital__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Strategic_dept__c != newObj.Strategic_dept__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Account__c != newObj.Account__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_medical_Staff__c != newObj.Loaner_medical_Staff__c ||
                           //opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Phone_Number_Encrypt__c  != newObj.Phone_Number_Encrypt__c ||
opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Phone_Number__c  != newObj.Phone_Number__c ||    //deloitte-zhj 20231116 PIPL还原
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Demo_purpose1__c  != newObj.Demo_purpose1__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.demo_purpose2__c  != newObj.demo_purpose2__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Product_category__c != newObj.Product_category__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.AnimalExerimentFlag__c != newObj.AnimalExerimentFlag__c  ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Campaign__c != newObj.Campaign__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Demo_purpose_text__c != newObj.Demo_purpose_text__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Repair__c != newObj.Repair__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Follow_UP_Opp__c != newObj.Follow_UP_Opp__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.CrinicalTrialName__c  != newObj.CrinicalTrialName__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.DB_loaner_request__c != newObj.DB_loaner_request__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_demo_detail__c  != newObj.Request_demo_detail__c ||
                           //opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_shipping_day__c != newObj.Request_shipping_day__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Request_return_day__c != newObj.Request_return_day__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Shipment_address__c != newObj.Shipment_address__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Dealer__c != newObj.Dealer__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_received_staff__c  != newObj.Loaner_received_staff__c ||
                           dsaecnew  != dsaecold ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.direct_send__c  != newObj.direct_send__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.pickup_time__c != newObj.pickup_time__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Loaner_received_staff_phone__c  != newObj.Loaner_received_staff_phone__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Post_Code__c  != newObj.Post_Code__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.GI_Diff__c  != newObj.GI_Diff__c ||
                           opd.OriginalOpdPlanApplication__r.Rental_Apply2__r.Hope_Lonaer_date_Num__c != newObj.Hope_Lonaer_date_Num__c ;
        } else {
            //deloitte-zhj 20231116 PIPL还原 start
            // String dsaecnew = newObj.Direct_Shippment_Address_Encrypt__c;
            // dsaecnew = String.isBlank(dsaecnew)||String.isEmpty(dsaecnew)?'':  dsaecnew.length()>200?dsaecnew.substring(0,200):dsaecnew;
            // String dsaecold = oldObj.Direct_Shippment_Address_Encrypt__c;
            // dsaecold =  String.isBlank(dsaecold)||String.isEmpty(dsaecold)?'': dsaecold.length()>200?dsaecold.substring(0,200):dsaecold;
String dsaecnew = newObj.Direct_Shippment_Address__c;
            String dsaecold = oldObj.Direct_Shippment_Address__c;
            //deloitte-zhj 20231116 PIPL还原 end
            changeFlag  =  newObj.Person_In_Charge__c != oldObj.Person_In_Charge__c ||
                           newObj.applyUser__c != oldObj.applyUser__c ||
                           newObj.ApplyPerson_Phone__c != oldObj.ApplyPerson_Phone__c ||
                           newObj.Hospital__c != oldObj.Hospital__c ||
                           newObj.Strategic_dept__c != oldObj.Strategic_dept__c ||
                           newObj.Account__c != oldObj.Account__c ||
                           newObj.Loaner_medical_Staff__c != oldObj.Loaner_medical_Staff__c ||
                           //newObj.Phone_Number_Encrypt__c != oldObj.Phone_Number_Encrypt__c ||
newObj.Phone_Number__c != oldObj.Phone_Number__c ||  //deloitte-zhj 20231116 PIPL还原
                           newObj.Demo_purpose1__c  != oldObj.Demo_purpose1__c ||
                           newObj.demo_purpose2__c != oldObj.demo_purpose2__c ||
                           newObj.Product_category__c != oldObj.Product_category__c ||
                           newObj.AnimalExerimentFlag__c != oldObj.AnimalExerimentFlag__c ||
                           newObj.Campaign__c != oldObj.Campaign__c ||
                           newObj.Demo_purpose_text__c != oldObj.Demo_purpose_text__c ||
                           newObj.Repair__c != oldObj.Repair__c ||
                           newObj.Follow_UP_Opp__c != oldObj.Follow_UP_Opp__c ||
                           newObj.CrinicalTrialName__c != oldObj.CrinicalTrialName__c ||
                           newObj.DB_loaner_request__c != oldObj.DB_loaner_request__c ||
                           newObj.Request_demo_detail__c != oldObj.Request_demo_detail__c ||
                           //newObj.Request_shipping_day__c != oldObj.Request_shipping_day__c ||
                           newObj.Request_return_day__c != oldObj.Request_return_day__c ||
                           newObj.Shipment_address__c != oldObj.Shipment_address__c ||
                           newObj.Dealer__c != oldObj.Dealer__c ||
                           newObj.Loaner_received_staff__c != oldObj.Loaner_received_staff__c ||
                           dsaecnew  != dsaecold ||
                           newObj.direct_send__c != oldObj.direct_send__c ||
                           newObj.pickup_time__c != oldObj.pickup_time__c ||
                           newObj.Loaner_received_staff_phone__c != oldObj.Loaner_received_staff_phone__c ||
                           newObj.Post_Code__c != oldObj.Post_Code__c ||
                           newObj.GI_Diff__c !=  oldObj.GI_Diff__c ||
                           newObj.Hope_Lonaer_date_Num__c !=  oldObj.Hope_Lonaer_date_Num__c;
        }
        return changeFlag;
        //zhj 2022-04-19 修改联系电话与直送收货地址的比较改为Encrypt的比较 end
    }
 
            
}