Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A616567126 GPT WEB JAVA AsyncService

From Leeroopedia
Knowledge Sources
Domains Async_Processing, Billing, WeChat_Integration
Last Updated 2026-10-13 00:00 GMT

Overview

Concrete tool for asynchronous background operations including key usage tracking, conversation persistence, credit refunds, and WeChat kefu message delivery, provided by the Spring Async framework.

Description

The AsyncService class provides @Async methods for non-blocking background tasks:

  • updateKeyNumber(key) — Increments GPT key usage count in DB
  • updateKeyState(key) — Disables a GPT key (currently commented out)
  • endOfAnswer(logId, value) — Appends assistant response to MessageLog conversation
  • updateRemainingTimes(userId, number) — Refunds credits (used on error/timeout)
  • updateLog(logId, messageLogSave) — Updates message log with completion data
  • sendMjWxMessage(mjTask) — Delivers MJ result to WeChat via kefu message
  • deleteImages(images) — Cleans up local image files

Usage

Import this service when you need to:

  • Persist GPT conversation results asynchronously
  • Track GPT key usage without blocking the request
  • Refund user credits on errors or timeouts
  • Deliver MJ task results to WeChat users via kefu messages

Code Reference

Source Location

  • Repository: GPT-WEB-JAVA
  • File: src/main/java/com/intelligent/bot/service/sys/AsyncService.java

Signature

@Component
public class AsyncService {
    @Async public void updateKeyNumber(String key);
    @Async public void updateKeyState(String key);
    @Async public void endOfAnswer(Long logId, String value);
    @Async public void updateRemainingTimes(Long userId, Integer number);
    @Async public void updateLog(Long logId, MessageLogSave messageLogSave);
    @Async public void sendMjWxMessage(Task mjTask) throws WxErrorException;
    @Async public void deleteImages(List<String> images);
    @Async public void deleteFile(File file);
    public void sparkChat(SparkDeskClient client, AIChatRequest req, Long logId, AtomicLong atomicLong);
}

Import

import com.intelligent.bot.service.sys.AsyncService;

I/O Contract

Inputs

Name Type Required Description
logId Long Yes (endOfAnswer) Conversation log ID
value String Yes (endOfAnswer) Accumulated assistant response
userId Long Yes (updateRemainingTimes) User ID for credit refund
number Integer Yes (updateRemainingTimes) Credits to refund
mjTask Task Yes (sendMjWxMessage) Completed MJ task with imageUrl, prompt, userId

Outputs

Name Type Description
endOfAnswer void MessageLog.useValue updated with assistant response appended
updateRemainingTimes void User.remaining_times incremented in DB
sendMjWxMessage void Image + text sent as WeChat kefu messages

Usage Examples

Persisting Conversation

// Called on stream completion
asyncService.endOfAnswer(logId, accumulatedResponse);
// Appends assistant message to existing conversation in MessageLog

Refunding Credits on Error

// In ConsoleStreamListener.onError()
asyncService.updateKeyState(messageLog.getGptKey());
asyncService.updateRemainingTimes(userId, messageLog.getUseNumber());
// Key disabled, credits returned to user

WeChat Kefu Message Delivery

// In NotifyServiceImpl.postJson() for subType==2
asyncService.sendMjWxMessage(mjTask);
// Uploads image as WeChat media, sends IMAGE + TEXT kefu messages
// Text includes prompt, translation, and upscale/variation command links

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment