|
@@ -1,13 +1,20 @@
|
|
|
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.BOOL;
|
|
|
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.config.DictionaryConfig;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
-import com.qmth.teachcloud.common.entity.BasicSchool;
|
|
|
+import com.qmth.teachcloud.common.entity.*;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
+import com.qmth.teachcloud.common.service.*;
|
|
|
import com.qmth.teachcloud.common.util.AuthThirdUtil;
|
|
|
+import com.qmth.teachcloud.common.util.JacksonUtil;
|
|
|
+import com.qmth.teachcloud.report.business.bean.params.LoginThirdParam;
|
|
|
+import com.qmth.teachcloud.report.business.cache.WhuUserAuthCacheUtil;
|
|
|
import io.swagger.annotations.*;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -22,6 +29,9 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URLDecoder;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.text.MessageFormat;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
/**
|
|
@@ -42,6 +52,18 @@ public class SsoApiController {
|
|
|
@Resource
|
|
|
DictionaryConfig dictionaryConfig;
|
|
|
|
|
|
+ @Resource
|
|
|
+ SysUserService sysUserService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ SysUserRoleService sysUserRoleService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ SysOrgService sysOrgService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ SysRoleService sysRoleService;
|
|
|
+
|
|
|
@ApiOperation(value = "单点登录接口")
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "单点登录接口", response = Object.class)})
|
|
|
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
|
@@ -50,11 +72,50 @@ public class SsoApiController {
|
|
|
Optional.ofNullable(result).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("数据为空"));
|
|
|
String decodeJson = URLDecoder.decode(result, SystemConstant.CHARSET_NAME);
|
|
|
log.info("login进来了,result:{}", decodeJson);
|
|
|
-// BasicSemesterParams basicSemesterParams = JacksonUtil.readJson(decodeJson, BasicSemesterParams.class);
|
|
|
-// Optional.ofNullable(basicSemesterParams).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("转换后的数据为空"));
|
|
|
-// basicSemesterParams.validParams();
|
|
|
+ LoginThirdParam loginThirdParam = JacksonUtil.readJson(decodeJson, LoginThirdParam.class);
|
|
|
+ Optional.ofNullable(loginThirdParam).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("转换后的数据为空"));
|
|
|
+ loginThirdParam.validParams();
|
|
|
BasicSchool basicSchool = AuthThirdUtil.hasPermission();
|
|
|
+ //插入或者更新用户
|
|
|
+ //查询用户是否存在
|
|
|
+ QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
|
|
|
+ sysUserQueryWrapper.lambda().eq(SysUser::getSchoolId, basicSchool.getId())
|
|
|
+ .eq(SysUser::getLoginName, loginThirdParam.getLoginName())
|
|
|
+ .eq(SysUser::getEnable, true);
|
|
|
+ SysUser sysUser = sysUserService.getOne(sysUserQueryWrapper);
|
|
|
+ if (Objects.isNull(sysUser)) {//新增
|
|
|
+ //查询学院id
|
|
|
+ QueryWrapper<SysOrg> sysOrgQueryWrapper = new QueryWrapper<>();
|
|
|
+ sysOrgQueryWrapper.lambda().eq(SysOrg::getSchoolId, basicSchool.getId())
|
|
|
+ .eq(SysOrg::getName, loginThirdParam.getOrgName())
|
|
|
+ .eq(SysOrg::getEnable, true);
|
|
|
+ SysOrg sysOrg = sysOrgService.getOne(sysOrgQueryWrapper);
|
|
|
+ Optional.ofNullable(sysOrg).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("学院数据为空"));
|
|
|
+
|
|
|
+ sysUser = new SysUser(basicSchool.getId(),
|
|
|
+ loginThirdParam.getLoginName(),
|
|
|
+ Objects.nonNull(loginThirdParam.getRealName()) ? loginThirdParam.getRealName() : loginThirdParam.getLoginName(),
|
|
|
+ Objects.nonNull(loginThirdParam.getMobileNumber()) ? loginThirdParam.getMobileNumber() : null,
|
|
|
+ sysOrg.getId());
|
|
|
+ sysUserService.save(sysUser);
|
|
|
+
|
|
|
+ //新增用户和角色关系
|
|
|
+ QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
|
|
|
+ sysRoleQueryWrapper.lambda().eq(SysRole::getType, loginThirdParam.getRole())
|
|
|
+ .eq(SysRole::getEnable, true);
|
|
|
+ SysRole sysRole = sysRoleService.getOne(sysRoleQueryWrapper);
|
|
|
+ Optional.ofNullable(sysRole).orElseThrow(() -> ExceptionResultEnum.PARAMS_ERROR.exception("角色数据为空"));
|
|
|
+
|
|
|
+ SysUserRole sysUserRole = new SysUserRole(sysUser.getId(), sysRole.getId());
|
|
|
+ sysUserRoleService.save(sysUserRole);
|
|
|
+ }
|
|
|
+
|
|
|
+ UserAuthenticationDto userAuthenticationDto = new UserAuthenticationDto(String.valueOf(sysUser.getId()), 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);
|
|
|
+
|
|
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
|
|
- response.sendRedirect(dictionaryConfig.sysDomain().getLoginAuthenUrl() + SystemConstant.getUuid());
|
|
|
+ response.sendRedirect(dictionaryConfig.sysDomain().getLoginAuthenUrl() + code);
|
|
|
}
|
|
|
}
|