feat(device): 更新设备管理功能并优化错误处理- 修改设备更新接口路径从 /updateExpire 到 /update- 添加设备注册时获取计算机名称功能
- 优化设备配额检查逻辑,增加账号存在性验证- 更新前端设备列表刷新逻辑,使用保存的用户名参数 - 修改账号编辑表单,禁用已存在账号的用户名和账号名编辑 -优化跟卖精灵打开功能的错误提示和异常处理- 添加页面刷新 IPC通信功能 - 限制用户名输入只能包含字母、数字和下划线 - 移除冗余的本地 IP 获取函数- 升级 erp_client_sb 模块版本至 2.4.9
This commit is contained in:
@@ -259,7 +259,7 @@ public class ClientAccountController extends BaseController {
|
||||
clientAccount.setPermissions("{\"amazon\":true,\"rakuten\":true,\"zebra\":true}");
|
||||
clientAccount.setPassword(passwordEncoder.encode(password));
|
||||
clientAccount.setAccountType("trial");
|
||||
clientAccount.setDeviceLimit(3);
|
||||
clientAccount.setDeviceLimit(1);
|
||||
clientAccount.setExpireTime(new Date(System.currentTimeMillis() + 3 * 24L * 60 * 60 * 1000));
|
||||
|
||||
int result = clientAccountService.insertClientAccount(clientAccount);
|
||||
|
||||
@@ -27,6 +27,10 @@ public class ClientDeviceController {
|
||||
return accountMapper.selectClientAccountByUsername(username);
|
||||
}
|
||||
|
||||
private int getDeviceLimit(ClientAccount account) {
|
||||
return account.getDeviceLimit() != null ? account.getDeviceLimit() : 1;
|
||||
}
|
||||
|
||||
private boolean exceedDeviceLimit(Long accountId, String deviceId, int limit) {
|
||||
int count = accountDeviceMapper.countActiveDevicesByAccountId(accountId);
|
||||
ClientAccountDevice binding = accountDeviceMapper.selectByAccountIdAndDeviceId(accountId, deviceId);
|
||||
@@ -37,22 +41,25 @@ public class ClientDeviceController {
|
||||
@GetMapping("/quota")
|
||||
public AjaxResult quota(@RequestParam String username) {
|
||||
ClientAccount account = getAccount(username);
|
||||
if (account == null) return AjaxResult.error("账号不存在");
|
||||
int used = accountDeviceMapper.countActiveDevicesByAccountId(account.getId());
|
||||
int limit = account.getDeviceLimit() != null ? account.getDeviceLimit() : 3;
|
||||
return AjaxResult.success(Map.of("limit", limit, "used", used));
|
||||
return AjaxResult.success(Map.of("limit", getDeviceLimit(account), "used", used));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public AjaxResult list(@RequestParam String username) {
|
||||
return AjaxResult.success(accountDeviceMapper.selectDevicesByAccountId(getAccount(username).getId()));
|
||||
ClientAccount account = getAccount(username);
|
||||
if (account == null) return AjaxResult.error("账号不存在");
|
||||
return AjaxResult.success(accountDeviceMapper.selectDevicesByAccountId(account.getId()));
|
||||
}
|
||||
@PostMapping("/register")
|
||||
public AjaxResult register(@RequestBody Map<String, String> data) {
|
||||
String username = data.get("username");
|
||||
String deviceId = data.get("deviceId");
|
||||
ClientAccount account = getAccount(username);
|
||||
int limit = account.getDeviceLimit() != null ? account.getDeviceLimit() : 3;
|
||||
if (account == null) return AjaxResult.error("账号不存在");
|
||||
|
||||
int limit = getDeviceLimit(account);
|
||||
if (exceedDeviceLimit(account.getId(), deviceId, limit)) {
|
||||
return AjaxResult.error("设备数量已达上限(" + limit + "个)");
|
||||
}
|
||||
@@ -62,17 +69,14 @@ public class ClientDeviceController {
|
||||
if (device == null) {
|
||||
device = new ClientDevice();
|
||||
device.setDeviceId(deviceId);
|
||||
device.setName(username + "@" + data.get("ip") + " (" + data.get("os") + ")");
|
||||
device.setOs(data.get("os"));
|
||||
device.setIp(data.get("ip"));
|
||||
device.setLocation(data.get("location"));
|
||||
device.setTrialExpireTime(new Date(System.currentTimeMillis() + 3 * 24L * 60 * 60 * 1000));
|
||||
deviceMapper.insert(device);
|
||||
}
|
||||
device.setName(username + "@" + data.get("computerName") + " (" + data.get("os") + ")");
|
||||
device.setOs(data.get("os"));
|
||||
device.setIp(data.get("ip"));
|
||||
device.setStatus("online");
|
||||
device.setLastActiveAt(now);
|
||||
device.setIp(data.get("ip"));
|
||||
device.setLocation(data.get("location"));
|
||||
deviceMapper.updateByDeviceId(device);
|
||||
|
||||
ClientAccountDevice binding = accountDeviceMapper.selectByAccountIdAndDeviceId(account.getId(), deviceId);
|
||||
@@ -90,14 +94,8 @@ public class ClientDeviceController {
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/rename")
|
||||
public AjaxResult rename(@RequestBody ClientDevice device) {
|
||||
deviceMapper.updateByDeviceId(device);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
@PostMapping("/updateExpire")
|
||||
public AjaxResult updateExpire(@RequestBody ClientDevice device) {
|
||||
@PostMapping("/update")
|
||||
public AjaxResult update(@RequestBody ClientDevice device) {
|
||||
deviceMapper.updateByDeviceId(device);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
@@ -106,9 +104,10 @@ public class ClientDeviceController {
|
||||
public AjaxResult remove(@RequestBody Map<String, String> data) {
|
||||
String deviceId = data.get("deviceId");
|
||||
String username = data.get("username");
|
||||
Long accountId = getAccount(username).getId();
|
||||
ClientAccount account = getAccount(username);
|
||||
if (account == null) return AjaxResult.error("账号不存在");
|
||||
|
||||
accountDeviceMapper.updateStatus(accountId, deviceId, "removed");
|
||||
accountDeviceMapper.updateStatus(account.getId(), deviceId, "removed");
|
||||
sseHubService.sendEvent(username, deviceId, "DEVICE_REMOVED", "{}");
|
||||
sseHubService.disconnectDevice(username, deviceId);
|
||||
return AjaxResult.success();
|
||||
@@ -124,6 +123,4 @@ public class ClientDeviceController {
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user