杜洪波
2025-05-14 9db1c6c261049fbdcb104e6c0e07fa544bb42013
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
package com.product.administration.service;
 
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.product.administration.config.CmnConst;
import com.product.administration.config.SystemCode;
import com.product.administration.service.ide.IConferenceManagerService;
import com.product.common.lang.DateUtils;
import com.product.common.lang.StringUtils;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.permission.PermissionService;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.service.support.QueryFilterService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.core.transfer.Transactional;
import com.product.core.websocket.service.WebsocketMesssageServiceThread;
import com.product.module.sys.entity.SystemUser;
import com.product.util.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
 
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
 
/**
 * @Author cheng
 * @Description
 * @Date 2021/4/20 14:42
 * @Version 1.0
 */
@Service("conferenceManagerService")
public class ConferenceManagerService extends AbstractBaseService implements IConferenceManagerService {
 
    @Autowired
    BaseDao baseDao;
 
    @Autowired
    QueryFilterService queryFilterService;
    @Autowired
    PermissionService permissionService;
 
    /**
     * 会议室列表
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public DataTableEntity getListConferenceRoom(FieldSetEntity fse) throws BaseException {
        String queryFilter = queryFilterService.getQueryFilter(fse);
        String dataFilter = permissionService.getDataFilter(CmnConst.ORG_LEVEL_UUID);
        StringBuilder filter = new StringBuilder();
        if (!StringUtils.isEmpty(queryFilter)) {
            filter.append(queryFilter);
        }
        String created_by_field = fse.getString("created_by_field");
        if (!StringUtils.isEmpty(created_by_field)) {
            Integer userId = SpringMVCContextHolder.getCurrentUser().getUser_id();
            if (filter.length() > 0) {
                filter.append("and (" + created_by_field + " = " + userId + ") ");
            } else {
                filter.append(" ( ");
                filter.append(created_by_field + " = " + userId);
                filter.append(" ) ");
            }
        } else if (!StringUtils.isEmpty(dataFilter)) {
            if (filter.length() > 0) {
                filter.append("and (" + dataFilter + ") ");
            } else {
                filter.append(" ( ");
                filter.append(dataFilter);
                filter.append(" ) ");
            }
        }
        if (!StringUtils.isEmpty(fse.getString("filter"))) {
            if (filter.length() > 0) {
                filter.append("and (" + fse.getString("filter") + ") ");
            } else {
                filter.append(" ( ");
                filter.append(fse.getString("filter"));
                filter.append(" ) ");
            }
        }
        DataTableEntity dt = baseDao.listTable(fse.getTableName(), filter.toString(), null, null, CmnConst.CREATED_UTC_DATETIME, fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE), false);
        baseDao.loadPromptData(dt);
        return dt;
    }
 
    /**
     * 会议室详情
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findConferenceRoom(FieldSetEntity fse) throws BaseException {
        return baseDao.getFieldSetEntity(fse.getTableName(), fse.getUUID(), true);
    }
 
    /**
     * 保存会议室
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Transactional
    @Override
    public boolean saveConferenceRoom(FieldSetEntity fse) throws BaseException {
        //重名验证对象
        FieldSetEntity nameVerification = null;
        if (StringUtils.isEmpty(fse.getUUID())) {
            fse.setValue(CmnConst.ORG_LEVEL_UUID, SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid());
            nameVerification = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_OA_CONFERENCE_ROOM_CONFIG, "room_name=?", new Object[] {fse.getString("room_name")}, false);
        }else {
            nameVerification = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_OA_CONFERENCE_ROOM_CONFIG, "room_name=? and uuid!=?", new Object[] {fse.getString("room_name"), fse.getUUID()}, false);
        }
        if (nameVerification!=null) {
            throw new BaseException(SystemCode.CONFERENCE_ROOM_SAVE_FIAL_DUPLICATE_NAME.getValue(), SystemCode.CONFERENCE_ROOM_SAVE_FIAL_DUPLICATE_NAME.getText());
        }
 
        BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fse);
        //重名验证
 
        return baseDao.saveFieldSetEntity(fse);
    }
 
    /**
     * 删除会议室
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Transactional
    @Override
    public boolean delConferenceRoom(FieldSetEntity fse) throws BaseException {
        return baseDao.delete(fse.getTableName(), fse.getUUID().split(","));
    }
 
    /**
     * 会议申请保存
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Override
    @Transactional
    public String saveConferenceApply(FieldSetEntity fse) throws BaseException {
        if ("0".equals(fse.getString("type"))){
            baseDao.saveFieldSetEntity(fse);
            return fse.getUUID();
        }
        if (StringUtils.isEmpty(fse.getUUID())) {
            fse.setValue(CmnConst.ORG_LEVEL_UUID, SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid());
            fse.setValue("flow_flag", 0);
        }
        if (StringUtils.isEmpty(fse.getString("meeting_room"))) {
            throw new BaseException(SystemCode.CONFERENCE_ROOM_REQUIRED.getValue(), SystemCode.CONFERENCE_ROOM_REQUIRED.getText());
        }
        String start_time = fse.getDate(CmnConst.START_TIME, CmnConst.YYYYMMDDHHMMSS);
        String end_time = fse.getDate(CmnConst.END_TIME, CmnConst.YYYYMMDDHHMMSS);
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT ");
        sql.append(" uuid ");
        sql.append(" FROM ");
        sql.append(" product_oa_conference_apply ");
        sql.append(" WHERE ");
        sql.append(" meeting_room=?  ");
        Object[] params;
        if (!StringUtils.isEmpty(fse.getUUID())) {
            sql.append(" and uuid !=? ");
            params = new Object[]{fse.getString("meeting_room"), fse.getUUID(), start_time, end_time, start_time, end_time, start_time, end_time};
        } else {
            params = new Object[]{fse.getString("meeting_room"), start_time, end_time, start_time, end_time, start_time, end_time};
        }
        sql.append(" and (( start_time >=? AND start_time <= ? ) ");
        sql.append(" OR ( start_time <= ? AND end_time >= ? ) ");
        sql.append(" OR ( end_time >= ? AND end_time <= ? ) ");
        sql.append(" ) and flow_flag in (1,2) ");
        DataTableEntity dataTableEntity = baseDao.listTable(sql.toString(), params);
        //验证会议室在选择时间段内是否被使用
        if (!BaseUtil.dataTableIsEmpty(dataTableEntity)) {
            // 会议室在时间段内被使用抛出错误
            throw new BaseException(SystemCode.CONFERENCE_ROOM_IS_USED.getValue(), SystemCode.CONFERENCE_ROOM_IS_USED.getText());
        }
        BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fse);
        baseDao.saveFieldSetEntity(fse);
        return fse.getUUID();
    }
 
    @Override
    @Transactional
    public boolean delConferenceApply(FieldSetEntity fse) throws BaseException {
        return baseDao.delete(fse.getTableName(), fse.getUUID().split(","));
    }
 
    @Override
    @Transactional
    public List getKbData(FieldSetEntity fse) throws BaseException {
 
        List<Object>param=new ArrayList<>();
        String meeting_date= fse.getString("meeting_date");
        String meeting_date_end= fse.getString("meeting_date_end");
        String meeting_resource = fse.getString("meeting_resource");
        param.add(meeting_date);
        param.add(meeting_date_end);
        String replace_meeting_resource="";
        if(!StringUtils.isEmpty(meeting_resource)){
 
            String[] split = meeting_resource.split(",");
            for (int i = 0; i < split.length; i++) {
                if(i!=split.length-1){
                    replace_meeting_resource=replace_meeting_resource+"y.meeting_resource like '%"+split[i]+"%' and ";
                }else {
                    replace_meeting_resource=replace_meeting_resource+"y.meeting_resource like '%"+split[i]+"%'";
                }
 
            }
 
        }
 
        StringBuilder bs=new StringBuilder();
        bs.append(" SELECT DISTINCT  g.room_name,g.uuid as meet_room_uuid,DATE_FORMAT(y.start_time, \"%d-%m-%Y %H:%i\")  start_time_format,DATE_FORMAT(y.end_time, \"%d-%m-%Y %H:%i\")  end_time_format,y.* ");
        bs.append(" FROM product_oa_conference_room_config g");
        bs.append(" left JOIN  product_oa_conference_apply y ");
        bs.append(" on y.meeting_room=g.uuid and y.start_time between  ? and ? ");
        if(!StringUtils.isEmpty(meeting_resource)){
            bs.append(" where ( "+replace_meeting_resource+" )");
        }
        bs.append(" ORDER BY y.start_time");
        DataTableEntity dataTableEntity = baseDao.listTable(bs.toString(), param.toArray());
        List<String> list=new ArrayList();
        List<HashMap> listDate=new ArrayList<>();
 
        for(int i=0;i<dataTableEntity.getRows();i++){
            FieldSetEntity fieldSetEntity = dataTableEntity.getData().get(i);
 
            //初始化会议室的使用的状态
            String filter=" meeting_room = '"+fieldSetEntity.getString("meeting_room")+"' and start_time between '"+meeting_date+"'  and '"+meeting_date_end+"'";
            DataTableEntity product_oa_conference_apply = baseDao.listTable("product_oa_conference_apply", filter, new Object[]{});
            for (int i1 = 0; i1 < product_oa_conference_apply.getRows(); i1++) {
                FieldSetEntity fieldSetEntity1 = product_oa_conference_apply.getFieldSetEntity(i1);
                Date date = new Date();
                if(date.before(fieldSetEntity1.getDate("start_time"))){
                    fieldSetEntity1.setValue("status","未开始");
                }else if(date.after(fieldSetEntity1.getDate("end_time"))){
                    fieldSetEntity1.setValue("status","已结束");
                }else {
                    fieldSetEntity1.setValue("status","会议中");
                }
                baseDao.executeUpdate("update product_oa_conference_apply set status='"+fieldSetEntity1.getString("status")+"' where uuid='"+fieldSetEntity1.getString("uuid")+"'");
            }
 
            if(ObjectUtil.isNotEmpty(fieldSetEntity.getString("uuid"))){
                //构造所需要的格式
                if(!list.contains(fieldSetEntity.getValue("room_name").toString())){
                    HashMap<String,Object> hashMap=new HashMap<>();
                    hashMap.put("room_name",fieldSetEntity.getValue("room_name").toString());
                    hashMap.put("uuid",fieldSetEntity.getValue("meet_room_uuid").toString());
                    Object getStartTime = null;
                    for (int j = 0; j < dataTableEntity.getRows(); j++) {
                        FieldSetEntity fieldSetEntity1 = dataTableEntity.getFieldSetEntity(j);
                        if(fieldSetEntity1.getString("room_name").equals(hashMap.get("room_name"))){
                            getStartTime = fieldSetEntity1.getValue("start_time");
                            SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm");
                            String time = dateFormat.format(getStartTime);
                            hashMap.put("start_time",time);
                            break;
                        }
 
                    }
                    list.add(fieldSetEntity.getValue("room_name").toString());
                    listDate.add(hashMap);
 
                }
                fieldSetEntity.setValue("parent",fieldSetEntity.getValue("meet_room_uuid").toString());
                HashMap<String,Object> hashMap=new HashMap<>();
                for (int j = 0; j < fieldSetEntity.getValues().keySet().size(); j++) {
                    if(fieldSetEntity.getValues().keySet().toArray()[j].toString().equals("start_time") || fieldSetEntity.getValues().keySet().toArray()[j].toString().equals("end_time")){
                        Object meeting_time = fieldSetEntity.getValue(fieldSetEntity.getValues().keySet().toArray()[j].toString());
                        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String time = dateFormat.format(meeting_time);
                        hashMap.put(fieldSetEntity.getValues().keySet().toArray()[j].toString(),time);
                        if(fieldSetEntity.getValues().keySet().toArray()[j].equals("start_time")){
                            hashMap.put("start_date",time);
                        }else {
                            hashMap.put("end_date",time);
                        }
                    }else {
                        hashMap.put(fieldSetEntity.getValues().keySet().toArray()[j].toString(),fieldSetEntity.getValue(fieldSetEntity.getValues().keySet().toArray()[j].toString()));
                    }
 
                }
                listDate.add(hashMap);
 
            }else {
                if(!list.contains(fieldSetEntity.getValue("room_name").toString())){
                    HashMap<String,Object> hashMap=new HashMap<>();
                    hashMap.put("room_name",fieldSetEntity.getValue("room_name").toString());
                    hashMap.put("uuid",fieldSetEntity.getValue("meet_room_uuid").toString());
                    hashMap.put("start_time","");
                    list.add(fieldSetEntity.getValue("room_name").toString());
                    listDate.add(hashMap);
                }
            }
 
        }
        return  listDate;
    }
 
    @Override
    public List getMeetingDetails(FieldSetEntity fse) throws BaseException {
        String meeting_room = fse.getString("meeting_room");
        String meeting_date = fse.getString("meeting_date");
        String meeting_date_end = fse.getString("meeting_date_end");
        String meeting_resource = fse.getString("meeting_resource");
        String replace_meeting_resource="";
        if(!StringUtils.isEmpty(meeting_resource)){
 
            String[] split = meeting_resource.split(",");
            for (int i = 0; i < split.length; i++) {
                if(i!=split.length-1){
                    replace_meeting_resource=replace_meeting_resource+"T1.meeting_resource like '%"+split[i]+"%' and ";
                }else {
                    replace_meeting_resource=replace_meeting_resource+"T1.meeting_resource like '%"+split[i]+"%'";
                }
 
            }
 
        }
 
        if(!StringUtils.isEmpty(meeting_room)&&!StringUtils.isEmpty(meeting_date)&&!StringUtils.isEmpty(meeting_date_end)){
            List<Object>param=new ArrayList<>();
            param.add(meeting_room);
            param.add(meeting_date);
            param.add(meeting_date_end);
            StringBuilder sb=new StringBuilder();
            sb.append(" SELECT b.uuid,DATE_FORMAT(b.start_time, \"%Y-%m-%d\")  start_time,b.start_time start_time1,b.end_time,b.meeting_topic,b.status,b.record_man as record_man_uuid, ");
            sb.append(" (select user_name from product_sys_users where user_id=b.record_man) as record_man,");
            sb.append(" (select user_name from product_sys_users where user_id=b.record_master) as record_master,");
            sb.append(" CONCAT(DATE_FORMAT(b.start_time,\"%H:%i\"),'~',DATE_FORMAT(b.end_time,\"%H:%i\"))  as time_quantum,");
            sb.append(" DATE_FORMAT(b.start_time,\"%Y-%m-%d\") as meeting_date,");
            sb.append(" GROUP_CONCAT(b.dict_label   SEPARATOR ',') AS meeting_resouces ");
            sb.append(" FROM (");
            sb.append(" SELECT DISTINCT a.uuid,a.start_time,a.end_time,a.meeting_topic,a.record_man,a.record_master,a.status,t.dict_label ");
            sb.append(" FROM (");
            sb.append("  SELECT T1.*, ");
            sb.append(" SUBSTRING_INDEX( SUBSTRING_INDEX( T1.meeting_resource, ',', T2.digit + 1 ), ',',- 1 ) AS type ");
            sb.append(" FROM product_oa_conference_apply T1 ");
            sb.append(" LEFT JOIN ( SELECT 0 AS digit UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 ) T2");
            sb.append(" ON T2.digit < ( length( T1.meeting_resource )- length( REPLACE ( T1.meeting_resource, ',', '' ))+ 1 )");
            sb.append(" WHERE T1.meeting_room = ? ");
            sb.append(" and T1.start_time between ? and ? ");
            if(!StringUtils.isEmpty(meeting_resource)){
             sb.append(" and ("+replace_meeting_resource+" )");
            }
            sb.append(" ) a");
            sb.append(" LEFT JOIN product_sys_dict t ON a.type = t.dict_value ");
            sb.append(" AND t.dict_name = '会议室资源'");
            sb.append(" )b ");
            sb.append(" group by b.uuid,b.start_time,b.end_time,b.meeting_topic,b.record_man,b.record_master,b.status ");
            DataTableEntity dataTableEntity = baseDao.listTable(sb.toString(), param.toArray());
 
          List dataList =new ArrayList();
            for (int i = 0; i < dataTableEntity.getRows(); i++) {
                FieldSetEntity fieldSetEntity = dataTableEntity.getData().get(i);
                Map<Object, Object> MapValues = fieldSetEntity.getValues();
                if(ObjectUtil.isNotEmpty(MapValues.get("start_time1")) || ObjectUtil.isNotEmpty( MapValues.get("end_time"))){
                    Object start_time = MapValues.get("start_time1");
                    Object end_time = MapValues.get("end_time");
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String start_time_date = dateFormat.format(start_time);
                    String end_time_date = dateFormat.format(end_time);
                   MapValues.put("start_time",start_time_date);
                   MapValues.put("end_time",end_time_date);
                }
 
                Date date = new Date();
                //是否能够取消
                if(date.before(fieldSetEntity.getDate("start_time"))){
                   MapValues.put("isCancel",true);
                }
                //是否执行开启功能
                if(date.before(fieldSetEntity.getDate("start_time")) && fieldSetEntity.getString("status").equals("已取消")){
                    MapValues.put("isStart",true);
                }
                dataList.add(MapValues);
            }
            return  dataList;
        }else {
            return null;
        }
 
    }
 
    @Override
    @Transactional
    public HashMap saveOrUpdateMeetingInfo(FieldSetEntity fse) throws BaseException {
 
        Date start_time_date = fse.getDate("start_time");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = dateFormat.format(start_time_date);
 
 
        String filter=" DATE_FORMAT(start_time,\"%Y-%m-%d\") ='"+format.split(" ")[0]+"'";
 
        DataTableEntity dataTableEntity = baseDao.listTable("product_oa_conference_apply",filter,new Object[]{});
        boolean flag=true;
        for (int i = 0; i < dataTableEntity.getRows(); i++) {
            FieldSetEntity fieldSetEntity = dataTableEntity.getData().get(i);
            Date start_time = fse.getDate("start_time");
            Date end_time = fse.getDate("end_time");
            Date start_time1 =fieldSetEntity.getDate("start_time");
            Date end_time1 = fieldSetEntity.getDate("end_time");
            if(start_time1.before(start_time) && end_time1.after(start_time)){
                flag=false;
            }
            if(start_time1.before(end_time) && end_time1.after(end_time)){
                flag=false;
            }
 
            if(start_time1.after(start_time) && end_time1.before(end_time)){
                flag=false;
            }
 
        }
        HashMap<String,Object> hashMap=new HashMap<>();
        BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fse);
        if(flag==false){
            hashMap.put("code","200");
            hashMap.put("msg","此时间段已被占用");
            hashMap.put("status","sucess");
        }else {
            if(ObjectUtil.isNotEmpty(fse.getValue("uuid"))){
                baseDao.update(fse);
            }else {
                fse.setValue("status","未开始");
                baseDao.add(fse);
            }
            hashMap.put("code","200");
            hashMap.put("msg","成功");
            hashMap.put("status","sucess");
        }
        return hashMap;
    }
 
    @Override
    public BitMatrix getQrCode(String content) throws BaseException, WriterException, IOException {
 
        //二维码的宽高
        int width = 200;
        int height = 200;
 
        //其他参数,如字符集编码
        Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
        hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
        //容错级别为H
        hints.put(EncodeHintType.ERROR_CORRECTION , ErrorCorrectionLevel.H);
        //白边的宽度,可取0~4
        hints.put(EncodeHintType.MARGIN , 0);
 
        BitMatrix bitMatrix = null;
        try {
 
            bitMatrix = new MultiFormatWriter().encode(content,
                    BarcodeFormat.QR_CODE, width, height, hints);
 
        } catch (WriterException e) {
            e.printStackTrace();
        }
 
        return bitMatrix;
    }
 
    @Override
    public void CancelAndStart(FieldSetEntity fse) throws BaseException {
 
        String uuid = fse.getString("uuid");
        String filter=" uuid='"+uuid+"'";
        DataTableEntity product_oa_conference_apply = baseDao.listTable("product_oa_conference_apply", filter, new Object[]{});
        if(product_oa_conference_apply.getRows()!=0){
            FieldSetEntity fieldSetEntity = product_oa_conference_apply.getFieldSetEntity(0);
            if(fieldSetEntity.getString("status").equals("已取消")){
                fieldSetEntity.setValue("status","已启用");
            }else {
                fieldSetEntity.setValue("status","已取消");
            }
            baseDao.update(fieldSetEntity);
        }
 
    }
 
    @Override
    public String ConferenceSign(FieldSetEntity fse) throws BaseException, ParseException {
 
 
        JSONObject jsonObject = new JSONObject();
        if(!StringUtils.isEmpty(fse.getString("uuid"))&&!StringUtils.isEmpty(fse.getString("date"))){
            String uuid = fse.getString("uuid");
            String date = fse.getString("date");
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date parseDate = dateFormat.parse(date);
            long between = DateUtil.between(parseDate, new Date(), DateUnit.SECOND);
 
            if(between>20){
                jsonObject.put("code","200");
                jsonObject.put("msg","二维码已失效");
                jsonObject.put("status","fail");
 
            }else {
 
                SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
                FieldSetEntity fieldSetEntity = new FieldSetEntity();
                fieldSetEntity.setTableName("product_oa_conference_sign");
                fieldSetEntity.setValue("sign_user",currentUser.getUser_name());
                fieldSetEntity.setValue("user_id",currentUser.getUser_id());
                fieldSetEntity.setValue("org_level_uuid","00000000-0000-0000-0000-000000000000");
                fieldSetEntity.setValue("organization",currentUser.getDept_uuid());
                fieldSetEntity.setValue("organization_name",currentUser.getCurrentDept().getString("org_level_name"));
                fieldSetEntity.setValue("sign_date",new Date());
                fieldSetEntity.setValue("sign_status","已签到");
                fieldSetEntity.setValue("meeting_uuid",uuid);
 
                BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fse);
                baseDao.add(fieldSetEntity);
                jsonObject.put("code","200");
                jsonObject.put("msg","签到成功");
                jsonObject.put("status","sucess");
            }
        }
 
        return jsonObject.toString();
    }
 
    @Override
    public HashMap getSignOrVisitInfo(FieldSetEntity fse) throws BaseException {
 
       String meeting_uuid = fse.getString("meeting_uuid");
       //type=1就是签到数据,type=2就是访问数据
       String type = fse.getString("type");
        List<Object> params=new ArrayList<>();
        params.add(meeting_uuid);
        params.add(meeting_uuid);
 
        StringBuilder sb=new StringBuilder();
        sb.append(" SELECT c.* FROM ( ");
        sb.append(" SELECT b.staff_id,b.uuid as meeting_uuid,f.show_name,l.uuid as dept_uuid,l.org_level_name,");
        if(type.equals("1")){
         sb.append(" n.sign_status");
        }else {
            sb.append(" n.visit_status");
        }
        sb.append(" FROM (" );
        sb.append(" SELECT y.*, ");
        sb.append(" SUBSTRING_INDEX( SUBSTRING_INDEX( participator, ',', n ), ',', - 1 ) AS staff_id");
        sb.append(" FROM product_oa_conference_apply y, ");
        sb.append(" ( SELECT @rownum := @rownum + 1 AS n FROM ( SELECT @rownum := 0 ) r, product_oa_conference_apply ) x ");
        sb.append(" WHERE 1 = 1 ");
        sb.append(" AND n <= ( LENGTH( participator ) - LENGTH( REPLACE ( participator, ',', '' ) ) + 1 )");
        sb.append(" and y.uuid= ? ");
        sb.append(" )b ");
        sb.append(" LEFT JOIN product_sys_staffs f on b.staff_id=f.user_id ");
        sb.append(" LEFT JOIN product_sys_org_levels l on f.dept_uuid=l.uuid ");
        if(type.equals("1")){
            sb.append(" LEFT JOIN product_oa_conference_sign n ");
        }else {
            sb.append(" LEFT JOIN product_oa_conference_visit n ");
        }
        sb.append(" on b.staff_id=n.user_id and n.meeting_uuid=? ");
        sb.append(" )c");
 
        DataTableEntity dataTableEntity = baseDao.listTable(sb.toString(),params.toArray());
        List<HashMap> listDate=new ArrayList<>();
        List<HashMap> listDateSign=new ArrayList<>();
        List<HashMap> listDateNoSign=new ArrayList<>();
 
        List<String> list=new ArrayList();
 
        int sign_count=0;
        int sign_all=0;
        int sign_down=0;
        HashMap<String,Object> hashMapResult=new HashMap<>();
        for (int i = 0; i < dataTableEntity.getRows(); i++) {
            FieldSetEntity fieldSetEntity = dataTableEntity.getFieldSetEntity(i);
 
            if(!list.contains(fieldSetEntity.getString("org_level_name"))){
                HashMap<String,Object> hashMap=new HashMap<>();
                hashMap.put("dept_uuid",fieldSetEntity.getString("dept_uuid"));
                hashMap.put("org_level_name",fieldSetEntity.getString("org_level_name"));
                list.add(fieldSetEntity.getString("org_level_name"));
                listDate.add(hashMap);
            }
 
            fieldSetEntity.setValue("parent",fieldSetEntity.getString("dept_uuid"));
            HashMap<String,Object> hashMap=new HashMap<>();
            for (int j = 0; j < fieldSetEntity.getValues().keySet().size(); j++) {
                hashMap.put(fieldSetEntity.getValues().keySet().toArray()[j].toString(),fieldSetEntity.getValue(fieldSetEntity.getValues().keySet().toArray()[j].toString()));
 
            }
            listDate.add(hashMap);
 
        }
        sign_all=listDate.size();
        List<String> list1=new ArrayList();
        List<String> list2=new ArrayList();
        for (int j = 0; j < listDate.size(); j++) {
            if((ObjectUtil.isNotEmpty(listDate.get(j).get("sign_status"))&&listDate.get(j).get("sign_status").equals("已签到")) || (ObjectUtil.isNotEmpty(listDate.get(j).get("visit_status"))&&listDate.get(j).get("visit_status").equals("已访问"))  ){
                if(!list1.contains(listDate.get(j).get("org_level_name"))){
                    list1.add(listDate.get(j).get("org_level_name").toString());
                    HashMap<String,Object> hashMap=new HashMap<>();
                    hashMap.put("dept_uuid",listDate.get(j).get("dept_uuid"));
                    hashMap.put("org_level_name",listDate.get(j).get("org_level_name"));
                    listDateSign.add(hashMap);
                }
                sign_count++;
                //避免重复添加部门
                if(listDate.get(j).size()!=2){
                    listDateSign.add(listDate.get(j));
                }
 
            }else {
                if(!list2.contains(listDate.get(j).get("org_level_name"))){
                    list2.add(listDate.get(j).get("org_level_name").toString());
                    HashMap<String,Object> hashMap=new HashMap<>();
                    hashMap.put("dept_uuid",listDate.get(j).get("dept_uuid"));
                    hashMap.put("org_level_name",listDate.get(j).get("org_level_name"));
                    listDateNoSign.add(hashMap);
                }
                //避免重复添加部门
                if(listDate.get(j).size()!=2){
                    listDateNoSign.add(listDate.get(j));
                }
 
 
            }
        }
        sign_down=sign_all-sign_count;
        hashMapResult.put("signOrvisit_down",sign_count);
        hashMapResult.put("no_signOrvisit",sign_down);
        hashMapResult.put("listDateNoSignOrVisit",listDateNoSign);
        hashMapResult.put("listDateSignOrVisit",listDateSign);
        return  hashMapResult;
    }
 
    @Override
    public void sendMsg(FieldSetEntity fse) throws BaseException {
 
        String meeting_uuid= fse.getString("meeting_uuid");
        String type = fse.getString("type");
        String user_ids = fse.getString("user_ids");
 
        FieldSetEntity product_oa_conference_apply = baseDao.getFieldSetEntity("product_oa_conference_apply", meeting_uuid, false);
 
 
        //此方式是根据后台自动统计未访问人员
       /* List<Object> params=new ArrayList<>();
        params.add(meeting_uuid);
        params.add(meeting_uuid);
 
        StringBuilder sb=new StringBuilder();
        sb.append(" SELECT c.* FROM ( ");
        sb.append(" SELECT b.staff_id,b.uuid as meeting_uuid,f.show_name,l.uuid as dept_uuid,l.org_level_name,");
        if(type.equals("1")){
            sb.append(" n.sign_status");
        }else {
            sb.append(" n.visit_status");
        }
        sb.append(" FROM (" );
        sb.append(" SELECT y.*, ");
        sb.append(" SUBSTRING_INDEX( SUBSTRING_INDEX( participator, ',', n ), ',', - 1 ) AS staff_id");
        sb.append(" FROM product_oa_conference_apply y, ");
        sb.append(" ( SELECT @rownum := @rownum + 1 AS n FROM ( SELECT @rownum := 0 ) r, product_oa_conference_apply ) x ");
        sb.append(" WHERE 1 = 1 ");
        sb.append(" AND n <= ( LENGTH( participator ) - LENGTH( REPLACE ( participator, ',', '' ) ) + 1 )");
        sb.append(" and y.uuid= ? ");
        sb.append(" )b ");
        sb.append(" LEFT JOIN product_sys_staffs f on b.staff_id=f.user_id ");
        sb.append(" LEFT JOIN product_sys_org_levels l on f.dept_uuid=l.uuid ");
        if(type.equals("1")){
            sb.append(" LEFT JOIN product_oa_conference_sign n ");
        }else {
            sb.append(" LEFT JOIN product_oa_conference_visit n ");
        }
        sb.append(" on b.staff_id=n.user_id and n.meeting_uuid=? ");
        sb.append(" )c");
        if(type.equals("1")){
            sb.append("  where c.sign_status is NULL");
        }else {
            sb.append("  where c.visit_status is NULL");
        }
 
        DataTableEntity dataTableEntity = baseDao.listTable(sb.toString(), params.toArray());
          String user_ids = "";
        for (int i = 0; i < dataTableEntity.getRows(); i++) {
            FieldSetEntity fieldSetEntity = dataTableEntity.getFieldSetEntity(i);
            if((i+1)==dataTableEntity.getRows()){
                user_ids=user_ids+fieldSetEntity.getString("staff_id");
            }else {
                user_ids=user_ids+fieldSetEntity.getString("staff_id")+",";
            }
 
        }*/
        String content="";
        if(type.equals("1")){
            content="会议将开始签到,"+product_oa_conference_apply.getString("meeting_topic")+"-"+product_oa_conference_apply.getString("start_time")+",请按时签到";
        }else {
            content="您有场会议需要参与,"+product_oa_conference_apply.getString("meeting_topic")+"-"+product_oa_conference_apply.getString("start_time")+",请查看会议详情";
        }
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        int user_id = currentUser.getUser_id();
        String send_user=user_id+"";
        //String reminder_mode = product_oa_conference_apply.getString("reminder_mode");
     /*   //短信
        if(reminder_mode.equals("0")){
        }
        //邮件
        if(reminder_mode.equals("1")){
 
        }
        //系统消息
        if(reminder_mode.equals("2")){
 
        }*/
        WebsocketMesssageServiceThread.getInstance().appendMessage(user_ids, content, "会议提醒", 1,"1", "", "", send_user, 1, 0, 0);
 
    }
 
 
    /**
     * 会议室使用情况
     *
     * @return
     * @throws BaseException
     */
    public String getConferenceRoomUsage(FieldSetEntity fse) throws BaseException {
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        String org_level_uuid = currentUser != null ? currentUser.getOrg_level_uuid() : null;
        if (currentUser == null || StringUtils.isEmpty(org_level_uuid)) {
            return null;
        }
        String clientType = currentUser.getClientType();
        System.out.println(clientType);
        String startTime = fse.getString("startTime");
        String endTime = fse.getString("endTime");
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT ");
        sql.append(" a.uuid, ");
        sql.append(" b.uuid apply_uuid, ");
        sql.append(" a.room_name, ");
        sql.append(" b.meeting_topic, ");
        if (com.product.admin.config.CmnConst.MOBILE_CLIENT_TYPE.equalsIgnoreCase(clientType)) {
            //移动端
            sql.append(" date_format(b.start_time,'%Y-%m-%d %H:%i:%s') start_time, ");
            sql.append(" date_format(b.end_time,'%Y-%m-%d %H:%i:%s') end_time, ");
        } else {
 
            sql.append(" b.start_time, ");
            sql.append(" b.end_time, ");
        }
        sql.append(" b.flow_flag, ");
        sql.append(" ( SELECT user_name FROM product_sys_users WHERE user_id = b.created_by ) proposer ");
        sql.append(" FROM ");
        sql.append(" product_oa_CONFERENCE_room_config a ");
        sql.append(" LEFT JOIN ( SELECT flow_flag,meeting_room,uuid,meeting_topic,start_time,end_time,created_by FROM  ");
        sql.append(" product_oa_conference_apply b WHERE ");
        sql.append("start_time>=? and start_time<=? or (end_time>=? and start_time<=?) ");
        sql.append(" and start_time is not null and end_time is not null and flow_flag in (1,2) ) b ");
        sql.append(" ON a.uuid = b.meeting_room ");
        sql.append(" WHERE ");
        sql.append(" a.`status` = 1 ");
        sql.append(" AND org_level_uuid = ? ");
        sql.append(" AND enabled_time <= now( ) ");
        sql.append(" GROUP BY ");
        sql.append(" a.uuid, ");
        sql.append(" b.uuid, ");
        sql.append(" a.room_name, ");
        sql.append(" b.meeting_topic, ");
        sql.append(" b.start_time, ");
        sql.append(" b.end_time, ");
        sql.append(" b.created_by,b.flow_flag ");
        sql.append(" ORDER BY ");
        sql.append(" b.start_time ");
        DataTableEntity dt = baseDao.listTable(sql.toString(), new Object[]{startTime, endTime, startTime, endTime, org_level_uuid});
        dt.getMeta().addAliasTable(CmnConst.PRODUCT_OA_CONFERENCE_APPLY, "b");
        baseDao.loadPromptData(dt);
        sql.setLength(0);
        if (!BaseUtil.dataTableIsEmpty(dt)) {
            if (!com.product.admin.config.CmnConst.MOBILE_CLIENT_TYPE.equalsIgnoreCase(clientType)) {
                List<String> weekRefer = new ArrayList<>();
                weekRefer.add("星期一");
                weekRefer.add("星期二");
                weekRefer.add("星期三");
                weekRefer.add("星期四");
                weekRefer.add("星期五");
                weekRefer.add("星期六");
                weekRefer.add("星期日");
                // key = 会议室 value :  key=星期几上午或下午 value=每次申请会议室的数据
                Map<String, Map<String, List<Map<Object, Object>>>> room = new HashMap<>();
                Map<String, String> room_name = new LinkedHashMap<>();
                for (int i = 0; i < dt.getRows(); i++) {
                    FieldSetEntity fs = dt.getFieldSetEntity(i);
                    String uuid = fs.getUUID();
                    Map<String, List<Map<Object, Object>>> data = room.get(uuid);
                    if (data == null) {
                        data = new HashMap<>();
                        room_name.put(uuid, fs.getString("room_name"));
                        room.put(uuid, data);
                    }
                    putMeetingToWeek(data, fs, fse);
                }
                HashMap<String, Object> objectObjectHashMap = new HashMap<>();
                objectObjectHashMap.put("room", room);
                return BaseUtil.success(room_name, objectObjectHashMap);
            } else {
                //移动端
                List<Map<String, String>> roomList = !fse.getBoolean("roomList") ? new ArrayList<>() : null;
                Map<String, List<Object>> meetingRecordMap = new HashMap<>();
                for (int i = 0; i < dt.getRows(); i++) {
                    FieldSetEntity fs = dt.getFieldSetEntity(i);
                    JSONObject jsonObject = BaseUtil.fieldSetEntityToJson(fs);
                    String roomUid = fs.getString(CmnConst.UUID);
                    List<Object> meetingRecordList = meetingRecordMap.get(roomUid);
                    if (meetingRecordList == null) {
                        meetingRecordList = new ArrayList<>();
                        meetingRecordMap.put(roomUid, meetingRecordList);
                        Map<String, String> room = new HashMap<>();
                        room.put("name", fs.getString("room_name"));
                        room.put("value", fs.getUUID());
                        if (roomList != null) {
                            roomList.add(room);
                        }
                    }
                    if (!StringUtils.isEmpty(fs.getString("apply_uuid"))) {
                        Date start_time = fs.getDate("start_time");
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(start_time);
                        jsonObject.put("year", calendar.get(Calendar.YEAR));
                        jsonObject.put("month", calendar.get(Calendar.MONTH) + 1);
                        jsonObject.put("day", calendar.get(Calendar.DAY_OF_MONTH));
                        Format f1 = new DecimalFormat("00");
                        jsonObject.put("start_h_m", calendar.get(Calendar.HOUR_OF_DAY) + ":" + f1.format(calendar.get(Calendar.MINUTE)));
                        calendar.setTime(fs.getDate("end_time"));
                        jsonObject.put("end_h_m", calendar.get(Calendar.HOUR_OF_DAY) + ":" + f1.format(calendar.get(Calendar.MINUTE)));
                        meetingRecordList.add(jsonObject);
                    }
                }
                Map<String, Object> result = new HashMap<>();
                result.put("roomList", roomList);
                result.put("meetingRecord", meetingRecordMap);
                return BaseUtil.success(result);
            }
        }
        return null;
    }
 
    private void putMeetingToWeek(Map<String, List<Map<Object, Object>>> data, FieldSetEntity fs, FieldSetEntity fse) throws BaseException {
 
        Date start_time = fs.getDate(CmnConst.START_TIME);
        // 周几
        if (start_time == null) {
            return;
        }
        String week = BaseUtil.getWeek(start_time);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(start_time);
        //  0 上午 1 下午
        int am_pm = calendar.get(Calendar.HOUR_OF_DAY) != 12 ? calendar.get(Calendar.AM_PM) : 0;
        Date end_time = fs.getDate(CmnConst.END_TIME);
        calendar.setTime(end_time);
        int end_am_pm = calendar.get(Calendar.HOUR_OF_DAY) != 12 ? calendar.get(Calendar.AM_PM) : 0;
        ;
        //是否同一天
        boolean samedate = DateUtils.isSameDay(start_time, end_time);
        if (end_am_pm == am_pm && samedate) {
            // 开始时间 和结束时间属于同一时间段且是同一天
        } else {
            if (end_am_pm != am_pm && samedate) {
                // 开始时间 和结束时间不属于同一时间段且是同一天
                putMeetingToWeek(data, week, end_am_pm, fs.getValues());
            } else {
                // 不在同一天
                //获取开始到结束的每一天
                List<Object> timePeriodDate = BaseUtil.getTimePeriodDate(start_time, end_time, false);
                putMeetingToWeek(data, timePeriodDate, fse, fs, am_pm);
            }
        }
        //记录的开始时间不能大于每周的开始时间
        if (!start_time.before(fse.getDate("startTime"))) {
            List<Map<Object, Object>> maps = data.get(week + "_" + am_pm);
            if (maps == null) {
                maps = new ArrayList<>();
                data.put(week + "_" + am_pm, maps);
            }
            maps.add(fs.getValues());
        }
    }
 
    private void putMeetingToWeek(Map<String, List<Map<Object, Object>>> data, List<Object> timePeriodDate, FieldSetEntity fse, FieldSetEntity fs, int am_pm) {
        Calendar calendar = Calendar.getInstance();
        Date start_time = fs.getDate(CmnConst.START_TIME);
        Date end_time = fs.getDate(CmnConst.END_TIME);
        for (int j = 0; j < timePeriodDate.size(); j++) {
            //每天的date
            Date o = (Date) timePeriodDate.get(j);
 
            if (o.before(fse.getDate("startTime")) || fse.getDate("endTime").before(o)) {
                continue;
            }
            String week_evey = BaseUtil.getWeek(o);
            //是否是同一天
            if (DateUtils.isSameDay(start_time, o)) {
                //是否为上午时段
                if (am_pm == 0) {
                    putMeetingToWeek(data, week_evey, 1, fs.getValues());
                }
            } else if ((j + 1) < timePeriodDate.size()) {
                putMeetingToWeek(data, week_evey, 0, fs.getValues());
                putMeetingToWeek(data, week_evey, 1, fs.getValues());
            } else {
                SimpleDateFormat dtf = new SimpleDateFormat(CmnConst.YYYYMMDDHHMMSS);
                String date1 = dtf.format(o);
                String date2 = dtf.format(end_time);
                if (date1.equals(date2)) {
                    //最后结束日期
                    calendar.setTime(o);
                    int cc = calendar.get(Calendar.HOUR_OF_DAY) != 12 ? calendar.get(Calendar.AM_PM) : 0;
                    if (cc == 1) {
                        //如果最后一天是下午则加上 上午
                        putMeetingToWeek(data, week_evey, 0, fs.getValues());
                    }
                    putMeetingToWeek(data, week_evey, cc, fs.getValues());
                } else {
 
                }
            }
        }
    }
 
    private void putMeetingToWeek(Map<String, List<Map<Object, Object>>> data, String week, int am_pm, Map<Object, Object> values) {
        List<Map<Object, Object>> list = data.get(week + "_" + am_pm);
        if (list == null) {
            list = new ArrayList<>();
            data.put(week + "_" + am_pm, list);
        }
        Map<Object, Object> clone = new TreeMap<>();
        clone.putAll(values);
        list.add(clone);
    }
 
    /**
     * 会议室详情
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findConferenceApply(FieldSetEntity fse) throws BaseException {
        FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntity(fse.getTableName(), fse.getUUID(), true);
        DataTableEntity dt = new DataTableEntity();
        dt.addFieldSetEntity(fieldSetEntity);
        if (!com.product.admin.config.CmnConst.MOBILE_CLIENT_TYPE.equals(SpringMVCContextHolder.getCurrentUser().getClientType())) {
            baseDao.loadPromptData(dt);
            fieldSetEntity.setValue("flow_flag", fieldSetEntity.getString("flow_flag_save_value"));
            fieldSetEntity.setValue(CmnConst.CREATED_BY, fieldSetEntity.getString(CmnConst.CREATED_BY + "_save_value"));
            fieldSetEntity.setValue("meetint_type", fieldSetEntity.getString("meetint_type_save_value"));
        }
 
 
        //存储访问记录
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        String fliter="meeting_uuid='"+fse.getUUID()+"' and  user_id='"+currentUser.getUser_id()+"'";
        DataTableEntity product_oa_conference_visit = baseDao.listTable("product_oa_conference_visit", fliter);
 
        if(product_oa_conference_visit.getRows()!=0){
            FieldSetEntity fieldSetEntity1 = product_oa_conference_visit.getFieldSetEntity(0);
            Integer visit_count = fieldSetEntity1.getInteger("visit_count");
            visit_count++;
            fieldSetEntity1.setValue("visit_count",visit_count);
            fieldSetEntity1.setValue("visit_date_new",new Date());
            baseDao.update(fieldSetEntity1);
        }else {
        FieldSetEntity fieldSetEntityVisit = new FieldSetEntity();
        fieldSetEntityVisit.setTableName("product_oa_conference_visit");
        fieldSetEntityVisit.setValue("visit_user",currentUser.getUser_name());
        fieldSetEntityVisit.setValue("user_id",currentUser.getUser_id());
        fieldSetEntityVisit.setValue("org_level_uuid","00000000-0000-0000-0000-000000000000");
        fieldSetEntityVisit.setValue("organization",currentUser.getDept_uuid());
        fieldSetEntityVisit.setValue("organization_name",currentUser.getCurrentDept().getString("org_level_name"));
        fieldSetEntityVisit.setValue("visit_date_first",new Date());
        fieldSetEntityVisit.setValue("visit_date_new",new Date());
        fieldSetEntityVisit.setValue("visit_count",1);
        fieldSetEntityVisit.setValue("visit_status","已访问");
        fieldSetEntityVisit.setValue("meeting_uuid",fse.getUUID());
        BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fieldSetEntityVisit);
        baseDao.add(fieldSetEntityVisit);
        }
 
 
        return fieldSetEntity;
    }
 
    /**
     * 会议申请列表
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public DataTableEntity getListConferenceApply(FieldSetEntity fse) throws BaseException {
        String queryFilter = queryFilterService.getQueryFilter(fse);
 
        String dataFilter = permissionService.getDataFilter(CmnConst.ORG_LEVEL_UUID);
 
        StringBuilder filter = new StringBuilder();
        if (!StringUtils.isEmpty(queryFilter)) {
            filter.append(queryFilter);
        }
        String created_by_field = fse.getString("created_by_field");
        if (!StringUtils.isEmpty(created_by_field)) {
            Integer userId = SpringMVCContextHolder.getCurrentUser().getUser_id();
            if (filter.length() > 0) {
                filter.append("and (" + created_by_field + " = " + userId + ") ");
            } else {
                filter.append(" ( ");
                filter.append(created_by_field + " = " + userId);
                filter.append(" ) ");
            }
        } else if (!StringUtils.isEmpty(dataFilter)) {
            if (filter.length() > 0) {
                filter.append("and (" + dataFilter + ") ");
            } else {
                filter.append(" ( ");
                filter.append(dataFilter);
                filter.append(" ) ");
            }
        }
        if (!StringUtils.isEmpty(fse.getString("filter"))) {
            if (filter.length() > 0) {
                filter.append("and (" + fse.getString("filter") + ") ");
            } else {
                filter.append(" ( ");
                filter.append(fse.getString("filter"));
                filter.append(" ) ");
            }
        }
        DataTableEntity dt = baseDao.listTable(fse.getTableName(), filter.toString(), new Object[]{}, null, "ifnull(updated_utc_datetime,created_utc_datetime) desc", fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE), false);
        baseDao.loadPromptData(dt);
        return dt;
    }
 
    public void taskMeetingRminder() {
        DataTableEntity dt = baseDao.listTable(CmnConst.PRODUCT_OA_CONFERENCE_APPLY, " flow_flag=2 and ( to_remind IS NULL OR to_remind = 0 ) AND reminder_time > 0 and reminder_time>=(( UNIX_TIMESTAMP(start_time ) - UNIX_TIMESTAMP( now( ) ) ) / 60) ", new Object[]{});
        baseDao.loadPromptData(dt);
        DataTableEntity dtt = new DataTableEntity();
        if (!BaseUtil.dataTableIsEmpty(dt)) {
            for (int i = 0; i < dt.getRows(); i++) {
                Set<String> users = new HashSet<>();
                String created_user = dt.getString(i, CmnConst.CREATED_BY + "_save_value");
                //记录人
                users.add(dt.getString(i, "record_man"));
                //主持人
                users.add(dt.getString(i, "record_master"));
                //参加者
                String[] participators = dt.getString(i, "participator").split(",");
                users.addAll(Arrays.asList(participators));
                String uuid = dt.getFieldSetEntity(i).getUUID();
                String date = dt.getDate(i, CmnConst.START_TIME, CmnConst.YYYYMMDDHHMMSS);
                if (date == null) {
                    date = "";
                }
                users.remove(created_user);
                Iterator<String> iterator = users.iterator();
                WebsocketMesssageServiceThread.getInstance().appendMessage(dt.getString(i, CmnConst.CREATED_BY + "_save_value"), "您发起的会议将在" + date + "开始", "您有新的会议提醒", dt.getInt(i, CmnConst.CREATED_BY + "_save_value"), "4", "162028970334036i3V1L458?uuid=" + uuid, CmnConst.PRODUCT_OA_CONFERENCE_APPLY, uuid, dt.getInt(i, CmnConst.CREATED_BY + "_save_value"), 0, 0);
                while (iterator.hasNext()) {
                    String send_user = iterator.next();
                    WebsocketMesssageServiceThread.getInstance().appendMessage(send_user, "来自" + dt.getString(i, CmnConst.CREATED_BY) + "发起的会议将在" + date + "开始", "您有新的会议提醒", dt.getInt(i, CmnConst.CREATED_BY + "_save_value"), "4", "162028970334036i3V1L458?uuid=" + uuid, CmnConst.PRODUCT_OA_CONFERENCE_APPLY, uuid, dt.getInt(i, CmnConst.CREATED_BY + "_save_value"), 0, 0);
                }
                dt.getMeta().setFields(new Object[]{CmnConst.UUID, "to_remind"});
                dt.getFieldSetEntity(i).getMeta().setFields(new Object[]{CmnConst.UUID});
                dt.setFieldValue(i, "to_remind", 1);
 
            }
            baseDao.update(dt);
        }
    }
}