多选用户接口
This commit is contained in:
parent
5d13e94804
commit
afb6450d37
|
|
@ -1,6 +1,7 @@
|
||||||
package com.chinaweal.aiccs.org.controller;
|
package com.chinaweal.aiccs.org.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.chinaweal.aiccs.common.base.controller.BaseController;
|
import com.chinaweal.aiccs.common.base.controller.BaseController;
|
||||||
import com.chinaweal.aiccs.common.constant.CommonConstants;
|
import com.chinaweal.aiccs.common.constant.CommonConstants;
|
||||||
|
|
@ -9,6 +10,7 @@ import com.chinaweal.aiccs.common.util.SM4Utils;
|
||||||
import com.chinaweal.aiccs.common.util.StringUtils;
|
import com.chinaweal.aiccs.common.util.StringUtils;
|
||||||
import com.chinaweal.aiccs.org.entity.*;
|
import com.chinaweal.aiccs.org.entity.*;
|
||||||
import com.chinaweal.aiccs.org.entity.dto.*;
|
import com.chinaweal.aiccs.org.entity.dto.*;
|
||||||
|
import com.chinaweal.aiccs.org.entity.vo.UserLoginSelectionVO;
|
||||||
import com.chinaweal.aiccs.org.service.*;
|
import com.chinaweal.aiccs.org.service.*;
|
||||||
import com.chinaweal.aiccs.redis.RedisService;
|
import com.chinaweal.aiccs.redis.RedisService;
|
||||||
import com.chinaweal.aicorg.model.AICUser;
|
import com.chinaweal.aicorg.model.AICUser;
|
||||||
|
|
@ -18,7 +20,9 @@ import com.chinaweal.youfool.framework.springboot.rest.ResultCode;
|
||||||
import com.chinaweal.youfool.framework.sso.util.SSOUtil;
|
import com.chinaweal.youfool.framework.sso.util.SSOUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
@ -29,6 +33,9 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Oauth登录控制器
|
* Oauth登录控制器
|
||||||
|
|
@ -65,6 +72,8 @@ public class OAuth2Controller extends BaseController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisService redisService;
|
private RedisService redisService;
|
||||||
|
|
||||||
|
private final static String USER_LOGIN_SELECTION = "USER_LOGIN_SELECTION:";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth授权端点
|
* OAuth授权端点
|
||||||
*/
|
*/
|
||||||
|
|
@ -636,29 +645,28 @@ public class OAuth2Controller extends BaseController {
|
||||||
.location(java.net.URI.create("/integration/#/login?requestId=" + requestId + "&error=" + URLEncoder.encode("统一身份认证回调信息不足以支持登录,请联系系统管理员", "UTF-8")))
|
.location(java.net.URI.create("/integration/#/login?requestId=" + requestId + "&error=" + URLEncoder.encode("统一身份认证回调信息不足以支持登录,请联系系统管理员", "UTF-8")))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
ImsUser one = iImsUserService.lambdaQuery().eq(ImsUser::getIdCard, userInfo.getIdCard())
|
List<UserSupInfo> supList = userSupInfoService.lambdaQuery().eq(UserSupInfo::getIdcardAbstr, DigestUtils.md5DigestAsHex(userInfo.getIdCard().getBytes())).list();
|
||||||
.eq(ImsUser::getDeleted, CommonConstants.FALSE_0).last("limit 1").one();
|
if (CollectionUtils.isEmpty(supList)) {
|
||||||
if (one == null) {
|
|
||||||
return ResponseEntity.status(HttpStatus.FOUND)
|
|
||||||
.location(java.net.URI.create("/integration/#/login?requestId=" + requestId + "&error=" + URLEncoder.encode("IMS_USER用户信息不存在,请联系系统管理员", "UTF-8")))
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
// 查询绑定的账号
|
|
||||||
String usercode = one.getUsercode();
|
|
||||||
ImsUser imsUser = iImsUserService.getById(usercode);
|
|
||||||
if (imsUser == null) {
|
|
||||||
return ResponseEntity.status(HttpStatus.FOUND)
|
return ResponseEntity.status(HttpStatus.FOUND)
|
||||||
.location(java.net.URI.create("/integration/#/login?requestId=" + requestId + "&error=" + URLEncoder.encode("无匹配的综合监管用户,请联系系统管理员", "UTF-8")))
|
.location(java.net.URI.create("/integration/#/login?requestId=" + requestId + "&error=" + URLEncoder.encode("无匹配的综合监管用户,请联系系统管理员", "UTF-8")))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
String idCard = SM4Utils.decrypt(imsUser.getIdCard(), sm4Key);
|
List<TUsers> list = usersService.lambdaQuery().in(TUsers::getUserid, supList.stream().map(UserSupInfo::getUserid).collect(Collectors.toList()))
|
||||||
UserSupInfo userSup = userSupInfoService.lambdaQuery().eq(UserSupInfo::getIdcardAbstr, DigestUtils.md5DigestAsHex(idCard.getBytes())).one();
|
.eq(TUsers::getDeleted, CommonConstants.FALSE_0).list();
|
||||||
if (userSup == null) {
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
return ResponseEntity.status(HttpStatus.FOUND)
|
return ResponseEntity.status(HttpStatus.FOUND)
|
||||||
.location(java.net.URI.create("/integration/#/login?requestId=" + requestId + "&error=" + URLEncoder.encode("无匹配的综合监管用户,请联系系统管理员", "UTF-8")))
|
.location(java.net.URI.create("/integration/#/login?requestId=" + requestId + "&error=" + URLEncoder.encode("无匹配的综合监管用户,请联系系统管理员", "UTF-8")))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
TUsers tuser = usersService.getById(userSup.getUserid());
|
// 存储候选
|
||||||
|
if (list.size() > 1) {
|
||||||
|
redisService.set(USER_LOGIN_SELECTION + code, JSON.toJSONString(list), 900);
|
||||||
|
return ResponseEntity.status(HttpStatus.FOUND)
|
||||||
|
.location(java.net.URI.create("/integration/#/oauth2?requestId=" + requestId + "&code=" + code))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
TUsers tuser = list.get(0);
|
||||||
|
|
||||||
RestResult<AICUser> loginResult = userBaseService.login(tuser.getUsername(), "ChinaWeal_2026");
|
RestResult<AICUser> loginResult = userBaseService.login(tuser.getUsername(), "ChinaWeal_2026");
|
||||||
AICUser user = loginResult.getData();
|
AICUser user = loginResult.getData();
|
||||||
|
|
@ -684,6 +692,66 @@ public class OAuth2Controller extends BaseController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据登录编码获取候选登录用户
|
||||||
|
*
|
||||||
|
* @param code 查询编码
|
||||||
|
* @return 查询结果
|
||||||
|
*/
|
||||||
|
@ApiOperation("根据登录编码获取候选登录用户")
|
||||||
|
@GetMapping("/unified/selection")
|
||||||
|
public RestResult<List<UserLoginSelectionVO>> getLoginSelection(@ApiParam("查询编码") @RequestParam String code) {
|
||||||
|
String json = redisService.get(USER_LOGIN_SELECTION + code);
|
||||||
|
if (StringUtils.isBlank(json)) {
|
||||||
|
return RestResult.error(ResultCode.DATA_NONE);
|
||||||
|
}
|
||||||
|
List<TUsers> list = JSONArray.parseArray(json, TUsers.class);
|
||||||
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
|
return RestResult.error(ResultCode.DATA_NONE);
|
||||||
|
}
|
||||||
|
List<UserLoginSelectionVO> loginSelectionList = new ArrayList<>(list.size());
|
||||||
|
for (TUsers each : list) {
|
||||||
|
UserLoginSelectionVO atom = new UserLoginSelectionVO();
|
||||||
|
atom.setUserId(each.getUserid());
|
||||||
|
atom.setUsername(each.getUsername());
|
||||||
|
atom.setRealname(each.getRealname());
|
||||||
|
loginSelectionList.add(atom);
|
||||||
|
}
|
||||||
|
return RestResult.ok(loginSelectionList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据登录编码获取候选登录用户
|
||||||
|
*
|
||||||
|
* @param code 查询编码
|
||||||
|
* @return 查询结果
|
||||||
|
*/
|
||||||
|
@ApiOperation("根据登录编码获取候选登录用户")
|
||||||
|
@PostMapping("/unified/select/login")
|
||||||
|
public RestResult<?> selectLogin(@ApiParam("查询编码") @RequestParam String code, @ApiParam("用户id") @RequestParam String userId,
|
||||||
|
HttpServletRequest request) {
|
||||||
|
String json = redisService.get(USER_LOGIN_SELECTION + code);
|
||||||
|
if (StringUtils.isBlank(json)) {
|
||||||
|
return RestResult.error(ResultCode.DATA_NONE);
|
||||||
|
}
|
||||||
|
List<TUsers> list = JSONArray.parseArray(json, TUsers.class);
|
||||||
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
|
return RestResult.error(ResultCode.DATA_NONE);
|
||||||
|
}
|
||||||
|
TUsers tuser = list.stream().filter(each -> StringUtils.equals(each.getUserid(), userId)).findFirst().orElse(null);
|
||||||
|
if (tuser == null) {
|
||||||
|
return RestResult.error(ResultCode.DATA_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
RestResult<AICUser> loginResult = userBaseService.login(tuser.getUsername(), "ChinaWeal_2026");
|
||||||
|
AICUser user = loginResult.getData();
|
||||||
|
// 将登录了的用户信息存至Session
|
||||||
|
request.getSession().setAttribute(DRUID_SESSION_KEY, String.format("%s(%s)", user.getName(), user.getEname()));
|
||||||
|
redisService.remove(tuser.getUsername());
|
||||||
|
SSOUtil.login(user);
|
||||||
|
return RestResult.ok();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统一认证平台单点登出
|
* 统一认证平台单点登出
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.chinaweal.aiccs.org.entity.vo;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户登录候选VO
|
||||||
|
* @author lroyia
|
||||||
|
* @since 2026/3/30 9:31
|
||||||
|
**/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@ApiModel("用户登录候选VO")
|
||||||
|
public class UserLoginSelectionVO implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("用户id")
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("用户名")
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户真名
|
||||||
|
*/
|
||||||
|
@ApiModelProperty("用户真名")
|
||||||
|
private String realname;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue