refactor:用户服务
parent
90e95fe247
commit
a84987e1ae
|
@ -1,8 +1,8 @@
|
||||||
package cc.iotkit.data.system;
|
package cc.iotkit.data.system;
|
||||||
|
|
||||||
|
|
||||||
import cc.iotkit.data.ICommonData;
|
|
||||||
import cc.iotkit.common.api.Paging;
|
import cc.iotkit.common.api.Paging;
|
||||||
|
import cc.iotkit.data.ICommonData;
|
||||||
import cc.iotkit.model.system.SysDept;
|
import cc.iotkit.model.system.SysDept;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -44,4 +44,12 @@ public interface ISysDeptData extends ICommonData<SysDept, Long> {
|
||||||
*/
|
*/
|
||||||
long countByParentId(Long parentId);
|
long countByParentId(Long parentId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询所有子部门数(所有状态)
|
||||||
|
*
|
||||||
|
* @param deptId 部门ID
|
||||||
|
* @return 部门列表
|
||||||
|
*/
|
||||||
|
List<SysDept> findByDeptId(Long deptId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,13 @@ package cc.iotkit.data.system;
|
||||||
import cc.iotkit.data.ICommonData;
|
import cc.iotkit.data.ICommonData;
|
||||||
import cc.iotkit.model.system.SysPost;
|
import cc.iotkit.model.system.SysPost;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作日志数据接口
|
* 操作日志数据接口
|
||||||
*
|
*
|
||||||
* @author sjg
|
* @author sjg
|
||||||
*/
|
*/
|
||||||
public interface ISysPostData extends ICommonData<SysPost, Long> {
|
public interface ISysPostData extends ICommonData<SysPost, Long> {
|
||||||
|
List<Long> selectPostListByUserId(Long userId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package cc.iotkit.data.system;
|
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> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import cc.iotkit.data.ICommonData;
|
||||||
import cc.iotkit.model.system.SysUser;
|
import cc.iotkit.model.system.SysUser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作日志数据接口
|
* 用户数据接口
|
||||||
*
|
*
|
||||||
* @author sjg
|
* @author sjg
|
||||||
*/
|
*/
|
||||||
|
@ -17,5 +17,11 @@ public interface ISysUserData extends ICommonData<SysUser, Long> {
|
||||||
* @return 数量
|
* @return 数量
|
||||||
*/
|
*/
|
||||||
long countByDeptId(Long deptId);
|
long countByDeptId(Long deptId);
|
||||||
|
|
||||||
|
|
||||||
|
boolean checkUserNameUnique(SysUser to);
|
||||||
|
|
||||||
|
boolean checkPhoneUnique(SysUser to);
|
||||||
|
|
||||||
|
boolean checkEmailUnique(SysUser to);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,20 @@
|
||||||
package cc.iotkit.data.system;
|
package cc.iotkit.data.system;
|
||||||
|
|
||||||
|
import cc.iotkit.data.ICommonData;
|
||||||
|
import cc.iotkit.model.system.SysUserPost;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作日志数据接口
|
* 用户岗位数据接口
|
||||||
*
|
*
|
||||||
* @author sjg
|
* @author sjg
|
||||||
*/
|
*/
|
||||||
public interface ISysUserPostData {
|
public interface ISysUserPostData extends ICommonData<SysUserPost, Long> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按用户id删除数据
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return 数量
|
||||||
|
*/
|
||||||
|
int deleteByUserId(Long userId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,19 @@
|
||||||
package cc.iotkit.data.system;
|
package cc.iotkit.data.system;
|
||||||
|
|
||||||
|
import cc.iotkit.data.ICommonData;
|
||||||
|
import cc.iotkit.model.system.SysUserRole;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作日志数据接口
|
* 用户角色数据接口
|
||||||
*
|
*
|
||||||
* @author sjg
|
* @author sjg
|
||||||
*/
|
*/
|
||||||
public interface ISysUserRoleData {
|
public interface ISysUserRoleData extends ICommonData<SysUserRole, Long> {
|
||||||
|
/**
|
||||||
|
* 按用户id删除数据
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @return 数量
|
||||||
|
*/
|
||||||
|
int deleteByUserId(Long userId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,4 +15,5 @@ import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||||
|
|
||||||
public interface SysUserPostRepository extends JpaRepository<TbSysUserPost, Long>, QuerydslPredicateExecutor<TbSysUserPost> {
|
public interface SysUserPostRepository extends JpaRepository<TbSysUserPost, Long>, QuerydslPredicateExecutor<TbSysUserPost> {
|
||||||
|
|
||||||
|
int deleteAllByUserId(Long userId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,10 @@
|
||||||
*/
|
*/
|
||||||
package cc.iotkit.data.dao;
|
package cc.iotkit.data.dao;
|
||||||
|
|
||||||
import cc.iotkit.data.model.TbSysDept;
|
|
||||||
import cc.iotkit.data.model.TbSysUser;
|
import cc.iotkit.data.model.TbSysUser;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||||
|
|
||||||
public interface SysUserRepository extends JpaRepository<TbSysUser, Long>, QuerydslPredicateExecutor<TbSysDept> {
|
public interface SysUserRepository extends JpaRepository<TbSysUser, Long>, QuerydslPredicateExecutor<TbSysUser> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,5 +14,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||||
|
|
||||||
public interface SysUserRoleRepository extends JpaRepository<TbSysUserRole, Long>, QuerydslPredicateExecutor<TbSysUserRole> {
|
public interface SysUserRoleRepository extends JpaRepository<TbSysUserRole, Long>, QuerydslPredicateExecutor<TbSysUserRole> {
|
||||||
|
int deleteAllByUserId(Long userId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package cc.iotkit.data.model;
|
package cc.iotkit.data.model;
|
||||||
|
|
||||||
import cc.iotkit.data.model.BaseEntity;
|
|
||||||
import cc.iotkit.model.system.SysConfig;
|
|
||||||
import cc.iotkit.model.system.SysDept;
|
import cc.iotkit.model.system.SysDept;
|
||||||
import io.github.linpeilie.annotations.AutoMapper;
|
import io.github.linpeilie.annotations.AutoMapper;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@ -32,8 +32,10 @@ public class TbSysDept extends BaseEntity {
|
||||||
* 部门ID
|
* 部门ID
|
||||||
*/
|
*/
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(generator = "SnowflakeIdGenerator")
|
||||||
|
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
|
||||||
@ApiModelProperty(value = "部门ID")
|
@ApiModelProperty(value = "部门ID")
|
||||||
private Long deptId;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户编号
|
* 租户编号
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package cc.iotkit.data.model;
|
package cc.iotkit.data.model;
|
||||||
|
|
||||||
import cc.iotkit.data.model.BaseEntity;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@ -25,8 +26,10 @@ public class TbSysPost extends BaseEntity {
|
||||||
* 岗位序号
|
* 岗位序号
|
||||||
*/
|
*/
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(generator = "SnowflakeIdGenerator")
|
||||||
|
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
|
||||||
@ApiModelProperty(value = "岗位序号")
|
@ApiModelProperty(value = "岗位序号")
|
||||||
private Long postId;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户编号
|
* 租户编号
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package cc.iotkit.data.model;
|
package cc.iotkit.data.model;
|
||||||
|
|
||||||
import cc.iotkit.data.model.BaseEntity;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@ -27,8 +28,10 @@ public class TbSysRole extends BaseEntity {
|
||||||
* 角色ID
|
* 角色ID
|
||||||
*/
|
*/
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(generator = "SnowflakeIdGenerator")
|
||||||
|
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
|
||||||
@ApiModelProperty(value = "角色ID")
|
@ApiModelProperty(value = "角色ID")
|
||||||
private Long roleId;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户编号
|
* 租户编号
|
||||||
|
@ -90,8 +93,8 @@ public class TbSysRole extends BaseEntity {
|
||||||
@ApiModelProperty(value = "备注")
|
@ApiModelProperty(value = "备注")
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
public TbSysRole(Long roleId) {
|
public TbSysRole(Long id) {
|
||||||
this.roleId = roleId;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,10 @@ package cc.iotkit.data.model;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@ -19,6 +21,8 @@ import javax.persistence.Table;
|
||||||
public class TbSysRoleDept {
|
public class TbSysRoleDept {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(generator = "SnowflakeIdGenerator")
|
||||||
|
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
|
||||||
@ApiModelProperty(value = "主键")
|
@ApiModelProperty(value = "主键")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,10 @@ package cc.iotkit.data.model;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@ -19,6 +21,8 @@ import javax.persistence.Table;
|
||||||
public class TbSysRoleMenu {
|
public class TbSysRoleMenu {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(generator = "SnowflakeIdGenerator")
|
||||||
|
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
|
||||||
@ApiModelProperty(value = "主键")
|
@ApiModelProperty(value = "主键")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package cc.iotkit.data.model;
|
package cc.iotkit.data.model;
|
||||||
|
|
||||||
import cc.iotkit.data.model.BaseEntity;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -28,8 +29,10 @@ public class TbSysUser extends BaseEntity {
|
||||||
* 用户ID
|
* 用户ID
|
||||||
*/
|
*/
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(generator = "SnowflakeIdGenerator")
|
||||||
|
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
|
||||||
@ApiModelProperty(value = "用户ID")
|
@ApiModelProperty(value = "用户ID")
|
||||||
private Long userId;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户编号
|
* 租户编号
|
||||||
|
@ -121,8 +124,8 @@ public class TbSysUser extends BaseEntity {
|
||||||
@ApiModelProperty(value = "备注")
|
@ApiModelProperty(value = "备注")
|
||||||
private String remark;
|
private String remark;
|
||||||
|
|
||||||
public TbSysUser(Long userId) {
|
public TbSysUser(Long id) {
|
||||||
this.userId = userId;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package cc.iotkit.data.model;
|
package cc.iotkit.data.model;
|
||||||
|
|
||||||
import cc.iotkit.data.model.BaseEntity;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@ -20,6 +21,8 @@ import javax.persistence.Table;
|
||||||
public class TbSysUserPost extends BaseEntity {
|
public class TbSysUserPost extends BaseEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(generator = "SnowflakeIdGenerator")
|
||||||
|
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package cc.iotkit.data.model;
|
package cc.iotkit.data.model;
|
||||||
|
|
||||||
import cc.iotkit.data.model.BaseEntity;
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
@ -20,6 +21,8 @@ import javax.persistence.Table;
|
||||||
public class TbSysUserRole extends BaseEntity {
|
public class TbSysUserRole extends BaseEntity {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
|
@GeneratedValue(generator = "SnowflakeIdGenerator")
|
||||||
|
@GenericGenerator(name = "SnowflakeIdGenerator", strategy = "cc.iotkit.data.config.id.SnowflakeIdGenerator")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -13,19 +13,14 @@ import cc.iotkit.data.system.ISysConfigData;
|
||||||
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.SysConfig;
|
import cc.iotkit.model.system.SysConfig;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import com.querydsl.core.types.Predicate;
|
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 lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.context.annotation.Primary;
|
import org.springframework.context.annotation.Primary;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static cc.iotkit.data.model.QTbSysConfig.tbSysConfig;
|
import static cc.iotkit.data.model.QTbSysConfig.tbSysConfig;
|
||||||
|
|
||||||
@Primary
|
@Primary
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:tfd
|
||||||
|
* @Date:2023/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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,8 +27,8 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static cc.iotkit.data.model.QTbSysMenu.tbSysMenu;
|
import static cc.iotkit.data.model.QTbSysMenu.tbSysMenu;
|
||||||
import static cc.iotkit.data.model.QTbSysRole.tbSysRole;
|
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.QTbSysRoleMenu.tbSysRoleMenu;
|
||||||
|
import static cc.iotkit.data.model.QTbSysUser.tbSysUser;
|
||||||
import static cc.iotkit.data.model.QTbSysUserRole.tbSysUserRole;
|
import static cc.iotkit.data.model.QTbSysUserRole.tbSysUserRole;
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ public class SysMenuDataImpl implements ISysMenuData {
|
||||||
.from(tbSysMenu)
|
.from(tbSysMenu)
|
||||||
.leftJoin(tbSysRoleMenu).on(tbSysMenu.menuId.eq(tbSysRoleMenu.menuId))
|
.leftJoin(tbSysRoleMenu).on(tbSysMenu.menuId.eq(tbSysRoleMenu.menuId))
|
||||||
.leftJoin(tbSysUserRole).on(tbSysRoleMenu.roleId.eq(tbSysUserRole.roleId))
|
.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
|
.where(predicateBuilder
|
||||||
.and(tbSysUserRole.userId.eq(userId))
|
.and(tbSysUserRole.userId.eq(userId))
|
||||||
.build())
|
.build())
|
||||||
|
@ -145,7 +145,7 @@ public class SysMenuDataImpl implements ISysMenuData {
|
||||||
.from(tbSysMenu)
|
.from(tbSysMenu)
|
||||||
.leftJoin(tbSysRoleMenu).on(tbSysMenu.menuId.eq(tbSysRoleMenu.menuId))
|
.leftJoin(tbSysRoleMenu).on(tbSysMenu.menuId.eq(tbSysRoleMenu.menuId))
|
||||||
.leftJoin(tbSysUserRole).on(tbSysRoleMenu.roleId.eq(tbSysUserRole.roleId))
|
.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()
|
.where(PredicateBuilder.instance()
|
||||||
.and(tbSysMenu.status.eq("0"))
|
.and(tbSysMenu.status.eq("0"))
|
||||||
.and(tbSysRole.status.eq("0"))
|
.and(tbSysRole.status.eq("0"))
|
||||||
|
@ -184,10 +184,10 @@ public class SysMenuDataImpl implements ISysMenuData {
|
||||||
.from(tbSysMenu)
|
.from(tbSysMenu)
|
||||||
.leftJoin(tbSysRoleMenu).on(tbSysMenu.menuId.eq(tbSysRoleMenu.menuId))
|
.leftJoin(tbSysRoleMenu).on(tbSysMenu.menuId.eq(tbSysRoleMenu.menuId))
|
||||||
.leftJoin(tbSysUserRole).on(tbSysRoleMenu.roleId.eq(tbSysUserRole.roleId))
|
.leftJoin(tbSysUserRole).on(tbSysRoleMenu.roleId.eq(tbSysUserRole.roleId))
|
||||||
.leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.roleId))
|
.leftJoin(tbSysRole).on(tbSysUserRole.roleId.eq(tbSysRole.id))
|
||||||
.leftJoin(tbSysUser).on(tbSysUserRole.userId.eq(tbSysUser.userId))
|
.leftJoin(tbSysUser).on(tbSysUserRole.userId.eq(tbSysUser.id))
|
||||||
.where(PredicateBuilder.instance()
|
.where(PredicateBuilder.instance()
|
||||||
.and(tbSysUser.userId.eq(userId))
|
.and(tbSysUser.id.eq(userId))
|
||||||
.and(tbSysMenu.menuType.in("M", "C"))
|
.and(tbSysMenu.menuType.in("M", "C"))
|
||||||
.and(tbSysMenu.status.eq("0"))
|
.and(tbSysMenu.status.eq("0"))
|
||||||
.and(tbSysRole.status.eq("0"))
|
.and(tbSysRole.status.eq("0"))
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:tfd
|
||||||
|
* @Date:2023/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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,6 @@ package cc.iotkit.data.service;
|
||||||
import cc.iotkit.common.constant.UserConstants;
|
import cc.iotkit.common.constant.UserConstants;
|
||||||
import cc.iotkit.common.utils.MapstructUtils;
|
import cc.iotkit.common.utils.MapstructUtils;
|
||||||
import cc.iotkit.data.dao.SysRoleRepository;
|
import cc.iotkit.data.dao.SysRoleRepository;
|
||||||
import cc.iotkit.data.model.QTbSysRole;
|
|
||||||
import cc.iotkit.data.model.TbSysRole;
|
import cc.iotkit.data.model.TbSysRole;
|
||||||
import cc.iotkit.data.system.ISysRoleData;
|
import cc.iotkit.data.system.ISysRoleData;
|
||||||
import cc.iotkit.data.util.PredicateBuilder;
|
import cc.iotkit.data.util.PredicateBuilder;
|
||||||
|
@ -80,10 +79,10 @@ public class SysRoleDataImpl implements ISysRoleData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Long> selectRoleListByUserId(Long userId) {
|
public List<Long> selectRoleListByUserId(Long userId) {
|
||||||
return jpaQueryFactory.select(tbSysRole.roleId).from(tbSysRole)
|
return jpaQueryFactory.select(tbSysRole.id).from(tbSysRole)
|
||||||
.leftJoin(tbSysUserRole).on(tbSysUserRole.roleId.eq(tbSysRole.roleId))
|
.leftJoin(tbSysUserRole).on(tbSysUserRole.roleId.eq(tbSysRole.id))
|
||||||
.leftJoin(tbSysUser).on(tbSysUser.userId.eq(tbSysUserRole.userId))
|
.leftJoin(tbSysUser).on(tbSysUser.id.eq(tbSysUserRole.userId))
|
||||||
.where(PredicateBuilder.instance().and(tbSysUser.userId.eq(userId)).build()).fetch();
|
.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)
|
final TbSysRole tbSysRoleRes = jpaQueryFactory.select(tbSysRole).from(tbSysRole)
|
||||||
.where(PredicateBuilder.instance()
|
.where(PredicateBuilder.instance()
|
||||||
.and(tbSysRole.roleName.eq(role.getRoleName()))
|
.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();
|
.build()).fetchOne();
|
||||||
return Objects.isNull(tbSysRoleRes);
|
return Objects.isNull(tbSysRoleRes);
|
||||||
}
|
}
|
||||||
|
@ -102,7 +101,7 @@ public class SysRoleDataImpl implements ISysRoleData {
|
||||||
final TbSysRole tbSysRoleRes = jpaQueryFactory.select(tbSysRole).from(tbSysRole)
|
final TbSysRole tbSysRoleRes = jpaQueryFactory.select(tbSysRole).from(tbSysRole)
|
||||||
.where(PredicateBuilder.instance()
|
.where(PredicateBuilder.instance()
|
||||||
.and(tbSysRole.roleKey.eq(role.getRoleKey()))
|
.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();
|
.build()).fetchOne();
|
||||||
return Objects.isNull(tbSysRoleRes);
|
return Objects.isNull(tbSysRoleRes);
|
||||||
}
|
}
|
||||||
|
@ -110,7 +109,7 @@ public class SysRoleDataImpl implements ISysRoleData {
|
||||||
@Override
|
@Override
|
||||||
public int updateById(SysRole role) {
|
public int updateById(SysRole role) {
|
||||||
long execute = jpaQueryFactory.update(tbSysRole)
|
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 + "");
|
return Integer.parseInt(execute + "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,13 +119,13 @@ public class SysRoleDataImpl implements ISysRoleData {
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SysRole> buildQueryTitle(Predicate predicate) {
|
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.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.roleId))
|
.leftJoin(tbSysUserRole).on(tbSysUserRole.roleId.eq(tbSysRole.id))
|
||||||
.leftJoin(tbSysUser).on(tbSysUser.userId.eq(tbSysUserRole.userId))
|
.leftJoin(tbSysUser).on(tbSysUser.id.eq(tbSysUserRole.userId))
|
||||||
.leftJoin(tbSysDept).on(tbSysUser.deptId.eq(tbSysDept.deptId))
|
.leftJoin(tbSysDept).on(tbSysUser.deptId.eq(tbSysDept.id))
|
||||||
.where(predicate)
|
.where(predicate)
|
||||||
.orderBy(tbSysRole.roleSort.asc(), tbSysRole.createTime.asc()).fetch();
|
.orderBy(tbSysRole.roleSort.asc(), tbSysRole.createTime.asc()).fetch();
|
||||||
}
|
}
|
||||||
|
@ -134,7 +133,7 @@ public class SysRoleDataImpl implements ISysRoleData {
|
||||||
private Predicate buildQueryWrapper(SysRole role) {
|
private Predicate buildQueryWrapper(SysRole role) {
|
||||||
return PredicateBuilder.instance()
|
return PredicateBuilder.instance()
|
||||||
.and(tbSysRole.delFlag.eq(UserConstants.ROLE_NORMAL))
|
.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.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()))
|
||||||
.and(StringUtils.isNotBlank(role.getRoleKey()), () -> tbSysRole.roleKey.like(role.getRoleKey()))
|
.and(StringUtils.isNotBlank(role.getRoleKey()), () -> tbSysRole.roleKey.like(role.getRoleKey()))
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:tfd
|
||||||
|
* @Date:2023/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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:tfd
|
||||||
|
* @Date:2023/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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:tfd
|
||||||
|
* @Date:2023/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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:tfd
|
||||||
|
* @Date:2023/5/30 16:36
|
||||||
|
*/
|
||||||
|
public class SysUserRoleDataImpl implements ISysUserRoleData {
|
||||||
|
@Autowired
|
||||||
|
private SysUserRoleRepository sysUserRoleRepository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteByUserId(Long userId) {
|
||||||
|
return sysUserRoleRepository.deleteAllByUserId(userId);
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,9 +7,9 @@ import cc.iotkit.common.utils.StringUtils;
|
||||||
import cc.iotkit.common.web.core.BaseController;
|
import cc.iotkit.common.web.core.BaseController;
|
||||||
import cc.iotkit.system.dto.bo.SysDeptBo;
|
import cc.iotkit.system.dto.bo.SysDeptBo;
|
||||||
import cc.iotkit.system.dto.vo.SysDeptVo;
|
import cc.iotkit.system.dto.vo.SysDeptVo;
|
||||||
|
import cc.iotkit.system.service.ISysDeptService;
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cc.iotkit.system.service.ISysDeptService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
@ -47,7 +47,7 @@ public class SysDeptController extends BaseController {
|
||||||
@GetMapping("/list/exclude/{deptId}")
|
@GetMapping("/list/exclude/{deptId}")
|
||||||
public List<SysDeptVo> excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) {
|
public List<SysDeptVo> excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) {
|
||||||
List<SysDeptVo> depts = deptService.selectDeptList(new SysDeptBo());
|
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)));
|
|| StringUtils.splitList(d.getAncestors()).contains(Convert.toStr(deptId)));
|
||||||
return depts;
|
return depts;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,11 @@ import cc.iotkit.system.dto.vo.AvatarVo;
|
||||||
import cc.iotkit.system.dto.vo.ProfileVo;
|
import cc.iotkit.system.dto.vo.ProfileVo;
|
||||||
import cc.iotkit.system.dto.vo.SysOssVo;
|
import cc.iotkit.system.dto.vo.SysOssVo;
|
||||||
import cc.iotkit.system.dto.vo.SysUserVo;
|
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.dev33.satoken.secure.BCrypt;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cc.iotkit.system.service.ISysOssService;
|
|
||||||
import cc.iotkit.system.service.ISysUserService;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
@ -65,7 +65,7 @@ public class SysProfileController extends BaseController {
|
||||||
if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
|
if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
|
||||||
fail("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
fail("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
|
||||||
}
|
}
|
||||||
user.setUserId(LoginHelper.getUserId());
|
user.setId(LoginHelper.getUserId());
|
||||||
if (userService.updateUserProfile(user) > 0) {
|
if (userService.updateUserProfile(user) > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ public class SysProfileController extends BaseController {
|
||||||
fail("新密码不能与旧密码相同");
|
fail("新密码不能与旧密码相同");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userService.resetUserPwd(user.getUserId(), BCrypt.hashpw(newPassword)) > 0) {
|
if (userService.resetUserPwd(user.getId(), BCrypt.hashpw(newPassword)) > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fail("修改密码异常,请联系管理员");
|
fail("修改密码异常,请联系管理员");
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package cc.iotkit.system.controller;
|
package cc.iotkit.system.controller;
|
||||||
|
|
||||||
import cc.iotkit.common.api.PageRequest;
|
import cc.iotkit.common.api.PageRequest;
|
||||||
import cc.iotkit.common.undefined.LoginUser;
|
|
||||||
import cc.iotkit.common.api.Paging;
|
import cc.iotkit.common.api.Paging;
|
||||||
import cc.iotkit.common.excel.core.ExcelResult;
|
import cc.iotkit.common.excel.core.ExcelResult;
|
||||||
import cc.iotkit.common.excel.utils.ExcelUtil;
|
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.log.enums.BusinessType;
|
||||||
import cc.iotkit.common.satoken.utils.LoginHelper;
|
import cc.iotkit.common.satoken.utils.LoginHelper;
|
||||||
import cc.iotkit.common.tenant.helper.TenantHelper;
|
import cc.iotkit.common.tenant.helper.TenantHelper;
|
||||||
|
import cc.iotkit.common.undefined.LoginUser;
|
||||||
import cc.iotkit.common.utils.MapstructUtils;
|
import cc.iotkit.common.utils.MapstructUtils;
|
||||||
import cc.iotkit.common.utils.StreamUtils;
|
import cc.iotkit.common.utils.StreamUtils;
|
||||||
import cc.iotkit.common.utils.StringUtils;
|
import cc.iotkit.common.utils.StringUtils;
|
||||||
|
import cc.iotkit.common.validate.QueryGroup;
|
||||||
import cc.iotkit.common.web.core.BaseController;
|
import cc.iotkit.common.web.core.BaseController;
|
||||||
import cc.iotkit.system.dto.bo.SysDeptBo;
|
import cc.iotkit.system.dto.bo.SysDeptBo;
|
||||||
import cc.iotkit.system.dto.bo.SysUserBo;
|
import cc.iotkit.system.dto.bo.SysUserBo;
|
||||||
import cc.iotkit.system.dto.vo.*;
|
import cc.iotkit.system.dto.vo.*;
|
||||||
|
import cc.iotkit.system.listener.SysUserImportListener;
|
||||||
import cc.iotkit.system.service.*;
|
import cc.iotkit.system.service.*;
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||||
import cn.dev33.satoken.secure.BCrypt;
|
import cn.dev33.satoken.secure.BCrypt;
|
||||||
import cn.hutool.core.lang.tree.Tree;
|
import cn.hutool.core.lang.tree.Tree;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import cc.iotkit.system.listener.SysUserImportListener;
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
@ -42,6 +45,7 @@ import java.util.List;
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/system/user")
|
@RequestMapping("/system/user")
|
||||||
|
@Api(tags = "用户信息")
|
||||||
public class SysUserController extends BaseController {
|
public class SysUserController extends BaseController {
|
||||||
|
|
||||||
private final ISysUserService userService;
|
private final ISysUserService userService;
|
||||||
|
@ -50,22 +54,19 @@ public class SysUserController extends BaseController {
|
||||||
private final ISysDeptService deptService;
|
private final ISysDeptService deptService;
|
||||||
private final ISysTenantService tenantService;
|
private final ISysTenantService tenantService;
|
||||||
|
|
||||||
/**
|
@ApiOperation("获取用户列表")
|
||||||
* 获取用户列表
|
|
||||||
*/
|
|
||||||
@SaCheckPermission("system:user:list")
|
@SaCheckPermission("system:user:list")
|
||||||
@GetMapping("/list")
|
@PostMapping("/list")
|
||||||
public Paging<SysUserVo> list(SysUserBo user, PageRequest<?> query) {
|
public Paging<SysUserVo> list(@RequestBody @Validated(QueryGroup.class) PageRequest<SysUserBo> query) {
|
||||||
return userService.selectPageUserList(user, query);
|
return userService.selectPageUserList(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@ApiOperation("导出用户列表")
|
||||||
* 导出用户列表
|
|
||||||
*/
|
|
||||||
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
@Log(title = "用户管理", businessType = BusinessType.EXPORT)
|
||||||
@SaCheckPermission("system:user:export")
|
@SaCheckPermission("system:user:export")
|
||||||
@PostMapping("/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<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);
|
||||||
|
@ -77,6 +78,7 @@ public class SysUserController extends BaseController {
|
||||||
* @param file 导入文件
|
* @param file 导入文件
|
||||||
* @param updateSupport 是否更新已存在数据
|
* @param updateSupport 是否更新已存在数据
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation("导入数据")
|
||||||
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
@Log(title = "用户管理", businessType = BusinessType.IMPORT)
|
||||||
@SaCheckPermission("system:user:import")
|
@SaCheckPermission("system:user:import")
|
||||||
@PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
@PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
@ -88,6 +90,7 @@ public class SysUserController extends BaseController {
|
||||||
/**
|
/**
|
||||||
* 获取导入模板
|
* 获取导入模板
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation("获取导入模板")
|
||||||
@PostMapping("/importTemplate")
|
@PostMapping("/importTemplate")
|
||||||
public void importTemplate(HttpServletResponse response) {
|
public void importTemplate(HttpServletResponse response) {
|
||||||
ExcelUtil.exportExcel(new ArrayList<>(), "用户数据", SysUserImportVo.class, response);
|
ExcelUtil.exportExcel(new ArrayList<>(), "用户数据", SysUserImportVo.class, response);
|
||||||
|
@ -98,7 +101,8 @@ public class SysUserController extends BaseController {
|
||||||
*
|
*
|
||||||
* @return 用户信息
|
* @return 用户信息
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getInfo")
|
@ApiOperation("获取用户信息")
|
||||||
|
@PostMapping("/getInfo")
|
||||||
public UserInfoVo getInfo() {
|
public UserInfoVo getInfo() {
|
||||||
UserInfoVo userInfoVo = new UserInfoVo();
|
UserInfoVo userInfoVo = new UserInfoVo();
|
||||||
LoginUser loginUser = LoginHelper.getLoginUser();
|
LoginUser loginUser = LoginHelper.getLoginUser();
|
||||||
|
@ -118,8 +122,9 @@ public class SysUserController extends BaseController {
|
||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation("根据用户编号获取详细信息")
|
||||||
@SaCheckPermission("system:user:query")
|
@SaCheckPermission("system:user:query")
|
||||||
@GetMapping(value = {"/", "/{userId}"})
|
@PostMapping(value = {"/", "/{userId}"})
|
||||||
public SysUserInfoVo getInfo(@PathVariable(value = "userId", required = false) Long userId) {
|
public SysUserInfoVo getInfo(@PathVariable(value = "userId", required = false) Long userId) {
|
||||||
userService.checkUserDataScope(userId);
|
userService.checkUserDataScope(userId);
|
||||||
SysUserInfoVo userInfoVo = new SysUserInfoVo();
|
SysUserInfoVo userInfoVo = new SysUserInfoVo();
|
||||||
|
@ -129,7 +134,7 @@ public class SysUserController extends BaseController {
|
||||||
if (ObjectUtil.isNotNull(userId)) {
|
if (ObjectUtil.isNotNull(userId)) {
|
||||||
SysUserVo sysUser = userService.selectUserById(userId);
|
SysUserVo sysUser = userService.selectUserById(userId);
|
||||||
userInfoVo.setUser(sysUser);
|
userInfoVo.setUser(sysUser);
|
||||||
userInfoVo.setRoleIds(StreamUtils.toList(sysUser.getRoles(), SysRoleVo::getRoleId));
|
userInfoVo.setRoleIds(StreamUtils.toList(sysUser.getRoles(), SysRoleVo::getId));
|
||||||
userInfoVo.setPostIds(postService.selectPostListByUserId(userId));
|
userInfoVo.setPostIds(postService.selectPostListByUserId(userId));
|
||||||
}
|
}
|
||||||
return userInfoVo;
|
return userInfoVo;
|
||||||
|
@ -138,6 +143,7 @@ public class SysUserController extends BaseController {
|
||||||
/**
|
/**
|
||||||
* 新增用户
|
* 新增用户
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation("新增用户")
|
||||||
@SaCheckPermission("system:user:add")
|
@SaCheckPermission("system:user:add")
|
||||||
@Log(title = "用户管理", businessType = BusinessType.INSERT)
|
@Log(title = "用户管理", businessType = BusinessType.INSERT)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
|
@ -161,12 +167,13 @@ public class SysUserController extends BaseController {
|
||||||
/**
|
/**
|
||||||
* 修改用户
|
* 修改用户
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation("修改用户")
|
||||||
@SaCheckPermission("system:user:edit")
|
@SaCheckPermission("system:user:edit")
|
||||||
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping
|
@PutMapping
|
||||||
public void edit(@Validated @RequestBody SysUserBo user) {
|
public void edit(@Validated @RequestBody SysUserBo user) {
|
||||||
userService.checkUserAllowed(user.getUserId());
|
userService.checkUserAllowed(user);
|
||||||
userService.checkUserDataScope(user.getUserId());
|
userService.checkUserDataScope(user.getId());
|
||||||
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)) {
|
||||||
|
@ -182,6 +189,7 @@ public class SysUserController extends BaseController {
|
||||||
*
|
*
|
||||||
* @param userIds 角色ID串
|
* @param userIds 角色ID串
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation("删除用户")
|
||||||
@SaCheckPermission("system:user:remove")
|
@SaCheckPermission("system:user:remove")
|
||||||
@Log(title = "用户管理", businessType = BusinessType.DELETE)
|
@Log(title = "用户管理", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{userIds}")
|
@DeleteMapping("/{userIds}")
|
||||||
|
@ -195,26 +203,28 @@ public class SysUserController extends BaseController {
|
||||||
/**
|
/**
|
||||||
* 重置密码
|
* 重置密码
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation("重置密码")
|
||||||
@SaCheckPermission("system:user:resetPwd")
|
@SaCheckPermission("system:user:resetPwd")
|
||||||
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping("/resetPwd")
|
@PutMapping("/resetPwd")
|
||||||
public void resetPwd(@RequestBody SysUserBo user) {
|
public void resetPwd(@RequestBody SysUserBo user) {
|
||||||
userService.checkUserAllowed(user.getUserId());
|
userService.checkUserAllowed(user);
|
||||||
userService.checkUserDataScope(user.getUserId());
|
userService.checkUserDataScope(user.getId());
|
||||||
user.setPassword(BCrypt.hashpw(user.getPassword()));
|
user.setPassword(BCrypt.hashpw(user.getPassword()));
|
||||||
userService.resetUserPwd(user.getUserId(), user.getPassword());
|
userService.resetUserPwd(user.getId(), user.getPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 状态修改
|
* 状态修改
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation("状态修改")
|
||||||
@SaCheckPermission("system:user:edit")
|
@SaCheckPermission("system:user:edit")
|
||||||
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
@Log(title = "用户管理", businessType = BusinessType.UPDATE)
|
||||||
@PutMapping("/changeStatus")
|
@PutMapping("/changeStatus")
|
||||||
public void changeStatus(@RequestBody SysUserBo user) {
|
public void changeStatus(@RequestBody SysUserBo user) {
|
||||||
userService.checkUserAllowed(user.getUserId());
|
userService.checkUserAllowed(user);
|
||||||
userService.checkUserDataScope(user.getUserId());
|
userService.checkUserDataScope(user.getId());
|
||||||
userService.updateUserStatus(user.getUserId(), user.getStatus());
|
userService.updateUserStatus(user.getId(), user.getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -222,6 +232,7 @@ public class SysUserController extends BaseController {
|
||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation("根据用户编号获取授权角色")
|
||||||
@SaCheckPermission("system:user:query")
|
@SaCheckPermission("system:user:query")
|
||||||
@GetMapping("/authRole/{userId}")
|
@GetMapping("/authRole/{userId}")
|
||||||
public SysUserInfoVo authRole(@PathVariable Long userId) {
|
public SysUserInfoVo authRole(@PathVariable Long userId) {
|
||||||
|
@ -239,6 +250,7 @@ public class SysUserController extends BaseController {
|
||||||
* @param userId 用户Id
|
* @param userId 用户Id
|
||||||
* @param roleIds 角色ID串
|
* @param roleIds 角色ID串
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation("用户授权角色")
|
||||||
@SaCheckPermission("system:user:edit")
|
@SaCheckPermission("system:user:edit")
|
||||||
@Log(title = "用户管理", businessType = BusinessType.GRANT)
|
@Log(title = "用户管理", businessType = BusinessType.GRANT)
|
||||||
@PutMapping("/authRole")
|
@PutMapping("/authRole")
|
||||||
|
@ -250,6 +262,7 @@ public class SysUserController extends BaseController {
|
||||||
/**
|
/**
|
||||||
* 获取部门树列表
|
* 获取部门树列表
|
||||||
*/
|
*/
|
||||||
|
@ApiOperation("获取部门树列表")
|
||||||
@SaCheckPermission("system:user:list")
|
@SaCheckPermission("system:user:list")
|
||||||
@GetMapping("/deptTree")
|
@GetMapping("/deptTree")
|
||||||
public List<Tree<Long>> deptTree(SysDeptBo dept) {
|
public List<Tree<Long>> deptTree(SysDeptBo dept) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package cc.iotkit.system.dto.bo;
|
package cc.iotkit.system.dto.bo;
|
||||||
|
|
||||||
import cc.iotkit.common.constant.UserConstants;
|
|
||||||
import cc.iotkit.common.api.BaseDto;
|
import cc.iotkit.common.api.BaseDto;
|
||||||
|
import cc.iotkit.common.constant.UserConstants;
|
||||||
import cc.iotkit.model.system.SysUser;
|
import cc.iotkit.model.system.SysUser;
|
||||||
import io.github.linpeilie.annotations.AutoMapper;
|
import io.github.linpeilie.annotations.AutoMapper;
|
||||||
import jakarta.validation.constraints.Email;
|
import jakarta.validation.constraints.Email;
|
||||||
|
@ -9,7 +9,6 @@ import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户信息业务对象 sys_user
|
* 用户信息业务对象 sys_user
|
||||||
|
@ -18,7 +17,6 @@ import lombok.NoArgsConstructor;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@AutoMapper(target = SysUser.class, reverseConvertGenerate = false)
|
@AutoMapper(target = SysUser.class, reverseConvertGenerate = false)
|
||||||
public class SysUserBo extends BaseDto {
|
public class SysUserBo extends BaseDto {
|
||||||
|
@ -26,7 +24,7 @@ public class SysUserBo extends BaseDto {
|
||||||
/**
|
/**
|
||||||
* 用户ID
|
* 用户ID
|
||||||
*/
|
*/
|
||||||
private Long userId;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 部门ID
|
* 部门ID
|
||||||
|
@ -99,12 +97,12 @@ public class SysUserBo extends BaseDto {
|
||||||
*/
|
*/
|
||||||
private Long roleId;
|
private Long roleId;
|
||||||
|
|
||||||
public SysUserBo(Long userId) {
|
public SysUserBo(Long id) {
|
||||||
this.userId = userId;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSuperAdmin() {
|
public boolean isSuperAdmin() {
|
||||||
return UserConstants.SUPER_ADMIN_ID.equals(this.userId);
|
return UserConstants.SUPER_ADMIN_ID.equals(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class SysDeptVo implements Serializable {
|
||||||
* 部门id
|
* 部门id
|
||||||
*/
|
*/
|
||||||
@ExcelProperty(value = "部门id")
|
@ExcelProperty(value = "部门id")
|
||||||
private Long deptId;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 父部门id
|
* 父部门id
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class SysPostVo implements Serializable {
|
||||||
* 岗位ID
|
* 岗位ID
|
||||||
*/
|
*/
|
||||||
@ExcelProperty(value = "岗位序号")
|
@ExcelProperty(value = "岗位序号")
|
||||||
private Long postId;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 岗位编码
|
* 岗位编码
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class SysRoleVo implements Serializable {
|
||||||
* 角色ID
|
* 角色ID
|
||||||
*/
|
*/
|
||||||
@ExcelProperty(value = "角色序号")
|
@ExcelProperty(value = "角色序号")
|
||||||
private Long roleId;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色名称
|
* 角色名称
|
||||||
|
@ -91,7 +91,7 @@ public class SysRoleVo implements Serializable {
|
||||||
private boolean flag = false;
|
private boolean flag = false;
|
||||||
|
|
||||||
public boolean isSuperAdmin() {
|
public boolean isSuperAdmin() {
|
||||||
return UserConstants.SUPER_ADMIN_ID.equals(this.roleId);
|
return UserConstants.SUPER_ADMIN_ID.equals(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class SysUserVo implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 用户ID
|
* 用户ID
|
||||||
*/
|
*/
|
||||||
private Long userId;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户ID
|
* 租户ID
|
||||||
|
|
|
@ -9,13 +9,13 @@ import cc.iotkit.common.utils.ValidatorUtils;
|
||||||
import cc.iotkit.system.dto.bo.SysUserBo;
|
import cc.iotkit.system.dto.bo.SysUserBo;
|
||||||
import cc.iotkit.system.dto.vo.SysUserImportVo;
|
import cc.iotkit.system.dto.vo.SysUserImportVo;
|
||||||
import cc.iotkit.system.dto.vo.SysUserVo;
|
import cc.iotkit.system.dto.vo.SysUserVo;
|
||||||
|
import cc.iotkit.system.service.ISysConfigService;
|
||||||
import cc.iotkit.system.service.ISysUserService;
|
import cc.iotkit.system.service.ISysUserService;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.crypto.digest.BCrypt;
|
import cn.hutool.crypto.digest.BCrypt;
|
||||||
import com.alibaba.excel.context.AnalysisContext;
|
import com.alibaba.excel.context.AnalysisContext;
|
||||||
import com.alibaba.excel.event.AnalysisEventListener;
|
import com.alibaba.excel.event.AnalysisEventListener;
|
||||||
import cc.iotkit.system.service.ISysConfigService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -63,12 +63,12 @@ public class SysUserImportListener extends AnalysisEventListener<SysUserImportVo
|
||||||
successNum++;
|
successNum++;
|
||||||
successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 导入成功");
|
successMsg.append("<br/>").append(successNum).append("、账号 ").append(user.getUserName()).append(" 导入成功");
|
||||||
} else if (isUpdateSupport) {
|
} else if (isUpdateSupport) {
|
||||||
Long userId = sysUser.getUserId();
|
Long userId = sysUser.getId();
|
||||||
SysUserBo user = BeanUtil.toBean(userVo, SysUserBo.class);
|
SysUserBo user = BeanUtil.toBean(userVo, SysUserBo.class);
|
||||||
user.setUserId(userId);
|
user.setId(userId);
|
||||||
ValidatorUtils.validate(user);
|
ValidatorUtils.validate(user);
|
||||||
userService.checkUserAllowed(user.getUserId());
|
userService.checkUserAllowed(user);
|
||||||
userService.checkUserDataScope(user.getUserId());
|
userService.checkUserDataScope(user.getId());
|
||||||
user.setUpdateBy(operUserId);
|
user.setUpdateBy(operUserId);
|
||||||
userService.updateUser(user);
|
userService.updateUser(user);
|
||||||
successNum++;
|
successNum++;
|
||||||
|
|
|
@ -15,7 +15,7 @@ import java.util.List;
|
||||||
public interface ISysUserService {
|
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
|
* @param userIds 需要删除的用户ID
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
int deleteUserByIds(Long[] userIds);
|
void deleteUserByIds(Long[] userIds);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import cc.iotkit.common.constant.UserConstants;
|
||||||
import cc.iotkit.common.exception.BizException;
|
import cc.iotkit.common.exception.BizException;
|
||||||
import cc.iotkit.common.redis.utils.CacheUtils;
|
import cc.iotkit.common.redis.utils.CacheUtils;
|
||||||
import cc.iotkit.common.service.ConfigService;
|
import cc.iotkit.common.service.ConfigService;
|
||||||
import cc.iotkit.common.utils.MapstructUtils;
|
|
||||||
import cc.iotkit.common.utils.SpringUtils;
|
import cc.iotkit.common.utils.SpringUtils;
|
||||||
import cc.iotkit.common.utils.StringUtils;
|
import cc.iotkit.common.utils.StringUtils;
|
||||||
import cc.iotkit.data.system.ISysConfigData;
|
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.dto.vo.SysConfigVo;
|
||||||
import cc.iotkit.system.service.ISysConfigService;
|
import cc.iotkit.system.service.ISysConfigService;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 参数配置 服务层实现
|
* 参数配置 服务层实现
|
||||||
*
|
*
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class SysPostServiceImpl implements ISysPostService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Long> selectPostListByUserId(Long userId) {
|
public List<Long> selectPostListByUserId(Long userId) {
|
||||||
return new ArrayList<>();
|
return sysPostData.selectPostListByUserId(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,11 +2,16 @@ package cc.iotkit.system.service.impl;
|
||||||
|
|
||||||
import cc.iotkit.common.api.PageRequest;
|
import cc.iotkit.common.api.PageRequest;
|
||||||
import cc.iotkit.common.api.Paging;
|
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.ISysTenantData;
|
||||||
|
import cc.iotkit.data.system.ISysUserData;
|
||||||
import cc.iotkit.system.dto.bo.SysTenantBo;
|
import cc.iotkit.system.dto.bo.SysTenantBo;
|
||||||
import cc.iotkit.system.dto.vo.SysTenantVo;
|
import cc.iotkit.system.dto.vo.SysTenantVo;
|
||||||
import cc.iotkit.system.service.ISysTenantService;
|
import cc.iotkit.system.service.ISysTenantService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -23,14 +28,20 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
||||||
|
|
||||||
private final ISysTenantData sysTenantData;
|
private final ISysTenantData sysTenantData;
|
||||||
|
|
||||||
|
private final ISysUserData sysUserData;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SysTenantVo queryById(Long id) {
|
public SysTenantVo queryById(Long id) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基于租户ID查询租户
|
||||||
|
*/
|
||||||
|
@Cacheable(cacheNames = CacheNames.SYS_TENANT, key = "#tenantId")
|
||||||
@Override
|
@Override
|
||||||
public SysTenantVo queryByTenantId(String tenantId) {
|
public SysTenantVo queryByTenantId(String tenantId) {
|
||||||
return null;
|
return MapstructUtils.convert(sysTenantData.findById(Long.valueOf(tenantId)),SysTenantVo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -75,7 +86,14 @@ public class SysTenantServiceImpl implements ISysTenantService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkAccountBalance(String tenantId) {
|
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
|
@Override
|
||||||
|
|
|
@ -2,13 +2,28 @@ package cc.iotkit.system.service.impl;
|
||||||
|
|
||||||
import cc.iotkit.common.api.PageRequest;
|
import cc.iotkit.common.api.PageRequest;
|
||||||
import cc.iotkit.common.api.Paging;
|
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.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.bo.SysUserBo;
|
||||||
import cc.iotkit.system.dto.vo.SysUserVo;
|
import cc.iotkit.system.dto.vo.SysUserVo;
|
||||||
import cc.iotkit.system.service.ISysUserService;
|
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.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -17,24 +32,43 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Service
|
@Service
|
||||||
public class SysUserServiceImpl implements ISysUserService, UserService {
|
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
|
@Override
|
||||||
public String selectUserNameById(Long userId) {
|
public String selectUserNameById(Long userId) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Paging<SysUserVo> selectPageUserList(SysUserBo user, PageRequest<?> query) {
|
public Paging<SysUserVo> selectPageUserList(PageRequest<SysUserBo> query) {
|
||||||
return null;
|
return sysUserData.findAll(query.to(SysUser.class)).to(SysUserVo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysUserVo> selectUserList(SysUserBo user) {
|
public List<SysUserVo> selectUserList(SysUserBo user) {
|
||||||
return null;
|
return MapstructUtils.convert(sysUserData.findAllByCondition(user.to(SysUser.class)),SysUserVo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,7 +93,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SysUserVo selectUserById(Long userId) {
|
public SysUserVo selectUserById(Long userId) {
|
||||||
return null;
|
return MapstructUtils.convert(sysUserData.findById(userId),SysUserVo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,32 +108,121 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkUserNameUnique(SysUserBo user) {
|
public boolean checkUserNameUnique(SysUserBo user) {
|
||||||
return false;
|
boolean exist = sysUserData.checkUserNameUnique(user.to(SysUser.class));
|
||||||
|
return !exist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkPhoneUnique(SysUserBo user) {
|
public boolean checkPhoneUnique(SysUserBo user) {
|
||||||
return false;
|
boolean exist = sysUserData.checkPhoneUnique(user.to(SysUser.class));
|
||||||
|
return !exist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkEmailUnique(SysUserBo user) {
|
public boolean checkEmailUnique(SysUserBo user) {
|
||||||
return false;
|
boolean exist = sysUserData.checkEmailUnique(user.to(SysUser.class));
|
||||||
|
return !exist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
public void checkUserDataScope(Long userId) {
|
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
|
@Override
|
||||||
public int insertUser(SysUserBo user) {
|
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
|
@Override
|
||||||
|
@ -108,18 +231,33 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public int updateUser(SysUserBo user) {
|
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
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void insertUserAuth(Long userId, Long[] roleIds) {
|
public void insertUserAuth(Long userId, Long[] roleIds) {
|
||||||
|
insertUserRole(userId, roleIds, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int updateUserStatus(Long userId, String status) {
|
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
|
@Override
|
||||||
|
@ -134,7 +272,9 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int resetUserPwd(Long userId, String password) {
|
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
|
@Override
|
||||||
|
@ -143,7 +283,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int deleteUserByIds(Long[] userIds) {
|
public void deleteUserByIds(Long[] userIds) {
|
||||||
return 0;
|
sysUserData.deleteByIds(List.of(userIds));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue