From 2f558094d133549b7e1867c6f9d674ec04cef360 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期四, 02 三月 2023 23:32:29 +0800
Subject: [PATCH] fix 修复 !pr292 相关问题 并优化写法

---
 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