Merge branch 'uat-userinfo' into 'uat_code'
修改获取当前用户机制 See merge request eshop/biz_service_ebtp_extend!91
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
package com.chinaunicom.mall.ebtp.extend.userinfo.controller;
|
package com.chinaunicom.mall.ebtp.extend.userinfo.controller;
|
||||||
|
|
||||||
import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.service.UserInfoService;
|
|
||||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.service.EbtpUserInfoService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
public class UserInfoController {
|
public class UserInfoController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserInfoService service;
|
private EbtpUserInfoService ebtpUserInfoService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户信息
|
* 获取用户信息
|
||||||
@ -33,7 +33,7 @@ public class UserInfoController {
|
|||||||
log.error("access token is empty");
|
log.error("access token is empty");
|
||||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
|
||||||
}
|
}
|
||||||
return ResponseEntity.ok(service.getUserInfo(token));
|
return ResponseEntity.ok(ebtpUserInfoService.getUserInfo(token));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.userinfo.dao;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.entity.BaseRole;
|
||||||
|
|
||||||
|
public interface BaseRoleMapper extends BaseMapper<BaseRole> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.userinfo.dao;
|
||||||
|
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.entity.BaseUser;
|
||||||
|
|
||||||
|
public interface BaseUserMapper extends BaseMapper<BaseUser> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.userinfo.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能模块bean
|
||||||
|
*
|
||||||
|
* @author zyx
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@ApiModel
|
||||||
|
@TableName(value = "maint_base_role", autoResultMap = true)
|
||||||
|
public class BaseRole implements Serializable {
|
||||||
|
|
||||||
|
private static final Long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 姓名
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "角色")
|
||||||
|
private String role;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "备注")
|
||||||
|
private String remarks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* role_id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "role_id")
|
||||||
|
private String roleId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "状态,0-默认")
|
||||||
|
private int status;
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.userinfo.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 功能模块bean
|
||||||
|
*
|
||||||
|
* @author zyx
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@ApiModel
|
||||||
|
@TableName(value = "maint_base_user", autoResultMap = true)
|
||||||
|
public class BaseUser implements Serializable {
|
||||||
|
|
||||||
|
private static final Long serialVersionUID = 1L;
|
||||||
|
/**
|
||||||
|
* id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "编号")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 姓名
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "姓名")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 账号
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "账号")
|
||||||
|
private String account;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "密码")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 省份
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "省份")
|
||||||
|
private String province;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "角色")
|
||||||
|
private String role;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "租户")
|
||||||
|
private String tenant;
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.userinfo.service;
|
||||||
|
|
||||||
|
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
||||||
|
|
||||||
|
public interface EbtpUserInfoService {
|
||||||
|
|
||||||
|
|
||||||
|
public BaseCacheUser getUserInfo(String token);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.chinaunicom.mall.ebtp.extend.userinfo.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import com.chinaunicom.mall.ebtp.cloud.security.starter.entity.AuthorityEntity;
|
||||||
|
import com.chinaunicom.mall.ebtp.cloud.userinfo.starter.service.UserInfoService;
|
||||||
|
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.dao.BaseRoleMapper;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.dao.BaseUserMapper;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.entity.BaseRole;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.entity.BaseUser;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.userinfo.service.EbtpUserInfoService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class EbtpUserInfoServiceImpl implements EbtpUserInfoService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserInfoService service;
|
||||||
|
@Autowired
|
||||||
|
private BaseUserMapper baseUserMapper;
|
||||||
|
@Autowired
|
||||||
|
private BaseRoleMapper baseRoleMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BaseCacheUser getUserInfo(String token) {
|
||||||
|
//查询山分库
|
||||||
|
BaseCacheUser user = service.getUserInfo(token);
|
||||||
|
|
||||||
|
if (Objects.isNull(user)) {
|
||||||
|
return new BaseCacheUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询拓展库的user表进行角色拓展
|
||||||
|
BaseUser baseUser = baseUserMapper.selectOne(Wrappers.lambdaQuery(BaseUser.class).eq(BaseUser::getAccount, user.getUserId()).eq(BaseUser::getTenant, "ebtp_mall"));
|
||||||
|
|
||||||
|
if (Objects.isNull(baseUser)) {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
user.setProvince(baseUser.getProvince())
|
||||||
|
//追加角色
|
||||||
|
.getAuthorityList().addAll(
|
||||||
|
Optional.of(baseRoleMapper.selectList(Wrappers.lambdaQuery(BaseRole.class).in(BaseRole::getRole, baseUser.getRole()))
|
||||||
|
.stream().map(br ->
|
||||||
|
new AuthorityEntity()
|
||||||
|
.setRoleId(br.getRoleId())
|
||||||
|
.setRoleCode(br.getRole())
|
||||||
|
.setRoleName(br.getRemarks())
|
||||||
|
.setRoleScope("EBTP")
|
||||||
|
.setAuthorities(Collections.emptyList()))
|
||||||
|
.collect(Collectors.toList()))
|
||||||
|
.orElseGet(Collections::emptyList));
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EbtpUserInfoServiceImpl() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user