作者 朱兆平

增加登录成功后用户的所在顶级组织机构信息返回

... ... @@ -25,7 +25,7 @@
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>info</level>
<level>debug</level>
</filter>
<encoder>
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
... ... @@ -169,7 +169,7 @@
不能设置为INHERITED或者同义词NULL。默认是DEBUG
可以包含零个或多个元素,标识这个appender将会添加到这个logger。
-->
<logger name="com.tianbo.warehouse.dao" level="info" />
<logger name="com.tianbo.warehouse.dao" level="debug" />
<!--开发环境:打印控制台-->
<springProfile name="dev">
<logger name="org.springframework.security" level="debug"/>
... ... @@ -194,4 +194,4 @@
</root>
</springProfile>
</configuration>
\ No newline at end of file
</configuration>
... ...
... ... @@ -205,10 +205,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-zipkin</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>de.codecentric</groupId>
... ...
... ... @@ -5,6 +5,7 @@ import com.tianbo.warehouse.annotation.LogAnnotation;
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.model.PERMISSION;
import com.tianbo.warehouse.service.PermissionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
... ... @@ -89,7 +90,7 @@ public class PermssionController {
}
return resultJson;
}
@LogAnnotation(moduleName = "权限管理",operate = "查找权限")
// @LogAnnotation(moduleName = "权限管理",operate = "查找权限")
@GetMapping("/findByRoleId")
public ResultJson findByRoleId(@RequestParam Integer roleId){
... ... @@ -110,8 +111,15 @@ public class PermssionController {
@GetMapping("/userMenu")
public ResultJson<List<PERMISSION>> userMenu(
@RequestParam(value = "userId", required = true) Integer userId){
@RequestParam(value = "userId") Integer userId){
return new ResultJson<List<PERMISSION>>("200","success",permissionService.getUserMenuTreeByUserId(userId));
}
@ApiOperation(value = "所有目录列表", notes = "查询所有目录菜单的树形结构信息")
@GetMapping("/menu")
public ResultJson<List<PERMISSION>> menu(){
return new ResultJson<List<PERMISSION>>("200","success",permissionService.getUserMenuTreeByUserId(0));
}
}
... ...
... ... @@ -70,11 +70,12 @@ public class UserController {
UserDetails userDetails =(UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return userDetails.getUsername();
}
@ApiOperation(value = "更新用户信息", notes = "跟新用户信息除了用户密码")
@LogAnnotation(moduleName = "用户管理",operate = "用户编辑")
@PutMapping("/edit")
public ResultJson updateUserById(@Validated(UpdateUser.class) @RequestBody USERS user){
int i = userService.updateByPrimaryKeySelective(user);
int i = userService.updateByPrimaryKeySelective(user);
user.setPassword(null);
ResultJson resultJson = new ResultJson();
return i==1 ? new ResultJson("200","success") :new ResultJson("500","update faild");
... ...
... ... @@ -39,7 +39,7 @@ public interface PERMISSIONMapper {
List<PERMISSION> getRolePermisson(Integer roleId);
List<PERMISSION> getUserMenuTreeByUserId(Integer userId);
List<PERMISSION> getUserMenuTreeByUserId(@Param("userId") Integer userId);
List<PERMISSION> getChildMenu(Integer parentId);
}
... ...
... ... @@ -18,10 +18,17 @@ public interface ROLEMapper {
List<ROLE> selectByParentId(Integer roleId);
/**
* 查询最顶层企业信息
* @param roleId 组织机构ID
* @return
*/
List<ROLE> selectTopByChildID(Integer roleId);
List<ROLE> findAll(@Param("roleName") String roleName,
@Param("type") String type);
int updateByPrimaryKeySelective(ROLE record);
int updateByPrimaryKey(ROLE record);
}
\ No newline at end of file
}
... ...
... ... @@ -20,8 +20,6 @@ public class ROLE implements GrantedAuthority {
private String description;
private String departmentId;
private String type;
private List<PERMISSION> permissions;
... ... @@ -38,7 +36,6 @@ public class ROLE implements GrantedAuthority {
private List<ROLE> children;
public Integer getRoleId() {
return roleId;
}
... ... @@ -79,9 +76,16 @@ public class ROLE implements GrantedAuthority {
this.type = type == null ? null : type.trim();
}
public String getDepartmentid() {
return departmentid;
}
public void setDepartmentid(String departmentid) {
this.departmentid = departmentid;
}
@Override
public String getAuthority(){
return this.getRoleName();
}
}
\ No newline at end of file
}
... ...
... ... @@ -24,7 +24,7 @@ public class USERS implements UserDetails {
private Integer userId;
@NotBlank(message="用户名不能为空",groups={InsertUser.class, UpdateUser.class})
@Length(min = 5, max = 11, message = "username 长度必须在 {min} - {max} 之间",groups={InsertUser.class, UpdateUser.class})
@Length(min = 1, max = 11, message = "username 长度必须在 {min} - {max} 之间",groups={InsertUser.class, UpdateUser.class})
@CheckUserExist(message = "用户已存在",groups=InsertUser.class)
private String username;
... ... @@ -58,7 +58,9 @@ public class USERS implements UserDetails {
private String token;
//用户所属企业ID,企业ID为用户绑定的组织机构顶层parentid为0的组织机构ID
private Integer companyId;
private String companyName;
private ROLE companyInfo;
... ... @@ -222,6 +224,14 @@ public class USERS implements UserDetails {
this.companyInfo = companyInfo;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
/**
*
* @return 账户未过期
... ...
... ... @@ -67,6 +67,9 @@ public class MyAuthenticationSuccessHandler extends SavedRequestAwareAuthenticat
loginedUser.setUserface(user.getUserface());
loginedUser.setUserId(user.getUserId());
loginedUser.setRealname(user.getRealname());
loginedUser.setCompanyId(user.getCompanyId());
loginedUser.setCompanyName(user.getCompanyName());
loginedUser.setCompanyInfo(user.getCompanyInfo());
//设置用户的TOKEN的有效时间,时间配置在配置文件中设置
... ...
... ... @@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
... ... @@ -26,7 +27,7 @@ public class PermissionServiceImp implements PermissionService {
PERMISSIONMapper permissionMapper;
@Override
@RedisCacheable(cacheKey = "findAllMenus")
// @RedisCacheable(cacheKey = "findAllMenus")
public PageInfo<PERMISSION> findAll(int pageNum, int pageSize, String name) {
Page<PERMISSION> page = PageHelper.startPage(pageNum, 0,true,true,true);
List<PERMISSION> list = permissionMapper.findAll(name);
... ... @@ -35,7 +36,7 @@ public class PermissionServiceImp implements PermissionService {
}
@Override
@RedisCacheable(cacheKey = "findByRoleId")
// @RedisCacheable(cacheKey = "findByRoleId")
public List<PERMISSION> findByRoleId(Integer roleId) {
List<PERMISSION> list = getPermissionList(permissionMapper.findByRoleId(roleId), 0);
return list;
... ... @@ -66,7 +67,7 @@ public class PermissionServiceImp implements PermissionService {
* @return
*/
@Override
@RedisCacheable(cacheKey = "findByUserIdWithLogin")
// @RedisCacheable(cacheKey = "findByUserIdWithLogin")
public List<PERMISSION> findByUserIdWithLogin(Integer userId){
return permissionMapper.findByUserIdWithLogin(userId);
}
... ... @@ -77,7 +78,7 @@ public class PermissionServiceImp implements PermissionService {
* @return
*/
@Override
@RedisCacheable(cacheKey = "getUserMenusTree")//添加缓存
// @RedisCacheable(cacheKey = "getUserMenusTree")//添加缓存
public Map<String, Object> getUserMenus(Integer userId) {
Map<String, Object> data = new HashMap<String, Object>();
try {
... ... @@ -181,8 +182,8 @@ public class PermissionServiceImp implements PermissionService {
}
@Override
@RedisCacheable(cacheKey = "getUserMenuTreeByUserId")
public List<PERMISSION> getUserMenuTreeByUserId(Integer userId) {
// @RedisCacheable(cacheKey = "getUserMenuTreeByUserId")
public List<PERMISSION> getUserMenuTreeByUserId(@NotNull Integer userId) {
return permissionMapper.getUserMenuTreeByUserId(userId);
}
... ...
... ... @@ -18,6 +18,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.management.relation.Role;
import java.util.Collections;
import java.util.List;
import java.util.Random;
... ... @@ -46,15 +48,34 @@ public class UserServiceImpl implements UserService{
if (userList != null && userList.size() > 0) {
USERS user = userList.get(0);
//获取用户角色列表,用户没有配置相关组织机构时,获取不到权限
List<ROLE> roleList = roleMapper.findRolesByUserId(user.getUserId());
//用户未绑定组织机构时会查询出null数组信息,现象为All elements are null
if (!roleList.isEmpty()){
ROLE ur = roleList.get(0);
/**
* 一个用户只能对应一个总组织机构(公司),可以在多个部门/岗位任职,设置用户所属顶级组织机构信息
*/
List<ROLE> topRoles = roleMapper.selectTopByChildID(ur.getRoleId());
topRoles.removeAll(Collections.singleton(null));
if (!topRoles.isEmpty()){
user.setCompanyId(topRoles.get(0).getRoleId());
user.setCompanyName(topRoles.get(0).getRoleName());
topRoles.get(0).setChildren(null);
topRoles.get(0).setPermissions(null);
user.setCompanyInfo(topRoles.get(0));
}
user.setRoles(roleList);
}
//用户权限列表
List<PERMISSION> permissionList = permissionService.findByUserIdWithLogin(user.getUserId());
if (permissionList!=null && permissionList.size()>0){
if (!permissionList.isEmpty()){
user.setPermissions(permissionList);
}
List<ROLE> roleList = roleMapper.findRolesByUserId(user.getUserId());
if (roleList!=null && roleList.size()>0){
user.setRoles(roleList);
}
return user;
}
return null;
... ...
... ... @@ -352,8 +352,10 @@ where P.url = #{permissionUrl,jdbcType=VARCHAR} ORDER BY permission_order
UR.role_id
FROM
user_role UR
<if test="userId != 0" >
WHERE
UR.user_id = #{userId,jdbcType=INTEGER}
</if>
)
)
)
... ...
... ... @@ -17,11 +17,11 @@
<collection column="role_id" property="children" select="selectByParentId" />
</resultMap>
<sql id="Base_Column_List">
role_id, role_name, role_sign, description, type, parentId, rsort, customs_reg_code,
role_id, role_name, role_sign, description, type, parentId, rsort, customs_reg_code,
business_license, departmentId, mq_code
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
select
<include refid="Base_Column_List" />
from role
where role_id = #{roleId,jdbcType=INTEGER}
... ... @@ -32,18 +32,53 @@
from role
where parentId = #{roleId,jdbcType=INTEGER}
</select>
<select id="selectTopByChildID" parameterType="java.lang.Integer" resultMap="BaseResultMap">
SELECT
*
FROM
(
SELECT
t3.*
FROM
(
SELECT
t1.*,
IF
(
FIND_IN_SET( role_id, @ids ) > 0,
@ids := CONCAT( parentId, ',', @ids ),
'0'
) AS isparent
FROM
(
SELECT
t.*
FROM
role AS t
ORDER BY
t.role_id DESC
) t1,
( SELECT @ids := #{roleId,jdbcType=INTEGER} ) t2
) t3
WHERE
t3.isparent != '0'
) t4
WHERE
t4.parentId = 0
order by role_id
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from role
where role_id = #{roleId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.tianbo.warehouse.model.ROLE">
insert into role (role_id, role_name, role_sign,
description, type, parentId,
rsort, customs_reg_code, business_license,
insert into role (role_id, role_name, role_sign,
description, type, parentId,
rsort, customs_reg_code, business_license,
departmentId, mq_code)
values (#{roleId,jdbcType=INTEGER}, #{roleName,jdbcType=VARCHAR}, #{roleSign,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{parentid,jdbcType=INTEGER},
#{rsort,jdbcType=INTEGER}, #{customsRegCode,jdbcType=VARCHAR}, #{businessLicense,jdbcType=VARCHAR},
values (#{roleId,jdbcType=INTEGER}, #{roleName,jdbcType=VARCHAR}, #{roleSign,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{parentid,jdbcType=INTEGER},
#{rsort,jdbcType=INTEGER}, #{customsRegCode,jdbcType=VARCHAR}, #{businessLicense,jdbcType=VARCHAR},
#{departmentid,jdbcType=VARCHAR},#{mqcode,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.tianbo.warehouse.model.ROLE">
... ... @@ -192,4 +227,4 @@
LEFT JOIN role R ON R.role_id= UR.role_id
where U.user_id = #{userId,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
</mapper>
... ...