feat(device): 更新设备管理功能并优化错误处理- 修改设备更新接口路径从 /updateExpire 到 /update- 添加设备注册时获取计算机名称功能

- 优化设备配额检查逻辑,增加账号存在性验证- 更新前端设备列表刷新逻辑,使用保存的用户名参数
- 修改账号编辑表单,禁用已存在账号的用户名和账号名编辑
-优化跟卖精灵打开功能的错误提示和异常处理- 添加页面刷新 IPC通信功能
- 限制用户名输入只能包含字母、数字和下划线
- 移除冗余的本地 IP 获取函数- 升级 erp_client_sb 模块版本至 2.4.9
This commit is contained in:
2025-10-22 14:18:28 +08:00
parent 17b6a7b9f9
commit 5468dc53fc
15 changed files with 115 additions and 96 deletions

View File

@@ -10,7 +10,7 @@
</parent>
<groupId>com.tashow.erp</groupId>
<artifactId>erp_client_sb</artifactId>
<version>2.4.8</version>
<version>2.4.9</version>
<name>erp_client_sb</name>
<description>erp客户端</description>
<properties>

View File

@@ -65,12 +65,13 @@ public class SystemController {
}
@GetMapping("/local-ip")
public JsonData getLocalIp() {
try {
return JsonData.buildSuccess(java.net.InetAddress.getLocalHost().getHostAddress());
} catch (Exception e) {
return JsonData.buildSuccess("127.0.0.1");
}
public JsonData getLocalIp() throws Exception {
return JsonData.buildSuccess(java.net.InetAddress.getLocalHost().getHostAddress());
}
@GetMapping("/computer-name")
public JsonData getComputerName() {
return JsonData.buildSuccess(System.getenv("COMPUTERNAME"));
}
@GetMapping("/version")
@@ -84,8 +85,14 @@ public class SystemController {
}
@PostMapping("/genmai/open")
public void openGenmaiWebsite() {
genmaiService.openGenmaiWebsite();
public JsonData openGenmaiWebsite() {
try {
genmaiService.openGenmaiWebsite();
return JsonData.buildSuccess("跟卖精灵已打开");
} catch (Exception e) {
logger.error("打开跟卖精灵失败", e);
return JsonData.buildError(e.getMessage() != null ? e.getMessage() : "打开跟卖精灵失败");
}
}
@GetMapping("/proxy/image")

View File

@@ -3,7 +3,6 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qiniu.util.UrlUtils;
import io.github.bonigarcia.wdm.WebDriverManager;
import lombok.SneakyThrows;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
@@ -25,26 +24,32 @@ public class GenmaiServiceImpl {
private String updateGenmaijlToken;
private final RestTemplate restTemplate = new RestTemplate();
ObjectMapper objectMapper = new ObjectMapper();
@SneakyThrows
public void openGenmaiWebsite() {
// 先关闭所有Chrome进程
Runtime.getRuntime().exec("taskkill /f /im chrome.exe");
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
String username = System.getProperty("user.name", "user");
String safeUsername;
char firstChar = username.charAt(0);
char flippedFirstChar = Character.isUpperCase(firstChar) ? Character.toLowerCase(firstChar) : Character.toUpperCase(firstChar);
safeUsername = flippedFirstChar + username.substring(1);
String chromeUserData = System.getProperty("user.home").replace(username, UrlUtils.urlEncode(safeUsername) )
+ "\\AppData\\Local\\Google\\Chrome\\User Data";
options.addArguments("user-data-dir=" + chromeUserData.toLowerCase());
options.addArguments("profile-directory=Default");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.genmaijl.com/#/profile");
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(String.format("localStorage.setItem('token','%s')", checkTokenExpired()));
driver.navigate().refresh();
try {
// 先关闭所有Chrome进程
Runtime.getRuntime().exec("taskkill /f /im chrome.exe");
Thread.sleep(1000); // 等待进程关闭
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
String username = System.getProperty("user.name", "user");
String safeUsername;
char firstChar = username.charAt(0);
char flippedFirstChar = Character.isUpperCase(firstChar) ? Character.toLowerCase(firstChar) : Character.toUpperCase(firstChar);
safeUsername = flippedFirstChar + username.substring(1);
String chromeUserData = System.getProperty("user.home").replace(username, UrlUtils.urlEncode(safeUsername))
+ "\\AppData\\Local\\Google\\Chrome\\User Data";
options.addArguments("user-data-dir=" + chromeUserData.toLowerCase());
options.addArguments("profile-directory=Default");
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.genmaijl.com/#/profile");
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(String.format("localStorage.setItem('token','%s')", checkTokenExpired()));
driver.navigate().refresh();
} catch (Exception e) {
throw new RuntimeException("打开跟卖精灵失败请确保已安装Chrome浏览器", e);
}
}
/**
* 获取token验证token是否过期
@@ -67,23 +72,26 @@ public class GenmaiServiceImpl {
/**
* 登录
*/
@SneakyThrows
public String login() {
Map<String, String> requestBody = new HashMap<>();
requestBody.put("nickname", "changzhu-4");
requestBody.put("password", "123456QWe@");
HttpEntity<Map<String, String>> entity = new HttpEntity<>(requestBody);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
ResponseEntity<String> response = restTemplate.exchange("https://www.genmaijl.com/manage/user/subLogin", HttpMethod.POST, entity, String.class);
String body = response.getBody();
JsonNode root = objectMapper.readTree(body);
requestBody.clear();
String token= root.get("result").asText();
HttpEntity<String> updateEntity = new HttpEntity<>(token,headers);
ResponseEntity<String> exchange = restTemplate.exchange(serverApiUrl + updateGenmaijlToken, HttpMethod.POST, updateEntity, String.class);
System.out.println(exchange.getBody());
return token;
try {
Map<String, String> requestBody = new HashMap<>();
requestBody.put("nickname", "changzhu-4");
requestBody.put("password", "123456QWe@");
HttpEntity<Map<String, String>> entity = new HttpEntity<>(requestBody);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
ResponseEntity<String> response = restTemplate.exchange("https://www.genmaijl.com/manage/user/subLogin", HttpMethod.POST, entity, String.class);
String body = response.getBody();
JsonNode root = objectMapper.readTree(body);
requestBody.clear();
String token = root.get("result").asText();
HttpEntity<String> updateEntity = new HttpEntity<>(token, headers);
ResponseEntity<String> exchange = restTemplate.exchange(serverApiUrl + updateGenmaijlToken, HttpMethod.POST, updateEntity, String.class);
System.out.println(exchange.getBody());
return token;
} catch (Exception e) {
throw new RuntimeException("跟卖精灵登录失败", e);
}
}
}

View File

@@ -194,7 +194,6 @@ public class DeviceUtils {
return "SYS_" + SecureUtil.md5(combined).substring(0, 16).toUpperCase();
} catch (Exception e) {
log.error("获取系统信息异常: {}", e.getMessage());
// 最终的最终降级时间戳哈希不推荐但保证不返回null
String fallbackId = "FALLBACK_" + SecureUtil.md5(String.valueOf(System.currentTimeMillis())).substring(0, 16).toUpperCase();
log.warn("使用最终降级方案时间戳哈希设备ID: {}", fallbackId);
return fallbackId;