From 8ba346faa6318bc78b5427a7feede5474c9e03d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=9D=B0?= <693337446@qq.com> Date: Mon, 31 May 2021 17:23:13 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BF=AE=E6=94=B9=E6=A1=86=E6=9E=B6?= =?UTF-8?q?=E4=B8=AD=E6=89=B9=E9=87=8F=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=8E=9F=E7=94=9Fmybatis=E6=89=A7=E8=A1=8Cforeach?= =?UTF-8?q?=EF=BC=8C=E6=94=B9=E5=96=84=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ruoyi/system/mapper/SysDeptMapper.java | 8 ++++++++ .../com/ruoyi/system/mapper/SysRoleDeptMapper.java | 10 ++++++++++ .../com/ruoyi/system/mapper/SysRoleMenuMapper.java | 10 ++++++++++ .../com/ruoyi/system/mapper/SysUserPostMapper.java | 10 ++++++++++ .../com/ruoyi/system/mapper/SysUserRoleMapper.java | 10 ++++++++++ .../system/service/impl/SysDeptServiceImpl.java | 2 +- .../system/service/impl/SysRoleServiceImpl.java | 8 ++------ .../system/service/impl/SysUserServiceImpl.java | 8 ++------ .../main/resources/mapper/system/SysDeptMapper.xml | 13 +++++++++++++ .../resources/mapper/system/SysRoleDeptMapper.xml | 9 ++++++++- .../resources/mapper/system/SysRoleMenuMapper.xml | 9 ++++++++- .../resources/mapper/system/SysUserPostMapper.xml | 9 ++++++++- .../resources/mapper/system/SysUserRoleMapper.xml | 9 ++++++++- 13 files changed, 98 insertions(+), 17 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java index 12824e75..54fe2611 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java @@ -30,4 +30,12 @@ public interface SysDeptMapper extends BaseMapperPlus { */ public List selectDeptListByRoleId(@Param("roleId") Long roleId, @Param("deptCheckStrictly") boolean deptCheckStrictly); + /** + * 修改子元素关系 + * + * @param depts 子元素 + * @return 结果 + */ + public int updateDeptChildren(@Param("depts") List depts); + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleDeptMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleDeptMapper.java index 6121490c..331ecb91 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleDeptMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleDeptMapper.java @@ -3,6 +3,8 @@ package com.ruoyi.system.mapper; import com.ruoyi.common.core.page.BaseMapperPlus; import com.ruoyi.system.domain.SysRoleDept; +import java.util.List; + /** * 角色与部门关联表 数据层 * @@ -10,4 +12,12 @@ import com.ruoyi.system.domain.SysRoleDept; */ public interface SysRoleDeptMapper extends BaseMapperPlus { + /** + * 批量新增角色部门信息 + * + * @param roleDeptList 角色部门列表 + * @return 结果 + */ + public int batchRoleDept(List roleDeptList); + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java index fa8c5a34..4f08ceae 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java @@ -3,6 +3,8 @@ package com.ruoyi.system.mapper; import com.ruoyi.common.core.page.BaseMapperPlus; import com.ruoyi.system.domain.SysRoleMenu; +import java.util.List; + /** * 角色与菜单关联表 数据层 * @@ -10,4 +12,12 @@ import com.ruoyi.system.domain.SysRoleMenu; */ public interface SysRoleMenuMapper extends BaseMapperPlus { + /** + * 批量新增角色菜单信息 + * + * @param roleMenuList 角色菜单列表 + * @return 结果 + */ + public int batchRoleMenu(List roleMenuList); + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserPostMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserPostMapper.java index c17dfd5f..7839bbe1 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserPostMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserPostMapper.java @@ -3,6 +3,8 @@ package com.ruoyi.system.mapper; import com.ruoyi.common.core.page.BaseMapperPlus; import com.ruoyi.system.domain.SysUserPost; +import java.util.List; + /** * 用户与岗位关联表 数据层 * @@ -10,4 +12,12 @@ import com.ruoyi.system.domain.SysUserPost; */ public interface SysUserPostMapper extends BaseMapperPlus { + /** + * 批量新增用户岗位信息 + * + * @param userPostList 用户角色列表 + * @return 结果 + */ + public int batchUserPost(List userPostList); + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java index ddebd389..365bbf47 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java @@ -3,6 +3,8 @@ package com.ruoyi.system.mapper; import com.ruoyi.common.core.page.BaseMapperPlus; import com.ruoyi.system.domain.SysUserRole; +import java.util.List; + /** * 用户与角色关联表 数据层 * @@ -10,4 +12,12 @@ import com.ruoyi.system.domain.SysUserRole; */ public interface SysUserRoleMapper extends BaseMapperPlus { + /** + * 批量新增用户角色信息 + * + * @param userRoleList 用户角色列表 + * @return 结果 + */ + public int batchUserRole(List userRoleList); + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index 65f86013..7cdda238 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -244,7 +244,7 @@ public class SysDeptServiceImpl extends ServiceImpl impl child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors)); } if (children.size() > 0) { - updateBatchById(children); + baseMapper.updateDeptChildren(children); } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java index 9d4b10a9..c46c45f9 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java @@ -240,9 +240,7 @@ public class SysRoleServiceImpl extends ServiceImpl impl list.add(rm); } if (list.size() > 0) { - for (SysRoleMenu sysRoleMenu : list) { - rows += roleMenuMapper.insert(sysRoleMenu); - } + rows = roleMenuMapper.batchRoleMenu(list); } return rows; } @@ -263,9 +261,7 @@ public class SysRoleServiceImpl extends ServiceImpl impl list.add(rd); } if (list.size() > 0) { - for (SysRoleDept sysRoleDept : list) { - rows += roleDeptMapper.insert(sysRoleDept); - } + rows = roleDeptMapper.batchRoleDept(list); } return rows; } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java index f729a818..d3fd7250 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java @@ -311,9 +311,7 @@ public class SysUserServiceImpl extends ServiceImpl impl list.add(ur); } if (list.size() > 0) { - for (SysUserRole sysUserRole : list) { - userRoleMapper.insert(sysUserRole); - } + userRoleMapper.batchUserRole(list); } } } @@ -335,9 +333,7 @@ public class SysUserServiceImpl extends ServiceImpl impl list.add(up); } if (list.size() > 0) { - for (SysUserPost sysUserPost : list) { - userPostMapper.insert(sysUserPost); - } + userPostMapper.batchUserPost(list); } } } diff --git a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml index 21f68541..2f565444 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -57,4 +57,17 @@ order by d.parent_id, d.order_num + + update sys_dept set ancestors = + + when #{item.deptId} then #{item.ancestors} + + where dept_id in + + #{item.deptId} + + + diff --git a/ruoyi-system/src/main/resources/mapper/system/SysRoleDeptMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysRoleDeptMapper.xml index 0fda6825..cace1f56 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysRoleDeptMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysRoleDeptMapper.xml @@ -9,4 +9,11 @@ - \ No newline at end of file + + insert into sys_role_dept(role_id, dept_id) values + + (#{item.roleId},#{item.deptId}) + + + + diff --git a/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml index 2529a720..356b6123 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml @@ -9,4 +9,11 @@ - \ No newline at end of file + + insert into sys_role_menu(role_id, menu_id) values + + (#{item.roleId},#{item.menuId}) + + + + diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserPostMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserPostMapper.xml index bd13ed43..8d70825c 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysUserPostMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysUserPostMapper.xml @@ -9,4 +9,11 @@ - \ No newline at end of file + + insert into sys_user_post(user_id, post_id) values + + (#{item.userId},#{item.postId}) + + + + diff --git a/ruoyi-system/src/main/resources/mapper/system/SysUserRoleMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysUserRoleMapper.xml index 3d41141b..1db2f0fe 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysUserRoleMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysUserRoleMapper.xml @@ -9,4 +9,11 @@ - \ No newline at end of file + + insert into sys_user_role(user_id, role_id) values + + (#{item.userId},#{item.roleId}) + + + +