renkang
2024-12-23 560c0bd2c5462f6838901d89fd20e2fc1b4763a9
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
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
package com.doumee.service.business.impl;
 
import com.alibaba.fastjson.JSONObject;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.biz.system.SystemUserBiz;
import com.doumee.config.DataSyncConfig;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.erp.ErpConstants;
import com.doumee.core.erp.ErpTool;
import com.doumee.core.erp.model.openapi.request.erp.ApproveAddRequest;
import com.doumee.core.erp.model.openapi.request.erp.UserInfoRequest;
import com.doumee.core.erp.model.openapi.response.erp.ApproveInfoResponse;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.haikang.model.HKConstants;
import com.doumee.core.haikang.model.param.BaseResponse;
import com.doumee.core.haikang.model.param.request.FacePictureCheckRequest;
import com.doumee.core.haikang.model.param.request.VisitAppointmentOutRequest;
import com.doumee.core.haikang.model.param.request.VisitAppointmentRequest;
import com.doumee.core.haikang.model.param.respose.FacePictureCheckResponse;
import com.doumee.core.haikang.model.param.respose.VisitAppointmentResponse;
import com.doumee.core.haikang.service.HKService;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.*;
import com.doumee.core.wx.wxPlat.WxPlatNotice;
import com.doumee.dao.admin.response.InterestedListVO;
import com.doumee.dao.admin.response.PCWorkPlatformDataVO;
import com.doumee.dao.business.*;
import com.doumee.dao.business.dao.CompanyMapper;
import com.doumee.dao.business.dao.SmsConfigMapper;
import com.doumee.dao.business.dao.SmsEmailMapper;
import com.doumee.dao.business.dto.ResetPasswordDTO;
import com.doumee.dao.business.join.DeviceJoinMapper;
import com.doumee.dao.business.join.VisitsJoinMapper;
import com.doumee.dao.business.model.*;
 
import com.doumee.dao.system.SystemUserMapper;
import com.doumee.dao.system.dto.ResetSystemUserPwdDTO;
import com.doumee.dao.system.join.NoticesJoinMapper;
import com.doumee.dao.system.model.Notices;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.dao.web.reqeust.AuditApproveDTO;
import com.doumee.dao.web.reqeust.ErpVisitDTO;
import com.doumee.dao.web.reqeust.ErpWithVisitDTO;
import com.doumee.dao.web.reqeust.VisitRecordDTO;
import com.doumee.dao.web.response.VisitDetailVO;
import com.doumee.dao.web.response.VisitRecordVO;
import com.doumee.service.business.ApproveService;
import com.doumee.service.business.InterfaceLogService;
import com.doumee.service.business.SmsEmailService;
import com.doumee.service.business.VisitsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doumee.service.business.impl.hksync.HkSyncVisitServiceImpl;
import com.doumee.service.business.third.EmayService;
import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.*;
import java.util.Date;
import java.util.stream.Collectors;
 
/**
 * 访客申请信息表Service实现
 * @author 江蹄蹄
 * @date 2023/11/30 15:33
 */
@Service
public class VisitsServiceImpl implements VisitsService {
 
    @Autowired
    private RetentionMapper retentionMapper;
    @Autowired
    private VisitsMapper visitsMapper;
    @Autowired
    private ApproveMapper approveMapper;
    @Autowired
    private ApproveParamMapper approveParamMapper;
    @Autowired
    private DeviceRoleMapper deviceRoleMapper;
    @Autowired
    private ProblemLogMapper problemLogMapper ;
    @Autowired
    private MemberMapper memberMapper ;
    @Autowired
    private VisitsJoinMapper visitsJoinMapper;
    @Autowired
    private CompanyMapper companyMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private SystemUserBiz systemUserBiz;
    @Autowired
    private DeviceJoinMapper deviceJoinMapper;
    @Autowired
    private ErpTool erpTool;
 
    @Autowired
    private WxPlatNotice wxPlatNotice;
 
    @Autowired
    private InterfaceLogService interfaceLogService;
    @Autowired
    private DataSyncConfig dataSyncConfig;
    @Autowired
    private SmsEmailService smsEmailService;
    @Autowired
    private SystemUserMapper systemUserMapper;
    @Autowired
    private ApproveService approveService;
    @Autowired
    private NoticesJoinMapper noticesJoinMapper;
    @Autowired
    private InoutDayCountMapper inoutDayCountMapper;
    @Autowired
    private CarEventMapper carEventMapper;
 
    @Autowired
    private SmsConfigMapper smsConfigMapper;
 
    @Autowired
    private SmsEmailMapper smsEmailMapper;
 
    @Autowired
    private EmayService emayService;
 
 
 
    @Override
    public Integer create(Visits visits) {
        visitsMapper.insert(visits);
        return visits.getId();
    }
 
 
    @Override
    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
    public void createFKForErp(ErpVisitDTO erpVisitDTO){
            if (Objects.isNull(erpVisitDTO)
                    || StringUtils.isBlank(erpVisitDTO.getName())
                    || StringUtils.isBlank(erpVisitDTO.getPhone())
                    || StringUtils.isBlank(erpVisitDTO.getCompanyName())
                    || Objects.isNull(erpVisitDTO.getIdcardType())
                    || StringUtils.isBlank(erpVisitDTO.getIdcardNo())
                    || Objects.isNull(erpVisitDTO.getStarttime())
                    || Objects.isNull(erpVisitDTO.getEndtime())
                    || StringUtils.isBlank(erpVisitDTO.getFaceImg())
                    || StringUtils.isBlank(erpVisitDTO.getDoors())
                    || Objects.isNull(erpVisitDTO.getReceptMemberId())
                    || Objects.isNull(erpVisitDTO.getErpId())
            ) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,信息填写不正确!");
            }
            if (erpVisitDTO.getEndtime().getTime() <= erpVisitDTO.getStarttime().getTime()) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,预约结束时间必须大于开始时间!");
            }
            if (Constants.equalsInteger(Constants.ZERO, erpVisitDTO.getIdcardType()) && erpVisitDTO.getIdcardNo().length() != 18
                //&&!IdcardUtil.isValidCard(visits.getIdcardNo())
            ) {
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,身份证号码有误,请核实后重试!");
            }
 
            Visits visits = new Visits();
            //根据被访问人ERP主键查询系统内人员主键信息
            Member member = memberMapper.selectOne(new QueryWrapper<Member>().lambda()
                    .eq(Member::getIsdeleted, Constants.ZERO).eq(Member::getType, Constants.memberType.internal)
                    .eq(Member::getErpId, erpVisitDTO.getReceptMemberId()).last("limit 1"));
            if (Objects.isNull(member)) {
                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "未查询到被访问人信息");
            }
            if (Objects.isNull(member.getCanVisit()) || member.getCanVisit().equals(Constants.ZERO)) {
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "当前被访问人无法被访问");
            }
            BeanUtils.copyProperties(erpVisitDTO, visits);
            //设置内部系统人员主键
            visits.setReceptMemberId(member.getId());
            visits.setSourceType(Constants.ONE);
            List<ErpWithVisitDTO> erpWithVisitDTOList = erpVisitDTO.getErpWithVisitDTOList();
            if (CollectionUtils.isNotEmpty(erpWithVisitDTOList)) {
                List<Visits> visitsList = new ArrayList<>();
                for (ErpWithVisitDTO erpWithVisitDTO : erpWithVisitDTOList) {
                    Visits withVisits = new Visits();
                    BeanUtils.copyProperties(erpWithVisitDTO, withVisits);
                    withVisits.setCompanyName(visits.getCompanyName());
                    withVisits.setReason(visits.getReason());
                    visitsList.add(withVisits);
                }
                visits.setWithUserList(visitsList);
            }
            this.createFk(visits,true,Constants.ONE);
    }
 
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    void saveInterfaceLog(Object param, String path, String result, Integer type) {
        InterfaceLog interfaceLog=new InterfaceLog();
        interfaceLog.setType(type);
        interfaceLog.setCreateDate(new Date());
        interfaceLog.setIsdeleted(Constants.ZERO);
        if(param!=null){
            interfaceLog.setRequest(JSONObject.toJSONString(param));
        }
        interfaceLog.setPlat(Constants.ONE);
        interfaceLog.setRepose(result);
        interfaceLog.setName(path);
        interfaceLog.setUrl(path);
        interfaceLogService.create(interfaceLog);
    }
 
 
    /**
     * 普通访客申请
     * @param visits
     * @return
     */
    @Override
    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
    public Integer createFk(Visits visits,Boolean isERP,Integer source) {
        isValidBaseParam(visits);
        //检查是否必须答题,并且符合答题要求
        ProblemLog problemLog = isValidProblemLog(visits,source);
        //获取申请的海康访问门禁组信息
        getHkDeviceRoles(visits,isERP);
        //检验拜访人是否合法
        Member visitMember = isValideVisitedUser(visits.getReceptMemberId());
        if(Constants.equalsInteger(Constants.ZERO, visits.getIdcardType())
                &&visits.getIdcardNo().length()!=18
        ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,身份证号码有误,请核实后重试!");
        }
        Date date = new Date();
        //创建时间
        visits.setCreateDate(date);
        //随行人员数量
        visits.setMemberNum(Constants.ZERO);
        //访客信息(使用身份证号查询是否已存在该普通访客,没有则新增,存在则更新openid等信息),包括随访人员校验和处理
        Member member = dealMemberAndVisits(visits);
        visits.setMemberId(member.getId());
        visits.setVisitType(Integer.valueOf(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.MDJ_VISIT_REQUIRED).getCode()));
        //初始化访客信息
        initVisitInfo(visits,date);
 
        if(StringUtils.isNotBlank(visits.getFaceImg())&&(Constants.equalsInteger(visits.getType(),Constants.ZERO)|| Constants.equalsInteger(visits.getType(),Constants.TWO))){
            //人脸评分
            FacePictureCheckRequest param = new FacePictureCheckRequest();
            String prefixUrl = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode() +
                    systemDictDataBiz.queryByCode(Constants.FTP,Constants.MEMBER_IMG).getCode();
            param.setFacePicUrl(prefixUrl + visits.getFaceImg());
            BaseResponse<FacePictureCheckResponse> response = HKService.facePictureCheck(param);
            if(response == null || !StringUtils.equals(response.getCode(), HKConstants.RESPONSE_SUCCEE)){
                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,人脸评分获取数据失败~");
            }
            FacePictureCheckResponse facePictureCheckResponse = response.getData();
            if(Objects.isNull(facePictureCheckResponse) || Objects.isNull(facePictureCheckResponse.getCheckResult())){
                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,人脸评分获取数据失败~");
            }
            if(!facePictureCheckResponse.getCheckResult()){
                throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), facePictureCheckResponse.getStatusMessage());
            }
        }
 
        visitsMapper.insert(visits);
 
        //发起ERP审批申请
        if(dataSyncConfig.getVisitorDataOrigin().equals(Constants.ONE)){
            String erpId = startSendErpCheck(visits,visitMember);
            if(StringUtils.isNotBlank(erpId)){
                visits.setErpId(erpId);
                visits.setStatus(Constants.VisitStatus.submitCheck);
                visitsMapper.updateById(visits);
            }else{
                throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,发起拜访审批申请失败!");
            }
            //发送微信公众号通知
            wxPlatNotice.sendVisitAuditTemplateNotice(visits,
                    systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_PREFIX).getCode(),
                    systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_AUDIT_VISIT).getCode());
        }else if(dataSyncConfig.getVisitorDataOrigin().equals(Constants.ZERO)){
            visits.setStatus(Constants.VisitStatus.waitCheck);
            visitsMapper.updateById(visits);
            approveService.createApproveFlow(visits.getType(),visits.getId(),visits.getReceptMemberId());
        }else{
            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,发起拜访审批申请失败!");
        }
        initWithVisitInfo(visits);
        updateProblemLog(visits,problemLog,member);
        //创建审批记录
        createApprove(visits,visitMember);
 
        return visits.getId();
    }
 
 
    @Override
    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
    public Integer visitReporting(Visits visits) {
        visits.setSourceType(Constants.ZERO);
        isValidBaseParam(visits);
        //检验被拜访人是否合法
        Member visitMember = isValideVisitedUser(visits.getMemberId());
        Date date = new Date();
        //创建时间
        visits.setCreateDate(date);
        //访客报备
        visits.setIsdeleted(Constants.ZERO);
        visits.setType(Constants.TWO);
        visits.setReceptMemberId(visitMember.getId());
        visits.setStatus(Constants.VisitStatus.waitCheck);
        visits.setVisitType(Integer.valueOf(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.MDJ_VISIT_REQUIRED).getCode()));
        visits.setIdcardNo(DESUtil.decrypt(Constants.EDS_PWD, visitMember.getIdcardNo()));
        //初始化访客信息
//        initVisitInfo(visits,date);
        visitsMapper.insert(visits);
        approveService.createApproveFlow(visits.getType(),visits.getId(),visits.getReceptMemberId());
        return visits.getId();
    }
 
 
 
 
 
    /**
     * 创建审批记录
     * @param visits
     * @param visitMember
     */
    public void createApprove(Visits visits,Member visitMember){
        List<Integer> approveIds = new ArrayList<>();
        ApproveParam approveParam = null;//this.getApproveIds(1,visitMember,approveIds);
        //创建待审批记录
        //获取审批配置主键
        Integer firstApproveId = this.checkFirstAudit();
        //内部人员创建 且创建人与被访问人相同
        if(!Objects.isNull(visits.getCreateMemberId())//内部人员发布
                &&visits.getCreateMemberId().equals(visitMember.getId())//创建人员与被访问人员是否是同一人
                &&!Objects.isNull(firstApproveId)//审批配置第一级为 被访问人审批
        ){
            approveParam = this.getApproveIds(2,visitMember,approveIds);
            Approve approve = new Approve();
            approve.setCreateDate(new Date());
            approve.setIsdeleted(Constants.ZERO);
            approve.setCheckInfo("自动审批");
            approve.setTemplatId(firstApproveId);
            approve.setIsEndCheck(Constants.ZERO);
            approve.setType(Constants.ZERO);
            approve.setLevel(Constants.ONE);
            approve.setObjId(visits.getId());
            approveMapper.insert(approve);
            if(!CollectionUtils.isNotEmpty(approveIds)){
                approve.setIsEndCheck(Constants.ONE);
                visits.setStatus(Constants.TWO);
                visitsMapper.updateById(visits);
                //存储抄送记录
                this.saveCopyFor(visits.getId());
            }
        }else{
            approveParam = this.getApproveIds(null,visitMember,approveIds);
            if(!CollectionUtils.isNotEmpty(approveIds)){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"无有效的审批配置,请联系管理员");
            }
        }
        if(!Objects.isNull(approveIds)){
            //创建下一级审批记录
            this.saveAuditRecord(visits.getId(),approveIds,approveParam);
        }
    }
 
 
    /**
     * 审批 审批记录 或签 审批通过进入下一步  会签 检测是否是最后一条待审批
     * @param auditApproveDTO
     */
    @Override
    public void auditApprove(AuditApproveDTO auditApproveDTO){
        Approve approve = approveMapper.selectById(auditApproveDTO.getId());
        if(Objects.isNull(approve)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(approve.getStatus().equals(Constants.approveStatus.wait)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"审批记录已处理!");
        }
        Visits visits = visitsMapper.selectById(approve.getObjId());
        if(Objects.isNull(visits)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(!auditApproveDTO.getMemberId().equals(approve.getChekorId())){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"人员信息匹配错误!");
        }
        //被访人
        Member visitMember = memberMapper.selectById(visits.getReceptMemberId());
        List<Integer> approveIds = new ArrayList<>();
        ApproveParam approveParam = this.getApproveIds(approve.getLevel()+1,visitMember,approveIds);
 
        approve.setStatus(auditApproveDTO.getStatus());
        approve.setEditDate(new Date());
        approve.setChekorId(auditApproveDTO.getMemberId());
        approve.setCheckInfo(auditApproveDTO.getCheckInfo());
        approveMapper.updateById(approve);
 
        if(auditApproveDTO.getStatus().equals(Constants.approveStatus.pass)){
            if(approve.getApproveType().equals(Constants.ONE)){
                //会签 查询是否是最后一条记录 如果是最后一条记录 则生成下级审批记录 如果是最后一级,则进行审批确认
                if(approveMapper.selectCount(new QueryWrapper<Approve>().lambda()
                        .eq(Approve::getObjId,visits.getId())
                        .eq(Approve::getLevel,approve.getLevel())
                        .ne(Approve::getId,approve.getId())
                )<=Constants.ZERO){
                    //当前审批级别 最后一条待审批记录
                    if(!CollectionUtils.isNotEmpty(approveIds)){
                        //没有下级审批流则 修改访客记录主键
                        visits.setStatus(auditApproveDTO.getStatus());
                        visits.setCheckDate(new Date());
                        visits.setCheckorId(auditApproveDTO.getMemberId());
                        visitsMapper.updateById(visits);
                    }else{
                        this.saveAuditRecord(visits.getId(),approveIds,approveParam);
                    }
                }
            }else{
                //或签
                approveMapper.update(null,new UpdateWrapper<Approve>().lambda()
                        .set(Approve::getStatus,Constants.approveStatus.otherDeal)
                        .set(Approve::getEditDate,new Date())
                        .set(Approve::getCheorId,auditApproveDTO.getMemberId())
                        .eq(Approve::getObjId,visits.getId())
                        .eq(Approve::getStatus,Constants.approveStatus.wait)
                        .ne(Approve::getId,approve.getId())
                        .eq(Approve::getLevel,approve.getLevel())
                );
 
                if(!CollectionUtils.isNotEmpty(approveIds)){
                    //没有下级审批流则 修改访客记录主键
                    visits.setStatus(auditApproveDTO.getStatus());
                    visits.setCheckDate(new Date());
                    visits.setCheckorId(auditApproveDTO.getMemberId());
                    visitsMapper.updateById(visits);
                }else{
                    this.saveAuditRecord(visits.getId(),approveIds,approveParam);
                }
 
            }
        }else if(auditApproveDTO.getStatus().equals(Constants.approveStatus.unPass)){
            visits.setStatus(auditApproveDTO.getStatus());
            visits.setCheckDate(new Date());
            visits.setCheckorId(auditApproveDTO.getMemberId());
            visitsMapper.updateById(visits);
 
            approveMapper.update(null,new UpdateWrapper<Approve>().lambda()
                    .set(Approve::getStatus,Constants.approveStatus.otherDeal)
                    .set(Approve::getEditDate,new Date())
                    .set(Approve::getCheorId,auditApproveDTO.getMemberId())
                    .eq(Approve::getObjId,visits.getId())
                    .eq(Approve::getStatus,Constants.approveStatus.wait)
                    .ne(Approve::getId,approve.getId())
                    .eq(Approve::getLevel,approve.getLevel())
            );
 
        }else{
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"审批状态错误!");
        }
    }
 
 
 
 
    /**
     * 存储抄送记录
     * @param visitId
     */
    public void  saveCopyFor(Integer visitId){
        ApproveParam approveParam = approveParamMapper.selectOne(new QueryWrapper<ApproveParam>().lambda()
                .eq(ApproveParam::getIsdeleted,Constants.ZERO)
                .eq(ApproveParam::getType,Constants.ONE)
                .eq(ApproveParam::getLevel,Constants.ONE)
                .last("limit 1"));
        if(Objects.isNull(approveParam)){
            return;
        }
        if(StringUtils.isNotBlank(approveParam.getObjIds())){
            String [] ids = approveParam.getObjIds().split(",");
            List<Approve> approveList = new ArrayList<>();
            for (String id:ids) {
                Approve approve = new Approve();
                approve.setCreateDate(new Date());
                approve.setIsdeleted(Constants.ZERO);
                approve.setCheckInfo("抄送记录");
                approve.setTemplatId(approveParam.getId());
                approve.setChekorId(Integer.valueOf(id));
                approve.setType(Constants.ONE);
                approve.setObjId(visitId);
                approveList.add(approve);
            }
            approveMapper.insert(approveList);
        }
    }
 
    /**
     * 存储下级审批记录
     * @param visitId
     * @param ids
     * @param approveParam
     */
    public void  saveAuditRecord(Integer visitId,List<Integer> ids,ApproveParam approveParam){
        if(CollectionUtils.isNotEmpty(ids)) {
            List<Approve> approveList = new ArrayList<>();
            for (Integer id:ids) {
                Approve approve = new Approve();
                approve.setCreateDate(new Date());
                approve.setIsdeleted(Constants.ZERO);
                approve.setStatus(Constants.ZERO);
                approve.setCheckInfo("抄送记录");
                approve.setTemplatId(approveParam.getId());
                approve.setLevel(approveParam.getLevel());
                approve.setApproveType(approveParam.getApproveType());
                approve.setChekorId(id);
                approve.setType(Constants.ONE);
                approve.setObjId(visitId);
                approveList.add(approve);
            }
            approveMapper.insert(approveList);
        }
    }
 
    /**
     * 判断一级审批人是否是创建人
     * @return
     */
    public Integer checkFirstAudit(){
        ApproveParam approveParam = approveParamMapper.selectOne(new QueryWrapper<ApproveParam>().lambda()
                .eq(ApproveParam::getIsdeleted,Constants.ZERO)
                .eq(ApproveParam::getType,Constants.ZERO)
                .eq(ApproveParam::getLevel,Constants.ONE)
                .eq(ApproveParam::getMemberType,Constants.ZERO)
                .last("limit 1"));
         return  Objects.isNull(approveParam)?null:approveParam.getId();
    }
 
 
    /**
     * 创建审批人员信息 若返回待审批人员主键列表为空,则无审批人员 抛出对应异常
     * @param level   处理级别
     * @param visitMember 被访人
     */
    public ApproveParam getApproveIds(Integer level,Member visitMember,List<Integer> ids){
        //查询审批配置项
        List<ApproveParam> allParam = approveParamMapper.selectList(new QueryWrapper<ApproveParam>().lambda()
                .eq(ApproveParam::getIsdeleted,Constants.ZERO)
                .eq(ApproveParam::getType,Constants.ZERO)
                .ge(!Objects.isNull(level),ApproveParam::getLevel,level)
                .orderByAsc(ApproveParam::getLevel));
        ApproveParam approveParam = new ApproveParam();
        //发送审批/抄送记录的用户主键集合
        ids.clear();
        if(!CollectionUtils.isNotEmpty(allParam)){
            if(Objects.isNull(level)){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未配置访客审批流,请联系管理员");
            }
        }else{
             approveParam = allParam.get(0);
            if(approveParam.getMemberType().equals(Constants.ZERO)){
                //被访人审批
                //添加审批人
                ids.add(visitMember.getId());
            }else if(approveParam.getMemberType().equals(Constants.ONE)){
                //指定人员审批
                String [] objIds = approveParam.getObjIds().split(",");
                for (String id:objIds) {
                    //添加审批人
                    ids.add(Integer.valueOf(id));
                }
            }else if(approveParam.getMemberType().equals(Constants.TWO)){
                //部门主管审批
                //审批部门
                Company auditCompany = this.getAuditCompanyHead(visitMember.getCompanyId(),approveParam.getObjLevel());
                if(Objects.isNull(auditCompany)){
                    //审批部门为空 自动流转下一级审批配置
                    level = level + 1;
                    return this.getApproveIds(level,visitMember,ids);
                }else{
                    //查询部门负责人
                    Member headMember = memberMapper.selectById(auditCompany.getHeadId());
                    if(Objects.isNull(headMember)){
                        //未查询到部门负责人
                        if(approveParam.getNoleaderOpt().equals(Constants.ONE)&&!Objects.isNull(auditCompany.getParentId())){
                            //由上级主管代替审核
                            auditCompany = companyMapper.selectOne(new QueryWrapper<Company>().lambda().eq(Company::getId,auditCompany.getParentId()));
                            if(Objects.isNull(auditCompany)){
                                //审批部门为空 自动流转下一级审批配置
                                level = level + 1;
                                this.getApproveIds(level,visitMember,ids);
                            }else{
                                headMember = memberMapper.selectById(auditCompany.getHeadId());
                                if(Objects.isNull(headMember)){
                                    //查询部门负责人 为空 自动流转下一级审批配置
                                    level = level + 1;
                                    return this.getApproveIds(level,visitMember,ids);
                                }else{
                                    //添加审批人
                                    ids.add(headMember.getId());
                                }
                            }
                        }else{
                            level = level + 1;
                            return this.getApproveIds(level,visitMember,ids);
                        }
                    }else{
                        //添加审批人
                        ids.add(headMember.getId());
                    }
 
                }
            }
        }
 
        return approveParam;
    }
 
    /**
     * 根据配置查询上级数据
     * @param companyId 直接部门
     * @param objLevel  查询级别
     */
    public Company getAuditCompanyHead(Integer companyId,Integer objLevel){
        Integer queryLevel = Constants.ONE;
        Integer nextCompanyId = companyId;
        Company auditCompany = new Company();
        while(queryLevel.equals(objLevel)){
            auditCompany = companyMapper.selectById(nextCompanyId);
            if(Objects.isNull(auditCompany)){
                return null;
            }
            nextCompanyId = auditCompany.getParentId();
        }
        return auditCompany;
    }
 
 
    /**
     * 校验必填项数据是否合法
     * @param visits
     */
    private void isValidBaseParam(Visits visits) {
        if(visits.getEndtime() == null
                || visits.getStarttime() == null
                ||  StringUtils.isBlank(visits.getReason())
                ||  StringUtils.isBlank( visits.getName())
                ||  StringUtils.isBlank( visits.getPhone())
                ||  StringUtils.isBlank( visits.getCompanyName())
                ||  Objects.isNull(visits.getType())
//                ||  StringUtils.isBlank( visits.getFaceImg() )
                || visits.getReceptMemberId() == null){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,信息填写不正确!");
        }
        if(Constants.equalsInteger(visits.getType(),Constants.ZERO)
             ||  Constants.equalsInteger(visits.getType(),Constants.ONE)){
            if(  visits.getIdcardType() == null
                    ||  StringUtils.isBlank( visits.getIdcardNo() ) || StringUtils.isBlank(visits.getFaceImg()) ){
                throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,信息填写不正确!");
            }
        }
        //访客报备
        if(Constants.equalsInteger(visits.getType(),Constants.TWO)
            && (StringUtils.isBlank( visits.getName())
                ||  StringUtils.isBlank( visits.getPhone())
                ||  StringUtils.isBlank( visits.getCompanyName())
                ||  StringUtils.isBlank( visits.getCarNos())
                ||  Objects.isNull(visits.getReceptMemberId()))
        ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,信息填写不正确!");
        }else if(visits.getType().equals(Constants.ONE) && StringUtils.isBlank(visits.getConstructionReason())){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,未填写施工事由!");
        }
        if(visits.getEndtime().getTime() <= visits.getStarttime().getTime()){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,离厂时间必须大于入厂时间!");//
        }
        if(visits.getEndtime().getTime() <= System.currentTimeMillis()){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,入厂时间必须大于当前时间!");//
        }
        if(!DateUtil.getDateLong(visits.getEndtime()).equals(DateUtil.getDateLong(visits.getStarttime()))){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,预约日期不可以跨天!");
        };
 
        if(visits.getSourceType().equals(Constants.ZERO)){
            String code = systemDictDataBiz.queryByCode(Constants.VISIT_CONFIG,Constants.VALIDATE_VISIT).getCode();
            int codenum =0;
            try {
                codenum = Integer.parseInt(code);
            }catch (Exception e){
 
            }
            if(StringUtils.isNotBlank(code)&&!StringUtils.equals(code,"0")){
                int betweenDays = DateUtil.daysBetweenDates11(visits.getEndtime(), visits.getStarttime())+1;
                if( betweenDays > codenum){
                    throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,预约总天数不能超过["+code+"天]!");
                }
            }
        }
    }
    private void isValidWithVisitParam(Visits visits,  List<Member> addList,  List<Member> updateList) {
        if(  StringUtils.isBlank( visits.getName())
                ||  StringUtils.isBlank( visits.getPhone())
                ||  visits.getIdcardType() == null
                ||  StringUtils.isBlank( visits.getFaceImg() )
                ||  StringUtils.isBlank( visits.getIdcardNo() )
                ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,信息填写不正确!");
        }
//        if(visits.getStarttime().getTime() < System.currentTimeMillis()){
//            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,预约开始时间必须大于当前时间!");//
//        }
        if(visits.getEndtime().getTime() <= visits.getStarttime().getTime()){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,预约结束时间必须大于开始时间!");//
        }
        if(isRepeatedMember(visits,addList,updateList)){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,手机号或身份证号出现重复数据,请修改后重新提交!");//
        }
    }
 
    private boolean isRepeatedMember(Visits visits, List<Member> addList, List<Member> updateList) {
        if(addList.size()>0){
            for(Member m :addList){
                if(StringUtils.equals(visits.getPhone(), m.getPhone()) || StringUtils.equals(visits.getIdcardNo(), m.getIdcardDecode())){
                    return true;
                }
            }
        }
        if(updateList.size()>0){
            for(Member m :updateList){
                if(StringUtils.equals(visits.getPhone(), m.getPhone()) || StringUtils.equals(visits.getIdcardNo(), m.getIdcardDecode())){
                    return true;
                }
            }
        }
        return  false;
    }
 
    private void initWithVisitInfo(Visits visits) {
        if(CollectionUtils.isNotEmpty(visits.getWithUserList())){
            for(Visits v :visits.getWithUserList()){
                v.setBirthday(Constants.getBirthdyByCardNo(v.getIdcardNo()));
                v.setParentId(visits.getId());
                v.setStarttime(visits.getStarttime());
                v.setEndtime(visits.getEndtime());
                v.setIsdeleted(Constants.ZERO);
                v.setCreateDate(visits.getCreateDate());
                v.setSex(Constants.getSexByCardNo(v.getIdcardNo()));
                v.setIdcardDecode(Constants.getTuominStr(v.getIdcardNo()));//脱敏身份证号
                v.setIdcardNo(DESUtil.encrypt(Constants.EDS_PWD, v.getIdcardNo()));//身份证号加密
                v.setErpId(visits.getErpId());
                v.setReceptMemberId(visits.getReceptMemberId());
                v.setMemberNum(Constants.ZERO);
                v.setHkStatus(Constants.ZERO);
                v.setReason(visits.getReason());
                v.setDoors(visits.getDoors());
                v.setType(visits.getType());
                v.setVisitType(visits.getVisitType());
                v.setStatus(visits.getStatus());
                v.setSourceType(visits.getSourceType());
            }
            //批量插入数据
            visitsMapper.insert(visits.getWithUserList());
        }
    }
 
    private void initVisitInfo(Visits visits,Date date) {
        visits.setHkStatus(Constants.ZERO);//未同步
        visits.setBirthday(Constants.getBirthdyByCardNo(visits.getIdcardNo()));
        visits.setStatus(Constants.ZERO);//待审批
        visits.setSex(Constants.getSexByCardNo(visits.getIdcardNo()));
        visits.setIdcardDecode(Constants.getTuominStr(visits.getIdcardNo()));//脱敏身份证号
        visits.setIdcardNo(DESUtil.encrypt(Constants.EDS_PWD, visits.getIdcardNo()));//身份证号加密
        visits.setIsdeleted(Constants.ZERO);
        visits.setCreateDate(date);
    }
 
    private String startSendErpCheck(Visits visits,Member visitMember) {
        ApproveAddRequest param = new ApproveAddRequest();
        List<Visits> withUserVisitsList = visits.getWithUserList();
        List<UserInfoRequest> withUserList = new ArrayList<>();
        UserInfoRequest mainUser = new UserInfoRequest();
        mainUser.setName(visits.getName());
        mainUser.setIdNo(DESUtil.decrypt(Constants.EDS_PWD, visits.getIdcardNo()));
        mainUser.setSex(visits.getSex());
        mainUser.setPhone(visits.getPhone());
        mainUser.setFaceImg(visits.getFaceImg());
        mainUser.setHealthImg(visits.getImgurl());
        withUserList.add(mainUser);
 
        if(CollectionUtils.isNotEmpty(withUserVisitsList)){
            for (Visits v:withUserVisitsList) {
                UserInfoRequest userInfoRequest = new UserInfoRequest();
                userInfoRequest.setName(v.getName());
                userInfoRequest.setIdNo(v.getIdcardNo());
                userInfoRequest.setSex(v.getSex());
                userInfoRequest.setPhone(v.getPhone());
                userInfoRequest.setFaceImg(v.getFaceImg());
                userInfoRequest.setHealthImg(v.getImgurl());
                withUserList.add(userInfoRequest);
            }
        }
        param.setWithUserList(withUserList);
 
        param.setId(visits.getId());
        param.setBeVisitedUserId(visitMember.getErpId());
        param.setVisitorWorkUint(visits.getCompanyName());
        param.setPurpose(visits.getReason());
        param.setStartTime(DateUtil.DateToStr(visits.getStarttime(),"yyyy-MM-dd HH:mm:ss"));
        param.setEndTime(DateUtil.DateToStr(visits.getEndtime(),"yyyy-MM-dd HH:mm:ss"));
        param.setBeVisitedOrgId(visitMember.getErpOrgId());
        if(StringUtils.isNotBlank(visits.getCarNos())){
            param.setCarNo(Arrays.asList(visits.getCarNos().split(",")));
        }
        if(StringUtils.isNotBlank(visits.getDoors())){
             List<DeviceRole> deviceRoleList = deviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda().in(DeviceRole::getId,Arrays.asList(visits.getDoors().split(","))));
             if(CollectionUtils.isNotEmpty(deviceRoleList)){
                 param.setRoleIds(deviceRoleList.stream().map(m->m.getId()).collect(Collectors.toList()));
                 param.setRoleNames(deviceRoleList.stream().map(m->m.getName()).collect(Collectors.toList()));
             }
        }
        ApproveInfoResponse response   = erpTool.submitApprove(ErpConstants.approveUrl,param);
        if(!Objects.isNull(response)){
            return visits.getId().toString();
        }
 
        return  null;
    }
 
 
 
    private String visitAppiontment(Visits visits) {
        VisitAppointmentRequest param = new VisitAppointmentRequest();
        param.setVisitStartTime(DateUtil.getISO8601Timestamp(visits.getStarttime()));
        param.setVisitEndTime(DateUtil.getISO8601Timestamp(visits.getStarttime()));
        BaseResponse<VisitAppointmentResponse>  res = HKService.visitAppiontment(param);
        if(res==null || !StringUtils.equals(res.getCode(), HKConstants.RESPONSE_SUCCEE) || res.getData()==null){
          //如果发起预约失败
            visits.setStatus(Constants.VisitStatus.xfFail);
        }else{
            visits.setStatus(Constants.VisitStatus.xfSuccess);
            visits.setHkStatus(Constants.ONE);
            visits.setHkId(res.getData().getAppointRecordId());
        }
        visits.setHkDate(visits.getCheckDate());
        return  res.getData().getAppointRecordId();
    }
 
    /**
     * 访客信息(使用身份证号查询是否已存在改普通访客,没有则新增,存在则更新openid等信息),包括随访人员校验和处理
     * @param visits
     * @return
     */
    private Member  dealMemberAndVisits(Visits visits ) {
        if(StringUtils.isNotBlank(visits.getOpenid())){
            //先清空原有访客的openid绑定关系
            memberMapper.update(null, new UpdateWrapper<Member>().lambda()
                    .eq(Member::getType,Constants.memberType.visitor)
                    .eq(Member::getOpenid,visits.getOpenid())
                    .set(Member::getOpenid,null)
            );
        }
        List<Member> addList = new ArrayList<>();
        List<Member> editList = new ArrayList<>();
        //申请人信息
        Member m = getMemberListParam(visits.getIdcardNo(),visits,addList,editList);
        //随访人员信息处理
        if(visits.getWithUserList()!= null && visits.getWithUserList().size()>0){
            for(Visits model:visits.getWithUserList()){
                model.setBirthday(Constants.getBirthdyByCardNo(model.getIdcardNo()));
                model.setStarttime(visits.getStarttime());
                model.setEndtime(visits.getEndtime());
                //校验随访人员填报数据合法性
                isValidWithVisitParam(model,addList,editList);
                model.setCreateDate(visits.getCreateDate());
                Member visitsMember = getMemberListParam(model.getIdcardNo(),model,addList,editList);
                model.setMemberId(visitsMember.getId());
            }
        }
        return  m;
    }
 
    private Member getMemberListParam(String cardno, Visits visits, List<Member> addList, List<Member> editList) {
        if(StringUtils.isNotBlank(visits.getCarNos())
                &&Objects.isNull(Constants.getVehiclePlateNo(visits.getCarNos()))
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,车牌号【"+visits.getCarNos()+"】不合法,请核实后重试~");
        }
        if(Constants.equalsInteger(Constants.ZERO, visits.getIdcardType())&&cardno.length()!=18
            //&&!IdcardUtil.isValidCard(cardno)
        ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,身份证【"+cardno+"】号码有误,请核实后重试!");
        }
        Member member = memberMapper.selectOne(new QueryWrapper<Member>().lambda()
                .eq(Member::getType,Constants.memberType.visitor)
                .eq(Member::getIdcardType,visits.getIdcardType())
                .eq(Member::getIdcardNo,DESUtil.encrypt(Constants.EDS_PWD, cardno)).last("limit 1" )
        );
        if(member == null){
            member = new Member();
            //如果用户不存在,则新增
            member.setCreateDate(visits.getCreateDate());
            member.setIsdeleted(Constants.ZERO);
            member.setIdcardNo(visits.getIdcardNo());
            member.setBirthday(Constants.getBirthdyByCardNo(cardno));
            member.setIdcardDecode(visits.getIdcardDecode());
            member.setIdcardNo(DESUtil.encrypt(Constants.EDS_PWD, cardno));//身份证号加密
            member.setIdcardDecode(Constants.getTuominStr(cardno));//脱敏手机号
            member.setFaceImg(visits.getFaceImg());
            member.setSex(Constants.getSexByCardNo(cardno));
            member.setImgurl(StringUtils.isNotBlank(visits.getImgurl())?visits.getImgurl():null);
            member.setIdcardType(visits.getIdcardType());
            member.setName(visits.getName());
            member.setPhone(visits.getPhone());
            member.setOpenid(visits.getOpenid());
            member.setType(Constants.memberType.visitor);
            member.setStatus(Constants.ZERO);
            member.setSex(Constants.getSexByCardNo(cardno));
            member.setHkStatus(Constants.ZERO);
            member.setErpStatus(Constants.ZERO);
            member.setVisitCompanyName(visits.getCompanyName());
            memberMapper.insert(member);
            // 新增访客
//            addList.add(member);
        }else{
            if(!Constants.equalsInteger(Constants.ZERO,member.getStatus() )){
                //如果用户状态异常,则提示
                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,【"+member.getName()+"】身份证号【"+cardno+"】在黑名单内,无法申请进入园区");
            }
            //核查预约用户是否存在未签离的预约记录
//            isExsitNoOutVisisRecord(member);
            member.setFaceImg(visits.getFaceImg());
            member.setImgurl(StringUtils.isNotBlank(visits.getImgurl())?visits.getImgurl():null);
            member.setEditDate(visits.getCreateDate());
            member.setIsdeleted(Constants.ZERO);
            member.setSex(Constants.getSexByCardNo(cardno));
            member.setIdcardNo(DESUtil.encrypt(Constants.EDS_PWD, cardno));//身份证号加密
            member.setIdcardDecode(Constants.getTuominStr(cardno));//脱敏身份证号
            member.setName(visits.getName());
            member.setPhone(visits.getPhone());
            member.setOpenid(visits.getOpenid());
            member.setSex(Constants.getSexByCardNo(cardno));
            member.setHkStatus(Constants.ZERO);
            member.setErpStatus(Constants.ZERO);
            member.setVisitCompanyName(visits.getCompanyName());
            memberMapper.updateById(member);
        }
        //根据手机号和身份证号码查询 当前预约的时间是否与其他预约记录有冲突
        if (visitsMapper.selectCount(new QueryWrapper<Visits>().lambda()
                        .notIn(Visits::getStatus,Constants.VisitStatus.cancel
                                ,Constants.VisitStatus.noPass
                                ,Constants.VisitStatus.xfFail
                                ,Constants.VisitStatus.signout
                                ,Constants.VisitStatus.invalid)
                .eq(Visits::getIdcardDecode, Constants.getTuominStr(cardno))
                .and(ms -> ms.eq(Visits::getPhone, visits.getPhone())
                        .or().eq(Visits::getIdcardDecode, Constants.getTuominStr(cardno)))
                .and(ms -> ms.apply(" visits.STARTTIME <= '" + DateUtil.DateToStr(visits.getStarttime(),"yyyy-MM-dd HH:mm:ss") + "' and visits.ENDTIME >= '" + DateUtil.DateToStr(visits.getStarttime(),"yyyy-MM-dd HH:mm:ss") + "' ")
                        .or().apply(" visits.STARTTIME <= '" + DateUtil.DateToStr(visits.getEndtime(),"yyyy-MM-dd HH:mm:ss") + "' and visits.ENDTIME >= '" + DateUtil.DateToStr(visits.getEndtime(),"yyyy-MM-dd HH:mm:ss") + "' ")
                        .or().apply(" visits.STARTTIME >= '" + DateUtil.DateToStr(visits.getStarttime(),"yyyy-MM-dd HH:mm:ss") + "' and visits.STARTTIME <= '" + DateUtil.DateToStr(visits.getEndtime(),"yyyy-MM-dd HH:mm:ss") + "' ")
                        .or().apply(" visits.ENDTIME >= '" + DateUtil.DateToStr(visits.getStarttime(),"yyyy-MM-dd HH:mm:ss") + "' and visits.ENDTIME <= '" + DateUtil.DateToStr(visits.getEndtime(),"yyyy-MM-dd HH:mm:ss") + "' ")
                )
        ) > Constants.ZERO) {
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,手机号【"+member.getPhone()+"】或身份证【"+ member.getIdcardDecode() +"】存在预约时间冲突,无法申请哦!");
        }
        return  member;
    }
 
    /**
     * 核查预约用户是否存在未签离的预约记录
     * @param member
     */
    private void isExsitNoOutVisisRecord(Member member) {
        Visits v = visitsMapper.selectOne(new QueryWrapper<Visits>().lambda()
                .eq(Visits::getPhone, member.getPhone())
                .eq(Visits::getStatus,Constants.VisitStatus.xfSuccess)
                .last(" limit 1" )
        );
        if(v !=null){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,手机号【"+member.getPhone()+"】存在未签离预约申请,不能重复申请哦!");
        }
 
 
 
    }
 
    private List<Member> isValideWithUsers(List<Visits> withUserList) {
        if(withUserList!= null && withUserList .size()>0){
            for(Visits model:withUserList){
 
            }
        }
 
        return null;
    }
 
    /**
     * 如果有答题记录,更新答题记录关联数据
     * @param visits
     * @param problemLog
     * @param member
     */
 
    private void updateProblemLog(Visits visits, ProblemLog problemLog,Member member) {
        if(problemLog!=null){
            problemLog.setEditDate(visits.getCreateDate());
            problemLog.setStatus(Constants.ONE);
            problemLog.setName(visits.getName());
            problemLog.setUserId(member.getId());
            problemLog.setPhone(member.getPhone());
            problemLog.setLogId(visits.getId());
            problemLogMapper.updateById(problemLog);
        }
    }
 
    /**
     *   检查访人是否合法
     * @param receptMemberId
     */
    private Member isValideVisitedUser(Integer receptMemberId) {
        Member member = memberMapper.selectById(receptMemberId);
        if(member == null || !Constants.equalsInteger(Constants.ZERO,member.getIsdeleted())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该拜访人暂时不能接受您的拜访申请!");
        }
        if(!Constants.equalsInteger(member.getStatus(), Constants.ZERO)){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该拜访人暂时不能接受您的拜访申请.");
        }
        if(!Constants.equalsInteger(Constants.ONE, member.getCanVisit())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该拜访人暂时不能接受您的拜访申请~");
        }
        if(StringUtils.isBlank(member.getHkId())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,该拜访人未下发暂时不能接受您的拜访申请~");
        }
        return  member;
    }
 
    /**
     * 是否需要答题
     * @param visits
     * @param source
     * @return
     */
    private ProblemLog isValidProblemLog(Visits visits,Integer source) {
        if(!Constants.equalsInteger(source,Constants.ZERO)){
            return null;
        }
        String required = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROBLEM_VISIT_REQUIRED).getCode();
        if(StringUtils.equals(required,Constants.ONE+"")&&visits.getSourceType()==Constants.ZERO&&!visits.getType().equals(Constants.TWO)){
            //如果必须答题,查找答题记录
            if(visits.getUserAnswerId() == null){
                throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请先按要求进行安全知识答题!");
            }
            ProblemLog log = problemLogMapper.selectById(visits.getUserAnswerId());
            if(log == null){
                throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请先按要求进行安全知识答题.");
            }
            if(log.getLogId() !=null&&log.getStatus().equals(Constants.ZERO)){
                throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请先按要求进行安全知识答题~");
            }
            return  log;
        }
        return null;
    }
 
    /**
     * 获取申请的海康访问门禁组信息
     * @param visits
     * @return
     */
    private String[] getHkDeviceRoles(Visits visits,Boolean isERP) {
        String mustSelectDoors = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SELECT_DOORS_VISIT_REQUIRED).getCode();
        if(isERP){
            mustSelectDoors = Constants.ONE+"";
        }
        List<DeviceRole> roles = null;
        if(StringUtils.equals(mustSelectDoors,Constants.ZERO+"")){
            roles = deviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda()
                    .eq(DeviceRole::getIsDefault,Constants.ZERO)
                    .eq(DeviceRole::getIsdeleted,Constants.ZERO)
                    .eq(DeviceRole::getType,Constants.DeviceRoleType.fk));
            if(roles.size() ==0){
                throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,暂不存在可访问的访客门禁,无法进行申请操作!");
            }
        }else{
            //如果必须选择门禁,但未选择
            if(StringUtils.isBlank(visits.getDoors())){
                throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请选择有效访问门禁!");
            }
            String[] dIds = visits.getDoors().split(",");
            roles = deviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda()
                    .eq(DeviceRole::getIsdeleted,Constants.ZERO)
                    .eq(DeviceRole::getType,Constants.DeviceRoleType.fk)
                    .in(DeviceRole::getId, Arrays.asList(dIds)));
            if(roles == null || roles.size()==0 || roles.size() != dIds.length){
                throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,请选择有效访问门禁!");
            }
        }
        String[] ids =new String[roles.size()];
        for (int i = 0; i < roles.size(); i++) {
            ids[i] = roles.get(i).getHkId();
        }
        return  ids;
    }
 
    @Override
    public void deleteById(Integer id) {
        visitsMapper.deleteById(id);
    }
 
    @Override
    public void delete(Visits visits) {
        UpdateWrapper<Visits> deleteWrapper = new UpdateWrapper<>(visits);
        visitsMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        visitsMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(Visits visits) {
        visitsMapper.updateById(visits);
    }
 
    @Override
    public void updateByIdInBatch(List<Visits> visitss) {
        if (CollectionUtils.isEmpty(visitss)) {
            return;
        }
        for (Visits visits: visitss) {
            this.updateById(visits);
        }
    }
 
    @Override
    public Visits findById(Integer id,Integer memberId) {
 
        MPJLambdaWrapper<Visits> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(Visits.class);
        queryWrapper.selectAs(Member::getName,Visits::getReceptMemberName);
        queryWrapper.selectAs(Company::getName,Visits::getReceptMemberDepartment);
        queryWrapper.select("t3.name",Visits::getCreateMemberName);
        queryWrapper.leftJoin(Member.class,Member::getId,Visits::getReceptMemberId);
        queryWrapper.leftJoin(Company.class,Company::getErpId,Member::getErpOrgId);
        queryWrapper.leftJoin("Member t3 on t.CREATE_MEMBER_ID=t3.id");
 
        queryWrapper.eq(Visits::getId,id);
        Visits result = visitsJoinMapper.selectJoinOne(Visits.class,queryWrapper);
 
        if(result!=null){
            if(StringUtils.isNotBlank(result.getDoors())){
                String[] doorList=result.getDoors().split(",");
                MPJLambdaWrapper<DeviceRole> deviceQuery = new MPJLambdaWrapper<>();
                deviceQuery.in(DeviceRole::getId,doorList);
                List<DeviceRole> deviceRoleList= deviceRoleMapper.selectList(deviceQuery);
                result.setDeviceRoleList(deviceRoleList);
            }
        }
 
        MPJLambdaWrapper<Visits> visitQuery = new MPJLambdaWrapper<>();
        visitQuery.selectAll(Visits.class);
        visitQuery.eq(Visits::getParentId,result.getId());
        visitQuery.isNotNull(Visits::getParentId);
        visitQuery.eq(Visits::getIsdeleted,Constants.ZERO);
        List<Visits> visitsList = visitsJoinMapper.selectList(visitQuery);
        Visits v = new Visits();
        BeanUtils.copyProperties(result,v);
        visitsList.add(0,v);
        result.setWithUserList(visitsList);
        result.setPrefixUrl(systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode() +
                systemDictDataBiz.queryByCode(Constants.FTP,Constants.MEMBER_IMG).getCode());
 
        result.setApproveDateVO(
                approveService.arrangeApprovedData(id,
                        result.getType(),
                        memberId)
        );
        if(Constants.equalsInteger(result.getStatus(),Constants.VisitStatus.xfSuccess)
                || Constants.equalsInteger(result.getStatus(),Constants.VisitStatus.xfFail)
                || Constants.equalsInteger(result.getStatus(),Constants.VisitStatus.signin)
                || Constants.equalsInteger(result.getStatus(),Constants.VisitStatus.signout)
                || Constants.equalsInteger(result.getStatus(),Constants.VisitStatus.invalid)){
            result.setBusinessStatus(Constants.VisitStatus.pass);
        }else{
            result.setBusinessStatus(result.getStatus());
        }
 
        return result;
    }
 
    @Override
    public Visits findOne(Visits visits) {
        QueryWrapper<Visits> wrapper = new QueryWrapper<>(visits);
        return visitsMapper.selectOne(wrapper);
    }
 
    @Override
    public List<Visits> findList(Visits visits) {
        QueryWrapper<Visits> wrapper = new QueryWrapper<>(visits);
        return visitsMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<Visits> findPage(PageWrap<Visits> pageWrap) {
         IPage<Visits> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<Visits> queryWrapper = new MPJLambdaWrapper<>();
 
        queryWrapper.selectAll(Visits.class);
        queryWrapper.select("  ( select count(distinct(v.CAR_NOS)) from visits v where v.PARENT_ID = t.ID and v.CAR_NOS is not null  and v.CAR_NOS != ''  and v.CAR_NOS != t.CAR_NOS ) as carNum  ");
        queryWrapper.selectAs(Member::getName,Visits::getReceptMemberName);
        queryWrapper.selectAs(Company::getName,Visits::getReceptMemberDepartment);
        queryWrapper.leftJoin(Member.class,Member::getId,Visits::getReceptMemberId);
        queryWrapper.leftJoin(Company.class,Company::getId,Member::getCompanyId);
 
        //数据权限开始--------------------start----------------
        LoginUserInfo userInfo =pageWrap.getModel().getLoginUserInfo();
        if(userInfo!=null && userInfo.getCompanyIdList()!=null){
            if(  userInfo.getCompanyIdList().size() ==0){
                //只能看自己(拜访人)
                queryWrapper.eq(Member::getId,userInfo.getMemberId());
            }else{
                queryWrapper.in(Company::getId ,userInfo.getCompanyIdList());
            }
        }
        //数据权限开始--------------------end----------------
 
        queryWrapper.eq(Visits::getIsdeleted,Constants.ZERO);
        queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getType())&&Constants.equalsInteger(pageWrap.getModel().getType(),Constants.TWO),Visits::getType,pageWrap.getModel().getType());
        queryWrapper.ne(Objects.nonNull(pageWrap.getModel().getType())&&!Constants.equalsInteger(pageWrap.getModel().getType(),Constants.TWO),Visits::getType,Constants.TWO);
        queryWrapper.eq(StringUtils.isNotBlank(pageWrap.getModel().getOpenid()),Visits::getOpenid,pageWrap.getModel().getOpenid());
        queryWrapper.like(StringUtils.isNotBlank(pageWrap.getModel().getCarNos()),Visits::getCarNos,pageWrap.getModel().getCarNos());
//        queryWrapper.eq(StringUtils.isBlank(pageWrap.getModel().getOpenid()),"1","2");
        queryWrapper.and(StringUtils.isNotBlank(pageWrap.getModel().getName()),ms->ms.like(Visits::getName,pageWrap.getModel().getName())
                .or().like(Visits::getPhone,pageWrap.getModel().getName()))
                .eq(StringUtils.isNotBlank(pageWrap.getModel().getIdcardNo()),Visits::getIdcardNo,DESUtil.encrypt(Constants.EDS_PWD, pageWrap.getModel().getIdcardNo()))
                .eq(StringUtils.isNotBlank(pageWrap.getModel().getCompanyName()),Visits::getCompanyName,pageWrap.getModel().getCompanyName())
                .eq(Objects.nonNull(pageWrap.getModel().getStatus()),Visits::getStatus,pageWrap.getModel().getStatus());
        queryWrapper.isNull(Visits::getParentId);
        queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getMemberId()),Visits::getMemberId,pageWrap.getModel().getMemberId());
        queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getReceptMemberId()),Visits::getReceptMemberId,pageWrap.getModel().getReceptMemberId());
        queryWrapper.orderByDesc(Visits::getCreateDate);
        IPage<Visits> result = visitsJoinMapper.selectJoinPage(page, Visits.class,queryWrapper);
 
        for (Visits visits:result.getRecords()) {
            if(StringUtils.isNotBlank(visits.getCarNos())){
                visits.setCarNum(visits.getCarNum() + Constants.ONE);
            }
        }
        return PageData.from(result);
    }
 
    @Override
    public long count(Visits visits) {
        QueryWrapper<Visits> wrapper = new QueryWrapper<>(visits);
        return visitsMapper.selectCount(wrapper);
    }
    public static PageData<Visits> retentionPageBiz(PageWrap<Visits> pageWrap, VisitsJoinMapper visitsJoinMapper,SystemDictDataBiz systemDictDataBiz) {
        String code= systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.TIMEOUT_WARNING).getCode();
        IPage<Visits> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<Visits> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(Visits.class);
        queryWrapper.selectAs(Member::getName,Visits::getReceptMemberName);
        queryWrapper.select("TIMESTAMPDIFF( MINUTE, NOW(), t.OUT_DATE) AS timeOut");
        queryWrapper.selectAs(Member::getType,Visits::getMemberType);
        queryWrapper.selectAs(Company::getName,Visits::getReceptMemberDepartment);
        queryWrapper.leftJoin(Member.class,Member::getId,Visits::getReceptMemberId);
        queryWrapper.leftJoin(Company.class,Company::getId,Member::getCompanyId);
        queryWrapper.leftJoin(" member m on m.id= t.MEMBER_ID");
        queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getLevelStatus()),Visits::getStatus,Constants.VisitStatus.signin);
        queryWrapper.apply(Objects.nonNull(pageWrap.getModel().getLevelStatus())," TIMESTAMPDIFF( MINUTE, NOW(), t.OUT_DATE) <= "+code+"  ");
 
        queryWrapper.ne("m.type ",Constants.TWO);
        queryWrapper.eq(Visits::getIsdeleted,Constants.ZERO);
        queryWrapper.eq(Objects.nonNull(pageWrap.getModel().getType()),Visits::getType,pageWrap.getModel().getType());
        queryWrapper.and(StringUtils.isNotBlank(pageWrap.getModel().getName()),ms->ms.like(Visits::getPhone,pageWrap.getModel().getName())
                .or().like(Visits::getName,pageWrap.getModel().getName()));
        queryWrapper.eq(StringUtils.isNotBlank(pageWrap.getModel().getIdcardNo()),Visits::getIdcardNo,StringUtils.isNotBlank(pageWrap.getModel().getIdcardNo()));
        queryWrapper.eq(StringUtils.isNotBlank(pageWrap.getModel().getCompanyName()),Visits::getCompanyName,pageWrap.getModel().getCompanyName());
        queryWrapper.orderByDesc(Visits::getEditDate);
        IPage<Visits> result = visitsJoinMapper.selectJoinPage(page, Visits.class,queryWrapper);
        if(result!=null&&result.getRecords()!=null){
            result.getRecords().stream().forEach(s ->{
                if(s.getStatus().equals(Constants.VisitStatus.signin)){
                    if(s.getTimeOut()<=Integer.valueOf(code)&&s.getTimeOut()>=0){
                        s.setOutStatus(Constants.TWO);
                    }else if(s.getTimeOut()>Constants.ZERO){
                        s.setOutStatus(Constants.ZERO);
                    }else{
                        s.setOutStatus(Constants.ONE);
                    }
                }
            });
        }
 
        return PageData.from(result);
    }
 
    @Override
    public PageData<Visits> retentionPage(PageWrap<Visits> pageWrap) {
        return  retentionPageBiz(pageWrap,visitsJoinMapper,systemDictDataBiz);
    }
 
 
 
    @Override
    public VisitDetailVO getVisitDetail(Integer id,Integer memberId){
        Visits visits = visitsMapper.selectById(id);
        if(Objects.isNull(visits)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        Member member = memberMapper.selectById(visits.getReceptMemberId());
        if(Objects.isNull(member)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到被访员工信息");
        }
        VisitDetailVO visitDetailVO = new VisitDetailVO();
        visitDetailVO.setCreateTime(visits.getCreateDate());
        visitDetailVO.setStatus(visits.getStatus());
        if(Constants.equalsInteger(visits.getStatus(),Constants.VisitStatus.xfSuccess)
        || Constants.equalsInteger(visits.getStatus(),Constants.VisitStatus.xfFail)
        || Constants.equalsInteger(visits.getStatus(),Constants.VisitStatus.signin)
        || Constants.equalsInteger(visits.getStatus(),Constants.VisitStatus.signout)
        || Constants.equalsInteger(visits.getStatus(),Constants.VisitStatus.invalid)){
            visitDetailVO.setBusinessStatus(Constants.VisitStatus.pass);
        }else{
            visitDetailVO.setBusinessStatus(visits.getStatus());
        }
        visitDetailVO.setCarNos(visits.getCarNos());
        visitDetailVO.setPhone(visits.getPhone());
        visitDetailVO.setVisitUserName(member.getName());
        visitDetailVO.setVisitReason(visits.getReason());
        visitDetailVO.setQrcode(visits.getQrcode());
        visitDetailVO.setIdcardType(visits.getIdcardType());
        visitDetailVO.setVisitTime(DateUtil.DateToStr(visits.getStarttime(),"yyyy-MM-dd HH:mm") + " 至 " + DateUtil.DateToStr(visits.getEndtime(),"yyyy-MM-dd HH:mm") );
        //被访人员部门
        Company company = companyMapper.selectById(member.getCompanyId());
        if(!Objects.isNull(company)){
            visitDetailVO.setVisitUserCompany(company.getName());
        }
        visitDetailVO.setName(visits.getName());
        visitDetailVO.setCompanyName(visits.getCompanyName());
        visitDetailVO.setFaceImg(visits.getFaceImg());
        visitDetailVO.setType(visits.getType());
        visitDetailVO.setConstructionReason(visits.getConstructionReason());
        visitDetailVO.setImgUrl(visits.getImgurl());
        visitDetailVO.setIdCardDecode(visits.getIdcardDecode());
        visitDetailVO.setFaceImg(visits.getFaceImg());
        visitDetailVO.setPrefix(systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode() +
                systemDictDataBiz.queryByCode(Constants.FTP,Constants.MEMBER_IMG).getCode());
        if(StringUtils.isNotBlank(visits.getDoors())){
            List<DeviceRole> deviceRoleList = deviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda()
                            .select(DeviceRole::getName)
                            .eq(DeviceRole::getIsdeleted,Constants.ZERO)
                    .in(DeviceRole::getId,visits.getDoors().split(",")));
            if(CollectionUtils.isNotEmpty(deviceRoleList)){
                visitDetailVO.setDoorGroupName(
                        deviceRoleList.stream().map(m->m.getName()).collect(Collectors.toList())
                );
            }
        }
        visitDetailVO.setWithVisitsList(
                visitsMapper.selectList(new QueryWrapper<Visits>().lambda()
                .select(Visits::getName,Visits::getPhone,Visits::getQrcode,Visits::getFaceImg,Visits::getImgurl,Visits::getIdcardDecode,Visits::getStatus)
                .eq(Visits::getParentId,id)));
 
 
//        if(Objects.nonNull(memberId)){
            visitDetailVO.setApproveDateVO(
                    approveService.arrangeApprovedData(id,
                            visits.getType(),
                            memberId)
            );
//        }
        return visitDetailVO;
    }
 
 
 
 
    @Override
    public PageData<VisitRecordVO> taskCenter(PageWrap<VisitRecordDTO> param) {
        VisitRecordDTO visitRecordDTO = param.getModel();
        IPage<Visits> page = new Page<>(param.getPage(), param.getCapacity());
        MPJLambdaWrapper<Visits> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(visitRecordDTO);
 
        queryWrapper.selectAs(Visits::getId,VisitRecordVO::getId);
        queryWrapper.selectAs(Visits::getName,VisitRecordVO::getName);
        queryWrapper.selectAs(Visits::getStarttime,VisitRecordVO::getStartTime);
        queryWrapper.selectAs(Visits::getEndtime,VisitRecordVO::getEndTime);
        queryWrapper.selectAs(Visits::getReason,VisitRecordVO::getReason);
        queryWrapper.selectAs(Visits::getMemberNum,VisitRecordVO::getInNum);
        queryWrapper.selectAs(Visits::getCreateDate,VisitRecordVO::getCreateDate);
        queryWrapper.leftJoin(Approve.class,Approve::getId,Visits::getId);
        if(!Objects.isNull(visitRecordDTO)){
            queryWrapper.like(StringUtils.isNotBlank(visitRecordDTO.getName()),Visits::getName,visitRecordDTO.getName());
            queryWrapper.le(!Objects.isNull(visitRecordDTO.getCreateTimeS()),Visits::getCreateDate,visitRecordDTO.getCreateTimeS());
            queryWrapper.ge(!Objects.isNull(visitRecordDTO.getCreateTimeE()),Visits::getCreateDate,visitRecordDTO.getCreateTimeE());
            queryWrapper.eq(!Objects.isNull(visitRecordDTO.getType()),Visits::getType,visitRecordDTO.getType());
            if(!Objects.isNull(visitRecordDTO.getState())&&visitRecordDTO.getState()<Constants.TWO){
                queryWrapper.eq(Approve::getStatus,visitRecordDTO.getState());
                queryWrapper.eq(Approve::getChekorId,visitRecordDTO.getMemberId());
            }else if(!Objects.isNull(visitRecordDTO.getState())&&visitRecordDTO.getState()==Constants.TWO){
                queryWrapper.eq(Visits::getMemberId,visitRecordDTO.getMemberId());
            }
        }
        queryWrapper.orderByDesc(Visits::getCreateDate);
        IPage<VisitRecordVO> result = visitsJoinMapper.selectJoinPage(page, VisitRecordVO.class,queryWrapper);
 
        return PageData.from(result);
    }
 
 
 
    @Override
    public void  visitLevel(Integer visitId){
        Visits visits = visitsMapper.selectById(visitId);
        if(Objects.isNull(visits)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(!visits.getStatus().equals(Constants.VisitStatus.signin)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"访客记录状态错误,请刷新重试");
        }
        VisitAppointmentOutRequest request = new VisitAppointmentOutRequest();
        request.setOrderId(visits.getHkId());
        //调用海康强制签离
        BaseResponse response =  HKService.outVisitAppiontment(request);
        visitsMapper.update(null,new UpdateWrapper<Visits>().lambda().set(Visits::getStatus,Constants.VisitStatus.signout)
                .eq(Visits::getId,visitId));
        //产出在场人员信息
        retentionMapper.delete(new UpdateWrapper<Retention>().lambda()
                .eq(Retention::getType,Constants.memberType.visitor)
                .eq(Retention::getMemberId,visits.getMemberId()));
    }
    @Override
    public void  visitCancel(Integer visitId){
        Visits visits = visitsMapper.selectById(visitId);
        if(Objects.isNull(visits)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(!visits.getStatus().equals(Constants.VisitStatus.xfSuccess)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"访客记录状态错误,请刷新重试");
        }
        VisitAppointmentOutRequest request = new VisitAppointmentOutRequest();
        request.setOrderId(visits.getHkId());
        //调用海康强制签离
        BaseResponse response =  HKService.outVisitAppiontment(request);
        visitsMapper.update(null,new UpdateWrapper<Visits>().lambda().set(Visits::getStatus,Constants.VisitStatus.signout)
                .eq(Visits::getId,visitId));
        //产出在场人员信息
        retentionMapper.delete(new UpdateWrapper<Retention>().lambda()
                .eq(Retention::getType,Constants.memberType.visitor)
                .eq(Retention::getMemberId,visits.getMemberId()));
    }
    @Override
    public  void visitResend(Integer visitId) {
        MPJLambdaWrapper<Visits> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(Visits.class);
        queryWrapper.selectAs(Member::getName,Visits::getReceptMemberName)
                .selectAs(Member::getHkId,Visits::getReceptMemberHkId)
                .leftJoin(Member.class,Member::getId,Visits::getReceptMemberId)
                .eq(Visits::getId,visitId)//未同步到海康
                .last("limit 1");
        Visits visits   = visitsMapper.selectJoinOne(Visits.class,queryWrapper);
        if(Objects.isNull(visits)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(!visits.getStatus().equals(Constants.VisitStatus.xfFail)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"访客记录状态错误,请刷新重试");
        }
        List<DeviceRole> roleList = deviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda()
                .eq(DeviceRole::getType, Constants.ONE));
        String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode()
                +systemDictDataBiz.queryByCode(Constants.FTP,Constants.MEMBER_IMG).getCode();
 
      HkSyncVisitServiceImpl.getUpdateModelByResponseIccm(visits,new Date(),roleList,path);
      if(Constants.equalsInteger(visits.getStatus(),Constants.VisitStatus.xfSuccess)){
          //如果下发成功,
          visitsMapper.updateById(visits);
          if(Objects.isNull(visits.getParentId())){
              wxPlatNotice.sendVisitAuditTemplateNotice(visits,
                      systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_PREFIX).getCode(),
                      systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_AUDIT_VISIT).getCode());
          }
      }else{
          throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"重新下发会失败!");
      }
    }
 
 
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    public void resetPassword(ResetPasswordDTO resetPasswordDTO){
        if(Objects.isNull(resetPasswordDTO)
            || StringUtils.isBlank(resetPasswordDTO.getPassword())
            || StringUtils.isBlank(resetPasswordDTO.getValidCode())
            || StringUtils.isBlank(resetPasswordDTO.getPhone())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        SystemUser systemUser = systemUserMapper.selectOne(new QueryWrapper<SystemUser>().lambda().eq(SystemUser::getMobile,resetPasswordDTO.getPhone()).eq(SystemUser::getDeleted,Constants.ZERO).last(" limit 1"));
        if(Objects.isNull(systemUser)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到手机号所属账户");
        }
        smsEmailService.validateCode(resetPasswordDTO.getValidCode(),resetPasswordDTO.getPhone());
        ResetSystemUserPwdDTO dto = new ResetSystemUserPwdDTO();
        dto.setPassword(resetPasswordDTO.getPassword());
        dto.setId(systemUser.getId());
        dto.setOperaUserId(systemUser.getId());
        systemUserBiz.resetPwd(dto);
    }
 
    /**
     *
     * @param queryType 查询类型:1=在园人数;2=报表数据;3=待办事项;4=超时预警
     * @param loginUserInfo
     * @return
     */
    @Override
    public PCWorkPlatformDataVO getPcWorkPlatformData(Integer queryType ,LoginUserInfo loginUserInfo){
        PCWorkPlatformDataVO pcWorkPlatformDataVO = new PCWorkPlatformDataVO();
        if(Constants.equalsInteger(queryType,Constants.ONE)){
            List<Retention> retentionList = retentionMapper.selectJoinList(Retention.class,
                    new MPJLambdaWrapper<Retention>()
                            .selectAll(Retention.class)
                            .selectAs(Company::getType,Retention::getCompanyType)
                            .leftJoin(Company.class,Company::getId,Retention::getCompanyId)
            );
 
            InoutDayCount inoutDayCount = inoutDayCountMapper.selectOne(new QueryWrapper<InoutDayCount>()
                            .lambda()
                    .apply(" DATE(TIME_INFO) = CURDATE()  ")
                    .last(" limit 1 ")
            );
 
            //今日在园人数
            pcWorkPlatformDataVO.setTodayInParkUserNum(
                    retentionList.stream().filter(i->!Constants.equalsInteger(i.getType(),Constants.THREE)).count()
            );
 
            pcWorkPlatformDataVO.setTodayInUserNum(Constants.ZERO);
            pcWorkPlatformDataVO.setTodayOutUserNum(Constants.ZERO);
 
            //在园长期相关方人数
            pcWorkPlatformDataVO.setInParkLwUserNum(
                    retentionList.stream().filter(i->Constants.equalsInteger(i.getType(),Constants.TWO) && Constants.equalsInteger(i.getCompanyType(),Constants.ZERO)).count()
            );
            pcWorkPlatformDataVO.setLwUserInNum(Constants.ZERO);
            pcWorkPlatformDataVO.setLwUserOutNum(Constants.ZERO);
 
 
            //在园访客数量
            pcWorkPlatformDataVO.setInParkVisitUserNum(
                    retentionList.stream().filter(i->Constants.equalsInteger(i.getType(),Constants.ONE)&&Objects.isNull(i.getCompanyType())).count()
            );
            pcWorkPlatformDataVO.setVisitUserNum(Constants.ZERO);
            pcWorkPlatformDataVO.setSignLevelNum(Constants.ZERO);
 
            //在园车辆
            pcWorkPlatformDataVO.setTodayInParkCarNum(
                    retentionList.stream().filter(i->Constants.equalsInteger(i.getType(),Constants.THREE)).count()
            );
            pcWorkPlatformDataVO.setTodayInCarNum(Constants.ZERO);
            pcWorkPlatformDataVO.setTodayOutCarNum(Constants.ZERO);
            if(Objects.nonNull(inoutDayCount)){
                //相关方
                pcWorkPlatformDataVO.setLwUserInNum(inoutDayCount.getInOtherMemberNum());
                pcWorkPlatformDataVO.setLwUserOutNum(inoutDayCount.getOutOtherMemberNum());
                //访客
                pcWorkPlatformDataVO.setVisitUserNum(inoutDayCount.getInVisitorNum());
                pcWorkPlatformDataVO.setSignLevelNum(inoutDayCount.getOutVisitorNum());
                //车辆
                pcWorkPlatformDataVO.setTodayInCarNum(inoutDayCount.getInCarNum());
                pcWorkPlatformDataVO.setTodayOutCarNum(inoutDayCount.getOutCarNum());
                //总人数
                pcWorkPlatformDataVO.setTodayInUserNum(pcWorkPlatformDataVO.getLwUserInNum() + pcWorkPlatformDataVO.getVisitUserNum() + inoutDayCount.getInSelfMemberNum() );
                pcWorkPlatformDataVO.setTodayOutUserNum(pcWorkPlatformDataVO.getLwUserOutNum() + pcWorkPlatformDataVO.getSignLevelNum() + inoutDayCount.getOutSelfMemberNum() );
            }
 
        }else if(Constants.equalsInteger(queryType,Constants.TWO)){
            List<String> weekDays = DateUtil.getBeforDays(new Date(),7);
            List<InterestedListVO> weekVisitList = new ArrayList<>();
            List<InterestedListVO> weekCarList = new ArrayList<>();
            List<InterestedListVO> lwList = new ArrayList<>();
            //查询七天前的访客记录数量
            List<Visits> visitsList = visitsMapper.selectList(new QueryWrapper<Visits>().lambda().in(Visits::getStatus,
                    Constants.VisitStatus.signin,Constants.VisitStatus.signout)
                    .apply(" STARTTIME >   CURDATE() - INTERVAL 7 DAY " )
            );
 
            List<CarEvent> carEventList = carEventMapper.selectList(new QueryWrapper<CarEvent>().lambda()
                    .in(CarEvent::getEventType,"771760131","771760130")
                    .apply(" STR_TO_DATE(happen_time, '%Y-%m-%dT%H:%i:%s') > CURDATE() - INTERVAL 7 DAY  " )
            );
 
            for (String days:weekDays) {
                InterestedListVO visitVO = new InterestedListVO();
                visitVO.setName(days);
                if(CollectionUtils.isNotEmpty(visitsList)){
                    //处理访客人员数量
                    List<Visits> daysList = visitsList.stream().filter(i->Objects.nonNull(i.getStarttime())&&DateUtil.dateToString(i.getStarttime(),"yyyy-MM-dd").equals(days)).collect(Collectors.toList());
                    List<String> memberIds = daysList.stream().map(i->i.getMemberId().toString()).collect(Collectors.toList());
                    if(CollectionUtils.isNotEmpty(memberIds)){
                        visitVO.setNum(new HashSet<String>(memberIds).size());
                    }
                }
                if(Objects.isNull(visitVO.getNum())){
                    visitVO.setNum(Constants.ZERO);
                }
 
 
                visitVO.setName(days);
                InterestedListVO carVO = new InterestedListVO();
                carVO.setName(days);
 
 
                if(CollectionUtils.isNotEmpty(carEventList)){
                    //处理访客人员数量
                    List<CarEvent> daysList = carEventList.stream().filter(i->StringUtils.isNotBlank(i.getHappenTime()) && i.getHappenTime().substring(0,10).equals(days)).collect(Collectors.toList());
                    List<String> carCodeList = daysList.stream().map(i->i.getPlateNos()).collect(Collectors.toList());
                    if(CollectionUtils.isNotEmpty(carCodeList)){
                        carVO.setNum(new HashSet<String>(carCodeList).size());
                    }
                }
                if(Objects.isNull(carVO.getNum())){
                    visitVO.setNum(Constants.ZERO);
                }
                weekVisitList.add(visitVO);
                weekCarList.add(carVO);
            }
            pcWorkPlatformDataVO.setWeekVisitList(weekVisitList );
            pcWorkPlatformDataVO.setWeekCarList(weekCarList);
 
            List<Company> companyList = companyMapper.selectList(new QueryWrapper<Company>().lambda()
                    .eq(Company::getType,Constants.ZERO)
                    .eq(Company::getIsdeleted,Constants.ZERO)
            );
 
            if(CollectionUtils.isNotEmpty(companyList)){
                List<Integer> companyIds = companyList.stream().map(i->i.getId()).collect(Collectors.toList());
                List<Retention> retentionList = retentionMapper.selectList(
                        new QueryWrapper<Retention>().lambda()
                                .in(Retention::getCompanyId,companyIds)
                );
                for (Company company:companyList) {
                    Integer count = retentionList.stream().filter(i->Constants.equalsInteger(i.getCompanyId(),company.getId())).collect(Collectors.toList()).size();
                    InterestedListVO lw = new InterestedListVO();
                    lw.setNum(count);
                    lw.setName(company.getName());
                    lwList.add(lw);
                }
            }
 
            pcWorkPlatformDataVO.setLwList(lwList   );
        }else if(Constants.equalsInteger(queryType,Constants.THREE)) {
            MPJLambdaWrapper<Notices> queryWrapper = new MPJLambdaWrapper<>();
            queryWrapper.selectAll(Notices.class);
            if (Objects.isNull(loginUserInfo.getMemberId())) {
                queryWrapper.eq("1", "2");
            } else {
                queryWrapper.eq(Notices::getStatus, Constants.ZERO);
                queryWrapper.eq(Notices::getSendacopy, Constants.ZERO);
                queryWrapper.eq(Notices::getParam2, Constants.ZERO);
                queryWrapper.eq(Notices::getUserId, loginUserInfo.getMemberId());
            }
            queryWrapper.orderByDesc(Notices::getCreateDate);
            List<Notices> noticesList = noticesJoinMapper.selectList(queryWrapper);
            pcWorkPlatformDataVO.setNoticesList(noticesList);
            pcWorkPlatformDataVO.setNoticesNum(noticesList.size());
            if(noticesList.size() > 5 ){
                pcWorkPlatformDataVO.setNoticesList(noticesList.subList(0,5));
            }else{
                pcWorkPlatformDataVO.setNoticesList(noticesList);
            }
        }else{
            String code= systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.TIMEOUT_WARNING).getCode();
            MPJLambdaWrapper<Visits> queryWrapper = new MPJLambdaWrapper<>();
            queryWrapper.selectAll(Visits.class);
            queryWrapper.selectAs(Member::getName,Visits::getReceptMemberName);
            queryWrapper.select("TIMESTAMPDIFF( MINUTE, NOW(), t.OUT_DATE) AS timeOut");
            queryWrapper.selectAs(Company::getName,Visits::getReceptMemberDepartment);
            queryWrapper.leftJoin(Member.class,Member::getId,Visits::getReceptMemberId);
            queryWrapper.leftJoin(Company.class,Company::getId,Member::getCompanyId);
            queryWrapper.leftJoin(" member m on m.id= t.MEMBER_ID");
            queryWrapper.eq(Visits::getStatus,Constants.VisitStatus.signin);
            queryWrapper.apply(" TIMESTAMPDIFF( MINUTE, NOW(), t.OUT_DATE) <= "+code+"  ");
            queryWrapper.ne("m.type ",Constants.TWO);
            queryWrapper.eq(Visits::getIsdeleted,Constants.ZERO);
            queryWrapper.orderByDesc(Visits::getEditDate);
            List<Visits> result = visitsJoinMapper.selectList(queryWrapper);
            if(result!=null&&result!=null){
                result.stream().forEach(s ->{
                    if(s.getStatus().equals(Constants.VisitStatus.signin)){
                        if(s.getTimeOut()<=Integer.valueOf(code)&&s.getTimeOut()>=0){
                            s.setOutStatus(Constants.TWO);
                        }else if(s.getTimeOut()>Constants.ZERO){
                            s.setOutStatus(Constants.ZERO);
                        }else{
                            s.setOutStatus(Constants.ONE);
                        }
                    }
                });
            }
            pcWorkPlatformDataVO.setTimeOutVisitNum(result.size());
            if(result.size() > 3 ){
                pcWorkPlatformDataVO.setTimeOutVisitList(result.subList(0,3));
            }else{
                pcWorkPlatformDataVO.setTimeOutVisitList(result);
            }
        }
        return pcWorkPlatformDataVO;
    }
 
 
    @Override
    public void syncTimeOutData(){
        String times = systemDictDataBiz.queryByCode(Constants.VISIT_CONFIG,Constants.TIME_OUT_CONFIG).getCode();
        List<Visits> visitsList = visitsMapper.selectList(new QueryWrapper<Visits>().lambda()
                .eq(Visits::getStatus,Constants.VisitStatus.signin)
                .eq(Visits::getSendTimeOutNotice,Constants.ZERO)
                .apply("   now() >=  DATE_ADD(ENDTIME,INTERVAL -"+times+" MINUTE)   ")
        );
        for (Visits visits:visitsList) {
            if(Constants.equalsInteger(visits.getType(),Constants.TWO)){
                SmsEmailServiceImpl.sendVisitReportSms(systemDictDataBiz,
                        emayService,smsEmailMapper,smsConfigMapper,visitsMapper,visits.getId(),
                        SmsConstants.visitReportingContent.visitReportingTimeOutSignOut,
                        null,Arrays.asList(visits.getPhone().split(","))
                );
            }else{
                SmsEmailServiceImpl.sendVisitSms(systemDictDataBiz,
                        emayService,smsEmailMapper,smsConfigMapper,visitsMapper,visits.getId(),
                        SmsConstants.visitContent.visitTimeOutSignOut,
                        null,Arrays.asList(visits.getPhone().split(","))
                );
            }
            visits.setSendTimeOutNotice(Constants.ONE);
            visitsMapper.updateById(visits);
        }
 
 
 
 
    }
 
 
}