| | |
| | | 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; |
| | |
| | | |
| | | @Override |
| | | public Long createTenantPackage(TenantPackageSaveReqVO createReqVO) { |
| | | // 校验套餐名是否重复 |
| | | validateTenantPackageNameUnique(null, createReqVO.getName()); |
| | | // 插入 |
| | | TenantPackageDO tenantPackage = BeanUtils.toBean(createReqVO, TenantPackageDO.class); |
| | | tenantPackageMapper.insert(tenantPackage); |
| | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | } |