|
@@ -1,25 +1,25 @@
|
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.qmth.boot.tools.signature.SignatureEntity;
|
|
|
import com.qmth.boot.tools.signature.SignatureType;
|
|
|
import com.qmth.distributed.print.business.service.SsoService;
|
|
|
+import com.qmth.teachcloud.common.bean.params.OpenParams;
|
|
|
import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
-import com.qmth.teachcloud.common.entity.BasicSchool;
|
|
|
-import com.qmth.teachcloud.common.entity.SysOrg;
|
|
|
-import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
+import com.qmth.teachcloud.common.entity.*;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.teachcloud.common.enums.OrgTypeEnum;
|
|
|
import com.qmth.teachcloud.common.enums.RoleTypeEnum;
|
|
|
import com.qmth.teachcloud.common.enums.userPush.SpecialPrivilegeEnum;
|
|
|
-import com.qmth.teachcloud.common.service.CommonCacheService;
|
|
|
-import com.qmth.teachcloud.common.service.SysOrgService;
|
|
|
-import com.qmth.teachcloud.common.service.SysUserService;
|
|
|
+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.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
@@ -50,6 +50,15 @@ public class SsoServiceImpl implements SsoService {
|
|
|
@Resource
|
|
|
SysOrgService sysOrgService;
|
|
|
|
|
|
+ @Value("${cas.config.questionLoginUrl}")
|
|
|
+ String questionLoginUrl;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ SysRoleService sysRoleService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ SysUserRoleService sysUserRoleService;
|
|
|
+
|
|
|
@Override
|
|
|
public Map<String, Object> markerLoginInfo() {
|
|
|
try {
|
|
@@ -97,8 +106,26 @@ public class SsoServiceImpl implements SsoService {
|
|
|
public Map<String, Object> analysisLogin(String loginName, RoleTypeEnum role, String orgName, String realName, String mobileNumber, Boolean enable, String returnUrl) throws IOException {
|
|
|
SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
BasicSchool basicSchool = commonCacheService.schoolCache(sysUser.getSchoolId());
|
|
|
+
|
|
|
+ QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
|
|
|
+ sysUserQueryWrapper.lambda().eq(SysUser::getLoginName, loginName)
|
|
|
+ .eq(SysUser::getSchoolId, basicSchool.getId());
|
|
|
+ SysUser sysUserCas = sysUserService.getOne(sysUserQueryWrapper);
|
|
|
+ Optional.ofNullable(sysUserCas).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("用户信息为空"));
|
|
|
+
|
|
|
+ QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
|
|
|
+ sysRoleQueryWrapper.lambda().eq(SysRole::getType, role);
|
|
|
+ SysRole sysRole = sysRoleService.getOne(sysRoleQueryWrapper);
|
|
|
+ Optional.ofNullable(sysRole).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("角色信息为空"));
|
|
|
+
|
|
|
+ QueryWrapper<SysUserRole> sysUserRoleQueryWrapper = new QueryWrapper<>();
|
|
|
+ sysUserRoleQueryWrapper.lambda().eq(SysUserRole::getUserId, sysUserCas.getId())
|
|
|
+ .eq(SysUserRole::getRoleId, sysRole.getId());
|
|
|
+ SysUserRole sysUserRole = sysUserRoleService.getOne(sysUserRoleQueryWrapper);
|
|
|
+ Optional.ofNullable(sysUserRole).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("用户没有该角色"));
|
|
|
+
|
|
|
if (role == RoleTypeEnum.PRESIDENT || role == RoleTypeEnum.TEACHER) {
|
|
|
- List<SysOrg> sysOrgList = sysOrgService.findByConnectByParentId(sysUser.getOrgId(), false, true);
|
|
|
+ List<SysOrg> sysOrgList = sysOrgService.findByConnectByParentId(sysUserCas.getOrgId(), false, true);
|
|
|
if (CollectionUtils.isEmpty(sysOrgList)) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("未找到学院信息");
|
|
|
} else {
|
|
@@ -114,8 +141,8 @@ public class SsoServiceImpl implements SsoService {
|
|
|
throw ExceptionResultEnum.ERROR.exception("未找到顶级学校信息");
|
|
|
}
|
|
|
}
|
|
|
- } else if (role == RoleTypeEnum.OFFICE_TEACHER && Objects.nonNull(sysUser.getOrgId())) {
|
|
|
- SysOrg sysOrg = commonCacheService.orgCache(sysUser.getOrgId());
|
|
|
+ } else if (role == RoleTypeEnum.OFFICE_TEACHER && Objects.nonNull(sysUserCas.getOrgId())) {
|
|
|
+ SysOrg sysOrg = commonCacheService.orgCache(sysUserCas.getOrgId());
|
|
|
if (Objects.isNull(sysOrg)) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("未找到学校信息");
|
|
|
} else if (Objects.nonNull(sysOrg) && sysOrg.getType() != OrgTypeEnum.SCHOOL) {
|
|
@@ -145,4 +172,71 @@ public class SsoServiceImpl implements SsoService {
|
|
|
map.put("redirectUrl", hostUrl + dictionaryConfig.reportOpenDomain().getSsoLoginApi());
|
|
|
return map;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 题库单点登录
|
|
|
+ *
|
|
|
+ * @param loginName
|
|
|
+ * @param role
|
|
|
+ * @param returnUrl
|
|
|
+ * @param params
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> questionLibraryLogin(String loginName, RoleTypeEnum role, String returnUrl, String params) throws IOException {
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
+ BasicSchool basicSchool = commonCacheService.schoolCache(sysUser.getSchoolId());
|
|
|
+
|
|
|
+ QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
|
|
|
+ sysUserQueryWrapper.lambda().eq(SysUser::getLoginName, loginName)
|
|
|
+ .eq(SysUser::getSchoolId, basicSchool.getId());
|
|
|
+ SysUser sysUserCas = sysUserService.getOne(sysUserQueryWrapper);
|
|
|
+ Optional.ofNullable(sysUserCas).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("用户信息为空"));
|
|
|
+
|
|
|
+ QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
|
|
|
+ sysRoleQueryWrapper.lambda().eq(SysRole::getType, role);
|
|
|
+ SysRole sysRole = sysRoleService.getOne(sysRoleQueryWrapper);
|
|
|
+ Optional.ofNullable(sysRole).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("角色信息为空"));
|
|
|
+
|
|
|
+ QueryWrapper<SysUserRole> sysUserRoleQueryWrapper = new QueryWrapper<>();
|
|
|
+ sysUserRoleQueryWrapper.lambda().eq(SysUserRole::getUserId, sysUserCas.getId())
|
|
|
+ .eq(SysUserRole::getRoleId, sysRole.getId());
|
|
|
+ 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 signature = SignatureEntity.build(SignatureType.SECRET, SystemConstant.GET, path, timestamp, basicSchool.getAccessKey(), basicSchool.getAccessSecret());
|
|
|
+
|
|
|
+ StringJoiner stringJoiner = new StringJoiner("")
|
|
|
+ .add(questionLoginUrl)
|
|
|
+ .add(SystemConstant.GET_UNKNOWN).add(SystemConstant.HEADER_TIME).add(SystemConstant.GET_EQUAL).add(String.valueOf(timestamp))
|
|
|
+ .add(SystemConstant.GET_SYMBOL).add(SystemConstant.SIGNATURE).add(SystemConstant.GET_EQUAL).add(signature)
|
|
|
+ .add(SystemConstant.GET_SYMBOL).add(SystemConstant.USER).add(SystemConstant.GET_EQUAL).add(loginName);
|
|
|
+
|
|
|
+ if (Objects.nonNull(returnUrl) && !Objects.equals(returnUrl, "")) {
|
|
|
+ stringJoiner = stringJoiner.add(SystemConstant.GET_SYMBOL).add(SystemConstant.RETURN_URL).add(SystemConstant.GET_EQUAL).add(returnUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ if (Objects.nonNull(params) && !Objects.equals(params, "")) {
|
|
|
+ OpenParams openParams = JacksonUtil.readJson(params, OpenParams.class);
|
|
|
+ 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("role", v -> role);
|
|
|
+ map.computeIfAbsent("returnUrl", v -> returnUrl);
|
|
|
+ map.put("redirectUrl", stringJoiner.toString());
|
|
|
+ return map;
|
|
|
+ }
|
|
|
}
|