✨ 获取应用信息.
This commit is contained in:
@@ -13,4 +13,8 @@ public interface CnConst {
|
|||||||
|
|
||||||
String CN_ROLE = "角色";
|
String CN_ROLE = "角色";
|
||||||
|
|
||||||
|
String CN_UNKNOWN = "未知";
|
||||||
|
|
||||||
|
String CN_INTRANET_IP = "内网IP";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,6 @@ public interface Const extends com.orion.lang.constant.Const, FieldConst, CnCons
|
|||||||
|
|
||||||
int MD5_LEN = 32;
|
int MD5_LEN = 32;
|
||||||
|
|
||||||
String UNKNOWN = "未知";
|
|
||||||
|
|
||||||
String INTRANET_IP = "内网IP";
|
|
||||||
|
|
||||||
Long ROOT_PARENT_ID = 0L;
|
Long ROOT_PARENT_ID = 0L;
|
||||||
|
|
||||||
Integer DEFAULT_SORT = 10;
|
Integer DEFAULT_SORT = 10;
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class IpUtils {
|
|||||||
*/
|
*/
|
||||||
public static String getLocation(String ip) {
|
public static String getLocation(String ip) {
|
||||||
if (ip == null) {
|
if (ip == null) {
|
||||||
return Const.UNKNOWN;
|
return Const.CN_UNKNOWN;
|
||||||
}
|
}
|
||||||
// 查询缓存
|
// 查询缓存
|
||||||
return CACHE.computeIfAbsent(ip, IpUtils::queryLocation);
|
return CACHE.computeIfAbsent(ip, IpUtils::queryLocation);
|
||||||
@@ -43,21 +43,21 @@ public class IpUtils {
|
|||||||
*/
|
*/
|
||||||
private static String queryLocation(String ip) {
|
private static String queryLocation(String ip) {
|
||||||
if (ip == null) {
|
if (ip == null) {
|
||||||
return Const.UNKNOWN;
|
return Const.CN_UNKNOWN;
|
||||||
}
|
}
|
||||||
Region region;
|
Region region;
|
||||||
try {
|
try {
|
||||||
region = LocationRegions.getRegion(ip, 3);
|
region = LocationRegions.getRegion(ip, 3);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return Const.UNKNOWN;
|
return Const.CN_UNKNOWN;
|
||||||
}
|
}
|
||||||
if (region != null) {
|
if (region != null) {
|
||||||
String net = region.getNet();
|
String net = region.getNet();
|
||||||
String province = region.getProvince();
|
String province = region.getProvince();
|
||||||
if (net.equals(Const.INTRANET_IP)) {
|
if (net.equals(Const.CN_INTRANET_IP)) {
|
||||||
return net;
|
return net;
|
||||||
}
|
}
|
||||||
if (province.equals(Const.UNKNOWN)) {
|
if (province.equals(Const.CN_UNKNOWN)) {
|
||||||
return province;
|
return province;
|
||||||
}
|
}
|
||||||
StringBuilder location = new StringBuilder()
|
StringBuilder location = new StringBuilder()
|
||||||
@@ -69,7 +69,7 @@ public class IpUtils {
|
|||||||
location.append(" (").append(net).append(')');
|
location.append(" (").append(net).append(')');
|
||||||
return location.toString();
|
return location.toString();
|
||||||
}
|
}
|
||||||
return Const.UNKNOWN;
|
return Const.CN_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.orion.visor.framework.common.utils;
|
||||||
|
|
||||||
|
import com.orion.lang.utils.Arrays1;
|
||||||
|
import com.orion.lang.utils.crypto.Caesars;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 混淆工具类
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2024/6/17 18:27
|
||||||
|
*/
|
||||||
|
public class Mixes {
|
||||||
|
|
||||||
|
|
||||||
|
private Mixes() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 混淆
|
||||||
|
* <p>
|
||||||
|
* 此方法不可修改
|
||||||
|
*
|
||||||
|
* @param str str
|
||||||
|
* @return str
|
||||||
|
*/
|
||||||
|
public static String obfuscate(String str) {
|
||||||
|
char[] chars = str.toCharArray();
|
||||||
|
Arrays1.reverse(chars);
|
||||||
|
for (int i = 0; i < chars.length; i += 2) {
|
||||||
|
char temp = chars[i];
|
||||||
|
chars[i] = chars[i + 1];
|
||||||
|
chars[i + 1] = temp;
|
||||||
|
}
|
||||||
|
String res = new String(chars);
|
||||||
|
return new Caesars().encrypt(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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