From b8a0affd03b5fa9fa33cd6f870e90394c2df86c7 Mon Sep 17 00:00:00 2001
From: 潘志宝 <979469083@qq.com>
Date: 星期一, 06 一月 2025 13:31:07 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/tenant/TenantPackageServiceImpl.java |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/tenant/TenantPackageServiceImpl.java b/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/tenant/TenantPackageServiceImpl.java
index 06371fa..e5898b6 100644
--- a/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/tenant/TenantPackageServiceImpl.java
+++ b/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/service/tenant/TenantPackageServiceImpl.java
@@ -1,6 +1,8 @@
 package com.iailab.module.system.service.tenant;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.google.common.annotations.VisibleForTesting;
 import com.iailab.framework.common.enums.CommonStatusEnum;
 import com.iailab.framework.common.pojo.PageResult;
 import com.iailab.framework.common.util.object.BeanUtils;
@@ -38,6 +40,8 @@
 
     @Override
     public Long createTenantPackage(TenantPackageSaveReqVO createReqVO) {
+        // 校验套餐名是否重复
+        validateTenantPackageNameUnique(null, createReqVO.getName());
         // 插入
         TenantPackageDO tenantPackage = BeanUtils.toBean(createReqVO, TenantPackageDO.class);
         tenantPackageMapper.insert(tenantPackage);
@@ -111,4 +115,22 @@
         return tenantPackageMapper.selectListByStatus(status);
     }
 
+    @VisibleForTesting
+    void validateTenantPackageNameUnique(Long id, String name) {
+        if (StrUtil.isBlank(name)) {
+            return;
+        }
+        TenantPackageDO tenantPackage = tenantPackageMapper.selectByName(name);
+        if (tenantPackage == null) {
+            return;
+        }
+        // 如果 id 为空,说明不用比较是否为相同 id 的用户
+        if (id == null) {
+            throw exception(TENANT_PACKAGE_NAME_DUPLICATE);
+        }
+        if (!tenantPackage.getId().equals(id)) {
+            throw exception(TENANT_PACKAGE_NAME_DUPLICATE);
+        }
+    }
+
 }

--
Gitblit v1.9.3