Browse Source

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

wuheng 1 năm trước cách đây
mục cha
commit
24688e8925

+ 15 - 0
controller/pom.xml

@@ -77,6 +77,21 @@
     </dependencyManagement>
 
     <build>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>true</filtering>
+                <includes>
+                    <include>**/*.png</include>
+                    <include>**/*.jpeg</include>
+                    <include>**/*.xml</include>
+                    <include>**/*.docx</include>
+                    <include>**/*.xlsx</include>
+                    <include>**/*.yaml</include>
+                    <include>**/*.properties</include>
+                </includes>
+            </resource>
+        </resources>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>

+ 2 - 1
controller/src/main/java/com/koobietech/eas/controller/EasStuProfileController.java

@@ -4,6 +4,7 @@ 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.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -17,7 +18,7 @@ public class EasStuProfileController {
     @Resource
     private EasStuProfileService easStuProfileService;
 
-    @RequestMapping("/StuProfileDownload")
+    @PostMapping("/StuProfileDownload")
     public JsonResult StuProfileDownload(@RequestBody  EasArcTlsStudents easArcTlsStudents) throws FileNotFoundException {
 
         return easStuProfileService.StuProfileDownload(easArcTlsStudents);

BIN
controller/src/main/resources/Temp/StuRegistTemp.docx


BIN
controller/src/main/resources/Temp/kun1.jpeg


BIN
controller/src/main/resources/Temp/~$uRegistTemp.docx


+ 30 - 0
controller/src/main/resources/application-wheng.yaml

@@ -0,0 +1,30 @@
+server:
+  port: 8080
+spring:
+  datasource:
+    url: jdbc:mysql://127.0.0.1:13306/eas?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=true&tinyInt1isBit=false
+    username: root
+    password: 0JZBdtlYoiOepddh
+    driver-class-name: com.mysql.cj.jdbc.Driver
+  redis:
+    host: localhost
+    database: 8
+    password:
+    port: 26379
+  security:
+    user:
+      name: admin
+      password: 123456
+springdoc:
+  version: v0.0.1
+  api-docs:
+    enabled: true
+  swagger-ui:
+    enabled: true
+knife4j:
+  enable: true
+  setting:
+    language: zh_cn
+logging:
+  level:
+    com.koobietech.eas.*: TRACE

+ 2 - 2
controller/src/main/resources/application.yaml

@@ -2,7 +2,7 @@ server:
   port: 8081
 spring:
   profiles:
-    active: local
+    active: wheng
   main:
     allow-circular-references: true
   servlet:
@@ -32,7 +32,7 @@ security:
       - /**
 eas:
   jwt-secret-key: 123456
-  jwt-expires-date: 1
+  jwt-expires-date: 2
   password-sign-key: eas-key-password
 aj:
   captcha:

+ 1 - 1
controller/src/main/resources/logback.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <configuration>
-    <property name="log.path" value="./" />
+    <property name="log.path" value="./logs" />
     <property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
     <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
         <encoder>

BIN
controller/src/main/resources/temp/kun.jpeg


+ 16 - 6
security/src/main/java/com/koobietech/eas/security/filter/EasSecurityFilter.java

@@ -6,6 +6,8 @@ import com.koobietech.eas.common.utils.JwtManager;
 import com.koobietech.eas.dao.adminLoginPojo.Permission;
 import com.koobietech.eas.dao.adminLoginPojo.UserDetail;
 import com.koobietech.eas.service.LoginRedisService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.authority.SimpleGrantedAuthority;
 import org.springframework.security.core.context.SecurityContext;
@@ -27,6 +29,8 @@ import javax.servlet.http.HttpServletResponse;
 @Component
 public class EasSecurityFilter extends OncePerRequestFilter {
 
+    private static final Logger logger = LoggerFactory.getLogger(EasSecurityFilter.class);
+
     @Resource
     private LoginRedisService loginRedisService;
 
@@ -45,16 +49,22 @@ public class EasSecurityFilter extends OncePerRequestFilter {
             try {
                 //过滤器 允许 Token 不正确, 后面Security 会拦截处理
                 jwtUserDto = jwtManager.decodeJwt(token);
-            } catch ( EasException e) {}
+            } catch ( EasException e) {
+                logger.debug(e.getMessage());
+            }
             if ( Objects.nonNull(jwtUserDto) ) {
                 //判断token是否有效
-                UserDetail userDetail = loginRedisService.checkToken(jwtUserDto);
-
-                // 获取当前的 SecurityContext 对象,用于保存当前用户的安全上下文信息
-                SecurityContext context = SecurityContextHolder.getContext();
+                UserDetail userDetail = null;
+                try {
+                    userDetail = loginRedisService.checkToken(jwtUserDto);
+                } catch ( EasException e) {
+                    logger.debug(e.getMessage());
+                }
 
+                // 如果获取到了有效的用户对象
                 if (Objects.nonNull(userDetail)) {
-                    // 如果获取到了有效的用户对象
+                    // 获取当前的 SecurityContext 对象,用于保存当前用户的安全上下文信息
+                    SecurityContext context = SecurityContextHolder.getContext();
 
                     // 获取用户的权限列表
                     List<Permission> permission = userDetail.getPermissions();

+ 19 - 0
security/src/main/java/com/koobietech/eas/security/utils/SecurityUtils.java

@@ -0,0 +1,19 @@
+package com.koobietech.eas.security.utils;
+import org.springframework.security.core.context.SecurityContextHolder;
+public class SecurityUtils {
+
+    public static String getLoginUserName(){
+        Object principal = getPrincipal();
+        return principal.toString().equals("anonymousUser") ? "" : principal.toString();
+    }
+
+    public static boolean isLogged(){
+        Object principal = getPrincipal();
+        return principal.toString().equals("anonymousUser");
+    }
+
+    private static Object getPrincipal(){
+        return SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+    }
+
+}

+ 2 - 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 = 60*3;
-    private final Integer refreshToken_expires = 60*7;
+    private final Integer token_expires = 24 * 60 * 60;
+    private final Integer refreshToken_expires = 48 * 60 * 60;
 
     @Override
     public LoginToken adminLogin(AdminPojo adminPojo) {

+ 7 - 8
service/src/main/java/com/koobietech/eas/service/impl/EasStuProfileServiceImpl.java

@@ -10,6 +10,7 @@ import org.apache.poi.xwpf.usermodel.XWPFTableCell;
 import org.apache.poi.xwpf.usermodel.XWPFTableRow;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.apache.poi.util.Units;
 import org.springframework.stereotype.Service;
 
 import java.io.*;
@@ -20,8 +21,8 @@ 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";
+    private static final String PHOTO_PATH = "temp/kun.jpeg";
+    private static final String OUTPUT_PATH = "C:\\Users\\lc\\Desktop\\test.docx";
 
     @Override
     public JsonResult StuProfileDownload(EasArcTlsStudents easArcTlsStudents) {
@@ -41,6 +42,7 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
             map.put("university", easArcTlsStudents.getUniversity());
 
             InputStream photo = getClass().getClassLoader().getResourceAsStream(PHOTO_PATH);
+            System.out.println( photo );
             map.put("avatar", photo);
 
             replacePlaceholders(doc, map);
@@ -76,12 +78,9 @@ public class EasStuProfileServiceImpl implements EasStuProfileService {
                                 cell.removeParagraph(0);
                                 if (value instanceof InputStream) {
                                     //如果是放置图片的单元格,在这里添加一个计算图片合适大小的方法,按比例
-
-
-
-
-                                    // 计算合适的宽度和高度
-                                    cell.addParagraph().createRun().addPicture((InputStream) value, XWPFDocument.PICTURE_TYPE_JPEG, "avatar.jpg", 400000, 400000);
+                                    cell.addParagraph().createRun().addPicture((InputStream) value,
+                                            XWPFDocument.PICTURE_TYPE_JPEG, "avatar.jpg",
+                                            Units.pixelToEMU(110), Units.pixelToEMU(140));
                                 } else {
                                     cell.setText(cellText.replace(placeholder, value.toString()));
                                 }