|
@@ -1541,21 +1541,36 @@ fn check_ip_exits_in_items<'a>(
|
|
|
ips: &[IpIns],
|
|
ips: &[IpIns],
|
|
|
item_exits: impl IntoIterator<Item = Option<&'a Value>>,
|
|
item_exits: impl IntoIterator<Item = Option<&'a Value>>,
|
|
|
) -> Result<(), BosError> {
|
|
) -> Result<(), BosError> {
|
|
|
- if ips.is_empty() {
|
|
|
|
|
|
|
+ let uses: Vec<(String, String)> = ips
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .enumerate()
|
|
|
|
|
+ .map(|(index, e)| (format!("ip_entries[{index}].line_exit"), e.line_exit.clone()))
|
|
|
|
|
+ .collect();
|
|
|
|
|
+ check_exits_within_items(&uses, item_exits)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/// 通用版:`uses`=(字段路径, 出口原文),`item_exits`=生效条目的 `line_exits`。
|
|
|
|
|
+///
|
|
|
|
|
+/// 拆出通用版是给「改服务构成但未重发 IP」的路径复用:那时要拿**库内 IP 条目**回代,
|
|
|
|
|
+/// 不能让「删掉条目出口、IP 条目照旧」从 `ip_entries` 缺席的口子溜过去。
|
|
|
|
|
+fn check_exits_within_items<'a>(
|
|
|
|
|
+ uses: &[(String, String)],
|
|
|
|
|
+ item_exits: impl IntoIterator<Item = Option<&'a Value>>,
|
|
|
|
|
+) -> Result<(), BosError> {
|
|
|
|
|
+ if uses.is_empty() {
|
|
|
return Ok(());
|
|
return Ok(());
|
|
|
}
|
|
}
|
|
|
let mut allowed: HashSet<String> = HashSet::new();
|
|
let mut allowed: HashSet<String> = HashSet::new();
|
|
|
for value in item_exits.into_iter().flatten() {
|
|
for value in item_exits.into_iter().flatten() {
|
|
|
collect_item_exit_keys(value, &mut allowed);
|
|
collect_item_exit_keys(value, &mut allowed);
|
|
|
}
|
|
}
|
|
|
- let bad: Vec<String> = ips
|
|
|
|
|
|
|
+ let bad: Vec<String> = uses
|
|
|
.iter()
|
|
.iter()
|
|
|
- .enumerate()
|
|
|
|
|
- .filter(|(_, e)| match super::line_exit::exit_key(&e.line_exit) {
|
|
|
|
|
|
|
+ .filter(|(_, raw)| match super::line_exit::exit_key(raw) {
|
|
|
Some(key) => !allowed.contains(&key),
|
|
Some(key) => !allowed.contains(&key),
|
|
|
None => true,
|
|
None => true,
|
|
|
})
|
|
})
|
|
|
- .map(|(index, e)| format!("ip_entries[{index}].line_exit「{}」", e.line_exit))
|
|
|
|
|
|
|
+ .map(|(field, raw)| format!("{field}「{raw}」"))
|
|
|
.collect();
|
|
.collect();
|
|
|
if bad.is_empty() {
|
|
if bad.is_empty() {
|
|
|
return Ok(());
|
|
return Ok(());
|
|
@@ -2714,6 +2729,26 @@ async fn do_update(
|
|
|
let (mut items, dropped) = resolve_items(db, &cur.customer_id, raw_items).await?;
|
|
let (mut items, dropped) = resolve_items(db, &cur.customer_id, raw_items).await?;
|
|
|
// 固定 IP 条目的出口只能取自**本次生效**的服务构成已选出口(2026-11-16 裁定)。
|
|
// 固定 IP 条目的出口只能取自**本次生效**的服务构成已选出口(2026-11-16 裁定)。
|
|
|
check_ip_exits_in_items(&ips, items.iter().map(|item| Some(&item.line_exits)))?;
|
|
check_ip_exits_in_items(&ips, items.iter().map(|item| Some(&item.line_exits)))?;
|
|
|
|
|
+ if !replace_ips {
|
|
|
|
|
+ // 只改服务构成、未重发 IP ⇒ 库内 IP 条目的出口也必须仍落在新条目出口集合内,
|
|
|
|
|
+ // 否则「把条目的出口删掉」就能留下一批悬空的 IP 出口。
|
|
|
|
|
+ let stored_ips = load_children(db, &[contract_id.to_string()])
|
|
|
|
|
+ .await?
|
|
|
|
|
+ .1
|
|
|
|
|
+ .get(contract_id)
|
|
|
|
|
+ .cloned()
|
|
|
|
|
+ .unwrap_or_default();
|
|
|
|
|
+ let used: Vec<(String, String)> = stored_ips
|
|
|
|
|
+ .iter()
|
|
|
|
|
+ .enumerate()
|
|
|
|
|
+ .filter_map(|(index, e)| {
|
|
|
|
|
+ e.get("line_exit").and_then(Value::as_str).map(|raw| {
|
|
|
|
|
+ (format!("ip_entries[{index}].line_exit"), raw.to_string())
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ .collect();
|
|
|
|
|
+ check_exits_within_items(&used, items.iter().map(|item| Some(&item.line_exits)))?;
|
|
|
|
|
+ }
|
|
|
item_dropped = dropped;
|
|
item_dropped = dropped;
|
|
|
let new_ids =
|
|
let new_ids =
|
|
|
issue_ids(db, "SI", "contract_service_item", year, items.iter().filter(|i| i.item_id.is_none()).count())
|
|
issue_ids(db, "SI", "contract_service_item", year, items.iter().filter(|i| i.item_id.is_none()).count())
|