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();
|
// }
|
// }
|
//
|
//
|
|
}
|