1. 组件名存在重复的报错返回前端

This commit is contained in:
chenbowen
2025-09-23 09:56:53 +08:00
parent 225c6151fa
commit fab444aa8c
4 changed files with 28 additions and 18 deletions

View File

@@ -3,6 +3,8 @@ package com.zt.plat.module.system.service.permission;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import com.zt.plat.framework.common.enums.CommonStatusEnum; import com.zt.plat.framework.common.enums.CommonStatusEnum;
import com.zt.plat.framework.common.util.object.BeanUtils; import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.system.controller.admin.permission.vo.menu.MenuListReqVO; import com.zt.plat.module.system.controller.admin.permission.vo.menu.MenuListReqVO;
@@ -12,8 +14,6 @@ import com.zt.plat.module.system.dal.mysql.permission.MenuMapper;
import com.zt.plat.module.system.dal.redis.RedisKeyConstants; import com.zt.plat.module.system.dal.redis.RedisKeyConstants;
import com.zt.plat.module.system.enums.permission.MenuTypeEnum; import com.zt.plat.module.system.enums.permission.MenuTypeEnum;
import com.zt.plat.module.system.service.tenant.TenantService; import com.zt.plat.module.system.service.tenant.TenantService;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
@@ -256,7 +256,12 @@ public class MenuServiceImpl implements MenuService {
if (StrUtil.isBlank(componentName)) { if (StrUtil.isBlank(componentName)) {
return; return;
} }
MenuDO menu = menuMapper.selectByComponentName(componentName); MenuDO menu = null;
try {
menu = menuMapper.selectByComponentName(componentName);
} catch (Exception e) {
throw exception(MENU_COMPONENT_NAME_DUPLICATE);
}
if (menu == null) { if (menu == null) {
return; return;
} }

View File

@@ -1,5 +1,6 @@
package com.zt.plat.module.template.controller.admin.contract; package com.zt.plat.module.template.controller.admin.contract;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.zt.plat.framework.apilog.core.annotation.ApiAccessLog; import com.zt.plat.framework.apilog.core.annotation.ApiAccessLog;
import com.zt.plat.framework.business.annotation.FileUploadController; import com.zt.plat.framework.business.annotation.FileUploadController;
import com.zt.plat.framework.business.controller.AbstractFileUploadController; import com.zt.plat.framework.business.controller.AbstractFileUploadController;
@@ -19,7 +20,6 @@ import com.zt.plat.module.template.controller.admin.contract.vo.DemoContractResp
import com.zt.plat.module.template.controller.admin.contract.vo.DemoContractSaveReqVO; import com.zt.plat.module.template.controller.admin.contract.vo.DemoContractSaveReqVO;
import com.zt.plat.module.template.dal.dataobject.contract.DemoContractDO; import com.zt.plat.module.template.dal.dataobject.contract.DemoContractDO;
import com.zt.plat.module.template.service.contract.DemoContractService; import com.zt.plat.module.template.service.contract.DemoContractService;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;

View File

@@ -4,10 +4,11 @@ import com.zt.plat.module.infra.api.config.ConfigApi;
import com.zt.plat.module.infra.api.file.FileApi; import com.zt.plat.module.infra.api.file.FileApi;
import com.zt.plat.module.infra.api.websocket.WebSocketSenderApi; import com.zt.plat.module.infra.api.websocket.WebSocketSenderApi;
import com.zt.plat.module.system.api.dept.DeptApi; import com.zt.plat.module.system.api.dept.DeptApi;
import com.zt.plat.module.system.api.sequence.SequenceApi;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@Configuration(value = "templateRpcConfiguration", proxyBeanMethods = false) @Configuration(value = "templateRpcConfiguration", proxyBeanMethods = false)
@EnableFeignClients(clients = {FileApi.class, WebSocketSenderApi.class, ConfigApi.class, DeptApi.class}) @EnableFeignClients(clients = {FileApi.class, WebSocketSenderApi.class, ConfigApi.class, DeptApi.class, SequenceApi.class})
public class RpcConfiguration { public class RpcConfiguration {
} }

View File

@@ -1,24 +1,23 @@
package com.zt.plat.module.template.service.contract; package com.zt.plat.module.template.service.contract;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service; import com.zt.plat.framework.common.pojo.CommonResult;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import com.zt.plat.module.template.controller.admin.contract.vo.*;
import com.zt.plat.module.template.dal.dataobject.contract.DemoContractDO;
import com.zt.plat.framework.common.pojo.PageResult; import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.pojo.PageParam;
import com.zt.plat.framework.common.util.object.BeanUtils; import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.system.api.sequence.SequenceApi;
import com.zt.plat.module.template.controller.admin.contract.vo.DemoContractPageReqVO;
import com.zt.plat.module.template.controller.admin.contract.vo.DemoContractRespVO;
import com.zt.plat.module.template.controller.admin.contract.vo.DemoContractSaveReqVO;
import com.zt.plat.module.template.dal.dataobject.contract.DemoContractDO;
import com.zt.plat.module.template.dal.mysql.contract.DemoContractMapper; import com.zt.plat.module.template.dal.mysql.contract.DemoContractMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.util.List;
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception; import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.zt.plat.framework.common.util.collection.CollectionUtils.convertList; import static com.zt.plat.module.template.enums.ErrorCodeConstants.DEMO_CONTRACT_NOT_EXISTS;
import static com.zt.plat.framework.common.util.collection.CollectionUtils.diffList;
import static com.zt.plat.module.template.enums.ErrorCodeConstants.*;
/** /**
* 合同 Service 实现类 * 合同 Service 实现类
@@ -32,10 +31,15 @@ public class DemoContractServiceImpl implements DemoContractService {
@Resource @Resource
private DemoContractMapper demoContractMapper; private DemoContractMapper demoContractMapper;
@Resource
private SequenceApi sequenceApi;
@Override @Override
public DemoContractRespVO createDemoContract(DemoContractSaveReqVO createReqVO) { public DemoContractRespVO createDemoContract(DemoContractSaveReqVO createReqVO) {
// 插入 // 插入
DemoContractDO demoContract = BeanUtils.toBean(createReqVO, DemoContractDO.class); DemoContractDO demoContract = BeanUtils.toBean(createReqVO, DemoContractDO.class);
CommonResult<String> seq = sequenceApi.getNextSequence("SEQ", null, null);
demoContract.setCode(seq.getData());
demoContractMapper.insert(demoContract); demoContractMapper.insert(demoContract);
// 返回 // 返回
return BeanUtils.toBean(demoContract, DemoContractRespVO.class); return BeanUtils.toBean(demoContract, DemoContractRespVO.class);