Proposal: 模板包机制——表单 Schema、流程定义与视图配置

未关闭
#4 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
go, json, yaml

调研方向

Start with the overall proposal in #1 and the storage design in #2, then review this issue’s schema, workflow, SLA, assignment, and view_config examples. The issue names no implementation files or tests; its expected outcome is an approved design that defines shared validation and rendering semantics, with #12 and #13 starting only after approval.

由索引模型根据 Issue 内容生成。

描述

proposal

背景

模板包是 TickFlow 的核心抽象(总体方案见 #1):工单类型 = 表单 schema + 流程 + SLA + 分派 + 视图配置,它决定「不同类型不同 UI、不同用法」如何落地。存储见 #2(ticket_types 表的 JSONB 字段),本文定义各 JSONB 的内部结构与校验规则。

表单 schema(form_schema)

采用 JSON Schema 的受限子集,前后端共用同一份做校验(后端校验必须存在,前端校验只为体验):

{
  "fields": [
    { "key": "device_sn", "label": "设备编号", "type": "string", "required": true, "placeholder": "位于机身底部标签" },
    { "key": "category", "label": "故障分类", "type": "select", "required": true,
      "options": [
        { "value": "hardware", "label": "硬件故障" },
        { "value": "software", "label": "软件异常" }
      ] },
    { "key": "occur_at", "label": "发生时间", "type": "datetime" },
    { "key": "photos", "label": "现场照片", "type": "attachments", "max_count": 9 }
  ]
}
  • 类型集:string / textarea / number / select / multiselect / boolean / date / datetime / attachments;
  • 字段 key 为英文蛇形命名,落库到 tickets.custom_fields;label 为展示文案;
  • 校验项:required、max_length、min / max、pattern、max_count;
  • schema 本身的合法性在保存类型时校验:未知类型、重复 key、非法 options、未知校验项一律拒绝保存。

流程定义(workflow)

可配置状态机,状态不进数据库枚举:

{
  "states": [
    { "key": "pending",    "name": "待受理", "type": "initial" },
    { "key": "processing", "name": "处理中", "type": "normal" },
    { "key": "confirming", "name": "待确认", "type": "normal" },
    { "key": "closed",     "name": "已关闭", "type": "final" }
  ],
  "transitions": [
    { "from": "pending",    "action": "accept",  "to": "processing", "roles": ["agent", "tenant_admin"] },
    { "from": "processing", "action": "resolve", "to": "confirming", "roles": ["agent", "tenant_admin"] },
    { "from": "confirming", "action": "confirm", "to": "closed",     "roles": ["creator", "agent", "tenant_admin"] },
    { "from": "confirming", "action": "reject",  "to": "processing", "roles": ["creator"] },
    { "from": "closed",     "action": "reopen",  "to": "pending",    "roles": ["creator", "tenant_admin"] }
  ]
}
  • roles 中的 creator 是相对角色(工单创建者本人),其余为租户角色;
  • 保存时校验:有且仅有一个 initial、至少一个 final、所有 from / to 必须存在于 states、同一状态下 action 不重复;
  • 运行时:POST /api/tickets/:id/transitions 按 action 找到流转,校验角色(与 #6 权限矩阵取交集),通过后更新 state、向 timeline 写入 state_change 记录、发布领域事件(见 #7);
  • 审批链(顺序 / 会签节点)是 P2 的节点扩展,P0 的 DSL 不预留半成品字段。

SLA 策略(sla_policy)

{
  "first_response_minutes": 30,
  "resolve_minutes": 480,
  "escalation": []
}

P0 仅存配置并在工单详情展示时限倒计时;计时、超时提醒、升级属 P1(见 #1 路线图),P0 不实现扫描器。

分派策略(assignment)

{ "mode": "manual" }

P0 仅支持 manual;round_robin、skill_group 为 P1。保存时校验枚举合法即可。

视图配置(view_config)

{
  "portal": {
    "title": "设备报修",
    "description": "请填写故障信息,工程师将在 30 分钟内响应",
    "success_text": "已提交,请留意通知"
  },
  "list_columns": [
    { "field": "number" }, { "field": "title" }, { "field": "state" },
    { "field": "assignee" }, { "field": "created_at" }
  ],
  "detail_groups": [
    { "title": "基础信息", "fields": ["number", "title", "priority", "state"] },
    { "title": "表单信息", "fields": ["device_sn", "category", "occur_at"] }
  ]
}
  • field 可引用内置字段(number / title / state / assignee / created_at / priority 等)或 form_schema 的字段 key,引用不存在时保存报错;
  • 工作台列表与详情按此渲染。注意区分:界面固定文案由前端代码维护(展示与数据分离),而 portal 的 title / description 等是租户配置的数据内容,允许存库。

内置种子模板包

四个场景各一个,YAML 文件内置在仓库 seed/ 目录(任务见 #19):新租户创建时自动复制为其初始类型(标记 is_builtin = true,允许停用与修改)。机制实现见 #12。

Expect

  • Go 校验器(schema / workflow / view_config)与 Vue 渲染器覆盖同一份语义,测试 fixtures 共享(seed YAML 即测试用例);
  • 本设计评审通过前,#12 与 #13 不开工。
主要语言
没有语言数据
星标
0
派生
1
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

LinuxSuRen/tick-flow 的其他 Issue

查看 LinuxSuRen/tick-flow 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。