From 0c85aa567798ea59083a8fc4ff85261fb1876c0b Mon Sep 17 00:00:00 2001 From: zhangzijienbplus <17738440858@163.com> Date: Fri, 17 Oct 2025 16:14:43 +0800 Subject: [PATCH] =?UTF-8?q?refactor(client):=E4=BC=98=E5=8C=96=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=AE=A1=E7=90=86=E4=B8=8E=E7=99=BB=E5=BD=95=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除冗余的日志记录器声明 - 简化设备心跳接口,合并注册与更新逻辑 - 调整设备数量限制检查逻辑,提高代码可读性 - 修改默认设备数量限制从3台调整为1台- 更新客户端登出提示文案- 固定启动窗口尺寸并移除延迟启动逻辑 - 调整设备移除时的消息提示内容 --- electron-vue-template/src/main/main.ts | 13 ++- electron-vue-template/src/renderer/App.vue | 15 +-- .../impl/AmazonScrapingServiceImpl.java | 3 +- .../system/ClientDeviceController.java | 99 +++---------------- ruoyi-ui/src/views/monitor/account/index.vue | 28 +++--- 5 files changed, 41 insertions(+), 117 deletions(-) diff --git a/electron-vue-template/src/main/main.ts b/electron-vue-template/src/main/main.ts index 650e837..a86038d 100644 --- a/electron-vue-template/src/main/main.ts +++ b/electron-vue-template/src/main/main.ts @@ -199,7 +199,7 @@ function startSpringBoot() { } } -// startSpringBoot(); +startSpringBoot(); function stopSpringBoot() { if (!springProcess) return; @@ -269,10 +269,9 @@ app.whenReady().then(() => { createWindow(); createTray(mainWindow); - const {width: sw, height: sh} = screen.getPrimaryDisplay().workAreaSize; splashWindow = new BrowserWindow({ - width: Math.min(Math.floor(sw * 0.8), 1800), - height: Math.min(Math.floor(sh * 0.8), 1200), + width: 1200, + height: 675, frame: false, transparent: false, resizable: false, @@ -296,9 +295,9 @@ app.whenReady().then(() => { splashWindow.loadFile(splashPath); } - setTimeout(() => { - openAppIfNotOpened(); - }, 2000); + // setTimeout(() => { + // openAppIfNotOpened(); + // }, 2000); app.on('activate', () => { if (mainWindow && !mainWindow.isDestroyed()) { diff --git a/electron-vue-template/src/renderer/App.vue b/electron-vue-template/src/renderer/App.vue index c67f496..1a068b6 100644 --- a/electron-vue-template/src/renderer/App.vue +++ b/electron-vue-template/src/renderer/App.vue @@ -185,16 +185,13 @@ async function handleLoginSuccess(data: { token: string; permissions?: string; e os: navigator.platform }) SSEManager.connect() - + // 根据不同场景显示提示 const accountExpired = vipExpireTime.value && new Date() > vipExpireTime.value const deviceExpired = deviceTrialExpired.value const isPaid = accountType.value === 'paid' - if (isPaid) { - // 场景5: 付费用户 - ElMessage.success('登录成功') - } else if (deviceExpired && accountExpired) { + if (deviceExpired && accountExpired) { // 场景4: 试用已到期,请订阅 trialExpiredType.value = 'both' showTrialExpiredDialog.value = true @@ -206,9 +203,6 @@ async function handleLoginSuccess(data: { token: string; permissions?: string; e // 场景2: 设备试用已到期,请更换设备或订阅 trialExpiredType.value = 'device' showTrialExpiredDialog.value = true - } else { - // 场景1: 允许使用 - ElMessage.success('登录成功') } } catch (e: any) { isAuthenticated.value = false @@ -234,7 +228,7 @@ function clearLocalAuth() { async function logout() { try { const deviceId = getClientIdFromToken() - if (deviceId) await deviceApi.offline({ deviceId, username: currentUsername.value }) + if (deviceId) await deviceApi.remove({ deviceId, username: currentUsername.value }) } catch (error) { console.warn('离线通知失败:', error) } @@ -253,7 +247,6 @@ async function handleUserClick() { cancelButtonText: '取消' }) await logout() - ElMessage.success('已退出登录') } catch {} } @@ -366,7 +359,7 @@ const SSEManager = { break case 'DEVICE_REMOVED': clearLocalAuth() - ElMessage.warning('您的设备已被移除,请重新登录') + ElMessage.warning('会话已失效,请重新登录') break case 'FORCE_LOGOUT': logout() diff --git a/erp_client_sb/src/main/java/com/tashow/erp/service/impl/AmazonScrapingServiceImpl.java b/erp_client_sb/src/main/java/com/tashow/erp/service/impl/AmazonScrapingServiceImpl.java index 5d51d72..2f4e4ba 100644 --- a/erp_client_sb/src/main/java/com/tashow/erp/service/impl/AmazonScrapingServiceImpl.java +++ b/erp_client_sb/src/main/java/com/tashow/erp/service/impl/AmazonScrapingServiceImpl.java @@ -27,7 +27,6 @@ import java.util.concurrent.ConcurrentHashMap; */ @Service public class AmazonScrapingServiceImpl implements IAmazonScrapingService, PageProcessor { - private static final Logger logger = LoggerFactory.getLogger(AmazonScrapingServiceImpl.class); @Autowired private AmazonProductRepository amazonProductRepository; @Autowired @@ -102,7 +101,7 @@ public class AmazonScrapingServiceImpl implements IAmazonScrapingService, PagePr @Override public List batchGetProductInfo(List asinList, String batchId, String region) { String sessionId = (batchId != null) ? batchId : "SINGLE_" + UUID.randomUUID(); - LocalDateTime batchTime = LocalDateTime.now(); // 统一的批次时间 + LocalDateTime batchTime = LocalDateTime.now(); // 第一步:清理1小时前的所有旧数据 amazonProductRepository.deleteAllDataBefore(LocalDateTime.now().minusHours(1)); diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ClientDeviceController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ClientDeviceController.java index d2b1b6f..f5c21c6 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ClientDeviceController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/ClientDeviceController.java @@ -24,40 +24,6 @@ public class ClientDeviceController { private ClientAccountMapper clientAccountMapper; @Autowired private SseHubService sseHubService; - private static final int DEFAULT_LIMIT = 3; - - /** - * 获取账号的设备数量限制 - * - * @param username 用户名 - * @return 设备数量限制,如果账号不存在或未配置则返回默认值 - */ - private int getDeviceLimit(String username) { - if (username == null || username.isEmpty()) { - return DEFAULT_LIMIT; - } - ClientAccount account = clientAccountMapper.selectClientAccountByUsername(username); - if (account == null || account.getDeviceLimit() == null) { - return DEFAULT_LIMIT; - } - return account.getDeviceLimit(); - } - - /** - * 检查设备数量限制 - * - * @param username 用户名 - * @param currentDeviceId 当前设备ID(检查时排除此设备) - * @throws RuntimeException 如果设备数量已达上限 - */ - private void checkDeviceLimit(String username, String currentDeviceId) { - int deviceLimit = getDeviceLimit(username); - List userDevices = clientDeviceMapper.selectByUsername(username); - if (userDevices.size() >= deviceLimit) { - throw new RuntimeException("设备数量已达上限(" + deviceLimit + "个),请先移除其他设备"); - } - - } /** * 查询设备配额与已使用数量 @@ -72,7 +38,8 @@ public class ClientDeviceController { for (ClientDevice d : all) { if (!"removed".equals(d.getStatus())) used++; } - int limit = getDeviceLimit(username); + ClientAccount account = clientAccountMapper.selectClientAccountByUsername(username); + int limit = (account != null && account.getDeviceLimit() != null) ? account.getDeviceLimit() : 3; Map map = new HashMap<>(); map.put("limit", limit); map.put("used", used); @@ -102,14 +69,21 @@ public class ClientDeviceController { String deviceId = device.getDeviceId(); String os = device.getOs(); String deviceName = username + "@" + ip + " (" + os + ")"; + + // 检查设备数量限制 + ClientAccount account = clientAccountMapper.selectClientAccountByUsername(username); + int deviceLimit = (account != null && account.getDeviceLimit() != null) ? account.getDeviceLimit() : 3; + List userDevices = clientDeviceMapper.selectByUsername(username); + int userDevice = userDevices.size(); + boolean deviceExists = userDevices.stream().anyMatch(d -> deviceId.equals(d.getDeviceId())); + if (deviceExists) userDevice--; + if (userDevice >= deviceLimit) { + return AjaxResult.error("设备数量已达上限(" + deviceLimit + "个),请先移除其他设备"); + } + ClientDevice exists = clientDeviceMapper.selectByDeviceIdAndUsername(deviceId, username); if (exists == null) { - // 检查设备数量限制 - try { - checkDeviceLimit(username, deviceId); - } catch (RuntimeException e) { - return AjaxResult.error(e.getMessage()); - } + device.setIp(ip); device.setStatus("online"); device.setLastActiveAt(new java.util.Date()); @@ -117,6 +91,7 @@ public class ClientDeviceController { device.setName(deviceName); clientDeviceMapper.insert(device); } else { + exists.setName(deviceName); exists.setOs(os); exists.setStatus("online"); @@ -188,48 +163,6 @@ public class ClientDeviceController { return AjaxResult.success(); } - /** - * 设备心跳 - * 若设备未注册则按注册逻辑插入;已注册则更新在线状态和设备信息 - * 所有情况都检查设备数量限制,被移除设备允许重新注册(需检查配额) - */ - @PostMapping("/heartbeat") - public AjaxResult heartbeat(@RequestBody ClientDevice device, HttpServletRequest request) { - String ip = IpUtils.getIpAddr(request); - String username = device.getUsername(); - String deviceId = device.getDeviceId(); - String os = device.getOs(); - String deviceName = username + "@" + ip + " (" + os + ")"; - - ClientDevice exists = clientDeviceMapper.selectByDeviceIdAndUsername(deviceId, username); - if (exists == null) { - // 新设备注册 - device.setIp(ip); - device.setStatus("online"); - device.setLastActiveAt(new java.util.Date()); - device.setTrialExpireTime(new java.util.Date(System.currentTimeMillis() + 3 * 24L * 60 * 60 * 1000)); - device.setName(deviceName); - clientDeviceMapper.insert(device); - } else if ("removed".equals(exists.getStatus())) { - // 被移除设备重新激活 - exists.setName(deviceName); - exists.setOs(os); - exists.setStatus("online"); - exists.setIp(ip); - exists.setLocation(device.getLocation()); - exists.setLastActiveAt(new java.util.Date()); - clientDeviceMapper.updateByDeviceIdAndUsername(exists); - } else { - // 已存在设备更新 - exists.setStatus("online"); - exists.setIp(ip); - exists.setLastActiveAt(new java.util.Date()); - exists.setName(deviceName); - clientDeviceMapper.updateByDeviceIdAndUsername(exists); - } - return AjaxResult.success(); - } - } diff --git a/ruoyi-ui/src/views/monitor/account/index.vue b/ruoyi-ui/src/views/monitor/account/index.vue index 1f27a8e..2743399 100644 --- a/ruoyi-ui/src/views/monitor/account/index.vue +++ b/ruoyi-ui/src/views/monitor/account/index.vue @@ -96,8 +96,8 @@