buli
2023-05-23 07390e2fcb4adf27c928335bf27ae7939c5a80ad
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
/**
 * 一覧共通component用、CreateRelationListPagingCtrlBase と一緒に使う
 * https://developer.salesforce.com/page/Controller_Component_Communication
 */
public without sharing class CreateRelationListPagingCmpCtrl {
 
    public CreateRelationListPagingCtrlBase pageController {
        get;
        set {
            System.debug('SSSSSSSSSSSSSSSSS: setPageController start');
            if (value!= null) {
                pageController = value;
                pageController.setComponentController(this);
            }
            System.debug('SSSSSSSSSSSSSSSSS: setPageController end');
        }
    }
    // 一覧ページにチェックボックスがあるか (compnent の param)
    public Integer bottomSp {get; set;}
    public Boolean hasChkBox { get; set; }
    public Boolean noSortHeader { get; set; }
    public Boolean isRadioBox { get; set; }
    public String  tabS {get; set;}
    public Boolean userCustomPaging {get; set;}
    public Boolean isNeedCheckEvent {
        get {
            return pageController.isNeedCheckEvent;
        }
        set;
    }
 
    // ページングを表示かどうか
    public Boolean isDisplayPaging { get; set; }
    public Integer page { get; set; }         // current page
    public Integer maxPage { get; set; }
    // 総件数
    public Integer recordAllCount { get; set; } // private
    // 当然ページに件数
    public Integer currentPageRecordCnt { get; set; } // private
    public Boolean hasPrevious { get; set; }
    public Boolean hasNext { get; set; }
    public Boolean canGoPage { get; set; } // getSearchNumMax >2000 の場合 goPageInt を非表示すること
    public List<SelectOption> pageNumList {
        get {
            pageNumList = new List<SelectOption>();
            for (Integer pi = 1; pi < maxPage+1; pi++) {
                pageNumList.add(new SelectOption(String.valueOf(pi), String.valueOf(pi)));
            }
            return pageNumList;
        } private set; }   // TODO ほしいのは、 << < ... 5,6,7 ... > >> がベストすが、一応そのまま
    public Integer goPageInt { get; set; }          // TODO wwf getSearchNumMax >2000 の場合 goPageInt を非表示すること
    // OFFSET句で使用可能な最大値
    public static final Integer OFFSET_LIMIT = 2000;
 
    // ページレイアウトの情報を取得
    private Map<String, String> DESC_RW = null;
 
    // FIXME where のcacheは? CmpCtrlの属性のはず
    /*****************ソートキー******************/
    public Object sort1stValue { get; set; }
    public Object sortLastValue { get; set; }
    public Object sort1stId { get; set; }
    public Object sortLastId { get; set; }
    public String sortKey { get; set; }
    public String preSortKey { get; set; }
    public Boolean sortOrderAsc { get; set; }
    public String[] sortOrder { get; set; }                 // TODO sortOrderLeft と sortOrderRight
    public String[] columus = new String[]{};
    public Set<String> columusSet = new Set<String>();
 
    // 项目set 字段标签
    public List<String> titleLeft { get; private set; }
    public List<String> titleRight { get; private set; }
    // 项目set 字段名
    public List<List<String>> columnsLeftApi { get; private set; }         // 参照項目用
    public List<List<String>> columnsRightApi { get; private set; }        // 参照項目用
    public List<String> columnsHiddenApi { get; private set; }              // 一階層のみ
    public List<String> columnLeftCss { get; private set; }               // css 用(もとはapi名)
    public List<String> columnRightCss { get; private set; }              // css 用(もとはapi名)
    public Map<String, String> columnLeftRW { get; private set; }              // r,w,wm用
    public Map<String, String> columnRightRW { get; private set; }             // r,w,wm用
    public String strColumus { get; private set; }             // Soqlに検索対応項目
 
    public Boolean isFirstRefresh { get; private set;}              // 1回目かどうか
 
    public Schema.Sobjecttype sObjType;
 
    //need add remote site flg
    public Boolean MetadataConnectionWarning {get;set;}
 
    public CreateRelationListPagingCmpCtrl() {
        System.debug('SSSSSSSSSSSSSSSSS: CreateRelationListPagingCmpCtrl start');
        isFirstRefresh = true;
        canGoPage = true;
        page = 1;
        maxPage = 1;
        recordAllCount = 0;
        System.debug('SSSSSSSSSSSSSSSSS: CreateRelationListPagingCmpCtrl end');
    }
 
    public void init() {
        System.debug('SSSSSSSSSSSSSSSSS: CreateRelationListPagingCmpCtrl.init start');
        MetadataConnectionWarning = false;
        if(String.isBlank(pageController.parentId)){
            pageController.isNeedSearchFirst = true;
            isFirstRefresh = false;
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, 'パラメータ:Id必须指定'));
            return;
        }
        if(String.isBlank(pageController.getRecordTypeId() )){
            try {
                Map<String, Map<String, String>> editLayoutItemRWMap = SoapApi.getEditLayoutItemRW(pageController.getObjName(), null);
                if(editLayoutItemRWMap.size() >0){
                    DESC_RW = editLayoutItemRWMap.values()[0];
                }
            }  catch (Exception e) {
                if (e.getMessage().contains('Remote site settings')) {
                    MetadataConnectionWarning = true;
                    return ;
                } else {
                    throw e;
                }
            }
        }else{
            try {
                DESC_RW = SoapApi.getEditLayoutItemRW(pageController.getObjName(), new String[]{pageController.getRecordTypeId()}).get(pageController.getRecordTypeId());
            }  catch (Exception e) {
                if (e.getMessage().contains('Remote site settings')) {
                    MetadataConnectionWarning = true;
                    return ;
                } else {
                    throw e;
                }
            }
        }
 
        if(String.isNotBlank(pageController.getObjName())){
            sObjType = (Schema.Sobjecttype) Schema.getGlobalDescribe().get(pageController.getObjName());
        }else{
            // TODO error
        }
 
        //FieldSetより画面中出す項目を設定する
        setLayoutRWInfo();
        getSelectedDataInfo();
 
        //検索結果を取得する
        searchAndPaging();
 
        if (String.isNotBlank(String.valueOf(pageController.getSearchNumMax()))
                    && pageController.getSearchNumMax() > OFFSET_LIMIT) {
            canGoPage = false; //goPage表示しない
        }
 
 
        System.debug('SSSSSSSSSSSSSSSSS: CreateRelationListPagingCmpCtrl.init end');
        return ;
    }
 
    /* FieldSetより画面中出す項目を設定する*/
    // FIXME 一回だけ呼べばいいのはず、途中fieldset変更した場合、画面を閉じれるOKじゃない?
    private void setLayoutRWInfo() {
        system.debug('●●●●● objName ' + pageController.getObjName());
        system.debug('●●●●● getSqlWhereStr() ' + pageController.sqlWhereStr);
        system.debug('●●●●● getColumnLeftFieldSetName() ' + pageController.getColumnLeftFieldSetName());
        system.debug('●●●●● getColumnRightFieldSetName() ' + pageController.getColumnRightFieldSetName());
        if (this.sortOrder == null) {
 
            try {
                // 获得项目set
                // FIXME エラー catch
                Map<String, Schema.FieldSet> fsMap = Schema.getGlobalDescribe().get(pageController.getObjName()).getDescribe().fieldSets.getMap();
                // 左 固定
                Schema.FieldSet fs = fsMap.get(pageController.getColumnLeftFieldSetName());
                system.debug('●●●●● fs ' + fs);
                // 获得项目set中的所有项目
                List<FieldSetMember> fsmList = new List<FieldSetMember>();
                if(fs!=null){
                    fsmList = fs.getFields();
                }
                // 获得字段标签和字段名
                titleLeft = new List<String>();
                List<String> columnLeft = new List<String>();
                columnLeftCss = new List<String>();
                columnsLeftApi = new List<List<String>>();
                columnLeftRW = new Map<String, String>();
                for (FieldSetMember fsm : fsmList) {
                    titleLeft.add(fsm.getLabel());
                    columnLeft.add(fsm.getFieldPath());
                    List<String> splitFieldPath = fsm.getFieldPath().split('\\.');
                    columnsLeftApi.add(splitFieldPath);
                    if (DESC_RW == null) {
                        columnLeftRW.put(fsm.getFieldPath(), 'r');
                    } else if (splitFieldPath.size() == 1) {
                        String rw = DESC_RW.get(fsm.getFieldPath());
                        if (rw != null) {
                            columnLeftRW.put(fsm.getFieldPath(), rw);
                        } else {
                            columnLeftRW.put(fsm.getFieldPath(), 'r');
                        }
                    } else {
                        columnLeftRW.put(fsm.getFieldPath(), 'r');
                    }
                }
                for (String s : columnLeft) {
                    if (columusSet.contains(s) == false) {
                        columus.add(s);
                        columusSet.add(s);
                    }
                    columnLeftCss.add(s.replace('.','_'));
                }
                fs = fsMap.get(pageController.getColumnRightFieldSetName());
                // 获得项目set中的所有项目
                fsmList = fs.getFields();
                // 获得字段标签和字段名
                titleRight = new List<String>();
                List<String> columnRight = new List<String>();
                columnRightCss = new List<String>();
                columnsRightApi = new List<List<String>>();
                columnRightRW = new Map<String, String>();
                for (FieldSetMember fsm : fsmList) {
                    titleRight.add(fsm.getLabel());
                    columnRight.add(fsm.getFieldPath());
                    List<String> splitFieldPath = fsm.getFieldPath().split('\\.');
                    columnsRightApi.add(splitFieldPath);
                    if (DESC_RW == null) {
                        columnRightRW.put(fsm.getFieldPath(), 'r');
                    } else if (splitFieldPath.size() == 1) {
                        String rw = DESC_RW.get(fsm.getFieldPath());
                        if (rw != null) {
                            columnRightRW.put(fsm.getFieldPath(), rw);
                        } else {
                            columnRightRW.put(fsm.getFieldPath(), 'r');
                        }
                    } else {
                        columnRightRW.put(fsm.getFieldPath(), 'r');
                    }
                }
                for (String wField : pageController.getWritableColumnFieldList()) {
                    system.debug('●●●●● wField:' + columnRightRW.get(wField));
                    if (columnRightRW.containsKey(wField) && columnRightRW.get(wField) == 'r') {
                        columnRightRW.put(wField, 'w');
                    }
                }
                for (String s : columnRight) {
                    if (columusSet.contains(s) == false) {
                        columus.add(s);
                        columusSet.add(s);
                    }
                    columnRightCss.add(s.replace('.','_'));
                }
 
                strColumus = String.join(columus, ',');
 
                // 获得 additionalInfoMap 字段
                columnsHiddenApi = new List<String>();
                for (String colname : pageController.getHiddenFieldList()) {
                    if (!columusSet.contains(colname)) {
                        strColumus += ',' + colname;
                    }
                    columnsHiddenApi.add(colname);
                }
                // strColumus 里加 field
                for (String colname : pageController.getColumnFieldList()) {
                    if (!columusSet.contains(colname)) {
                        strColumus += ',' + colname;
                    }
                }
                if (!String.isBlank(pageController.getFKColumnField())
                        && !columusSet.contains(pageController.getFKColumnField())) {
                    strColumus += ',' + pageController.getFKColumnField();
                }
 
                if (String.isNotBlank(pageController.getWidth0Field())) {
                    String firstOrder = pageController.getWidth0Field();
                    if (!columus.contains(firstOrder)) {
                        columus.add(firstOrder);
                        this.sortKey = String.valueOf(columus.size() - 1);
                    } else {
                        for (Integer i = 0; i < columus.size(); i++) {
                            if (columus[i] == firstOrder) {
                                this.sortKey = String.valueOf(i);
                                break;
                            }
                        }
                    }
                }
 
                // FIXME2 ここからしたのロジックなにか意味ありますか? このメソッドは更新権限とクエリ項目作成用
                this.sortOrderAsc = true;
                this.sortOrder = new String[columus.size()];   // TODO sortOrderLeft と sortOrderRight
                for (Integer i = 0; i < columus.size(); i++) this.sortOrder[i] = ' ';
                system.debug('●●●●● sortOrder ' + sortOrder.size());
 
            }  catch (Exception e) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, e.getMessage()));
            }
        }
    }
 
    public void getSelectedDataInfo() {
        if (!String.isBlank(pageController.getSelectedDataSql())) {
            String soql ='';
            final String soqlStr = 'Select {0} {1} ';
            soql += String.format(soqlStr, new String[] {strColumus , pageController.getSelectedDataSql()});
            system.debug(pageController + 'getSelectedDataInfo soql ' + soql);
            List<sObject> queryList = Database.query(soql);
            pageController.selectedData = queryList;
            pageController.makeSelectedDataInfo();
        }
    }
 
    /* コンポーネントにSoqlを発行して、ページングする*/
    /* Search対象:original sObjType */
    public void searchAndPaging() {
 
        try {
            System.debug('searchAndPaging start!!!');
            system.debug('●●●●● sortKey ' + this.sortKey);
            if (!pageController.getIsNeedRunSearch() || !pageController.isNeedSearchFirst) {
                isFirstRefresh = false;
                pageController.isNeedSearchFirst = true;            // 一回目falseの時、ここで trueになる
                // get selected data
                pageController.setViewList(new List<sObject>());
                currentPageRecordCnt = pageController.viewList.size();
                recordAllCount = currentPageRecordCnt;
                pageController.sqlWhereStr = '';
                return;
            }
 
            isFirstRefresh = false;
            pageController.isNeedSearchFirst = true;
            if (pageController.sqlWhereStr == '') return;
 
            String whereStr = pageController.sqlWhereStr;
            if (!String.isBlank(pageController.getFKColumnField())
                    && pageController.selectedFKIdList != null && pageController.selectedFKIdList.size() > 0) {
                String collegeIdString = '\'';
                collegeIdString += String.join(pageController.selectedFKIdList, '\',\'');
                collegeIdString += '\'';
                //这里会把检索出来数据的ID从soql里面除掉
                whereStr += ' and Id not in (' + collegeIdString + ') ';
            }
 
            Integer offsetLimit = OFFSET_LIMIT;
            if (String.isNotBlank(String.valueOf(pageController.getSearchNumMax()))) {
                offsetLimit = Math.max(pageController.getSearchNumMax(), OFFSET_LIMIT);
            }
            Integer offsetLimitAddOne = offsetLimit + 1;
 
            String soql = this.makeSoql('count()', pageController.getOriginObjName(), whereStr, '', ' LIMIT :offsetLimitAddOne' );
            // FIXME count() と select 2つあるので、transaction startしてください。
            recordAllCount = Database.countQuery(soql);
            if (pageController.getShowRecordCountMSG()) {
                /* ページング*/
                if (recordAllCount > offsetLimit) {
                    final String err2Str = '数据超过 {0} 件,只显示前 {1} 件';
                    String err2 = String.format(err2Str, new String[] {offsetLimit+'', offsetLimit+''});
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, err2));
                    recordAllCount--;
                } else {
                    final String err3Str = '取得了 {0} 条数据';
                    String err3 = String.format(err3Str, new String[] {recordAllCount+''});
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, err3));
                }
            }
 
            Integer pageSize = 0;
            // 画面のパラメータ:件数/ページ
            // FIXME2 ページングいらないページを計算する必要もないー>すべてのCountを取得しなくでもいいでは?→ページ数の表示方を検討要
            if(String.isBlank(pageController.pageSize)){
                pageSize = OFFSET_LIMIT;
                if (String.isNotBlank(String.valueOf(pageController.getSearchNumMax()))) {
                    pageSize = Math.min(pageController.getSearchNumMax(), OFFSET_LIMIT);
                }
                isDisplayPaging = false;
            }else{
                pageSize = Integer.valueOf(pageController.pageSize);
                isDisplayPaging = true;
            }
 
            // 指定可能な最大ページ番号
            Integer offsetMaxPage = (offsetLimit + pageSize - 1) / pageSize + 1;
            maxPage = (recordAllCount - 1) / pageSize + 1;
            // 表示ページの調整
            page = Math.min(Math.min(page, maxPage), offsetMaxPage);
 
            Integer offset = (page - 1) * pageSize;
            hasPrevious = offset > 0;
            hasNext = offset + pageSize < Math.min(recordAllCount, offsetLimit + 1);
 
            String limitClause = ' LIMIT :pageSize OFFSET :offset';
// TODO wwf please check
            if (String.isNotBlank(String.valueOf(pageController.getSearchNumMax()))
                    && pageController.getSearchNumMax() > OFFSET_LIMIT && String.isNotBlank(this.sortKey)) {
                // and sort condition
                Object o_1stValue = this.sort1stValue;
                Object o_LastValue = this.sortLastValue;
                Object o_1stId = this.sort1stId;
                Object o_LastId = this.sortLastId;
 
                if (goPageInt == null && page == 1) {
                    // sort condition 追加なし
                }
                // next page
                else if (page > goPageInt || (goPageInt == null && page > 1)) {
                    limitClause = ' LIMIT :pageSize';
                    if (this.sortOrderAsc == true) {
                        // asc next
                        if (o_LastValue != null) {
                            whereStr += ' and (' + this.columus[Integer.valueOf(this.sortKey)] + ' > :o_LastValue '
                                    + 'or (' + this.columus[Integer.valueOf(this.sortKey)] + ' = :o_LastValue and Id > :o_LastId)'
                                    + ')';
                        } else {
                            whereStr += ' and (' + this.columus[Integer.valueOf(this.sortKey)] + ' <> null '
                                    + 'or (' + this.columus[Integer.valueOf(this.sortKey)] + ' = null and Id > :o_LastId)'
                                    + ')';
                        }
                    } else {
                        // desc next
                        if (o_LastValue != null) {
                            whereStr += ' and (' + this.columus[Integer.valueOf(this.sortKey)] + ' < :o_LastValue '
                                    + 'or (' + this.columus[Integer.valueOf(this.sortKey)] + ' = :o_LastValue and Id < :o_LastId)'
                                    + ')';
                        } else {
                            whereStr += ' and (' + this.columus[Integer.valueOf(this.sortKey)] + ' = null '
                                    + '   and Id < :o_LastId'
                                    + ')';
                        }
                    }
                }
                // prev page
                else if (page < goPageInt) {
                    limitClause = ' LIMIT :pageSize';
                    if (this.sortOrderAsc == true) {
                        // asc prev
                        if (o_1stValue != null) {
                            whereStr += ' and (' + this.columus[Integer.valueOf(this.sortKey)] + ' < :o_1stValue '
                                    + 'or (' + this.columus[Integer.valueOf(this.sortKey)] + ' = :o_1stValue and Id < :o_1stId)'
                                    + ')';
                        } else {
                            whereStr += ' and (' + this.columus[Integer.valueOf(this.sortKey)] + ' = :o_1stValue '
                                    + '   and Id < :o_1stId'
                                    + ')';
                        }
                    } else {
                        // desc prev
                        if (o_1stValue != null) {
                            whereStr += ' and (' + this.columus[Integer.valueOf(this.sortKey)] + ' > :o_1stValue '
                                    + 'or (' + this.columus[Integer.valueOf(this.sortKey)] + ' = :o_1stValue and Id > :o_1stId)'
                                    + ')';
                        } else {
                            whereStr += ' and (' + this.columus[Integer.valueOf(this.sortKey)] + ' <> null '
                                    + 'or (' + this.columus[Integer.valueOf(this.sortKey)] + ' = null and Id > :o_1stId)'
                                    + ')';
                        }
                    }
                }
                // go page
                else {
                    // sort condition 追加なし
                }
            }
 
            String orderStr = ' ';
            if (String.isBlank(this.sortKey)) {
                String ctrlOrderStr = pageController.getOrderbyStr();
                if (String.isBlank(ctrlOrderStr)) {
                    orderStr += 'order by LastModifiedDate desc ';
                } else {
                    orderStr += ctrlOrderStr + ' ';
                }
 
            } else {
                orderStr += 'order by ' + this.columus[Integer.valueOf(this.sortKey)] + ' ' + (this.sortOrderAsc == true ? 'asc nulls first, Id asc' : 'desc nulls last, Id desc') ;
            }
            System.debug('orderStr' + orderStr);
            System.debug('whereStr' + whereStr);
            // ここ getOriginObjColumns して、setViewList() のなか、再度 strColumus より探します。
            if (String.isNotBlank(this.sortKey)) {
                String sortCol = this.columus[Integer.valueOf(this.sortKey)];
                String columsWithSortKey = pageController.getOriginObjColumns();
                if (!columsWithSortKey.contains(sortCol)) {
                    columsWithSortKey += ', ' + sortCol;
                }
                soql = this.makeSoql(columsWithSortKey, pageController.getOriginObjName(), whereStr, orderStr, limitClause );
            } else {
                soql = this.makeSoql(pageController.getOriginObjColumns(), pageController.getOriginObjName(), whereStr, orderStr, limitClause );
            }
            system.debug('●●●●● soql ' + soql);
 
            List<sObject> queryList = Database.query(soql);
            // sort1stValue と sortLastValue
            if (queryList.size() > 0 && String.isNotBlank(this.sortKey)) {
                List<String> sortKeyCols = this.columus[Integer.valueOf(this.sortKey)].split('\\.');
                sort1stValue = CreateRelationListPagingCmpCtrl.getObjectValue(queryList[0], sortKeyCols);
                sort1stId = queryList[0].Id;
                sortLastValue = CreateRelationListPagingCmpCtrl.getObjectValue(queryList[queryList.size() - 1], sortKeyCols);
                sortLastId = queryList[queryList.size() - 1].Id;
            }
 
            pageController.setViewList(queryList);
            currentPageRecordCnt = pageController.viewList.size();
 
system.debug('●●●●● searchAndPaging END ' );
        }  catch (Exception e) {
            System.debug(e.getStackTraceString());
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,e.getMessage()));
        }
    }
 
    public void sortTable() {
        if(String.isNotBlank(pageController.sortKey)){
            this.sortKey = pageController.sortKey;
        }
        String sort_param = ApexPages.currentPage().getParameters().get('sortKey');
        if (String.isNotBlank(sort_param)) {
            this.sortKey = sort_param;
        }
        if (this.sortKey == this.preSortKey) {
            if (String.isBlank(this.sortKey) == false) {
                // 方向が変わるのみ
                this.sortOrderAsc = !this.sortOrderAsc;
                this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓');
            }
        } else {
            this.sortOrderAsc = true;
            if (String.isBlank(this.preSortKey) == false) {
                this.sortOrder[Integer.valueOf(this.preSortKey)] = ' ';
            }
            this.sortOrder[Integer.valueOf(this.sortKey)] = (this.sortOrderAsc == true ? '↑' : '↓');
        }
        this.preSortKey = this.sortKey;
        //FIXME2 200行目による this.sortOrderAsc = true; false になることはない
        //setLayoutRWInfo();
        //getSelectedDataInfo();
        page = 1;
        goPageInt = null;
        searchAndPaging();
        goPageInt = page;
        return;
    }
 
    public static Object getObjectValue(sObject obj, List<String> cols) {
        if (obj == null) return null;
        if (cols.size() == 1) {
            return obj.get(cols[0]);
        } else {
            sObject obj_r = obj.getSObject(cols[0]);
            cols.remove(0);
            return getObjectValue(obj_r, cols);
        }
    }
 
    /* Soql文を作成する*/
    private String makeSoql(String sltStr, String fromObj, String whereStr, String orderStr, String limitStr) {
        String soql ='';
        final String soqlStr = 'Select {0} From {1} {2} {3} {4}  ';
        soql += String.format(soqlStr, new String[] {sltStr
                                        , fromObj
                                        , whereStr
                                        , orderStr
                                        , limitStr});
 
        system.debug(soql);
        return soql;
    }
    public void searchGoPage() {
        try {
            page = goPageInt;
            //setLayoutRWInfo();
            //getSelectedDataInfo();
            searchAndPaging();
        } catch (Exception e) {
            ApexPages.addMessages(e);
        }
 
        return;
    }
    public void searchNext() {
        try {
            page = page + 1;
            //setLayoutRWInfo();
            //getSelectedDataInfo();
            searchAndPaging();
            goPageInt = page;
        } catch (Exception e) {
            ApexPages.addMessages(e);
        }
 
        return;
    }
    public void searchPrevious() {
        try {
            page = page - 1;
            //setLayoutRWInfo();
            //getSelectedDataInfo();
            searchAndPaging();
            goPageInt = page;
        } catch (Exception e) {
            ApexPages.addMessages(e);
        }
        return;
    }
 
    //// assignTo="{!clickLineNo}" より url を組み立てる
    //// TODO rerenderなど
    //public void checkEvent() {
    //    pageController.checkEvent(clickLineNo);
    //}
    @testVisible
    private void testI() {
        Integer i = 0;
        
    }
}