|
@@ -10,8 +10,11 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
import com.cyksj.common.util.Jsons;
|
|
|
|
|
+import com.cyksj.common.util.StringUtil;
|
|
|
|
|
+import com.cyksj.mapper.ClaudeCodeUserMapper;
|
|
|
import com.cyksj.mapper.ClaudeCodeUserRenewExpiryRecordMapper;
|
|
import com.cyksj.mapper.ClaudeCodeUserRenewExpiryRecordMapper;
|
|
|
import com.cyksj.mapper.GroupsRelationMapper;
|
|
import com.cyksj.mapper.GroupsRelationMapper;
|
|
|
|
|
+import com.cyksj.model.entity.ClaudeCodeUser;
|
|
|
import com.cyksj.model.entity.ClaudeCodeUserRenewExpiryRecord;
|
|
import com.cyksj.model.entity.ClaudeCodeUserRenewExpiryRecord;
|
|
|
import com.cyksj.model.entity.GoodsDonSku;
|
|
import com.cyksj.model.entity.GoodsDonSku;
|
|
|
import com.cyksj.model.entity.GroupsRelation;
|
|
import com.cyksj.model.entity.GroupsRelation;
|
|
@@ -22,7 +25,9 @@ import com.cyksj.model.request.ClaudeCodeDelReq;
|
|
|
import com.cyksj.model.response.ClaudeCodePointsHistoryResp;
|
|
import com.cyksj.model.response.ClaudeCodePointsHistoryResp;
|
|
|
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.ClaudeCodeUserApiKeysView;
|
|
|
|
|
+import com.cyksj.model.views.ClaudeCodeUserInfoView;
|
|
|
import com.cyksj.model.views.ClaudeCodeUserPackageView;
|
|
import com.cyksj.model.views.ClaudeCodeUserPackageView;
|
|
|
|
|
+import com.cyksj.model.views.RenewalView;
|
|
|
import com.cyksj.service.claude.ClaudeCodeService;
|
|
import com.cyksj.service.claude.ClaudeCodeService;
|
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
import com.cyksj.service.user.UserBindRelationService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
@@ -30,6 +35,7 @@ import com.ejlchina.searcher.param.Operator;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
@@ -55,6 +61,8 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
|
|
|
|
|
private final ClaudeCodeUserRenewExpiryRecordMapper claudeCodeUserRenewExpiryRecordMapper;
|
|
private final ClaudeCodeUserRenewExpiryRecordMapper claudeCodeUserRenewExpiryRecordMapper;
|
|
|
|
|
|
|
|
|
|
+ private final ClaudeCodeUserMapper claudeCodeUserMapper;
|
|
|
|
|
+
|
|
|
private final static String CLAUDE_CODE_API_PREFIX = "https://relay01.yhlxj.com/";
|
|
private final static String CLAUDE_CODE_API_PREFIX = "https://relay01.yhlxj.com/";
|
|
|
|
|
|
|
|
public static final String CLAUDE_CODE_API_ADMIN_KEY = "claudecodeyhlxjclaude";
|
|
public static final String CLAUDE_CODE_API_ADMIN_KEY = "claudecodeyhlxjclaude";
|
|
@@ -72,22 +80,50 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
Long skuId = sku.getId();
|
|
Long skuId = sku.getId();
|
|
|
//生成claude code用户套餐
|
|
//生成claude code用户套餐
|
|
|
try {
|
|
try {
|
|
|
- createOrUpdateClaudeCodeUserPackage(relation.getUserId(), sku.getSpecVal(), codePoints, codeCreditRecovery, expiryTime);
|
|
|
|
|
- //设置车位的套餐
|
|
|
|
|
- relation.setCodePoints(codePoints);
|
|
|
|
|
- relation.setCodeCreditRecovery(codeCreditRecovery);
|
|
|
|
|
- relation.setCodeSkuId(skuId);
|
|
|
|
|
- relationMapper.updateById(relation);
|
|
|
|
|
- if (orderType == 2) {
|
|
|
|
|
- invalidateUserCache(relationUserId);
|
|
|
|
|
- //若是续费升级 记录此时续费升级的过期时间
|
|
|
|
|
- if (relationCodePoints != null && relationCodePoints <= codePoints && !ObjectUtil.equal(relationCodeSkuId, skuId)) {
|
|
|
|
|
- saveClaudeCodeRenewExpiryRecord(orderId, relationUserId, relationId, expiryTime, skuId);
|
|
|
|
|
|
|
+ Boolean isUpgrade = false;
|
|
|
|
|
+ //若是续费升级 记录此时续费升级的过期时间
|
|
|
|
|
+ if (relationCodePoints != null && relationCodePoints <= codePoints && !ObjectUtil.equal(relationCodeSkuId, skuId)) {
|
|
|
|
|
+ saveClaudeCodeRenewExpiryRecord(orderId, relationUserId, relationId, expiryTime, skuId);
|
|
|
|
|
+ isUpgrade = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ ClaudeCodeResp codeUserPackage = createOrUpdateClaudeCodeUserPackage(relation.getUserId(), sku.getSpecVal(), codePoints, codeCreditRecovery, expiryTime);
|
|
|
|
|
+ if (codeUserPackage.getSuccess()) {
|
|
|
|
|
+ //设置车位的套餐
|
|
|
|
|
+ relation.setCodePoints(codePoints);
|
|
|
|
|
+ relation.setCodeCreditRecovery(codeCreditRecovery);
|
|
|
|
|
+ relation.setCodeSkuId(skuId);
|
|
|
|
|
+ relationMapper.updateById(relation);
|
|
|
|
|
+ if (orderType == 2) {
|
|
|
|
|
+ invalidateUserCache(relationUserId);
|
|
|
}
|
|
}
|
|
|
|
|
+ generateOrUpdateClaudeCodeUser(relationUserId, relationId, codePoints, codeCreditRecovery, expiryTime, isUpgrade, skuId);
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
|
|
+ log.error("生成或更新claude code用户:{}套餐skuId:{} 失败,error_info:{}", userId, skuId, StringUtil.getErrorText(e));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ private void generateOrUpdateClaudeCodeUser(Long relationUserId, Long relationId, Integer codePoints, Integer codeCreditRecovery, Date expiryTime, Boolean isUpgrade, Long renewSkuId) {
|
|
|
|
|
+ ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).eq(ClaudeCodeUser::getRelationId, relationId).last("limit 1"));
|
|
|
|
|
+ if (claudeCodeUser == null) {
|
|
|
|
|
+ claudeCodeUser = new ClaudeCodeUser();
|
|
|
|
|
+ claudeCodeUser.setUserId(relationUserId);
|
|
|
|
|
+ claudeCodeUser.setRelationId(relationId);
|
|
|
|
|
+ claudeCodeUser.setExpiryTime(expiryTime);
|
|
|
|
|
+ claudeCodeUser.setCodePoints(codePoints);
|
|
|
|
|
+ claudeCodeUser.setCodeCreditRecovery(codeCreditRecovery);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isUpgrade) {
|
|
|
|
|
+ claudeCodeUser.setRenewSkuId(renewSkuId);
|
|
|
|
|
+ claudeCodeUser.setRenewExpiryTime(expiryTime);
|
|
|
}
|
|
}
|
|
|
|
|
+ if (claudeCodeUser.getId() == null) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ claudeCodeUserMapper.insert(claudeCodeUser);
|
|
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
|
|
+ log.info("插入claude code user 重复");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else claudeCodeUserMapper.updateById(claudeCodeUser);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -259,7 +295,45 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
executeClaudeCodeGetApi(url);
|
|
executeClaudeCodeGetApi(url);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void createOrUpdateClaudeCodeUserPackage(Long userId, String planName, Integer codePoints, Integer codeCreditRecovery, Date expiryTime) throws Exception {
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public ClaudeCodeUserInfoView getClaudeCodeUserSubsInfo(Long userId) {
|
|
|
|
|
+ List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
|
|
|
|
|
+ //是否有该车票
|
|
|
|
|
+ GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
|
|
|
|
|
+ .field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
|
|
|
|
|
+ .field(GroupsRelationView::getGoodsId, Constant.CLAUDE_CODE_GOODS_ID)
|
|
|
|
|
+ .field(GroupsRelationView::getExpiryTime, DateTime.now())
|
|
|
|
|
+ .build());
|
|
|
|
|
+ if (groupsRelationView == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ ClaudeCodeUser claudeCodeUser = claudeCodeUserMapper.selectOne(Wrappers.lambdaQuery(ClaudeCodeUser.class).in(ClaudeCodeUser::getUserId, userIdList).last("limit 1"));
|
|
|
|
|
+ if (claudeCodeUser == null) {
|
|
|
|
|
+ if (groupsRelationView != null) {
|
|
|
|
|
+ claudeCodeUser = new ClaudeCodeUser();
|
|
|
|
|
+ claudeCodeUser.setCodePoints(groupsRelationView.getCodePoints());
|
|
|
|
|
+ claudeCodeUser.setCodeCreditRecovery(groupsRelationView.getCodeCreditRecovery());
|
|
|
|
|
+ claudeCodeUser.setRelationId(groupsRelationView.getId());
|
|
|
|
|
+ claudeCodeUser.setUserId(groupsRelationView.getUserId());
|
|
|
|
|
+ claudeCodeUser.setRenewSkuId(groupsRelationView.getCodeSkuId());
|
|
|
|
|
+ claudeCodeUser.setExpiryTime(groupsRelationView.getExpiryTime());
|
|
|
|
|
+ claudeCodeUser.setRenewExpiryTime(groupsRelationView.getExpiryTime());
|
|
|
|
|
+ claudeCodeUserMapper.insert(claudeCodeUser);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Integer codePoints = claudeCodeUser.getCodePoints();
|
|
|
|
|
+ Integer relationViewCodePoints = groupsRelationView.getCodePoints();
|
|
|
|
|
+ if (codePoints < relationViewCodePoints) {
|
|
|
|
|
+ claudeCodeUser.setCodePoints(relationViewCodePoints);
|
|
|
|
|
+ claudeCodeUser.setCodeCreditRecovery(groupsRelationView.getCodeCreditRecovery());
|
|
|
|
|
+ claudeCodeUser.setRenewExpiryTime(groupsRelationView.getExpiryTime());
|
|
|
|
|
+ claudeCodeUser.setRenewSkuId(groupsRelationView.getSkuId());
|
|
|
|
|
+ }
|
|
|
|
|
+ claudeCodeUser.setExpiryTime(groupsRelationView.getExpiryTime());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public ClaudeCodeResp createOrUpdateClaudeCodeUserPackage(Long userId, String planName, Integer codePoints, Integer codeCreditRecovery, Date expiryTime) 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);
|
|
@@ -271,6 +345,7 @@ public class ClaudeCodeServiceImpl implements ClaudeCodeService {
|
|
|
if (claudeCodeResp.getSuccess()) {
|
|
if (claudeCodeResp.getSuccess()) {
|
|
|
log.info("用户claude code用户:{}套餐:{}创建或更新成功", userId, planName);
|
|
log.info("用户claude code用户:{}套餐:{}创建或更新成功", userId, planName);
|
|
|
}
|
|
}
|
|
|
|
|
+ return claudeCodeResp;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|