Implementation:A616567126 GPT WEB JAVA CheckService
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Access_Control, Billing |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Concrete tool for validating user credits and deducting usage costs before AI service execution, provided by the Spring framework.
Description
The CheckService class provides three credit validation methods:
checkUser(MessageLog, Long id)— Deducts credits, persists a MessageLog record, returns the log ID. Used by GPT chat and SD generation.checkUser(Long userId, Integer number)— Deducts a fixed number of credits. Used by MJ task submission.checkWxUser(Long userId, Integer number)— Returns boolean instead of throwing. Used by WeChat bot.
All methods bypass credit checks for admin users (type == -1). The service is @Transactional to ensure atomicity of the check-and-deduct operation.
Usage
Import this service when you need to:
- Validate and deduct credits before AI service calls
- Persist MessageLog records for GPT and SD usage tracking
- Return boolean credit status for WeChat bot flows
Code Reference
Source Location
- Repository: GPT-WEB-JAVA
- File: src/main/java/com/intelligent/bot/service/sys/CheckService.java
Signature
@Service("CheckService")
@Transactional(rollbackFor = E.class)
public class CheckService {
public Long checkUser(MessageLog messageLog, Long id);
public void checkUser(Long userId, Integer number);
public boolean checkWxUser(Long userId, Integer number);
}
Import
import com.intelligent.bot.service.sys.CheckService;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| messageLog | MessageLog | Yes (v1) | userId, useNumber, sendType, useValue, gptKey |
| id | Long | No (v1) | Existing logId for conversation continuation |
| userId | Long | Yes (v2,v3) | User ID |
| number | Integer | Yes (v2,v3) | Credits to deduct |
Outputs
| Name | Type | Description |
|---|---|---|
| checkUser (v1) returns | Long | MessageLog ID (new or updated) |
| checkUser (v2) returns | void | Throws E if insufficient credits |
| checkWxUser returns | boolean | True if credits deducted, false if insufficient |
Usage Examples
GPT Chat Credit Check
Long logId = checkService.checkUser(MessageLog.builder()
.useNumber(CommonConst.GPT_NUMBER)
.sendType(SendType.GPT.getType())
.useValue(JSONObject.toJSONString(messages))
.gptKey(gptKey)
.userId(JwtUtil.getUserId())
.build(), req.getLogId());
MJ Credit Check
checkService.checkUser(JwtUtil.getUserId(), CommonConst.MJ_NUMBER);
// Throws E("剩余次数不足请充值") if insufficient
WeChat Bot Credit Check
boolean ok = checkService.checkWxUser(user.getId(), CommonConst.MJ_NUMBER);
if (ok) {
// Submit MJ task
} else {
return "❗️余额不足,请充值";
}
Related Pages
Implements Principle
Requires Environment
- Environment:A616567126_GPT_WEB_JAVA_Spring_Boot_Runtime
- Environment:A616567126_GPT_WEB_JAVA_MySQL_Database
Uses Heuristic
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment