🐛 字典值排序无效.

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() AnsiAppender appender = AnsiAppender.create()
.append(AnsiForeground.BRIGHT_GREEN, "> 准备执行命令 ") .append(AnsiForeground.BRIGHT_GREEN, "> 准备执行命令 ")
.append(Dates.current()) .append(this.getCurrentTime())
.newLine() .newLine()
.append(AnsiForeground.BRIGHT_BLUE, "执行记录: ") .append(AnsiForeground.BRIGHT_BLUE, "执行记录: ")
.append(execCommand.getLogId()) .append(execCommand.getLogId())
@@ -81,7 +81,7 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
// 非脚本执行拼接开始执行日志 // 非脚本执行拼接开始执行日志
if (!Booleans.isTrue(execCommand.getScriptExec())) { if (!Booleans.isTrue(execCommand.getScriptExec())) {
appender.append(AnsiForeground.BRIGHT_GREEN, "> 开始执行命令 ") appender.append(AnsiForeground.BRIGHT_GREEN, "> 开始执行命令 ")
.append(Dates.current()) .append(this.getCurrentTime())
.newLine(); .newLine();
} }
this.appendLog(appender); this.appendLog(appender);
@@ -94,7 +94,7 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
AnsiAppender startAppender = AnsiAppender.create() AnsiAppender startAppender = AnsiAppender.create()
.newLine() .newLine()
.append(AnsiForeground.BRIGHT_GREEN, "> 准备上传脚本 ") .append(AnsiForeground.BRIGHT_GREEN, "> 准备上传脚本 ")
.append(Dates.current()) .append(this.getCurrentTime())
.newLine() .newLine()
.append(AnsiForeground.BRIGHT_BLUE, "文件路径: ") .append(AnsiForeground.BRIGHT_BLUE, "文件路径: ")
.append(execHostCommand.getScriptPath()) .append(execHostCommand.getScriptPath())
@@ -105,18 +105,18 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
// 拼接完成日志 // 拼接完成日志
AnsiAppender finishAppender = AnsiAppender.create() AnsiAppender finishAppender = AnsiAppender.create()
.append(AnsiForeground.BRIGHT_GREEN, "< 脚本上传成功 ") .append(AnsiForeground.BRIGHT_GREEN, "< 脚本上传成功 ")
.append(Dates.current()) .append(this.getCurrentTime())
.newLine() .newLine()
.newLine() .newLine()
.append(AnsiForeground.BRIGHT_GREEN, "> 开始执行脚本 ") .append(AnsiForeground.BRIGHT_GREEN, "> 开始执行脚本 ")
.append(Dates.current()) .append(this.getCurrentTime())
.newLine(); .newLine();
this.appendLog(finishAppender); this.appendLog(finishAppender);
} catch (Exception e) { } catch (Exception e) {
// 拼接失败日志 // 拼接失败日志
AnsiAppender errorAppender = AnsiAppender.create() AnsiAppender errorAppender = AnsiAppender.create()
.append(AnsiForeground.BRIGHT_RED, "< 脚本上传失败 ") .append(AnsiForeground.BRIGHT_RED, "< 脚本上传失败 ")
.append(Dates.current()) .append(this.getCurrentTime())
.newLine(); .newLine();
this.appendLog(errorAppender); this.appendLog(errorAppender);
throw e; throw e;
@@ -133,12 +133,12 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
if (this.status == ExecHostStatusEnum.INTERRUPTED) { if (this.status == ExecHostStatusEnum.INTERRUPTED) {
// 中断执行 // 中断执行
appender.append(AnsiForeground.BRIGHT_YELLOW, "< 命令执行中断 ") appender.append(AnsiForeground.BRIGHT_YELLOW, "< 命令执行中断 ")
.append(Dates.current()) .append(this.getCurrentTime())
.newLine(); .newLine();
} else if (this.status == ExecHostStatusEnum.FAILED) { } else if (this.status == ExecHostStatusEnum.FAILED) {
// 执行失败 // 执行失败
appender.append(AnsiForeground.BRIGHT_RED, "< 命令执行失败 ") appender.append(AnsiForeground.BRIGHT_RED, "< 命令执行失败 ")
.append(Dates.current()) .append(this.getCurrentTime())
.newLine() .newLine()
.append(AnsiForeground.BRIGHT_RED, "错误原因: ") .append(AnsiForeground.BRIGHT_RED, "错误原因: ")
.append(this.getErrorMessage(e)) .append(this.getErrorMessage(e))
@@ -146,14 +146,14 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
} else if (this.status == ExecHostStatusEnum.TIMEOUT) { } else if (this.status == ExecHostStatusEnum.TIMEOUT) {
// 更新执行超时 // 更新执行超时
appender.append(AnsiForeground.BRIGHT_YELLOW, "< 命令执行超时 ") appender.append(AnsiForeground.BRIGHT_YELLOW, "< 命令执行超时 ")
.append(Dates.current()) .append(this.getCurrentTime())
.newLine(); .newLine();
} else { } else {
long ms = updateRecord.getFinishTime().getTime() - updateRecord.getStartTime().getTime(); long ms = updateRecord.getFinishTime().getTime() - updateRecord.getStartTime().getTime();
Integer exitCode = updateRecord.getExitCode(); Integer exitCode = updateRecord.getExitCode();
// 执行完成 // 执行完成
appender.append(AnsiForeground.BRIGHT_GREEN, "< 命令执行完成 ") appender.append(AnsiForeground.BRIGHT_GREEN, "< 命令执行完成 ")
.append(Dates.current()) .append(this.getCurrentTime())
.newLine() .newLine()
.append(AnsiForeground.BRIGHT_BLUE, "exit: "); .append(AnsiForeground.BRIGHT_BLUE, "exit: ");
if (ExitCode.isSuccess(exitCode)) { if (ExitCode.isSuccess(exitCode)) {
@@ -173,4 +173,13 @@ public class ExecCommandAnsiHandler extends BaseExecCommandHandler {
this.appendLog(appender); 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.net.host.sftp.SftpExecutor;
import com.orion.spring.SpringHolder; import com.orion.spring.SpringHolder;
import com.orion.visor.framework.common.constant.Const; 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.file.FileClient;
import com.orion.visor.framework.common.utils.PathUtils; import com.orion.visor.framework.common.utils.PathUtils;
import com.orion.visor.module.asset.dao.UploadTaskFileDAO; 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.enums.UploadTaskFileStatusEnum;
import com.orion.visor.module.asset.handler.host.upload.model.FileUploadFileItemDTO; 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.HostTerminalService;
import com.orion.visor.module.asset.service.UploadTaskService;
import com.orion.visor.module.asset.utils.SftpUtils; import com.orion.visor.module.asset.utils.SftpUtils;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -134,7 +134,7 @@ public class FileUploader implements IFileUploader {
this.updateStatus(file, UploadTaskFileStatusEnum.UPLOADING); this.updateStatus(file, UploadTaskFileStatusEnum.UPLOADING);
try { 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 localPath = localFileClient.getReturnPath(endpoint + Const.SLASH + file.getFileId());
// 检查文件是否存在 // 检查文件是否存在
String remotePath = file.getRemotePath(); String remotePath = file.getRemotePath();

View File

@@ -19,8 +19,6 @@ import java.util.List;
*/ */
public interface UploadTaskService { 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.annotation.Keep;
import com.orion.visor.framework.common.constant.Const; import com.orion.visor.framework.common.constant.Const;
import com.orion.visor.framework.common.constant.ErrorMessage; 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.file.FileClient;
import com.orion.visor.framework.common.security.LoginUser; import com.orion.visor.framework.common.security.LoginUser;
import com.orion.visor.framework.common.utils.PathUtils; import com.orion.visor.framework.common.utils.PathUtils;
@@ -140,10 +141,10 @@ public class ExecCommandServiceImpl implements ExecCommandService {
execLogDAO.insert(execLog); execLogDAO.insert(execLog);
Long execId = execLog.getId(); 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() 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()); .collect(Collectors.toList());
execHostLogDAO.insertBatch(execHostLogs); execHostLogDAO.insertBatch(execHostLogs);
// 操作日志 // 操作日志
@@ -231,13 +232,13 @@ public class ExecCommandServiceImpl implements ExecCommandService {
* @param host host * @param host host
* @param execLog execLog * @param execLog execLog
* @param config config * @param config config
* @param builtinsParams builtinsParams * @param builtinParams builtinParams
* @return execHostLog * @return execHostLog
*/ */
private ExecHostLogDO convertExecHostLog(HostDO host, private ExecHostLogDO convertExecHostLog(HostDO host,
ExecLogDO execLog, ExecLogDO execLog,
HostSshConfigModel config, HostSshConfigModel config,
Map<String, Object> builtinsParams) { Map<String, Object> builtinParams) {
Long execId = execLog.getId(); Long execId = execLog.getId();
Long hostId = host.getId(); Long hostId = host.getId();
// 脚本路径 // 脚本路径
@@ -246,7 +247,7 @@ public class ExecCommandServiceImpl implements ExecCommandService {
scriptPath = this.buildScriptPath(config.getUsername(), config.getOsType(), execId, hostId); 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() return ExecHostLogDO.builder()
.logId(execId) .logId(execId)
.hostId(hostId) .hostId(hostId)
@@ -267,7 +268,7 @@ public class ExecCommandServiceImpl implements ExecCommandService {
* @param request request * @param request request
* @return params * @return params
*/ */
private Map<String, Object> getBaseBuiltinsParams(Long execId, ExecCommandExecDTO request) { private Map<String, Object> getBaseBuiltinParams(Long execId, ExecCommandExecDTO request) {
String uuid = UUIds.random(); String uuid = UUIds.random();
Date date = new Date(); Date date = new Date();
// 输入参数 // 输入参数
@@ -353,8 +354,7 @@ public class ExecCommandServiceImpl implements ExecCommandService {
* @return logPath * @return logPath
*/ */
private String buildLogPath(Long logId, Long hostId) { private String buildLogPath(Long logId, Long hostId) {
String logFile = "/" + PathConst.EXEC + "/" + logId + "/" + logId + "_" + hostId + ".log"; return logsFileClient.getReturnPath(EndpointDefine.EXEC_LOG.format(logId, hostId));
return logsFileClient.getReturnPath(logFile);
} }
/** /**
@@ -368,11 +368,11 @@ public class ExecCommandServiceImpl implements ExecCommandService {
*/ */
private String buildScriptPath(String username, String osType, Long logId, Long hostId) { private String buildScriptPath(String username, String osType, Long logId, Long hostId) {
HostSshOsTypeEnum os = HostSshOsTypeEnum.of(osType); HostSshOsTypeEnum os = HostSshOsTypeEnum.of(osType);
String name = PathConst.EXEC String name = FileConst.EXEC
+ "_" + logId + "/" + logId
+ "_" + hostId + "/" + hostId
+ os.getScriptSuffix(); + 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.biz.operator.log.core.utils.OperatorLogs;
import com.orion.visor.framework.common.annotation.Keep; import com.orion.visor.framework.common.annotation.Keep;
import com.orion.visor.framework.common.constant.Const; 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.constant.ErrorMessage;
import com.orion.visor.framework.common.file.FileClient; import com.orion.visor.framework.common.file.FileClient;
import com.orion.visor.framework.common.security.LoginUser; import com.orion.visor.framework.common.security.LoginUser;
@@ -140,7 +141,7 @@ public class UploadTaskServiceImpl implements UploadTaskService {
} }
uploadTaskFileDAO.insertBatch(uploadFiles); uploadTaskFileDAO.insertBatch(uploadFiles);
// 设置 uploadToken // 设置 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); log.info("UploadTaskService-createUploadTask id: {}, effect: {}", id, effect);
// 添加日志参数 // 添加日志参数
OperatorLogs.add(OperatorLogs.NAME, record.getDescription()); OperatorLogs.add(OperatorLogs.NAME, record.getDescription());
@@ -296,7 +297,7 @@ public class UploadTaskServiceImpl implements UploadTaskService {
} }
// 查询记录 // 查询记录
List<String> paths = idList.stream() List<String> paths = idList.stream()
.map(s -> Strings.format(SWAP_ENDPOINT, s)) .map(EndpointDefine.UPLOAD_SWAP::format)
.map(localFileClient::getReturnPath) .map(localFileClient::getReturnPath)
.map(localFileClient::getAbsolutePath) .map(localFileClient::getAbsolutePath)
.collect(Collectors.toList()); .collect(Collectors.toList());
@@ -348,7 +349,7 @@ public class UploadTaskServiceImpl implements UploadTaskService {
.collect(Collectors.groupingBy(UploadTaskFileDO::getFileId)); .collect(Collectors.groupingBy(UploadTaskFileDO::getFileId));
fileIdGroups.forEach((k, v) -> { 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)); File file = new File(localFileClient.getAbsolutePath(path));
// 文件不存在/大小不正确 // 文件不存在/大小不正确
if (!Files1.isFile(file) || file.length() != v.get(0).getFileSize()) { if (!Files1.isFile(file) || file.length() != v.get(0).getFileSize()) {

View File

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

View File

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