From 659023bb358512bc7c75178d6af7f8edb65ec1e1 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 16 Mar 2022 00:21:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20FileConfig=20=E7=9A=84?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/core/mapper/BaseMapperX.java | 3 + .../infra/enums/ErrorCodeConstants.java | 1 + .../file/vo/config/FileConfigRespVO.java | 8 +- .../service/codegen/CodegenServiceImpl.java | 16 +- .../service/file/FileConfigServiceImpl.java | 21 +- .../dal/mysql/permission/RoleMenuMapper.java | 3 +- yudao-ui-admin/src/api/infra/fileConfig.js | 59 ++++ .../src/components/DictTag/index.vue | 2 +- yudao-ui-admin/src/utils/dict.js | 2 + .../src/views/infra/fileConfig/index.vue | 313 ++++++++++++++++++ 10 files changed, 411 insertions(+), 17 deletions(-) create mode 100755 yudao-ui-admin/src/api/infra/fileConfig.js create mode 100755 yudao-ui-admin/src/views/infra/fileConfig/index.vue diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java index e31600cb1..4ca5becb3 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java @@ -80,4 +80,7 @@ public interface BaseMapperX extends BaseMapper { entities.forEach(this::insert); } + default void updateBatch(T update) { + update(update, new QueryWrapper<>()); + } } diff --git a/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java index 3b5423792..1528955f9 100644 --- a/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java +++ b/yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants.java @@ -47,5 +47,6 @@ public interface ErrorCodeConstants { // ========== 文件配置 1001006000 ========== ErrorCode FILE_CONFIG_NOT_EXISTS = new ErrorCode(1001006000, "文件配置不存在"); + ErrorCode FILE_CONFIG_DELETE_FAIL_MASTER = new ErrorCode(1001006001, "该文件配置不允许删除,原因:它是主配置,删除会导致无法上传文件"); } diff --git a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigRespVO.java b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigRespVO.java index 5988b48c9..74291925b 100755 --- a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigRespVO.java +++ b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/vo/config/FileConfigRespVO.java @@ -19,13 +19,17 @@ public class FileConfigRespVO extends FileConfigBaseVO { @ApiModelProperty(value = "编号", required = true, example = "1") private Long id; - @ApiModelProperty(value = "存储配置", required = true) - private FileClientConfig config; + @ApiModelProperty(value = "存储器", required = true, example = "1", notes = "参见 FileStorageEnum 枚举类") + @NotNull(message = "存储器不能为空") + private Integer storage; @ApiModelProperty(value = "是否为主配置", required = true, example = "true") @NotNull(message = "是否为主配置不能为空") private Boolean master; + @ApiModelProperty(value = "存储配置", required = true) + private FileClientConfig config; + @ApiModelProperty(value = "创建时间", required = true) private Date createTime; diff --git a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java index 1c2b59ba8..31db3d572 100644 --- a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java @@ -15,7 +15,6 @@ import cn.iocoder.yudao.module.infra.dal.mysql.codegen.CodegenTableMapper; import cn.iocoder.yudao.module.infra.dal.mysql.codegen.SchemaColumnMapper; import cn.iocoder.yudao.module.infra.dal.mysql.codegen.SchemaTableMapper; import cn.iocoder.yudao.module.infra.enums.codegen.CodegenImportTypeEnum; -import cn.iocoder.yudao.module.infra.enums.codegen.CodegenSceneEnum; import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenBuilder; import cn.iocoder.yudao.module.infra.service.codegen.inner.CodegenEngine; @@ -26,7 +25,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -81,10 +83,7 @@ public class CodegenServiceImpl implements CodegenService { codegenTableMapper.insert(table); // 构建 CodegenColumnDO 数组,插入到 DB 中 List columns = codegenBuilder.buildColumns(schemaColumns); - columns.forEach(column -> { - column.setTableId(table.getId()); - codegenColumnMapper.insert(column); // TODO 批量插入 - }); + codegenColumnMapper.insertBatch(columns); return table.getId(); } @@ -198,10 +197,7 @@ public class CodegenServiceImpl implements CodegenService { // 插入新增的字段 List columns = codegenBuilder.buildColumns(schemaColumns); - columns.forEach(column -> { - column.setTableId(tableId); - codegenColumnMapper.insert(column); // TODO 批量插入 - }); + codegenColumnMapper.insertBatch(columns); // 删除不存在的字段 if (CollUtil.isNotEmpty(deleteColumnIds)) { codegenColumnMapper.deleteBatchIds(deleteColumnIds); diff --git a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java index deb4c1e0e..d74f1db0a 100755 --- a/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-impl/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java @@ -22,6 +22,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.support.TransactionSynchronization; +import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.validation.annotation.Validated; import javax.annotation.PostConstruct; @@ -33,6 +36,7 @@ import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_CONFIG_DELETE_FAIL_MASTER; import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.FILE_CONFIG_NOT_EXISTS; /** @@ -151,13 +155,23 @@ public class FileConfigServiceImpl implements FileConfigService { } @Override + @Transactional(rollbackFor = Exception.class) public void updateFileConfigMaster(Long id) { // 校验存在 this.validateFileConfigExists(id); + // 更新其它为非 master + fileConfigMapper.updateBatch(new FileConfigDO().setMaster(false)); // 更新 fileConfigMapper.updateById(new FileConfigDO().setId(id).setMaster(true)); // 发送刷新配置的消息 - fileConfigProducer.sendFileConfigRefreshMessage(); + TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { + + @Override + public void afterCommit() { + fileConfigProducer.sendFileConfigRefreshMessage(); + } + + }); } private FileClientConfig parseClientConfig(Integer storage, Map config) { @@ -174,7 +188,10 @@ public class FileConfigServiceImpl implements FileConfigService { @Override public void deleteFileConfig(Long id) { // 校验存在 - this.validateFileConfigExists(id); + FileConfigDO config = this.validateFileConfigExists(id); + if (Boolean.TRUE.equals(config.getMaster())) { + throw exception(FILE_CONFIG_DELETE_FAIL_MASTER); + } // 删除 fileConfigMapper.deleteById(id); // 发送刷新配置的消息 diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMenuMapper.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMenuMapper.java index 02008bce8..f519b4ee9 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMenuMapper.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/RoleMenuMapper.java @@ -25,8 +25,7 @@ public interface RoleMenuMapper extends BaseMapperX { entity.setMenuId(menuId); return entity; }).collect(Collectors.toList()); - // TODO 芋艿,mybatis plus 增加批量插入的功能 - list.forEach(this::insert); + insertBatch(list); } default void deleteListByRoleIdAndMenuIds(Long roleId, Collection menuIds) { diff --git a/yudao-ui-admin/src/api/infra/fileConfig.js b/yudao-ui-admin/src/api/infra/fileConfig.js new file mode 100755 index 000000000..4b75773bf --- /dev/null +++ b/yudao-ui-admin/src/api/infra/fileConfig.js @@ -0,0 +1,59 @@ +import request from '@/utils/request' + +// 创建文件配置 +export function createFileConfig(data) { + return request({ + url: '/infra/file-config/create', + method: 'post', + data: data + }) +} + +// 更新文件配置 +export function updateFileConfig(data) { + return request({ + url: '/infra/file-config/update', + method: 'put', + data: data + }) +} + +// 更新文件配置为主配置 +export function updateFileConfigMaster(id) { + return request({ + url: '/infra/file-config/update-master?id=' + id, + method: 'put' + }) +} + +// 删除文件配置 +export function deleteFileConfig(id) { + return request({ + url: '/infra/file-config/delete?id=' + id, + method: 'delete' + }) +} + +// 获得文件配置 +export function getFileConfig(id) { + return request({ + url: '/infra/file-config/get?id=' + id, + method: 'get' + }) +} + +// 获得文件配置分页 +export function getFileConfigPage(query) { + return request({ + url: '/infra/file-config/page', + method: 'get', + params: query + }) +} + +export function testFileConfig(id) { + return request({ + url: '/infra/file-config/test?id=' + id, + method: 'get' + }) +} diff --git a/yudao-ui-admin/src/components/DictTag/index.vue b/yudao-ui-admin/src/components/DictTag/index.vue index 8f863046d..f7efc5eaf 100644 --- a/yudao-ui-admin/src/components/DictTag/index.vue +++ b/yudao-ui-admin/src/components/DictTag/index.vue @@ -17,7 +17,7 @@ export default { name: "DictTag", props: { type: String, - value: [Number, String, Array], + value: [Number, String, Boolean, Array], }, }; diff --git a/yudao-ui-admin/src/utils/dict.js b/yudao-ui-admin/src/utils/dict.js index 46f0c60d3..2e7d0a090 100644 --- a/yudao-ui-admin/src/utils/dict.js +++ b/yudao-ui-admin/src/utils/dict.js @@ -25,6 +25,7 @@ export const DICT_TYPE = { SYSTEM_ERROR_CODE_TYPE: 'system_error_code_type', // ========== INFRA 模块 ========== + INFRA_BOOLEAN_STRING: 'infra_boolean_string', INFRA_REDIS_TIMEOUT_TYPE: 'infra_redis_timeout_type', INFRA_JOB_STATUS: 'infra_job_status', INFRA_JOB_LOG_STATUS: 'infra_job_log_status', @@ -32,6 +33,7 @@ export const DICT_TYPE = { INFRA_CONFIG_TYPE: 'infra_config_type', INFRA_CODEGEN_TEMPLATE_TYPE: 'infra_codegen_template_type', INFRA_CODEGEN_SCENE: 'infra_codegen_scene', + INFRA_FILE_STORAGE: 'infra_file_storage', // ========== BPM 模块 ========== BPM_MODEL_CATEGORY: 'bpm_model_category', diff --git a/yudao-ui-admin/src/views/infra/fileConfig/index.vue b/yudao-ui-admin/src/views/infra/fileConfig/index.vue new file mode 100755 index 000000000..1643dd638 --- /dev/null +++ b/yudao-ui-admin/src/views/infra/fileConfig/index.vue @@ -0,0 +1,313 @@ + + +