高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
global class UpdateRentalApplyEquipmentSetBatch implements Database.Batchable<sObject>, Database.Stateful {
 
    private static final Integer MAXERRORCNT = 20; // 邮件表单位最大错误信息显示数量
    private Date tdy = Date.today();
    private Date timeLine = Date.newInstance(2019, 7, 1);
 
    private ErrorBean eb = new ErrorBean(); // 邮件发送ERRORBEAN
    private UpdateRentalApplyBatch.ScBean scB;
    private String scErrorMessage = ''; // 添加计划错误信息
 
    /**
     * コンスタント
     */
    global UpdateRentalApplyEquipmentSetBatch() {
        Integer i = 0;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
        i ++;
    }
 
    /**
     * startには、queryを実行、备品申请借出历史を検索
     */
    global Database.QueryLocator start(Database.BatchableContext BC) {
        scB = UpdateRentalApplyBatch.setSc('UpdateRentalApplyEquipmentSetSchedule', 9, 23, 0, '0 30 2', null);
        if (System.Test.isRunningTest() == false) {
            Boolean haveError = false;
            try {
                system.schedule(scB.scName, scB.scTime, new UpdateRentalApplyEquipmentSetSchedule());
            }
            catch(Exception e) {
                haveError = true;
            }
            // 如果哟同名的Batch计划删除已存在的计划重新设置
            if (haveError) {
                haveError = false;
                for(CronTrigger ct : [SELECT Id,CronJobDetailId,CronExpression,CronJobDetail.Name
                                        FROM CronTrigger
                                       WHERE CronJobDetail.Name = :scB.scName]){
                    System.abortJob(ct.Id);
                }
                try {
                    system.schedule(scB.scName, scB.scTime, new UpdateRentalApplyEquipmentSetSchedule());
                }
                catch(Exception e) {
                    scErrorMessage = e.getMessage() + e.getStackTraceString() + '<br/>';
                }
            }
        }
        return Database.getQueryLocator(
            [select Id from User where Id = :UserInfo.getUserId()]
        );
    }
 
    global void execute(Database.BatchableContext BC, List<SObject> userList) {
        Map<Id, Rental_Apply_Equipment_Set__c> needUpdateMap = new Map<Id, Rental_Apply_Equipment_Set__c>();
        // 获取需要更新Text字段的备品借出一览
        List<Rental_Apply_Equipment_Set__c> raesList = getRaes(null);
        Set<Id> raesIdSet = new Set<Id>();
        for (Rental_Apply_Equipment_Set__c raes: raesList) {
            Rental_Apply_Equipment_Set__c raes1 = raes;
            if (needUpdateMap.containsKey(raes1.Id)) {
                raes1 = needUpdateMap.get(raes1.Id);
            }
            Rental_Apply_Equipment_Set__c upd = UpdateRentalApplyEquipmentSetBatch.setRAES(raes1, raesIdSet);
            if (upd != null) {
                needUpdateMap.put(upd.Id, upd);
            }
        }
 
        // 上面的逻辑是对应备品借出一览公式字段和Text的更新(既存逻辑)
 
 
        // 以下逻辑是更新备品借出申请一览的工作日的逻辑
        // 获取需要更新工作日的备品借出一览
        raesList = [SELECT Id
                      , Bollow_Date__c
                   FROM Rental_Apply_Equipment_Set__c
                  WHERE Rental_Apply__r.Request_demo_day__c >= :timeLine
                    AND Bollow_Date__c != null
                    AND (Bollow_Date_Add_7_WD__c = null OR Bollow_Date_Add_10_WD__c = null)
                  order by Id Limit :Integer.valueOf(System.Label.UpdateRentalApplyEquipmentSetBatchLimit)];
        System.debug('raesList.size()' + raesList.size());
        if (raesList.size() > 0) {
            Date minDate = Date.newInstance(4000, 12, 31);
            Date maxDate = Date.newInstance(1700, 1, 1);
            for (Rental_Apply_Equipment_Set__c raesd : raesList) {
                if (minDate > raesd.Bollow_Date__c) {
                    minDate = raesd.Bollow_Date__c;
                }
                if (maxDate < raesd.Bollow_Date__c) {
                    maxDate = raesd.Bollow_Date__c;
                }
            }
            List<OlympusCalendar__c> ocList = [SELECT Id
                        , Date__c
                     FROM OlympusCalendar__c
                    WHERE Date__c >= :minDate
                      AND Date__c <= :maxDate.addDays(30)
                      AND IsWorkDay__c = 1
                    ORDER BY Date__c ASC];
            Map<Date, Date> dateadd7Map = new Map<Date, Date>();
            Map<Date, Date> dateadd10Map = new Map<Date, Date>();
            Integer ocListSize = ocList.size();
            if (ocListSize > 7) {
                for (Integer i = 0; i < ocListSize - 7; i ++) {
                    dateadd7Map.put(ocList[i].Date__c, ocList[i + 7].Date__c);
                    if(i + 10 < ocListSize) {
                        dateadd10Map.put(ocList[i].Date__c, ocList[i + 10].Date__c);
                    }
                }
                List<Rental_Apply_Equipment_Set__c> hDayRaesList = new List<Rental_Apply_Equipment_Set__c>();
                for (Rental_Apply_Equipment_Set__c raesd : raesList) {
                    if (dateadd7Map.containsKey(raesd.Bollow_Date__c)) {
                        Rental_Apply_Equipment_Set__c raes1 = raesd;
                        // 如果工作日和Text字段都需要更新。需要更新在一个实例里面,不然会覆盖
                        if (needUpdateMap.containsKey(raes1.Id)) {
                            raes1 = needUpdateMap.get(raes1.Id);
                        }
                        else {
                            needUpdateMap.put(raes1.Id, raes1);
                        }
                        raes1.Bollow_Date_Add_7_WD__c = dateadd7Map.get(raesd.Bollow_Date__c);
                        if(dateadd10Map.containsKey(raes1.Bollow_Date__c)) {
                            raes1.Bollow_Date_Add_10_WD__c = dateadd10Map.get(raes1.Bollow_Date__c);
                        }
                    }
                    else {
                        hDayRaesList.add(raesd);
                    }
                }
                if (hDayRaesList.size() > 0) {
                    for (Integer i = 0; i < hDayRaesList.size(); i ++) {
                        for (Integer j = 0; j < ocListSize; j ++) {
                            if (j != ocListSize - 1
                                    && (ocList[j].Date__c <  hDayRaesList[i].Bollow_Date__c
                                          || (j == 0 && ocList[j].Date__c >  hDayRaesList[i].Bollow_Date__c)
                                      )
                                    && ocList[j + 1].Date__c > hDayRaesList[i].Bollow_Date__c) {
                                Rental_Apply_Equipment_Set__c raes1 = hDayRaesList[i];
                                if (needUpdateMap.containsKey(raes1.Id)) {
                                    raes1 = needUpdateMap.get(raes1.Id);
                                }
                                else {
                                    needUpdateMap.put(raes1.Id, raes1);
                                }
                                raes1.Bollow_Date_Add_7_WD__c = dateadd7Map.get(ocList[j].Date__c);
                                if(dateadd10Map.containsKey(ocList[j].Date__c)) {
                                    raes1.Bollow_Date_Add_10_WD__c = dateadd10Map.get(ocList[j].Date__c);
                                }
                                break;
                            }
                        }
                    }
                }
                System.debug('raesList.size()' + raesList);
            }
        }
 
        if (!needUpdateMap.isEmpty()) {
            Database.SaveResult[] saveRes = Database.update(needUpdateMap.values(), false);
            // 备品借出一览更新保存Error
            eb.setError(saveRes, MAXERRORCNT, Rental_Apply_Equipment_Set__c.sObjectType);
        }
 
        if (raesIdSet.size() > 0) {
            raesList = getRaes(raesIdSet);
            needUpdateMap = new Map<Id, Rental_Apply_Equipment_Set__c>();
            for (Rental_Apply_Equipment_Set__c raes : raesList) {
                Rental_Apply_Equipment_Set__c raes1 = raes;
                Rental_Apply_Equipment_Set__c upd = UpdateRentalApplyEquipmentSetBatch.setRAES(raes1, raesIdSet);
                if (upd != null) {
                    needUpdateMap.put(upd.Id, upd);
                }
            }
            if (!needUpdateMap.isEmpty()) {
                Database.SaveResult[] saveRes = Database.update(needUpdateMap.values(), false);
                // 备品借出一览更新保存Error
                eb.setError(saveRes, MAXERRORCNT, Rental_Apply_Equipment_Set__c.sObjectType);
            }
        }
 
        // xiongyl--start
        // 因为犯规点数有集计SetOrderPoint_sum_Text__c字段。所以需要再SetOrderPoint_sum_Text__c更新后再计算犯规点数
        List<AggregateResult> points = [select SUM(RequestOrderPoint_sum__c) fp, OwnerId userId
                from Rental_Apply__c where RequestOrderPoint_sum__c > 0 group by OwnerId];
        Map<String, Integer> pointMap = new Map<String,integer>();
        for(AggregateResult point : points){
            pointMap.put(String.valueOf(point.get('userId')), Integer.valueOf(point.get('fp')));
        }
 
        List<User> users = [select Id, Foul_Points__c from User where Id != '005100000016ykkAAA' AND Id != '00510000007iWvrAAE' AND Id != '0051000000D9fP3AAJ'];
        List<User> updList = new List<User>();
        for (User usr : users) {
            if (usr.Foul_Points__c <> 0 || pointMap.containsKey(usr.id) == true) {
                usr.Foul_Points__c = pointMap.get(usr.id) == null ? 0 : pointMap.get(usr.id);
                updList.add(usr);
            }
        }
        if (updList.size() > 0) {
            Database.SaveResult[] saveRes = Database.update(updList, false);
            // USER更新Error
            eb.setError(saveRes, MAXERRORCNT, User.sObjectType);
        }
        // xiongyl--end
//bp2
//        List<Equipment_Set_Detail__c> esdList =
//            [select Id,Asset_condition__c,Asset_condition_Text__c,
//                    Serial_Lot__c,Serial_Lot_text__c,
//                    Asset__r.Loaner_accsessary__c, Loaner_accsessary_text__c,
//                    Active_judgement_select__c,Active_judgement_text__c,
//                    Last_Reserve_RAES_Detail_RAES_F__c, Last_Reserve_RAES_Detail_RAES_Id__c,
//                    Equipment_Set_Last_Reserve_RAES_F__c, Equipment_Set_Last_Reserve_RAES_Id__c
//               from Equipment_Set_Detail__c
//              where Asset_condition_Changed__c = true
//              order by Id limit 4000];
 
//        List<Equipment_Set_Detail__c> updateList2 = UpdateRentalApplyEquipmentSetBatch.setESD(esdList);
//        if (!updateList2.isEmpty()) update updateList2;
    }
 
    public static List<Rental_Apply_Equipment_Set__c> getRaes(Set<Id> idSet) {
        String soql = 'SELECT Id'
                         + ', Repair_Status1__c'
                         + ', Repair_Status2__c'
                         + ', Repair_Status_Text__c'
                         + ', Final_reply_day__c'
                         + ', Final_reply_day_text__c'
                         + ', Received_Confirm_NG_Not_Return__c'
                         + ', Received_Confirm_NG_Not_Return_Text__c'
                         + ', Received_Confirm_Status_F__c'
                         + ', Received_Confirm_Status_Text__c'
                         + ', NG_Final_reply_day_Text__c'
                         + ', NG_Final_reply_day_F__c'
                         + ', Yizhouweixiu_Final_reply_day_Text__c'
                         + ', Yizhouweixiu_Final_reply_day_F__c'
                         + ', Extend_Final_reply_day_Text__c'
                         + ', Extend_Final_reply_day_F__c'
                         + ', QIS_Final_reply_day_Text__c'
                         + ', QIS_Final_reply_day_F__c'
                         + ', Repair_cancel_Final_reply_day_Text__c'
                         + ', Repair_cancel_Final_reply_day_F__c'
                         + ', Return_to_office_Final_reply_day_Text__c'
                         + ', Return_to_office_Final_reply_day_F__c'
                         + ', Repair_delete_Final_reply_day_Text__c'
                         + ', Repair_delete_Final_reply_day_F__c'
                         + ', Yigoudaihuo_Final_reply_day_Text__c'
                         + ', Yigoudaihuo_Final_reply_day_F__c'
                         + ', Guzhangpaicha_Final_reply_day_Text__c'
                         + ', Guzhangpaicha_Final_reply_day_F__c'
                         + ', Repair_Agreed_Quotation_F__c'
                         + ', Repair_Agreed_Quotation_Text__c'
                         + ', Return_to_office_Final_reply_day_U_RC__c'
                         + ', Return_to_office_Final_reply_day_U_RC_F__c'
                         + ', Extend_Date__c'
                         + ', Extend_Date_F__c'
                         + ', Received_NG_ReAssign_Text__c'
                         + ', Received_NG_ReAssign__c'
                +' FROM Rental_Apply_Equipment_Set__c'
                +' WHERE ' + (idSet == null ? '' : 'Id = :idSet AND (')
                        + '('
                        +'  ('
                            +    '(Rental_Apply__r.Repair__c = null and Repair_Status_Text__c <> \'\')'
                            +' OR (Rental_Apply__r.Repair__c <> null and Repair_Status_Text__c = \'\')'
                            +' OR (Rental_Apply__r.Repair__c <> null and Repair_Status_Changed__c = \'1\')' // 用来判断Repair_Status_Text__c 字段有变更的变更字段
                            +' OR Final_reply_day_Changed__c = \'1\'' // 用来判断Final_reply_day_text__c 字段有变更的变更字段
                        +' )'
                        +' AND Cancel_Select__c = False'
                        +' )'
                        +' OR ForBatch_Changed_F__c = true' // 用来判断Received_Confirm_NG_Not_Return_Text__c
                                                         //        Received_Confirm_Status_Text__c
                                                         //        SetOrderPoint_sum_Text__c有变更的字段
                        +' OR ForBatch_Changed1_F__c = true' // Text(NG_Final_reply_day_Text__c) != Text(NG_Final_reply_day_F__c)
                                                          // || Text(Yizhouweixiu_Final_reply_day_Text__c) != Text(Yizhouweixiu_Final_reply_day_F__c)
                        +' OR ForBatch_Changed2_F__c = true '// Text(Repair_cancel_Final_reply_day_Text__c) != Text(Repair_cancel_Final_reply_day_F__c)
                                                          // || Text(Return_to_office_Final_reply_day_Text__c) != Text(Return_to_office_Final_reply_day_F__c)
                        +' OR ForBatch_Changed3_F__c = true '// Text(QIS_Final_reply_day_Text__c) != Text(QIS_Final_reply_day_F__c)
                        +' OR ForBatch_Changed4_F__c = true '// Text(Repair_delete_Final_reply_day_Text__c) != Text(Repair_delete_Final_reply_day_F__c)
                                                          // || Text(Yigoudaihuo_Final_reply_day_Text__c) != Text(Yigoudaihuo_Final_reply_day_F__c)
                        +' OR ForBatch_Changed5_F__c = true '//  Text(Extend_Final_reply_day_Text__c) != Text(Extend_Final_reply_day_F__c)
                        + (idSet == null ? '' : ')')
                +' order by Id Limit ' + System.Label.UpdateRentalApplyEquipmentSetBatchLimit;
        System.debug(soql);
        return Database.query(soql);
    }
 
    global void finish(Database.BatchableContext BC) {
        Boolean haveError = false;
        String body = scErrorMessage;
        UpdateRentalApplyBatch.removeOtherSc('UpdateRentalApplyEquipmentSetSchedule', scB.scName);
        for (Id objId : eb.messageMap.keySet()) {
            haveError = true;
            body += eb.messageMap.get(objId) + '<br/>';
        }
        if (eb.overMax) {
            body += ':Over ' + MAXERRORCNT + 'Record<br/>';
        }
        if (haveError == true || String.isNotBlank(scErrorMessage)) {
            // BatchユーザId
            String batchUserId = System.Label.Batch_User_Id;
            List<User> us = [Select Id,NAme,Email From User Where Id =: batchUserId];
            if (!us.isEmpty()) {
                User use = us[0];
                if (String.isNotBlank(use.Email)) {
                    List<String> MailCc;
                    if (System.Label.Batch_Error_Send_To_CC != 'null') {
                        MailCc = System.Label.Batch_Error_Send_To_CC.split(',');
                    }
                    if (System.Test.isRunningTest() == false) {
                        FixtureUtil.sendMessage(batchUserId,
                                                MailCc,
                                                'UpdateRentalApplyEquipmentSetBatch Error',
                                                 body
                                                );
                    }
                }
            }
        }
    }
 
    // RentalApplyWebService 里有在使用setRAES方法
    public static Rental_Apply_Equipment_Set__c setRAES(Rental_Apply_Equipment_Set__c obj) {
        return setRAES(obj, null);
    }
 
    public static Rental_Apply_Equipment_Set__c setRAES(Rental_Apply_Equipment_Set__c obj, Set<Id> raesIdSet) {
        Rental_Apply_Equipment_Set__c raes = new Rental_Apply_Equipment_Set__c(id = obj.Id);
        Boolean hasChange = false;
 
        /************************************ 第一次更新字段(需要第二次更新的字段) Start ******************************************/
        // Return_to_office_Final_reply_day_F__c有使用Repair_Agreed_Quotation_Text__c字段
        if (equalNullCheck(obj.Repair_Agreed_Quotation_Text__c, obj.Repair_Agreed_Quotation_F__c) || obj.Repair_Agreed_Quotation_Text__c != obj.Repair_Agreed_Quotation_F__c) {
            raes.Repair_Agreed_Quotation_Text__c = obj.Repair_Agreed_Quotation_F__c;
            hasChange = true;
            if (raesIdSet != null) {
                raesIdSet.add(raes.Id);
            }
        }
        // 字段Return_to_office_Final_reply_day_F__c有使用Return_to_office_Final_reply_day_U_RC__c字段
        if (equalNullCheck(obj.Return_to_office_Final_reply_day_U_RC__c, obj.Return_to_office_Final_reply_day_U_RC_F__c) || obj.Return_to_office_Final_reply_day_U_RC__c != obj.Return_to_office_Final_reply_day_U_RC_F__c) {
            raes.Return_to_office_Final_reply_day_U_RC__c = obj.Return_to_office_Final_reply_day_U_RC_F__c;
            hasChange = true;
            if (raesIdSet != null) {
                raesIdSet.add(raes.Id);
            }
        }
        /************************************ 第一次更新字段(需要第二次更新的字段) End ******************************************/
 
        /************************************ 第二次更新字段 OR 只更新一次就可以的字段 Start ******************************************/
 
        if (equalNullCheck(obj.Repair_Status_Text__c, obj.Repair_Status1__c) || obj.Repair_Status_Text__c != obj.Repair_Status1__c) {
            raes.Repair_Status_Text__c = obj.Repair_Status1__c;
            hasChange = true;
        }
        if (equalNullCheck(obj.Final_reply_day_text__c, obj.Final_reply_day__c) || obj.Final_reply_day_text__c != obj.Final_reply_day__c) {
            raes.Final_reply_day_text__c = obj.Final_reply_day__c;
            hasChange = true;
        }
        if (equalNullCheck(obj.Received_Confirm_NG_Not_Return_Text__c, obj.Received_Confirm_NG_Not_Return__c) || obj.Received_Confirm_NG_Not_Return_Text__c != obj.Received_Confirm_NG_Not_Return__c) {
            raes.Received_Confirm_NG_Not_Return_Text__c = obj.Received_Confirm_NG_Not_Return__c;
            hasChange = true;
        }
        if (equalNullCheck(obj.Received_Confirm_Status_Text__c, obj.Received_Confirm_Status_F__c) || obj.Received_Confirm_Status_Text__c != obj.Received_Confirm_Status_F__c) {
            raes.Received_Confirm_Status_Text__c = obj.Received_Confirm_Status_F__c;
            hasChange = true;
        }
        if (equalNullCheck(obj.QIS_Final_reply_day_Text__c, obj.QIS_Final_reply_day_F__c) || obj.QIS_Final_reply_day_Text__c != obj.QIS_Final_reply_day_F__c) {
            raes.QIS_Final_reply_day_Text__c = obj.QIS_Final_reply_day_F__c;
            hasChange = true;
        }
        /******************************* Min_Final_reply_day_F__c使用字段 Start Min_Final_reply_day_Text__c 的更新在Handler里 **************************************/
        // Min_Final_reply_day_F__c有使用Yizhouweixiu_Final_reply_day_Text__c字段
        if (equalNullCheck(obj.Yizhouweixiu_Final_reply_day_Text__c, obj.Yizhouweixiu_Final_reply_day_F__c) || obj.Yizhouweixiu_Final_reply_day_Text__c != obj.Yizhouweixiu_Final_reply_day_F__c) {
            raes.Yizhouweixiu_Final_reply_day_Text__c = obj.Yizhouweixiu_Final_reply_day_F__c;
            hasChange = true;
        }
        // Min_Final_reply_day_F__c有使用Extend_Final_reply_day_Text__c字段
        if (equalNullCheck(obj.Extend_Final_reply_day_Text__c, obj.Extend_Final_reply_day_F__c) || obj.Extend_Final_reply_day_Text__c != obj.Extend_Final_reply_day_F__c) {
            raes.Extend_Final_reply_day_Text__c = obj.Extend_Final_reply_day_F__c;
            hasChange = true;
        }
        // Min_Final_reply_day_F__c有使用NG_Final_reply_day_F__c字段
        if (equalNullCheck(obj.NG_Final_reply_day_Text__c, obj.NG_Final_reply_day_F__c) || obj.NG_Final_reply_day_Text__c != obj.NG_Final_reply_day_F__c) {
            raes.NG_Final_reply_day_Text__c = obj.NG_Final_reply_day_F__c;
            hasChange = true;
        }
        // Min_Final_reply_day_F__c有使用Repair_cancel_Final_reply_day_Text__c字段
        if (equalNullCheck(obj.Repair_cancel_Final_reply_day_Text__c, obj.Repair_cancel_Final_reply_day_F__c) || obj.Repair_cancel_Final_reply_day_Text__c != obj.Repair_cancel_Final_reply_day_F__c) {
            raes.Repair_cancel_Final_reply_day_Text__c = obj.Repair_cancel_Final_reply_day_F__c;
            hasChange = true;
        }
        // Min_Final_reply_day_F__c有使用Return_to_office_Final_reply_day_Text__c字段
        if (equalNullCheck(obj.Return_to_office_Final_reply_day_Text__c, obj.Return_to_office_Final_reply_day_F__c) || obj.Return_to_office_Final_reply_day_Text__c != obj.Return_to_office_Final_reply_day_F__c) {
            raes.Return_to_office_Final_reply_day_Text__c = obj.Return_to_office_Final_reply_day_F__c;
            hasChange = true;
        }
        // Min_Final_reply_day_F__c有使用Repair_delete_Final_reply_day_Text__c字段
        if (equalNullCheck(obj.Repair_delete_Final_reply_day_Text__c, obj.Repair_delete_Final_reply_day_F__c) || obj.Repair_delete_Final_reply_day_Text__c != obj.Repair_delete_Final_reply_day_F__c) {
            raes.Repair_delete_Final_reply_day_Text__c = obj.Repair_delete_Final_reply_day_F__c;
            hasChange = true;
        }
        // Min_Final_reply_day_F__c有使用Yigoudaihuo_Final_reply_day_Text__c字段
        if (equalNullCheck(obj.Yigoudaihuo_Final_reply_day_Text__c, obj.Yigoudaihuo_Final_reply_day_F__c) || obj.Yigoudaihuo_Final_reply_day_Text__c != obj.Yigoudaihuo_Final_reply_day_F__c) {
            raes.Yigoudaihuo_Final_reply_day_Text__c = obj.Yigoudaihuo_Final_reply_day_F__c;
            hasChange = true;
        }
        // Min_Final_reply_day_F__c有使用Guzhangpaicha_Final_reply_day_Text__c字段
        if (equalNullCheck(obj.Guzhangpaicha_Final_reply_day_Text__c, obj.Guzhangpaicha_Final_reply_day_F__c) || obj.Guzhangpaicha_Final_reply_day_Text__c != obj.Guzhangpaicha_Final_reply_day_F__c) {
            raes.Guzhangpaicha_Final_reply_day_Text__c = obj.Guzhangpaicha_Final_reply_day_F__c;
            hasChange = true;
        }
        if (equalNullCheck(obj.Extend_Date__c, obj.Extend_Date_F__c) || obj.Extend_Date__c != obj.Extend_Date_F__c) {
            raes.Extend_Date__c = obj.Extend_Date_F__c;
            hasChange = true;
        }
        if (equalNullCheck(obj.Received_NG_ReAssign_Text__c, obj.Received_NG_ReAssign__c) || obj.Received_NG_ReAssign_Text__c != obj.Received_NG_ReAssign__c) {
            raes.Received_NG_ReAssign_Text__c = obj.Received_NG_ReAssign__c;
            hasChange = true;
        }
        /******************************* Min_Final_reply_day_F__c使用字段 End **************************************/
 
        /************************************ 第二次更新字段 OR 只更新一次就可以的字段 End ******************************************/
 
        if (hasChange) {
            return raes;
        } else {
            return null;
        }
        return null;
    }
 
    private static Boolean equalNullCheck(Object obj, Object obj1) {
        return obj == null && obj1 != null || obj1 == null && obj != null;
    }
 
//bp2
//    public static List<Equipment_Set_Detail__c> setESD(List<Equipment_Set_Detail__c> esdList) {
//        List<Equipment_Set_Detail__c> updateList = new List<Equipment_Set_Detail__c>();
//        for (SObject obj: esdList) {
//            Boolean needUpdate = false;
//            Equipment_Set_Detail__c esd = (Equipment_Set_Detail__c) obj;
//            if (esd.Asset_condition__c != esd.Asset_condition_Text__c) {
//                esd.Asset_condition_Text__c = esd.Asset_condition__c;
//                needUpdate = true;
//            }
//            if (esd.Serial_Lot__c != esd.Serial_Lot_text__c) {
//                esd.Serial_Lot_text__c = esd.Serial_Lot__c;
//                needUpdate = true;
//            }
//            if (esd.Asset__r.Loaner_accsessary__c != esd.Loaner_accsessary_text__c) {
//                esd.Loaner_accsessary_text__c = esd.Asset__r.Loaner_accsessary__c;
//                needUpdate = true;
//            }
//            if (esd.Active_judgement_select__c != esd.Active_judgement_text__c) {
//                esd.Active_judgement_text__c = esd.Active_judgement_select__c;
//                needUpdate = true;
//            }
//            if (esd.Last_Reserve_RAES_Detail_RAES_F__c != esd.Last_Reserve_RAES_Detail_RAES_Id__c) {
//                esd.Last_Reserve_RAES_Detail_RAES_Id__c = esd.Last_Reserve_RAES_Detail_RAES_F__c;
//                needUpdate = true;
//            }
//            if (esd.Equipment_Set_Last_Reserve_RAES_F__c != esd.Equipment_Set_Last_Reserve_RAES_Id__c) {
//                esd.Equipment_Set_Last_Reserve_RAES_Id__c = esd.Equipment_Set_Last_Reserve_RAES_F__c;
//                needUpdate = true;
//            }
//            if (needUpdate) updateList.add(esd);
//        }
//        return updateList;
//    }
/************************* Inner Class ******************************/
   public class ErrorBean{
        // public String objectName;
        // public String objectLabel;
        public Map<Id, String> messageMap;
        public Boolean overMax;
        // public ErrorBean(Schema.sObjectType obj) {
        //     objectName = obj.getDescribe().getName();
        //     objectLabel = obj.getDescribe().getLabel();
        //     messageMap = new Map<Id, String>();
        //     overMax = false;
        // }
        public ErrorBean() {
          messageMap = new Map<Id, String>();
          overMax = false;
        }
        public void setError (Database.SaveResult[] saveRes, Integer maxCut, Schema.sObjectType obj) {
            if (messageMap.keySet().size() <= maxCut && overMax == false) {
                String objectName = obj.getDescribe().getName();
                String objectLabel = obj.getDescribe().getLabel();
                for (Database.SaveResult saveRe : saveRes) {
                    if (!saveRe.isSuccess()) {
                        if (!messageMap.containsKey(saveRe.getId())) {
                            if (messageMap.keySet().size() >= maxCut) {
                                overMax = true;
                                break;
                            }
                            for (Database.Error err : saveRe.getErrors()) {
 
                                String message = objectName + ':'
                                               + objectLabel + ':'
                                               + err.getStatusCode() + ':'
                                               + err.getFields() + ':'
                                               + err.getMessage();
                                // 数据里面有复数错误信息的话只获取第一条
                                messageMap.put(saveRe.getId(), message);
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
}