添加租户、项目 ID 唯一性校验.

pull/10/head
chen.ma 3 years ago
parent fb1441708b
commit 2100145b0a

@ -1,5 +1,6 @@
package cn.hippo4j.config.service.biz.impl; package cn.hippo4j.config.service.biz.impl;
import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.config.enums.DelEnum; import cn.hippo4j.config.enums.DelEnum;
import cn.hippo4j.config.mapper.ItemInfoMapper; import cn.hippo4j.config.mapper.ItemInfoMapper;
import cn.hippo4j.config.model.ItemInfo; import cn.hippo4j.config.model.ItemInfo;
@ -7,16 +8,16 @@ import cn.hippo4j.config.model.biz.item.ItemQueryReqDTO;
import cn.hippo4j.config.model.biz.item.ItemRespDTO; import cn.hippo4j.config.model.biz.item.ItemRespDTO;
import cn.hippo4j.config.model.biz.item.ItemSaveReqDTO; import cn.hippo4j.config.model.biz.item.ItemSaveReqDTO;
import cn.hippo4j.config.model.biz.item.ItemUpdateReqDTO; import cn.hippo4j.config.model.biz.item.ItemUpdateReqDTO;
import cn.hippo4j.config.model.biz.threadpool.ThreadPoolRespDTO;
import cn.hippo4j.config.service.biz.ItemService; import cn.hippo4j.config.service.biz.ItemService;
import cn.hippo4j.config.service.biz.ThreadPoolService;
import cn.hippo4j.config.toolkit.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import cn.hippo4j.config.model.biz.threadpool.ThreadPoolRespDTO;
import cn.hippo4j.config.service.biz.ThreadPoolService;
import cn.hippo4j.config.toolkit.BeanUtil;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -73,6 +74,12 @@ public class ItemServiceImpl implements ItemService {
@Override @Override
public void saveItem(ItemSaveReqDTO reqDTO) { public void saveItem(ItemSaveReqDTO reqDTO) {
LambdaQueryWrapper<ItemInfo> queryWrapper = Wrappers.lambdaQuery(ItemInfo.class)
.eq(ItemInfo::getItemId, reqDTO.getItemId());
ItemInfo existItemInfo = itemInfoMapper.selectOne(queryWrapper);
Assert.isNull(existItemInfo, "项目 ID 不允许重复.");
ItemInfo itemInfo = BeanUtil.convert(reqDTO, ItemInfo.class); ItemInfo itemInfo = BeanUtil.convert(reqDTO, ItemInfo.class);
int insertResult = itemInfoMapper.insert(itemInfo); int insertResult = itemInfoMapper.insert(itemInfo);

@ -1,24 +1,25 @@
package cn.hippo4j.config.service.biz.impl; package cn.hippo4j.config.service.biz.impl;
import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.config.enums.DelEnum; import cn.hippo4j.config.enums.DelEnum;
import cn.hippo4j.config.mapper.TenantInfoMapper; import cn.hippo4j.config.mapper.TenantInfoMapper;
import cn.hippo4j.config.model.TenantInfo; import cn.hippo4j.config.model.TenantInfo;
import cn.hippo4j.config.model.biz.item.ItemQueryReqDTO; import cn.hippo4j.config.model.biz.item.ItemQueryReqDTO;
import cn.hippo4j.config.model.biz.item.ItemRespDTO; import cn.hippo4j.config.model.biz.item.ItemRespDTO;
import cn.hippo4j.config.model.biz.tenant.TenantQueryReqDTO; import cn.hippo4j.config.model.biz.tenant.TenantQueryReqDTO;
import cn.hippo4j.config.model.biz.tenant.TenantRespDTO;
import cn.hippo4j.config.model.biz.tenant.TenantSaveReqDTO; import cn.hippo4j.config.model.biz.tenant.TenantSaveReqDTO;
import cn.hippo4j.config.model.biz.tenant.TenantUpdateReqDTO;
import cn.hippo4j.config.service.biz.ItemService; import cn.hippo4j.config.service.biz.ItemService;
import cn.hippo4j.config.service.biz.TenantService;
import cn.hippo4j.config.toolkit.BeanUtil;
import cn.hippo4j.tools.logrecord.annotation.LogRecord;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import cn.hippo4j.config.model.biz.tenant.TenantRespDTO;
import cn.hippo4j.config.model.biz.tenant.TenantUpdateReqDTO;
import cn.hippo4j.config.service.biz.TenantService;
import cn.hippo4j.config.toolkit.BeanUtil;
import cn.hippo4j.tools.logrecord.annotation.LogRecord;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -67,6 +68,12 @@ public class TenantServiceImpl implements TenantService {
@Override @Override
public void saveTenant(TenantSaveReqDTO reqDTO) { public void saveTenant(TenantSaveReqDTO reqDTO) {
LambdaQueryWrapper<TenantInfo> queryWrapper = Wrappers.lambdaQuery(TenantInfo.class)
.eq(TenantInfo::getTenantId, reqDTO.getTenantId());
TenantInfo existTenantInfo = tenantInfoMapper.selectOne(queryWrapper);
Assert.isNull(existTenantInfo, "租户 ID 不允许重复.");
TenantInfo tenantInfo = BeanUtil.convert(reqDTO, TenantInfo.class); TenantInfo tenantInfo = BeanUtil.convert(reqDTO, TenantInfo.class);
int insertResult = tenantInfoMapper.insert(tenantInfo); int insertResult = tenantInfoMapper.insert(tenantInfo);

Loading…
Cancel
Save