Browse Source

Merge branch 'dev_v2.1.0' of http://git.qmth.com.cn/wangliang/distributed-print-service into dev_v2.1.0

xiaof 4 years ago
parent
commit
ca57293109

+ 3 - 3
teachcloud-common/src/main/java/com/qmth/teachcloud/common/SignatureEntityTest.java

@@ -13,9 +13,9 @@ public class SignatureEntityTest {
 
 
     private static final String PATTERN = "{0} {1}{2}{3}";
     private static final String PATTERN = "{0} {1}{2}{3}";
 
 
-    private static final String FIELD_JOINER = ":";
+    public static final String FIELD_JOINER = ":";
 
 
-    private static final String PARAM_JOINER = "&";
+    public static final String PARAM_JOINER = "&";
 
 
     private static Map<String, SignatureType> typeMap = new HashMap<>();
     private static Map<String, SignatureType> typeMap = new HashMap<>();
 
 
@@ -98,7 +98,7 @@ public class SignatureEntityTest {
         this.secret = secret;
         this.secret = secret;
     }
     }
 
 
-    private static String encrypt(String... values) {
+    public static String encrypt(String... values) {
         return Base64Util.encode(ShaUtils.sha1(StringUtils.join(values, PARAM_JOINER)));
         return Base64Util.encode(ShaUtils.sha1(StringUtils.join(values, PARAM_JOINER)));
     }
     }
 
 

+ 46 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/bean/dto/UserAuthenticationDto.java

@@ -0,0 +1,46 @@
+package com.qmth.teachcloud.common.bean.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * @Description: 临时授权码
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/6/29
+ */
+public class UserAuthenticationDto implements Serializable {
+
+    @ApiModelProperty("uid")
+    private String uid;
+
+    @ApiModelProperty("临时授权码")
+    private String code;
+
+    public UserAuthenticationDto() {
+
+    }
+
+    public UserAuthenticationDto(String uid, String code) {
+        this.uid = uid;
+        this.code = code;
+    }
+
+    public String getUid() {
+        return uid;
+    }
+
+    public void setUid(String uid) {
+        this.uid = uid;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+}

+ 1 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java

@@ -114,6 +114,7 @@ public class SystemConstant {
     public static final int DEFAULT_SESSION_EXPIRE = 1;//过期时间1天
     public static final int DEFAULT_SESSION_EXPIRE = 1;//过期时间1天
     public static final long REDIS_DEFAULT_EXPIRE_TIME = 24 * 60L * 60L;//过期时间24小时
     public static final long REDIS_DEFAULT_EXPIRE_TIME = 24 * 60L * 60L;//过期时间24小时
     public static final long REDIS_CREATE_PDF_EXPIRE_TIME = 1 * 60L * 60L;//过期时间1小时
     public static final long REDIS_CREATE_PDF_EXPIRE_TIME = 1 * 60L * 60L;//过期时间1小时
+    public static final long REDIS_WHU_USER_AUTH_EXPIRE_TIME = 2 * 60L;//过期时间2分钟
 
 
     /**
     /**
      * redis lock
      * redis lock

+ 10 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/domain/SysDomain.java

@@ -45,6 +45,16 @@ public class SysDomain implements Serializable {
 
 
     Duration sessionActive;
     Duration sessionActive;
 
 
+    String loginAuthenUrl;
+
+    public String getLoginAuthenUrl() {
+        return loginAuthenUrl;
+    }
+
+    public void setLoginAuthenUrl(String loginAuthenUrl) {
+        this.loginAuthenUrl = loginAuthenUrl;
+    }
+
     public Duration getSessionActive() {
     public Duration getSessionActive() {
         return sessionActive;
         return sessionActive;
     }
     }

+ 17 - 0
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/cache/RedisKeyHelper.java

@@ -0,0 +1,17 @@
+package com.qmth.teachcloud.report.business.cache;
+
+/**
+ * @Description: redis cache helper
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/4/26
+ */
+public class RedisKeyHelper {
+
+    private static String whuUserAuthFix = "whu_user_auth:";
+
+    public static String whuUserAuth(String key) {
+        return whuUserAuthFix + key;
+    }
+}

+ 31 - 0
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/cache/WhuUserAuthCacheUtil.java

@@ -0,0 +1,31 @@
+package com.qmth.teachcloud.report.business.cache;
+
+import com.qmth.teachcloud.common.bean.dto.UserAuthenticationDto;
+import com.qmth.teachcloud.common.contant.SpringContextHolder;
+import com.qmth.teachcloud.common.contant.SystemConstant;
+import com.qmth.teachcloud.common.util.RedisUtil;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @Description: 武大开发鉴权用户临时授权cache
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/6/29
+ */
+public class WhuUserAuthCacheUtil {
+    private static RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
+
+    public static void setAuthCode(UserAuthenticationDto userAuthenticationDto) {
+        redisUtil.set(RedisKeyHelper.whuUserAuth(userAuthenticationDto.getUid()), userAuthenticationDto.getCode(), SystemConstant.REDIS_WHU_USER_AUTH_EXPIRE_TIME, TimeUnit.SECONDS);
+    }
+
+    public static String getAuthCode(String key) {
+        return (String) redisUtil.get(RedisKeyHelper.whuUserAuth(key));
+    }
+
+    public static void deleteAuthCode(String key) {
+        redisUtil.delete(RedisKeyHelper.whuUserAuth(key));
+    }
+}

+ 2 - 2
teachcloud-report-business/src/main/java/com/qmth/teachcloud/report/business/enums/SemesterEnum.java

@@ -11,9 +11,9 @@ import java.util.Objects;
  */
  */
 public enum SemesterEnum {
 public enum SemesterEnum {
 
 
-    FIRST("第一学期"),
+    FIRST("2020-2021学年度第1学期"),
 
 
-    SECOND("第二学期");
+    SECOND("2020-2021学年度第2学期");
 
 
     private String title;
     private String title;
 
 

+ 1 - 0
teachcloud-report-business/src/main/resources/mapper/TBExamStudentMapper.xml

@@ -175,6 +175,7 @@
         sys_user h ON a.teacher_id = h.id
         sys_user h ON a.teacher_id = h.id
         <where>
         <where>
             and d.school_id = #{schoolId}
             and d.school_id = #{schoolId}
+            and a.absent = false
             <if test="semester != null and semester != ''">
             <if test="semester != null and semester != ''">
                 and d.semester = #{semester}
                 and d.semester = #{semester}
             </if>
             </if>

+ 78 - 13
teachcloud-report/src/main/java/com/qmth/teachcloud/report/api/WudaOpenApiController.java

@@ -1,33 +1,42 @@
 package com.qmth.teachcloud.report.api;
 package com.qmth.teachcloud.report.api;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.teachcloud.common.SignatureEntityTest;
+import com.qmth.teachcloud.common.bean.dto.UserAuthenticationDto;
+import com.qmth.teachcloud.common.bean.result.LoginResult;
 import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicSchool;
 import com.qmth.teachcloud.common.entity.BasicSchool;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
+import com.qmth.teachcloud.common.enums.RoleTypeEnum;
 import com.qmth.teachcloud.common.service.CacheService;
 import com.qmth.teachcloud.common.service.CacheService;
-import com.qmth.teachcloud.common.util.JacksonUtil;
-import com.qmth.teachcloud.common.util.Result;
-import com.qmth.teachcloud.common.util.ServletUtil;
+import com.qmth.teachcloud.common.service.SysUserService;
+import com.qmth.teachcloud.common.service.TeachcloudCommonService;
+import com.qmth.teachcloud.common.util.*;
 import com.qmth.teachcloud.report.aspect.ApiControllerAspect;
 import com.qmth.teachcloud.report.aspect.ApiControllerAspect;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiResponse;
-import io.swagger.annotations.ApiResponses;
+import com.qmth.teachcloud.report.business.cache.WhuUserAuthCacheUtil;
+import io.swagger.annotations.*;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.*;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
+import javax.validation.Valid;
 import java.io.IOException;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.security.NoSuchAlgorithmException;
+import java.text.MessageFormat;
+import java.util.List;
 import java.util.Objects;
 import java.util.Objects;
 
 
 @Api(tags = "武大开放接口层apiController")
 @Api(tags = "武大开放接口层apiController")
@@ -42,6 +51,12 @@ public class WudaOpenApiController {
     @Resource
     @Resource
     CacheService cacheService;
     CacheService cacheService;
 
 
+    @Resource
+    SysUserService sysUserService;
+
+    @Resource
+    TeachcloudCommonService teachcloudCommonService;
+
     @ApiOperation(value = "cas鉴权接口")
     @ApiOperation(value = "cas鉴权接口")
     @RequestMapping(value = "/authentication", method = RequestMethod.GET)
     @RequestMapping(value = "/authentication", method = RequestMethod.GET)
     @ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
     @ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
@@ -67,9 +82,59 @@ public class WudaOpenApiController {
         if (Objects.isNull(uid)) {
         if (Objects.isNull(uid)) {
             throw ExceptionResultEnum.NOT_LOGIN.exception();
             throw ExceptionResultEnum.NOT_LOGIN.exception();
         }
         }
-        BasicSchool basicSchool = cacheService.schoolCache(SystemConstant.SCHOOL_CODE);
+        UserAuthenticationDto userAuthenticationDto = new UserAuthenticationDto(uid, SystemConstant.getUuid());
+        WhuUserAuthCacheUtil.setAuthCode(userAuthenticationDto);
+        String pattern = "{0}{1}{2}";
+        String code = URLEncoder.encode(MessageFormat.format(pattern, userAuthenticationDto.getUid(), SignatureEntityTest.FIELD_JOINER, SignatureEntityTest.encrypt(userAuthenticationDto.getCode())), SystemConstant.CHARSET_NAME);
+        log.info("code:{}", code);
         response.setHeader("Access-Control-Allow-Origin", "*");
         response.setHeader("Access-Control-Allow-Origin", "*");
-        response.sendRedirect(dictionaryConfig.sysDomain().getReportUrl() + basicSchool.getId() + "/" + uid);
+        response.sendRedirect(dictionaryConfig.sysDomain().getLoginAuthenUrl() + "/" + code);
+    }
+
+    @ApiOperation(value = "cas用户鉴权测试接口")
+    @RequestMapping(value = "/user/authentication/test", method = RequestMethod.GET)
+    @ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = Result.class)})
+    @Aac(auth = BOOL.FALSE)
+    public void userAuthenticationTest(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        String uid = "yz1";
+        UserAuthenticationDto userAuthenticationDto = new UserAuthenticationDto(uid, SystemConstant.getUuid());
+        WhuUserAuthCacheUtil.setAuthCode(userAuthenticationDto);
+        String pattern = "{0}{1}{2}";
+        String code = URLEncoder.encode(MessageFormat.format(pattern, userAuthenticationDto.getUid(), SignatureEntityTest.FIELD_JOINER, SignatureEntityTest.encrypt(userAuthenticationDto.getCode())), SystemConstant.CHARSET_NAME);
+        log.info("code:{}", code);
+        response.setHeader("Access-Control-Allow-Origin", "*");
+        response.sendRedirect(dictionaryConfig.sysDomain().getLoginAuthenUrl() + code);
+    }
+
+    @ApiOperation(value = "cas用户临时授权登录接口")
+    @RequestMapping(value = "/user/authentication/login", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "返回消息", response = LoginResult.class)})
+    @Aac(auth = BOOL.FALSE)
+    public Result login(@ApiParam(value = "授权码信息", required = true) @RequestParam String code) throws NoSuchAlgorithmException, UnsupportedEncodingException {
+        String[] values = StringUtils.split(URLDecoder.decode(code, SystemConstant.CHARSET_NAME), SignatureEntityTest.FIELD_JOINER);
+        if (Objects.isNull(values) || values.length != 2) {
+            throw ExceptionResultEnum.ERROR.exception("临时授权码出错,请重新获取");
+        }
+        log.info("values:{}", JacksonUtil.parseJson(values));
+        QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
+        wrapper.lambda().eq(SysUser::getLoginName, values[0]);
+        SysUser sysUser = sysUserService.getOne(wrapper);
+        //用户不存在
+        if (Objects.isNull(sysUser)) {
+            throw ExceptionResultEnum.USER_NO_DATA.exception();
+        }
+        //停用
+        if (!sysUser.getEnable()) {
+            throw ExceptionResultEnum.USER_ENABLE.exception();
+        }
+
+        String userAuthCode = WhuUserAuthCacheUtil.getAuthCode(values[0]);
+        if (Objects.isNull(userAuthCode) || !Objects.equals(values[1], SignatureEntityTest.encrypt(userAuthCode))) {
+            throw ExceptionResultEnum.ERROR.exception("临时授权码已过期");
+        }
+        LoginResult loginResult = teachcloudCommonService.login(sysUser.getPassword(), sysUser);
+        WhuUserAuthCacheUtil.deleteAuthCode(values[0]);
+        return ResultUtil.ok(loginResult);
     }
     }
 
 
 //    @ApiOperation(value = "cas鉴权接口")
 //    @ApiOperation(value = "cas鉴权接口")

+ 2 - 1
teachcloud-report/src/main/resources/application-dev.properties

@@ -13,7 +13,7 @@ spring.application.name=teachcloud-report
 db.host=192.168.10.136
 db.host=192.168.10.136
 #db.host=localhost
 #db.host=localhost
 db.port=3306
 db.port=3306
-db.name=teachcloud-report-617
+db.name=teachcloud-report
 db.username=root
 db.username=root
 db.password=Qmth87863577!
 db.password=Qmth87863577!
 #db.password=123456789
 #db.password=123456789
@@ -60,6 +60,7 @@ sys.config.threadPoolCoreSize=1
 sys.config.customThreadPoolCoreSize=false
 sys.config.customThreadPoolCoreSize=false
 sys.config.sessionActive=1h
 sys.config.sessionActive=1h
 sys.config.reportUrl=http://localhost:9099/#/student-report/
 sys.config.reportUrl=http://localhost:9099/#/student-report/
+sys.config.loginAuthenUrl=http://localhost:9099/#/login-authen/
 spring.resources.static-locations=file:${sys.config.serverUpload},classpath:/META-INF/resources/,classpath:/resources/
 spring.resources.static-locations=file:${sys.config.serverUpload},classpath:/META-INF/resources/,classpath:/resources/
 
 
 org.center.url=https://solar.qmth.com.cn
 org.center.url=https://solar.qmth.com.cn

+ 1 - 0
teachcloud-report/src/main/resources/application-release.properties

@@ -58,6 +58,7 @@ sys.config.threadPoolCoreSize=1
 sys.config.customThreadPoolCoreSize=false
 sys.config.customThreadPoolCoreSize=false
 sys.config.sessionActive=1h
 sys.config.sessionActive=1h
 sys.config.reportUrl=https://wdfx.qmth.com.cn/#/student-report/
 sys.config.reportUrl=https://wdfx.qmth.com.cn/#/student-report/
+sys.config.loginAuthenUrl=https://wdfx.qmth.com.cn/#/login-authen/
 spring.resources.static-locations=file:${sys.config.serverUpload},classpath:/META-INF/resources/,classpath:/resources/
 spring.resources.static-locations=file:${sys.config.serverUpload},classpath:/META-INF/resources/,classpath:/resources/
 
 
 org.center.url=https://solar.qmth.com.cn
 org.center.url=https://solar.qmth.com.cn

+ 1 - 0
teachcloud-report/src/main/resources/application-test.properties

@@ -58,6 +58,7 @@ sys.config.threadPoolCoreSize=1
 sys.config.customThreadPoolCoreSize=false
 sys.config.customThreadPoolCoreSize=false
 sys.config.sessionActive=1h
 sys.config.sessionActive=1h
 sys.config.reportUrl=http://192.168.10.136:7005/#/student-report/
 sys.config.reportUrl=http://192.168.10.136:7005/#/student-report/
+sys.config.loginAuthenUrl=http://192.168.10.136:7005/#/login-authen/
 spring.resources.static-locations=file:${sys.config.serverUpload},classpath:/META-INF/resources/,classpath:/resources/
 spring.resources.static-locations=file:${sys.config.serverUpload},classpath:/META-INF/resources/,classpath:/resources/
 
 
 org.center.url=https://solar.qmth.com.cn
 org.center.url=https://solar.qmth.com.cn