caozixuan пре 2 година
родитељ
комит
eec447dd6e

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/SsoService.java

@@ -40,5 +40,5 @@ public interface SsoService {
      * @return
      * @throws IOException
      */
-    Map<String, Object> questionLibraryLogin(String loginName, RoleTypeEnum role, String returnUrl, String params) throws IOException;
+    Map<String, Object> questionLibraryLogin(String loginName,String realName, RoleTypeEnum role, String returnUrl, String params) throws IOException;
 }

+ 33 - 27
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/SsoServiceImpl.java

@@ -1,5 +1,6 @@
 package com.qmth.distributed.print.business.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qmth.boot.tools.signature.SignatureEntity;
 import com.qmth.boot.tools.signature.SignatureType;
@@ -16,6 +17,7 @@ import com.qmth.teachcloud.common.service.*;
 import com.qmth.teachcloud.common.sync.CloudMarkingTaskUtils;
 import com.qmth.teachcloud.common.util.JacksonUtil;
 import com.qmth.teachcloud.common.util.ServletUtil;
+import org.apache.commons.text.StringEscapeUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -25,6 +27,7 @@ import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.io.IOException;
+import java.net.URLEncoder;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -50,8 +53,11 @@ public class SsoServiceImpl implements SsoService {
     @Resource
     SysOrgService sysOrgService;
 
-    @Value("${cas.config.questionLoginUrl}")
-    String questionLoginUrl;
+    @Value("${cas.config.questionLoginUri}")
+    String questionLoginUri;
+
+    @Value("${cas.config.questionHostUrl}")
+    String questionHostUrl;
 
     @Resource
     SysRoleService sysRoleService;
@@ -125,21 +131,25 @@ public class SsoServiceImpl implements SsoService {
         Optional.ofNullable(sysUserRole).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("用户没有该角色"));
 
         if (role == RoleTypeEnum.PRESIDENT || role == RoleTypeEnum.TEACHER) {
-            List<SysOrg> sysOrgList = sysOrgService.findByConnectByParentId(sysUserCas.getOrgId(), false, true);
-            if (CollectionUtils.isEmpty(sysOrgList)) {
-                throw ExceptionResultEnum.ERROR.exception("未找到学院信息");
-            } else {
-                List<SysOrg> sysOrgSchool = sysOrgList.stream().filter(s -> s.getType() == OrgTypeEnum.SCHOOL).collect(Collectors.toList());
-                if (!CollectionUtils.isEmpty(sysOrgSchool)) {
-                    for (SysOrg s : sysOrgList) {
-                        if (Objects.nonNull(s.getParentId()) && s.getParentId().longValue() == sysOrgSchool.get(0).getId().longValue()) {
-                            orgName = s.getName();
-                            break;
-                        }
-                    }
-                } else {
-                    throw ExceptionResultEnum.ERROR.exception("未找到顶级学校信息");
-                }
+//            List<SysOrg> sysOrgList = sysOrgService.findByConnectByParentId(sysUserCas.getOrgId(), false, true);
+            SysOrg sysOrg = sysOrgService.findCollegeLevelOrgByOrgId(sysUserCas.getOrgId());
+//            if (CollectionUtils.isEmpty(sysOrgList)) {
+//                throw ExceptionResultEnum.ERROR.exception("未找到学院信息");
+//            } else {
+//                List<SysOrg> sysOrgSchool = sysOrgList.stream().filter(s -> s.getType() == OrgTypeEnum.SCHOOL).collect(Collectors.toList());
+//                if (!CollectionUtils.isEmpty(sysOrgSchool)) {
+//                    for (SysOrg s : sysOrgList) {
+//                        if (Objects.nonNull(s.getParentId()) && s.getParentId().longValue() == sysOrgSchool.get(0).getId().longValue()) {
+//                            orgName = s.getName();
+//                            break;
+//                        }
+//                    }
+//                } else {
+//                    throw ExceptionResultEnum.ERROR.exception("未找到顶级学校信息");
+//                }
+//            }
+            if (Objects.isNull(sysOrg)){
+                throw ExceptionResultEnum.ERROR.exception("未找到顶级机构");
             }
         } else if (role == RoleTypeEnum.OFFICE_TEACHER && Objects.nonNull(sysUserCas.getOrgId())) {
             SysOrg sysOrg = commonCacheService.orgCache(sysUserCas.getOrgId());
@@ -170,6 +180,7 @@ public class SsoServiceImpl implements SsoService {
 
         hostUrl = SystemConstant.getLocalFileHost(hostUrl);
         map.put("redirectUrl", hostUrl + dictionaryConfig.reportOpenDomain().getSsoLoginApi());
+        System.out.println(JSON.toJSONString(map));
         return map;
     }
 
@@ -184,7 +195,7 @@ public class SsoServiceImpl implements SsoService {
      * @throws IOException
      */
     @Override
-    public Map<String, Object> questionLibraryLogin(String loginName, RoleTypeEnum role, String returnUrl, String params) throws IOException {
+    public Map<String, Object> questionLibraryLogin(String loginName,String realName, RoleTypeEnum role, String returnUrl, String params) throws IOException {
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         BasicSchool basicSchool = commonCacheService.schoolCache(sysUser.getSchoolId());
 
@@ -205,16 +216,11 @@ public class SsoServiceImpl implements SsoService {
         SysUserRole sysUserRole = sysUserRoleService.getOne(sysUserRoleQueryWrapper);
         Optional.ofNullable(sysUserRole).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("用户没有该角色"));
 
-        //TODO 题库推送用户逻辑
-
-        //TODO 拼装redirectUrl
-        if (questionLoginUrl.contains(SystemConstant.PATH_MATCH)) {
-            questionLoginUrl = questionLoginUrl.replace(SystemConstant.PATH_MATCH, basicSchool.getCode());
-        }
-
         long timestamp = System.currentTimeMillis();
-        String path = questionLoginUrl.substring(questionLoginUrl.indexOf(SystemConstant.PATH_SUBSTR), questionLoginUrl.length());
+        String questionLoginUrl = questionHostUrl + questionLoginUri;
+        String path = questionLoginUri;
         String signature = SignatureEntity.build(SignatureType.SECRET, SystemConstant.GET, path, timestamp, basicSchool.getAccessKey(), basicSchool.getAccessSecret());
+        signature = URLEncoder.encode(signature,"utf-8");
 
         StringJoiner stringJoiner = new StringJoiner("")
                 .add(questionLoginUrl)
@@ -232,8 +238,8 @@ public class SsoServiceImpl implements SsoService {
             stringJoiner = stringJoiner.add(SystemConstant.GET_SYMBOL).add(SystemConstant.PARAMS).add(SystemConstant.GET_EQUAL).add(JacksonUtil.parseJson(openParams));
             map.computeIfAbsent(SystemConstant.PARAMS, v -> JacksonUtil.parseJson(openParams));
         }
-
         map.computeIfAbsent("loginName", v -> loginName);
+        map.computeIfAbsent("realName", v -> realName);
         map.computeIfAbsent("role", v -> role);
         map.computeIfAbsent("returnUrl", v -> returnUrl);
         map.put("redirectUrl", stringJoiner.toString());

+ 1 - 1
distributed-print-business/src/main/resources/db/2、init-table-data.sql

@@ -712,7 +712,7 @@ INSERT INTO `sys_role` VALUES (4, NULL, NULL, '任课老师', 1, 'TEACHER', NULL
 INSERT INTO `sys_role` VALUES (5, NULL, NULL, '评卷员', 1, 'MARKER', NULL, NULL, NULL, NULL, 1, 'CLOUD_MARK', '系统内置');
 INSERT INTO `sys_role` VALUES (6, NULL, NULL, '科组长', 1, 'MARKER_LEADER', NULL, NULL, NULL, NULL, 1, 'CLOUD_MARK', '系统内置');
 INSERT INTO `sys_role` VALUES (7, NULL, NULL, '学科老师', 1, 'SUBJECT_TEACHER', NULL, NULL, NULL, NULL, 1, 'QUESTION_LIBRARY', '系统内置');
-INSERT INTO `sys_role` VALUES (8, NULL, NULL, '命题老师', 1, 'QUESTION_TEACHER', NULL, NULL, NULL, NULL, 1, 'QUESTION_LIBRARY', '系统内置');
+INSERT INTO `sys_role` VALUES (8, NULL, NULL, '命题老师', 1, 'ASSIGN_TEACHER', NULL, NULL, NULL, NULL, 1, 'QUESTION_LIBRARY', '系统内置');
 
 INSERT INTO `sys_role_privilege` VALUES (1, 1, 1, 1);
 INSERT INTO `sys_role_privilege` VALUES (2, 1, 2, 1);

+ 8 - 2
distributed-print/src/main/java/com/qmth/distributed/print/api/SsoController.java

@@ -1,8 +1,10 @@
 package com.qmth.distributed.print.api;
 
 
+import com.alibaba.fastjson.JSON;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.distributed.print.business.service.SsoService;
+import com.qmth.teachcloud.common.bean.params.OpenParams;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.RoleTypeEnum;
 import com.qmth.teachcloud.common.util.Result;
@@ -61,6 +63,7 @@ public class SsoController {
     @ApiResponses({@ApiResponse(code = 200, message = "题库单点登录", response = Result.class)})
     @RequestMapping(value = "/question_library_login", method = RequestMethod.POST)
     public Result questionLibraryLogin(@ApiParam(value = "登录名", required = true) @RequestParam String loginName,
+                                       @ApiParam(value = "真实姓名", required = true) @RequestParam String realName,
                                        @ApiParam(value = "角色", required = true) @RequestParam RoleTypeEnum role,
                                        @ApiParam(value = "返回url") @RequestParam(required = false) String returnUrl,
                                        @ApiParam(value = "其它参数") @RequestParam(required = false) String params) throws IOException {
@@ -70,10 +73,13 @@ public class SsoController {
         if (Objects.isNull(role)) {
             throw ExceptionResultEnum.PARAMS_ERROR.exception("角色不能为空");
         }
-        if (role != RoleTypeEnum.SUBJECT_TEACHER && role != RoleTypeEnum.QUESTION_TEACHER) {
+        if (role != RoleTypeEnum.SUBJECT_TEACHER && role != RoleTypeEnum.ASSIGN_TEACHER) {
             throw ExceptionResultEnum.ERROR.exception("角色类型超出限制");
         }
-        return ResultUtil.ok(ssoService.questionLibraryLogin(loginName, role, returnUrl, params));
+        OpenParams openParams = new OpenParams();
+        openParams.setName(realName);
+        openParams.setRoleName(role.name());
+        return ResultUtil.ok(ssoService.questionLibraryLogin(loginName,realName, role, returnUrl, JSON.toJSONString(openParams)));
     }
 
     @ApiOperation(value = "教研分析单点登录")

+ 1 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/enums/RoleTypeEnum.java

@@ -18,7 +18,7 @@ public enum RoleTypeEnum {
     MARKER("评卷员"),
     MARKER_LEADER("科组长"),
     SUBJECT_TEACHER("学科老师"),
-    QUESTION_TEACHER("命题老师");
+    ASSIGN_TEACHER("命题老师");
 
     RoleTypeEnum(String desc) {
         this.desc = desc;