From 5285591fc5ff59ac3388d47087b08ee5bd3e1abf Mon Sep 17 00:00:00 2001 From: dataprince Date: Mon, 25 Sep 2023 20:36:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8mybatis-flex=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E2=80=9C=E9=83=A8=E9=97=A8=E7=AE=A1=E7=90=86=E2=80=9D?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-dev.yml | 2 +- .../common/orm/core/domain/BaseEntity.java | 6 + .../com/ruoyi/demo/domain/DemoStudent.java | 3 + .../controller/system/SysDeptController.java | 72 +++-- .../controller/system/SysRoleController.java | 3 +- .../controller/system/SysUserController.java | 3 +- .../java/com/ruoyi/system/domain/SysDept.java | 306 +++++++++--------- .../java/com/ruoyi/system/domain/SysRole.java | 201 ++---------- .../com/ruoyi/system/domain/SysRoleMenu.java | 14 +- .../java/com/ruoyi/system/domain/SysUser.java | 35 +- .../com/ruoyi/system/domain/bo/SysUserBo.java | 6 +- .../com/ruoyi/system/domain/vo/SysDeptVo.java | 2 + .../com/ruoyi/system/domain/vo/SysUserVo.java | 2 +- .../ruoyi/system/mapper/SysDeptMapper.java | 176 +++++----- .../ruoyi/system/mapper/SysUserMapper.java | 4 +- .../ruoyi/system/service/ISysDeptService.java | 44 +-- .../ruoyi/system/service/ISysUserService.java | 11 +- .../service/impl/SysDeptServiceImpl.java | 289 ++++++++++------- .../service/impl/SysNoticeServiceImpl.java | 3 +- .../service/impl/SysUserServiceImpl.java | 32 +- .../resources/mapper/system/SysDeptMapper.xml | 244 +++++++------- .../resources/mapper/system/SysUserMapper.xml | 12 +- ruoyi-ui/src/views/demo/customer/index.vue | 8 +- ruoyi-ui/src/views/demo/student/index.vue | 6 +- ruoyi-ui/src/views/system/user/index.vue | 4 +- 25 files changed, 749 insertions(+), 739 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index a60e73a..134ad74 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -16,7 +16,7 @@ mybatis-flex: autoMappingBehavior: FULL # MyBatis 自动映射时未知列或未知属性处理策 # NONE:不做处理 WARNING:打印相关警告 FAILING:抛出异常和详细信息 - autoMappingUnknownColumnBehavior: WARNING + autoMappingUnknownColumnBehavior: NONE # 更详细的日志输出 会有性能损耗 org.apache.ibatis.logging.stdout.StdOutImpl # 关闭日志记录 org.apache.ibatis.logging.nologging.NoLoggingImpl # 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl diff --git a/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/core/domain/BaseEntity.java b/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/core/domain/BaseEntity.java index 9d77c0d..f92385f 100644 --- a/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/core/domain/BaseEntity.java +++ b/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/core/domain/BaseEntity.java @@ -24,6 +24,12 @@ public class BaseEntity implements Serializable { @Serial private static final long serialVersionUID = 1L; + /** + * 租户编号 + */ + @Column(ignore = true) + private Long tenantId; + /** * 搜索值 */ diff --git a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/demo/domain/DemoStudent.java b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/demo/domain/DemoStudent.java index d6963b7..f5490e8 100644 --- a/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/demo/domain/DemoStudent.java +++ b/ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/demo/domain/DemoStudent.java @@ -2,6 +2,7 @@ package com.ruoyi.demo.domain; import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; +import jakarta.validation.constraints.NotBlank; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.core.annotation.Excel; @@ -26,6 +27,8 @@ public class DemoStudent extends BaseEntity /** 年龄 */ @Excel(name = "年龄") + //@NotBlank + //private int studentAge; private Long studentAge; /** 爱好(0代码 1音乐 2电影) */ diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysDeptController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysDeptController.java index 470aa9d..4ba3506 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysDeptController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysDeptController.java @@ -3,13 +3,16 @@ package com.ruoyi.system.controller.system; import java.util.List; import cn.dev33.satoken.annotation.SaCheckPermission; +import com.ruoyi.common.core.core.domain.R; +import com.ruoyi.common.core.core.text.Convert; import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.security.utils.LoginHelper; -import com.ruoyi.system.domain.SysDept; +import com.ruoyi.system.domain.bo.SysDeptBo; +import com.ruoyi.system.domain.vo.SysDeptVo; +import com.ruoyi.system.service.ISysUserService; import jakarta.annotation.Resource; import lombok.RequiredArgsConstructor; -import org.apache.commons.lang3.ArrayUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; @@ -38,14 +41,17 @@ public class SysDeptController extends BaseController { @Resource private ISysDeptService deptService; + @Resource + private ISysUserService sysUserService; + /** * 获取部门列表 */ @SaCheckPermission("system:dept:list") @GetMapping("/list") - public AjaxResult list(SysDept dept) { - List depts = deptService.selectDeptList(dept); - return success(depts); + public R> list(SysDeptBo deptBo) { + List depts = deptService.selectDeptList(deptBo); + return R.ok(depts); } /** @@ -53,10 +59,10 @@ public class SysDeptController extends BaseController { */ @SaCheckPermission("system:dept:list") @GetMapping("/list/exclude/{deptId}") - public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) { - List depts = deptService.selectDeptList(new SysDept()); - depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")); - return success(depts); + public R> excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) { + List depts = deptService.selectDeptList(new SysDeptBo()); + depts.removeIf(d -> d.getDeptId().equals(deptId) || StringUtils.splitList(d.getAncestors()).contains(Convert.toStr(deptId))); + return R.ok(depts); } /** @@ -65,9 +71,9 @@ public class SysDeptController extends BaseController { @SaCheckPermission("system:dept:query") @Log(title = "部门管理", businessType = BusinessType.INSERT) @GetMapping(value = "/{deptId}") - public AjaxResult getInfo(@PathVariable Long deptId) { + public R getInfo(@PathVariable Long deptId) { deptService.checkDeptDataScope(deptId); - return success(deptService.selectDeptById(deptId)); + return R.ok(deptService.selectDeptById(deptId)); } /** @@ -75,12 +81,15 @@ public class SysDeptController extends BaseController { */ @SaCheckPermission("system:dept:add") @PostMapping - public AjaxResult add(@Validated @RequestBody SysDept dept) { + public R add(@Validated @RequestBody SysDeptBo dept) { if (!deptService.checkDeptNameUnique(dept)) { - return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在"); + return R.fail("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在"); } - dept.setCreateBy(LoginHelper.getUserId()); - return toAjax(deptService.insertDept(dept)); + int inserted = deptService.insertDept(dept); + if (inserted != 1) { + return R.fail("新增部门记录失败!"); + } + return R.ok(); } /** @@ -89,22 +98,25 @@ public class SysDeptController extends BaseController { @SaCheckPermission("system:dept:edit") @Log(title = "部门管理", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@Validated @RequestBody SysDept dept) { + public R edit(@Validated @RequestBody SysDeptBo dept) { Long deptId = dept.getDeptId(); deptService.checkDeptDataScope(deptId); if (!deptService.checkDeptNameUnique(dept)) { - return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在"); + return R.fail("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在"); } else if (dept.getParentId().equals(deptId)) { - return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己"); + return R.fail("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己"); } else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())) { if (deptService.selectNormalChildrenDeptById(deptId) > 0) { - return error("该部门包含未停用的子部门!"); - } else if (deptService.checkDeptExistUser(deptId)) { - return error("该部门下存在已分配用户,不能禁用!"); + return R.fail("该部门包含未停用的子部门!"); + } else if (sysUserService.checkDeptExistUser(deptId)) { + return R.fail("该部门下存在已分配用户,不能禁用!"); } } - dept.setUpdateBy(LoginHelper.getUserId()); - return toAjax(deptService.updateDept(dept)); + boolean updated = deptService.updateDept(dept); + if (!updated) { + return R.fail("修改部门'" + dept.getDeptName() + "'失败"); + } + return R.ok(); } /** @@ -113,14 +125,18 @@ public class SysDeptController extends BaseController { @SaCheckPermission("system:dept:remove") @Log(title = "部门管理", businessType = BusinessType.DELETE) @DeleteMapping("/{deptId}") - public AjaxResult remove(@PathVariable Long deptId) { + public R remove(@PathVariable Long deptId) { if (deptService.hasChildByDeptId(deptId)) { - return warn("存在下级部门,不允许删除"); + return R.warn("存在下级部门,不允许删除"); } - if (deptService.checkDeptExistUser(deptId)) { - return warn("部门存在用户,不允许删除"); + if (sysUserService.checkDeptExistUser(deptId)) { + return R.warn("部门存在用户,不允许删除"); } deptService.checkDeptDataScope(deptId); - return toAjax(deptService.deleteDeptById(deptId)); + boolean updated = deptService.deleteDeptById(deptId); + if (!updated) { + return R.fail("删除部门失败"); + } + return R.ok(); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysRoleController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysRoleController.java index cb2bd6b..8dee70b 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysRoleController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysRoleController.java @@ -10,6 +10,7 @@ import com.ruoyi.common.security.utils.LoginHelper; import com.ruoyi.system.domain.SysDept; import com.ruoyi.system.domain.SysRole; import com.ruoyi.system.domain.SysUser; +import com.ruoyi.system.domain.bo.SysDeptBo; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; @@ -244,7 +245,7 @@ public class SysRoleController extends BaseController { AjaxResult ajax = AjaxResult.success(); ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId)); - ajax.put("depts", deptService.selectDeptTreeList(new SysDept())); + ajax.put("depts", deptService.selectDeptTreeList(new SysDeptBo())); return ajax; } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysUserController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysUserController.java index af8ee02..f40cadc 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysUserController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysUserController.java @@ -14,6 +14,7 @@ import com.ruoyi.system.domain.SysDept; import com.ruoyi.system.domain.SysPost; import com.ruoyi.system.domain.SysRole; import com.ruoyi.system.domain.SysUser; +import com.ruoyi.system.domain.bo.SysDeptBo; import com.ruoyi.system.domain.bo.SysPostBo; import com.ruoyi.system.service.*; import jakarta.annotation.Resource; @@ -238,7 +239,7 @@ public class SysUserController extends BaseController { */ @SaCheckPermission("system:user:list") @GetMapping("/deptTree") - public AjaxResult deptTree(SysDept dept) { + public AjaxResult deptTree(SysDeptBo dept) { return success(deptService.selectDeptTreeList(dept)); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDept.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDept.java index 6500c24..b06ea4b 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDept.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysDept.java @@ -3,9 +3,16 @@ package com.ruoyi.system.domain; import java.io.Serial; import java.util.ArrayList; import java.util.List; + +import com.mybatisflex.annotation.Column; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; +import com.mybatisflex.annotation.Table; import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.orm.core.domain.BaseEntity; @@ -15,12 +22,14 @@ import com.ruoyi.common.orm.core.domain.BaseEntity; * * @author ruoyi */ +@Data +@EqualsAndHashCode(callSuper = true) +@Table(value = "sys_dept") public class SysDept extends BaseEntity { - @Serial - private static final long serialVersionUID = 1L; /** 部门ID */ + @Id(keyType = KeyType.Auto) private Long deptId; /** 父部门ID */ @@ -36,7 +45,7 @@ public class SysDept extends BaseEntity private String orderNum; /** 负责人 */ - private String leader; + private String leader;//TODO:修改为Long类型 /** 联系电话 */ private String phone; @@ -51,154 +60,155 @@ public class SysDept extends BaseEntity private String delFlag; /** 父部门名称 */ + @Column(ignore = true) private String parentName; /** 子部门 */ private List children = new ArrayList(); - public Long getDeptId() - { - return deptId; - } - - public void setDeptId(Long deptId) - { - this.deptId = deptId; - } - - public Long getParentId() - { - return parentId; - } - - public void setParentId(Long parentId) - { - this.parentId = parentId; - } - - public String getAncestors() - { - return ancestors; - } - - public void setAncestors(String ancestors) - { - this.ancestors = ancestors; - } - - @NotBlank(message = "部门名称不能为空") - @Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符") - public String getDeptName() - { - return deptName; - } - - public void setDeptName(String deptName) - { - this.deptName = deptName; - } - - @NotBlank(message = "显示顺序不能为空") - public String getOrderNum() - { - return orderNum; - } - - public void setOrderNum(String orderNum) - { - this.orderNum = orderNum; - } - - public String getLeader() - { - return leader; - } - - public void setLeader(String leader) - { - this.leader = leader; - } - - @Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符") - public String getPhone() - { - return phone; - } - - public void setPhone(String phone) - { - this.phone = phone; - } - - @Email(message = "邮箱格式不正确") - @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符") - public String getEmail() - { - return email; - } - - public void setEmail(String email) - { - this.email = email; - } - - public String getStatus() - { - return status; - } - - public void setStatus(String status) - { - this.status = status; - } - - public String getDelFlag() - { - return delFlag; - } - - public void setDelFlag(String delFlag) - { - this.delFlag = delFlag; - } - - public String getParentName() - { - return parentName; - } - - public void setParentName(String parentName) - { - this.parentName = parentName; - } - - public List getChildren() - { - return children; - } - - public void setChildren(List children) - { - this.children = children; - } - - @Override - public String toString() { - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("deptId", getDeptId()) - .append("parentId", getParentId()) - .append("ancestors", getAncestors()) - .append("deptName", getDeptName()) - .append("orderNum", getOrderNum()) - .append("leader", getLeader()) - .append("phone", getPhone()) - .append("email", getEmail()) - .append("status", getStatus()) - .append("delFlag", getDelFlag()) - .append("createBy", getCreateBy()) - .append("createTime", getCreateTime()) - .append("updateBy", getUpdateBy()) - .append("updateTime", getUpdateTime()) - .toString(); - } +// public Long getDeptId() +// { +// return deptId; +// } +// +// public void setDeptId(Long deptId) +// { +// this.deptId = deptId; +// } +// +// public Long getParentId() +// { +// return parentId; +// } +// +// public void setParentId(Long parentId) +// { +// this.parentId = parentId; +// } +// +// public String getAncestors() +// { +// return ancestors; +// } +// +// public void setAncestors(String ancestors) +// { +// this.ancestors = ancestors; +// } +// +// @NotBlank(message = "部门名称不能为空") +// @Size(min = 0, max = 30, message = "部门名称长度不能超过30个字符") +// public String getDeptName() +// { +// return deptName; +// } +// +// public void setDeptName(String deptName) +// { +// this.deptName = deptName; +// } +// +// @NotBlank(message = "显示顺序不能为空") +// public String getOrderNum() +// { +// return orderNum; +// } +// +// public void setOrderNum(String orderNum) +// { +// this.orderNum = orderNum; +// } +// +// public String getLeader() +// { +// return leader; +// } +// +// public void setLeader(String leader) +// { +// this.leader = leader; +// } +// +// @Size(min = 0, max = 11, message = "联系电话长度不能超过11个字符") +// public String getPhone() +// { +// return phone; +// } +// +// public void setPhone(String phone) +// { +// this.phone = phone; +// } +// +// @Email(message = "邮箱格式不正确") +// @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符") +// public String getEmail() +// { +// return email; +// } +// +// public void setEmail(String email) +// { +// this.email = email; +// } +// +// public String getStatus() +// { +// return status; +// } +// +// public void setStatus(String status) +// { +// this.status = status; +// } +// +// public String getDelFlag() +// { +// return delFlag; +// } +// +// public void setDelFlag(String delFlag) +// { +// this.delFlag = delFlag; +// } +// +// public String getParentName() +// { +// return parentName; +// } +// +// public void setParentName(String parentName) +// { +// this.parentName = parentName; +// } +// +// public List getChildren() +// { +// return children; +// } +// +// public void setChildren(List children) +// { +// this.children = children; +// } +// +// @Override +// public String toString() { +// return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) +// .append("deptId", getDeptId()) +// .append("parentId", getParentId()) +// .append("ancestors", getAncestors()) +// .append("deptName", getDeptName()) +// .append("orderNum", getOrderNum()) +// .append("leader", getLeader()) +// .append("phone", getPhone()) +// .append("email", getEmail()) +// .append("status", getStatus()) +// .append("delFlag", getDelFlag()) +// .append("createBy", getCreateBy()) +// .append("createTime", getCreateTime()) +// .append("updateBy", getUpdateBy()) +// .append("updateTime", getUpdateTime()) +// .toString(); +// } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java index 3a244d5..4aee36d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java @@ -1,7 +1,14 @@ package com.ruoyi.system.domain; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; +import com.mybatisflex.annotation.RelationManyToMany; +import com.mybatisflex.annotation.Table; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.core.annotation.Excel; @@ -9,6 +16,7 @@ import com.ruoyi.common.core.annotation.Excel.ColumnType; import com.ruoyi.common.orm.core.domain.BaseEntity; import java.io.Serial; +import java.util.List; import java.util.Set; /** @@ -16,13 +24,15 @@ import java.util.Set; * * @author ruoyi */ +@Data +@NoArgsConstructor +@EqualsAndHashCode(callSuper = true) +@Table(value = "sys_role") public class SysRole extends BaseEntity { - @Serial - private static final long serialVersionUID = 1L; - /** 角色ID */ @Excel(name = "角色序号", cellType = ColumnType.NUMERIC) + @Id(keyType = KeyType.Auto) private Long roleId; /** 角色名称 */ @@ -65,40 +75,35 @@ public class SysRole extends BaseEntity /** 菜单组 */ private Long[] menuIds; + @RelationManyToMany( + selfField = "roleId", + targetField = "menuId", + joinTable = "sys_role_menu", + joinSelfColumn = "role_id", + joinTargetColumn = "menu_id" + ) + private List menuList; + /** 部门组(数据权限) */ private Long[] deptIds; + @RelationManyToMany( + selfField = "roleId", + targetField = "deptId", + joinTable = "sys_role_dept", + joinSelfColumn = "role_id", + joinTargetColumn = "dept_id" + ) + private List deptList; + /** 角色菜单权限 */ private Set permissions; - public String getRemark() { - return remark; - } - - public void setRemark(String remark) { - this.remark = remark; - } - - public SysRole() - { - - } - public SysRole(Long roleId) { this.roleId = roleId; } - public Long getRoleId() - { - return roleId; - } - - public void setRoleId(Long roleId) - { - this.roleId = roleId; - } - public boolean isAdmin() { return isAdmin(this.roleId); @@ -109,148 +114,4 @@ public class SysRole extends BaseEntity return roleId != null && 1L == roleId; } - @NotBlank(message = "角色名称不能为空") - @Size(min = 0, max = 30, message = "角色名称长度不能超过30个字符") - public String getRoleName() - { - return roleName; - } - - public void setRoleName(String roleName) - { - this.roleName = roleName; - } - - @NotBlank(message = "权限字符不能为空") - @Size(min = 0, max = 100, message = "权限字符长度不能超过100个字符") - public String getRoleKey() - { - return roleKey; - } - - public void setRoleKey(String roleKey) - { - this.roleKey = roleKey; - } - - @NotBlank(message = "显示顺序不能为空") - public String getRoleSort() - { - return roleSort; - } - - public void setRoleSort(String roleSort) - { - this.roleSort = roleSort; - } - - public String getDataScope() - { - return dataScope; - } - - public void setDataScope(String dataScope) - { - this.dataScope = dataScope; - } - - public boolean isMenuCheckStrictly() - { - return menuCheckStrictly; - } - - public void setMenuCheckStrictly(boolean menuCheckStrictly) - { - this.menuCheckStrictly = menuCheckStrictly; - } - - public boolean isDeptCheckStrictly() - { - return deptCheckStrictly; - } - - public void setDeptCheckStrictly(boolean deptCheckStrictly) - { - this.deptCheckStrictly = deptCheckStrictly; - } - - public String getStatus() - { - return status; - } - - public void setStatus(String status) - { - this.status = status; - } - - public String getDelFlag() - { - return delFlag; - } - - public void setDelFlag(String delFlag) - { - this.delFlag = delFlag; - } - - public boolean isFlag() - { - return flag; - } - - public void setFlag(boolean flag) - { - this.flag = flag; - } - - public Long[] getMenuIds() - { - return menuIds; - } - - public void setMenuIds(Long[] menuIds) - { - this.menuIds = menuIds; - } - - public Long[] getDeptIds() - { - return deptIds; - } - - public void setDeptIds(Long[] deptIds) - { - this.deptIds = deptIds; - } - - public Set getPermissions() - { - return permissions; - } - - public void setPermissions(Set permissions) - { - this.permissions = permissions; - } - - @Override - public String toString() { - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("roleId", getRoleId()) - .append("roleName", getRoleName()) - .append("roleKey", getRoleKey()) - .append("roleSort", getRoleSort()) - .append("dataScope", getDataScope()) - .append("menuCheckStrictly", isMenuCheckStrictly()) - .append("deptCheckStrictly", isDeptCheckStrictly()) - .append("status", getStatus()) - .append("delFlag", getDelFlag()) - .append("createBy", getCreateBy()) - .append("createTime", getCreateTime()) - .append("updateBy", getUpdateBy()) - .append("updateTime", getUpdateTime()) - .append("remark", getRemark()) - .toString(); - } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleMenu.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleMenu.java index de10a74..52aa10d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleMenu.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleMenu.java @@ -1,19 +1,29 @@ package com.ruoyi.system.domain; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; +import com.mybatisflex.annotation.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; /** * 角色和菜单关联 sys_role_menu - * + * * @author ruoyi */ +@Data +@Table(value = "sys_role_menu") public class SysRoleMenu { /** 角色ID */ + @Id(keyType = KeyType.None) private Long roleId; - + /** 菜单ID */ + @Id(keyType = KeyType.None) private Long menuId; public Long getRoleId() diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUser.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUser.java index 5ef3e93..f6674c6 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUser.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUser.java @@ -1,10 +1,18 @@ package com.ruoyi.system.domain; +import java.io.Serial; import java.util.Date; import java.util.List; -import com.ruoyi.common.tenant.core.TenantEntity; +import com.mybatisflex.annotation.Id; +import com.mybatisflex.annotation.KeyType; +import com.mybatisflex.annotation.Table; +import com.ruoyi.common.core.constant.UserConstants; +import com.ruoyi.common.orm.core.domain.BaseEntity; import jakarta.validation.constraints.*; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -13,7 +21,6 @@ import com.ruoyi.common.core.annotation.Excel; import com.ruoyi.common.core.annotation.Excel.ColumnType; import com.ruoyi.common.core.annotation.Excel.Type; import com.ruoyi.common.core.annotation.Excels; -import com.ruoyi.common.orm.core.domain.BaseEntity; import com.ruoyi.common.core.xss.Xss; /** @@ -21,12 +28,13 @@ import com.ruoyi.common.core.xss.Xss; * * @author ruoyi */ -public class SysUser extends TenantEntity -{ - private static final long serialVersionUID = 1L; +@Table(value = "sys_user") +public class SysUser extends BaseEntity +{ /** 用户ID */ @Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号") + @Id(keyType = KeyType.Auto) private Long userId; /** 部门ID */ @@ -56,7 +64,7 @@ public class SysUser extends TenantEntity /** 用户性别 */ @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知") - private String sex; + private String gender; /** 用户头像 */ private String avatar; @@ -202,14 +210,14 @@ public class SysUser extends TenantEntity this.phonenumber = phonenumber; } - public String getSex() + public String getGender() { - return sex; + return gender; } - public void setSex(String sex) + public void setGender(String gender) { - this.sex = sex; + this.gender = gender; } public String getAvatar() @@ -352,7 +360,7 @@ public class SysUser extends TenantEntity .append("userType", getUserType()) .append("email", getEmail()) .append("phonenumber", getPhonenumber()) - .append("sex", getSex()) + .append("sex", getGender()) .append("avatar", getAvatar()) .append("password", getPassword()) .append("salt", getSalt()) @@ -368,4 +376,9 @@ public class SysUser extends TenantEntity .append("dept", getDept()) .toString(); } + + public boolean isSuperAdmin() { + return UserConstants.SUPER_ADMIN_ID.equals(this.userId); + } + } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysUserBo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysUserBo.java index c98146d..383b31c 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysUserBo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/bo/SysUserBo.java @@ -1,6 +1,6 @@ package com.ruoyi.system.domain.bo; -import com.ruoyi.common.tenant.core.TenantEntity; +import com.ruoyi.common.orm.core.domain.BaseEntity; import io.github.linpeilie.annotations.AutoMapper; import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotBlank; @@ -22,7 +22,7 @@ import com.ruoyi.system.domain.SysUser; @NoArgsConstructor @EqualsAndHashCode(callSuper = true) @AutoMapper(target = SysUser.class) -public class SysUserBo extends TenantEntity { +public class SysUserBo extends BaseEntity { /** * 用户ID @@ -70,7 +70,7 @@ public class SysUserBo extends TenantEntity { /** * 用户性别(0男 1女 2未知) */ - private String sex; + private String gender; /** * 密码 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysDeptVo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysDeptVo.java index 71027e9..1dc99e3 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysDeptVo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysDeptVo.java @@ -2,6 +2,7 @@ package com.ruoyi.system.domain.vo; import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; import com.alibaba.excel.annotation.ExcelProperty; +import com.mybatisflex.annotation.Column; import com.ruoyi.common.excel.annotation.ExcelDictFormat; import com.ruoyi.common.excel.convert.ExcelDictConvert; import com.ruoyi.system.domain.SysDept; @@ -39,6 +40,7 @@ public class SysDeptVo implements Serializable { /** * 父部门名称 */ + @Column(ignore = true) private String parentName; /** diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysUserVo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysUserVo.java index 616d04f..e3ebef8 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysUserVo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysUserVo.java @@ -73,7 +73,7 @@ public class SysUserVo implements Serializable { /** * 用户性别(0男 1女 2未知) */ - private String sex; + private String gender; /** * 头像地址 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java index fd40ab6..dd360e7 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java @@ -2,7 +2,10 @@ package com.ruoyi.system.mapper; import java.util.List; +import com.mybatisflex.core.BaseMapper; import com.ruoyi.system.domain.SysDept; +import com.ruoyi.system.domain.vo.SysDeptVo; +import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; /** @@ -10,15 +13,16 @@ import org.apache.ibatis.annotations.Param; * * @author ruoyi */ -public interface SysDeptMapper +@Mapper +public interface SysDeptMapper extends BaseMapper { - /** - * 查询部门管理数据 - * - * @param dept 部门信息 - * @return 部门信息集合 - */ - List selectDeptList(SysDept dept); +// /** +// * 查询部门管理数据 +// * +// * @param dept 部门信息 +// * @return 部门信息集合 +// */ +// List selectDeptList(SysDept dept); /** * 根据角色ID查询部门树信息 @@ -29,91 +33,91 @@ public interface SysDeptMapper */ List selectDeptListByRoleId(@Param("roleId") Long roleId, @Param("deptCheckStrictly") boolean deptCheckStrictly); - /** - * 根据部门ID查询信息 - * - * @param deptId 部门ID - * @return 部门信息 - */ - SysDept selectDeptById(Long deptId); +// /** +// * 根据部门ID查询信息 +// * +// * @param deptId 部门ID +// * @return 部门信息 +// */ +// SysDeptVo selectDeptById(Long deptId); - /** - * 根据ID查询所有子部门 - * - * @param deptId 部门ID - * @return 部门列表 - */ - List selectChildrenDeptById(Long deptId); +// /** +// * 根据ID查询所有子部门 +// * +// * @param deptId 部门ID +// * @return 部门列表 +// */ +// List selectChildrenDeptById(Long deptId); - /** - * 根据ID查询所有子部门(正常状态) - * - * @param deptId 部门ID - * @return 子部门数 - */ - int selectNormalChildrenDeptById(Long deptId); +// /** +// * 根据ID查询所有子部门(正常状态) +// * +// * @param deptId 部门ID +// * @return 子部门数 +// */ +// int selectNormalChildrenDeptById(Long deptId); - /** - * 是否存在子节点 - * - * @param deptId 部门ID - * @return 结果 - */ - int hasChildByDeptId(Long deptId); +// /** +// * 是否存在子节点 +// * +// * @param deptId 部门ID +// * @return 结果 +// */ +// int hasChildByDeptId(Long deptId); - /** - * 查询部门是否存在用户 - * - * @param deptId 部门ID - * @return 结果 - */ - int checkDeptExistUser(Long deptId); +// /** +// * 查询部门是否存在用户 +// * +// * @param deptId 部门ID +// * @return 结果 +// */ +// int checkDeptExistUser(Long deptId); - /** - * 校验部门名称是否唯一 - * - * @param deptName 部门名称 - * @param parentId 父部门ID - * @return 结果 - */ - SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId); +// /** +// * 校验部门名称是否唯一 +// * +// * @param deptName 部门名称 +// * @param parentId 父部门ID +// * @return 结果 +// */ +// SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId); +// +// /** +// * 新增部门信息 +// * +// * @param dept 部门信息 +// * @return 结果 +// */ +// int insertDept(SysDept dept); - /** - * 新增部门信息 - * - * @param dept 部门信息 - * @return 结果 - */ - int insertDept(SysDept dept); +// /** +// * 修改部门信息 +// * +// * @param dept 部门信息 +// * @return 结果 +// */ +// int updateDept(SysDept dept); - /** - * 修改部门信息 - * - * @param dept 部门信息 - * @return 结果 - */ - int updateDept(SysDept dept); +// /** +// * 修改所在部门正常状态 +// * +// * @param deptIds 部门ID组 +// */ +// void updateDeptStatusNormal(Long[] deptIds); - /** - * 修改所在部门正常状态 - * - * @param deptIds 部门ID组 - */ - void updateDeptStatusNormal(Long[] deptIds); +// /** +// * 修改子元素关系 +// * +// * @param depts 子元素 +// * @return 结果 +// */ +// int updateDeptChildren(@Param("depts") List depts); - /** - * 修改子元素关系 - * - * @param depts 子元素 - * @return 结果 - */ - int updateDeptChildren(@Param("depts") List depts); - - /** - * 删除部门管理信息 - * - * @param deptId 部门ID - * @return 结果 - */ - int deleteDeptById(Long deptId); +// /** +// * 删除部门管理信息 +// * +// * @param deptId 部门ID +// * @return 结果 +// */ +// int deleteDeptById(Long deptId); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java index f4171b8..2aec5fb 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java @@ -2,8 +2,8 @@ package com.ruoyi.system.mapper; import java.util.List; +import com.mybatisflex.core.BaseMapper; import com.ruoyi.system.domain.SysUser; -import com.ruoyi.system.domain.vo.SysUserVo; import org.apache.ibatis.annotations.Param; /** @@ -11,7 +11,7 @@ import org.apache.ibatis.annotations.Param; * * @author ruoyi */ -public interface SysUserMapper +public interface SysUserMapper extends BaseMapper { /** * 根据条件分页查询用户列表 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java index f8ef496..127ef48 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java @@ -1,15 +1,19 @@ package com.ruoyi.system.service; import java.util.List; -import com.ruoyi.system.domain.TreeSelect; + +import cn.hutool.core.lang.tree.Tree; +import com.ruoyi.common.orm.core.service.IBaseService; import com.ruoyi.system.domain.SysDept; +import com.ruoyi.system.domain.bo.SysDeptBo; +import com.ruoyi.system.domain.vo.SysDeptVo; /** * 部门管理 服务层 * * @author ruoyi */ -public interface ISysDeptService +public interface ISysDeptService extends IBaseService { /** * 查询部门管理数据 @@ -17,7 +21,7 @@ public interface ISysDeptService * @param dept 部门信息 * @return 部门信息集合 */ - List selectDeptList(SysDept dept); + List selectDeptList(SysDeptBo dept); /** * 查询部门树结构信息 @@ -25,15 +29,7 @@ public interface ISysDeptService * @param dept 部门信息 * @return 部门树信息集合 */ - List selectDeptTreeList(SysDept dept); - - /** - * 构建前端所需要树结构 - * - * @param depts 部门列表 - * @return 树结构列表 - */ - List buildDeptTree(List depts); + List> selectDeptTreeList(SysDeptBo dept) ; /** * 构建前端所需要下拉树结构 @@ -41,7 +37,7 @@ public interface ISysDeptService * @param depts 部门列表 * @return 下拉树结构列表 */ - List buildDeptTreeSelect(List depts); + List> buildDeptTreeSelect(List depts); /** * 根据角色ID查询部门树信息 @@ -57,7 +53,7 @@ public interface ISysDeptService * @param deptId 部门ID * @return 部门信息 */ - SysDept selectDeptById(Long deptId); + SysDeptVo selectDeptById(Long deptId); /** * 根据ID查询所有子部门(正常状态) @@ -75,21 +71,13 @@ public interface ISysDeptService */ boolean hasChildByDeptId(Long deptId); - /** - * 查询部门是否存在用户 - * - * @param deptId 部门ID - * @return 结果 true 存在 false 不存在 - */ - boolean checkDeptExistUser(Long deptId); - /** * 校验部门名称是否唯一 * * @param dept 部门信息 * @return 结果 */ - boolean checkDeptNameUnique(SysDept dept); + boolean checkDeptNameUnique(SysDeptBo dept); /** * 校验部门是否有数据权限 @@ -101,10 +89,10 @@ public interface ISysDeptService /** * 新增保存部门信息 * - * @param dept 部门信息 - * @return 结果 + * @param deptBo 部门信息 + * @return 受影响的行数 */ - int insertDept(SysDept dept); + int insertDept(SysDeptBo deptBo); /** * 修改保存部门信息 @@ -112,7 +100,7 @@ public interface ISysDeptService * @param dept 部门信息 * @return 结果 */ - int updateDept(SysDept dept); + boolean updateDept(SysDeptBo dept); /** * 删除部门管理信息 @@ -120,5 +108,5 @@ public interface ISysDeptService * @param deptId 部门ID * @return 结果 */ - int deleteDeptById(Long deptId); + boolean deleteDeptById(Long deptId); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java index e356e5d..e427b98 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java @@ -1,5 +1,6 @@ package com.ruoyi.system.service; +import com.ruoyi.common.orm.core.service.IBaseService; import com.ruoyi.system.domain.SysUser; import com.ruoyi.system.domain.bo.SysUserBo; import com.ruoyi.system.domain.vo.SysUserVo; @@ -11,7 +12,7 @@ import java.util.List; * * @author ruoyi */ -public interface ISysUserService +public interface ISysUserService extends IBaseService { /** * 根据条件分页查询用户列表 @@ -107,6 +108,14 @@ public interface ISysUserService */ void checkUserDataScope(Long userId); + /** + * 查询部门是否存在用户 + * + * @param deptId 部门ID + * @return 结果 true 存在 false 不存在 + */ + boolean checkDeptExistUser(Long deptId); + /** * 新增用户信息 * diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index 658921b..9ca53d7 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -5,17 +5,31 @@ import java.util.Iterator; import java.util.List; import java.util.stream.Collectors; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.lang.tree.Tree; import cn.hutool.core.util.ObjectUtil; +import com.mybatisflex.core.query.QueryMethods; +import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.core.update.UpdateChain; +import com.ruoyi.common.core.constant.CacheNames; +import com.ruoyi.common.core.core.page.PageDomain; +import com.ruoyi.common.core.core.page.TableSupport; import com.ruoyi.common.core.service.DeptService; +import com.ruoyi.common.core.utils.MapstructUtils; +import com.ruoyi.common.core.utils.TreeBuildUtils; +import com.ruoyi.common.core.utils.sql.SqlUtil; +import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl; import com.ruoyi.common.security.utils.LoginHelper; -import com.ruoyi.system.domain.SysDept; -import com.ruoyi.system.domain.SysRole; +import com.ruoyi.system.domain.*; +import com.ruoyi.system.domain.bo.SysDeptBo; +import com.ruoyi.system.domain.vo.SysDeptVo; import jakarta.annotation.Resource; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import com.ruoyi.common.core.annotation.DataScope; import com.ruoyi.common.core.constant.UserConstants; -import com.ruoyi.system.domain.TreeSelect; import com.ruoyi.common.core.core.text.Convert; import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.utils.StringUtils; @@ -23,6 +37,9 @@ import com.ruoyi.common.core.utils.SpringUtils; import com.ruoyi.system.mapper.SysDeptMapper; import com.ruoyi.system.mapper.SysRoleMapper; import com.ruoyi.system.service.ISysDeptService; +import org.springframework.transaction.annotation.Transactional; + +import static com.ruoyi.system.domain.table.SysDeptTableDef.SYS_DEPT; /** * 部门管理 服务实现 @@ -31,25 +48,57 @@ import com.ruoyi.system.service.ISysDeptService; */ @RequiredArgsConstructor @Service -public class SysDeptServiceImpl implements ISysDeptService, DeptService { +public class SysDeptServiceImpl extends BaseServiceImpl implements ISysDeptService, DeptService { @Resource private SysDeptMapper deptMapper; @Resource private SysRoleMapper roleMapper; + @Override + public QueryWrapper query() { + return super.query().from(SYS_DEPT); + } + + /** + * 根据ndeptBo构建QueryWrapper查询条件 + * + * @param deptBo + * @return 查询条件 + */ + private QueryWrapper buildQueryWrapper(SysDeptBo deptBo) { + QueryWrapper queryWrapper = super.buildBaseQueryWrapper(); + PageDomain pageDomain = TableSupport.buildPageRequest(); + queryWrapper.where(SYS_DEPT.DEL_FLAG.eq("0")); + + if (ObjectUtil.isNotNull(deptBo.getDeptId())) { + queryWrapper.and(SYS_DEPT.DEPT_ID.eq(deptBo.getDeptId())); + } + if (ObjectUtil.isNotNull(deptBo.getParentId())) { + queryWrapper.and(SYS_DEPT.PARENT_ID.eq(deptBo.getParentId())); + } + if (StringUtils.isNotNull(deptBo.getDeptName())) { + queryWrapper.and(SYS_DEPT.DEPT_NAME.like(deptBo.getDeptName())); + } + if (StringUtils.isNotNull(deptBo.getStatus())) { + queryWrapper.and(SYS_DEPT.STATUS.eq(deptBo.getStatus())); + } + queryWrapper.orderBy(SYS_DEPT.PARENT_ID.asc(),SYS_DEPT.ORDER_NUM.asc()); + + return queryWrapper; + } + /** * 查询部门管理数据 * - * @param dept 部门信息 + * @param deptBo 部门信息 * @return 部门信息集合 */ @Override @DataScope(deptAlias = "d") - public List selectDeptList(SysDept dept) { - // 只查询未禁用部门 - //dept.setStatus(UserConstants.DEPT_NORMAL); - return deptMapper.selectDeptList(dept); + public List selectDeptList(SysDeptBo deptBo) { + QueryWrapper queryWrapper = buildQueryWrapper(deptBo); + return this.listAs(queryWrapper, SysDeptVo.class); } /** @@ -59,36 +108,13 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { * @return 部门树信息集合 */ @Override - public List selectDeptTreeList(SysDept dept) { + public List> selectDeptTreeList(SysDeptBo dept) { // 只查询未禁用部门 dept.setStatus(UserConstants.DEPT_NORMAL); - List depts = SpringUtils.getAopProxy(this).selectDeptList(dept); + List depts = SpringUtils.getAopProxy(this).selectDeptList(dept); return buildDeptTreeSelect(depts); } - /** - * 构建前端所需要树结构 - * - * @param depts 部门列表 - * @return 树结构列表 - */ - @Override - public List buildDeptTree(List depts) { - List returnList = new ArrayList<>(); - List tempList = depts.stream().map(SysDept::getDeptId).collect(Collectors.toList()); - for (SysDept dept : depts) { - // 如果是顶级节点, 遍历该父节点的所有子节点 - if (!tempList.contains(dept.getParentId())) { - recursionFn(depts, dept); - returnList.add(dept); - } - } - if (returnList.isEmpty()) { - returnList = depts; - } - return returnList; - } - /** * 构建前端所需要下拉树结构 * @@ -96,9 +122,15 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { * @return 下拉树结构列表 */ @Override - public List buildDeptTreeSelect(List depts) { - List deptTrees = buildDeptTree(depts); - return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); + public List> buildDeptTreeSelect(List depts) { + if (CollUtil.isEmpty(depts)) { + return CollUtil.newArrayList(); + } + return TreeBuildUtils.build(depts, (dept, tree) -> + tree.setId(dept.getDeptId()) + .setParentId(dept.getParentId()) + .setName(dept.getDeptName()) + .setWeight(dept.getOrderNum())); } /** @@ -119,9 +151,12 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { * @param deptId 部门ID * @return 部门信息 */ + @Cacheable(cacheNames = CacheNames.SYS_DEPT, key = "#deptId") @Override - public SysDept selectDeptById(Long deptId) { - return deptMapper.selectDeptById(deptId); + public SysDeptVo selectDeptById(Long deptId) { + QueryWrapper queryWrapper = query().where(SYS_DEPT.DEL_FLAG.eq("0")); + queryWrapper.and(SYS_DEPT.DEPT_ID.eq(deptId)); + return this.getOneAs(queryWrapper, SysDeptVo.class);//TODO:缺少parent_name } /** @@ -132,7 +167,15 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { */ @Override public int selectNormalChildrenDeptById(Long deptId) { - return deptMapper.selectNormalChildrenDeptById(deptId); +// return deptMapper.selectNormalChildrenDeptById(deptId); + QueryWrapper queryWrapper = QueryWrapper.create() + .select(QueryMethods.count(SYS_DEPT.DEPT_ID)) + .from(SYS_DEPT) + .where(SYS_DEPT.STATUS.eq("0")) + .and(SYS_DEPT.DEL_FLAG.eq("0")) + .and(QueryMethods.findInSet(QueryMethods.number(deptId),SYS_DEPT.ANCESTORS).gt(0)); + + return deptMapper.selectObjectByQueryAs(queryWrapper,Integer.class); } /** @@ -143,21 +186,16 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { */ @Override public boolean hasChildByDeptId(Long deptId) { - int result = deptMapper.hasChildByDeptId(deptId); + QueryWrapper queryWrapper = QueryWrapper.create() + .select(QueryMethods.count(SYS_DEPT.DEPT_ID)) + .from(SYS_DEPT) + .where(SYS_DEPT.DEL_FLAG.eq("0")) + .and(SYS_DEPT.PARENT_ID.eq(deptId)); + + int result = deptMapper.selectObjectByQueryAs(queryWrapper,Integer.class); return result > 0; } - /** - * 查询部门是否存在用户 - * - * @param deptId 部门ID - * @return 结果 true 存在 false 不存在 - */ - @Override - public boolean checkDeptExistUser(Long deptId) { - int result = deptMapper.checkDeptExistUser(deptId); - return result > 0; - } /** * 校验部门名称是否唯一 @@ -166,9 +204,14 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { * @return 结果 */ @Override - public boolean checkDeptNameUnique(SysDept dept) { - Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId(); - SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId()); + public boolean checkDeptNameUnique(SysDeptBo dept) { + Long deptId = ObjectUtil.isNull(dept.getDeptId()) ? -1L : dept.getDeptId(); + + QueryWrapper queryWrapper = query().where(SYS_DEPT.DEL_FLAG.eq("0")); + queryWrapper.and(SYS_DEPT.DEPT_NAME.eq(dept.getDeptName())); + queryWrapper.and(SYS_DEPT.PARENT_ID.eq(dept.getParentId())); + SysDeptVo info = this.getOneAs(queryWrapper, SysDeptVo.class); + if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) { return UserConstants.NOT_UNIQUE; } @@ -189,9 +232,9 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { return; } - SysDept dept = new SysDept(); + SysDeptBo dept = new SysDeptBo(); dept.setDeptId(deptId); - List depts = SpringUtils.getAopProxy(this).selectDeptList(dept); + List depts = SpringUtils.getAopProxy(this).selectDeptList(dept); if (ObjectUtil.isNull(depts)) { throw new ServiceException("没有权限访问部门数据!"); } @@ -200,37 +243,42 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { /** * 新增保存部门信息 * - * @param dept 部门信息 - * @return 结果 + * @param deptBo 部门信息 + * @return 受影响的行数 */ @Override - public int insertDept(SysDept dept) { - SysDept info = deptMapper.selectDeptById(dept.getParentId()); + public int insertDept(SysDeptBo deptBo) { + SysDeptVo info = selectDeptById(deptBo.getParentId()); // 如果父节点不为正常状态,则不允许新增子节点 if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) { throw new ServiceException("部门停用,不允许新增"); } + SysDept dept = MapstructUtils.convert(deptBo, SysDept.class); dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); - return deptMapper.insertDept(dept); + dept.setDelFlag("0");//0代表存在 + return deptMapper.insert(dept, false); } /** * 修改保存部门信息 * - * @param dept 部门信息 - * @return 结果 + * @param deptBo 部门信息 + * @return 结果:true 更新成功,false 更新失败 */ + @Transactional + @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptBo.deptId") @Override - public int updateDept(SysDept dept) { - SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId()); - SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId()); + public boolean updateDept(SysDeptBo deptBo) { + SysDept dept = MapstructUtils.convert(deptBo, SysDept.class); + SysDeptVo newParentDept = selectDeptById(dept.getParentId()); + SysDeptVo oldDept = selectDeptById(dept.getDeptId()); if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) { String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId(); String oldAncestors = oldDept.getAncestors(); dept.setAncestors(newAncestors); updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); } - int result = deptMapper.updateDept(dept); + boolean result = this.updateById(dept); if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) && !StringUtils.equals("0", dept.getAncestors())) { // 如果该部门是启用状态,则启用该部门的所有上级部门 @@ -247,7 +295,11 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { private void updateParentDeptStatusNormal(SysDept dept) { String ancestors = dept.getAncestors(); Long[] deptIds = Convert.toLongArray(ancestors); - deptMapper.updateDeptStatusNormal(deptIds); + + UpdateChain.of(SysDept.class) + .set(SysDept::getStatus, "0") + .where(SysDept::getDeptId).in(deptIds) + .update(); } /** @@ -258,13 +310,22 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { * @param oldAncestors 旧的父ID集合 */ public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) { - List children = deptMapper.selectChildrenDeptById(deptId); - for (SysDept child : children) { + //select * from sys_dept where find_in_set(#{deptId}, ancestors) + QueryWrapper queryWrapper = QueryWrapper.create() + .from(SYS_DEPT) + .where(QueryMethods.findInSet(QueryMethods.number(deptId),SYS_DEPT.ANCESTORS).gt(0)); + + List children = this.listAs(queryWrapper, SysDeptVo.class); + + for (SysDeptVo child : children) { child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors)); + + UpdateChain.of(SysDept.class) + .set(SysDept::getAncestors, child.getAncestors()) + .where(SysDept::getDeptId).eq(child.getDeptId()) + .update(); } - if (children.size() > 0) { - deptMapper.updateDeptChildren(children); - } + return; } /** @@ -274,45 +335,49 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { * @return 结果 */ @Override - public int deleteDeptById(Long deptId) { - return deptMapper.deleteDeptById(deptId); + public boolean deleteDeptById(Long deptId) { + //update sys_dept set del_flag = '1' where dept_id = #{deptId} + SysDept sysDept = new SysDept(); + sysDept.setDeptId(deptId); + sysDept.setDelFlag("1"); + return this.updateById(sysDept); } - /** - * 递归列表 - */ - private void recursionFn(List list, SysDept t) { - // 得到子节点列表 - List childList = getChildList(list, t); - t.setChildren(childList); - for (SysDept tChild : childList) { - if (hasChild(list, tChild)) { - recursionFn(list, tChild); - } - } - } - - /** - * 得到子节点列表 - */ - private List getChildList(List list, SysDept t) { - List tlist = new ArrayList<>(); - Iterator it = list.iterator(); - while (it.hasNext()) { - SysDept n = (SysDept) it.next(); - if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) { - tlist.add(n); - } - } - return tlist; - } - - /** - * 判断是否有子节点 - */ - private boolean hasChild(List list, SysDept t) { - return getChildList(list, t).size() > 0; - } +// /** +// * 递归列表 +// */ +// private void recursionFn(List list, SysDept t) { +// // 得到子节点列表 +// List childList = getChildList(list, t); +// t.setChildren(childList); +// for (SysDept tChild : childList) { +// if (hasChild(list, tChild)) { +// recursionFn(list, tChild); +// } +// } +// } +// +// /** +// * 得到子节点列表 +// */ +// private List getChildList(List list, SysDept t) { +// List tlist = new ArrayList<>(); +// Iterator it = list.iterator(); +// while (it.hasNext()) { +// SysDept n = (SysDept) it.next(); +// if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) { +// tlist.add(n); +// } +// } +// return tlist; +// } +// +// /** +// * 判断是否有子节点 +// */ +// private boolean hasChild(List list, SysDept t) { +// return getChildList(list, t).size() > 0; +// } /** * 通过部门ID查询部门名称 @@ -324,7 +389,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { public String selectDeptNameByIds(String deptIds) { List list = new ArrayList<>(); for (Long id : StringUtils.splitTo(deptIds, Convert::toLong)) { - SysDept dept = SpringUtils.getAopProxy(this).selectDeptById(id); + SysDeptVo dept = SpringUtils.getAopProxy(this).selectDeptById(id); if (ObjectUtil.isNotNull(dept)) { list.add(dept.getDeptName()); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java index 96f03e9..45ac7f0 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java @@ -3,6 +3,7 @@ package com.ruoyi.system.service.impl; import java.util.Arrays; import java.util.List; +import cn.hutool.core.util.ObjectUtil; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryWrapper; import com.ruoyi.common.core.core.page.PageDomain; @@ -65,7 +66,7 @@ public class SysNoticeServiceImpl extends BaseServiceImpl implements ISysUserService, UserService { private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class); @Resource @@ -234,6 +236,24 @@ public class SysUserServiceImpl implements ISysUserService, UserService { } } + /** + * 查询部门是否存在用户 + * + * @param deptId 部门ID + * @return 结果 true 存在 false 不存在 + */ + @Override + public boolean checkDeptExistUser(Long deptId) { + QueryWrapper queryWrapper = QueryWrapper.create() + .select(QueryMethods.count(SYS_USER.USER_ID)) + .from(SYS_USER) + .where(SYS_USER.DEPT_ID.eq(deptId)) + .and(SYS_USER.DEL_FLAG.eq("0")); + + int result = userMapper.selectObjectByQueryAs(queryWrapper,Integer.class); + return result > 0; + } + /** * 新增保存用户信息 * diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml index 518623c..5d4ae3d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -21,32 +21,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + - select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time + select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time from sys_dept d - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - insert into sys_dept( - dept_id, - parent_id, - dept_name, - ancestors, - order_num, - leader, - phone, - email, - status, - create_by, - create_time - )values( - #{deptId}, - #{parentId}, - #{deptName}, - #{ancestors}, - #{orderNum}, - #{leader}, - #{phone}, - #{email}, - #{status}, - #{createBy}, - sysdate() - ) - - - - update sys_dept - - parent_id = #{parentId}, - dept_name = #{deptName}, - ancestors = #{ancestors}, - order_num = #{orderNum}, - leader = #{leader}, - phone = #{phone}, - email = #{email}, - status = #{status}, - update_by = #{updateBy}, - update_time = sysdate() - - where dept_id = #{deptId} - - - - update sys_dept set ancestors = - - when #{item.deptId} then #{item.ancestors} - - where dept_id in - - #{item.deptId} - - - - - update sys_dept set status = '0' where dept_id in - - #{deptId} - - - - - update sys_dept set del_flag = '1' where dept_id = #{deptId} - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml index 741f460..1b04e3a 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -13,7 +13,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + @@ -49,7 +49,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select u.user_id, u.tenant_id,u.dept_id, u.user_name, u.nick_name, u.user_type, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, + select u.user_id, u.tenant_id,u.dept_id, u.user_name, u.nick_name, u.user_type, u.email, u.avatar, u.phonenumber, u.password, u.gender, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status, r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status from sys_user u @@ -59,7 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"