From 6e21c6472843d67bfb5dd590e33207a58d41695e Mon Sep 17 00:00:00 2001 From: MichelleChung <1242874891@qq.com> Date: 星期四, 02 三月 2023 22:09:51 +0800 Subject: [PATCH] !292 mapstruct-plus 接入替换 BeanUtil * add 新增 mapstruct-plus 用于实体类转换 ; --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTenantServiceImpl.java | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTenantServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTenantServiceImpl.java index e22f651..ea2bc54 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTenantServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysTenantServiceImpl.java @@ -1,7 +1,6 @@ package com.ruoyi.system.service.impl; import cn.dev33.satoken.secure.BCrypt; -import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.RandomUtil; @@ -12,6 +11,7 @@ import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.TenantConstants; import com.ruoyi.common.core.exception.ServiceException; +import com.ruoyi.common.core.utils.MapstructUtils; import com.ruoyi.common.core.utils.SpringUtils; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.mybatis.core.page.PageQuery; @@ -115,7 +115,7 @@ public Boolean insertByBo(SysTenantBo bo) { TenantHelper.enableIgnore(); - SysTenant add = BeanUtil.toBean(bo, SysTenant.class); + SysTenant add = MapstructUtils.convert(bo, SysTenant.class); // 鑾峰彇鎵�鏈夌鎴风紪鍙� List<String> tenantIds = baseMapper.selectObjs( @@ -124,6 +124,7 @@ add.setTenantId(tenantId); boolean flag = baseMapper.insert(add) > 0; if (!flag) { + TenantHelper.disableIgnore(); throw new ServiceException("鍒涘缓绉熸埛澶辫触"); } bo.setId(add.getId()); @@ -251,7 +252,7 @@ @CacheEvict(cacheNames = CacheNames.SYS_TENANT, key = "#bo.tenantId") @Override public Boolean updateByBo(SysTenantBo bo) { - SysTenant tenant = BeanUtil.toBean(bo, SysTenant.class); + SysTenant tenant = MapstructUtils.convert(bo, SysTenant.class); tenant.setTenantId(null); tenant.setPackageId(null); return baseMapper.updateById(tenant) > 0; @@ -266,7 +267,7 @@ @CacheEvict(cacheNames = CacheNames.SYS_TENANT, key = "#bo.tenantId") @Override public int updateTenantStatus(SysTenantBo bo) { - SysTenant tenant = BeanUtil.toBean(bo, SysTenant.class); + SysTenant tenant = MapstructUtils.convert(bo, SysTenant.class); return baseMapper.updateById(tenant); } @@ -278,6 +279,9 @@ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { if (isValid) { // 鍋氫竴浜涗笟鍔′笂鐨勬牎楠�,鍒ゆ柇鏄惁闇�瑕佹牎楠� + if (ids.contains(TenantConstants.SUPER_ADMIN_ID)) { + throw new ServiceException("瓒呯绉熸埛涓嶈兘鍒犻櫎"); + } } return baseMapper.deleteBatchIds(ids) > 0; } -- Gitblit v1.9.3