feat: 回滚字典值.
This commit is contained in:
@@ -25,8 +25,8 @@ public class DictValueOperatorType extends InitializingOperatorTypes {
|
||||
@Override
|
||||
public OperatorType[] types() {
|
||||
return new OperatorType[]{
|
||||
new OperatorType(L, CREATE, "创建字典配置值 <sb>${keyName}</sb> <sb>${label}=${value}</sb>"),
|
||||
new OperatorType(M, UPDATE, "更新字典配置值 <sb>${keyName}</sb> <sb>${label}=${value}</sb>"),
|
||||
new OperatorType(L, CREATE, "创建字典配置值 <sb>${keyName}</sb>: <sb>${label}</sb> | <sb>${value}</sb>"),
|
||||
new OperatorType(M, UPDATE, "更新字典配置值 <sb>${keyName}</sb>: <sb>${label}</sb> | <sb>${value}</sb>"),
|
||||
new OperatorType(H, DELETE, "删除字典配置值 <sb>${value}</sb>"),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查对象是否存在
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user