update 优化 租户套餐重名校验

2.X
疯狂的狮子Li 5 months ago
parent 528cee3eaa
commit 6dab38be78

@ -93,6 +93,9 @@ public class SysTenantPackageController extends BaseController {
@RepeatSubmit()
@PostMapping()
public R<Void> add(@Validated(AddGroup.class) @RequestBody SysTenantPackageBo bo) {
if (!tenantPackageService.checkPackageNameUnique(bo)) {
return R.fail("新增套餐'" + bo.getPackageName() + "'失败,套餐名称已存在");
}
return toAjax(tenantPackageService.insertByBo(bo));
}
@ -105,6 +108,9 @@ public class SysTenantPackageController extends BaseController {
@RepeatSubmit()
@PutMapping()
public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysTenantPackageBo bo) {
if (!tenantPackageService.checkPackageNameUnique(bo)) {
return R.fail("修改套餐'" + bo.getPackageName() + "'失败,套餐名称已存在");
}
return toAjax(tenantPackageService.updateByBo(bo));
}

@ -45,6 +45,11 @@ public interface ISysTenantPackageService {
*/
Boolean updateByBo(SysTenantPackageBo bo);
/**
*
*/
boolean checkPackageNameUnique(SysTenantPackageBo bo);
/**
*
*/

@ -1,6 +1,7 @@
package org.dromara.system.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -116,6 +117,17 @@ public class SysTenantPackageServiceImpl implements ISysTenantPackageService {
return baseMapper.updateById(update) > 0;
}
/**
*
*/
@Override
public boolean checkPackageNameUnique(SysTenantPackageBo bo) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysTenantPackage>()
.eq(SysTenantPackage::getPackageName, bo.getPackageName())
.ne(ObjectUtil.isNotNull(bo.getPackageId()), SysTenantPackage::getPackageId, bo.getPackageId()));
return !exist;
}
/**
*
*

Loading…
Cancel
Save