郑永安
2023-06-19 f65443d8abeaedc9d102324565e8368e7c9d90c8
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
package com.gk.firework.Service.ServiceImpl;
 
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gk.firework.Domain.*;
import com.gk.firework.Domain.Enum.*;
import com.gk.firework.Domain.Exception.BusinessException;
import com.gk.firework.Domain.Utils.*;
import com.gk.firework.Domain.Utils.Properties;
import com.gk.firework.Domain.Vo.EnterpriseExportVo;
import com.gk.firework.Domain.Vo.EnterpriseVo;
import com.gk.firework.Mapper.EnterpriseMapper;
import com.gk.firework.Mapper.HiddenDangerReportMapper;
import com.gk.firework.Mapper.SaleOrderInfoMapper;
import com.gk.firework.Service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
 
import java.io.*;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;
 
 
@Service("enterpriseService")
public class EnterpriseServiceImpl extends ServiceImpl<EnterpriseMapper, Enterprise> implements EnterpriseService {
 
    @Autowired
    EnterpriseMapper enterpriseMapper;
    @Autowired
    EnterpriseApplyService enterpriseApplyService;
    @Autowired
    EnterpriseService enterpriseService;
    @Autowired
    EnterpriseStaffService enterpriseStaffService;
    @Autowired
    UserService userService;
    @Autowired
    UserRolesService userRolesService;
    @Autowired
    RoleService roleService;
    @Autowired
    ProductService productService;
    @Autowired
    HiddenDangerReportMapper hiddenDangerReportMapper;
    @Autowired
    HiddenDangerReportDetailService hiddenDangerReportDetailService;
    @Autowired
    ExcelExportService excelExportService;
    @Autowired
    SaleOrderInfoMapper saleOrderInfoMapper;
 
 
    /**
     * @Description: 新增申请,根据前端提交状态commitStatus来判断增加还是删除 parentId为编辑对象id
     * @date 2021/3/17 15:57
     */
    @Override
    @Transactional
    public void addApply(EnterpriseApply enterpriseApply,UserInfo user) throws IllegalAccessException {
 
        if (enterpriseApply.getCommitstatus() == CommitStatus.MOD) {
            //新建一个修改给过后的数据
            Enterprise enp2 = new Enterprise();
            //ParentId为修改企业的id
            enp2.setId(enterpriseApply.getParentid());
            //以下是页面可以修改的值
            enp2.setSafetysupervision(enterpriseApply.getSafetysupervision());
            enp2.setEconomicindustry(enterpriseApply.getEconomicindustry());
            enp2.setEnterprisenumber(enterpriseApply.getEnterprisenumber());
            enp2.setEnterprisename(enterpriseApply.getEnterprisename());
            enp2.setEnterpriseemail(enterpriseApply.getEnterpriseemail());
            enp2.setEnterprisesize(enterpriseApply.getEnterprisesize());
            enp2.setEnterprisestatus(enterpriseApply.getEnterprisestatus());
            enp2.setDepartment(enterpriseApply.getDepartment());
            enp2.setDevicenumber(enterpriseApply.getDevicenumber());
            enp2.setOfficeaddress(enterpriseApply.getOfficeaddress());
            enp2.setProvince(enterpriseApply.getProvince());
            enp2.setCity(enterpriseApply.getCity());
            enp2.setDistrict(enterpriseApply.getDistrict());
            enp2.setStreet(enterpriseApply.getStreet());
            enp2.setCommittee(enterpriseApply.getCommittee());
            enp2.setSecuritysupervisory(enterpriseApply.getSecuritysupervisory());
            enp2.setOfficephone(enterpriseApply.getOfficephone());
            enp2.setFaxphone(enterpriseApply.getFaxphone());
            enp2.setRegisteraddress(enterpriseApply.getRegisteraddress());
            enp2.setRegistertype(enterpriseApply.getRegistertype());
            enp2.setEstablishtime(enterpriseApply.getEstablishtime());
            enp2.setQqnumber(enterpriseApply.getQqnumber());
            enp2.setPostcode(enterpriseApply.getPostcode());
            enp2.setRoomnumber(enterpriseApply.getRoomnumber());
            enp2.setEconomictype(enterpriseApply.getEconomictype());
            enp2.setProductioncontent(enterpriseApply.getProductioncontent());
            enp2.setBusinessregisternumber(enterpriseApply.getBusinessregisternumber());
            enp2.setOrganizationstructurecode(enterpriseApply.getOrganizationstructurecode());
            enp2.setValidstarttime(enterpriseApply.getValidstarttime());
            enp2.setValidendtime(enterpriseApply.getValidendtime());
            enp2.setEmployeenumber(enterpriseApply.getEmployeenumber());
            enp2.setIspaysafetyinsurance(enterpriseApply.getIspaysafetyinsurance());
            enp2.setInsurancecontractnumber(enterpriseApply.getInsurancecontractnumber());
            enp2.setInsurestarttime(enterpriseApply.getInsurestarttime());
            enp2.setInsureendtime(enterpriseApply.getInsureendtime());
            enp2.setIsmajorhazard(enterpriseApply.getIsmajorhazard());
            enp2.setIsspecialequipment(enterpriseApply.getIsspecialequipment());
            enp2.setIsoccupationalhealthinfo(enterpriseApply.getIsoccupationalhealthinfo());
            enp2.setIsspecialpersonnel(enterpriseApply.getIsspecialpersonnel());
            enp2.setSelfrecordingcycle(enterpriseApply.getSelfrecordingcycle());
            enp2.setIsparententerprise(enterpriseApply.getIsparententerprise());
            enp2.setParententerpriseid(enterpriseApply.getParententerpriseid());
            enp2.setParententerprisename(enterpriseApply.getParententerprisename());
            //密码
            enp2.setPassword(enterpriseApply.getPassword());
 
            Enterprise enp1 = this.getById(enterpriseApply.getParentid());
            if (enp1 == null) {
 
            }
            //以下是非对比内容;设置对比内容相同
            assert enp1 != null;
            enp2.setInfocreatetime(enp1.getInfocreatetime());
            enp2.setInfoupdatetime(enp1.getInfoupdatetime());
            enp2.setInfoupdateby(enp1.getInfoupdateby());
            enp2.setInfocreateby(enp1.getInfocreateby());
            enp2.setValidflag(enp1.getValidflag());
            enp2.setInfocreatebyname(enp1.getInfocreatebyname());
            enp2.setInfoupdatebyname(enp1.getInfoupdatebyname());
 
            //两个对象差
            String updateFields = compareObj(Enterprise.class, enp1, enp2);
            //提出时间
            enterpriseApply.setApplytime(new Date());
            //等待审批
            enterpriseApply.setApplystatus(ApplyStatus.APPROVING);
            enterpriseApply.setValidflag(true);
            //更新字段
            enterpriseApply.setUpdatefields(updateFields);
 
            {
                enterpriseApply.setSafetysupervision(enp1.getSafetysupervision());
                enterpriseApply.setEconomicindustry(enp1.getEconomicindustry());
                enterpriseApply.setEnterprisenumber(enp1.getEnterprisenumber());
                enterpriseApply.setEnterprisename(enp1.getEnterprisename());
                enterpriseApply.setEnterpriseemail(enp1.getEnterpriseemail());
                enterpriseApply.setEnterprisesize(enp1.getEnterprisesize());
                enterpriseApply.setEnterprisestatus(enp1.getEnterprisestatus());
                enterpriseApply.setDepartment(enp1.getDepartment());
                enterpriseApply.setDevicenumber(enp1.getDevicenumber());
                enterpriseApply.setOfficeaddress(enp1.getOfficeaddress());
                enterpriseApply.setProvince(enp1.getProvince());
                enterpriseApply.setCity(enp1.getCity());
                enterpriseApply.setDistrict(enp1.getDistrict());
                enterpriseApply.setStreet(enp1.getStreet());
                enterpriseApply.setCommittee(enp1.getCommittee());
                enterpriseApply.setSecuritysupervisory(enp1.getSecuritysupervisory());
                enterpriseApply.setOfficephone(enp1.getOfficephone());
                enterpriseApply.setFaxphone(enp1.getFaxphone());
                enterpriseApply.setRegisteraddress(enp1.getRegisteraddress());
                enterpriseApply.setRegistertype(enp1.getRegistertype());
                enterpriseApply.setEstablishtime(enp1.getEstablishtime());
                enterpriseApply.setQqnumber(enp1.getQqnumber());
                enterpriseApply.setPostcode(enp1.getPostcode());
                enterpriseApply.setRoomnumber(enp1.getRoomnumber());
                enterpriseApply.setEconomictype(enp1.getEconomictype());
                enterpriseApply.setProductioncontent(enp1.getProductioncontent());
                enterpriseApply.setBusinessregisternumber(enp1.getBusinessregisternumber());
                enterpriseApply.setOrganizationstructurecode(enp1.getOrganizationstructurecode());
                enterpriseApply.setValidstarttime(enp1.getValidstarttime());
                enterpriseApply.setValidendtime(enp1.getValidendtime());
                enterpriseApply.setEmployeenumber(enp1.getEmployeenumber());
                enterpriseApply.setIspaysafetyinsurance(enp1.getIspaysafetyinsurance());
                enterpriseApply.setInsurancecontractnumber(enp1.getInsurancecontractnumber());
                enterpriseApply.setInsurestarttime(enp1.getInsurestarttime());
                enterpriseApply.setInsureendtime(enp1.getInsureendtime());
                enterpriseApply.setIsmajorhazard(enp1.getIsmajorhazard());
                enterpriseApply.setIsspecialequipment(enp1.getIsspecialequipment());
                enterpriseApply.setIsoccupationalhealthinfo(enp1.getIsoccupationalhealthinfo());
                enterpriseApply.setIsspecialpersonnel(enp1.getIsspecialpersonnel());
                enterpriseApply.setSelfrecordingcycle(enp1.getSelfrecordingcycle());
                enterpriseApply.setIsparententerprise(enp1.getIsparententerprise());
                enterpriseApply.setParententerprisename(enp1.getParententerprisename());
                enterpriseApply.setApplypersonname(user.getUsername());
                enterpriseApply.setApplypersonid(user.getId());
                UserInfo userInfo = userService.selectOneByCompanyId(enp1.getId());
                enterpriseApply.setPassword(userInfo.getPassword());
            }
            //新增审批
            enterpriseApplyService.save(enterpriseApply);
            //修改企业信息状态
            Enterprise updateEp = new Enterprise();
            updateEp.setId(enp1.getId());
            enterpriseService.updateById(updateEp);
        }
 
        if (enterpriseApply.getCommitstatus() == CommitStatus.DEL) {
 
            //提出时间
            enterpriseApply.setApplytime(new Date());
            //等待审批
            enterpriseApply.setApplystatus(ApplyStatus.APPROVING);
            Enterprise enp = this.getById(enterpriseApply.getParentid());
            enterpriseApply.setSafetysupervision(enp.getSafetysupervision());
            enterpriseApply.setEconomicindustry(enp.getEconomicindustry());
            enterpriseApply.setEnterprisenumber(enp.getEnterprisenumber());
            enterpriseApply.setEnterprisename(enp.getEnterprisename());
            enterpriseApply.setEnterpriseemail(enp.getEnterpriseemail());
            enterpriseApply.setEnterprisesize(enp.getEnterprisesize());
            enterpriseApply.setEnterprisestatus(enp.getEnterprisestatus());
            enterpriseApply.setDepartment(enp.getDepartment());
            enterpriseApply.setDevicenumber(enp.getDevicenumber());
            enterpriseApply.setOfficeaddress(enp.getOfficeaddress());
            enterpriseApply.setProvince(enp.getProvince());
            enterpriseApply.setCity(enp.getCity());
            enterpriseApply.setDistrict(enp.getCity());
            enterpriseApply.setStreet(enp.getStreet());
            enterpriseApply.setCommittee(enp.getCommittee());
            enterpriseApply.setSecuritysupervisory(enp.getSecuritysupervisory());
            enterpriseApply.setOfficephone(enp.getOfficephone());
            enterpriseApply.setFaxphone(enp.getFaxphone());
            enterpriseApply.setRegisteraddress(enp.getRegisteraddress());
            enterpriseApply.setRegistertype(enp.getRegistertype());
            enterpriseApply.setEstablishtime(enp.getEstablishtime());
            enterpriseApply.setQqnumber(enp.getQqnumber());
            enterpriseApply.setPostcode(enp.getPostcode());
            enterpriseApply.setRoomnumber(enp.getRoomnumber());
            enterpriseApply.setEconomictype(enp.getEconomictype());
            enterpriseApply.setProductioncontent(enp.getProductioncontent());
            enterpriseApply.setBusinessregisternumber(enp.getBusinessregisternumber());
            enterpriseApply.setOrganizationstructurecode(enp.getOrganizationstructurecode());
            enterpriseApply.setValidstarttime(enp.getValidstarttime());
            enterpriseApply.setValidendtime(enp.getValidendtime());
            enterpriseApply.setEmployeenumber(enp.getEmployeenumber());
            enterpriseApply.setIspaysafetyinsurance(enp.getIspaysafetyinsurance());
            enterpriseApply.setInsurancecontractnumber(enp.getInsurancecontractnumber());
            enterpriseApply.setInsurestarttime(enp.getInsurestarttime());
            enterpriseApply.setInsureendtime(enp.getInsureendtime());
            enterpriseApply.setIsmajorhazard(enp.getIsmajorhazard());
            enterpriseApply.setIsspecialequipment(enp.getIsspecialequipment());
            enterpriseApply.setIsoccupationalhealthinfo(enp.getIsoccupationalhealthinfo());
            enterpriseApply.setIsspecialpersonnel(enp.getIsspecialpersonnel());
            enterpriseApply.setSelfrecordingcycle(enp.getSelfrecordingcycle());
            enterpriseApply.setIsparententerprise(enp.getIsparententerprise());
            enterpriseApply.setParententerprisename(enp.getParententerprisename());
            enterpriseApply.setValidflag(true);
            enterpriseApply.setApplypersonid(user.getId());
            enterpriseApply.setApplypersonname(user.getUsername());
            enterpriseApply.setPassword(enp.getPassword());
            enterpriseApply.setParententerpriseid(enp.getParententerpriseid());
            enterpriseApplyService.save(enterpriseApply);
 
            //修改企业信息状态
            Enterprise updateEp = new Enterprise();
            updateEp.setId(enp.getId());
            enterpriseService.updateById(updateEp);
 
 
        }
    }
 
    /**
    * @Description: 查询企业信息
    * @date 2021/3/31 9:31
    */
 
    @Override
    public IPage<Enterprise> selectEnterprise(Page<Enterprise> page, Map filter,UserInfo user) {
 
        UserInfo userInfo = userService.getById(user.getId());
        Map<String, Object> params = new HashMap<>();
        //四类人
        params.put("leagalrepresentative", Constants.LEGAL_REPRESENTATIVE);
        params.put("mainprincipal", Constants.MAIN_PRINCIPAL);
        params.put("securityofficer", Constants.SECURITY_OFFICER);
        params.put("informationofficer", Constants.INFORMATION_OFFICER);
 
        //监管部门 根据 地区看所有
        params.put("province", userInfo.getProvince());
        params.put("city", userInfo.getCity());
        params.put("district", userInfo.getArea());
        params.put("street", userInfo.getTown());
        params.put("committee", userInfo.getCommunity());
        //企业用户
        params.put("enterprisenumber", userInfo.getCompanynumber());
 
        //过滤条件
        { //企业类型
            params.put("safetySupervision", filter.get("safetysupervision"));
            //经济类型
            params.put("economicIndustry", filter.get("economicindustry"));
            //许可证有效|过期
            params.put("valid", filter.get("valid"));
            //登录有效 loginvalid 1 就是有效
            params.put("loginValid",filter.get("loginValid"));
            //地区
            params.put("filterProvince", filter.get("province"));
            params.put("filterCity", filter.get("city"));
            params.put("filterDistrict", filter.get("district"));
            params.put("filterStreet", filter.get("street"));
            params.put("filterCommittee", filter.get("committee"));
            //企业名称
            params.put("enterprisename", filter.get("enterprisename"));
 
        }
 
        List<Enterprise> list = enterpriseMapper.selectPages(page, params);
        return page.setRecords(list);
 
    }
 
    /**
    * @Description: 新建企业信息
    * @date 2021/3/31 10:49
    */
    @Override
    @Transactional
    public void addEnterprise(Enterprise enterprise,UserInfo userInfo) {
        UserInfo userInfo2 = userService.getById(userInfo.getId());
        if (userInfo2.getCompanynumber() != null) {
            throw new BusinessException("没有新增权限");
        }
        //计算安全监管分类个数
        {
            int i = countBySafetySupervision(enterprise.getSafetysupervision());
            enterprise.setDivideflag((byte) (DivideFlagUtil.enterpriseDivideFlagGenerate(i)));
        }
 
        //新建企业信息
        {
            enterprise.setInfocreatetime(new Date());
            enterprise.setInfocreateby(userInfo.getId());
            enterprise.setInfocreatebyname(userInfo.getUsername());
            enterprise.setInfoupdatetime(new Date());
            enterprise.setValidflag(true);
            String randomStr = Element.random(Element.class).getValue().toString()+Element.random(Element.class).getValue().toString();
            while (enterpriseService.isDuplicate2BitCode(randomStr)) {
                 randomStr = Element.random(Element.class).getValue().toString()+Element.random(Element.class).getValue().toString();
            }
            enterprise.setTwobitcode(randomStr);
            //执行
            this.save(enterprise);
        }
        //新建企业关联staff
        {
            List<EnterpriseStaff> staff = new ArrayList<>();
            if (enterprise.getLegalrepresentative() != null) {
                enterprise.getLegalrepresentative().setId(null);
                enterprise.getLegalrepresentative().setType(Constants.LEGAL_REPRESENTATIVE);
                enterprise.getLegalrepresentative().setBelongid(enterprise.getId());
                enterprise.getLegalrepresentative().setBelongname(enterprise.getEnterprisename());
                staff.add(enterprise.getLegalrepresentative());
 
            }
            if (enterprise.getInformationofficer() != null) {
                enterprise.getInformationofficer().setId(null);
                enterprise.getInformationofficer().setType(Constants.INFORMATION_OFFICER);
                enterprise.getInformationofficer().setBelongid(enterprise.getId());
                enterprise.getInformationofficer().setBelongname(enterprise.getEnterprisename());
                staff.add(enterprise.getInformationofficer());
            }
            if (enterprise.getSecurityofficer() != null) {
                enterprise.getSecurityofficer().setId(null);
                enterprise.getSecurityofficer().setType(Constants.SECURITY_OFFICER);
                enterprise.getSecurityofficer().setBelongid(enterprise.getId());
                enterprise.getSecurityofficer().setBelongname(enterprise.getEnterprisename());
                staff.add(enterprise.getSecurityofficer());
            }
            if (enterprise.getMainprincipal() != null) {
                enterprise.getMainprincipal().setId(null);
                enterprise.getMainprincipal().setType(Constants.MAIN_PRINCIPAL);
                enterprise.getMainprincipal().setBelongid(enterprise.getId());
                enterprise.getMainprincipal().setBelongname(enterprise.getEnterprisename());
                staff.add(enterprise.getMainprincipal());
            }
            if (staff.size()>0)
                enterpriseStaffService.saveBatch(staff);
 
        }
 
 
        //保存信息两份到用户表
        {
            UserInfo user = new UserInfo();
            user.setIsdel((byte) 0);
            user.setUsername(enterprise.getEnterprisename());
            user.setCompany(enterprise.getEnterprisename());
            user.setEmail(enterprise.getEnterpriseemail());
            user.setDepartment(enterprise.getDepartment());
            user.setIssale((byte) 0);
            //普通用户
            user.setType(3);
            user.setProvince(enterprise.getProvince());
            user.setPhone(enterprise.getOfficephone());
            user.setCity(enterprise.getCity());
            user.setArea(enterprise.getDistrict());
            user.setTown(enterprise.getStreet());
            user.setCommunity(enterprise.getCommittee());
            //提出人为创建人
            user.setCreatedby(user.getUsername());
            user.setCompanyid(enterprise.getId());
            user.setCreateddate(new Date());
            //设置密码
            user.setPassword(Base64Encrypt.encode(enterprise.getPassword().getBytes()));
            user.setCompanynumber(enterprise.getEnterprisenumber());
            //执行
            userService.save(user);
 
            //如果有企业角色设置用户角色为企业
            UserRolesInfo uri = new UserRolesInfo();
            uri.setUserid(user.getId());
            if (enterprise.getSafetysupervision().equals(EnterpriseSafetySupervision.PRODUCE.getMsg())){
                uri.setRoleid((long) 3);
            }else {
                uri.setRoleid((long) 2);
            }
            userRolesService.save(uri);
 
            //终端机
            user.setId(null);
            user.setIssale((byte) 1);
            user.setStatus((byte) 1);
            Calendar instance = Calendar.getInstance();
            instance.setTime(enterprise.getValidendtime());
            instance.set(Calendar.HOUR_OF_DAY, 23);
            instance.set(Calendar.MINUTE, 59);
            instance.set(Calendar.SECOND, 59);
            user.setExpiredate(instance.getTime());
            userService.save(user);
            //终端机角色不需要
 
        }
 
 
    }
 
 
    /**
    * @Description: 修改企业信息
    * @date 2021/3/31 10:48
    */
    @Override
    @Transactional
    public void modEnterprise(Enterprise enterprise,UserInfo user) {
 
        //修改企业信息
        {
            enterprise.setInfoupdatetime(new Date());
            enterprise.setInfoupdateby(user.getId());
            enterprise.setInfoupdatebyname(user.getUsername());
            //企业名称和企业编号 不会修改
            enterprise.setEnterprisenumber(null);
            enterprise.setEnterprisename(null);
            this.updateById(enterprise);
        }
 
        //修改企业关联staff
        {
            ///更新的员工
            List<EnterpriseStaff> staff = new ArrayList<>();
            //新增的员工
            List<EnterpriseStaff> adds = new ArrayList<>();
            if (enterprise.getSecurityofficer() != null) {
                if (enterprise.getSecurityofficer().getId() != null) {
                    enterprise.getSecurityofficer().setBelongname(enterprise.getEnterprisename());
                    staff.add(enterprise.getSecurityofficer());
                }else{
                    enterprise.getSecurityofficer().setType(Constants.SECURITY_OFFICER);
                    enterprise.getSecurityofficer().setBelongid(enterprise.getId());
                    enterprise.getSecurityofficer().setBelongname(enterprise.getEnterprisename());
                    adds.add(enterprise.getSecurityofficer());
                }
            }
            if (enterprise.getLegalrepresentative() != null) {
                if (enterprise.getLegalrepresentative().getId() != null) {
                    enterprise.getLegalrepresentative().setBelongname(enterprise.getEnterprisename());
                    staff.add(enterprise.getLegalrepresentative());
                }else{
                    enterprise.getLegalrepresentative().setType(Constants.LEGAL_REPRESENTATIVE);
                    enterprise.getLegalrepresentative().setBelongid(enterprise.getId());
                    enterprise.getLegalrepresentative().setBelongname(enterprise.getEnterprisename());
                    adds.add(enterprise.getLegalrepresentative());
                }
 
            }
            if (enterprise.getMainprincipal() != null) {
                if (enterprise.getMainprincipal().getId() != null) {
                    enterprise.getMainprincipal().setBelongname(enterprise.getEnterprisename());
                    staff.add(enterprise.getMainprincipal());
                }else{
                    enterprise.getMainprincipal().setType(Constants.MAIN_PRINCIPAL);
                    enterprise.getMainprincipal().setBelongid(enterprise.getId());
                    enterprise.getMainprincipal().setBelongname(enterprise.getEnterprisename());
                    adds.add(enterprise.getMainprincipal());
                }
 
            }
            if (enterprise.getInformationofficer() != null) {
                if (enterprise.getInformationofficer().getId() != null) {
                    enterprise.getInformationofficer().setBelongname(enterprise.getEnterprisename());
                    staff.add(enterprise.getInformationofficer());
                }else{
                    enterprise.getInformationofficer().setType(Constants.INFORMATION_OFFICER);
                    enterprise.getInformationofficer().setBelongid(enterprise.getId());
                    enterprise.getInformationofficer().setBelongname(enterprise.getEnterprisename());
                    adds.add(enterprise.getInformationofficer());
                }
            }
 
            if (staff.size()>0)
                enterpriseStaffService.updateBatchById(staff);
            if (adds.size() > 0) {
                enterpriseStaffService.saveBatch(adds);
            }
        }
 
        //修改人员
        {
            //修改用户和终端机
            List<UserInfo> userList = userService.selectByCompanyId(enterprise.getId(),0);
            if (userList.size() != 2) {
                throw new BusinessException("发生错误,请联系管理员");
            }
            for (UserInfo info : userList) {
                if (StringUtils.isNotBlank(enterprise.getPassword())) {
                    info.setPassword(Base64Encrypt.encode(enterprise.getPassword().getBytes()));
                }
                info.setEmail(enterprise.getEnterpriseemail());
                info.setCompany(enterprise.getEnterprisename());
                info.setDepartment(enterprise.getDepartment());
                info.setProvince(enterprise.getProvince());
                info.setPhone(enterprise.getOfficephone());
                info.setCity(enterprise.getCity());
                info.setArea(enterprise.getDistrict());
                info.setTown(enterprise.getStreet());
                info.setCommunity(enterprise.getCommittee());
                //修改许可证 同时修改issale=1的用户有效期
                if (info.getIssale() == (byte) 1) {
                    //设置过期时间为选择当日的23:59:59
                    if (enterprise.getValidendtime() != null) {
                        Calendar instance = Calendar.getInstance();
                        instance.setTime(enterprise.getValidendtime());
                        instance.set(Calendar.HOUR_OF_DAY, 23);
                        instance.set(Calendar.MINUTE, 59);
                        instance.set(Calendar.SECOND, 59);
                        info.setExpiredate(instance.getTime());
                    }
                }
                userService.updateById(info);
            }
        }
 
    }
 
 
    @Override
    public int countBySafetySupervision(String safetySupervision) {
        LambdaQueryWrapper<Enterprise> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Enterprise::getSafetysupervision, safetySupervision)
                .eq(Enterprise::getValidflag, true);
        return enterpriseMapper.selectCount(queryWrapper);
    }
 
    @Override
    public IPage<Enterprise> selectParentEnterprise(Page<Enterprise> page, Map filter) {
        //重新赋一遍
        Map<String, Object> params = new HashMap<>();
        params.put("safetysupervision", filter.get("safetysupervision"));
        params.put("enterprisename", filter.get("enterprisename"));
        params.put("province", filter.get("province"));
        params.put("city", filter.get("city"));
        params.put("district", filter.get("district"));
        params.put("street", filter.get("street"));
        List<Enterprise> list = enterpriseMapper.selectParentPage(page, params);
        return page.setRecords(list);
    }
 
    @Override
    @Transactional
    public void delEnterprise(Long id, UserInfo user) {
 
        UserInfo userInfo = userService.getById(user.getId());
        Integer type = userInfo.getType();
        if (type != 1 && type != 2) {
            throw new BusinessException("没有权限删除");
        }
        //企业信息删除
        Enterprise enterprise = this.getById(id);
        if (enterprise == null) {
            throw new BusinessException("企业信息发生改变,请联系管理员");
        }
        enterprise.setInfoupdatebyname(user.getUsername());
        enterprise.setInfoupdatetime(new Date());
        enterprise.setValidflag(false);
        this.updateById(enterprise);
        //删除用户
        userService.deleteOneByCompanyId(id);
        //根据企业名称去删除所有产品
        productService.deleteByEnterpriseName(enterprise.getEnterprisename(),user.getUsername());
 
 
    }
 
    /**
     * @Description: 企业信息新增的校验
     * @date 2021/4/2 16:54
     */
    @Override
    public void checkAddEnterprise(Enterprise enterprise, Boolean flag) {
        if (StringUtils.isBlank(enterprise.getSafetysupervision())) {
            throw new BusinessException("安全监管分类不能为空");
        }
 
        if (StringUtils.isBlank(enterprise.getEconomicindustry())) {
            throw new BusinessException("国民经济行业分类不能为空");
        }
 
        if (StringUtils.isBlank(enterprise.getDepartment())) {
            throw new BusinessException("行政主管部门不能为空");
        }
 
        if (flag) {
            if (StringUtils.isBlank(enterprise.getPassword())) {
                throw new BusinessException("密码不能为空");
            }
 
            String PW_PATTERN = "(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~!@#$%^&*_.]).{8,}";
            if (!enterprise.getPassword().matches(PW_PATTERN)){
                throw new BusinessException("密码必须8位以上,并且包含大小写字母、数字、特殊符号三种以上");
            }
        }
 
 
        if (StringUtils.isBlank(enterprise.getEnterprisenumber())) {
            throw new BusinessException("单位编号不能为空");
        }
        //编号格式判断-不能有特殊字符
        String regEx= "[`~!@#$%^&*()+=|{}':;,\\[\\].<>/?!¥…()—【】‘;:”“’。,、?\\\\]";
        Pattern p = Pattern.compile(regEx);
        if (p.matcher(enterprise.getEnterprisenumber()).find()) {
            throw new BusinessException("单位编号不能包含特殊字符");
        }
        //单位编号判断重复
        if (this.isDuplicateNumber(enterprise.getEnterprisenumber(),enterprise.getId())) {
            throw new BusinessException("单位编号已经存在");
        }
 
        if (StringUtils.isBlank(enterprise.getEnterprisename())) {
            throw new BusinessException("企业名称不能为空");
        }
 
        //单位名称不能重复
        if (this.isDuplicateEnterpriseName(enterprise.getEnterprisename(), enterprise.getId())) {
            throw new BusinessException("企业名称已经存在");
        }
 
        if (!enterprise.getSafetysupervision().contains("长期") && StringUtils.isBlank(enterprise.getRegisteraddress())) {
            throw new BusinessException("单位注册地址不能为空");
        }
 
        if (!enterprise.getSafetysupervision().contains("短期") && StringUtils.isBlank(enterprise.getOfficeaddress())) {
            throw new BusinessException("单位办公地址不能为空");
        }
 
        if (StringUtils.isBlank(enterprise.getProvince())) {
            throw new BusinessException("所属省不能为空");
        }
 
        if (StringUtils.isBlank(enterprise.getCity())) {
            throw new BusinessException("所属市不能为空");
        }
 
        if (StringUtils.isBlank(enterprise.getOfficephone())) {
            throw new BusinessException("办公电话不能为空");
        }
 
        if (!enterprise.getSafetysupervision().contains("短期") &&
                !enterprise.getSafetysupervision().contains("长期") &&
                StringUtils.isBlank(enterprise.getFaxphone())) {
            throw new BusinessException("传真电话不能为空");
        }
 
        if (StringUtils.isBlank(enterprise.getDistrict())) {
            throw new BusinessException("所属区不能为空");
        }
 
        if (StringUtils.isBlank(enterprise.getBusinessregisternumber())) {
            throw new BusinessException("工商注册号不能为空");
        }
 
        if (StringUtils.isBlank(enterprise.getOrganizationstructurecode())) {
            throw new BusinessException("组织结构代码不能为空");
        }
 
 
        if (StringUtils.isBlank(enterprise.getProductioncontent())) {
            throw new BusinessException("生产经营项目不能为空");
        }
 
        if (enterprise.getEstablishtime() == null) {
            throw new BusinessException("成立时间不能为空");
        }
 
        if (StringUtils.isBlank(enterprise.getInsurancecompany())) {
            throw new BusinessException("保险公司名称不能为空,没有请填写无");
        }
 
        //非临时,有投必填
        if (!enterprise.getSafetysupervision().contains("临时")) {
            if (enterprise.getIspaysafetyinsurance()) {
                if (StringUtils.isBlank(enterprise.getInsurancecontractnumber())) {
                    throw new BusinessException("保单号不能为空");
                }
 
                if (enterprise.getInsureamount() == null) {
                    throw new BusinessException("投保金额不能为空");
                }
 
            }
        }
 
        //法定负责人
        if (enterprise.getLegalrepresentative() != null) {
 
            if (StringUtils.isBlank(enterprise.getLegalrepresentative().getName())) {
                throw new BusinessException("法定负责人姓名不能为空");
            }
 
            if (StringUtils.isBlank(enterprise.getLegalrepresentative().getPost())) {
                throw new BusinessException("法定负责人职务不能为空");
            }
            if (StringUtils.isBlank(enterprise.getLegalrepresentative().getIdentify())) {
                throw new BusinessException("法定负责人身份证号不能为空");
            }
            if (StringUtils.isBlank(enterprise.getLegalrepresentative().getPhone())) {
                throw new BusinessException("法定负责人手机号不能为空");
            }
            if (StringUtils.isBlank(enterprise.getLegalrepresentative().getOfficephone())) {
                throw new BusinessException("法定负责人办公室电话不能为空");
            }
            if (StringUtils.isBlank(enterprise.getLegalrepresentative().getNumber())) {
                throw new BusinessException("法定负责人合格证编号不能为空");
            }
            if (enterprise.getLegalrepresentative().getValidendtime() == null ||enterprise.getLegalrepresentative().getValidstarttime() == null ) {
                throw new BusinessException("法定负责人有效期不能为空");
            }
 
        }
 
        //主要负责人
        if (enterprise.getMainprincipal() != null) {
            if (StringUtils.isBlank(enterprise.getMainprincipal().getName())) {
                throw new BusinessException("主要负责人姓名不能为空");
            }
 
            if (StringUtils.isBlank(enterprise.getMainprincipal().getPost())) {
                throw new BusinessException("主要负责人职务不能为空");
            }
            if (StringUtils.isBlank(enterprise.getMainprincipal().getPhone())) {
                throw new BusinessException("主要负责人手机号不能为空");
            }
 
            if (StringUtils.isBlank(enterprise.getMainprincipal().getOfficephone())) {
                throw new BusinessException("主要负责人办公室电话不能为空");
            }
            if (StringUtils.isBlank(enterprise.getMainprincipal().getNumber())) {
                throw new BusinessException("主要负责人合格证编号不能为空");
            }
            if (enterprise.getMainprincipal().getValidendtime() == null ||enterprise.getMainprincipal().getValidstarttime() == null ) {
                throw new BusinessException("主要负责人有效期不能为空");
            }
 
        }
 
    }
 
    /**
    * @Description: 企业信息修改的校验
    * @date 2021/4/6 10:15
    */
    @Override
    public void checkModEnterprise(Enterprise enterprise) {
 
        if (enterprise.getId() == null) {
            throw new BusinessException("修改企业信息时发生错误,请联系管理员");
        }
 
        Enterprise theOne = this.getById(enterprise.getId());
        if (theOne == null) {
            throw new BusinessException("修改企业信息已发生变化,请联系管理员");
        }
 
        if (StringUtils.isBlank(enterprise.getSafetysupervision())) {
            throw new BusinessException("安全监管分类不能为空");
        }
 
        assert theOne.getSafetysupervision() != null;
        if (theOne.getSafetysupervision().equals(enterprise.getSafetysupervision())) {
            //接下来和新增判断一样
            this.checkAddEnterprise(enterprise,false);
        }
 
    }
 
    /**
    * @Description: 判断企业编号是否重复
    * @date 2021/4/20 16:18
    */
    @Override
    public boolean isDuplicateNumber(String enterpriseNumber, Long id) {
 
        LambdaQueryWrapper<Enterprise> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Enterprise::getEnterprisenumber, enterpriseNumber)
                .eq(Enterprise::getValidflag, true);
        //修改时:除自己以外是否还有重复
        if (id != null) {
            queryWrapper.ne(Enterprise::getId, id);
        }
        return enterpriseMapper.selectCount(queryWrapper) > 0;
    }
 
    /**
    * @Description: 判断企业名是否重复
    * @date 2021/4/20 16:16
    */
    @Override
    public boolean isDuplicateEnterpriseName(String enterpriseName, Long id) {
        LambdaQueryWrapper<Enterprise> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Enterprise::getEnterprisename, enterpriseName)
                .eq(Enterprise::getValidflag, true);
        //修改时:除自己以外是否还有重复
        if (id != null) {
            queryWrapper.ne(Enterprise::getId, id);
        }
        return enterpriseMapper.selectCount(queryWrapper) > 0;
    }
 
    @Override
    public List<Long> findEnterpriseIdsByLocation(String province, String city, String district, String street, String committee) {
        if(province == null || province.isEmpty()){
            return null;
        }
        if(province == null && city == null && district == null && street == null && committee == null){
            return null;
        }
        return enterpriseMapper.selectEnterpriseIdsByLocation(province,city,district,street,committee);
    }
 
 
 
    @Override
    public List<Enterprise> findEnterpriseListByLocation(String province, String city, String district, String street, String committee) {
        return enterpriseMapper.selectEnterpriseListByLocation(province,city,district,street,committee);
    }
 
    /**
    * @Description: 根据企业单位编号获取企业信息和实名登记和自查自改
    * @date 2021/4/14 8:25
    */
    @Override
    public Map getEnterpriseDetail(String enterpriseNumber, Integer days, String starttime, String endtime) {
        if (StringUtils.isBlank(enterpriseNumber)) {
            throw new BusinessException("企业单位编号为空");
        }
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(new Date());
        //当前日期往前推days天
        calendar.add(Calendar.DATE, -days);
        Date startTime = calendar.getTime();
        Map<String, Object> map = new HashMap<>();
        EnterpriseVo enterpriseVo = selctSimpleByNumber(enterpriseNumber);
        map.put("enterprise", enterpriseVo);
        //实名登记数量(入库数,销售数)
        Map registerNumObj = enterpriseMapper.selectInAndOut(enterpriseNumber,startTime);
        map.put("registerNum", registerNumObj);
        //自检自查报告
        List<Map>  reports= hiddenDangerReportMapper.getReportList(enterpriseNumber, startTime);
        if (reports.size() > 0) {
            for (Map report : reports) {
                int overduenum = hiddenDangerReportDetailService.countOverdueByReportCode((String) report.get("code"));
                //过期并且未处理
                report.put("overduenum",overduenum);
            }
        }
        map.put("reports", reports);
 
        Map<String, Object> params = new HashMap<>();
        params.put("enterprisename", enterpriseVo.getEnterprisename());
        params.put("starttime", starttime);
        params.put("endtime", endtime);
        List<Map> saleRecord =  saleOrderInfoMapper.selectSaleRecord3(params);
        map.put("saleRecord",saleRecord);
 
        return map;
    }
 
    @Override
    public EnterpriseVo selctSimpleByNumber(String enterprisenumber) {
        return enterpriseMapper.selctSimpleByNumber(enterprisenumber);
    }
    @Override
    public Enterprise selectEnterpriseByCompanyId(Long companyid) {
        LambdaQueryWrapper<Enterprise> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Enterprise::getId,companyid);
        return enterpriseMapper.selectOne(queryWrapper);
    }
 
    @Override
    public List<Enterprise> selectProduceEnterprise() {
        LambdaQueryWrapper<Enterprise> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Enterprise::getSafetysupervision, EnterpriseSafetySupervision.PRODUCE.getMsg());
        return enterpriseMapper.selectList(queryWrapper);
    }
 
    @Override
    public List<Enterprise> selectSaleEnterprise() {
        LambdaQueryWrapper<Enterprise> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.ne(Enterprise::getSafetysupervision, EnterpriseSafetySupervision.PRODUCE.getMsg());
        queryWrapper.eq(Enterprise::getValidflag,1);
        queryWrapper.eq(Enterprise::getEnterprisestatus ,"ON");
        return enterpriseMapper.selectList(queryWrapper);
    }
 
    @Override
    public List<Enterprise> selectSaleEnterprise(Map<String, Object>param) {
        LambdaQueryWrapper<Enterprise> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(param.get("filterProvince").toString())){
            queryWrapper.eq(Enterprise::getProvince,param.get("filterProvince"));
        }
        if (StringUtils.isNotBlank(param.get("filterCity").toString())){
            queryWrapper.eq(Enterprise::getCity,param.get("filterCity"));
        }
 
        if (StringUtils.isNotBlank(param.get("filterDistrict").toString())){
            queryWrapper.eq(Enterprise::getDistrict,param.get("filterDistrict"));
        }
        if (StringUtils.isNotBlank(param.get("filterStreet").toString())){
            queryWrapper.eq(Enterprise::getStreet,param.get("filterStreet"));
        }
        if (StringUtils.isNotBlank(param.get("filterCommittee").toString())){
            queryWrapper.eq(Enterprise::getCommittee,param.get("filterCommittee"));
        }
        if (StringUtils.isNotBlank(param.get("safetysupervision").toString())){
            queryWrapper.eq(Enterprise::getSafetysupervision,param.get("safetysupervision"));
        }
        if (StringUtils.isNotBlank(param.get("parententerprisename").toString())){
            queryWrapper.like(Enterprise::getParententerprisename,param.get("parententerprisename"));
        }
        queryWrapper.ne(Enterprise::getSafetysupervision, EnterpriseSafetySupervision.PRODUCE.getMsg());
        queryWrapper.eq(Enterprise::getEnterprisestatus, EnterpriseStatus.ON);
        queryWrapper.eq(Enterprise::getValidflag, true);
        return enterpriseMapper.selectList(queryWrapper);
    }
 
    @Override
    public List<Enterprise> selectSaleEnterprise(Map<String, Object> param, Page<Enterprise> page) {
        return enterpriseMapper.selectSaleEnterprise(param,page);
    }
 
    @Override
    public Enterprise selectEnterpriseByNumber(String number) {
        LambdaQueryWrapper<Enterprise> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Enterprise::getEnterprisenumber, number)
         .eq(Enterprise::getValidflag,true);
        return enterpriseMapper.selectOne(queryWrapper);
    }
 
    @Override
    public List<Map> getAllLocation(String city) {
        return enterpriseMapper.getAllLocation(city);
    }
 
    @Override
    public List<Map> getRetailStatisticsByArea() {
        Map<String, Object> params = new HashMap<>();
        params.put("province", "新疆维吾尔自治区");
        return enterpriseMapper.getRetailStatisticsByArea(params);
    }
 
    /**
    * @Description: 导出企业信息
    * @date 2021/4/19 8:51
    */
    @Override
    public List<EnterpriseExportVo> selectExportEnterprise(Map filter, UserInfo user) {
 
        UserInfo userInfo = userService.getById(user.getId());
        Map<String, Object> params = new HashMap<>();
        //监管部门 根据 地区看所有
        params.put("enterprisenumber", userInfo.getCompanynumber());
        params.put("province", userInfo.getProvince());
        params.put("city", userInfo.getCity());
        params.put("district", userInfo.getArea());
        params.put("street", userInfo.getTown());
        params.put("committee", userInfo.getCommunity());
        //企业用户
        params.put("companyId", userInfo.getCompanyid());
 
        //过滤条件
        { //企业类型
            params.put("safetySupervision", filter.get("safetysupervision"));
            //经济类型
            params.put("economicIndustry", filter.get("economicindustry"));
            //许可证有效|过期
            params.put("valid", filter.get("valid"));
            //地区
            params.put("filterProvince", filter.get("province"));
            params.put("filterCity", filter.get("city"));
            params.put("filterDistrict", filter.get("district"));
            params.put("filterStreet", filter.get("street"));
            params.put("filterCommittee", filter.get("committee"));
            //企业名称
            params.put("enterprisename", filter.get("enterprisename"));
 
        }
        return enterpriseMapper.selectExportEnterprise(params);
    }
 
    /**
    * @Description: 企业信息导入
    * @date 2021/4/19 9:08
    */
    @Override
    public BooleanReason importEnterprise(MultipartFile file,UserInfo userInfo) {
 
        UserInfo user = userService.getById(userInfo.getId());
        if (user.getCompanynumber() != null) {
            throw new BusinessException("没有导入权限");
        }
        if(!FileOptUtils.isDirExists(Properties.filePath)){
            throw new BusinessException("发生错误或不为目录");
        }
 
        if (file == null || file.getSize() == 0) {
            throw new BusinessException("上传文件或者请求出现问题");
        }
 
        if(!FileOptUtils.isDirExists(Properties.filePath)){
            throw new BusinessException("发生错误或不为目录");
        }
 
        SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMddHHmmssSSS" );
        String fileSave = Properties.filePath + userInfo.getUsername() + "_" + sdf.format(new Date()) +".xlsx";
 
        try {
            file.transferTo(new File(fileSave));
            InputStream in = new FileInputStream(fileSave);
            String name = file.getOriginalFilename();
            assert name != null;
            Boolean isExcel2007 = name.substring(name.lastIndexOf(".") + 1).endsWith("xlsx");
            return excelExportService.importEnterpriseExcel(in, userInfo, isExcel2007);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            throw new BusinessException("找不到文件");
        } catch (IOException e) {
            e.printStackTrace();
            throw new BusinessException("发生错误,请联系管理员");
        }
 
 
    }
 
    @Override
    public int getSaleNum() {
        return enterpriseMapper.getSaleNum(Collections.singletonMap("safetysupervision",EnterpriseSafetySupervision.PRODUCE.getMsg()));
    }
 
    @Override
    public List<SaleOrderDetailInfo> getEnterpriseSaleDetail(String enterpriseNumber, String itemcode, String starttime, String endtime) {
        return saleOrderInfoMapper.getEnterpriseSaleDetail(enterpriseNumber, itemcode, starttime, endtime);
    }
 
    @Override
    public Enterprise selectEnterpriseByName(String name) {
        LambdaQueryWrapper<Enterprise> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Enterprise::getEnterprisename, name)
                    .eq(Enterprise::getValidflag,true);
        return enterpriseMapper.selectOne(queryWrapper);
    }
 
 
    /**
     * @Description: 停用企业
     * @date 2021/5/28 15:58
     */
    @Override
    @Transactional
    public void deactivateEnterprise(Long id,String enterprisenumber, UserInfo user) {
        Enterprise enterprise = null;
        if (id == null && StringUtils.isBlank(enterprisenumber))
            throw new BusinessException("参数传递错误");
 
        if (id != null)
            enterprise = this.getById(id);
 
        if (enterprise == null)
            enterprise = this.selectEnterpriseByNumber(enterprisenumber);
 
        if (enterprise == null) {
            throw new BusinessException("没有该企业");
        }
        //1.修改企业状态为 停止
        this.setEnterpriseStatus(EnterpriseStatus.OFF, enterprise.getId());
 
        //2.修改企业用户isdel=1     3.修改终端用户isdel=1
        List<UserInfo> userList = userService.selectByCompanyId(enterprise.getId(),0);
        if (userList.size() != 2) {
            throw new BusinessException("发生错误,请联系管理员");
        }
        for (UserInfo info : userList) {
            userService.deleteById(info.getId());
        }
 
    }
 
    @Override
    @Transactional
    public void activateEnterprise(Long id,String enterprisenumber, UserInfo user) {
        Enterprise enterprise = null;
        if (id == null && StringUtils.isBlank(enterprisenumber))
            throw new BusinessException("参数传递错误");
 
        if (id != null)
            enterprise = this.getById(id);
 
        if (enterprise == null)
            enterprise = this.selectEnterpriseByNumber(enterprisenumber);
 
        if (enterprise == null) {
            throw new BusinessException("没有该企业");
        }
        //1.修改企业状态为 启用
        this.setEnterpriseStatus(EnterpriseStatus.ON, enterprise.getId());
        //2.修改企业用户isdel 0
        //3.修改终端用户isdel 0
        List<UserInfo> userList = userService.selectByCompanyId(enterprise.getId(),1);
        if (userList.size() != 2) {
            throw new BusinessException("发生错误,请联系管理员");
        }
        for (UserInfo info : userList) {
            userService.recoverOneById(info.getId());
        }
    }
 
    @Override
    public void setEnterpriseStatus(EnterpriseStatus status, Long id) {
        if (id == null) {
            throw new BusinessException("参数传递不能为空");
        }
        LambdaUpdateWrapper<Enterprise> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(Enterprise::getEnterprisestatus, status)
                .eq(Enterprise::getId, id);
        this.update(updateWrapper);
    }
 
    @Override
    public int countAllUndoneEnterprise(UserInfo userInfo) {
        Map<String, Object> params = new HashMap<>();
        params.put("province", userInfo.getProvince());
        params.put("city", userInfo.getCity());
        params.put("district", userInfo.getArea());
        params.put("street", userInfo.getTown());
        params.put("committee", userInfo.getCommunity());
        return enterpriseMapper.countAllUndoneEnterprise(params);
    }
 
    @Override
    public int countAllEnterpriseExpired(UserInfo userInfo) {
        Map<String, Object> params = new HashMap<>();
        params.put("province", userInfo.getProvince());
        params.put("city", userInfo.getCity());
        params.put("district", userInfo.getArea());
        params.put("street", userInfo.getTown());
        params.put("committee", userInfo.getCommunity());
        return enterpriseMapper.countAllEnterpriseExpired(params);
    }
 
    @Override
    public void addEnterpriseByRegister(RegisterInfo registerInfo, UserInfo userInfo) {
        Enterprise enterprise = new Enterprise();
        enterprise.setSafetysupervision(registerInfo.getType());
        enterprise.setEnterprisenumber(registerInfo.getEnterprisenumber());
        enterprise.setEnterprisename(registerInfo.getEnterprisename());
        enterprise.setProvince(registerInfo.getProvince());
        enterprise.setCity(registerInfo.getCity());
        enterprise.setDistrict(registerInfo.getDistrict());
        enterprise.setStreet(registerInfo.getStreet());
        enterprise.setCommittee(registerInfo.getCommittee());
        enterprise.setRegisteraddress(registerInfo.getAddress());
        enterprise.setPassword(Base64Encrypt.encode(registerInfo.getPassword().getBytes()));
        int i = enterpriseService.countBySafetySupervision(enterprise.getSafetysupervision());
        enterprise.setDivideflag((byte) (DivideFlagUtil.enterpriseDivideFlagGenerate(i)));
        enterprise.setInfocreatebyname(userInfo.getUsername());
        enterprise.setInfocreateby(userInfo.getId());
        enterprise.setInfoupdatetime(new Date());
        enterprise.setValidflag(true);
 
        enterpriseService.save(enterprise);
 
        //保存用户
        UserInfo user = new UserInfo();
        user.setIsdel((byte) 0);
        user.setProvince(enterprise.getProvince());
        user.setCity(enterprise.getCity());
        user.setArea(enterprise.getDistrict());
        user.setUsername(enterprise.getEnterprisename());
        user.setCompany(enterprise.getEnterprisename());
        user.setIssale((byte) 0);
        //普通用户
        user.setType(3);
        user.setCreatedby(user.getUsername());
        user.setCompanyid(enterprise.getId());
        user.setCreateddate(new Date());
        //设置密码
        user.setPassword(enterprise.getPassword());
        user.setCompanynumber(enterprise.getEnterprisenumber());
        //执行
        userService.save(user);
 
        //如果有企业角色设置用户角色为企业
        UserRolesInfo uri = new UserRolesInfo();
        uri.setUserid(user.getId());
        if (enterprise.getSafetysupervision().equals(EnterpriseSafetySupervision.PRODUCE.getMsg())){
            uri.setRoleid((long) 3);
        }else {
            uri.setRoleid((long) 2);
        }
        userRolesService.save(uri);
        //终端机
        user.setId(null);
        user.setUsername(enterprise.getEnterprisenumber());
        user.setIssale((byte) 1);
        user.setStatus((byte) 1);
        userService.save(user);
    }
 
    @Override
    public List<Enterprise> selectListUnderSupervision(Integer type,UserInfo userInfo) {
        List<Enterprise> result = new ArrayList<>();
        Map<String, Object> params = new HashMap<>();
        UserInfo user = userService.getById(userInfo);
        if (StringUtils.isBlank(user.getCompanynumber())) {
            params.put("province", user.getProvince());
            params.put("city", user.getCity());
            params.put("district", user.getArea());
            params.put("street", user.getTown());
            params.put("committee", user.getCommunity());
            params.put("safetysupervision", EnterpriseSafetySupervision.PRODUCE.getMsg());
            //1生产企业,2销售企业
            params.put("type", type);
            result=  enterpriseMapper.selectListUnderSupervision(params);
        }
        return result;
 
    }
 
    @Override
    public IPage selectUndoneList(Page<Enterprise> page, Map filter,UserInfo userInfo) {
        Map<Object, Object> params = new HashMap<>();
        List<Enterprise> undoneList = null;
        UserInfo user = userService.getById(userInfo);
        //可见度
        if (StringUtils.isBlank(user.getCompanynumber())) {
            params.put("province", user.getProvince());
            params.put("city", user.getCity());
            params.put("district", user.getArea());
            params.put("street", user.getTown());
            params.put("committee", user.getCommunity());
 
            //过滤条件
            params.put("enterprisename", filter.get("enterprisename"));
            params.put("filterProvince", filter.get("province"));
            params.put("filterCity", filter.get("city"));
            params.put("filterDistrict", filter.get("district"));
            params.put("filterStreet", filter.get("street"));
            params.put("filterCommittee", filter.get("committee"));
            undoneList = enterpriseMapper.selectUndoneList(page,params);
 
        }
 
        return page.setRecords(undoneList);
    }
 
    @Override
    public List<Enterprise> selectExportUndoneList(Map filter, UserInfo userInfo) {
        Map<Object, Object> params = new HashMap<>();
        List<Enterprise> undoneList = null;
        UserInfo user = userService.getById(userInfo);
        //可见度
        if (StringUtils.isBlank(user.getCompanynumber())) {
            params.put("province", user.getProvince());
            params.put("city", user.getCity());
            params.put("district", user.getArea());
            params.put("street", user.getTown());
            params.put("committee", user.getCommunity());
 
            //过滤条件
            params.put("enterprisename", filter.get("enterprisename"));
            params.put("filterProvince", filter.get("province"));
            params.put("filterCity", filter.get("city"));
            params.put("filterDistrict", filter.get("district"));
            params.put("filterStreet", filter.get("street"));
            params.put("filterCommittee", filter.get("committee"));
            undoneList = enterpriseMapper.selectUndoneList(params);
        }
        return undoneList;
    }
 
    @Override
    public boolean isDuplicate2BitCode(String twoBit) {
        LambdaQueryWrapper<Enterprise> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Enterprise::getTwobitcode, twoBit)
                .eq(Enterprise::getValidflag,true);
        return enterpriseMapper.selectCount(queryWrapper) > 0;
    }
 
    @Override
    public IPage selectExpiredList(Page<Enterprise> page, Map filter, UserInfo userInfo) {
        Map<Object, Object> params = new HashMap<>();
        List<Enterprise> expiredList = null;
        UserInfo user = userService.getById(userInfo);
        //可见度
        if (StringUtils.isBlank(user.getCompanynumber())) {
            params.put("province", user.getProvince());
            params.put("city", user.getCity());
            params.put("district", user.getArea());
            params.put("street", user.getTown());
            params.put("committee", user.getCommunity());
 
            //过滤条件
            params.put("enterprisename", filter.get("enterprisename"));
            params.put("filterProvince", filter.get("province"));
            params.put("filterCity", filter.get("city"));
            params.put("filterDistrict", filter.get("district"));
            params.put("filterStreet", filter.get("street"));
            params.put("filterCommittee", filter.get("committee"));
            expiredList = enterpriseMapper.selectExpiredList(page,params);
        }
        return page.setRecords(expiredList);
    }
 
    @Override
    public List<Enterprise> selectExportExpiredList(Map<String, Object> filter, UserInfo userInfo) {
        Map<Object, Object> params = new HashMap<>();
        List<Enterprise> expiredList = null;
        UserInfo user = userService.getById(userInfo);
        //可见度
        if (StringUtils.isBlank(user.getCompanynumber())) {
            params.put("province", user.getProvince());
            params.put("city", user.getCity());
            params.put("district", user.getArea());
            params.put("street", user.getTown());
            params.put("committee", user.getCommunity());
 
            //过滤条件
            params.put("enterprisename", filter.get("enterprisename"));
            params.put("filterProvince", filter.get("province"));
            params.put("filterCity", filter.get("city"));
            params.put("filterDistrict", filter.get("district"));
            params.put("filterStreet", filter.get("street"));
            params.put("filterCommittee", filter.get("committee"));
            expiredList = enterpriseMapper.selectExpiredList(params);
        }
        return expiredList;
    }
 
    @Override
    public List<Enterprise> selectSubEnterprise(Long enterpriseId) {
 
        Enterprise parent = enterpriseService.getById(enterpriseId);
        if (parent == null) throw new BusinessException("不存在企业信息");
        LambdaQueryWrapper<Enterprise> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Enterprise::getParententerprisename, parent.getEnterprisename())
                .eq(Enterprise::getValidflag,true)
                .eq(Enterprise::getEnterprisestatus,EnterpriseStatus.ON);
        return enterpriseMapper.selectList(queryWrapper);
    }
 
    @Override
    public List<Enterprise> getEnterpriseByLimit(Map<String, Object> condition) {
        return enterpriseMapper.getEnterpriseByLimit(condition);
    }
 
    @Override
    public Integer getEnterpriseByLimitCount(Map<String, Object> condition) {
        return enterpriseMapper.getEnterpriseByLimitCount(condition);
    }
 
    @Override
    public BooleanReason importDlCompanyCode(MultipartFile file, UserInfo userInfo) {
        UserInfo user = userService.getById(userInfo.getId());
        if (user.getCompanynumber() != null)
            throw new BusinessException("没有导入权限");
 
        if (file == null || file.getSize() == 0)
            throw new BusinessException("上传文件或者请求出现问题");
 
        try {
            String name = file.getOriginalFilename();
            InputStream in = file.getInputStream();
            assert name != null;
            boolean isExcel2007 = name.substring(name.lastIndexOf(".") + 1).endsWith("xlsx");
            return excelExportService.importDLCompanyCodeExcel(in, userInfo, isExcel2007);
        } catch (BusinessException e) {
            throw new BusinessException(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("导入失败,请联系管理员");
        }
    }
 
    @Override
    public List<Enterprise> exportDlCompanyCode() {
        LambdaQueryWrapper<Enterprise> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper
                .select(Enterprise::getEnterprisename,
                        Enterprise::getDlcompanycode,
                        Enterprise::getDeviceid)
                .eq(Enterprise::getValidflag, true)
                .isNotNull(Enterprise::getDlcompanycode);
        return enterpriseMapper.selectList(queryWrapper);
    }
 
    @Override
    public List<Enterprise> selectAllDlCompanyCodeIsNotNull() {
        LambdaQueryWrapper<Enterprise> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper
                .select(Enterprise::getId,
                        Enterprise::getEnterprisenumber,
                        Enterprise::getDlcompanycode)
                .eq(Enterprise::getValidflag,true)
                .isNull(Enterprise::getDeviceid)
                .isNotNull(Enterprise::getDlcompanycode);
 
        return enterpriseMapper.selectList(queryWrapper);
    }
 
    @Override
    public void updateCompanyCode(Enterprise e) {
        enterpriseMapper.updateCompanyCodeAndSetDeviceIdNull(e);
    }
 
    @Override
    public List<Enterprise> selectSaleEnterpriseForUpload() {
        LambdaQueryWrapper<Enterprise> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.ne(Enterprise::getSafetysupervision, EnterpriseSafetySupervision.PRODUCE.getMsg());
        queryWrapper.eq(Enterprise::getValidflag,1);
        queryWrapper.eq(Enterprise::getEnterprisestatus ,"ON");
        queryWrapper.isNotNull(Enterprise::getDlcompanycode);
        queryWrapper.isNotNull(Enterprise::getDeviceid);
        return enterpriseMapper.selectList(queryWrapper);
    }
 
 
    /*
        判断是否注销 true 注销,flase 正常
     */
    @Override
    public boolean isLogOut(String companynumber) {
        boolean flag = false;
        if (StringUtils.isBlank(companynumber)) throw new BusinessException("企业编号为空");
        LambdaQueryWrapper<Enterprise> queryWrapper = new LambdaQueryWrapper<>();
        Enterprise enterprise = enterpriseMapper.selectOne(
                queryWrapper.select(Enterprise::getEnterprisename,Enterprise::getLoginvalidflag)
                        .eq(Enterprise::getEnterprisenumber, companynumber));
        if (enterprise == null) throw new BusinessException("企业不存在");
        if ( enterprise.getLoginvalidflag() != null && !enterprise.getLoginvalidflag()) flag = true;
        return flag;
    }
 
    @Override
    @Transactional
    public void logout(List<Long> ids, UserInfo user) {
        if (user.getType() != 1) throw new BusinessException("没有权限");
        if (ids == null || ids.size() < 1) throw new BusinessException("参数为空");
        for (Long id : ids) {
            enterpriseMapper.updateLoginValidFlag(id,false);
        }
 
    }
 
    @Override
    public void recoverLogin(Long id, UserInfo user) {
        if (user.getType() != 1) throw new BusinessException("没有权限");
        if(id == null) throw new BusinessException("参数为空");
        enterpriseMapper.updateLoginValidFlag(id,true);
    }
 
    @Override
    @Transactional
    public void recoverLoginBatch(List<Long> ids, UserInfo user) {
        if (user.getType() != 1) throw new BusinessException("没有权限");
        if (ids == null || ids.size() < 1) throw new BusinessException("参数为空");
        for (Long id : ids) {
            enterpriseMapper.updateLoginValidFlag(id,true);
        }
    }
 
    @Override
    public List<Enterprise> selectEnterpriseListByNameLike(String name) {
        if(name == null || name.isEmpty()){
            return null;
        }else {
            return enterpriseMapper.selectEnterpriseListByNameLike(name);
        }
    }
 
    private String compareObj(Class clazz,Object obj1,Object obj2) throws IllegalAccessException {
        Class<?> class1 = obj1.getClass();
        Class<?> class2 = obj2.getClass();
        Field[] fields = clazz.getDeclaredFields();
        JSONObject jo = new JSONObject();
        if (fields.length> 0) {
            for (Field field : fields) {
                field.setAccessible(true);
                String name = field.getName();
                if (!name.equals("serialVersionUID")&& !name.equals("divideflag")
                        && !Objects.equals(field.get(obj1),field.get(obj2))) {
 
                        if (field.get(obj1) != null && field.get(obj2) == null){
                            jo.put(name, "");
                        }else{
                            if (name.equals("legalrepresentative") ||
                                    name.equals("mainprincipal")||
                                    name.equals("securityofficer")||
                                    name.equals("informationofficer")){
                                String o1 = (String) field.get(obj1);
                                String o2 = (String) field.get(obj2);
 
                                JSONObject jsonObject1 = JSONObject.parseObject(o1);
                                JSONObject jsonObject2 = JSONObject.parseObject(o2);
                                Map<String, Object> innerMap1 = jsonObject1.getInnerMap();
                                Map<String, Object> innerMap2 = jsonObject2.getInnerMap();
                                for (Map.Entry<String, Object> entry : innerMap1.entrySet()) {
                                    String f = entry.getKey();
                                    Object value1 = innerMap1.get(f);
                                    Object value2= innerMap2.get(f);
                                    if (!Objects.equals(value1, value2)) {
                                        jo.put(f, value2);
                                    }
 
                                }
                            }
 
                            jo.put(name, field.get(obj2));
                        }
 
 
 
 
 
 
                }
            }
        }
 
        return jo.isEmpty()?null:jo.toJSONString();
    }
 
 
}