diff --git a/src/modules/system/controller/sys_tenant.go b/src/modules/system/controller/sys_tenant.go index 03f7e368..30d15291 100644 --- a/src/modules/system/controller/sys_tenant.go +++ b/src/modules/system/controller/sys_tenant.go @@ -141,7 +141,7 @@ func (s *SysTenantController) Add(c *gin.Context) { return } } else { - uniqueTenancy := s.sysTenantService.IsUniqueTenancy(body.TenancyType, body.TenancyKey) + uniqueTenancy := s.sysTenantService.IsUniqueTenancy(body.TenantID, body.TenancyType, body.TenancyKey) if !uniqueTenancy { // 租赁对象添加失败,租赁对象已存在 msg := i18n.TTemplate(language, "Tenancy object is exist", map[string]any{"key": body.TenancyKey}) @@ -206,7 +206,7 @@ func (s *SysTenantController) Edit(c *gin.Context) { return } } else { - uniqueTenancy := s.sysTenantService.IsUniqueTenancy(body.TenancyType, body.TenancyKey) + uniqueTenancy := s.sysTenantService.IsUniqueTenancy(body.TenantID, body.TenancyType, body.TenancyKey) if !uniqueTenancy { // 租赁对象添加失败,租赁对象已存在 msg := i18n.TTemplate(language, "Tenancy object is exist", map[string]any{"key": body.TenancyKey}) diff --git a/src/modules/system/model/sys_tenant.go b/src/modules/system/model/sys_tenant.go index c70ed51f..656c1f5b 100644 --- a/src/modules/system/model/sys_tenant.go +++ b/src/modules/system/model/sys_tenant.go @@ -9,7 +9,7 @@ type SysTenant struct { // 祖级列表 Ancestors string `json:"ancestors"` // 租户名称 - TenantName string `json:"tenantName" binding:"required"` + TenantName string `json:"tenantName"` // 显示顺序 OrderNum int `json:"orderNum"` // tenancy type: sd-sst, apn, imsi, msisdn diff --git a/src/modules/system/repository/sys_tenant.impl.go b/src/modules/system/repository/sys_tenant.impl.go index 4d0776cb..5dc72b9b 100644 --- a/src/modules/system/repository/sys_tenant.impl.go +++ b/src/modules/system/repository/sys_tenant.impl.go @@ -236,6 +236,10 @@ func (r *SysTenantImpl) IsUniqueTenancy(sysTenant model.SysTenant) bool { // 查询条件拼接 var conditions []string var params []any + if sysTenant.TenantID != "" { + conditions = append(conditions, "tenant_id != ?") + params = append(params, sysTenant.TenantID) + } if sysTenant.TenancyType != "" { conditions = append(conditions, "tenancy_type = ?") params = append(params, sysTenant.TenancyType) diff --git a/src/modules/system/service/sys_tenant.go b/src/modules/system/service/sys_tenant.go index c9df9ab2..7ce0a358 100644 --- a/src/modules/system/service/sys_tenant.go +++ b/src/modules/system/service/sys_tenant.go @@ -26,7 +26,7 @@ type ISysTenant interface { CheckUniqueTenantName(tenantName, parentId, tenantId string) bool // check unique tenancy_type and tenancy_key - IsUniqueTenancy(tenancyType, tenancyKey string) bool + IsUniqueTenancy(tenantID, tenancyType, tenancyKey string) bool // InsertTenant 新增租户信息 InsertTenant(sysTenant model.SysTenant) string diff --git a/src/modules/system/service/sys_tenant.impl.go b/src/modules/system/service/sys_tenant.impl.go index 5eb69810..b73f44bd 100644 --- a/src/modules/system/service/sys_tenant.impl.go +++ b/src/modules/system/service/sys_tenant.impl.go @@ -74,8 +74,9 @@ func (r *SysTenantImpl) CheckUniqueTenantName(tenantName, parentId, tenantId str } // CheckUniqueTenantName 校验同级部门名称是否唯一 -func (r *SysTenantImpl) IsUniqueTenancy(tenancyType, tenancyKey string) bool { +func (r *SysTenantImpl) IsUniqueTenancy(tenantID, tenancyType, tenancyKey string) bool { return r.sysTenantRepository.IsUniqueTenancy(model.SysTenant{ + TenantID: tenantID, TenancyType: tenancyType, TenancyKey: tenancyKey, })