Commit 461abb080e3c26b0ef5ea0a55d14f53c2d44157a
1 parent
8b94a56a
Exists in
master
修改提交
Showing
8 changed files
with
221 additions
and
10 deletions
Show diff stats
cloud/dahua/pom.xml
| ... | ... | @@ -143,6 +143,12 @@ |
| 143 | 143 | <artifactId>pinyin4j</artifactId> |
| 144 | 144 | <version>2.5.0</version> |
| 145 | 145 | </dependency> |
| 146 | + <!--easypoi依赖,excel导入导出--> | |
| 147 | + <dependency> | |
| 148 | + <groupId>cn.afterturn</groupId> | |
| 149 | + <artifactId>easypoi-spring-boot-starter</artifactId> | |
| 150 | + <version>4.3.0</version> | |
| 151 | + </dependency> | |
| 146 | 152 | <!-- <dependency>--> |
| 147 | 153 | <!-- <groupId>com.aliyun.oss</groupId>--> |
| 148 | 154 | <!-- <artifactId>aliyun-sdk-oss</artifactId>--> | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/bean/yx/ExportStudentBean.java
0 → 100644
| ... | ... | @@ -0,0 +1,49 @@ |
| 1 | +package com.example.dahua.bean.yx; | |
| 2 | + | |
| 3 | +import cn.afterturn.easypoi.excel.annotation.Excel; | |
| 4 | + | |
| 5 | +import java.io.Serializable; | |
| 6 | + | |
| 7 | +public class ExportStudentBean implements Serializable { | |
| 8 | + | |
| 9 | + @Excel(name = "姓名") | |
| 10 | + private String name; | |
| 11 | + @Excel(name = "班级") | |
| 12 | + private String className; | |
| 13 | + @Excel(name = "十六进制") | |
| 14 | + private String studentNum; | |
| 15 | + @Excel(name = "十进制") | |
| 16 | + private String studentNum10; | |
| 17 | + | |
| 18 | + public String getName() { | |
| 19 | + return name; | |
| 20 | + } | |
| 21 | + | |
| 22 | + public void setName(String name) { | |
| 23 | + this.name = name; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public String getClassName() { | |
| 27 | + return className; | |
| 28 | + } | |
| 29 | + | |
| 30 | + public void setClassName(String className) { | |
| 31 | + this.className = className; | |
| 32 | + } | |
| 33 | + | |
| 34 | + public String getStudentNum() { | |
| 35 | + return studentNum; | |
| 36 | + } | |
| 37 | + | |
| 38 | + public void setStudentNum(String studentNum) { | |
| 39 | + this.studentNum = studentNum; | |
| 40 | + } | |
| 41 | + | |
| 42 | + public String getStudentNum10() { | |
| 43 | + return studentNum10; | |
| 44 | + } | |
| 45 | + | |
| 46 | + public void setStudentNum10(String studentNum10) { | |
| 47 | + this.studentNum10 = studentNum10; | |
| 48 | + } | |
| 49 | +} | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/control/UserOperateController.java
| ... | ... | @@ -7,6 +7,7 @@ import com.example.dahua.dao.UserDao; |
| 7 | 7 | import com.example.dahua.service.UserOperateService; |
| 8 | 8 | import com.example.dahua.service.imp.BaseService; |
| 9 | 9 | import com.example.dahua.utils.ExcelUtil; |
| 10 | +import com.example.dahua.utils.ExcelUtil2; | |
| 10 | 11 | import com.example.dahua.utils.HttpUtils; |
| 11 | 12 | import com.example.dahua.utils.ReadExcelUtil; |
| 12 | 13 | import io.swagger.annotations.Api; |
| ... | ... | @@ -19,10 +20,12 @@ import org.springframework.web.multipart.MultipartFile; |
| 19 | 20 | import org.springframework.web.multipart.MultipartHttpServletRequest; |
| 20 | 21 | |
| 21 | 22 | import javax.servlet.http.HttpServletRequest; |
| 23 | +import javax.servlet.http.HttpServletResponse; | |
| 22 | 24 | import java.io.IOException; |
| 23 | 25 | import java.io.InputStream; |
| 24 | 26 | import java.util.ArrayList; |
| 25 | 27 | import java.util.List; |
| 28 | +import java.util.Map; | |
| 26 | 29 | |
| 27 | 30 | /** |
| 28 | 31 | * 用户信息、人脸、卡信息、权限下发控制类 |
| ... | ... | @@ -119,6 +122,21 @@ public class UserOperateController { |
| 119 | 122 | userOperateService.saveStudentInfo(readExcel, fileName); |
| 120 | 123 | } |
| 121 | 124 | |
| 125 | + /** | |
| 126 | + * 中意导出学生名单 | |
| 127 | + * @param schoolId | |
| 128 | + * @param request | |
| 129 | + * @param response | |
| 130 | + */ | |
| 131 | + @ApiOperation(value = "导入学生信息") | |
| 132 | + @RequestMapping(value = "exportStudent", method = RequestMethod.GET) | |
| 133 | + public void importExcel(@RequestParam("schoolId") Integer schoolId, | |
| 134 | + HttpServletRequest request, HttpServletResponse response){ | |
| 135 | + | |
| 136 | + List<Map<String, Object>> sheetList = userOperateService.exportStudent(schoolId,"188368,188369,188370,188371"); | |
| 137 | + ExcelUtil2.exportExcelByEasyPoi(sheetList,"中意",request,response); | |
| 138 | + } | |
| 139 | + | |
| 122 | 140 | @ApiOperation(value = "艺校照片特定下发") |
| 123 | 141 | @RequestMapping(value = "sendYxFace", method = RequestMethod.POST) |
| 124 | 142 | public Result sendFaceByThread(@RequestBody YxSendFaceDto sendFaceDto) { | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/service/UserOperateService.java
| ... | ... | @@ -6,6 +6,7 @@ import com.example.dahua.bean.yx.YxSendFaceDto; |
| 6 | 6 | |
| 7 | 7 | import java.util.ArrayList; |
| 8 | 8 | import java.util.List; |
| 9 | +import java.util.Map; | |
| 9 | 10 | |
| 10 | 11 | /** |
| 11 | 12 | * 下发用户信息、人脸、卡、权限接口 |
| ... | ... | @@ -40,4 +41,6 @@ public interface UserOperateService { |
| 40 | 41 | Result sendYxUserFace(YxSendFaceDto sendFaceDto); |
| 41 | 42 | |
| 42 | 43 | void sendCard(String cardNum,Integer schoolId,String deviceIds); |
| 44 | + | |
| 45 | + List<Map<String, Object>> exportStudent(Integer schoolId, String deviceIds); | |
| 43 | 46 | } | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/service/imp/UserOperateServiceImpl.java
| 1 | 1 | package com.example.dahua.service.imp; |
| 2 | 2 | |
| 3 | +import cn.afterturn.easypoi.excel.entity.ExportParams; | |
| 3 | 4 | import com.example.dahua.MyTask; |
| 4 | 5 | import com.example.dahua.bean.SendRecordBean; |
| 5 | 6 | import com.example.dahua.bean.StudentBean; |
| 6 | 7 | import com.example.dahua.bean.UserInfoBean; |
| 7 | -import com.example.dahua.bean.yx.ImportStudent; | |
| 8 | -import com.example.dahua.bean.yx.Result; | |
| 9 | -import com.example.dahua.bean.yx.ResultGenerator; | |
| 10 | -import com.example.dahua.bean.yx.YxSendFaceDto; | |
| 8 | +import com.example.dahua.bean.yx.*; | |
| 11 | 9 | import com.example.dahua.dao.UserDao; |
| 12 | 10 | import com.example.dahua.lib.CompressPic; |
| 13 | 11 | import com.example.dahua.lib.FilePath; |
| ... | ... | @@ -324,4 +322,47 @@ public class UserOperateServiceImpl implements UserOperateService { |
| 324 | 322 | } |
| 325 | 323 | }); |
| 326 | 324 | } |
| 325 | + | |
| 326 | + | |
| 327 | + @Override | |
| 328 | + public List<Map<String, Object>> exportStudent(Integer schoolId,String classIds) { | |
| 329 | + // 将sheet1、sheet2使用得map进行包装 | |
| 330 | + List<Map<String, Object>> sheetsList = new ArrayList<>(); | |
| 331 | + //根据类型获取下发用户信息 | |
| 332 | + List<StudentBean> studentBeanList = baseService.getStudentByClassId(schoolId,classIds); | |
| 333 | + log.info("统计共有下发用户数量:{}",studentBeanList.size()); | |
| 334 | + | |
| 335 | + List<ExportStudentBean> studentBeans = studentBeanList.stream().map(s->{ | |
| 336 | + ExportStudentBean studentBean = new ExportStudentBean(); | |
| 337 | + studentBean.setName(s.getName()); | |
| 338 | + studentBean.setClassName(s.getClass_name()); | |
| 339 | + studentBean.setStudentNum(s.getStudent_num()); | |
| 340 | + studentBean.setStudentNum10(Long.parseLong(getCard(s.getStudent_num()),16)+""); | |
| 341 | + return studentBean; | |
| 342 | + }).collect(Collectors.toList()); | |
| 343 | + | |
| 344 | + String title = "学事通升学汇大数据(多元升学规划定位表)"; | |
| 345 | + ExportParams exportParams = new ExportParams(); | |
| 346 | + exportParams.setSheetName("选科规划"); | |
| 347 | + exportParams.setTitle(title); | |
| 348 | + Map<String, Object> universityMap = new HashMap<>(); | |
| 349 | + universityMap.put("title", exportParams); | |
| 350 | + | |
| 351 | + universityMap.put("entity", ExportStudentBean.class); | |
| 352 | + universityMap.put("data", studentBeans); | |
| 353 | + sheetsList.add(universityMap); | |
| 354 | + return sheetsList; | |
| 355 | + } | |
| 356 | + | |
| 357 | + public static String getCard(String cardNo) { | |
| 358 | + if (cardNo.length() == 8) { | |
| 359 | + int length = cardNo.length(); | |
| 360 | + String result = cardNo.substring(length - 2, length) + cardNo.substring(length - 4, length - 2) + cardNo.substring(length - 6, length - 4) | |
| 361 | + + cardNo.substring(length - 8, length - 6); | |
| 362 | + return result; | |
| 363 | + } else { | |
| 364 | + System.out.println("卡号位数不对:" + cardNo); | |
| 365 | + return ""; | |
| 366 | + } | |
| 367 | + } | |
| 327 | 368 | } | ... | ... |
cloud/dahua/src/main/java/com/example/dahua/utils/ExcelUtil2.java
0 → 100644
| ... | ... | @@ -0,0 +1,94 @@ |
| 1 | +package com.example.dahua.utils; | |
| 2 | + | |
| 3 | +import cn.afterturn.easypoi.excel.ExcelExportUtil; | |
| 4 | +import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; | |
| 5 | +import org.apache.poi.ss.usermodel.Workbook; | |
| 6 | +import org.slf4j.Logger; | |
| 7 | +import org.slf4j.LoggerFactory; | |
| 8 | + | |
| 9 | +import javax.servlet.http.HttpServletRequest; | |
| 10 | +import javax.servlet.http.HttpServletResponse; | |
| 11 | +import java.io.IOException; | |
| 12 | +import java.io.UnsupportedEncodingException; | |
| 13 | +import java.net.URLEncoder; | |
| 14 | +import java.nio.charset.StandardCharsets; | |
| 15 | +import java.util.List; | |
| 16 | +import java.util.Map; | |
| 17 | + | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * Excel相关处理 | |
| 21 | + * | |
| 22 | + * @author liudhc | |
| 23 | + */ | |
| 24 | +public class ExcelUtil2<T> { | |
| 25 | + | |
| 26 | + private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class); | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 导出多个Sheet | |
| 30 | + * @param sheetsList | |
| 31 | + * @param sheetName | |
| 32 | + * @param request | |
| 33 | + * @param response | |
| 34 | + */ | |
| 35 | + public static void exportExcelByEasyPoi(List<Map<String, Object>> sheetsList,String sheetName, HttpServletRequest request, HttpServletResponse response) { | |
| 36 | + //功能描述:把同一个表格多个sheet测试结果重新输出, | |
| 37 | + Workbook workBook = null; | |
| 38 | + try { | |
| 39 | + // 执行方法 | |
| 40 | + workBook = ExcelExportUtil.exportExcel(sheetsList, ExcelType.HSSF); | |
| 41 | + //文件名 | |
| 42 | + String fileName = sheetName; | |
| 43 | + fileName = getFileName(request, fileName); | |
| 44 | + //设置编码格式 | |
| 45 | + response.setCharacterEncoding(StandardCharsets.UTF_8.name()); | |
| 46 | + //设置内容类型 | |
| 47 | + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); | |
| 48 | + //设置头及文件命名。 | |
| 49 | + response.setHeader("Content-Disposition","attachment;filename="+ fileName +".xlsx"); | |
| 50 | + //写出流 | |
| 51 | + workBook.write(response.getOutputStream()); | |
| 52 | + } catch (Exception e) { | |
| 53 | + e.printStackTrace(); | |
| 54 | + log.error("导出Excel异常{}", e.getMessage()); | |
| 55 | + } finally { | |
| 56 | + if (workBook != null) { | |
| 57 | + try { | |
| 58 | + //强行关流 | |
| 59 | + workBook.close(); | |
| 60 | + } catch (IOException e) { | |
| 61 | + e.printStackTrace(); | |
| 62 | + } | |
| 63 | + } | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + public static String getFileName(HttpServletRequest request, String fileName) throws UnsupportedEncodingException | |
| 68 | + { | |
| 69 | + final String agent = request.getHeader("USER-AGENT"); | |
| 70 | + String filename = fileName; | |
| 71 | + if (agent.contains("MSIE")) | |
| 72 | + { | |
| 73 | + // IE浏览器 | |
| 74 | + filename = URLEncoder.encode(filename, "utf-8"); | |
| 75 | + filename = filename.replace("+", " "); | |
| 76 | + } | |
| 77 | + else if (agent.contains("Firefox")) | |
| 78 | + { | |
| 79 | + // 火狐浏览器 | |
| 80 | + filename = new String(fileName.getBytes(), "ISO8859-1"); | |
| 81 | + } | |
| 82 | + else if (agent.contains("Chrome")) | |
| 83 | + { | |
| 84 | + // google浏览器 | |
| 85 | + filename = URLEncoder.encode(filename, "utf-8"); | |
| 86 | + } | |
| 87 | + else | |
| 88 | + { | |
| 89 | + // 其它浏览器 | |
| 90 | + filename = URLEncoder.encode(filename, "utf-8"); | |
| 91 | + } | |
| 92 | + return filename; | |
| 93 | + } | |
| 94 | +} | |
| 0 | 95 | \ No newline at end of file | ... | ... |
cloud/dahua/src/main/resources/logback-spring.xml
| ... | ... | @@ -9,7 +9,7 @@ |
| 9 | 9 | |
| 10 | 10 | <!--日志文件存储的基础路径: ${user.home} 为当前服务器用户主目录--> |
| 11 | 11 | <!--100--> |
| 12 | - <property name="LOG_PATH" value="E:\dahua\logs"/> | |
| 12 | + <property name="LOG_PATH" value="D:\dahua\logs"/> | |
| 13 | 13 | <!--137--> |
| 14 | 14 | <!--<property name="LOG_PATH" value="C:\workspace\dahua\logs"/>--> |
| 15 | 15 | ... | ... |
cloud/pom.xml
| ... | ... | @@ -31,7 +31,7 @@ |
| 31 | 31 | <module>common</module> |
| 32 | 32 | <module>dahua</module> |
| 33 | 33 | <module>haikangface</module> |
| 34 | -<!-- <module>quartz</module>--> | |
| 34 | + <module>quartz</module> | |
| 35 | 35 | <!-- <module>getaway</module>--> |
| 36 | 36 | <!-- <module>haikang</module>--> |
| 37 | 37 | <!-- <module>consumer</module>--> |
| ... | ... | @@ -54,10 +54,10 @@ |
| 54 | 54 | <version>1.2.58</version> |
| 55 | 55 | <scope>compile</scope> |
| 56 | 56 | </dependency> |
| 57 | - <dependency> | |
| 58 | - <groupId>org.springframework.cloud</groupId> | |
| 59 | - <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> | |
| 60 | - </dependency> | |
| 57 | +<!-- <dependency>--> | |
| 58 | +<!-- <groupId>org.springframework.cloud</groupId>--> | |
| 59 | +<!-- <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>--> | |
| 60 | +<!-- </dependency>--> | |
| 61 | 61 | <dependency> |
| 62 | 62 | <groupId>org.springframework.boot</groupId> |
| 63 | 63 | <artifactId>spring-boot-configuration-processor</artifactId> | ... | ... |