|
|
@@ -153,7 +153,7 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
|
|
|
.execute();
|
|
|
String body = response.body();
|
|
|
log.info("任务查询响应: {}", body);
|
|
|
-
|
|
|
+
|
|
|
JSONObject jsonResponse = JSONUtil.parseObj(body);
|
|
|
TaskResult result = new TaskResult(
|
|
|
jsonResponse.getStr("status"),
|
|
|
@@ -161,15 +161,8 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
|
|
|
);
|
|
|
log.info("任务查询结果: {}", result);
|
|
|
String status = result.getStatus();
|
|
|
- if ("success".equals(status)) {
|
|
|
- GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
- .eq(GroupsRelation::getGptTaskId, taskId)
|
|
|
- .last("limit 1"));
|
|
|
- if (relation != null) {
|
|
|
- relation.setRechargeStatus(GroupsRelation.RechargeStatus.complete);
|
|
|
- relationMapper.updateById(relation);
|
|
|
- }
|
|
|
- }
|
|
|
+ //更新代充状态
|
|
|
+ resetGroupsRelationRechargeStatus(taskId, status);
|
|
|
return result;
|
|
|
} catch (Exception e) {
|
|
|
log.error("获取任务结果失败: {}", e.getMessage(), e);
|
|
|
@@ -200,6 +193,9 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
|
|
|
if (rechargeRemainNum == null || rechargeRemainNum <= 0) {
|
|
|
throw BusinessRuntimeException.getInstance("剩余可代充次数为0");
|
|
|
}
|
|
|
+ if (relation.getRechargeStatus() == GroupsRelation.RechargeStatus.auto_recharge) {
|
|
|
+ throw BusinessRuntimeException.getInstance("自动充值中");
|
|
|
+ }
|
|
|
int updateRemainNum = relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
.set(GroupsRelation::getRechargeRemainNum, rechargeRemainNum - 1)
|
|
|
.eq(GroupsRelation::getId, relationId)
|
|
|
@@ -269,4 +265,38 @@ public class GptProxyRechargeServiceImpl implements GptProxyRechargeService {
|
|
|
relationMapper.updateById(relation);
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新代充状态
|
|
|
+ */
|
|
|
+ private void resetGroupsRelationRechargeStatus(String taskId, String status) {
|
|
|
+ if ("completed".equals(status) || !"processing".equals(status)) {
|
|
|
+ GroupsRelation relation = relationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
+ .eq(GroupsRelation::getGptTaskId, taskId)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (relation != null && relation.getRechargeStatus() == GroupsRelation.RechargeStatus.auto_recharge) {
|
|
|
+ Integer rechargeRemainNum = relation.getRechargeRemainNum();
|
|
|
+ GroupsRelation.RechargeStatus rechargeStatus = "completed".equals(status) ? GroupsRelation.RechargeStatus.complete : GroupsRelation.RechargeStatus.auto_error;
|
|
|
+ if (rechargeStatus == GroupsRelation.RechargeStatus.auto_error) {
|
|
|
+ String cardKey = relation.getCardKey();
|
|
|
+ GptRechargeCardKey gptRechargeCardKey = gptRechargeCardKeyMapper.selectOne(Wrappers.lambdaQuery(GptRechargeCardKey.class)
|
|
|
+ .eq(GptRechargeCardKey::getCardKey, cardKey)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (gptRechargeCardKey != null) {
|
|
|
+ gptRechargeCardKeyMapper.update(null, Wrappers.lambdaUpdate(GptRechargeCardKey.class)
|
|
|
+ .set(GptRechargeCardKey::getStatus, Boolean.FALSE)
|
|
|
+ .set(GptRechargeCardKey::getOrderId, null)
|
|
|
+ .set(GptRechargeCardKey::getOrderNo, null)
|
|
|
+ .eq(GptRechargeCardKey::getId, gptRechargeCardKey.getId())
|
|
|
+ .eq(GptRechargeCardKey::getStatus, Boolean.TRUE));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ relationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
+ .set(rechargeStatus == GroupsRelation.RechargeStatus.auto_error, GroupsRelation::getRechargeRemainNum, rechargeRemainNum + 1)
|
|
|
+ .set(GroupsRelation::getRechargeStatus, rechargeStatus)
|
|
|
+ .eq(GroupsRelation::getId, relation.getId())
|
|
|
+ .eq(GroupsRelation::getRechargeStatus, GroupsRelation.RechargeStatus.auto_recharge));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|