sunxia
2022-11-21 0fd788ee4e392c702c15ac9e1754e0a94770de8f
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
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
global with sharing class TransferApplySelectDetailSubController extends CreateRelationListPagingCtrlBase {
    public override Integer getSearchNumMax() {
        //各ページに制御あれば、最大件数を指定する
        // searchNumMax = Integer.valueOf(Label.Product_Select_Limit);
        // searchNumMax = 20;
        pagesize = '20';
        return searchNumMax;
    }
 
    /* 選択されたデータ取得用Soql Fromから*/
    public override String getSelectedDataSql() {
        // オブジェクトAPI名
        selectedDataSql = '';
        for(String field:FIELD_NAME_MAP.keySet()) {
            myComponentController.columnRightRW.put(field, 'r');
        }
        myComponentController.columnRightRW.put('OneToOneAccessory__c', 'r');
        myComponentController.columnRightRW.put('VF_TransferCount__c', 'r');
        myComponentController.columnRightRW.put('SalesProvince_After__c', 'w');
        myComponentController.columnRightRW.put('Salesdepartment_After__c', 'w');
        myComponentController.columnRightRW.put('EquipmentSet_Managment_Code_After__c', 'w');
        myComponentController.columnRightRW.put('Equipment_Type_After__c', 'w');
        myComponentController.columnRightRW.put('WH_location__c', 'w');
        myComponentController.columnRightRW.put('IsPerfect__c', 'w');
        // 20210813 ljh 管理编码 add start
        myComponentController.columnRightRW.put('CodeKey__c', 'r');
        myComponentController.columnRightRW.put('Internal_asset_location_After__c', 'r');
        myComponentController.columnRightRW.put('Product_category__c', 'r');
        // 20210813 ljh 管理编码 add end
        
        return selectedDataSql;
    }
 
    public override String getOriginObjName() {
        // オブジェクトAPI名
        originObjName = 'TransferApplyDetail__c';
        return originObjName;
    }
    public override String getOriginObjColumns() {
        // 項目セット
        originObjColumns = myComponentController.strColumus ;
        return originObjColumns;
    }
 
    public override String getObjName() {
        // オブジェクトAPI名
        objName = 'TransferApplyDetail__c';
        return objName;
    }
    public override String getColumnLeftFieldSetName() {
        // 左の項目セット
        columnLeftFieldSetName = '';
        return columnLeftFieldSetName;
    }
    public override String getColumnRightFieldSetName() {
        // 右の項目セット
        columnRightFieldSetName = 'DetailBulkUpdate';
        return columnRightFieldSetName;
    }
 
    public override List<String> getColumnFieldList() {
        // strColumus 里加 field
        // FixtureUtil#raesdGroupByAssetId()の項目も必要
        return new List<String>{'TransferApplySummary__c', 'LastModifiedDate', 'Name'
                                , 'Arrival_in_wh__c','Arrival_wh_Flag_F__c','Arrival_wh_Abandoned_Flag_F__c'
                                , 'CodeKey__c' // 20210814 ljh 管理编码
                                , 'Internal_asset_location_After__c' // 20210814 ljh 管理编码
                                , 'Product_category__c' // 20210814 ljh 管理编码
                            };
    }
 
    public override String getFKColumnField() {
        // getObjName 连 getOriginObjName 的 FK
        return 'Asset__c';
    }
 
    public override String getRecordTypeId() {
        //ページレイアウトを収得するのレコードタイプ
        recordTypeId = '';
        return recordTypeId;
    }
 
    // ページコントローラに検索処理は、WhereSoql作成のみ、パラメータとして、コンポーネントに渡される
    public override String getSqlWhereStr() {
        sqlWhereStr = '';
 
        if (getIsNeedRunSearch()) {
            //update by rentx 2021-05-07 start 1802 
            // sqlWhereStr = this.makeSoql(keyword, assetnumber);
            sqlWhereStr = this.makeSoql(keyword, assetnumber, isPerfect);
            //update by rentx 2021-05-07 end 1802
        }
 
        return sqlWhereStr;
 
    }
 
    public override String getOrderbyStr() {
        String ordStr = 'order by TransferApplySummary__r.Name, TransferApplySummary__c, Name';
        return ordStr;
    }
 
    public override Boolean getIsNeedRunSearch() {
        return true;
    }
 
    /*****************検索用******************/
 
 
    /*****************ソート時再検索条件(画面からの入力条件を無視するため)******************/
    public String keyword { get; set; }
    public String assetnumber {get; set;}
    public TransferApply__c parentObj { get; private set; }
    public Boolean editMode {get;set;}
    //add by rentx 1802 2021-04-07 start
    // public Boolean isPerfect {get;set;}
    public String isPerfect {get;set;}
    public List<SelectOption> options {get;set;}
    //add by rentx 1802 2021-04-07 end
 
    //20210812 ljh 管理编码 start
    public transient static Map<String,String> locationMap;
    static {
        locationMap = new Map<String, String> {
            '北京 备品中心' => 'BJ',
            '上海 备品中心' => 'SH',
            '广州 备品中心' => 'GZ'
        };
    }
    //20210812 ljh 管理编码 end
    public TransferApplySelectDetailSubController() {
        parentId = ApexPages.currentPage().getParameters().get('id');
        editMode = false;
        //add by rentx 1802 2021-04-08 start
        String NONE = system.label.StartTrading_None;
        options = new List<SelectOption> { new SelectOption(NONE, NONE) };
        options.add(new SelectOption('是', '是'));
        options.add(new SelectOption('否', '否'));
        //add by rentx 1802 2021-04-08 end
        
        //借出备品一览の情報を取得
        if (!String.isBlank(this.parentId)) {
            List<TransferApply__c> taList = [
                SELECT Id
                     , Add_Approval_Status__c
                     , Status__c
                     , RecordType.DeveloperName
                  FROM TransferApply__c
                 WHERE Id=:parentId
            ];
            if(taList.isEmpty()) {
                throw new ControllerUtil.myException('参数错误:请指定Id。');
            }
            else{
                parentObj = taList[0];
            }
        } else {
            throw new ControllerUtil.myException('参数错误:请指定Id。');
        }
    }
 
    public void init() {
        isNeedSearchFirst = true;
        //searchOppSetParam();
        getSqlWhereStr();
    }
 
    // 所在地区(本部)
    public List<SelectOption> salesdepartmentOpts {
        get {
            if (salesdepartmentOpts == null) {
                salesdepartmentOpts = getPickList('TransferApplyDetail__c', 'Salesdepartment__c');
            }
            return salesdepartmentOpts;
        }
        set;
    }
    // 所在地区(省)
    public List<SelectOption> salesProvinceOpts {
        get {
            if (salesProvinceOpts == null) {
                salesProvinceOpts = getPickList('TransferApplyDetail__c', 'SalesProvince__c');
            }
            return salesProvinceOpts;
        }
        set;
    }
    // 备品分类
    public List<SelectOption> equipmentTypeOpts {
        get {
            if (equipmentTypeOpts == null) {
                equipmentTypeOpts = getPickList('TransferApplyDetail__c', 'Equipment_Type__c');
            }
            return equipmentTypeOpts;
        }
        set;
    }
 
    public PageReference searchOpp() {
        //searchOppSetParam();
 
        if (!getIsNeedRunSearch()) {
            return null;
        }
        // 選択済みの製品を取得
        myComponentController.getSelectedDataInfo();
 
        getSqlWhereStr();
        // コンポーネントにSoqlを発行して、ページングする
        myComponentController.searchAndPaging();
        return null;
    }
 
    public void changeEdit() {
        editMode = !editMode;
        for(WrapperInfo wi:viewList) {
            TransferApplyDetail__c tad =(TransferApplyDetail__c) wi.sobj;
            wi.canEdit = editMode && !tad.Arrival_in_wh__c && (tad.Arrival_wh_Flag_F__c || tad.Arrival_wh_Abandoned_Flag_F__c);
        }
    }
    public PageReference savePage() {
        if(save()){
            searchOpp();
            ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.INFO, '保存完了'));
        }
        return null;
    }
    public Boolean save() {
        Boolean done = false;
        List<TransferApplyDetail__c> updateTadList = new List<TransferApplyDetail__c>();
        // 20210812 ljh 管理编码 add start
        Set<Id> tadClearId = new Set<Id>();
        Map<Id, TransferApplyDetail__c> codMap = new Map<Id, TransferApplyDetail__c>();
        Map<String, List<TransferApplyDetail__c>> codeNewMap = new Map<String, List<TransferApplyDetail__c>>();
        Map<String, List<TransferApplyDetail__c>> fmnMap = new Map<String, List<TransferApplyDetail__c>>();
        List<Asset_EquipmentSet_Managment_Code__c> aesmUList = new List<Asset_EquipmentSet_Managment_Code__c>();
        Set<Id> xl0TadId = new Set<Id>();
        List<TransferApplyDetail__c> tadBMList = new List<TransferApplyDetail__c>();
        List<TransferApplyDetail__c> tadBMNewList = new List<TransferApplyDetail__c>();// 20211122 ljh SFDC-C8W3HW
        String xl0 = System.Label.xl0String;
        List<String> xl0List = xl0.split(';');
        // 20210812 ljh 管理编码 add end
        Savepoint sp = Database.setSavepoint();
        try {
            for(WrapperInfo wf : viewList) {
                if(wf.check) {
                    TransferApplyDetail__c tad = (TransferApplyDetail__c) wf.sobj;
                    updateTadList.add(tad);
                    // 20210813 ljh 管理编码 add start
                    // 需要编码的
                    if(tad.Loaner_accsessary__c == false){ 
                        // 20211122 ljh SFDC-C8W3HW
                        // if((String.isNotBlank(tad.Equipment_Type_After__c) 
                        //     && ((tad.Equipment_Type__c == '检测用备品' && tad.Equipment_Type_After__c != '检测用备品') || (tad.Equipment_Type__c != '检测用备品' && tad.Equipment_Type_After__c == '检测用备品'))
                        //     )
                        //     ||(String.isNotBlank(tad.Salesdepartment_After__c) && tad.Salesdepartment_After__c != tad.Salesdepartment__c)
                        // ){
                            List<TransferApplyDetail__c> tadFsList = new List<TransferApplyDetail__c>();
                            if(fmnMap.containsKey(tad.Fixture_Model_No__c)){
                                tadFsList = fmnMap.get(tad.Fixture_Model_No__c);
                                tadFsList.add(tad);
                                fmnMap.put(tad.Fixture_Model_No__c,tadFsList);
                            }else{
                                tadFsList = new List<TransferApplyDetail__c>();
                                tadFsList.add(tad);
                                fmnMap.put(tad.Fixture_Model_No__c,tadFsList);
                            }
                        // 20211122 ljh SFDC-C8W3HW
                        // }else if(String.isNotBlank(tad.CodeKey__c)){
                        //     tadClearId.add(tad.Id);
                        // }
                        // 20211122 ljh SFDC-C8W3HW
                    }
                    // 20210813 ljh 管理编码 add end
                }
            }
            if(fmnMap.size() > 0){
                List<Fixture_Set__c> fsList =  [SELECT Id, Name, Loaner_categoryII__c 
                 FROM Fixture_Set__c WHERE Name IN:fmnMap.keySet()];
                for(Fixture_Set__c fs:fsList){
                    if(xl0List.contains(fs.Loaner_categoryII__c)){
                        for(TransferApplyDetail__c tadfs:fmnMap.get(fs.Name)){
                            xl0TadId.add(tadfs.Id);
                        }
                    }
                }
                for(String fmn:fmnMap.keySet()){
                    tadBMList.addAll(fmnMap.get(fmn));
                }
                // 20211122 ljh SFDC-C8W3HW  add start
                // 重新设计需要编码的tadBMNewList
                for(TransferApplyDetail__c tad:tadBMList){
                    String SalesdepartmentS = String.isNotBlank(tad.Salesdepartment_After__c)?tad.Salesdepartment_After__c:tad.Salesdepartment__c;
                    Integer SalesdepartmentI;
                    if(String.isNotBlank(SalesdepartmentS)){
                        String[] SalesdepartmentArr = SalesdepartmentS.split('\\.');
                        if(SalesdepartmentArr.size() > 0){
                            String Salesdepartment = SalesdepartmentArr[0];
                            SalesdepartmentI = Integer.valueOf(Salesdepartment);
                        }
                    }
                    // 1.备品分类 改变重新编码
                    if(String.isNotBlank(tad.Equipment_Type_After__c)   &&  tad.Equipment_Type__c != '检测用备品' && tad.Equipment_Type_After__c == '检测用备品'  
                    ){
                        tadBMNewList.add(tad);
                    // 2.备品分类 不改变(非检测)本部改变 重新编码
                    }else if( String.isNotBlank(tad.Salesdepartment_After__c) && tad.Salesdepartment_After__c != tad.Salesdepartment__c){
                        tadBMNewList.add(tad);
                    }else {
                        // 3.备品分类 不改变(非检测)本部不改变  0系改变重新编码
                        // 原来系列 第三位 是否是0
                        String IsCode0 = ''; 
                        if(String.isNotBlank(tad.EquipmentSet_Managment_Code__c)){
                            IsCode0 = tad.EquipmentSet_Managment_Code__c.substring(2,3);
                        }
                        Boolean IsCode0B  = xl0TadId.contains(tad.Id);
                        if(String.isNotBlank(IsCode0)&& ((IsCode0 == '0' && IsCode0B == false)||(IsCode0 != '0' && IsCode0B == true))
                            ){
                            tadBMNewList.add(tad);
                        }else{
                            // 4.备品分类 不改变(非检测)本部不改变  0系不改变(0系) 0本部 存放地改变 重新编码
                            // 存放地改变 暂时认为 只有备品中心调拨到备品中心才发生改变。  
                            if(IsCode0B){
                                if(SalesdepartmentI != null && SalesdepartmentI == 0  && parentObj.RecordType.DeveloperName == 'CenterToCenter'){
                                    tadBMNewList.add(tad);
                                }
                            }else{
                                // 5\6\7.备品分类 不改变(非检测)本部不改变  0系不改变(!0系) 0本部和7-11本部 存放地改变 重新编码
                                if(parentObj.RecordType.DeveloperName == 'CenterToCenter' && SalesdepartmentI != null && (SalesdepartmentI == 0 || (SalesdepartmentI > 6 && SalesdepartmentI < 12) || SalesdepartmentI == 16)){
                                    tadBMNewList.add(tad);
                                }else if(String.isNotBlank(tad.CodeKey__c)){
                                    tadClearId.add(tad.Id);
                                }
                            }
                        }
                        
                    } 
                }
                // 20211122 ljh SFDC-C8W3HW  add start end
                // for(TransferApplyDetail__c tad:tadBMList){
                for(TransferApplyDetail__c tad:tadBMNewList){
                    String SalesdepartmentS = String.isNotBlank(tad.Salesdepartment_After__c)?tad.Salesdepartment_After__c:tad.Salesdepartment__c;
                    if(String.isNotBlank(SalesdepartmentS)){
                        String[] SalesdepartmentArr = SalesdepartmentS.split('\\.');
                        if(SalesdepartmentArr.size() > 0){
                            String Salesdepartment = SalesdepartmentArr[0];
                            Integer SalesdepartmentI = Integer.valueOf(Salesdepartment);
                            if(SalesdepartmentI < 12 || SalesdepartmentI == 16){
                                // key一览明细本次  key1一览明细上次
                                // 备品分类、本部、是否0系列、产品分类(GI/SP)、存放地
                                List<TransferApplyDetail__c> tadTempList = new List<TransferApplyDetail__c>();
                                String key = '';
                                // 1. 备品分类
                                String EquipmentType = String.isNotBlank(tad.Equipment_Type_After__c)?tad.Equipment_Type_After__c:tad.Equipment_Type__c;
                                if(EquipmentType == '检测用备品'){
                                    key += 'JC;'+locationMap.get(tad.Internal_asset_location_After__c);    
                                }else{
                                    key += 'NJC;';
                                    //2.本部 
                                    key += Salesdepartment+';';
                                    //3.是否0系列
                                    // 原管理编码的第三可知是否是0系列
                                    // String IsCode0 = tad.EquipmentSet_Managment_Code__c.substring(2,3);
                                    // 0系列 还是看 型号
                                    Boolean IsCode0  = xl0TadId.contains(tad.Id);
                                    // if(IsCode0 == '0'){
                                    if(IsCode0){
                                        if(SalesdepartmentI == 0 || SalesdepartmentI == 10){
                                            key += '0;'+locationMap.get(tad.Internal_asset_location_After__c);
                                        }else{
                                            key += '0';
                                        }
                                    }else{
                                        key += 'N0;';
                                        if(SalesdepartmentI == 0 || SalesdepartmentI > 6 ){
                                            key += tad.Product_category__c+';'+locationMap.get(tad.Internal_asset_location_After__c);
                                        }else if(SalesdepartmentI < 7){
                                            key += tad.Product_category__c;
                                        }
                                    }
                                }
                                // key
                                if(String.isBlank(tad.CodeKey__c) || (!String.isBlank(tad.CodeKey__c) && tad.CodeKey__c != key)){
                                    if(codeNewMap.containsKey(key)){
                                        tadTempList = codeNewMap.get(key);
                                        tadTempList.add(tad);
                                        codeNewMap.put(key,tadTempList);
                                    }else{
                                        tadTempList = new List<TransferApplyDetail__c>();
                                        tadTempList.add(tad);
                                        codeNewMap.put(key,tadTempList);
                                    }
                                }
                            }else if(String.isNotBlank(tad.CodeKey__c)){
                                // 本部大于等于 12清空管理编码
                                tadClearId.add(tad.Id);
                            }
                        }
                    }
                }
            }
            // 20210813 ljh 管理编码 add start
            if(codeNewMap.size() > 0){
                List<Asset_EquipmentSet_Managment_Code__c> aemCodeList = [SELECT Id, key__c, code__c,   
                         LastNo__c, keyName__c, isSpecial__c, MaxLastNo__c FROM Asset_EquipmentSet_Managment_Code__c
                        WHERE key__c IN :codeNewMap.keySet() for update];
                for(Asset_EquipmentSet_Managment_Code__c aem:aemCodeList){
                    Integer code = Integer.valueOf(aem.LastNo__c);
                    String codeManange;
                    // String codeString = 
                    if(aem.LastNo__c == aem.MaxLastNo__c){
                        // 无法编码 抛出异常
                        throw new ControllerUtil.myException('编码已满,暂时无法编码。');
                    }else if(Integer.valueOf(aem.MaxLastNo__c)-Integer.valueOf(aem.LastNo__c) < codeNewMap.get(aem.key__c).size()){
                        // 不足 抛出异常
                        throw new ControllerUtil.myException('编码内存不足,暂时无法编码。');
                    }else{
                        //正常编码
                        for(TransferApplyDetail__c tad2:codeNewMap.get(aem.key__c)){
                           if(code == 19999 || code == 29999 || code == 39999
                               || code == 39999 || code == 49999 || code == 59999
                                ){
                                code = code + 2;
                            }else{
                                code = code + 1;
                            }
                            if(aem.isSpecial__c){
                                codeManange = aem.code__c + String.valueOf(code).leftpad(5, '0').subString(0,1)+'-'+String.valueOf(code).leftpad(5, '0').substring(1,5);
                            }else{
                                codeManange = aem.code__c +'-'+String.valueOf(code).leftpad(5, '0').substring(1,5);
                            }
                            TransferApplyDetail__c tad3 = new TransferApplyDetail__c();
                            tad3.Id = tad2.Id;
                            tad3.EquipmentSet_Managment_Code_After__c= codeManange;
                            tad3.CodeKey__c = aem.key__c;
                            codMap.put(tad2.Id,tad3); 
                        }
                        Asset_EquipmentSet_Managment_Code__c aesm = new Asset_EquipmentSet_Managment_Code__c();
                        aesm.Id = aem.Id;
                        aesm.LastNo__c = code;
                        aesm.EquipmentSet_Managment_Code__c = codeManange;
                        aesm.Edit_staff__c = UserInfo.getUserId();
                        aesmUList.add(aesm);
                    }
                }
            }
            // 20210813 ljh 管理编码 add end
            if(!updateTadList.isEmpty()) {
                List<String> errorList = modifiedByOthers(updateTadList);
                if(errorList.isEmpty()) {
                    //20210813 ljh 管理编码 start
                    for(TransferApplyDetail__c utad:updateTadList){
                        if(tadClearId.contains(utad.Id)){
                           utad.EquipmentSet_Managment_Code_After__c = ''; //有值才拷贝到保有设备
                           utad.CodeKey__c = '';
                        }
                        if(codMap.containsKey(utad.Id)){
                           utad.EquipmentSet_Managment_Code_After__c = codMap.get(utad.Id).EquipmentSet_Managment_Code_After__c; 
                           utad.CodeKey__c = codMap.get(utad.Id).CodeKey__c; 
                        }
                    }
                    //20210813 ljh 管理编码 end
                    update updateTadList;
                    update aesmUList; //20210809 ljh 管理编码 
                    done = true;
                }
                else {
                    for(String err:errorList) {
                        ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, err));
                    }
                    return false;
                }
            }
        }
        catch (Exception ex) {
            System.debug(ex.getStackTraceString());
            ApexPages.addMessages(ex);
            Database.rollback(sp);
        }
        return done;
    }
    private List<String> modifiedByOthers(List<TransferApplyDetail__c> objs) {
        List<String> errorList = new List<String>();
        Map<Id, TransferApplyDetail__c> objMap = new Map<Id, TransferApplyDetail__c>([
            SELECT Id, LastModifiedDate, LastModifiedBy.Name
            FROM TransferApplyDetail__c
            WHERE Id IN: objs
        ]);
        for(TransferApplyDetail__c obj:objs) {
            if(!objMap.containsKey(obj.Id)) {
                errorList.add(obj.Name + '不存在!');
            }
            else if(obj.LastModifiedDate != objMap.get(obj.Id).LastModifiedDate) {
                errorList.add(obj.Name + ' 已被 ' + objMap.get(obj.Id).LastModifiedBy.Name + ' 修改,请刷新画面重试!' );
            }
        }
        return errorList;
    }
 
    public PageReference turnback() {
        PageReference ret = null;
        if (!String.isBlank(this.parentId)) {
            ret = new PageReference('/' + this.parentId);
        }
        return ret;
    }
 
    //update by rentx 2021-05-07 start 1802
    // private String makeSoql(String keyword, String assetnumber) {
    private String makeSoql(String keyword, String assetnumber, String isPerfect) {
    //update by rentx 2021-05-07 end 1802
        // 検索条件
        String dateToday = String.valueOf(Date.today());
 
        String soql ='';
        soql += ' where TransferApply__c = \'' + String.escapeSingleQuotes(parentId) + '\'';
        soql += ' and Cancel_Select__c = false';
 
        if (!String.isBlank(keyword)) {
            String[] vals = keyword.split(' ');
             soql += ' and (';
             String fmodelno = '';
            for (String v : vals) {
                v = String.escapeSingleQuotes(v.replace('%', '\\%').replace('*', '%'));
                fmodelno += ' Asset__r.Product2.Fixture_Model_No_T__c like \'' + v + '\' ';
                fmodelno += ' or Asset__r.Product2.Name like \'' + v + '\' ';
                fmodelno += 'or';
            }
            fmodelno = fmodelno.removeEnd('or');
            soql += fmodelno + ' )';
        }
 
        if (!String.isBlank(assetnumber)) {
            String num = String.escapeSingleQuotes(assetnumber.replace('%', '\\%').replace('*', '%'));
            soql += ' and Asset__r.Internal_Asset_number_key__c like\'' + num + '\' ';
        }
 
        //add by rentx 2021-05-07 start 1802 
        if (isPerfect != null && isPerfect == '是') {
            soql += ' and IsPerfect__c = true ';
        }else if (isPerfect != null && isPerfect == '否') {
            soql += ' and IsPerfect__c = false ';
        }
        // if (isPerfect != null) {
            // soql += ' and IsPerfect__c = '+ !isPerfect;
        // }
        //add by rentx 2021-05-07 end 1802
        return soql;
    }
    public void saveAndSearch() {
        if(save()) {
            searchOpp();
        }
    }
    public void saveAndSearchNext() {
        if(save()) {
            myComponentController.searchNext();
        }
    }
    public void saveAndsearchPrevious() {
        if(save()) {
            myComponentController.searchPrevious();
        }
    }
    public void saveAndsearchGoPage() {
        if(save()) {
            myComponentController.searchGoPage();
        }
    }
 
    public override void setViewList(List<sObject> queryList) {
        viewList = new List<WrapperInfo>();
        //Id lastTASId = null;
        // 自己的数据打勾,被检索出来的数据不打勾
        for (Integer i = 0; i < queryList.size(); i++) {
            TransferApplyDetail__c tad = (TransferApplyDetail__c) queryList[i];
            WrapperInfo wf= new WrapperInfo(tad, myComponentController);
            wf.check = false;
            wf.oldCheck = false;
            wf.canEdit = editMode && !tad.Arrival_in_wh__c && (tad.Arrival_wh_Flag_F__c || tad.Arrival_wh_Abandoned_Flag_F__c);
            wf.lineNo = i;
            viewList.add(wf);
        }
    }
 
    public List<SelectOption> getPickList(String objApi, String fieldApi) {
        Schema.DescribeFieldResult fieldResult = Schema.getGlobalDescribe().get(objApi).getDescribe().fields.getMap().get(fieldApi).getDescribe();
        List<SelectOption> pickListValuesList= new List<SelectOption>();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        pickListValuesList.add(new SelectOption('', ''));
        pickListValuesList.add(new SelectOption('--无--', '--无--'));
        for( Schema.PicklistEntry pickListVal : ple){
            pickListValuesList.add(new SelectOption(pickListVal.getValue(), pickListVal.getLabel()));
        }
        return pickListValuesList;
    }
    private static Map<String, String> FIELD_NAME_MAP = new Map<String, String> {
        // 明细字段->asset字段
        'Asset__c'                       => 'Id',
        'Fixture_Model_No__c'            => 'Fixture_Model_No_F__c',
        'SerialNumber__c'                => 'SerialNumber',
        'Internal_Asset_number_key__c'   => 'Internal_Asset_number_key__c',
        'Internal_asset_location__c'     => 'Internal_asset_location__c',
        'Salesdepartment__c'             => 'Salesdepartment__c',
        'SalesProvince__c'               => 'SalesProvince__c',
        'Equipment_Type__c'              => 'Equipment_Type__c',
        'EquipmentSet_Managment_Code__c' => 'EquipmentSet_Managment_Code__c',
        'Main_OneToOne__c'               => 'Main_OneToOne__c',
        'Manage_type__c'                 => 'Manage_type__c',
        'Loaner_accsessary__c'           => 'Loaner_accsessary__c',
        'You_Xiao_Ku_Cun__c'             => 'You_Xiao_Ku_Cun__c'
    };
}