Add async AI generation tasks

This commit is contained in:
王鹏
2026-05-24 13:55:14 +08:00
parent 6682a44a43
commit bb7291f7d1
29 changed files with 2304 additions and 30 deletions

View File

@@ -1261,6 +1261,9 @@ insert into sys_project_structure (node_id, parent_id, node_name, node_type, mod
-- =================================================
drop table if exists front_project_file;
drop table if exists front_ai_usage_ledger;
drop table if exists front_ai_generation_task;
drop table if exists front_ai_quota_bucket;
drop table if exists front_project_generation;
drop table if exists front_project_column;
drop table if exists front_project_table;
@@ -1383,6 +1386,82 @@ create table front_project_generation (
key idx_front_project_generation_project_id (project_id)
) engine=innodb auto_increment=100 default charset=utf8mb4 comment='前台项目生成记录';
create table front_ai_generation_task (
task_id bigint(20) not null auto_increment comment 'AI task ID',
generation_id bigint(20) default null comment 'Generation record ID',
project_id bigint(20) not null comment 'Project ID',
user_id bigint(20) not null comment 'Front user ID',
generate_type varchar(50) not null comment 'Generation type',
provider varchar(50) default 'deepseek' comment 'AI provider',
model varchar(100) default 'deepseek-chat' comment 'AI model',
status varchar(30) not null default 'QUEUED' comment 'Task status',
request_hash varchar(64) not null comment 'Request idempotency hash',
request_payload longtext comment 'Request JSON',
result_payload longtext comment 'Result JSON',
error_code varchar(100) default '' comment 'Error code',
error_message varchar(1000) default '' comment 'Error message',
attempts int default 0 comment 'Attempt count',
max_attempts int default 3 comment 'Max attempts',
next_retry_time datetime default null comment 'Next retry time',
locked_by varchar(100) default '' comment 'Worker lock owner',
locked_until datetime default null comment 'Worker lock expiry',
progress int default 0 comment 'Progress percent',
current_step varchar(100) default '' comment 'Current step',
input_tokens int default 0 comment 'Input tokens',
output_tokens int default 0 comment 'Output tokens',
total_tokens int default 0 comment 'Total tokens',
cost_cents int default 0 comment 'Estimated cost in cents',
started_at datetime default null comment 'Started time',
finished_at datetime default null comment 'Finished time',
create_time datetime default null comment 'Create time',
update_time datetime default null comment 'Update time',
primary key (task_id),
key idx_front_ai_task_project (user_id, project_id),
key idx_front_ai_task_status (status, next_retry_time),
key idx_front_ai_task_generation (generation_id),
key idx_front_ai_task_hash (user_id, project_id, request_hash)
) engine=innodb auto_increment=100 default charset=utf8mb4 comment='Front AI generation task';
create table front_ai_quota_bucket (
bucket_id bigint(20) not null auto_increment comment 'Quota bucket ID',
user_id bigint(20) not null comment 'Front user ID',
period_type varchar(20) not null comment 'DAY or MONTH',
period_key varchar(20) not null comment 'Period key',
task_limit int default 0 comment 'Task limit',
task_used int default 0 comment 'Used tasks',
token_limit int default 0 comment 'Token limit',
token_used int default 0 comment 'Used tokens',
cost_limit_cents int default 0 comment 'Cost limit in cents',
cost_used_cents int default 0 comment 'Used cost in cents',
running_limit int default 1 comment 'Running task limit',
running_count int default 0 comment 'Running task count',
create_time datetime default null comment 'Create time',
update_time datetime default null comment 'Update time',
primary key (bucket_id),
unique key uk_front_ai_quota_bucket (user_id, period_type, period_key)
) engine=innodb auto_increment=100 default charset=utf8mb4 comment='Front AI quota bucket';
create table front_ai_usage_ledger (
ledger_id bigint(20) not null auto_increment comment 'Usage ledger ID',
task_id bigint(20) default null comment 'Task ID',
generation_id bigint(20) default null comment 'Generation record ID',
project_id bigint(20) not null comment 'Project ID',
user_id bigint(20) not null comment 'Front user ID',
generate_type varchar(50) not null comment 'Generation type',
provider varchar(50) default 'deepseek' comment 'AI provider',
model varchar(100) default 'deepseek-chat' comment 'AI model',
input_tokens int default 0 comment 'Input tokens',
output_tokens int default 0 comment 'Output tokens',
total_tokens int default 0 comment 'Total tokens',
cost_cents int default 0 comment 'Estimated cost in cents',
success char(1) default '0' comment 'Success flag',
error_message varchar(1000) default '' comment 'Error message',
create_time datetime default null comment 'Create time',
primary key (ledger_id),
key idx_front_ai_usage_user (user_id, create_time),
key idx_front_ai_usage_task (task_id)
) engine=innodb auto_increment=100 default charset=utf8mb4 comment='Front AI usage ledger';
create table front_project_file (
file_id bigint(20) not null auto_increment comment '文件缓存ID',
project_id bigint(20) not null comment '项目ID',

View File

@@ -0,0 +1,77 @@
-- EasyCode front AI task center incremental upgrade
create table if not exists front_ai_generation_task (
task_id bigint(20) not null auto_increment comment 'AI task ID',
generation_id bigint(20) default null comment 'Generation record ID',
project_id bigint(20) not null comment 'Project ID',
user_id bigint(20) not null comment 'Front user ID',
generate_type varchar(50) not null comment 'Generation type',
provider varchar(50) default 'deepseek' comment 'AI provider',
model varchar(100) default 'deepseek-chat' comment 'AI model',
status varchar(30) not null default 'QUEUED' comment 'Task status',
request_hash varchar(64) not null comment 'Request idempotency hash',
request_payload longtext comment 'Request JSON',
result_payload longtext comment 'Result JSON',
error_code varchar(100) default '' comment 'Error code',
error_message varchar(1000) default '' comment 'Error message',
attempts int default 0 comment 'Attempt count',
max_attempts int default 3 comment 'Max attempts',
next_retry_time datetime default null comment 'Next retry time',
locked_by varchar(100) default '' comment 'Worker lock owner',
locked_until datetime default null comment 'Worker lock expiry',
progress int default 0 comment 'Progress percent',
current_step varchar(100) default '' comment 'Current step',
input_tokens int default 0 comment 'Input tokens',
output_tokens int default 0 comment 'Output tokens',
total_tokens int default 0 comment 'Total tokens',
cost_cents int default 0 comment 'Estimated cost in cents',
started_at datetime default null comment 'Started time',
finished_at datetime default null comment 'Finished time',
create_time datetime default null comment 'Create time',
update_time datetime default null comment 'Update time',
primary key (task_id),
key idx_front_ai_task_project (user_id, project_id),
key idx_front_ai_task_status (status, next_retry_time),
key idx_front_ai_task_generation (generation_id),
key idx_front_ai_task_hash (user_id, project_id, request_hash)
) engine=innodb auto_increment=100 default charset=utf8mb4 comment='Front AI generation task';
create table if not exists front_ai_quota_bucket (
bucket_id bigint(20) not null auto_increment comment 'Quota bucket ID',
user_id bigint(20) not null comment 'Front user ID',
period_type varchar(20) not null comment 'DAY or MONTH',
period_key varchar(20) not null comment 'Period key',
task_limit int default 0 comment 'Task limit',
task_used int default 0 comment 'Used tasks',
token_limit int default 0 comment 'Token limit',
token_used int default 0 comment 'Used tokens',
cost_limit_cents int default 0 comment 'Cost limit in cents',
cost_used_cents int default 0 comment 'Used cost in cents',
running_limit int default 1 comment 'Running task limit',
running_count int default 0 comment 'Running task count',
create_time datetime default null comment 'Create time',
update_time datetime default null comment 'Update time',
primary key (bucket_id),
unique key uk_front_ai_quota_bucket (user_id, period_type, period_key)
) engine=innodb auto_increment=100 default charset=utf8mb4 comment='Front AI quota bucket';
create table if not exists front_ai_usage_ledger (
ledger_id bigint(20) not null auto_increment comment 'Usage ledger ID',
task_id bigint(20) default null comment 'Task ID',
generation_id bigint(20) default null comment 'Generation record ID',
project_id bigint(20) not null comment 'Project ID',
user_id bigint(20) not null comment 'Front user ID',
generate_type varchar(50) not null comment 'Generation type',
provider varchar(50) default 'deepseek' comment 'AI provider',
model varchar(100) default 'deepseek-chat' comment 'AI model',
input_tokens int default 0 comment 'Input tokens',
output_tokens int default 0 comment 'Output tokens',
total_tokens int default 0 comment 'Total tokens',
cost_cents int default 0 comment 'Estimated cost in cents',
success char(1) default '0' comment 'Success flag',
error_message varchar(1000) default '' comment 'Error message',
create_time datetime default null comment 'Create time',
primary key (ledger_id),
key idx_front_ai_usage_user (user_id, create_time),
key idx_front_ai_usage_task (task_id)
) engine=innodb auto_increment=100 default charset=utf8mb4 comment='Front AI usage ledger';

View File

@@ -4,6 +4,9 @@
-- =================================================
drop table if exists front_project_file;
drop table if exists front_ai_usage_ledger;
drop table if exists front_ai_generation_task;
drop table if exists front_ai_quota_bucket;
drop table if exists front_project_generation;
drop table if exists front_project_column;
drop table if exists front_project_table;
@@ -144,6 +147,82 @@ create table front_project_generation (
key idx_front_project_generation_project_id (project_id)
) engine=innodb auto_increment=100 default charset=utf8mb4 comment='前台项目生成记录';
create table front_ai_generation_task (
task_id bigint(20) not null auto_increment comment 'AI task ID',
generation_id bigint(20) default null comment 'Generation record ID',
project_id bigint(20) not null comment 'Project ID',
user_id bigint(20) not null comment 'Front user ID',
generate_type varchar(50) not null comment 'Generation type',
provider varchar(50) default 'deepseek' comment 'AI provider',
model varchar(100) default 'deepseek-chat' comment 'AI model',
status varchar(30) not null default 'QUEUED' comment 'Task status',
request_hash varchar(64) not null comment 'Request idempotency hash',
request_payload longtext comment 'Request JSON',
result_payload longtext comment 'Result JSON',
error_code varchar(100) default '' comment 'Error code',
error_message varchar(1000) default '' comment 'Error message',
attempts int default 0 comment 'Attempt count',
max_attempts int default 3 comment 'Max attempts',
next_retry_time datetime default null comment 'Next retry time',
locked_by varchar(100) default '' comment 'Worker lock owner',
locked_until datetime default null comment 'Worker lock expiry',
progress int default 0 comment 'Progress percent',
current_step varchar(100) default '' comment 'Current step',
input_tokens int default 0 comment 'Input tokens',
output_tokens int default 0 comment 'Output tokens',
total_tokens int default 0 comment 'Total tokens',
cost_cents int default 0 comment 'Estimated cost in cents',
started_at datetime default null comment 'Started time',
finished_at datetime default null comment 'Finished time',
create_time datetime default null comment 'Create time',
update_time datetime default null comment 'Update time',
primary key (task_id),
key idx_front_ai_task_project (user_id, project_id),
key idx_front_ai_task_status (status, next_retry_time),
key idx_front_ai_task_generation (generation_id),
key idx_front_ai_task_hash (user_id, project_id, request_hash)
) engine=innodb auto_increment=100 default charset=utf8mb4 comment='Front AI generation task';
create table front_ai_quota_bucket (
bucket_id bigint(20) not null auto_increment comment 'Quota bucket ID',
user_id bigint(20) not null comment 'Front user ID',
period_type varchar(20) not null comment 'DAY or MONTH',
period_key varchar(20) not null comment 'Period key',
task_limit int default 0 comment 'Task limit',
task_used int default 0 comment 'Used tasks',
token_limit int default 0 comment 'Token limit',
token_used int default 0 comment 'Used tokens',
cost_limit_cents int default 0 comment 'Cost limit in cents',
cost_used_cents int default 0 comment 'Used cost in cents',
running_limit int default 1 comment 'Running task limit',
running_count int default 0 comment 'Running task count',
create_time datetime default null comment 'Create time',
update_time datetime default null comment 'Update time',
primary key (bucket_id),
unique key uk_front_ai_quota_bucket (user_id, period_type, period_key)
) engine=innodb auto_increment=100 default charset=utf8mb4 comment='Front AI quota bucket';
create table front_ai_usage_ledger (
ledger_id bigint(20) not null auto_increment comment 'Usage ledger ID',
task_id bigint(20) default null comment 'Task ID',
generation_id bigint(20) default null comment 'Generation record ID',
project_id bigint(20) not null comment 'Project ID',
user_id bigint(20) not null comment 'Front user ID',
generate_type varchar(50) not null comment 'Generation type',
provider varchar(50) default 'deepseek' comment 'AI provider',
model varchar(100) default 'deepseek-chat' comment 'AI model',
input_tokens int default 0 comment 'Input tokens',
output_tokens int default 0 comment 'Output tokens',
total_tokens int default 0 comment 'Total tokens',
cost_cents int default 0 comment 'Estimated cost in cents',
success char(1) default '0' comment 'Success flag',
error_message varchar(1000) default '' comment 'Error message',
create_time datetime default null comment 'Create time',
primary key (ledger_id),
key idx_front_ai_usage_user (user_id, create_time),
key idx_front_ai_usage_task (task_id)
) engine=innodb auto_increment=100 default charset=utf8mb4 comment='Front AI usage ledger';
create table front_project_file (
file_id bigint(20) not null auto_increment comment '文件缓存ID',
project_id bigint(20) not null comment '项目ID',