Procházet zdrojové kódy

Merge branch 'superb' of wuheng/eas-system into master

wuheng před 1 rokem
rodič
revize
2e5e451a83

+ 2 - 0
.gitignore

@@ -11,6 +11,8 @@ sys-debug*
 sys-info*
 sys-error*
 
+temp/*
+
 ### STS ###
 .apt_generated
 .classpath

+ 6 - 0
controller/src/main/java/com/koobietech/eas/controller/AdminLoginController.java

@@ -43,6 +43,12 @@ public class AdminLoginController {
         return JsonResult.data(result);
     }
 
+    @GetMapping("getUserInfo")
+    @Operation(summary = "获取用户信息", description = "根据token获取用户信息")
+    public JsonResult getUserInfo(@RequestHeader("Authorization") String token) {
+        return JsonResult.data(adminLoginService.getUserInfo(token));
+    }
+
     @PostMapping("/refreshToken")
     @Operation(summary = "刷新token", description = "当token过期,在请求头中携带refresh token,若刷新成功,返回新的token和refresh token")
     public JsonResult refreshToken(@RequestHeader("Authorization") String refreshToken) {

+ 27 - 0
controller/src/main/java/com/koobietech/eas/controller/EasStuProfileController.java

@@ -0,0 +1,27 @@
+package com.koobietech.eas.controller;
+
+
+import com.koobietech.eas.common.result.JsonResult;
+import com.koobietech.eas.mbg.model.EasArcTlsStudents;
+import com.koobietech.eas.service.EasStuProfileService;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.io.FileNotFoundException;
+
+@RestController
+public class EasStuProfileController {
+
+    @Resource
+    private EasStuProfileService easStuProfileService;
+
+    @RequestMapping("/StuProfileDownload")
+    public JsonResult StuProfileDownload(@RequestBody  EasArcTlsStudents easArcTlsStudents) throws FileNotFoundException {
+
+        return easStuProfileService.StuProfileDownload(easArcTlsStudents);
+    }
+
+
+}

binární
controller/src/main/resources/Temp/StuRegistTemp.docx


binární
controller/src/main/resources/Temp/kun1.jpeg


binární
controller/src/main/resources/Temp/~$uRegistTemp.docx


binární
controller/src/main/resources/temp/StuRegistTemp.docx


+ 5 - 4
controller/src/test/java/com/koobietech/eas/controller/ControllerApplicationTests.java

@@ -16,10 +16,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.test.context.SpringBootTest;
 
 import javax.annotation.Resource;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
+import java.io.*;
 import java.util.*;
 
 
@@ -28,6 +25,10 @@ class ControllerApplicationTests {
 
     @Test
     void contextLoads() throws IOException {
+
+        InputStream wordStream = this.getClass().getClassLoader().getResourceAsStream("\\temp\\StuRegistTemp.docx");
+        System.out.println( wordStream );
+
 //        List<Map> list = new ArrayList<>();
 //        Workbook workbook = null;
 //        ExportParams params = new ExportParams("大数据测试", "测试");

+ 6 - 0
mbg/src/main/java/com/koobietech/eas/mbg/model/EasArcTlsStudents.java

@@ -1,6 +1,9 @@
 package com.koobietech.eas.mbg.model;
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.v3.oas.annotations.media.Schema;
+import org.springframework.format.annotation.DateTimeFormat;
+
 import java.io.Serializable;
 import java.util.Date;
 
@@ -51,6 +54,7 @@ public class EasArcTlsStudents implements Serializable {
      * @mbg.generated
      */
     @Schema(description = "学生出生日期")
+    @JsonFormat(pattern = "yyyy-MM-dd")
     private Date birthdate;
 
     /**
@@ -83,6 +87,7 @@ public class EasArcTlsStudents implements Serializable {
      * @mbg.generated
      */
     @Schema(description = "学生入学进入培训班日期")
+    @JsonFormat(pattern = "yyyy-MM-dd")
     private Date enrollmentDate;
 
     /**
@@ -91,6 +96,7 @@ public class EasArcTlsStudents implements Serializable {
      * @mbg.generated
      */
     @Schema(description = "学生在培训班毕业日期")
+    @JsonFormat(pattern = "yyyy-MM-dd")
     private Date graduationDate;
 
     /**

+ 4 - 0
service/pom.xml

@@ -8,6 +8,10 @@
     <description>service</description>
 
     <dependencies>
+        <dependency>
+            <groupId>cn.afterturn</groupId>
+            <artifactId>easypoi-spring-boot-starter</artifactId>
+        </dependency>
         <dependency>
             <groupId>com.github.pagehelper</groupId>
             <artifactId>pagehelper-spring-boot-starter</artifactId>

+ 1 - 0
service/src/main/java/com/koobietech/eas/service/AdminLoginService.java

@@ -15,4 +15,5 @@ public interface AdminLoginService {
     JsonResult verifyToJsonResult(ResponseModel responseModel);
 
 
+    UserDetail getUserInfo(String token);
 }

+ 10 - 0
service/src/main/java/com/koobietech/eas/service/EasStuProfileService.java

@@ -0,0 +1,10 @@
+package com.koobietech.eas.service;
+
+import com.koobietech.eas.common.result.JsonResult;
+import com.koobietech.eas.mbg.model.EasArcTlsStudents;
+
+import java.io.FileNotFoundException;
+
+public interface EasStuProfileService {
+    JsonResult StuProfileDownload(EasArcTlsStudents easArcTlsStudents) throws FileNotFoundException;
+}

+ 17 - 2
service/src/main/java/com/koobietech/eas/service/impl/AdminLoginServiceImpl.java

@@ -41,8 +41,8 @@ public class AdminLoginServiceImpl implements AdminLoginService {
     private JwtManager jwtManager;
 
     // token过期时间 单位:s
-    private final Integer token_expires = 30;
-    private final Integer refreshToken_expires = 60;
+    private final Integer token_expires = 60*3;
+    private final Integer refreshToken_expires = 60*7;
 
     @Override
     public LoginToken adminLogin(AdminPojo adminPojo) {
@@ -73,6 +73,8 @@ public class AdminLoginServiceImpl implements AdminLoginService {
             JwtUserDto jwtUserDto = new JwtUserDto(userDetailInRedis.getUsername(), userDetailInRedis.getId(), userType);
             String token = jwtManager.createJwt(jwtUserDto, token_expires);
             String refreshToken = jwtManager.createJwt(jwtUserDto, refreshToken_expires);
+            System.out.println("token:" + token);
+            System.out.println("refreshToken:" + refreshToken);
 
             // 生成redis key
             String redisTokenKey = loginRedisService.createJwtTokenKey(jwtUserDto);
@@ -130,6 +132,19 @@ public class AdminLoginServiceImpl implements AdminLoginService {
         return result;
     }
 
+    @Override
+    public UserDetail getUserInfo(String token) {
+
+        try {
+            // 解析token
+            JwtUserDto jwtUserDto = jwtManager.decodeJwt(token);
+            // 封装成字符以便在redis中查找
+            String tokenToRedisKey = loginRedisService.createJwtTokenKey(jwtUserDto);
+            return loginRedisService.loginGetCache(tokenToRedisKey);
+        } catch (Exception e) {
+            // 处理异常情况
+            throw new EasException("Token获取用户信息失败", e);
+        }}
 
 
     private EasSysUserinfo findAdminByUsername(String username, String password)  {

+ 105 - 0
service/src/main/java/com/koobietech/eas/service/impl/EasStuProfileServiceImpl.java

@@ -0,0 +1,105 @@
+package com.koobietech.eas.service.impl;
+
+import com.koobietech.eas.common.result.JsonResult;
+import com.koobietech.eas.mbg.model.EasArcTlsStudents;
+import com.koobietech.eas.service.EasStuProfileService;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFTable;
+import org.apache.poi.xwpf.usermodel.XWPFTableCell;
+import org.apache.poi.xwpf.usermodel.XWPFTableRow;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import java.io.*;
+import java.util.*;
+
+@Service
+public class EasStuProfileServiceImpl implements EasStuProfileService {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(EasStuProfileServiceImpl.class);
+    private static final String TEMPLATE_PATH = "temp/StuRegistTemp.docx";
+    private static final String PHOTO_PATH = "temp/kun1.jpeg";
+    private static final String OUTPUT_PATH = "D:\\myDesk\\test.docx";
+
+    @Override
+    public JsonResult StuProfileDownload(EasArcTlsStudents easArcTlsStudents) {
+        LOGGER.info("开始学员档案导出:{}", easArcTlsStudents);
+
+        try (InputStream wordStream = getClass().getClassLoader().getResourceAsStream(TEMPLATE_PATH)) {
+            assert wordStream != null;
+            XWPFDocument doc = new XWPFDocument(wordStream);
+
+            Map<String, Object> map = new HashMap<>();
+            map.put("student_name", easArcTlsStudents.getStudentName());
+            map.put("gender", easArcTlsStudents.getGender());
+            map.put("major", easArcTlsStudents.getMajor());
+            map.put("grade", easArcTlsStudents.getGrade());
+            map.put("enrollment_date", easArcTlsStudents.getEnrollmentDate());
+            map.put("phone", easArcTlsStudents.getPhone());
+            map.put("university", easArcTlsStudents.getUniversity());
+
+            InputStream photo = getClass().getClassLoader().getResourceAsStream(PHOTO_PATH);
+            map.put("avatar", photo);
+
+            replacePlaceholders(doc, map);
+
+            saveDocument(doc);
+        } catch (IOException e) {
+            LOGGER.error("学员档案导出失败:{}", e.getMessage(), e);
+            return JsonResult.fail("学员档案导出失败!");
+        }
+
+        LOGGER.info("学员档案导出成功!");
+        return JsonResult.ok("学员档案导出成功!");
+    }
+
+    private void replacePlaceholders(XWPFDocument document, Map<String, Object> map) {
+        Iterator<XWPFTable> it = document.getTablesIterator();
+
+        while (it.hasNext()) {
+            XWPFTable table = it.next();
+            int rcount = table.getNumberOfRows();
+            for (int n = 0; n < rcount; n++) {
+                XWPFTableRow wrow = table.getRow(n);
+                List<XWPFTableCell> cells = wrow.getTableCells();
+                for (XWPFTableCell cell : cells) {
+                    String cellText = cell.getText();
+                    if (!cellText.contains("${")) {
+                        continue;
+                    }
+                    map.forEach((key, value) -> {
+                        String placeholder = "${" + key + "}";
+                        if (cellText.contains(placeholder) && Objects.nonNull(value)) {
+                            try {
+                                cell.removeParagraph(0);
+                                if (value instanceof InputStream) {
+                                    //如果是放置图片的单元格,在这里添加一个计算图片合适大小的方法,按比例
+
+
+
+
+                                    // 计算合适的宽度和高度
+                                    cell.addParagraph().createRun().addPicture((InputStream) value, XWPFDocument.PICTURE_TYPE_JPEG, "avatar.jpg", 400000, 400000);
+                                } else {
+                                    cell.setText(cellText.replace(placeholder, value.toString()));
+                                }
+                            } catch (IOException | InvalidFormatException e) {
+                                throw new RuntimeException(e);
+                            }
+                        }
+                    });
+                }
+            }
+        }
+    }
+
+    private void saveDocument(XWPFDocument document) throws IOException {
+        try (FileOutputStream outputStream = new FileOutputStream(OUTPUT_PATH)) {
+            document.write(outputStream);
+        }
+    }
+
+
+}