✨ 获取应用信息.
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
### 查询应用信息
|
||||
GET {{baseUrl}}/infra/system/app-info
|
||||
Authorization: {{token}}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.orion.visor.module.infra.controller;
|
||||
|
||||
import com.orion.visor.framework.log.core.annotation.IgnoreLog;
|
||||
import com.orion.visor.framework.log.core.enums.IgnoreLogMode;
|
||||
import com.orion.visor.framework.web.core.annotation.RestWrapper;
|
||||
import com.orion.visor.module.infra.entity.vo.AppInfoVO;
|
||||
import com.orion.visor.module.infra.service.SystemService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 系统服务
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-7-17 11:39
|
||||
*/
|
||||
@Tag(name = "infra - 系统服务")
|
||||
@Slf4j
|
||||
@Validated
|
||||
@RestWrapper
|
||||
@RestController
|
||||
@RequestMapping("/infra/system")
|
||||
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
|
||||
public class SystemController {
|
||||
|
||||
@Resource
|
||||
private SystemService systemService;
|
||||
|
||||
@IgnoreLog(IgnoreLogMode.RET)
|
||||
@GetMapping("/app-info")
|
||||
@Operation(summary = "查询应用信息")
|
||||
public AppInfoVO getAppInfo() {
|
||||
return systemService.getAppInfo();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.orion.visor.module.infra.entity.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 应用信息 视图响应对象
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023-7-18 10:18
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(name = "AppInfoVO", description = "应用信息 视图响应对象")
|
||||
public class AppInfoVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "系统版本")
|
||||
private String version;
|
||||
|
||||
@Schema(description = "机器码")
|
||||
private String uuid;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.orion.visor.module.infra.service;
|
||||
|
||||
import com.orion.visor.module.infra.entity.vo.AppInfoVO;
|
||||
|
||||
/**
|
||||
* 系统服务
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/6/17 18:10
|
||||
*/
|
||||
public interface SystemService {
|
||||
|
||||
/**
|
||||
* 获取应用信息
|
||||
*
|
||||
* @return info
|
||||
*/
|
||||
AppInfoVO getAppInfo();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.orion.visor.module.infra.service.impl;
|
||||
|
||||
import com.orion.ext.process.Processes;
|
||||
import com.orion.lang.utils.Arrays1;
|
||||
import com.orion.lang.utils.Strings;
|
||||
import com.orion.visor.framework.common.constant.AppConst;
|
||||
import com.orion.visor.framework.common.constant.Const;
|
||||
import com.orion.visor.framework.common.utils.Mixes;
|
||||
import com.orion.visor.module.infra.entity.vo.AppInfoVO;
|
||||
import com.orion.visor.module.infra.service.SystemService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 系统服务 实现类
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/6/17 18:10
|
||||
*/
|
||||
@Service
|
||||
public class SystemServiceImpl implements SystemService {
|
||||
|
||||
private String uuid;
|
||||
|
||||
@Override
|
||||
public AppInfoVO getAppInfo() {
|
||||
return AppInfoVO.builder()
|
||||
.version(AppConst.VERSION)
|
||||
.uuid(this.getSystemUuid())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统 uuid
|
||||
*
|
||||
* @return uuid
|
||||
*/
|
||||
private String getSystemUuid() {
|
||||
if (this.uuid != null) {
|
||||
return this.uuid;
|
||||
}
|
||||
String[] cmd = new String[]{"cat /sys/class/dmi/id/product_serial", "dmidecode -s system-uuid", "wmic csproduct get uuid"};
|
||||
for (String s : cmd) {
|
||||
try {
|
||||
// 执行命令获取 uuid
|
||||
String uuid = Processes.getOutputResultString(s);
|
||||
if (Strings.isBlank(uuid)) {
|
||||
continue;
|
||||
}
|
||||
// 去除符号并且转为大写
|
||||
uuid = uuid.replaceAll(Const.DASHED, Const.EMPTY).toUpperCase();
|
||||
// 去除特殊字符
|
||||
String extraUuid = Arrays1.last(uuid.trim().split(Const.LF));
|
||||
if (!Strings.isBlank(extraUuid)) {
|
||||
uuid = extraUuid;
|
||||
}
|
||||
// 转义
|
||||
return this.uuid = Mixes.obfuscate(uuid);
|
||||
} catch (Exception e) {
|
||||
// IGNORED
|
||||
}
|
||||
}
|
||||
return this.uuid = Const.UNKNOWN;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user