|
|
@@ -216,7 +216,7 @@ public class CodexServiceImpl implements CodexService {
|
|
|
return null;
|
|
|
}
|
|
|
// 调用Codex API获取实时使用统计
|
|
|
- String usageUrl = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/usage?period=%s", userId, period);
|
|
|
+ String usageUrl = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/openai/users/%s/usage?period=%s", userId, period);
|
|
|
ClaudeCodeResp codexResp = executeCodexGetApi(usageUrl);
|
|
|
return codexResp;
|
|
|
}
|
|
|
@@ -309,93 +309,6 @@ public class CodexServiceImpl implements CodexService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public ClaudeCodeResp getUserKeys(Long userId) {
|
|
|
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
- CodexUser codexUser = codexUserMapper.selectOne(Wrappers.lambdaQuery(CodexUser.class).in(CodexUser::getUserId, userIdList).last("limit 1"));
|
|
|
-
|
|
|
- if (codexUser == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- // 调用Codex API获取用户密钥列表
|
|
|
- String keysUrl = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/keys", userId);
|
|
|
- ClaudeCodeResp codexResp = executeCodexGetApi(keysUrl);
|
|
|
-
|
|
|
- if (codexResp == null) {
|
|
|
- log.error("获取用户{}密钥列表失败: API返回null", userId);
|
|
|
- throw new BusinessRuntimeException("获取用户密钥列表失败");
|
|
|
- }
|
|
|
-
|
|
|
- log.info("成功获取用户{}密钥列表", userId);
|
|
|
- return codexResp;
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("获取用户{}密钥列表异常, error={}", userId, StringUtil.getErrorText(e));
|
|
|
- throw new BusinessRuntimeException("获取用户密钥列表失败");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public ClaudeCodeResp createUserKey(Long userId, String keyName) {
|
|
|
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
- CodexUser codexUser = codexUserMapper.selectOne(Wrappers.lambdaQuery(CodexUser.class).in(CodexUser::getUserId, userIdList).last("limit 1"));
|
|
|
-
|
|
|
- if (codexUser == null) {
|
|
|
- throw new BusinessRuntimeException("用户未开通Codex服务");
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- // 调用Codex API创建用户密钥
|
|
|
- String createKeyUrl = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/keys", userId);
|
|
|
- Map<String, Object> params = new HashMap<>();
|
|
|
- params.put("name", keyName);
|
|
|
-
|
|
|
- ClaudeCodeResp codexResp = executeCodexPostApi(createKeyUrl, Jsons.toJson(params));
|
|
|
-
|
|
|
- if (!"success".equals(codexResp.getMessage())) {
|
|
|
- log.error("创建用户{}密钥失败: {}", userId, codexResp.getMessage());
|
|
|
- throw new BusinessRuntimeException("创建用户密钥失败");
|
|
|
- }
|
|
|
-
|
|
|
- log.info("成功创建用户{}密钥, keyName={}", userId, keyName);
|
|
|
- return codexResp;
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("创建用户{}密钥异常, keyName={}, error={}", userId, keyName, StringUtil.getErrorText(e));
|
|
|
- throw new BusinessRuntimeException("创建用户密钥失败");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public ClaudeCodeResp deleteUserKey(Long userId, String keyId) {
|
|
|
- List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
- CodexUser codexUser = codexUserMapper.selectOne(Wrappers.lambdaQuery(CodexUser.class).in(CodexUser::getUserId, userIdList).last("limit 1"));
|
|
|
-
|
|
|
- if (codexUser == null) {
|
|
|
- throw new BusinessRuntimeException("用户未开通Codex服务");
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- // 调用Codex API删除用户密钥
|
|
|
- String deleteKeyUrl = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/keys/%s", userId, keyId);
|
|
|
- ClaudeCodeResp codexResp = executeCodexDeleteApi(deleteKeyUrl);
|
|
|
-
|
|
|
- if (!"success".equals(codexResp.getMessage())) {
|
|
|
- log.error("删除用户{}密钥{}失败: {}", userId, keyId, codexResp.getMessage());
|
|
|
- throw new BusinessRuntimeException("删除用户密钥失败");
|
|
|
- }
|
|
|
-
|
|
|
- log.info("成功删除用户{}密钥{}", userId, keyId);
|
|
|
- return codexResp;
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("删除用户{}密钥{}异常, error={}", userId, keyId, StringUtil.getErrorText(e));
|
|
|
- throw new BusinessRuntimeException("删除用户密钥失败");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public ClaudeCodeResp getUserDashboard(Long userId) {
|
|
|
List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|