refactor:用户服务

V0.5.x
tangfudong 2023-05-31 11:42:58 +08:00
parent 90e95fe247
commit a84987e1ae
40 changed files with 705 additions and 132 deletions

View File

@ -1,8 +1,8 @@
package cc.iotkit.data.system;
import cc.iotkit.data.ICommonData;
import cc.iotkit.common.api.Paging;
import cc.iotkit.data.ICommonData;
import cc.iotkit.model.system.SysDept;
import java.util.List;
@ -44,4 +44,12 @@ public interface ISysDeptData extends ICommonData<SysDept, Long> {
*/
long countByParentId(Long parentId);
/**
* ID
*
* @param deptId ID
* @return
*/
List<SysDept> findByDeptId(Long deptId);
}

View File

@ -3,10 +3,13 @@ package cc.iotkit.data.system;
import cc.iotkit.data.ICommonData;
import cc.iotkit.model.system.SysPost;
import java.util.List;
/**
*
*
* @author sjg
*/
public interface ISysPostData extends ICommonData<SysPost, Long> {
List<Long> selectPostListByUserId(Long userId);
}

View File

@ -1,9 +1,13 @@
package cc.iotkit.data.system;
import cc.iotkit.data.ICommonData;
import cc.iotkit.model.system.SysUser;
/**
*
*
*
* @author sjg
* @author tfd
*/
public interface ISysTenantData {
public interface ISysTenantData extends ICommonData<SysUser, Long> {
}

View File

@ -4,7 +4,7 @@ import cc.iotkit.data.ICommonData;
import cc.iotkit.model.system.SysUser;
/**
*
*
*
* @author sjg
*/
@ -17,5 +17,11 @@ public interface ISysUserData extends ICommonData<SysUser, Long> {
* @return
*/
long countByDeptId(Long deptId);
boolean checkUserNameUnique(SysUser to);
boolean checkPhoneUnique(SysUser to);
boolean checkEmailUnique(SysUser to);
}

View File

@ -1,9 +1,20 @@
package cc.iotkit.data.system;
import cc.iotkit.data.ICommonData;
import cc.iotkit.model.system.SysUserPost;
/**
*
*
*
* @author sjg
*/
public interface ISysUserPostData {
public interface ISysUserPostData extends ICommonData<SysUserPost, Long> {
/**
* id
*
* @param userId id
* @return
*/
int deleteByUserId(Long userId);
}

View File

@ -1,9 +1,19 @@
package cc.iotkit.data.system;
import cc.iotkit.data.ICommonData;
import cc.iotkit.model.system.SysUserRole;
/**
*
*
*
* @author sjg
*/
public interface ISysUserRoleData {
public interface ISysUserRoleData extends ICommonData<SysUserRole, Long> {
/**
* id
*
* @param userId id
* @return
*/
int deleteByUserId(Long userId);
}

View File

@ -15,4 +15,5 @@ import org.springframework.data.querydsl.QuerydslPredicateExecutor;
public interface SysUserPostRepository extends JpaRepository<TbSysUserPost, Long>, QuerydslPredicateExecutor<TbSysUserPost> {
int deleteAllByUserId(Long userId);
}

View File

@ -9,11 +9,10 @@
*/
package cc.iotkit.data.dao;
import cc.iotkit.data.model.TbSysDept;
import cc.iotkit.data.model.TbSysUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
public interface SysUserRepository extends JpaRepository<TbSysUser, Long>, QuerydslPredicateExecutor<TbSysDept> {
public interface SysUserRepository extends JpaRepository<TbSysUser, Long>, QuerydslPredicateExecutor<TbSysUser> {
}

View File

@ -14,5 +14,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
public interface SysUserRoleRepository extends JpaRepository<TbSysUserRole, Long>, QuerydslPredicateExecutor<TbSysUserRole> {
int deleteAllByUserId(Long userId);
}

View File

@ -1,15 +1,15 @@
package cc.iotkit.data.model;
import cc.iotkit.data.model.BaseEntity;
import cc.iotkit.model.system.SysConfig;
import cc.iotkit.model.system.SysDept;
import io.github.linpeilie.annotations.AutoMapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@ -32,8 +32,10 @@ public class TbSysDept extends BaseEntity {
* ID
*/
@Id
@GeneratedValue(generator = "SnowflakeIdGenerator")
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
@ApiModelProperty(value = "部门ID")
private Long deptId;
private Long id;
/**
*

View File

@ -1,11 +1,12 @@
package cc.iotkit.data.model;
import cc.iotkit.data.model.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@ -25,8 +26,10 @@ public class TbSysPost extends BaseEntity {
*
*/
@Id
@GeneratedValue(generator = "SnowflakeIdGenerator")
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
@ApiModelProperty(value = "岗位序号")
private Long postId;
private Long id;
/**
*

View File

@ -1,12 +1,13 @@
package cc.iotkit.data.model;
import cc.iotkit.data.model.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@ -27,8 +28,10 @@ public class TbSysRole extends BaseEntity {
* ID
*/
@Id
@GeneratedValue(generator = "SnowflakeIdGenerator")
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
@ApiModelProperty(value = "角色ID")
private Long roleId;
private Long id;
/**
*
@ -90,8 +93,8 @@ public class TbSysRole extends BaseEntity {
@ApiModelProperty(value = "备注")
private String remark;
public TbSysRole(Long roleId) {
this.roleId = roleId;
public TbSysRole(Long id) {
this.id = id;
}
}

View File

@ -2,8 +2,10 @@ package cc.iotkit.data.model;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@ -19,6 +21,8 @@ import javax.persistence.Table;
public class TbSysRoleDept {
@Id
@GeneratedValue(generator = "SnowflakeIdGenerator")
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
@ApiModelProperty(value = "主键")
private Long id;

View File

@ -2,8 +2,10 @@ package cc.iotkit.data.model;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@ -19,6 +21,8 @@ import javax.persistence.Table;
public class TbSysRoleMenu {
@Id
@GeneratedValue(generator = "SnowflakeIdGenerator")
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
@ApiModelProperty(value = "主键")
private Long id;

View File

@ -1,12 +1,13 @@
package cc.iotkit.data.model;
import cc.iotkit.data.model.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
@ -28,8 +29,10 @@ public class TbSysUser extends BaseEntity {
* ID
*/
@Id
@GeneratedValue(generator = "SnowflakeIdGenerator")
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
@ApiModelProperty(value = "用户ID")
private Long userId;
private Long id;
/**
*
@ -121,8 +124,8 @@ public class TbSysUser extends BaseEntity {
@ApiModelProperty(value = "备注")
private String remark;
public TbSysUser(Long userId) {
this.userId = userId;
public TbSysUser(Long id) {
this.id = id;
}
}

View File

@ -1,10 +1,11 @@
package cc.iotkit.data.model;
import cc.iotkit.data.model.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@ -20,6 +21,8 @@ import javax.persistence.Table;
public class TbSysUserPost extends BaseEntity {
@Id
@GeneratedValue(generator = "SnowflakeIdGenerator")
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
private Long id;
/**

View File

@ -1,10 +1,11 @@
package cc.iotkit.data.model;
import cc.iotkit.data.model.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@ -20,6 +21,8 @@ import javax.persistence.Table;
public class TbSysUserRole extends BaseEntity {
@Id
@GeneratedValue(generator = "SnowflakeIdGenerator")
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
private Long id;
/**

View File

@ -13,19 +13,14 @@ import cc.iotkit.data.system.ISysConfigData;
import cc.iotkit.data.util.PageBuilder;
import cc.iotkit.data.util.PredicateBuilder;
import cc.iotkit.model.system.SysConfig;
import cn.hutool.core.collection.CollUtil;
import com.querydsl.core.types.Predicate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import static cc.iotkit.data.model.QTbSysConfig.tbSysConfig;
@Primary

View File

@ -0,0 +1,69 @@
package cc.iotkit.data.service;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.constant.UserConstants;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.data.dao.SysDeptRepository;
import cc.iotkit.data.system.ISysDeptData;
import cc.iotkit.data.util.PredicateBuilder;
import cc.iotkit.model.system.SysDept;
import cn.hutool.core.util.ObjectUtil;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import static cc.iotkit.data.model.QTbSysDept.tbSysDept;
/**
* @Authortfd
* @Date2023/5/30 13:43
*/
@Primary
@Service
@RequiredArgsConstructor
public class SysDeptDataImpl implements ISysDeptData {
@Autowired
private SysDeptRepository deptRepository;
private final JPAQueryFactory jpaQueryFactory;
@Override
public Paging<SysDept> findByConditions(Long parentId, String deptName, String status, int page, int size) {
return null;
}
@Override
public List<SysDept> findDepts(SysDept dept) {
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.getParentId()), () -> tbSysDept.parentId.eq(dept.getParentId()))
.and(StringUtils.isNotEmpty(dept.getDeptName()), () -> tbSysDept.deptName.like(dept.getDeptName()))
.and(StringUtils.isNotEmpty(dept.getStatus()), () -> tbSysDept.status.eq(dept.getStatus()));
return MapstructUtils.convert(StreamSupport.stream(deptRepository.findAll(predicateBuilder.build()).spliterator(),false).collect(Collectors.toList()),SysDept.class);
}
@Override
public List<SysDept> findByRoleId(Long roleId) {
return null;
}
@Override
public long countByParentId(Long parentId) {
return 0;
}
@Override
public List<SysDept> findByDeptId(Long deptId) {
return MapstructUtils.convert(deptRepository.findAll().stream().filter(o->o.getAncestors().indexOf(deptId.toString())!=-1)
.collect(Collectors.toList()),SysDept.class);
}
}

View File

@ -27,8 +27,8 @@ import java.util.stream.Collectors;
import static cc.iotkit.data.model.QTbSysMenu.tbSysMenu;
import static cc.iotkit.data.model.QTbSysRole.tbSysRole;
import static cc.iotkit.data.model.QTbSysUser.tbSysUser;
import static cc.iotkit.data.model.QTbSysRoleMenu.tbSysRoleMenu;
import static cc.iotkit.data.model.QTbSysUser.tbSysUser;
import static cc.iotkit.data.model.QTbSysUserRole.tbSysUserRole;
@ -128,7 +128,7 @@ public class SysMenuDataImpl implements ISysMenuData {
.from(tbSysMenu)
.leftJoin(tbSysRoleMenu).on(tbSysMenu.menuId.eq(tbSysRoleMenu.menuId))
.leftJoin(tbSysUserRole).on(tbSysRoleMenu.roleId.eq(tbSysUserRole.roleId))
.leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.roleId))
.leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.id))
.where(predicateBuilder
.and(tbSysUserRole.userId.eq(userId))
.build())
@ -145,7 +145,7 @@ public class SysMenuDataImpl implements ISysMenuData {
.from(tbSysMenu)
.leftJoin(tbSysRoleMenu).on(tbSysMenu.menuId.eq(tbSysRoleMenu.menuId))
.leftJoin(tbSysUserRole).on(tbSysRoleMenu.roleId.eq(tbSysUserRole.roleId))
.leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.roleId))
.leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.id))
.where(PredicateBuilder.instance()
.and(tbSysMenu.status.eq("0"))
.and(tbSysRole.status.eq("0"))
@ -184,10 +184,10 @@ public class SysMenuDataImpl implements ISysMenuData {
.from(tbSysMenu)
.leftJoin(tbSysRoleMenu).on(tbSysMenu.menuId.eq(tbSysRoleMenu.menuId))
.leftJoin(tbSysUserRole).on(tbSysRoleMenu.roleId.eq(tbSysUserRole.roleId))
.leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.roleId))
.leftJoin(tbSysUser).on(tbSysUserRole.userId.eq(tbSysUser.userId))
.leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.id))
.leftJoin(tbSysUser).on(tbSysUserRole.userId.eq(tbSysUser.id))
.where(PredicateBuilder.instance()
.and(tbSysUser.userId.eq(userId))
.and(tbSysUser.id.eq(userId))
.and(tbSysMenu.menuType.in("M", "C"))
.and(tbSysMenu.status.eq("0"))
.and(tbSysRole.status.eq("0"))

View File

@ -0,0 +1,49 @@
package cc.iotkit.data.service;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.SysPostRepository;
import cc.iotkit.data.system.ISysPostData;
import cc.iotkit.data.util.PredicateBuilder;
import cc.iotkit.model.system.SysPost;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import java.util.List;
import static cc.iotkit.data.model.QTbSysPost.tbSysPost;
import static cc.iotkit.data.model.QTbSysUser.tbSysUser;
import static cc.iotkit.data.model.QTbSysUserPost.tbSysUserPost;
/**
* @Authortfd
* @Date2023/5/30 18:20
*/
@Primary
@Service
@RequiredArgsConstructor
public class SysPostDataImpl implements ISysPostData {
private SysPostRepository postRepository;
private final JPAQueryFactory jpaQueryFactory;
@Override
public List<SysPost> findAll() {
return MapstructUtils.convert(postRepository.findAll(),SysPost.class);
}
@Override
public List<Long> selectPostListByUserId(Long userId) {
return jpaQueryFactory.select(Projections.bean(Long.class, tbSysPost.id))
.from(tbSysPost)
.leftJoin(tbSysUserPost).on(tbSysUserPost.postId.eq(tbSysPost.id))
.leftJoin(tbSysUser).on(tbSysUser.id.eq(tbSysUserPost.userId))
.where(PredicateBuilder.instance()
.and(tbSysUser.id.eq(userId))
.build()).fetch();
}
}

View File

@ -3,7 +3,6 @@ package cc.iotkit.data.service;
import cc.iotkit.common.constant.UserConstants;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.SysRoleRepository;
import cc.iotkit.data.model.QTbSysRole;
import cc.iotkit.data.model.TbSysRole;
import cc.iotkit.data.system.ISysRoleData;
import cc.iotkit.data.util.PredicateBuilder;
@ -80,10 +79,10 @@ public class SysRoleDataImpl implements ISysRoleData {
@Override
public List<Long> selectRoleListByUserId(Long userId) {
return jpaQueryFactory.select(tbSysRole.roleId).from(tbSysRole)
.leftJoin(tbSysUserRole).on(tbSysUserRole.roleId.eq(tbSysRole.roleId))
.leftJoin(tbSysUser).on(tbSysUser.userId.eq(tbSysUserRole.userId))
.where(PredicateBuilder.instance().and(tbSysUser.userId.eq(userId)).build()).fetch();
return jpaQueryFactory.select(tbSysRole.id).from(tbSysRole)
.leftJoin(tbSysUserRole).on(tbSysUserRole.roleId.eq(tbSysRole.id))
.leftJoin(tbSysUser).on(tbSysUser.id.eq(tbSysUserRole.userId))
.where(PredicateBuilder.instance().and(tbSysUser.id.eq(userId)).build()).fetch();
}
@ -92,7 +91,7 @@ public class SysRoleDataImpl implements ISysRoleData {
final TbSysRole tbSysRoleRes = jpaQueryFactory.select(tbSysRole).from(tbSysRole)
.where(PredicateBuilder.instance()
.and(tbSysRole.roleName.eq(role.getRoleName()))
.and(Objects.nonNull(role.getId()), () -> tbSysRole.roleId.eq(role.getId()))
.and(Objects.nonNull(role.getId()), () -> tbSysRole.id.eq(role.getId()))
.build()).fetchOne();
return Objects.isNull(tbSysRoleRes);
}
@ -102,7 +101,7 @@ public class SysRoleDataImpl implements ISysRoleData {
final TbSysRole tbSysRoleRes = jpaQueryFactory.select(tbSysRole).from(tbSysRole)
.where(PredicateBuilder.instance()
.and(tbSysRole.roleKey.eq(role.getRoleKey()))
.and(Objects.nonNull(role.getId()), () -> tbSysRole.roleId.eq(role.getId()))
.and(Objects.nonNull(role.getId()), () -> tbSysRole.id.eq(role.getId()))
.build()).fetchOne();
return Objects.isNull(tbSysRoleRes);
}
@ -110,7 +109,7 @@ public class SysRoleDataImpl implements ISysRoleData {
@Override
public int updateById(SysRole role) {
long execute = jpaQueryFactory.update(tbSysRole)
.where(PredicateBuilder.instance().and(tbSysRole.roleId.eq(role.getId())).build()).execute();
.where(PredicateBuilder.instance().and(tbSysRole.id.eq(role.getId())).build()).execute();
return Integer.parseInt(execute + "");
}
@ -120,13 +119,13 @@ public class SysRoleDataImpl implements ISysRoleData {
}
private List<SysRole> buildQueryTitle(Predicate predicate) {
return jpaQueryFactory.select(Projections.bean(SysRole.class, tbSysRole.roleId.countDistinct(), tbSysRole.roleName,
return jpaQueryFactory.select(Projections.bean(SysRole.class, tbSysRole.id.countDistinct(), tbSysRole.roleName,
tbSysRole.roleKey, tbSysRole.roleSort, tbSysRole.menuCheckStrictly, tbSysRole.deptCheckStrictly,
tbSysRole.status, tbSysRole.delFlag, tbSysRole.createTime, tbSysRole.remark))
.from(tbSysRole)
.leftJoin(tbSysUserRole).on(tbSysUserRole.roleId.eq(tbSysRole.roleId))
.leftJoin(tbSysUser).on(tbSysUser.userId.eq(tbSysUserRole.userId))
.leftJoin(tbSysDept).on(tbSysUser.deptId.eq(tbSysDept.deptId))
.leftJoin(tbSysUserRole).on(tbSysUserRole.roleId.eq(tbSysRole.id))
.leftJoin(tbSysUser).on(tbSysUser.id.eq(tbSysUserRole.userId))
.leftJoin(tbSysDept).on(tbSysUser.deptId.eq(tbSysDept.id))
.where(predicate)
.orderBy(tbSysRole.roleSort.asc(), tbSysRole.createTime.asc()).fetch();
}
@ -134,7 +133,7 @@ public class SysRoleDataImpl implements ISysRoleData {
private Predicate buildQueryWrapper(SysRole role) {
return PredicateBuilder.instance()
.and(tbSysRole.delFlag.eq(UserConstants.ROLE_NORMAL))
.and(Objects.nonNull(role.getId()), () -> tbSysRole.roleId.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.getStatus()), () -> tbSysRole.roleName.eq(role.getStatus()))
.and(StringUtils.isNotBlank(role.getRoleKey()), () -> tbSysRole.roleKey.like(role.getRoleKey()))

View File

@ -0,0 +1,26 @@
package cc.iotkit.data.service;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.SysTenantRepository;
import cc.iotkit.data.system.ISysTenantData;
import cc.iotkit.model.system.SysUser;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
/**
* @Authortfd
* @Date2023/5/31 9:45
*/
@Primary
@Service
@RequiredArgsConstructor
public class SysTenantDataImpl implements ISysTenantData {
private SysTenantRepository sysTenantRepository;
@Override
public SysUser findById(Long aLong) {
return MapstructUtils.convert(sysTenantRepository.findById(aLong),SysUser.class);
}
}

View File

@ -0,0 +1,152 @@
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.utils.MapstructUtils;
import cc.iotkit.common.utils.StreamUtils;
import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.data.dao.SysUserRepository;
import cc.iotkit.data.model.TbSysUser;
import cc.iotkit.data.system.ISysDeptData;
import cc.iotkit.data.system.ISysUserData;
import cc.iotkit.data.util.PredicateBuilder;
import cc.iotkit.model.system.SysDept;
import cc.iotkit.model.system.SysUser;
import cn.hutool.core.util.ObjectUtil;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import static cc.iotkit.data.model.QTbSysDept.tbSysDept;
import static cc.iotkit.data.model.QTbSysUser.tbSysUser;
/**
* @Authortfd
* @Date2023/5/29 16:00
*/
@Primary
@Service
@RequiredArgsConstructor
public class SysUserDataImpl implements ISysUserData {
private SysUserRepository userRepository;
private ISysDeptData sysDeptData;
private JPAQueryFactory jpaQueryFactory;
@Override
public long countByDeptId(Long aLong) {
return 0;
}
@Override
public boolean checkUserNameUnique(SysUser user) {
final TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser)
.where(PredicateBuilder.instance()
.and(tbSysUser.userName.eq(user.getUserName()))
.and(Objects.nonNull(user.getId()), () -> tbSysUser.id.eq(user.getId()))
.build()).fetchOne();
return Objects.isNull(ret);
}
@Override
public boolean checkPhoneUnique(SysUser user) {
final TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser)
.where(PredicateBuilder.instance()
.and(tbSysUser.phonenumber.eq(user.getPhonenumber()))
.and(Objects.nonNull(user.getId()), () -> tbSysUser.id.eq(user.getId()))
.build()).fetchOne();
return Objects.isNull(ret);
}
@Override
public boolean checkEmailUnique(SysUser user) {
final TbSysUser ret = jpaQueryFactory.select(tbSysUser).from(tbSysUser)
.where(PredicateBuilder.instance()
.and(tbSysUser.email.eq(user.getEmail()))
.and(Objects.nonNull(user.getId()), () -> tbSysUser.id.eq(user.getId()))
.build()).fetchOne();
return Objects.isNull(ret);
}
@Override
public SysUser findById(Long aLong) {
return MapstructUtils.convert(userRepository.findById(aLong),SysUser.class);
}
@Override
public List<SysUser> findByIds(Collection<Long> collection) {
return null;
}
@Override
public SysUser save(SysUser sysUser) {
return MapstructUtils.convert(userRepository.save(MapstructUtils.convert(sysUser,TbSysUser.class)),SysUser.class);
}
@Override
public void batchSave(List<SysUser> list) {
}
@Override
public void deleteById(Long aLong) {
}
@Override
public void deleteByIds(Collection<Long> collection) {
userRepository.deleteAllByIdInBatch(collection);
}
@Override
public long count() {
return userRepository.count();
}
@Override
public List<SysUser> findAll() {
return null;
}
@Override
public Paging<SysUser> findAll(PageRequest<SysUser> pageRequest) {
return null;
}
@Override
public List<SysUser> findAllByCondition(SysUser user) {
List<SysDept> depts = sysDeptData.findByDeptId(user.getDeptId());
List<Long> ids = StreamUtils.toList(depts, SysDept::getId);
ids.add(user.getDeptId());
PredicateBuilder predicateBuilder = PredicateBuilder.instance()
.and(tbSysUser.delFlag.eq(UserConstants.USER_NORMAL))
.and(ObjectUtil.isNotNull(user.getId()), () -> tbSysUser.id.eq(user.getId()))
.and(StringUtils.isNotEmpty(user.getUserName()), () -> tbSysUser.userName.like(user.getUserName()))
.and(StringUtils.isNotEmpty(user.getStatus()), () -> tbSysUser.status.eq(user.getStatus()))
.and(StringUtils.isNotEmpty(user.getPhonenumber()), () -> tbSysUser.phonenumber.like(user.getPhonenumber()))
.and(ObjectUtil.isNotNull(user.getDeptId()), () -> tbSysUser.deptId.in(ids));
List<TbSysUser> users = jpaQueryFactory.select(Projections.bean(TbSysUser.class, tbSysUser.id, tbSysUser.deptId,
tbSysUser.nickName, tbSysUser.userName, tbSysUser.email, tbSysUser.avatar, tbSysUser.phonenumber, tbSysUser.sex,
tbSysUser.status, tbSysUser.delFlag, tbSysUser.loginIp, tbSysUser.loginDate, tbSysUser.createBy, tbSysUser.createTime,
tbSysUser.remark, tbSysDept.deptName, tbSysDept.leader))
.from(tbSysUser)
.leftJoin(tbSysDept).on(tbSysUser.deptId.eq(tbSysDept.id))
.where(predicateBuilder.build()).fetch();
return MapstructUtils.convert(users, SysUser.class);
}
@Override
public SysUser findOneByCondition(SysUser sysUser) {
return null;
}
}

View File

@ -0,0 +1,30 @@
package cc.iotkit.data.service;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.data.dao.SysUserPostRepository;
import cc.iotkit.data.model.TbSysUserPost;
import cc.iotkit.data.system.ISysUserPostData;
import cc.iotkit.model.system.SysUserPost;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
/**
* @Authortfd
* @Date2023/5/30 17:04
*/
public class SysUserPostDataImpl implements ISysUserPostData {
@Autowired
private SysUserPostRepository sysUserPostRepository;
@Override
public int deleteByUserId(Long userId) {
return sysUserPostRepository.deleteAllByUserId(userId);
}
@Override
public void batchSave(List<SysUserPost> data) {
sysUserPostRepository.saveAll(MapstructUtils.convert(data, TbSysUserPost.class));
}
}

View File

@ -0,0 +1,19 @@
package cc.iotkit.data.service;
import cc.iotkit.data.dao.SysUserRoleRepository;
import cc.iotkit.data.system.ISysUserRoleData;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @Authortfd
* @Date2023/5/30 16:36
*/
public class SysUserRoleDataImpl implements ISysUserRoleData {
@Autowired
private SysUserRoleRepository sysUserRoleRepository;
@Override
public int deleteByUserId(Long userId) {
return sysUserRoleRepository.deleteAllByUserId(userId);
}
}

View File

@ -7,9 +7,9 @@ import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.common.web.core.BaseController;
import cc.iotkit.system.dto.bo.SysDeptBo;
import cc.iotkit.system.dto.vo.SysDeptVo;
import cc.iotkit.system.service.ISysDeptService;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.convert.Convert;
import cc.iotkit.system.service.ISysDeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -47,7 +47,7 @@ public class SysDeptController extends BaseController {
@GetMapping("/list/exclude/{deptId}")
public List<SysDeptVo> excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) {
List<SysDeptVo> depts = deptService.selectDeptList(new SysDeptBo());
depts.removeIf(d -> d.getDeptId().equals(deptId)
depts.removeIf(d -> d.getId().equals(deptId)
|| StringUtils.splitList(d.getAncestors()).contains(Convert.toStr(deptId)));
return depts;
}

View File

@ -12,11 +12,11 @@ import cc.iotkit.system.dto.vo.AvatarVo;
import cc.iotkit.system.dto.vo.ProfileVo;
import cc.iotkit.system.dto.vo.SysOssVo;
import cc.iotkit.system.dto.vo.SysUserVo;
import cc.iotkit.system.service.ISysOssService;
import cc.iotkit.system.service.ISysUserService;
import cn.dev33.satoken.secure.BCrypt;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.FileUtil;
import cc.iotkit.system.service.ISysOssService;
import cc.iotkit.system.service.ISysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
@ -65,7 +65,7 @@ public class SysProfileController extends BaseController {
if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
fail("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
}
user.setUserId(LoginHelper.getUserId());
user.setId(LoginHelper.getUserId());
if (userService.updateUserProfile(user) > 0) {
return;
}
@ -90,7 +90,7 @@ public class SysProfileController extends BaseController {
fail("新密码不能与旧密码相同");
}
if (userService.resetUserPwd(user.getUserId(), BCrypt.hashpw(newPassword)) > 0) {
if (userService.resetUserPwd(user.getId(), BCrypt.hashpw(newPassword)) > 0) {
return;
}
fail("修改密码异常,请联系管理员");

View File

@ -1,7 +1,6 @@
package cc.iotkit.system.controller;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.undefined.LoginUser;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.excel.core.ExcelResult;
import cc.iotkit.common.excel.utils.ExcelUtil;
@ -9,21 +8,25 @@ import cc.iotkit.common.log.annotation.Log;
import cc.iotkit.common.log.enums.BusinessType;
import cc.iotkit.common.satoken.utils.LoginHelper;
import cc.iotkit.common.tenant.helper.TenantHelper;
import cc.iotkit.common.undefined.LoginUser;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.utils.StreamUtils;
import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.common.validate.QueryGroup;
import cc.iotkit.common.web.core.BaseController;
import cc.iotkit.system.dto.bo.SysDeptBo;
import cc.iotkit.system.dto.bo.SysUserBo;
import cc.iotkit.system.dto.vo.*;
import cc.iotkit.system.listener.SysUserImportListener;
import cc.iotkit.system.service.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.secure.BCrypt;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import cc.iotkit.system.listener.SysUserImportListener;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -42,6 +45,7 @@ import java.util.List;
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/user")
@Api(tags = "用户信息")
public class SysUserController extends BaseController {
private final ISysUserService userService;
@ -50,22 +54,19 @@ public class SysUserController extends BaseController {
private final ISysDeptService deptService;
private final ISysTenantService tenantService;
/**
*
*/
@ApiOperation("获取用户列表")
@SaCheckPermission("system:user:list")
@GetMapping("/list")
public Paging<SysUserVo> list(SysUserBo user, PageRequest<?> query) {
return userService.selectPageUserList(user, query);
@PostMapping("/list")
public Paging<SysUserVo> list(@RequestBody @Validated(QueryGroup.class) PageRequest<SysUserBo> query) {
return userService.selectPageUserList(query);
}
/**
*
*/
@ApiOperation("导出用户列表")
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
@SaCheckPermission("system:user:export")
@PostMapping("/export")
public void export(SysUserBo user, HttpServletResponse response) {
public void export(@RequestBody @Validated(QueryGroup.class) SysUserBo user,
HttpServletResponse response) {
List<SysUserVo> list = userService.selectUserList(user);
List<SysUserExportVo> listVo = MapstructUtils.convert(list, SysUserExportVo.class);
ExcelUtil.exportExcel(listVo, "用户数据", SysUserExportVo.class, response);
@ -77,6 +78,7 @@ public class SysUserController extends BaseController {
* @param file
* @param updateSupport
*/
@ApiOperation("导入数据")
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
@SaCheckPermission("system:user:import")
@PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ -88,6 +90,7 @@ public class SysUserController extends BaseController {
/**
*
*/
@ApiOperation("获取导入模板")
@PostMapping("/importTemplate")
public void importTemplate(HttpServletResponse response) {
ExcelUtil.exportExcel(new ArrayList<>(), "用户数据", SysUserImportVo.class, response);
@ -98,7 +101,8 @@ public class SysUserController extends BaseController {
*
* @return
*/
@GetMapping("/getInfo")
@ApiOperation("获取用户信息")
@PostMapping("/getInfo")
public UserInfoVo getInfo() {
UserInfoVo userInfoVo = new UserInfoVo();
LoginUser loginUser = LoginHelper.getLoginUser();
@ -118,8 +122,9 @@ public class SysUserController extends BaseController {
*
* @param userId ID
*/
@ApiOperation("根据用户编号获取详细信息")
@SaCheckPermission("system:user:query")
@GetMapping(value = {"/", "/{userId}"})
@PostMapping(value = {"/", "/{userId}"})
public SysUserInfoVo getInfo(@PathVariable(value = "userId", required = false) Long userId) {
userService.checkUserDataScope(userId);
SysUserInfoVo userInfoVo = new SysUserInfoVo();
@ -129,7 +134,7 @@ public class SysUserController extends BaseController {
if (ObjectUtil.isNotNull(userId)) {
SysUserVo sysUser = userService.selectUserById(userId);
userInfoVo.setUser(sysUser);
userInfoVo.setRoleIds(StreamUtils.toList(sysUser.getRoles(), SysRoleVo::getRoleId));
userInfoVo.setRoleIds(StreamUtils.toList(sysUser.getRoles(), SysRoleVo::getId));
userInfoVo.setPostIds(postService.selectPostListByUserId(userId));
}
return userInfoVo;
@ -138,6 +143,7 @@ public class SysUserController extends BaseController {
/**
*
*/
@ApiOperation("新增用户")
@SaCheckPermission("system:user:add")
@Log(title = "用户管理", businessType = BusinessType.INSERT)
@PostMapping
@ -161,12 +167,13 @@ public class SysUserController extends BaseController {
/**
*
*/
@ApiOperation("修改用户")
@SaCheckPermission("system:user:edit")
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping
public void edit(@Validated @RequestBody SysUserBo user) {
userService.checkUserAllowed(user.getUserId());
userService.checkUserDataScope(user.getUserId());
userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getId());
if (!userService.checkUserNameUnique(user)) {
fail("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
} else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
@ -182,6 +189,7 @@ public class SysUserController extends BaseController {
*
* @param userIds ID
*/
@ApiOperation("删除用户")
@SaCheckPermission("system:user:remove")
@Log(title = "用户管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{userIds}")
@ -195,26 +203,28 @@ public class SysUserController extends BaseController {
/**
*
*/
@ApiOperation("重置密码")
@SaCheckPermission("system:user:resetPwd")
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping("/resetPwd")
public void resetPwd(@RequestBody SysUserBo user) {
userService.checkUserAllowed(user.getUserId());
userService.checkUserDataScope(user.getUserId());
userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getId());
user.setPassword(BCrypt.hashpw(user.getPassword()));
userService.resetUserPwd(user.getUserId(), user.getPassword());
userService.resetUserPwd(user.getId(), user.getPassword());
}
/**
*
*/
@ApiOperation("状态修改")
@SaCheckPermission("system:user:edit")
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
@PutMapping("/changeStatus")
public void changeStatus(@RequestBody SysUserBo user) {
userService.checkUserAllowed(user.getUserId());
userService.checkUserDataScope(user.getUserId());
userService.updateUserStatus(user.getUserId(), user.getStatus());
userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getId());
userService.updateUserStatus(user.getId(), user.getStatus());
}
/**
@ -222,6 +232,7 @@ public class SysUserController extends BaseController {
*
* @param userId ID
*/
@ApiOperation("根据用户编号获取授权角色")
@SaCheckPermission("system:user:query")
@GetMapping("/authRole/{userId}")
public SysUserInfoVo authRole(@PathVariable Long userId) {
@ -239,6 +250,7 @@ public class SysUserController extends BaseController {
* @param userId Id
* @param roleIds ID
*/
@ApiOperation("用户授权角色")
@SaCheckPermission("system:user:edit")
@Log(title = "用户管理", businessType = BusinessType.GRANT)
@PutMapping("/authRole")
@ -250,6 +262,7 @@ public class SysUserController extends BaseController {
/**
*
*/
@ApiOperation("获取部门树列表")
@SaCheckPermission("system:user:list")
@GetMapping("/deptTree")
public List<Tree<Long>> deptTree(SysDeptBo dept) {

View File

@ -1,7 +1,7 @@
package cc.iotkit.system.dto.bo;
import cc.iotkit.common.constant.UserConstants;
import cc.iotkit.common.api.BaseDto;
import cc.iotkit.common.constant.UserConstants;
import cc.iotkit.model.system.SysUser;
import io.github.linpeilie.annotations.AutoMapper;
import jakarta.validation.constraints.Email;
@ -9,7 +9,6 @@ import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* sys_user
@ -18,7 +17,6 @@ import lombok.NoArgsConstructor;
*/
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = SysUser.class, reverseConvertGenerate = false)
public class SysUserBo extends BaseDto {
@ -26,7 +24,7 @@ public class SysUserBo extends BaseDto {
/**
* ID
*/
private Long userId;
private Long id;
/**
* ID
@ -99,12 +97,12 @@ public class SysUserBo extends BaseDto {
*/
private Long roleId;
public SysUserBo(Long userId) {
this.userId = userId;
public SysUserBo(Long id) {
this.id = id;
}
public boolean isSuperAdmin() {
return UserConstants.SUPER_ADMIN_ID.equals(this.userId);
return UserConstants.SUPER_ADMIN_ID.equals(this.id);
}
}

View File

@ -26,7 +26,7 @@ public class SysDeptVo implements Serializable {
* id
*/
@ExcelProperty(value = "部门id")
private Long deptId;
private Long id;
/**
* id

View File

@ -28,7 +28,7 @@ public class SysPostVo implements Serializable {
* ID
*/
@ExcelProperty(value = "岗位序号")
private Long postId;
private Long id;
/**
*

View File

@ -27,7 +27,7 @@ public class SysRoleVo implements Serializable {
* ID
*/
@ExcelProperty(value = "角色序号")
private Long roleId;
private Long id;
/**
*
@ -91,7 +91,7 @@ public class SysRoleVo implements Serializable {
private boolean flag = false;
public boolean isSuperAdmin() {
return UserConstants.SUPER_ADMIN_ID.equals(this.roleId);
return UserConstants.SUPER_ADMIN_ID.equals(this.id);
}
}

View File

@ -24,7 +24,7 @@ public class SysUserVo implements Serializable {
/**
* ID
*/
private Long userId;
private Long id;
/**
* ID

View File

@ -9,13 +9,13 @@ import cc.iotkit.common.utils.ValidatorUtils;
import cc.iotkit.system.dto.bo.SysUserBo;
import cc.iotkit.system.dto.vo.SysUserImportVo;
import cc.iotkit.system.dto.vo.SysUserVo;
import cc.iotkit.system.service.ISysConfigService;
import cc.iotkit.system.service.ISysUserService;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.digest.BCrypt;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import cc.iotkit.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
@ -63,12 +63,12 @@ public class SysUserImportListener extends AnalysisEventListener<SysUserImportVo
successNum++;
successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 导入成功");
} else if (isUpdateSupport) {
Long userId = sysUser.getUserId();
Long userId = sysUser.getId();
SysUserBo user = BeanUtil.toBean(userVo, SysUserBo.class);
user.setUserId(userId);
user.setId(userId);
ValidatorUtils.validate(user);
userService.checkUserAllowed(user.getUserId());
userService.checkUserDataScope(user.getUserId());
userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getId());
user.setUpdateBy(operUserId);
userService.updateUser(user);
successNum++;

View File

@ -15,7 +15,7 @@ import java.util.List;
public interface ISysUserService {
Paging<SysUserVo> selectPageUserList(SysUserBo user, PageRequest<?> query);
Paging<SysUserVo> selectPageUserList(PageRequest<SysUserBo> query);
/**
*
@ -108,9 +108,9 @@ public interface ISysUserService {
/**
*
*
* @param userId ID
* @param user
*/
void checkUserAllowed(Long userId);
void checkUserAllowed(SysUserBo user);
/**
*
@ -200,6 +200,6 @@ public interface ISysUserService {
* @param userIds ID
* @return
*/
int deleteUserByIds(Long[] userIds);
void deleteUserByIds(Long[] userIds);
}

View File

@ -7,7 +7,6 @@ import cc.iotkit.common.constant.UserConstants;
import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.redis.utils.CacheUtils;
import cc.iotkit.common.service.ConfigService;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.utils.SpringUtils;
import cc.iotkit.common.utils.StringUtils;
import cc.iotkit.data.system.ISysConfigData;
@ -16,14 +15,13 @@ import cc.iotkit.system.dto.bo.SysConfigBo;
import cc.iotkit.system.dto.vo.SysConfigVo;
import cc.iotkit.system.service.ISysConfigService;
import cn.hutool.core.util.ObjectUtil;
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
*
*

View File

@ -71,7 +71,7 @@ public class SysPostServiceImpl implements ISysPostService {
*/
@Override
public List<Long> selectPostListByUserId(Long userId) {
return new ArrayList<>();
return sysPostData.selectPostListByUserId(userId);
}
/**

View File

@ -2,11 +2,16 @@ package cc.iotkit.system.service.impl;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.constant.CacheNames;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.utils.SpringUtils;
import cc.iotkit.data.system.ISysTenantData;
import cc.iotkit.data.system.ISysUserData;
import cc.iotkit.system.dto.bo.SysTenantBo;
import cc.iotkit.system.dto.vo.SysTenantVo;
import cc.iotkit.system.service.ISysTenantService;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.Collection;
@ -23,14 +28,20 @@ public class SysTenantServiceImpl implements ISysTenantService {
private final ISysTenantData sysTenantData;
private final ISysUserData sysUserData;
@Override
public SysTenantVo queryById(Long id) {
return null;
}
/**
* ID
*/
@Cacheable(cacheNames = CacheNames.SYS_TENANT, key = "#tenantId")
@Override
public SysTenantVo queryByTenantId(String tenantId) {
return null;
return MapstructUtils.convert(sysTenantData.findById(Long.valueOf(tenantId)),SysTenantVo.class);
}
@Override
@ -75,7 +86,14 @@ public class SysTenantServiceImpl implements ISysTenantService {
@Override
public boolean checkAccountBalance(String tenantId) {
return false;
SysTenantVo tenant = SpringUtils.getAopProxy(this).queryByTenantId(tenantId);
// 如果余额为-1代表不限制
if (tenant.getAccountCount() == -1) {
return true;
}
Long userNumber = sysUserData.count();
// 如果余额大于0代表还有可用名额
return tenant.getAccountCount() - userNumber > 0;
}
@Override

View File

@ -2,13 +2,28 @@ package cc.iotkit.system.service.impl;
import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.constant.UserConstants;
import cc.iotkit.common.enums.ErrCode;
import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.satoken.utils.LoginHelper;
import cc.iotkit.common.service.UserService;
import cc.iotkit.common.utils.MapstructUtils;
import cc.iotkit.common.utils.StreamUtils;
import cc.iotkit.data.system.*;
import cc.iotkit.model.system.SysRole;
import cc.iotkit.model.system.SysUser;
import cc.iotkit.model.system.SysUserPost;
import cc.iotkit.model.system.SysUserRole;
import cc.iotkit.system.dto.bo.SysUserBo;
import cc.iotkit.system.dto.vo.SysUserVo;
import cc.iotkit.system.service.ISysUserService;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@ -17,24 +32,43 @@ import java.util.List;
*
* @author Lion Li
*/
@Slf4j
@RequiredArgsConstructor
@Service
public class SysUserServiceImpl implements ISysUserService, UserService {
@Autowired
private ISysUserData sysUserData;
@Autowired
private ISysDeptData sysDeptData;
@Autowired
private ISysRoleData sysRoleData;
@Autowired
private ISysPostData sysPostData;
@Autowired
private ISysUserRoleData sysUserRoleData;
@Autowired
private ISysUserPostData sysUserPostData;
@Override
public String selectUserNameById(Long userId) {
return null;
}
@Override
public Paging<SysUserVo> selectPageUserList(SysUserBo user, PageRequest<?> query) {
return null;
public Paging<SysUserVo> selectPageUserList(PageRequest<SysUserBo> query) {
return sysUserData.findAll(query.to(SysUser.class)).to(SysUserVo.class);
}
@Override
public List<SysUserVo> selectUserList(SysUserBo user) {
return null;
return MapstructUtils.convert(sysUserData.findAllByCondition(user.to(SysUser.class)),SysUserVo.class);
}
@Override
@ -59,7 +93,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Override
public SysUserVo selectUserById(Long userId) {
return null;
return MapstructUtils.convert(sysUserData.findById(userId),SysUserVo.class);
}
@Override
@ -74,32 +108,121 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Override
public boolean checkUserNameUnique(SysUserBo user) {
return false;
boolean exist = sysUserData.checkUserNameUnique(user.to(SysUser.class));
return !exist;
}
@Override
public boolean checkPhoneUnique(SysUserBo user) {
return false;
boolean exist = sysUserData.checkPhoneUnique(user.to(SysUser.class));
return !exist;
}
@Override
public boolean checkEmailUnique(SysUserBo user) {
return false;
boolean exist = sysUserData.checkEmailUnique(user.to(SysUser.class));
return !exist;
}
@Override
public void checkUserAllowed(Long userId) {
public void checkUserAllowed(SysUserBo user) {
if (ObjectUtil.isNotNull(user.getId()) && user.isSuperAdmin()) {
throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION);
}
}
@Override
public void checkUserDataScope(Long userId) {
if (!LoginHelper.isSuperAdmin()) {
SysUser user = new SysUser();
user.setId(userId);
List<SysUser> users = sysUserData.findAllByCondition(user);
if (CollUtil.isEmpty(users)) {
throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION);
}
}
}
@Override
public int insertUser(SysUserBo user) {
return 0;
// 新增用户信息
int rows=sysUserData.save(user.to(SysUser.class))!=null?1:0;
// 新增用户岗位关联
insertUserPost(user,false);
// 新增用户与角色管理
insertUserRole(user, false);
return rows;
}
/**
*
*
* @param user
* @param clear
*/
private void insertUserRole(SysUserBo user, boolean clear) {
this.insertUserRole(user.getId(), user.getRoleIds(), clear);
}
/**
*
*
* @param user
* @param clear
*/
private void insertUserPost(SysUserBo user, boolean clear) {
Long[] posts = user.getPostIds();
if (ArrayUtil.isNotEmpty(posts)) {
if (clear) {
// 删除用户与岗位关联
sysUserPostData.deleteByUserId(user.getId());
}
// 新增用户与岗位管理
List<SysUserPost> list = StreamUtils.toList(List.of(posts), postId -> {
SysUserPost up = new SysUserPost();
up.setUserId(user.getId());
up.setPostId(postId);
return up;
});
sysUserPostData.batchSave(list);
}
}
/**
*
*
* @param userId ID
* @param roleIds
* @param clear
*/
private void insertUserRole(Long userId, Long[] roleIds, boolean clear) {
if (ArrayUtil.isNotEmpty(roleIds)) {
// 判断是否具有此角色的操作权限
List<SysRole> roles = sysRoleData.selectRoleList(new SysRole());
if (CollUtil.isEmpty(roles)) {
throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION);
}
List<Long> roleList = StreamUtils.toList(roles, SysRole::getId);
if (!LoginHelper.isSuperAdmin(userId)) {
roleList.remove(UserConstants.SUPER_ADMIN_ID);
}
List<Long> canDoRoleList = StreamUtils.filter(List.of(roleIds), roleList::contains);
if (CollUtil.isEmpty(canDoRoleList)) {
throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION);
}
if (clear) {
// 删除用户与角色关联
sysUserRoleData.deleteByUserId(userId);
}
// 新增用户与角色管理
List<SysUserRole> list = StreamUtils.toList(canDoRoleList, roleId -> {
SysUserRole ur = new SysUserRole();
ur.setUserId(userId);
ur.setRoleId(roleId);
return ur;
});
sysUserRoleData.batchSave(list);
}
}
@Override
@ -108,18 +231,33 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
}
@Override
@Transactional(rollbackFor = Exception.class)
public int updateUser(SysUserBo user) {
return 0;
// 新增用户与角色管理
insertUserRole(user, true);
// 新增用户与岗位管理
insertUserPost(user, true);
SysUser sysUser = MapstructUtils.convert(user, SysUser.class);
// 防止错误更新后导致的数据误删除
SysUser ret = sysUserData.save(sysUser);
if (ret==null) {
throw new BizException("修改用户" + user.getUserName() + "信息失败");
}
return ret==null?1:0;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void insertUserAuth(Long userId, Long[] roleIds) {
insertUserRole(userId, roleIds, true);
}
@Override
public int updateUserStatus(Long userId, String status) {
return 0;
SysUser user=sysUserData.findById(userId);
user.setStatus(status);
return sysUserData.save(user)!=null?1:0;
}
@Override
@ -134,7 +272,9 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Override
public int resetUserPwd(Long userId, String password) {
return 0;
SysUser user=sysUserData.findById(userId);
user.setPassword(password);
return sysUserData.save(user)!=null?1:0;
}
@Override
@ -143,7 +283,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
}
@Override
public int deleteUserByIds(Long[] userIds) {
return 0;
public void deleteUserByIds(Long[] userIds) {
sysUserData.deleteByIds(List.of(userIds));
}
}