From 6d995308c4aeb9cf35f9e1e1f39e96fb0c46a8db Mon Sep 17 00:00:00 2001 From: Parker Date: Mon, 11 Jan 2021 19:22:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E7=BB=87=E7=BB=93=E6=9E=84=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=9B=B4=E6=94=B9=E7=A7=9F=E6=88=B7=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E9=80=90=E7=BA=A7=E4=BF=AE=E6=94=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/opsli/modulars/system/SystemMsg.java | 4 +- .../menu/service/impl/MenuServiceImpl.java | 6 +-- .../org/service/impl/SysOrgServiceImpl.java | 46 ++++++++++++++++--- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java index 0947cfa..fcc6049 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/SystemMsg.java @@ -69,7 +69,9 @@ public enum SystemMsg implements BaseMsg { * 组织机构 */ EXCEPTION_ORG_UNIQUE(20500,"组织机构编号重复,已存在"), - EXCEPTION_ORG_USE(20501,"组织机构已被引用,不能删除"), + EXCEPTION_ORG_USE(20501,"组织机构已被引用,不能操作"), + EXCEPTION_ORG_USE_TENANT(20501,"组织机构已被引用,不能修改租户"), + /** * 地域 diff --git a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/service/impl/MenuServiceImpl.java b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/service/impl/MenuServiceImpl.java index efd98f9..d963065 100644 --- a/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/service/impl/MenuServiceImpl.java +++ b/opsli-modulars/opsli-modulars-system/src/main/java/org/opsli/modulars/system/menu/service/impl/MenuServiceImpl.java @@ -163,8 +163,7 @@ public class MenuServiceImpl extends CrudServiceImpl queryBuilder = new GenQueryBuilder<>(); QueryWrapper queryWrapper = queryBuilder.build(); queryWrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); @@ -172,9 +171,8 @@ public class MenuServiceImpl extends CrudServiceImpl queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("org_id", sysOrgModel.getId()); + Integer countTmp = mapper.hasUse(queryWrapper); + if(countTmp > 0){ + // 组织机构已被引用,不能删除 + throw new ServiceException(SystemMsg.EXCEPTION_ORG_USE_TENANT); + } + + // 如果没有被引用 则逐级修改 + this.updateTenantByParentId(sysOrgModel.getId(), model.getTenantId()); + } + + // 修改 return super.update(model); } @@ -167,24 +184,41 @@ public class SysOrgServiceImpl extends CrudServiceImpl queryBuilder = new GenQueryBuilder<>(); + QueryWrapper queryWrapper = queryBuilder.build(); + queryWrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); + List entityList = super.findList(queryWrapper); + for (SysOrg sysOrg : entityList) { + sysOrg.setTenantId(tenantId); + super.updateById(sysOrg); + // 逐级删除子数据 + this.updateTenantByParentId(sysOrg.getId(), tenantId); + } + } + /** * 逐级删除子数据 * @param parentId * @return */ @Transactional(rollbackFor = Exception.class) - public boolean deleteByParentId(String parentId) { - boolean ret = false; + public void deleteByParentId(String parentId) { QueryBuilder queryBuilder = new GenQueryBuilder<>(); QueryWrapper queryWrapper = queryBuilder.build(); queryWrapper.eq(HumpUtil.humpToUnderline(MyBatisConstants.FIELD_PARENT_ID), parentId); - List menuList = super.findList(queryWrapper); - for (SysOrg sysOrg : menuList) { + List entityList = super.findList(queryWrapper); + for (SysOrg sysOrg : entityList) { super.delete(sysOrg.getId()); // 逐级删除子数据 - ret = this.deleteByParentId(sysOrg.getId()); + this.deleteByParentId(sysOrg.getId()); } - return ret; } /**