Implementation:A616567126 GPT WEB JAVA AsyncService
Appearance
| 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 DBupdateKeyState(key)— Disables a GPT key (currently commented out)endOfAnswer(logId, value)— Appends assistant response to MessageLog conversationupdateRemainingTimes(userId, number)— Refunds credits (used on error/timeout)updateLog(logId, messageLogSave)— Updates message log with completion datasendMjWxMessage(mjTask)— Delivers MJ result to WeChat via kefu messagedeleteImages(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
- Principle:A616567126_GPT_WEB_JAVA_Async_Notification
- Principle:A616567126_GPT_WEB_JAVA_WeChat_Official_Account
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment