Merge branch 'dev-V0.4.5' of https://gitee.com/iotkit-open-source/iotkit-parent into dev-V0.4.5
commit
165449fcb8
File diff suppressed because it is too large
Load Diff
|
@ -60,4 +60,6 @@ public interface ISysRoleData extends ICommonData<SysRole, Long> {
|
||||||
int updateById(SysRole role);
|
int updateById(SysRole role);
|
||||||
|
|
||||||
List<SysRole> selectRoleList(SysRole role);
|
List<SysRole> selectRoleList(SysRole role);
|
||||||
|
|
||||||
|
List<SysRole> findByUserId(Long id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@ package cc.iotkit.data.config.id;
|
||||||
|
|
||||||
import cc.iotkit.common.utils.SnowflakeIdGeneratorUtil;
|
import cc.iotkit.common.utils.SnowflakeIdGeneratorUtil;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.id.IdentifierGenerator;
|
import org.hibernate.id.IdentifierGenerator;
|
||||||
|
@ -18,6 +21,17 @@ public class SnowflakeIdGenerator implements IdentifierGenerator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException {
|
public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException {
|
||||||
|
Field id = null;
|
||||||
|
try {
|
||||||
|
id = o.getClass().getDeclaredField("id");
|
||||||
|
id.setAccessible(true);
|
||||||
|
Object val = id.get(o);
|
||||||
|
if (Objects.nonNull(val)){
|
||||||
|
return (Serializable) val;
|
||||||
|
}
|
||||||
|
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||||
|
|
||||||
|
}
|
||||||
return SnowflakeIdGeneratorUtil.getInstanceSnowflake().nextId();
|
return SnowflakeIdGeneratorUtil.getInstanceSnowflake().nextId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class SysPostDataImpl implements ISysPostData, IJPACommData<SysPost, Long
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Long> selectPostListByUserId(Long userId) {
|
public List<Long> selectPostListByUserId(Long userId) {
|
||||||
return jpaQueryFactory.select(Projections.bean(Long.class, tbSysPost.id))
|
return jpaQueryFactory.select( tbSysPost.id)
|
||||||
.from(tbSysPost)
|
.from(tbSysPost)
|
||||||
.leftJoin(tbSysUserPost).on(tbSysUserPost.postId.eq(tbSysPost.id))
|
.leftJoin(tbSysUserPost).on(tbSysUserPost.postId.eq(tbSysPost.id))
|
||||||
.leftJoin(tbSysUser).on(tbSysUser.id.eq(tbSysUserPost.userId))
|
.leftJoin(tbSysUser).on(tbSysUser.id.eq(tbSysUserPost.userId))
|
||||||
|
|
|
@ -143,6 +143,15 @@ public class SysRoleDataImpl implements ISysRoleData, IJPACommData<SysRole, Long
|
||||||
return buildQueryTitle(buildQueryWrapper(role));
|
return buildQueryTitle(buildQueryWrapper(role));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysRole> findByUserId(Long id) {
|
||||||
|
return jpaQueryFactory.select(Projections.bean(SysRole.class, tbSysRole.id, tbSysRole.roleName, tbSysRole.roleKey, tbSysRole.roleSort, tbSysRole.dataScope, tbSysRole.status, tbSysRole.delFlag, tbSysRole.createTime, tbSysRole.remark))
|
||||||
|
.from(tbSysRole)
|
||||||
|
.leftJoin(tbSysUserRole).on(tbSysUserRole.roleId.eq(tbSysRole.id))
|
||||||
|
.where(tbSysUserRole.userId.eq(id))
|
||||||
|
.fetch();
|
||||||
|
}
|
||||||
|
|
||||||
private List<SysRole> buildQueryTitle(Predicate predicate) {
|
private List<SysRole> buildQueryTitle(Predicate predicate) {
|
||||||
return jpaQueryFactory.select(Projections.fields(SysRole.class, tbSysRole.id, tbSysRole.roleName,
|
return jpaQueryFactory.select(Projections.fields(SysRole.class, tbSysRole.id, tbSysRole.roleName,
|
||||||
tbSysRole.roleKey, tbSysRole.roleSort, tbSysRole.menuCheckStrictly, tbSysRole.deptCheckStrictly,
|
tbSysRole.roleKey, tbSysRole.roleSort, tbSysRole.menuCheckStrictly, tbSysRole.deptCheckStrictly,
|
||||||
|
|
|
@ -12,10 +12,12 @@ import cc.iotkit.data.model.TbSysPost;
|
||||||
import cc.iotkit.data.model.TbSysRole;
|
import cc.iotkit.data.model.TbSysRole;
|
||||||
import cc.iotkit.data.model.TbSysUser;
|
import cc.iotkit.data.model.TbSysUser;
|
||||||
import cc.iotkit.data.system.ISysDeptData;
|
import cc.iotkit.data.system.ISysDeptData;
|
||||||
|
import cc.iotkit.data.system.ISysRoleData;
|
||||||
import cc.iotkit.data.system.ISysUserData;
|
import cc.iotkit.data.system.ISysUserData;
|
||||||
import cc.iotkit.data.util.PageBuilder;
|
import cc.iotkit.data.util.PageBuilder;
|
||||||
import cc.iotkit.data.util.PredicateBuilder;
|
import cc.iotkit.data.util.PredicateBuilder;
|
||||||
import cc.iotkit.model.system.SysDept;
|
import cc.iotkit.model.system.SysDept;
|
||||||
|
import cc.iotkit.model.system.SysRole;
|
||||||
import cc.iotkit.model.system.SysUser;
|
import cc.iotkit.model.system.SysUser;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.querydsl.core.QueryResults;
|
import com.querydsl.core.QueryResults;
|
||||||
|
@ -53,6 +55,8 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
|
||||||
|
|
||||||
private final ISysDeptData sysDeptData;
|
private final ISysDeptData sysDeptData;
|
||||||
|
|
||||||
|
private final ISysRoleData sysRoleData;
|
||||||
|
|
||||||
private final JPAQueryFactory jpaQueryFactory;
|
private final JPAQueryFactory jpaQueryFactory;
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,6 +101,20 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
|
||||||
return Objects.isNull(ret);
|
return Objects.isNull(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysUser findById(Long id){
|
||||||
|
TbSysUser sysUser = jpaQueryFactory.select(tbSysUser).from(tbSysUser).where(tbSysUser.id.eq(id)).fetchOne();
|
||||||
|
|
||||||
|
SysUser convert = MapstructUtils.convert(sysUser, SysUser.class);
|
||||||
|
List<SysRole> sysRoles = sysRoleData.findByUserId(id);
|
||||||
|
convert.setRoles(sysRoles);
|
||||||
|
SysDept dept = sysDeptData.findById(convert.getDeptId());
|
||||||
|
if(ObjectUtil.isNotNull(dept)){
|
||||||
|
convert.setDept(dept);
|
||||||
|
}
|
||||||
|
return convert;
|
||||||
|
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean checkEmailUnique(SysUser user) {
|
public boolean checkEmailUnique(SysUser user) {
|
||||||
final TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser)
|
final TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser)
|
||||||
|
@ -161,7 +179,18 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
|
||||||
.where(PredicateBuilder.instance()
|
.where(PredicateBuilder.instance()
|
||||||
.and(tbSysUser.userName.eq(username))
|
.and(tbSysUser.userName.eq(username))
|
||||||
.build()).fetchOne();
|
.build()).fetchOne();
|
||||||
return MapstructUtils.convert(ret, SysUser.class);
|
SysUser convert = MapstructUtils.convert(ret, SysUser.class);
|
||||||
|
Long deptId = ret.getDeptId();
|
||||||
|
if(Objects.nonNull(deptId)){
|
||||||
|
// 获取部门信息
|
||||||
|
SysDept sysDept = sysDeptData.findById(deptId);
|
||||||
|
convert.setDept(sysDept);
|
||||||
|
// 获取角色信息
|
||||||
|
List<SysRole> sysRoles = sysRoleData.findByUserId(ret.getId());
|
||||||
|
|
||||||
|
convert.setRoles(sysRoles);
|
||||||
|
}
|
||||||
|
return convert;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -236,7 +265,7 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Paging<SysUser> findAll(PageRequest<SysUser> pageRequest) {
|
public Paging<SysUser> findAll(PageRequest<SysUser> pageRequest) {
|
||||||
return PageBuilder.toPaging(userRepository.findAll(buildQueryCondition(pageRequest.getData()), PageBuilder.toPageable(pageRequest)));
|
return PageBuilder.toPaging(userRepository.findAll(buildQueryCondition(pageRequest.getData()), PageBuilder.toPageable(pageRequest))).to(SysUser.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -256,15 +285,22 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
|
||||||
}
|
}
|
||||||
|
|
||||||
private Predicate buildQueryCondition(SysUser user) {
|
private Predicate buildQueryCondition(SysUser user) {
|
||||||
List<SysDept> depts = sysDeptData.findByDeptId(user.getDeptId());
|
Long deptId = user.getDeptId();
|
||||||
List<Long> ids = StreamUtils.toList(depts, SysDept::getId);
|
List<Long> ids;
|
||||||
ids.add(user.getDeptId());
|
if(Objects.nonNull(deptId)){
|
||||||
|
List<SysDept> depts = sysDeptData.findByDeptId(deptId);
|
||||||
|
ids = StreamUtils.toList(depts, SysDept::getId);
|
||||||
|
ids.add(deptId);
|
||||||
|
} else {
|
||||||
|
ids = null;
|
||||||
|
}
|
||||||
|
|
||||||
return PredicateBuilder.instance()
|
return PredicateBuilder.instance()
|
||||||
.and(tbSysUser.delFlag.eq(UserConstants.USER_NORMAL))
|
.and(tbSysUser.delFlag.eq(UserConstants.USER_NORMAL))
|
||||||
.and(ObjectUtil.isNotNull(user.getId()), () -> tbSysUser.id.eq(user.getId()))
|
.and(ObjectUtil.isNotNull(user.getId()), () -> tbSysUser.id.eq(user.getId()))
|
||||||
.and(StringUtils.isNotEmpty(user.getUserName()), () -> tbSysUser.userName.like(user.getUserName()))
|
.and(StringUtils.isNotEmpty(user.getUserName()), () -> tbSysUser.userName.like(user.getUserName()))
|
||||||
.and(StringUtils.isNotEmpty(user.getStatus()), () -> tbSysUser.status.eq(user.getStatus()))
|
.and(StringUtils.isNotEmpty(user.getStatus()), () -> tbSysUser.status.eq(user.getStatus()))
|
||||||
.and(StringUtils.isNotEmpty(user.getPhonenumber()), () -> tbSysUser.phonenumber.like(user.getPhonenumber()))
|
.and(StringUtils.isNotEmpty(user.getPhonenumber()), () -> tbSysUser.phonenumber.like(user.getPhonenumber()))
|
||||||
.and(ObjectUtil.isNotNull(user.getDeptId()), () -> tbSysUser.deptId.in(ids)).build();
|
.and(ObjectUtil.isNotEmpty(ids), () -> tbSysUser.deptId.in(ids)).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,13 +123,13 @@ public class SysUserController extends BaseController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据用户编号获取详细信息
|
* 根据用户编号获取详细信息
|
||||||
*
|
*用户ID
|
||||||
* @param userId 用户ID
|
|
||||||
*/
|
*/
|
||||||
@ApiOperation("根据用户编号获取详细信息")
|
@ApiOperation("根据用户编号获取详细信息")
|
||||||
@SaCheckPermission("system:user:query")
|
@SaCheckPermission("system:user:query")
|
||||||
@PostMapping(value = {"/", "/{userId}"})
|
@PostMapping(value = {"/getDetail"})
|
||||||
public SysUserInfoVo getInfo(@PathVariable(value = "userId", required = false) Long userId) {
|
public SysUserInfoVo getInfo(@Validated @RequestBody Request<Long> req) {
|
||||||
|
Long userId = req.getData();
|
||||||
userService.checkUserDataScope(userId);
|
userService.checkUserDataScope(userId);
|
||||||
SysUserInfoVo userInfoVo = new SysUserInfoVo();
|
SysUserInfoVo userInfoVo = new SysUserInfoVo();
|
||||||
List<SysRoleVo> roles = roleService.selectRoleAll();
|
List<SysRoleVo> roles = roleService.selectRoleAll();
|
||||||
|
|
Loading…
Reference in New Issue