1、统一抛出ServiceException带占位符的填充方式,不再使用ServiceExceptionUtils;2、新增System服务ErrorCode的国际化;3、Webcad异步导入移除分布式锁,导入解析事务完善;

This commit is contained in:
gaoqr
2025-11-20 11:12:21 +08:00
parent f051e6466b
commit ab4ec08078
139 changed files with 1005 additions and 1193 deletions
@@ -1,5 +1,6 @@
package com.cf.imes.module.infra.controller.admin.config;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.pojo.PageParam;
import com.cf.imes.framework.common.pojo.PageResult;
@@ -25,7 +26,7 @@ import jakarta.validation.Valid;
import java.io.IOException;
import java.util.List;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.framework.common.pojo.CommonResult.success;
import static com.cf.imes.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@@ -79,7 +80,7 @@ public class ConfigController {
return success(null);
}
if (!config.getVisible()) {
throw exception(ErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_VISIBLE);
throw new ServiceException(ErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_VISIBLE);
}
return success(config.getValue());
}
@@ -2,6 +2,7 @@ package com.cf.imes.module.infra.service.codegen;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.CharSequenceUtil;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.module.infra.controller.admin.codegen.vo.CodegenCreateListReqVO;
@@ -30,7 +31,7 @@ import java.util.*;
import java.util.function.BiPredicate;
import java.util.stream.Collectors;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertMap;
import static com.cf.imes.framework.common.util.collection.CollectionUtils.convertSet;
import static com.cf.imes.module.infra.enums.ErrorCodeConstants.*;
@@ -84,7 +85,7 @@ public class CodegenServiceImpl implements CodegenService {
// 校验是否已经存在
if (codegenTableMapper.selectByTableNameAndDataSourceConfigId(tableInfo.getName(),
dataSourceConfigId) != null) {
throw exception(CODEGEN_TABLE_EXISTS);
throw new ServiceException(CODEGEN_TABLE_EXISTS);
}
// 构建 CodegenTableDO 对象,插入到 DB 中
@@ -108,17 +109,17 @@ public class CodegenServiceImpl implements CodegenService {
@VisibleForTesting
void validateTableInfo(TableInfo tableInfo) {
if (tableInfo == null) {
throw exception(CODEGEN_IMPORT_TABLE_NULL);
throw new ServiceException(CODEGEN_IMPORT_TABLE_NULL);
}
if (CharSequenceUtil.isEmpty(tableInfo.getComment())) {
throw exception(CODEGEN_TABLE_INFO_TABLE_COMMENT_IS_NULL);
throw new ServiceException(CODEGEN_TABLE_INFO_TABLE_COMMENT_IS_NULL);
}
if (CollUtil.isEmpty(tableInfo.getFields())) {
throw exception(CODEGEN_IMPORT_COLUMNS_NULL);
throw new ServiceException(CODEGEN_IMPORT_COLUMNS_NULL);
}
tableInfo.getFields().forEach(field -> {
if (CharSequenceUtil.isEmpty(field.getComment())) {
throw exception(CODEGEN_TABLE_INFO_COLUMN_COMMENT_IS_NULL, field.getName());
throw new ServiceException(CODEGEN_TABLE_INFO_COLUMN_COMMENT_IS_NULL, field.getName());
}
});
}
@@ -128,16 +129,16 @@ public class CodegenServiceImpl implements CodegenService {
public void updateCodegen(CodegenUpdateReqVO updateReqVO) {
// 校验是否已经存在
if (codegenTableMapper.selectById(updateReqVO.getTable().getId()) == null) {
throw exception(CODEGEN_TABLE_NOT_EXISTS);
throw new ServiceException(CODEGEN_TABLE_NOT_EXISTS);
}
// 校验主表字段存在
if (Objects.equals(updateReqVO.getTable().getTemplateType(), CodegenTemplateTypeEnum.SUB.getType())) {
if (codegenTableMapper.selectById(updateReqVO.getTable().getMasterTableId()) == null) {
throw exception(CODEGEN_MASTER_TABLE_NOT_EXISTS, updateReqVO.getTable().getMasterTableId());
throw new ServiceException(CODEGEN_MASTER_TABLE_NOT_EXISTS, updateReqVO.getTable().getMasterTableId());
}
if (CollUtil.findOne(updateReqVO.getColumns(), // 关联主表的字段不存在
column -> column.getId().equals(updateReqVO.getTable().getSubJoinColumnId())) == null) {
throw exception(CODEGEN_SUB_COLUMN_NOT_EXISTS, updateReqVO.getTable().getSubJoinColumnId());
throw new ServiceException(CODEGEN_SUB_COLUMN_NOT_EXISTS, updateReqVO.getTable().getSubJoinColumnId());
}
}
@@ -155,7 +156,7 @@ public class CodegenServiceImpl implements CodegenService {
// 校验是否已经存在
CodegenTableDO table = codegenTableMapper.selectById(tableId);
if (table == null) {
throw exception(CODEGEN_TABLE_NOT_EXISTS);
throw new ServiceException(CODEGEN_TABLE_NOT_EXISTS);
}
// 从数据库中,获得数据库表结构
TableInfo tableInfo = databaseTableService.getTable(table.getDataSourceConfigId(), table.getTableName());
@@ -192,7 +193,7 @@ public class CodegenServiceImpl implements CodegenService {
// 移除已经存在的字段
tableFields.removeIf(column -> codegenColumnNames.contains(column.getColumnName()) && (!modifyFieldNames.contains(column.getColumnName())));
if (CollUtil.isEmpty(tableFields) && CollUtil.isEmpty(deleteColumnIds)) {
throw exception(CODEGEN_SYNC_NONE_CHANGE);
throw new ServiceException(CODEGEN_SYNC_NONE_CHANGE);
}
// 4.1 插入新增的字段
@@ -209,7 +210,7 @@ public class CodegenServiceImpl implements CodegenService {
public void deleteCodegen(Long tableId) {
// 校验是否已经存在
if (codegenTableMapper.selectById(tableId) == null) {
throw exception(CODEGEN_TABLE_NOT_EXISTS);
throw new ServiceException(CODEGEN_TABLE_NOT_EXISTS);
}
// 删除 table 表定义
@@ -243,11 +244,11 @@ public class CodegenServiceImpl implements CodegenService {
// 校验是否已经存在
CodegenTableDO table = codegenTableMapper.selectById(tableId);
if (table == null) {
throw exception(CODEGEN_TABLE_NOT_EXISTS);
throw new ServiceException(CODEGEN_TABLE_NOT_EXISTS);
}
List<CodegenColumnDO> columns = codegenColumnMapper.selectListByTableId(tableId);
if (CollUtil.isEmpty(columns)) {
throw exception(CODEGEN_COLUMN_NOT_EXISTS);
throw new ServiceException(CODEGEN_COLUMN_NOT_EXISTS);
}
// 如果是主子表,则加载对应的子表信息
@@ -258,14 +259,14 @@ public class CodegenServiceImpl implements CodegenService {
subTables = codegenTableMapper.selectListByTemplateTypeAndMasterTableId(
CodegenTemplateTypeEnum.SUB.getType(), tableId);
if (CollUtil.isEmpty(subTables)) {
throw exception(CODEGEN_MASTER_GENERATION_FAIL_NO_SUB_TABLE);
throw new ServiceException(CODEGEN_MASTER_GENERATION_FAIL_NO_SUB_TABLE);
}
// 校验子表的关联字段存在
subColumnsList = new ArrayList<>();
for (CodegenTableDO subTable : subTables) {
List<CodegenColumnDO> subColumns = codegenColumnMapper.selectListByTableId(subTable.getId());
if (CollUtil.findOne(subColumns, column -> column.getId().equals(subTable.getSubJoinColumnId())) == null) {
throw exception(CODEGEN_SUB_COLUMN_NOT_EXISTS, subTable.getId());
throw new ServiceException(CODEGEN_SUB_COLUMN_NOT_EXISTS, subTable.getId());
}
subColumnsList.add(subColumns);
}
@@ -1,5 +1,6 @@
package com.cf.imes.module.infra.service.config;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.module.infra.controller.admin.config.vo.ConfigPageReqVO;
import com.cf.imes.module.infra.controller.admin.config.vo.ConfigSaveReqVO;
@@ -14,7 +15,7 @@ import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.module.infra.enums.ErrorCodeConstants.*;
/**
@@ -58,7 +59,7 @@ public class ConfigServiceImpl implements ConfigService {
ConfigDO config = validateConfigExists(id);
// 内置配置,不允许删除
if (ConfigTypeEnum.SYSTEM.getType().equals(config.getType())) {
throw exception(CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
throw new ServiceException(CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
}
// 删除
configMapper.deleteById(id);
@@ -86,7 +87,7 @@ public class ConfigServiceImpl implements ConfigService {
}
ConfigDO config = configMapper.selectById(id);
if (config == null) {
throw exception(CONFIG_NOT_EXISTS);
throw new ServiceException(CONFIG_NOT_EXISTS);
}
return config;
}
@@ -99,10 +100,10 @@ public class ConfigServiceImpl implements ConfigService {
}
// 如果 id 为空,说明不用比较是否为相同 id 的参数配置
if (id == null) {
throw exception(CONFIG_KEY_DUPLICATE);
throw new ServiceException(CONFIG_KEY_DUPLICATE);
}
if (!config.getId().equals(id)) {
throw exception(CONFIG_KEY_DUPLICATE);
throw new ServiceException(CONFIG_KEY_DUPLICATE);
}
}
@@ -1,6 +1,6 @@
package com.cf.imes.module.infra.service.db;
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.framework.mybatis.core.util.JdbcUtils;
import com.cf.imes.module.infra.controller.admin.db.vo.DataSourceConfigSaveReqVO;
@@ -16,7 +16,7 @@ import jakarta.annotation.Resource;
import java.util.List;
import java.util.Objects;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
/**
* 数据源配置 Service 实现类
@@ -65,7 +65,7 @@ public class DataSourceConfigServiceImpl implements DataSourceConfigService {
private void validateDataSourceConfigExists(Long id) {
if (dataSourceConfigMapper.selectById(id) == null) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.DATA_SOURCE_CONFIG_NOT_EXISTS);
throw new ServiceException(ErrorCodeConstants.DATA_SOURCE_CONFIG_NOT_EXISTS);
}
}
@@ -90,7 +90,7 @@ public class DataSourceConfigServiceImpl implements DataSourceConfigService {
private void validateConnectionOK(DataSourceConfigDO config) {
boolean success = JdbcUtils.isConnectionOK(config.getUrl(), config.getUsername(), config.getPassword());
if (!success) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.DATA_SOURCE_CONFIG_NOT_OK);
throw new ServiceException(ErrorCodeConstants.DATA_SOURCE_CONFIG_NOT_OK);
}
}
@@ -2,6 +2,7 @@ package com.cf.imes.module.infra.service.file;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.util.IdUtil;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.json.JsonUtils;
import com.cf.imes.framework.common.util.validation.ValidationUtils;
@@ -28,7 +29,7 @@ import java.time.Duration;
import java.util.Map;
import java.util.Objects;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.framework.common.util.cache.CacheUtils.buildAsyncReloadingCache;
import static com.cf.imes.module.infra.enums.ErrorCodeConstants.FILE_CONFIG_DELETE_FAIL_MASTER;
import static com.cf.imes.module.infra.enums.ErrorCodeConstants.FILE_CONFIG_NOT_EXISTS;
@@ -125,7 +126,7 @@ public class FileConfigServiceImpl implements FileConfigService {
// 校验存在
FileConfigDO config = validateFileConfigExists(id);
if (Boolean.TRUE.equals(config.getMaster())) {
throw exception(FILE_CONFIG_DELETE_FAIL_MASTER);
throw new ServiceException(FILE_CONFIG_DELETE_FAIL_MASTER);
}
// 删除
fileConfigMapper.deleteById(id);
@@ -152,7 +153,7 @@ public class FileConfigServiceImpl implements FileConfigService {
private FileConfigDO validateFileConfigExists(Long id) {
FileConfigDO config = fileConfigMapper.selectById(id);
if (config == null) {
throw exception(FILE_CONFIG_NOT_EXISTS);
throw new ServiceException(FILE_CONFIG_NOT_EXISTS);
}
return config;
}
@@ -2,6 +2,7 @@ package com.cf.imes.module.infra.service.file;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.text.CharSequenceUtil;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.Assert.AssertUtils;
import com.cf.imes.framework.common.util.io.FileUtils;
@@ -18,7 +19,7 @@ import jakarta.annotation.Resource;
import java.util.Objects;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.module.infra.enums.ErrorCodeConstants.FILE_NOT_EXISTS;
import static com.cf.imes.module.infra.enums.ErrorCodeConstants.FILE_REMOVE_FAIL;
@@ -120,7 +121,7 @@ public class FileServiceImpl implements FileService {
private FileDO validateFileExists(Long id) {
FileDO fileDO = fileMapper.selectById(id);
if (fileDO == null) {
throw exception(FILE_NOT_EXISTS);
throw new ServiceException(FILE_NOT_EXISTS);
}
return fileDO;
}
@@ -149,7 +150,7 @@ public class FileServiceImpl implements FileService {
// 校验存在
FileDO fileDO = fileMapper.selectOne(new LambdaQueryWrapperX<FileDO>().eq(FileDO::getPath, path));
if(Objects.isNull(fileDO)) {
throw exception(FILE_NOT_EXISTS);
throw new ServiceException(FILE_NOT_EXISTS);
}
// 从文件存储器中删除
FileClient client = fileConfigService.getFileClient(fileDO.getConfigId());
@@ -157,7 +158,7 @@ public class FileServiceImpl implements FileService {
try {
client.delete(path);
} catch (Exception e) {
throw exception(FILE_REMOVE_FAIL);
throw new ServiceException(FILE_REMOVE_FAIL);
}
// 删除记录
@@ -1,6 +1,7 @@
package com.cf.imes.module.infra.service.logger;
import cn.hutool.core.text.CharSequenceUtil;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.object.BeanUtils;
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
@@ -17,7 +18,6 @@ import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource;
import java.time.LocalDateTime;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.module.infra.dal.dataobject.logger.ApiErrorLogDO.REQUEST_PARAMS_MAX_LENGTH;
import static com.cf.imes.module.infra.enums.ErrorCodeConstants.API_ERROR_LOG_NOT_FOUND;
import static com.cf.imes.module.infra.enums.ErrorCodeConstants.API_ERROR_LOG_PROCESSED;
@@ -57,10 +57,10 @@ public class ApiErrorLogServiceImpl implements ApiErrorLogService {
public void updateApiErrorLogProcess(Long id, Integer processStatus, Long processUserId) {
ApiErrorLogDO errorLog = apiErrorLogMapper.selectById(id);
if (errorLog == null) {
throw exception(API_ERROR_LOG_NOT_FOUND);
throw new ServiceException(API_ERROR_LOG_NOT_FOUND);
}
if (!ApiErrorLogProcessStatusEnum.INIT.getStatus().equals(errorLog.getProcessStatus())) {
throw exception(API_ERROR_LOG_PROCESSED);
throw new ServiceException(API_ERROR_LOG_PROCESSED);
}
// 标记处理
apiErrorLogMapper.updateById(ApiErrorLogDO.builder().id(id).processStatus(processStatus)