Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b878a094b5 | ||
|
|
246ae4607c | ||
|
|
eca0a7ad93 |
+29
@@ -81,3 +81,32 @@ agent-release.zip
|
||||
/友通达询价智能体监听包/
|
||||
/_tmp_analyze_templates.py
|
||||
/styles.css
|
||||
|
||||
# 本机调试/核对杂物(不进仓;消掉资源管理器叹号)
|
||||
.vs/
|
||||
/debug-*.json
|
||||
/debug-*.log
|
||||
/YTD*.docx
|
||||
inquiry-agent/_debug_*.py
|
||||
inquiry-agent/agent/debug_ndjson.py
|
||||
inquiry-agent/scripts/_verify_quote/
|
||||
inquiry-agent/scripts/_last_*.json
|
||||
inquiry-api/**/db/_bot_reply_xlsx.json
|
||||
inquiry-api/**/db/_gen_bot_reply_seed.py
|
||||
inquiry-api/**/Debug*Test.java
|
||||
inquiry-api/**/*DebugProbeTest.java
|
||||
inquiry-backend/dist.bak-*/
|
||||
inquiry-backend/scripts/
|
||||
/tools/_*
|
||||
/tools/*Probe.java
|
||||
/tools/JeecgPwdEncrypt.java
|
||||
/tools/*.json
|
||||
/tools/*.txt
|
||||
/tools/*.xlsx
|
||||
/tools/e2e_*.py
|
||||
/tools/sources.txt
|
||||
/tools/wo*
|
||||
/tools/clear_*
|
||||
/tools/probe_*
|
||||
/tools/implausible_*
|
||||
/tools/tms_req_*
|
||||
|
||||
@@ -1049,6 +1049,25 @@ _RE_WEIGHT_BAND_OPEN = re.compile(
|
||||
r"(?P<price>\d+(?:\.\d+)?)",
|
||||
re.I,
|
||||
)
|
||||
# 陆运整车产品口语:车型:5T/8T:13000 10T:14000 40HQ/45HQ:19500
|
||||
# 标签可斜杠并价(5T/8T 同价);40/45HQ 要拆成 40HQ+45HQ。金额至少三位,避免吃到「段1」。
|
||||
_RE_VEHICLE_RATE_ITEM = re.compile(
|
||||
r"(?P<label>"
|
||||
r"\d+(?:\.\d+)?\s*(?:T|吨|HQ|GP|尺)"
|
||||
r"(?:\s*/\s*\d+(?:\.\d+)?\s*(?:T|吨|HQ|GP|尺)?)*"
|
||||
r"|"
|
||||
r"\d+\s*/\s*\d+\s*(?:HQ|GP|尺|T|吨)"
|
||||
r")"
|
||||
r"\s*[::=]?\s*"
|
||||
rf"(?:(?P<ccy>{_CCY_TOKEN})\s*)?"
|
||||
r"(?P<price>\d{3,}(?:\.\d+)?)",
|
||||
re.I,
|
||||
)
|
||||
# 多车型价后的口语备注(非「备注:」格式)
|
||||
_RE_VEHICLE_QUOTE_REMARK = re.compile(
|
||||
r"(含\s*0\s*点\s*税?|含\s*0\s*点|国六车提货|不含税|含税)",
|
||||
re.I,
|
||||
)
|
||||
_RE_FUEL_SURCHARGE_RATE = re.compile(
|
||||
r"燃油附加费率\s*[::=]?\s*(?P<rate>\d+(?:\.\d+)?)\s*%?",
|
||||
re.I,
|
||||
@@ -1067,6 +1086,29 @@ _RE_FEE_LINE = re.compile(
|
||||
rf"\s*(?P<ccy2>{_CCY_TOKEN}|元)?",
|
||||
re.I,
|
||||
)
|
||||
# 中港陆运口语:「深圳--香港元朗运费10T:1700HKD/车」——车型吨位不是金额。
|
||||
# 必须先于普通费用行,否则会抽成运费=10(WO202610300015)。
|
||||
_RE_FEE_VEHICLE_PRICE = re.compile(
|
||||
r"(?P<name>[\u4e00-\u9fffA-Za-z][\u4e00-\u9fffA-Za-z0-9/()()++\--]{0,24}费)"
|
||||
r"\s*(?:改为|改成|调整为|调整成)?"
|
||||
r"\s*[::=]?"
|
||||
r"\s*(?P<label>\d+(?:\.\d+)?\s*(?:T|吨|HQ|GP|尺))"
|
||||
r"\s*[::=]?\s*"
|
||||
rf"(?:(?P<ccy1>{_CCY_TOKEN})\s*)?"
|
||||
r"(?P<amount>\d+(?:\.\d+)?)"
|
||||
rf"\s*(?P<ccy2>{_CCY_TOKEN}|元)?"
|
||||
r"(?:\s*/\s*车)?",
|
||||
re.I,
|
||||
)
|
||||
# 金额后紧跟车型单位:该数字是吨位/柜型,不是费用金额。
|
||||
_RE_AMOUNT_IS_VEHICLE_UNIT = re.compile(r"^\s*(?:T|吨|HQ|GP|尺)\b", re.I)
|
||||
# 「压夜按运费80%」「压日按运费100%」是比例,禁止落成 HKD 80/100 再加进合计。
|
||||
_RE_FEE_OF_FREIGHT_PCT = re.compile(
|
||||
r"(?P<name>[\u4e00-\u9fff]{1,8}按运费|[\u4e00-\u9fffA-Za-z][\u4e00-\u9fffA-Za-z0-9/()()++\--]{0,16}费)"
|
||||
r"\s*[::=]?\s*"
|
||||
r"(?P<amount>\d+(?:\.\d+)?)\s*%",
|
||||
re.I,
|
||||
)
|
||||
# 多段报价「段1:」「第一段」只是段号,数字不能当费用金额。
|
||||
_RE_SEGMENT_INDEX_LABEL = re.compile(
|
||||
r"(?:段\s*\d+\s*[::]?|第\s*[一二三四五六七八九\d]+\s*段\s*[::]?)",
|
||||
@@ -1116,6 +1158,12 @@ _RE_FEE_PROJECT_PREFIX = re.compile(
|
||||
r"^\s*(?P<project>空运段|空运|起运港|起运地|目的地|目的港|其它|其他)\s*[,,、::]\s*",
|
||||
re.I,
|
||||
)
|
||||
# 航线常另起一行写「备注:1:250+ 吨上」;剥 @ 后换行常被压成空格,不能只认行首。
|
||||
# 必须进费用行 remark,出单才有备注列(WO202610230028)。
|
||||
_RE_STANDALONE_REMARK = re.compile(
|
||||
r"备注\s*[::]\s*(?P<remark>[^\n\r@]+)",
|
||||
re.I,
|
||||
)
|
||||
_FULLWIDTH_NUM = str.maketrans("0123456789.", "0123456789.")
|
||||
|
||||
|
||||
@@ -1299,6 +1347,41 @@ def _strip_segment_index_labels(text: str) -> str:
|
||||
return _RE_SEGMENT_INDEX_LABEL.sub(" ", text or "").strip()
|
||||
|
||||
|
||||
def _extract_quote_remark(text: str) -> str:
|
||||
"""
|
||||
抽出文字报价里单独标注的「备注:…」。
|
||||
|
||||
例:备注:1:250+ 吨上 → 1:250+ 吨上。工单号、@机器人不进备注。
|
||||
副作用:无。
|
||||
"""
|
||||
hit = _RE_STANDALONE_REMARK.search(text or "")
|
||||
if not hit:
|
||||
return ""
|
||||
note = (hit.group("remark") or "").strip()
|
||||
note = re.sub(r"\s*WO\d{12}\s*", " ", note, flags=re.I)
|
||||
note = re.sub(r"\s+", " ", note).strip(" ,,;;")
|
||||
return note
|
||||
|
||||
|
||||
def _attach_quote_remark(rows: list[dict[str, str]], remark: str) -> list[dict[str, str]]:
|
||||
"""
|
||||
把整句备注挂到第一条非费率费用行。已有行内 remark 的不覆盖。
|
||||
|
||||
出单 Excel 备注列读 fee_rows[].remark;挂不到行上则报价单备注空白(WO028)。
|
||||
"""
|
||||
note = (remark or "").strip()
|
||||
if not note or not rows:
|
||||
return rows
|
||||
for row in rows:
|
||||
if "%" in str(row.get("amount") or ""):
|
||||
continue
|
||||
if str(row.get("remark") or "").strip():
|
||||
continue
|
||||
row["remark"] = note
|
||||
break
|
||||
return rows
|
||||
|
||||
|
||||
def _parse_fee_rows(text: str, baseline_currency: str = "") -> list[dict[str, str]]:
|
||||
"""
|
||||
按行抽费用:码头操作费100CNY、报关费改为300CNY。
|
||||
@@ -1306,6 +1389,8 @@ def _parse_fee_rows(text: str, baseline_currency: str = "") -> list[dict[str, st
|
||||
只认带「费」的中文名或短英文费用码,避免把工单号当金额。
|
||||
句里无币种时继承 baseline_currency(通常是当前 TMS/主账币种),禁止默认 USD。
|
||||
认「费名, KG, 单价…」与「费名_板,单价…」里的计量单位,写入 unit,禁止出单再默认「票」。
|
||||
「运费10T:1700HKD」先认车型价,禁止把吨位 10 当成运费金额。
|
||||
「压夜按运费80%」金额带 %,禁止当绝对金额加进合计。
|
||||
"""
|
||||
project, body = _split_fee_project_prefix(text or "")
|
||||
raw = _ascii_amount(body)
|
||||
@@ -1335,11 +1420,44 @@ def _parse_fee_rows(text: str, baseline_currency: str = "") -> list[dict[str, st
|
||||
row[key] = val
|
||||
rows.append(row)
|
||||
|
||||
# 先认「运费10T:1700」——车型价;再认「按运费80%」比例;最后才普通金额行。
|
||||
for hit in _RE_FEE_VEHICLE_PRICE.finditer(raw):
|
||||
label = (hit.group("label") or "").strip().replace(" ", "")
|
||||
_add(
|
||||
(hit.group("name") or "").strip(),
|
||||
_ascii_amount(hit.group("amount") or ""),
|
||||
hit.group("ccy1") or hit.group("ccy2") or "",
|
||||
unit="车",
|
||||
vehicle=label,
|
||||
unit_price=_ascii_amount(hit.group("amount") or ""),
|
||||
)
|
||||
for hit in _RE_FEE_OF_FREIGHT_PCT.finditer(raw):
|
||||
name = (hit.group("name") or "").strip()
|
||||
amt = _ascii_amount(hit.group("amount") or "")
|
||||
if not name or not amt:
|
||||
continue
|
||||
_add(name, f"{amt}%", "")
|
||||
priced_hits = 0
|
||||
for hit in _RE_FEE_PRICED.finditer(raw):
|
||||
priced_hits += 1
|
||||
# 有「金额」用金额;只有单价时才用单价。禁止把单价误当成这一行的总金额。
|
||||
amount = (hit.group("amount") or "").strip() or (hit.group("unit") or "").strip()
|
||||
# 有「金额」用金额;无金额但有单价×数量时算行金额;只有单价才退回单价。
|
||||
# 禁止「空运费单价CNY17 数量3500」把金额写成 17(WO202610230028)。
|
||||
explicit_amount = _ascii_amount(hit.group("amount") or "")
|
||||
unit_price = _ascii_amount(hit.group("unit") or "")
|
||||
quantity = _ascii_amount(hit.group("qty") or "")
|
||||
amount = explicit_amount
|
||||
amount_source = "explicit"
|
||||
if not amount and unit_price and quantity:
|
||||
try:
|
||||
product = float(unit_price) * float(quantity)
|
||||
amount = f"{product:.10g}"
|
||||
amount_source = "unit_x_qty"
|
||||
except ValueError:
|
||||
amount = unit_price
|
||||
amount_source = "unit_fallback_bad_qty"
|
||||
elif not amount:
|
||||
amount = unit_price
|
||||
amount_source = "unit_only"
|
||||
ccy = hit.group("amt_ccy") or hit.group("unit_ccy") or ""
|
||||
uom = (hit.groupdict().get("uom") or "").strip()
|
||||
_add(
|
||||
@@ -1347,13 +1465,21 @@ def _parse_fee_rows(text: str, baseline_currency: str = "") -> list[dict[str, st
|
||||
_ascii_amount(amount),
|
||||
ccy,
|
||||
unit=uom,
|
||||
unit_price=_ascii_amount(hit.group("unit") or ""),
|
||||
quantity=_ascii_amount(hit.group("qty") or ""),
|
||||
unit_price=unit_price,
|
||||
quantity=quantity,
|
||||
)
|
||||
for hit in _RE_FEE_LINE.finditer(raw):
|
||||
amount = _ascii_amount(hit.group("amount") or "")
|
||||
after_amount = raw[hit.end("amount") :]
|
||||
# 吨位/柜型数字不能当金额(运费10T:… 已被车型价规则吃掉;这里再挡漏网)。
|
||||
if _RE_AMOUNT_IS_VEHICLE_UNIT.match(after_amount):
|
||||
continue
|
||||
# 「80%」保留百分号,合计时只加绝对金额。
|
||||
if re.match(r"\s*%", after_amount or ""):
|
||||
amount = f"{amount}%"
|
||||
_add(
|
||||
(hit.group("name") or "").strip(),
|
||||
_ascii_amount(hit.group("amount") or ""),
|
||||
amount,
|
||||
hit.group("ccy1") or hit.group("ccy2") or "",
|
||||
)
|
||||
for hit in _RE_FEE_CHANGE.finditer(raw):
|
||||
@@ -1398,6 +1524,8 @@ def extract_product_quote(
|
||||
认不出价格返回空 dict,调用方回「没有识别到报价」。
|
||||
群里常见「码头操作费100CNY / 报关费改为300CNY」,不能只把第一笔数当成海运费。
|
||||
「空运费 单价…金额…」必须保留空运费,金额用「金额」后面的数,不用单价。
|
||||
只写「单价…数量…」未写金额时,行金额按单价×数量(WO202610230028),禁止落成单价。
|
||||
另起一行「备注:…」写入费用行 remark,出单备注列才有值(WO202610230028)。
|
||||
陆运集拼:「2-500KG 单价CNY990,燃油附加费率1%,税率6%」走分档单价+费率,
|
||||
禁止把公斤档下限「2」当成燃油附加费金额(WO021)。
|
||||
无费用名时按 business_line/transport_mode 默认陆运费/空运费/海运费,禁止陆运硬套海运费。
|
||||
@@ -1418,8 +1546,21 @@ def extract_product_quote(
|
||||
# 只补报价日期/有效期/时效要求时直接空:年份、天数不能当费用金额。
|
||||
if is_quote_date_only_message(raw) or is_non_fee_meta_only_message(raw):
|
||||
return {}
|
||||
quote_remark = _extract_quote_remark(stripped or raw)
|
||||
# 多车型整车价必须先于普通费用行:否则「40HQ/45HQ:19500」会被抽成 HQ=19500。
|
||||
vehicle = _parse_vehicle_rates_quote(stripped or raw, baseline_currency=base_ccy)
|
||||
if vehicle:
|
||||
note = quote_remark or str(vehicle.get("remark") or "")
|
||||
if note:
|
||||
vehicle["remark"] = note
|
||||
_attach_quote_remark(list(vehicle.get("fee_rows") or []), note)
|
||||
vehicle["fee_lines"] = list(vehicle.get("fee_rows") or [])
|
||||
return vehicle
|
||||
band = _parse_weight_band_quote(stripped or raw, baseline_currency=base_ccy)
|
||||
if band:
|
||||
if quote_remark:
|
||||
_attach_quote_remark(list(band.get("fee_rows") or []), quote_remark)
|
||||
band["fee_lines"] = list(band.get("fee_rows") or [])
|
||||
return band
|
||||
# 费率句若仍落到普通费用行,会把「燃油附加费」配上句首公斤数。先剥掉再抽。
|
||||
# 必须用剥掉 @询价小助手 后的正文,否则句首「起运港、」分段标签匹配不到。
|
||||
@@ -1428,8 +1569,11 @@ def extract_product_quote(
|
||||
scrubbed = _strip_segment_index_labels(
|
||||
_strip_rate_and_band_noise(_strip_non_fee_meta_chunks(stripped or raw))
|
||||
)
|
||||
# 备注整段不参与费用金额匹配,避免「备注:1:…」里的数字干扰。
|
||||
scrubbed = _RE_STANDALONE_REMARK.sub(" ", scrubbed)
|
||||
rows = _parse_fee_rows(scrubbed, baseline_currency=base_ccy) if scrubbed.strip() else []
|
||||
if rows:
|
||||
_attach_quote_remark(rows, quote_remark)
|
||||
ccy = rows[0].get("currency") or _currency_of(raw, base_ccy) or base_ccy
|
||||
money_rows = [x for x in rows if "%" not in str(x.get("amount") or "")]
|
||||
total = (money_rows[0] if money_rows else rows[0])["amount"]
|
||||
@@ -1471,13 +1615,15 @@ def extract_product_quote(
|
||||
elif fee_name == "燃油附加费":
|
||||
# 「燃油附加费率」误抽成费名时:陆运/空运用本单默认;海运旧行为落陆运费,避免当海运费金额。
|
||||
fee_name = default_fee if default_fee != "海运费" else "陆运费"
|
||||
fee_row: dict[str, str] = {"name": fee_name, "amount": amount, "currency": ccy}
|
||||
rows = _attach_quote_remark([fee_row], quote_remark)
|
||||
out = {
|
||||
"total": amount,
|
||||
"currency": ccy,
|
||||
"source_label": "产品报价",
|
||||
"raw_text": raw,
|
||||
"fee_rows": [{"name": fee_name, "amount": amount, "currency": ccy}],
|
||||
"fee_lines": [{"name": fee_name, "amount": amount, "currency": ccy}],
|
||||
"fee_rows": rows,
|
||||
"fee_lines": list(rows),
|
||||
}
|
||||
out.update(_extract_rate_fields(raw))
|
||||
return out
|
||||
@@ -1517,6 +1663,138 @@ def _strip_rate_and_band_noise(text: str) -> str:
|
||||
return cleaned
|
||||
|
||||
|
||||
def _normalize_vehicle_rate_token(token: str, *, sibling_suffix: str = "") -> str:
|
||||
"""
|
||||
车型口语归一:去空格、全角;裸「40」在「40/45HQ」里补成 40HQ。
|
||||
|
||||
副作用:无。
|
||||
"""
|
||||
raw = (token or "").strip().replace(" ", "").replace(" ", "")
|
||||
if not raw:
|
||||
return ""
|
||||
raw = raw.upper().replace("T", "T").replace("吨", "T")
|
||||
if sibling_suffix and not re.search(r"(T|HQ|GP|尺|厢车)$", raw, re.I):
|
||||
if re.fullmatch(r"\d+(?:\.\d+)?", raw):
|
||||
raw = raw + sibling_suffix.upper()
|
||||
return raw
|
||||
|
||||
|
||||
def _expand_vehicle_rate_label(label: str) -> list[str]:
|
||||
"""
|
||||
「5T/8T」「40HQ/45HQ」「40/45HQ」拆成可对表头的车型键。
|
||||
|
||||
斜杠并价时每个车型各占一列;禁止把整段「5T/8T」当唯一键(模板列是裸 5T/8T)。
|
||||
"""
|
||||
text = (label or "").strip()
|
||||
if not text:
|
||||
return []
|
||||
parts = [p.strip() for p in re.split(r"[//]", text) if p.strip()]
|
||||
suffix = ""
|
||||
for part in reversed(parts):
|
||||
hit = re.search(r"(T|HQ|GP|尺|厢车)$", part.replace(" ", ""), re.I)
|
||||
if hit:
|
||||
suffix = hit.group(1)
|
||||
break
|
||||
out: list[str] = []
|
||||
seen: set[str] = set()
|
||||
for part in parts:
|
||||
key = _normalize_vehicle_rate_token(part, sibling_suffix=suffix)
|
||||
if not key or key in seen:
|
||||
continue
|
||||
seen.add(key)
|
||||
out.append(key)
|
||||
return out
|
||||
|
||||
|
||||
def _harvest_vehicle_quote_remark(text: str) -> str:
|
||||
"""多车型价后的「含0点税 / 国六车提货」等口语备注。"""
|
||||
hits = [re.sub(r"\s+", "", m.group(0)) for m in _RE_VEHICLE_QUOTE_REMARK.finditer(text or "")]
|
||||
if not hits:
|
||||
return ""
|
||||
# 去重保序:含0点税 + 国六车提货 一并进备注
|
||||
seen: set[str] = set()
|
||||
parts: list[str] = []
|
||||
for hit in hits:
|
||||
if hit in seen:
|
||||
continue
|
||||
seen.add(hit)
|
||||
parts.append(hit)
|
||||
return " ".join(parts)
|
||||
|
||||
|
||||
def _parse_vehicle_rates_quote(text: str, baseline_currency: str = "") -> dict[str, Any]:
|
||||
"""
|
||||
陆运整车产品多车型价:车型:5T/8T:13000 10T:14000 40HQ/45HQ:19500。
|
||||
|
||||
产出 vehicleRates(键→金额)供主账按表头车型列写入;fee_rows 便于群摘要。
|
||||
至少两档车型价,或正文含「车型」且至少一档,才认定,避免普通金额误伤。
|
||||
无币种时继承 baseline,再退回 CNY(整车群报常见人民币)。
|
||||
"""
|
||||
raw = _ascii_amount(text or "")
|
||||
if not raw.strip():
|
||||
return {}
|
||||
base_ccy = str(baseline_currency or "").strip().upper()
|
||||
rates: dict[str, str] = {}
|
||||
rows: list[dict[str, str]] = []
|
||||
ccy = ""
|
||||
hits = list(_RE_VEHICLE_RATE_ITEM.finditer(raw))
|
||||
for hit in hits:
|
||||
label = (hit.group("label") or "").strip()
|
||||
price = _ascii_amount(hit.group("price") or "")
|
||||
if not label or not price:
|
||||
continue
|
||||
line_ccy = _currency_of(raw, hit.group("ccy") or base_ccy) or base_ccy
|
||||
ccy = ccy or line_ccy
|
||||
keys = _expand_vehicle_rate_label(label)
|
||||
if not keys:
|
||||
continue
|
||||
for key in keys:
|
||||
rates[key] = price
|
||||
rows.append(
|
||||
{
|
||||
"name": key,
|
||||
"amount": price,
|
||||
"currency": line_ccy or ccy or base_ccy or "CNY",
|
||||
"unit_price": price,
|
||||
}
|
||||
)
|
||||
if not rates:
|
||||
return {}
|
||||
has_vehicle_word = "车型" in raw
|
||||
if len(rates) < 2 and not has_vehicle_word:
|
||||
return {}
|
||||
remark = _harvest_vehicle_quote_remark(raw)
|
||||
# 多车型不要相加冒充合计;取第一档价作展示合计。
|
||||
first_price = next(iter(rates.values()))
|
||||
# fee_rows 用「陆运费」摘要一行(金额取第一档),禁止把 5T/40HQ 当费目名——
|
||||
# 否则出单 writeFeeAmountsByName 会命中车型表头,把车型名写进国内段起始地。
|
||||
summary_rows: list[dict[str, str]] = [
|
||||
{
|
||||
"name": "陆运费",
|
||||
"amount": first_price,
|
||||
"currency": ccy or base_ccy or "CNY",
|
||||
"unit_price": first_price,
|
||||
}
|
||||
]
|
||||
if remark:
|
||||
_attach_quote_remark(summary_rows, remark)
|
||||
out: dict[str, Any] = {
|
||||
"total": first_price,
|
||||
"currency": ccy or base_ccy or "CNY",
|
||||
"source_label": "产品报价",
|
||||
"raw_text": (text or "").strip(),
|
||||
"fee_rows": summary_rows,
|
||||
"fee_lines": list(summary_rows),
|
||||
"vehicleRates": dict(rates),
|
||||
"vehicle_rates": dict(rates),
|
||||
# 群摘要仍可展示分车型明细(不出单写费目名)
|
||||
"vehicle_fee_rows": rows,
|
||||
}
|
||||
if remark:
|
||||
out["remark"] = remark
|
||||
return out
|
||||
|
||||
|
||||
def _parse_weight_band_quote(text: str, baseline_currency: str = "") -> dict[str, Any]:
|
||||
"""
|
||||
陆运集拼分档单价:2-500KG 单价CNY990 + 可选燃油附加费率/税率。
|
||||
|
||||
@@ -102,10 +102,11 @@ def air_price_lines(
|
||||
facts: dict[str, str] | None = None,
|
||||
) -> list[str]:
|
||||
"""
|
||||
TMS 价格段:费用行、备注、费用合计、报价有效期。
|
||||
TMS 价格段:费用行、备注、费用合计约、报价有效期。
|
||||
|
||||
有单价且有计价单位:单价CNY11/KG。按票:CNY300/票。只有金额:CNY 100.0。
|
||||
备注每次都有,TMS 没带回就「-」。不写时效。
|
||||
合计是预估,不等于最终费用,所以文字里写「费用合计约」。卡片引用条仍叫费用合计。
|
||||
"""
|
||||
from agent.policy.inquiry_copy import money_text, tms_valid_until_display
|
||||
|
||||
@@ -115,7 +116,7 @@ def air_price_lines(
|
||||
lines = [line for line in lines if line]
|
||||
lines.append(f"备注:{_remark_display(src, facts)}")
|
||||
total = money_text(str(src.get("total") or "-").strip() or "-", header_ccy)
|
||||
lines.append(f"费用合计:{total}")
|
||||
lines.append(f"费用合计约:{total}")
|
||||
lines.append(f"报价有效期:{tms_valid_until_display(src)}")
|
||||
return lines
|
||||
|
||||
|
||||
@@ -578,23 +578,30 @@ def air_confirm_card(facts: dict[str, str] | None) -> str:
|
||||
"""
|
||||
确定查价前的核对卡。没有工单号。
|
||||
|
||||
起运地(非必填)紧挨在目的地(必填)上面。
|
||||
报价日期说了写成「报价日期:日期」;没说写成「报价日期(非必填):」,不填当天。
|
||||
必填项一律列出(方便核对)。非必填与报价日期:有识别结果才展示,空着不占行。
|
||||
起运地有值时紧挨在目的地上面。报价日期没说不填当天、也不出空行。
|
||||
"""
|
||||
src = dict(facts or {})
|
||||
lines = ["运输方式(必填):空运"]
|
||||
lines.append(_air_field_line("起运港", _air_known_value(src, "起运港"), required=False))
|
||||
origin_val = _air_known_value(src, "起运港")
|
||||
if origin_val:
|
||||
lines.append(_air_field_line("起运港", origin_val, required=False))
|
||||
for key, _label in AIR_REQUIRED_FIELDS:
|
||||
if key == "报价日期":
|
||||
val = _air_known_value(src, key)
|
||||
# 说了日期就只写日期;没说标明非必填并留空,禁止写成当天。
|
||||
lines.append(f"报价日期:{val}" if val else "报价日期(非必填):")
|
||||
# 说了才展示;没说不占行、不填当天(产品:空非必填不显示)。
|
||||
if val:
|
||||
lines.append(f"报价日期:{val}")
|
||||
continue
|
||||
lines.append(_air_field_line(key, _air_known_value(src, key), required=True))
|
||||
for key, _label in AIR_OPTIONAL_FIELDS:
|
||||
if key == "起运港":
|
||||
continue
|
||||
lines.append(_air_field_line(key, _air_known_value(src, key), required=False))
|
||||
opt_val = _air_known_value(src, key)
|
||||
if not opt_val:
|
||||
continue
|
||||
opt_line = _air_field_line(key, opt_val, required=False)
|
||||
lines.append(opt_line)
|
||||
lines.append("")
|
||||
lines.append(AIR_CONFIRM_TAIL)
|
||||
return "\n".join(lines)
|
||||
|
||||
@@ -967,13 +967,18 @@ def apply_product_quote(
|
||||
send_group_text(client, chat_id, copy.group_quote_not_recognized())
|
||||
return "quote_not_recognized"
|
||||
quote = _attach_land_weight_band_segment(quote, view)
|
||||
quote = _attach_land_vehicle_rates_segment(quote, view)
|
||||
if _has_tms_quote(base):
|
||||
_park_pending_quote(no, quote, sess, flow)
|
||||
send_group_text(client, chat_id, copy.group_ask_tms_or_product())
|
||||
return "wait_tms_choice"
|
||||
# 分档单价是完整人工价(含费率),禁止和旧错误行(如燃油附加费=2)相加。
|
||||
# 分档单价 / 多车型价表是完整人工价,禁止和旧错误行相加。
|
||||
# 旧错默认「海运费」的陆运产品价:重报时按本单默认运费对齐后再盖,避免海运费+陆运费并排。
|
||||
if _quote_fee_rows(base) and not (quote.get("weightPrices") or []):
|
||||
if (
|
||||
_quote_fee_rows(base)
|
||||
and not (quote.get("weightPrices") or [])
|
||||
and not (quote.get("vehicleRates") or quote.get("vehicle_rates") or [])
|
||||
):
|
||||
base = _align_wrong_default_freight(base, quote, business_line=line)
|
||||
quote = merge_quote_fees(base, quote)
|
||||
_save_product_quote(flow, no, quote, sess)
|
||||
@@ -2009,6 +2014,79 @@ def _attach_land_weight_band_segment(
|
||||
return src
|
||||
|
||||
|
||||
def _land_od_from_view(view: dict[str, Any]) -> tuple[str, str]:
|
||||
"""
|
||||
工单询价事实里的起运/目的。
|
||||
|
||||
合同归一后陆运常用「起运港/目的港」「提货地址/收货地址」;
|
||||
「目的地→目的港」「送货地址→收货地址」。产品口语「太原富士康--春疆」不当目的港。
|
||||
"""
|
||||
facts = dict((view or {}).get("facts") or {})
|
||||
origin = str(
|
||||
facts.get("起运港")
|
||||
or facts.get("始发站")
|
||||
or facts.get("始发地")
|
||||
or facts.get("起运地")
|
||||
or facts.get("提货地址")
|
||||
or facts.get("origin")
|
||||
or (view or {}).get("origin")
|
||||
or ""
|
||||
).strip()
|
||||
dest = str(
|
||||
facts.get("目的港")
|
||||
or facts.get("目的地")
|
||||
or facts.get("收货地址")
|
||||
or facts.get("送货地址")
|
||||
or facts.get("destination")
|
||||
or (view or {}).get("destination")
|
||||
or ""
|
||||
).strip()
|
||||
return origin, dest
|
||||
|
||||
|
||||
def _attach_land_vehicle_rates_segment(
|
||||
quote: dict[str, Any], view: dict[str, Any]
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
陆运产品多车型价:把 vehicleRates 挂到 landSegments,出单才能填 5T/10T/40HQ 列。
|
||||
|
||||
无车型价表时原样返回。OD 取工单询价事实;备注进段上 remark(含0点税等)。
|
||||
不写裸 salePrice 冒充单车型,避免多列表头误灌同一价。
|
||||
"""
|
||||
src = dict(quote or {})
|
||||
rates = src.get("vehicleRates") or src.get("vehicle_rates")
|
||||
if not isinstance(rates, dict) or not rates:
|
||||
return src
|
||||
clean = {
|
||||
str(k).strip(): str(v).strip()
|
||||
for k, v in rates.items()
|
||||
if str(k).strip() and str(v).strip()
|
||||
}
|
||||
if not clean:
|
||||
return src
|
||||
origin, dest = _land_od_from_view(view)
|
||||
remark = str(src.get("remark") or "").strip()
|
||||
seg: dict[str, Any] = {
|
||||
"origin": origin,
|
||||
"destination": dest,
|
||||
"vehicleRates": dict(clean),
|
||||
"vehicle_rates": dict(clean),
|
||||
"currency": str(src.get("currency") or "CNY"),
|
||||
}
|
||||
if remark:
|
||||
seg["remark"] = remark
|
||||
# 展示合计用第一档,不写入 salePrice,防止 resolve 在无 map 匹配时乱灌。
|
||||
src["landSegments"] = [seg]
|
||||
src["route_rows"] = [seg]
|
||||
src["vehicleRates"] = dict(clean)
|
||||
src["vehicle_rates"] = dict(clean)
|
||||
# 多车型价只走 vehicleRates 矩阵列;fee_rows 若仍是「10T/40HQ」会被出单当成费目名
|
||||
# 写进国内段「起始地」(运行证据:国内段出现 10T/40HQ/45HQ 行)。挂段后清空费目行。
|
||||
src["fee_rows"] = []
|
||||
src["fee_lines"] = []
|
||||
return src
|
||||
|
||||
|
||||
def _save_product_quote(
|
||||
flow: Any,
|
||||
no: str,
|
||||
|
||||
@@ -237,13 +237,27 @@ class SeaTextInquiryFlow(AirTextInquiryFlow):
|
||||
|
||||
# 刚选定海运时,贸易条款、运输分类要对照定方式前的全部原话,不只看「海运」两个字。
|
||||
source = waiting_mode_source(sess, text)
|
||||
# 补问阶段 waiting_mode_source 只给本句;首句里的「港到港」必须拼回去,
|
||||
# 否则 apply_spoken 会把会话已有条款当成模型冒充删掉(只补货量时再问贸易条款)。
|
||||
trade_source = source
|
||||
if sess and getattr(sess, "phase", "") in {"clarify", "wait_confirm", "sensitive_block"}:
|
||||
trade_source = stack_user_text(getattr(sess, "immutable_text", "") or "", text)
|
||||
# 整句只回「港到港」是贸易条款举例,不要改写成运输分类。
|
||||
class_source = "" if short_sea_trade_reply(source) == "港到港" else source
|
||||
facts = harvest_sea_class(class_source, facts)
|
||||
# 贸易条款标签行原样优先;整句回复或长句里写了门到门/港到港都要收下。
|
||||
# 原话没出现这两个词时,模型冒充的门到门、港到港继续丢掉。
|
||||
facts = apply_spoken_sea_trade_reply(source, facts)
|
||||
spoken = harvest_spoken_trade_term(source)
|
||||
# 补问用 trade_source(首句+本句),避免只补货量时丢掉已确认的港到港。
|
||||
facts = apply_spoken_sea_trade_reply(trade_source, facts)
|
||||
# 本句显式改条款时覆盖历史(短回门到门/港到港,或写出 FOB/CIF 等)。
|
||||
short_now = short_sea_trade_reply(text)
|
||||
if short_now:
|
||||
facts["贸易条款"] = short_now
|
||||
else:
|
||||
spoken_now = harvest_spoken_trade_term(text)
|
||||
if spoken_now.get("贸易条款"):
|
||||
facts["贸易条款"] = spoken_now["贸易条款"]
|
||||
spoken = harvest_spoken_trade_term(trade_source)
|
||||
if spoken.get("贸易条款") and not str(facts.get("贸易条款") or "").strip():
|
||||
facts["贸易条款"] = spoken["贸易条款"]
|
||||
check = validate_required_fields(facts=facts, business_line="SEA")
|
||||
|
||||
@@ -169,15 +169,35 @@ ALL_COLLAB_KEYS = tuple(
|
||||
|
||||
# 口语里已经带上 TMS 文档规定的单位时,补进空字段。
|
||||
# 只认「数字+单位」,不猜港口,不把长宽高换算成立方。
|
||||
_RE_PIECES = re.compile(r"(?<![\d.])(\d+)\s*(件|pcs)\b", re.I)
|
||||
_RE_WEIGHT = re.compile(r"(?<![\d.])(\d+(?:\.\d+)?)\s*(kgs|kg|公斤|千克)\b", re.I)
|
||||
# 单位后不用 Unicode \b:CBM/KG 紧贴中文时 \w 含汉字,\b 不成立会整段漏抽。
|
||||
_RE_PIECES = re.compile(r"(?<![\d.])(\d+)\s*(件|pcs)(?![A-Za-z0-9])", re.I)
|
||||
_RE_WEIGHT = re.compile(
|
||||
r"(?<![\d.])(\d+(?:\.\d+)?)\s*(kgs|kg|公斤|千克)(?![A-Za-z0-9])",
|
||||
re.I,
|
||||
)
|
||||
_RE_VOLUME = re.compile(
|
||||
r"(?<![\d.])(\d+(?:\.\d+)?)\s*(cbm|立方米|立方|m3|m³)\b",
|
||||
r"(?<![\d.])(\d+(?:\.\d+)?)\s*(cbm|立方米|立方|m3|m³)(?![A-Za-z0-9])",
|
||||
re.I,
|
||||
)
|
||||
_RE_VOLUME_FANG = re.compile(r"(?<![\d.])(\d+(?:\.\d+)?)\s*方(?!向)")
|
||||
_RE_WEIGHT_WORD = re.compile(r"(?:毛重|重量)\s*[::]?\s*(\d+(?:\.\d+)?)")
|
||||
_RE_VOLUME_WORD = re.compile(r"体积\s*[::]?\s*(\d+(?:\.\d+)?)")
|
||||
# 销售常把小数点两侧空开,或误用全角点/中文句号:578. 5KG、1. 03CBM。
|
||||
# 只在后面跟重量/体积单位时收拢,避免误伤普通句号。
|
||||
_RE_BROKEN_DECIMAL = re.compile(
|
||||
r"(\d+)\s*[..。]\s*(\d+)(?=\s*(?:kgs?|公斤|千克|cbm|立方米|立方|m3|m³|方))",
|
||||
re.I,
|
||||
)
|
||||
|
||||
|
||||
def _glue_broken_decimals(text: str) -> str:
|
||||
"""
|
||||
把「578. 5KG」「1. 03CBM」收成「578.5KG」「1.03CBM」。
|
||||
|
||||
中英文句号/全角点两侧有空格时,机读否则只命中小数段变成 5KG/03CBM。
|
||||
副作用:无。不改主账。
|
||||
"""
|
||||
return _RE_BROKEN_DECIMAL.sub(r"\1.\2", text or "")
|
||||
# 销售原话里的包装词:当前句出现则覆盖旧值,散货也要收下
|
||||
_PACK_WORDS = ("纸箱", "木箱", "托盘", "卡板", "散货")
|
||||
# 销售口中的报价日期。内部键仍是报价日期。货好时间、提货地址不是这里。
|
||||
@@ -439,10 +459,12 @@ def harvest_oral_measures(text: str, facts: dict[str, str] | None = None) -> dic
|
||||
|
||||
当前句写了的覆盖旧值:散货替换托盘,9月16日写入报价日期。
|
||||
补问复制清单的示例行不参与机读。
|
||||
小数点两侧空格先收拢,再匹配单位。
|
||||
副作用:无。不改主账。不猜港口。
|
||||
"""
|
||||
merged = dict(facts or {})
|
||||
raw = _without_clarify_examples(text or "")
|
||||
raw0 = _without_clarify_examples(text or "")
|
||||
raw = _glue_broken_decimals(raw0)
|
||||
hit = _RE_PIECES.search(raw)
|
||||
if hit:
|
||||
merged["件数"] = f"{hit.group(1)}{hit.group(2)}"
|
||||
@@ -656,6 +678,27 @@ def looks_like_container_spec(text: str) -> bool:
|
||||
return bool(_CONTAINER_SPEC.search(text or ""))
|
||||
|
||||
|
||||
# 货量里除箱型外还有装满/吨等意图时,不能当「误写入的箱型」丢掉。
|
||||
_CARGO_QTY_INTENT = re.compile(
|
||||
r"装满|满柜|满载|吨|件|KG|KGS|CBM|立方|\d+\s*方|票|报价\s*\d|\d+\s*个价格",
|
||||
re.I,
|
||||
)
|
||||
|
||||
|
||||
def is_container_only_cargo_qty(text: str) -> bool:
|
||||
"""
|
||||
货量是否整段只是箱型箱量写法。
|
||||
|
||||
「40HQ*1」「1x40HQ」应从货量剔除;「40HQ、20GP 装满,报价2个价格」是销售在答货物数量,保留。
|
||||
"""
|
||||
raw = (text or "").strip()
|
||||
if not looks_like_container_spec(raw):
|
||||
return False
|
||||
if _CARGO_QTY_INTENT.search(raw):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def promote_land_vehicle_from_container(facts: dict[str, str] | None) -> dict[str, str]:
|
||||
"""
|
||||
陆运时把误落入「箱型箱量」的车型改写到「车型/数量」。
|
||||
@@ -697,18 +740,21 @@ def project_sea_cargo_qty(facts: dict[str, str] | None) -> dict[str, str]:
|
||||
海运货物数量投影。
|
||||
|
||||
抽字段常把「20件」放进件数,又把「40HQ*1」写进货量。
|
||||
货量只要长得像箱型,就丢掉,改用件数里的数量;件数也是箱型则不搬。
|
||||
箱型箱量空着时,把这串箱型补到箱型箱量。不限具体件数。
|
||||
货量若整段只是箱型写法,就丢掉,改用件数里的数量;件数也是箱型则不搬。
|
||||
「40HQ 装满」这类带货量意图的保留,不能再逼销售重填。
|
||||
箱型箱量空着时,把纯箱型串补到箱型箱量。不限具体件数。
|
||||
"""
|
||||
merged = dict(facts or {})
|
||||
qty = (merged.get("货量") or merged.get("货物数量") or "").strip()
|
||||
pieces = (merged.get("件数") or "").strip()
|
||||
if looks_like_container_spec(qty):
|
||||
if is_container_only_cargo_qty(qty):
|
||||
if not (merged.get("箱型箱量") or "").strip():
|
||||
merged["箱型箱量"] = qty
|
||||
merged.pop("货量", None)
|
||||
merged.pop("货物数量", None)
|
||||
qty = ""
|
||||
elif looks_like_container_spec(qty) and _CARGO_QTY_INTENT.search(qty):
|
||||
pass
|
||||
if not qty and pieces and not looks_like_container_spec(pieces):
|
||||
merged["货量"] = pieces
|
||||
return merged
|
||||
|
||||
@@ -119,7 +119,8 @@ class AirAddedServicesTests(unittest.TestCase):
|
||||
self.assertEqual(snap["facts"].get("包装方式"), "托盘")
|
||||
card = copy.air_confirm_card(snap["facts"])
|
||||
self.assertIn("包装类型(必填):托盘", card)
|
||||
self.assertIn("增值服务(非必填):\n", card)
|
||||
# 增值服务未识别:核对卡不占空行。
|
||||
self.assertNotIn("增值服务(非必填)", card)
|
||||
self.assertNotIn("托盘、报价日期", card)
|
||||
|
||||
def test_pallet_alone_is_package_and_service(self) -> None:
|
||||
@@ -135,7 +136,12 @@ class AirAddedServicesTests(unittest.TestCase):
|
||||
|
||||
def test_confirm_lists_optional_and_ticket_hides_empty(self) -> None:
|
||||
card = copy.air_confirm_card({"目的港": "吉隆坡", "包装方式": "纸箱"})
|
||||
self.assertIn("增值服务(非必填):", card)
|
||||
# 核对卡空非必填不展示;有值时才出现。
|
||||
self.assertNotIn("增值服务(非必填)", card)
|
||||
with_svc = copy.air_confirm_card(
|
||||
{"目的港": "吉隆坡", "包装方式": "纸箱", "added_services": "托盘"}
|
||||
)
|
||||
self.assertIn("增值服务(非必填):托盘", with_svc)
|
||||
clarify = copy.ask_clarify(
|
||||
facts={"目的港": "吉隆坡"},
|
||||
missing_keys=["品名"],
|
||||
|
||||
@@ -110,17 +110,49 @@ class AirFieldContractTests(unittest.TestCase):
|
||||
"体积": "2",
|
||||
"包装方式": "托盘",
|
||||
"报价日期": "2026-09-22",
|
||||
"起运港": "南京",
|
||||
"货源地": "东莞",
|
||||
}
|
||||
)
|
||||
self.assertNotIn("工单号", text)
|
||||
self.assertIn("起运地(非必填):", text)
|
||||
# 有值的非必填才展示;空着的(贸易条款等)不占行。
|
||||
self.assertIn("起运地(非必填):南京", text)
|
||||
self.assertNotIn("起运港(非必填)", text)
|
||||
self.assertLess(text.index("起运地(非必填):"), text.index("目的地(必填):克拉克"))
|
||||
self.assertLess(text.index("起运地(非必填):南京"), text.index("目的地(必填):克拉克"))
|
||||
self.assertIn("目的地(必填):克拉克", text)
|
||||
self.assertIn("货源地(非必填):", text)
|
||||
self.assertIn("贸易条款(非必填):", text)
|
||||
self.assertIn("货源地(非必填):东莞", text)
|
||||
self.assertIn("报价日期:2026-09-22", text)
|
||||
self.assertNotIn("贸易条款(非必填):", text)
|
||||
self.assertNotIn("货好时间(非必填):", text)
|
||||
self.assertIn(copy.AIR_CONFIRM_TAIL, text)
|
||||
|
||||
def test_confirm_card_hides_empty_optional(self) -> None:
|
||||
"""空运核对卡:未识别的非必填(含空报价日期)不展示。"""
|
||||
text = copy.air_confirm_card(
|
||||
{
|
||||
"目的港": "KUL",
|
||||
"品名": "普货",
|
||||
"件数": "4",
|
||||
"毛重": "636",
|
||||
"体积": "7.497",
|
||||
"包装方式": "托盘",
|
||||
"提货地址": "深圳",
|
||||
"added_services": "托盘",
|
||||
}
|
||||
)
|
||||
self.assertIn("目的地(必填):KUL", text)
|
||||
self.assertIn("提货地址(非必填):深圳", text)
|
||||
self.assertIn("增值服务(非必填):托盘", text)
|
||||
for empty in (
|
||||
"起运地(非必填):",
|
||||
"报价日期(非必填):",
|
||||
"货源地(非必填):",
|
||||
"货好时间(非必填):",
|
||||
"收货地址(非必填):",
|
||||
"贸易条款(非必填):",
|
||||
):
|
||||
self.assertNotIn(empty, text)
|
||||
|
||||
def test_clarify_puts_origin_above_destination(self) -> None:
|
||||
text = copy.ask_clarify(
|
||||
facts={},
|
||||
|
||||
@@ -485,7 +485,7 @@ class AirRouteOptionsTests(unittest.TestCase):
|
||||
"增点费:CNY 100.0",
|
||||
"拆板费:USD 100.0",
|
||||
"备注:-",
|
||||
"费用合计:CNY 5001.0",
|
||||
"费用合计约:CNY 5001.0",
|
||||
"报价有效期:2026-09-30",
|
||||
]
|
||||
),
|
||||
@@ -547,7 +547,7 @@ class AirRouteOptionsTests(unittest.TestCase):
|
||||
self.assertIn("报关费:CNY250/票", text)
|
||||
self.assertIn("增点费:CNY 100.0", text)
|
||||
self.assertIn("备注:其他杂费如有实报实销,不含续页;续页50/票", text)
|
||||
self.assertIn("费用合计:CNY 87150.0", text)
|
||||
self.assertIn("费用合计约:CNY 87150.0", text)
|
||||
self.assertIn("报价有效期:2026-10-31", text)
|
||||
self.assertNotIn("询价字段", text)
|
||||
|
||||
@@ -657,7 +657,8 @@ class AirRouteOptionsTests(unittest.TestCase):
|
||||
flow.on_text(sender_id="u_cabin", text="空运", reply=reply, injected_facts=facts, injected_mode="AIR"),
|
||||
"wait_confirm",
|
||||
)
|
||||
self.assertIn("报价日期(非必填):", replies[-1])
|
||||
# 没说报价日期:核对卡不占空行,也不默认写成当天。
|
||||
self.assertNotIn("报价日期(非必填):", replies[-1])
|
||||
self.assertNotIn("报价日期:2026", replies[-1])
|
||||
self.assertEqual(flow.on_text(sender_id="u_cabin", text="确定", reply=reply), "wait_air_route")
|
||||
self.assertEqual(ledger.queries, 1)
|
||||
|
||||
@@ -972,7 +972,7 @@ class AirTextInquiryTests(unittest.TestCase):
|
||||
self.assertIn("操作费:CNY 1220.00", text)
|
||||
self.assertIn("空运费:USD 1250.00", text)
|
||||
self.assertIn("备注:-", text)
|
||||
self.assertIn("费用合计:CNY 142998.53", text)
|
||||
self.assertIn("费用合计约:CNY 142998.53", text)
|
||||
self.assertNotIn("时效", text)
|
||||
self.assertIn("报价有效期:2026-09-30", text)
|
||||
card_text = copy.quote_area_safe_text(long_quote, business_line="AIR")
|
||||
@@ -1024,7 +1024,7 @@ class AirTextInquiryTests(unittest.TestCase):
|
||||
self.assertNotIn("ZUH-CAN-CRK", detail)
|
||||
self.assertIn("价格方案如下:", detail)
|
||||
self.assertIn("运输费:CNY 11.0", detail)
|
||||
self.assertIn("费用合计:CNY 183370", detail)
|
||||
self.assertIn("费用合计约:CNY 183370", detail)
|
||||
rows = {
|
||||
x["keyname"]: x["value"]
|
||||
for x in copy.scheme_horizontal_rows(
|
||||
|
||||
@@ -335,6 +335,21 @@ class OralExtractTests(unittest.TestCase):
|
||||
self.assertIn("重量(KG):1.5KG", shown)
|
||||
self.assertNotIn("1.5KGS", shown)
|
||||
|
||||
def test_broken_decimal_space_keeps_full_weight_volume(self) -> None:
|
||||
"""小数点后空格不得只抽到小数段:578. 5KG/1. 03CBM → 578.5KG/1.03CBM。"""
|
||||
from agent.schema.field_validate import harvest_oral_measures
|
||||
|
||||
text = "1个木箱/578. 5KG/1. 03CBM空运普货1箱托盘到MAA"
|
||||
facts = harvest_oral_measures(text, {})
|
||||
self.assertEqual(facts.get("毛重"), "578.5KG")
|
||||
self.assertEqual(facts.get("体积"), "1.03CBM")
|
||||
self.assertNotEqual(facts.get("毛重"), "5KG")
|
||||
self.assertNotEqual(facts.get("体积"), "03CBM")
|
||||
|
||||
fullwidth = harvest_oral_measures("茶叶,578. 5KG,1。03CBM,托盘", {})
|
||||
self.assertEqual(fullwidth.get("毛重"), "578.5KG")
|
||||
self.assertEqual(fullwidth.get("体积"), "1.03CBM")
|
||||
|
||||
def test_dimension_text_is_volume_without_multiplying(self) -> None:
|
||||
from agent.schema.field_validate import harvest_oral_measures
|
||||
|
||||
|
||||
@@ -360,6 +360,43 @@ class LandGroupCollabTests(unittest.TestCase):
|
||||
"只有这张单的销售能调价。航线请继续报价,价格未改。",
|
||||
)
|
||||
|
||||
def test_land_multi_vehicle_rates_attach_segment(self) -> None:
|
||||
"""多车型价挂到 landSegments,出单才能按车型列写入;OD 用工单事实。"""
|
||||
from agent.llm.extract_text import extract_product_quote
|
||||
from agent.policy.sea_group_ops import _attach_land_vehicle_rates_segment
|
||||
|
||||
quote = extract_product_quote(
|
||||
"太原富士康--春疆\n车型:\n5T/8T:13000\n10T:14000\n40HQ/45HQ:19500\n含0点税",
|
||||
business_line="LAND",
|
||||
)
|
||||
view = {
|
||||
"facts": {
|
||||
"起运港": "太原富士康",
|
||||
"目的港": "越南北寧市南山工業區",
|
||||
}
|
||||
}
|
||||
out = _attach_land_vehicle_rates_segment(quote, view)
|
||||
segs = list(out.get("landSegments") or [])
|
||||
self.assertEqual(len(segs), 1)
|
||||
seg = segs[0]
|
||||
self.assertEqual(str(seg.get("origin") or ""), "太原富士康")
|
||||
self.assertEqual(str(seg.get("destination") or ""), "越南北寧市南山工業區")
|
||||
rates = dict(seg.get("vehicleRates") or {})
|
||||
self.assertEqual(rates.get("5T"), "13000")
|
||||
self.assertEqual(rates.get("45HQ"), "19500")
|
||||
self.assertEqual(str(seg.get("remark") or ""), "含0点税")
|
||||
self.assertFalse(str(seg.get("salePrice") or "").strip())
|
||||
self.assertEqual(list(out.get("fee_rows") or []), [])
|
||||
# 收货地址归一键也能取到目的地
|
||||
out2 = _attach_land_vehicle_rates_segment(
|
||||
quote,
|
||||
{"facts": {"提货地址": "太原富士康", "收货地址": "越南北寧市南山工業區"}},
|
||||
)
|
||||
self.assertEqual(
|
||||
str((out2.get("landSegments") or [{}])[0].get("destination") or ""),
|
||||
"越南北寧市南山工業區",
|
||||
)
|
||||
|
||||
def test_land_bare_price_defaults_to_land_fee(self) -> None:
|
||||
"""陆运「价格为1RMB/KG」无费用名时默认陆运费,禁止落成海运费(WO118)。"""
|
||||
from agent.llm.extract_text import extract_product_quote
|
||||
|
||||
@@ -518,6 +518,41 @@ class SeaTextInquiryTests(unittest.TestCase):
|
||||
self.assertNotIn("1.贸易条款(必填)", body)
|
||||
self.assertNotEqual(phase, "need_mode")
|
||||
|
||||
def test_clarify_qty_keeps_gangdaogang_and_accepts_full_box_qty(self) -> None:
|
||||
"""已有港到港时只补「装满」货量:不再追问货物数量和贸易条款。"""
|
||||
inq = "东莞到新西兰利特尔顿港和奥克兰港!报一下40HQ和20GP的价格,产品是装奶粉的罐子,条款港到港"
|
||||
facts = {
|
||||
"起运港": "东莞",
|
||||
"目的港": "利特尔顿港",
|
||||
"品名": "奶粉罐子",
|
||||
"整柜或拼柜": "整柜",
|
||||
"箱型箱量": "40HQ、20GP",
|
||||
"贸易条款": "港到港",
|
||||
"运输分类": "Port to Port",
|
||||
}
|
||||
phase = self.flow.on_text(
|
||||
sender_id="s-full-box",
|
||||
text=inq,
|
||||
reply=self._reply,
|
||||
injected_facts=facts,
|
||||
injected_mode="SEA",
|
||||
)
|
||||
self.assertEqual(phase, "clarify")
|
||||
self.replies.clear()
|
||||
phase = self.flow.on_text(
|
||||
sender_id="s-full-box",
|
||||
text="1.货物数量(必填):40HQ、20GP 装满,报价2个价格\n(如:20吨)",
|
||||
reply=self._reply,
|
||||
)
|
||||
self.assertEqual(phase, "wait_confirm")
|
||||
sess = self.flow.session_of("s-full-box")
|
||||
self.assertEqual(sess.facts.get("贸易条款"), "港到港")
|
||||
self.assertIn("装满", str(sess.facts.get("货量") or ""))
|
||||
body = "\n".join(self.replies)
|
||||
self.assertIn("贸易条款(必填):港到港", body)
|
||||
self.assertNotIn("1.货物数量(必填):\n", body)
|
||||
self.assertNotIn("贸易条款(必填):\n(如:门到门、港到港)", body)
|
||||
|
||||
def test_harvest_class_from_reply_then_quotes(self) -> None:
|
||||
first = dict(COMPLETE_SEA)
|
||||
first.pop("运输分类")
|
||||
@@ -1341,6 +1376,66 @@ class SeaGroupCollabFieldTests(unittest.TestCase):
|
||||
self.assertEqual(str(rows["海运费"].get("amount") or ""), "100.00")
|
||||
self.assertEqual(str(rows["燃油附加费"].get("amount") or ""), "15.00")
|
||||
|
||||
def test_land_hk_vehicle_tonnage_not_freight_amount(self) -> None:
|
||||
"""中港陆运「运费10T:1700HKD」不能抽成运费=10;压夜/压日按运费比例不能进合计。"""
|
||||
from agent.llm.extract_text import extract_product_quote
|
||||
|
||||
text = (
|
||||
"深圳--香港元朗运费10T:1700HKD/车\n"
|
||||
"超时费:免等候2小时,超出按200/小时收取;如遇海关查验,查验等候免3小时,"
|
||||
"超过了200/小时,压夜按运费80%,压日按运费100%以上港币报价,不含保,杂费实报实"
|
||||
)
|
||||
quote = extract_product_quote(
|
||||
text, business_line="LAND", transport_mode="陆运", baseline_currency="HKD"
|
||||
)
|
||||
rows = {str(x.get("name") or ""): x for x in (quote.get("fee_rows") or [])}
|
||||
freight = rows.get("深圳--香港元朗运费") or {}
|
||||
self.assertEqual(str(freight.get("amount") or ""), "1700")
|
||||
self.assertEqual(str(freight.get("currency") or ""), "HKD")
|
||||
self.assertEqual(str(rows.get("压夜按运费", {}).get("amount") or ""), "80%")
|
||||
self.assertEqual(str(rows.get("压日按运费", {}).get("amount") or ""), "100%")
|
||||
self.assertEqual(float(quote.get("total") or 0), 1700.0)
|
||||
self.assertNotEqual(str(quote.get("total") or ""), "190.0")
|
||||
|
||||
def test_land_multi_vehicle_rates_not_hq_fee(self) -> None:
|
||||
"""陆运整车多车型价:不能抽成 HQ=19500;要拆成 5T/8T/10T/40HQ/45HQ 价表。"""
|
||||
from agent.llm.extract_text import extract_product_quote
|
||||
|
||||
quote = extract_product_quote(
|
||||
"太原富士康--春疆\n车型:\n5T/8T:13000\n10T:14000\n40HQ/45HQ:19500\n 含0点税",
|
||||
business_line="LAND",
|
||||
transport_mode="陆运",
|
||||
)
|
||||
rates = dict(quote.get("vehicleRates") or {})
|
||||
self.assertEqual(rates.get("5T"), "13000")
|
||||
self.assertEqual(rates.get("8T"), "13000")
|
||||
self.assertEqual(rates.get("10T"), "14000")
|
||||
self.assertEqual(rates.get("40HQ"), "19500")
|
||||
self.assertEqual(rates.get("45HQ"), "19500")
|
||||
self.assertEqual(str(quote.get("remark") or ""), "含0点税")
|
||||
names = {str(x.get("name") or "") for x in (quote.get("fee_rows") or [])}
|
||||
self.assertNotIn("HQ", names)
|
||||
self.assertNotIn("5T", names)
|
||||
self.assertNotIn("40HQ", names)
|
||||
self.assertIn("陆运费", names)
|
||||
veh_names = {str(x.get("name") or "") for x in (quote.get("vehicle_fee_rows") or [])}
|
||||
self.assertIn("5T", veh_names)
|
||||
self.assertIn("40HQ", veh_names)
|
||||
|
||||
def test_land_multi_vehicle_40_slash_45hq(self) -> None:
|
||||
"""口语 40/45HQ 19500 要拆成 40HQ+45HQ,不能只认 45HQ。"""
|
||||
from agent.llm.extract_text import extract_product_quote
|
||||
|
||||
quote = extract_product_quote(
|
||||
"车型:5T/8T:13000 10T:14000 40/45HQ 19500 含0点 国六车提货",
|
||||
business_line="LAND",
|
||||
)
|
||||
rates = dict(quote.get("vehicleRates") or {})
|
||||
self.assertEqual(rates.get("40HQ"), "19500")
|
||||
self.assertEqual(rates.get("45HQ"), "19500")
|
||||
self.assertEqual(rates.get("5T"), "13000")
|
||||
self.assertIn("含0点", str(quote.get("remark") or ""))
|
||||
|
||||
def test_land_weight_band_unit_price_and_rates(self) -> None:
|
||||
"""陆运集拼:2-500KG 单价 + 燃油附加费率/税率,不能把档下限 2 当成燃油附加费。"""
|
||||
from agent.llm.extract_text import extract_product_quote
|
||||
@@ -1379,6 +1474,24 @@ class SeaGroupCollabFieldTests(unittest.TestCase):
|
||||
self.assertEqual(str(rows["空运费"].get("quantity") or ""), "100")
|
||||
self.assertEqual(str(quote.get("total") or ""), "199.0")
|
||||
|
||||
def test_air_unit_qty_without_amount_multiplies(self) -> None:
|
||||
"""WO028:只写单价+数量、不写金额时,行金额必须是单价×数量,不能落成单价。"""
|
||||
from agent.llm.extract_text import extract_product_quote
|
||||
|
||||
quote = extract_product_quote(
|
||||
"空运费单价CNY17.00 数量3500@智价通AIQ\n备注:1:250+ 吨上\nWO202610230028",
|
||||
business_line="AIR",
|
||||
transport_mode="空运",
|
||||
)
|
||||
rows = {str(x.get("name") or ""): x for x in (quote.get("fee_rows") or [])}
|
||||
self.assertIn("空运费", rows)
|
||||
self.assertEqual(str(rows["空运费"].get("unit_price") or ""), "17.00")
|
||||
self.assertEqual(str(rows["空运费"].get("quantity") or ""), "3500")
|
||||
self.assertEqual(str(rows["空运费"].get("amount") or ""), "59500")
|
||||
self.assertEqual(str(rows["空运费"].get("currency") or ""), "CNY")
|
||||
self.assertEqual(str(rows["空运费"].get("remark") or ""), "1:250+ 吨上")
|
||||
self.assertEqual(str(quote.get("total") or ""), "59500.0")
|
||||
|
||||
def test_air_fee_priced_with_unit_between_name_and_unit_price(self) -> None:
|
||||
"""WO003:空运费, KG, 单价…数量…金额… 中间夹单位时不能把单价当行金额。"""
|
||||
from agent.llm.extract_text import extract_product_quote
|
||||
|
||||
+23
-3
@@ -51,11 +51,12 @@ public class InquiryBotReplyController extends JeecgController<InquiryBotReply,
|
||||
}
|
||||
|
||||
/**
|
||||
* 全量列表,供分类页一次加载。
|
||||
* 全量列表,供分类页一次加载;布局拉后台标题也会走到这里(旧前端缓存)。
|
||||
* 只要已登录即可读,不要求 inquiry:reply:list——中港等业务角色进看板否则会弹「没有权限」。
|
||||
* 增删改仍走带权限的 add/edit/enable/disable。
|
||||
* 必须显式大分页:Jeecg 分页拦截器可能把无 Page 的 list() 收成前 10 条,后台会看起来像没显示全。
|
||||
*/
|
||||
@ApiOperation("全量列表(按分类排序,供分类页一次加载)")
|
||||
@RequiresPermissions("inquiry:reply:list")
|
||||
@ApiOperation("全量列表(按分类排序,供分类页一次加载;登录可读)")
|
||||
@GetMapping("/listAll")
|
||||
public Result<List<InquiryBotReply>> listAll() {
|
||||
QueryWrapper<InquiryBotReply> qw = new QueryWrapper<>();
|
||||
@@ -66,6 +67,25 @@ public class InquiryBotReplyController extends JeecgController<InquiryBotReply,
|
||||
return Result.OK(botReplyService.page(page, qw).getRecords());
|
||||
}
|
||||
|
||||
/**
|
||||
* 读系统品牌文案(后台名称 / 机器人显示名)。
|
||||
* 只要已登录即可,不要求 inquiry:reply:list。
|
||||
* 中港等业务角色进看板会拉标题;若仍走 listAll 会弹「没有权限」。
|
||||
* 仅白名单 reply_code,禁止借此枚举全部回复语。
|
||||
*/
|
||||
@ApiOperation("系统品牌文案(登录可读,白名单码)")
|
||||
@GetMapping("/systemText")
|
||||
public Result<InquiryBotReply> systemText(@RequestParam(name = "replyCode") String replyCode) {
|
||||
String code = StringUtils.trimToEmpty(replyCode);
|
||||
if (!"system.admin_site_title".equals(code) && !"system.bot_display_name".equals(code)) {
|
||||
return Result.error("不支持的系统文案码");
|
||||
}
|
||||
InquiryBotReply row = botReplyService.getOne(new QueryWrapper<InquiryBotReply>()
|
||||
.eq("reply_code", code)
|
||||
.last("LIMIT 1"), false);
|
||||
return Result.OK(row);
|
||||
}
|
||||
|
||||
@AutoLog(value = "回复语-新增")
|
||||
@RequiresPermissions("inquiry:reply:add")
|
||||
@PostMapping("/add")
|
||||
|
||||
+5
@@ -15,6 +15,9 @@ import java.util.Date;
|
||||
|
||||
/**
|
||||
* 工单附件元数据,对应 inq_attachment。只存对象存储键,不存文件字节。
|
||||
* <p>
|
||||
* createBy:上传人(企微 userid / 登录名 / agent)。详情展示前会解析成姓名。
|
||||
* 为何:管理后台「附件记录·上传人」读此字段;实体缺字段则 API 永远不回上传人。
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@@ -33,6 +36,8 @@ public class InquiryAttachment implements Serializable {
|
||||
private String objectKey;
|
||||
private String contentType;
|
||||
private Long fileSize;
|
||||
/** 上传人:企微 userid、后台登录名或 agent;详情接口会解析成可读姓名。 */
|
||||
private String createBy;
|
||||
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
|
||||
+156
-20
@@ -53,6 +53,8 @@ public class InquiryDashboardServiceImpl implements IInquiryDashboardService {
|
||||
|
||||
private static final ZoneId ZONE = ZoneId.of("Asia/Shanghai");
|
||||
private static final DateTimeFormatter DAY_FMT = DateTimeFormatter.ofPattern("MM-dd");
|
||||
/** 人员排名:销售 / 航线 / 产品 各自保留的条数(避免全局截断挤掉航线产品)。 */
|
||||
private static final int RANK_PER_ROLE = 20;
|
||||
private static final int COST_ROUTE_LIMIT = 16;
|
||||
/** 协同「分发」:海运/陆运建群、空运群激活。 */
|
||||
private static final List<String> COLLAB_DISPATCH_ACTIONS = Arrays.asList(
|
||||
@@ -168,7 +170,9 @@ public class InquiryDashboardServiceImpl implements IInquiryDashboardService {
|
||||
}
|
||||
}
|
||||
|
||||
List<Map<String, Object>> rankings = buildRankings(tickets, staffByWecom, staffByName);
|
||||
// 产品/航线账号:人员排名只留智能体团队(航线+产品),不返回销售/用户
|
||||
boolean agentTeamOnly = isProductOrRouteViewer(staffByWecom);
|
||||
List<Map<String, Object>> rankings = buildRankings(tickets, staffByWecom, staffByName, agentTeamOnly);
|
||||
List<Map<String, Object>> costRoutes = buildCostRoutes(tickets, dayIndex, trendDates);
|
||||
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
@@ -178,11 +182,112 @@ public class InquiryDashboardServiceImpl implements IInquiryDashboardService {
|
||||
result.put("metrics", metricCards);
|
||||
result.put("trend", trend);
|
||||
result.put("rankings", rankings);
|
||||
// 前端据此隐藏「销售」筛选项;超管/销售账号为 all
|
||||
result.put("rankingScope", agentTeamOnly ? "agent_team" : "all");
|
||||
result.put("costDates", trendDates);
|
||||
result.put("costRoutes", costRoutes);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前登录人是否为产品/航线岗位(只能看智能体团队排名)。
|
||||
* <p>
|
||||
* 判定顺序:超管放行 → 员工表 wecom 岗位 air/sea/land → Jeecg 角色名含航线/产品/空运/海运/陆运。
|
||||
* 纯「销售」角色不算。无登录上下文时不收窄(避免内部调用被误锁)。
|
||||
*/
|
||||
private boolean isProductOrRouteViewer(Map<String, InquiryStaffRole> staffByWecom) {
|
||||
org.jeecg.common.system.vo.LoginUser login = currentLoginUser();
|
||||
if (login == null) {
|
||||
return false;
|
||||
}
|
||||
if (isDashboardAdministrator(login)) {
|
||||
return false;
|
||||
}
|
||||
String wecom = InquiryDataScopeSupport.wecomId(login);
|
||||
if (StringUtils.isNotBlank(wecom) && staffByWecom != null) {
|
||||
InquiryStaffRole staff = staffByWecom.get(wecom.trim());
|
||||
if (staff != null) {
|
||||
String code = StringUtils.trimToEmpty(staff.getRoleCode());
|
||||
if ("air".equals(code) || "sea".equals(code) || "land".equals(code)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
String username = StringUtils.trimToEmpty(login.getUsername());
|
||||
for (String roleName : loadSysRoleNames(username)) {
|
||||
if (roleNameLooksProductOrRoute(roleName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 角色名点明航线/产品(含空运/海运/陆运)。纯「销售」不含这些字,不算。 */
|
||||
static boolean roleNameLooksProductOrRoute(String roleName) {
|
||||
String name = StringUtils.trimToEmpty(roleName);
|
||||
if (name.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return name.contains("航线") || name.contains("产品")
|
||||
|| name.contains("空运") || name.contains("海运") || name.contains("陆运");
|
||||
}
|
||||
|
||||
private static org.jeecg.common.system.vo.LoginUser currentLoginUser() {
|
||||
try {
|
||||
Object p = org.apache.shiro.SecurityUtils.getSubject().getPrincipal();
|
||||
if (p instanceof org.jeecg.common.system.vo.LoginUser) {
|
||||
return (org.jeecg.common.system.vo.LoginUser) p;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// 无登录态
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isDashboardAdministrator(org.jeecg.common.system.vo.LoginUser login) {
|
||||
if (login == null) {
|
||||
return false;
|
||||
}
|
||||
if ("admin".equalsIgnoreCase(StringUtils.trimToEmpty(login.getUsername()))) {
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
return org.apache.shiro.SecurityUtils.getSubject().hasRole("admin")
|
||||
|| org.apache.shiro.SecurityUtils.getSubject().hasRole("管理员");
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 读账号绑定的 Jeecg 角色名;失败当无角色,不抛到看板。 */
|
||||
private static List<String> loadSysRoleNames(String username) {
|
||||
List<String> names = new ArrayList<>();
|
||||
if (StringUtils.isBlank(username)) {
|
||||
return names;
|
||||
}
|
||||
String sql = "SELECT r.role_name FROM sys_role r "
|
||||
+ "INNER JOIN sys_user_role ur ON ur.role_id = r.id "
|
||||
+ "INNER JOIN sys_user u ON u.id = ur.user_id WHERE u.username = ?";
|
||||
try {
|
||||
javax.sql.DataSource ds = org.jeecg.common.util.SpringContextUtils.getBean(javax.sql.DataSource.class);
|
||||
try (java.sql.Connection conn = ds.getConnection();
|
||||
java.sql.PreparedStatement ps = conn.prepareStatement(sql)) {
|
||||
ps.setString(1, username);
|
||||
try (java.sql.ResultSet rs = ps.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
String n = rs.getString("role_name");
|
||||
if (StringUtils.isNotBlank(n)) {
|
||||
names.add(n.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// 角色读失败不收窄
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析看板统计起止日。
|
||||
* 优先用显式 dateFrom/dateTo(与工单列表同源);否则按 range=today|7d|30d 相对「今天」。
|
||||
@@ -213,10 +318,13 @@ public class InquiryDashboardServiceImpl implements IInquiryDashboardService {
|
||||
/**
|
||||
* 人员排名:与工单列表 enrichDisplayFields 同口径。
|
||||
* 聚合键优先 salesWecomId(同人合并),展示名走 resolveSalesDisplayName。
|
||||
*
|
||||
* @param agentTeamOnly true 时只保留员工岗位为航线/产品的人(智能体团队),去掉销售与未绑定用户
|
||||
*/
|
||||
private static List<Map<String, Object>> buildRankings(List<InquiryTicket> tickets,
|
||||
Map<String, InquiryStaffRole> staffByWecom,
|
||||
Map<String, InquiryStaffRole> staffByName) {
|
||||
Map<String, InquiryStaffRole> staffByName,
|
||||
boolean agentTeamOnly) {
|
||||
class Acc {
|
||||
String name;
|
||||
InquiryStaffRole staff;
|
||||
@@ -260,24 +368,52 @@ public class InquiryDashboardServiceImpl implements IInquiryDashboardService {
|
||||
acc.name = acc.staff.getName().trim();
|
||||
}
|
||||
}
|
||||
return byKey.values().stream()
|
||||
.sorted(Comparator.comparingLong((Acc a) -> a.volume).reversed()
|
||||
.thenComparing(a -> a.name, Comparator.nullsLast(String::compareTo)))
|
||||
.limit(20)
|
||||
.map(a -> {
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("name", a.name);
|
||||
if (a.staff != null) {
|
||||
row.put("role", mapRankRole(a.staff.getRoleCode()));
|
||||
row.put("dept", StringUtils.defaultIfBlank(a.staff.getDepartName(), "-"));
|
||||
} else {
|
||||
row.put("role", "sales");
|
||||
row.put("dept", "-");
|
||||
}
|
||||
row.put("volumeNum", a.volume);
|
||||
return row;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
// 按岗位分组各取 TopN,禁止全局 Top20 被销售占满导致「航线无人 / 产品只剩 1 人」
|
||||
Map<String, List<Acc>> grouped = new LinkedHashMap<>();
|
||||
grouped.put("sales", new ArrayList<>());
|
||||
grouped.put("route", new ArrayList<>());
|
||||
grouped.put("product", new ArrayList<>());
|
||||
for (Acc a : byKey.values()) {
|
||||
if (agentTeamOnly) {
|
||||
// 智能体团队:员工表航线(air)/产品(sea|land);销售与未绑定用户一律排除
|
||||
if (a.staff == null) {
|
||||
continue;
|
||||
}
|
||||
String rr = mapRankRole(a.staff.getRoleCode());
|
||||
if (!"route".equals(rr) && !"product".equals(rr)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
String role = a.staff != null ? mapRankRole(a.staff.getRoleCode()) : "sales";
|
||||
List<Acc> bucket = grouped.get(role);
|
||||
if (bucket == null) {
|
||||
bucket = grouped.get("sales");
|
||||
}
|
||||
bucket.add(a);
|
||||
}
|
||||
Comparator<Acc> byVolume = Comparator.comparingLong((Acc a) -> a.volume).reversed()
|
||||
.thenComparing(a -> a.name, Comparator.nullsLast(String::compareTo));
|
||||
List<Map<String, Object>> rows = new ArrayList<>();
|
||||
for (String roleKey : Arrays.asList("sales", "route", "product")) {
|
||||
List<Acc> bucket = grouped.get(roleKey);
|
||||
if (bucket == null || bucket.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
bucket.stream().sorted(byVolume).limit(RANK_PER_ROLE).forEach(a -> {
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("name", a.name);
|
||||
if (a.staff != null) {
|
||||
row.put("role", mapRankRole(a.staff.getRoleCode()));
|
||||
row.put("dept", StringUtils.defaultIfBlank(a.staff.getDepartName(), "-"));
|
||||
} else {
|
||||
row.put("role", "sales");
|
||||
row.put("dept", "-");
|
||||
}
|
||||
row.put("volumeNum", a.volume);
|
||||
rows.add(row);
|
||||
});
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+41
-1
@@ -954,6 +954,8 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
|
||||
row.setObjectKey(objectKey);
|
||||
row.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
row.setFileSize(fileSize);
|
||||
// 出单附件是智能体生成的,上传人固定 agent(详情展示成机器人显示名,禁止冒充发起人)。
|
||||
row.setCreateBy("agent");
|
||||
row.setCreateTime(new Date());
|
||||
attachmentMapper.insert(row);
|
||||
return true;
|
||||
@@ -1374,9 +1376,10 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
|
||||
JSONArray routeRows = QuoteTemplateExcelSupport.parseFeeRows(q.get("route_rows"));
|
||||
JSONArray rawLand = QuoteTemplateExcelSupport.parseFeeRows(q.get("landSegments"));
|
||||
JSONArray landSegs = routeRows.isEmpty() ? rawLand : routeRows;
|
||||
// 已落库的 route_rows 是规范化扁平行,分档公斤价还在原始 landSegments 上。
|
||||
// 已落库的 route_rows 是规范化扁平行,分档公斤价 / 多车型价表还在原始 landSegments 上。
|
||||
if (!routeRows.isEmpty()) {
|
||||
QuoteTemplateExcelSupport.copyMissingWeightPrices(landSegs, rawLand);
|
||||
QuoteTemplateExcelSupport.copyMissingVehicleRates(landSegs, rawLand);
|
||||
}
|
||||
// 销售已选线路透传:跨境整车国内/境外段按 legs 写完整起讫(多备选混在 route_rows 时不能靠同序列过滤)
|
||||
Object selectedLand = q.get("selected_land_route");
|
||||
@@ -1389,6 +1392,8 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
|
||||
if (!landSegs.isEmpty()) {
|
||||
// 产品文字价/分档壳偶发无 vehicleType:用询价「车型/数量」补上,否则整车矩阵车型列空、金额只进合计。
|
||||
enrichLandRouteVehicleFromInquiry(landSegs, out, src);
|
||||
// 产品多车型挂段时 OD 偶发空:用询价 facts 顶层 origin/destination 回填(境外段目的地不能空)。
|
||||
fillBlankLandRouteOdFromInquiry(landSegs, out, src);
|
||||
out.put("landSegments", landSegs);
|
||||
out.put("route_rows", landSegs);
|
||||
// 首段时效/燃油/税率抬到顶层,供侧栏与标签回填(WO006 燃油列不能空着有数却写不上)
|
||||
@@ -1522,6 +1527,41 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 线路行缺起运/目的时,用询价顶层 OD / 提货收货地址回填。
|
||||
* <p>
|
||||
* 为何:产品多车型价挂段时智能体偶发只带上提货地址、目的港键名对不上,境外段目的地空着。
|
||||
* 副作用:只改传入行;不写库。
|
||||
*/
|
||||
private static void fillBlankLandRouteOdFromInquiry(JSONArray landSegs, JSONObject out,
|
||||
Map<String, Object> src) {
|
||||
if (landSegs == null || landSegs.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String origin = firstNonBlankLocal(
|
||||
out == null ? null : out.getString("origin"),
|
||||
first(src, "起运港", "起运地", "始发站", "始发地", "提货地址", "origin", "pol"));
|
||||
String dest = firstNonBlankLocal(
|
||||
out == null ? null : out.getString("destination"),
|
||||
out == null ? null : out.getString("pod"),
|
||||
first(src, "目的港", "目的地", "收货地址", "送货地址", "destination", "pod"));
|
||||
if (StringUtils.isBlank(origin) && StringUtils.isBlank(dest)) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < landSegs.size(); i++) {
|
||||
JSONObject seg = landSegs.getJSONObject(i);
|
||||
if (seg == null) {
|
||||
continue;
|
||||
}
|
||||
if (StringUtils.isBlank(seg.getString("origin")) && StringUtils.isNotBlank(origin)) {
|
||||
seg.put("origin", origin);
|
||||
}
|
||||
if (StringUtils.isBlank(seg.getString("destination")) && StringUtils.isNotBlank(dest)) {
|
||||
seg.put("destination", dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 线路行缺 vehicleType 时,从询价「车型/数量」拆出车型补上。
|
||||
* <p>
|
||||
|
||||
+131
-4
@@ -12,6 +12,7 @@ import org.jeecg.modules.inquiry.dto.AgentTicketCreateRequest;
|
||||
import org.jeecg.modules.inquiry.dto.TicketAbnormalRequest;
|
||||
import org.jeecg.modules.inquiry.dto.TicketTransitionRequest;
|
||||
import org.jeecg.modules.inquiry.entity.InquiryAttachment;
|
||||
import org.jeecg.modules.inquiry.entity.InquiryBotReply;
|
||||
import org.jeecg.modules.inquiry.entity.InquiryExceptionCase;
|
||||
import org.jeecg.modules.inquiry.entity.InquiryQuote;
|
||||
import org.jeecg.modules.inquiry.entity.InquiryStaffRole;
|
||||
@@ -46,10 +47,6 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -89,6 +86,13 @@ public class InquiryWorkOrderServiceImpl extends ServiceImpl<InquiryTicketMapper
|
||||
private InquiryExceptionNotifyMapper exceptionNotifyMapper;
|
||||
@Autowired
|
||||
private AgentSystemExceptionRetryClient exceptionRetryClient;
|
||||
@Autowired
|
||||
private org.jeecg.modules.inquiry.mapper.InquiryBotReplyMapper botReplyMapper;
|
||||
|
||||
/** 智能体出单/系统附件落库标记;详情展示时解析成机器人显示名。 */
|
||||
private static final String ATTACH_UPLOADER_AGENT = "agent";
|
||||
/** 与智能体 bot_name 默认一致;库里 system.bot_display_name 优先。 */
|
||||
private static final String DEFAULT_BOT_DISPLAY_NAME = "智价通AIQ";
|
||||
|
||||
@Override
|
||||
public IPage<InquiryTicket> pageView(Page<InquiryTicket> page, Map<String, String> filters) {
|
||||
@@ -228,6 +232,7 @@ public class InquiryWorkOrderServiceImpl extends ServiceImpl<InquiryTicketMapper
|
||||
List<InquiryAttachment> attachments = attachmentMapper.selectList(new LambdaQueryWrapper<InquiryAttachment>()
|
||||
.eq(InquiryAttachment::getWorkOrderNo, workOrderNo)
|
||||
.orderByAsc(InquiryAttachment::getCreateTime));
|
||||
enrichAttachmentUploaders(ticket, attachments);
|
||||
List<InquiryTicketStatusLog> timeline = statusLogMapper.selectList(new LambdaQueryWrapper<InquiryTicketStatusLog>()
|
||||
.eq(InquiryTicketStatusLog::getWorkOrderNo, workOrderNo)
|
||||
.orderByAsc(InquiryTicketStatusLog::getCreateTime));
|
||||
@@ -244,6 +249,126 @@ public class InquiryWorkOrderServiceImpl extends ServiceImpl<InquiryTicketMapper
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析附件上传人写入值。
|
||||
* <p>
|
||||
* 真人上传:用 body 的 senderId/createBy。
|
||||
* 智能体出单/系统落库:无真人 sender 时固定写 {@link #ATTACH_UPLOADER_AGENT},
|
||||
* <b>禁止</b>用发起人冒充上传人(产品:智价通AIQ 上传须显示智价通AIQ)。
|
||||
* 副作用:无;只读 body。
|
||||
*/
|
||||
private static String resolveAttachmentUploader(Map<String, Object> body, InquiryTicket ticket) {
|
||||
String fromBody = text(body, "createBy", "create_by", "senderId", "sender_id", "operatorUserId", "operator");
|
||||
if (StringUtils.isNotBlank(fromBody)) {
|
||||
String raw = fromBody.trim();
|
||||
// 显式 agent/system 保留;其它视为真人企微 id / 登录名。
|
||||
return raw;
|
||||
}
|
||||
return ATTACH_UPLOADER_AGENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情附件上传人展示:真人企微 id→姓名;agent/system/空→机器人显示名(智价通AIQ)。
|
||||
* 兼容错误回填:create_by 被写成发起人、但文件名是报价单时,仍按机器人显示。
|
||||
* 副作用:只改内存中的 createBy,不写库。
|
||||
*/
|
||||
private void enrichAttachmentUploaders(InquiryTicket ticket, List<InquiryAttachment> attachments) {
|
||||
if (attachments == null || attachments.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String botName = loadBotDisplayName();
|
||||
String salesWecom = ticket == null ? "" : StringUtils.trimToEmpty(ticket.getSalesWecomId());
|
||||
String salesName = ticket == null ? "" : StringUtils.trimToEmpty(ticket.getSalesName());
|
||||
Set<String> wecomIds = new HashSet<>();
|
||||
for (InquiryAttachment row : attachments) {
|
||||
if (row == null || StringUtils.isBlank(row.getCreateBy())) {
|
||||
continue;
|
||||
}
|
||||
String raw = row.getCreateBy().trim();
|
||||
if (isAgentUploaderMark(raw)) {
|
||||
continue;
|
||||
}
|
||||
wecomIds.add(raw);
|
||||
}
|
||||
Map<String, String> nameByWecom = Collections.emptyMap();
|
||||
if (!wecomIds.isEmpty()) {
|
||||
List<InquiryStaffRole> staffRows = staffRoleMapper.selectList(new LambdaQueryWrapper<InquiryStaffRole>()
|
||||
.in(InquiryStaffRole::getWecomId, new ArrayList<>(wecomIds))
|
||||
.eq(InquiryStaffRole::getStatus, "active"));
|
||||
nameByWecom = new HashMap<>();
|
||||
if (staffRows != null) {
|
||||
for (InquiryStaffRole staff : staffRows) {
|
||||
if (staff == null || StringUtils.isBlank(staff.getWecomId()) || StringUtils.isBlank(staff.getName())) {
|
||||
continue;
|
||||
}
|
||||
nameByWecom.put(staff.getWecomId().trim(), staff.getName().trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (InquiryAttachment row : attachments) {
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
String raw = StringUtils.trimToEmpty(row.getCreateBy());
|
||||
String fileName = StringUtils.trimToEmpty(row.getFileName());
|
||||
boolean quoteSheet = looksLikeBotQuoteSheet(fileName);
|
||||
boolean mistookAsSales = StringUtils.isNotBlank(raw)
|
||||
&& (raw.equalsIgnoreCase(salesWecom) || raw.equals(salesName))
|
||||
&& quoteSheet;
|
||||
if (raw.isEmpty() || isAgentUploaderMark(raw) || mistookAsSales) {
|
||||
row.setCreateBy(botName);
|
||||
continue;
|
||||
}
|
||||
String named = nameByWecom.get(raw);
|
||||
if (StringUtils.isNotBlank(named)) {
|
||||
row.setCreateBy(named);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** agent/system 标记:智能体或系统落库,展示时换成机器人显示名。 */
|
||||
private static boolean isAgentUploaderMark(String raw) {
|
||||
return ATTACH_UPLOADER_AGENT.equalsIgnoreCase(raw) || "system".equalsIgnoreCase(raw);
|
||||
}
|
||||
|
||||
/** 文件名像智能体出的报价单(历史错误回填发起人时用来纠偏展示)。 */
|
||||
private static boolean looksLikeBotQuoteSheet(String fileName) {
|
||||
if (StringUtils.isBlank(fileName)) {
|
||||
return false;
|
||||
}
|
||||
String n = fileName.trim();
|
||||
return n.contains("报价单") || n.contains("报价表");
|
||||
}
|
||||
|
||||
/**
|
||||
* 读后台配置的机器人显示名(inq_bot_reply.system.bot_display_name)。
|
||||
* 空/停用回退 {@link #DEFAULT_BOT_DISPLAY_NAME}。
|
||||
*/
|
||||
private String loadBotDisplayName() {
|
||||
try {
|
||||
if (botReplyMapper == null) {
|
||||
return DEFAULT_BOT_DISPLAY_NAME;
|
||||
}
|
||||
InquiryBotReply row = botReplyMapper.selectOne(new LambdaQueryWrapper<InquiryBotReply>()
|
||||
.eq(InquiryBotReply::getReplyCode, "system.bot_display_name")
|
||||
.last("LIMIT 1"));
|
||||
if (row == null) {
|
||||
return DEFAULT_BOT_DISPLAY_NAME;
|
||||
}
|
||||
if (row.getEnabled() != null && row.getEnabled() == 0) {
|
||||
return DEFAULT_BOT_DISPLAY_NAME;
|
||||
}
|
||||
String text = StringUtils.trimToEmpty(row.getReplyText());
|
||||
if (text.isEmpty()) {
|
||||
return DEFAULT_BOT_DISPLAY_NAME;
|
||||
}
|
||||
String first = text.split("\\R", 2)[0].trim();
|
||||
return StringUtils.defaultIfBlank(first, DEFAULT_BOT_DISPLAY_NAME);
|
||||
} catch (Exception e) {
|
||||
return DEFAULT_BOT_DISPLAY_NAME;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表/详情响应补齐:发起人姓名、询价需求摘要、成本价/销售价/利润点、报价信息行。
|
||||
* 副作用:只改内存中的 ticket 展示字段,不 updateById。
|
||||
@@ -1441,6 +1566,7 @@ public class InquiryWorkOrderServiceImpl extends ServiceImpl<InquiryTicketMapper
|
||||
row.setFileName(text(body, "fileName", "file_name"));
|
||||
row.setObjectKey(text(body, "objectKey", "object_key"));
|
||||
row.setContentType(text(body, "contentType", "content_type"));
|
||||
row.setCreateBy(resolveAttachmentUploader(body, ticket));
|
||||
row.setCreateTime(new Date());
|
||||
attachmentMapper.insert(row);
|
||||
out.put("ok", true);
|
||||
@@ -1508,6 +1634,7 @@ public class InquiryWorkOrderServiceImpl extends ServiceImpl<InquiryTicketMapper
|
||||
row.setObjectKey(objectKey);
|
||||
row.setContentType(contentType);
|
||||
row.setFileSize((long) bytes.length);
|
||||
row.setCreateBy(resolveAttachmentUploader(body, ticket));
|
||||
row.setCreateTime(new Date());
|
||||
attachmentMapper.insert(row);
|
||||
out.put("ok", true);
|
||||
|
||||
+99
-7
@@ -16,7 +16,8 @@ import java.util.Set;
|
||||
* <p>
|
||||
* 只看自己:非超管且 {@code dashboardSelfOnly=true} →
|
||||
* {@code salesWecomId = 工号} 或 {@code createBy = 登录名}。
|
||||
* 业务范围:角色是陆运中港,或数据权限只有陆运线路时,看板和工单只留陆运。
|
||||
* 业务范围:先按空运/海运/陆运收窄;若 dataPerms 点了陆运线路叶子(如中港),
|
||||
* 再按 facts「线路类别」收窄,禁止中港权限看到东南亚等其它陆运单。
|
||||
* 看板与工单列表共用,避免只收一边。没有登录上下文时不限制(智能体内部调用)。
|
||||
* 线程:只读登录态,无全局锁。
|
||||
*/
|
||||
@@ -69,8 +70,9 @@ public final class InquiryDataScopeSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* 按角色把工单收成空运 / 海运 / 陆运。不限制时原样返回。
|
||||
* 按角色把工单收成空运 / 海运 / 陆运,并在有陆运线路叶子时再按「线路类别」收窄。
|
||||
* 有业务线码时只认码;业务线空着才用中文标签兜底,避免海运单被写成「陆运」后漏出来。
|
||||
* 中港数据权限只勾「中港/中亚/中欧」时,不得再放出东南亚等其它陆运单。
|
||||
*/
|
||||
public static void applyRoleBizLines(LambdaQueryWrapper<InquiryTicket> qw) {
|
||||
if (qw == null) {
|
||||
@@ -117,25 +119,115 @@ public final class InquiryDataScopeSupport {
|
||||
}
|
||||
sql.append(" OR biz_type_label LIKE '%多段%' OR biz_type_label LIKE '%联运%'");
|
||||
sql.append(")))");
|
||||
|
||||
Set<String> landRoutes = InquiryQuoteTemplateBizScope.currentAllowedLandRoutesOrNull();
|
||||
String landRouteSql = buildLandRouteFilterSql(landRoutes);
|
||||
if (StringUtils.isNotBlank(landRouteSql)) {
|
||||
sql.insert(0, '(');
|
||||
sql.append(") AND (").append(landRouteSql).append(')');
|
||||
}
|
||||
qw.apply(sql.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 陆运线路叶子 SQL:只白名单目录码,禁止拼接用户原文。
|
||||
* 非陆运业务(AIR/SEA)放行;陆运/多段/空业务线必须 facts 线路类别命中。
|
||||
*
|
||||
* @return null 表示不追加线路条件
|
||||
*/
|
||||
static String buildLandRouteFilterSql(Set<String> landRoutes) {
|
||||
if (landRoutes == null) {
|
||||
return null;
|
||||
}
|
||||
List<String> safe = new ArrayList<String>();
|
||||
for (String raw : landRoutes) {
|
||||
String leaf = InquiryRoleBizScope.normalizeLandRouteKey(raw);
|
||||
if (leaf != null && !"陆运全线".equals(leaf)) {
|
||||
safe.add(leaf);
|
||||
}
|
||||
}
|
||||
StringBuilder landPred = new StringBuilder();
|
||||
if (safe.isEmpty()) {
|
||||
landPred.append("1 = 0");
|
||||
} else {
|
||||
landPred.append('(');
|
||||
for (int i = 0; i < safe.size(); i++) {
|
||||
if (i > 0) {
|
||||
landPred.append(" OR ");
|
||||
}
|
||||
String esc = safe.get(i).replace("'", "''");
|
||||
// MySQL 8:优先 JSON 抽取;再兼容无空格 / 有空格的手工 JSON
|
||||
landPred.append("(JSON_UNQUOTE(JSON_EXTRACT(facts_json, '$.\"线路类别\"')) = '")
|
||||
.append(esc).append("'")
|
||||
.append(" OR facts_json LIKE '%\"线路类别\":\"").append(esc).append("\"%'")
|
||||
.append(" OR facts_json LIKE '%\"线路类别\": \"").append(esc).append("\"%')");
|
||||
}
|
||||
landPred.append(')');
|
||||
}
|
||||
// 空运/海运业务线不受陆运线路叶子限制;陆运与多段必须命中线路。
|
||||
return "(UPPER(IFNULL(business_line,'')) IN ('AIR','SEA')"
|
||||
+ " OR (" + landPred + "))";
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情、流转、异常处理:列表里不该出现的工单,按编号打开也不给看。
|
||||
* 业务线通过后,若账号有陆运线路叶子,还要核对 facts 里的线路类别。
|
||||
*/
|
||||
public static void assertTicketBizAllowed(InquiryTicket ticket) {
|
||||
if (ticket == null) {
|
||||
return;
|
||||
}
|
||||
Set<String> allowed = InquiryQuoteTemplateBizScope.currentAllowedOrNull();
|
||||
if (InquiryRoleBizScope.ticketInScope(ticket.getBusinessLine(), ticket.getBizTypeLabel(), allowed)) {
|
||||
if (!InquiryRoleBizScope.ticketInScope(ticket.getBusinessLine(), ticket.getBizTypeLabel(), allowed)) {
|
||||
String scope = InquiryRoleBizScope.joinLabels(allowed);
|
||||
if (StringUtils.isBlank(scope)) {
|
||||
scope = "已授权业务";
|
||||
}
|
||||
throw new JeecgBootException("当前账号只能查看" + scope + "的询价工单和数据看板");
|
||||
}
|
||||
Set<String> landRoutes = InquiryQuoteTemplateBizScope.currentAllowedLandRoutesOrNull();
|
||||
if (landRoutes == null) {
|
||||
return;
|
||||
}
|
||||
String scope = InquiryRoleBizScope.joinLabels(allowed);
|
||||
if (StringUtils.isBlank(scope)) {
|
||||
scope = "已授权业务";
|
||||
String biz = InquiryRoleBizScope.classifyTicketBiz(ticket.getBusinessLine(), ticket.getBizTypeLabel());
|
||||
String line = StringUtils.trimToEmpty(ticket.getBusinessLine()).toUpperCase();
|
||||
String label = StringUtils.trimToEmpty(ticket.getBizTypeLabel());
|
||||
boolean landish = InquiryRoleBizScope.LAND.equals(biz)
|
||||
|| "MULTI".equals(line)
|
||||
|| label.contains("多段")
|
||||
|| label.contains("联运");
|
||||
// 纯空运/海运单:线路叶子不拦。
|
||||
if (!landish && (InquiryRoleBizScope.AIR.equals(biz) || InquiryRoleBizScope.SEA.equals(biz))) {
|
||||
return;
|
||||
}
|
||||
throw new JeecgBootException("当前账号只能查看" + scope + "的询价工单和数据看板");
|
||||
// 陆运权限账号打开陆运/多段单:必须线路类别命中;无线路类别宁可不看。
|
||||
if (landish || StringUtils.isBlank(biz)) {
|
||||
String route = extractRouteCategory(ticket.getFactsJson());
|
||||
if (InquiryRoleBizScope.ticketRouteInScope(route, landRoutes)) {
|
||||
return;
|
||||
}
|
||||
throw new JeecgBootException("当前账号只能查看已授权陆运线路的询价工单和数据看板");
|
||||
}
|
||||
}
|
||||
|
||||
/** 从 facts JSON 取线路类别;解析失败当空。 */
|
||||
static String extractRouteCategory(String factsJson) {
|
||||
if (StringUtils.isBlank(factsJson)) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
com.fasterxml.jackson.databind.JsonNode root =
|
||||
new com.fasterxml.jackson.databind.ObjectMapper().readTree(factsJson);
|
||||
for (String key : new String[]{"线路类别", "routeCategory", "landRouteCategory"}) {
|
||||
com.fasterxml.jackson.databind.JsonNode n = root.get(key);
|
||||
if (n != null && !n.isNull() && StringUtils.isNotBlank(n.asText())) {
|
||||
return n.asText().trim();
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// 解析失败当无线路
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+17
-1
@@ -40,7 +40,23 @@ public final class InquiryQuoteTemplateBizScope {
|
||||
}
|
||||
String username = StringUtils.trimToEmpty(login.getUsername());
|
||||
List<InquiryRoleBizScope.RoleSnap> roles = loadRoles(username);
|
||||
return InquiryRoleBizScope.resolve(isAdministrator(login, roles), roles);
|
||||
boolean admin = isAdministrator(login, roles);
|
||||
return InquiryRoleBizScope.resolve(admin, roles);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前登录人允许的陆运线路叶子。
|
||||
*
|
||||
* @return {@code null} 表示不限制陆运线路;非空则工单/看板只留这些线路类别
|
||||
*/
|
||||
public static Set<String> currentAllowedLandRoutesOrNull() {
|
||||
LoginUser login = currentLoginUser();
|
||||
if (login == null) {
|
||||
return null;
|
||||
}
|
||||
String username = StringUtils.trimToEmpty(login.getUsername());
|
||||
List<InquiryRoleBizScope.RoleSnap> roles = loadRoles(username);
|
||||
return InquiryRoleBizScope.resolveLandRoutes(isAdministrator(login, roles), roles);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+108
-2
@@ -13,11 +13,13 @@ import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 把角色名称和角色数据权限,收成报价模板能用的业务线:空运 / 海运 / 陆运。
|
||||
* 把角色名称和角色数据权限,收成报价模板能用的业务线:空运 / 海运 / 陆运;
|
||||
* 以及工单/看板用的陆运线路叶子(中港 / 东南亚等)。
|
||||
* <p>
|
||||
* 数据权限写在 {@code sys_role.description} 的 {@code [dataPerms:…]},目录与后台
|
||||
* {@code dataPermCatalog.ts} 一致。报价模板只有业务线,没有「中港 / 国内整车」这一层,
|
||||
* 所以陆运线路(含中港)都归到「陆运」。
|
||||
* 所以陆运线路(含中港)在模板侧都归到「陆运」;工单与看板必须再按线路叶子收窄,
|
||||
* 否则「中港数据权限」会看到全部陆运工单。
|
||||
* <p>
|
||||
* 纯函数,不读库、不碰登录态。超管是否放行由调用方传入。
|
||||
*/
|
||||
@@ -121,6 +123,110 @@ public final class InquiryRoleBizScope {
|
||||
return allowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前账号允许的陆运线路叶子。
|
||||
* <p>
|
||||
* {@code null}:不限制陆运线路(超管、勾了「陆运全线」、或只有业务线「陆运」未点名具体线路)。
|
||||
* 非空:工单/看板只留这些线路类别(与 facts 里「线路类别」整词相同)。
|
||||
* 多个角色取并集;任一角色含「陆运全线」则整段不限制。
|
||||
* <p>
|
||||
* 与 {@link #resolve} 独立:角色名已点明「陆运」时 resolve 会跳过 dataPerms 的业务线并集,
|
||||
* 但线路叶子仍必须读 dataPerms,否则中港权限会漏成陆运全线。
|
||||
*/
|
||||
public static Set<String> resolveLandRoutes(boolean administrator, List<RoleSnap> roles) {
|
||||
if (administrator) {
|
||||
return null;
|
||||
}
|
||||
LinkedHashSet<String> routes = new LinkedHashSet<String>();
|
||||
boolean anyLandLeaf = false;
|
||||
boolean landAll = false;
|
||||
if (roles != null) {
|
||||
for (RoleSnap role : roles) {
|
||||
if (role == null) {
|
||||
continue;
|
||||
}
|
||||
for (String key : landRouteKeysOf(role)) {
|
||||
anyLandLeaf = true;
|
||||
if ("陆运全线".equals(key)) {
|
||||
landAll = true;
|
||||
} else {
|
||||
routes.add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (landAll) {
|
||||
return null;
|
||||
}
|
||||
if (!anyLandLeaf) {
|
||||
return null;
|
||||
}
|
||||
return routes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 一个角色描述 + 名称里点到的陆运线路叶子(含「陆运全线」)。
|
||||
* 只认目录稳定码;禁止把「中港/中亚/中欧」按斜杠切开。
|
||||
*/
|
||||
public static List<String> landRouteKeysOf(RoleSnap role) {
|
||||
LinkedHashSet<String> out = new LinkedHashSet<String>();
|
||||
if (role == null) {
|
||||
return new ArrayList<String>(out);
|
||||
}
|
||||
for (String key : parseDataPermKeys(role.getDescription())) {
|
||||
String leaf = normalizeLandRouteKey(key);
|
||||
if (leaf != null) {
|
||||
out.add(leaf);
|
||||
}
|
||||
}
|
||||
String name = StringUtils.trimToEmpty(role.getRoleName());
|
||||
if (!name.isEmpty()) {
|
||||
for (String known : LAND_ROUTE_KEYS) {
|
||||
if (name.contains(known)) {
|
||||
out.add(known);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ArrayList<String>(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据权限码 → 陆运线路叶子;非陆运叶子返回 null。
|
||||
*/
|
||||
public static String normalizeLandRouteKey(String raw) {
|
||||
String key = StringUtils.trimToEmpty(raw);
|
||||
if (key.isEmpty() || key.contains("系统异常")) {
|
||||
return null;
|
||||
}
|
||||
if (LAND_ROUTE_KEYS.contains(key)) {
|
||||
return key;
|
||||
}
|
||||
String leaf = key;
|
||||
int dot = Math.max(key.lastIndexOf('·'), key.lastIndexOf('•'));
|
||||
if (dot >= 0 && dot + 1 < key.length()) {
|
||||
leaf = key.substring(dot + 1).trim();
|
||||
}
|
||||
if (LAND_ROUTE_KEYS.contains(leaf)) {
|
||||
return leaf;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 工单线路类别是否在陆运线路权限内。{@code allowedLandRoutes == null} 不限制。
|
||||
* 空集合表示点了陆运叶子但解析结果为空,陆运单一律不可见。
|
||||
*/
|
||||
public static boolean ticketRouteInScope(String routeCategory, Set<String> allowedLandRoutes) {
|
||||
if (allowedLandRoutes == null) {
|
||||
return true;
|
||||
}
|
||||
String route = StringUtils.trimToEmpty(routeCategory);
|
||||
if (route.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return allowedLandRoutes.contains(route);
|
||||
}
|
||||
|
||||
/**
|
||||
* 界面下拉用的稳定顺序:空运、海运、陆运。{@code allowed == null} 时三项都返回。
|
||||
*/
|
||||
|
||||
+404
-6
@@ -806,7 +806,9 @@ public final class QuoteTemplateExcelSupport {
|
||||
// 禁止 Excel 重写 drawing(3983) 的 other_excel 包(WO013)。
|
||||
// 再盖回 WO011 sheet1 骨架,单选才稳定可见(WO030 vs POI 瘦 sheet)。
|
||||
syncSeaTransportClassFormControls(targetXlsx, facts, seaDrawParts);
|
||||
boolean scaffoldOk = restoreSeaSheet1Scaffold(targetXlsx, seaDrawParts);
|
||||
// 无费用明细时:骨架合并须清币别/单位/数量等样例,不能只清金额(WO202611050004)
|
||||
boolean wipeSeaFeeSamples = !hasSeaQuoteCharges(facts);
|
||||
boolean scaffoldOk = restoreSeaSheet1Scaffold(targetXlsx, seaDrawParts, null, wipeSeaFeeSamples);
|
||||
String seaCls = canonicalizeSeaTransportClass(facts == null ? null : firstNonBlank(
|
||||
facts.getString("运输分类"), facts.getString("transport_class"), facts.getString("sea_class")));
|
||||
if ("其他".equals(seaCls)) {
|
||||
@@ -1574,11 +1576,19 @@ public final class QuoteTemplateExcelSupport {
|
||||
* @return true=骨架盖回且合并成功;false=跳过/失败(调用方应写 B3 明文兜底)
|
||||
*/
|
||||
static boolean restoreSeaSheet1Scaffold(Path targetXlsx, Map<String, byte[]> preservedParts) {
|
||||
return restoreSeaSheet1Scaffold(targetXlsx, preservedParts, null);
|
||||
return restoreSeaSheet1Scaffold(targetXlsx, preservedParts, null, false);
|
||||
}
|
||||
|
||||
static boolean restoreSeaSheet1Scaffold(Path targetXlsx, Map<String, byte[]> preservedParts,
|
||||
String seaTransportClass) {
|
||||
return restoreSeaSheet1Scaffold(targetXlsx, preservedParts, seaTransportClass, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param wipeSeaFeeSamples true=无 TMS/人工费用时,清骨架费用行样例(含币别/单位/数量)
|
||||
*/
|
||||
static boolean restoreSeaSheet1Scaffold(Path targetXlsx, Map<String, byte[]> preservedParts,
|
||||
String seaTransportClass, boolean wipeSeaFeeSamples) {
|
||||
if (targetXlsx == null || !Files.isRegularFile(targetXlsx) || preservedParts == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -1611,7 +1621,7 @@ public final class QuoteTemplateExcelSupport {
|
||||
}
|
||||
Map<String, String> poiValues = parseSheetCellTexts(poiSheet, poiSst);
|
||||
byte[] scaffoldSst = loadWo011SeaSharedStrings();
|
||||
SeaSheetMerge merged = mergeValuesOntoSeaScaffold(scaffold, scaffoldSst, poiValues);
|
||||
SeaSheetMerge merged = mergeValuesOntoSeaScaffold(scaffold, scaffoldSst, poiValues, wipeSeaFeeSamples);
|
||||
int rowCount = countSheetRows(merged.sheetXml);
|
||||
// WO035 证据:错误正则把自闭合 <c .../> 的 / 吃进属性,一次匹配跨越多行,
|
||||
// sheet 从 17KB 缩成 7KB、只剩 2 行。合并结果过瘦则放弃,保留 POI 原 sheet。
|
||||
@@ -1787,13 +1797,22 @@ public final class QuoteTemplateExcelSupport {
|
||||
* sheetData 会从约 20KB 瘦到 17KB,WPS 界面可能不画顶部单选。
|
||||
* 策略:保留 WO011 原 SST 词序与索引,只追加新词;只改 POI 非空且与骨架不同的格;
|
||||
* B3:J3 单选锚点区一律不动。
|
||||
* <p>
|
||||
* 例外(WO202611050001):POI 已清空的费用样例格(40HQ/操作费/金额等)必须写成空格,
|
||||
* 禁止「空值不覆盖骨架」把 WO011 样例价盖回无 TMS 报价单。
|
||||
*/
|
||||
static SeaSheetMerge mergeValuesOntoSeaScaffold(byte[] scaffoldSheet, Map<String, String> poiValues) {
|
||||
return mergeValuesOntoSeaScaffold(scaffoldSheet, loadWo011SeaSharedStrings(), poiValues);
|
||||
return mergeValuesOntoSeaScaffold(scaffoldSheet, loadWo011SeaSharedStrings(), poiValues, false);
|
||||
}
|
||||
|
||||
static SeaSheetMerge mergeValuesOntoSeaScaffold(byte[] scaffoldSheet, byte[] scaffoldSst,
|
||||
Map<String, String> poiValues) {
|
||||
return mergeValuesOntoSeaScaffold(scaffoldSheet, scaffoldSst, poiValues, false);
|
||||
}
|
||||
|
||||
static SeaSheetMerge mergeValuesOntoSeaScaffold(byte[] scaffoldSheet, byte[] scaffoldSst,
|
||||
Map<String, String> poiValues,
|
||||
boolean wipeSeaFeeSamples) {
|
||||
String sheet = new String(scaffoldSheet, StandardCharsets.UTF_8);
|
||||
List<String> newSst = new ArrayList<>(parseSharedStrings(scaffoldSst));
|
||||
Map<String, Integer> sstIndex = new LinkedHashMap<>();
|
||||
@@ -1816,6 +1835,7 @@ public final class QuoteTemplateExcelSupport {
|
||||
|
||||
Map<String, String> scaffoldVals = parseSheetCellTexts(scaffoldSheet, scaffoldSst);
|
||||
|
||||
|
||||
java.util.regex.Matcher m = SEA_CELL_PATTERN.matcher(sheet);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (m.find()) {
|
||||
@@ -1834,19 +1854,70 @@ public final class QuoteTemplateExcelSupport {
|
||||
m.appendReplacement(sb, java.util.regex.Matcher.quoteReplacement(original));
|
||||
continue;
|
||||
}
|
||||
String scaffoldVal = scaffoldVals.get(ref);
|
||||
// 无价:清骨架费用行样例(金额/费目/币别/单位/数量/有效期)。
|
||||
// 但 POI 已写入且与骨架不同的业务值必须保留(WO202611050005:询价箱型 20GP*2
|
||||
// 不能因骨架曾是 40HQ*1 被一并清掉)。
|
||||
if (wipeSeaFeeSamples && isSeaScaffoldFeeSampleValue(scaffoldVal)) {
|
||||
String poiKeep = null;
|
||||
if (poiValues != null && poiValues.containsKey(ref)) {
|
||||
poiKeep = poiValues.get(ref);
|
||||
}
|
||||
if (poiKeep != null && !poiKeep.isEmpty()) {
|
||||
String keepNorm = poiKeep.replace("&", "&").replace("<", "<").replace(">", ">");
|
||||
String scNorm = scaffoldVal.replace("&", "&").replace("<", "<").replace(">", ">");
|
||||
if (!keepNorm.equals(scNorm)) {
|
||||
java.util.regex.Matcher smKeep = java.util.regex.Pattern.compile("\\bs=\"(\\d+)\"").matcher(attrs);
|
||||
String styleKeep = smKeep.find() ? (" s=\"" + smKeep.group(1) + "\"") : "";
|
||||
String keepRepl;
|
||||
if (keepNorm.matches("^-?\\d+(\\.\\d+)?$")) {
|
||||
keepRepl = "<c r=\"" + ref + "\"" + styleKeep + " t=\"n\"><v>" + keepNorm + "</v></c>";
|
||||
} else {
|
||||
int idxKeep = idxOf.apply(keepNorm);
|
||||
keepRepl = "<c r=\"" + ref + "\"" + styleKeep + " t=\"s\"><v>" + idxKeep + "</v></c>";
|
||||
}
|
||||
m.appendReplacement(sb, java.util.regex.Matcher.quoteReplacement(keepRepl));
|
||||
patched[0]++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
java.util.regex.Matcher smWipe = java.util.regex.Pattern.compile("\\bs=\"(\\d+)\"").matcher(attrs);
|
||||
String styleWipe = smWipe.find() ? (" s=\"" + smWipe.group(1) + "\"") : "";
|
||||
String emptyWipe = "<c r=\"" + ref + "\"" + styleWipe + "/>";
|
||||
m.appendReplacement(sb, java.util.regex.Matcher.quoteReplacement(emptyWipe));
|
||||
patched[0]++;
|
||||
continue;
|
||||
}
|
||||
if (poiValues == null || !poiValues.containsKey(ref)) {
|
||||
// POI 未带出该格:骨架费用样例仍要清,否则无价出单会冒出 40HQ 样例价
|
||||
if (isSeaScaffoldFeeSampleValue(scaffoldVal)) {
|
||||
java.util.regex.Matcher smMiss = java.util.regex.Pattern.compile("\\bs=\"(\\d+)\"").matcher(attrs);
|
||||
String styleMiss = smMiss.find() ? (" s=\"" + smMiss.group(1) + "\"") : "";
|
||||
String emptyMiss = "<c r=\"" + ref + "\"" + styleMiss + "/>";
|
||||
m.appendReplacement(sb, java.util.regex.Matcher.quoteReplacement(emptyMiss));
|
||||
patched[0]++;
|
||||
continue;
|
||||
}
|
||||
m.appendReplacement(sb, java.util.regex.Matcher.quoteReplacement(original));
|
||||
continue;
|
||||
}
|
||||
String val = poiValues.get(ref);
|
||||
if (val == null || val.isEmpty()) {
|
||||
// 费用样例:POI 已清空则必须写空,禁止盖回 WO011 样例(WO202611050001)
|
||||
if (isSeaScaffoldFeeSampleValue(scaffoldVal)) {
|
||||
java.util.regex.Matcher smEmpty = java.util.regex.Pattern.compile("\\bs=\"(\\d+)\"").matcher(attrs);
|
||||
String styleEmpty = smEmpty.find() ? (" s=\"" + smEmpty.group(1) + "\"") : "";
|
||||
String emptyRepl = "<c r=\"" + ref + "\"" + styleEmpty + "/>";
|
||||
m.appendReplacement(sb, java.util.regex.Matcher.quoteReplacement(emptyRepl));
|
||||
patched[0]++;
|
||||
continue;
|
||||
}
|
||||
// 空值不覆盖骨架(标签/样式格)
|
||||
m.appendReplacement(sb, java.util.regex.Matcher.quoteReplacement(original));
|
||||
continue;
|
||||
}
|
||||
// 去掉 POI/骨架可能带来的双重转义
|
||||
String norm = val.replace("&", "&").replace("<", "<").replace(">", ">");
|
||||
String scaffoldVal = scaffoldVals.get(ref);
|
||||
String scaffoldNorm = scaffoldVal == null ? ""
|
||||
: scaffoldVal.replace("&", "&").replace("<", "<").replace(">", ">");
|
||||
if (norm.equals(scaffoldNorm)) {
|
||||
@@ -1878,6 +1949,73 @@ public final class QuoteTemplateExcelSupport {
|
||||
return new SeaSheetMerge(sb.toString(), sstXml.toString(), newSst.size(), patched[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有可写入报价单的海运费用(明细或总价)。无则出单须清骨架费用行样例。
|
||||
*/
|
||||
static boolean hasSeaQuoteCharges(JSONObject facts) {
|
||||
if (facts == null || facts.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
JSONArray charged = filterFeeRowsWithCharge(parseFeeRows(facts.get("fee_rows")));
|
||||
if (charged != null && !charged.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
String total = StringUtils.trimToEmpty(firstNonBlank(
|
||||
facts.getString("total_amount"), facts.getString("total"), facts.getString("salePrice")));
|
||||
return StringUtils.isNotBlank(total) && !"-".equals(total);
|
||||
}
|
||||
|
||||
/**
|
||||
* WO011 骨架里的费用行样例:箱型/费目/金额/币别/单位/数量;标题表头不算。
|
||||
* 用于无 TMS 报价时清掉样例,避免空值合并或 POI 残留把样例盖回出单表。
|
||||
*/
|
||||
static boolean isSeaScaffoldFeeSampleValue(String raw) {
|
||||
if (raw == null) {
|
||||
return false;
|
||||
}
|
||||
String s = raw.replace("&", "&").replace("<", "<").replace(">", ">").trim();
|
||||
if (s.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
// 费用表头「箱型(动态填充箱型)」/「箱型(20GP)」不是样例行,禁止当费用样例清掉
|
||||
if (s.contains("动态填充") || s.contains("动态箱型")
|
||||
|| (s.contains("箱型") && (s.contains("(") || s.contains("(") || s.contains("\n")))) {
|
||||
return false;
|
||||
}
|
||||
// 箱型样例:40HQ、20GP*1(数据行);勿把表头已填 20GP 当样例——上面已排除含「箱型」括号形
|
||||
if (s.matches("(?i)^\\d{2}(GP|HQ|OT|RF|TK|FR)(\\*\\d+)?$") || s.contains("40HQ") || s.contains("20GP")) {
|
||||
return true;
|
||||
}
|
||||
// 币别样例
|
||||
if ("CNY".equalsIgnoreCase(s) || "USD".equalsIgnoreCase(s) || "EUR".equalsIgnoreCase(s)
|
||||
|| "HKD".equalsIgnoreCase(s) || "RMB".equalsIgnoreCase(s)) {
|
||||
return true;
|
||||
}
|
||||
// 单位样例(费用行「柜/票/卡」;勿清表头「单位/Unit」)
|
||||
if ("柜".equals(s) || "票".equals(s) || "卡".equals(s) || "箱".equals(s)) {
|
||||
return true;
|
||||
}
|
||||
// 报价有效期等日期样例(询价日期若 POI 已写且不同则合并逻辑会保留)
|
||||
if (s.matches("^\\d{4}-\\d{2}-\\d{2}$")) {
|
||||
return true;
|
||||
}
|
||||
// 费用行数量/金额数字样例(含 1、0、1220.0)
|
||||
if (s.matches("^-?\\d+(\\.\\d+)?$")) {
|
||||
return true;
|
||||
}
|
||||
// 精确费目名(勿用「海运费用」标题;只认「海运费」等样例行)
|
||||
if ("操作费".equals(s) || "箱单费".equals(s) || "VGM申报费".equals(s) || "文件费".equals(s)
|
||||
|| "电放费".equals(s) || "更改费".equals(s) || "报关费".equals(s) || "海运费".equals(s)
|
||||
|| "进仓操作费".equals(s) || s.startsWith("封条费")
|
||||
|| s.startsWith("进口集装箱检验费") || s.startsWith("电子数据交换费")
|
||||
|| s.startsWith("进口设备监控费") || s.contains("CLTY") || s.contains("EDI")
|
||||
|| s.contains("EMCI")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static String xmlEscape(String s) {
|
||||
if (s == null) {
|
||||
return "";
|
||||
@@ -2308,7 +2446,11 @@ public final class QuoteTemplateExcelSupport {
|
||||
int stopRow = findStopRow(sheet, region.getJSONArray("stopAtText"), startRow);
|
||||
// 无明细:保留项目列骨架(空运段/起运港/目的港/其他),清掉样例费目名。
|
||||
// 对齐到港「有费用的才显示行」——到门模板样例(操作费/目的港派送费…)无报价时不得残留。
|
||||
// 但仍须替换表头「箱型(动态填充箱型)」→「箱型(20GP)」:无价不等于不要询价箱型(WO202611050009)。
|
||||
if (rows.isEmpty()) {
|
||||
if (Boolean.TRUE.equals(region.getBoolean("dynamicContainerHeader"))) {
|
||||
applyDynamicContainerHeader(sheet, region, columns, facts, yellow);
|
||||
}
|
||||
clearFeeRowsAfter(sheet, startRow, stopRow, columns, yellow, sheet.getSheetName(), true);
|
||||
continue;
|
||||
}
|
||||
@@ -3339,7 +3481,8 @@ public final class QuoteTemplateExcelSupport {
|
||||
yellow, sheet.getSheetName());
|
||||
}
|
||||
JSONObject vehicleRates = columns.getJSONObject("vehicleRates");
|
||||
if (vehicleRates != null) {
|
||||
int wroteRates = 0;
|
||||
if (vehicleRates != null && !vehicleRates.isEmpty()) {
|
||||
for (String vk : vehicleRates.keySet()) {
|
||||
String col = vehicleRates.getString(vk);
|
||||
if (StringUtils.isBlank(col)) {
|
||||
@@ -3348,14 +3491,99 @@ public final class QuoteTemplateExcelSupport {
|
||||
String price = resolveRouteVehicleRate(rowObj, facts, vk, vehicleRates.size(), kind);
|
||||
if (StringUtils.isNotBlank(price) && !"-".equals(price)) {
|
||||
writeFeeCol(sheet, ri, col, price, yellow, sheet.getSheetName());
|
||||
wroteRates++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 映射漏了 vehicleRates 时:按表头车型列扫写(与侧栏币种扫头同一思路)。
|
||||
// WO202610280104:境外段有起讫/CNY、车型运价全空,常见于仅映射了 origin/destination。
|
||||
wroteRates = writeLandMatrixVehicleRatesByHeaderScan(
|
||||
sheet, ri, region, rowObj, facts, yellow, kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 映射未给出 columns.vehicleRates 时,扫表头车型列再写运价。
|
||||
* <p>
|
||||
* 为何:千问 sheet_map 偶发只映射起始地/目的地/币种,漏掉整车矩阵车型列;
|
||||
* 侧栏币种已能扫头写入,车型列若不扫就会「有起讫无运价」。
|
||||
* 禁止:把同一售价灌进所有车型列(仍走 resolveRouteVehicleRate 匹配)。
|
||||
*
|
||||
* @return 实际写入的车型列数
|
||||
*/
|
||||
static int writeLandMatrixVehicleRatesByHeaderScan(Sheet sheet, int dataRow, JSONObject region,
|
||||
JSONObject rowObj, JSONObject facts,
|
||||
Set<String> yellow, String kind) {
|
||||
if (sheet == null || rowObj == null || region == null) {
|
||||
return 0;
|
||||
}
|
||||
int header0 = region.getIntValue("headerRow") - 1;
|
||||
if (header0 < 0) {
|
||||
header0 = dataRow - 1;
|
||||
}
|
||||
DataFormatter fmt = new DataFormatter();
|
||||
List<String> headers = new ArrayList<>();
|
||||
List<Integer> cols = new ArrayList<>();
|
||||
int from = Math.max(0, header0 - 1);
|
||||
int to = header0 + 1;
|
||||
for (int r = from; r <= to; r++) {
|
||||
Row row = sheet.getRow(r);
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
short last = row.getLastCellNum();
|
||||
for (int c = 0; c < last; c++) {
|
||||
String text = StringUtils.trimToEmpty(fmt.formatCellValue(row.getCell(c))).replaceAll("\\s+", "");
|
||||
if (!looksLikeLandMatrixVehicleHeader(text)) {
|
||||
continue;
|
||||
}
|
||||
if (cols.contains(c)) {
|
||||
continue;
|
||||
}
|
||||
headers.add(text);
|
||||
cols.add(c);
|
||||
}
|
||||
}
|
||||
if (headers.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
int wrote = 0;
|
||||
int headerCount = headers.size();
|
||||
for (int i = 0; i < headers.size(); i++) {
|
||||
String price = resolveRouteVehicleRate(rowObj, facts, headers.get(i), headerCount, kind);
|
||||
if (StringUtils.isBlank(price) || "-".equals(price)) {
|
||||
continue;
|
||||
}
|
||||
String col = CellReference.convertNumToColString(cols.get(i));
|
||||
writeFeeCol(sheet, dataRow, col, price, yellow, sheet.getSheetName());
|
||||
wrote++;
|
||||
}
|
||||
return wrote;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否陆运矩阵车型/柜型表头(3.5T、40HQ、13.75平板等),排除起始地/币种/时效。
|
||||
*/
|
||||
static boolean looksLikeLandMatrixVehicleHeader(String header) {
|
||||
if (StringUtils.isBlank(header)) {
|
||||
return false;
|
||||
}
|
||||
String t = header.trim();
|
||||
if (t.contains("起始") || t.contains("始发") || t.contains("目的") || t.contains("时效")
|
||||
|| t.contains("币种") || t.contains("币别") || t.contains("燃油") || t.contains("税率")
|
||||
|| t.contains("含税") || t.contains("备注") || "序号".equals(t)) {
|
||||
return false;
|
||||
}
|
||||
if (looksLikeVehicleTypeToken(t)) {
|
||||
return true;
|
||||
}
|
||||
String u = t.toUpperCase(Locale.ROOT);
|
||||
return t.contains("米/") || t.contains("尺") || u.matches(".*\\d+(\\.\\d+)?T.*")
|
||||
|| u.contains("HQ") || t.contains("平板") || t.contains("冷柜") || t.contains("厢车");
|
||||
}
|
||||
|
||||
/**
|
||||
* 运价表右侧时效、币种、燃油、税率、含税合计:按列头写到数据行。
|
||||
* 燃油/税率/含税合计只写行上或 TMS 已有的数,不编造。
|
||||
@@ -3883,6 +4111,12 @@ public final class QuoteTemplateExcelSupport {
|
||||
out.put("amount", sale);
|
||||
}
|
||||
}
|
||||
// 产品多车型价表:overseas_full / 分段切片后必须带上,否则境外段只剩起讫、车型列全空。
|
||||
JSONObject rates = vehicleRatesOf(row);
|
||||
if (rates != null && !rates.isEmpty()) {
|
||||
out.put("vehicleRates", rates);
|
||||
out.put("vehicle_rates", rates);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -4209,6 +4443,11 @@ public final class QuoteTemplateExcelSupport {
|
||||
rowObj == null ? null : rowObj.getString("land_freight"),
|
||||
facts == null ? null : facts.getString("land_freight"));
|
||||
}
|
||||
// 1.5) 产品多车型价表:一行挂多个车型价,按表头键对列(5T/8T 同价拆键后分别命中)
|
||||
String fromMap = matchVehicleRateFromMap(rowObj, key, sectionKind);
|
||||
if (StringUtils.isNotBlank(fromMap) && !"-".equals(fromMap)) {
|
||||
return fromMap;
|
||||
}
|
||||
// 2) 车型列:仅当 vehicleType 对得上才写售价(含跨境国内/国外标注换算)
|
||||
String vehicleType = firstNonBlank(rowObj == null ? null : rowObj.getString("vehicleType"),
|
||||
rowObj == null ? null : rowObj.getString("vehicle_type"));
|
||||
@@ -4227,6 +4466,67 @@ public final class QuoteTemplateExcelSupport {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品文字多车型价:landSegments.vehicleRates(或 vehicle_rates)按表头车型匹配金额。
|
||||
* <p>
|
||||
* 为何:群报「5T/8T:13000 10T:14000」会拆成多键同价;不能只用单行 vehicleType+salePrice,
|
||||
* 否则只能填一列。对不上的列空着,禁止把第一档价灌进所有车型列。
|
||||
*/
|
||||
static String matchVehicleRateFromMap(JSONObject rowObj, String headerKey, String sectionKind) {
|
||||
JSONObject rates = vehicleRatesOf(rowObj);
|
||||
if (rates == null || rates.isEmpty() || StringUtils.isBlank(headerKey)) {
|
||||
return "";
|
||||
}
|
||||
for (String vk : rates.keySet()) {
|
||||
if (StringUtils.isBlank(vk)) {
|
||||
continue;
|
||||
}
|
||||
if (!vehicleTypeMatchesSection(vk, headerKey, sectionKind)) {
|
||||
continue;
|
||||
}
|
||||
String amount = StringUtils.trimToEmpty(rates.getString(vk));
|
||||
if (StringUtils.isNotBlank(amount) && !"-".equals(amount)) {
|
||||
return formatTierPrice(amount);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取行上多车型价表;兼容 camel / snake。值为对象 {5T:13000,...}。
|
||||
*/
|
||||
static JSONObject vehicleRatesOf(JSONObject row) {
|
||||
if (row == null) {
|
||||
return null;
|
||||
}
|
||||
Object raw = row.get("vehicleRates");
|
||||
if (raw == null) {
|
||||
raw = row.get("vehicle_rates");
|
||||
}
|
||||
if (raw instanceof JSONObject) {
|
||||
return (JSONObject) raw;
|
||||
}
|
||||
if (raw instanceof String) {
|
||||
String text = StringUtils.trimToEmpty((String) raw);
|
||||
if (text.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Object parsed = JSON.parse(text);
|
||||
if (parsed instanceof JSONObject) {
|
||||
return (JSONObject) parsed;
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (raw instanceof Map) {
|
||||
Object converted = JSON.toJSON(raw);
|
||||
return converted instanceof JSONObject ? (JSONObject) converted : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 车型列是否对得上当前段表头。
|
||||
* <p>
|
||||
@@ -4673,6 +4973,64 @@ public final class QuoteTemplateExcelSupport {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 规范化 route_rows 会丢掉 vehicleRates。出单前从原始 landSegments 补回。
|
||||
*/
|
||||
public static void copyMissingVehicleRates(JSONArray rows, JSONArray rawLand) {
|
||||
if (rows == null || rawLand == null || rawLand.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < rows.size(); i++) {
|
||||
JSONObject row = rows.getJSONObject(i);
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
JSONObject existing = vehicleRatesOf(row);
|
||||
if (existing != null && !existing.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
JSONObject src = i < rawLand.size() ? rawLand.getJSONObject(i) : null;
|
||||
if (vehicleRatesOf(src) == null) {
|
||||
src = findLandSegmentByVehicleRates(rawLand, row);
|
||||
}
|
||||
JSONObject rates = vehicleRatesOf(src);
|
||||
if (rates != null && !rates.isEmpty()) {
|
||||
row.put("vehicleRates", rates);
|
||||
row.put("vehicle_rates", rates);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static JSONObject findLandSegmentByVehicleRates(JSONArray rawLand, JSONObject row) {
|
||||
if (rawLand == null) {
|
||||
return null;
|
||||
}
|
||||
String origin = StringUtils.trimToEmpty(firstNonBlank(
|
||||
row == null ? null : row.getString("origin"),
|
||||
row == null ? null : row.getString("originCode")));
|
||||
String dest = StringUtils.trimToEmpty(firstNonBlank(
|
||||
row == null ? null : row.getString("destination"),
|
||||
row == null ? null : row.getString("destinationCode")));
|
||||
for (int i = 0; i < rawLand.size(); i++) {
|
||||
JSONObject one = rawLand.getJSONObject(i);
|
||||
if (one == null || vehicleRatesOf(one) == null) {
|
||||
continue;
|
||||
}
|
||||
String o = StringUtils.trimToEmpty(firstNonBlank(one.getString("origin"), one.getString("originCode")));
|
||||
String d = StringUtils.trimToEmpty(firstNonBlank(one.getString("destination"), one.getString("destinationCode")));
|
||||
if (origin.equals(o) && dest.equals(d)) {
|
||||
return one;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < rawLand.size(); i++) {
|
||||
JSONObject one = rawLand.getJSONObject(i);
|
||||
if (vehicleRatesOf(one) != null) {
|
||||
return one;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static JSONObject findLandSegmentByOriginDest(JSONArray rawLand, JSONObject row) {
|
||||
if (rawLand == null || row == null) {
|
||||
return null;
|
||||
@@ -5250,12 +5608,16 @@ public final class QuoteTemplateExcelSupport {
|
||||
/**
|
||||
* 费用名,不是城市。写进「起始地/目的地」会把深圳盖成运输费。
|
||||
* 只拦常见运价费目,不拦「春疆货场」这类地名。
|
||||
* 车型码(5T/40HQ)也不是地名:产品多车型 fee_rows 误写进起始地列时要拦。
|
||||
*/
|
||||
static boolean looksLikeFeeNameNotPlace(String value) {
|
||||
if (StringUtils.isBlank(value)) {
|
||||
return false;
|
||||
}
|
||||
String t = value.trim().replaceAll("\\s+", "");
|
||||
if (looksLikeVehicleTypeToken(t)) {
|
||||
return true;
|
||||
}
|
||||
if ("运输费".equals(t) || "提货费".equals(t) || "送货费".equals(t) || "派送费".equals(t)
|
||||
|| "陆运费".equals(t) || "干线费".equals(t) || "空运费".equals(t) || "海运费".equals(t)
|
||||
|| "运费".equals(t) || "燃油附加费".equals(t) || "操作费".equals(t) || "文件费".equals(t)
|
||||
@@ -5267,6 +5629,33 @@ public final class QuoteTemplateExcelSupport {
|
||||
&& !t.contains("站") && !t.contains("仓");
|
||||
}
|
||||
|
||||
/**
|
||||
* 车型口语/表头码:5T、10T、40HQ、45HQ、3.5T、53尺 等。
|
||||
* 产品多车型价表键与矩阵列头同形;禁止当费目名找格、当城市写进起始地。
|
||||
*/
|
||||
static boolean looksLikeVehicleTypeToken(String value) {
|
||||
if (StringUtils.isBlank(value)) {
|
||||
return false;
|
||||
}
|
||||
String t = normalizeVehicleCompareToken(value);
|
||||
if (t.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (t.matches("^\\d+(\\.\\d+)?T$")) {
|
||||
return true;
|
||||
}
|
||||
if (t.matches("^\\d+(HQ|GP|RH)$")) {
|
||||
return true;
|
||||
}
|
||||
if (t.matches("^\\d+尺$")) {
|
||||
return true;
|
||||
}
|
||||
if (t.contains("平板") || t.contains("厢车") || t.contains("冷柜")) {
|
||||
return t.length() <= 12;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 这些列头不是币种:写 CNY 会把覆盖区域的城市、或燃油附加费率的空格盖掉。
|
||||
* 表头是「币种 / 币别」,或上面没有列头时,仍允许写币种。
|
||||
@@ -7530,6 +7919,10 @@ public final class QuoteTemplateExcelSupport {
|
||||
if (StringUtils.isBlank(name) || StringUtils.isBlank(amount) || "-".equals(amount)) {
|
||||
continue;
|
||||
}
|
||||
// 多车型价键(5T/40HQ)禁止当费目名:会命中矩阵列头,把车型写进国内段起始地。
|
||||
if (looksLikeVehicleTypeToken(name)) {
|
||||
continue;
|
||||
}
|
||||
Cell nameCell = findCellByFeeName(sheet, name, usedRows);
|
||||
if (nameCell == null) {
|
||||
nameCell = findCellByLandFeeAlias(sheet, name, usedRows);
|
||||
@@ -7954,6 +8347,11 @@ public final class QuoteTemplateExcelSupport {
|
||||
if (StringUtils.isBlank(text) || isFeeTableHeader(text) || isSectionTitle(sheet, cell)) {
|
||||
continue;
|
||||
}
|
||||
// 跨境整车矩阵列头「10T/40HQ」不是费用名称格
|
||||
if (looksLikeVehicleTypeToken(text) || isLandRouteMatrixHeaderCell(text)
|
||||
|| looksLikeVehicleDimensionText(text)) {
|
||||
continue;
|
||||
}
|
||||
if (feeNameMatches(text, want)) {
|
||||
return cell;
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
-- 附件表补上传人 create_by,供管理后台「附件记录·上传人」展示。
|
||||
-- 仅改 inquiry_robot。列已存在则跳过(手工执行前请 DESCRIBE inq_attachment)。
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
ALTER TABLE `inq_attachment`
|
||||
ADD COLUMN `create_by` varchar(64) NULL COMMENT '上传人(企微userid/登录名/agent)' AFTER `file_size`;
|
||||
|
||||
-- 历史空上传人:智能体/系统附件写 agent(详情展示机器人显示名)。
|
||||
-- 禁止回填发起人:产品要求智价通AIQ 上传显示智价通AIQ,见 migration_inq_attachment_uploader_bot_v2.sql。
|
||||
UPDATE `inq_attachment`
|
||||
SET `create_by` = 'agent'
|
||||
WHERE `create_by` IS NULL OR TRIM(`create_by`) = '';
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
-- 纠正附件上传人:智能体报价单勿写成发起人,统一写 agent(详情展示机器人显示名)。
|
||||
-- 仅改 inquiry_robot。可重复执行。
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
|
||||
UPDATE `inq_attachment` a
|
||||
INNER JOIN `inq_ticket` t ON t.work_order_no = a.work_order_no
|
||||
SET a.create_by = 'agent'
|
||||
WHERE (
|
||||
a.create_by = t.sales_name
|
||||
OR a.create_by = t.sales_wecom_id
|
||||
OR a.create_by IS NULL
|
||||
OR TRIM(a.create_by) = ''
|
||||
)
|
||||
AND (
|
||||
a.file_name LIKE '%报价单%'
|
||||
OR a.file_name LIKE '%报价表%'
|
||||
);
|
||||
+9
@@ -66,4 +66,13 @@ public class InquiryDashboardServiceImplTest {
|
||||
Assert.assertNull(InquiryDashboardServiceImpl.firstReplyAfter(
|
||||
java.util.Collections.singletonList(new java.util.Date(100L)), dispatch));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roleNameLooksProductOrRouteDetectsOpsRoles() {
|
||||
Assert.assertTrue(InquiryDashboardServiceImpl.roleNameLooksProductOrRoute("海运产品"));
|
||||
Assert.assertTrue(InquiryDashboardServiceImpl.roleNameLooksProductOrRoute("空运航线"));
|
||||
Assert.assertTrue(InquiryDashboardServiceImpl.roleNameLooksProductOrRoute("陆运中港"));
|
||||
Assert.assertFalse(InquiryDashboardServiceImpl.roleNameLooksProductOrRoute("销售"));
|
||||
Assert.assertFalse(InquiryDashboardServiceImpl.roleNameLooksProductOrRoute(""));
|
||||
}
|
||||
}
|
||||
|
||||
+28
@@ -104,4 +104,32 @@ public class InquiryRoleBizScopeTest {
|
||||
assertEquals(InquiryRoleBizScope.LAND, InquiryRoleBizScope.classifyTicketBiz("land", ""));
|
||||
assertEquals("", InquiryRoleBizScope.classifyTicketBiz("MULTI", "陆运"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zhonggangDataPermResolvesOnlyZhonggangLandRoute() {
|
||||
Set<String> routes = InquiryRoleBizScope.resolveLandRoutes(false, Collections.singletonList(
|
||||
new InquiryRoleBizScope.RoleSnap("陆运产品:中港/中亚/中欧数据权限", "land_hk",
|
||||
"[dataPerms:中港/中亚/中欧]")));
|
||||
assertEquals(Collections.singleton("中港/中亚/中欧"), routes);
|
||||
assertTrue(InquiryRoleBizScope.ticketRouteInScope("中港/中亚/中欧", routes));
|
||||
assertFalse(InquiryRoleBizScope.ticketRouteInScope("东南亚", routes));
|
||||
assertFalse(InquiryRoleBizScope.ticketRouteInScope("", routes));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void landAllDataPermDoesNotRestrictLandRoutes() {
|
||||
assertNull(InquiryRoleBizScope.resolveLandRoutes(false, Collections.singletonList(
|
||||
new InquiryRoleBizScope.RoleSnap("陆运全线", "land_all",
|
||||
"[dataPerms:陆运全线]")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void landRouteFilterSqlOnlyWhitelistZhonggang() {
|
||||
String sql = InquiryDataScopeSupport.buildLandRouteFilterSql(
|
||||
Collections.singleton("中港/中亚/中欧"));
|
||||
assertTrue(sql.contains("中港/中亚/中欧"));
|
||||
assertTrue(sql.contains("facts_json"));
|
||||
assertTrue(sql.contains("AIR"));
|
||||
assertFalse(sql.contains("东南亚"));
|
||||
}
|
||||
}
|
||||
|
||||
+178
@@ -2423,6 +2423,105 @@ public class QuoteTemplateFillTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* overseas_full 切片必须带上 vehicleRates;否则多车型价只剩起讫,境外段运价全空(WO104 形态)。
|
||||
*/
|
||||
@Test
|
||||
public void sliceCrossBorderOdKeepsVehicleRatesMap() {
|
||||
JSONObject row = new JSONObject(true);
|
||||
row.put("origin", "大窑");
|
||||
row.put("destination", "越南某工业园");
|
||||
row.put("currency", "CNY");
|
||||
JSONObject rates = new JSONObject(true);
|
||||
rates.put("5T", "8000");
|
||||
rates.put("10T", "12000");
|
||||
row.put("vehicleRates", rates);
|
||||
JSONObject sliced = QuoteTemplateExcelSupport.sliceCrossBorderOd(row, "overseas_full");
|
||||
assertEquals("大窑", sliced.getString("origin"));
|
||||
assertEquals("CNY", sliced.getString("currency"));
|
||||
assertEquals("8000", QuoteTemplateExcelSupport.resolveRouteVehicleRate(
|
||||
sliced, null, "5T", 2, "overseas"));
|
||||
assertEquals("12000", QuoteTemplateExcelSupport.resolveRouteVehicleRate(
|
||||
sliced, null, "10T", 2, "overseas"));
|
||||
assertEquals("", QuoteTemplateExcelSupport.resolveRouteVehicleRate(
|
||||
sliced, null, "3.5T", 2, "overseas"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 映射漏掉 columns.vehicleRates 时,仍须按表头车型列写入运价(有起讫无运价的修复)。
|
||||
*/
|
||||
@Test
|
||||
public void landCrossBorderFtlHeaderScanWritesRateWhenMappingOmitsVehicleRates() throws Exception {
|
||||
Path src = Files.createTempFile("quote-land-cb-scan-src", ".xlsx");
|
||||
Path out = Files.createTempFile("quote-land-cb-scan-out", ".xlsx");
|
||||
try (Workbook wb = new XSSFWorkbook()) {
|
||||
Sheet sheet = wb.createSheet("跨境整车");
|
||||
row(sheet, 5).createCell(0).setCellValue("一、国内段报价");
|
||||
org.apache.poi.ss.usermodel.Row head1 = row(sheet, 7);
|
||||
head1.createCell(1).setCellValue("起始地");
|
||||
head1.createCell(2).setCellValue("目的地");
|
||||
head1.createCell(3).setCellValue("3T");
|
||||
head1.createCell(4).setCellValue("5T");
|
||||
row(sheet, 24).createCell(0).setCellValue("二、境外段报价");
|
||||
org.apache.poi.ss.usermodel.Row head2 = row(sheet, 26);
|
||||
head2.createCell(1).setCellValue("起始地");
|
||||
head2.createCell(2).setCellValue("目的地");
|
||||
head2.createCell(3).setCellValue("1.25T");
|
||||
head2.createCell(4).setCellValue("2.5T");
|
||||
head2.createCell(5).setCellValue("3.5T");
|
||||
head2.createCell(6).setCellValue("5T");
|
||||
head2.createCell(16).setCellValue("币种");
|
||||
try (java.io.OutputStream os = Files.newOutputStream(src)) {
|
||||
wb.write(os);
|
||||
}
|
||||
}
|
||||
JSONObject mapping = new JSONObject(true);
|
||||
mapping.put("sheet", "跨境整车");
|
||||
JSONArray regions = new JSONArray();
|
||||
JSONObject inland = new JSONObject(true);
|
||||
inland.put("title", "国内段报价");
|
||||
inland.put("headerRow", 8);
|
||||
inland.put("dataStartRow", 9);
|
||||
JSONObject cols1 = new JSONObject(true);
|
||||
cols1.put("origin", "B");
|
||||
cols1.put("destination", "C");
|
||||
// 故意不放 vehicleRates,复现映射漏列
|
||||
inland.put("columns", cols1);
|
||||
regions.add(inland);
|
||||
JSONObject overseas = new JSONObject(true);
|
||||
overseas.put("title", "境外段报价");
|
||||
overseas.put("headerRow", 27);
|
||||
overseas.put("dataStartRow", 28);
|
||||
JSONObject cols2 = new JSONObject(true);
|
||||
cols2.put("origin", "B");
|
||||
cols2.put("destination", "C");
|
||||
overseas.put("columns", cols2);
|
||||
regions.add(overseas);
|
||||
mapping.put("routeRegions", regions);
|
||||
JSONObject facts = new JSONObject(true);
|
||||
facts.put("运输类型", "跨境整车");
|
||||
facts.put("currency", "CNY");
|
||||
facts.put("route_rows",
|
||||
"[{\"origin\":\"大窑\",\"destination\":\"越南某工业园\","
|
||||
+ "\"vehicleType\":\"3T\",\"amount\":\"4500\",\"currency\":\"CNY\"}]");
|
||||
System.setProperty("ytd.agent.debug.runId", "wo104-header-scan");
|
||||
QuoteTemplateExcelSupport.fillWorkbook(src, out, mapping, facts);
|
||||
try (Workbook filled = new XSSFWorkbook(Files.newInputStream(out))) {
|
||||
Sheet sheet = filled.getSheetAt(0);
|
||||
assertEquals("", read(sheet, 8, 1));
|
||||
assertEquals("大窑", read(sheet, 27, 1));
|
||||
assertEquals("越南某工业园", read(sheet, 27, 2));
|
||||
assertEquals("CNY", read(sheet, 27, 16));
|
||||
// 3T → 境外 3.5T 列(F,index 5)
|
||||
assertEquals("4500", normalizeMoney(read(sheet, 27, 5)));
|
||||
assertEquals("", read(sheet, 27, 3));
|
||||
assertEquals("", read(sheet, 27, 6));
|
||||
} finally {
|
||||
Files.deleteIfExists(src);
|
||||
Files.deleteIfExists(out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 境外段「起始地」若是白底,对齐表头时不能拿它去刷「币种」灰底。
|
||||
*/
|
||||
@@ -3411,6 +3510,85 @@ public class QuoteTemplateFillTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品多车型价表:一行 vehicleRates 按表头写入多列;禁止无匹配时把第一档灌进所有列。
|
||||
*/
|
||||
@Test
|
||||
public void landProductMultiVehicleRatesFillColumns() throws Exception {
|
||||
Path src = Files.createTempFile("quote-land-mv-src", ".xlsx");
|
||||
Path out = Files.createTempFile("quote-land-mv-out", ".xlsx");
|
||||
try (Workbook wb = new XSSFWorkbook()) {
|
||||
Sheet sheet = wb.createSheet("跨境整车");
|
||||
Row header = row(sheet, 8);
|
||||
header.createCell(1).setCellValue("起始地");
|
||||
header.createCell(2).setCellValue("目的地");
|
||||
header.createCell(3).setCellValue("5T");
|
||||
header.createCell(4).setCellValue("8T");
|
||||
header.createCell(5).setCellValue("10T");
|
||||
header.createCell(6).setCellValue("40HQ");
|
||||
header.createCell(7).setCellValue("45HQ");
|
||||
header.createCell(8).setCellValue("备注");
|
||||
row(sheet, 9);
|
||||
try (java.io.OutputStream os = Files.newOutputStream(src)) {
|
||||
wb.write(os);
|
||||
}
|
||||
}
|
||||
JSONObject mapping = new JSONObject(true);
|
||||
mapping.put("sheet", "跨境整车");
|
||||
JSONArray regions = new JSONArray();
|
||||
JSONObject region = new JSONObject(true);
|
||||
region.put("title", "项目一");
|
||||
region.put("headerRow", 9);
|
||||
region.put("dataStartRow", 10);
|
||||
JSONObject cols = new JSONObject(true);
|
||||
cols.put("origin", "B");
|
||||
cols.put("destination", "C");
|
||||
cols.put("remark", "I");
|
||||
JSONObject rates = new JSONObject(true);
|
||||
rates.put("5T", "D");
|
||||
rates.put("8T", "E");
|
||||
rates.put("10T", "F");
|
||||
rates.put("40HQ", "G");
|
||||
rates.put("45HQ", "H");
|
||||
cols.put("vehicleRates", rates);
|
||||
region.put("columns", cols);
|
||||
regions.add(region);
|
||||
mapping.put("routeRegions", regions);
|
||||
JSONObject facts = new JSONObject(true);
|
||||
facts.put("origin", "太原富士康");
|
||||
facts.put("destination", "越南北寧市南山工業區");
|
||||
facts.put("currency", "CNY");
|
||||
facts.put("route_rows",
|
||||
"[{\"origin\":\"太原富士康\",\"destination\":\"越南北寧市南山工業區\","
|
||||
+ "\"currency\":\"CNY\",\"remark\":\"含0点税\","
|
||||
+ "\"vehicleRates\":{\"5T\":\"13000\",\"8T\":\"13000\",\"10T\":\"14000\","
|
||||
+ "\"40HQ\":\"19500\",\"45HQ\":\"19500\"}}]");
|
||||
assertEquals("13000", QuoteTemplateExcelSupport.resolveRouteVehicleRate(
|
||||
JSON.parseObject("{\"vehicleRates\":{\"5T\":\"13000\",\"10T\":\"14000\"}}"),
|
||||
facts, "5T", 5, ""));
|
||||
assertEquals("14000", QuoteTemplateExcelSupport.resolveRouteVehicleRate(
|
||||
JSON.parseObject("{\"vehicleRates\":{\"5T\":\"13000\",\"10T\":\"14000\"}}"),
|
||||
facts, "10T", 5, ""));
|
||||
assertEquals("", QuoteTemplateExcelSupport.resolveRouteVehicleRate(
|
||||
JSON.parseObject("{\"vehicleRates\":{\"5T\":\"13000\"}}"),
|
||||
facts, "40HQ", 5, ""));
|
||||
QuoteTemplateExcelSupport.fillWorkbook(src, out, mapping, facts);
|
||||
try (Workbook filled = new XSSFWorkbook(Files.newInputStream(out))) {
|
||||
Sheet sheet = filled.getSheetAt(0);
|
||||
assertEquals("太原富士康", read(sheet, 9, 1));
|
||||
assertEquals("越南北寧市南山工業區", read(sheet, 9, 2));
|
||||
assertEquals("13000", normalizeMoney(read(sheet, 9, 3)));
|
||||
assertEquals("13000", normalizeMoney(read(sheet, 9, 4)));
|
||||
assertEquals("14000", normalizeMoney(read(sheet, 9, 5)));
|
||||
assertEquals("19500", normalizeMoney(read(sheet, 9, 6)));
|
||||
assertEquals("19500", normalizeMoney(read(sheet, 9, 7)));
|
||||
assertEquals("含0点税", read(sheet, 9, 8));
|
||||
} finally {
|
||||
Files.deleteIfExists(src);
|
||||
Files.deleteIfExists(out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 中港:TMS 别名经国内映射后再对等中港表头;跨境:吨位列与 3T 族境外 3.5T;禁止 5T 误命中 3.5T。
|
||||
*/
|
||||
|
||||
@@ -33,6 +33,8 @@ const routeFilterOpen = ref(false);
|
||||
const selectedRoutes = ref<string[]>([]);
|
||||
const rankingRole = ref<"all" | "sales" | "route" | "product">("all");
|
||||
const rankingDept = ref("");
|
||||
/** 主账 rankingScope:agent_team=产品/航线账号,只看智能体团队,隐藏「销售」筛选项 */
|
||||
const rankingScope = ref<"all" | "agent_team">("all");
|
||||
const chartReady = ref(false);
|
||||
const loading = ref(false);
|
||||
const chartTip = ref({
|
||||
@@ -110,6 +112,11 @@ async function loadMetrics() {
|
||||
dept: String(p.dept || "-"),
|
||||
volumeNum: Number(p.volumeNum || 0),
|
||||
}));
|
||||
rankingScope.value = data.rankingScope === "agent_team" ? "agent_team" : "all";
|
||||
// 产品/航线账号不允许停留在「销售」筛选项
|
||||
if (rankingScope.value === "agent_team" && rankingRole.value === "sales") {
|
||||
rankingRole.value = "all";
|
||||
}
|
||||
rankingDepts.value = Array.from(
|
||||
new Set(rankingPeople.value.map((p) => p.dept).filter((d) => d && d !== "-")),
|
||||
);
|
||||
@@ -605,7 +612,14 @@ onUnmounted(() => document.removeEventListener("click", onDocClick));
|
||||
</select>
|
||||
<div class="tabs-pill" role="tablist" aria-label="人员角色">
|
||||
<button type="button" :class="{ 'is-active': rankingRole === 'all' }" @click="rankingRole = 'all'">全部</button>
|
||||
<button type="button" :class="{ 'is-active': rankingRole === 'sales' }" @click="rankingRole = 'sales'">销售</button>
|
||||
<button
|
||||
v-if="rankingScope !== 'agent_team'"
|
||||
type="button"
|
||||
:class="{ 'is-active': rankingRole === 'sales' }"
|
||||
@click="rankingRole = 'sales'"
|
||||
>
|
||||
销售
|
||||
</button>
|
||||
<button type="button" :class="{ 'is-active': rankingRole === 'route' }" @click="rankingRole = 'route'">航线</button>
|
||||
<button type="button" :class="{ 'is-active': rankingRole === 'product' }" @click="rankingRole = 'product'">产品</button>
|
||||
</div>
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
* 管理后台品牌标题:默认文案 + 可配置项(落 inq_bot_reply)。
|
||||
* 登录前用默认;登录后 refresh 一次,侧栏/浏览器标签同步。
|
||||
* 配置页:系统配置 → 后台名称。
|
||||
* <p>
|
||||
* 读标题走专用 systemText 接口(登录即可),禁止再调 listAll:
|
||||
* 中港等无 inquiry:reply:list 的角色进看板会被拦截弹出「没有权限」。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import { getReplyListAll } from '/@/views/inquiry/botReply/botReply.api';
|
||||
import { defHttp } from '/@/utils/http/axios';
|
||||
|
||||
/** 产品默认名;库中无配置时全站用此文案 */
|
||||
export const DEFAULT_ADMIN_SITE_TITLE = '友通达智价通AIQ管理后台';
|
||||
@@ -17,22 +20,29 @@ export const adminSiteTitle = ref(DEFAULT_ADMIN_SITE_TITLE);
|
||||
|
||||
/**
|
||||
* 从主账拉取已保存的后台名称。
|
||||
* 失败或未配置时保持默认,不抛错打断布局。
|
||||
* 失败或未配置时保持默认;errorMessageMode=none,避免无回复语权限时弹「没有权限」。
|
||||
*/
|
||||
export async function refreshAdminSiteTitle(): Promise<string> {
|
||||
try {
|
||||
const res: any = await getReplyListAll();
|
||||
const list = Array.isArray(res)
|
||||
? res
|
||||
: Array.isArray(res?.result)
|
||||
? res.result
|
||||
: Array.isArray(res?.records)
|
||||
? res.records
|
||||
: [];
|
||||
const hit = list.find((r: any) => String(r.replyCode || '') === ADMIN_SITE_TITLE_REPLY_CODE);
|
||||
const enabled = !hit || hit.enabled === 1 || hit.enabled === true;
|
||||
const name = enabled ? String(hit?.replyText || '').trim() : '';
|
||||
adminSiteTitle.value = name || DEFAULT_ADMIN_SITE_TITLE;
|
||||
// defHttp 已解包 result:成功时就是 InquiryBotReply,未配置则为 null/空
|
||||
const res: any = await defHttp.get(
|
||||
{
|
||||
url: '/inquiry/botReply/systemText',
|
||||
params: { replyCode: ADMIN_SITE_TITLE_REPLY_CODE },
|
||||
},
|
||||
{ errorMessageMode: 'none' },
|
||||
);
|
||||
if (!res) {
|
||||
adminSiteTitle.value = DEFAULT_ADMIN_SITE_TITLE;
|
||||
return adminSiteTitle.value;
|
||||
}
|
||||
const text = String(res.replyText || '').trim();
|
||||
const enabledRaw = res.enabled;
|
||||
const enabled = enabledRaw === undefined || enabledRaw === null
|
||||
|| enabledRaw === 1
|
||||
|| enabledRaw === true
|
||||
|| enabledRaw === '1';
|
||||
adminSiteTitle.value = enabled && text ? text : DEFAULT_ADMIN_SITE_TITLE;
|
||||
} catch {
|
||||
adminSiteTitle.value = DEFAULT_ADMIN_SITE_TITLE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user