liuxiaolong
2019-05-06 f99bc8c6a1d10610373738edd7d0aa0181c81d99
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
package com.cloud.user.controller;
 
import com.cloud.common.constants.GlobalDict;
//import com.cloud.common.utils.AppUserUtil;
import com.cloud.common.utils.OrgTypeUtil;
import com.cloud.common.utils.UpperByName;
import com.cloud.model.file.FileInfo;
import com.cloud.model.sys.BbEmployee;
import com.cloud.model.sys.SysOrganization;
import com.cloud.user.constants.EmpTypeConstant;
import com.cloud.user.dao.BbEmployeeDao;
import com.cloud.user.dao.BbFaceDao;
import com.cloud.user.dao.SysOrganizationDao;
//import com.cloud.user.feign.FileUtilClient;
import com.cloud.user.model.BbFace;
import com.cloud.user.service.BbEmployeeService;
import com.cloud.user.service.ExcelService;
import com.cloud.user.service.GolDictService;
import com.cloud.user.service.SysOrganizationService;
import com.cloud.user.utils.FaceUtil;
import com.cloud.user.utils.ImageUtils;
import com.cloud.user.utils.PersonCotrollerUtil;
import com.cloud.user.vo.BbEmployeeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.PictureData;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.usermodel.*;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
 
/**
 * 人员
 * 控制层
 */
@Slf4j
@Api(value = "ExcelController", description = "Excel控制层")
@RestController
@RequestMapping("data")
public class ExcelController {
//
//    @Autowired
//    private ExcelService excelService;
//    @Autowired
//    private FileUtilClient fileUtilClient;
//    @Autowired
//    private BbFaceDao bbFaceDao;
//    @Autowired
//    private SysOrganizationDao orgDao;
//    @Autowired
//    private BbEmployeeDao dao;
//
//    @Autowired
//    private BbEmployeeService service;
//    @Autowired
//    private GolDictService golDictService;
//    @Autowired
//    private SysOrganizationService sysOrganizationService;
//
//    @RequestMapping("/emp")
//    public void getExcel(@RequestParam(value = "file", required = false) MultipartFile files,int index) {
//
//        excelService.getExcel(files, index);
//        log.info("获取ExcelEmp人员表信息");
//    }
//
//
//
//
//
//
//    /**
//     * ***************导入Excel文件************************************************************************************************************************
//     */
//
//    /**
//     * 导入人员信息
//     *
//     * @param files 导入文件
//     * @param orgId 当前组织orgId
//     * @param officeId 当前 部门或班级officeId
//     * @return Result
//     */
//    @RequestMapping(value = "/excel/importExcel")
//    @ResponseBody
//    @ApiOperation(value = "Excel人员信息导入", notes = "Excel人员信息导入",response = Map.class, responseContainer = "Map", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "files", value = "MultipartFile上传组件", required = true, dataType = "string", paramType = "body"),
//            @ApiImplicitParam(name = "orgId", value = "学校id", required = true, dataType = "long", paramType = "body"),
//            @ApiImplicitParam(name = "officeId", value = "所选部门或班级的ID", required = true, dataType = "long", paramType = "body")
//    })
//    public Map<String,Object> importExcel(MultipartFile files, Integer orgId, Integer officeId) {
//
//        Map<String,Object> map = new HashMap<>();
//
//        log.info("excel导入处理...");
//        try {
//            if (!files.isEmpty()) {
//                String orignFilename = files.getOriginalFilename().trim();
//                log.info("导入文件名" + orignFilename);
//                if (null == orignFilename || "".equals(orignFilename)) {
//                    return null;
//                } else {
//                    //获取文件名
//                    String fileExtName = orignFilename.substring(orignFilename.lastIndexOf(".") + 1);
//                    log.info("导入的文件的扩展名:" + fileExtName);
//                    //获取文件的大小
//                    long size = files.getSize();
//                    //获取文件的流
//                    InputStream inputStream = files.getInputStream();
//                    log.info("导入文件大小:" + size / 1024 / 1024 + "MB");
//                    //导入Excel(文件流,officeId,当前用户,部门ID,部门名字)
//                    List<String> result =
//                            importExcelSheet(inputStream, orgId, officeId);
//                    if (0 == result.size()) {
//                        map.put("code",0);
//                        map.put("message","导入成功!");
//                    } else {
//                        map.put("code",1);
//                        map.put("message",result);
//                    }
//                }
//            } else {
//                log.error("导入文件不能为空!");
//                map.put("code",1);
//                map.put("message","导入文件不能为空!");
//            }
//        } catch (Exception e) {
//            map.put("code",1);
//            map.put("message","导入异常!"+e.getMessage().toString());
//            return map;
//        }
//
//        return map;
//    }
//
//    /**
//     * . 导入Excel
//     *
//     * @param inputStream 当前file对象的流
//     * @param orgId 当前组织orgId
//     * @param officeId 当前 部门或班级officeId
//     * @return true 学生 false 教职工
//     */
//    public List<String> importExcelSheet(InputStream inputStream, Integer orgId,Integer officeId) {
//        List<String> errlist = new ArrayList<>();
//        try {
//            // 构造 XSSFWorkbook 对象,strPath 传入文件路径
//            XSSFWorkbook xwb = new XSSFWorkbook(inputStream);
//            // 读取第一章表格内容
//            XSSFSheet sheet = xwb.getSheetAt(0);
//            boolean flag = isStudentSheetType(sheet);
//            if (flag) {
//                return errOrSaveData(sheet, GlobalDict.STUDENT_SHEET_LINE, xwb, orgId, officeId, flag);
//            } else {
//                return errOrSaveData(sheet, GlobalDict.TEACHER_SHEET_LINE, xwb, orgId,officeId,flag);
//            }
//        } catch (Exception e) {
//            errlist.add(e.getMessage());
//            e.printStackTrace();
//        }
//        return errlist;
//    }
//
//    /**
//     * . 获取Excel类型 学生还是教职工
//     *
//     * @param sheet 当前sheet对象
//     *
//     * @return true 学生 false 教职工
//     */
//    public boolean isStudentSheetType(XSSFSheet sheet) {
//        String title = sheet.getRow(0).getCell(0).toString();
//        return title.contains("学生");
//    }
//
//    /**
//     * . 处理sheet数据
//     *
//     * @param sheet 当前sheet
//     * @param sheetline 当前sheet的列数
//     * @param xwb excel表格
//     * @param orgId 当前组织orgId
//     * @param officeId 当前 部门或班级officeId
//     * @param flag 表类型标志 true 为学生表
//     * @return List 错误信息的集合
//     * @throws Exception 异常提示
//     *
//     */
//    public List<String> errOrSaveData(XSSFSheet sheet, int sheetline, XSSFWorkbook xwb,Integer orgId, Integer officeId, boolean flag)
//            throws Exception {
//        List<BbEmployeeVO> list = new ArrayList<>();
//        List<BbEmployeeVO> addList = new ArrayList<>();
//        List<BbEmployeeVO> updateList = new ArrayList<>();
//        List<String> errList = new ArrayList<String>();
//        //验证单元格数据是否
//        errList = verifySheet(sheet, sheetline, orgId, xwb,officeId,flag);
//        int photoNum = getSheetPictrues(0, sheet).size();
//        if (errList.size() == 0) {  //errList.size() == 0
//            if (flag) {
//                list = studentListAdd(sheet, orgId, officeId, flag);
//            } else {
//                list = teacherListAdd(sheet,orgId,officeId, flag);
//            }
//            if (list.size() == photoNum) {
//                getPhoto(list, xwb, errList);
//                if (errList.size() == 0) {
//                    for (BbEmployeeVO u : list) {
//                        if (isExist(u)) {
//                            updateList.add(u);
//                        } else {
//                            addList.add(u);
//                        }
//                    }
//                    service.batchAddBbEmployee(addList);
//
//                    service.batchUpdatePerson(updateList);
//                }else {
//                    return errList;
//                }
//            } else {
//                errList.add(
//                        "导入数据" + list.size() + "条,图片" + photoNum + "张,缺少图片" + (list.size() - photoNum) + "张");
//            }
//        }
//        return errList;
//    }
//
//    /**
//     * . 验证excel数据
//     *
//     * @param sheet 当前sheet对象
//     * @param line sheet表的总列数 @ param companyId @ param xwb
//     * @return List 错误信息的集合
//     */
//    private List<String> verifySheet(XSSFSheet sheet, int line, Integer orgId,XSSFWorkbook xwb,Integer officeId,boolean flag) {
//
//        List<String> errList = new ArrayList<String>();
//        Boolean isSchool = null;
//        if(flag){
//            //首先验证选择的组织是否是班级
//            Map<String,Object> param = new HashMap<>();
//            if(orgId != null){
//                param.put("orgId",orgId);
//            }
//            param.put("officeId",officeId);
//            boolean isClass = isImportStudentClass(param);
//            if(!isClass){
//                errList.add("请选择正确的班级!");
//                return errList;
//            }
//        }else {
//            //导入教师验证是否是学校节点或者是部门节点
//            Map<String,Object> param = new HashMap<>();
//            if(orgId != null){
//                param.put("orgId",orgId);
//            }
//            param.put("officeId",officeId);
//            Integer isoffice = isImportTeacherOffice(param);
//            switch (isoffice){
//                case 1:
//                    isSchool = true;
//                    break;
//                case 2:
//                    isSchool = false;
//                    break;
//                case 3:
//                    errList.add("导入教师请选择学校或部门!");
//                    return errList;
//            }
//        }
//
//
//        // 定义 row、cell
//        XSSFRow row;
//        XSSFCell cell;
//        List<String> title = new ArrayList<String>();
//        Integer dep = Integer.parseInt(OrgTypeUtil.getByKey(GlobalDict.DEPARTMENT).getValue());
//        List<SysOrganization> orgs = sysOrganizationService.findDownByType(dep,Long.valueOf(officeId),null);
//        //查找组织部门名称
//        String compactName = sysOrganizationService.findCompactName(officeId);
//        Map<String,Object> params = new HashMap<>();
//        params.put("orgId", AppUserUtil.getOrgId());
//        //字典查出教师编制类型
//        params.put("type","PACT_TYPE");
//        List<Map<String,Object>> compacts = golDictService.getTeacherPact(params);
//        Integer sheetInt = sheet.getPhysicalNumberOfRows();
//        for (int i = sheet.getFirstRowNum() + GlobalDict.DATA_LINE; i < sheet
//                .getPhysicalNumberOfRows(); i++) {
//            row = sheet.getRow(i);
//
//            for (int j = row.getFirstCellNum(); j < line; j++) {
//                // 通过 row.getCell(j).toString() 获取单元格内容,
//                cell = row.getCell(j);
//                if (i == GlobalDict.DATA_LINE) {
//                    title.add(cell == null ? "" : cell.toString());
//                }
//                if ((cell == null || cell.toString().trim().isEmpty()) && j != GlobalDict.PHOTO_LINE
//                        && j != GlobalDict.TEL) {
//                    String errString = "第" + (i + 1) + "行  " + title.get(j) + "列不可为空";
//                    errList.add(errString);
//                } else if (i > GlobalDict.DATA_LINE && title.get(j).equals("身份证号")
//                        && !PersonCotrollerUtil.isCard2(DataValue(cell))) {
//                    String errString = "第" + (i + 1) + "行  " + title.get(j) + "列信息有误";
//                    errList.add(errString);
//                } else if (i > GlobalDict.DATA_LINE && title.get(j).equals("出生日期")
//                        && !PersonCotrollerUtil.isDate(cell.toString())) {
//                    String errString = "第" + (i + 1) + "行  " + title.get(j) + "列信息有误";
//                    errList.add(errString);
//                } else if (i > GlobalDict.DATA_LINE && title.get(j).equals("部门")&&isSchool
//                        && !offcieExsit(cell.toString(), orgs)) {
//                    String errString = "第" + (i + 1) + "行  " + title.get(j) + "列不存在此部门";
//                    errList.add(errString);
//                }else if (i > GlobalDict.DATA_LINE && title.get(j).equals("部门")&&!isSchool
//                        && !compactName.equals(cell.toString())) {
//                    String errString = "第" + (i + 1) + "行  " + title.get(j) + "名称输入有误";
//                    errList.add(errString);
//                }
//                else if (i > GlobalDict.DATA_LINE && title.get(j).equals("职务")
//                        && !postExsit(cell.toString(), orgId)) {
//                    String errString = "第" + (i + 1) + "行  " + title.get(j) + "列不存在此职务";
//                    errList.add(errString);
//                }else if (i > GlobalDict.DATA_LINE && title.get(j).equals("编制")&&!isCompact(compacts,cell.toString()))
//                {
//                    String errString = "第" + (i + 1) + "行  " + title.get(j) + "列不存在此编制";
//                    errList.add(errString);
//                }
//                else if (i > GlobalDict.DATA_LINE && title.get(j).equals("联系电话")
//                        && cell.toString() != null && !"".equals(cell.toString())
//                        && !PersonCotrollerUtil.isPhone(cell.toString())&&!PersonCotrollerUtil.isMobile(cell.toString())) {
//                    String errString = "第" + (i + 1) + "行  " + title.get(j) + "列信息有误";
//                    errList.add(errString);
//                } else if (i > GlobalDict.DATA_LINE && title.get(j).equals("手机")
//                        && !PersonCotrollerUtil.isMobile(DataValue(cell))) {
//                    String errString = "第" + (i + 1) + "行" + title.get(j) + "列信息有误";
//                    errList.add(errString);
//                }
//            }
//        }
//        return errList;
//    }
//
//    private Integer isImportTeacherOffice(Map<String, Object> param) {
//        //1.学校2.部门3.选择有误
//        Integer state = 3;
//        //字典里获取学校value和部门value
//        String schoolValue  = OrgTypeUtil.getByKey(GlobalDict.SCHOOL).getValue();
//        String compactValue = OrgTypeUtil.getByKey(GlobalDict.DEPARTMENT).getValue();
//        param.put("schoolValue",schoolValue);
//        param.put("compactValue",compactValue);
//        Map<String,Object> map = sysOrganizationService.isisImportTeacherOffice(param);
//        if(Integer.valueOf(map.get("isSchool").toString()) != 0){
//            state = 1;
//        }
//        if(Integer.valueOf(map.get("isCompact").toString()) != 0){
//            state = 2;
//        }
//        return state;
//    }
//
//    private boolean isImportStudentClass(Map<String, Object> param) {
//        //字典里获取班级的value
//        String type = OrgTypeUtil.getByKey(GlobalDict.CLASS).getValue();
//        param.put("type",type);
//        return sysOrganizationService.isImportStudentClass(param);
//    }
//
//
//    /**
//     * . 获取教职工身份证
//     *
//     * @param cell 当前cell对象
//     *
//     * @return string idcard
//     */
//
//    public String DataValue(XSSFCell cell) {
//        if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
//            BigDecimal bd = new BigDecimal(cell.getNumericCellValue());
//            return bd.toPlainString();
//        } else {
//            return cell.toString();
//        }
//    }
//
//    /**
//     * 判断机构下是否存在该部门
//     *
//     * @param officeName
//     * @param orgs
//     * @return
//     */
//    private boolean offcieExsit(String officeName, List<SysOrganization> orgs) {
//        boolean isDep = false;
//        for(SysOrganization org:orgs){
//            if(org.getName().equals(officeName)){
//                return  true;
//            }
//        }
//        return isDep;
//    }
//
//    //获取offiecId部门value值
//    private Long getOfficeValue(String officeName,List<SysOrganization> orgs){
//        Long depValue = null;
//        for(SysOrganization org:orgs){
//            if(org.getName().equals(officeName)){
//                return org.getId();
//            }
//        }
//        return depValue;
//    }
//
//    //获取编制Value值
//    private String getCompactTypeValue(List<Map<String,Object>> compacts,String compactName){
//        String compactValue = "";
//        if(compacts.size() > 1){
//            for(int i=1;i<compacts.size();i++){
//                if(compacts.get(i).get("lable").toString().equals(compactName)){
//                    compactValue = compacts.get(i).get("value").toString();
//                }
//            }
//        }
//        return compactValue;
//    }
//
//    //判断职位是否存在
//    private Boolean isCompact(List<Map<String,Object>> compacts,String compactName){
//        boolean iscompact = false;
//        if(compacts.size() > 1){
//            for(int i=1;i<compacts.size();i++){
//                if(compacts.get(i).get("lable").toString().equals(compactName)){
//                    iscompact = true;
//                }
//            }
//        }
//        return iscompact;
//    }
//
//    /**.
//     * 判断机构下是否存在该部门
//     * @ param postNames
//     * @ param orgId
//     * @ return
//     */
//    private boolean postExsit(String postNames, Integer orgId) {
//        Map<String,Object> params = new HashMap<>();
//        //字典查询出职务类型标示符
//        String type = "PEO_TYPE";
//        params.put("type",type);
//        params.put("orgId",orgId);
//        Map<String,Object> postJobs = golDictService.getPeoType(params);
//        List<Map<String,Object>> jobs = (List<Map<String,Object>>)postJobs.get("data");
//        for(Map<String,Object> map:jobs){
//            if(map.get("lable").toString().equals(postNames)){
//                return true;
//            }
//        }
//       return false;
//    }
//
//    /**
//     * . 获取Excel2007图片
//     *
//     * @param sheetNum 当前sheet编号
//     * @param sheet 当前sheet对象
//     * @return Map key:图片单元格索引(0_1_1)String,value:图片流PictureData
//     */
//
//    public Map<String, PictureData> getSheetPictrues(int sheetNum, XSSFSheet sheet) {
//        Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
//        for (POIXMLDocumentPart dr : sheet.getRelations()) {
//            if (dr instanceof XSSFDrawing) {
//                XSSFDrawing drawing = (XSSFDrawing) dr;
//                List<XSSFShape> shapes = drawing.getShapes();
//                for (XSSFShape shape : shapes) {
//                    if (shape instanceof XSSFPicture) {
//                        XSSFPicture pic = (XSSFPicture) shape;
//                        XSSFClientAnchor anchor = pic.getPreferredSize();
//                        CTMarker ctMarker = anchor.getFrom();
//                        String picIndex =
//                                String.valueOf(sheetNum) + "_" + ctMarker.getRow() + "_" + ctMarker.getCol();
//                        sheetIndexPicMap.put(picIndex, pic.getPictureData());
//                    }
//                }
//            }
//        }
//        return sheetIndexPicMap;
//    }
//
//    /**
//     * . 往集合添加学生数据
//     *
//     * @param sheet 当前sheet对象
//     * @param orgId 当前组织orgId
//     * @param officeId 当前 部门或班级officeId
//     * @param flag 学生为true
//     * @return List 学生的集合
//     * @throws Exception e
//     */
//
//    public List<BbEmployeeVO> studentListAdd(XSSFSheet sheet, Integer orgId, Integer officeId,
//                                        Boolean flag) throws Exception {
//        // 定义 row、cell
//        XSSFRow row;
//        XSSFCell cell;
//        List<BbEmployeeVO> list = new ArrayList<BbEmployeeVO>();
//        // 循环输出表格中的内容
//        for (int i = sheet.getFirstRowNum() + 1 + GlobalDict.DATA_LINE; i < sheet
//                .getPhysicalNumberOfRows(); i++) {
//            row = sheet.getRow(i);
//            BbEmployeeVO bbEmployeeVO = new BbEmployeeVO();
//
//            bbEmployeeVO.setOrgId(Long.parseLong(orgId+""));
//            bbEmployeeVO.setOfficeId(Long.parseLong(officeId+""));
//            bbEmployeeVO.setType(isEmpType(flag));
//            bbEmployeeVO.setRevJson1("{}");
//
//            //设置组织机构沉余
//            String parendIds = orgDao.findCurentParentIds(officeId.longValue(),null);
//            List<String> orgList = orgDao.finCurentOrgs(parendIds,null);
//            if(orgList.size()>0){
//                String orgNams = orgList.get(0).toString();
//                if(orgList.size()>1) {
//                    for (int j = 1; j < orgList.size(); j++) {
//                        orgNams += " " + orgList.get(j).toString();
//                    }
//                }
//                bbEmployeeVO.setOrgNamesJson(orgNams);
//            }
//
//            for (int j = row.getFirstCellNum(); j < GlobalDict.STUDENT_SHEET_LINE; j++) {
//                // 通过 row.getCell(j).toString() 获取单元格内容,
//                cell = row.getCell(j);
//                switch (j) {
//                    case 0:// 姓名列
//                        bbEmployeeVO.setName(cell.toString());
//                        //提取姓名助记码
//                        bbEmployeeVO.setMnemonicCode(new UpperByName().toUpperByName(bbEmployeeVO.getName()));
//                        break;
//                    case 1:// 性别列
//                        bbEmployeeVO.setGender(cell.toString());
//                        break;
//                    case 2:// 身份证号
//                        bbEmployeeVO.setCardId(cell.toString());
//                        break;
//                    default:
//                        break;
//                }
//            }
//            list.add(bbEmployeeVO);
//        }
//        return list;
//    }
//
//    /**
//     * . 往集合添加老师数据
//     *
//     * @param sheet 当前sheet对象
//     * @param orgId 当前组织orgId
//     * @param officeId 当前 部门或班级officeId
//     * @param flag 教师为flase
//     * @return List 学生的集合
//     * @throws Exception e
//     */
//
//    public List<BbEmployeeVO> teacherListAdd(XSSFSheet sheet, Integer orgId, Integer officeId,
//                                           Boolean flag) throws Exception {
//        // 定义 row、cell
//        XSSFRow row;
//        XSSFCell cell;
//        List<BbEmployeeVO> list = new ArrayList<BbEmployeeVO>();
//        Integer dep = Integer.parseInt(OrgTypeUtil.getByKey(GlobalDict.DEPARTMENT).getValue());
//        List<SysOrganization> orgs = sysOrganizationService.findDownByType(dep,Long.valueOf(officeId),null);
//        Map<String,Object> params = new HashMap<>();
//        params.put("orgId", AppUserUtil.getOrgId());
//        //字典查出教师编制类型
//        params.put("type","PACT_TYPE");
//        List<Map<String,Object>> compacts = golDictService.getTeacherPact(params);
//        // 循环输出表格中的内容
//        for (int i = sheet.getFirstRowNum() + 1 + GlobalDict.DATA_LINE; i < sheet.getPhysicalNumberOfRows(); i++) {
//            row = sheet.getRow(i);
//            BbEmployeeVO bbEmployeeVO = new BbEmployeeVO();
//
//            bbEmployeeVO.setOrgId(Long.parseLong(orgId+""));
//            bbEmployeeVO.setOfficeId(Long.parseLong(officeId+""));
//            bbEmployeeVO.setType(isEmpType(flag));
//            //可变的后期根据需求更改
//            bbEmployeeVO.setCompactType("200");
//            bbEmployeeVO.setRevJson1("{}");
//
//            for (int j = row.getFirstCellNum(); j < GlobalDict.TEACHER_SHEET_LINE; j++) {
//                // 通过 row.getCell(j).toString() 获取单元格内容,
//                cell = row.getCell(j);
//                String cellStr = getCellValue(cell);
//                switch (j) {
//                    case 0:// 姓名列
//                        bbEmployeeVO.setName(cellStr);
//                        //提取姓名助记码
//                        bbEmployeeVO.setMnemonicCode(new UpperByName().toUpperByName(bbEmployeeVO.getName()));
//                        break;
//                    case 1:// 性别列
//                        bbEmployeeVO.setGender(cellStr);
//                        break;
//                    case 2:// 身份证号
//                        bbEmployeeVO.setCardId(cellStr);
//                        break;
//                    case 4:// 电话
//                        bbEmployeeVO.setPhone(cellStr);
//                        break;
//                    case 5://部门
//                        bbEmployeeVO.setOfficeId(getOfficeValue(cellStr,orgs));
//
//                        String parendIds = orgDao.findCurentParentIds(bbEmployeeVO.getOfficeId(),null);
//                        String orgNamesJson = orgDao.getParentNames(parendIds,null, " ");
//
//                        bbEmployeeVO.setOrgNamesJson(StringUtils.isEmpty(orgNamesJson)?"":orgNamesJson);
//                        break;
//                    case 6://编制
//                        bbEmployeeVO.setCompactType(getCompactTypeValue(compacts,cellStr));
//                    default:
//                        break;
//                }
//            }
//            list.add(bbEmployeeVO);
//        }
//        return list;
//    }
//
//    /**
//     * . 导出Excel2007图片
//     *
//     * @param xwb excel表格
//     * @param list 添加数据的集合
//     * @param errList
//     */
//    public void  getPhoto(List<BbEmployeeVO> list, XSSFWorkbook xwb, List<String> errList)
//            throws Exception {
//        // 创建sheet
//        Sheet sheet = null;
//        // 获取excel sheet总数
//        int sheetNumbers = xwb.getNumberOfSheets();
//        // sheet list
//        List<Map<String, PictureData>> sheetList = new ArrayList<Map<String, PictureData>>();
//        // 循环sheet
//        for (int i = 0; i < sheetNumbers; i++) {
//            sheet = xwb.getSheetAt(i);
//            // map等待存储excel图片
//            Map<String, PictureData> sheetIndexPicMap;
//            // 用07方法获取图片
//            sheetIndexPicMap = getSheetPictrues(i, (XSSFSheet) sheet);
//            // 将当前sheet图片map存入list
//            sheetList.add(sheetIndexPicMap);
//        }
//
//        printImg(sheetList, list, errList);
//    }
//
//    /**
//     * . 打印Excel2007图片
//     *
//     * @param sheetList 当前sheet图片集合
//     * @param list 添加数据的集合
//     * @param errList
//     */
//    public List<String> printImg(List<Map<String, PictureData>> sheetList, List<BbEmployeeVO> list,
//                         List<String> errList) throws Exception {
//        String err = new String();
//        for (int j = 0; j < sheetList.size(); ++j) {
//            Map<String, PictureData> map = sheetList.get(j);
//            Object[] key = map.keySet().toArray();
//            String path = "";
//            for (int i = 0; i < map.size(); i++) {
//                // 获取图片流
//                PictureData pic = map.get(key[i]);
//                // 获取图片索引
//                String picName = key[i].toString();
//                // 获取图片格式
//                String ext = pic.suggestFileExtension();
//                long time = System.currentTimeMillis();
//                byte[] data = pic.getData();
//                data = ImageUtils.resize(data, ext);
//                String faces = FaceUtil.extractFeature(data,"");
//                if (faces == null||faces=="") {
//                    int row = Integer.parseInt(picName.split("_")[1]) + 1;
//                    err = "第" + row + "行的人员照片未识别";
//                    errList.add(err);
//                } else {
//                    String orignFilename = time + "_" + picName + "." + ext;
//                    try {
//                        //小于30K进行压缩
//                        if(data.length > 50*1024) {
//                            try {
//                                data = getImageMin(orignFilename, data);
//                            } catch (Exception e) {
//                                e.printStackTrace();
//                            }
//                        }
//                        //上传到服务器拿到路径
//                        FileInfo fileInfo = fileUtilClient.uploadByFile( orignFilename,data,"", AppUserUtil.getAccessToken());
//                        //匹配当前人的照片
//                        String[] nos = key[i].toString().split("_");
//                        int no = Integer.parseInt(nos[1])-3;
//                        list.get(no).setPhotos(fileInfo.getUrl());
//
//                        //人脸特征不为空时
//                        if(!faces.isEmpty()){
//                            BbFace bbFace = new BbFace();
//                            bbFace.setOrgId(list.get(i).getOrgId());
//                            bbFace.setFeature(faces);
//                            bbFaceDao.save(bbFace);
//                        }
//                        //查询人脸表ID
//                        if(!faces.isEmpty()){
//                            Integer bbFaciId = bbFaceDao.findIdByFaces(faces);
//                            list.get(no).setFaceIds(bbFaciId.toString());
//                        }
//                    }catch (Exception e){
//                        errList.add("连接失败,请重新导入或联系管理员");
//                        System.out.println(e.getMessage());
//                        return errList;
//                    }
//                }
//            }
//        }
//        return errList;
//    }
//
//    public static String getCellValue(Cell cell){
//        String cellValue = "";
//        if(cell == null){
//            return cellValue;
//        }
//        //把数字当成String来读,避免出现1读成1.0的情况
//        if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
//
//            //判断是否是日期类型 如果是日期类型 处理成日期类型
//            if (HSSFDateUtil.isCellDateFormatted(cell)) {
//                Date d = cell.getDateCellValue();
//                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//                cellValue=sdf.format(d);
//                return cellValue;
//            }else{
//                cell.setCellType(Cell.CELL_TYPE_STRING);
//            }
//
//        }
//        //判断数据的类型
//        switch (cell.getCellType()){
//            case Cell.CELL_TYPE_NUMERIC: //数字
//                cellValue = String.valueOf(cell.getNumericCellValue());
//                break;
//            case Cell.CELL_TYPE_STRING: //字符串
//                cellValue = String.valueOf(cell.getStringCellValue());
//                break;
//            case Cell.CELL_TYPE_BOOLEAN: //Boolean
//                cellValue = String.valueOf(cell.getBooleanCellValue());
//                break;
//            case Cell.CELL_TYPE_FORMULA: //公式
//                cellValue = String.valueOf(cell.getCellFormula());
//                break;
//            case Cell.CELL_TYPE_BLANK: //空值
//                cellValue = "";
//                break;
//            case Cell.CELL_TYPE_ERROR: //故障
//                cellValue = "非法字符";
//                break;
//            default:
//                cellValue = "未知类型";
//                break;
//        }
//        return cellValue;
//    }
//
//    /**
//     * . 该人员是否存在
//     *
//     * @param u 用户
//     * @return 存在flag
//     */
//
//    private boolean isExist(BbEmployeeVO u) {
//        BbEmployee bbEmployee = dao.isExistEmployee(u.getOrgId(),u.getPhone());
//        if(bbEmployee == null){
//            return false;
//        }else{
//            if(bbEmployee.getFaceIds()!=null){
//                u.setId(bbEmployee.getId());
//            }
//            return true;
//        }
//    }
//
//    private String isEmpType(Boolean flag){
//        if(flag == true){
//            return EmpTypeConstant.EMP_STUDENT;
//        }else{
//            return EmpTypeConstant.EMP_TEACHER;
//        }
//    }
//
//    //图像质量压缩
//    public byte[] getImageMin(String filename,byte[] byt)  throws Exception {
//
//        InputStream stream = new ByteArrayInputStream(byt);
//        MultipartFile multipartFile = new MockMultipartFile("file",filename+".jpg", "text/plain", IOUtils.toByteArray(stream));
//
//
//        File f = null;
//        if(multipartFile.equals("")||multipartFile.getSize()<=0){
//            multipartFile = null;
//        }else{
//            InputStream ins = multipartFile.getInputStream();
//            f=new File(multipartFile.getOriginalFilename());
//            //inputStreamToFile(ins, f);
//
//        }
////        DecimalFormat df=new DecimalFormat("0.000000000000");
////        float fn = Float.parseFloat(df.format(30.0f*1024/byt.length));
//        Thumbnails.of(multipartFile.getInputStream()).scale(1f).outputQuality(0.2f).toFile(f);
//        byte[] data =  Files.readAllBytes(f.toPath());
//        File del = new File(f.toURI());
//        del.delete();
//
//        return data;
//    }
//
//    //文件转换
//    public static void inputStreamToFile(InputStream ins,File file) {
//        try {
//            OutputStream os = new FileOutputStream(file);
//            int bytesRead = 0;
//            byte[] buffer = new byte[8192];
//            while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
//                os.write(buffer, 0, bytesRead);
//            }
//            os.close();
//            ins.close();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//
//
//
//
//
//    /**
//     * ***************模板下載************************************************************************************************************************
//     */
//
//    /**
//     * excel模板下载
//     *
//     * @param type 下载表的类型
//     */
//    @RequestMapping("excel/excelDownload")
//    @ApiOperation(value = "Excel人员信息导入模版下载", notes = "Excel人员信息导入模版下载", httpMethod = "GET", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "type", value = "模版类型:stu 是学生; tea 是教师", required = true, dataType = "string", paramType = "query")
//    })
//    public String excelDownload(HttpServletResponse response, String type, Integer companyId) {
//        try{
//            String fileName = "";
//            switch (type) {
//                case GlobalDict.TEMPLATE_STU:
//                    fileName = "学生人员信息.xlsx";
//                    break;
//                case GlobalDict.TEMPLATE_TEA:
//                    fileName = "教职工人员信息.xlsx";
//                    break;
//                case GlobalDict.TEMPLATE_TEAM:
//                    fileName = "教职工人员信息.xlsx";
//                    break;
//            }
//            String name = new String(fileName.getBytes(), "ISO8859-1");
//            response.setCharacterEncoding("utf-8");
//            response.setContentType("multipart/form-data");
//            response.setHeader("Content-Disposition", "attachment;fileName=" + name);
//            downloadModel(type, companyId, response.getOutputStream());
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
//
//    /**
//     * .下载模板
//     *
//     * @param type 模板类型
//     * @param companyId 机构id
//     * @param out 输出流
//     */
//    public void downloadModel(String type, Integer companyId, OutputStream out) throws Exception {
//        String[] headers = {};
//        String[] addArray = {};
//        String[] postArray = {};
//        List<String> addList = new ArrayList<String>();
//        List<String> postList = new ArrayList<String>();
//        String title = "";
//        switch (type) {
//            case GlobalDict.TEMPLATE_STU:
//                headers = GlobalDict.STUDENT_HEADERS;   //设置学生标题
//                addArray = GlobalDict.GENDER;           //设置性别
//                title = "学生人员信息";
//                break;
//            case GlobalDict.TEMPLATE_TEA:
//                headers = GlobalDict.TEACHER_HEADERS;   //设置教师标题
//                title = "教职工人员信息";                       //设置标头
//                break;
//            case GlobalDict.TEMPLATE_TEAM:
//                break;
//        }
//        XSSFWorkbook workbook = createExcel(title, headers, true);   //创建excel 模版
//        //setAddList(workbook, addArray, postArray);        //设置下拉数据流
//        downloadExcel(workbook, out);
//        out.close();
//    }
//
//    /**
//     * . 创建excel
//     *
//     * @param title sheet 的标题
//     * @param headers sheet的列名
//     * @param flag 下载模板 true 导出人员 false
//     * @return XSSFWorkbook excel
//     */
//
//    public XSSFWorkbook createExcel(String title, String[] headers, boolean flag) {
//        // 声明一个工作薄
//        XSSFWorkbook workbook = new XSSFWorkbook();                //创建好excel模版sheet1
//        // 生成一个表格
//        XSSFSheet sheet = workbook.createSheet("sheet1");
//        // 设置表格默认列宽度为15个字节
//        sheet.setDefaultColumnWidth((short) 15);
//        // 生成并设置另一个样式
//        XSSFCellStyle style = setSheetStyle(workbook);
//        // 产生表格标题
//        setSheetTitle(sheet, style, title, headers, flag);          //设置标题
//        // 产生表格标题行
//        setSheetHeaders(sheet, style, headers, flag);
//
//        return workbook;
//    }
//
//    /**
//     * . 设置excel 格式
//     *
//     * @param workbook excel
//     * @return XSSFCellStyle excel 表格
//     */
//
//    public XSSFCellStyle setSheetStyle(XSSFWorkbook workbook) {
//        XSSFCellStyle style = workbook.createCellStyle();
//        style.setAlignment(XSSFCellStyle.ALIGN_CENTER);
//        // 生成一个字体
//        XSSFFont font = workbook.createFont();
//        font.setFontHeightInPoints((short) 12);
//        font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
//        // 把字体应用到当前的样式
//        style.setFont(font);
//        return style;
//    }
//
//    /**
//     * . 设置标题
//     *
//     * @param sheet 当前sheet对象
//     * @param style 当前sheet对象的style
//     * @param title 标题
//     * @param headers 列名
//     */
//    public void setSheetTitle(XSSFSheet sheet, XSSFCellStyle style, String title, String[] headers,   //设置excel模版的样式。标题
//                              boolean flag) {
//        XSSFRow row = sheet.createRow(0);   //设置第一行
//        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, headers.length - 1));   //合并单元格
//        XSSFRichTextString sheetName = new XSSFRichTextString(title);  //设置标题
//        XSSFCell cellTitle = row.createCell(0);  //创建第一列
//        cellTitle.setCellStyle(style);   //设置第一列的样式
//        cellTitle.setCellValue(sheetName); //设置
//        if (flag) {
//            XSSFRow row1 = sheet.createRow(1);
//            sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, headers.length - 1));
//            String hint = "提示:请把照片放在单元格中,联系电话必填,不可重复 (注意事项:禁止修改模版名字,身份证号,联系电话列属性修改为文本)";
//            XSSFCell cellTitle1 = row1.createCell(0);
//            cellTitle1.setCellValue(hint);
//        }
//    }
//
//    /**
//     * . 设置sheet列名
//     *
//     * @param sheet 当前sheet对象
//     * @param style 当前sheet对象的style
//     * @param headers 列名
//     * @param flag 区分导出还是下载的标志
//     */
//    private void setSheetHeaders(XSSFSheet sheet, XSSFCellStyle style, String[] headers,
//                                 boolean flag) {
//        XSSFRow row = null;
//        if (flag) {
//            row = sheet.createRow(2);
//        } else {
//            row = sheet.createRow(1);
//        }
//        for (short i = 0; i < headers.length; i++) {
//            XSSFCell cell = row.createCell(i);
//            cell.setCellStyle(style);
//            XSSFRichTextString text = new XSSFRichTextString(headers[i]);
//            cell.setCellValue(text);
//        }
//    }
//
//    /**
//     * . 设置下拉数据列表
//     *
//     * @param workbook excel
//     * @param strs 下拉数据列表流
//     *
//     */
//
//    private void setAddList(XSSFWorkbook workbook, String[] strs, String[] postNames) {         //设置excel表格下拉列表   性别  职务,部门
//        if ((strs == null || strs.length == 0) && (postNames == null || postNames.length == 0)) {
//            return;
//        }
//        XSSFSheet sheet = workbook.getSheet("sheet1");
//        XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper(sheet);
//        XSSFDataValidationConstraint dvConstraint =
//                (XSSFDataValidationConstraint) dvHelper.createExplicitListConstraint(strs);
//        XSSFDataValidationConstraint dvConstraintPost =
//                (XSSFDataValidationConstraint) dvHelper.createExplicitListConstraint(postNames);
//        CellRangeAddressList addressList = null;
//        XSSFDataValidation validation = null;
//        for (int i = GlobalDict.DATA_LINE; i < 100; i++) {
//            if (strs != null && strs.length > 0) {
//                addressList = new CellRangeAddressList(i, i, GlobalDict.ADD_LIST_LINE_NUM,
//                        GlobalDict.ADD_LIST_LINE_NUM);// 行,列,
//                validation = (XSSFDataValidation) dvHelper.createValidation(dvConstraint, addressList);
//                sheet.addValidationData(validation);
//            }
//            if (postNames != null && postNames.length > 0) {
//                addressList = new CellRangeAddressList(i, i, GlobalDict.ADD_LIST_LINE_NUM_3,
//                        GlobalDict.ADD_LIST_LINE_NUM_3);// 行,列,
//                validation = (XSSFDataValidation) dvHelper.createValidation(dvConstraintPost, addressList);
//                sheet.addValidationData(validation);
//            }
//        }
//    }
//
//    /**
//     * . 下载excel
//     *
//     * @param workbook excel
//     * @param out 输出流
//     *
//     */
//    public void downloadExcel(XSSFWorkbook workbook, OutputStream out) throws Exception {
//        try {
//            workbook.write(out);                                                  //输出流下载excel
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//
//
 
}