|
@@ -27,17 +27,16 @@ import com.cyksj.model.request.ClaudeCodeApiKeysReq;
|
|
|
import com.cyksj.model.request.ClaudeCodeCreditCardUseReq;
|
|
import com.cyksj.model.request.ClaudeCodeCreditCardUseReq;
|
|
|
import com.cyksj.model.request.ClaudeCodeDelReq;
|
|
import com.cyksj.model.request.ClaudeCodeDelReq;
|
|
|
import com.cyksj.model.request.CreditResetReq;
|
|
import com.cyksj.model.request.CreditResetReq;
|
|
|
|
|
+import com.cyksj.model.request.codex.CodexUserPackageReq;
|
|
|
import com.cyksj.model.response.ClaudeCodePointsHistoryResp;
|
|
import com.cyksj.model.response.ClaudeCodePointsHistoryResp;
|
|
|
import com.cyksj.model.response.ClaudeCodeRewardDetailsResp;
|
|
import com.cyksj.model.response.ClaudeCodeRewardDetailsResp;
|
|
|
import com.cyksj.model.response.CreditResetResp;
|
|
import com.cyksj.model.response.CreditResetResp;
|
|
|
import com.cyksj.model.response.TimeRateConfigsResp;
|
|
import com.cyksj.model.response.TimeRateConfigsResp;
|
|
|
import com.cyksj.model.response.claudecode.ClaudeCodeResp;
|
|
import com.cyksj.model.response.claudecode.ClaudeCodeResp;
|
|
|
-import com.cyksj.model.views.ClaudeCodeUserApiKeysView;
|
|
|
|
|
-import com.cyksj.model.views.ClaudeCodeUserCreditCardRecordView;
|
|
|
|
|
-import com.cyksj.model.views.ClaudeCodeUserInfoView;
|
|
|
|
|
-import com.cyksj.model.views.ClaudeCodeUserResetRecordView;
|
|
|
|
|
|
|
+import com.cyksj.model.views.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.claude.ClaudeCodeService;
|
|
import com.cyksj.service.claude.ClaudeCodeService;
|
|
|
|
|
+import com.cyksj.service.codex.CodexService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.SearchResult;
|
|
import com.ejlchina.searcher.SearchResult;
|
|
@@ -100,14 +99,9 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
|
|
|
|
|
private final RedisService redisService;
|
|
private final RedisService redisService;
|
|
|
|
|
|
|
|
- private final static String CLAUDE_CODE_API_PREFIX = "https://relay01.yhlxj.com/";
|
|
|
|
|
-
|
|
|
|
|
- public static final String CLAUDE_CODE_HEARD_KEY = "X-Admin-Key";
|
|
|
|
|
-
|
|
|
|
|
- public static final String CLAUDE_CODE_API_ADMIN_KEY = "claudecodeyhlxjclaude";
|
|
|
|
|
-
|
|
|
|
|
- //连接超时时间 毫秒
|
|
|
|
|
- public static final int CONNECT_MILLISECONDS = 10000;
|
|
|
|
|
|
|
+ private final CodexService codexService;
|
|
|
|
|
+
|
|
|
|
|
+ private final CodexUserMapper codexUserMapper;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void generateOrUpdateClaudeCodeUserInfo(Long orderId, Long relationId, Long userId, GoodsDonSku sku, Integer orderType) {
|
|
public void generateOrUpdateClaudeCodeUserInfo(Long orderId, Long relationId, Long userId, GoodsDonSku sku, Integer orderType) {
|
|
@@ -148,7 +142,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
//获取最新的claude code user
|
|
//获取最新的claude code user
|
|
|
claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).eq(ClaudeCodeUser::getRelationId, relationId).last("limit 1"));
|
|
claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).eq(ClaudeCodeUser::getRelationId, relationId).last("limit 1"));
|
|
|
//生成claude code或更新用户套餐
|
|
//生成claude code或更新用户套餐
|
|
|
- ClaudeCodeResp codeUserPackage = createOrUpdateClaudeCodeUserPackage(relation.getUserId(), claudeCodeUser.getPlanName(), claudeCodeUser.getCodePoints(), claudeCodeUser.getCodeCreditRecovery(), claudeCodeUser.getExpiryTime());
|
|
|
|
|
|
|
+ ClaudeCodeResp codeUserPackage = createOrUpdateClaudeCodeUserPackage(relation.getUserId(), claudeCodeUser.getPlanName(), claudeCodeUser.getCodePoints(), claudeCodeUser.getCodeCreditRecovery(), claudeCodeUser.getExpiryTime(), claudeCodeUser.getRelationId(), sku);
|
|
|
if (!Constant.SUCCESS.equals(codeUserPackage.getMessage())) {
|
|
if (!Constant.SUCCESS.equals(codeUserPackage.getMessage())) {
|
|
|
//重试更新code userInfo数据
|
|
//重试更新code userInfo数据
|
|
|
setClaudeCodeUserRetryUpdateInfo(relationId);
|
|
setClaudeCodeUserRetryUpdateInfo(relationId);
|
|
@@ -206,7 +200,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
if (checkClaudeCodeUser(userId)) {
|
|
if (checkClaudeCodeUser(userId)) {
|
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
|
Assert.notNull(claudeCodeUserId, "您的claude code账号已过期");
|
|
Assert.notNull(claudeCodeUserId, "您的claude code账号已过期");
|
|
|
- String apiKeyUrl = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/keys", claudeCodeUserId);
|
|
|
|
|
|
|
+ String apiKeyUrl = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/keys", claudeCodeUserId);
|
|
|
Map<String, Object> parmas = new HashMap<>();
|
|
Map<String, Object> parmas = new HashMap<>();
|
|
|
parmas.put("name", req.getName());
|
|
parmas.put("name", req.getName());
|
|
|
Integer expiresDays = req.getExpiresDays();
|
|
Integer expiresDays = req.getExpiresDays();
|
|
@@ -228,8 +222,8 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
Long keyId = delReq.getKeyId();
|
|
Long keyId = delReq.getKeyId();
|
|
|
if (checkClaudeCodeUser(userId)) {
|
|
if (checkClaudeCodeUser(userId)) {
|
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/keys/%s/%s", claudeCodeUserId, keyId);
|
|
|
|
|
- HttpResponse execute = HttpUtil.createRequest(Method.DELETE, url).header(CLAUDE_CODE_HEARD_KEY, CLAUDE_CODE_API_ADMIN_KEY).setConnectionTimeout(CONNECT_MILLISECONDS).execute();
|
|
|
|
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/keys/%s/%s", claudeCodeUserId, keyId);
|
|
|
|
|
+ HttpResponse execute = HttpUtil.createRequest(Method.DELETE, url).header(Constant.CLAUDE_CODE_HEARD_KEY, Constant.CLAUDE_CODE_API_ADMIN_KEY).setConnectionTimeout(Constant.CONNECT_MILLISECONDS).execute();
|
|
|
String responseBody = execute.body();
|
|
String responseBody = execute.body();
|
|
|
ClaudeCodeResp claudeCodeResp = Jsons.parseObject(responseBody, ClaudeCodeResp.class);
|
|
ClaudeCodeResp claudeCodeResp = Jsons.parseObject(responseBody, ClaudeCodeResp.class);
|
|
|
if (!Constant.SUCCESS.equals(claudeCodeResp.getMessage())) {
|
|
if (!Constant.SUCCESS.equals(claudeCodeResp.getMessage())) {
|
|
@@ -243,7 +237,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
public List<ClaudeCodeUserApiKeysView> getUserApiKeys(long userId) throws Exception {
|
|
public List<ClaudeCodeUserApiKeysView> getUserApiKeys(long userId) throws Exception {
|
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
|
if (claudeCodeUserId != null) {
|
|
if (claudeCodeUserId != null) {
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/keys", claudeCodeUserId);
|
|
|
|
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/keys", claudeCodeUserId);
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
|
return Jsons.parseList(claudeCodeResp.getData(), ClaudeCodeUserApiKeysView.class);
|
|
return Jsons.parseList(claudeCodeResp.getData(), ClaudeCodeUserApiKeysView.class);
|
|
|
}
|
|
}
|
|
@@ -254,7 +248,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
public ClaudeCodePointsHistoryResp getUserPointsDetail(Long userId, String type, Integer page, Integer limit) throws Exception {
|
|
public ClaudeCodePointsHistoryResp getUserPointsDetail(Long userId, String type, Integer page, Integer limit) throws Exception {
|
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
|
if (claudeCodeUserId != null) {
|
|
if (claudeCodeUserId != null) {
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/credits/history?page=%s&limit=%s&type=%s", claudeCodeUserId, page, limit, type);
|
|
|
|
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/credits/history?page=%s&limit=%s&type=%s", claudeCodeUserId, page, limit, type);
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
|
ClaudeCodePointsHistoryResp historyResp = Jsons.parseObject(claudeCodeResp.getData(), ClaudeCodePointsHistoryResp.class);
|
|
ClaudeCodePointsHistoryResp historyResp = Jsons.parseObject(claudeCodeResp.getData(), ClaudeCodePointsHistoryResp.class);
|
|
|
return historyResp;
|
|
return historyResp;
|
|
@@ -266,7 +260,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
public ClaudeCodeResp getUserDashboard(Long userId) throws Exception {
|
|
public ClaudeCodeResp getUserDashboard(Long userId) throws Exception {
|
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
|
if (claudeCodeUserId != null) {
|
|
if (claudeCodeUserId != null) {
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/dashboard", claudeCodeUserId);
|
|
|
|
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/dashboard", claudeCodeUserId);
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
|
return claudeCodeResp;
|
|
return claudeCodeResp;
|
|
|
}
|
|
}
|
|
@@ -277,7 +271,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
public ClaudeCodeResp getUserBalance(Long userId) throws Exception {
|
|
public ClaudeCodeResp getUserBalance(Long userId) throws Exception {
|
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
Long claudeCodeUserId = getClaudeCodeUserId(userId);
|
|
|
if (claudeCodeUserId != null) {
|
|
if (claudeCodeUserId != null) {
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/balance", claudeCodeUserId);
|
|
|
|
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/balance", claudeCodeUserId);
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
|
return claudeCodeResp;
|
|
return claudeCodeResp;
|
|
|
}
|
|
}
|
|
@@ -293,7 +287,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
end = now.toString();
|
|
end = now.toString();
|
|
|
}
|
|
}
|
|
|
if (claudeCodeUserId != null) {
|
|
if (claudeCodeUserId != null) {
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/credits/analytics?start=%s&end=%s&tz=%s&page=%s&limit=%s&order=%s&type=%s", claudeCodeUserId, start, end, tz, page, limit, order, type);
|
|
|
|
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/credits/analytics?start=%s&end=%s&tz=%s&page=%s&limit=%s&order=%s&type=%s", claudeCodeUserId, start, end, tz, page, limit, order, type);
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
|
return claudeCodeResp;
|
|
return claudeCodeResp;
|
|
|
}
|
|
}
|
|
@@ -306,7 +300,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public void invalidateUserCache(Long userId) {
|
|
public void invalidateUserCache(Long userId) {
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/cache/invalidate/user/%s", userId);
|
|
|
|
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/cache/invalidate/user/%s", userId);
|
|
|
try {
|
|
try {
|
|
|
executeClaudeCodePostApi(url, null);
|
|
executeClaudeCodePostApi(url, null);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -331,6 +325,8 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
//清除用户套餐
|
|
//清除用户套餐
|
|
|
if (delUserPackages(claudeCodeUser.getUserId())) {
|
|
if (delUserPackages(claudeCodeUser.getUserId())) {
|
|
|
claudeCodeUserMapper.deleteById(claudeCodeUser.getId());
|
|
claudeCodeUserMapper.deleteById(claudeCodeUser.getId());
|
|
|
|
|
+ //codex
|
|
|
|
|
+ codexUserMapper.delete(Wrappers.lambdaQuery(CodexUser.class).eq(CodexUser::getRelationId, claudeCodeUser.getRelationId()).in(CodexUser::getUserId, userIdList));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return null;
|
|
return null;
|
|
@@ -359,13 +355,17 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
claudeCodeUser.setExpiryTime(groupsRelationView.getExpiryTime());
|
|
claudeCodeUser.setExpiryTime(groupsRelationView.getExpiryTime());
|
|
|
claudeCodeUserMapper.updateById(claudeCodeUser);
|
|
claudeCodeUserMapper.updateById(claudeCodeUser);
|
|
|
}
|
|
}
|
|
|
|
|
+ //续费升级
|
|
|
|
|
+ if (claudeCodeUser.getRenewSkuId() != null) {
|
|
|
|
|
+ sku = skuMapper.selectById(claudeCodeUser.getRenewSkuId());
|
|
|
|
|
+ }
|
|
|
if (sku == null) {
|
|
if (sku == null) {
|
|
|
sku = skuMapper.selectById(groupsRelationView.getSkuId());
|
|
sku = skuMapper.selectById(groupsRelationView.getSkuId());
|
|
|
}
|
|
}
|
|
|
//是否需要重试更新 cladueCode userInfo信息
|
|
//是否需要重试更新 cladueCode userInfo信息
|
|
|
if (claudeCodeUser.getIsRetry()) {
|
|
if (claudeCodeUser.getIsRetry()) {
|
|
|
try {
|
|
try {
|
|
|
- ClaudeCodeResp codeUserPackage = createOrUpdateClaudeCodeUserPackage(claudeCodeUser.getUserId(), claudeCodeUser.getPlanName(), claudeCodeUser.getCodePoints(), claudeCodeUser.getCodeCreditRecovery(), claudeCodeUser.getExpiryTime());
|
|
|
|
|
|
|
+ ClaudeCodeResp codeUserPackage = createOrUpdateClaudeCodeUserPackage(claudeCodeUser.getUserId(), claudeCodeUser.getPlanName(), claudeCodeUser.getCodePoints(), claudeCodeUser.getCodeCreditRecovery(), claudeCodeUser.getExpiryTime(), claudeCodeUser.getRelationId(), sku);
|
|
|
if (!Constant.SUCCESS.equals(codeUserPackage.getMessage())) {
|
|
if (!Constant.SUCCESS.equals(codeUserPackage.getMessage())) {
|
|
|
claudeCodeUser.setIsRetry(Boolean.TRUE);
|
|
claudeCodeUser.setIsRetry(Boolean.TRUE);
|
|
|
claudeCodeUserMapper.updateById(claudeCodeUser);
|
|
claudeCodeUserMapper.updateById(claudeCodeUser);
|
|
@@ -377,6 +377,25 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ CodexUser codexUser = codexUserMapper.selectOne(Wrappers.lambdaQuery(CodexUser.class).eq(CodexUser::getRelationId, claudeCodeUser.getRelationId()).in(CodexUser::getUserId, userIdList).last("limit 1"));
|
|
|
|
|
+ if (codexUser == null) {
|
|
|
|
|
+ //是否赠送codex
|
|
|
|
|
+ if (sku.getIsCodex()) {
|
|
|
|
|
+ CodexUserPackageReq codexPackageReq = CodexUserPackageReq.builder()
|
|
|
|
|
+ .userId(claudeCodeUser.getUserId())
|
|
|
|
|
+ .relationId(claudeCodeUser.getRelationId())
|
|
|
|
|
+ .planName(sku.getCodexPlanName())
|
|
|
|
|
+ .openaiDailyLimit(sku.getOpenaiDailyLimit())
|
|
|
|
|
+ .openaiQuota(sku.getOpenaiQuota())
|
|
|
|
|
+ .expiryTime(claudeCodeUser.getExpiryTime()).build();
|
|
|
|
|
+ codexService.createOrUpdateUserPackage(codexPackageReq);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ CodexUserInfoView codexUserInfoView = null;
|
|
|
|
|
+ if (codexUser != null) {
|
|
|
|
|
+ codexUserInfoView = CodexUserInfoView.builder().planName(codexUser.getPlanName()).openaiDailyLimit(codexUser.getOpenaiDailyLimit()).openaiQuota(codexUser.getOpenaiQuota()).relationId(codexUser.getRelationId()).build();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return ClaudeCodeUserInfoView.builder()
|
|
return ClaudeCodeUserInfoView.builder()
|
|
|
.planName(claudeCodeUser.getPlanName())
|
|
.planName(claudeCodeUser.getPlanName())
|
|
|
.relationId(claudeCodeUser.getRelationId())
|
|
.relationId(claudeCodeUser.getRelationId())
|
|
@@ -387,19 +406,41 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
.renewOrderId(claudeCodeUser.getRenewOrderId())
|
|
.renewOrderId(claudeCodeUser.getRenewOrderId())
|
|
|
.renewExpiryTime(claudeCodeUser.getRenewExpiryTime())
|
|
.renewExpiryTime(claudeCodeUser.getRenewExpiryTime())
|
|
|
.highestUsage(sku.getHighestUsage())
|
|
.highestUsage(sku.getHighestUsage())
|
|
|
|
|
+ .codexUserInfo(codexUserInfoView)
|
|
|
.build();
|
|
.build();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public ClaudeCodeResp createOrUpdateClaudeCodeUserPackage(Long userId, String planName, Integer codePoints, Integer codeCreditRecovery, Date expiryTime) throws Exception {
|
|
|
|
|
|
|
+ public ClaudeCodeResp createOrUpdateClaudeCodeUserPackage(Long userId, String planName, Integer codePoints, Integer codeCreditRecovery, Date expiryTime, Long relationId, GoodsDonSku sku) throws Exception {
|
|
|
Map<String, Object> parmas = new HashMap<>();
|
|
Map<String, Object> parmas = new HashMap<>();
|
|
|
parmas.put("plan_name", planName.replaceAll(";", ""));
|
|
parmas.put("plan_name", planName.replaceAll(";", ""));
|
|
|
parmas.put("credit_limit", codePoints);
|
|
parmas.put("credit_limit", codePoints);
|
|
|
parmas.put("credit_recovery", codeCreditRecovery);
|
|
parmas.put("credit_recovery", codeCreditRecovery);
|
|
|
- parmas.put("expire_time", DateUtil.format(expiryTime,"yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
- String planUrl = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/plan", userId);
|
|
|
|
|
|
|
+ if (sku.getIsCodex()) {
|
|
|
|
|
+ parmas.put("openai_daily_limit", sku.getOpenaiDailyLimit());
|
|
|
|
|
+ parmas.put("openai_quota", sku.getOpenaiQuota());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ parmas.put("openai_daily_limit", 0);
|
|
|
|
|
+ parmas.put("openai_quota", 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ parmas.put("expire_time", DateUtil.format(expiryTime, "yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
+ String planUrl = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/plan", userId);
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodePostApi(planUrl, Jsons.toJson(parmas));
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodePostApi(planUrl, Jsons.toJson(parmas));
|
|
|
if (!Constant.SUCCESS.equals(claudeCodeResp.getMessage())) {
|
|
if (!Constant.SUCCESS.equals(claudeCodeResp.getMessage())) {
|
|
|
log.info("用户claude code用户:{}套餐:{}创建或更新失败,info:{}", userId, planName, claudeCodeResp.getMessage());
|
|
log.info("用户claude code用户:{}套餐:{}创建或更新失败,info:{}", userId, planName, claudeCodeResp.getMessage());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //是否赠送codex
|
|
|
|
|
+ if (sku.getIsCodex()) {
|
|
|
|
|
+ CodexUserPackageReq codexPackageReq = CodexUserPackageReq.builder()
|
|
|
|
|
+ .userId(userId)
|
|
|
|
|
+ .relationId(relationId)
|
|
|
|
|
+ .planName(sku.getCodexPlanName())
|
|
|
|
|
+ .openaiDailyLimit(sku.getOpenaiDailyLimit())
|
|
|
|
|
+ .openaiQuota(sku.getOpenaiQuota())
|
|
|
|
|
+ .expiryTime(expiryTime).build();
|
|
|
|
|
+ codexService.createOrUpdateUserPackage(codexPackageReq);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ codexService.delCodexUser(userId, relationId);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return claudeCodeResp;
|
|
return claudeCodeResp;
|
|
|
}
|
|
}
|
|
@@ -418,9 +459,9 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void updateClaudeCodeUserPackageInfo(ClaudeCodeUser claudeCodeUser, Date expiryTime) {
|
|
|
|
|
|
|
+ public void updateClaudeCodeUserPackageInfo(ClaudeCodeUser claudeCodeUser, Date expiryTime, GoodsDonSku sku) {
|
|
|
try {
|
|
try {
|
|
|
- ClaudeCodeResp codeUserPackage = createOrUpdateClaudeCodeUserPackage(claudeCodeUser.getUserId(), claudeCodeUser.getPlanName(), claudeCodeUser.getCodePoints(), claudeCodeUser.getCodeCreditRecovery(), expiryTime);
|
|
|
|
|
|
|
+ ClaudeCodeResp codeUserPackage = createOrUpdateClaudeCodeUserPackage(claudeCodeUser.getUserId(), claudeCodeUser.getPlanName(), claudeCodeUser.getCodePoints(), claudeCodeUser.getCodeCreditRecovery(), expiryTime, claudeCodeUser.getRelationId(), sku);
|
|
|
if (!Constant.SUCCESS.equals(codeUserPackage.getMessage())) {
|
|
if (!Constant.SUCCESS.equals(codeUserPackage.getMessage())) {
|
|
|
//重试标记
|
|
//重试标记
|
|
|
claudeCodeUser.setIsRetry(Boolean.TRUE);
|
|
claudeCodeUser.setIsRetry(Boolean.TRUE);
|
|
@@ -437,7 +478,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public Boolean delUserPackages(Long userId) {
|
|
public Boolean delUserPackages(Long userId) {
|
|
|
- String url = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/plan", userId);
|
|
|
|
|
|
|
+ String url = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/plan", userId);
|
|
|
try {
|
|
try {
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeDeletedApi(url);
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeDeletedApi(url);
|
|
|
if (!Constant.SUCCESS.equals(claudeCodeResp.getMessage())) {
|
|
if (!Constant.SUCCESS.equals(claudeCodeResp.getMessage())) {
|
|
@@ -459,7 +500,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
@Override
|
|
@Override
|
|
|
public TimeRateConfigsResp getAllConfigs() {
|
|
public TimeRateConfigsResp getAllConfigs() {
|
|
|
try {
|
|
try {
|
|
|
- String url = CLAUDE_CODE_API_PREFIX + "api/time-multiplier/configs";
|
|
|
|
|
|
|
+ String url = Constant.CLAUDE_CODE_API_PREFIX + "api/time-multiplier/configs";
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodeGetApi(url);
|
|
|
return Jsons.parseObject(claudeCodeResp.getData(), TimeRateConfigsResp.class);
|
|
return Jsons.parseObject(claudeCodeResp.getData(), TimeRateConfigsResp.class);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -474,7 +515,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
throw BusinessRuntimeException.getInstance("用户ID无效");
|
|
throw BusinessRuntimeException.getInstance("用户ID无效");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String url = CLAUDE_CODE_API_PREFIX + "api/users/" + userId + "/credits/reset";
|
|
|
|
|
|
|
+ String url = Constant.CLAUDE_CODE_API_PREFIX + "api/users/" + userId + "/credits/reset";
|
|
|
String body = req != null ? Jsons.toJson(req) : "{}";
|
|
String body = req != null ? Jsons.toJson(req) : "{}";
|
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodePostApi(url, body);
|
|
ClaudeCodeResp claudeCodeResp = executeClaudeCodePostApi(url, body);
|
|
|
if (!Constant.SUCCESS.equals(claudeCodeResp.getMessage())) {
|
|
if (!Constant.SUCCESS.equals(claudeCodeResp.getMessage())) {
|
|
@@ -523,8 +564,8 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
return build.call(() -> {
|
|
return build.call(() -> {
|
|
|
try {
|
|
try {
|
|
|
HttpResponse execute = HttpUtil.createGet(url)
|
|
HttpResponse execute = HttpUtil.createGet(url)
|
|
|
- .header(CLAUDE_CODE_HEARD_KEY, CLAUDE_CODE_API_ADMIN_KEY)
|
|
|
|
|
- .setConnectionTimeout(CONNECT_MILLISECONDS)
|
|
|
|
|
|
|
+ .header(Constant.CLAUDE_CODE_HEARD_KEY, Constant.CLAUDE_CODE_API_ADMIN_KEY)
|
|
|
|
|
+ .setConnectionTimeout(Constant.CONNECT_MILLISECONDS)
|
|
|
.execute();
|
|
.execute();
|
|
|
ClaudeCodeResp resp = Jsons.parseObject(execute.body(), ClaudeCodeResp.class);
|
|
ClaudeCodeResp resp = Jsons.parseObject(execute.body(), ClaudeCodeResp.class);
|
|
|
if (!Constant.SUCCESS.equals(resp.getMessage())) {
|
|
if (!Constant.SUCCESS.equals(resp.getMessage())) {
|
|
@@ -551,8 +592,8 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
return build.call(() -> {
|
|
return build.call(() -> {
|
|
|
try {
|
|
try {
|
|
|
HttpResponse execute = HttpUtil.createPost(url)
|
|
HttpResponse execute = HttpUtil.createPost(url)
|
|
|
- .header(CLAUDE_CODE_HEARD_KEY, CLAUDE_CODE_API_ADMIN_KEY)
|
|
|
|
|
- .setConnectionTimeout(CONNECT_MILLISECONDS)
|
|
|
|
|
|
|
+ .header(Constant.CLAUDE_CODE_HEARD_KEY, Constant.CLAUDE_CODE_API_ADMIN_KEY)
|
|
|
|
|
+ .setConnectionTimeout(Constant.CONNECT_MILLISECONDS)
|
|
|
.body(body)
|
|
.body(body)
|
|
|
.execute();
|
|
.execute();
|
|
|
ClaudeCodeResp resp = Jsons.parseObject(execute.body(), ClaudeCodeResp.class);
|
|
ClaudeCodeResp resp = Jsons.parseObject(execute.body(), ClaudeCodeResp.class);
|
|
@@ -578,7 +619,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
try {
|
|
try {
|
|
|
return build.call(() -> {
|
|
return build.call(() -> {
|
|
|
try {
|
|
try {
|
|
|
- HttpResponse execute = HttpUtil.createRequest(Method.DELETE, url).header(CLAUDE_CODE_HEARD_KEY, CLAUDE_CODE_API_ADMIN_KEY).setConnectionTimeout(CONNECT_MILLISECONDS).execute();
|
|
|
|
|
|
|
+ HttpResponse execute = HttpUtil.createRequest(Method.DELETE, url).header(Constant.CLAUDE_CODE_HEARD_KEY, Constant.CLAUDE_CODE_API_ADMIN_KEY).setConnectionTimeout(Constant.CONNECT_MILLISECONDS).execute();
|
|
|
ClaudeCodeResp resp = Jsons.parseObject(execute.body(), ClaudeCodeResp.class);
|
|
ClaudeCodeResp resp = Jsons.parseObject(execute.body(), ClaudeCodeResp.class);
|
|
|
if (!Constant.SUCCESS.equals(resp.getMessage())) {
|
|
if (!Constant.SUCCESS.equals(resp.getMessage())) {
|
|
|
log.error("claude code DELETE URL:{}接口返回msg:{}", url, resp.getMessage());
|
|
log.error("claude code DELETE URL:{}接口返回msg:{}", url, resp.getMessage());
|
|
@@ -607,7 +648,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * claude code用户信息重试更新信息
|
|
|
|
|
|
|
+ * claude code、codex user用户信息重试更新信息
|
|
|
*/
|
|
*/
|
|
|
public void setClaudeCodeUserRetryUpdateInfo(Long relationId) {
|
|
public void setClaudeCodeUserRetryUpdateInfo(Long relationId) {
|
|
|
ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).eq(ClaudeCodeUser::getRelationId, relationId).last("limit 1"));
|
|
ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).eq(ClaudeCodeUser::getRelationId, relationId).last("limit 1"));
|
|
@@ -615,6 +656,12 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
claudeCodeUser.setIsRetry(Boolean.TRUE);
|
|
claudeCodeUser.setIsRetry(Boolean.TRUE);
|
|
|
claudeCodeUserMapper.updateById(claudeCodeUser);
|
|
claudeCodeUserMapper.updateById(claudeCodeUser);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ CodexUser codexUser = codexUserMapper.selectOne(Wrappers.lambdaQuery(CodexUser.class).eq(CodexUser::getRelationId, relationId).last("limit 1"));
|
|
|
|
|
+ if (codexUser != null) {
|
|
|
|
|
+ codexUser.setIsRetry(Boolean.TRUE);
|
|
|
|
|
+ codexUserMapper.updateById(codexUser);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public Retryer getApiRetryer(Integer sleepSecond, Integer attemptNum) {
|
|
public Retryer getApiRetryer(Integer sleepSecond, Integer attemptNum) {
|
|
@@ -1033,7 +1080,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void adjClaudeCodeUserPoints(Long userId, Integer points, String type, String description) throws Exception {
|
|
private void adjClaudeCodeUserPoints(Long userId, Integer points, String type, String description) throws Exception {
|
|
|
- String apiKeyUrl = String.format(CLAUDE_CODE_API_PREFIX + "api/users/%s/credits/adjust", userId);
|
|
|
|
|
|
|
+ String apiKeyUrl = String.format(Constant.CLAUDE_CODE_API_PREFIX + "api/users/%s/credits/adjust", userId);
|
|
|
Map<String, Object> parmas = new HashMap<>();
|
|
Map<String, Object> parmas = new HashMap<>();
|
|
|
parmas.put("amount", points);
|
|
parmas.put("amount", points);
|
|
|
parmas.put("type", type);
|
|
parmas.put("type", type);
|