refactor(api):重构API服务接口与实现
- 移除多余的接口定义文件,简化依赖关系- 更新控制器和服务实现类的注入方式-优化请求参数处理逻辑 - 统一响应数据结构格式- 调整方法签名以提高一致性 - 删除冗余注释和无用代码- 修改系统API调用路径引用位置 - 简化认证服务实现并移除不必要的抽象层 - 优化Excel文件解析相关功能 - 清理无用的工具类和配置项 - 调整错误上报机制的依赖注入方式 - 更新跟卖精灵服务的实现细节- 优化HTTP请求工具函数结构 - 移除废弃的缓存管理服务接口定义 - 调整设备配额检查逻辑复用性 - 优化订单服务的数据返回格式 - 更新产品服务中的数据处理方式 - 重构客户端账户控制器中的设备限制检查逻辑
This commit is contained in:
@@ -3,7 +3,6 @@ package com.ruoyi.web.controller.monitor;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.ruoyi.common.annotation.Anonymous;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -58,6 +57,17 @@ public class ClientAccountController extends BaseController {
|
||||
@Autowired
|
||||
private ClientDeviceMapper clientDeviceMapper;
|
||||
|
||||
private AjaxResult checkDeviceLimit(String username, String deviceId, int deviceLimit) {
|
||||
List<ClientDevice> userDevices = clientDeviceMapper.selectByUsername(username);
|
||||
int userDevice = userDevices.size();
|
||||
boolean exists = userDevices.stream().anyMatch(d -> deviceId.equals(d.getDeviceId()));
|
||||
if (exists) userDevice--;
|
||||
if (userDevice >= deviceLimit) {
|
||||
return AjaxResult.error("设备数量已达上限(" + deviceLimit + "个),请先移除其他设备");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询账号列表
|
||||
*/
|
||||
@@ -140,15 +150,8 @@ public class ClientAccountController extends BaseController {
|
||||
return AjaxResult.error("账号已被停用");
|
||||
}
|
||||
|
||||
// 检查设备数量限制
|
||||
int deviceLimit = account.getDeviceLimit();
|
||||
List<ClientDevice> userDevices = clientDeviceMapper.selectByUsername(username);
|
||||
int userDevice = userDevices.size();
|
||||
boolean exists = userDevices.stream().anyMatch(d -> clientId.equals(d.getDeviceId()));
|
||||
if (exists) userDevice--;
|
||||
if (userDevice >= deviceLimit) {
|
||||
return AjaxResult.error("设备数量已达上限(" + deviceLimit + "个),请先移除其他设备");
|
||||
}
|
||||
AjaxResult limitCheck = checkDeviceLimit(username, clientId, account.getDeviceLimit());
|
||||
if (limitCheck != null) return limitCheck;
|
||||
String token = Jwts.builder()
|
||||
.setHeaderParam("kid", jwtRsaKeyService.getKeyId())
|
||||
.setSubject(username)
|
||||
@@ -160,7 +163,6 @@ public class ClientAccountController extends BaseController {
|
||||
.signWith(SignatureAlgorithm.RS256, jwtRsaKeyService.getPrivateKey())
|
||||
.compact();
|
||||
|
||||
// 检查设备试用期(仅对trial账号生效)
|
||||
boolean deviceTrialExpired = false;
|
||||
if ("trial".equals(account.getAccountType())) {
|
||||
ClientDevice device = clientDeviceMapper.selectByDeviceIdAndUsername(clientId, username);
|
||||
@@ -169,14 +171,14 @@ public class ClientAccountController extends BaseController {
|
||||
&& new Date().after(device.getTrialExpireTime());
|
||||
}
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("token", token);
|
||||
data.put("permissions", account.getPermissions());
|
||||
data.put("accountName", account.getAccountName());
|
||||
data.put("expireTime", account.getExpireTime());
|
||||
data.put("accountType", account.getAccountType());
|
||||
data.put("deviceTrialExpired", deviceTrialExpired);
|
||||
return AjaxResult.success(data);
|
||||
return AjaxResult.success(Map.of(
|
||||
"token", token,
|
||||
"permissions", account.getPermissions(),
|
||||
"accountName", account.getAccountName(),
|
||||
"expireTime", account.getExpireTime(),
|
||||
"accountType", account.getAccountType(),
|
||||
"deviceTrialExpired", deviceTrialExpired
|
||||
));
|
||||
}
|
||||
/**
|
||||
* 验证token
|
||||
@@ -202,7 +204,6 @@ public class ClientAccountController extends BaseController {
|
||||
clientAccountService.updateClientAccount(account);
|
||||
}
|
||||
|
||||
// 检查设备试用期(仅对trial账号生效)
|
||||
boolean deviceTrialExpired = false;
|
||||
if ("trial".equals(account.getAccountType())) {
|
||||
ClientDevice device = clientDeviceMapper.selectByDeviceIdAndUsername(clientId, username);
|
||||
@@ -211,14 +212,14 @@ public class ClientAccountController extends BaseController {
|
||||
&& new Date().after(device.getTrialExpireTime());
|
||||
}
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("username", username);
|
||||
result.put("permissions", account.getPermissions());
|
||||
result.put("accountName", account.getAccountName());
|
||||
result.put("expireTime", account.getExpireTime());
|
||||
result.put("accountType", account.getAccountType());
|
||||
result.put("deviceTrialExpired", deviceTrialExpired);
|
||||
return AjaxResult.success(result);
|
||||
return AjaxResult.success(Map.of(
|
||||
"username", username,
|
||||
"permissions", account.getPermissions(),
|
||||
"accountName", account.getAccountName(),
|
||||
"expireTime", account.getExpireTime(),
|
||||
"accountType", account.getAccountType(),
|
||||
"deviceTrialExpired", deviceTrialExpired
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,14 +277,14 @@ public class ClientAccountController extends BaseController {
|
||||
.signWith(SignatureAlgorithm.RS256, jwtRsaKeyService.getPrivateKey())
|
||||
.compact();
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("token", token);
|
||||
data.put("permissions", clientAccount.getPermissions());
|
||||
data.put("accountName", clientAccount.getAccountName());
|
||||
data.put("expireTime", clientAccount.getExpireTime());
|
||||
data.put("accountType", clientAccount.getAccountType());
|
||||
data.put("deviceTrialExpired", false);
|
||||
return AjaxResult.success(data);
|
||||
return AjaxResult.success(Map.of(
|
||||
"token", token,
|
||||
"permissions", clientAccount.getPermissions(),
|
||||
"accountName", clientAccount.getAccountName(),
|
||||
"expireTime", clientAccount.getExpireTime(),
|
||||
"accountType", clientAccount.getAccountType(),
|
||||
"deviceTrialExpired", false
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,13 +325,10 @@ public class ClientAccountController extends BaseController {
|
||||
account.setUpdateBy(getUsername());
|
||||
clientAccountService.updateClientAccount(account);
|
||||
|
||||
// 推送续费通知
|
||||
sseHubService.sendEventToAllDevices(account.getUsername(), "VIP_RENEWED",
|
||||
"{\"expireTime\":\"" + newExpireTime + "\"}");
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("expireTime", newExpireTime);
|
||||
return AjaxResult.success(result);
|
||||
return AjaxResult.success(Map.of("expireTime", newExpireTime));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.ruoyi.web.controller.system;
|
||||
import com.ruoyi.common.annotation.Anonymous;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.ip.IpUtils;
|
||||
import com.ruoyi.system.domain.ClientDevice;
|
||||
import com.ruoyi.system.mapper.ClientDeviceMapper;
|
||||
import com.ruoyi.system.mapper.ClientAccountMapper;
|
||||
@@ -10,7 +9,6 @@ import com.ruoyi.web.sse.SseHubService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -24,13 +22,19 @@ public class ClientDeviceController {
|
||||
private ClientAccountMapper clientAccountMapper;
|
||||
@Autowired
|
||||
private SseHubService sseHubService;
|
||||
private AjaxResult checkDeviceLimit(String username, String deviceId) {
|
||||
ClientAccount account = clientAccountMapper.selectClientAccountByUsername(username);
|
||||
int deviceLimit = (account != null && account.getDeviceLimit() != null) ? account.getDeviceLimit() : 3;
|
||||
List<ClientDevice> 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 + "个),请先移除其他设备");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备配额与已使用数量
|
||||
*
|
||||
* @param username 用户名,为空时返回0
|
||||
* @return 配额信息
|
||||
*/
|
||||
@GetMapping("/quota")
|
||||
public AjaxResult quota(@RequestParam(value = "username", required = false) String username) {
|
||||
List<ClientDevice> all = clientDeviceMapper.selectByUsername(username);
|
||||
@@ -40,10 +44,7 @@ public class ClientDeviceController {
|
||||
}
|
||||
ClientAccount account = clientAccountMapper.selectClientAccountByUsername(username);
|
||||
int limit = (account != null && account.getDeviceLimit() != null) ? account.getDeviceLimit() : 3;
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("limit", limit);
|
||||
map.put("used", used);
|
||||
return AjaxResult.success(map);
|
||||
return AjaxResult.success(Map.of("limit", limit, "used", used));
|
||||
}
|
||||
/**
|
||||
* 按用户名查询设备列表(最近活动优先)
|
||||
@@ -70,16 +71,8 @@ public class ClientDeviceController {
|
||||
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<ClientDevice> 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 + "个),请先移除其他设备");
|
||||
}
|
||||
AjaxResult limitCheck = checkDeviceLimit(username, deviceId);
|
||||
if (limitCheck != null) return limitCheck;
|
||||
|
||||
ClientDevice exists = clientDeviceMapper.selectByDeviceIdAndUsername(deviceId, username);
|
||||
if (exists == null) {
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.ruoyi.web.controller.tool;
|
||||
|
||||
import com.ruoyi.common.annotation.Anonymous;
|
||||
import com.ruoyi.common.core.redis.RedisCache;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@Anonymous
|
||||
public class GenmaijlController {
|
||||
@Autowired
|
||||
RedisCache redisCache;
|
||||
@GetMapping("/getToken")
|
||||
public String getToken(){
|
||||
return redisCache.getCacheObject("genmaijlToken");
|
||||
}
|
||||
|
||||
@PostMapping("/saveToken")
|
||||
public int saveToken(@RequestBody String token){
|
||||
redisCache.setCacheObject("genmaijlToken", token);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user