feat: 修复工作区状态并提交CRUD生成文件

- 修复文件权限 (600→644)
- 删除调试日志 (global_func.py)
- 添加 CRUD 生成的 wwwroot 文件 (pipeline_core/dist/ops)
- 添加 mysql.ddl.sql 文件
- 更新 pyproject.toml 配置
- 添加 showcase 模块安装 (build.sh)
- 更新 index.ui (sidebar toggle + 管理按钮)
- 设置 start.sh/stop.sh 可执行权限
- 添加 wwwroot 符号链接 (appbase/rbac/pipeline_sdlc)
- 更新 .gitignore (排除 pkgs/bricks/pipeline.pid)
This commit is contained in:
yumoqing 2026-06-26 16:44:23 +08:00
parent 62f1f9d000
commit 17331c770a
17 changed files with 1815 additions and 9 deletions

116
mysql.ddl.sql Normal file
View File

@ -0,0 +1,116 @@
-- models/pipeline_capacity.json
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists pipeline_capacity;
CREATE TABLE pipeline_capacity
(
`id` VARCHAR(32) NOT NULL comment '主键',
`pipeline_id` VARCHAR(32) NOT NULL comment '产线ID',
`max_concurrent` int comment '最大并发数',
`daily_limit` int comment '每日限额',
`monthly_limit` int comment '每月限额',
`today_usage` int comment '今日用量',
`month_usage` int comment '本月用量',
`status` VARCHAR(20) DEFAULT 'active' comment '状态',
`org_id` VARCHAR(32) DEFAULT '0' comment '所属组织',
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '更新时间'
,primary key(id)
)
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb
comment '产线容量表'
;
CREATE UNIQUE INDEX pipeline_capacity_uk_capacity_pipeline ON pipeline_capacity(pipeline_id);
-- models/pipeline_pricing.json
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists pipeline_pricing;
CREATE TABLE pipeline_pricing
(
`id` VARCHAR(32) NOT NULL comment '主键',
`pipeline_id` VARCHAR(32) NOT NULL comment '产线ID',
`pricing_type` VARCHAR(20) NOT NULL comment '计费方式',
`unit_price` double(15,4) NOT NULL DEFAULT '0' comment '单价',
`currency` VARCHAR(10) DEFAULT 'CNY' comment '货币',
`pricing_config` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '定价配置JSON',
`effective_date` date comment '生效日期',
`expiry_date` date comment '失效日期',
`status` VARCHAR(20) DEFAULT 'active' comment '状态',
`org_id` VARCHAR(32) DEFAULT '0' comment '所属组织',
`created_by` VARCHAR(32) comment '创建人',
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间',
`updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '更新时间'
,primary key(id)
)
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb
comment '产线定价表'
;
CREATE INDEX pipeline_pricing_idx_pricing_pipeline ON pipeline_pricing(pipeline_id);
CREATE INDEX pipeline_pricing_idx_pricing_status_date ON pipeline_pricing(status,effective_date);
-- models/pipeline_usage_log.json
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists pipeline_usage_log;
CREATE TABLE pipeline_usage_log
(
`id` VARCHAR(32) NOT NULL comment '主键',
`pipeline_id` VARCHAR(32) NOT NULL comment '产线ID',
`user_id` VARCHAR(32) comment '用户ID',
`distributor_id` VARCHAR(32) comment '分销商ID',
`call_count` int DEFAULT '1' comment '调用次数',
`token_input` int DEFAULT '0' comment '输入Token数',
`token_output` int DEFAULT '0' comment '输出Token数',
`amount` double(15,4) DEFAULT '0' comment '金额',
`status` VARCHAR(20) comment '状态',
`error_message` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci comment '错误信息',
`called_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '调用时间'
,primary key(id)
)
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci
engine=innodb
comment '产线调用日志表'
;
CREATE INDEX pipeline_usage_log_idx_usagelog_pipeline ON pipeline_usage_log(pipeline_id);
CREATE INDEX pipeline_usage_log_idx_usagelog_called_at ON pipeline_usage_log(called_at);
CREATE INDEX pipeline_usage_log_idx_usagelog_distributor ON pipeline_usage_log(distributor_id);

View File

@ -1,12 +1,9 @@
[project]
name = "pipeline_ops"
version = "1.0.0"
description = "Pipeline operations module - pricing, capacity, and usage tracking"
dependencies = [
"sqlor",
"bricks_for_python"
]
version = "0.1.0"
description = "产线运维模块"
dependencies = ["sqlor"]
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[tool.setuptools.packages.find]
where = ["."]
include = ["pipeline_ops*"]

View File

@ -0,0 +1,51 @@
ns = params_kw.copy()
for k,v in ns.items():
if v == 'NaN' or v == 'null':
ns[k] = None
id = params_kw.id
if not id or len(id) > 32:
id = uuid()
ns['id'] = id
userorgid = await get_userorgid()
if not userorgid:
return {
"widgettype":"Error",
"options":{
"title":"Authorization Error",
"timeout":3,
"cwidth":16,
"cheight":9,
"message":"Please login"
}
}
ns['org_id'] = userorgid
db = DBPools()
dbname = get_module_dbname('pipeline_ops')
async with db.sqlorContext(dbname) as sor:
r = await sor.C('pipeline_capacity', ns.copy())
return {
"widgettype":"Message",
"options":{
"cwidth":16,
"cheight":9,
"title":"Add Success",
"timeout":3,
"message":"ok"
}
}
return {
"widgettype":"Error",
"options":{
"title":"Add Error",
"cwidth":16,
"cheight":9,
"timeout":3,
"message":"failed"
}
}

View File

@ -0,0 +1,47 @@
ns = {
'id':params_kw['id'],
}
userorgid = await get_userorgid()
if not userorgid:
return {
"widgettype":"Error",
"options":{
"title":"Authorization Error",
"timeout":3,
"cwidth":16,
"cheight":9,
"message":"Please login"
}
}
ns['org_id'] = userorgid
db = DBPools()
dbname = get_module_dbname('pipeline_ops')
async with db.sqlorContext(dbname) as sor:
r = await sor.D('pipeline_capacity', ns)
debug('delete success');
return {
"widgettype":"Message",
"options":{
"title":"Delete Success",
"timeout":3,
"cwidth":16,
"cheight":9,
"message":"ok"
}
}
debug('Delete failed');
return {
"widgettype":"Error",
"options":{
"title":"Delete Error",
"timeout":3,
"cwidth":16,
"cheight":9,
"message":"failed"
}
}

View File

@ -0,0 +1,142 @@
ns = params_kw.copy()
userorgid = await get_userorgid()
if not userorgid:
return {
"widgettype":"Error",
"options":{
"title":"Authorization Error",
"timeout":3,
"cwidth":16,
"cheight":9,
"message":"Please login"
}
}
ns['org_id'] = userorgid
ns['userorgid'] = userorgid
debug(f'get_pipeline_capacity.dspy:{ns=}')
if not ns.get('page'):
ns['page'] = 1
if not ns.get('sort'):
ns['sort'] = ["pipeline_id"]
sql = '''select a.*, b.pipeline_id_text, c.status_text
from (select * from pipeline_capacity where 1=1 [[filterstr]]) a left join (select id as pipeline_id,
name as pipeline_id_text from pipelines where 1 = 1) b on a.pipeline_id = b.pipeline_id left join (select k as status,
v as status_text from appcodes_kv where parentid='capacity_status') c on a.status = c.status'''
filterjson = params_kw.get('data_filter')
if filterjson and isinstance(filterjson, str):
try:
filterjson = json.loads(filterjson)
except (json.JSONDecodeError, TypeError):
filterjson = None
fields_str=r'''[
{
"name": "id",
"title": "主键",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "pipeline_id",
"title": "产线ID",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "max_concurrent",
"title": "最大并发数",
"type": "int"
},
{
"name": "daily_limit",
"title": "每日限额",
"type": "int"
},
{
"name": "monthly_limit",
"title": "每月限额",
"type": "int"
},
{
"name": "today_usage",
"title": "今日用量",
"type": "int"
},
{
"name": "month_usage",
"title": "本月用量",
"type": "int"
},
{
"name": "status",
"title": "状态",
"type": "str",
"length": 20,
"default": "active"
},
{
"name": "org_id",
"title": "所属组织",
"type": "str",
"length": 32,
"default": "0"
},
{
"name": "updated_at",
"title": "更新时间",
"type": "timestamp"
}
]'''
ori_fields = json.loads(fields_str)
if not filterjson:
fields = [ f['name'] for f in ori_fields ]
filterjson = default_filterjson(fields, ns)
# 确保 logined 过滤条件始终生效
if filterjson:
if not isinstance(filterjson, dict) or 'AND' not in filterjson:
filterjson = {'AND': [filterjson] if filterjson else []}
filterjson['AND'].append({'field': 'org_id', 'op': '=', 'var': '__logined_orgid__'})
ns['__logined_orgid__'] = userorgid
filterdic = ns.copy()
filterdic['filterstr'] = ''
filterdic['userorgid'] = '${userorgid}$'
filterdic['userid'] = '${userid}$'
if filterjson:
dbf = DBFilter(filterjson)
conds = dbf.gen(ns)
if conds:
ns.update(dbf.consts)
conds = f' and {conds}'
filterdic['filterstr'] = conds
ac = ArgsConvert('[[', ']]')
vars = ac.findAllVariables(sql)
NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' }
filterdic.update(NameSpace)
sql = ac.convert(sql, filterdic)
debug(f'{sql=}')
db = DBPools()
dbname = get_module_dbname('pipeline_ops')
async with db.sqlorContext(dbname) as sor:
r = await sor.sqlPaging(sql, ns)
return r
return {
"total":0,
"rows":[]
}

View File

@ -0,0 +1,227 @@
{
"widgettype":"VBox",
"options":{"cheight":40,"width":"100%"},
"subwidgets":[{
"id":"pipeline_capacity_tbl",
"widgettype":"Tabular",
"options":{
"width":"100%",
"height":"100%",
"title":"产线容量表",
"css":"card",
"editable":{
"new_data_url":"{{entire_url('add_pipeline_capacity.dspy')}}",
"delete_data_url":"{{entire_url('delete_pipeline_capacity.dspy')}}",
"update_data_url":"{{entire_url('update_pipeline_capacity.dspy')}}"
},
"data_url":"{{entire_url('./get_pipeline_capacity.dspy')}}",
"data_method":"GET",
"data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}},
"row_options":{
"browserfields": {
"exclouded": [
"id"
],
"alters": {
"pipeline_id": {
"uitype": "code",
"dataurl": "{{entire_url('../api/get_search_pipeline_id.dspy')}}"
},
"status": {
"uitype": "code",
"data": [
{
"value": "active",
"text": "生效中"
},
{
"value": "disabled",
"text": "已停用"
}
]
}
}
},
"fields":[
{
"name": "id",
"title": "主键",
"type": "str",
"length": 32,
"nullable": "no",
"cwidth": 18,
"uitype": "str",
"datatype": "str",
"label": "主键"
},
{
"name": "pipeline_id",
"title": "产线ID",
"type": "str",
"length": 32,
"nullable": "no",
"label": "产线ID",
"uitype": "code",
"valueField": "pipeline_id",
"textField": "pipeline_id_text",
"params": {
"dbname": "{{get_module_dbname('pipeline_ops')}}",
"table": "pipelines",
"tblvalue": "id",
"tbltext": "name",
"valueField": "pipeline_id",
"textField": "pipeline_id_text"
},
"dataurl": "{{entire_url('../api/get_search_pipeline_id.dspy')}}"
},
{
"name": "max_concurrent",
"title": "最大并发数",
"type": "int",
"length": 0,
"uitype": "int",
"datatype": "int",
"label": "最大并发数"
},
{
"name": "daily_limit",
"title": "每日限额",
"type": "int",
"length": 0,
"uitype": "int",
"datatype": "int",
"label": "每日限额"
},
{
"name": "monthly_limit",
"title": "每月限额",
"type": "int",
"length": 0,
"uitype": "int",
"datatype": "int",
"label": "每月限额"
},
{
"name": "today_usage",
"title": "今日用量",
"type": "int",
"length": 0,
"uitype": "int",
"datatype": "int",
"label": "今日用量"
},
{
"name": "month_usage",
"title": "本月用量",
"type": "int",
"length": 0,
"uitype": "int",
"datatype": "int",
"label": "本月用量"
},
{
"name": "status",
"title": "状态",
"type": "str",
"length": 20,
"default": "active",
"label": "状态",
"uitype": "code",
"valueField": "status",
"textField": "status_text",
"params": {
"dbname": "{{get_module_dbname('pipeline_ops')}}",
"table": "appcodes_kv",
"tblvalue": "k",
"tbltext": "v",
"valueField": "status",
"textField": "status_text",
"cond": "parentid='capacity_status'"
},
"dataurl": "{{entire_url('/appbase/get_code.dspy')}}",
"data": [
{
"value": "active",
"text": "生效中"
},
{
"value": "disabled",
"text": "已停用"
}
]
},
{
"name": "org_id",
"title": "所属组织",
"type": "str",
"length": 32,
"default": "0",
"cwidth": 18,
"uitype": "str",
"datatype": "str",
"label": "所属组织"
},
{
"name": "updated_at",
"title": "更新时间",
"type": "timestamp",
"length": 0,
"uitype": "str",
"datatype": "timestamp",
"label": "更新时间"
}
]
},
"data_filter":{
"AND": [
{
"field": "pipeline_id",
"op": "=",
"var": "filter_pipeline_id"
},
{
"field": "status",
"op": "=",
"var": "filter_status"
}
]
},
"page_rows":160,
"cache_limit":5
}
,"binds":[]
}]
}

View File

@ -0,0 +1,70 @@
ns = params_kw.copy()
for k,v in ns.items():
if v == 'NaN' or v == 'null':
ns[k] = None
userorgid = await get_userorgid()
if not userorgid:
return {
"widgettype":"Error",
"options":{
"title":"Authorization Error",
"timeout":3,
"cwidth":16,
"cheight":9,
"message":"Please login"
}
}
ns['org_id'] = userorgid
db = DBPools()
dbname = get_module_dbname('pipeline_ops')
async with db.sqlorContext(dbname) as sor:
ns1 = {
"org_id": userorgid,
"id": params_kw.id
}
recs = await sor.R('pipeline_capacity', ns1)
if len(recs) < 1:
return {
"widgettype":"Error",
"options":{
"title":"Update Error",
"cwidth":16,
"cheight":9,
"timeout":3,
"message":"Record no exist or with wrong ownership"
}
}
r = await sor.U('pipeline_capacity', ns)
debug('update success');
return {
"widgettype":"Message",
"options":{
"title":"Update Success",
"cwidth":16,
"cheight":9,
"timeout":3,
"message":"ok"
}
}
return {
"widgettype":"Error",
"options":{
"title":"Update Error",
"cwidth":16,
"cheight":9,
"timeout":3,
"message":"failed"
}
}

View File

@ -0,0 +1,51 @@
ns = params_kw.copy()
for k,v in ns.items():
if v == 'NaN' or v == 'null':
ns[k] = None
id = params_kw.id
if not id or len(id) > 32:
id = uuid()
ns['id'] = id
userorgid = await get_userorgid()
if not userorgid:
return {
"widgettype":"Error",
"options":{
"title":"Authorization Error",
"timeout":3,
"cwidth":16,
"cheight":9,
"message":"Please login"
}
}
ns['org_id'] = userorgid
db = DBPools()
dbname = get_module_dbname('pipeline_ops')
async with db.sqlorContext(dbname) as sor:
r = await sor.C('pipeline_pricing', ns.copy())
return {
"widgettype":"Message",
"options":{
"cwidth":16,
"cheight":9,
"title":"Add Success",
"timeout":3,
"message":"ok"
}
}
return {
"widgettype":"Error",
"options":{
"title":"Add Error",
"cwidth":16,
"cheight":9,
"timeout":3,
"message":"failed"
}
}

View File

@ -0,0 +1,47 @@
ns = {
'id':params_kw['id'],
}
userorgid = await get_userorgid()
if not userorgid:
return {
"widgettype":"Error",
"options":{
"title":"Authorization Error",
"timeout":3,
"cwidth":16,
"cheight":9,
"message":"Please login"
}
}
ns['org_id'] = userorgid
db = DBPools()
dbname = get_module_dbname('pipeline_ops')
async with db.sqlorContext(dbname) as sor:
r = await sor.D('pipeline_pricing', ns)
debug('delete success');
return {
"widgettype":"Message",
"options":{
"title":"Delete Success",
"timeout":3,
"cwidth":16,
"cheight":9,
"message":"ok"
}
}
debug('Delete failed');
return {
"widgettype":"Error",
"options":{
"title":"Delete Error",
"timeout":3,
"cwidth":16,
"cheight":9,
"message":"failed"
}
}

View File

@ -0,0 +1,168 @@
ns = params_kw.copy()
userorgid = await get_userorgid()
if not userorgid:
return {
"widgettype":"Error",
"options":{
"title":"Authorization Error",
"timeout":3,
"cwidth":16,
"cheight":9,
"message":"Please login"
}
}
ns['org_id'] = userorgid
ns['userorgid'] = userorgid
debug(f'get_pipeline_pricing.dspy:{ns=}')
if not ns.get('page'):
ns['page'] = 1
if not ns.get('sort'):
ns['sort'] = ["effective_date desc"]
sql = '''select a.*, b.pipeline_id_text, c.pricing_type_text, d.currency_text, e.status_text
from (select * from pipeline_pricing where 1=1 [[filterstr]]) a left join (select id as pipeline_id,
name as pipeline_id_text from pipelines where 1 = 1) b on a.pipeline_id = b.pipeline_id left join (select k as pricing_type,
v as pricing_type_text from appcodes_kv where parentid='pricing_type') c on a.pricing_type = c.pricing_type left join (select k as currency,
v as currency_text from appcodes_kv where parentid='currency') d on a.currency = d.currency left join (select k as status,
v as status_text from appcodes_kv where parentid='pricing_status') e on a.status = e.status'''
filterjson = params_kw.get('data_filter')
if filterjson and isinstance(filterjson, str):
try:
filterjson = json.loads(filterjson)
except (json.JSONDecodeError, TypeError):
filterjson = None
fields_str=r'''[
{
"name": "id",
"title": "主键",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "pipeline_id",
"title": "产线ID",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "pricing_type",
"title": "计费方式",
"type": "str",
"length": 20,
"nullable": "no"
},
{
"name": "unit_price",
"title": "单价",
"type": "double",
"length": 15,
"dec": 4,
"nullable": "no",
"default": "0"
},
{
"name": "currency",
"title": "货币",
"type": "str",
"length": 10,
"default": "CNY"
},
{
"name": "pricing_config",
"title": "定价配置JSON",
"type": "text"
},
{
"name": "effective_date",
"title": "生效日期",
"type": "date"
},
{
"name": "expiry_date",
"title": "失效日期",
"type": "date"
},
{
"name": "status",
"title": "状态",
"type": "str",
"length": 20,
"default": "active"
},
{
"name": "org_id",
"title": "所属组织",
"type": "str",
"length": 32,
"default": "0"
},
{
"name": "created_by",
"title": "创建人",
"type": "str",
"length": 32
},
{
"name": "created_at",
"title": "创建时间",
"type": "timestamp"
},
{
"name": "updated_at",
"title": "更新时间",
"type": "timestamp"
}
]'''
ori_fields = json.loads(fields_str)
if not filterjson:
fields = [ f['name'] for f in ori_fields ]
filterjson = default_filterjson(fields, ns)
# 确保 logined 过滤条件始终生效
if filterjson:
if not isinstance(filterjson, dict) or 'AND' not in filterjson:
filterjson = {'AND': [filterjson] if filterjson else []}
filterjson['AND'].append({'field': 'org_id', 'op': '=', 'var': '__logined_orgid__'})
ns['__logined_orgid__'] = userorgid
filterdic = ns.copy()
filterdic['filterstr'] = ''
filterdic['userorgid'] = '${userorgid}$'
filterdic['userid'] = '${userid}$'
if filterjson:
dbf = DBFilter(filterjson)
conds = dbf.gen(ns)
if conds:
ns.update(dbf.consts)
conds = f' and {conds}'
filterdic['filterstr'] = conds
ac = ArgsConvert('[[', ']]')
vars = ac.findAllVariables(sql)
NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' }
filterdic.update(NameSpace)
sql = ac.convert(sql, filterdic)
debug(f'{sql=}')
db = DBPools()
dbname = get_module_dbname('pipeline_ops')
async with db.sqlorContext(dbname) as sor:
r = await sor.sqlPaging(sql, ns)
return r
return {
"total":0,
"rows":[]
}

View File

@ -0,0 +1,322 @@
{
"widgettype":"VBox",
"options":{"cheight":40,"width":"100%"},
"subwidgets":[{
"id":"pipeline_pricing_tbl",
"widgettype":"Tabular",
"options":{
"width":"100%",
"height":"100%",
"title":"产线定价表",
"css":"card",
"editable":{
"new_data_url":"{{entire_url('add_pipeline_pricing.dspy')}}",
"delete_data_url":"{{entire_url('delete_pipeline_pricing.dspy')}}",
"update_data_url":"{{entire_url('update_pipeline_pricing.dspy')}}"
},
"data_url":"{{entire_url('./get_pipeline_pricing.dspy')}}",
"data_method":"GET",
"data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}},
"row_options":{
"browserfields": {
"exclouded": [
"id"
],
"alters": {
"pipeline_id": {
"uitype": "code",
"dataurl": "{{entire_url('../api/get_search_pipeline_id.dspy')}}"
},
"pricing_type": {
"uitype": "code",
"data": [
{
"value": "per_call",
"text": "按次计费"
},
{
"value": "per_token",
"text": "按token计费"
},
{
"value": "subscription",
"text": "订阅制"
}
]
},
"status": {
"uitype": "code",
"data": [
{
"value": "active",
"text": "生效中"
},
{
"value": "expired",
"text": "已过期"
},
{
"value": "disabled",
"text": "已停用"
}
]
}
}
},
"fields":[
{
"name": "id",
"title": "主键",
"type": "str",
"length": 32,
"nullable": "no",
"cwidth": 18,
"uitype": "str",
"datatype": "str",
"label": "主键"
},
{
"name": "pipeline_id",
"title": "产线ID",
"type": "str",
"length": 32,
"nullable": "no",
"label": "产线ID",
"uitype": "code",
"valueField": "pipeline_id",
"textField": "pipeline_id_text",
"params": {
"dbname": "{{get_module_dbname('pipeline_ops')}}",
"table": "pipelines",
"tblvalue": "id",
"tbltext": "name",
"valueField": "pipeline_id",
"textField": "pipeline_id_text"
},
"dataurl": "{{entire_url('../api/get_search_pipeline_id.dspy')}}"
},
{
"name": "pricing_type",
"title": "计费方式",
"type": "str",
"length": 20,
"nullable": "no",
"label": "计费方式",
"uitype": "code",
"valueField": "pricing_type",
"textField": "pricing_type_text",
"params": {
"dbname": "{{get_module_dbname('pipeline_ops')}}",
"table": "appcodes_kv",
"tblvalue": "k",
"tbltext": "v",
"valueField": "pricing_type",
"textField": "pricing_type_text",
"cond": "parentid='pricing_type'"
},
"dataurl": "{{entire_url('/appbase/get_code.dspy')}}",
"data": [
{
"value": "per_call",
"text": "按次计费"
},
{
"value": "per_token",
"text": "按token计费"
},
{
"value": "subscription",
"text": "订阅制"
}
]
},
{
"name": "unit_price",
"title": "单价",
"type": "double",
"length": 15,
"dec": 4,
"nullable": "no",
"default": "0",
"cwidth": 15,
"uitype": "float",
"datatype": "double",
"label": "单价"
},
{
"name": "currency",
"title": "货币",
"type": "str",
"length": 10,
"default": "CNY",
"label": "货币",
"uitype": "code",
"valueField": "currency",
"textField": "currency_text",
"params": {
"dbname": "{{get_module_dbname('pipeline_ops')}}",
"table": "appcodes_kv",
"tblvalue": "k",
"tbltext": "v",
"valueField": "currency",
"textField": "currency_text",
"cond": "parentid='currency'"
},
"dataurl": "{{entire_url('/appbase/get_code.dspy')}}"
},
{
"name": "pricing_config",
"title": "定价配置JSON",
"type": "text",
"length": 0,
"uitype": "text",
"datatype": "text",
"label": "定价配置JSON"
},
{
"name": "effective_date",
"title": "生效日期",
"type": "date",
"length": 0,
"uitype": "date",
"datatype": "date",
"label": "生效日期"
},
{
"name": "expiry_date",
"title": "失效日期",
"type": "date",
"length": 0,
"uitype": "date",
"datatype": "date",
"label": "失效日期"
},
{
"name": "status",
"title": "状态",
"type": "str",
"length": 20,
"default": "active",
"label": "状态",
"uitype": "code",
"valueField": "status",
"textField": "status_text",
"params": {
"dbname": "{{get_module_dbname('pipeline_ops')}}",
"table": "appcodes_kv",
"tblvalue": "k",
"tbltext": "v",
"valueField": "status",
"textField": "status_text",
"cond": "parentid='pricing_status'"
},
"dataurl": "{{entire_url('/appbase/get_code.dspy')}}",
"data": [
{
"value": "active",
"text": "生效中"
},
{
"value": "expired",
"text": "已过期"
},
{
"value": "disabled",
"text": "已停用"
}
]
},
{
"name": "org_id",
"title": "所属组织",
"type": "str",
"length": 32,
"default": "0",
"cwidth": 18,
"uitype": "str",
"datatype": "str",
"label": "所属组织"
},
{
"name": "created_by",
"title": "创建人",
"type": "str",
"length": 32,
"cwidth": 18,
"uitype": "str",
"datatype": "str",
"label": "创建人"
},
{
"name": "created_at",
"title": "创建时间",
"type": "timestamp",
"length": 0,
"uitype": "str",
"datatype": "timestamp",
"label": "创建时间"
},
{
"name": "updated_at",
"title": "更新时间",
"type": "timestamp",
"length": 0,
"uitype": "str",
"datatype": "timestamp",
"label": "更新时间"
}
]
},
"data_filter":{
"AND": [
{
"field": "pipeline_id",
"op": "=",
"var": "filter_pipeline_id"
},
{
"field": "status",
"op": "=",
"var": "filter_status"
}
]
},
"page_rows":160,
"cache_limit":5
}
,"binds":[]
}]
}

View File

@ -0,0 +1,70 @@
ns = params_kw.copy()
for k,v in ns.items():
if v == 'NaN' or v == 'null':
ns[k] = None
userorgid = await get_userorgid()
if not userorgid:
return {
"widgettype":"Error",
"options":{
"title":"Authorization Error",
"timeout":3,
"cwidth":16,
"cheight":9,
"message":"Please login"
}
}
ns['org_id'] = userorgid
db = DBPools()
dbname = get_module_dbname('pipeline_ops')
async with db.sqlorContext(dbname) as sor:
ns1 = {
"org_id": userorgid,
"id": params_kw.id
}
recs = await sor.R('pipeline_pricing', ns1)
if len(recs) < 1:
return {
"widgettype":"Error",
"options":{
"title":"Update Error",
"cwidth":16,
"cheight":9,
"timeout":3,
"message":"Record no exist or with wrong ownership"
}
}
r = await sor.U('pipeline_pricing', ns)
debug('update success');
return {
"widgettype":"Message",
"options":{
"title":"Update Success",
"cwidth":16,
"cheight":9,
"timeout":3,
"message":"ok"
}
}
return {
"widgettype":"Error",
"options":{
"title":"Update Error",
"cwidth":16,
"cheight":9,
"timeout":3,
"message":"failed"
}
}

View File

@ -0,0 +1,37 @@
ns = params_kw.copy()
for k,v in ns.items():
if v == 'NaN' or v == 'null':
ns[k] = None
id = params_kw.id
if not id or len(id) > 32:
id = uuid()
ns['id'] = id
db = DBPools()
dbname = get_module_dbname('pipeline_ops')
async with db.sqlorContext(dbname) as sor:
r = await sor.C('pipeline_usage_log', ns.copy())
return {
"widgettype":"Message",
"options":{
"cwidth":16,
"cheight":9,
"title":"Add Success",
"timeout":3,
"message":"ok"
}
}
return {
"widgettype":"Error",
"options":{
"title":"Add Error",
"cwidth":16,
"cheight":9,
"timeout":3,
"message":"failed"
}
}

View File

@ -0,0 +1,33 @@
ns = {
'id':params_kw['id'],
}
db = DBPools()
dbname = get_module_dbname('pipeline_ops')
async with db.sqlorContext(dbname) as sor:
r = await sor.D('pipeline_usage_log', ns)
debug('delete success');
return {
"widgettype":"Message",
"options":{
"title":"Delete Success",
"timeout":3,
"cwidth":16,
"cheight":9,
"message":"ok"
}
}
debug('Delete failed');
return {
"widgettype":"Error",
"options":{
"title":"Delete Error",
"timeout":3,
"cwidth":16,
"cheight":9,
"message":"failed"
}
}

View File

@ -0,0 +1,127 @@
ns = params_kw.copy()
debug(f'get_pipeline_usage_log.dspy:{ns=}')
if not ns.get('page'):
ns['page'] = 1
if not ns.get('sort'):
ns['sort'] = ["called_at desc"]
sql = '''select a.*, b.pipeline_id_text, c.status_text
from (select * from pipeline_usage_log where 1=1 [[filterstr]]) a left join (select id as pipeline_id,
name as pipeline_id_text from pipelines where 1 = 1) b on a.pipeline_id = b.pipeline_id left join (select k as status,
v as status_text from appcodes_kv where parentid='usage_status') c on a.status = c.status'''
filterjson = params_kw.get('data_filter')
if filterjson and isinstance(filterjson, str):
try:
filterjson = json.loads(filterjson)
except (json.JSONDecodeError, TypeError):
filterjson = None
fields_str=r'''[
{
"name": "id",
"title": "主键",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "pipeline_id",
"title": "产线ID",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "user_id",
"title": "用户ID",
"type": "str",
"length": 32
},
{
"name": "distributor_id",
"title": "分销商ID",
"type": "str",
"length": 32
},
{
"name": "call_count",
"title": "调用次数",
"type": "int",
"default": "1"
},
{
"name": "token_input",
"title": "输入Token数",
"type": "int",
"default": "0"
},
{
"name": "token_output",
"title": "输出Token数",
"type": "int",
"default": "0"
},
{
"name": "amount",
"title": "金额",
"type": "double",
"length": 15,
"dec": 4,
"default": "0"
},
{
"name": "status",
"title": "状态",
"type": "str",
"length": 20
},
{
"name": "error_message",
"title": "错误信息",
"type": "text"
},
{
"name": "called_at",
"title": "调用时间",
"type": "timestamp"
}
]'''
ori_fields = json.loads(fields_str)
if not filterjson:
fields = [ f['name'] for f in ori_fields ]
filterjson = default_filterjson(fields, ns)
filterdic = ns.copy()
filterdic['filterstr'] = ''
filterdic['userorgid'] = '${userorgid}$'
filterdic['userid'] = '${userid}$'
if filterjson:
dbf = DBFilter(filterjson)
conds = dbf.gen(ns)
if conds:
ns.update(dbf.consts)
conds = f' and {conds}'
filterdic['filterstr'] = conds
ac = ArgsConvert('[[', ']]')
vars = ac.findAllVariables(sql)
NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' }
filterdic.update(NameSpace)
sql = ac.convert(sql, filterdic)
debug(f'{sql=}')
db = DBPools()
dbname = get_module_dbname('pipeline_ops')
async with db.sqlorContext(dbname) as sor:
r = await sor.sqlPaging(sql, ns)
return r
return {
"total":0,
"rows":[]
}

View File

@ -0,0 +1,265 @@
{
"widgettype":"VBox",
"options":{"cheight":40,"width":"100%"},
"subwidgets":[{
"id":"pipeline_usage_log_tbl",
"widgettype":"Tabular",
"options":{
"width":"100%",
"height":"100%",
"title":"产线调用日志表",
"css":"card",
"editable":{
"new_data_url":"{{entire_url('add_pipeline_usage_log.dspy')}}",
"delete_data_url":"{{entire_url('delete_pipeline_usage_log.dspy')}}",
"update_data_url":"{{entire_url('update_pipeline_usage_log.dspy')}}"
},
"data_url":"{{entire_url('./get_pipeline_usage_log.dspy')}}",
"data_method":"GET",
"data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}},
"row_options":{
"browserfields": {
"exclouded": [
"id"
],
"alters": {
"pipeline_id": {
"uitype": "code",
"dataurl": "{{entire_url('../api/get_search_pipeline_id.dspy')}}"
},
"status": {
"uitype": "code",
"data": [
{
"value": "success",
"text": "成功"
},
{
"value": "failed",
"text": "失败"
}
]
}
}
},
"editexclouded":[
"id",
"pipeline_id",
"user_id",
"distributor_id",
"call_count",
"token_input",
"token_output",
"amount",
"status",
"error_message",
"called_at"
],
"fields":[
{
"name": "id",
"title": "主键",
"type": "str",
"length": 32,
"nullable": "no",
"cwidth": 18,
"uitype": "str",
"datatype": "str",
"label": "主键"
},
{
"name": "pipeline_id",
"title": "产线ID",
"type": "str",
"length": 32,
"nullable": "no",
"label": "产线ID",
"uitype": "code",
"valueField": "pipeline_id",
"textField": "pipeline_id_text",
"params": {
"dbname": "{{get_module_dbname('pipeline_ops')}}",
"table": "pipelines",
"tblvalue": "id",
"tbltext": "name",
"valueField": "pipeline_id",
"textField": "pipeline_id_text"
},
"dataurl": "{{entire_url('../api/get_search_pipeline_id.dspy')}}"
},
{
"name": "user_id",
"title": "用户ID",
"type": "str",
"length": 32,
"cwidth": 18,
"uitype": "str",
"datatype": "str",
"label": "用户ID"
},
{
"name": "distributor_id",
"title": "分销商ID",
"type": "str",
"length": 32,
"cwidth": 18,
"uitype": "str",
"datatype": "str",
"label": "分销商ID"
},
{
"name": "call_count",
"title": "调用次数",
"type": "int",
"default": "1",
"length": 0,
"uitype": "int",
"datatype": "int",
"label": "调用次数"
},
{
"name": "token_input",
"title": "输入Token数",
"type": "int",
"default": "0",
"length": 0,
"uitype": "int",
"datatype": "int",
"label": "输入Token数"
},
{
"name": "token_output",
"title": "输出Token数",
"type": "int",
"default": "0",
"length": 0,
"uitype": "int",
"datatype": "int",
"label": "输出Token数"
},
{
"name": "amount",
"title": "金额",
"type": "double",
"length": 15,
"dec": 4,
"default": "0",
"cwidth": 15,
"uitype": "float",
"datatype": "double",
"label": "金额"
},
{
"name": "status",
"title": "状态",
"type": "str",
"length": 20,
"label": "状态",
"uitype": "code",
"valueField": "status",
"textField": "status_text",
"params": {
"dbname": "{{get_module_dbname('pipeline_ops')}}",
"table": "appcodes_kv",
"tblvalue": "k",
"tbltext": "v",
"valueField": "status",
"textField": "status_text",
"cond": "parentid='usage_status'"
},
"dataurl": "{{entire_url('/appbase/get_code.dspy')}}",
"data": [
{
"value": "success",
"text": "成功"
},
{
"value": "failed",
"text": "失败"
}
]
},
{
"name": "error_message",
"title": "错误信息",
"type": "text",
"length": 0,
"uitype": "text",
"datatype": "text",
"label": "错误信息"
},
{
"name": "called_at",
"title": "调用时间",
"type": "timestamp",
"length": 0,
"uitype": "str",
"datatype": "timestamp",
"label": "调用时间"
}
]
},
"data_filter":{
"AND": [
{
"field": "pipeline_id",
"op": "=",
"var": "filter_pipeline_id"
},
{
"field": "called_at",
"op": ">=",
"var": "filter_called_at_start"
},
{
"field": "called_at",
"op": "<=",
"var": "filter_called_at_end"
},
{
"field": "status",
"op": "=",
"var": "filter_status"
}
]
},
"page_rows":160,
"cache_limit":5
}
,"binds":[]
}]
}

View File

@ -0,0 +1,36 @@
ns = params_kw.copy()
for k,v in ns.items():
if v == 'NaN' or v == 'null':
ns[k] = None
db = DBPools()
dbname = get_module_dbname('pipeline_ops')
async with db.sqlorContext(dbname) as sor:
r = await sor.U('pipeline_usage_log', ns)
debug('update success');
return {
"widgettype":"Message",
"options":{
"title":"Update Success",
"cwidth":16,
"cheight":9,
"timeout":3,
"message":"ok"
}
}
return {
"widgettype":"Error",
"options":{
"title":"Update Error",
"cwidth":16,
"cheight":9,
"timeout":3,
"message":"failed"
}
}