feat: 新增系统字典

This commit is contained in:
x6g2
2026-11-07 07:08:37 +08:00
parent 3fc6986c89
commit 8f9ec7e893
23 changed files with 804 additions and 56 deletions
+2 -1
View File
@@ -403,7 +403,8 @@ const handleExport = () => {
/** 上下架状态修改 */
const handleStatusChange = async (row: Partial<ApiPackageVO>) => {
const text = row.status === '0' ? '上架' : '下架';
const text =
(billing_package_status.value || []).find((dict: any) => dict.value === row.status)?.label ?? row.status;
try {
await modal.confirm('确认要"' + text + '"吗?');
await changeApiPackageStatus(row.id, row.status);
+2 -1
View File
@@ -514,7 +514,8 @@ const handleStatusChange = async (row: Partial<ApiUserWalletVO>) => {
if (row.id == null || row.status == null) {
return;
}
const text = row.status === '0' ? '正常' : '冻结';
const text =
(billing_wallet_status.value || []).find((dict: any) => dict.value === row.status)?.label ?? row.status;
try {
await modal.confirm('确认要将该钱包状态调整为"' + text + '"吗?');
await changeApiUserWalletStatus(row.id, row.status);
+11 -11
View File
@@ -19,17 +19,17 @@
</el-form-item>
<el-form-item label="请求方法" prop="method">
<el-select v-model="queryParams.method" placeholder="请求方法" clearable>
<el-option v-for="dict in api_method" :key="dict.value" :label="dict.label" :value="dict.value" />
<el-option v-for="dict in openapi_api_method" :key="dict.value" :label="dict.label" :value="dict.value" />
</el-select>
</el-form-item>
<el-form-item label="计费模式" prop="chargeType">
<el-select v-model="queryParams.chargeType" placeholder="计费模式" clearable>
<el-option v-for="dict in charge_type" :key="dict.value" :label="dict.label" :value="dict.value" />
<el-option v-for="dict in openapi_charge_type" :key="dict.value" :label="dict.label" :value="dict.value" />
</el-select>
</el-form-item>
<el-form-item label="接口状态" prop="status">
<el-select v-model="queryParams.status" placeholder="接口状态" clearable>
<el-option v-for="dict in api_status" :key="dict.value" :label="dict.label" :value="dict.value" />
<el-option v-for="dict in openapi_api_status" :key="dict.value" :label="dict.label" :value="dict.value" />
</el-select>
</el-form-item>
<el-form-item label="分类" prop="categoryId">
@@ -120,7 +120,7 @@
</el-table-column>
<el-table-column label="计费模式" align="center">
<template #default="scope">
<dict-tag :options="charge_type" :value="scope.row.chargeType" />
<dict-tag :options="openapi_charge_type" :value="scope.row.chargeType" />
</template>
</el-table-column>
<el-table-column label="调用单价" align="center">
@@ -132,7 +132,7 @@
<el-table-column label="QPS上限" align="center" prop="qpsLimit" />
<el-table-column label="状态" align="center">
<template #default="scope">
<dict-tag :options="api_status" :value="scope.row.status" />
<dict-tag :options="openapi_api_status" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
@@ -191,7 +191,7 @@
</el-form-item>
<el-form-item label="请求方法" prop="method">
<el-select v-model="form.method" placeholder="请选择请求方法">
<el-option v-for="dict in api_method" :key="dict.value" :label="dict.label" :value="dict.value" />
<el-option v-for="dict in openapi_api_method" :key="dict.value" :label="dict.label" :value="dict.value" />
</el-select>
</el-form-item>
<el-form-item label="后端代理地址" prop="upstreamUrl">
@@ -202,7 +202,7 @@
</el-form-item>
<el-form-item label="计费模式" prop="chargeType">
<el-radio-group v-model="form.chargeType">
<el-radio v-for="dict in charge_type" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
<el-radio v-for="dict in openapi_charge_type" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="调用单价(元)" prop="pricePerCall">
@@ -222,7 +222,7 @@
</el-form-item>
<el-form-item label="接口状态" prop="status">
<el-radio-group v-model="form.status">
<el-radio v-for="dict in api_status" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
<el-radio v-for="dict in openapi_api_status" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="接口说明" prop="description">
@@ -255,9 +255,9 @@ import { useDict } from '@/utils/dict';
import { download as requestDownload } from '@/utils/request';
import { parseTime } from '@/utils/ruoyi';
const { api_status } = toRefs<any>(useDict('api_status'));
const { charge_type } = toRefs<any>(useDict('charge_type'));
const { api_method } = toRefs<any>(useDict('api_method'));
const { openapi_api_status } = toRefs<any>(useDict('openapi_api_status'));
const { openapi_charge_type } = toRefs<any>(useDict('openapi_charge_type'));
const { openapi_api_method } = toRefs<any>(useDict('openapi_api_method'));
const apiInfoList = ref<ApiInfoVO[]>([]);
const categoryOptions = ref<ApiCategoryVO[]>([]);
+4 -4
View File
@@ -16,7 +16,7 @@
</el-form-item>
<el-form-item label="授权状态" prop="authStatus">
<el-select v-model="queryParams.authStatus" placeholder="授权状态" clearable>
<el-option v-for="dict in auth_status" :key="dict.value" :label="dict.label" :value="dict.value" />
<el-option v-for="dict in openapi_auth_status" :key="dict.value" :label="dict.label" :value="dict.value" />
</el-select>
</el-form-item>
<el-form-item label="创建时间" style="width: 308px">
@@ -100,7 +100,7 @@
</el-table-column>
<el-table-column label="授权状态" align="center">
<template #default="scope">
<dict-tag :options="auth_status" :value="scope.row.authStatus" />
<dict-tag :options="openapi_auth_status" :value="scope.row.authStatus" />
</template>
</el-table-column>
<el-table-column label="剩余免费次数" align="center" prop="freeCallsLeft" />
@@ -176,7 +176,7 @@
</el-form-item>
<el-form-item label="授权状态" prop="authStatus">
<el-radio-group v-model="form.authStatus">
<el-radio v-for="dict in auth_status" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
<el-radio v-for="dict in openapi_auth_status" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="剩余免费次数" prop="freeCallsLeft">
@@ -245,7 +245,7 @@ import { useDict } from '@/utils/dict';
import { download as requestDownload } from '@/utils/request';
import { parseTime } from '@/utils/ruoyi';
const { auth_status } = toRefs<any>(useDict('auth_status'));
const { openapi_auth_status } = toRefs<any>(useDict('openapi_auth_status'));
const authList = ref<ApiAppAuthVO[]>([]);
const appOptions = ref<ApiAppVO[]>([]);
+3 -1
View File
@@ -62,7 +62,9 @@ pnpm lint
## 后端依赖
- 后端服务:`starapi-admin`(8080),需 MySQL + Redis。
- 建库与初始化数据:`script/sql/api_billing.sql`。
- 建库与初始化:先执行 `script/sql/ry_vue.sql`(框架表 + 基础数据),再按顺序执行
`script/sql/starapi_openapi.sql`、`script/sql/starapi_billing.sql`、`script/sql/starapi_calllog.sql`
(业务表 + 后台菜单路由 + 系统字典);已有库的充值订单补列见 `script/sql/starapi_crypto_payment.sql`。
- 邮箱验证码:在 `starapi-admin` 的 `application-dev.yml` 中开启并配置 SMTP:
```yaml
+8 -6
View File
@@ -11,7 +11,7 @@
<div class="api-hero__main">
<div class="api-hero__title-row">
<h2 class="api-hero__title">{{ formatText(apiData.name) }}</h2>
<dict-tag :options="api_status" :value="apiData.status" />
<dict-tag :options="openapi_api_status" :value="apiData.status" />
<el-tag v-if="apiData.categoryName" type="info" effect="plain">
{{ formatText(apiData.categoryName) }}
</el-tag>
@@ -19,7 +19,7 @@
<div class="api-hero__meta">
<code class="api-hero__code">{{ formatText(apiData.apiCode) }}</code>
<el-divider direction="vertical" />
<dict-tag :options="api_method" :value="apiData.method" />
<dict-tag :options="openapi_api_method" :value="apiData.method" />
<span class="api-hero__path">{{ formatText(apiData.path) }}</span>
</div>
</div>
@@ -50,13 +50,13 @@
</el-descriptions-item>
<el-descriptions-item label="分类">{{ formatText(apiData.categoryName) }}</el-descriptions-item>
<el-descriptions-item label="请求方法">
<dict-tag :options="api_method" :value="apiData.method" />
<dict-tag :options="openapi_api_method" :value="apiData.method" />
</el-descriptions-item>
<el-descriptions-item label="网关路径">
<code>{{ formatText(apiData.path) }}</code>
</el-descriptions-item>
<el-descriptions-item label="计费模式">
<dict-tag :options="charge_type" :value="apiData.chargeType" />
<dict-tag :options="openapi_charge_type" :value="apiData.chargeType" />
</el-descriptions-item>
<el-descriptions-item label="单价">
<span>{{ priceText }}</span>
@@ -66,7 +66,7 @@
<el-descriptions-item label="QPS 上限">{{ qpsText }}</el-descriptions-item>
<el-descriptions-item label="超时时间">{{ formatDuration(apiData.timeoutMs) }}</el-descriptions-item>
<el-descriptions-item label="状态">
<dict-tag :options="api_status" :value="apiData.status" />
<dict-tag :options="openapi_api_status" :value="apiData.status" />
</el-descriptions-item>
<el-descriptions-item label="创建时间">{{ createTimeText }}</el-descriptions-item>
</el-descriptions>
@@ -203,7 +203,9 @@ import { useDict } from '@/utils/dict';
import { copyToClipboard, formatAmount, formatDuration, formatText, maskAppKey } from '@/utils/portal-format';
import { parseTime } from '@/utils/ruoyi';
const { api_method, api_status, charge_type } = toRefs<any>(useDict('api_method', 'api_status', 'charge_type'));
const { openapi_api_method, openapi_api_status, openapi_charge_type } = toRefs<any>(
useDict('openapi_api_method', 'openapi_api_status', 'openapi_charge_type')
);
const route = useRoute();
const router = useRouter();
+7 -5
View File
@@ -52,7 +52,7 @@
</el-form-item>
<el-form-item label="计费模式" prop="chargeType">
<el-select v-model="queryParams.chargeType" placeholder="计费模式" clearable>
<el-option v-for="dict in charge_type" :key="dict.value" :label="dict.label" :value="dict.value" />
<el-option v-for="dict in openapi_charge_type" :key="dict.value" :label="dict.label" :value="dict.value" />
</el-select>
</el-form-item>
<el-form-item>
@@ -98,7 +98,7 @@
</el-table-column>
<el-table-column label="请求方法" align="center" width="110">
<template #default="scope">
<dict-tag :options="api_method" :value="scope.row.method" />
<dict-tag :options="openapi_api_method" :value="scope.row.method" />
</template>
</el-table-column>
<el-table-column label="路径" align="left" min-width="200" :show-overflow-tooltip="true">
@@ -108,7 +108,7 @@
</el-table-column>
<el-table-column label="计费模式" align="center" width="120">
<template #default="scope">
<dict-tag :options="charge_type" :value="scope.row.chargeType" />
<dict-tag :options="openapi_charge_type" :value="scope.row.chargeType" />
</template>
</el-table-column>
<el-table-column label="单价" align="center" width="120">
@@ -128,7 +128,7 @@
</el-table-column>
<el-table-column label="状态" align="center" width="100">
<template #default="scope">
<dict-tag :options="api_status" :value="scope.row.status" />
<dict-tag :options="openapi_api_status" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column
@@ -169,7 +169,9 @@ import { useFullHeightTable } from '@/hooks/table/useFullHeightTable';
import { useDict } from '@/utils/dict';
import { formatAmount, formatText } from '@/utils/portal-format';
const { api_method, api_status, charge_type } = toRefs<any>(useDict('api_method', 'api_status', 'charge_type'));
const { openapi_api_method, openapi_api_status, openapi_charge_type } = toRefs<any>(
useDict('openapi_api_method', 'openapi_api_status', 'openapi_charge_type')
);
const router = useRouter();
+7 -7
View File
@@ -128,7 +128,7 @@
>
<el-form-item label="授权状态" prop="authStatus">
<el-select v-model="authQueryParams.authStatus" placeholder="授权状态" clearable>
<el-option v-for="dict in auth_status" :key="dict.value" :label="dict.label" :value="dict.value" />
<el-option v-for="dict in openapi_auth_status" :key="dict.value" :label="dict.label" :value="dict.value" />
</el-select>
</el-form-item>
<el-form-item label="接口名称" prop="apiName">
@@ -173,7 +173,7 @@
</el-table-column>
<el-table-column label="计费模式" align="center" width="130">
<template #default="scope">
<dict-tag :options="charge_type" :value="scope.row.chargeType" />
<dict-tag :options="openapi_charge_type" :value="scope.row.chargeType" />
</template>
</el-table-column>
<el-table-column label="单价" align="center" width="120">
@@ -188,7 +188,7 @@
</el-table-column>
<el-table-column label="授权状态" align="center" width="110">
<template #default="scope">
<dict-tag :options="auth_status" :value="scope.row.authStatus" />
<dict-tag :options="openapi_auth_status" :value="scope.row.authStatus" />
</template>
</el-table-column>
<el-table-column label="审核意见" align="center" min-width="150" :show-overflow-tooltip="true">
@@ -301,12 +301,12 @@
</el-table-column>
<el-table-column label="计费模式" align="center" width="120">
<template #default="scope">
<dict-tag :options="charge_type" :value="scope.row.chargeType" />
<dict-tag :options="openapi_charge_type" :value="scope.row.chargeType" />
</template>
</el-table-column>
<el-table-column label="当前授权状态" align="center" width="140">
<template #default="scope">
<dict-tag v-if="currentAuthStatus(scope.row)" :options="auth_status" :value="currentAuthStatus(scope.row)" />
<dict-tag v-if="currentAuthStatus(scope.row)" :options="openapi_auth_status" :value="currentAuthStatus(scope.row)" />
<span v-else class="action-empty">未申请</span>
</template>
</el-table-column>
@@ -386,8 +386,8 @@ import { useDict } from '@/utils/dict';
import { copyToClipboard, formatAmount, formatText, maskAppKey } from '@/utils/portal-format';
import { parseTime } from '@/utils/ruoyi';
const { openapi_app_status, charge_type, auth_status } = toRefs<any>(
useDict('openapi_app_status', 'charge_type', 'auth_status')
const { openapi_app_status, openapi_charge_type, openapi_auth_status } = toRefs<any>(
useDict('openapi_app_status', 'openapi_charge_type', 'openapi_auth_status')
);
const route = useRoute();
+299
View File
@@ -0,0 +1,299 @@
-- ----------------------------------------------------------------------------
-- StarAPI 计费中心(billing)数据库初始化脚本
-- 适用数据库:MySQL 8.x;脚本可重复执行(建表与数据写入均做幂等处理)
-- 执行顺序:ry_vue.sql -> starapi_openapi.sql -> starapi_billing.sql -> starapi_calllog.sql
-- (三模块之间无外键依赖,顺序可调,建议按此顺序执行)
-- 包含内容:
-- 1) 建表:api_package / api_user_wallet / api_wallet_flow / api_recharge_order / api_user_package
-- 2) 后台菜单路由:计费中心目录 + 5 个功能菜单 + 按钮权限
-- 3) 系统字典:计费套餐状态、用户次数包状态、钱包状态、流水类型、支付状态、支付方式
-- 说明:
-- 1) api_recharge_order 已包含全部加密货币扩展列(price_amount、price_currency、pay_coin、
-- pay_network、pay_currency、pay_amount、pay_address、pay_memo、paid_amount、exchange_rate、
-- provider、provider_payment_id、provider_status、expire_time),类型与精度逐列对齐
-- starapi_crypto_payment.sql;新库直接执行本文件即含全部列,无需再执行 crypto 脚本的加列语句;
-- 2) 已上线且 api_recharge_order 已存在的库,只需执行 starapi_crypto_payment.sql 补列;
-- 本文件中的 billing_pay_type 字典与 crypto 脚本使用相同 ID 且均按 dict_type / dict_value 判重,
-- 先后执行顺序不影响结果;
-- 3) 表结构不含外键,索引按 ServiceImpl / Mapper / 用户端服务的真实查询与唯一性校验建立;
-- 审计列严格按实体定义:仅 ApiPackage extends BaseEntity(含 create_dept/create_by/create_time/
-- update_by/update_time),其余 4 个实体 implements Serializable,只保留自身声明的
-- create_time / update_time(ApiWalletFlow 仅 create_time);
-- 4) 金额、余额类字段统一 decimal(18,4):精度 18 位,标度取代码实际要求的 4 位
-- (ApiUserWalletServiceImpl AMOUNT_SCALE=4、CryptoPaymentServiceImpl AMOUNT_SCALE=4、
-- 前端套餐售价与充值金额 :precision="4"、文档「amount 4 位小数」均要求 4 位;若压缩为 2 位
-- 会导致余额与流水四舍五入后账实不平);加密货币数量保留 8 位小数,美元金额保留 2 位小数,
-- 汇率保留 6 位小数(与 starapi_crypto_payment.sql 逐列一致)。
-- ----------------------------------------------------------------------------
-- ----------------------------
-- 1、API次数套餐规格表
-- ----------------------------
create table if not exists api_package (
id bigint(20) not null comment '套餐ID',
api_id bigint(20) default null comment '绑定API ID(0代表全平台通用包)',
name varchar(128) not null comment '套餐包名称(如:天气接口-1万次季度包)',
total_calls int(11) not null comment '套餐总调用次数',
price decimal(18,4) not null comment '售价(元)',
valid_days int(11) default null comment '有效天数',
status char(1) default '0' comment '状态(0上架 1下架)',
del_flag char(1) default '0' comment '删除标志(0代表存在 1代表删除)',
create_dept bigint(20) default null comment '创建部门',
create_by bigint(20) default null comment '创建者',
create_time datetime comment '创建时间',
update_by bigint(20) default null comment '更新者',
update_time datetime comment '更新时间',
primary key (id),
key idx_api_package_status (status),
key idx_api_package_api_id (api_id)
) engine=innodb comment = 'API次数套餐规格表';
-- ----------------------------
-- 2、用户钱包资产表(同一用户仅允许一个钱包,Service 开户前校验 + uk_user_id 兜底)
-- ----------------------------
create table if not exists api_user_wallet (
id bigint(20) not null comment '主键ID',
user_id bigint(20) not null comment '用户ID(关联 api_user.id)',
balance decimal(18,4) default null comment '可用余额(元)',
frozen_amount decimal(18,4) default null comment '冻结金额(元)',
total_recharged decimal(18,4) default null comment '累计充值金额(元)',
total_consumed decimal(18,4) default null comment '累计消费金额(元)',
version bigint(20) default 0 comment '乐观锁版本号',
status char(1) default '0' comment '状态(0正常 1冻结)',
create_time datetime comment '创建时间',
update_time datetime comment '更新时间',
primary key (id),
unique key uk_api_user_wallet_user_id (user_id)
) engine=innodb comment = '用户钱包资产表';
-- ----------------------------
-- 3、钱包资金流水明细表
-- ----------------------------
create table if not exists api_wallet_flow (
id bigint(20) not null comment '流水ID',
user_id bigint(20) default null comment '用户ID(关联 api_user.id)',
flow_no varchar(64) default null comment '流水号(全局唯一)',
type char(1) default null comment '变动类型(1充值入账 2调用扣费 3购买次数包 4人工调账 5退款)',
amount decimal(18,4) default null comment '变动金额(正数增加,负数扣减)',
balance_before decimal(18,4) default null comment '变动前余额',
balance_after decimal(18,4) default null comment '变动后余额',
relate_biz_id varchar(64) default null comment '关联业务单号(充值订单号或调用RequestId)',
remark varchar(500) default null comment '变动说明',
create_time datetime comment '创建时间',
primary key (id),
unique key uk_api_wallet_flow_flow_no (flow_no),
key idx_api_wallet_flow_user_type_create (user_id, type, create_time),
key idx_api_wallet_flow_relate_biz (relate_biz_id, type)
) engine=innodb comment = '钱包资金流水明细表';
-- ----------------------------
-- 4、用户充值订单表(含加密货币在线支付扩展列,逐列对齐 starapi_crypto_payment.sql)
-- ----------------------------
create table if not exists api_recharge_order (
id bigint(20) not null comment '订单ID',
order_no varchar(64) default null comment '平台商户订单号',
user_id bigint(20) not null comment '用户ID',
amount decimal(18,4) not null comment '充值金额(元)',
price_amount decimal(18,2) default null comment '充值金额(USD)',
price_currency varchar(8) default null comment '计价货币,固定 USD',
pay_coin varchar(16) default null comment '稳定币:USDT/USDC',
pay_network varchar(32) default null comment '网络:Ethereum/BSC',
pay_currency varchar(32) default null comment 'NOWPayments 支付币种代码,如 usdterc20',
pay_amount decimal(28,8) default null comment '应付加密货币数量',
pay_address varchar(191) default null comment '收款地址',
pay_memo varchar(128) default null comment '地址备注/Memo',
paid_amount decimal(28,8) default null comment '链上实付币数',
exchange_rate decimal(18,6) default null comment 'USD-CNY 汇率快照',
provider varchar(32) default null comment '支付通道:nowpayments/mock',
provider_payment_id varchar(64) default null comment '通道支付单号',
provider_status varchar(32) default null comment '通道原始状态',
expire_time datetime default null comment '支付有效期',
pay_type char(1) default null comment '支付方式(1微信 2支付宝 3对公转账 4加密货币)',
pay_status char(1) default '0' comment '支付状态(0待支付 1支付成功 2支付失败 3已取消)',
out_trade_no varchar(128) default null comment '第三方支付流水号(加密货币订单为链上交易哈希)',
pay_time datetime default null comment '支付时间',
create_time datetime comment '创建时间',
update_time datetime comment '更新时间',
primary key (id),
unique key uk_api_recharge_order_order_no (order_no),
key idx_recharge_order_user_status (user_id, pay_status),
key idx_recharge_order_provider_payment (provider_payment_id),
key idx_recharge_order_pay_type_create (pay_type, create_time)
) engine=innodb comment = '用户充值订单表';
-- ----------------------------
-- 5、用户已购API次数包表
-- ----------------------------
create table if not exists api_user_package (
id bigint(20) not null comment '用户套餐ID',
user_id bigint(20) not null comment '用户ID(关联api_user.id)',
api_id bigint(20) default null comment '绑定API ID(0为通用)',
package_id bigint(20) not null comment '关联套餐规格ID',
total_calls int(11) default null comment '总可用次数',
remain_calls int(11) default null comment '剩余可用次数',
expire_time datetime default null comment '过期时间',
status char(1) default '0' comment '状态(0有效 1已耗尽 2已过期)',
create_time datetime comment '创建时间',
update_time datetime comment '更新时间',
primary key (id),
key idx_api_user_package_user_status (user_id, status, expire_time),
key idx_api_user_package_package_id (package_id)
) engine=innodb comment = '用户已购API次数包表';
-- ----------------------------
-- 后台菜单路由(计费中心)
-- 号段:目录 1761400000000003001;功能菜单 1761400000000003101-3105;按钮 1761400000000003211-3229
-- ----------------------------
-- 一级目录
insert into sys_menu select 1761400000000003001, '计费中心', 0, 6, 'billing', null, '', 'N', 'Y', 'M', '0', '0', '', 'money', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '计费中心目录' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003001);
-- 功能菜单
insert into sys_menu select 1761400000000003101, '充值订单', 1761400000000003001, 1, 'order', 'billing/order/index', '', 'N', 'Y', 'C', '0', '0', 'billing:order:list', 'list', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '充值订单菜单' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003101);
insert into sys_menu select 1761400000000003102, 'API套餐规格', 1761400000000003001, 2, 'package', 'billing/package/index', '', 'N', 'Y', 'C', '0', '0', 'billing:package:list', 'shopping', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, 'API套餐规格菜单' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003102);
insert into sys_menu select 1761400000000003103, '用户次数包', 1761400000000003001, 3, 'userPackage', 'billing/userPackage/index', '', 'N', 'Y', 'C', '0', '0', 'billing:userPackage:list', 'user', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '用户次数包菜单' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003103);
insert into sys_menu select 1761400000000003104, '钱包资产', 1761400000000003001, 4, 'wallet', 'billing/wallet/index', '', 'N', 'Y', 'C', '0', '0', 'billing:wallet:list', 'money', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '钱包资产菜单' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003104);
insert into sys_menu select 1761400000000003105, '资金流水', 1761400000000003001, 5, 'flow', 'billing/flow/index', '', 'N', 'Y', 'C', '0', '0', 'billing:flow:list', 'chart', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '资金流水菜单' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003105);
-- 充值订单按钮
insert into sys_menu select 1761400000000003211, '充值订单查询', 1761400000000003101, 1, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:order:query', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003211);
insert into sys_menu select 1761400000000003212, '充值订单新增', 1761400000000003101, 2, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:order:add', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003212);
insert into sys_menu select 1761400000000003213, '充值订单修改', 1761400000000003101, 3, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:order:edit', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '确认收款、取消订单、同步通道状态' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003213);
insert into sys_menu select 1761400000000003214, '充值订单导出', 1761400000000003101, 4, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:order:export', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003214);
-- API套餐规格按钮
insert into sys_menu select 1761400000000003215, '套餐查询', 1761400000000003102, 1, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:package:query', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003215);
insert into sys_menu select 1761400000000003216, '套餐新增', 1761400000000003102, 2, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:package:add', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003216);
insert into sys_menu select 1761400000000003217, '套餐修改', 1761400000000003102, 3, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:package:edit', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '含上下架状态修改' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003217);
insert into sys_menu select 1761400000000003218, '套餐删除', 1761400000000003102, 4, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:package:remove', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003218);
insert into sys_menu select 1761400000000003219, '套餐导出', 1761400000000003102, 5, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:package:export', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003219);
-- 用户次数包按钮
insert into sys_menu select 1761400000000003220, '次数包查询', 1761400000000003103, 1, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:userPackage:query', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003220);
insert into sys_menu select 1761400000000003221, '购买次数包', 1761400000000003103, 2, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:userPackage:purchase', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003221);
insert into sys_menu select 1761400000000003222, '发放次数包', 1761400000000003103, 3, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:userPackage:add', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003222);
insert into sys_menu select 1761400000000003223, '次数包导出', 1761400000000003103, 4, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:userPackage:export', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003223);
-- 钱包资产按钮
insert into sys_menu select 1761400000000003224, '钱包查询', 1761400000000003104, 1, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:wallet:query', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003224);
insert into sys_menu select 1761400000000003225, '钱包开户', 1761400000000003104, 2, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:wallet:add', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003225);
insert into sys_menu select 1761400000000003226, '钱包修改', 1761400000000003104, 3, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:wallet:edit', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '充值、调账、冻结/解冻' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003226);
insert into sys_menu select 1761400000000003227, '钱包导出', 1761400000000003104, 4, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:wallet:export', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003227);
-- 资金流水按钮
insert into sys_menu select 1761400000000003228, '流水查询', 1761400000000003105, 1, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:flow:query', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003228);
insert into sys_menu select 1761400000000003229, '流水导出', 1761400000000003105, 2, '', '', '', 'N', 'Y', 'F', '0', '0', 'billing:flow:export', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000003229);
-- ----------------------------
-- 系统字典(类型号段 1761500000000000120-124;数据号段 1761600000000000300-315)
-- billing_pay_type 与 starapi_crypto_payment.sql 完全一致(dict_id 1761500000000000100,dict_code 101-104)
-- ----------------------------
-- 字典类型
insert into sys_dict_type (dict_id, dict_name, dict_type, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761500000000000120, '计费套餐状态', 'billing_package_status', 1761000000000000103, 1761100000000000001, sysdate(), null, null, 'API次数套餐上下架状态'
from dual where not exists (select 1 from sys_dict_type where dict_type = 'billing_package_status');
insert into sys_dict_type (dict_id, dict_name, dict_type, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761500000000000121, '用户次数包状态', 'billing_user_package_status', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '用户已购次数包使用状态'
from dual where not exists (select 1 from sys_dict_type where dict_type = 'billing_user_package_status');
insert into sys_dict_type (dict_id, dict_name, dict_type, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761500000000000122, '钱包状态', 'billing_wallet_status', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '用户钱包资产状态'
from dual where not exists (select 1 from sys_dict_type where dict_type = 'billing_wallet_status');
insert into sys_dict_type (dict_id, dict_name, dict_type, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761500000000000123, '钱包流水类型', 'billing_flow_type', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '钱包资金流水变动类型'
from dual where not exists (select 1 from sys_dict_type where dict_type = 'billing_flow_type');
insert into sys_dict_type (dict_id, dict_name, dict_type, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761500000000000124, '充值支付状态', 'billing_pay_status', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '充值订单支付状态'
from dual where not exists (select 1 from sys_dict_type where dict_type = 'billing_pay_status');
insert into sys_dict_type (dict_id, dict_name, dict_type, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761500000000000100, '计费支付方式', 'billing_pay_type', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '充值订单支付方式'
from dual where not exists (select 1 from sys_dict_type where dict_type = 'billing_pay_type');
-- 计费套餐状态
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000300, 1, '上架', '0', 'billing_package_status', '', 'primary', 'Y', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '套餐上架可购买'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_package_status' and dict_value = '0');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000301, 2, '下架', '1', 'billing_package_status', '', 'info', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '套餐下架不可购买'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_package_status' and dict_value = '1');
-- 用户次数包状态
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000302, 1, '有效', '0', 'billing_user_package_status', '', 'success', 'Y', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '次数包未过期且仍有剩余次数'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_user_package_status' and dict_value = '0');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000303, 2, '已耗尽', '1', 'billing_user_package_status', '', 'warning', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '剩余次数已扣减为0'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_user_package_status' and dict_value = '1');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000304, 3, '已过期', '2', 'billing_user_package_status', '', 'danger', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '已超过有效期'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_user_package_status' and dict_value = '2');
-- 钱包状态
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000305, 1, '正常', '0', 'billing_wallet_status', '', 'primary', 'Y', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '钱包正常,可充值可扣费'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_wallet_status' and dict_value = '0');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000306, 2, '冻结', '1', 'billing_wallet_status', '', 'danger', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '钱包冻结,不允许扣费'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_wallet_status' and dict_value = '1');
-- 钱包流水类型
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000307, 1, '充值入账', '1', 'billing_flow_type', '', 'success', 'Y', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '充值订单收款或管理员手工充值入账'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_flow_type' and dict_value = '1');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000308, 2, '调用扣费', '2', 'billing_flow_type', '', 'warning', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, 'API调用按次扣减钱包余额'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_flow_type' and dict_value = '2');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000309, 3, '购买次数包', '3', 'billing_flow_type', '', 'primary', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '购买API次数包扣减钱包余额'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_flow_type' and dict_value = '3');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000310, 4, '人工调账', '4', 'billing_flow_type', '', 'info', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '管理员人工调整钱包余额'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_flow_type' and dict_value = '4');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000311, 5, '退款', '5', 'billing_flow_type', '', 'danger', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '充值或消费退款入账'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_flow_type' and dict_value = '5');
-- 充值支付状态
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000312, 1, '待支付', '0', 'billing_pay_status', '', 'warning', 'Y', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '订单已创建,等待支付'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_pay_status' and dict_value = '0');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000313, 2, '支付成功', '1', 'billing_pay_status', '', 'success', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '订单已确认收款并入账钱包'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_pay_status' and dict_value = '1');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000314, 3, '支付失败', '2', 'billing_pay_status', '', 'danger', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '支付通道下单或支付失败'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_pay_status' and dict_value = '2');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000315, 4, '已取消', '3', 'billing_pay_status', '', 'info', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '待支付订单被取消'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_pay_status' and dict_value = '3');
-- 计费支付方式(与 starapi_crypto_payment.sql 完全一致)
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000101, 1, '微信', '1', 'billing_pay_type', '', 'primary', 'Y', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '微信支付'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_pay_type' and dict_value = '1');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000102, 2, '支付宝', '2', 'billing_pay_type', '', 'primary', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '支付宝支付'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_pay_type' and dict_value = '2');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000103, 3, '对公转账', '3', 'billing_pay_type', '', 'info', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '线下对公转账'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_pay_type' and dict_value = '3');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000104, 4, '加密货币', '4', 'billing_pay_type', '', 'success', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, 'USDT/USDC (ERC-20/BEP-20) 链上转账'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'billing_pay_type' and dict_value = '4');
+130
View File
@@ -0,0 +1,130 @@
-- ----------------------------------------------------------------------------
-- StarAPI 调用日志模块(calllog)数据库初始化脚本
-- 适用数据库:MySQL 8.x;执行前请备份 api_call_log、api_call_daily_stat 及菜单、字典相关表
-- 执行顺序:ry_vue.sql -> starapi_openapi.sql -> starapi_billing.sql -> starapi_calllog.sql
-- (三模块之间无外键依赖,顺序可调,建议按此顺序执行)
-- 说明:
-- 1) 建表语句使用 create table if not exists,菜单/字典使用 where not exists 保证可重复执行;
-- 2) calllog 模块实体均未继承 BaseEntity,两张表按实体字段建列,api_call_daily_stat 仅保留
-- 实体自带的 create_time/update_time,不含 create_dept/create_by 等公共列;
-- 3) 菜单号段 1761400000000004001-1761400000000004217,字典号段
-- 1761500000000000130-1761500000000000131、1761600000000000400-1761600000000000405;
-- 4) 金额列按计费精度保留 4 位小数(billing AMOUNT_SCALE=4、api_info.price_per_call
-- 为 decimal(18,4)、钱包余额 decimal(18,4)),与钱包账实口径一致。
-- ----------------------------------------------------------------------------
-- ----------------------------
-- 一、建表
-- ----------------------------
-- 1、API调用与计费明细表
create table if not exists api_call_log (
id bigint(20) not null comment '主键ID',
request_id varchar(64) not null comment '网关全局唯一链路追踪ID(防重与幂等)',
user_id bigint(20) not null comment '调用方用户ID(关联 api_user.id)',
app_id bigint(20) not null comment '调用方应用ID',
api_id bigint(20) not null comment '调用的API ID',
request_time datetime not null comment '请求到达时间(精确到毫秒)',
response_time datetime default null comment '响应结束时间',
duration_ms int(11) default null comment '请求总耗时(毫秒)',
http_status int(11) default null comment 'HTTP状态码',
biz_code int(11) default null comment '后端业务返回码(0表示成功,非0表示业务失败)',
client_ip varchar(64) default null comment '调用端IP',
is_charge char(1) default '0' comment '是否计费(0未计费 1已计费)',
charge_mode char(1) default '0' comment '扣费模式(0无 1扣免费额度 2扣次数包 3扣钱包余额)',
deduct_calls int(11) default null comment '扣减调用次数(常规为1)',
deduct_amount decimal(18, 4) default null comment '扣减金额(元)',
balance_after decimal(18, 4) default null comment '扣费后钱包剩余金额(元)',
error_msg varchar(512) default null comment '异常原因说明',
primary key (id),
unique key uk_api_call_log_request_id (request_id),
key idx_call_log_user_time (user_id, request_time),
key idx_call_log_app_time (app_id, request_time),
key idx_call_log_api_time (api_id, request_time),
key idx_call_log_request_time (request_time)
) engine=innodb comment = 'API调用与计费明细表';
-- 2、API调用每日聚合统计表
create table if not exists api_call_daily_stat (
id bigint(20) not null comment '统计ID',
stat_date date not null comment '统计日期',
user_id bigint(20) not null comment '用户ID(关联 api_user.id)',
app_id bigint(20) not null comment '应用ID',
api_id bigint(20) not null comment 'API ID',
total_calls int(11) default null comment '总调用次数',
success_calls int(11) default null comment '成功调用次数',
fail_calls int(11) default null comment '失败调用次数',
charge_calls int(11) default null comment '实际计费调用次数',
total_cost decimal(18, 4) default null comment '当日总消费金额(元)',
create_time datetime comment '创建时间',
update_time datetime comment '更新时间',
primary key (id),
unique key uk_api_call_daily_stat_dim (stat_date, user_id, app_id, api_id),
key idx_api_call_daily_stat_user_date (user_id, stat_date),
key idx_api_call_daily_stat_app_date (app_id, stat_date),
key idx_api_call_daily_stat_api_date (api_id, stat_date),
key idx_api_call_daily_stat_date_api (stat_date, api_id)
) engine=innodb comment = 'API调用每日聚合统计表';
-- ----------------------------
-- 二、后台菜单路由(调用日志目录 + 日志查询/调用统计/调用报表 + 按钮权限)
-- ----------------------------
-- 一级目录
insert into sys_menu select 1761400000000004001, '调用日志', 0, 7, 'calllog', null, '', 'N', 'Y', 'M', '0', '0', '', 'log', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '调用日志目录' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000004001);
-- 功能菜单
insert into sys_menu select 1761400000000004101, '日志查询', 1761400000000004001, 1, 'log', 'calllog/log/index', '', 'N', 'Y', 'C', '0', '0', 'calllog:log:list', 'log', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '调用日志菜单' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000004101);
insert into sys_menu select 1761400000000004102, '调用统计', 1761400000000004001, 2, 'stat', 'calllog/stat/index', '', 'N', 'Y', 'C', '0', '0', 'calllog:stat:list', 'chart', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '调用统计菜单' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000004102);
insert into sys_menu select 1761400000000004103, '调用报表', 1761400000000004001, 3, 'report', 'calllog/report/index', '', 'N', 'Y', 'C', '0', '0', 'calllog:report:overview', 'dashboard', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '调用报表菜单' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000004103);
-- 按钮权限(日志查询)
insert into sys_menu select 1761400000000004211, '日志详情', 1761400000000004101, 1, '', '', '', 'N', 'Y', 'F', '0', '0', 'calllog:log:query', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000004211);
insert into sys_menu select 1761400000000004212, '日志导出', 1761400000000004101, 2, '', '', '', 'N', 'Y', 'F', '0', '0', 'calllog:log:export', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000004212);
-- 按钮权限(调用统计)
insert into sys_menu select 1761400000000004213, '统计详情', 1761400000000004102, 1, '', '', '', 'N', 'Y', 'F', '0', '0', 'calllog:stat:query', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000004213);
insert into sys_menu select 1761400000000004214, '统计导出', 1761400000000004102, 2, '', '', '', 'N', 'Y', 'F', '0', '0', 'calllog:stat:export', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000004214);
insert into sys_menu select 1761400000000004215, '重新聚合', 1761400000000004102, 3, '', '', '', 'N', 'Y', 'F', '0', '0', 'calllog:stat:refresh', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000004215);
-- 按钮权限(调用报表)
insert into sys_menu select 1761400000000004216, '调用趋势', 1761400000000004103, 1, '', '', '', 'N', 'Y', 'F', '0', '0', 'calllog:report:trend', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000004216);
insert into sys_menu select 1761400000000004217, '接口排行', 1761400000000004103, 2, '', '', '', 'N', 'Y', 'F', '0', '0', 'calllog:report:apiRank', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000004217);
-- ----------------------------
-- 三、系统字典(是否计费 / 扣费模式)
-- ----------------------------
-- 字典类型
insert into sys_dict_type (dict_id, dict_name, dict_type, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761500000000000130, '是否计费', 'calllog_charge_flag', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '调用日志是否计费标识'
from dual
where not exists (select 1 from sys_dict_type where dict_type = 'calllog_charge_flag');
insert into sys_dict_type (dict_id, dict_name, dict_type, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761500000000000131, '扣费模式', 'calllog_charge_mode', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '调用日志扣费模式'
from dual
where not exists (select 1 from sys_dict_type where dict_type = 'calllog_charge_mode');
-- 字典数据:是否计费
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000400, 1, '未计费', '0', 'calllog_charge_flag', '', 'info', 'Y', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '未计费'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'calllog_charge_flag' and dict_value = '0');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000401, 2, '已计费', '1', 'calllog_charge_flag', '', 'success', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '已计费'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'calllog_charge_flag' and dict_value = '1');
-- 字典数据:扣费模式
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000402, 1, '无', '0', 'calllog_charge_mode', '', 'info', 'Y', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '未扣费'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'calllog_charge_mode' and dict_value = '0');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000403, 2, '扣免费额度', '1', 'calllog_charge_mode', '', 'primary', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '扣减免费额度'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'calllog_charge_mode' and dict_value = '1');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000404, 3, '扣次数包', '2', 'calllog_charge_mode', '', 'warning', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '扣减次数包'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'calllog_charge_mode' and dict_value = '2');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000405, 4, '扣钱包余额', '3', 'calllog_charge_mode', '', 'success', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '扣减钱包余额'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'calllog_charge_mode' and dict_value = '3');
+309
View File
@@ -0,0 +1,309 @@
-- ----------------------------------------------------------------------------
-- StarAPI 开放平台(openapi)数据库初始化脚本
-- 适用数据库:MySQL 8.x;执行顺序:先执行基础脚本 ry_vue.sql,再执行本脚本
-- 内容:
-- 1) 建表:api_category / api_info / api_app / api_app_auth / api_user(共 5 张)
-- 2) 后台菜单:开放平台目录 + 5 个功能菜单 + 26 个按钮权限(sys_menu)
-- 3) 系统字典:6 种类型、21 条字典数据(sys_dict_type / sys_dict_data)
-- 说明:
-- 1) 主键 ID 由应用雪花算法生成,表结构不使用 auto_increment;
-- 2) 所有 insert 均按主键或业务唯一键幂等,可重复执行,不会产生重复数据;
-- 3) 不建外键,字符集与排序规则沿用库默认;
-- 4) api_category 状态沿用既有字典 sys_normal_disable,本脚本不重复创建;
-- 5) api_user / api_app / api_info 启用逻辑删除(del_flag),与基础框架 sys_user 一致:
-- 唯一性由 Service 层「排除已删除行」的校验保证,数据库层只建普通索引,避免软删除历史行
-- 导致「删除后重建同名/同编码」时写入失败。
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
-- 第一部分:建表
-- ----------------------------------------------------------------------------
-- ----------------------------
-- 1、API分类表
-- ----------------------------
create table if not exists api_category (
id bigint(20) not null comment '分类ID',
name varchar(64) not null comment '分类名称',
sort int(11) default 0 comment '排序值(升序)',
status char(1) default '0' comment '状态(0正常 1停用)',
del_flag char(1) default '0' comment '删除标志(0代表存在 1代表删除)',
create_dept bigint(20) default null comment '创建部门',
create_by bigint(20) default null comment '创建者',
create_time datetime comment '创建时间',
update_by bigint(20) default null comment '更新者',
update_time datetime comment '更新时间',
primary key (id),
key idx_api_category_status (status)
) engine=innodb comment = 'API分类表';
-- ----------------------------
-- 2、API接口信息表
-- ----------------------------
create table if not exists api_info (
id bigint(20) not null comment 'API接口ID',
category_id bigint(20) default null comment '分类ID',
name varchar(128) not null comment '接口名称',
api_code varchar(64) not null comment '接口唯一标识编码',
path varchar(255) not null comment '对外暴露网关路由路径',
method varchar(10) not null comment '请求方法(GET、POST、PUT、DELETE、PATCH、ALL)',
upstream_url varchar(512) not null comment '后端目标代理URL',
timeout_ms int(11) default null comment '超时时间(毫秒)',
charge_type char(1) default null comment '计费模式(0免费 1按次扣费 2仅限套餐包)',
price_per_call decimal(18,4) default null comment '每次调用单价(元)',
free_calls int(11) default null comment '新接入应用免费赠送次数',
qps_limit int(11) default null comment '该接口全局单应用QPS上限',
status char(1) default '0' comment '接口状态(0正常 1停用 2维护中)',
description text comment '接口说明与文档Markdown',
del_flag char(1) default '0' comment '删除标志(0代表存在 1代表删除)',
create_dept bigint(20) default null comment '创建部门',
create_by bigint(20) default null comment '创建者',
create_time datetime comment '创建时间',
update_by bigint(20) default null comment '更新者',
update_time datetime comment '更新时间',
primary key (id),
key idx_api_info_api_code (api_code),
key idx_api_info_path_method (path, method),
key idx_api_info_category_id (category_id),
key idx_api_info_status (status)
) engine=innodb comment = 'API接口信息表';
-- ----------------------------
-- 3、开发者应用及凭证表
-- ----------------------------
create table if not exists api_app (
id bigint(20) not null comment '应用ID',
user_id bigint(20) not null comment '所属开发者用户ID',
app_name varchar(128) not null comment '应用名称',
app_key varchar(64) default null comment '应用AppKey(公开客户端标识)',
app_secret varchar(128) default null comment '应用AppSecret(用于签名/加密Token)',
ip_white_list varchar(512) default null comment 'IP白名单(多个逗号隔开,空表示不限)',
qps_limit int(11) default null comment '应用级QPS流控阈值',
daily_call_limit int(11) default null comment '每日调用总次数限额(0为不限)',
status char(1) default '0' comment '状态(0正常 1禁用)',
del_flag char(1) default '0' comment '删除标志(0代表存在 1代表删除)',
create_dept bigint(20) default null comment '创建部门',
create_by bigint(20) default null comment '创建者',
create_time datetime comment '创建时间',
update_by bigint(20) default null comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注说明',
primary key (id),
key idx_api_app_app_key (app_key),
key idx_api_app_user_id (user_id)
) engine=innodb comment = '开发者应用及凭证表';
-- ----------------------------
-- 4、应用与接口授权关系表
-- ----------------------------
create table if not exists api_app_auth (
id bigint(20) not null comment '授权ID',
app_id bigint(20) not null comment '应用ID',
api_id bigint(20) not null comment 'API接口ID',
auth_status char(1) default '0' comment '授权状态(0已开通 1已暂停 2待审核 3已驳回)',
free_calls_left int(11) default null comment '剩余免费试用次数',
audit_remark varchar(255) default null comment '审核意见(驳回原因,仅在驳回时写入,重新申请时清空)',
create_time datetime comment '开通时间',
update_time datetime comment '更新时间',
primary key (id),
unique key uk_api_app_auth_app_api (app_id, api_id),
key idx_api_app_auth_api_id (api_id)
) engine=innodb comment = '应用与接口授权关系表';
-- ----------------------------
-- 5、开放平台开发者账号表
-- ----------------------------
create table if not exists api_user (
id bigint(20) not null comment '开发者/用户ID',
user_name varchar(64) not null comment '登录账号/用户名',
nick_name varchar(64) default null comment '用户昵称',
password varchar(100) default null comment '登录密码(BCrypt密文)',
email varchar(128) default null comment '用户邮箱(用于账单及调用告警)',
phonenumber varchar(20) default null comment '手机号码',
avatar varchar(255) default null comment '用户头像URL',
status char(1) default '0' comment '帐号状态(0正常 1停用 2已冻结)',
login_ip varchar(128) default null comment '最后登录IP',
login_date datetime comment '最后登录时间',
del_flag char(1) default '0' comment '删除标志(0代表存在 1代表删除)',
create_dept bigint(20) default null comment '创建部门',
create_by bigint(20) default null comment '创建者',
create_time datetime comment '创建时间',
update_by bigint(20) default null comment '更新者',
update_time datetime comment '更新时间',
remark varchar(500) default null comment '备注说明',
primary key (id),
key idx_api_user_user_name (user_name),
key idx_api_user_email (email),
key idx_api_user_status (status)
) engine=innodb comment = '开放平台开发者账号表';
-- ----------------------------------------------------------------------------
-- 第二部分:后台菜单路由(sys_menu)
-- 目录 1761400000000002001;功能菜单 1761400000000002101-2105;按钮 1761400000000002211 起逐条 +1
-- ----------------------------------------------------------------------------
-- 一级目录
insert into sys_menu select 1761400000000002001, '开放平台', 0, 2, 'openapi', null, '', 'N', 'Y', 'M', '0', '0', '', 'international', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '开放平台目录' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002001);
-- 功能菜单
insert into sys_menu select 1761400000000002101, 'API分类', 1761400000000002001, 1, 'category', 'openapi/category/index', '', 'N', 'Y', 'C', '0', '0', 'openapi:category:list', 'tree', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, 'API分类菜单' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002101);
insert into sys_menu select 1761400000000002102, 'API接口', 1761400000000002001, 2, 'api', 'openapi/api/index', '', 'N', 'Y', 'C', '0', '0', 'openapi:api:list', 'swagger', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, 'API接口菜单' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002102);
insert into sys_menu select 1761400000000002103, '应用管理', 1761400000000002001, 4, 'app', 'openapi/app/index', '', 'N', 'Y', 'C', '0', '0', 'openapi:app:list', 'star', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '开发者应用菜单' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002103);
insert into sys_menu select 1761400000000002104, '授权管理', 1761400000000002001, 5, 'auth', 'openapi/auth/index', '', 'N', 'Y', 'C', '0', '0', 'openapi:auth:list', 'lock', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '应用授权菜单' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002104);
insert into sys_menu select 1761400000000002105, '开发者账号', 1761400000000002001, 3, 'user', 'openapi/user/index', '', 'N', 'Y', 'C', '0', '0', 'openapi:user:list', 'user', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '开发者账号菜单' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002105);
-- API分类按钮
insert into sys_menu select 1761400000000002211, '分类查询', 1761400000000002101, 1, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:category:query', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002211);
insert into sys_menu select 1761400000000002212, '分类新增', 1761400000000002101, 2, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:category:add', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002212);
insert into sys_menu select 1761400000000002213, '分类修改', 1761400000000002101, 3, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:category:edit', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002213);
insert into sys_menu select 1761400000000002214, '分类删除', 1761400000000002101, 4, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:category:remove', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002214);
insert into sys_menu select 1761400000000002215, '分类导出', 1761400000000002101, 5, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:category:export', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002215);
-- API接口按钮
insert into sys_menu select 1761400000000002216, '接口查询', 1761400000000002102, 1, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:api:query', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002216);
insert into sys_menu select 1761400000000002217, '接口新增', 1761400000000002102, 2, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:api:add', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002217);
insert into sys_menu select 1761400000000002218, '接口修改', 1761400000000002102, 3, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:api:edit', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002218);
insert into sys_menu select 1761400000000002219, '接口删除', 1761400000000002102, 4, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:api:remove', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002219);
insert into sys_menu select 1761400000000002220, '接口导出', 1761400000000002102, 5, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:api:export', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002220);
-- 应用管理按钮
insert into sys_menu select 1761400000000002221, '应用查询', 1761400000000002103, 1, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:app:query', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002221);
insert into sys_menu select 1761400000000002222, '应用新增', 1761400000000002103, 2, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:app:add', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002222);
insert into sys_menu select 1761400000000002223, '应用修改', 1761400000000002103, 3, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:app:edit', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002223);
insert into sys_menu select 1761400000000002224, '应用删除', 1761400000000002103, 4, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:app:remove', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002224);
insert into sys_menu select 1761400000000002225, '应用导出', 1761400000000002103, 5, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:app:export', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002225);
-- 授权管理按钮
insert into sys_menu select 1761400000000002226, '授权查询', 1761400000000002104, 1, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:auth:query', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002226);
insert into sys_menu select 1761400000000002227, '授权新增', 1761400000000002104, 2, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:auth:add', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002227);
insert into sys_menu select 1761400000000002228, '授权修改', 1761400000000002104, 3, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:auth:edit', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002228);
insert into sys_menu select 1761400000000002229, '授权删除', 1761400000000002104, 4, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:auth:remove', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002229);
insert into sys_menu select 1761400000000002230, '授权导出', 1761400000000002104, 5, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:auth:export', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002230);
-- 开发者账号按钮
insert into sys_menu select 1761400000000002231, '账号查询', 1761400000000002105, 1, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:user:query', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002231);
insert into sys_menu select 1761400000000002232, '账号新增', 1761400000000002105, 2, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:user:add', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002232);
insert into sys_menu select 1761400000000002233, '账号修改', 1761400000000002105, 3, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:user:edit', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002233);
insert into sys_menu select 1761400000000002234, '重置密码', 1761400000000002105, 4, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:user:resetPwd', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002234);
insert into sys_menu select 1761400000000002235, '账号删除', 1761400000000002105, 5, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:user:remove', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002235);
insert into sys_menu select 1761400000000002236, '账号导出', 1761400000000002105, 6, '', '', '', 'N', 'Y', 'F', '0', '0', 'openapi:user:export', '#', '', '', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '' from dual where not exists (select 1 from sys_menu where menu_id = 1761400000000002236);
-- ----------------------------------------------------------------------------
-- 第三部分:系统字典(sys_dict_type / sys_dict_data)
-- 字典类型 1761500000000000110-115;字典数据 1761600000000000200 起逐条 +1
-- ----------------------------------------------------------------------------
-- 3.1 字典类型
insert into sys_dict_type (dict_id, dict_name, dict_type, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761500000000000110, '开放平台账号状态', 'openapi_user_status', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '开发者账号状态列表'
from dual
where not exists (select 1 from sys_dict_type where dict_type = 'openapi_user_status');
insert into sys_dict_type (dict_id, dict_name, dict_type, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761500000000000111, '开放平台应用状态', 'openapi_app_status', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '开发者应用状态列表'
from dual
where not exists (select 1 from sys_dict_type where dict_type = 'openapi_app_status');
insert into sys_dict_type (dict_id, dict_name, dict_type, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761500000000000112, '接口授权状态', 'openapi_auth_status', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '应用与接口授权状态列表'
from dual
where not exists (select 1 from sys_dict_type where dict_type = 'openapi_auth_status');
insert into sys_dict_type (dict_id, dict_name, dict_type, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761500000000000113, 'API接口状态', 'openapi_api_status', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '开放 API 接口状态列表'
from dual
where not exists (select 1 from sys_dict_type where dict_type = 'openapi_api_status');
insert into sys_dict_type (dict_id, dict_name, dict_type, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761500000000000114, 'API计费模式', 'openapi_charge_type', 1761000000000000103, 1761100000000000001, sysdate(), null, null, 'API 接口计费模式列表'
from dual
where not exists (select 1 from sys_dict_type where dict_type = 'openapi_charge_type');
insert into sys_dict_type (dict_id, dict_name, dict_type, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761500000000000115, 'API请求方法', 'openapi_api_method', 1761000000000000103, 1761100000000000001, sysdate(), null, null, 'API 接口请求方法列表'
from dual
where not exists (select 1 from sys_dict_type where dict_type = 'openapi_api_method');
-- 3.2 字典数据
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000200, 1, '正常', '0', 'openapi_user_status', '', 'primary', 'Y', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '账号状态-正常'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_user_status' and dict_value = '0');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000201, 2, '停用', '1', 'openapi_user_status', '', 'warning', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '账号状态-停用'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_user_status' and dict_value = '1');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000202, 3, '已冻结', '2', 'openapi_user_status', '', 'danger', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '账号状态-已冻结'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_user_status' and dict_value = '2');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000203, 1, '正常', '0', 'openapi_app_status', '', 'primary', 'Y', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '应用状态-正常'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_app_status' and dict_value = '0');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000204, 2, '禁用', '1', 'openapi_app_status', '', 'danger', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '应用状态-禁用'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_app_status' and dict_value = '1');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000205, 1, '已开通', '0', 'openapi_auth_status', '', 'primary', 'Y', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '授权状态-已开通'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_auth_status' and dict_value = '0');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000206, 2, '已暂停', '1', 'openapi_auth_status', '', 'warning', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '授权状态-已暂停'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_auth_status' and dict_value = '1');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000207, 3, '待审核', '2', 'openapi_auth_status', '', 'info', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '授权状态-待审核'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_auth_status' and dict_value = '2');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000208, 4, '已驳回', '3', 'openapi_auth_status', '', 'danger', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '授权状态-已驳回'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_auth_status' and dict_value = '3');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000209, 1, '正常', '0', 'openapi_api_status', '', 'primary', 'Y', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '接口状态-正常'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_api_status' and dict_value = '0');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000210, 2, '停用', '1', 'openapi_api_status', '', 'danger', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '接口状态-停用'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_api_status' and dict_value = '1');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000211, 3, '维护中', '2', 'openapi_api_status', '', 'warning', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '接口状态-维护中'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_api_status' and dict_value = '2');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000212, 1, '免费', '0', 'openapi_charge_type', '', 'success', 'Y', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '计费模式-免费'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_charge_type' and dict_value = '0');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000213, 2, '按次扣费', '1', 'openapi_charge_type', '', 'primary', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '计费模式-按次扣费'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_charge_type' and dict_value = '1');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000214, 3, '仅限套餐包', '2', 'openapi_charge_type', '', 'warning', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '计费模式-仅限套餐包'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_charge_type' and dict_value = '2');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000215, 1, 'GET', 'GET', 'openapi_api_method', '', 'info', 'Y', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '请求方法-GET'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_api_method' and dict_value = 'GET');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000216, 2, 'POST', 'POST', 'openapi_api_method', '', 'info', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '请求方法-POST'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_api_method' and dict_value = 'POST');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000217, 3, 'PUT', 'PUT', 'openapi_api_method', '', 'info', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '请求方法-PUT'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_api_method' and dict_value = 'PUT');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000218, 4, 'DELETE', 'DELETE', 'openapi_api_method', '', 'info', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '请求方法-DELETE'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_api_method' and dict_value = 'DELETE');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000219, 5, 'PATCH', 'PATCH', 'openapi_api_method', '', 'info', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '请求方法-PATCH'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_api_method' and dict_value = 'PATCH');
insert into sys_dict_data (dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, create_dept, create_by, create_time, update_by, update_time, remark)
select 1761600000000000220, 6, 'ALL', 'ALL', 'openapi_api_method', '', 'info', 'N', 1761000000000000103, 1761100000000000001, sysdate(), null, null, '请求方法-ALL'
from dual where not exists (select 1 from sys_dict_data where dict_type = 'openapi_api_method' and dict_value = 'ALL');
@@ -67,7 +67,7 @@ public class ApiPackageVo implements Serializable {
* 状态(0上架 1下架)
*/
@ExcelProperty(value = "状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=上架,1=下架")
@ExcelDictFormat(dictType = "billing_package_status")
private String status;
/**
@@ -55,14 +55,14 @@ public class ApiRechargeOrderVo implements Serializable {
* 支付方式(1微信 2支付宝 3对公转账 4加密货币)
*/
@ExcelProperty(value = "支付方式", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "1=微信,2=支付宝,3=对公转账,4=加密货币")
@ExcelDictFormat(dictType = "billing_pay_type")
private String payType;
/**
* 支付状态(0待支付 1支付成功 2支付失败 3已取消)
*/
@ExcelProperty(value = "支付状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=待支付,1=支付成功,2=支付失败,3=已取消")
@ExcelDictFormat(dictType = "billing_pay_status")
private String payStatus;
/**
@@ -72,7 +72,7 @@ public class ApiUserPackageVo implements Serializable {
* 状态(0有效 1已耗尽 2已过期)
*/
@ExcelProperty(value = "状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=有效,1=已耗尽,2=已过期")
@ExcelDictFormat(dictType = "billing_user_package_status")
private String status;
/**
@@ -67,7 +67,7 @@ public class ApiUserWalletVo implements Serializable {
* 状态(0正常 1冻结)
*/
@ExcelProperty(value = "状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=正常,1=冻结")
@ExcelDictFormat(dictType = "billing_wallet_status")
private String status;
/**
@@ -49,7 +49,7 @@ public class ApiWalletFlowVo implements Serializable {
* 变动类型(1充值入账 2调用扣费 3购买次数包 4人工调账 5退款)
*/
@ExcelProperty(value = "变动类型", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "1=充值入账,2=调用扣费,3=购买次数包,4=人工调账,5=退款")
@ExcelDictFormat(dictType = "billing_flow_type")
private String type;
/**
@@ -97,14 +97,14 @@ public class ApiCallLogVo implements Serializable {
* 是否计费(0未计费 1已计费)
*/
@ExcelProperty(value = "是否计费", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=未计费,1=已计费")
@ExcelDictFormat(dictType = "calllog_charge_flag")
private String isCharge;
/**
* 扣费模式(0无 1扣免费额度 2扣次数包 3扣钱包余额)
*/
@ExcelProperty(value = "扣费模式", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=无,1=扣免费额度,2=扣次数包,3=扣钱包余额")
@ExcelDictFormat(dictType = "calllog_charge_mode")
private String chargeMode;
/**
@@ -51,7 +51,7 @@ public class ApiInfo extends BaseEntity {
private String path;
/**
* 请求方法(GET、POST、ALL)
* 请求方法(GET、POST、PUT、DELETE、PATCH、ALL)
*/
private String method;
@@ -74,16 +74,17 @@ public class ApiAppAuthVo implements Serializable {
private String path;
/**
* 请求方法(GET、POST、ALL)
* 请求方法(GET、POST、PUT、DELETE、PATCH、ALL)
*/
@ExcelProperty(value = "请求方法")
@ExcelProperty(value = "请求方法", converter = ExcelDictConvert.class)
@ExcelDictFormat(dictType = "openapi_api_method")
private String method;
/**
* 接口计费模式(0免费 1按次扣费 2仅限套餐包)
*/
@ExcelProperty(value = "计费模式", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=免费,1=按次扣费,2=仅限套餐包")
@ExcelDictFormat(dictType = "openapi_charge_type")
private String chargeType;
/**
@@ -96,7 +97,7 @@ public class ApiAppAuthVo implements Serializable {
* 授权状态(0已开通 1已暂停 2待审核 3已驳回)
*/
@ExcelProperty(value = "授权状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=已开通,1=已暂停,2=待审核,3=已驳回")
@ExcelDictFormat(dictType = "openapi_auth_status")
private String authStatus;
/**
@@ -83,7 +83,7 @@ public class ApiAppVo implements Serializable {
* 状态(0正常 1禁用)
*/
@ExcelProperty(value = "状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=正常,1=禁用")
@ExcelDictFormat(dictType = "openapi_app_status")
private String status;
/**
@@ -48,7 +48,7 @@ public class ApiCategoryVo implements Serializable {
* 状态(0正常 1停用)
*/
@ExcelProperty(value = "状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=正常,1=停用")
@ExcelDictFormat(dictType = "sys_normal_disable")
private String status;
/**
@@ -63,9 +63,10 @@ public class ApiInfoVo implements Serializable {
private String path;
/**
* 请求方法(GET、POST、ALL)
* 请求方法(GET、POST、PUT、DELETE、PATCH、ALL)
*/
@ExcelProperty(value = "请求方法")
@ExcelProperty(value = "请求方法", converter = ExcelDictConvert.class)
@ExcelDictFormat(dictType = "openapi_api_method")
private String method;
/**
@@ -84,7 +85,7 @@ public class ApiInfoVo implements Serializable {
* 计费模式(0免费 1按次扣费 2仅限套餐包)
*/
@ExcelProperty(value = "计费模式", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=免费,1=按次扣费,2=仅限套餐包")
@ExcelDictFormat(dictType = "openapi_charge_type")
private String chargeType;
/**
@@ -109,7 +110,7 @@ public class ApiInfoVo implements Serializable {
* 接口状态(0正常/上线 1停用/下线 2维护中)
*/
@ExcelProperty(value = "接口状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=正常,1=停用,2=维护中")
@ExcelDictFormat(dictType = "openapi_api_status")
private String status;
/**
@@ -69,7 +69,7 @@ public class ApiUserVo implements Serializable {
* 帐号状态(0正常 1停用 2已冻结)
*/
@ExcelProperty(value = "帐号状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=正常,1=停用,2=已冻结")
@ExcelDictFormat(dictType = "openapi_user_status")
private String status;
/**