fix:系统管理相关接口报错修复

V0.5.x
xiwa 2023-06-10 23:57:59 +08:00
parent 8e41ad2711
commit 57e26656b4
17 changed files with 138 additions and 124 deletions

View File

@ -6,6 +6,7 @@ import cn.hutool.core.collection.CollUtil;
import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min; import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import java.util.Map; import java.util.Map;
import lombok.*; import lombok.*;
@ -26,78 +27,76 @@ import java.util.Objects;
@Builder @Builder
public class PageRequest<T> extends Request<T> implements Serializable { public class PageRequest<T> extends Request<T> implements Serializable {
/** /**
* *
*/ */
@Min(1) @Min(1)
@NotNull @NotNull
private Integer pageSize; private Integer pageSize;
/** /**
* *
*/ */
@Min(1) @Min(1)
@Max(100) @Max(100)
@NotNull @NotNull
private Integer pageNum; private Integer pageNum;
/** /**
* key valuedescasc * key valuedescasc
*/ */
private Map<String,String> sortMap; private Map<String, String> sortMap;
/**
*
*/
public static final int DEFAULT_PAGE_NUM = 1;
/**
*
*/
public static final int DEFAULT_PAGE_SIZE = 20;
public static <T> PageRequest<T> of(T data) {
/** PageRequest<T> pageRequest = new PageRequest<>();
* pageRequest.setPageSize(DEFAULT_PAGE_SIZE);
*/ pageRequest.setPageNum(DEFAULT_PAGE_NUM);
public static final int DEFAULT_PAGE_NUM = 1; pageRequest.setData(data);
pageRequest.setRequestId(String.valueOf(SnowflakeIdGeneratorUtil.getInstanceSnowflake().nextId()));
/** return pageRequest;
*
*/
public static final int DEFAULT_PAGE_SIZE = 20;
public static <T> PageRequest<T> of(T data) {
PageRequest<T> pageRequest = new PageRequest<>();
pageRequest.setPageSize(DEFAULT_PAGE_SIZE);
pageRequest.setPageNum(DEFAULT_PAGE_NUM);
pageRequest.setData(data);
pageRequest.setRequestId(String.valueOf(SnowflakeIdGeneratorUtil.getInstanceSnowflake().nextId()));
return pageRequest;
}
public static <DTO> PageRequest<DTO> request2PageRequest(Request<DTO> request) {
PageRequest<DTO> pageRequest = new PageRequest<>();
pageRequest.setData(request.getData());
pageRequest.setPageNum(DEFAULT_PAGE_NUM);
pageRequest.setPageSize(DEFAULT_PAGE_SIZE);
pageRequest.setRequestId(request.getRequestId());
return pageRequest;
}
public <DTO> PageRequest<DTO> to(Class<DTO> dtoClass) {
PageRequest<DTO> pageRequest = new PageRequest<>();
if(Objects.nonNull(getData())){
pageRequest.setData(MapstructUtils.convert(getData(), dtoClass));
} }
pageRequest.setPageNum(this.getPageNum());
pageRequest.setPageSize(this.getPageSize());
pageRequest.setRequestId(this.getRequestId());
pageRequest.setSortMap(this.getSortMap());
return pageRequest;
}
public Integer getPageSize() { public static <DTO> PageRequest<DTO> request2PageRequest(Request<DTO> request) {
return pageSize == null ? DEFAULT_PAGE_SIZE : pageSize; PageRequest<DTO> pageRequest = new PageRequest<>();
} pageRequest.setData(request.getData());
pageRequest.setPageNum(DEFAULT_PAGE_NUM);
pageRequest.setPageSize(DEFAULT_PAGE_SIZE);
pageRequest.setRequestId(request.getRequestId());
return pageRequest;
}
public Integer getPageNum() { public <DTO> PageRequest<DTO> to(Class<DTO> dtoClass) {
return pageNum == null ? DEFAULT_PAGE_NUM : pageNum; PageRequest<DTO> pageRequest = new PageRequest<>();
} if (Objects.nonNull(getData())) {
pageRequest.setData(MapstructUtils.convert(getData(), dtoClass));
}
pageRequest.setPageNum(this.getPageNum());
pageRequest.setPageSize(this.getPageSize());
pageRequest.setRequestId(this.getRequestId());
pageRequest.setSortMap(this.getSortMap());
return pageRequest;
}
public Integer getOffset() { public Integer getPageSize() {
return (getPageNum() - 1) * getPageSize(); return pageSize == null ? DEFAULT_PAGE_SIZE : pageSize;
} }
public Integer getPageNum() {
return pageNum == null ? DEFAULT_PAGE_NUM : pageNum;
}
public Integer getOffset() {
return (getPageNum() - 1) * getPageSize();
}
} }

View File

@ -38,6 +38,7 @@ public class BizException extends RuntimeException {
public BizException(String message) { public BizException(String message) {
super(message); super(message);
this.message = message;
this.code = ErrCode.SYSTEM_EXCEPTION.getKey(); this.code = ErrCode.SYSTEM_EXCEPTION.getKey();
} }

View File

@ -13,8 +13,8 @@ import lombok.EqualsAndHashCode;
@Data @Data
public class ViewException extends RuntimeException { public class ViewException extends RuntimeException {
public static final int CODE_FAILED = 0; public static final int CODE_FAILED = 500;
public static final int CODE_WARN = 1; public static final int CODE_WARN = 601;
private int code; private int code;
private String message; private String message;
@ -25,6 +25,7 @@ public class ViewException extends RuntimeException {
public ViewException(String message) { public ViewException(String message) {
super(message); super(message);
this.message = message;
} }
public ViewException(int code, String message) { public ViewException(int code, String message) {

View File

@ -62,7 +62,6 @@ public class SysDeptDataImpl implements ISysDeptData, IJPACommData<SysDept, Long
@Override @Override
public List<SysDept> findDepts(SysDept dept) { public List<SysDept> findDepts(SysDept dept) {
PredicateBuilder predicateBuilder = PredicateBuilder.instance() PredicateBuilder predicateBuilder = PredicateBuilder.instance()
.and(tbSysDept.delFlag.eq(UserConstants.USER_NORMAL))
.and(ObjectUtil.isNotNull(dept.getId()), () -> tbSysDept.id.eq(dept.getId())) .and(ObjectUtil.isNotNull(dept.getId()), () -> tbSysDept.id.eq(dept.getId()))
.and(ObjectUtil.isNotNull(dept.getParentId()), () -> tbSysDept.parentId.eq(dept.getParentId())) .and(ObjectUtil.isNotNull(dept.getParentId()), () -> tbSysDept.parentId.eq(dept.getParentId()))
.and(StringUtils.isNotEmpty(dept.getDeptName()), () -> tbSysDept.deptName.like(dept.getDeptName())) .and(StringUtils.isNotEmpty(dept.getDeptName()), () -> tbSysDept.deptName.like(dept.getDeptName()))

View File

@ -1,7 +1,5 @@
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.constant.UserConstants; import cc.iotkit.common.constant.UserConstants;
import cc.iotkit.common.enums.ErrCode; import cc.iotkit.common.enums.ErrCode;
import cc.iotkit.common.exception.BizException; import cc.iotkit.common.exception.BizException;
@ -112,6 +110,7 @@ public class SysMenuDataImpl implements ISysMenuData, IJPACommData<SysMenu, Long
List<TbSysMenu> tbSysMenuList; List<TbSysMenu> tbSysMenuList;
if (isSuperAdmin) { if (isSuperAdmin) {
tbSysMenuList = jpaQueryFactory.select(tbSysMenu) tbSysMenuList = jpaQueryFactory.select(tbSysMenu)
.from(tbSysMenu)
.where(predicateBuilder.build()) .where(predicateBuilder.build())
.orderBy(tbSysMenu.parentId.asc(), tbSysMenu.orderNum.asc()).fetch(); .orderBy(tbSysMenu.parentId.asc(), tbSysMenu.orderNum.asc()).fetch();
} else { } else {

View File

@ -65,7 +65,12 @@ public class SysOperLogDataImpl implements ISysOperLogData, IJPACommData<SysOper
@Override @Override
public Paging<SysOperLog> findAll(PageRequest<SysOperLog> pageRequest) { public Paging<SysOperLog> findAll(PageRequest<SysOperLog> pageRequest) {
return PageBuilder.toPaging(operLogRepository.findAll(buildQueryCondition(pageRequest.getData()), PageBuilder.toPageable(pageRequest))); return PageBuilder.toPaging(
operLogRepository.findAll(
buildQueryCondition(pageRequest.getData()),
PageBuilder.toPageable(pageRequest))
, SysOperLog.class
);
} }
@Override @Override
@ -75,18 +80,18 @@ public class SysOperLogDataImpl implements ISysOperLogData, IJPACommData<SysOper
@Override @Override
public List<SysOperLog> findAllByCondition(SysOperLog data) { public List<SysOperLog> findAllByCondition(SysOperLog data) {
List<TbSysOperLog> ret=jpaQueryFactory.selectFrom(tbSysOperLog).where(buildQueryCondition(data)) List<TbSysOperLog> ret = jpaQueryFactory.selectFrom(tbSysOperLog).where(buildQueryCondition(data))
.orderBy(tbSysOperLog.id.desc()).fetch(); .orderBy(tbSysOperLog.id.desc()).fetch();
return MapstructUtils.convert(ret, SysOperLog.class); return MapstructUtils.convert(ret, SysOperLog.class);
} }
private Predicate buildQueryCondition(SysOperLog data) { private Predicate buildQueryCondition(SysOperLog data) {
return PredicateBuilder.instance() return PredicateBuilder.instance()
.and(StringUtils.isNotBlank(data.getTitle()),()->tbSysOperLog.title.like(data.getTitle())) .and(StringUtils.isNotBlank(data.getTitle()), () -> tbSysOperLog.title.like(data.getTitle()))
.and(data.getBusinessType()!=null&&data.getBusinessType()>0,()->tbSysOperLog.businessType.eq(data.getBusinessType())) .and(data.getBusinessType() != null && data.getBusinessType() > 0, () -> tbSysOperLog.businessType.eq(data.getBusinessType()))
.and(ArrayUtil.isNotEmpty(data.getBusinessTypes()),()->tbSysOperLog.businessType.in(Arrays.asList(data.getBusinessTypes()))) .and(ArrayUtil.isNotEmpty(data.getBusinessTypes()), () -> tbSysOperLog.businessType.in(Arrays.asList(data.getBusinessTypes())))
.and(data.getStatus() != null && data.getStatus() > 0,()->tbSysOperLog.status.eq(data.getStatus())) .and(data.getStatus() != null && data.getStatus() > 0, () -> tbSysOperLog.status.eq(data.getStatus()))
.and(StringUtils.isNotBlank(data.getOperName()),()->tbSysOperLog.operName.like(data.getOperName())) .and(StringUtils.isNotBlank(data.getOperName()), () -> tbSysOperLog.operName.like(data.getOperName()))
.build(); .build();
} }
} }

View File

@ -57,12 +57,16 @@ public class SysPostDataImpl implements ISysPostData, IJPACommData<SysPost, Long
@Override @Override
public Paging<SysPost> findAll(PageRequest<SysPost> pageRequest) { public Paging<SysPost> findAll(PageRequest<SysPost> pageRequest) {
return PageBuilder.toPaging(postRepository.findAll(buildQueryCondition(pageRequest.getData()), PageBuilder.toPageable(pageRequest))); return PageBuilder.toPaging(
postRepository.findAll(
buildQueryCondition(pageRequest.getData()), PageBuilder.toPageable(pageRequest))
, SysPost.class
);
} }
@Override @Override
public List<Long> selectPostListByUserId(Long userId) { public List<Long> selectPostListByUserId(Long userId) {
return jpaQueryFactory.select( 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))
@ -73,9 +77,9 @@ public class SysPostDataImpl implements ISysPostData, IJPACommData<SysPost, Long
@Override @Override
public List<SysPost> selectPostList(SysPost post) { public List<SysPost> selectPostList(SysPost post) {
List<TbSysPost> ret=jpaQueryFactory.selectFrom(tbSysPost).where(buildQueryCondition(post)) List<TbSysPost> ret = jpaQueryFactory.selectFrom(tbSysPost).where(buildQueryCondition(post))
.orderBy(tbSysPost.postSort.asc()).fetch(); .orderBy(tbSysPost.postSort.asc()).fetch();
return MapstructUtils.convert(ret,SysPost.class); return MapstructUtils.convert(ret, SysPost.class);
} }
@Override @Override
@ -100,8 +104,8 @@ public class SysPostDataImpl implements ISysPostData, IJPACommData<SysPost, Long
private Predicate buildQueryCondition(SysPost post) { private Predicate buildQueryCondition(SysPost post) {
return PredicateBuilder.instance() return PredicateBuilder.instance()
.and(StringUtils.isNotBlank(post.getPostCode()),()->tbSysPost.postCode.like(post.getPostCode())) .and(StringUtils.isNotBlank(post.getPostCode()), () -> tbSysPost.postCode.like(post.getPostCode()))
.and(StringUtils.isNotBlank(post.getPostName()),()->tbSysPost.postName.like(post.getPostName())) .and(StringUtils.isNotBlank(post.getPostName()), () -> tbSysPost.postName.like(post.getPostName()))
.and(StringUtils.isNotBlank(post.getStatus()),()->tbSysPost.status.eq(post.getStatus())).build(); .and(StringUtils.isNotBlank(post.getStatus()), () -> tbSysPost.status.eq(post.getStatus())).build();
} }
} }

View File

@ -135,7 +135,12 @@ public class SysRoleDataImpl implements ISysRoleData, IJPACommData<SysRole, Long
@Override @Override
public Paging<SysRole> findAll(PageRequest<SysRole> pageRequest) { public Paging<SysRole> findAll(PageRequest<SysRole> pageRequest) {
return PageBuilder.toPaging(sysRoleRepository.findAll(buildQueryWrapper(pageRequest.getData()), PageBuilder.toPageable(pageRequest))); return PageBuilder.toPaging(
sysRoleRepository.findAll(
buildQueryWrapper(pageRequest.getData()),
PageBuilder.toPageable(pageRequest))
, SysRole.class
);
} }
@Override @Override
@ -154,8 +159,8 @@ public class SysRoleDataImpl implements ISysRoleData, IJPACommData<SysRole, Long
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,
tbSysRole.status, tbSysRole.delFlag, tbSysRole.createTime, tbSysRole.remark)) tbSysRole.status, tbSysRole.delFlag, tbSysRole.createTime, tbSysRole.remark))
.from(tbSysRole) .from(tbSysRole)
.leftJoin(tbSysUserRole).on(tbSysUserRole.roleId.eq(tbSysRole.id)) .leftJoin(tbSysUserRole).on(tbSysUserRole.roleId.eq(tbSysRole.id))
.leftJoin(tbSysUser).on(tbSysUser.id.eq(tbSysUserRole.userId)) .leftJoin(tbSysUser).on(tbSysUser.id.eq(tbSysUserRole.userId))
@ -166,7 +171,6 @@ public class SysRoleDataImpl implements ISysRoleData, IJPACommData<SysRole, Long
private Predicate buildQueryWrapper(SysRole role) { private Predicate buildQueryWrapper(SysRole role) {
return PredicateBuilder.instance() return PredicateBuilder.instance()
.and(tbSysRole.delFlag.eq(UserConstants.ROLE_NORMAL))
.and(Objects.nonNull(role.getId()), () -> tbSysRole.id.eq(role.getId())) .and(Objects.nonNull(role.getId()), () -> tbSysRole.id.eq(role.getId()))
.and(StringUtils.isNotBlank(role.getRoleName()), () -> tbSysRole.roleName.like(role.getRoleName())) .and(StringUtils.isNotBlank(role.getRoleName()), () -> tbSysRole.roleName.like(role.getRoleName()))
.and(StringUtils.isNotBlank(role.getStatus()), () -> tbSysRole.roleName.eq(role.getStatus())) .and(StringUtils.isNotBlank(role.getStatus()), () -> tbSysRole.roleName.eq(role.getStatus()))

View File

@ -21,7 +21,6 @@ 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;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.Predicate; import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.Projections; import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory; import com.querydsl.jpa.impl.JPAQueryFactory;
@ -75,7 +74,6 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
return SysUser.class; return SysUser.class;
} }
@Override @Override
public long countByDeptId(Long aLong) { public long countByDeptId(Long aLong) {
return 0; return 0;
@ -102,19 +100,20 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
} }
@Override @Override
public SysUser findById(Long id){ public SysUser findById(Long id) {
TbSysUser sysUser = jpaQueryFactory.select(tbSysUser).from(tbSysUser).where(tbSysUser.id.eq(id)).fetchOne(); TbSysUser sysUser = jpaQueryFactory.select(tbSysUser).from(tbSysUser).where(tbSysUser.id.eq(id)).fetchOne();
SysUser convert = MapstructUtils.convert(sysUser, SysUser.class); SysUser convert = MapstructUtils.convert(sysUser, SysUser.class);
List<SysRole> sysRoles = sysRoleData.findByUserId(id); List<SysRole> sysRoles = sysRoleData.findByUserId(id);
convert.setRoles(sysRoles); convert.setRoles(sysRoles);
SysDept dept = sysDeptData.findById(convert.getDeptId()); SysDept dept = sysDeptData.findById(convert.getDeptId());
if(ObjectUtil.isNotNull(dept)){ if (ObjectUtil.isNotNull(dept)) {
convert.setDept(dept); convert.setDept(dept);
} }
return convert; 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)
@ -175,13 +174,13 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
@Override @Override
public SysUser selectUserByUserName(String username) { public SysUser selectUserByUserName(String username) {
TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser) TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser)
.where(PredicateBuilder.instance() .where(PredicateBuilder.instance()
.and(tbSysUser.userName.eq(username)) .and(tbSysUser.userName.eq(username))
.build()).fetchOne(); .build()).fetchOne();
SysUser convert = MapstructUtils.convert(ret, SysUser.class); SysUser convert = MapstructUtils.convert(ret, SysUser.class);
Long deptId = ret.getDeptId(); Long deptId = ret.getDeptId();
if(Objects.nonNull(deptId)){ if (Objects.nonNull(deptId)) {
// 获取部门信息 // 获取部门信息
SysDept sysDept = sysDeptData.findById(deptId); SysDept sysDept = sysDeptData.findById(deptId);
convert.setDept(sysDept); convert.setDept(sysDept);
@ -204,7 +203,7 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
.and(Objects.nonNull(data.getDeptId()), () -> tbSysUser.deptId.eq(data.getDeptId())) .and(Objects.nonNull(data.getDeptId()), () -> tbSysUser.deptId.eq(data.getDeptId()))
.and(tbSysUser.delFlag.eq(UserConstants.ROLE_NORMAL)); .and(tbSysUser.delFlag.eq(UserConstants.ROLE_NORMAL));
QueryResults<TbSysUser> tbSysUserQueryResults = jpaQueryFactory.select(Projections.bean(TbSysUser.class, tbSysUser.id, tbSysUser.deptId, tbSysUser.userName, QueryResults<TbSysUser> tbSysUserQueryResults = jpaQueryFactory.select(Projections.bean(TbSysUser.class, tbSysUser.id, tbSysUser.deptId, tbSysUser.userName,
tbSysUser.nickName, tbSysUser.email, tbSysUser.phonenumber, tbSysUser.createTime)).from(tbSysUser) tbSysUser.nickName, tbSysUser.email, tbSysUser.phonenumber, tbSysUser.createTime)).from(tbSysUser)
.leftJoin(tbSysDept).on(tbSysUser.deptId.eq(tbSysDept.id)) .leftJoin(tbSysDept).on(tbSysUser.deptId.eq(tbSysDept.id))
.leftJoin(tbSysUserRole).on(tbSysUser.id.eq(tbSysUserRole.userId)) .leftJoin(tbSysUserRole).on(tbSysUser.id.eq(tbSysUserRole.userId))
.leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.id)) .leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.id))
@ -234,7 +233,6 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
} }
@Override @Override
public Paging<SysUser> selectUnallocatedList(PageRequest<SysUser> to) { public Paging<SysUser> selectUnallocatedList(PageRequest<SysUser> to) {
//TODO: 未分配用户列表 //TODO: 未分配用户列表
@ -246,7 +244,7 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
.and(Objects.nonNull(data.getDeptId()), () -> tbSysUser.deptId.eq(data.getDeptId())) .and(Objects.nonNull(data.getDeptId()), () -> tbSysUser.deptId.eq(data.getDeptId()))
.and(tbSysUser.delFlag.eq(UserConstants.ROLE_NORMAL)); .and(tbSysUser.delFlag.eq(UserConstants.ROLE_NORMAL));
QueryResults<SysUser> sysUserQueryResults = jpaQueryFactory.select(Projections.bean(SysUser.class, tbSysUser.id, tbSysUser.deptId, tbSysUser.userName, QueryResults<SysUser> sysUserQueryResults = jpaQueryFactory.select(Projections.bean(SysUser.class, tbSysUser.id, tbSysUser.deptId, tbSysUser.userName,
tbSysUser.nickName, tbSysUser.email, tbSysUser.phonenumber, tbSysUser.createTime)).from(tbSysUser) tbSysUser.nickName, tbSysUser.email, tbSysUser.phonenumber, tbSysUser.createTime)).from(tbSysUser)
.leftJoin(tbSysDept).on(tbSysUser.deptId.eq(tbSysDept.id)) .leftJoin(tbSysDept).on(tbSysUser.deptId.eq(tbSysDept.id))
.leftJoin(tbSysUserRole).on(tbSysUser.id.eq(tbSysUserRole.userId)) .leftJoin(tbSysUserRole).on(tbSysUser.id.eq(tbSysUserRole.userId))
.leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.id)) .leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.id))
@ -286,7 +284,7 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
private Predicate buildQueryCondition(SysUser user) { private Predicate buildQueryCondition(SysUser user) {
List<Long> ids; List<Long> ids;
if(Objects.nonNull(user)&&Objects.nonNull(user.getDeptId())){ if (Objects.nonNull(user) && Objects.nonNull(user.getDeptId())) {
Long deptId = user.getDeptId(); Long deptId = user.getDeptId();
List<SysDept> depts = sysDeptData.findByDeptId(deptId); List<SysDept> depts = sysDeptData.findByDeptId(deptId);
ids = StreamUtils.toList(depts, SysDept::getId); ids = StreamUtils.toList(depts, SysDept::getId);
@ -295,7 +293,6 @@ public class SysUserDataImpl implements ISysUserData, IJPACommData<SysUser, Long
ids = null; ids = null;
} }
return PredicateBuilder.instance() return PredicateBuilder.instance()
.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()))

View File

@ -16,7 +16,7 @@ public class BaseController {
} }
public static void fail(String msg) { public static void fail(String msg) {
throw new ViewException(msg); throw new ViewException(ViewException.CODE_FAILED, msg);
} }
public static <T> void fail(T data) { public static <T> void fail(T data) {

View File

@ -10,6 +10,7 @@
package cc.iotkit.common.web.handler; package cc.iotkit.common.web.handler;
import cc.iotkit.common.exception.BizException; import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.exception.ViewException;
import cn.dev33.satoken.exception.NotLoginException; import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotPermissionException; import cn.dev33.satoken.exception.NotPermissionException;
import cn.dev33.satoken.exception.NotRoleException; import cn.dev33.satoken.exception.NotRoleException;
@ -40,11 +41,15 @@ public class GlobalExceptionHandler {
response.setStatus(403); response.setStatus(403);
return new RequestResult(403, "没有权限"); return new RequestResult(403, "没有权限");
} }
if (e instanceof BizException){ if (e instanceof BizException) {
BizException bizException = (BizException) e; BizException bizException = (BizException) e;
response.setStatus(500); response.setStatus(200);
return new RequestResult(bizException.getCode(), bizException.getMessage()); return new RequestResult(bizException.getCode(), bizException.getMessage());
} }
if (e instanceof ViewException) {
response.setStatus(200);
return new RequestResult(((ViewException) e).getCode(), e.getMessage());
}
if (e.getMessage().contains("Unauthorized")) { if (e.getMessage().contains("Unauthorized")) {
response.setStatus(403); response.setStatus(403);

View File

@ -47,7 +47,7 @@ public class SysRoleController extends BaseController {
@ApiOperation(value = "获取角色信息列表", notes = "获取角色信息列表,根据查询条件分页") @ApiOperation(value = "获取角色信息列表", notes = "获取角色信息列表,根据查询条件分页")
@SaCheckPermission("system:role:list") @SaCheckPermission("system:role:list")
@PostMapping("/list") @PostMapping("/list")
public Paging<SysRoleVo> list(PageRequest<SysRoleBo> query) { public Paging<SysRoleVo> list(@RequestBody @Validated PageRequest<SysRoleBo> query) {
return roleService.selectPageRoleList(query); return roleService.selectPageRoleList(query);
} }
@ -140,7 +140,8 @@ public class SysRoleController extends BaseController {
@SaCheckPermission("system:role:edit") @SaCheckPermission("system:role:edit")
@Log(title = "角色管理", businessType = BusinessType.UPDATE) @Log(title = "角色管理", businessType = BusinessType.UPDATE)
@PostMapping("/changeStatus") @PostMapping("/changeStatus")
public void changeStatus(@RequestBody SysRoleBo role) { public void changeStatus(@RequestBody Request<SysRoleBo> bo) {
SysRoleBo role = bo.getData();
roleService.checkRoleAllowed(role.getRoleId()); roleService.checkRoleAllowed(role.getRoleId());
roleService.checkRoleDataScope(role.getRoleId()); roleService.checkRoleDataScope(role.getRoleId());
roleService.updateRoleStatus(role.getRoleId(), role.getStatus()); roleService.updateRoleStatus(role.getRoleId(), role.getStatus());

View File

@ -70,7 +70,7 @@ public class SysUserController extends BaseController {
@PostMapping("/export") @PostMapping("/export")
public void export(@RequestBody @Validated(QueryGroup.class) Request<SysUserBo> req, public void export(@RequestBody @Validated(QueryGroup.class) Request<SysUserBo> req,
HttpServletResponse response) { HttpServletResponse response) {
SysUserBo user=req.getData(); SysUserBo user = req.getData();
List<SysUserVo> list = userService.selectUserList(user); List<SysUserVo> list = userService.selectUserList(user);
List<SysUserExportVo> listVo = MapstructUtils.convert(list, SysUserExportVo.class); List<SysUserExportVo> listVo = MapstructUtils.convert(list, SysUserExportVo.class);
ExcelUtil.exportExcel(listVo, "用户数据", SysUserExportVo.class, response); ExcelUtil.exportExcel(listVo, "用户数据", SysUserExportVo.class, response);
@ -123,13 +123,13 @@ public class SysUserController extends BaseController {
/** /**
* *
*ID * ID
*/ */
@ApiOperation("根据用户编号获取详细信息") @ApiOperation("根据用户编号获取详细信息")
@SaCheckPermission("system:user:query") @SaCheckPermission("system:user:query")
@PostMapping(value = {"/getDetail"}) @PostMapping(value = {"/getDetail"})
public SysUserInfoVo getInfo(@Validated @RequestBody Request<SysUserBo> req) { public SysUserInfoVo getInfo(@Validated @RequestBody Request<Long> req) {
Long userId = req.getData().getId(); 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();
@ -152,7 +152,7 @@ public class SysUserController extends BaseController {
@Log(title = "用户管理", businessType = BusinessType.INSERT) @Log(title = "用户管理", businessType = BusinessType.INSERT)
@PostMapping("/add") @PostMapping("/add")
public void add(@Validated(EditGroup.class) @RequestBody Request<SysUserBo> reqUser) { public void add(@Validated(EditGroup.class) @RequestBody Request<SysUserBo> reqUser) {
SysUserBo user=reqUser.getData(); SysUserBo user = reqUser.getData();
if (!userService.checkUserNameUnique(user)) { if (!userService.checkUserNameUnique(user)) {
fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
@ -177,7 +177,7 @@ public class SysUserController extends BaseController {
@Log(title = "用户管理", businessType = BusinessType.UPDATE) @Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PostMapping("/edit") @PostMapping("/edit")
public void edit(@Validated(EditGroup.class) @RequestBody Request<SysUserBo> reqUser) { public void edit(@Validated(EditGroup.class) @RequestBody Request<SysUserBo> reqUser) {
SysUserBo user=reqUser.getData(); SysUserBo user = reqUser.getData();
userService.checkUserAllowed(user); userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getId()); userService.checkUserDataScope(user.getId());
if (!userService.checkUserNameUnique(user)) { if (!userService.checkUserNameUnique(user)) {
@ -192,7 +192,6 @@ public class SysUserController extends BaseController {
/** /**
* *
*
*/ */
@ApiOperation("删除用户") @ApiOperation("删除用户")
@SaCheckPermission("system:user:remove") @SaCheckPermission("system:user:remove")
@ -200,7 +199,7 @@ public class SysUserController extends BaseController {
@PostMapping("/delete") @PostMapping("/delete")
public void remove(@Validated @RequestBody Request<List<Long>> bo) { public void remove(@Validated @RequestBody Request<List<Long>> bo) {
List<Long> userIds = bo.getData(); List<Long> userIds = bo.getData();
if (userIds.contains( LoginHelper.getUserId())) { if (userIds.contains(LoginHelper.getUserId())) {
fail("当前用户不能删除"); fail("当前用户不能删除");
} }
userService.deleteUserByIds(userIds); userService.deleteUserByIds(userIds);
@ -213,8 +212,8 @@ public class SysUserController extends BaseController {
@SaCheckPermission("system:user:resetPwd") @SaCheckPermission("system:user:resetPwd")
@Log(title = "用户管理", businessType = BusinessType.UPDATE) @Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PostMapping("/resetPwd") @PostMapping("/resetPwd")
public void resetPwd(@RequestBody @Validated(EditGroup.class)Request<SysUserBo> reqUser) { public void resetPwd(@RequestBody @Validated(EditGroup.class) Request<SysUserBo> reqUser) {
SysUserBo user=reqUser.getData(); SysUserBo user = reqUser.getData();
userService.checkUserAllowed(user); userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getId()); userService.checkUserDataScope(user.getId());
user.setPassword(BCrypt.hashpw(user.getPassword())); user.setPassword(BCrypt.hashpw(user.getPassword()));
@ -228,8 +227,8 @@ public class SysUserController extends BaseController {
@SaCheckPermission("system:user:edit") @SaCheckPermission("system:user:edit")
@Log(title = "用户管理", businessType = BusinessType.UPDATE) @Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PostMapping("/changeStatus") @PostMapping("/changeStatus")
public void changeStatus(@RequestBody @Validated(EditGroup.class)Request<SysUserBo> reqUser) { public void changeStatus(@RequestBody @Validated(EditGroup.class) Request<SysUserBo> reqUser) {
SysUserBo user=reqUser.getData(); SysUserBo user = reqUser.getData();
userService.checkUserAllowed(user); userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getId()); userService.checkUserDataScope(user.getId());
userService.updateUserStatus(user.getId(), user.getStatus()); userService.updateUserStatus(user.getId(), user.getStatus());
@ -255,15 +254,15 @@ public class SysUserController extends BaseController {
/** /**
* *
* *
* @param reqUserId Id * @param reqUserId Id
* @param roleIds ID * @param roleIds ID
*/ */
@ApiOperation("用户授权角色") @ApiOperation("用户授权角色")
@SaCheckPermission("system:user:edit") @SaCheckPermission("system:user:edit")
@Log(title = "用户管理", businessType = BusinessType.GRANT) @Log(title = "用户管理", businessType = BusinessType.GRANT)
@PostMapping("/authRole") @PostMapping("/authRole")
public void insertAuthRole(Request<Long> reqUserId, Long[] roleIds) { public void insertAuthRole(Request<Long> reqUserId, Long[] roleIds) {
Long userId=reqUserId.getData(); Long userId = reqUserId.getData();
userService.checkUserDataScope(userId); userService.checkUserDataScope(userId);
userService.insertUserAuth(userId, roleIds); userService.insertUserAuth(userId, roleIds);
} }

View File

@ -23,7 +23,7 @@ public class SysMenuVo implements Serializable {
/** /**
* ID * ID
*/ */
private Long menuId; private Long id;
/** /**
* *

View File

@ -259,7 +259,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
return CollUtil.newArrayList(); return CollUtil.newArrayList();
} }
return TreeBuildUtils.build(menus, (menu, tree) -> return TreeBuildUtils.build(menus, (menu, tree) ->
tree.setId(menu.getMenuId()) tree.setId(menu.getId())
.setParentId(menu.getParentId()) .setParentId(menu.getParentId())
.setName(menu.getMenuName()) .setName(menu.getMenuName())
.setWeight(menu.getOrderNum())); .setWeight(menu.getOrderNum()));

View File

@ -27,7 +27,7 @@ import java.util.List;
@Service @Service
public class SysNoticeServiceImpl implements ISysNoticeService { public class SysNoticeServiceImpl implements ISysNoticeService {
private ISysNoticeData sysNoticeData; private final ISysNoticeData sysNoticeData;
@Override @Override
public Paging<SysNoticeVo> selectPageNoticeList( PageRequest<SysNoticeBo> query) { public Paging<SysNoticeVo> selectPageNoticeList( PageRequest<SysNoticeBo> query) {

View File

@ -11,7 +11,7 @@ spring:
#注: 切换数据库时需要将项目根目录中的.init文件删除再重启 #注: 切换数据库时需要将项目根目录中的.init文件删除再重启
# <<=======内置H2数据库连接设置开始========== # <<=======内置H2数据库连接设置开始==========
jpa: jpa:
# show-sql: true show-sql: true
hibernate: hibernate:
ddl-auto: update ddl-auto: update
properties: properties: