From 9a23b0634bda30a1cfbb9fc2a99628d7a35ee259 Mon Sep 17 00:00:00 2001 From: lijiahangmax Date: Tue, 31 Oct 2023 01:32:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9B=9E=E6=BB=9A=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E5=80=BC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/validator/group/Id.java | 4 +- .../common/validator/group/Page.java | 4 +- .../src/main/resources/application.yaml | 4 +- .../operator/DictValueOperatorType.java | 4 +- .../history/HistoryValueQueryRequest.java | 3 +- .../service/impl/DictValueServiceImpl.java | 30 ++- .../service/impl/HistoryValueServiceImpl.java | 4 +- orion-ops-ui/src/api/system/dict-value.ts | 2 +- .../meta/history/history-value-modal.vue | 217 ++++++++++++++++++ .../src/views/system/dict-value/index.vue | 18 +- .../views/system/dict-value/types/const.ts | 2 + 11 files changed, 277 insertions(+), 15 deletions(-) create mode 100644 orion-ops-ui/src/components/meta/history/history-value-modal.vue diff --git a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/validator/group/Id.java b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/validator/group/Id.java index 15d3a54b..2cec166f 100644 --- a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/validator/group/Id.java +++ b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/validator/group/Id.java @@ -1,5 +1,7 @@ package com.orion.ops.framework.common.validator.group; +import javax.validation.groups.Default; + /** * 分页验证分组 * @@ -7,5 +9,5 @@ package com.orion.ops.framework.common.validator.group; * @version 1.0.0 * @since 2023/9/1 19:13 */ -public interface Id { +public interface Id extends Default { } diff --git a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/validator/group/Page.java b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/validator/group/Page.java index 819b14c9..f5af02aa 100644 --- a/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/validator/group/Page.java +++ b/orion-ops-framework/orion-ops-framework-common/src/main/java/com/orion/ops/framework/common/validator/group/Page.java @@ -1,5 +1,7 @@ package com.orion.ops.framework.common.validator.group; +import javax.validation.groups.Default; + /** * 分页验证分组 * @@ -7,5 +9,5 @@ package com.orion.ops.framework.common.validator.group; * @version 1.0.0 * @since 2023/9/1 19:13 */ -public interface Page { +public interface Page extends Default { } diff --git a/orion-ops-launch/src/main/resources/application.yaml b/orion-ops-launch/src/main/resources/application.yaml index 93d79fb7..95d8cd49 100644 --- a/orion-ops-launch/src/main/resources/application.yaml +++ b/orion-ops-launch/src/main/resources/application.yaml @@ -120,8 +120,8 @@ logging: max-file-size: 16MB total-size-cap: 0B pattern: - console: '%clr(%d{${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %boldBlue([%X{tid}]) %clr([%22.22t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}' - file: "%d{${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:-%5p} [%X{tid}] [%t] %-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}" + console: '%clr(%d{${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}}){faint} %clr(${LOG_LEVEL_PATTERN:-%6p}) %boldBlue([%X{tid}]) %clr([%22.22t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}' + file: "%d{${LOG_DATEFORMAT_PATTERN:yyyy-MM-dd HH:mm:ss.SSS}} ${LOG_LEVEL_PATTERN:-%6p} [%X{tid}] [%t] %-40.40logger{39} : %m%n${LOG_EXCEPTION_CONVERSION_WORD:%wEx}" level: com.orion.ops.launch.controller.BootstrapController: INFO diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/operator/DictValueOperatorType.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/operator/DictValueOperatorType.java index c09a894e..4f5109e1 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/operator/DictValueOperatorType.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/define/operator/DictValueOperatorType.java @@ -25,8 +25,8 @@ public class DictValueOperatorType extends InitializingOperatorTypes { @Override public OperatorType[] types() { return new OperatorType[]{ - new OperatorType(L, CREATE, "创建字典配置值 ${keyName} ${label}=${value}"), - new OperatorType(M, UPDATE, "更新字典配置值 ${keyName} ${label}=${value}"), + new OperatorType(L, CREATE, "创建字典配置值 ${keyName}: ${label} | ${value}"), + new OperatorType(M, UPDATE, "更新字典配置值 ${keyName}: ${label} | ${value}"), new OperatorType(H, DELETE, "删除字典配置值 ${value}"), }; } diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/history/HistoryValueQueryRequest.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/history/HistoryValueQueryRequest.java index 69451a65..19a36026 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/history/HistoryValueQueryRequest.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/entity/request/history/HistoryValueQueryRequest.java @@ -4,6 +4,7 @@ import com.orion.ops.framework.common.entity.PageRequest; import io.swagger.v3.oas.annotations.media.Schema; import lombok.*; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; @@ -27,7 +28,7 @@ public class HistoryValueQueryRequest extends PageRequest { private Long relId; @Size(max = 16) - @NotNull + @NotBlank @Schema(description = "类型") private String type; diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictValueServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictValueServiceImpl.java index bb0c67fc..40269b8b 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictValueServiceImpl.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/DictValueServiceImpl.java @@ -9,6 +9,7 @@ import com.orion.lang.utils.collect.Lists; import com.orion.ops.framework.biz.operator.log.core.uitls.OperatorLogs; import com.orion.ops.framework.common.constant.Const; import com.orion.ops.framework.common.constant.ErrorMessage; +import com.orion.ops.framework.common.constant.FieldConst; import com.orion.ops.framework.common.utils.Valid; import com.orion.ops.framework.mybatis.core.query.Conditions; import com.orion.ops.framework.redis.core.utils.RedisStrings; @@ -98,6 +99,7 @@ public class DictValueServiceImpl implements DictValueService { this.checkDictValuePresent(updateRecord); // 更新 OperatorLogs.add(OperatorLogs.KEY_NAME, dictKey); + OperatorLogs.add(OperatorLogs.VALUE, this.getDictValueJson(updateRecord)); updateRecord.setKeyName(key); int effect = dictValueDAO.updateById(updateRecord); log.info("DictValueService-updateDictValueById effect: {}", effect); @@ -118,6 +120,9 @@ public class DictValueServiceImpl implements DictValueService { // 查询历史值 HistoryValueDO history = historyValueService.getHistoryByRelId(request.getValueId(), id, HistoryValueTypeEnum.DICT.name()); Valid.notNull(history, ErrorMessage.HISTORY_ABSENT); + JSONObject historyValue = JSON.parseObject(history.getBeforeValue()); + String label = (String) historyValue.remove(OperatorLogs.LABEL); + String value = (String) historyValue.remove(OperatorLogs.VALUE); // 记录日志参数 OperatorLogs.add(OperatorLogs.KEY_NAME, record.getKeyName()); OperatorLogs.add(OperatorLogs.LABEL, record.getLabel()); @@ -125,7 +130,9 @@ public class DictValueServiceImpl implements DictValueService { // 更新 DictValueDO updateRecord = new DictValueDO(); updateRecord.setId(id); - updateRecord.setValue(history.getBeforeValue()); + updateRecord.setLabel(label); + updateRecord.setValue(value); + updateRecord.setExtra(historyValue.toString()); int effect = dictValueDAO.updateById(updateRecord); log.info("DictValueService-rollbackDictValueById effect: {}", effect); // 删除缓存 @@ -306,9 +313,11 @@ public class DictValueServiceImpl implements DictValueService { * @param record 修改前 */ private void checkRecordHistory(DictValueDO updateRecord, DictValueDO record) { + // 原始值 + String beforeValue = this.getDictValueJson(record); + // 新值 + String afterValue = this.getDictValueJson(updateRecord); // 检查值是否发生改变 - String beforeValue = record.getValue(); - String afterValue = updateRecord.getValue(); if (!beforeValue.equals(afterValue)) { // 记录历史值 HistoryValueCreateRequest historyRequest = new HistoryValueCreateRequest(); @@ -320,6 +329,21 @@ public class DictValueServiceImpl implements DictValueService { } } + /** + * 获取字典值 json + * + * @param record record + * @return value + */ + private String getDictValueJson(DictValueDO record) { + JSONObject beforeValue = Optional.ofNullable(record.getExtra()) + .map(JSON::parseObject) + .orElseGet(JSONObject::new); + beforeValue.put(FieldConst.VALUE, record.getValue()); + beforeValue.put(FieldConst.LABEL, record.getLabel()); + return beforeValue.toString(); + } + /** * 检查对象是否存在 * diff --git a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/HistoryValueServiceImpl.java b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/HistoryValueServiceImpl.java index a12b0aa2..35678bbe 100644 --- a/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/HistoryValueServiceImpl.java +++ b/orion-ops-module-infra/orion-ops-module-infra-service/src/main/java/com/orion/ops/module/infra/service/impl/HistoryValueServiceImpl.java @@ -97,8 +97,8 @@ public class HistoryValueServiceImpl implements HistoryValueService { .eq(HistoryValueDO::getRelId, request.getRelId()) .eq(HistoryValueDO::getType, request.getType()) .and(Strings.isNotEmpty(searchValue), c -> c - .eq(HistoryValueDO::getBeforeValue, searchValue).or() - .eq(HistoryValueDO::getAfterValue, searchValue) + .like(HistoryValueDO::getBeforeValue, searchValue).or() + .like(HistoryValueDO::getAfterValue, searchValue) ) .orderByDesc(HistoryValueDO::getId); } diff --git a/orion-ops-ui/src/api/system/dict-value.ts b/orion-ops-ui/src/api/system/dict-value.ts index 956b8420..3ec62e77 100644 --- a/orion-ops-ui/src/api/system/dict-value.ts +++ b/orion-ops-ui/src/api/system/dict-value.ts @@ -27,7 +27,7 @@ export interface DictValueUpdateRequest extends DictValueCreateRequest { */ export interface DictValueRollbackRequest { id?: number; - relId?: number; + valueId?: number; } /** diff --git a/orion-ops-ui/src/components/meta/history/history-value-modal.vue b/orion-ops-ui/src/components/meta/history/history-value-modal.vue new file mode 100644 index 00000000..06e62090 --- /dev/null +++ b/orion-ops-ui/src/components/meta/history/history-value-modal.vue @@ -0,0 +1,217 @@ + + + + + + + diff --git a/orion-ops-ui/src/views/system/dict-value/index.vue b/orion-ops-ui/src/views/system/dict-value/index.vue index a3c70e73..f697f221 100644 --- a/orion-ops-ui/src/views/system/dict-value/index.vue +++ b/orion-ops-ui/src/views/system/dict-value/index.vue @@ -3,11 +3,17 @@ + @openUpdate="(e) => modal.openUpdate(e)" + @openHistory="(e) => history.open(e.id, e.label)" /> + + @@ -20,15 +26,18 @@