|
@@ -57,27 +57,28 @@ public class OAuthClaudeCodeServiceImpl implements OAuthClaudeCodeService {
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public String generateAccessToken(Long userId, String clientId) throws Exception {
|
|
public String generateAccessToken(Long userId, String clientId) throws Exception {
|
|
|
-
|
|
|
|
|
- List<ClaudeCodeUserApiKeysView> userApiKeys = claudeCodeService.getUserApiKeys(userId);
|
|
|
|
|
- if (CollectionUtil.isEmpty(userApiKeys)) {
|
|
|
|
|
- ClaudeCodeApiKeysReq claudeCodeApiKeysReq = new ClaudeCodeApiKeysReq();
|
|
|
|
|
- claudeCodeApiKeysReq.setName("系统创建");
|
|
|
|
|
- claudeCodeApiKeysReq.setUserId(userId);
|
|
|
|
|
- claudeCodeApiKeysReq.setExpiresDays(30);
|
|
|
|
|
- ClaudeCodeResp apiKeys = claudeCodeService.createApiKeys(claudeCodeApiKeysReq);
|
|
|
|
|
- JSONObject jsonObject = new JSONObject(apiKeys.getData());
|
|
|
|
|
- String token = jsonObject.getStr("key_value");
|
|
|
|
|
- // 保存token
|
|
|
|
|
- OAuthToken oAuthToken = new OAuthToken();
|
|
|
|
|
- oAuthToken.setTokenValue(token);
|
|
|
|
|
- oAuthToken.setUserId(userId);
|
|
|
|
|
- oAuthToken.setClientId(clientId);
|
|
|
|
|
- oAuthToken.setStatus(1);
|
|
|
|
|
- oAuthToken.setCreatedTime(new Date());
|
|
|
|
|
-
|
|
|
|
|
- oauthTokenMapper.insert(oAuthToken);
|
|
|
|
|
- return token;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ if (claudeCodeService.checkClaudeCodeUser(userId)) {
|
|
|
|
|
+ List<ClaudeCodeUserApiKeysView> userApiKeys = claudeCodeService.getUserApiKeys(userId);
|
|
|
|
|
+ if (CollectionUtil.isEmpty(userApiKeys)) {
|
|
|
|
|
+ ClaudeCodeApiKeysReq claudeCodeApiKeysReq = new ClaudeCodeApiKeysReq();
|
|
|
|
|
+ claudeCodeApiKeysReq.setName("系统创建");
|
|
|
|
|
+ claudeCodeApiKeysReq.setUserId(userId);
|
|
|
|
|
+ claudeCodeApiKeysReq.setExpiresDays(30);
|
|
|
|
|
+ ClaudeCodeResp apiKeys = claudeCodeService.createApiKeys(claudeCodeApiKeysReq);
|
|
|
|
|
+ JSONObject jsonObject = new JSONObject(apiKeys.getData());
|
|
|
|
|
+ String token = jsonObject.getStr("key_value");
|
|
|
|
|
+ // 保存token
|
|
|
|
|
+ OAuthToken oAuthToken = new OAuthToken();
|
|
|
|
|
+ oAuthToken.setTokenValue(token);
|
|
|
|
|
+ oAuthToken.setUserId(userId);
|
|
|
|
|
+ oAuthToken.setClientId(clientId);
|
|
|
|
|
+ oAuthToken.setStatus(1);
|
|
|
|
|
+ oAuthToken.setCreatedTime(new Date());
|
|
|
|
|
+
|
|
|
|
|
+ oauthTokenMapper.insert(oAuthToken);
|
|
|
|
|
+ return token;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
return null;
|