AdministerServiceImpl.java
96.5 KB
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
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
package com.subsidy.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.subsidy.common.RedisPrefixConstant;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.administer.ClassDailyInfoDTO;
import com.subsidy.dto.administer.ClassDetailDTO;
import com.subsidy.dto.administer.ClassVodDailyInfoDTO;
import com.subsidy.dto.administer.ClassVodInfoDTO;
import com.subsidy.dto.administer.MemberStudyLogDTO;
import com.subsidy.dto.administer.OperatorsDTO;
import com.subsidy.dto.member.ImportMemberDTO;
import com.subsidy.mapper.AdministerMapper;
import com.subsidy.mapper.AnsweringQuestionMapper;
import com.subsidy.mapper.ClassDictMapper;
import com.subsidy.mapper.ClassMemberMappingMapper;
import com.subsidy.mapper.CompanyDictMapper;
import com.subsidy.mapper.CourseDictMapper;
import com.subsidy.mapper.DepartmentDictMapper;
import com.subsidy.mapper.ExerciseDoneResultMapper;
import com.subsidy.mapper.MemberDepartmentMappingMapper;
import com.subsidy.mapper.MemberMapper;
import com.subsidy.mapper.OprAdmDictMapper;
import com.subsidy.mapper.RoleAdministerMappingMapper;
import com.subsidy.mapper.VodDictMapper;
import com.subsidy.mapper.VodPlayHistoryMapper;
import com.subsidy.model.AdministerDO;
import com.subsidy.model.AnsweringQuestionDO;
import com.subsidy.model.ClassDictDO;
import com.subsidy.model.ClassMemberMappingDO;
import com.subsidy.model.CompanyDictDO;
import com.subsidy.model.CourseDictDO;
import com.subsidy.model.DepartmentDictDO;
import com.subsidy.model.ExerciseDoneHistoryDO;
import com.subsidy.model.ExerciseDoneResultDO;
import com.subsidy.model.MemberDO;
import com.subsidy.model.MemberDepartmentMappingDO;
import com.subsidy.model.RoleAdministerMappingDO;
import com.subsidy.model.SignInRecordDO;
import com.subsidy.model.VodDictDO;
import com.subsidy.model.OprAdmDictDO;
import com.subsidy.service.AdministerService;
import com.subsidy.service.FieldDictService;
import com.subsidy.util.ConstantUtils;
import com.subsidy.util.DateFormatUtil;
import com.subsidy.util.ExcelFormatUtils;
import com.subsidy.util.JwtUtil;
import com.subsidy.util.Localstorage;
import com.subsidy.util.MathUtil;
import com.subsidy.util.RedisUtil;
import com.subsidy.util.excel.ExcelUtil;
import com.subsidy.vo.administer.AdministerPermissionVO;
import com.subsidy.vo.administer.ClassDailyInfoVO;
import com.subsidy.vo.administer.ClassSummaryVO;
import com.subsidy.vo.administer.ClassVodDailyInfoItemVO;
import com.subsidy.vo.administer.ClassVodInfoVO;
import com.subsidy.vo.administer.ExerciseTestVO;
import com.subsidy.vo.administer.GetMemberPapersVO;
import com.subsidy.vo.administer.GetPaperDetailVO;
import com.subsidy.vo.administer.LoginVO;
import com.subsidy.vo.administer.MemberStudyLogVO;
import com.subsidy.vo.administer.OperatorsVO;
import com.subsidy.vo.administer.PermissionsVO;
import com.subsidy.vo.classdict.ClassDetailVO;
import com.subsidy.vo.done.GetMaxScoreVO;
import com.subsidy.vo.done.TestScoreInfoVO;
import com.subsidy.vo.member.ClassSignVO;
import com.subsidy.vo.sign.AnswerRecordVO;
import com.subsidy.vo.vod.ClassMemberPlayLengthVO;
import com.subsidy.vo.vod.ClassVodCompleteInfoVO;
import com.subsidy.vo.vod.DayInfoItemVO;
import com.subsidy.vo.vod.GetMemberStudyInfoVO;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFCell;
import org.apache.poi.xssf.streaming.SXSSFRow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/**
* <p>
* 管理平台用户 服务实现类
* </p>
*
* @author DengMin
* @since 2021-10-11
*/
@Service
public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, AdministerDO> implements AdministerService {
@Autowired
private ClassDictMapper classDictMapper;
@Autowired
private VodPlayHistoryMapper vodPlayHistoryMapper;
@Autowired
private ExerciseDoneResultMapper exerciseDoneResultMapper;
@Autowired
private AnsweringQuestionMapper answeringQuestionMapper;
@Autowired
private ClassMemberMappingMapper classMemberMappingMapper;
@Autowired
private CourseDictMapper courseDictMapper;
@Autowired
private CompanyDictMapper companyDictMapper;
@Autowired
private RoleAdministerMappingMapper roleAdministerMappingMapper;
@Autowired
private MemberMapper memberMapper;
@Autowired
private DepartmentDictMapper departmentDictMapper;
@Autowired
private MemberDepartmentMappingMapper memberDepartmentMappingMapper;
@Autowired
private VodDictMapper vodDictMapper;
@Autowired
private RedisUtil redisUtil;
@Autowired
private OprAdmDictMapper oprAdmDictMapper;
@Autowired
private FieldDictService fieldDictService;
//@Autowired
//private MongoTemplate mongoTemplate;
public LoginVO login(AdministerDO administerDO) {
LoginVO loginVO = new LoginVO();
/**
* 先从redis里拿
*/
AdministerDO administerDO1 = (AdministerDO) redisUtil.get(RedisPrefixConstant.SUBSIDY_ADMINISTER_PREFIX + administerDO.getAccountName());
if (null == administerDO1) {
/**
* 查表,并将数据写入到redis
*/
administerDO1 = this.baseMapper.selectOne(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getAccountName, administerDO.getAccountName()));
redisUtil.set(RedisPrefixConstant.SUBSIDY_ADMINISTER_PREFIX + administerDO.getAccountName(), administerDO1);
}
if ("0".equals(administerDO1.getStatus())) {
throw new HttpException(10013);
}
/**
* 最近5次都输入失败,5分钟后再验证
*/
List<OprAdmDictDO> oprAdmDictDOS = oprAdmDictMapper.getLoginInfo(administerDO1.getId());
//查mysql逻辑
//List<OprAdmDictDO> oprAdmDictDOS = oprAdmDictMapper.getLoginInfo(administerDO1.getId());
boolean flag = false;
for (int i = 0; i < oprAdmDictDOS.size(); i++) {
if (oprAdmDictDOS.get(i).getResult() == 1) {
flag = true;
break;
}
}
if (!flag && oprAdmDictDOS.size() >= 4) {
throw new HttpException(10016);
}
if (null != administerDO1) {
if (administerDO.getPassword().equals(administerDO1.getPassword())) {
String token = JwtUtil.generateToken(administerDO1.getId(), ConstantUtils.ADMINISTER_TERMINATE);
//登录成功,记录日志
OprAdmDictDO oprAdmDictDO = new OprAdmDictDO();
oprAdmDictDO.setUserId(administerDO1.getId());
oprAdmDictDO.setOprType("登录");
oprAdmDictDO.setResult(1);
//oprAdmDictDO.setCreateDate(System.currentTimeMillis() + "");
//oprAdmDictDO.setLoginDateFormat(DateFormatUtil.format(new Date(), "yyyyMMdd"));
//oprAdmDictDO.setUserName(administerDO1.getUserName());
//oprAdmDictDO.setCompanyId(administerDO1.getCompanyId());
oprAdmDictMapper.insert(oprAdmDictDO);
//mongoTemplate.insert(oprAdmDictDO);
loginVO.setToken(token);
return loginVO;
} else {
//登录失败,记录日志
OprAdmDictDO oprAdmDictDO = new OprAdmDictDO();
oprAdmDictDO.setUserId(administerDO1.getId());
oprAdmDictDO.setOprType("登录");
oprAdmDictDO.setResult(0);
oprAdmDictMapper.insert(oprAdmDictDO);
//oprAdmDictDO.setCreateDate(System.currentTimeMillis() + "");
//oprAdmDictDO.setLoginDateFormat(DateFormatUtil.format(new Date(), "yyyyMMdd"));
//oprAdmDictDO.setUserName(administerDO1.getUserName());
//oprAdmDictDO.setCompanyId(administerDO1.getCompanyId());
//mongoTemplate.insert(oprAdmDictDO);
int i = 0;
for (OprAdmDictDO oad : oprAdmDictDOS) {
if (oad.getResult() == 1) {
break;
}
i++;
}
if (i == 0) {
throw new HttpException(10024);
} else if (i == 1) {
throw new HttpException(10023);
} else if (i == 2) {
throw new HttpException(10022);
} else if (i == 3) {
throw new HttpException(10021);
} else {
throw new HttpException(10016);
}
}
} else {
throw new HttpException(10011);
}
}
public AdministerPermissionVO getPermissions() {
AdministerPermissionVO administerPermissionVO = new AdministerPermissionVO();
AdministerDO administerDO = (AdministerDO) Localstorage.getUser();
if (administerDO == null) {
throw new HttpException(10012);
}
BeanUtils.copyProperties(administerDO, administerPermissionVO);
List<PermissionsVO> list = this.baseMapper.getPermissions(administerDO.getId());
List<PermissionsVO> treeList = new ArrayList();
if (list != null) {
list.forEach(permission -> {
if (permission.getParentId() == null) {
treeList.add(permission);
}
list.forEach(p -> {
if (null != p.getParentId() && p.getParentId().equals(permission.getId())) {
if (permission.getChildren() == null) {
permission.setChildren(new ArrayList<>());
}
permission.getChildren().add(p);
}
});
});
}
administerPermissionVO.setPermissions(treeList);
return administerPermissionVO;
}
public IPage<OperatorsVO> operators(OperatorsDTO operatorsDTO) {
Page pager = new Page(operatorsDTO.getPageNum(), operatorsDTO.getPageSize());
//判断该用户的角色
Integer count = roleAdministerMappingMapper.selectCount(new QueryWrapper<RoleAdministerMappingDO>()
.lambda()
.eq(RoleAdministerMappingDO::getAdministerId, operatorsDTO.getId())
.eq(RoleAdministerMappingDO::getRoleId, 1));
if (count > 0) {
operatorsDTO.setId(null);
}
IPage<OperatorsVO> operatorsVOIPage = companyDictMapper.operators(pager, operatorsDTO.getCompanyName(), operatorsDTO.getId(), operatorsDTO.getUserName(), 0);
List<OperatorsVO> operatorsVOS = operatorsVOIPage.getRecords();
for (OperatorsVO operatorsVO : operatorsVOS){
//operatorsVO.getField()
}
return operatorsVOIPage;
}
public String addAdminister(AdministerDO administerDO) {
int count = this.baseMapper.selectCount(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getAccountName, administerDO.getAccountName()));
if (count > 0) {
throw new HttpException(20002);
}
administerDO.setRole(0);
administerDO.setPassword("admin123");
administerDO.setStatus("1");
this.baseMapper.insert(administerDO);
RoleAdministerMappingDO roleAdministerMappingDO = new RoleAdministerMappingDO();
roleAdministerMappingDO.setAdministerId(administerDO.getId());
roleAdministerMappingDO.setRoleId(1L);
roleAdministerMappingMapper.insert(roleAdministerMappingDO);
return ConstantUtils.ADD_SUCCESS;
}
public String deleteAdminister(AdministerDO administerDO) {
this.baseMapper.deleteById(administerDO.getId());
roleAdministerMappingMapper.delete(new QueryWrapper<RoleAdministerMappingDO>()
.lambda()
.eq(RoleAdministerMappingDO::getAdministerId, administerDO.getId()));
return ConstantUtils.DELETE_SUCCESS;
}
public String updateAdminister(AdministerDO administerDO) {
int count = this.baseMapper.selectCount(new QueryWrapper<AdministerDO>()
.lambda()
.eq(AdministerDO::getAccountName, administerDO.getAccountName())
.ne(AdministerDO::getId, administerDO.getId()));
if (count > 0) {
throw new HttpException(20002);
}
this.baseMapper.updateById(administerDO);
AdministerDO administerDO1 = this.baseMapper.selectById(administerDO.getId());
//更新redis里该老师的数据
redisUtil.set(RedisPrefixConstant.SUBSIDY_ADMINISTER_PREFIX + administerDO1.getAccountName(), administerDO1);
return ConstantUtils.SET_SUCCESS;
}
public ClassSummaryVO classSummary(ClassDetailDTO classDetailDTO) {
ClassSummaryVO classSummaryVO = new ClassSummaryVO();
ClassDictDO classDictDO = classDictMapper.selectById(classDetailDTO.getId());
classSummaryVO.setClassId(classDetailDTO.getId());
classSummaryVO.setClassName(classDictDO.getClassName());
classSummaryVO.setStartDate(classDictDO.getStartDate());
classSummaryVO.setEndDate(classDictDO.getEndDate());
CourseDictDO courseDictDO = courseDictMapper.selectById(classDictDO.getCourseId());
classSummaryVO.setCourseName(courseDictDO.getCourseName());
//班级人数
List<ClassMemberMappingDO> classMemberMappingDOS = classMemberMappingMapper.selectList(new QueryWrapper<ClassMemberMappingDO>()
.lambda()
.eq(ClassMemberMappingDO::getClassId, classDetailDTO.getId()));
classSummaryVO.setMemberCount(classMemberMappingDOS.size());
//课程总数
List<VodDictDO> vodDictDOS = classDictMapper.getClassVods(classDetailDTO.getId());
classSummaryVO.setTotalVodCounts(vodDictDOS.size());
/**
* 学生平均学习时长和平均学习次数
*/
int totalStudyVods = 0;
int totalStudyLength = 0;
//学生总共学习课时数
for (VodDictDO vodDictDO : vodDictDOS) {
for (ClassMemberMappingDO classMemberMappingDO : classMemberMappingDOS) {
int totalLength = vodPlayHistoryMapper.memberVodTotalLength(classMemberMappingDO.getMemberId(), vodDictDO.getId());
if (totalLength >= vodDictDO.getVodLength()) {
totalStudyVods++;
}
totalStudyLength+=totalLength;
}
}
classSummaryVO.setStudyVodCounts(MathUtil.intDivCeil(totalStudyVods, classMemberMappingDOS.size()));
//平均完成时长 学生观看课程视频的全部时长/总人数
int avg = MathUtil.intDivCeil(totalStudyLength, classMemberMappingDOS.size());
classSummaryVO.setAvgVodPlayLength(avg);
//测试通过率
Integer passNum = exerciseDoneResultMapper.getClassTestPassRate(classDictDO.getId());
classSummaryVO.setPassRate(MathUtil.intDivFloorPercent(passNum, classSummaryVO.getMemberCount()));
//签到总次数
long signCount = redisUtil.scan("subsidySignInfo*:classId:" + classDictDO.getId() + "*").stream().count();
classSummaryVO.setAvgSignCount(MathUtil.intDivCeil(signCount, classSummaryVO.getMemberCount()));
//答疑数
Integer count = answeringQuestionMapper.selectCount(new QueryWrapper<AnsweringQuestionDO>()
.lambda()
.eq(AnsweringQuestionDO::getClassId, classDictDO.getId()));
classSummaryVO.setAnswerCount(count);
return classSummaryVO;
}
public IPage<ClassDetailVO> classDetail(ClassDetailDTO classDetailDTO) {
Page pager = new Page(classDetailDTO.getPageNum(), classDetailDTO.getPageSize());
IPage<ClassDetailVO> classDetailVOIPage = this.baseMapper.classMembers(pager, classDetailDTO.getId(), classDetailDTO.getUserName());
List<ClassDetailVO> classDetailVOS = classDetailVOIPage.getRecords();
//课程由多少个视频
List<VodDictDO> vodDictDOS = classDictMapper.getClassVods(classDetailDTO.getId());
//课程详情
ClassDictDO classDictDO = classDictMapper.selectById(classDetailDTO.getId());
for (ClassDetailVO classDetailVO : classDetailVOS) {
/**
* 学生平均学习时长和平均学习次数
*/
//该学生完成了多少个
int i = 0;
int playLength = 0;
//该成员完成了几个视频
for (VodDictDO vodDictDO : vodDictDOS) {
int totalPlayLength = vodPlayHistoryMapper.memberVodTotalLength(classDetailVO.getId(), vodDictDO.getId());
if (totalPlayLength >= vodDictDO.getVodLength()) {
i++;
}
playLength += totalPlayLength;
}
//培训时长
classDetailVO.setTrainingLength(playLength);
//学生测试完成情况 多套卷子各返回最高成绩
List<GetMaxScoreVO> getMaxScoreVOS = exerciseDoneResultMapper.getMaxScore(classDictDO.getId(), classDetailVO.getId());
classDetailVO.setGetMaxScoreVOS(getMaxScoreVOS);
Boolean flag = true;
if (getMaxScoreVOS.size() > 0) {
for (GetMaxScoreVO getMaxScoreVO : getMaxScoreVOS) {
if (getMaxScoreVO.getScore() < 60) {
flag = false;
}
}
} else {
flag = false;
}
//总评价
classDetailVO.setResult(flag && i == vodDictDOS.size() ? "合格" : "不合格");
//课程进度
classDetailVO.setClassProcess(i + "/" + vodDictDOS.size());
//答疑
Integer count = answeringQuestionMapper.selectCount(new QueryWrapper<AnsweringQuestionDO>()
.lambda()
.eq(AnsweringQuestionDO::getAskId, classDetailVO.getId())
.eq(AnsweringQuestionDO::getClassId, classDetailDTO.getId()));
classDetailVO.setAskCounts(count);
//签到次数
long set = redisUtil.scan(RedisPrefixConstant.SUBSIDY_SIGN_INFO_PREFIX + classDetailVO.getId() + ":classId:" + classDetailDTO.getId() + "*").stream().count();
classDetailVO.setSignCounts(set);
}
classDetailVOIPage.setRecords(classDetailVOS);
return classDetailVOIPage;
}
public List<ClassDetailVO> exportClassDetail(ClassDetailDTO classDetailDTO) throws Exception {
Page pager = new Page(1, -1L);
IPage<ClassDetailVO> classDetailVOIPage = this.baseMapper.classMembers(pager, classDetailDTO.getId(), classDetailDTO.getUserName());
List<ClassDetailVO> classDetailVOS = classDetailVOIPage.getRecords();
//课程由多少个视频
List<VodDictDO> vodDictDOS = classDictMapper.getClassVods(classDetailDTO.getId());
//课程详情
ClassDictDO classDictDO = classDictMapper.selectById(classDetailDTO.getId());
CompanyDictDO companyDictDO = companyDictMapper.selectById(classDictDO.getCompanyId());
for (ClassDetailVO classDetailVO : classDetailVOS) {
//该学生完成了多少个
int i = 0;
int playLength = 0;
//该成员完成了几个视频
for (VodDictDO vodDictDO : vodDictDOS) {
int totalPlayLength = vodPlayHistoryMapper.memberVodTotalLength(classDetailVO.getId(), vodDictDO.getId());
if (totalPlayLength >= vodDictDO.getVodLength()) {
i++;
}
playLength += totalPlayLength;
}
//课程进度
classDetailVO.setClassProcess(i + "/" + vodDictDOS.size());
//学生测试完成情况 多套卷子各返回最高成绩
List<GetMaxScoreVO> getMaxScoreVOS = exerciseDoneResultMapper.getMaxScore(classDictDO.getId(), classDetailVO.getId());
classDetailVO.setGetMaxScoreVOS(getMaxScoreVOS);
Boolean flag = true;
StringBuilder stringBuilder = new StringBuilder();
if (getMaxScoreVOS.size() > 0) {
for (GetMaxScoreVO getMaxScoreVO : getMaxScoreVOS) {
stringBuilder.append(getMaxScoreVO.getPaperName() + ":" + getMaxScoreVO.getScore());
if (getMaxScoreVO.getScore() < 60) {
flag = false;
}
stringBuilder.append(" ");
}
} else {
flag = false;
}
//总评价
classDetailVO.setResult(flag && i == vodDictDOS.size() ? "合格" : "不合格");
classDetailVO.setScore(stringBuilder.toString());
//培训时长
classDetailVO.setTrainingLengthStr(MathUtil.secToTime(playLength));
//答疑
Integer count = answeringQuestionMapper.selectCount(new QueryWrapper<AnsweringQuestionDO>()
.lambda()
.eq(AnsweringQuestionDO::getAskId, classDetailVO.getId())
.eq(AnsweringQuestionDO::getClassId, classDetailDTO.getId()));
classDetailVO.setAskCounts(count);
//签到次数
long set = redisUtil.scan(RedisPrefixConstant.SUBSIDY_SIGN_INFO_PREFIX + classDetailVO.getId() + ":classId:" + classDetailDTO.getId() + "*").stream().count();
classDetailVO.setSignCounts(set);
}
if (classDetailDTO.getFlag()) {
CourseDictDO courseDictDO = courseDictMapper.selectById(classDictDO.getCourseId());
String studyDate = classDictDO.getStartDate() + " 至 " + classDictDO.getEndDate();
ExcelUtil.writeMemberExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "授课记录汇总表", classDetailVOS, ExcelFormatUtils.memberList);
}
return classDetailVOS;
}
public IPage<ClassSignVO> signDetail(ClassDetailDTO classDetailDTO) {
Page pager = new Page(classDetailDTO.getPageNum(), classDetailDTO.getPageSize());
IPage<ClassSignVO> classSignVOIPage = this.baseMapper.classSign(pager, classDetailDTO.getId(), classDetailDTO.getUserName());
List<ClassSignVO> classSignVOS = classSignVOIPage.getRecords();
//课程由多少个视频
List<VodDictDO> vodDictDOS = classDictMapper.getClassVods(classDetailDTO.getId());
for (ClassSignVO classSignVO : classSignVOS) {
//该学生完成了多少个
int i = 0;
int playLength = 0;
//该成员完成了几个视频
for (VodDictDO vodDictDO : vodDictDOS) {
int totalPlayLength = vodPlayHistoryMapper.memberVodTotalLength(classSignVO.getId(), vodDictDO.getId());
if (totalPlayLength >= vodDictDO.getVodLength()) {
i++;
}
playLength += totalPlayLength;
}
//课程进度
classSignVO.setClassProcess(i + "/" + vodDictDOS.size());
//完成率
String percent = MathUtil.getPercentAvgIndexWithPercent(new BigDecimal(i), new BigDecimal(vodDictDOS.size()));
classSignVO.setPercent(percent);
//培训时长
classSignVO.setTrainingLength(playLength);
classSignVO.setTrainingLengthStr(MathUtil.secToTime(playLength));
Set<String> sortSet = new TreeSet<String>(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return -o2.compareTo(o1);//降序排列
}
});
//签到
Set<String> set = redisUtil.scan(RedisPrefixConstant.SUBSIDY_SIGN_INFO_PREFIX + classSignVO.getId() + ":classId:" + classDetailDTO.getId() + "*");
classSignVO.setSignCounts(set.size());
StringBuilder stringBuilder = new StringBuilder();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sortSet.addAll(set);
//签到时间
for (String signInRecordDO : sortSet) {
String[] array = signInRecordDO.split(":");
//时间戳转时间
stringBuilder.append(sdf.format(new Date(Long.valueOf(array[array.length - 1])))).append(";");
}
if (StringUtils.isNotBlank(stringBuilder.toString())) {
String signInDate = stringBuilder.toString().substring(0, stringBuilder.length() - 1);
classSignVO.setSignInDateList(signInDate);
}
}
classSignVOIPage.setRecords(classSignVOS);
return classSignVOIPage;
}
public List<ClassSignVO> exportSignDetail(ClassDetailDTO classDetailDTO) throws Exception {
Page pager = new Page(1, -1L);
IPage<ClassSignVO> classSignVOIPage = this.baseMapper.classSign(pager, classDetailDTO.getId(), classDetailDTO.getUserName());
List<ClassSignVO> classSignVOS = classSignVOIPage.getRecords();
//课程由多少个视频
List<VodDictDO> vodDictDOS = classDictMapper.getClassVods(classDetailDTO.getId());
for (ClassSignVO classSignVO : classSignVOS) {
//该学生完成了多少个
int i = 0;
int playLength = 0;
//该成员完成了几个视频
for (VodDictDO vodDictDO : vodDictDOS) {
int totalPlayLength = vodPlayHistoryMapper.memberVodTotalLength(classSignVO.getId(), vodDictDO.getId());
if (totalPlayLength >= vodDictDO.getVodLength()) {
i++;
}
playLength += totalPlayLength;
}
classSignVO.setClassProcess(i + "/" + vodDictDOS.size());
//完成率
String percent = MathUtil.getPercentAvgIndexWithPercent(new BigDecimal(i), new BigDecimal(vodDictDOS.size()));
classSignVO.setPercent(percent);
//培训时长
classSignVO.setTrainingLengthStr(MathUtil.secToTime(playLength));
//签到
Set<String> set = redisUtil.scan(RedisPrefixConstant.SUBSIDY_SIGN_INFO_PREFIX + classSignVO.getId() + ":classId:" + classDetailDTO.getId() + "*");
classSignVO.setSignCounts(set.size());
Set<String> sortSet = new TreeSet<String>(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return -o2.compareTo(o1);//降序排列
}
});
sortSet.addAll(set);
StringBuilder stringBuilder = new StringBuilder();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//签到时间
for (String signInRecordDO : sortSet) {
String[] array = signInRecordDO.split(":");
//时间戳转时间
stringBuilder.append(sdf.format(new Date(Long.valueOf(array[array.length - 1])))).append(";");
}
if (StringUtils.isNotBlank(stringBuilder.toString())) {
String signInDate = stringBuilder.toString().substring(0, stringBuilder.length() - 1);
classSignVO.setSignInDateList(signInDate);
}
}
if (classDetailDTO.getFlag()) {
ClassDictDO classDictDO = classDictMapper.selectById(classDetailDTO.getId());
CompanyDictDO companyDictDO = companyDictMapper.selectById(classDictDO.getCompanyId());
CourseDictDO courseDictDO = courseDictMapper.selectById(classDictDO.getCourseId());
String studyDate = classDictDO.getStartDate() + " 至 " + classDictDO.getEndDate();
ExcelUtil.writeSignExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "注册签到表", classSignVOS, ExcelFormatUtils.signList);
}
return classSignVOS;
}
public IPage<ExerciseTestVO> exerciseTest(ClassDetailDTO classDetailDTO) {
Page pager = new Page(classDetailDTO.getPageNum(), classDetailDTO.getPageSize());
IPage<ExerciseTestVO> exerciseTestVOIPage = this.baseMapper.exerciseTest(pager, classDetailDTO.getId(), classDetailDTO.getUserName());
List<ExerciseTestVO> classSignVOS = exerciseTestVOIPage.getRecords();
for (ExerciseTestVO exerciseTestVO : classSignVOS) {
//学生测试完成情况
TestScoreInfoVO testScoreInfoVO = exerciseDoneResultMapper.testScoreInfo(classDetailDTO.getPaperId(), exerciseTestVO.getId());
exerciseTestVO.setPaperId(exerciseTestVO.getPaperId());
if (null != testScoreInfoVO) {
exerciseTestVO.setScore(testScoreInfoVO.getScore());
exerciseTestVO.setResult(testScoreInfoVO.getResult());
//测评次数
exerciseTestVO.setCount(testScoreInfoVO.getCnt());
} else {
exerciseTestVO.setScore(0);
exerciseTestVO.setResult("不合格");
exerciseTestVO.setCount(0);
}
}
exerciseTestVOIPage.setRecords(classSignVOS);
return exerciseTestVOIPage;
}
public List<ExerciseTestVO> exportExerciseTest(ClassDetailDTO classDetailDTO) throws Exception {
Page pager = new Page(0, -1L);
IPage<ExerciseTestVO> exerciseTestVOIPage = this.baseMapper.exerciseTest(pager, classDetailDTO.getId(), classDetailDTO.getUserName());
List<ExerciseTestVO> exerciseTestVOS = exerciseTestVOIPage.getRecords();
//课程详情
ClassDictDO classDictDO = classDictMapper.selectById(classDetailDTO.getId());
for (ExerciseTestVO exerciseTestVO : exerciseTestVOS) {
//学生测试完成情况
TestScoreInfoVO testScoreInfoVO = exerciseDoneResultMapper.testScoreInfo(classDetailDTO.getPaperId(), exerciseTestVO.getId());
exerciseTestVO.setPaperId(exerciseTestVO.getPaperId());
if (null != testScoreInfoVO) {
exerciseTestVO.setScore(testScoreInfoVO.getScore());
exerciseTestVO.setResult(testScoreInfoVO.getResult());
//测评次数
exerciseTestVO.setCount(testScoreInfoVO.getCnt());
} else {
exerciseTestVO.setScore(0);
exerciseTestVO.setResult("不合格");
exerciseTestVO.setCount(0);
}
}
if (classDetailDTO.getFlag()) {
CompanyDictDO companyDictDO = companyDictMapper.selectById(classDictDO.getCompanyId());
CourseDictDO courseDictDO = courseDictMapper.selectById(classDictDO.getCourseId());
String studyDate = classDictDO.getStartDate() + " 至 " + classDictDO.getEndDate();
ExcelUtil.writeTestExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "测试成绩表", exerciseTestVOS, ExcelFormatUtils.scoreList);
}
return exerciseTestVOS;
}
public List<GetMemberPapersVO> getMemberPapers(ExerciseDoneResultDO exerciseDoneResultDO) {
return exerciseDoneResultMapper.queryExerciseDoneResult(exerciseDoneResultDO.getMemberId(), null, exerciseDoneResultDO.getPaperId());
}
public List<GetPaperDetailVO> getPaperDetail(ExerciseDoneHistoryDO exerciseDoneHistoryDO) {
return exerciseDoneResultMapper.getPaperDetail(exerciseDoneHistoryDO.getMemberId(), exerciseDoneHistoryDO.getDoneId());
}
public IPage answerRecord(ClassDetailDTO classDetailDTO) {
Page pager = new Page(classDetailDTO.getPageNum(), classDetailDTO.getPageSize());
return this.baseMapper.answerRecord(pager, classDetailDTO.getId(), classDetailDTO.getUserName());
}
public List<AnswerRecordVO> exportAnswerRecord(ClassDetailDTO classDetailDTO) throws Exception {
Page pager = new Page(1, -1L);
IPage iPage = this.baseMapper.answerRecord(pager, classDetailDTO.getId(), classDetailDTO.getUserName());
List<AnswerRecordVO> answerRecordVOS = iPage.getRecords();
if (classDetailDTO.getFlag()) {
ClassDictDO classDictDO = classDictMapper.selectById(classDetailDTO.getId());
CompanyDictDO companyDictDO = companyDictMapper.selectById(classDictDO.getCompanyId());
CourseDictDO courseDictDO = courseDictMapper.selectById(classDictDO.getCourseId());
String studyDate = classDictDO.getStartDate() + " 至 " + classDictDO.getEndDate();
ExcelUtil.writeAnswerExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "答疑记录表", answerRecordVOS, ExcelFormatUtils.answersList);
}
return answerRecordVOS;
}
public List<ClassVodInfoVO> classVodInfo(ClassVodInfoDTO classVodInfoDTO) {
List<ClassVodInfoVO> result = new ArrayList<>();
//获取班级成员
List<Long> memberIds = classMemberMappingMapper.getClassMembers(classVodInfoDTO.getClassId());
//获取课程下的视频
List<VodDictDO> vodDictDOS = vodDictMapper.getCourseVods(classVodInfoDTO.getCourseId(), classVodInfoDTO.getVodName());
for (VodDictDO vodDictDO : vodDictDOS) {
//获取这个视频的学习人数和平均学习时长
ClassVodCompleteInfoVO classVodCompleteInfoVO = vodDictMapper.classVodCompleteInfo(classVodInfoDTO.getClassId(), vodDictDO.getId(), memberIds, classVodInfoDTO.getVodName());
ClassVodInfoVO classVodInfoVO = new ClassVodInfoVO();
classVodInfoVO.setVodName(vodDictDO.getVodName());
classVodInfoVO.setStudyCnt(classVodCompleteInfoVO.getCnt());
classVodInfoVO.setStudyLength(classVodCompleteInfoVO.getStudyLength());
result.add(classVodInfoVO);
}
return result;
}
public IPage<ClassDailyInfoVO> classDailyInfo(ClassDailyInfoDTO classDailyInfoDTO) {
Page pager = new Page(classDailyInfoDTO.getPageNum(), classDailyInfoDTO.getPageSize());
//获取班级成员
IPage<ClassDailyInfoVO> classDailyInfoVOIPage = classMemberMappingMapper.getClassMembersWithName(pager, classDailyInfoDTO.getClassId(), classDailyInfoDTO.getUserName());
//整理出这些学员id
List<ClassDailyInfoVO> classDailyInfoVOS = classDailyInfoVOIPage.getRecords();
List<Long> memberIds = new ArrayList<>();
for (ClassDailyInfoVO classDailyInfoVO : classDailyInfoVOS) {
memberIds.add(classDailyInfoVO.getId());
}
//这些成员完成情况
List<GetMemberStudyInfoVO> getMemberStudyInfoVOS = vodPlayHistoryMapper.getMemberStudyInfo(classDailyInfoDTO.getClassId(), memberIds, classDailyInfoDTO.getStartDate(), classDailyInfoDTO.getEndDate());
for (ClassDailyInfoVO classDailyInfoVO : classDailyInfoVOS) {
List<DayInfoItemVO> dayInfoItemVOS = new ArrayList<>();
int total = 0;
for (GetMemberStudyInfoVO getMemberStudyInfoVO : getMemberStudyInfoVOS) {
if (classDailyInfoVO.getId().equals(getMemberStudyInfoVO.getMemberId())) {
DayInfoItemVO dayInfoItemVO = new DayInfoItemVO();
dayInfoItemVO.setStudyDate(getMemberStudyInfoVO.getStudyDate());
dayInfoItemVO.setTotalLength(getMemberStudyInfoVO.getPlayLength());
total += getMemberStudyInfoVO.getPlayLength();
dayInfoItemVOS.add(dayInfoItemVO);
}
}
classDailyInfoVO.setTotal(total);
classDailyInfoVO.setDayInfoItemVOS(dayInfoItemVOS);
}
return classDailyInfoVOIPage;
}
public void exportClassDailyInfo(ClassDailyInfoDTO classDailyInfoDTO) {
Page pager = new Page(1, -1L);
// 表头
List<String> title = new ArrayList<>();
title.add("序号");
title.add("姓名");
title.addAll(findDaysStr(classDailyInfoDTO.getStartDate(), classDailyInfoDTO.getEndDate()));
title.add("合计时长");
//获取班级成员
IPage<ClassDailyInfoVO> classDailyInfoVOIPage = classMemberMappingMapper.getClassMembersWithName(pager, classDailyInfoDTO.getClassId(), classDailyInfoDTO.getUserName());
//整理出这些学员id
List<ClassDailyInfoVO> classDailyInfoVOS = classDailyInfoVOIPage.getRecords();
List<Long> memberIds = new ArrayList<>();
for (ClassDailyInfoVO classDailyInfoVO : classDailyInfoVOS) {
memberIds.add(classDailyInfoVO.getId());
}
//这些成员完成情况
List<GetMemberStudyInfoVO> getMemberStudyInfoVOS = vodPlayHistoryMapper.getMemberStudyInfo(classDailyInfoDTO.getClassId(), memberIds, classDailyInfoDTO.getStartDate(), classDailyInfoDTO.getEndDate());
HashMap<Long, HashMap<String, Integer>> hashMap = new HashMap();
for (GetMemberStudyInfoVO getMemberStudyInfoVO : getMemberStudyInfoVOS) {
if (!hashMap.containsKey(getMemberStudyInfoVO.getMemberId())) {
HashMap<String, Integer> hashMap1 = new HashMap<>();
hashMap1.put(getMemberStudyInfoVO.getStudyDate(), getMemberStudyInfoVO.getPlayLength());
hashMap.put(getMemberStudyInfoVO.getMemberId(), hashMap1);
} else {
HashMap<String, Integer> hashMap1 = hashMap.get(getMemberStudyInfoVO.getMemberId());
hashMap1.put(getMemberStudyInfoVO.getStudyDate(), getMemberStudyInfoVO.getPlayLength());
hashMap.put(getMemberStudyInfoVO.getMemberId(), hashMap1);
}
}
writeExcel(memberIds, hashMap, title);
}
public IPage<ClassDailyInfoVO> classVodDailyInfo(ClassVodDailyInfoDTO classVodDailyInfoDTO) {
//查看班级里有多少人
Page pager = new Page(classVodDailyInfoDTO.getPageNum(), classVodDailyInfoDTO.getPageSize());
//获取班级成员
IPage<ClassDailyInfoVO> classDailyInfoVOIPage = classMemberMappingMapper.getClassMembersWithName(pager, classVodDailyInfoDTO.getClassId(), classVodDailyInfoDTO.getUserName());
List<ClassDailyInfoVO> classDailyInfoVOS = classDailyInfoVOIPage.getRecords();
//获取班级、每个学员维度的视频播放总时长
List<ClassMemberPlayLengthVO> vodPlayHistoryDOS = vodPlayHistoryMapper.classMemberPlayLength(classVodDailyInfoDTO.getClassId());
HashMap<String, Integer> hashMap = new HashMap<>();
//存在一个map里
for (ClassMemberPlayLengthVO vodPlayHistoryDO : vodPlayHistoryDOS) {
hashMap.put(vodPlayHistoryDO.getMemberId() + "-" + vodPlayHistoryDO.getVodId(), vodPlayHistoryDO.getPlayLength());
}
//查询这个班级的所有视频
ClassDictDO classDictDO = classDictMapper.selectById(classVodDailyInfoDTO.getClassId());
List<VodDictDO> vodDictDOS = vodDictMapper.getCourseVods(classDictDO.getCourseId(), null);
for (ClassDailyInfoVO classDailyInfoVO : classDailyInfoVOS) {
//查看这个人某个视频的长度
int total = 0;
int playLengthTmp = 0;
List<ClassVodDailyInfoItemVO> classVodDailyInfoItemVOS = new ArrayList<>();
for (VodDictDO vodDictDO : vodDictDOS) {
Integer playLength = hashMap.get(classDailyInfoVO.getId() + "-" + vodDictDO.getId());
ClassVodDailyInfoItemVO classVodDailyInfoItemVO = new ClassVodDailyInfoItemVO();
classVodDailyInfoItemVO.setVodId(vodDictDO.getId());
classVodDailyInfoItemVO.setVodName(vodDictDO.getVodName());
if (null != playLength) {
classVodDailyInfoItemVO.setPlayLength(playLength);
classVodDailyInfoItemVOS.add(classVodDailyInfoItemVO);
if (playLength >= vodDictDO.getVodLength()) {
total++;
}
playLengthTmp += playLength;
} else {
classVodDailyInfoItemVO.setPlayLength(0);
classVodDailyInfoItemVOS.add(classVodDailyInfoItemVO);
}
}
classDailyInfoVO.setStudyLength(playLengthTmp);
classDailyInfoVO.setTotal(MathUtil.intDivFloorPercent(total, vodDictDOS.size()));
classDailyInfoVO.setClassVodDailyInfoItemVOS(classVodDailyInfoItemVOS);
}
return classDailyInfoVOIPage;
}
public void exportClassVodDailyInfo(ClassVodDailyInfoDTO classVodDailyInfoDTO) {
//查看班级里有多少人
Page pager = new Page(1, -1L);
ClassDictDO classDictDO = classDictMapper.selectById(classVodDailyInfoDTO.getClassId());
//查询所有视频
List<VodDictDO> vodDictDOS = vodDictMapper.getCourseVods(classDictDO.getCourseId(), null);
HashMap<String, Integer> vodHashmap = new HashMap<>();
for (VodDictDO vodDictDO : vodDictDOS) {
vodHashmap.put(vodDictDO.getVodName(), vodDictDO.getVodLength());
}
// 表头
List<String> title = new ArrayList<>();
title.add("序号");
title.add("姓名");
title.add("完成率");
title.add("学习时长");
for (VodDictDO vodDictDO : vodDictDOS) {
title.add(vodDictDO.getVodName());
}
//获取班级成员
IPage<ClassDailyInfoVO> classDailyInfoVOIPage = classMemberMappingMapper.getClassMembersWithName(pager, classVodDailyInfoDTO.getClassId(), classVodDailyInfoDTO.getUserName());
List<ClassDailyInfoVO> classDailyInfoVOS = classDailyInfoVOIPage.getRecords();
//获取班级、每个学员维度的视频播放总时长
List<ClassMemberPlayLengthVO> classMemberPlayLengthVOS = vodPlayHistoryMapper.classMemberPlayLength(classVodDailyInfoDTO.getClassId());
HashMap<String, Integer> hashMap = new HashMap<>();
//存在一个map里
for (ClassMemberPlayLengthVO classMemberPlayLengthVO : classMemberPlayLengthVOS) {
hashMap.put(classMemberPlayLengthVO.getMemberId() + "-" + classMemberPlayLengthVO.getVodName(), classMemberPlayLengthVO.getPlayLength());
}
writeVodExcel(classDailyInfoVOS, hashMap, title, vodHashmap);
}
public <T> void writeVodExcel(List<ClassDailyInfoVO> classDailyInfoVOS, HashMap<String, Integer> hashMap, List<String> title, HashMap<String, Integer> vodHashmap) {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletResponse response = servletRequestAttributes.getResponse();
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet();
AtomicInteger ai = new AtomicInteger();
Row row = sheet.createRow(ai.getAndIncrement());
AtomicInteger at = new AtomicInteger();
title.forEach(field -> {
Cell cell = row.createCell(at.getAndIncrement());
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
Font font = wb.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
cellStyle.setFont(font);
cell.setCellStyle(cellStyle);
cell.setCellValue(field);
});
int i = 1;
if (hashMap != null) {
for (ClassDailyInfoVO classDailyInfoVO : classDailyInfoVOS){
Row r = sheet.createRow(ai.getAndIncrement());
AtomicInteger a = new AtomicInteger();
Cell cell = r.createCell(at.getAndIncrement());
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
cell.setCellStyle(cellStyle);
Cell seqcell = r.createCell(a.getAndIncrement());
seqcell.setCellValue(i++);
Cell namecell = r.createCell(a.getAndIncrement());
namecell.setCellValue(classDailyInfoVO.getUserName());
Cell totalCell = r.createCell(a.getAndIncrement());
Cell studyLengthCell = r.createCell(a.getAndIncrement());
Integer total = 0;
int studyLength = 0;
for (String tt : title) {
if (!"姓名".equals(tt) && !"完成率".equals(tt) && !"学习时长".equals(tt)&& !"序号".equals(tt)) {
Cell cell1 = r.createCell(a.getAndIncrement());
if (null != hashMap) {
Integer playLength = hashMap.get(classDailyInfoVO.getId() + "-" + tt);
if (null != playLength) {
cell1.setCellValue(MathUtil.secToTime(playLength));
if (vodHashmap.get(tt) <= playLength) {
total++;
}
studyLength += playLength;
} else {
cell1.setCellValue("00:00:00");
}
}
}
}
studyLengthCell.setCellValue(MathUtil.secToTime(studyLength));
totalCell.setCellValue(MathUtil.intDivFloorPercent(total, vodHashmap.keySet().size()) + "%");
}
}
String fileName = String.valueOf(new Date().getTime());
try {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xlsx", "utf-8"));
response.flushBuffer();
wb.write(response.getOutputStream());
} catch (IOException e) {
log.error(String.format("downLoad excel exception"), e);
}
}
/**
* 导出excel文件
*/
public <T> void writeExcel(List<Long> memberIds, HashMap<Long, HashMap<String, Integer>> hashMap, List<String> dates) {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletResponse response = servletRequestAttributes.getResponse();
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet();
AtomicInteger ai = new AtomicInteger();
Row row = sheet.createRow(ai.getAndIncrement());
AtomicInteger at = new AtomicInteger();
dates.forEach(field -> {
Cell cell = row.createCell(at.getAndIncrement());
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
Font font = wb.createFont();
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
cellStyle.setFont(font);
cell.setCellStyle(cellStyle);
cell.setCellValue(field);
});
if (hashMap != null) {
int i= 1;
for (Long lg : memberIds){
Row r = sheet.createRow(ai.getAndIncrement());
AtomicInteger a = new AtomicInteger();
Cell cell = r.createCell(at.getAndIncrement());
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
cell.setCellStyle(cellStyle);
HashMap<String, Integer> hashMap1 = hashMap.get(lg);
Cell seqcell = r.createCell(a.getAndIncrement());
seqcell.setCellValue(i++);
Cell namecell = r.createCell(a.getAndIncrement());
namecell.setCellValue(memberMapper.selectById(lg).getUserName());
int total = 0;
for (String date : dates) {
if (!date.equals("姓名") && !"合计时长".equals(date)&& !"序号".equals(date)) {
Cell cell1 = r.createCell(a.getAndIncrement());
if (null != hashMap1) {
total += null == hashMap1.get(date) ? 0 : hashMap1.get(date);
cell1.setCellValue(null == hashMap1.get(date) ? "00:00:00" : MathUtil.secToTime(hashMap1.get(date)));
} else {
cell1.setCellValue("00:00:00");
}
}
}
Cell totalCell = r.createCell(a.getAndIncrement());
totalCell.setCellValue(MathUtil.secToTime(total));
}
}
String fileName = String.valueOf(new Date().getTime());
try {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".xlsx", "utf-8"));
response.flushBuffer();
wb.write(response.getOutputStream());
} catch (IOException e) {
log.error(String.format("downLoad excel exception"), e);
}
}
//JAVA 获取时间段内的每一天
public static List<String> findDaysStr(String begintTime, String endTime) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date dBegin = null;
Date dEnd = null;
try {
dBegin = sdf.parse(begintTime);
dEnd = sdf.parse(endTime);
} catch (ParseException e) {
e.printStackTrace();
}
List<String> daysStrList = new ArrayList<String>();
daysStrList.add(sdf.format(dBegin));
Calendar calBegin = Calendar.getInstance();
calBegin.setTime(dBegin);
Calendar calEnd = Calendar.getInstance();
calEnd.setTime(dEnd);
while (dEnd.after(calBegin.getTime())) {
calBegin.add(Calendar.DAY_OF_MONTH, 1);
String dayStr = sdf.format(calBegin.getTime());
daysStrList.add(dayStr);
}
return daysStrList;
}
public void export(ClassDetailDTO classDetailDTO) throws Exception {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletResponse response = servletRequestAttributes.getResponse();
ServletOutputStream sos = response.getOutputStream();
ZipOutputStream zipOutputStream = new ZipOutputStream(sos);
String zipname = "summary.zip";
response.reset();
response.setHeader("Access-Control-Allow-Origin", "*");
response.setContentType("application/zip;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename=" + new String((zipname).getBytes(StandardCharsets.UTF_8), "ISO8859-1"));
ClassDictDO classDictDO = classDictMapper.selectById(classDetailDTO.getId());
CompanyDictDO companyDictDO = companyDictMapper.selectById(classDictDO.getCompanyId());
CourseDictDO courseDictDO = courseDictMapper.selectById(classDictDO.getCourseId());
/**
* 班级成员
*/
ByteArrayOutputStream baos = new ByteArrayOutputStream();
classDetailDTO.setFlag(false);
List<ClassDetailVO> classDetailVOS = exportClassDetail(classDetailDTO);
String studyDate = classDictDO.getStartDate() + " 至 " + classDictDO.getEndDate();
membersListExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "授课记录汇总表", ExcelFormatUtils.memberList, classDetailVOS, null, 0, baos);
compressFileToZipStream(zipOutputStream, baos, "member.xlsx");
/**
* 注册签到
*/
ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
classDetailDTO.setFlag(false);
List<ClassSignVO> classSignVOS = exportSignDetail(classDetailDTO);
signListExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "注册签到", ExcelFormatUtils.signList, classSignVOS, null, 0, baos1);
compressFileToZipStream(zipOutputStream, baos1, "sign.xlsx");
/**
* 测试成绩
*/
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
classDetailDTO.setFlag(false);
List<ExerciseTestVO> exerciseTestVOS = exportExerciseTest(classDetailDTO);
testListExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "测试成绩", ExcelFormatUtils.scoreList, exerciseTestVOS, null, 0, baos2);
compressFileToZipStream(zipOutputStream, baos2, "test.xlsx");
/**
* 答疑记录
*/
ByteArrayOutputStream baos3 = new ByteArrayOutputStream();
List<AnswerRecordVO> answerRecordVOS = exportAnswerRecord(classDetailDTO);
askListExcel(companyDictDO.getCompanyName(), studyDate, courseDictDO.getCourseName(), "答疑记录", ExcelFormatUtils.answersList, answerRecordVOS, null, 0, baos3);
compressFileToZipStream(zipOutputStream, baos3, "answer.xlsx");
zipOutputStream.flush();
zipOutputStream.closeEntry();
baos.close();
zipOutputStream.flush();
zipOutputStream.close();
sos.close();
}
public IPage memberStudy(MemberStudyLogDTO memberStudyLogDTO) {
Page pager = new Page(memberStudyLogDTO.getPageNum(), memberStudyLogDTO.getPageSize());
IPage iPage = vodPlayHistoryMapper.memberStudy(pager, memberStudyLogDTO.getClassId(), memberStudyLogDTO.getMemberId());
List<MemberStudyLogVO> memberStudyLogVOS = iPage.getRecords();
for (MemberStudyLogVO memberStudyLogVO : memberStudyLogVOS) {
memberStudyLogVO.setPlayLength(MathUtil.secToTime(Integer.valueOf(memberStudyLogVO.getPlayLength())));
memberStudyLogVO.setTotalLength(MathUtil.secToTime(Integer.valueOf(memberStudyLogVO.getTotalLength())));
}
return iPage;
}
public void memberStudyLog(MemberStudyLogDTO memberStudyLogDTO) throws Exception {
MemberDO memberDO = memberMapper.selectById(memberStudyLogDTO.getMemberId());
List<MemberStudyLogVO> memberStudyLog = vodPlayHistoryMapper.memberStudyLog(memberStudyLogDTO.getClassId(), memberStudyLogDTO.getMemberId());
for (MemberStudyLogVO memberStudyLogVO : memberStudyLog) {
memberStudyLogVO.setPlayLength(MathUtil.secToTime(Integer.valueOf(memberStudyLogVO.getPlayLength())));
memberStudyLogVO.setTotalLength(MathUtil.secToTime(Integer.valueOf(memberStudyLogVO.getTotalLength())));
}
ExcelUtil.writeMemberStudyLog(memberDO, "学习记录", memberStudyLog, ExcelFormatUtils.studyLogList);
}
@Transactional(rollbackFor = Exception.class)
public String importMember(Long companyId, MultipartFile multipartFile) {
try {
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
//拼音小写
format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
//不带声调
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
ExcelUtil.readExcel(null, ImportMemberDTO.class, multipartFile).forEach(s -> {
MemberDO memberDO = memberMapper.selectOne(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getTelephone, s.getTelephone()));
if (null != memberDO) {
//memberDOS.add(memberDO);
} else {
MemberDO memberDO1 = new MemberDO();
memberDO1.setUserName(s.getUserName());
memberDO1.setGender(s.getGender());
try {
String accountName = PinyinHelper.toHanYuPinyinString(s.getUserName(), format, "", true);
List<MemberDO> memberDOS = memberMapper.selectList(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getAccountName, accountName)
.eq(MemberDO::getCompanyId, companyId));
if (memberDOS.size() > 0) {
String usernames = userName(accountName, 0, companyId);
memberDO1.setAccountName(usernames.replace("u:", "v"));
} else {
memberDO1.setAccountName(accountName.replace("u:", "v"));
}
} catch (BadHanyuPinyinOutputFormatCombination ex) {
}
memberDO1.setCompanyId(companyId);
memberDO1.setFirstLogin(0);
memberDO1.setTelephone(s.getTelephone());
memberDO1.setIdCard(s.getIdCard());
memberDO1.setStatus("启用");
memberDO1.setPassword("123456");
memberMapper.insert(memberDO1);
//找到该公司最大的部门
DepartmentDictDO departmentDictDO = departmentDictMapper.selectOne(new QueryWrapper<DepartmentDictDO>()
.lambda()
.isNull(DepartmentDictDO::getParentId)
.eq(DepartmentDictDO::getCompanyId, companyId));
MemberDepartmentMappingDO memberDepartmentMappingDO = new MemberDepartmentMappingDO();
memberDepartmentMappingDO.setDepartmentId(departmentDictDO.getId());
memberDepartmentMappingDO.setMemberId(memberDO1.getId());
memberDepartmentMappingMapper.insert(memberDepartmentMappingDO);
}
});
} catch (Exception e) {
throw new HttpException(10001);
}
return ConstantUtils.ADD_SUCCESS;
}
public String userName(String originName, int i, Long companyId) {
i++;
List<MemberDO> memberDOS = memberMapper.selectList(new QueryWrapper<MemberDO>()
.lambda()
.eq(MemberDO::getAccountName, originName + i)
.eq(MemberDO::getCompanyId, companyId));
if (memberDOS.size() > 0) {
return userName(originName, i, companyId);
} else {
return originName + i;
}
}
public static void membersListExcel(String companyName, String studyDate, String courseName, String title, List<String> headerList, List<ClassDetailVO> classDetailVOS, String datePattern, int colWidth, OutputStream out) {
// 声明一个工作薄
SXSSFWorkbook workbook = new SXSSFWorkbook(1000);//缓存
workbook.setCompressTempFiles(true);
//表头样式
CellStyle titleStyle = workbook.createCellStyle();
setStyle(titleStyle);
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short) 20);
titleFont.setBoldweight((short) 700);
titleStyle.setFont(titleFont);
//第二行
CellStyle secondStyle = workbook.createCellStyle();
secondStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
secondStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
secondStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
secondStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font secondFont = workbook.createFont();
secondStyle.setFont(secondFont);
//第三行
CellStyle thirdStyle = workbook.createCellStyle();
thirdStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
thirdStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
thirdStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
thirdStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font thirdFont = workbook.createFont();
thirdStyle.setFont(thirdFont);
// 列头样式
CellStyle headerStyle = workbook.createCellStyle();
setStyle(headerStyle);
Font headerFont = workbook.createFont();
headerFont.setFontHeightInPoints((short) 12);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
headerStyle.setFont(headerFont);
// 数据单元格样式
CellStyle cellStyle = workbook.createCellStyle();
setStyle(cellStyle);
Font cellFont = workbook.createFont();
cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
cellStyle.setFont(cellFont);
// 生成一个(带标题)表格
SXSSFSheet sheet = workbook.createSheet();
//设置列宽
int minBytes = 17;//至少字节数
int[] arrColWidth = new int[headerList.size()];
// 产生表格标题行,以及设置列宽
String[] headers = new String[headerList.size()];
int ii = 0;
for (int i = 0; i < headerList.size(); i++) {
headers[ii] = headerList.get(i);
int bytes = headerList.get(i).getBytes().length;
arrColWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, arrColWidth[ii] * 256);
ii++;
}
//第二行
int[] secondWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] secondHead = new String[2];
List<String> secondList = Arrays.asList("培训实施单位:" + companyName, "培训时间:" + studyDate);
//第三行
int[] thirdWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] thirdHead = new String[2];
List<String> thirdList = Arrays.asList("培训项目:" + courseName, "培训平台:有课互联系统");
ii = 0;
for (int i = 0; i < 2; i++) {
secondHead[ii] = secondList.get(i);
int bytes = secondList.get(i).getBytes().length;
secondWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, secondWidth[ii] * 256);
ii++;
}
ii = 0;
for (int i = 0; i < 2; i++) {
thirdHead[ii] = thirdList.get(i);
int bytes = thirdList.get(i).getBytes().length;
thirdWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, thirdWidth[ii] * 256);
ii++;
}
// 遍历集合数据,产生数据行
//标题 0
SXSSFRow titleRow = sheet.createRow(0);//表头 rowIndex=0
titleRow.createCell(0).setCellValue(title);
setBorderStyle(HSSFCellStyle.BORDER_THIN, new CellRangeAddress(0, 0, 0, 0), sheet, workbook); //给合并过的单元格加边框
titleRow.getCell(0).setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headerList.size() - 1));
//第二行 1
SXSSFRow secondRow = sheet.createRow(1); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress21 = new CellRangeAddress(1, 1, 0, 4);
sheet.addMergedRegion(cellRangeAddress21);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress21, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress22 = new CellRangeAddress(1, 1, 5, 10);
sheet.addMergedRegion(cellRangeAddress22);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress22, sheet, workbook); //给合并过的单元格加边框
secondRow.createCell(0).setCellValue(secondHead[0]);
secondRow.getCell(0).setCellStyle(secondStyle);
secondRow.createCell(5).setCellValue(secondHead[1]);
secondRow.getCell(5).setCellStyle(secondStyle);
//第三行 2
SXSSFRow thirdRow = sheet.createRow(2); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress31 = new CellRangeAddress(2, 2, 0, 4);
sheet.addMergedRegion(cellRangeAddress31);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress31, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress32 = new CellRangeAddress(2, 2, 5, 10);
sheet.addMergedRegion(cellRangeAddress32);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress32, sheet, workbook); //给合并过的单元格加边框
thirdRow.createCell(0).setCellValue(thirdHead[0]);
thirdRow.getCell(0).setCellStyle(thirdStyle);
thirdRow.createCell(5).setCellValue(thirdHead[1]);
thirdRow.getCell(5).setCellStyle(thirdStyle);
//标题 3
SXSSFRow headerRow = sheet.createRow(3); //列头 rowIndex =1
for (int i = 0; i < headers.length; i++) {
headerRow.createCell(i).setCellValue(headers[i]);
headerRow.getCell(i).setCellStyle(headerStyle);
}
int seq = 1;
//内容
int rowIndex = 0;
for (ClassDetailVO classDetailVO : classDetailVOS) {
if (rowIndex == 65535 || rowIndex == 0) {
if (rowIndex != 0) {
sheet = workbook.createSheet();//如果数据超过了,则在第二页显示
}
rowIndex = 4;//数据内容从 rowIndex=2开始
}
SXSSFRow dataRow = sheet.createRow(rowIndex);
SXSSFCell newCell = dataRow.createCell(0);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(seq);
newCell = dataRow.createCell(1);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getUserName());
newCell = dataRow.createCell(2);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getIdCard());
newCell = dataRow.createCell(3);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getGender());
newCell = dataRow.createCell(4);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getAccountName());
newCell = dataRow.createCell(5);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getTelephone());
newCell = dataRow.createCell(6);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getSignCounts());
newCell = dataRow.createCell(7);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getClassProcess());
newCell = dataRow.createCell(8);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getTrainingLengthStr());
newCell = dataRow.createCell(9);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getAskCounts());
newCell = dataRow.createCell(10);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getScore());
newCell = dataRow.createCell(11);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classDetailVO.getResult());
rowIndex++;
seq++;
}
try {
workbook.write(out);
workbook.close();
workbook.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void signListExcel(String companyName, String studyDate, String courseName, String title, List<String> headerList, List<ClassSignVO> classSignVOS, String datePattern, int colWidth, OutputStream out) {
// 声明一个工作薄
SXSSFWorkbook workbook = new SXSSFWorkbook(1000);//缓存
workbook.setCompressTempFiles(true);
//表头样式
CellStyle titleStyle = workbook.createCellStyle();
setStyle(titleStyle);
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short) 20);
titleFont.setBoldweight((short) 700);
titleStyle.setFont(titleFont);
//第二行
CellStyle secondStyle = workbook.createCellStyle();
secondStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
secondStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
secondStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
secondStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font secondFont = workbook.createFont();
secondStyle.setFont(secondFont);
//第三行
CellStyle thirdStyle = workbook.createCellStyle();
thirdStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
thirdStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
thirdStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
thirdStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font thirdFont = workbook.createFont();
thirdStyle.setFont(thirdFont);
// 列头样式
CellStyle headerStyle = workbook.createCellStyle();
setStyle(headerStyle);
Font headerFont = workbook.createFont();
headerFont.setFontHeightInPoints((short) 12);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
headerStyle.setFont(headerFont);
// 数据单元格样式
CellStyle cellStyle = workbook.createCellStyle();
setStyle(cellStyle);
Font cellFont = workbook.createFont();
cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
cellStyle.setFont(cellFont);
// 生成一个(带标题)表格
SXSSFSheet sheet = workbook.createSheet();
//设置列宽
int minBytes = 17;//至少字节数
int[] arrColWidth = new int[headerList.size()];
// 产生表格标题行,以及设置列宽
String[] headers = new String[headerList.size()];
int ii = 0;
for (int i = 0; i < headerList.size(); i++) {
headers[ii] = headerList.get(i);
int bytes = headerList.get(i).getBytes().length;
arrColWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, arrColWidth[ii] * 256);
ii++;
}
//第二行
int[] secondWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] secondHead = new String[2];
List<String> secondList = Arrays.asList("培训实施单位:" + companyName, "培训时间:" + studyDate);
//第三行
int[] thirdWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] thirdHead = new String[2];
List<String> thirdList = Arrays.asList("培训项目:" + courseName, "培训平台:有课互联系统");
ii = 0;
for (int i = 0; i < 2; i++) {
secondHead[ii] = secondList.get(i);
int bytes = secondList.get(i).getBytes().length;
secondWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, secondWidth[ii] * 256);
ii++;
}
ii = 0;
for (int i = 0; i < 2; i++) {
thirdHead[ii] = thirdList.get(i);
int bytes = thirdList.get(i).getBytes().length;
thirdWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, thirdWidth[ii] * 256);
ii++;
}
// 遍历集合数据,产生数据行
//标题 0
SXSSFRow titleRow = sheet.createRow(0);//表头 rowIndex=0
titleRow.createCell(0).setCellValue(title);
setBorderStyle(HSSFCellStyle.BORDER_THIN, new CellRangeAddress(0, 0, 0, 0), sheet, workbook); //给合并过的单元格加边框
titleRow.getCell(0).setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headerList.size() - 1));
//第二行 1
SXSSFRow secondRow = sheet.createRow(1); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress21 = new CellRangeAddress(1, 1, 0, 3);
sheet.addMergedRegion(cellRangeAddress21);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress21, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress22 = new CellRangeAddress(1, 1, 4, 8);
sheet.addMergedRegion(cellRangeAddress22);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress22, sheet, workbook); //给合并过的单元格加边框
secondRow.createCell(0).setCellValue(secondHead[0]);
secondRow.getCell(0).setCellStyle(secondStyle);
secondRow.createCell(4).setCellValue(secondHead[1]);
secondRow.getCell(4).setCellStyle(secondStyle);
//第三行 2
SXSSFRow thirdRow = sheet.createRow(2); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress31 = new CellRangeAddress(2, 2, 0, 3);
sheet.addMergedRegion(cellRangeAddress31);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress31, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress32 = new CellRangeAddress(2, 2, 4, 8);
sheet.addMergedRegion(cellRangeAddress32);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress32, sheet, workbook); //给合并过的单元格加边框
thirdRow.createCell(0).setCellValue(thirdHead[0]);
thirdRow.getCell(0).setCellStyle(thirdStyle);
thirdRow.createCell(4).setCellValue(thirdHead[1]);
thirdRow.getCell(4).setCellStyle(thirdStyle);
//标题 3
SXSSFRow headerRow = sheet.createRow(3); //列头 rowIndex =1
for (int i = 0; i < headers.length; i++) {
headerRow.createCell(i).setCellValue(headers[i]);
headerRow.getCell(i).setCellStyle(headerStyle);
}
int seq = 1;
//内容
int rowIndex = 0;
for (ClassSignVO classSignVO : classSignVOS) {
if (rowIndex == 65535 || rowIndex == 0) {
if (rowIndex != 0) {
sheet = workbook.createSheet();//如果数据超过了,则在第二页显示
}
rowIndex = 4;//数据内容从 rowIndex=2开始
}
SXSSFRow dataRow = sheet.createRow(rowIndex);
SXSSFCell newCell = dataRow.createCell(0);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(seq);
newCell = dataRow.createCell(1);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getUserName());
newCell = dataRow.createCell(2);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getIdCard());
newCell = dataRow.createCell(3);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getTelephone());
newCell = dataRow.createCell(4);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getTrainingLengthStr());
newCell = dataRow.createCell(5);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getClassProcess());
newCell = dataRow.createCell(6);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getPercent());
newCell = dataRow.createCell(7);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getSignCounts());
newCell = dataRow.createCell(8);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(classSignVO.getSignInDateList());
rowIndex++;
seq++;
}
try {
workbook.write(out);
workbook.close();
workbook.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void testListExcel(String companyName, String studyDate, String courseName, String title, List<String> headerList, List<ExerciseTestVO> exerciseTestVOS, String datePattern, int colWidth, OutputStream out) {
// 声明一个工作薄
SXSSFWorkbook workbook = new SXSSFWorkbook(1000);//缓存
workbook.setCompressTempFiles(true);
//表头样式
CellStyle titleStyle = workbook.createCellStyle();
setStyle(titleStyle);
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short) 20);
titleFont.setBoldweight((short) 700);
titleStyle.setFont(titleFont);
//第二行
CellStyle secondStyle = workbook.createCellStyle();
secondStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
secondStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
secondStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
secondStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font secondFont = workbook.createFont();
secondStyle.setFont(secondFont);
//第三行
CellStyle thirdStyle = workbook.createCellStyle();
thirdStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
thirdStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
thirdStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
thirdStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font thirdFont = workbook.createFont();
thirdStyle.setFont(thirdFont);
// 列头样式
CellStyle headerStyle = workbook.createCellStyle();
setStyle(headerStyle);
Font headerFont = workbook.createFont();
headerFont.setFontHeightInPoints((short) 12);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
headerStyle.setFont(headerFont);
// 数据单元格样式
CellStyle cellStyle = workbook.createCellStyle();
setStyle(cellStyle);
Font cellFont = workbook.createFont();
cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
cellStyle.setFont(cellFont);
// 生成一个(带标题)表格
SXSSFSheet sheet = workbook.createSheet();
//设置列宽
int minBytes = 17;//至少字节数
int[] arrColWidth = new int[headerList.size()];
// 产生表格标题行,以及设置列宽
String[] headers = new String[headerList.size()];
int ii = 0;
for (int i = 0; i < headerList.size(); i++) {
headers[ii] = headerList.get(i);
int bytes = headerList.get(i).getBytes().length;
arrColWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, arrColWidth[ii] * 256);
ii++;
}
//第二行
int[] secondWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] secondHead = new String[2];
List<String> secondList = Arrays.asList("培训实施单位:" + companyName, "培训时间:" + studyDate);
//第三行
int[] thirdWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] thirdHead = new String[2];
List<String> thirdList = Arrays.asList("培训项目:" + courseName, "培训平台:有课互联系统");
ii = 0;
for (int i = 0; i < 2; i++) {
secondHead[ii] = secondList.get(i);
int bytes = secondList.get(i).getBytes().length;
secondWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, secondWidth[ii] * 256);
ii++;
}
ii = 0;
for (int i = 0; i < 2; i++) {
thirdHead[ii] = thirdList.get(i);
int bytes = thirdList.get(i).getBytes().length;
thirdWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, thirdWidth[ii] * 256);
ii++;
}
// 遍历集合数据,产生数据行
//标题 0
SXSSFRow titleRow = sheet.createRow(0);//表头 rowIndex=0
titleRow.createCell(0).setCellValue(title);
setBorderStyle(HSSFCellStyle.BORDER_THIN, new CellRangeAddress(0, 0, 0, 0), sheet, workbook); //给合并过的单元格加边框
titleRow.getCell(0).setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headerList.size() - 1));
//第二行 1
SXSSFRow secondRow = sheet.createRow(1); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress21 = new CellRangeAddress(1, 1, 0, 3);
sheet.addMergedRegion(cellRangeAddress21);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress21, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress22 = new CellRangeAddress(1, 1, 4, 6);
sheet.addMergedRegion(cellRangeAddress22);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress22, sheet, workbook); //给合并过的单元格加边框
secondRow.createCell(0).setCellValue(secondHead[0]);
secondRow.getCell(0).setCellStyle(secondStyle);
secondRow.createCell(4).setCellValue(secondHead[1]);
secondRow.getCell(4).setCellStyle(secondStyle);
//第三行 2
SXSSFRow thirdRow = sheet.createRow(2); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress31 = new CellRangeAddress(2, 2, 0, 3);
sheet.addMergedRegion(cellRangeAddress31);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress31, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress32 = new CellRangeAddress(2, 2, 4, 6);
sheet.addMergedRegion(cellRangeAddress32);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress32, sheet, workbook); //给合并过的单元格加边框
thirdRow.createCell(0).setCellValue(thirdHead[0]);
thirdRow.getCell(0).setCellStyle(thirdStyle);
thirdRow.createCell(4).setCellValue(thirdHead[1]);
thirdRow.getCell(4).setCellStyle(thirdStyle);
//标题 3
SXSSFRow headerRow = sheet.createRow(3); //列头 rowIndex =1
for (int i = 0; i < headers.length; i++) {
headerRow.createCell(i).setCellValue(headers[i]);
headerRow.getCell(i).setCellStyle(headerStyle);
}
int seq = 1;
//内容
int rowIndex = 0;
for (ExerciseTestVO exerciseTestVO : exerciseTestVOS) {
if (rowIndex == 65535 || rowIndex == 0) {
if (rowIndex != 0) {
sheet = workbook.createSheet();//如果数据超过了,则在第二页显示
}
rowIndex = 4;//数据内容从 rowIndex=2开始
}
SXSSFRow dataRow = sheet.createRow(rowIndex);
SXSSFCell newCell = dataRow.createCell(0);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(seq);
newCell = dataRow.createCell(1);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(exerciseTestVO.getUserName());
newCell = dataRow.createCell(2);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(exerciseTestVO.getIdCard());
newCell = dataRow.createCell(3);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(exerciseTestVO.getTelephone());
newCell = dataRow.createCell(4);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(exerciseTestVO.getScore());
//次数
newCell = dataRow.createCell(5);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(exerciseTestVO.getCount());
newCell = dataRow.createCell(6);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(exerciseTestVO.getScore() >= 60 ? "合格" : "不合格");
rowIndex++;
seq++;
}
try {
workbook.write(out);
workbook.close();
workbook.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void askListExcel(String companyName, String studyDate, String courseName, String title, List<String> headerList, List<AnswerRecordVO> answerRecordVOS, String datePattern, int colWidth, OutputStream out) {
// 声明一个工作薄
SXSSFWorkbook workbook = new SXSSFWorkbook(1000);//缓存
workbook.setCompressTempFiles(true);
//表头样式
CellStyle titleStyle = workbook.createCellStyle();
setStyle(titleStyle);
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short) 20);
titleFont.setBoldweight((short) 700);
titleStyle.setFont(titleFont);
//第二行
CellStyle secondStyle = workbook.createCellStyle();
secondStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
secondStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
secondStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
secondStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font secondFont = workbook.createFont();
secondStyle.setFont(secondFont);
//第三行
CellStyle thirdStyle = workbook.createCellStyle();
thirdStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
thirdStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
thirdStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
thirdStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
secondStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
Font thirdFont = workbook.createFont();
thirdStyle.setFont(thirdFont);
// 列头样式
CellStyle headerStyle = workbook.createCellStyle();
setStyle(headerStyle);
Font headerFont = workbook.createFont();
headerFont.setFontHeightInPoints((short) 12);
headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
headerStyle.setFont(headerFont);
// 数据单元格样式
CellStyle cellStyle = workbook.createCellStyle();
setStyle(cellStyle);
Font cellFont = workbook.createFont();
cellFont.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
cellStyle.setFont(cellFont);
// 生成一个(带标题)表格
SXSSFSheet sheet = workbook.createSheet();
//设置列宽
int minBytes = 17;//至少字节数
int[] arrColWidth = new int[headerList.size()];
// 产生表格标题行,以及设置列宽
String[] headers = new String[headerList.size()];
int ii = 0;
for (int i = 0; i < headerList.size(); i++) {
headers[ii] = headerList.get(i);
int bytes = headerList.get(i).getBytes().length;
arrColWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, arrColWidth[ii] * 256);
ii++;
}
//第二行
int[] secondWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] secondHead = new String[2];
List<String> secondList = Arrays.asList("培训实施单位:" + companyName, "培训时间:" + studyDate);
//第三行
int[] thirdWidth = new int[2];
// 产生表格标题行,以及设置列宽
String[] thirdHead = new String[2];
List<String> thirdList = Arrays.asList("培训项目:" + courseName, "培训平台:有课互联系统");
ii = 0;
for (int i = 0; i < 2; i++) {
secondHead[ii] = secondList.get(i);
int bytes = secondList.get(i).getBytes().length;
secondWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, secondWidth[ii] * 256);
ii++;
}
ii = 0;
for (int i = 0; i < 2; i++) {
thirdHead[ii] = thirdList.get(i);
int bytes = thirdList.get(i).getBytes().length;
thirdWidth[ii] = bytes < minBytes ? minBytes : bytes;
sheet.setColumnWidth(ii, thirdWidth[ii] * 256);
ii++;
}
// 遍历集合数据,产生数据行
//标题 0
SXSSFRow titleRow = sheet.createRow(0);//表头 rowIndex=0
titleRow.createCell(0).setCellValue(title);
setBorderStyle(HSSFCellStyle.BORDER_THIN, new CellRangeAddress(0, 0, 0, 0), sheet, workbook); //给合并过的单元格加边框
titleRow.getCell(0).setCellStyle(titleStyle);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headerList.size() - 1));
//第二行 1
SXSSFRow secondRow = sheet.createRow(1); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress21 = new CellRangeAddress(1, 1, 0, 2);
sheet.addMergedRegion(cellRangeAddress21);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress21, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress22 = new CellRangeAddress(1, 1, 3, 5);
sheet.addMergedRegion(cellRangeAddress22);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress22, sheet, workbook); //给合并过的单元格加边框
secondRow.createCell(0).setCellValue(secondHead[0]);
secondRow.getCell(0).setCellStyle(secondStyle);
secondRow.createCell(3).setCellValue(secondHead[1]);
secondRow.getCell(3).setCellStyle(secondStyle);
//第三行 2
SXSSFRow thirdRow = sheet.createRow(2); //第二行 rowIndex =1
CellRangeAddress cellRangeAddress31 = new CellRangeAddress(2, 2, 0, 2);
sheet.addMergedRegion(cellRangeAddress31);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress31, sheet, workbook); //给合并过的单元格加边框
CellRangeAddress cellRangeAddress32 = new CellRangeAddress(2, 2, 3, 5);
sheet.addMergedRegion(cellRangeAddress32);
setBorderStyle(HSSFCellStyle.BORDER_THIN, cellRangeAddress32, sheet, workbook); //给合并过的单元格加边框
thirdRow.createCell(0).setCellValue(thirdHead[0]);
thirdRow.getCell(0).setCellStyle(thirdStyle);
thirdRow.createCell(3).setCellValue(thirdHead[1]);
thirdRow.getCell(3).setCellStyle(thirdStyle);
//标题 3
SXSSFRow headerRow = sheet.createRow(3); //列头 rowIndex =1
for (int i = 0; i < headers.length; i++) {
headerRow.createCell(i).setCellValue(headers[i]);
headerRow.getCell(i).setCellStyle(headerStyle);
}
int seq = 1;
//内容
int rowIndex = 0;
for (AnswerRecordVO answerRecordVO : answerRecordVOS) {
if (rowIndex == 65535 || rowIndex == 0) {
if (rowIndex != 0) {
sheet = workbook.createSheet();//如果数据超过了,则在第二页显示
}
rowIndex = 4;//数据内容从 rowIndex=2开始
}
SXSSFRow dataRow = sheet.createRow(rowIndex);
SXSSFCell newCell = dataRow.createCell(0);
cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(seq);
newCell = dataRow.createCell(1);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getTitle());
newCell = dataRow.createCell(2);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getAnswer());
newCell = dataRow.createCell(3);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getCreateDate());
newCell = dataRow.createCell(4);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getUserName());
//次数
newCell = dataRow.createCell(5);
newCell.setCellStyle(cellStyle);
newCell.setCellValue(answerRecordVO.getUpdateDate());
rowIndex++;
seq++;
}
try {
workbook.write(out);
workbook.close();
workbook.dispose();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 压缩单个excel文件的输出流 到zip输出流,注意zipOutputStream未关闭,需要交由调用者关闭之
*
* @param zipOutputStream zip文件的输出流
* @param excelOutputStream excel文件的输出流
* @param excelFilename 文件名可以带目录,例如 TestDir/test1.xlsx
*/
public static void compressFileToZipStream(ZipOutputStream zipOutputStream,
ByteArrayOutputStream excelOutputStream, String excelFilename) {
byte[] buf = new byte[1024];
try {
// Compress the files
byte[] content = excelOutputStream.toByteArray();
ByteArrayInputStream is = new ByteArrayInputStream(content);
BufferedInputStream bis = new BufferedInputStream(is);
// Add ZIP entry to output stream.
zipOutputStream.putNextEntry(new ZipEntry(excelFilename));
// Transfer bytes from the file to the ZIP file
int len;
while ((len = bis.read(buf)) > 0) {
zipOutputStream.write(buf, 0, len);
}
// Complete the entry
//excelOutputStream.close();//关闭excel输出流
//zipOutputStream.closeEntry();
bis.close();
is.close();
// Complete the ZIP file
} catch (IOException e) {
e.printStackTrace();
}
}
//也可用以下方法
public static void setBorderStyle(int border, CellRangeAddress region, SXSSFSheet sheet, SXSSFWorkbook wb) {
CellStyle cs = wb.createCellStyle(); // 样式对象
cs.setBorderBottom((short) border);
cs.setBorderTop((short) border);
cs.setBorderLeft((short) border);
cs.setBorderRight((short) border);
setRegionStyle(cs, region, sheet);
}
private static void setRegionStyle(CellStyle cs, CellRangeAddress region, SXSSFSheet sheet) {
for (int i = region.getFirstRow(); i <= region.getLastRow(); i++) {
SXSSFRow row = sheet.getRow(i);
if (row == null) {
row = sheet.createRow(i);
}
for (int j = region.getFirstColumn(); j <= region.getLastColumn(); j++) {
SXSSFCell cell = row.getCell(j);
if (cell == null) {
cell = row.createCell(j);
cell.setCellValue("");
}
cell.setCellStyle(cs);
}
}
}
private static void setStyle(CellStyle cellStyle) {
// 水平居中
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
// 垂直居中
cellStyle.setVerticalAlignment(CellStyle.ALIGN_CENTER);
// 边框
cellStyle.setBorderTop(CellStyle.BORDER_THIN);
// 边框
cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
// 边框
cellStyle.setBorderRight(CellStyle.BORDER_THIN);
// 边框
cellStyle.setBorderBottom(CellStyle.BORDER_THIN);
}
}