|
@@ -114,18 +114,21 @@ const CONTRACT_COLS: &str = "k.contract_id, k.customer_id, k.contract_no, k.stat
|
|
|
k.start_date, k.end_date, k.agent_name, k.agent_mobile, \
|
|
k.start_date, k.end_date, k.agent_name, k.agent_mobile, \
|
|
|
k.agent_handover_on, k.agent_org, k.attachment_url, k.row_version, \
|
|
k.agent_handover_on, k.agent_org, k.attachment_url, k.row_version, \
|
|
|
k.source, k.created_by, \
|
|
k.source, k.created_by, \
|
|
|
|
|
+ NULLIF(TRIM(cu.customer_name), '') AS customer_name, \
|
|
|
NULLIF(COALESCE(NULLIF(a.display_name,''), NULLIF(u.username,''), \
|
|
NULLIF(COALESCE(NULLIF(a.display_name,''), NULLIF(u.username,''), \
|
|
|
k.created_by), '') AS created_by_name, \
|
|
k.created_by), '') AS created_by_name, \
|
|
|
NULLIF(COALESCE(NULLIF(et.team_name,''), NULLIF(ot.team_name,''), \
|
|
NULLIF(COALESCE(NULLIF(et.team_name,''), NULLIF(ot.team_name,''), \
|
|
|
CASE WHEN u.subject_type = 'hq' THEN '总部' END), '') AS created_by_org, \
|
|
CASE WHEN u.subject_type = 'hq' THEN '总部' END), '') AS created_by_org, \
|
|
|
u.mobile AS created_by_mobile";
|
|
u.mobile AS created_by_mobile";
|
|
|
-/// ⚠️ 四个 LEFT JOIN **必须**与 [`CONTRACT_COLS`] 成对出现(列里有 `a.`/`u.`/`et.`/`ot.` 的引用)。
|
|
|
|
|
|
|
+/// ⚠️ 五个 LEFT JOIN **必须**与 [`CONTRACT_COLS`] 成对出现(列里有 `cu.`/`a.`/`u.`/`et.`/`ot.`)。
|
|
|
/// 都是按主键/账号一一对应 ⇒ ⛔ 改变行数(列表统计卡与列表同一条 WHERE 的前提)。
|
|
/// 都是按主键/账号一一对应 ⇒ ⛔ 改变行数(列表统计卡与列表同一条 WHERE 的前提)。
|
|
|
///
|
|
///
|
|
|
/// 录入经办人三段的取数:姓名=`bos_account_ext.display_name` → 登录名 → 账号 ID 兜底;
|
|
/// 录入经办人三段的取数:姓名=`bos_account_ext.display_name` → 登录名 → 账号 ID 兜底;
|
|
|
/// 机构=运营团队/运维团队名(`hq` 总运营账号回落「总运营」);联系方式=绑定手机号
|
|
/// 机构=运营团队/运维团队名(`hq` 总运营账号回落「总运营」);联系方式=绑定手机号
|
|
|
/// (⚠️ 出参前在 [`base_json`] 统一掩码,需求 §3.3「列表页默认掩码」同口径)。
|
|
/// (⚠️ 出参前在 [`base_json`] 统一掩码,需求 §3.3「列表页默认掩码」同口径)。
|
|
|
|
|
+/// 客户名经 `customer` JOIN 同趟带回(⛔ 列表再 `pairs_by` 一跳)。
|
|
|
const CONTRACT_FROM: &str = "FROM contract k \
|
|
const CONTRACT_FROM: &str = "FROM contract k \
|
|
|
|
|
+ LEFT JOIN customer cu ON cu.customer_id = k.customer_id \
|
|
|
LEFT JOIN bos_user_binding u ON u.user_id::text = k.created_by \
|
|
LEFT JOIN bos_user_binding u ON u.user_id::text = k.created_by \
|
|
|
LEFT JOIN bos_account_ext a ON a.user_id = u.user_id \
|
|
LEFT JOIN bos_account_ext a ON a.user_id = u.user_id \
|
|
|
LEFT JOIN ent_team et ON et.team_id = u.subject_id AND u.subject_type = 'ent_team' \
|
|
LEFT JOIN ent_team et ON et.team_id = u.subject_id AND u.subject_type = 'ent_team' \
|
|
@@ -369,6 +372,9 @@ struct ContractRow {
|
|
|
contract_id: String,
|
|
contract_id: String,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
customer_id: String,
|
|
customer_id: String,
|
|
|
|
|
+ /// JOIN `customer` 同趟带回;客户注销/脏引用 ⇒ `None`。
|
|
|
|
|
+ #[serde(default, deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ customer_name: Option<String>,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
|
contract_no: String,
|
|
contract_no: String,
|
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
#[serde(deserialize_with = "de::as_string")]
|
|
@@ -676,35 +682,78 @@ async fn load_children(db: &UdsClient, ids: &[String]) -> Result<Children, BosEr
|
|
|
}
|
|
}
|
|
|
let mut p = Params::default();
|
|
let mut p = Params::default();
|
|
|
let in_pred = push_in(&mut p, "i.contract_id", ids, "text");
|
|
let in_pred = push_in(&mut p, "i.contract_id", ids, "text");
|
|
|
|
|
+ // UDS 收拢:条目 + catalog_plan 名/形态 原 2 跳 → 1 条 LEFT JOIN。
|
|
|
let sql = format!(
|
|
let sql = format!(
|
|
|
"SELECT i.item_id, i.contract_id, i.plan_id, i.quantity, i.item_family, \
|
|
"SELECT i.item_id, i.contract_id, i.plan_id, i.quantity, i.item_family, \
|
|
|
- i.item_mode, i.serves_item_id, i.ref_subscription_id, i.line_exits \
|
|
|
|
|
- FROM contract_service_item i WHERE {in_pred} ORDER BY i.created_at, i.item_id"
|
|
|
|
|
|
|
+ i.item_mode, i.serves_item_id, i.ref_subscription_id, i.line_exits, \
|
|
|
|
|
+ p.plan_name AS joined_plan_name, p.plan_family AS joined_plan_family, \
|
|
|
|
|
+ p.sub_account_quota AS joined_sub_account_quota \
|
|
|
|
|
+ FROM contract_service_item i \
|
|
|
|
|
+ LEFT JOIN catalog_plan p ON p.plan_id = i.plan_id \
|
|
|
|
|
+ WHERE {in_pred} ORDER BY i.created_at, i.item_id"
|
|
|
);
|
|
);
|
|
|
- let mut rows: Vec<ItemRow> = db.query_all::<ItemRow>(&sql, p.values()).await?;
|
|
|
|
|
-
|
|
|
|
|
- // D-22:条目只存 `plan_id`,套餐名与形态在 `catalog_plan`
|
|
|
|
|
- // ⇒ 汇总档位主键后**一次**批量回查(⛔ 逐条 N+1)。
|
|
|
|
|
- let plan_ids: Vec<String> = rows
|
|
|
|
|
- .iter()
|
|
|
|
|
- .map(|r| r.plan_id.clone())
|
|
|
|
|
- .filter(|s| !s.trim().is_empty())
|
|
|
|
|
- .collect::<BTreeSet<String>>()
|
|
|
|
|
- .into_iter()
|
|
|
|
|
- .collect();
|
|
|
|
|
- let plans = load_plan_names(db, &plan_ids).await?;
|
|
|
|
|
|
|
+ #[derive(Deserialize)]
|
|
|
|
|
+ struct ItemJoinRow {
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_string")]
|
|
|
|
|
+ item_id: String,
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_string")]
|
|
|
|
|
+ contract_id: String,
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_string")]
|
|
|
|
|
+ plan_id: String,
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ quantity: Option<String>,
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ item_family: Option<String>,
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ item_mode: Option<String>,
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ serves_item_id: Option<String>,
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ ref_subscription_id: Option<String>,
|
|
|
|
|
+ #[serde(default)]
|
|
|
|
|
+ line_exits: Option<Value>,
|
|
|
|
|
+ #[serde(default)]
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ joined_plan_name: Option<String>,
|
|
|
|
|
+ #[serde(default)]
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ joined_plan_family: Option<String>,
|
|
|
|
|
+ #[serde(default)]
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_opt_string")]
|
|
|
|
|
+ joined_sub_account_quota: Option<String>,
|
|
|
|
|
+ }
|
|
|
|
|
+ let rows: Vec<ItemJoinRow> = db.query_all::<ItemJoinRow>(&sql, p.values()).await?;
|
|
|
|
|
+ let mut plans: HashMap<String, PlanName> = HashMap::new();
|
|
|
let mut items: Children = HashMap::new();
|
|
let mut items: Children = HashMap::new();
|
|
|
- for r in rows.drain(..) {
|
|
|
|
|
- let cid = r.contract_id.clone();
|
|
|
|
|
- items.entry(cid).or_default().push(item_json(r, &plans));
|
|
|
|
|
|
|
+ for r in rows {
|
|
|
|
|
+ if let Some(name) = r.joined_plan_name.as_ref().map(|s| s.trim()).filter(|s| !s.is_empty()) {
|
|
|
|
|
+ plans.entry(r.plan_id.clone()).or_insert_with(|| PlanName {
|
|
|
|
|
+ plan_id: r.plan_id.clone(),
|
|
|
|
|
+ plan_name: name.to_string(),
|
|
|
|
|
+ plan_family: r.joined_plan_family.clone(),
|
|
|
|
|
+ sub_account_quota: r.joined_sub_account_quota.clone(),
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ let item = ItemRow {
|
|
|
|
|
+ item_id: r.item_id,
|
|
|
|
|
+ contract_id: r.contract_id.clone(),
|
|
|
|
|
+ plan_id: r.plan_id,
|
|
|
|
|
+ quantity: r.quantity,
|
|
|
|
|
+ item_family: r.item_family,
|
|
|
|
|
+ item_mode: r.item_mode,
|
|
|
|
|
+ serves_item_id: r.serves_item_id,
|
|
|
|
|
+ ref_subscription_id: r.ref_subscription_id,
|
|
|
|
|
+ line_exits: r.line_exits,
|
|
|
|
|
+ };
|
|
|
|
|
+ items.entry(r.contract_id).or_default().push(item_json(item, &plans));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
Ok(items)
|
|
Ok(items)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// 按档位主键集合批量回查「名称+形态+分账号额度」(D-22 展示联查,⛔ 逐条查)。
|
|
/// 按档位主键集合批量回查「名称+形态+分账号额度」(D-22 展示联查,⛔ 逐条查)。
|
|
|
///
|
|
///
|
|
|
/// 查不到(档位被删)⇒ 该条目回 `plan_name:null`=「未配置」,⛔ 拿 `plan_id` 冒充套餐名。
|
|
/// 查不到(档位被删)⇒ 该条目回 `plan_name:null`=「未配置」,⛔ 拿 `plan_id` 冒充套餐名。
|
|
|
|
|
+#[allow(dead_code)] // 列表路径已 JOIN;保留供其它回读复用
|
|
|
async fn load_plan_names(db: &UdsClient, ids: &[String]) -> Result<HashMap<String, PlanName>, BosError> {
|
|
async fn load_plan_names(db: &UdsClient, ids: &[String]) -> Result<HashMap<String, PlanName>, BosError> {
|
|
|
if ids.is_empty() {
|
|
if ids.is_empty() {
|
|
|
return Ok(HashMap::new());
|
|
return Ok(HashMap::new());
|
|
@@ -725,6 +774,8 @@ async fn load_plan_names(db: &UdsClient, ids: &[String]) -> Result<HashMap<Strin
|
|
|
|
|
|
|
|
/// 按本页 `customer_id` 集合回查 `customer.customer_name`(⛔ JOIN 嵌套循环)。
|
|
/// 按本页 `customer_id` 集合回查 `customer.customer_name`(⛔ JOIN 嵌套循环)。
|
|
|
/// 取数失败**不**降级——回 `Err`,⛔ 静默成片空名。
|
|
/// 取数失败**不**降级——回 `Err`,⛔ 静默成片空名。
|
|
|
|
|
+/// 列表/详情主路径已 JOIN `cu.customer_name`;保留供其它回读复用。
|
|
|
|
|
+#[allow(dead_code)]
|
|
|
async fn customer_names(db: &UdsClient, ids: &[String]) -> Result<HashMap<String, String>, BosError> {
|
|
async fn customer_names(db: &UdsClient, ids: &[String]) -> Result<HashMap<String, String>, BosError> {
|
|
|
let uniq: Vec<String> = ids.iter().cloned().collect::<BTreeSet<_>>().into_iter().collect();
|
|
let uniq: Vec<String> = ids.iter().cloned().collect::<BTreeSet<_>>().into_iter().collect();
|
|
|
let pairs = pairs_by(db, "customer", "customer_id", "customer_name", &uniq).await?;
|
|
let pairs = pairs_by(db, "customer", "customer_id", "customer_name", &uniq).await?;
|
|
@@ -2153,9 +2204,9 @@ fn resolve_contract_type(
|
|
|
"expand" | "change" if renew_from.is_some() => Err(BosError::bad_params(
|
|
"expand" | "change" if renew_from.is_some() => Err(BosError::bad_params(
|
|
|
"续签合同(带 renew_from_contract_id)的合同类型只能是 renew",
|
|
"续签合同(带 renew_from_contract_id)的合同类型只能是 renew",
|
|
|
)),
|
|
)),
|
|
|
- "expand" if !all_increment => Err(BosError::bad_params(
|
|
|
|
|
- "合同类型为扩容补充协议,但服务构成不是整批增量叠加服务(扩容不新开跨境链路)",
|
|
|
|
|
- )),
|
|
|
|
|
|
|
+ // D-CT-09:扩容允许纯跨境链路条目(页面可录 link);整批增量仍可走 expand。
|
|
|
|
|
+ // 旧口径「expand 必须全增量」与页面契约冲突,且落成 `KLT-S20004` 难排查。
|
|
|
|
|
+ "expand" | "change" | "new" | "renew" => Ok(kind.to_string()),
|
|
|
other => Ok(other.to_string()),
|
|
other => Ok(other.to_string()),
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -2777,11 +2828,16 @@ impl PlannedSubs {
|
|
|
/* ─────────── 续签「服务内容未变」判据(2026-11-17 定案:未变 ⇒ 不派工) ─────────── */
|
|
/* ─────────── 续签「服务内容未变」判据(2026-11-17 定案:未变 ⇒ 不派工) ─────────── */
|
|
|
|
|
|
|
|
/// 一份合同的服务构成条目(按 `created_at, item_id` 排序=续签带入时的原始顺序)。
|
|
/// 一份合同的服务构成条目(按 `created_at, item_id` 排序=续签带入时的原始顺序)。
|
|
|
|
|
+///
|
|
|
|
|
+/// 列集与 [`load_children`]/[`stored_items`] 对齐:缺 `item_mode`/`serves_item_id`/
|
|
|
|
|
+/// `ref_subscription_id` 时 UDS 反序列化 `ItemRow` 会直接 `KLT-S20007`(续签创建全链路阻断,
|
|
|
|
|
+/// D-CT-01)。
|
|
|
async fn items_of_contract(db: &UdsClient, contract_id: &str) -> Result<Vec<ItemRow>, BosError> {
|
|
async fn items_of_contract(db: &UdsClient, contract_id: &str) -> Result<Vec<ItemRow>, BosError> {
|
|
|
let mut p = Params::default();
|
|
let mut p = Params::default();
|
|
|
let c = p.push(Value::String(contract_id.to_string()));
|
|
let c = p.push(Value::String(contract_id.to_string()));
|
|
|
let sql = format!(
|
|
let sql = format!(
|
|
|
- "SELECT i.item_id, i.contract_id, i.plan_id, i.quantity, i.item_family, i.line_exits \
|
|
|
|
|
|
|
+ "SELECT i.item_id, i.contract_id, i.plan_id, i.quantity, i.item_family, \
|
|
|
|
|
+ i.item_mode, i.serves_item_id, i.ref_subscription_id, i.line_exits \
|
|
|
FROM contract_service_item i WHERE i.contract_id = {c}::text \
|
|
FROM contract_service_item i WHERE i.contract_id = {c}::text \
|
|
|
ORDER BY i.created_at, i.item_id"
|
|
ORDER BY i.created_at, i.item_id"
|
|
|
);
|
|
);
|
|
@@ -2941,6 +2997,20 @@ async fn plan_contract_subs(
|
|
|
format!("{prefix}:原订阅 {rid} 不属于客户 {customer_id}(§5.3)"),
|
|
format!("{prefix}:原订阅 {rid} 不属于客户 {customer_id}(§5.3)"),
|
|
|
)
|
|
)
|
|
|
})?;
|
|
})?;
|
|
|
|
|
+ // D-CT-08:原订阅已被替换过 ⇒ 显式拒绝(带次数),⛔ 再走「期间不相交 ⇒ 静默丢
|
|
|
|
|
+ // replaces」短路——截原后期间常不相交,第二条替换会因此悄悄变成新开。
|
|
|
|
|
+ match super::subscription::replacement_count(state, &rid).await {
|
|
|
|
|
+ Ok(0) => {}
|
|
|
|
|
+ Ok(k) => {
|
|
|
|
|
+ return Err(BosError::klt(
|
|
|
|
|
+ KltCode::M226,
|
|
|
|
|
+ format!(
|
|
|
|
|
+ "{prefix}:原订阅 {rid} 已被替换过 {k} 次:replaces_subscription_id 至多被指向一次"
|
|
|
|
|
+ ),
|
|
|
|
|
+ ));
|
|
|
|
|
+ }
|
|
|
|
|
+ Err(e) => return Err(e),
|
|
|
|
|
+ }
|
|
|
// 期间不相交 ⇒ 忽略替换键,按续签新开(旧行自然到期,截原会把它往后延)。
|
|
// 期间不相交 ⇒ 忽略替换键,按续签新开(旧行自然到期,截原会把它往后延)。
|
|
|
if !succession::period_hits(
|
|
if !succession::period_hits(
|
|
|
orig.start_date.as_deref(),
|
|
orig.start_date.as_deref(),
|
|
@@ -3366,7 +3436,7 @@ async fn do_update(
|
|
|
|| !same_text(draft.agent_org.as_deref(), cur.agent_org.as_deref());
|
|
|| !same_text(draft.agent_org.as_deref(), cur.agent_org.as_deref());
|
|
|
|
|
|
|
|
if billing_touched || archive_touched {
|
|
if billing_touched || archive_touched {
|
|
|
- let flags = opened_flags(db, &[contract_id.to_string()]).await?;
|
|
|
|
|
|
|
+ let (flags, _) = opened_flags(db, &[contract_id.to_string()]).await?;
|
|
|
let is_opened = matches!(flags.get(contract_id), Some(Opened::Opened));
|
|
let is_opened = matches!(flags.get(contract_id), Some(Opened::Opened));
|
|
|
let scope = contract_edit_scope(
|
|
let scope = contract_edit_scope(
|
|
|
&cur.source,
|
|
&cur.source,
|
|
@@ -3417,6 +3487,18 @@ async fn do_update(
|
|
|
.map(str::to_string);
|
|
.map(str::to_string);
|
|
|
|
|
|
|
|
if !touched_main && b.service_items.is_none() {
|
|
if !touched_main && b.service_items.is_none() {
|
|
|
|
|
+ // D-CT-09:只回传锁定键(合同号/客户/录入经办人)时,⛔ 用「没有需要更新的字段」
|
|
|
|
|
+ // 掩盖「这些字段不可改」——同值回显放行后落到这里,文案须点名锁定面。
|
|
|
|
|
+ let locked_only = contract_no_echoed
|
|
|
|
|
+ || trimmed(&b.customer_id).is_some()
|
|
|
|
|
+ || ["created_by", "created_by_name", "created_by_org", "created_by_mobile"]
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .any(|k| b.extra.contains_key(*k));
|
|
|
|
|
+ if locked_only {
|
|
|
|
|
+ return Err(BosError::bad_params(
|
|
|
|
|
+ "没有可更新的字段:合同编号/所属客户/录入经办人建后不可改;请改可写字段或 service_items(11103)",
|
|
|
|
|
+ ));
|
|
|
|
|
+ }
|
|
|
return Err(BosError::bad_params(
|
|
return Err(BosError::bad_params(
|
|
|
"没有需要更新的字段(11103:主档字段/service_items 至少给一项)",
|
|
"没有需要更新的字段(11103:主档字段/service_items 至少给一项)",
|
|
|
));
|
|
));
|
|
@@ -3662,7 +3744,7 @@ async fn do_update(
|
|
|
v["audit_written"] = json!(true);
|
|
v["audit_written"] = json!(true);
|
|
|
// 保存后刷新编辑口径:刚改过期间/刚过更正期都会改变两轴结论,页面必须拿到新结论。
|
|
// 保存后刷新编辑口径:刚改过期间/刚过更正期都会改变两轴结论,页面必须拿到新结论。
|
|
|
if let Some(row) = fetch_row(db, contract_id).await? {
|
|
if let Some(row) = fetch_row(db, contract_id).await? {
|
|
|
- let flags = opened_flags(db, &[contract_id.to_string()]).await?;
|
|
|
|
|
|
|
+ let (flags, _) = opened_flags(db, &[contract_id.to_string()]).await?;
|
|
|
v["edit_scope"] = edit_scope_of(&row, matches!(flags.get(contract_id), Some(Opened::Opened)));
|
|
v["edit_scope"] = edit_scope_of(&row, matches!(flags.get(contract_id), Some(Opened::Opened)));
|
|
|
}
|
|
}
|
|
|
persist_note(&mut v, &b.extra, &item_dropped);
|
|
persist_note(&mut v, &b.extra, &item_dropped);
|
|
@@ -3789,9 +3871,13 @@ fn lifecycle(start: &Option<String>, end: &Option<String>, now: NaiveDate) -> (V
|
|
|
///
|
|
///
|
|
|
/// 工单输入恒 [`CrossRead::Unconfigured`](第 5 册只读口未接线,缺口已登 18 册);
|
|
/// 工单输入恒 [`CrossRead::Unconfigured`](第 5 册只读口未接线,缺口已登 18 册);
|
|
|
/// 判据本身⛔ 在本层重写——`bos-invariant::opened_of` 是唯一真源。
|
|
/// 判据本身⛔ 在本层重写——`bos-invariant::opened_of` 是唯一真源。
|
|
|
-async fn opened_flags(db: &UdsClient, ids: &[String]) -> Result<HashMap<String, Opened>, BosError> {
|
|
|
|
|
|
|
+async fn opened_flags(
|
|
|
|
|
+ db: &UdsClient,
|
|
|
|
|
+ ids: &[String],
|
|
|
|
|
+) -> Result<(HashMap<String, Opened>, HashMap<String, String>), BosError> {
|
|
|
|
|
+ let mut dates: HashMap<String, String> = HashMap::with_capacity(ids.len());
|
|
|
if ids.is_empty() {
|
|
if ids.is_empty() {
|
|
|
- return Ok(HashMap::new());
|
|
|
|
|
|
|
+ return Ok((HashMap::new(), dates));
|
|
|
}
|
|
}
|
|
|
let mut backfill: HashMap<String, Vec<Option<String>>> = HashMap::with_capacity(ids.len());
|
|
let mut backfill: HashMap<String, Vec<Option<String>>> = HashMap::with_capacity(ids.len());
|
|
|
for id in ids {
|
|
for id in ids {
|
|
@@ -3799,11 +3885,22 @@ async fn opened_flags(db: &UdsClient, ids: &[String]) -> Result<HashMap<String,
|
|
|
}
|
|
}
|
|
|
let mut p = Params::default();
|
|
let mut p = Params::default();
|
|
|
let in_pred = push_in(&mut p, "s.contract_id", ids, "text");
|
|
let in_pred = push_in(&mut p, "s.contract_id", ids, "text");
|
|
|
|
|
+ // UDS 收拢:开通态 + 最早实际开通日 共用同一条 subscription 扫描(原 opened_flags+opened_dates 两跳)。
|
|
|
let sql = format!(
|
|
let sql = format!(
|
|
|
"SELECT s.contract_id AS contract_id, s.actual_opened_at AS opened_at \
|
|
"SELECT s.contract_id AS contract_id, s.actual_opened_at AS opened_at \
|
|
|
FROM subscription s WHERE {in_pred}"
|
|
FROM subscription s WHERE {in_pred}"
|
|
|
);
|
|
);
|
|
|
for r in db.query_all::<SubOpenedRow>(&sql, p.values()).await? {
|
|
for r in db.query_all::<SubOpenedRow>(&sql, p.values()).await? {
|
|
|
|
|
+ if let Some(d) = r.opened_at.as_ref().map(|s| s.trim()).filter(|s| !s.is_empty()) {
|
|
|
|
|
+ dates
|
|
|
|
|
+ .entry(r.contract_id.clone())
|
|
|
|
|
+ .and_modify(|cur| {
|
|
|
|
|
+ if d < cur.as_str() {
|
|
|
|
|
+ *cur = d.to_string();
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .or_insert_with(|| d.to_string());
|
|
|
|
|
+ }
|
|
|
backfill.entry(r.contract_id).or_default().push(r.opened_at);
|
|
backfill.entry(r.contract_id).or_default().push(r.opened_at);
|
|
|
}
|
|
}
|
|
|
let probes: Vec<(String, OpenedProbe)> = backfill
|
|
let probes: Vec<(String, OpenedProbe)> = backfill
|
|
@@ -3818,37 +3915,8 @@ async fn opened_flags(db: &UdsClient, ids: &[String]) -> Result<HashMap<String,
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
.collect();
|
|
.collect();
|
|
|
- contracts_opened(&probes)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/// 合同侧「是否已开通」列下方的**实际开通日**(04 册 §4.5:优先取关联订单上的
|
|
|
|
|
-/// `actual_opened_at`;多份订单时取**最早**一个,即首次交付日)。
|
|
|
|
|
-///
|
|
|
|
|
-/// 与 [`opened_flags`] 同一条 `IN` 批量读,⛔ 逐行 N+1;只收非空值,空值=尚未回填。
|
|
|
|
|
-async fn opened_dates(db: &UdsClient, ids: &[String]) -> Result<HashMap<String, String>, BosError> {
|
|
|
|
|
- let mut out: HashMap<String, String> = HashMap::with_capacity(ids.len());
|
|
|
|
|
- if ids.is_empty() {
|
|
|
|
|
- return Ok(out);
|
|
|
|
|
- }
|
|
|
|
|
- let mut p = Params::default();
|
|
|
|
|
- let in_pred = push_in(&mut p, "s.contract_id", ids, "text");
|
|
|
|
|
- let sql = format!(
|
|
|
|
|
- "SELECT s.contract_id AS contract_id, s.actual_opened_at AS opened_at \
|
|
|
|
|
- FROM subscription s WHERE {in_pred}"
|
|
|
|
|
- );
|
|
|
|
|
- for r in db.query_all::<SubOpenedRow>(&sql, p.values()).await? {
|
|
|
|
|
- let Some(d) = r.opened_at.filter(|v| !v.trim().is_empty()) else {
|
|
|
|
|
- continue;
|
|
|
|
|
- };
|
|
|
|
|
- out.entry(r.contract_id)
|
|
|
|
|
- .and_modify(|cur| {
|
|
|
|
|
- if d < *cur {
|
|
|
|
|
- *cur = d.clone();
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- .or_insert(d);
|
|
|
|
|
- }
|
|
|
|
|
- Ok(out)
|
|
|
|
|
|
|
+ let flags = contracts_opened(&probes)?;
|
|
|
|
|
+ Ok((flags, dates))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// 编辑口径出参(04 册 §4.2):只给布尔与原因码,文案表在前端(⛔ 后端拼提示语)。
|
|
/// 编辑口径出参(04 册 §4.2):只给布尔与原因码,文案表在前端(⛔ 后端拼提示语)。
|
|
@@ -3960,11 +4028,36 @@ async fn subscriptions_of(db: &UdsClient, contract_id: &str) -> Result<Vec<Value
|
|
|
sub_mode, plan_family, annual_price_cents, monthly_settle_cents, order_no, \
|
|
sub_mode, plan_family, annual_price_cents, monthly_settle_cents, order_no, \
|
|
|
contract_item_id, replaces_subscription_id, quantity, parent_subscription_id \
|
|
contract_item_id, replaces_subscription_id, quantity, parent_subscription_id \
|
|
|
FROM subscription WHERE contract_id = $1::text ORDER BY subscription_id";
|
|
FROM subscription WHERE contract_id = $1::text ORDER BY subscription_id";
|
|
|
- Ok(db
|
|
|
|
|
|
|
+ let rows = db
|
|
|
.query_all::<SubBrief>(sql, &[Value::String(contract_id.to_string())])
|
|
.query_all::<SubBrief>(sql, &[Value::String(contract_id.to_string())])
|
|
|
- .await?
|
|
|
|
|
|
|
+ .await?;
|
|
|
|
|
+ // D-CT-08:反向指针——谁替换了本订阅(`replaces_subscription_id` 指向本行的那条)。
|
|
|
|
|
+ // ⛔ 相关子查询(UDS 13001);一次 `IN` 批量回填。
|
|
|
|
|
+ let ids: Vec<String> = rows.iter().map(|s| s.subscription_id.clone()).collect();
|
|
|
|
|
+ let mut replaced_by: HashMap<String, String> = HashMap::new();
|
|
|
|
|
+ if !ids.is_empty() {
|
|
|
|
|
+ let mut p = Params::default();
|
|
|
|
|
+ let in_pred = push_in(&mut p, "r.replaces_subscription_id", &ids, "text");
|
|
|
|
|
+ let q = format!(
|
|
|
|
|
+ "SELECT r.replaces_subscription_id AS k, r.subscription_id AS v \
|
|
|
|
|
+ FROM subscription r WHERE {in_pred} ORDER BY r.subscription_id"
|
|
|
|
|
+ );
|
|
|
|
|
+ #[derive(Deserialize)]
|
|
|
|
|
+ struct Pair {
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_string")]
|
|
|
|
|
+ k: String,
|
|
|
|
|
+ #[serde(deserialize_with = "de::as_string")]
|
|
|
|
|
+ v: String,
|
|
|
|
|
+ }
|
|
|
|
|
+ for row in db.query_all::<Pair>(&q, p.values()).await? {
|
|
|
|
|
+ // 契约:至多被指向一次;若脏数据多行,取订阅号最小的一条并如实回显。
|
|
|
|
|
+ replaced_by.entry(row.k).or_insert(row.v);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Ok(rows
|
|
|
.into_iter()
|
|
.into_iter()
|
|
|
.map(|s| {
|
|
.map(|s| {
|
|
|
|
|
+ let by = replaced_by.get(&s.subscription_id).cloned();
|
|
|
json!({
|
|
json!({
|
|
|
"subscription_id": s.subscription_id,
|
|
"subscription_id": s.subscription_id,
|
|
|
"plan_name": s.plan_name,
|
|
"plan_name": s.plan_name,
|
|
@@ -3979,6 +4072,7 @@ async fn subscriptions_of(db: &UdsClient, contract_id: &str) -> Result<Vec<Value
|
|
|
"order_no": s.order_no,
|
|
"order_no": s.order_no,
|
|
|
"contract_item_id": s.contract_item_id,
|
|
"contract_item_id": s.contract_item_id,
|
|
|
"replaces_subscription_id": s.replaces_subscription_id,
|
|
"replaces_subscription_id": s.replaces_subscription_id,
|
|
|
|
|
+ "replaced_by_subscription_id": by,
|
|
|
"quantity": s.quantity,
|
|
"quantity": s.quantity,
|
|
|
// P1(D-7):附加订阅的父;界面据此平铺标「叠加于 SUB-xxx」。
|
|
// P1(D-7):附加订阅的父;界面据此平铺标「叠加于 SUB-xxx」。
|
|
|
"parent_subscription_id": s.parent_subscription_id,
|
|
"parent_subscription_id": s.parent_subscription_id,
|
|
@@ -3994,25 +4088,50 @@ fn preds(
|
|
|
keyword: Option<&str>,
|
|
keyword: Option<&str>,
|
|
|
customer_id: Option<&str>,
|
|
customer_id: Option<&str>,
|
|
|
status: Option<&str>,
|
|
status: Option<&str>,
|
|
|
-) -> Vec<String> {
|
|
|
|
|
|
|
+) -> Result<Vec<String>, BosError> {
|
|
|
let mut v = Vec::new();
|
|
let mut v = Vec::new();
|
|
|
if let Some(k) = p.push_like(keyword) {
|
|
if let Some(k) = p.push_like(keyword) {
|
|
|
- // 合同没有名称列 ⇒ 只命中合同号与客户编号。
|
|
|
|
|
- let k2 = k.clone();
|
|
|
|
|
- v.push(format!("(k.contract_no LIKE {k} OR k.customer_id LIKE {k2})"));
|
|
|
|
|
|
|
+ // 与清单页搜索占位同口径:编号/客户名/客户编号/外部单号/经办人/手机;ILIKE=大小写不敏感(D-CT-06)。
|
|
|
|
|
+ v.push(format!(
|
|
|
|
|
+ "(k.contract_no ILIKE {k} OR k.customer_id ILIKE {k} \
|
|
|
|
|
+ OR COALESCE(cu.customer_name, '') ILIKE {k} \
|
|
|
|
|
+ OR COALESCE(k.external_no, '') ILIKE {k} \
|
|
|
|
|
+ OR COALESCE(k.agent_name, '') ILIKE {k} \
|
|
|
|
|
+ OR COALESCE(k.agent_mobile, '') ILIKE {k})"
|
|
|
|
|
+ ));
|
|
|
}
|
|
}
|
|
|
if let Some(c) = p.push_eq(customer_id) {
|
|
if let Some(c) = p.push_eq(customer_id) {
|
|
|
v.push(format!("k.customer_id = {c}::text"));
|
|
v.push(format!("k.customer_id = {c}::text"));
|
|
|
}
|
|
}
|
|
|
- if let Some(s) = p.push_eq(status) {
|
|
|
|
|
- v.push(format!("k.status = {s}::text"));
|
|
|
|
|
|
|
+ // `status`=生命周期派生态(§4.9),⛔ 读 `contract.status` 业务列(那列不是
|
|
|
|
|
+ // effective/not_effective/expired;D-CT-03 曾因此恒空集)。
|
|
|
|
|
+ if let Some(raw) = status.map(str::trim).filter(|s| !s.is_empty()) {
|
|
|
|
|
+ let today = p.push(Value::String(super::subscription::today()));
|
|
|
|
|
+ let pred = match raw {
|
|
|
|
|
+ "effective" | "生效中" => format!(
|
|
|
|
|
+ "k.start_date IS NOT NULL AND k.end_date IS NOT NULL \
|
|
|
|
|
+ AND k.start_date::date <= {today}::date AND k.end_date::date >= {today}::date"
|
|
|
|
|
+ ),
|
|
|
|
|
+ "not_effective" | "待生效" | "未生效" => format!(
|
|
|
|
|
+ "k.start_date IS NOT NULL AND k.start_date::date > {today}::date"
|
|
|
|
|
+ ),
|
|
|
|
|
+ "expired" | "已到期" => format!(
|
|
|
|
|
+ "k.end_date IS NOT NULL AND k.end_date::date < {today}::date"
|
|
|
|
|
+ ),
|
|
|
|
|
+ other => {
|
|
|
|
|
+ return Err(BosError::bad_params(format!(
|
|
|
|
|
+ "status 只接受 effective/not_effective/expired(或生效中/待生效/已到期),收到「{other}」"
|
|
|
|
|
+ )));
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ v.push(pred);
|
|
|
}
|
|
}
|
|
|
// ⚠️ 开通态筛选⛔ 进 SQL:UDS 侧执行引擎(DataFusion)对**相关子查询**回
|
|
// ⚠️ 开通态筛选⛔ 进 SQL:UDS 侧执行引擎(DataFusion)对**相关子查询**回
|
|
|
// `13001 This feature is not implemented: Physical plan ...`,`EXISTS (SELECT 1 FROM
|
|
// `13001 This feature is not implemented: Physical plan ...`,`EXISTS (SELECT 1 FROM
|
|
|
// subscription s WHERE s.contract_id = k.contract_id …)` 整条语句直接失败。
|
|
// subscription s WHERE s.contract_id = k.contract_id …)` 整条语句直接失败。
|
|
|
// ⇒ `opened` 在 [`get_list`] 里按「先取符合筛选的合同 ID 全集 → [`opened_flags`] 批量判据
|
|
// ⇒ `opened` 在 [`get_list`] 里按「先取符合筛选的合同 ID 全集 → [`opened_flags`] 批量判据
|
|
|
// → 内存筛选/统计 → 分页 ID 进 `IN`」实现,判据仍只有一枚(`bos-invariant::opened_of`)。
|
|
// → 内存筛选/统计 → 分页 ID 进 `IN`」实现,判据仍只有一枚(`bos-invariant::opened_of`)。
|
|
|
- v
|
|
|
|
|
|
|
+ Ok(v)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// `opened` 筛选值收敛:`true`/`false` 之外的类型=11103(⛔ 把 `"true"`、`1` 当假值静默放过)。
|
|
/// `opened` 筛选值收敛:`true`/`false` 之外的类型=11103(⛔ 把 `"true"`、`1` 当假值静默放过)。
|
|
@@ -4032,17 +4151,33 @@ pub async fn get_list(
|
|
|
RequireAuth(auth): RequireAuth,
|
|
RequireAuth(auth): RequireAuth,
|
|
|
DataBody(body): DataBody<ContractListReq>,
|
|
DataBody(body): DataBody<ContractListReq>,
|
|
|
) -> Response {
|
|
) -> Response {
|
|
|
|
|
+ // D-CT-07:越界 page/page_size 显式拒绝(⛔ 静默钳位掩盖上游传参错误)。
|
|
|
|
|
+ if body.pg.page < 0 {
|
|
|
|
|
+ return json_err(BosError::bad_params(format!(
|
|
|
|
|
+ "page 须 ≥ 0(0 基),收到 {}",
|
|
|
|
|
+ body.pg.page
|
|
|
|
|
+ )));
|
|
|
|
|
+ }
|
|
|
|
|
+ if body.pg.page_size < 1 || body.pg.page_size > 200 {
|
|
|
|
|
+ return json_err(BosError::bad_params(format!(
|
|
|
|
|
+ "page_size 须在 1..=200,收到 {}",
|
|
|
|
|
+ body.pg.page_size
|
|
|
|
|
+ )));
|
|
|
|
|
+ }
|
|
|
let opened = match want_opened(body.opened.as_ref()) {
|
|
let opened = match want_opened(body.opened.as_ref()) {
|
|
|
Ok(v) => v,
|
|
Ok(v) => v,
|
|
|
Err(e) => return json_err(e),
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
};
|
|
|
let mut p = Params::default();
|
|
let mut p = Params::default();
|
|
|
- let mut w = preds(
|
|
|
|
|
|
|
+ let mut w = match preds(
|
|
|
&mut p,
|
|
&mut p,
|
|
|
body.keyword.as_deref(),
|
|
body.keyword.as_deref(),
|
|
|
body.customer_id.as_deref(),
|
|
body.customer_id.as_deref(),
|
|
|
body.status.as_deref(),
|
|
body.status.as_deref(),
|
|
|
- );
|
|
|
|
|
|
|
+ ) {
|
|
|
|
|
+ Ok(v) => v,
|
|
|
|
|
+ Err(e) => return json_err(e),
|
|
|
|
|
+ };
|
|
|
// 可见性谓词排在筛选之后一起进 WHERE:`Params` 负责占位符与值的对应次序。
|
|
// 可见性谓词排在筛选之后一起进 WHERE:`Params` 负责占位符与值的对应次序。
|
|
|
match customer_scope_pred(&state, &auth, &mut p, "k.customer_id").await {
|
|
match customer_scope_pred(&state, &auth, &mut p, "k.customer_id").await {
|
|
|
Ok(s) => w.push(s),
|
|
Ok(s) => w.push(s),
|
|
@@ -4061,7 +4196,7 @@ pub async fn get_list(
|
|
|
Err(e) => return json_err(e),
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
};
|
|
|
// ② 一次批量取开通态(判据=`bos-invariant::opened_of`,⛔ 在本层重写、⛔ 逐行 N+1)。
|
|
// ② 一次批量取开通态(判据=`bos-invariant::opened_of`,⛔ 在本层重写、⛔ 逐行 N+1)。
|
|
|
- let flags = match opened_flags(state.db.as_ref(), &all_ids).await {
|
|
|
|
|
|
|
+ let (flags, opened_on_all) = match opened_flags(state.db.as_ref(), &all_ids).await {
|
|
|
Ok(m) => m,
|
|
Ok(m) => m,
|
|
|
Err(e) => return json_err(e),
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
};
|
|
@@ -4076,6 +4211,7 @@ pub async fn get_list(
|
|
|
let total_n = filtered.len() as i64;
|
|
let total_n = filtered.len() as i64;
|
|
|
let opened_n = filtered.iter().filter(|id| is_opened(id)).count() as i64;
|
|
let opened_n = filtered.iter().filter(|id| is_opened(id)).count() as i64;
|
|
|
// ④ 分页=在内存里切 ID,再把这一页的 ID 送进 `IN`(⛔ 依赖 SQL 侧半连接)。
|
|
// ④ 分页=在内存里切 ID,再把这一页的 ID 送进 `IN`(⛔ 依赖 SQL 侧半连接)。
|
|
|
|
|
+ // ⚠️ 切好的 page_ids **不再**套 LIMIT/OFFSET(D-CT-02:二次分页让 page≥1 恒空集)。
|
|
|
let page_ids: Vec<String> = filtered
|
|
let page_ids: Vec<String> = filtered
|
|
|
.iter()
|
|
.iter()
|
|
|
.skip(body.pg.offset().max(0) as usize)
|
|
.skip(body.pg.offset().max(0) as usize)
|
|
@@ -4085,10 +4221,9 @@ pub async fn get_list(
|
|
|
let rows = if page_ids.is_empty() {
|
|
let rows = if page_ids.is_empty() {
|
|
|
Vec::new()
|
|
Vec::new()
|
|
|
} else {
|
|
} else {
|
|
|
- let (lim, off) = p.push_page(&body.pg);
|
|
|
|
|
w.push(push_in(&mut p, "k.contract_id", &page_ids, "text"));
|
|
w.push(push_in(&mut p, "k.contract_id", &page_ids, "text"));
|
|
|
let sql = format!(
|
|
let sql = format!(
|
|
|
- "SELECT {CONTRACT_COLS} {CONTRACT_FROM} {} ORDER BY k.created_at DESC LIMIT {lim} OFFSET {off}",
|
|
|
|
|
|
|
+ "SELECT {CONTRACT_COLS} {CONTRACT_FROM} {} ORDER BY k.created_at DESC",
|
|
|
p.where_clause(&w)
|
|
p.where_clause(&w)
|
|
|
);
|
|
);
|
|
|
match state.db.query_all::<ContractRow>(&sql, p.values()).await {
|
|
match state.db.query_all::<ContractRow>(&sql, p.values()).await {
|
|
@@ -4097,27 +4232,22 @@ pub async fn get_list(
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
let cids: Vec<String> = rows.iter().map(|r| r.contract_id.clone()).collect();
|
|
let cids: Vec<String> = rows.iter().map(|r| r.contract_id.clone()).collect();
|
|
|
- let uids: Vec<String> = rows.iter().map(|r| r.customer_id.clone()).collect();
|
|
|
|
|
- let names = match customer_names(state.db.as_ref(), &uids).await {
|
|
|
|
|
- Ok(m) => m,
|
|
|
|
|
- Err(e) => return json_err(e),
|
|
|
|
|
- };
|
|
|
|
|
let items = match load_children(state.db.as_ref(), &cids).await {
|
|
let items = match load_children(state.db.as_ref(), &cids).await {
|
|
|
Ok(v) => v,
|
|
Ok(v) => v,
|
|
|
Err(e) => return json_err(e),
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
};
|
|
|
- // 04 册 §4.5:「是否已开通」标签下方的**实际开通日**(关联订单回填值,多份取最早)。
|
|
|
|
|
- let opened_on = match opened_dates(state.db.as_ref(), &cids).await {
|
|
|
|
|
- Ok(m) => m,
|
|
|
|
|
- Err(e) => return json_err(e),
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ // 04 册 §4.5:实际开通日已在 opened_flags 同趟取回(按本页 ID 裁剪)。
|
|
|
|
|
+ let opened_on: HashMap<String, String> = cids
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .filter_map(|id| opened_on_all.get(id).cloned().map(|d| (id.clone(), d)))
|
|
|
|
|
+ .collect();
|
|
|
json_ok(with_pending(json!({
|
|
json_ok(with_pending(json!({
|
|
|
"items": rows
|
|
"items": rows
|
|
|
.iter()
|
|
.iter()
|
|
|
.map(|r| {
|
|
.map(|r| {
|
|
|
let mut v = with_opened(
|
|
let mut v = with_opened(
|
|
|
with_children(
|
|
with_children(
|
|
|
- base_json(r, names.get(&r.customer_id).map(String::as_str)),
|
|
|
|
|
|
|
+ base_json(r, r.customer_name.as_deref()),
|
|
|
&r.contract_id,
|
|
&r.contract_id,
|
|
|
&items,
|
|
&items,
|
|
|
),
|
|
),
|
|
@@ -4170,16 +4300,11 @@ pub async fn get(
|
|
|
Err(e) => return json_err(e),
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
};
|
|
|
let ids = vec![r.contract_id.clone()];
|
|
let ids = vec![r.contract_id.clone()];
|
|
|
- let uids = vec![r.customer_id.clone()];
|
|
|
|
|
- let name = match customer_names(state.db.as_ref(), &uids).await {
|
|
|
|
|
- Ok(m) => m.get(&r.customer_id).cloned(),
|
|
|
|
|
- Err(e) => return json_err(e),
|
|
|
|
|
- };
|
|
|
|
|
let items = match load_children(state.db.as_ref(), &ids).await {
|
|
let items = match load_children(state.db.as_ref(), &ids).await {
|
|
|
Ok(v) => v,
|
|
Ok(v) => v,
|
|
|
Err(e) => return json_err(e),
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
};
|
|
|
- let flags = match opened_flags(state.db.as_ref(), &ids).await {
|
|
|
|
|
|
|
+ let (flags, opened_on) = match opened_flags(state.db.as_ref(), &ids).await {
|
|
|
Ok(m) => m,
|
|
Ok(m) => m,
|
|
|
Err(e) => return json_err(e),
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
};
|
|
@@ -4188,22 +4313,17 @@ pub async fn get(
|
|
|
Err(e) => return json_err(e),
|
|
Err(e) => return json_err(e),
|
|
|
};
|
|
};
|
|
|
let mut v = with_opened(
|
|
let mut v = with_opened(
|
|
|
- with_children(base_json(&r, name.as_deref()), &r.contract_id, &items),
|
|
|
|
|
|
|
+ with_children(base_json(&r, r.customer_name.as_deref()), &r.contract_id, &items),
|
|
|
&r,
|
|
&r,
|
|
|
&flags,
|
|
&flags,
|
|
|
);
|
|
);
|
|
|
v["subscriptions"] = json!(subs);
|
|
v["subscriptions"] = json!(subs);
|
|
|
v["subscriptions_note"] =
|
|
v["subscriptions_note"] =
|
|
|
json!("关联订阅按 contract_id 现查 subscription 组装(第 6 类只读关联,不冗余列);contract_item_id/replaces_subscription_id 只交代关联落点");
|
|
json!("关联订阅按 contract_id 现查 subscription 组装(第 6 类只读关联,不冗余列);contract_item_id/replaces_subscription_id 只交代关联落点");
|
|
|
- // 04 册 §4.5:详情「商业信息 · 网络开通」的实际开通日同样取关联订单回填值(多份取最早)。
|
|
|
|
|
- // 此前只下发 `opened` 不下发日期 ⇒ 已开通合同显示「已开通 · 待回填日期」,与下方
|
|
|
|
|
- // 「04 关联订单」里的实际开通日自相矛盾。
|
|
|
|
|
- v["actual_opened_at"] = match opened_dates(state.db.as_ref(), &ids).await {
|
|
|
|
|
- Ok(m) => match m.get(&r.contract_id) {
|
|
|
|
|
- Some(d) => json!(d),
|
|
|
|
|
- None => Value::Null,
|
|
|
|
|
- },
|
|
|
|
|
- Err(e) => return json_err(e),
|
|
|
|
|
|
|
+ // 04 册 §4.5:实际开通日与 opened 同趟取自 subscription(多份取最早)。
|
|
|
|
|
+ v["actual_opened_at"] = match opened_on.get(&r.contract_id) {
|
|
|
|
|
+ Some(d) => json!(d),
|
|
|
|
|
+ None => Value::Null,
|
|
|
};
|
|
};
|
|
|
// D-23:「01 客户资料」段此前只回 `customer_id`+`customer_name` ⇒ 六项全显「未登记」。
|
|
// D-23:「01 客户资料」段此前只回 `customer_id`+`customer_name` ⇒ 六项全显「未登记」。
|
|
|
// 档案取不到(客户被注销)=`null` +如实口径,⛔ 让界面把「档案取不到」显示成「未登记」。
|
|
// 档案取不到(客户被注销)=`null` +如实口径,⛔ 让界面把「档案取不到」显示成「未登记」。
|
|
@@ -4308,7 +4428,14 @@ async fn do_change_log(
|
|
|
)));
|
|
)));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let page_size = b.page_size.clamp(1, 50);
|
|
|
|
|
|
|
+ // D-CT-07/契约 maximum 50:越界拒绝,⛔ clamp(1,50) 放行 201。
|
|
|
|
|
+ if b.page_size < 1 || b.page_size > 50 {
|
|
|
|
|
+ return Err(BosError::bad_params(format!(
|
|
|
|
|
+ "page_size 须在 1..=50,收到 {}",
|
|
|
|
|
+ b.page_size
|
|
|
|
|
+ )));
|
|
|
|
|
+ }
|
|
|
|
|
+ let page_size = b.page_size;
|
|
|
let mut p = Params::default();
|
|
let mut p = Params::default();
|
|
|
let cid = p.push(Value::String(contract_id.to_string()));
|
|
let cid = p.push(Value::String(contract_id.to_string()));
|
|
|
let mut preds = vec![format!(
|
|
let mut preds = vec![format!(
|
|
@@ -4323,18 +4450,24 @@ async fn do_change_log(
|
|
|
}
|
|
}
|
|
|
let ph_c = p.push(Value::String(c.to_string()));
|
|
let ph_c = p.push(Value::String(c.to_string()));
|
|
|
let ph_i = p.push(Value::String(i.to_string()));
|
|
let ph_i = p.push(Value::String(i.to_string()));
|
|
|
|
|
+ // UDS/DataFusion ⛔ 元组比较(`(a,b) < ($1,$2)` → 13001 Only identifiers and
|
|
|
|
|
+ // literals are supported in tuples,D-CT-04)⇒ 拆成两段 OR。
|
|
|
|
|
+ // 时间列用 COALESCE(occurred_at, created_at):dev 种子行 occurred_at 可能为 NULL。
|
|
|
preds.push(format!(
|
|
preds.push(format!(
|
|
|
- "(a.occurred_at, a.id) < ({ph_c}::timestamptz, {ph_i}::bigint)"
|
|
|
|
|
|
|
+ "(COALESCE(a.occurred_at, a.created_at) < {ph_c}::timestamptz \
|
|
|
|
|
+ OR (COALESCE(a.occurred_at, a.created_at) = {ph_c}::timestamptz AND a.id < {ph_i}::bigint))"
|
|
|
));
|
|
));
|
|
|
}
|
|
}
|
|
|
let lim = p.push(Value::from(page_size + 1));
|
|
let lim = p.push(Value::from(page_size + 1));
|
|
|
let sql = format!(
|
|
let sql = format!(
|
|
|
- "SELECT a.id, a.occurred_at, a.actor_user_id, a.action, a.detail_json, \
|
|
|
|
|
|
|
+ "SELECT a.id, COALESCE(a.occurred_at, a.created_at) AS occurred_at, \
|
|
|
|
|
+ a.actor_user_id, a.action, a.detail_json, \
|
|
|
NULLIF(COALESCE(NULLIF(ac.display_name,''), NULLIF(u.username,'')), '') AS actor_name \
|
|
NULLIF(COALESCE(NULLIF(ac.display_name,''), NULLIF(u.username,'')), '') AS actor_name \
|
|
|
FROM bos_audit_log a \
|
|
FROM bos_audit_log a \
|
|
|
LEFT JOIN bos_user_binding u ON u.user_id = a.actor_user_id \
|
|
LEFT JOIN bos_user_binding u ON u.user_id = a.actor_user_id \
|
|
|
LEFT JOIN bos_account_ext ac ON ac.user_id = u.user_id \
|
|
LEFT JOIN bos_account_ext ac ON ac.user_id = u.user_id \
|
|
|
- {} ORDER BY a.occurred_at DESC NULLS LAST, a.id DESC LIMIT {lim}::bigint",
|
|
|
|
|
|
|
+ {} ORDER BY COALESCE(a.occurred_at, a.created_at) DESC NULLS LAST, a.id DESC \
|
|
|
|
|
+ LIMIT {lim}::bigint",
|
|
|
p.where_clause(&preds)
|
|
p.where_clause(&preds)
|
|
|
);
|
|
);
|
|
|
let rows = db.query_all::<ChangeLogRow>(&sql, p.values()).await?;
|
|
let rows = db.query_all::<ChangeLogRow>(&sql, p.values()).await?;
|
|
@@ -4355,7 +4488,7 @@ async fn do_change_log(
|
|
|
},
|
|
},
|
|
|
"actor": { "user_id": r.actor_user_id, "name": r.actor_name },
|
|
"actor": { "user_id": r.actor_user_id, "name": r.actor_name },
|
|
|
"detail": json_cell(r.detail_json),
|
|
"detail": json_cell(r.detail_json),
|
|
|
- // `occurred_at` 缺失时无法构造游标 ⇒ 回 null(⛔ 拼假游标)
|
|
|
|
|
|
|
+ // 时间列缺失时无法构造游标 ⇒ 回 null(⛔ 拼假游标)
|
|
|
"cursor": r.occurred_at.as_deref().map(|t| format!("{t}|{}", r.id)),
|
|
"cursor": r.occurred_at.as_deref().map(|t| format!("{t}|{}", r.id)),
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|