🐛 字典值排序无效.

This commit is contained in:
lijiahang
2024-06-26 10:23:32 +08:00
parent f0a122d862
commit 41384fab17
7 changed files with 43 additions and 34 deletions

View File

@@ -31,7 +31,7 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
// 拼接启动日志
AnsiAppender appender = AnsiAppender.create()
.append(AnsiForeground.BRIGHT_GREEN, "> 准备执行命令 ")
.append(Dates.current())
.append(this.getCurrentTime())
.newLine()
.append(AnsiForeground.BRIGHT_BLUE, "执行记录: ")
.append(execCommand.getLogId())
@@ -81,7 +81,7 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
// 非脚本执行拼接开始执行日志
if (!Booleans.isTrue(execCommand.getScriptExec())) {
appender.append(AnsiForeground.BRIGHT_GREEN, "> 开始执行命令 ")
.append(Dates.current())
.append(this.getCurrentTime())
.newLine();
}
this.appendLog(appender);
@@ -94,7 +94,7 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
AnsiAppender startAppender = AnsiAppender.create()
.newLine()
.append(AnsiForeground.BRIGHT_GREEN, "> 准备上传脚本 ")
.append(Dates.current())
.append(this.getCurrentTime())
.newLine()
.append(AnsiForeground.BRIGHT_BLUE, "文件路径: ")
.append(execHostCommand.getScriptPath())
@@ -105,18 +105,18 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
// 拼接完成日志
AnsiAppender finishAppender = AnsiAppender.create()
.append(AnsiForeground.BRIGHT_GREEN, "< 脚本上传成功 ")
.append(Dates.current())
.append(this.getCurrentTime())
.newLine()
.newLine()
.append(AnsiForeground.BRIGHT_GREEN, "> 开始执行脚本 ")
.append(Dates.current())
.append(this.getCurrentTime())
.newLine();
this.appendLog(finishAppender);
} catch (Exception e) {
// 拼接失败日志
AnsiAppender errorAppender = AnsiAppender.create()
.append(AnsiForeground.BRIGHT_RED, "< 脚本上传失败 ")
.append(Dates.current())
.append(this.getCurrentTime())
.newLine();
this.appendLog(errorAppender);
throw e;
@@ -133,12 +133,12 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
if (this.status == ExecHostStatusEnum.INTERRUPTED) {
// 中断执行
appender.append(AnsiForeground.BRIGHT_YELLOW, "< 命令执行中断 ")
.append(Dates.current())
.append(this.getCurrentTime())
.newLine();
} else if (this.status == ExecHostStatusEnum.FAILED) {
// 执行失败
appender.append(AnsiForeground.BRIGHT_RED, "< 命令执行失败 ")
.append(Dates.current())
.append(this.getCurrentTime())
.newLine()
.append(AnsiForeground.BRIGHT_RED, "错误原因: ")
.append(this.getErrorMessage(e))
@@ -146,14 +146,14 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
} else if (this.status == ExecHostStatusEnum.TIMEOUT) {
// 更新执行超时
appender.append(AnsiForeground.BRIGHT_YELLOW, "< 命令执行超时 ")
.append(Dates.current())
.append(this.getCurrentTime())
.newLine();
} else {
long ms = updateRecord.getFinishTime().getTime() - updateRecord.getStartTime().getTime();
Integer exitCode = updateRecord.getExitCode();
// 执行完成
appender.append(AnsiForeground.BRIGHT_GREEN, "< 命令执行完成 ")
.append(Dates.current())
.append(this.getCurrentTime())
.newLine()
.append(AnsiForeground.BRIGHT_BLUE, "exit: ");
if (ExitCode.isSuccess(exitCode)) {
@@ -173,4 +173,13 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
this.appendLog(appender);
}
/**
* 获取当前时间
*
* @return 当前时间
*/
private String getCurrentTime() {
return Const.SPACE + Dates.current();
}
}

View File

@@ -8,6 +8,7 @@ import com.orion.net.host.SessionStore;
import com.orion.net.host.sftp.SftpExecutor;
import com.orion.spring.SpringHolder;
import com.orion.visor.framework.common.constant.Const;
import com.orion.visor.framework.common.enums.EndpointDefine;
import com.orion.visor.framework.common.file.FileClient;
import com.orion.visor.framework.common.utils.PathUtils;
import com.orion.visor.module.asset.dao.UploadTaskFileDAO;
@@ -18,7 +19,6 @@ import com.orion.visor.module.asset.enums.HostSshOsTypeEnum;
import com.orion.visor.module.asset.enums.UploadTaskFileStatusEnum;
import com.orion.visor.module.asset.handler.host.upload.model.FileUploadFileItemDTO;
import com.orion.visor.module.asset.service.HostTerminalService;
import com.orion.visor.module.asset.service.UploadTaskService;
import com.orion.visor.module.asset.utils.SftpUtils;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@@ -134,7 +134,7 @@ public class FileUploader implements IFileUploader {
this.updateStatus(file, UploadTaskFileStatusEnum.UPLOADING);
try {
// 获取本地文件路径
String endpoint = Strings.format(UploadTaskService.SWAP_ENDPOINT, taskId);
String endpoint = EndpointDefine.UPLOAD_SWAP.format(taskId);
String localPath = localFileClient.getReturnPath(endpoint + Const.SLASH + file.getFileId());
// 检查文件是否存在
String remotePath = file.getRemotePath();

View File

@@ -19,8 +19,6 @@ import java.util.List;
*/
public interface UploadTaskService {
String SWAP_ENDPOINT = "/upload/swap/{}";
/**
* 创建上传任务
*

View File

@@ -14,7 +14,8 @@ import com.orion.visor.framework.biz.operator.log.core.utils.OperatorLogs;
import com.orion.visor.framework.common.annotation.Keep;
import com.orion.visor.framework.common.constant.Const;
import com.orion.visor.framework.common.constant.ErrorMessage;
import com.orion.visor.framework.common.constant.PathConst;
import com.orion.visor.framework.common.constant.FileConst;
import com.orion.visor.framework.common.enums.EndpointDefine;
import com.orion.visor.framework.common.file.FileClient;
import com.orion.visor.framework.common.security.LoginUser;
import com.orion.visor.framework.common.utils.PathUtils;
@@ -140,10 +141,10 @@ public class ExecCommandServiceImpl implements ExecCommandService {
execLogDAO.insert(execLog);
Long execId = execLog.getId();
// 获取内置参数
Map<String, Object> builtinsParams = this.getBaseBuiltinsParams(execId, request);
Map<String, Object> builtinParams = this.getBaseBuiltinParams(execId, request);
// 设置主机日志
List<ExecHostLogDO> execHostLogs = hosts.stream()
.map(s -> this.convertExecHostLog(s, execLog, hostConfigMap.get(s.getId()), builtinsParams))
.map(s -> this.convertExecHostLog(s, execLog, hostConfigMap.get(s.getId()), builtinParams))
.collect(Collectors.toList());
execHostLogDAO.insertBatch(execHostLogs);
// 操作日志
@@ -228,16 +229,16 @@ public class ExecCommandServiceImpl implements ExecCommandService {
/**
* 转换为 execHostLog
*
* @param host host
* @param execLog execLog
* @param config config
* @param builtinsParams builtinsParams
* @param host host
* @param execLog execLog
* @param config config
* @param builtinParams builtinParams
* @return execHostLog
*/
private ExecHostLogDO convertExecHostLog(HostDO host,
ExecLogDO execLog,
HostSshConfigModel config,
Map<String, Object> builtinsParams) {
Map<String, Object> builtinParams) {
Long execId = execLog.getId();
Long hostId = host.getId();
// 脚本路径
@@ -246,7 +247,7 @@ public class ExecCommandServiceImpl implements ExecCommandService {
scriptPath = this.buildScriptPath(config.getUsername(), config.getOsType(), execId, hostId);
}
// 获取参数
String parameter = JSON.toJSONString(this.getHostParams(builtinsParams, host, config, scriptPath));
String parameter = JSON.toJSONString(this.getHostParams(builtinParams, host, config, scriptPath));
return ExecHostLogDO.builder()
.logId(execId)
.hostId(hostId)
@@ -267,7 +268,7 @@ public class ExecCommandServiceImpl implements ExecCommandService {
* @param request request
* @return params
*/
private Map<String, Object> getBaseBuiltinsParams(Long execId, ExecCommandExecDTO request) {
private Map<String, Object> getBaseBuiltinParams(Long execId, ExecCommandExecDTO request) {
String uuid = UUIds.random();
Date date = new Date();
// 输入参数
@@ -353,8 +354,7 @@ public class ExecCommandServiceImpl implements ExecCommandService {
* @return logPath
*/
private String buildLogPath(Long logId, Long hostId) {
String logFile = "/" + PathConst.EXEC + "/" + logId + "/" + logId + "_" + hostId + ".log";
return logsFileClient.getReturnPath(logFile);
return logsFileClient.getReturnPath(EndpointDefine.EXEC_LOG.format(logId, hostId));
}
/**
@@ -368,11 +368,11 @@ public class ExecCommandServiceImpl implements ExecCommandService {
*/
private String buildScriptPath(String username, String osType, Long logId, Long hostId) {
HostSshOsTypeEnum os = HostSshOsTypeEnum.of(osType);
String name = PathConst.EXEC
+ "_" + logId
+ "_" + hostId
String name = FileConst.EXEC
+ "/" + logId
+ "/" + hostId
+ os.getScriptSuffix();
return PathUtils.buildAppPath(HostSshOsTypeEnum.WINDOWS.equals(os), username, PathConst.SCRIPT, name);
return PathUtils.buildAppPath(HostSshOsTypeEnum.WINDOWS.equals(os), username, FileConst.SCRIPT, name);
}
}

View File

@@ -14,6 +14,7 @@ import com.orion.lang.utils.time.Dates;
import com.orion.visor.framework.biz.operator.log.core.utils.OperatorLogs;
import com.orion.visor.framework.common.annotation.Keep;
import com.orion.visor.framework.common.constant.Const;
import com.orion.visor.framework.common.enums.EndpointDefine;
import com.orion.visor.framework.common.constant.ErrorMessage;
import com.orion.visor.framework.common.file.FileClient;
import com.orion.visor.framework.common.security.LoginUser;
@@ -140,7 +141,7 @@ public class UploadTaskServiceImpl implements UploadTaskService {
}
uploadTaskFileDAO.insertBatch(uploadFiles);
// 设置 uploadToken
String token = fileUploadApi.createUploadToken(user.getId(), Strings.format(SWAP_ENDPOINT, id));
String token = fileUploadApi.createUploadToken(user.getId(), EndpointDefine.UPLOAD_SWAP.format(id));
log.info("UploadTaskService-createUploadTask id: {}, effect: {}", id, effect);
// 添加日志参数
OperatorLogs.add(OperatorLogs.NAME, record.getDescription());
@@ -296,7 +297,7 @@ public class UploadTaskServiceImpl implements UploadTaskService {
}
// 查询记录
List<String> paths = idList.stream()
.map(s -> Strings.format(SWAP_ENDPOINT, s))
.map(EndpointDefine.UPLOAD_SWAP::format)
.map(localFileClient::getReturnPath)
.map(localFileClient::getAbsolutePath)
.collect(Collectors.toList());
@@ -348,7 +349,7 @@ public class UploadTaskServiceImpl implements UploadTaskService {
.collect(Collectors.groupingBy(UploadTaskFileDO::getFileId));
fileIdGroups.forEach((k, v) -> {
// 获取文件实际路径
String path = localFileClient.getReturnPath(Strings.format(SWAP_ENDPOINT, id) + Const.SLASH + k);
String path = localFileClient.getReturnPath(EndpointDefine.UPLOAD_SWAP.format(id) + Const.SLASH + k);
File file = new File(localFileClient.getAbsolutePath(path));
// 文件不存在/大小不正确
if (!Files1.isFile(file) || file.length() != v.get(0).getFileSize()) {

View File

@@ -29,7 +29,7 @@ public class TerminalPreferenceStrategy extends AbstractGenericsDataStrategy<Ter
.builder()
.fontFamily("_")
.fontSize(14)
.lineHeight(1.12)
.lineHeight(1.20)
.letterSpacing(0)
.fontWeight("normal")
.fontWeightBold("bold")

View File

@@ -396,6 +396,7 @@ public class DictValueServiceImpl implements DictValueService {
Map<String, String> schema = dictKeyService.getDictSchema(key);
// 转换
return values.stream()
.sorted(Comparator.comparing(DictValueDO::getSort))
.map(s -> {
// 设置值
JSONObject item = new JSONObject();