高章伟
2022-03-10 1312ba82d4c880bdb5357d28e0d4af5b285f610f
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
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
/**
 * @param province  省
 * @param salesDpt  本部
 * @param text 項目
 * @param cond 条件
 * @param val  値
 * @param search  値
 * @param t1 d | k
 * @param t2 all | null     全部展开
 * @param ocm 0 | null(1)      是否销售本部
 * @param mk 表示週
 * @param md 表示日
 */
public with sharing class PersonalCalendarController {
    // ユーザー上限
    private static Integer MAX_USER = 200;
    // 翻訳
    public static Map<String, String> at2CnMap;
    static {
        at2CnMap = new Map<String, String>();
        at2CnMap.put('病院', '用户拜访');
        at2CnMap.put('販売店', '经销商支持');
        at2CnMap.put('社内活動', '公司工作');
        at2CnMap.put('社外イベント', '社外会议');
        at2CnMap.put('移動', '移动');
        at2CnMap.put('休暇', '休假');
    }
    public static Map<String, String> mvlCnMap;
    static {
        mvlCnMap = new Map<String, String>();
        mvlCnMap.put('内視鏡室', '内镜室');
        mvlCnMap.put('手術室', '手术室');
        mvlCnMap.put('設備課', '设备科');
        mvlCnMap.put('外来', '门诊');
        mvlCnMap.put('病棟', '病房');
        mvlCnMap.put('その他', '其他');
    }
    public static Map<String, String> purposeCnMap;
    static {
        purposeCnMap = new Map<String, String>();
        purposeCnMap.put('移動', '移动');
        purposeCnMap.put('会議参加', '会议参加');
        purposeCnMap.put('休暇', '休假');
        purposeCnMap.put('点検', '点检');
        purposeCnMap.put('投诉対応(含QIS)', '投诉对应(含QIS)');
        purposeCnMap.put('納品(装机)', '装机');
    }
    private static Boolean isWeek;
    public Boolean getIsWeek() {
        return PersonalCalendarController.isWeek;
    }
    public Boolean t2 { get; set; }
    public Boolean ocmUser { get; set; }
    public Boolean allProvince { get; set; }
 
    // 登陆用户、検索条件に兼用
    public User loginUser { get; set; }
 
    // 本部、中国仕様
    public String salesDpt { get; set; }
    public static List<SelectOption> salesDptOpts  { get; private set; }
    static {
        salesDptOpts = new List<SelectOption>();
        salesDptOpts.add(new SelectOption('','--无--'));
        salesDptOpts.add(new SelectOption('1.华北','1.华北'));
        salesDptOpts.add(new SelectOption('2.东北','2.东北'));
        salesDptOpts.add(new SelectOption('3.西北','3.西北'));
        salesDptOpts.add(new SelectOption('4.西南','4.西南'));
        salesDptOpts.add(new SelectOption('5.华东','5.华东'));
        salesDptOpts.add(new SelectOption('6.华南','6.华南'));
    }
    
    // 省、ユーザの省(在开发报表可以选择)を見る
    public String province { get; set; }
    public List<SelectOption> provinceOpts  { get; private set; }
    
    // 職位のチェックボックス、中国仕様
    String[] postNames = new String[]{};
    public String[] getPostNames() {
        return postNames;
    }
    public void setPostNames(String[] postNames) {
        this.postNames = postNames;
    }
    public static List<SelectOption> postOpts { get; private set; }
    static {
        postOpts = new List<SelectOption>();
        postOpts.add(new SelectOption('一般','一般'));
        postOpts.add(new SelectOption('高级','高级'));
        postOpts.add(new SelectOption('主管','主管'));
        postOpts.add(new SelectOption('副经理','副经理'));
        postOpts.add(new SelectOption('经理','经理'));
        postOpts.add(new SelectOption('副部长','副部长'));
        postOpts.add(new SelectOption('部长','部长'));
    }
 
    // 表示日
    public Date mdDay { get; private set; }
    public String getMdDayFormat() {
        return mdDay.format();
    }
    private Date mdToday; // 今週の場合 mdToday に値をセット
    // 表示範囲の日 yyyy-MM-dd or 時間 HH24
    public static List<String> mdKeyList;
    public static List<Map<String, String>> mdKeyList2 { get; private set; }    // 0indexに User
 
    // 表示ユーザー一覧
    public UserCalendarInfo campaignInfo { get; private set; }
    public Integer getCampaignMaxTr () {
        return campaignInfo.maxTr;
    }
    public List<Id> userIds { get; private set; }
    public Map<Id, UserCalendarInfo> userCalendarInfoMap { get; private set; }
    public static Map<Id, Daily_Report__c> drMap;
    public static Map<Id, Account> evtAccountMap;
    public static Map<Id, Campaign> evtCampaignMap;
 
    // 検索条件
    public static List<SelectOption> textOpts { get; private set; }
    static {
        textOpts = new List<SelectOption>();
        textOpts.add(new SelectOption('','-无-'));
        textOpts.add(new SelectOption('S:Alias', 'User'));
        textOpts.add(new SelectOption('S:Post__c', Schema.SObjectType.User.fields.Post__c.label));
        textOpts.add(new SelectOption('S:Job_Category__c', Schema.SObjectType.User.fields.Job_Category__c.label));
        textOpts.add(new SelectOption('S:Group__c', Schema.SObjectType.User.fields.Group__c.label));
        textOpts.add(new SelectOption('S:Category6__c', Schema.SObjectType.User.fields.Category6__c.label));
        textOpts.add(new SelectOption('S:SP_incharge_staff__c', Schema.SObjectType.User.fields.SP_incharge_staff__c.label));
        textOpts.add(new SelectOption('S:Sales_Speciality__c', Schema.SObjectType.User.fields.Sales_Speciality__c.label));
        textOpts.add(new SelectOption('S:Product_specialist_incharge_product__c', Schema.SObjectType.User.fields.Product_specialist_incharge_product__c.label));
//        textOpts.add(new SelectOption('S:Location', Schema.SObjectType.Event.fields.Location.label));
//        textOpts.add(new SelectOption('S:Subject', Schema.SObjectType.Event.fields.Subject.label));
    }
    public static List<SelectOption> equalOpts { get; private set; }
    static {
        equalOpts = new List<SelectOption>();
        equalOpts.add(new SelectOption('equals','等于'));
        equalOpts.add(new SelectOption('notequals','不等于'));
        equalOpts.add(new SelectOption('contains','包含'));
        equalOpts.add(new SelectOption('notcontains','不包含'));
    }
    public String text1 { get; set; }
    public String cond1 { get; set; }
    public String val1 { get; set; }
    public String searchText { get; set; }
    public static Integer markCnt { get; private set; }
    
    public PersonalCalendarController() {
//        Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8');
        PersonalCalendarController.markCnt = 0;
        evtListsMapMap = new Map<String, Map<String, List<Event>>>();
        evtMarkedMapMap = new Map<String, Map<String, List<Integer>>>();
        searchWordsMapMap = new Map<String, Map<String, List<String>>>();
        whatIdsMapMap = new Map<String, Map<String, List<Id>>>();
        // Dailyの時だけ使う、重ね表示用
        evtsStartMap = new Map<String, List<Long>>();
        evtsEndMap = new Map<String, List<Long>>();
        evtsZMap = new Map<String, List<Integer>>();
        
        provinceOpts = new List<SelectOption>();
        provinceOpts.add(new SelectOption('','--无--'));
    }
 
    // 画面初始化
    public Pagereference init() {
        // 当前用户信息、初期値にする
        if (loginUser == null) {
            loginUser = [Select Id, Salesdepartment__c, Province__c, ProfileId, Job_Category__c, UserRoleId, UserRole.Name, Additional_Role__c, Province_select__c, pe_tab_range__c From User where Id = :Userinfo.getUserId()];
        }
        salesDpt = loginUser.Salesdepartment__c;
        String jobCategory = loginUser.Job_Category__c;
        
        // 省プルダウンを作成、自分の省は選択できる、以外は項目を見る
        province = loginUser.Province__c;
        provinceOpts.add(new SelectOption(province, province));
        if (String.isBlank(loginUser.Province_select__c) == false) {
            for (String pro : loginUser.Province_select__c.split(';', -1)) {
                if (pro != province) {
                    provinceOpts.add(new SelectOption(pro, pro));
                }
            }
        }
 
        PersonalCalendarController.isWeek = true;
        String mkParam = System.currentPageReference().getParameters().get('mk');
        if (String.isBlank(mkParam)) {
            // 现在日
            mdDay = Date.today();
        } else {
            String[] mkParams = mkParam.split('/');
            mdDay = Date.newInstance(Integer.valueOf(mkParams[0]), Integer.valueOf(mkParams[1]), Integer.valueOf(mkParams[2]));
        }
        String mdParam = System.currentPageReference().getParameters().get('md');
        if (String.isBlank(mdParam) == false) {
            PersonalCalendarController.isWeek = false;
            String[] mdParams = mdParam.split('/');
            mdDay = Date.newInstance(Integer.valueOf(mdParams[0]), Integer.valueOf(mdParams[1]), Integer.valueOf(mdParams[2]));
        }
        
        List<Date> mdateKeys = new List<Date>();            // sql用
        PersonalCalendarController.mdKeyList = new List<String>();
        PersonalCalendarController.mdKeyList2 = new List<Map<String, String>>();
        PersonalCalendarController.mdKeyList2.add(new Map<String, String>{'md' => 'User', 'md2' => 'User', 'mdCss' => ''});
        if (PersonalCalendarController.isWeek) {
            // 初始化,週単位
            mdDay = mdDay.toStartofWeek();
            Datetime dt = DateTime.newInstance(mdDay.year(), mdDay.month(), mdDay.day());
            String dayOfWeek = dt.format('EEEE'); //returns Sunday or Monday or ..
            if  (dayOfWeek == 'Monday') {
                mdDay = mdDay.addDays(-1);
            }
            Date weekStart = mdDay;
            for (Integer i = 0; i < 7; i++) {
                mdateKeys.add(weekStart);
                dt = DateTime.newInstance(weekStart.year(), weekStart.month(), weekStart.day());
                PersonalCalendarController.mdKeyList.add(dt.format('yyyy-MM-dd'));
                String mdCss = '';
                if (i == 0) mdCss = ' fc-sun';
                if (i == 1) mdCss = ' fc-mon';
                if (i == 2) mdCss = ' fc-tue';
                if (i == 3) mdCss = ' fc-wed';
                if (i == 4) mdCss = ' fc-thu';
                if (i == 5) mdCss = ' fc-fri';
                if (i == 6) mdCss = ' fc-sat';
                if (weekStart == System.Today()) { mdCss += ' fc-today'; mdToday = System.Today(); }
                PersonalCalendarController.mdKeyList2.add(new Map<String, String>{'md' => dt.format('yyyy-MM-dd'), 'md2' => dt.format('MM/dd'), 'mdCss' => mdCss});
                weekStart = weekStart.addDays(1);
            }
        } else {
            // 初始化,日単位
            mdateKeys.add(mdDay);
            String t2Param = System.currentPageReference().getParameters().get('t2');
            Integer hStart = 7;
            Integer hEnd = 21;
            if (t2Param == 'all') {
                hStart = 0;
                hEnd = 24;
                t2 = true;
            }
            for (Integer i = hStart; i < hEnd; i++) {
                PersonalCalendarController.mdKeyList.add('' + i + ':00');
                PersonalCalendarController.mdKeyList2.add(new Map<String, String>{'md' => '' + i + ':00', 'md2' => '' + i + ':00', 'mdCss' => ''});
            }
        }
        
        Set<Id> roleIds = ControllerUtil.getAllSubRoleIds(loginUser.UserRoleId, loginUser.Additional_Role__c);
        // List<User> userList = [select Id from user where IsActive = true and Test_staff__c = false and UserRoleId in :roleIds];
        List<User> userList = [select Id from user where IsActive = true and Test_staff__c = false and UserType__c != 'PowerCustomerSuccess' and UserRoleId in :roleIds];
        userList.add(loginUser);
        
        // 本部
        String salesDptParam = System.currentPageReference().getParameters().get('salesDpt');
        if (String.isBlank(salesDptParam)) {
            // loginUserの値を使う
        } else {
            salesDpt = salesDptParam;
            loginUser.Province__c = '';
        }
        
        // 20150911 xudan 全部省
        allProvince = true;
        String ap = System.currentPageReference().getParameters().get('ap');
        if (ap == '0') {
            allProvince = false;
        } else if (ap == '1') {
            allProvince = true;
        } else {}
        // 省、省優先
        String provinceParam = System.currentPageReference().getParameters().get('province');
        if (String.isBlank(provinceParam)) {
            // loginUserの値を使う
        } else {
            loginUser.Province__c = provinceParam;
            province = provinceParam;
        }
        if (String.isBlank(loginUser.Province__c) == false) {
            salesDpt = '';
        }
        
        String text0;           // 隠し条件
        String cond0;           // 隠し条件
        String val0;            // 隠し条件
        String value1;          // 隠し条件
        // 20150511 xudan CIC 00154733
        // 職種にて销售市场/销售推广/销售服务/支援の場合には、デフォルトで販売本部のフラグがON。それ以外の場合にはOFF
        ocmUser = false;
        String ocmParam = System.currentPageReference().getParameters().get('ocm');
        if (ocmParam == '0') {
            ocmUser = false;
        } else if (ocmParam == '1') {
            ocmUser = true;
        } else {
            if (jobCategory == '销售推广' || jobCategory == '销售服务' || jobCategory == '销售市场' || jobCategory == '支援') {
                ocmUser = true;
            }
        }
        text1 = System.currentPageReference().getParameters().get('text');
        cond1 = System.currentPageReference().getParameters().get('cond');
        val1 = System.currentPageReference().getParameters().get('val');
        value1 = val1;
        searchText = System.currentPageReference().getParameters().get('search');
//      if (text1 == 'S:Job_Category__c' && cond1 == 'equals') {
//          if (ocmUser) {
//              if (String.isBlank(value1)) {
//                  value1 = '销售推广,销售服务,销售市场,支援';
//              } else {
//                  value1 += ',销售推广,销售服务,销售市场,支援';
//              }
//          }
//      } else {
            if (ocmUser) {
                text0 = 'S:Job_Category__c';
                cond0 = 'equals';
                val0 = '销售推广,销售服务,销售市场,支援';
            }
//      }
        
        List<User> users = new List<User>();
        if (text1 != 'S:Location' && text1 != 'S:Subject') {
            users = this.getUserList(userList, text0, cond0, val0, text1, cond1, value1);
        } else {
            users = this.getUserList(userList, text0, cond0, val0);
        }
        if (users.size() > MAX_USER) {
            Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.INFO, '用户超过' + MAX_USER + '人,请追加条件'));
        }
        userIds = new List<Id>();
        userCalendarInfoMap = new Map<Id, UserCalendarInfo>();
        for (User u : users) {
            userCalendarInfoMap.put(u.Id, new UserCalendarInfo(u.Id, u.Photo_Text__c, u.Alias, u.Job_category_for_calendar__c));
            userIds.add(u.Id);
        }
        
        List<Event> events = new List<Event>();
        List<Id> whatIdsForSearch = new List<Id>();
        List<Id> whatId_csForSearch = new List<Id>();
        events = this.getEventList(mdateKeys, userIds);
        for (Event e : events) {
            if (String.isBlank(e.WhatId) == false) {
                whatIdsForSearch.add(e.WhatId);
            }
            if (String.isBlank(e.WhatId__c) == false) {
                whatId_csForSearch.add(e.WhatId__c);
            }
        }
        // Mark イベント
        PersonalCalendarController.evtAccountMap = new Map<Id, Account>([
                Select Id, Name, Name_for_Daily_Report_text__c, HP_146POCM_Category_From_Dept__c
                  from Account where Id IN :whatId_csForSearch
        ]);
        PersonalCalendarController.evtCampaignMap = new Map<Id, Campaign>([
                Select Id, Name, Name2__c
                  from Campaign where Id IN :whatId_csForSearch
        ]);
        
        for (Event e : events) {
            UserCalendarInfo uci = userCalendarInfoMap.get(e.OwnerId);
            uci.addEvent(e, searchText);
        }
        PersonalCalendarController.drMap = ControllerUtil.reportMapSelectByIds(whatIdsForSearch);
        
        // キャンペーン情報
        campaignInfo = new UserCalendarInfo('0', '', Schema.SObjectType.Campaign.Label, null);
        for (Campaign c :
                [select Id, StartDate, EndDate, RecordType.Name, Name, Name2__c, Society_Type__c, Status
                   from Campaign
                  where Status <> '草案中'
                    and StartDate <=: mdateKeys[mdateKeys.size() - 1]
                    and EndDate >=: mdateKeys[0]
                  order by Society_Type__c, StartDate
                ]
        ) {
            campaignInfo.addCampaign(c);
        }
        return null;
    }
    
    private List<Event> getEventList(List<Date> mdates, List<Id> users) {
        return getEventList(mdates, users, null, null, null);
    }
    
    private List<Event> getEventList(List<Date> mdates, List<Id> users, String txt, String con, String val) {
        String soql = 'select id, ActivityDate, OwnerId, Subject, WhatId__c, Location, Activity_Type2__c, whatId,'
                    + ' StartDateTime, DurationInMinutes, EndDateTime, Main_Visit_Location__c, IsScheduled__c, Purpose_Type__c,'
                    + ' Related_Opportunity1__c, Related_Opportunity1_ID__c, Related_Service1__c, Related_Service1_ID__c'
                    + ' from Event where WS_flg__c = false and ActivityDate IN :mdates and OwnerId IN :users'
                    // 任务事件改善 20210625 Start
                    + ' and EventStatus__c not in (\'04 取消\',\'05 延期\',\'06 关闭\',\'07 未执行\')';
                    // 任务事件改善 20210625 End
        soql += makeTextSql(txt, con, val);
        
        soql += ' order by OwnerId, StartDateTime, DurationInMinutes Desc, id';
        
        system.debug('=====' + soql);
        
        return ControllerUtil.eventSelectByUsers(soql, mdates, users);
    }
    
    private List<User> getUserList(List<User> userList, String txt, String con, String val) {
        return getUserList(userList, txt, con, val, null, null, null);
    }
    // ユーザの検索、TODO public で共通かする?
    private List<User> getUserList(List<User> userList, String txt, String con, String val, String txt1, String con1, String val1) {
        String soql = 'select Id, Photo_Text__c, Salesdepartment__c, Province__c, Alias, Job_Category__c, Job_category_for_calendar__c'
                    + '  from User where Id in :userList and IsActive = true and Test_staff__c = false';
        // 全部省の場合
        if (allProvince == true) {
            List<String> provinces = new List<String>();
            if (String.isBlank(loginUser.Province_select__c) == false) {
                provinces = loginUser.Province_select__c.split(';', -1);
            } else {
                provinces.add(loginUser.Province__c);
            }
            soql += ' and Province__c in :provinces';
        } else {
            // 省を指定したら、本部を見ない
            if (!String.isBlank(loginUser.Province__c)) {
                soql += ' and Province__c = \'' + loginUser.Province__c + '\'';
            }
            else if (!String.isBlank(salesDpt) && salesDpt != '0') {
                soql += ' and Salesdepartment__c = \'' + salesDpt + '\'';
            }
        }
        
        soql += makeTextSql(txt, con, val);
        soql += makeTextSql(txt1, con1, val1);
        
        // 職位条件
//        if (postNames.size() > 0) {
//            soql += ' and (';
//            for (Integer i = 0; i < postNames.size(); i++) {
//                if (i == postNames.size() - 1) {
//                    soql += ' Post__c = \'' + postNames[i] + '\'';
//                } else {
//                    soql += ' Post__c = \'' + postNames[i] + '\' or';
//                }
//            }
//            soql += ')';
//        }
//        soql += ' order by Salesdepartment__c, Province__c, UserRole.Name';
        soql += ' order by Alias limit ' + (MAX_USER + 1);
        
        system.debug('getUserList=====' + soql);
        
        return Database.query(soql);
    }
    
    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 = '';
                for (String v : vals) {
                    cSql += this.makeTextSqlStr(txt1, con, v);
                }
                if (con == 'contains') {
                    soql += cSql;
                } else {
                    // notcontains
                    cSql = cSql.replaceAll(' and ', ') and (NOT ');
                    soql += cSql.substring(1) + ') ';
                }
            } 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 + ') ';
                    }
                }
            }
        }
        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;
            // 空白の場合''にする
            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 \'%' + tmpVal + '%\'';
                } else if (con == 'starts with') {
                    soql += ' like \'' + tmpVal + '%\'';
                } else {
                    if (colType == 'S:') {
                        soql += ' ' + con + '\'' + tmpVal + '\'';
                    } else {
                        soql += ' ' + con + ' ' + tmpVal + ' ';
                    }
                }
            }
        }
        return soql;
    }
    
    // 検索用url
    public String getSearchJsUrl() {
        PageReference pr = System.currentPageReference();
        String orgT = pr.getParameters().get('text');
        String orgC = pr.getParameters().get('cond');
        String orgV = pr.getParameters().get('val');
        String orgH = pr.getParameters().get('search');
        String orgO = pr.getParameters().get('ocm');
        String orgA = pr.getParameters().get('ap');
        pr.getParameters().put('text', null);
        pr.getParameters().put('cond', null);
        pr.getParameters().put('val', null);
        pr.getParameters().put('search', null);
        pr.getParameters().put('ocm', null);
        pr.getParameters().put('ap', null);
        String rtn = pr.getUrl();
        pr.getParameters().put('text', orgT);
        pr.getParameters().put('cond', orgC);
        pr.getParameters().put('val', orgV);
        pr.getParameters().put('search', orgH);
        pr.getParameters().put('ocm', orgO);
        pr.getParameters().put('ap', orgA);
        return rtn;
    }
    // 検索用url
    public String getShowDayAllUrl() {
        PageReference pr = System.currentPageReference();
        String orgT = pr.getParameters().get('t2');
        String orgH = pr.getParameters().get('search');
        pr.getParameters().put('t2', null);
        pr.getParameters().put('search', null);
        String rtn = pr.getUrl();
        pr.getParameters().put('t2', orgT);
        pr.getParameters().put('search', orgH);
        return rtn;
    }
    // 本部と省のURL
    public String getProvinceUrl() {
        PageReference pr = System.currentPageReference();
        String orgP = pr.getParameters().get('province');
        String orgS = pr.getParameters().get('salesDpt');
        String orgA = pr.getParameters().get('ap');
        pr.getParameters().put('province', null);
        pr.getParameters().put('salesDpt', null);
        pr.getParameters().put('ap', null);
        String rtn = pr.getUrl();
        pr.getParameters().put('province', orgP);
        pr.getParameters().put('salesDpt', orgS);
        pr.getParameters().put('ap', orgA);
        return rtn;
    }
    public String getDayViewUrl() {
        PageReference pr = System.currentPageReference();
        String orgD = pr.getParameters().get('md');
        String orgK = pr.getParameters().get('mk');
        String orgH = pr.getParameters().get('search');
        pr.getParameters().put('mk', null);
        pr.getParameters().put('search', null);
        if (mdToday != null) {
            pr.getParameters().put('md', mdToday.format());
        } else {
            pr.getParameters().put('md', mdDay.format());
        }
        String rtn = pr.getUrl();
        pr.getParameters().put('md', orgD);
        pr.getParameters().put('mk', orgK);
        pr.getParameters().put('search', orgH);
        return rtn;
    }
    public String getWeekViewUrl() {
        PageReference pr = System.currentPageReference();
        String orgD = pr.getParameters().get('md');
        String orgK = pr.getParameters().get('mk');
        String orgH = pr.getParameters().get('search');
        pr.getParameters().put('md', null);
        pr.getParameters().put('mk', mdDay.format());
        pr.getParameters().put('search', null);
        String rtn = pr.getUrl();
        pr.getParameters().put('md', orgD);
        pr.getParameters().put('mk', orgK);
        pr.getParameters().put('search', orgH);
        return rtn;
    }
    public String getChangeDayUrl() {
        PageReference pr = System.currentPageReference();
        String orgD = pr.getParameters().get('md');
        String orgK = pr.getParameters().get('mk');
        String orgH = pr.getParameters().get('search');
        pr.getParameters().put('md', null);
        pr.getParameters().put('mk', null);
        pr.getParameters().put('search', null);
        String rtn = pr.getUrl();
        pr.getParameters().put('md', orgD);
        pr.getParameters().put('mk', orgK);
        pr.getParameters().put('search', orgH);
        return rtn;
    }
    public String getPrevUrl() {
        PageReference pr = System.currentPageReference();
        String orgD = pr.getParameters().get('md');
        String orgK = pr.getParameters().get('mk');
        String orgH = pr.getParameters().get('search');
        if (PersonalCalendarController.isWeek) {
            pr.getParameters().put('mk', mdDay.addDays(-7).format());
            pr.getParameters().put('md', null);
        } else {
            pr.getParameters().put('mk', null);
            pr.getParameters().put('md', mdDay.addDays(-1).format());
        }
        pr.getParameters().put('search', null);
        String rtn = pr.getUrl();
        pr.getParameters().put('md', orgD);
        pr.getParameters().put('mk', orgK);
        pr.getParameters().put('search', orgH);
        return rtn;
    }
    public String getNextUrl() {
        PageReference pr = System.currentPageReference();
        String orgD = pr.getParameters().get('md');
        String orgK = pr.getParameters().get('mk');
        String orgH = pr.getParameters().get('search');
        if (PersonalCalendarController.isWeek) {
            pr.getParameters().put('mk', mdDay.addDays(7).format());
            pr.getParameters().put('md', null);
        } else {
            pr.getParameters().put('mk', null);
            pr.getParameters().put('md', mdDay.addDays(1).format());
        }
        pr.getParameters().put('search', null);
        String rtn = pr.getUrl();
        pr.getParameters().put('md', orgD);
        pr.getParameters().put('mk', orgK);
        pr.getParameters().put('search', orgH);
        return rtn;
    }
 
    // {ユーザーId単位 => {md2 => [XXX]}}
    public static Map<String, Map<String, List<Event>>> evtListsMapMap;
    public static Map<String, Map<String, List<Integer>>> evtMarkedMapMap;
    public static Map<String, Map<String, List<String>>> searchWordsMapMap;
    public static Map<String, Map<String, List<Id>>> whatIdsMapMap;     // getMdKeyList3 専用
    // Dailyの時だけ使う、重ね表示用
    public static Map<String, List<Long>> evtsStartMap;
    public static Map<String, List<Long>> evtsEndMap;
    public static Map<String, List<Integer>> evtsZMap;
 
    /**
     * 1人1つインスタンス
     */
    class UserCalendarInfo {
        public String userId { get; private set; }
        public String Photo_Text { get; private set; }
        public String userAlias { get; private set; }
        public String userDesc { get; private set; }
        // ユーザー毎、一週間のうち日の最大のエベント数
        public Integer maxTr { get; private set; }      // 1つセルに最大Event数
        
        // Innerで使うprivate method
        private String at2Css(String at2) {
            String at2Css = 'fc-event';     // default
            if (at2 == '用户拜访') { at2Css = 'fc-eventH'; }
            else if (at2 == '经销商支持') { at2Css = 'fc-eventA'; }
            else if (at2 == '公司工作') { at2Css = 'fc-eventI'; }
            else if (at2 == '社外会议') { at2Css = 'fc-eventC'; }
            else if (at2 == '移动') { at2Css = 'fc-eventM'; }
            else if (at2 == '休假') { at2Css = 'fc-eventY'; }
            return at2Css;
        }
        
        // 訪問場所のIdを返す(Acount, Campaign の可能性があります)、ない場合 false を返す
        private String vfWhatIdC(String whatIdc) {
            String accId = 'false';
            if (String.isBlank(whatIdc) == false) {
                Account acc = PersonalCalendarController.evtAccountMap.get(whatIdc);
                Campaign cpg = PersonalCalendarController.evtCampaignMap.get(whatIdc);
                if (acc != null) {
                    accId = whatIdc;
                }
                if (cpg != null) {
                    accId = whatIdc;
                }
            }
            return accId;
        }
        
        private String time2Str(Event e) {
            String time2Str = '' + e.StartDateTime.hour();
            if (e.StartDateTime.minute() != 0) {
                time2Str += ':' + e.StartDateTime.format('mm');
            }
            time2Str += '-' + e.EndDateTime.hour();
            if (e.EndDateTime.minute() != 0) {
                time2Str += ':' + e.EndDateTime.format('mm');
            }
            return time2Str;
        }
 
        // VFより呼び出すpublic method
        public Integer getRowspan() {
            if (PersonalCalendarController.isWeek) {
                return maxTr == 0 ? 1 : maxTr;
            } else {
                return 1;
            }
        }
 
        public List<Map<String, String>> getMdKeyList3() {
            if (this.userId == '0') {
                return PersonalCalendarController.mdKeyList2;
            }
            Map<String, List<Event>> evtListsMap = evtListsMapMap.get(this.userId);
            Map<String, List<Id>> whatIdsMap = whatIdsMapMap.get(this.userId);
 
            List<Map<String, String>> rtn2 = new List<Map<String, String>>();
            Map<String, String> md2User = PersonalCalendarController.mdKeyList2[0].clone();
            rtn2.add(md2User);
            if (PersonalCalendarController.isWeek) {
                for (Integer i = 1; i < PersonalCalendarController.mdKeyList2.size(); i++) {
                    Map<String, String> md2 = PersonalCalendarController.mdKeyList2[i].clone();
                    List<Id> whatIds = whatIdsMap.get(md2.get('md'));
                    List<Event> evtLists = evtListsMap.get(md2.get('md'));
System.debug('getMdKeyList3 mdKey:' + md2.get('md'));
System.debug('getMdKeyList3 WhatId.size():' + whatIds.size());
                    if (evtLists.size() > 0) {
                        Boolean submited = false;
                        for (Id whatId : whatIds) {
                            if (PersonalCalendarController.drMap.get(whatId) != null) {
                                Daily_Report__c dr = PersonalCalendarController.drMap.get(whatId);
System.debug('getMdKeyList3 ' + whatId + ':' + dr.Submit_Date_New__c);
                                if (dr.Submit_Date_New__c != null) {
                                    submited = true;
                                    break;
                                }
                            }
                        }
                        // TODO cssの調整がうまくいかないため、とりあえず 前の md2 に mdCssを設定
                        Map<String, String> md2Before = rtn2[rtn2.size() - 1];
                        if (submited == false) {
                            md2Before.put('mdCss', md2Before.get('mdCss') + ' unSubmited');
                        }
                    }
                    rtn2.add(md2);
                }
            } else {
                Boolean submited = false;
                Integer evtCnt = 0;
                for (Integer i = 1; i < PersonalCalendarController.mdKeyList2.size(); i++) {
                    Map<String, String> md2 = PersonalCalendarController.mdKeyList2[i].clone();
                    List<Id> whatIds = whatIdsMap.get(md2.get('md'));
                    List<Event> evtLists = evtListsMap.get(md2.get('md'));
                    if (evtLists.size() > 0) {
                        evtCnt += evtLists.size();
                        Boolean needBreakAll = false;
                        for (Id whatId : whatIds) {
                            if (PersonalCalendarController.drMap.get(whatId) != null) {
                                Daily_Report__c dr = PersonalCalendarController.drMap.get(whatId);
                                if (dr.Submit_Date_New__c != null) {
                                    submited = true;
                                    needBreakAll = true;
                                    break;
                                }
                            }
                        }
                        if (needBreakAll) break;
                    }
                }
                // 日の場合ユーザーに css をつける
                if (evtCnt > 0 && submited == false) {
                    md2User.put('mdCss', md2User.get('mdCss') + ' unSubmited');
                }
                for (Integer i = 1; i < PersonalCalendarController.mdKeyList2.size(); i++) {
                    Map<String, String> md2 = PersonalCalendarController.mdKeyList2[i].clone();
                    rtn2.add(md2);
                }
            }
            return rtn2;
        }
 
        // 週の行単位に変換、line は 1 から
        // maxTrが1以上の場合のみ呼び出す
        public List<List<Map<String, String>>> getRowInfoList() {
            Map<String, List<Event>> evtListsMap = evtListsMapMap.get(this.userId);
            Map<String, List<Integer>> evtMarkedMap = evtMarkedMapMap.get(this.userId);
            Map<String, List<String>> searchWordsMap = searchWordsMapMap.get(this.userId);
            Map<String, List<Id>> whatIdsMap = whatIdsMapMap.get(this.userId);
            // Dailyの時だけ使う、重ね表示用
            List<Long> evtsStart = evtsStartMap.get(this.userId);
            List<Long> evtsEnd = evtsEndMap.get(this.userId);
            List<Integer> evtsZ = evtsZMap.get(this.userId);
 
            List<List<Map<String, String>>> trList = new List<List<Map<String, String>>>();
            for (Integer line = 1; line <= maxTr; line++) {
                List<Map<String, String>> tdList = new List<Map<String, String>>();
                trList.add(tdList);
                for (String mdKey : PersonalCalendarController.mdKeyList) {
                    List<Id> whatIds = whatIdsMap.get(mdKey);
                    List<Event> evtLists = evtListsMap.get(mdKey);
                    List<Integer> evtMarked = evtMarkedMap.get(mdKey);
                    List<String> searchWords = searchWordsMap.get(mdKey);
                    Map<String, String> ev = new Map<String, String>();
                    ev.put('isEvent', '0');
                    ev.put('evtId', '');
                    Integer sz = evtLists.size();
                    if (sz < line) {
                        // td のみ出力
                    } else {
                        ev.put('whatId', 'false');
                        for (Id whatId : whatIds) {
                            if (PersonalCalendarController.drMap.get(whatId) != null) {
                                ev.put('whatId', whatId);
                                break;
                            }
                        }
                        ev.put('isEvent', '1');
                        Event e = evtLists[line - 1];
                        ev.put('at2Css', at2Css(e.Activity_Type2__c));
                        ev.put('evtMarked', '' + evtMarked[line - 1]);
                        if (e.IsAllDayEvent) {
                            // Campaign
                            ev.put('evtId', e.NextEventC_ID__c);
                            if (PersonalCalendarController.isWeek) {
                                Integer lft = Date.valueOf(mdKey).daysBetween(e.ActivityDate);
System.debug('IsAllDayEvent Campaign lft:' + lft);
                                if (lft > 0) {
                                    ev.put('sLeft', (lft / 0.07) + '%');
                                } else {
                                    ev.put('sLeft', '0%');
                                }
                                Integer wth = Date.valueOf(e.ActivityDate).daysBetween(Date.newInstance(e.EndDateTime.year(), e.EndDateTime.month(), e.EndDateTime.day()));
                                ev.put('eWidth', ((wth + 1) / 0.07) + '%');
                            } else {
                                ev.put('sLeft', '0%');
                                ev.put('eWidth', '100%');
                            }
                            ev.put('time', e.Subject);
                            ev.put('title', e.Location);
                        } else {
                            // 週 Event
                            ev.put('evtId', e.Id);
                            ev.put('sLeft', '0%');
                            ev.put('eWidth', '100%');
                            ev.put('time', time2Str(e) + ' ' + e.Subject);
                            ev.put('title', String.isBlank(e.Location) ? e.Activity_Type2__c : e.Location);
                        }
                        ev.put('isScheduled', '' + e.IsScheduled__c);
                        ev.put('accId', vfWhatIdC(e.WhatId__c));
                        // 詳細の時使う
                        ev.put('mainVisit', e.Main_Visit_Location__c);
                        ev.put('purposeType', e.Purpose_Type__c);
                        ev.put('opp1Id', String.isBlank(e.Related_Opportunity1_ID__c) ? 'false' : e.Related_Opportunity1_ID__c);
                        ev.put('opp1Name', String.isBlank(e.Related_Opportunity1__c) ? '' : e.Related_Opportunity1__c);
                        ev.put('service1Id', String.isBlank(e.Related_Service1_ID__c) ? 'false' : e.Related_Service1_ID__c);
                        ev.put('service1Name', String.isBlank(e.Related_Service1__c) ? '' : e.Related_Service1__c);
                        ev.put('searchWord', searchWords[line - 1]);
                    }
                    tdList.add(ev);
                }
            }
            return trList;
        }
 
        // 日行単位に変換、TODO とりあえず 常に1行
        // mdKey の td常に 出力
        // Page側Eventが複数のevだけ再度loopする
        public List<List<Map<String, String>>> getDayEventInfoList() {
            Map<String, List<Event>> evtListsMap = evtListsMapMap.get(this.userId);
            Map<String, List<Integer>> evtMarkedMap = evtMarkedMapMap.get(this.userId);
            Map<String, List<String>> searchWordsMap = searchWordsMapMap.get(this.userId);
            Map<String, List<Id>> whatIdsMap = whatIdsMapMap.get(this.userId);
            // Dailyの時だけ使う、重ね表示用
            List<Long> evtsStart = evtsStartMap.get(this.userId);
            List<Long> evtsEnd = evtsEndMap.get(this.userId);
            List<Integer> evtsZ = evtsZMap.get(this.userId);
 
            List<List<Map<String, String>>> tdList = new List<List<Map<String, String>>>();
            Integer evtIdx = 0;
            for (Integer mdIdx = 0; mdIdx < PersonalCalendarController.mdKeyList.size(); mdIdx++) {
                String mdKey = PersonalCalendarController.mdKeyList[mdIdx];
                List<Map<String, String>> evList = new List<Map<String, String>>();
                tdList.add(evList);
                List<Id> whatIds = whatIdsMap.get(mdKey);
                List<Event> evtLists = evtListsMap.get(mdKey);
                List<Integer> evtMarked = evtMarkedMap.get(mdKey);
                List<String> searchWords = searchWordsMap.get(mdKey);
                
                if (evtLists.size() > 0) {
                    for (Integer line = 1; line <= evtLists.size(); line++) {
                        Map<String, String> ev = new Map<String, String>();
                        ev.put('whatId', 'false');
                        for (Id whatId : whatIds) {
                            if (PersonalCalendarController.drMap.get(whatId) != null) {
                                ev.put('whatId', whatId);
                                break;
                            }
                        }
                        ev.put('isEvent', '1');
                        Event e = evtLists[line - 1];
                        ev.put('evtId', e.Id);
                        ev.put('at2Css', at2Css(e.Activity_Type2__c));
                        ev.put('evtMarked', '' + evtMarked[line - 1]);
System.debug('getDayEventInfoList evtsZ[' + evtIdx + ']=' + evtsZ[evtIdx]);
                        ev.put('sTop', '' + (evtsZ[evtIdx] * 4));       // 重なってずれの対応、top:4px ズラす
                        // 精度を保つため、ここ 0.6 にしました。
                        ev.put('sLeft', ((mdIdx * 100.0 + e.StartDateTime.minute() / 0.6) / PersonalCalendarController.mdKeyList.size()) + '%');
                        ev.put('eWidth', ((e.DurationInMinutes / 0.6) / PersonalCalendarController.mdKeyList.size()) + '%');
                        ev.put('isScheduled', '' + e.IsScheduled__c);
                        ev.put('time', (String.isBlank(e.Subject) ? e.StartDateTime.format('mm') + '-' + e.EndDateTime.format('mm') : e.Subject));
                        ev.put('time2', time2Str(e) + ' ' + e.Subject);
                        ev.put('title', String.isBlank(e.Location) ? e.Activity_Type2__c : e.Location);
                        ev.put('accId', vfWhatIdC(e.WhatId__c));
                        // 詳細の時使う
                        ev.put('mainVisit', e.Main_Visit_Location__c);
                        ev.put('purposeType', e.Purpose_Type__c);
                        ev.put('opp1Id', String.isBlank(e.Related_Opportunity1_ID__c) ? 'false' : e.Related_Opportunity1_ID__c);
                        ev.put('opp1Name', String.isBlank(e.Related_Opportunity1__c) ? '' : e.Related_Opportunity1__c);
                        ev.put('service1Id', String.isBlank(e.Related_Service1_ID__c) ? 'false' : e.Related_Service1_ID__c);
                        ev.put('service1Name', String.isBlank(e.Related_Service1__c) ? '' : e.Related_Service1__c);
                        ev.put('searchWord', searchWords[line - 1]);
                        evList.add(ev);
                        evtIdx++;
                    }
                } else {
                    // td のみ出力
                    Map<String, String> ev = new Map<String, String>();
                    ev.put('isEvent', '0');
                    ev.put('evtId', '');
                    ev.put('mainVisit', '');
                    evList.add(ev);
                }
            }
            return tdList;
        }
        
        // Instance 及び 中身 を作る関数
        public UserCalendarInfo(String userId, String Photo_Text, String userAlias, String userDesc) {
            this.userId = userId;
            this.Photo_Text = Photo_Text;
            this.userAlias = userAlias;
            this.userDesc = userDesc;
 
            PersonalCalendarController.evtListsMapMap.put(this.userId, new Map<String, List<Event>>());
            PersonalCalendarController.evtMarkedMapMap.put(this.userId, new Map<String, List<Integer>>());
            PersonalCalendarController.searchWordsMapMap.put(this.userId, new Map<String, List<String>>());
            PersonalCalendarController.whatIdsMapMap.put(this.userId, new Map<String, List<Id>>());
            // Dailyの時だけ使う、重ね表示用
            PersonalCalendarController.evtsStartMap.put(this.userId, new List<Long>());
            PersonalCalendarController.evtsEndMap.put(this.userId, new List<Long>());
            PersonalCalendarController.evtsZMap.put(this.userId, new List<Integer>());
            
            Map<String, List<Event>> evtListsMap = evtListsMapMap.get(this.userId);
            Map<String, List<Integer>> evtMarkedMap = evtMarkedMapMap.get(this.userId);
            Map<String, List<String>> searchWordsMap = searchWordsMapMap.get(this.userId);
            Map<String, List<Id>> whatIdsMap = whatIdsMapMap.get(this.userId);
            maxTr = 0;
            for (String mdKey : PersonalCalendarController.mdKeyList) {
                evtListsMap.put(mdKey, new List<Event>());
                evtMarkedMap.put(mdKey, new List<Integer>());
                searchWordsMap.put(mdKey, new List<String>());
                whatIdsMap.put(mdKey, new List<Id>());
            }
        }
 
        public void addEvent(Event e, String searchText) {
            Map<String, List<Event>> evtListsMap = evtListsMapMap.get(this.userId);
            Map<String, List<Integer>> evtMarkedMap = evtMarkedMapMap.get(this.userId);
            Map<String, List<String>> searchWordsMap = searchWordsMapMap.get(this.userId);
            Map<String, List<Id>> whatIdsMap = whatIdsMapMap.get(this.userId);
            // Dailyの時だけ使う、重ね表示用
            List<Long> evtsStart = evtsStartMap.get(this.userId);
            List<Long> evtsEnd = evtsEndMap.get(this.userId);
            List<Integer> evtsZ = evtsZMap.get(this.userId);
 
System.debug('addEvent e.Id, searchText:' + e.Id + ',' + searchText);
            Datetime ead = e.StartDateTime;
            if (PersonalCalendarController.isWeek) {
                ead = DateTime.newInstance(e.ActivityDate.year(), e.ActivityDate.month(), e.ActivityDate.day());
            }
            String mdKey = ead.format('H') + ':00';
            if (PersonalCalendarController.isWeek) {
                mdKey = ead.format('yyyy-MM-dd');
            }
System.debug('addEvent mdKey:' + mdKey);
            List<Id> whatIds = whatIdsMap.get(mdKey);
            if (whatIds == null) {
                // 表示範囲外の場合
                return;
            }
            if (String.isBlank(e.WhatId) == false) {
System.debug('addEvent WhatId:' + e.WhatId);
                whatIds.add(e.WhatId);
            }
 
            List<Event> evtLists = evtListsMap.get(mdKey);
            evtLists.add(e);
            List<Integer> evtMarked = evtMarkedMap.get(mdKey);
            List<String> searchWords = searchWordsMap.get(mdKey);
            String mainVisit = e.Main_Visit_Location__c == null ? '' : e.Main_Visit_Location__c;
            mainVisit = PersonalCalendarController.mvlCnMap.containsKey(mainVisit) ? PersonalCalendarController.mvlCnMap.get(mainVisit) : mainVisit;
            e.Main_Visit_Location__c = mainVisit;
            String purposeType = e.Purpose_Type__c == null ? '' : e.Purpose_Type__c;
            purposeType = PersonalCalendarController.purposeCnMap.containsKey(purposeType) ? PersonalCalendarController.purposeCnMap.get(purposeType) : purposeType;
            e.Purpose_Type__c = purposeType;
            String searchWord = '';
            searchWord += String.isBlank(e.subject) ? '' : '||' + e.subject;
            searchWord += String.isBlank(e.Location) ? '' : '||' + e.Location;
            searchWord += String.isBlank(mainVisit) ? '' : '||' + mainVisit;
            searchWord += String.isBlank(purposeType) ? '' : '||' + purposeType;
            searchWord += String.isBlank(e.Related_Opportunity1__c) ? '' : '||' + e.Related_Opportunity1__c;
            searchWord += String.isBlank(e.Related_Service1__c) ? '' : '||' + e.Related_Service1__c;
            if (String.isBlank(e.WhatId__c) == false) {
                Account acc = PersonalCalendarController.evtAccountMap.get(e.WhatId__c);
                Campaign cpg = PersonalCalendarController.evtCampaignMap.get(e.WhatId__c);
                if (acc != null) {
                    searchWord += String.isBlank(acc.Name) ? '' : '||' + acc.Name;
                    searchWord += String.isBlank(acc.Name_for_Daily_Report_text__c) ? '' : '||' + acc.Name_for_Daily_Report_text__c;
                    searchWord += String.isBlank(acc.HP_146POCM_Category_From_Dept__c) ? '' : '||' + acc.HP_146POCM_Category_From_Dept__c;
                }
                if (cpg != null) {
                    searchWord += String.isBlank(cpg.Name2__c) ? '' : '||' + cpg.Name2__c;
                }
            }
            searchWord = searchWord.toUpperCase();
            searchWords.add(searchWord);
System.debug('addEvent searchWord:' + searchWord);
            
            Long evtStart =  e.StartDateTime.getTime();
            evtsStart.add(evtStart);
            evtsEnd.add(e.EndDateTime.getTime());
            Integer linkZ =  0;
            Integer evtZ =  0;
            if (evtsZ.size() > 0) {
                evtZ = evtsZ[evtsZ.size() - 1];
                linkZ = evtsZ[evtsZ.size() - 1];
            }
System.debug('addEvent evtStart:' + evtStart);
            for (Integer beforeIdx = evtsStart.size() - 2; beforeIdx >= 0; beforeIdx--) {
                Long bevtEnd =  evtsEnd[beforeIdx];
                Integer bevtZ =  evtsZ[beforeIdx];
System.debug('addEvent beforeIdx:' + beforeIdx);
System.debug('addEvent bevtEnd:' + bevtEnd);
System.debug('addEvent bevtZ:' + bevtZ);
                if (bevtEnd > evtStart) {
System.debug('addEvent bevtEnd > evtStart');
                    if (evtZ <= bevtZ) {
                        // 重なっているため、かつ 前のやつより階層Z小さい場合、一階下がる
System.debug('addEvent evtZ = bevtZ + 1');
                        evtZ = bevtZ + 1;
                        linkZ = bevtZ;
                    }
                } else {
                    if (linkZ != bevtZ) {
                        // さらに、階層も1階層以上離れた場合、同じ階層にする
                        if (evtZ - bevtZ >= 1) {
System.debug('addEvent evtZ = bevtZ');
                            evtZ = bevtZ;
                        }
                    }
                }
//                // 0 になったら、さらに遡る必要がないです。
//                if (evtZ == 0) {
//                    break;
//                }
            }
            evtsZ.add(evtZ);
System.debug('addEvent evtsZ.add:' + evtZ);
 
            String at2 = e.Activity_Type2__c == null ? '' : e.Activity_Type2__c;
            at2 = PersonalCalendarController.at2CnMap.containsKey(at2) ? PersonalCalendarController.at2CnMap.get(at2) : at2;
            e.Activity_Type2__c = at2;
            
            // Mark イベント
            Boolean isMark = false;
            if (String.isBlank(searchText) == false) {
                if (searchWord.indexOf(searchText.toUpperCase()) >= 0) {
                    isMark = true;
                }
            }
            if (isMark) {
                PersonalCalendarController.markCnt++;
                evtMarked.add(PersonalCalendarController.markCnt);
            } else {
                evtMarked.add(0);
            }
System.debug('addEvent evtMarked.add:' + isMark);
            if (evtLists.size() > maxTr) {
                maxTr = evtLists.size();
            }
        }
        
        public void addCampaign(Campaign c) {
            Map<String, List<Event>> evtListsMap = evtListsMapMap.get(this.userId);
            Map<String, List<Integer>> evtMarkedMap = evtMarkedMapMap.get(this.userId);
            Map<String, List<String>> searchWordsMap = searchWordsMapMap.get(this.userId);
 
System.debug('addCampaign c.Id:' + c.Id);
            String mdKey = PersonalCalendarController.mdKeyList[0];
System.debug('addCampaign mdKey:' + mdKey);
            List<Event> evtLists = evtListsMap.get(mdKey);
            List<Integer> evtMarked = evtMarkedMap.get(mdKey);
            List<String> searchWords = searchWordsMap.get(mdKey);
            Event e = new Event(
                IsAllDayEvent = true,           // getRowInfoList のところ Campaign かどうか 判断用
                NextEventC_ID__c = c.Id,
                Activity_Type2__c = '',
                Main_Visit_Location__c = '',
                Purpose_Type__c = '',
                Related_Opportunity1_ID__c = '',
                Related_Opportunity1__c = '',
                Related_Service1_ID__c = '',
                Related_Service1__c = '',
                IsScheduled__c = false,
                ActivityDate = c.StartDate,
                StartDateTime = DateTime.newInstance(c.StartDate.year(), c.StartDate.month(), c.StartDate.day()),
                EndDateTime = DateTime.newInstance(c.EndDate.year(), c.EndDate.month(), c.EndDate.day()),
                Subject = c.RecordType.Name + ':' + c.Society_Type__c
            );
            evtLists.add(e);
            if (PersonalCalendarController.isWeek) {
                e.Location = c.Name2__c;
            } else {
                e.Location = c.Name;
            }
            if (evtLists.size() > maxTr) {
                maxTr = evtLists.size();
            }
            // 使わない項目
            evtMarked.add(0);
            searchWords.add('');
        }
    }
}