Compare commits

..

6 Commits

Author SHA1 Message Date
96652bceb4 feat: UI pages, build.sh, deployment scripts, model uitype fixes
- Add SDLC dashboard, pipeline editor, ops center UI
- build.sh: clone business modules to pkgs/, xls2ui CRUD, fix created_by
- global_func.py: password_encode None-safe wrapper
- pipeline_app.py: permission cache warmup removed
- load_path.py: RBAC permission registration for all modules
- scripts/merge_i18n.py: i18n merge tool
- bin/init_perms.py, bin/init_data.py: init scripts
- set_role_perm.py: single permission registration
- Model uitype fields set for form editing
- pipeline_core/pipeline_ops load_path.py scripts
2026-08-03 16:20:26 +08:00
5aa80a6132 style: modernize card UI — colored icon boxes, fixed height, white bg, Title3
- pipeline_core: 3 cards with colored icon containers (blue/green/amber)
- pipeline_ops: 3 cards with icons (red/sky/purple), consistent height
- pipeline_dist: 2 cards with icons (green/orange), added distributor management card
2026-08-03 16:20:26 +08:00
77ced63b68 fix: rewrite index.ui for pipeline_ops/pipeline_dist as proper bricks cards
- pipeline_ops: VBox+ResponsableBox cards → pricing/capacity/usage_log
- pipeline_dist: VBox+ResponsableBox cards → distributor_pipeline
- main index.ui: fix task center URL (/pipeline_task→/pipeline_sdlc/sd_projects), menu cwidth
2026-08-03 16:20:26 +08:00
d483238ac5 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)
2026-08-03 16:20:26 +08:00
cec46e4f3a fix: init/data.json格式修正+model codes补全
pipeline-core:
- pipelines.json codes cond: id -> parentid

pipeline-ops:
- init/data.json: 转为Format B(parentid/parentname/items)
- pipeline_pricing.json: +4 codes(pricing_type/currency/status/pipeline_id)
- pipeline_capacity.json: +2 codes(capacity_status/pipeline_id)
- pipeline_usage_log.json: +2 codes(usage_status/pipeline_id)

pipeline-dist:
- init/data.json: 转为Format B(parentid/parentname/items)
- distributors.json: +1 code(distributor_status)
- distributor_pipeline.json: +4 codes(markup_type/dp_status/外键)
2026-08-03 16:20:26 +08:00
c92e3f1bf0 feat: pipeline-app独立产线后端服务
3个业务模块:
- pipeline_core: 产线定义(pipelines/steps/versions)
- pipeline_ops: 运营(定价/供应量/使用记录)
- pipeline_dist: 分销(分销商/独立定价/API密钥)

- ahserver独立部署(端口9090)
- 独立数据库pipeline
- 80个文件, 符合module/db-table/crud三规范
2026-08-03 16:20:26 +08:00
30 changed files with 1869 additions and 0 deletions

29
init/data.json Normal file
View File

@ -0,0 +1,29 @@
{
"appcodes": [
{
"parentid": "distributor_status",
"parentname": "分销商状态",
"items": [
{"k": "active", "v": "活跃"},
{"k": "suspended", "v": "暂停"},
{"k": "terminated", "v": "终止"}
]
},
{
"parentid": "markup_type",
"parentname": "加价方式",
"items": [
{"k": "fixed", "v": "固定加价"},
{"k": "percentage", "v": "百分比加价"}
]
},
{
"parentid": "dp_status",
"parentname": "分销产线状态",
"items": [
{"k": "enabled", "v": "已启用"},
{"k": "disabled", "v": "已停用"}
]
}
]
}

View File

@ -0,0 +1,33 @@
{
"tblname": "distributor_pipeline",
"title": "分销商产线配置",
"params": {
"sortby": "created_at",
"browserfields": {
"exclouded": ["id"],
"cwidth": {},
"alters": {
"distributor_id": {"dataurl": "{{entire_url('../api/get_search_distributor_id.dspy')}}"},
"pipeline_id": {"dataurl": "{{entire_url('../api/get_search_pipeline_id.dspy')}}"}
}
},
"editexclouded": [
"id", "created_at", "updated_at"
],
"editable": {
"new_data_url": "{{entire_url('../api/distributor_pipeline_create.dspy')}}",
"update_data_url": "{{entire_url('../api/distributor_pipeline_update.dspy')}}",
"delete_data_url": "{{entire_url('../api/distributor_pipeline_delete.dspy')}}"
},
"confidential_fields": [],
"subtables": [
{"field": "distributor_id", "title": "分销商", "subtable": "distributors"},
{"field": "pipeline_id", "title": "产线", "subtable": "pipelines"}
],
"data_filter": {
"distributor_id": "",
"pipeline_id": "",
"status": ""
}
}
}

24
json/distributors.json Normal file
View File

@ -0,0 +1,24 @@
{
"tblname": "distributors",
"title": "分销商管理",
"params": {
"sortby": "created_at",
"browserfields": {
"exclouded": ["id", "api_key", "remarks"],
"cwidth": {}
},
"editexclouded": [
"id", "created_at", "updated_at"
],
"editable": {
"new_data_url": "{{entire_url('../api/distributors_create.dspy')}}",
"update_data_url": "{{entire_url('../api/distributors_update.dspy')}}",
"delete_data_url": "{{entire_url('../api/distributors_delete.dspy')}}"
},
"confidential_fields": ["api_key"],
"data_filter": {
"name": "",
"status": ""
}
}
}

View File

@ -0,0 +1,140 @@
{
"summary": [
{
"name": "distributor_pipeline",
"title": "分销商-产线关联定价表",
"primary": [
"id"
]
}
],
"fields": [
{
"name": "id",
"title": "主键",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "distributor_id",
"title": "分销商ID",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "pipeline_id",
"title": "产线ID",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "custom_price",
"title": "自定义单价",
"type": "double",
"length": 15,
"dec": 4
},
{
"name": "markup_type",
"title": "加价方式",
"type": "str",
"length": 20
},
{
"name": "markup_value",
"title": "加价值",
"type": "double",
"length": 10,
"dec": 2
},
{
"name": "daily_limit",
"title": "日限额",
"type": "int",
"default": "0"
},
{
"name": "monthly_limit",
"title": "月限额",
"type": "int",
"default": "0"
},
{
"name": "today_usage",
"title": "今日已用",
"type": "int",
"default": "0"
},
{
"name": "month_usage",
"title": "本月已用",
"type": "int",
"default": "0"
},
{
"name": "status",
"title": "状态",
"type": "str",
"length": 20,
"default": "active"
},
{
"name": "created_at",
"title": "创建时间",
"type": "timestamp"
},
{
"name": "updated_at",
"title": "更新时间",
"type": "timestamp"
}
],
"indexes": [
{
"name": "idx_dp_dist_pipe",
"idxtype": "unique",
"idxfields": [
"distributor_id",
"pipeline_id"
]
},
{
"name": "idx_dp_distributor",
"idxtype": "index",
"idxfields": [
"distributor_id"
]
}
],
"codes": [
{
"field": "distributor_id",
"table": "distributors",
"valuefield": "id",
"textfield": "name"
},
{
"field": "pipeline_id",
"table": "pipelines",
"valuefield": "id",
"textfield": "name"
},
{
"field": "markup_type",
"table": "appcodes_kv",
"valuefield": "k",
"textfield": "v",
"cond": "parentid='markup_type'"
},
{
"field": "status",
"table": "appcodes_kv",
"valuefield": "k",
"textfield": "v",
"cond": "parentid='dp_status'"
}
]
}

128
models/distributors.json Normal file
View File

@ -0,0 +1,128 @@
{
"summary": [
{
"name": "distributors",
"title": "分销商表",
"primary": [
"id"
]
}
],
"fields": [
{
"name": "id",
"title": "主键",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "name",
"title": "分销商名称",
"type": "str",
"length": 200,
"nullable": "no"
},
{
"name": "org_id",
"title": "关联组织ID",
"type": "str",
"length": 32
},
{
"name": "contact_name",
"title": "联系人",
"type": "str",
"length": 50
},
{
"name": "contact_phone",
"title": "联系电话",
"type": "str",
"length": 20
},
{
"name": "contact_email",
"title": "联系邮箱",
"type": "str",
"length": 100
},
{
"name": "api_key",
"title": "API密钥",
"type": "str",
"length": 200
},
{
"name": "commission_rate",
"title": "佣金比例%",
"type": "double",
"length": 5,
"dec": 2,
"default": "0"
},
{
"name": "status",
"title": "状态",
"type": "str",
"length": 20,
"default": "active"
},
{
"name": "agreement_start",
"title": "协议开始日",
"type": "date"
},
{
"name": "agreement_end",
"title": "协议结束日",
"type": "date"
},
{
"name": "remarks",
"title": "备注",
"type": "text"
},
{
"name": "created_by",
"title": "创建人",
"type": "str",
"length": 32
},
{
"name": "created_at",
"title": "创建时间",
"type": "timestamp"
},
{
"name": "updated_at",
"title": "更新时间",
"type": "timestamp"
}
],
"indexes": [
{
"name": "idx_dist_name",
"idxtype": "index",
"idxfields": [
"name"
]
},
{
"name": "idx_dist_status",
"idxtype": "index",
"idxfields": [
"status"
]
}
],
"codes": [
{
"field": "status",
"table": "appcodes_kv",
"valuefield": "k",
"textfield": "v",
"cond": "parentid='distributor_status'"
}
]
}

83
mysql.ddl.sql Normal file
View File

@ -0,0 +1,83 @@
-- models/distributors.json
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists distributors;
CREATE TABLE distributors
(
`id` VARCHAR(32) NOT NULL comment '主键',
`name` VARCHAR(200) NOT NULL comment '分销商名称',
`org_id` VARCHAR(32) comment '关联组织ID',
`contact_name` VARCHAR(50) comment '联系人',
`contact_phone` VARCHAR(20) comment '联系电话',
`contact_email` VARCHAR(100) comment '联系邮箱',
`api_key` VARCHAR(200) comment 'API密钥',
`commission_rate` double(5,2) DEFAULT '0' comment '佣金比例%',
`status` VARCHAR(20) DEFAULT 'active' comment '状态',
`agreement_start` date comment '协议开始日',
`agreement_end` date comment '协议结束日',
`remarks` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci 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 distributors_idx_dist_name ON distributors(name);
CREATE INDEX distributors_idx_dist_status ON distributors(status);
-- models/distributor_pipeline.json
-- 建库时请用以下语句支持emoji字符
-- CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
drop table if exists distributor_pipeline;
CREATE TABLE distributor_pipeline
(
`id` VARCHAR(32) NOT NULL comment '主键',
`distributor_id` VARCHAR(32) NOT NULL comment '分销商ID',
`pipeline_id` VARCHAR(32) NOT NULL comment '产线ID',
`custom_price` double(15,4) comment '自定义单价',
`markup_type` VARCHAR(20) comment '加价方式',
`markup_value` double(10,2) comment '加价值',
`daily_limit` int DEFAULT '0' comment '日限额',
`monthly_limit` int DEFAULT '0' comment '月限额',
`today_usage` int DEFAULT '0' comment '今日已用',
`month_usage` int DEFAULT '0' comment '本月已用',
`status` VARCHAR(20) DEFAULT 'active' 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 UNIQUE INDEX distributor_pipeline_idx_dp_dist_pipe ON distributor_pipeline(distributor_id,pipeline_id);
CREATE INDEX distributor_pipeline_idx_dp_distributor ON distributor_pipeline(distributor_id);

13
pipeline_dist/__init__.py Normal file
View File

@ -0,0 +1,13 @@
from .init import (
MODULE_NAME,
DBNAME,
distributors_create,
distributors_update,
distributors_delete,
distributor_pipeline_create,
distributor_pipeline_update,
distributor_pipeline_delete,
generate_api_key,
calculate_price,
load_pipeline_dist,
)

229
pipeline_dist/init.py Normal file
View File

@ -0,0 +1,229 @@
"""pipeline_dist 模块 - 分销商管理模块"""
import json
from appPublic.uniqueID import getID
from sqlor.dbpools import DBPools
from ahserver.serverenv import ServerEnv
from appPublic.log import debug
MODULE_NAME = 'pipeline_dist'
DBNAME = 'pipeline'
def _get_sor():
"""Get database pool and dbname for pipeline_dist module."""
return DBPools(), DBNAME
async def distributors_create(params_kw):
"""创建分销商记录"""
result = {'success': False, 'message': ''}
try:
db, dbname = _get_sor()
async with db.sqlorContext(dbname) as sor:
data = params_kw.copy()
data.pop('page', None)
data.pop('rows', None)
data.pop('data_filter', None)
data['id'] = getID()
await sor.C('distributors', data)
result['success'] = True
result['message'] = '创建成功'
result['id'] = data['id']
except Exception as e:
result['message'] = str(e)
return json.dumps(result, ensure_ascii=False, default=str)
async def distributors_update(params_kw):
"""更新分销商记录"""
result = {'success': False, 'message': ''}
try:
db, dbname = _get_sor()
async with db.sqlorContext(dbname) as sor:
data = params_kw.copy()
data.pop('page', None)
data.pop('rows', None)
data.pop('data_filter', None)
if not data.get('id'):
result['message'] = '缺少id'
else:
await sor.U('distributors', data)
result['success'] = True
result['message'] = '更新成功'
except Exception as e:
result['message'] = str(e)
return json.dumps(result, ensure_ascii=False, default=str)
async def distributors_delete(params_kw):
"""删除分销商记录"""
result = {'success': False, 'message': ''}
try:
db, dbname = _get_sor()
async with db.sqlorContext(dbname) as sor:
record_id = params_kw.get('id')
if not record_id:
result['message'] = '缺少id'
else:
await sor.D('distributors', {'id': record_id})
result['success'] = True
result['message'] = '删除成功'
except Exception as e:
result['message'] = str(e)
return json.dumps(result, ensure_ascii=False, default=str)
async def distributor_pipeline_create(params_kw):
"""创建分销商-产线关联记录"""
result = {'success': False, 'message': ''}
try:
db, dbname = _get_sor()
async with db.sqlorContext(dbname) as sor:
data = params_kw.copy()
data.pop('page', None)
data.pop('rows', None)
data.pop('data_filter', None)
data['id'] = getID()
await sor.C('distributor_pipeline', data)
result['success'] = True
result['message'] = '创建成功'
result['id'] = data['id']
except Exception as e:
result['message'] = str(e)
return json.dumps(result, ensure_ascii=False, default=str)
async def distributor_pipeline_update(params_kw):
"""更新分销商-产线关联记录"""
result = {'success': False, 'message': ''}
try:
db, dbname = _get_sor()
async with db.sqlorContext(dbname) as sor:
data = params_kw.copy()
data.pop('page', None)
data.pop('rows', None)
data.pop('data_filter', None)
if not data.get('id'):
result['message'] = '缺少id'
else:
await sor.U('distributor_pipeline', data)
result['success'] = True
result['message'] = '更新成功'
except Exception as e:
result['message'] = str(e)
return json.dumps(result, ensure_ascii=False, default=str)
async def distributor_pipeline_delete(params_kw):
"""删除分销商-产线关联记录"""
result = {'success': False, 'message': ''}
try:
db, dbname = _get_sor()
async with db.sqlorContext(dbname) as sor:
record_id = params_kw.get('id')
if not record_id:
result['message'] = '缺少id'
else:
await sor.D('distributor_pipeline', {'id': record_id})
result['success'] = True
result['message'] = '删除成功'
except Exception as e:
result['message'] = str(e)
return json.dumps(result, ensure_ascii=False, default=str)
async def generate_api_key(params_kw):
"""Generate a new API key for a distributor"""
result = {'success': False, 'message': ''}
try:
distributor_id = params_kw.get('id') or params_kw.get('distributor_id')
if not distributor_id:
result['message'] = '缺少distributor_id'
return json.dumps(result, ensure_ascii=False, default=str)
new_key = getID() + getID()
db, dbname = _get_sor()
async with db.sqlorContext(dbname) as sor:
await sor.U('distributors', {'id': distributor_id, 'api_key': new_key})
result['success'] = True
result['key'] = new_key
result['distributor_id'] = distributor_id
except Exception as e:
result['message'] = str(e)
return json.dumps(result, ensure_ascii=False, default=str)
async def calculate_price(params_kw):
"""Calculate effective price for a distributor-pipeline combination.
Returns the effective price considering custom pricing and markup.
If no custom pricing exists, returns None (caller should use base price).
"""
result = {'success': False, 'message': '', 'price': None}
try:
distributor_id = params_kw.get('distributor_id')
pipeline_id = params_kw.get('pipeline_id')
if not distributor_id or not pipeline_id:
result['message'] = '缺少distributor_id或pipeline_id'
return json.dumps(result, ensure_ascii=False, default=str)
db, dbname = _get_sor()
async with db.sqlorContext(dbname) as sor:
rows = await sor.sqlExe(
'select * from distributor_pipeline where distributor_id = :distributor_id and pipeline_id = :pipeline_id',
{'distributor_id': distributor_id, 'pipeline_id': pipeline_id}
)
if not rows:
result['success'] = True
result['price'] = None
return json.dumps(result, ensure_ascii=False, default=str)
dp = rows[0] if isinstance(rows, list) else rows
# If custom_price is set, use it as base
base_price = None
custom_price = dp.get('custom_price') if hasattr(dp, 'get') else getattr(dp, 'custom_price', None)
if custom_price is not None:
base_price = custom_price
# Apply markup if configured
markup_type = dp.get('markup_type') if hasattr(dp, 'get') else getattr(dp, 'markup_type', None)
markup_value = dp.get('markup_value') if hasattr(dp, 'get') else getattr(dp, 'markup_value', None)
if markup_type and markup_value is not None and base_price is not None:
if markup_type == 'fixed':
result['price'] = base_price + markup_value
elif markup_type == 'percentage':
result['price'] = base_price * (1 + markup_value / 100)
else:
result['price'] = base_price
result['success'] = True
except Exception as e:
result['message'] = str(e)
return json.dumps(result, ensure_ascii=False, default=str)
def load_pipeline_dist():
"""注册函数到 ServerEnv"""
env = ServerEnv()
# Distributors
env.distributors_create = distributors_create
env.distributors_creates = distributors_create
env.distributors_update = distributors_update
env.distributors_updates = distributors_update
env.distributors_delete = distributors_delete
env.distributors_deletes = distributors_delete
# Distributor Pipeline
env.distributor_pipeline_create = distributor_pipeline_create
env.distributor_pipeline_creates = distributor_pipeline_create
env.distributor_pipeline_update = distributor_pipeline_update
env.distributor_pipeline_updates = distributor_pipeline_update
env.distributor_pipeline_delete = distributor_pipeline_delete
env.distributor_pipeline_deletes = distributor_pipeline_delete
# Utility functions
env.generate_api_key = generate_api_key
env.calculate_price = calculate_price
debug(f'[{MODULE_NAME}] module loaded')
return True

9
pyproject.toml Normal file
View File

@ -0,0 +1,9 @@
[project]
name = "pipeline_dist"
version = "0.1.0"
description = "产线分发模块"
dependencies = ["sqlor"]
[tool.setuptools.packages.find]
where = ["."]
include = ["pipeline_dist*"]

38
scripts/load_path.py Normal file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env python3
"""RBAC path registration for pipeline_dist + showcase modules."""
import os, sys, subprocess
MODS = [
("pipeline_dist", [
"/pipeline_dist",
"/pipeline_dist/index.ui",
"/pipeline_dist/distributors/index.ui",
"/pipeline_dist/distributor_pipeline/index.ui",
]),
("showcase", [
"/showcase",
"/showcase/index.ui",
]),
]
def main():
root = os.path.expanduser("~/pipeline")
set_perm = os.path.join(root, "set_role_perm.py")
if not os.path.isfile(set_perm):
print("ERROR: pipeline root not found"); sys.exit(1)
py = sys.executable
count = 0
total = 0
for mod, paths in MODS:
total += len(paths)
for path in paths:
r = subprocess.run([py, set_perm, "logined", path], capture_output=True, text=True, cwd=root)
if r.returncode == 0: count += 1
else: print(f" WARN: {path}")
print(f" {mod}: {len(paths)} paths")
print(f"Registered {count}/{total}")
if __name__ == "__main__":
main()

View File

@ -0,0 +1,2 @@
result = await generate_api_key(params_kw)
return result

View File

@ -0,0 +1,2 @@
result = await distributor_pipeline_create(params_kw)
return result

View File

@ -0,0 +1,2 @@
result = await distributor_pipeline_delete(params_kw)
return result

View File

@ -0,0 +1,2 @@
result = await distributor_pipeline_update(params_kw)
return result

View File

@ -0,0 +1,2 @@
result = await distributors_create(params_kw)
return result

View File

@ -0,0 +1,2 @@
result = await distributors_delete(params_kw)
return result

View File

@ -0,0 +1,2 @@
result = await distributors_update(params_kw)
return result

View File

@ -0,0 +1,8 @@
data = [{'value': '', 'text': '全部'}]
try:
async with get_sor_context(request._run_ns, 'pipeline') as sor:
rows = await sor.sqlExe('select id as value, name as text from distributors order by name', {})
data.extend(list(rows))
except Exception as e:
debug('error: ' + str(e))
return json.dumps(data, ensure_ascii=False)

View File

@ -0,0 +1,8 @@
data = [{'value': '', 'text': '全部'}]
try:
async with get_sor_context(request._run_ns, 'pipeline') as sor:
rows = await sor.sqlExe('select id as value, name as text from pipelines order by name', {})
data.extend(list(rows))
except Exception as e:
debug('error: ' + str(e))
return json.dumps(data, ensure_ascii=False)

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_dist')
async with db.sqlorContext(dbname) as sor:
r = await sor.C('distributor_pipeline', 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_dist')
async with db.sqlorContext(dbname) as sor:
r = await sor.D('distributor_pipeline', 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,143 @@
ns = params_kw.copy()
debug(f'get_distributor_pipeline.dspy:{ns=}')
if not ns.get('page'):
ns['page'] = 1
if not ns.get('sort'):
ns['sort'] = 'created_at'
sql = '''select a.*, b.distributor_id_text, c.pipeline_id_text, d.markup_type_text, e.status_text
from (select * from distributor_pipeline where 1=1 [[filterstr]]) a left join (select id as distributor_id,
name as distributor_id_text from distributors where 1 = 1) b on a.distributor_id = b.distributor_id left join (select id as pipeline_id,
name as pipeline_id_text from pipelines where 1 = 1) c on a.pipeline_id = c.pipeline_id left join (select k as markup_type,
v as markup_type_text from appcodes_kv where parentid='markup_type') d on a.markup_type = d.markup_type left join (select k as status,
v as status_text from appcodes_kv where parentid='dp_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": "distributor_id",
"title": "分销商ID",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "pipeline_id",
"title": "产线ID",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "custom_price",
"title": "自定义单价",
"type": "double",
"length": 15,
"dec": 4
},
{
"name": "markup_type",
"title": "加价方式",
"type": "str",
"length": 20
},
{
"name": "markup_value",
"title": "加价值",
"type": "double",
"length": 10,
"dec": 2
},
{
"name": "daily_limit",
"title": "日限额",
"type": "int",
"default": "0"
},
{
"name": "monthly_limit",
"title": "月限额",
"type": "int",
"default": "0"
},
{
"name": "today_usage",
"title": "今日已用",
"type": "int",
"default": "0"
},
{
"name": "month_usage",
"title": "本月已用",
"type": "int",
"default": "0"
},
{
"name": "status",
"title": "状态",
"type": "str",
"length": 20,
"default": "active"
},
{
"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)
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_dist')
async with db.sqlorContext(dbname) as sor:
r = await sor.sqlPaging(sql, ns)
return r
return {
"total":0,
"rows":[]
}

View File

@ -0,0 +1,327 @@
{
"widgettype":"VBox",
"options":{"cheight":40,"width":"100%"},
"subwidgets":[{
"id":"distributor_pipeline_tbl",
"widgettype":"Tabular",
"options":{
"width":"100%",
"height":"100%",
"title":"分销商-产线关联定价表",
"toolbar":{
"tools": [
{
"selected_row": true,
"name": "distributors",
"icon": "{{entire_url('/imgs/distributors.svg')}}",
"label": "分销商"
},
{
"selected_row": true,
"name": "pipelines",
"icon": "{{entire_url('/imgs/pipelines.svg')}}",
"label": "产线"
}
]
},
"css":"card",
"editable":{
"new_data_url":"{{entire_url('add_distributor_pipeline.dspy')}}",
"delete_data_url":"{{entire_url('delete_distributor_pipeline.dspy')}}",
"update_data_url":"{{entire_url('update_distributor_pipeline.dspy')}}"
},
"data_url":"{{entire_url('./get_distributor_pipeline.dspy')}}",
"data_method":"GET",
"data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}},
"row_options":{
"browserfields": {
"exclouded": [
"id"
],
"cwidth": {},
"alters": {
"distributor_id": {
"dataurl": "{{entire_url('../api/get_search_distributor_id.dspy')}}"
},
"pipeline_id": {
"dataurl": "{{entire_url('../api/get_search_pipeline_id.dspy')}}"
}
}
},
"editexclouded":[
"id",
"created_at",
"updated_at"
],
"fields":[
{
"name": "id",
"title": "主键",
"type": "str",
"length": 32,
"nullable": "no",
"cwidth": 18,
"uitype": "str",
"datatype": "str",
"label": "主键"
},
{
"name": "distributor_id",
"title": "分销商ID",
"type": "str",
"length": 32,
"nullable": "no",
"label": "分销商ID",
"uitype": "code",
"valueField": "distributor_id",
"textField": "distributor_id_text",
"params": {
"dbname": "{{get_module_dbname('pipeline_dist')}}",
"table": "distributors",
"tblvalue": "id",
"tbltext": "name",
"valueField": "distributor_id",
"textField": "distributor_id_text"
},
"dataurl": "{{entire_url('../api/get_search_distributor_id.dspy')}}"
},
{
"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_dist')}}",
"table": "pipelines",
"tblvalue": "id",
"tbltext": "name",
"valueField": "pipeline_id",
"textField": "pipeline_id_text"
},
"dataurl": "{{entire_url('../api/get_search_pipeline_id.dspy')}}"
},
{
"name": "custom_price",
"title": "自定义单价",
"type": "double",
"length": 15,
"dec": 4,
"cwidth": 15,
"uitype": "float",
"datatype": "double",
"label": "自定义单价"
},
{
"name": "markup_type",
"title": "加价方式",
"type": "str",
"length": 20,
"label": "加价方式",
"uitype": "code",
"valueField": "markup_type",
"textField": "markup_type_text",
"params": {
"dbname": "{{get_module_dbname('pipeline_dist')}}",
"table": "appcodes_kv",
"tblvalue": "k",
"tbltext": "v",
"valueField": "markup_type",
"textField": "markup_type_text",
"cond": "parentid='markup_type'"
},
"dataurl": "{{entire_url('/appbase/get_code.dspy')}}"
},
{
"name": "markup_value",
"title": "加价值",
"type": "double",
"length": 10,
"dec": 2,
"cwidth": 10,
"uitype": "float",
"datatype": "double",
"label": "加价值"
},
{
"name": "daily_limit",
"title": "日限额",
"type": "int",
"default": "0",
"length": 0,
"uitype": "int",
"datatype": "int",
"label": "日限额"
},
{
"name": "monthly_limit",
"title": "月限额",
"type": "int",
"default": "0",
"length": 0,
"uitype": "int",
"datatype": "int",
"label": "月限额"
},
{
"name": "today_usage",
"title": "今日已用",
"type": "int",
"default": "0",
"length": 0,
"uitype": "int",
"datatype": "int",
"label": "今日已用"
},
{
"name": "month_usage",
"title": "本月已用",
"type": "int",
"default": "0",
"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_dist')}}",
"table": "appcodes_kv",
"tblvalue": "k",
"tbltext": "v",
"valueField": "status",
"textField": "status_text",
"cond": "parentid='dp_status'"
},
"dataurl": "{{entire_url('/appbase/get_code.dspy')}}"
},
{
"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":{
"distributor_id": "",
"pipeline_id": "",
"status": ""
},
"page_rows":160,
"cache_limit":5
}
,"binds":[
{
"wid": "self",
"event": "distributors",
"actiontype": "urlwidget",
"target": "PopupWindow",
"popup_options": {
"title": "分销商",
"icon": "{{entire_url('/appbase/get_icon.dspy')}}?id=distributors",
"resizable": true,
"height": "70%",
"width": "70%"
},
"params_mapping": {
"mapping": {
"id": "distributor_id",
"referer_widget": "referer_widget"
},
"need_other": false
},
"options": {
"method": "POST",
"params": {},
"url": "{{entire_url('../distributors')}}"
}
},
{
"wid": "self",
"event": "pipelines",
"actiontype": "urlwidget",
"target": "PopupWindow",
"popup_options": {
"title": "产线",
"icon": "{{entire_url('/appbase/get_icon.dspy')}}?id=pipelines",
"resizable": true,
"height": "70%",
"width": "70%"
},
"params_mapping": {
"mapping": {
"id": "pipeline_id",
"referer_widget": "referer_widget"
},
"need_other": false
},
"options": {
"method": "POST",
"params": {},
"url": "{{entire_url('../pipelines')}}"
}
}
]
}]
}

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_dist')
async with db.sqlorContext(dbname) as sor:
r = await sor.U('distributor_pipeline', 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,40 @@
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
if params_kw.get('api_key'):
ns['api_key'] = password_encode(params_kw.get('api_key'))
db = DBPools()
dbname = get_module_dbname('pipeline_dist')
async with db.sqlorContext(dbname) as sor:
r = await sor.C('distributors', 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_dist')
async with db.sqlorContext(dbname) as sor:
r = await sor.D('distributors', 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,148 @@
ns = params_kw.copy()
debug(f'get_distributors.dspy:{ns=}')
if not ns.get('page'):
ns['page'] = 1
if not ns.get('sort'):
ns['sort'] = 'created_at'
sql = '''select a.*, b.status_text
from (select * from distributors where 1=1 [[filterstr]]) a left join (select k as status,
v as status_text from appcodes_kv where parentid='distributor_status') b on a.status = b.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": "name",
"title": "分销商名称",
"type": "str",
"length": 200,
"nullable": "no"
},
{
"name": "org_id",
"title": "关联组织ID",
"type": "str",
"length": 32
},
{
"name": "contact_name",
"title": "联系人",
"type": "str",
"length": 50
},
{
"name": "contact_phone",
"title": "联系电话",
"type": "str",
"length": 20
},
{
"name": "contact_email",
"title": "联系邮箱",
"type": "str",
"length": 100
},
{
"name": "api_key",
"title": "API密钥",
"type": "str",
"length": 200
},
{
"name": "commission_rate",
"title": "佣金比例%",
"type": "double",
"length": 5,
"dec": 2,
"default": "0"
},
{
"name": "status",
"title": "状态",
"type": "str",
"length": 20,
"default": "active"
},
{
"name": "agreement_start",
"title": "协议开始日",
"type": "date"
},
{
"name": "agreement_end",
"title": "协议结束日",
"type": "date"
},
{
"name": "remarks",
"title": "备注",
"type": "text"
},
{
"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)
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_dist')
async with db.sqlorContext(dbname) as sor:
r = await sor.sqlPaging(sql, ns)
return r
return {
"total":0,
"rows":[]
}

View File

@ -0,0 +1,240 @@
{
"widgettype":"VBox",
"options":{"cheight":40,"width":"100%"},
"subwidgets":[{
"id":"distributors_tbl",
"widgettype":"Tabular",
"options":{
"width":"100%",
"height":"100%",
"title":"分销商表",
"css":"card",
"editable":{
"new_data_url":"{{entire_url('add_distributors.dspy')}}",
"delete_data_url":"{{entire_url('delete_distributors.dspy')}}",
"update_data_url":"{{entire_url('update_distributors.dspy')}}"
},
"data_url":"{{entire_url('./get_distributors.dspy')}}",
"data_method":"GET",
"data_params":{{json.dumps(params_kw, indent=4, ensure_ascii=False)}},
"row_options":{
"browserfields": {
"exclouded": [
"id",
"api_key",
"remarks"
],
"cwidth": {}
},
"editexclouded":[
"id",
"created_at",
"updated_at"
],
"fields":[
{
"name": "id",
"title": "主键",
"type": "str",
"length": 32,
"nullable": "no",
"cwidth": 18,
"uitype": "str",
"datatype": "str",
"label": "主键"
},
{
"name": "name",
"title": "分销商名称",
"type": "str",
"length": 200,
"nullable": "no",
"cwidth": 18,
"uitype": "str",
"datatype": "str",
"label": "分销商名称"
},
{
"name": "org_id",
"title": "关联组织ID",
"type": "str",
"length": 32,
"cwidth": 18,
"uitype": "str",
"datatype": "str",
"label": "关联组织ID"
},
{
"name": "contact_name",
"title": "联系人",
"type": "str",
"length": 50,
"cwidth": 18,
"uitype": "str",
"datatype": "str",
"label": "联系人"
},
{
"name": "contact_phone",
"title": "联系电话",
"type": "str",
"length": 20,
"cwidth": 18,
"uitype": "str",
"datatype": "str",
"label": "联系电话"
},
{
"name": "contact_email",
"title": "联系邮箱",
"type": "str",
"length": 100,
"cwidth": 18,
"uitype": "str",
"datatype": "str",
"label": "联系邮箱"
},
{
"name": "api_key",
"title": "API密钥",
"type": "str",
"length": 200,
"cwidth": 18,
"uitype": "password",
"datatype": "str",
"label": "API密钥"
},
{
"name": "commission_rate",
"title": "佣金比例%",
"type": "double",
"length": 5,
"dec": 2,
"default": "0",
"cwidth": 5,
"uitype": "float",
"datatype": "double",
"label": "佣金比例%"
},
{
"name": "status",
"title": "状态",
"type": "str",
"length": 20,
"default": "active",
"label": "状态",
"uitype": "code",
"valueField": "status",
"textField": "status_text",
"params": {
"dbname": "{{get_module_dbname('pipeline_dist')}}",
"table": "appcodes_kv",
"tblvalue": "k",
"tbltext": "v",
"valueField": "status",
"textField": "status_text",
"cond": "parentid='distributor_status'"
},
"dataurl": "{{entire_url('/appbase/get_code.dspy')}}"
},
{
"name": "agreement_start",
"title": "协议开始日",
"type": "date",
"length": 0,
"uitype": "date",
"datatype": "date",
"label": "协议开始日"
},
{
"name": "agreement_end",
"title": "协议结束日",
"type": "date",
"length": 0,
"uitype": "date",
"datatype": "date",
"label": "协议结束日"
},
{
"name": "remarks",
"title": "备注",
"type": "text",
"length": 0,
"uitype": "text",
"datatype": "text",
"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":{
"name": "",
"status": ""
},
"page_rows":160,
"cache_limit":5
}
,"binds":[]
}]
}

View File

@ -0,0 +1,39 @@
ns = params_kw.copy()
for k,v in ns.items():
if v == 'NaN' or v == 'null':
ns[k] = None
if params_kw.get('api_key'):
ns['api_key'] = password_encode(params_kw.get('api_key'))
db = DBPools()
dbname = get_module_dbname('pipeline_dist')
async with db.sqlorContext(dbname) as sor:
r = await sor.U('distributors', 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"
}
}

37
wwwroot/index.ui Normal file
View File

@ -0,0 +1,37 @@
{
"widgettype": "VBox",
"options": {"width": "100%", "height": "100%", "padding": "24px", "spacing": "20px"},
"subwidgets": [
{"widgettype": "Title2", "options": {"text": "分销管理"}},
{
"widgettype": "ResponsableBox",
"options": {"gap": "24px", "minWidth": "260px"},
"subwidgets": [
{
"widgettype": "VBox",
"options": {"css": "card", "cwidth": 23, "cheight": 11, "padding": "24px", "cursor": "pointer", "bgcolor": "#fff"},
"binds": [{"wid": "self", "event": "click", "actiontype": "urlwidget", "target": "app.main_content", "options": {"url": "{{entire_url('distributor_pipeline/')}}"}, "mode": "replace"}],
"subwidgets": [
{"widgettype": "VBox", "options": {"width": "44px", "height": "44px", "bgcolor": "#ECFDF5", "borderRadius": "12px", "alignItems": "center", "justifyContent": "center", "marginBottom": "12px"}, "subwidgets": [
{"widgettype": "Svg", "options": {"svg": "<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"#10B981\" stroke-width=\"2\"><path d=\"M16 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2\"/><circle cx=\"8.5\" cy=\"7\" r=\"4\"/><polyline points=\"17 11 19 13 23 9\"/></svg>", "width": "24px", "height": "24px"}}
]},
{"widgettype": "Title3", "options": {"text": "分销商产线配置", "marginBottom": "4px"}},
{"widgettype": "Text", "options": {"text": "管理分销商与产线绑定关系", "cfontsize": 0.9}}
]
},
{
"widgettype": "VBox",
"options": {"css": "card", "cwidth": 23, "cheight": 11, "padding": "24px", "cursor": "pointer", "bgcolor": "#fff"},
"binds": [{"wid": "self", "event": "click", "actiontype": "urlwidget", "target": "app.main_content", "options": {"url": "{{entire_url('distributors/')}}"}, "mode": "replace"}],
"subwidgets": [
{"widgettype": "VBox", "options": {"width": "44px", "height": "44px", "bgcolor": "#FFF7ED", "borderRadius": "12px", "alignItems": "center", "justifyContent": "center", "marginBottom": "12px"}, "subwidgets": [
{"widgettype": "Svg", "options": {"svg": "<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"#F97316\" stroke-width=\"2\"><path d=\"M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2\"/><circle cx=\"9\" cy=\"7\" r=\"4\"/><path d=\"M23 21v-2a4 4 0 00-3-3.87\"/><path d=\"M16 3.13a4 4 0 010 7.75\"/></svg>", "width": "24px", "height": "24px"}}
]},
{"widgettype": "Title3", "options": {"text": "分销商管理", "marginBottom": "4px"}},
{"widgettype": "Text", "options": {"text": "管理分销商账号与基本信息", "cfontsize": 0.9}}
]
}
]
}
]
}