binxie
2024-01-16 1b08402678deb31bba4a347bfd388eba8360cbc1
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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
public class SelectAssetExtension {
 
    private String targetHospitalId { get; set; }
 
    private String targetContractId { get; set; }
 
    // 引数のサービス契約の情報を格納する。
    public Maintenance_Contract__c contract { get; set; }
 
    // 病院配下の納入機器の情報を格納する。
    //public List<Asset> assetRecords { get; set; }//20191220 modify
    //public static  List<Asset> assetRecords  = new List<Asset>();
    public List<List<Asset>> assetLists { get; set; }
    // zzm  20231026 start
    private static integer MAX_RECORD_NUM = 500; //SelectAssetExtension.cls
    // zzm  20231026 end
 
    public Integer getProductCount() {
        //return this.assetRecords.size();
        Integer listSize = assetLists.size();
 
        Integer pCount = 0;
        if (listSize > 0) {
            for (Integer i = 0; i < listSize; i++) {
                List<Asset> aList = assetLists.get(i);
                pCount += aList.size();
            }
        }
        return pCount;
    }
 
    // 選択済みの納入機器の
    public List<Maintenance_Contract_Asset__c> selectedAsset { get; set; }
    public List<Maintenance_Contract_Asset_Estimate__c> selectedAsset2 { get; set; }
    //public List<Maintenance_Contract_Asset_Estimate__c> selectedAsset2{ get; set; }
    public String sortKey { get; set; }
    public String preSortKey { get; set; }
    public Boolean sortOrderAsc { get; set; }
 
    public String[] sortOrder { get; set; }
 
    public String[] columus = new String[] { 'asset.name',
            'asset.SerialNumber',
            'asset.Department_Name__c',
            'asset.Installation_Site__c',
            'asset.Posting_Date__c',
            'asset.Asset_Owner__c'
                                           };
    //zzm 230831增加检索条件解决数据超量报错的问题 start
    public static List<SelectOption> textOpts { get; private set; }
    static {
        textOpts = new List<SelectOption>();
       
        // textOpts.add(new SelectOption('S:AssetMark__c', '主机/耗材'));
        textOpts.add(new SelectOption('S:Name', Schema.SObjectType.Asset.fields.Name.label));
        textOpts.add(new SelectOption('S:SerialNumber', Schema.SObjectType.Asset.fields.SerialNumber.label));
        // textOpts.add(new SelectOption('S:CurrentContract__r.Management_Code__c', Schema.SObjectType.Asset.fields.CurrentContract__c.label));
        textOpts.add(new SelectOption('S:Installation_Site__c', Schema.SObjectType.Asset.fields.Installation_Site__c.label));
        textOpts.add(new SelectOption('S:Department_Name__c', Schema.SObjectType.Asset.fields.Department_Name__c.label));
    }
    public static List<SelectOption> equalOpts { get; private set; }
    static {
        equalOpts = new List<SelectOption>();
        equalOpts.add(new SelectOption('equals', '等于'));
        equalOpts.add(new SelectOption('contains', '包含'));
        equalOpts.add(new SelectOption('notequals', '不等于'));
    }
    public String text1 { get; set; }                         // 对象
    public String cond1 { get; set; }                         // 条件
    public String val1 { get; set; }                                         
    //zzm 230831增加检索条件解决数据超量报错的问题 end
 
    public  void init() {
 
        List<Asset> assetRecords  = new List<Asset>();//20191220 add
    //zzm 230831增加检索条件解决数据超量报错的问题 start
        List<Asset> selectAssetRecords  = new List<Asset>();
        List<Asset> notSelectedAssetRecords  = new List<Asset>();
    //zzm 230831增加检索条件解决数据超量报错的问题 end
        // サービス契約の情報を取得
        try {
            this.contract = [SELECT Id, Name, Management_Code__c, Hospital__c, Contract_Start_Date__c, Contract_End_Date__c FROM Maintenance_Contract__c WHERE Id = :this.targetContractId][0];
            this.targetHospitalId = this.contract.Hospital__c;
        } catch ( System.ListException le) {
            this.contract = new Maintenance_Contract__c();
        }
 
        // 納入機器の情報を取得
        if ( this.targetHospitalId == null || ( this.targetHospitalId.length() != 15 && this.targetHospitalId.length() != 18)) {
            system.debug('assetRecords123456789==' + assetRecords);
        } else {
            // HWAG-BHD66X start
        //zzm 230831增加检索条件解决数据超量报错的问题 start
            /*assetRecords = [SELECT Id, Name, CheckBox__c, SerialNumber,TransferToOther__c    ,
                            Department_Name__c, Installation_Site__c, Posting_Date__c,
                            Asset_Owner__c,    Product2Id
                            // Gzw 20200826 保存上一期合同临时用 start
                            , Remarks__c,MDM_Model_No__c
                            // Gzw 20200826 保存上一期合同临时用 end
                            // fxk 2021/9/17 点检对象临时用 star
                            // , Freeze_sign__c
                            // fxk 2021/9/17 点检对象临时用 end
                            FROM Asset
                            WHERE Hospital__c = :this.targetHospitalId
                                                // XLIU-CK46FR zyh start
                                                AND Status != '廃棄' AND Status != '待报废' 
                                                AND (Competitor_Name__c = '奥林巴斯' OR Competitor_Name__c = '' OR Competitor_Name__c = '其他')
                                                AND Category1__c != 'ET'
                                                AND (Category1__c != 'SP' OR Category2__c != '附属品' )
                                                AND (Category1__c != 'GI' OR Category2__c != '附属品' OR Category4__c != 'OER' )
                                                AND (Category1__c != 'GI' OR Category2__c != '其他' )
                                                AND (Category1__c != 'ENG' OR Category2__c != '附属品' )
                                                AND (Category1__c != 'ENG' OR Category2__c != '耗材' )
                                                // AND (Category1__c != 'SP' OR Category2__c != '附属品' )
                                                // AND (Category1__c != 'GI' OR (Category2__c != '附属品' OR Category2__c != '其他') )
                                                // AND (Category1__c != 'ENG' OR (Category2__c != '附属品' OR Category2__c != '耗材') )
                                                // AND AssetMark__c != '耗材' 
                                                // XLIU-CK46FR zyh end
                                                AND ( AssetMark__c != '耗材' OR Product2.Family != 'ET' )
                                                ORDER BY Department_Name__c, Posting_Date__c, SerialNumber
            ];*/
       
                                 
            String sqlStr = this.makeSoqlconfim();
            sqlStr += ' and id in (SELECT Asset__c FROM Maintenance_Contract_Asset__c WHERE Maintenance_Contract__c =\'' + this.targetContractId + '\') ';
                            
            // if (String.isNotBlank(text1) && String.isNotBlank(cond1) && String.isNotBlank(val1)) {
            //     sqlStr += makeTextSql(text1, cond1, val1);
            // }
            sqlStr += ' ORDER BY Department_Name__c, Posting_Date__c, SerialNumber';
 
            selectAssetRecords = Database.query(sqlstr);
            integer assetSize = selectAssetRecords.size();
 
            integer limitNum = MAX_RECORD_NUM - assetSize;
            String notSelectedAssetSql = this.makeSoqlconfim();
            notSelectedAssetSql += ' and id not in (SELECT Asset__c FROM Maintenance_Contract_Asset__c WHERE Maintenance_Contract__c =\'' + this.targetContractId + '\') ';
                        
            notSelectedAssetSql += ' ORDER BY Department_Name__c, Posting_Date__c, SerialNumber ';
            notSelectedAssetSql += ' limit  :limitNum';
 
            notSelectedAssetRecords = Database.query(notSelectedAssetSql);
            assetRecords.addAll(selectAssetRecords);
            assetRecords.addAll(notSelectedAssetRecords);
            
            
        
        
        
           
 
            system.debug('assetRecords123456789' + assetRecords.size());
        }
        assetRecords = this.markAsset(assetRecords);
    /*
     // 選択済みの納入機器情報を取得
        this.selectedAsset = [SELECT Id, Name, Check_object__c, Maintenance_Contract__c, LastMContract__c, Asset__c FROM Maintenance_Contract_Asset__c WHERE Maintenance_Contract__c = :this.targetContractId];
        system.debug('selectedAsset==========>'+selectedAsset);
        //Maintenance_Contract_Asset_Estimate__c
        this.selectedAsset2 = [SELECT Id, Name,Product_Manual__c,Product_Manual__r.MDM_Model_No__c, Check_object__c,Maintenance_Contract_Estimate__r.Maintenance_Contract__c,Asset__c,Asset__r.product2Id 
        FROM Maintenance_Contract_Asset_Estimate__c WHERE Maintenance_Contract_Estimate__r.Maintenance_Contract__c = :this.targetContractId];
        system.debug('selectedAsset2==========>'+selectedAsset2);
        //SELECT Id, Name, Check_object__c, Asset__c FROM Maintenance_Contract_Asset_Estimate__c WHERE     Maintenance_Contract_Estimate__r.Maintenance_Contract__c = 'a0H1m000002shhL'
        // 選択済みのものにチェックを付ける
        Boolean selected = false;
        for ( Asset local  : assetRecords) {
            selected = false;
            local.Remarks__c = null;
            local.TransferToOther__c = null;
            // local.Freeze_sign__c = false;
            for ( Maintenance_Contract_Asset__c selectedLocal : this.selectedAsset) {
                if ( local.Id == selectedLocal.Asset__c) {
                    local.CheckBox__c = true;
                    local.Remarks__c = selectedLocal.LastMContract__c;
                    local.TransferToOther__c = selectedLocal.Check_object__c;
                    //占用一个复选框字段用于展示“点检对象”
                    // fxk 2021/9/17 点检对象临时用 star
                    // local.Freeze_sign__c = selectedLocal.Check_object__c;
                    // fxk 2021/9/17 点检对象临时用 end
                    selected = true;
                    break;
                }
            }
            for(Maintenance_Contract_Asset_Estimate__c selectedLocal : this.selectedAsset2){
                if(local.MDM_Model_No__c == selectedLocal.Product_Manual__r.MDM_Model_No__c){
                    //local.TransferToOther__c = true;
                    local.TransferToOther__c = selectedLocal.Check_object__c;
                    system.debug('TransferToOther__c============>'+local.TransferToOther__c);
                }
                
            }
            if ( selected == true) {
                continue;
            }
        }
        // List<Asset> assetRecordsv = new List<Asset>(); 
        // for(Asset local : assetRecords){
        //      local.Internal_Asset_photo__c = false;
        //      for(Maintenance_Contract_Asset_Estimate__c equipment : this.selectedAsset2){
        //         if(local.Id == equipment.Maintenance_Contract_Estimate__r.Maintenance_Contract__c){
        //             local.Internal_Asset_photo__c = equipment.Check_object__c;
        //         }
        //     }
        //     assetRecordsv.add(local);
        // }
    */
    //zzm 230831增加检索条件解决数据超量报错的问题 end  
        this.sortKey = '0';
        this.preSortKey = '0';
        this.sortOrderAsc = true;
        this.sortOrder = new String[6];
        this.sortOrder = new String[] { '↓', ' ', ' ', ' ', ' ', ' ',' '};
        
        
        this.cutListSize(assetRecords);
    }
   
 
    //private void cutListSize() {//20191220 modify
    private void cutListSize(List<Asset> assetRecordsv) {
        this.assetLists = new List<List<Asset>>();
        List<Asset> tempList = new List<Asset>();
        //for (Integer i = 0; i < this.assetRecords.size(); i++) {//20191220 modify
        for (Integer i = 0; i < assetRecordsv.size(); i++) {
            //Asset a = this.assetRecords.get(i);//20191220 modify
            Asset a = assetRecordsv.get(i);
            if (Math.mod(i, 1000) == 0) {
                if ( tempList.size() > 0) {
                    assetLists.add(tempList);
                }
                tempList = new List<Asset>();
            }
            tempList.add(a);
        }
        if (tempList.size() > 0) {
            this.assetLists.add(tempList);
        }
 
        //this.assetRecords.clear()//20191220 modify
        assetRecordsv.clear();
    }
 
    //private void mergeList() {//20191220 modify
    private List<Asset> mergeList() {
        List<Asset> assetRecords  = new List<Asset>();//20191220 add
        Integer listSize = this.assetLists.size();
        if (listSize == 1) {
            assetRecords.addAll(this.assetLists.get(0));
        } else {
            for (Integer i = 0; i < listSize; i++) {
                assetRecords.addAll(this.assetLists.get(i));
            }
        }
        return assetRecords;//20191220 add
    }
 
    /**
     * Visaulforceから呼ばれるコンストラクタです。
     */
    public SelectAssetExtension( ApexPages.StandardController controller) {
        this.targetContractId = (String)(ApexPages.currentPage().getParameters().get( 'targetContractId'));
        this.init();
    }
 
    /**
     * 保存メソッドです。
     */
    public void save() { //20231026 zzm 
        // Map<String,Boolean> mCAssetEstMap = new Map<String,Boolean>();
        // List<Maintenance_Contract_Asset_Estimate__c> mCAssetEstList = [select Id, Check_Object__c, Maintenance_Contract_Estimate__c, Product_Manual__r.Name 
        //                                                                 from Maintenance_Contract_Asset_Estimate__c 
        //                                                                 where Check_Object__c = true and Maintenance_Contract_Estimate__r.Estimation_Decision__c = true 
        //                                                                 and Maintenance_Contract_Estimate__r.Maintenance_Contract__c =: targetContractId ];
        // for(Maintenance_Contract_Asset_Estimate__c mCAssetEstinfo : mCAssetEstList){
        //     mCAssetEstMap.put(mCAssetEstinfo.Product_Manual__r.Name, mCAssetEstinfo.Check_Object__c);
        // }
        //this.mergeList();//20191220 modify
        List<Asset> assetRecords  = new List<Asset>();//20191220 add
        assetRecords = this.mergeList();
        List<Maintenance_Contract_Asset__c> insertTarget = new List<Maintenance_Contract_Asset__c>();
        Maintenance_Contract_Asset__c target = null;
        for ( Asset input : assetRecords) {
            if ( input.CheckBox__c == true) {
                target = new Maintenance_Contract_Asset__c();
                target.Maintenance_Contract__c = this.targetContractId;
                target.Asset__c = input.Id;
                target.LastMContract__c = input.Remarks__c;
                target.Check_object__c = input.TransferToOther__c;
                // fxk 2021/9/17 点检对象临时用 star
                // target.Check_object__c = input.Freeze_sign__c;
                // fxk 2021/9/17 点检对象临时用 end
                insertTarget.add( target);
            }
        }
 
        // delete and insertする
        if ( this.selectedAsset.size() > 0) {
            delete selectedAsset;
        }
        if ( insertTarget.size() > 0) {
            insert insertTarget;
        }
        // system.debug('insertTarget=============>'+insertTarget);
        system.debug('insertTarget.size=============>'+insertTarget.size());
    //zzm 20231026 
        // return null;
        // return cancel(); //zzm 20231026 
    }
 
    /**
     * キャンセルメソッドです。
     */
    public PageReference cancel() {
        PageReference ret = null;
        if ( this.targetContractId != null) {
 
            ret = new PageReference( '/' + this.targetContractId);
    // zzm  20231026 start
            ret.setRedirect(true);
            // ret.setRedirectCode(301);
            // aura.redirect(ret);
            system.debug('已进入');
                
        }else{
 
            system.debug('未进入');
    // zzm  20231026 end
        }
 
        return ret;
    }
 
    /**
     * ソートメソッドです。
     */
    public void sortTable() {
 
        System.debug( '-----:sortTable start!!');
        //this.mergeList();//20191220 modify
        List<Asset> assetRecords  = new List<Asset>();//20191220 add
        assetRecords = this.mergeList();
        // check済み退避
        List<Asset> checkedAssets = new List<Asset>();
        for ( Asset local : assetRecords) {
            if ( local.checkBox__c == true) {
                checkedAssets.add( local);
            }
        }
 
        if ( this.sortKey == this.preSortKey) {
            // 方向が変わるのみ
            this.sortOrderAsc = !this.sortOrderAsc;
            this.sortOrder[Integer.valueOf( this.sortKey)] = ( this.sortOrderAsc == true ? '↓' : '↑');
        } else {
            this.sortOrderAsc = true;
            this.sortOrder[Integer.valueOf( this.preSortKey)] = ' ';
            this.sortOrder[Integer.valueOf( this.sortKey)] = ( this.sortOrderAsc == true ? '↓' : '↑');
        }
        this.preSortKey = this.sortKey;
        // HWAG-BHD66X start
        string sqlstr = 'SELECT Id, Name, CheckBox__c,' +
                        'SerialNumber, Department_Name__c, ' +
                        ' Installation_Site__c, Posting_Date__c, ' +
                        'Asset_Owner__c FROM Asset WHERE Hospital__c = \'' +
                        this.targetHospitalId +
                        '\' AND ( AssetMark__c != \'耗材\' OR Product2.Family != \'ET\' )' +
                        ' ORDER BY ' + this.columus[Integer.valueOf(this.sortKey)]
                        + ' ' + (this.sortOrderAsc == true ?
                                 'ASC NULLS FIRST' : 'DESC NULLS LAST');
        System.debug(sqlstr);
        assetRecords = Database.query(sqlstr);
        // HWAG-BHD66X end
        // 選択済みのものにチェックを付ける
        Boolean selected = false;
        for ( Asset local  : assetRecords) {
            selected = false;
            local.Remarks__c = null;
            for ( Asset selectedLocal : checkedAssets) {
                if ( local.Id == selectedLocal.Id) {
                    local.CheckBox__c = true;
                    local.Remarks__c = selectedLocal.Remarks__c;
 
                    selected = true;
                    break;
                }
            }
            if ( selected == true) {
                continue;
            }
        }
        this.cutListSize(assetRecords);
 
        System.debug( '-----:sortTable end!!');
 
    }
 
    //zzm 230831增加检索条件解决数据超量报错的问题 start
    // 检索按钮
    public PageReference searchBtn() {
 
        List<Asset> assetRecords  = new List<Asset>();//20191220 add
        
        assetRecords = this.mergeList();
        List<String> selectedIds = new List<String>();
        List<Asset> insertTarget = new List<Asset>();
        Maintenance_Contract_Asset__c target = null;
        for ( Asset input : assetRecords) {
            if ( input.CheckBox__c == true) {
                insertTarget.add(input);
                selectedIds.add(input.Id);
            }
        }
        Integer limitNum = MAX_RECORD_NUM - insertTarget.size();
        List<Asset> seachAssetRecords = new List<Asset>();
        String seachAssetSql = this.makeSoqlconfim();
        seachAssetSql += ' and id not in : selectedIds';
        if (String.isNotBlank(text1) && String.isNotBlank(cond1) && String.isNotBlank(val1)) {
            seachAssetSql += makeTextSql(text1, cond1, val1);
        }            
        seachAssetSql += ' ORDER BY Department_Name__c, Posting_Date__c, SerialNumber ';
        seachAssetSql += ' limit :limitNum ';
        seachAssetRecords = Database.query(seachAssetSql);
 
        assetRecords = new List<Asset>();
        assetRecords.addAll(insertTarget);
        assetRecords.addAll(this.markAsset(seachAssetRecords));
        this.cutListSize(assetRecords);
        return null;
    }
    //检索验证
    // private List<Asset> getAssetconfim(String txt, String con, String val) {
    //     String soql = this.makeSoqlconfim();
    //     soql += makeTextSql(txt, con, val);
    //     // system.debug('makeTextSql_soql' + soql);
    //     // if (isSoft) {
    //     //     soql += ' order by ' + this.columus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last ');
    //     // } else {
    //     //     soql += ' order by SerialNumber, Name, Department_Name__c, InstallDate';
    //     // }
    //     // system.debug('====getAssetconfim:' + soql);
    //     return Database.query(soql);
    // }
    // private List<Asset> getAsset(String txt, String con, String val) {
    //     String soql = this.makeSoqlconfim();
    //     soql += makeTextSql(txt, con, val);
    
    //     // if (isSoft) {
    //     //     soql += ' order by ' + this.columus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first' : 'desc nulls last ');
    //     // } else {
    //     //     soql += ' order by SerialNumber, Name, Department_Name__c, InstallDate';
    //     // }
    //     // soql += ' limit ' + System.Label.Asset_Maxcount;
    //     // soql += ' OFFSET ' + (countorder - 1) * Integer.valueOf(System.Label.Asset_Maxcount);
    //     return Database.query(soql);
    // }
    private String makeSoqlconfim() {
        String sqlStr = 'SELECT Id, Name, CheckBox__c, SerialNumber,TransferToOther__c,'  
                            + 'Department_Name__c, Installation_Site__c, Posting_Date__c,'
                            + 'Asset_Owner__c, Product2Id'
                            +', Remarks__c,MDM_Model_No__c,Product2.Asset_Model_No__c'
                            +' FROM Asset'
                            +' WHERE Hospital__c =\'' + this.targetHospitalId + '\' '
                            +' AND Status != \'廃棄\''
                            +' AND Status != \'待报废 \''
                            +' AND (Competitor_Name__c = \'奥林巴斯\' OR Competitor_Name__c = \'\' OR Competitor_Name__c = \'其他\')'
                            +' AND Category1__c != \'ET \''
                            +' AND (Category1__c != \'SP\' OR Category2__c != \'附属品\' )'
                            +' AND (Category1__c != \'GI\' OR Category2__c != \'附属品\' OR Category4__c != \'OER\' )'
                            +' AND (Category1__c != \'GI\' OR Category2__c != \'其他\' )'
                            +' AND (Category1__c != \'ENG\' OR Category2__c != \'附属品\' )'
                            +' AND (Category1__c != \'ENG\' OR Category2__c != \'耗材\' )'
                            +' AND ( AssetMark__c != \'耗材\' OR Product2.Family != \'ET\' ) ' ;
        return sqlstr;
    }
    // 拼接检索条件sql文
    private String makeTextSql(String txt1, String con, String val) {
        String soql = '';
        if (String.isBlank(con)) {
            con = 'equals';
        }
        // containsの場合、日報画面の病院検索を真似し、spaceで分けて、and検索
        // equalsの場合、SF標準の検索を真似し、「,」で分けて、or検索
        if (!String.isBlank(txt1)) {
            if ((con == 'contains' || con == 'notcontains') && val.contains(' ')) {
                String[] vals = val.split(' ');
    
                String cSql = '';
                if (vals.size() > 0) {
                    String txt = txt1.substring(2);
                    soql += ' and ( ';
                    for (String v : vals) {
                        if (String.isNotBlank(v)) {
                            if (con == 'contains') {
                                soql += txt + ' like \'%' + v + '%\' or ';
                            } else {
                                soql += txt + ' not like \'%' + v + '%\' and ';
                            }
                        }
    
    
                    }
                    soql = soql.substring(0, soql.length() - 4);
                    soql += ')';
                }
                system.debug('containssoql:     ' + soql);
            } else if ((con == 'equals' || con == 'notequals') && val.contains(',')) {
                String[] vals = val.split(',');
                if (vals.size() > 0) {
                    String txt = txt1.substring(2);                 // S:Name 、最初の2文字がタイプです
                    soql += ' and ( ';
                    for (String v : vals) {
                        if (con == 'equals') {
                            soql += txt + ' = \'' + v + '\' or ';
                        } else {
                            // notequals
                            soql += txt + ' <> \'' + v + '\' and ';
                        }
                    }
                    soql = soql.substring(0, soql.length() - 4);
                    soql += ')';
                }
            } else {
                String cSql = this.makeTextSqlStr(txt1, con, val);
                if (con != 'notcontains') {
                    soql += this.makeTextSqlStr(txt1, con, val);
                } else {
                    // notcontains
                    if (!String.isBlank(cSql)) {
                        cSql = cSql.substring(5);                 // ' and ' の5文字を外す
                        soql += ' and (NOT ' + cSql + ') ';
                    }
                }
            }
        }
        // //JZHG-BSDUT4 ---20200825---update By rentongxiao---Start
        // else{
        //     soql += 'And AssetMark__c = \'主机\'';
        // }
        // //JZHG-BSDUT4 ---20200825---update By rentongxiao---End
        return soql;
    }
    private String makeTextSqlStr(String txt1, String con, String val) {
        String soql = '';
        if (!String.isBlank(txt1)) {
            String txt = txt1.substring(2);
            String colType = txt1.substring(0, 2);
            String tmpVal = val.trim();
            // 空白の場合''にする
            if (String.isBlank(tmpVal)) {
                if (con == 'equals') {
                    //soql += ' and ' + txt + ' = ' + tmpVal;
                    soql += ' and ' + txt + ' = null';
                } else if (con == 'notequals') {
                    soql += ' and ' + txt + ' <> null';
                } else {
                    // 空白の場合、contains, notcontains と starts withは無視
                }
            } else {
                soql += ' and ' + txt;
                if (con == 'equals') {
                    if (colType == 'S:') {
                        soql += ' = \'' + tmpVal + '\'';
                    } else {
                        soql += ' = ' + tmpVal + ' ';
                    }
                } else if (con == 'notequals') {
                    if (colType == 'S:') {
                        soql += ' <> \'' + tmpVal + '\'';
                    } else {
                        soql += ' <> ' + tmpVal + ' ';
                    }
                } else if (con == 'contains' || con == 'notcontains') {
                    soql += ' like \'%' + String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) + '%\'';
                } else if (con == 'starts with') {
                    soql += ' like \'' + String.escapeSingleQuotes(tmpVal.replaceAll('%', '\\%')) + '%\'';
                } else {
                    if (colType == 'S:') {
                        soql += ' ' + con + '\'' + tmpVal + '\'';
                    } else {
                        soql += ' ' + con + ' ' + tmpVal + ' ';
                    }
                }
            }
        }
        return soql;
    }
     private List<Asset> markAsset(List<Asset> allAsset) {
         // 選択済みの納入機器情報を取得
        this.selectedAsset = [SELECT Id, Name, Check_object__c, Maintenance_Contract__c, LastMContract__c, Asset__c FROM Maintenance_Contract_Asset__c WHERE Maintenance_Contract__c = :this.targetContractId];
        system.debug('selectedAsset==========>'+selectedAsset);
        //Maintenance_Contract_Asset_Estimate__c
        this.selectedAsset2 = [SELECT Id, Name,Product_Manual__c,Product_Manual__r.MDM_Model_No__c,Product_Manual__r.Asset_Model_No__c, Check_object__c,Maintenance_Contract_Estimate__r.Maintenance_Contract__c,Asset__c,Asset__r.product2Id 
        FROM Maintenance_Contract_Asset_Estimate__c WHERE Maintenance_Contract_Estimate__r.Maintenance_Contract__c = :this.targetContractId];
        system.debug('selectedAsset2==========>'+selectedAsset2);
        //SELECT Id, Name, Check_object__c, Asset__c FROM Maintenance_Contract_Asset_Estimate__c WHERE  Maintenance_Contract_Estimate__r.Maintenance_Contract__c = 'a0H1m000002shhL'
        // 選択済みのものにチェックを付ける
        Boolean selected = false;
        for ( Asset local  : allAsset) {
            selected = false;
            local.Remarks__c = null;
            local.TransferToOther__c = null;
            // local.Freeze_sign__c = false;
            for ( Maintenance_Contract_Asset__c selectedLocal : this.selectedAsset) {
                if ( local.Id == selectedLocal.Asset__c) {
                    local.CheckBox__c = true;
                    local.Remarks__c = selectedLocal.LastMContract__c;
                    local.TransferToOther__c = selectedLocal.Check_object__c;
                    //占用一个复选框字段用于展示“点检对象”
                    // fxk 2021/9/17 点检对象临时用 star
                    // local.Freeze_sign__c = selectedLocal.Check_object__c;
                    // fxk 2021/9/17 点检对象临时用 end
                    selected = true;
                    break;
                }
            }
            for(Maintenance_Contract_Asset_Estimate__c selectedLocal : this.selectedAsset2){
                if(local.MDM_Model_No__c == selectedLocal.Product_Manual__r.MDM_Model_No__c){
                    //local.TransferToOther__c = true;
                    local.TransferToOther__c = selectedLocal.Check_object__c;
                    system.debug('TransferToOther__c============>'+local.TransferToOther__c);
 
                 //zzm 230908 start    MDM_Model_No__c 匹配不上的话,再用Asset_Model_No__c 匹配一下
                } else if(local.Product2.Asset_Model_No__c == selectedLocal.Product_Manual__r.Asset_Model_No__c){
                    local.TransferToOther__c = selectedLocal.Check_object__c;
                }
                //zzm 230908 end MDM_Model_No__c 匹配不上的话,再用Asset_Model_No__c 匹配一下
                
            }
            if ( selected == true) {
                continue;
            }
        }
        return allAsset;
    }
    //zzm 230831增加检索条件解决数据超量报错的问题 end
 
 
   
}