From a84987e1ae7fb8767f3bb015ce518be52e3db895 Mon Sep 17 00:00:00 2001 From: tangfudong <280620913@qq.com> Date: Wed, 31 May 2023 11:42:58 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=E7=94=A8=E6=88=B7=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cc/iotkit/data/system/ISysDeptData.java | 10 +- .../cc/iotkit/data/system/ISysPostData.java | 3 + .../cc/iotkit/data/system/ISysTenantData.java | 10 +- .../cc/iotkit/data/system/ISysUserData.java | 10 +- .../iotkit/data/system/ISysUserPostData.java | 15 +- .../iotkit/data/system/ISysUserRoleData.java | 14 +- .../data/dao/SysUserPostRepository.java | 1 + .../cc/iotkit/data/dao/SysUserRepository.java | 3 +- .../data/dao/SysUserRoleRepository.java | 2 +- .../java/cc/iotkit/data/model/TbSysDept.java | 8 +- .../java/cc/iotkit/data/model/TbSysPost.java | 7 +- .../java/cc/iotkit/data/model/TbSysRole.java | 11 +- .../cc/iotkit/data/model/TbSysRoleDept.java | 4 + .../cc/iotkit/data/model/TbSysRoleMenu.java | 4 + .../java/cc/iotkit/data/model/TbSysUser.java | 11 +- .../cc/iotkit/data/model/TbSysUserPost.java | 5 +- .../cc/iotkit/data/model/TbSysUserRole.java | 5 +- .../data/service/SysConfigDataImpl.java | 11 +- .../iotkit/data/service/SysDeptDataImpl.java | 69 +++++++ .../iotkit/data/service/SysMenuDataImpl.java | 12 +- .../iotkit/data/service/SysPostDataImpl.java | 49 +++++ .../iotkit/data/service/SysRoleDataImpl.java | 25 ++- .../data/service/SysTenantDataImpl.java | 26 +++ .../iotkit/data/service/SysUserDataImpl.java | 152 +++++++++++++++ .../data/service/SysUserPostDataImpl.java | 30 +++ .../data/service/SysUserRoleDataImpl.java | 19 ++ .../system/controller/SysDeptController.java | 4 +- .../controller/SysProfileController.java | 8 +- .../system/controller/SysUserController.java | 59 +++--- .../cc/iotkit/system/dto/bo/SysUserBo.java | 12 +- .../cc/iotkit/system/dto/vo/SysDeptVo.java | 2 +- .../cc/iotkit/system/dto/vo/SysPostVo.java | 2 +- .../cc/iotkit/system/dto/vo/SysRoleVo.java | 4 +- .../cc/iotkit/system/dto/vo/SysUserVo.java | 2 +- .../listener/SysUserImportListener.java | 10 +- .../system/service/ISysUserService.java | 8 +- .../service/impl/SysConfigServiceImpl.java | 8 +- .../service/impl/SysPostServiceImpl.java | 2 +- .../service/impl/SysTenantServiceImpl.java | 22 ++- .../service/impl/SysUserServiceImpl.java | 178 ++++++++++++++++-- 40 files changed, 705 insertions(+), 132 deletions(-) create mode 100644 iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDeptDataImpl.java create mode 100644 iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysPostDataImpl.java create mode 100644 iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysTenantDataImpl.java create mode 100644 iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserDataImpl.java create mode 100644 iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserPostDataImpl.java create mode 100644 iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserRoleDataImpl.java diff --git a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDeptData.java b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDeptData.java index 97c1afe7..e99d5ef7 100644 --- a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDeptData.java +++ b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysDeptData.java @@ -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 { */ long countByParentId(Long parentId); + /** + * 根据ID查询所有子部门数(所有状态) + * + * @param deptId 部门ID + * @return 部门列表 + */ + List findByDeptId(Long deptId); + } diff --git a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysPostData.java b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysPostData.java index 05f0fe3a..3d392e35 100644 --- a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysPostData.java +++ b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysPostData.java @@ -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 { + List selectPostListByUserId(Long userId); } diff --git a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysTenantData.java b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysTenantData.java index 61c83abf..a69ff919 100644 --- a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysTenantData.java +++ b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysTenantData.java @@ -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 { + } diff --git a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserData.java b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserData.java index bc4a8c53..b6fd27e6 100644 --- a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserData.java +++ b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserData.java @@ -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 { * @return 数量 */ long countByDeptId(Long deptId); - + + + boolean checkUserNameUnique(SysUser to); + + boolean checkPhoneUnique(SysUser to); + + boolean checkEmailUnique(SysUser to); } diff --git a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserPostData.java b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserPostData.java index 4008646d..c12f9746 100644 --- a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserPostData.java +++ b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserPostData.java @@ -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 { + + /** + * 按用户id删除数据 + * + * @param userId 用户id + * @return 数量 + */ + int deleteByUserId(Long userId); } diff --git a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserRoleData.java b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserRoleData.java index 30df6893..8f4dfceb 100644 --- a/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserRoleData.java +++ b/iot-common/iot-common-dao/iot-data-service/src/main/java/cc/iotkit/data/system/ISysUserRoleData.java @@ -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 { + /** + * 按用户id删除数据 + * + * @param userId 用户id + * @return 数量 + */ + int deleteByUserId(Long userId); } diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserPostRepository.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserPostRepository.java index 3205326e..325de905 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserPostRepository.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserPostRepository.java @@ -15,4 +15,5 @@ import org.springframework.data.querydsl.QuerydslPredicateExecutor; public interface SysUserPostRepository extends JpaRepository, QuerydslPredicateExecutor { + int deleteAllByUserId(Long userId); } diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRepository.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRepository.java index 66f78db4..5a4f042d 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRepository.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRepository.java @@ -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, QuerydslPredicateExecutor { +public interface SysUserRepository extends JpaRepository, QuerydslPredicateExecutor { } diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRoleRepository.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRoleRepository.java index 03a4c2bf..946b3550 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRoleRepository.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/SysUserRoleRepository.java @@ -14,5 +14,5 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.querydsl.QuerydslPredicateExecutor; public interface SysUserRoleRepository extends JpaRepository, QuerydslPredicateExecutor { - + int deleteAllByUserId(Long userId); } diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDept.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDept.java index 5bcd3131..f78d39d9 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDept.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysDept.java @@ -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; /** * 租户编号 diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysPost.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysPost.java index 27bbb5bd..9bb95bae 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysPost.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysPost.java @@ -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; /** * 租户编号 diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRole.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRole.java index 7fd993b8..9bd5b073 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRole.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRole.java @@ -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; } } diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleDept.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleDept.java index d037d31d..fc5cca93 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleDept.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleDept.java @@ -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; diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleMenu.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleMenu.java index 8d478d44..0e240abe 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleMenu.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysRoleMenu.java @@ -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; diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUser.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUser.java index 36cb5760..e2d78efc 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUser.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUser.java @@ -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; } } diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserPost.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserPost.java index acd7064d..fca655be 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserPost.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserPost.java @@ -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; /** diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserRole.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserRole.java index a5ffd76b..21c87767 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserRole.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/model/TbSysUserRole.java @@ -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; /** diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysConfigDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysConfigDataImpl.java index e7b4a41a..7645ffe3 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysConfigDataImpl.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysConfigDataImpl.java @@ -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 diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDeptDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDeptDataImpl.java new file mode 100644 index 00000000..94236bb4 --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysDeptDataImpl.java @@ -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 findByConditions(Long parentId, String deptName, String status, int page, int size) { + return null; + } + + @Override + public List 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 findByRoleId(Long roleId) { + return null; + } + + @Override + public long countByParentId(Long parentId) { + return 0; + } + + @Override + public List findByDeptId(Long deptId) { + return MapstructUtils.convert(deptRepository.findAll().stream().filter(o->o.getAncestors().indexOf(deptId.toString())!=-1) + .collect(Collectors.toList()),SysDept.class); + } +} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysMenuDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysMenuDataImpl.java index 84f6ac4e..5cf7e0f4 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysMenuDataImpl.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysMenuDataImpl.java @@ -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")) diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysPostDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysPostDataImpl.java new file mode 100644 index 00000000..5929d8ba --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysPostDataImpl.java @@ -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 findAll() { + return MapstructUtils.convert(postRepository.findAll(),SysPost.class); + } + + @Override + public List 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(); + } +} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleDataImpl.java index 186cbebc..26e7d616 100644 --- a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleDataImpl.java +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysRoleDataImpl.java @@ -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 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 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())) diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysTenantDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysTenantDataImpl.java new file mode 100644 index 00000000..cbcd092b --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysTenantDataImpl.java @@ -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); + } +} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserDataImpl.java new file mode 100644 index 00000000..9261f744 --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserDataImpl.java @@ -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 findByIds(Collection 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 list) { + + } + + @Override + public void deleteById(Long aLong) { + + } + + @Override + public void deleteByIds(Collection collection) { + userRepository.deleteAllByIdInBatch(collection); + } + + @Override + public long count() { + return userRepository.count(); + } + + @Override + public List findAll() { + return null; + } + + @Override + public Paging findAll(PageRequest pageRequest) { + return null; + } + + @Override + public List findAllByCondition(SysUser user) { + List depts = sysDeptData.findByDeptId(user.getDeptId()); + List 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 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; + } +} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserPostDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserPostDataImpl.java new file mode 100644 index 00000000..b67c97e7 --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserPostDataImpl.java @@ -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 data) { + sysUserPostRepository.saveAll(MapstructUtils.convert(data, TbSysUserPost.class)); + } +} diff --git a/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserRoleDataImpl.java b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserRoleDataImpl.java new file mode 100644 index 00000000..7de1a8c6 --- /dev/null +++ b/iot-common/iot-common-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/service/SysUserRoleDataImpl.java @@ -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); + } +} diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysDeptController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysDeptController.java index 4d94cc49..92f73433 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysDeptController.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysDeptController.java @@ -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 excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) { List 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; } diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysProfileController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysProfileController.java index 1f273b76..51ab0659 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysProfileController.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysProfileController.java @@ -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("修改密码异常,请联系管理员"); diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysUserController.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysUserController.java index 5ee17c86..690f3197 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysUserController.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/controller/SysUserController.java @@ -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 list(SysUserBo user, PageRequest query) { - return userService.selectPageUserList(user, query); + @PostMapping("/list") + public Paging list(@RequestBody @Validated(QueryGroup.class) PageRequest 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 list = userService.selectUserList(user); List 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> deptTree(SysDeptBo dept) { diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysUserBo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysUserBo.java index c880763e..32d4fdc9 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysUserBo.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/bo/SysUserBo.java @@ -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); } } diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysDeptVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysDeptVo.java index 5b0044dd..3c104520 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysDeptVo.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysDeptVo.java @@ -26,7 +26,7 @@ public class SysDeptVo implements Serializable { * 部门id */ @ExcelProperty(value = "部门id") - private Long deptId; + private Long id; /** * 父部门id diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysPostVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysPostVo.java index 3185cd2a..c0877df0 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysPostVo.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysPostVo.java @@ -28,7 +28,7 @@ public class SysPostVo implements Serializable { * 岗位ID */ @ExcelProperty(value = "岗位序号") - private Long postId; + private Long id; /** * 岗位编码 diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysRoleVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysRoleVo.java index ca5d87ee..f8e1be89 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysRoleVo.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysRoleVo.java @@ -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); } } diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserVo.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserVo.java index f2334129..44a7d9f6 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserVo.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/dto/vo/SysUserVo.java @@ -24,7 +24,7 @@ public class SysUserVo implements Serializable { /** * 用户ID */ - private Long userId; + private Long id; /** * 租户ID diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/listener/SysUserImportListener.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/listener/SysUserImportListener.java index 386b822f..1205b9dd 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/listener/SysUserImportListener.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/listener/SysUserImportListener.java @@ -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").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++; diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysUserService.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysUserService.java index 235d1502..276c143b 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysUserService.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/ISysUserService.java @@ -15,7 +15,7 @@ import java.util.List; public interface ISysUserService { - Paging selectPageUserList(SysUserBo user, PageRequest query); + Paging selectPageUserList(PageRequest 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); } diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysConfigServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysConfigServiceImpl.java index 94d5f4af..f72b86fa 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysConfigServiceImpl.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysConfigServiceImpl.java @@ -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; + /** * 参数配置 服务层实现 * diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysPostServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysPostServiceImpl.java index 7d6c5725..5fa250cd 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysPostServiceImpl.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysPostServiceImpl.java @@ -71,7 +71,7 @@ public class SysPostServiceImpl implements ISysPostService { */ @Override public List selectPostListByUserId(Long userId) { - return new ArrayList<>(); + return sysPostData.selectPostListByUserId(userId); } /** diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysTenantServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysTenantServiceImpl.java index 165ea265..0024bffd 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysTenantServiceImpl.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysTenantServiceImpl.java @@ -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 diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysUserServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysUserServiceImpl.java index e871e044..58b5e75e 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysUserServiceImpl.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysUserServiceImpl.java @@ -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 selectPageUserList(SysUserBo user, PageRequest query) { - return null; + public Paging selectPageUserList(PageRequest query) { + return sysUserData.findAll(query.to(SysUser.class)).to(SysUserVo.class); } @Override public List 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 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 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 roles = sysRoleData.selectRoleList(new SysRole()); + if (CollUtil.isEmpty(roles)) { + throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION); + } + List roleList = StreamUtils.toList(roles, SysRole::getId); + if (!LoginHelper.isSuperAdmin(userId)) { + roleList.remove(UserConstants.SUPER_ADMIN_ID); + } + List canDoRoleList = StreamUtils.filter(List.of(roleIds), roleList::contains); + if (CollUtil.isEmpty(canDoRoleList)) { + throw new BizException(ErrCode.UNAUTHORIZED_EXCEPTION); + } + if (clear) { + // 删除用户与角色关联 + sysUserRoleData.deleteByUserId(userId); + } + // 新增用户与角色管理 + List 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)); } }