Jelajahi Sumber

fix(角色): 删除 worker 角色并把团队/成员去类型化(10 类角色→9 类)

业务侧口径变更(业主 2026-11-05 定案),非平台能力变更:

- 库表:ops_team 删 team_type(唯一索引收成 uq_ops_team_name)、ops_member 删
  member_type、customer_team_belong 删 team_type(部分唯一索引改为
  (customer_id, team_id) WHERE is_current,客户可挂多支团队、类型允许重叠)
- 快照:billing_snapshot_customer 删 team_regular_id/team_construction_id,
  新增逐工单类型子表 billing_snapshot_customer_team(period, customer_id,
  ticket_type, team_id);freeze_customer_snapshot 改收 team_by_ticket_type,
  主表与子表同事务写入、已定稿期次整体跳过
- OpenAPI:删 team_type/member_type 请求键,member_add/member_update 补
  ticket_types(I5 子集、可空=不接单);客户建档/编辑/改挂的两枚固定团队
  标量改为一枚 ops_team_ids 数组,导出列改 ops_team_names
- 错误码:I105 落 20082(原误写 20074,与 KLT-T214 撞号);I101/I102 按
  总则§9 真源同步为 20078/20079
- 文档:SEOH 建议书 v4.27/评估说明 v1.29 按 9 类角色复算(S7 3,900→3,510、
  S8 首年 150 万→135 万/三年 900 万→810 万,口径 11 否决结论不翻);组织册
  数据模型与 I5 用例描述同步
- 原型:客户列表按数组渲染所挂团队(原按 Object.entries 渲染会显示成
  「0·团队名」);开通账号注释去掉「按成员类型」

Co-authored-by: Cursor <cursoragent@cursor.com>
cg 2 minggu lalu
induk
melakukan
a8dc928c32

File diff ditekan karena terlalu besar
+ 3 - 3
docs/SEOH平台交互/SEOH平台能力补齐与优化建议书.md


File diff ditekan karena terlalu besar
+ 1 - 1
docs/SEOH平台交互/SEOH支撑能力评估与欠缺说明.md


+ 3 - 2
docs/详细设计说明书/01-第1册-组织区域账号团队/02-数据模型本域表.md

@@ -39,7 +39,7 @@
 
 > ⚠️ **2026-11-05 业主定案(角色码改名)**:运营主账号 `regAdmin` → **`opsMain`**、运营子账号 `regSubAdmin` → **`opsSub`**,与全库文档简写及 F18 口径(`admin`=总运营、`opsMain`=运营主账号、`opsSub`=运营子账号)对齐。两个旧名此后⛔ 不得出现在授键脚本、夹具、`role_code` 常量或新写文档,仅存于留痕/历史对照行;代码侧同步=`src/crates/bos-core/src/roles.rs`、`src/migrations/dev/20261104000001_bos_core_tables.sql` 注释、原型 `prototype/app.js`/`data.js`。⚠️ 主/子账号由 `role_code` 表达 ⇒ 组织§5.4 `OR-11` 主账号转交=`is_primary` 与 `role_code`(`opsMain`↔`opsSub`)同事务切换,⛔ 不再有"只改主/子标记、不改角色"的旧表述。
 >
-> 需求 12 册的「录入人员」不是第 11 类角色,是运维子账号的变体 ⇒ 用 `role_code=ops + entry_only=true` 表达,其谓词差异只有一条:工单查询恒空集(不分派)`[Data-backed]`(原实施计划 §6.2 表)。⚠️ 2026-11-05 起**不再有 `worker` 角色**:原「施工人员」是运维子账号的一个实例(成员档案上只勾了开户),不是独立角色;角色总数由 10 类降为 9 类,工单可接类型由 `ops_member_ticket_type` 决定,⛔ 不写在 `role_code` 上。
+> 需求 12 册的「录入人员」**不是独立角色**(历史上曾议为"第 11 类角色",已裁决不建)⇒ 它是运维子账号的一个形态:`role_code=ops` + `bos_user_binding.entry_only=true` + 成员档案不勾任何接单类型(`ops_member_ticket_type` 为空集),其谓词差异只有一条:工单查询恒空集(不分派)`[Data-backed]`(原实施计划 §6.2 表)。⚠️ 2026-11-05 起**不再有 `worker` 角色**:原「施工人员」同样是运维子账号的一个实例(成员档案上只勾了开户),不是独立角色;角色总数由 10 类降为 9 类,工单可接类型由 `ops_member_ticket_type` 决定,⛔ 不写在 `role_code` 上。
 
 **`bos_account_ext`(账号业务扩展,M6)** `[Data-backed]`
 
@@ -104,11 +104,12 @@ erDiagram
   operator ||--o{ customer : "operator_id 归属等值"
   partner ||--o{ customer : "partner_id 归属等值"
   ops_team ||--o{ customer_team_belong : "team_id"
-  customer ||--|| customer_team_belong : "当前归属"
+  customer ||--o{ customer_team_belong : "当前归属(可挂多支团队)"
   customer ||--|| customer_region_mount : "挂载请求号"
   region_node ||--o{ dim_node_ancestor : "平台树→缓存"
   region_node ||--o{ customer_region_mount : "parent_node_id"
   customer ||--o{ billing_snapshot_customer : "账期期初冻结"
+  billing_snapshot_customer ||--o{ billing_snapshot_customer_team : "按工单类型冻结承接团队"
   iam_user ||--o{ bos_audit_log : "操作者"
 ```
 

+ 1 - 1
docs/详细设计说明书/01-第1册-组织区域账号团队/15-测试用例设计.md

@@ -10,7 +10,7 @@
 | 未设置谓词 | 绕过 `predicate()` 直接取字段 | `predicate()` 返 `Err`;类型上拿不到"默认全量" |
 | **静态断言**:`for_partner`/`for_operator` | 断言生成的 SQL 串**不含** `dim_node_ancestor` | 命中即失败(这是"合伙人/运营商不读树"的可执行守卫,总则§6.3) |
 | `check_scope_containment(tx, 变更前后)` | ① 真超出;② 调整后仍是子集;③ 改个人范围后仍是子集;④ **同一构造先改成"跟着团队走"再缩同一片**;⑤ 只有使原团队失去该客户才触发 | ① 报越界;②③④ **通过**;⑤ 判定用前后差集(组织§10.1) |
-| `check_i1`…`check_i6` | 每条一正一反;I3 只含"同一团队不重复挂"(类型重叠自 2026-11-05 起不拦截,改由派单期专精优先唯一确定,见 工单§3.4.1);I5 含"成员类型集合越出团队集合即拒"与"空集合合法";I6 含"同用途分类同时间" | 冲突整单回滚、返回 `KLT-Ixxx` |
+| `check_i1`…`check_i6` | 每条一正一反;I3 只含"同一团队不重复挂"(类型重叠自 2026-11-05 起不拦截,改由派单期专精优先唯一确定,见 工单§3.4.1);I5 含"成员可处理工单类型集合越出团队可分配类型集合即拒(`KLT-I105`,返回越界类型清单)"与"空集合合法(不接单)";I6 含"同用途分类同时间" | 冲突整单回滚、返回 `KLT-Ixxx` |
 | I7–I9 | **不写用例**(第 2/3 期接线,函数未建) | 不得为凑覆盖率建空函数 |
 | 幂等键派生 | 同输入两次派生;改挂类带 `request_id` 的两次不同操作 | 同输入同键;不同操作不同键;`request_id` 不出现在业务派生键里(总则§12.6) |
 | 主账号登录名自动转写 | 6 步逐级:带符号/带公司后缀/纯中文/空回落主体号去横线/撞名追加 `2`/`3` | 确定性、可重复、过唯一性守卫(组织§4.5) |

+ 2 - 2
prototype/app.js

@@ -1802,7 +1802,7 @@ function enterpriseTable(indexes, opts = {}) {
   const rows = indexes.map((i) => {
     const e = db.enterprises[i];
     /* 运维团队一行一个:与「、」串成整句相比列宽能收窄,行尾三枚按钮才排得下 */
-    const teams = Object.entries(e.teams).map(([type, ti]) => esc(`${type}·${db.teams[ti].name}`)).join("<br>");
+    const teams = (e.teams || []).map((ti) => esc(db.teams[ti] ? db.teams[ti].name : "(已删除团队)")).join("<br>");
     return `<tr class="clickable" role="button" tabindex="0" data-go="enterprise" data-id="${i}">
       <td>${seq(i)}</td>
       <td class="c-ent">${esc(e.no)}<br><span class="note">${esc(e.name)}</span></td>
@@ -4746,7 +4746,7 @@ function canManageRegOpsTeam(ti) {
   return isAdmin(u) || (isOpsAcct(u) && u.regTeam === ti);
 }
 
-/* 开通登录账号:运营商建对账查看账号行,运维按成员类型建子账号行,运营团队成员与客户在既有行上补登录名 */
+/* 开通登录账号:运营商建对账查看账号行,运维为成员档案开通子账号,运营团队成员与客户在既有行上补登录名 */
 function openAcctRow(t, login, must, phone) {
   let row;
   if (t.type === "operator") {

+ 40 - 45
src/bin/klt-bos/openapi.yaml

@@ -1250,7 +1250,7 @@ paths:
   /ops_team/create@v1:
     post:
       summary: 新建运维团队
-      description: 建档后 team_type 不可改。须指定所属区域、团队类型、可派工单类型≥1、分派方式与结算口径。
+      description: 须指定所属区域、可派工单类型≥1、分派方式与结算口径。⚠️ 2026-11-05 起团队不分类型(无 team_type 键)。
       x-require-auth: true
       x-resource-type: bos.ops_team
       x-action: create
@@ -1275,12 +1275,6 @@ paths:
                     region_node_id:
                       type: string
                       description: 所属区域节点 ID
-                    team_type:
-                      type: string
-                      description: 团队类型:regular=常规;construction=施工(建后不可改)
-                      enum:
-                      - regular
-                      - construction
                     ticket_types:
                       type: array
                       description: 可派工单类型列表(至少 1 项)
@@ -1308,7 +1302,6 @@ paths:
                   required:
                   - team_name
                   - region_node_id
-                  - team_type
                   - ticket_types
                   - dispatch_mode
               required:
@@ -1319,7 +1312,7 @@ paths:
   /ops_team/update@v1:
     post:
       summary: 编辑运维团队
-      description: 编辑团队资料;拒收 team_type(建后不可改)。
+      description: 编辑团队资料。⚠️ 2026-11-05 起团队不分类型,请求体无 team_type 键。
       x-require-auth: true
       x-resource-type: bos.ops_team
       x-action: update
@@ -1448,7 +1441,7 @@ paths:
   /ops_team/member_add@v1:
     post:
       summary: 添加运维成员
-      description: 成员类型与账号角色一一映射。
+      description: 新建成员档案并开通运维子账号(`role_code=ops`)。⚠️ 2026-11-05 起成员不分类型,服务侧只校验 `ticket_types` 是团队可分配类型的子集(`KLT-I105`,可为空=不接单)。
       x-require-auth: true
       x-resource-type: bos.ops_team
       x-action: manage
@@ -1470,12 +1463,12 @@ paths:
                     team_id:
                       type: string
                       description: 团队 ID
-                    member_type:
-                      type: string
-                      description: 成员类型:regular=常规;construction=施工
-                      enum:
-                      - regular
-                      - construction
+                    ticket_types:
+                      type: array
+                      description: 该成员可处理的工单类型(须为团队可分配类型的子集;空数组=不接单,如录入人员)
+                      items:
+                        type: string
+                        description: 工单类型码
                     username:
                       type: string
                       description: 登录名
@@ -1484,7 +1477,6 @@ paths:
                       description: 手机号(可选)
                   required:
                   - team_id
-                  - member_type
                   - username
               required:
               - data
@@ -1494,7 +1486,7 @@ paths:
   /ops_team/member_update@v1:
     post:
       summary: 更新运维成员
-      description: 可改成员类型;类型变更同事务改写 role_code。
+      description: 可改手机号与可处理工单类型。⚠️ 2026-11-05 起成员不分类型,⛔ 不因类型变更改写 role_code;可接类型落 ops_member_ticket_type。
       x-require-auth: true
       x-resource-type: bos.ops_team
       x-action: manage
@@ -1516,12 +1508,15 @@ paths:
                     team_id:
                       type: string
                       description: 团队 ID
+                    ticket_types:
+                      type: array
+                      description: 该成员可处理的工单类型(整体替换;须为团队可分配类型的子集;空数组=不接单)
+                      items:
+                        type: string
+                        description: 工单类型码
                     member_id:
                       type: string
                       description: 成员 ID
-                    member_type:
-                      type: string
-                      description: 成员类型:regular/construction
                     mobile:
                       type: string
                       description: 手机号(可选)
@@ -1718,12 +1713,12 @@ paths:
                     address:
                       type: string
                       description: 地址(可选)
-                    regular_ops_team_id:
-                      type: string
-                      description: 常规运维团队 ID(可选)
-                    construction_ops_team_id:
-                      type: string
-                      description: 施工运维团队 ID(可选)
+                    ops_team_ids:
+                      type: array
+                      description: 所挂运维团队 ID 列表(可选;至少一支时须在操作人负责范围内,多支之间允许可分配类型重叠)
+                      items:
+                        type: string
+                        description: 运维团队 ID
                     primary_username:
                       type: string
                       description: 客户主账号登录名(可选)
@@ -1870,12 +1865,12 @@ paths:
                     address:
                       type: string
                       description: 地址
-                    regular_ops_team_id:
-                      type: string
-                      description: 常规运维团队 ID
-                    construction_ops_team_id:
-                      type: string
-                      description: 施工运维团队 ID
+                    ops_team_ids:
+                      type: array
+                      description: 所挂运维团队 ID 列表(整体替换当前归属;多支之间允许可分配类型重叠)
+                      items:
+                        type: string
+                        description: 运维团队 ID
                     row_version:
                       type: integer
                       description: 乐观锁版本(若启用)
@@ -2071,12 +2066,12 @@ paths:
                     new_region_node_id:
                       type: string
                       description: 新挂载区域节点 ID
-                    regular_ops_team_id:
-                      type: string
-                      description: 常规运维团队 ID(可选,随改挂重绑)
-                    construction_ops_team_id:
-                      type: string
-                      description: 施工运维团队 ID(可选,随改挂重绑)
+                    ops_team_ids:
+                      type: array
+                      description: 所挂运维团队 ID 列表(可选,随改挂重绑)
+                      items:
+                        type: string
+                        description: 运维团队 ID
                   required:
                   - customer_id
                   - new_region_node_id
@@ -2195,12 +2190,12 @@ paths:
                           partner_name:
                             type: string
                             description: 合伙人
-                          regular_ops_team_name:
-                            type: string
-                            description: 常规运维团队
-                          construction_ops_team_name:
-                            type: string
-                            description: 施工运维团队
+                          ops_team_names:
+                            type: array
+                            description: 所挂运维团队名称列表(多支时逐项列出)
+                            items:
+                              type: string
+                              description: 运维团队名称
                           primary_username:
                             type: string
                             description: 主账号登录名

+ 3 - 3
src/crates/bos-core/src/error.rs

@@ -109,9 +109,9 @@ impl KltCode {
             Self::T225 => 20052,
             Self::C001 => 20060,
             Self::C008 => 20061,
-            Self::I101 => 20070,
-            Self::I102 => 20071,
-            Self::I105 => 20074,
+            Self::I101 => 20078,
+            Self::I102 => 20079,
+            Self::I105 => 20082,
             Self::S401 => 20101,
             Self::S402 => 20102,
             Self::S403 => 20103,

+ 19 - 15
src/migrations/dev/20261104000001_bos_core_tables.sql

@@ -176,7 +176,6 @@ COMMENT ON COLUMN ent_team_member.is_primary IS '是否主账号(每团队有
 
 CREATE TABLE IF NOT EXISTS ops_team (
     team_id VARCHAR(64) PRIMARY KEY,
-    team_type VARCHAR(32) NOT NULL,
     team_name VARCHAR(128) NOT NULL,
     team_name_norm VARCHAR(128) NOT NULL,
     region_node_id VARCHAR(64) NOT NULL,
@@ -185,12 +184,11 @@ CREATE TABLE IF NOT EXISTS ops_team (
     settle_value NUMERIC(12,4) NULL,
     created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
 );
-CREATE UNIQUE INDEX IF NOT EXISTS uq_ops_team_type_name ON ops_team (team_type, team_name_norm);
+CREATE UNIQUE INDEX IF NOT EXISTS uq_ops_team_name ON ops_team (team_name_norm);
 COMMENT ON TABLE ops_team IS '运维团队档案';
 COMMENT ON COLUMN ops_team.team_id IS '运维团队 ID';
-COMMENT ON COLUMN ops_team.team_type IS '团队类型:regular(常规)/construction(施工)';
 COMMENT ON COLUMN ops_team.team_name IS '团队名称';
-COMMENT ON COLUMN ops_team.team_name_norm IS '团队名称归一化(同类型唯一)';
+COMMENT ON COLUMN ops_team.team_name_norm IS '团队名称归一化(全站唯一)';
 COMMENT ON COLUMN ops_team.region_node_id IS '所属区域节点 ID';
 COMMENT ON COLUMN ops_team.dispatch_mode IS '工单分派方式:manual/auto_avg';
 COMMENT ON COLUMN ops_team.settle_mode IS '分成方式:ratio/amount/per_account;空=未配置';
@@ -210,7 +208,6 @@ CREATE TABLE IF NOT EXISTS ops_member (
     member_id VARCHAR(64) PRIMARY KEY,
     team_id VARCHAR(64) NOT NULL REFERENCES ops_team(team_id),
     user_id BIGINT NOT NULL UNIQUE,
-    member_type VARCHAR(32) NOT NULL,
     scope_mode VARCHAR(32) NOT NULL DEFAULT 'follow_team',
     is_primary BOOLEAN NOT NULL DEFAULT FALSE,
     created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
@@ -220,7 +217,6 @@ COMMENT ON TABLE ops_member IS '运维团队成员';
 COMMENT ON COLUMN ops_member.member_id IS '成员档案 ID';
 COMMENT ON COLUMN ops_member.team_id IS '所属运维团队 ID';
 COMMENT ON COLUMN ops_member.user_id IS '绑定平台用户 ID(一人一档)';
-COMMENT ON COLUMN ops_member.member_type IS '成员类型:regular(常规)/construction(施工)';
 COMMENT ON COLUMN ops_member.scope_mode IS '负责范围形态:follow_team/region/customer';
 COMMENT ON COLUMN ops_member.is_primary IS '是否团队主账号(每团队有且仅有一个)';
 COMMENT ON COLUMN ops_member.created_at IS '创建时间';
@@ -280,18 +276,16 @@ COMMENT ON COLUMN customer_region_mount.cleaned_at IS '悬空清理完成时间'
 CREATE TABLE IF NOT EXISTS customer_team_belong (
     id BIGSERIAL PRIMARY KEY,
     customer_id VARCHAR(64) NOT NULL REFERENCES customer(customer_id),
-    team_type VARCHAR(32) NOT NULL,
     team_id VARCHAR(64) NOT NULL,
     is_current BOOLEAN NOT NULL DEFAULT TRUE,
     valid_from TIMESTAMPTZ NOT NULL DEFAULT NOW(),
     valid_to TIMESTAMPTZ NULL
 );
-CREATE UNIQUE INDEX IF NOT EXISTS uq_customer_team_current ON customer_team_belong (customer_id, team_type) WHERE is_current;
-COMMENT ON TABLE customer_team_belong IS '客户对各类型运维团队的归属(当前值 + 历史)';
+CREATE UNIQUE INDEX IF NOT EXISTS uq_customer_team_current ON customer_team_belong (customer_id, team_id) WHERE is_current;
+COMMENT ON TABLE customer_team_belong IS '客户对所挂运维团队的归属(当前值 + 历史)';
 COMMENT ON COLUMN customer_team_belong.id IS '主键';
 COMMENT ON COLUMN customer_team_belong.customer_id IS '客户主体号';
-COMMENT ON COLUMN customer_team_belong.team_type IS '团队类型:regular/construction(同类型当前至多一条)';
-COMMENT ON COLUMN customer_team_belong.team_id IS '运维团队 ID';
+COMMENT ON COLUMN customer_team_belong.team_id IS '运维团队 ID(同一团队对同一客户当前至多一条)';
 COMMENT ON COLUMN customer_team_belong.is_current IS '是否当前归属';
 COMMENT ON COLUMN customer_team_belong.valid_from IS '生效起';
 COMMENT ON COLUMN customer_team_belong.valid_to IS '生效止(空=仍有效)';
@@ -303,8 +297,6 @@ CREATE TABLE IF NOT EXISTS billing_snapshot_customer (
     region_path TEXT NOT NULL,
     operator_id VARCHAR(64) NOT NULL,
     partner_id VARCHAR(64) NULL,
-    team_regular_id VARCHAR(64) NULL,
-    team_construction_id VARCHAR(64) NULL,
     frozen_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
     PRIMARY KEY (period, customer_id)
 );
@@ -315,10 +307,22 @@ COMMENT ON COLUMN billing_snapshot_customer.region_node_id IS '冻结的归属
 COMMENT ON COLUMN billing_snapshot_customer.region_path IS '冻结的区域全路径文本';
 COMMENT ON COLUMN billing_snapshot_customer.operator_id IS '冻结的归属运营商 ID';
 COMMENT ON COLUMN billing_snapshot_customer.partner_id IS '冻结的归属合伙人 ID';
-COMMENT ON COLUMN billing_snapshot_customer.team_regular_id IS '冻结的常规运维团队 ID';
-COMMENT ON COLUMN billing_snapshot_customer.team_construction_id IS '冻结的施工运维团队 ID';
 COMMENT ON COLUMN billing_snapshot_customer.frozen_at IS '冻结时间';
 
+-- 团队维度逐工单类型一行(2026-11-05 起团队不分类型、客户可挂多支团队)
+CREATE TABLE IF NOT EXISTS billing_snapshot_customer_team (
+    period VARCHAR(7) NOT NULL,
+    customer_id VARCHAR(64) NOT NULL,
+    ticket_type VARCHAR(32) NOT NULL,
+    team_id VARCHAR(64) NOT NULL,
+    PRIMARY KEY (period, customer_id, ticket_type)
+);
+COMMENT ON TABLE billing_snapshot_customer_team IS '账期期初客户在各工单类型上的承接团队(与主表同事务冻结)';
+COMMENT ON COLUMN billing_snapshot_customer_team.period IS '账期标识 YYYY-MM';
+COMMENT ON COLUMN billing_snapshot_customer_team.customer_id IS '客户主体号';
+COMMENT ON COLUMN billing_snapshot_customer_team.ticket_type IS '工单类型码(派单期由专精优先唯一确定承接团队)';
+COMMENT ON COLUMN billing_snapshot_customer_team.team_id IS '冻结的承接运维团队 ID';
+
 CREATE TABLE IF NOT EXISTS import_batch (
     batch_id BIGSERIAL PRIMARY KEY,
     batch_no VARCHAR(32) NOT NULL UNIQUE,

+ 40 - 9
src/modules/billing/src/lib.rs

@@ -13,6 +13,10 @@ pub fn validate_period(period: &str) -> Result<(), BosError> {
 }
 
 /// 写入或跳过已存在的期初快照(存在即定稿,不 UPDATE)。
+///
+/// ⚠️ 2026-11-05 起团队不分类型、客户可挂多支团队 ⇒ 主表不再持有团队维度列,
+/// 「该期哪个工单类型由哪支团队承接」落子表 `billing_snapshot_customer_team`。
+/// 主表与子表**同一事务**写入:主表已存在(已定稿)即整体跳过,子表不补写。
 pub async fn freeze_customer_snapshot(
     pool: &PgPool,
     period: &str,
@@ -21,17 +25,19 @@ pub async fn freeze_customer_snapshot(
     region_path: &str,
     operator_id: &str,
     partner_id: Option<&str>,
-    team_regular_id: Option<&str>,
-    team_construction_id: Option<&str>,
+    team_by_ticket_type: &[(&str, &str)],
 ) -> Result<bool, BosError> {
     validate_period(period)?;
+    let mut tx = pool
+        .begin()
+        .await
+        .map_err(|e| BosError::internal(e.to_string()))?;
     let res = sqlx::query(
         r#"
         INSERT INTO billing_snapshot_customer (
             period, customer_id, region_node_id, region_path,
-            operator_id, partner_id, team_regular_id, team_construction_id,
-            frozen_at
-        ) VALUES ($1,$2,$3,$4,$5,$6,$7,$8, NOW())
+            operator_id, partner_id, frozen_at
+        ) VALUES ($1,$2,$3,$4,$5,$6, NOW())
         ON CONFLICT (period, customer_id) DO NOTHING
         "#,
     )
@@ -41,12 +47,37 @@ pub async fn freeze_customer_snapshot(
     .bind(region_path)
     .bind(operator_id)
     .bind(partner_id)
-    .bind(team_regular_id)
-    .bind(team_construction_id)
-    .execute(pool)
+    .execute(&mut *tx)
     .await
     .map_err(|e| BosError::internal(e.to_string()))?;
-    Ok(res.rows_affected() > 0)
+    if res.rows_affected() == 0 {
+        // 已定稿的期次不补写子表,避免与主表口径错位
+        tx.rollback()
+            .await
+            .map_err(|e| BosError::internal(e.to_string()))?;
+        return Ok(false);
+    }
+    for (ticket_type, team_id) in team_by_ticket_type {
+        sqlx::query(
+            r#"
+            INSERT INTO billing_snapshot_customer_team (
+                period, customer_id, ticket_type, team_id
+            ) VALUES ($1,$2,$3,$4)
+            ON CONFLICT (period, customer_id, ticket_type) DO NOTHING
+            "#,
+        )
+        .bind(period)
+        .bind(customer_id)
+        .bind(ticket_type)
+        .bind(team_id)
+        .execute(&mut *tx)
+        .await
+        .map_err(|e| BosError::internal(e.to_string()))?;
+    }
+    tx.commit()
+        .await
+        .map_err(|e| BosError::internal(e.to_string()))?;
+    Ok(true)
 }
 
 pub fn period_start_date(period: &str) -> Result<NaiveDate, BosError> {

+ 40 - 45
src/openapi.yaml

@@ -1250,7 +1250,7 @@ paths:
   /ops_team/create@v1:
     post:
       summary: 新建运维团队
-      description: 建档后 team_type 不可改。须指定所属区域、团队类型、可派工单类型≥1、分派方式与结算口径。
+      description: 须指定所属区域、可派工单类型≥1、分派方式与结算口径。⚠️ 2026-11-05 起团队不分类型(无 team_type 键)。
       x-require-auth: true
       x-resource-type: bos.ops_team
       x-action: create
@@ -1275,12 +1275,6 @@ paths:
                     region_node_id:
                       type: string
                       description: 所属区域节点 ID
-                    team_type:
-                      type: string
-                      description: 团队类型:regular=常规;construction=施工(建后不可改)
-                      enum:
-                      - regular
-                      - construction
                     ticket_types:
                       type: array
                       description: 可派工单类型列表(至少 1 项)
@@ -1308,7 +1302,6 @@ paths:
                   required:
                   - team_name
                   - region_node_id
-                  - team_type
                   - ticket_types
                   - dispatch_mode
               required:
@@ -1319,7 +1312,7 @@ paths:
   /ops_team/update@v1:
     post:
       summary: 编辑运维团队
-      description: 编辑团队资料;拒收 team_type(建后不可改)。
+      description: 编辑团队资料。⚠️ 2026-11-05 起团队不分类型,请求体无 team_type 键。
       x-require-auth: true
       x-resource-type: bos.ops_team
       x-action: update
@@ -1448,7 +1441,7 @@ paths:
   /ops_team/member_add@v1:
     post:
       summary: 添加运维成员
-      description: 成员类型与账号角色一一映射。
+      description: 新建成员档案并开通运维子账号(`role_code=ops`)。⚠️ 2026-11-05 起成员不分类型,服务侧只校验 `ticket_types` 是团队可分配类型的子集(`KLT-I105`,可为空=不接单)。
       x-require-auth: true
       x-resource-type: bos.ops_team
       x-action: manage
@@ -1470,12 +1463,12 @@ paths:
                     team_id:
                       type: string
                       description: 团队 ID
-                    member_type:
-                      type: string
-                      description: 成员类型:regular=常规;construction=施工
-                      enum:
-                      - regular
-                      - construction
+                    ticket_types:
+                      type: array
+                      description: 该成员可处理的工单类型(须为团队可分配类型的子集;空数组=不接单,如录入人员)
+                      items:
+                        type: string
+                        description: 工单类型码
                     username:
                       type: string
                       description: 登录名
@@ -1484,7 +1477,6 @@ paths:
                       description: 手机号(可选)
                   required:
                   - team_id
-                  - member_type
                   - username
               required:
               - data
@@ -1494,7 +1486,7 @@ paths:
   /ops_team/member_update@v1:
     post:
       summary: 更新运维成员
-      description: 可改成员类型;类型变更同事务改写 role_code。
+      description: 可改手机号与可处理工单类型。⚠️ 2026-11-05 起成员不分类型,⛔ 不因类型变更改写 role_code;可接类型落 ops_member_ticket_type。
       x-require-auth: true
       x-resource-type: bos.ops_team
       x-action: manage
@@ -1516,12 +1508,15 @@ paths:
                     team_id:
                       type: string
                       description: 团队 ID
+                    ticket_types:
+                      type: array
+                      description: 该成员可处理的工单类型(整体替换;须为团队可分配类型的子集;空数组=不接单)
+                      items:
+                        type: string
+                        description: 工单类型码
                     member_id:
                       type: string
                       description: 成员 ID
-                    member_type:
-                      type: string
-                      description: 成员类型:regular/construction
                     mobile:
                       type: string
                       description: 手机号(可选)
@@ -1718,12 +1713,12 @@ paths:
                     address:
                       type: string
                       description: 地址(可选)
-                    regular_ops_team_id:
-                      type: string
-                      description: 常规运维团队 ID(可选)
-                    construction_ops_team_id:
-                      type: string
-                      description: 施工运维团队 ID(可选)
+                    ops_team_ids:
+                      type: array
+                      description: 所挂运维团队 ID 列表(可选;至少一支时须在操作人负责范围内,多支之间允许可分配类型重叠)
+                      items:
+                        type: string
+                        description: 运维团队 ID
                     primary_username:
                       type: string
                       description: 客户主账号登录名(可选)
@@ -1870,12 +1865,12 @@ paths:
                     address:
                       type: string
                       description: 地址
-                    regular_ops_team_id:
-                      type: string
-                      description: 常规运维团队 ID
-                    construction_ops_team_id:
-                      type: string
-                      description: 施工运维团队 ID
+                    ops_team_ids:
+                      type: array
+                      description: 所挂运维团队 ID 列表(整体替换当前归属;多支之间允许可分配类型重叠)
+                      items:
+                        type: string
+                        description: 运维团队 ID
                     row_version:
                       type: integer
                       description: 乐观锁版本(若启用)
@@ -2071,12 +2066,12 @@ paths:
                     new_region_node_id:
                       type: string
                       description: 新挂载区域节点 ID
-                    regular_ops_team_id:
-                      type: string
-                      description: 常规运维团队 ID(可选,随改挂重绑)
-                    construction_ops_team_id:
-                      type: string
-                      description: 施工运维团队 ID(可选,随改挂重绑)
+                    ops_team_ids:
+                      type: array
+                      description: 所挂运维团队 ID 列表(可选,随改挂重绑)
+                      items:
+                        type: string
+                        description: 运维团队 ID
                   required:
                   - customer_id
                   - new_region_node_id
@@ -2195,12 +2190,12 @@ paths:
                           partner_name:
                             type: string
                             description: 合伙人
-                          regular_ops_team_name:
-                            type: string
-                            description: 常规运维团队
-                          construction_ops_team_name:
-                            type: string
-                            description: 施工运维团队
+                          ops_team_names:
+                            type: array
+                            description: 所挂运维团队名称列表(多支时逐项列出)
+                            items:
+                              type: string
+                              description: 运维团队名称
                           primary_username:
                             type: string
                             description: 主账号登录名

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini