Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
739ba401aa | ||
|
|
185abbf45e |
@@ -53,6 +53,8 @@ from agent.routing.air_group_intent import (
|
||||
INTENT_PICK_OPTION,
|
||||
INTENT_QUOTE,
|
||||
INTENT_RELEASE,
|
||||
INTENT_RELEASE_ASK,
|
||||
cabin_confirm_answer,
|
||||
classify_air_group_text,
|
||||
)
|
||||
|
||||
@@ -167,6 +169,9 @@ def handle_air_group(
|
||||
return "duplicate_inbound"
|
||||
mark_air_text(chat_id=chat_id, sender_id=message.sender_id, text=text)
|
||||
wo = copy.extract_work_order_no(text)
|
||||
answered = _answer_pending_cabin_cancel(engine, message, text)
|
||||
if answered:
|
||||
return answered
|
||||
# 句中有多段工单号,或本群已经激活过多段单:跟这张单,不必每句再带工单号。
|
||||
followed = _follow_activated_multi(
|
||||
engine,
|
||||
@@ -200,7 +205,7 @@ def handle_air_group(
|
||||
intent,
|
||||
wo or "-",
|
||||
)
|
||||
if intent in {INTENT_LOCK, INTENT_RELEASE}:
|
||||
if intent in {INTENT_LOCK, INTENT_RELEASE, INTENT_RELEASE_ASK}:
|
||||
return _handle_cabin(
|
||||
engine,
|
||||
message,
|
||||
@@ -309,6 +314,92 @@ def _should_speak_activate(intent: str) -> bool:
|
||||
return intent in {INTENT_ACTIVATE, INTENT_OTHER}
|
||||
|
||||
|
||||
def _answer_pending_cabin_cancel(engine, message: InboundMessage, text: str) -> str:
|
||||
"""
|
||||
上一句已经问过是否取消舱位。
|
||||
|
||||
航线回是/需要/确认/取消舱位才执行。回否/不用/不需要就停。
|
||||
销售回这些词不算。说了别的业务就清掉询问,按那句话继续办。
|
||||
没有待确认时返回空串。
|
||||
"""
|
||||
from agent.policy.air_group_ops import is_airline
|
||||
from agent.redis_coord.pending_cabin_cancel import (
|
||||
clear_pending_cabin_cancel,
|
||||
load_pending_cabin_cancel,
|
||||
)
|
||||
|
||||
chat_id = (message.chat_id or "").strip()
|
||||
pending_wo = load_pending_cabin_cancel(chat_id)
|
||||
if not pending_wo:
|
||||
return ""
|
||||
kind = cabin_confirm_answer(text)
|
||||
if not kind:
|
||||
clear_pending_cabin_cancel(chat_id)
|
||||
logger.info("cabin.ask dropped chat=%s wo=%s", chat_id, pending_wo)
|
||||
return ""
|
||||
if not is_airline(engine, message.sender_id):
|
||||
send_group_text(group_client_of(engine), chat_id, copy.air_airline_only_cabin())
|
||||
return "not_airline"
|
||||
clear_pending_cabin_cancel(chat_id)
|
||||
if kind == "no":
|
||||
send_group_text(group_client_of(engine), chat_id, copy.air_release_ask_dropped())
|
||||
return "release_ask_dropped"
|
||||
ticket, phase = resolve_cabin_ticket(
|
||||
flow=engine,
|
||||
chat_id=chat_id,
|
||||
work_order_no=pending_wo,
|
||||
allow_terminal=True,
|
||||
)
|
||||
if ticket is None:
|
||||
return phase
|
||||
return apply_air_release(
|
||||
flow=engine,
|
||||
ticket=ticket,
|
||||
sender_id=message.sender_id,
|
||||
chat_id=chat_id,
|
||||
instruction=text,
|
||||
)
|
||||
|
||||
|
||||
def _ask_cabin_cancel(
|
||||
engine,
|
||||
message: InboundMessage,
|
||||
*,
|
||||
work_order_no: str,
|
||||
) -> str:
|
||||
"""航线说了释放舱位:只提问,不打 TMS。"""
|
||||
from agent.policy.air_group_ops import is_airline
|
||||
from agent.redis_coord.pending_cabin_cancel import save_pending_cabin_cancel
|
||||
|
||||
chat_id = message.chat_id
|
||||
if not is_airline(engine, message.sender_id):
|
||||
send_group_text(group_client_of(engine), chat_id, copy.air_airline_only_cabin())
|
||||
return "not_airline"
|
||||
no = (work_order_no or "").strip()
|
||||
if not no:
|
||||
bound = current_ticket(engine, chat_id)
|
||||
if bound is not None and is_air_ticket(bound):
|
||||
from agent.policy.sea_group_ops import ticket_no
|
||||
|
||||
no = ticket_no(bound)
|
||||
if not no:
|
||||
send_group_text(group_client_of(engine), chat_id, copy.air_lock_need_work_order())
|
||||
return "cabin_need_work_order"
|
||||
ticket, phase = resolve_cabin_ticket(
|
||||
flow=engine,
|
||||
chat_id=chat_id,
|
||||
work_order_no=no,
|
||||
allow_terminal=True,
|
||||
)
|
||||
if ticket is None:
|
||||
return phase
|
||||
from agent.policy.sea_group_ops import ticket_no
|
||||
|
||||
save_pending_cabin_cancel(chat_id, ticket_no(ticket))
|
||||
send_group_text(group_client_of(engine), chat_id, copy.air_release_ask())
|
||||
return "release_ask"
|
||||
|
||||
|
||||
def _handle_cabin(
|
||||
engine,
|
||||
message: InboundMessage,
|
||||
@@ -319,6 +410,12 @@ def _handle_cabin(
|
||||
) -> str:
|
||||
_ = injected_quote
|
||||
chat_id = message.chat_id
|
||||
if intent == INTENT_RELEASE_ASK:
|
||||
return _ask_cabin_cancel(
|
||||
engine,
|
||||
message,
|
||||
work_order_no=work_order_no,
|
||||
)
|
||||
if not work_order_no:
|
||||
# 本群已经在锁这张单时,补舱位不用再报工单号。
|
||||
bound = current_ticket(engine, chat_id)
|
||||
|
||||
@@ -371,6 +371,68 @@ def _tighten_sheet_labels(text: str) -> str:
|
||||
return body
|
||||
|
||||
|
||||
# 「货交上海」是提货地址,不是起运地。地址/地、到/于只是口语粘连,不进地址正文。
|
||||
_RE_CARGO_HANDOVER = re.compile(
|
||||
r"货交\s*(?:地址|地)?\s*[::]?\s*(?:到|于|至|往)?\s*([^\n,,。;;]{1,60})"
|
||||
)
|
||||
# 同一行跟在地址后面的询价口头禅或下一栏字段,不是地址的一部分。
|
||||
_RE_HANDOVER_TAIL = re.compile(
|
||||
r"(?:\s+|,|,)?(?:看看价格|看一下价格|看价格|询价|报价|多少钱|多少|"
|
||||
r"目的地|目的港|起运地|起运港|品名|件数|毛重|体积|包装|空运|海运|陆运).*$"
|
||||
)
|
||||
# 另有起运说法时保留起运地。先抠掉「货交…」,避免「货交到上海」被当成「到上海」。
|
||||
_RE_EXPLICIT_ORIGIN = re.compile(
|
||||
r"起运地|起运港|"
|
||||
r"[A-Za-z]{3}\s*[-–—//]\s*[A-Za-z]{3}|"
|
||||
r"[A-Za-z]{3}\s*(?:到|至)\s*[A-Za-z]{3}|"
|
||||
r"从\s*\S{1,16}\s*(?:飞|到|至)|"
|
||||
r"[\u4e00-\u9fff]{2,12}\s*飞|"
|
||||
r"[\u4e00-\u9fff]{2,12}\s*到\s*[\u4e00-\u9fffA-Za-z]{2,12}"
|
||||
)
|
||||
|
||||
|
||||
def _handover_place(raw: str) -> str:
|
||||
"""货交后面的地名。去掉口头禅和首尾标点,空的不当地址。"""
|
||||
place = _RE_HANDOVER_TAIL.sub("", (raw or "").strip())
|
||||
return place.strip(" ::,,。;;")
|
||||
|
||||
|
||||
def _has_explicit_origin(text: str) -> bool:
|
||||
"""原话里另写了起运地、三字码航线或「从哪飞/到」。货交那一段先拿掉。"""
|
||||
stripped = _RE_CARGO_HANDOVER.sub(" ", text or "")
|
||||
return _RE_EXPLICIT_ORIGIN.search(stripped) is not None
|
||||
|
||||
|
||||
def apply_cargo_handover_synonym(
|
||||
text: str,
|
||||
facts: dict[str, str] | None,
|
||||
*,
|
||||
business_line: str = "",
|
||||
) -> dict[str, str]:
|
||||
"""
|
||||
货交 = 提货地址。例:货交上海 → 提货地址上海。
|
||||
|
||||
只认原话里的「货交」,不把裸城市猜成港口。
|
||||
空运且没有另写起运地时,清掉被误收成起运地的同一处地名,否则 TMS 会按错误起运查价。
|
||||
海运/陆运只补提货地址,不动起运港。副作用:无。
|
||||
"""
|
||||
merged = dict(facts or {})
|
||||
places: list[str] = []
|
||||
for hit in _RE_CARGO_HANDOVER.finditer(text or ""):
|
||||
place = _handover_place(hit.group(1))
|
||||
if place and place not in places:
|
||||
places.append(place)
|
||||
if not places:
|
||||
return merged
|
||||
merged["提货地址"] = "、".join(places)
|
||||
is_air = (business_line or "").strip().upper() == "AIR" or "空运" in (text or "")
|
||||
if is_air and not _has_explicit_origin(text):
|
||||
merged.pop("起运港", None)
|
||||
merged.pop("起运地", None)
|
||||
merged.pop("originCode", None)
|
||||
return merged
|
||||
|
||||
|
||||
def _drop_fee_place_values(facts: dict[str, str]) -> dict[str, str]:
|
||||
"""起运地/目的地收成「操作费、文件费」时丢掉。那是费用栏,不是港口。"""
|
||||
out = dict(facts or {})
|
||||
@@ -407,6 +469,7 @@ def extract_inquiry_snapshot(
|
||||
facts = harvest_oral_measures(text, normalize_facts(dict(injected_facts)))
|
||||
facts = _merge_spoken_collab(text, facts)
|
||||
facts = _merge_optional_inquiry_labels(text, facts)
|
||||
facts = apply_cargo_handover_synonym(text, facts, business_line=mode)
|
||||
for key in ("货好时间", "提货地址", "收货地址", "货源地", "贸易条款"):
|
||||
if str(facts.get(key) or "").strip():
|
||||
facts[key] = clip_inquiry_value(str(facts[key]))
|
||||
@@ -453,6 +516,7 @@ def extract_inquiry_snapshot(
|
||||
facts = harvest_oral_measures(text, normalize_facts(facts))
|
||||
facts = _merge_spoken_collab(text, facts)
|
||||
facts = _merge_optional_inquiry_labels(text, facts)
|
||||
facts = apply_cargo_handover_synonym(text, facts, business_line=mode)
|
||||
for key in ("货好时间", "提货地址", "收货地址", "货源地", "贸易条款"):
|
||||
if str(facts.get(key) or "").strip():
|
||||
facts[key] = clip_inquiry_value(str(facts[key]))
|
||||
|
||||
@@ -35,6 +35,7 @@ _FIELD_KEYS = (
|
||||
"车型数量",
|
||||
"通关口岸",
|
||||
"贸易条款",
|
||||
"提货地址",
|
||||
)
|
||||
|
||||
|
||||
@@ -134,6 +135,8 @@ def build_extract_messages(text: str) -> list[dict[str, str]]:
|
||||
"陆运「通关口岸:皇岗」「通关口岸皇岗」「过皇岗」有说就写入通关口岸,没说留空,禁止编造口岸。"
|
||||
"原话单独出现 DAP、DDP、CIF、CIP、FOB、EXW 时写入贸易条款;没出现留空,禁止编造。"
|
||||
"「从南京飞吉隆坡」起运港=南京、目的港=吉隆坡;「北京飞吉隆坡」起运港=北京。"
|
||||
"「货交上海」「货交:上海」「货交到上海」是提货地址=上海,不是起运港。"
|
||||
"没有另写起运地、三字码航线或「从哪飞/到」时,起运港必须空串。"
|
||||
"原话是机场三字码或航线就原样记,禁止翻译成城市名:"
|
||||
"SZX-CGK / SZX/CGK / SZX到CGK → 起运港=SZX、目的港=CGK,不要写成深圳、雅加达。"
|
||||
"换城市必须覆盖旧值,不要沿用上一句的港口。"
|
||||
|
||||
@@ -1068,7 +1068,7 @@ def apply_air_release(
|
||||
send_group_text(
|
||||
group_client_of(flow),
|
||||
chat_id,
|
||||
copy.air_release_fail(work_order_no=no, operator=name, reason="主账未开放释放"),
|
||||
copy.air_release_fail(work_order_no=no, operator=name, reason="主账未开放取消舱位"),
|
||||
)
|
||||
return "release_unavailable"
|
||||
from agent.policy.system_exception import (
|
||||
@@ -1104,7 +1104,7 @@ def apply_air_release(
|
||||
event=SystemExceptionEvent(
|
||||
exception_type=TYPE_TMS,
|
||||
step=STEP_TMS_RELEASE,
|
||||
reason="空运释放舱位接口调用失败",
|
||||
reason="空运取消舱位接口调用失败",
|
||||
service="空运舱位",
|
||||
error_code=why or "RELEASE_FAIL",
|
||||
work_order_no=no,
|
||||
|
||||
@@ -39,6 +39,24 @@ def _r(code: str, default: str, **kwargs: Any) -> str:
|
||||
return render(code, default, **kwargs)
|
||||
|
||||
|
||||
def _cabin_copy(code: str, default: str, **kwargs: Any) -> str:
|
||||
"""
|
||||
舱位话术。库里旧句仍写「释放」时,新发出的改用当前默认句。
|
||||
|
||||
先把填进去的原因、工单号抠掉再看骨架,避免 TMS 原文里的「释放」把新句子打回去。
|
||||
已经发出的历史消息不在这里改。
|
||||
"""
|
||||
text = _r(code, default, **kwargs)
|
||||
skeleton = text
|
||||
for value in kwargs.values():
|
||||
token = str(value or "")
|
||||
if token:
|
||||
skeleton = skeleton.replace(token, "")
|
||||
if "释放" in skeleton:
|
||||
return default
|
||||
return text
|
||||
|
||||
|
||||
# 空运补问:必填 7 项 + 非必填。报价日期默认当天,不进待补充。
|
||||
_AIR_EXAMPLES = {
|
||||
"起运港": "南京",
|
||||
@@ -314,7 +332,7 @@ _LAND_EXAMPLES = {
|
||||
"体积": "100CBM",
|
||||
"毛重": "50kg",
|
||||
"车型/数量": "9米6/1",
|
||||
"通关口岸": "皇岗",
|
||||
"通关口岸": "友谊关",
|
||||
"运输类型": "国内运输拼车",
|
||||
"线路类别": "国内长途/零担",
|
||||
"运输分类": "急件",
|
||||
@@ -2879,9 +2897,9 @@ def air_need_work_order() -> str:
|
||||
|
||||
def air_lock_need_work_order() -> str:
|
||||
"""锁舱/释放必须自带工单号。后台 inquiring.air_lock_need_wo。"""
|
||||
return _r(
|
||||
return _cabin_copy(
|
||||
"inquiring.air_lock_need_wo",
|
||||
"锁舱或释放舱位请带上工单号,例如 WO202609160001锁舱。",
|
||||
"锁舱或取消舱位请带上工单号,例如 WO202609160001取消舱位。",
|
||||
)
|
||||
|
||||
|
||||
@@ -3041,9 +3059,9 @@ def air_airline_only_quote() -> str:
|
||||
|
||||
def air_airline_only_cabin() -> str:
|
||||
"""只有航线能锁舱或释放。后台 inquiring.air_airline_only_cabin。"""
|
||||
return _r(
|
||||
return _cabin_copy(
|
||||
"inquiring.air_airline_only_cabin",
|
||||
"只有岗位为「航线·空运」的人能锁舱或释放舱位。",
|
||||
"只有岗位为「航线·空运」的人能锁舱或取消舱位。",
|
||||
)
|
||||
|
||||
|
||||
@@ -3264,13 +3282,13 @@ def air_release_ok(
|
||||
) -> str:
|
||||
"""空运释放成功。后台 inquiring.air_release_ok。"""
|
||||
default = (
|
||||
f"工单{work_order_no} 已通知TMS执行空运释放舱位成功\n"
|
||||
f"工单{work_order_no} 已通知TMS执行空运取消舱位成功\n"
|
||||
f"操作人:{operator}\n"
|
||||
f"舱位选项:{option_no}\n"
|
||||
f"执行编号:{exec_no}\n"
|
||||
f"报价编号:{quote_no}"
|
||||
)
|
||||
return _r(
|
||||
return _cabin_copy(
|
||||
"inquiring.air_release_ok",
|
||||
default,
|
||||
ticket_no=work_order_no,
|
||||
@@ -3285,12 +3303,12 @@ def air_release_fail(*, work_order_no: str, operator: str, reason: str) -> str:
|
||||
"""空运释放失败。后台 inquiring.air_release_fail。"""
|
||||
why = (reason or "").strip() or "TMS未返回原因"
|
||||
default = (
|
||||
f"工单{work_order_no} 空运释放舱位失败。\n"
|
||||
f"工单{work_order_no} 空运取消舱位失败。\n"
|
||||
f"操作人:{operator}\n"
|
||||
f"释放舱位失败的原因:{why}\n"
|
||||
f"取消舱位失败的原因:{why}\n"
|
||||
"已通知IT运维排查,请稍等。"
|
||||
)
|
||||
return _r(
|
||||
return _cabin_copy(
|
||||
"inquiring.air_release_fail",
|
||||
default,
|
||||
ticket_no=work_order_no,
|
||||
@@ -3302,9 +3320,9 @@ def air_release_fail(*, work_order_no: str, operator: str, reason: str) -> str:
|
||||
def air_release_deal_blocked(work_order_no: str) -> str:
|
||||
"""已成交不能释放舱位。后台 inquiring.air_release_deal_blocked。"""
|
||||
no = (work_order_no or "").strip()
|
||||
return _r(
|
||||
return _cabin_copy(
|
||||
"inquiring.air_release_deal_blocked",
|
||||
f"释放舱位失败,工单{no}已成交。",
|
||||
f"取消舱位失败,工单{no}已成交。",
|
||||
ticket_no=no,
|
||||
)
|
||||
|
||||
@@ -3312,9 +3330,9 @@ def air_release_deal_blocked(work_order_no: str) -> str:
|
||||
def air_release_need_lock(work_order_no: str) -> str:
|
||||
"""没有有效锁舱不能释放。后台 inquiring.air_release_need_lock。"""
|
||||
no = (work_order_no or "").strip()
|
||||
return _r(
|
||||
return _cabin_copy(
|
||||
"inquiring.air_release_need_lock",
|
||||
f"工单{no}还没有有效锁舱,不能释放。",
|
||||
f"工单{no}还没有有效锁舱,不能取消舱位。",
|
||||
ticket_no=no,
|
||||
)
|
||||
|
||||
@@ -3342,9 +3360,19 @@ SYS_EXC_RECOVERY_GROUP = "建群已恢复正常,感谢您的耐心等待。"
|
||||
IMPACT_LLM_NO_TICKET = "尚未建单,不落后台工单"
|
||||
IMPACT_LLM = "当前识别暂停,已有字段与工单状态保持不变"
|
||||
IMPACT_TMS_QUOTE = "当前询价流程暂停,识别字段与原业务节点保持不变"
|
||||
IMPACT_TMS_CABIN = "当前锁舱/释放暂停,工单状态保持不变"
|
||||
IMPACT_TMS_CABIN = "当前锁舱/取消舱位暂停,工单状态保持不变"
|
||||
IMPACT_TMS_LOCK = "锁舱失败,工单状态保持不变"
|
||||
IMPACT_TMS_RELEASE = "释放舱位失败,工单状态保持不变"
|
||||
IMPACT_TMS_RELEASE = "取消舱位失败,工单状态保持不变"
|
||||
|
||||
|
||||
def air_release_ask() -> str:
|
||||
"""航线说了和舱位有关的「释放」时先问,不直接取消。"""
|
||||
return "是否需要取消舱位?"
|
||||
|
||||
|
||||
def air_release_ask_dropped() -> str:
|
||||
"""航线否认这次取消。不打 TMS。"""
|
||||
return "已取消这次操作"
|
||||
IMPACT_GROUP = "当前建群/加人暂停,已建群不新建第二个群"
|
||||
|
||||
|
||||
|
||||
@@ -289,6 +289,15 @@ def _cabin(flow: Any, ticket: object, chat_id: str, sender_id: str, text: str, i
|
||||
operator_name,
|
||||
)
|
||||
|
||||
if intent == "ask":
|
||||
if not is_airline(flow, sender_id):
|
||||
send_group_text(group_client_of(flow), chat_id, copy.air_airline_only_cabin())
|
||||
return "not_airline"
|
||||
from agent.redis_coord.pending_cabin_cancel import save_pending_cabin_cancel
|
||||
|
||||
save_pending_cabin_cancel(chat_id, ticket_no(ticket))
|
||||
send_group_text(group_client_of(flow), chat_id, copy.air_release_ask())
|
||||
return "release_ask"
|
||||
if intent == "release":
|
||||
return apply_air_release(
|
||||
flow=flow,
|
||||
@@ -314,10 +323,15 @@ def _cabin(flow: Any, ticket: object, chat_id: str, sender_id: str, text: str, i
|
||||
|
||||
|
||||
def _cabin_intent(text: str) -> str:
|
||||
raw = text or ""
|
||||
if "释放" in raw and "舱" in raw:
|
||||
"""取消舱位马上办;和舱位有关的「释放」只提问。"""
|
||||
from agent.routing.air_group_intent import cabin_release_kind
|
||||
|
||||
kind = cabin_release_kind(text or "")
|
||||
if kind == "direct":
|
||||
return "release"
|
||||
if "锁舱" in raw:
|
||||
if kind == "ask":
|
||||
return "ask"
|
||||
if "锁舱" in (text or ""):
|
||||
return "lock"
|
||||
return ""
|
||||
|
||||
|
||||
@@ -888,7 +888,7 @@ def _resume_cabin_step(
|
||||
is_ok=lambda x: bool((x or {}).get("ok")),
|
||||
)
|
||||
service = "空运舱位"
|
||||
reason = "空运释放舱位接口调用失败"
|
||||
reason = "空运取消舱位接口调用失败"
|
||||
else:
|
||||
# 与首次群锁舱对齐:重试必须带 operatorName / airline,否则 MANUAL 出站缺姓名。
|
||||
locker = getattr(ledger, "lock_cabin", None)
|
||||
|
||||
@@ -57,6 +57,8 @@ QUOTE_FILE_READY = "quote_file_ready"
|
||||
PENDING_PRODUCT_QUOTE = "pending_product_quote"
|
||||
# 陆运核对卡已出、等确定查价:短协调,不当六态、不当工单号
|
||||
PENDING_LAND_CONFIRM = "pending_land_confirm"
|
||||
# 空运群问过「是否需要取消舱位」:短协调,不当六态
|
||||
PENDING_CABIN_CANCEL = "pending_cabin_cancel"
|
||||
# 空运/海运/陆运当前书签:HTTP 与 Worker 共用,不当六态
|
||||
FLOW_BOOKMARK = "flow_bookmark"
|
||||
# 私聊图片波次:HTTP 与 Worker 必须共用,不当六态
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
"""
|
||||
空运群取消舱位待确认。
|
||||
|
||||
航线说出和舱位有关的「释放」后先问一句,确认前不打 TMS。
|
||||
短协调,不当六态、不当 checkpoint。按群记下工单号,双进程仍能读到。
|
||||
两小时没人接话就过期,避免过后回一个「是」误取消。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
|
||||
from agent.redis_coord.keys import PENDING_CABIN_CANCEL
|
||||
from agent.redis_coord.runtime import get_redis_runtime
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# 问句只在这一阵有效。过期后「是」不再取消舱位。
|
||||
_TTL_SECONDS = 2 * 60 * 60
|
||||
|
||||
|
||||
def save_pending_cabin_cancel(chat_id: str, work_order_no: str) -> None:
|
||||
"""记下本群正在等航线确认取消哪张单。"""
|
||||
room = (chat_id or "").strip()
|
||||
no = (work_order_no or "").strip()
|
||||
if not room or not no:
|
||||
return
|
||||
payload = {"work_order_no": no}
|
||||
try:
|
||||
client = get_redis_runtime().client
|
||||
client.raw.set(
|
||||
client.key(PENDING_CABIN_CANCEL, room),
|
||||
json.dumps(payload, ensure_ascii=False),
|
||||
ex=_TTL_SECONDS,
|
||||
)
|
||||
logger.info("cabin.ask saved chat=%s wo=%s", room, no)
|
||||
except Exception:
|
||||
logger.exception("写取消舱位待确认失败 chat=%s", room)
|
||||
|
||||
|
||||
def load_pending_cabin_cancel(chat_id: str) -> str:
|
||||
"""本群正在等确认的工单号。没有则空串。"""
|
||||
room = (chat_id or "").strip()
|
||||
if not room:
|
||||
return ""
|
||||
try:
|
||||
client = get_redis_runtime().client
|
||||
raw = client.raw.get(client.key(PENDING_CABIN_CANCEL, room))
|
||||
if not raw:
|
||||
return ""
|
||||
if isinstance(raw, bytes):
|
||||
raw = raw.decode("utf-8")
|
||||
data = json.loads(raw)
|
||||
if not isinstance(data, dict):
|
||||
return ""
|
||||
return str(data.get("work_order_no") or "").strip()
|
||||
except Exception:
|
||||
logger.exception("读取消舱位待确认失败 chat=%s", room)
|
||||
return ""
|
||||
|
||||
|
||||
def clear_pending_cabin_cancel(chat_id: str) -> None:
|
||||
"""确认、否认或改口办别的事时清掉。"""
|
||||
room = (chat_id or "").strip()
|
||||
if not room:
|
||||
return
|
||||
try:
|
||||
client = get_redis_runtime().client
|
||||
client.raw.delete(client.key(PENDING_CABIN_CANCEL, room))
|
||||
except Exception:
|
||||
logger.exception("清取消舱位待确认失败 chat=%s", room)
|
||||
@@ -35,12 +35,15 @@ logger = logging.getLogger(__name__)
|
||||
INTENT_ACTIVATE = "air_activate"
|
||||
INTENT_LOCK = "air_lock"
|
||||
INTENT_RELEASE = "air_release"
|
||||
# 说出和舱位有关的「释放」:先问是否取消,不直接执行。
|
||||
INTENT_RELEASE_ASK = "air_release_ask"
|
||||
INTENT_PICK_OPTION = "air_pick_option"
|
||||
|
||||
_VALID = {
|
||||
INTENT_ACTIVATE,
|
||||
INTENT_LOCK,
|
||||
INTENT_RELEASE,
|
||||
INTENT_RELEASE_ASK,
|
||||
INTENT_PICK_OPTION,
|
||||
INTENT_FIELDS,
|
||||
INTENT_QUOTE,
|
||||
@@ -56,7 +59,10 @@ _VALID = {
|
||||
|
||||
# 相近说法回退,不是唯一口令。
|
||||
_LOCK_HINTS = ("锁舱", "锁仓", "锁定舱位", "锁住舱位", "帮我锁舱")
|
||||
_RELEASE_HINTS = ("释放舱位", "放舱", "解锁舱", "取消锁舱", "释放舱")
|
||||
# 这四句马上取消舱位。「释放舱位」不在这里。
|
||||
_RELEASE_DIRECT = ("取消舱位", "放舱", "解锁舱", "取消锁舱")
|
||||
_CONFIRM_YES = ("是", "需要", "确认")
|
||||
_CONFIRM_NO = ("不需要", "不用", "否")
|
||||
|
||||
|
||||
def is_missed_air_bot_at(text: str, *, room_already_air: bool = False) -> bool:
|
||||
@@ -154,10 +160,53 @@ def classify_air_group_text(
|
||||
return INTENT_OTHER
|
||||
|
||||
|
||||
def _compact_cabin_text(text: str) -> str:
|
||||
"""去掉空白,方便认「取消舱位」「释放舱位」。"""
|
||||
return (text or "").replace(" ", "").replace(" ", "")
|
||||
|
||||
|
||||
def cabin_release_kind(text: str) -> str:
|
||||
"""
|
||||
舱位取消怎么认。
|
||||
|
||||
direct:马上执行。ask:先问「是否需要取消舱位」。
|
||||
跟舱位有关的「释放」只问不办。没说舱位的「释放」不当取消。
|
||||
"""
|
||||
blob = _compact_cabin_text(text)
|
||||
# 「释放舱位」里含着「放舱」,必须先认释放,避免被放舱直接取消。
|
||||
if "释放" in blob and "舱" in blob:
|
||||
return "ask"
|
||||
if any(hint in blob for hint in _RELEASE_DIRECT):
|
||||
return "direct"
|
||||
return ""
|
||||
|
||||
|
||||
def cabin_confirm_answer(text: str) -> str:
|
||||
"""
|
||||
问过之后这一句是确认、否认,还是别的业务。
|
||||
|
||||
只认整句(可带工单号和 @)。「不需要」不能被看成「需要」。
|
||||
返回 yes / no / 空串。空串表示询问作废,调用方按原句继续办。
|
||||
"""
|
||||
raw = text or ""
|
||||
no = copy.extract_work_order_no(raw)
|
||||
rest = raw.replace(no, "").replace(no.lower(), "")
|
||||
rest = rest.replace("@询价小助手", "").replace("询价小助手", "")
|
||||
rest = "".join(ch for ch in rest if ch.isalnum() or "\u4e00" <= ch <= "\u9fff")
|
||||
if rest in _CONFIRM_NO:
|
||||
return "no"
|
||||
if rest in _CONFIRM_YES or rest == "取消舱位":
|
||||
return "yes"
|
||||
return ""
|
||||
|
||||
|
||||
def _hint_lock_or_release(text: str) -> str:
|
||||
blob = (text or "").replace(" ", "").replace(" ", "")
|
||||
if any(x in blob for x in _RELEASE_HINTS):
|
||||
kind = cabin_release_kind(text)
|
||||
if kind == "direct":
|
||||
return INTENT_RELEASE
|
||||
if kind == "ask":
|
||||
return INTENT_RELEASE_ASK
|
||||
blob = _compact_cabin_text(text)
|
||||
if any(x in blob for x in _LOCK_HINTS):
|
||||
return INTENT_LOCK
|
||||
return ""
|
||||
@@ -191,7 +240,8 @@ def _classify_with_model(text: str, settings) -> str:
|
||||
client = LlmHttpClient.from_settings(settings)
|
||||
system = (
|
||||
"你是空运协同群意图分类。只回复一个英文词,不要解释。"
|
||||
"air_lock=航线要锁舱;air_release=航线要释放舱位;"
|
||||
"air_lock=航线要锁舱;air_release=航线要取消舱位(取消舱位、放舱、解锁舱、取消锁舱);"
|
||||
"说出释放舱位、释放舱、把舱位释放了时不要回 air_release;"
|
||||
"air_activate=只是指定/切换工单号;"
|
||||
"air_pick_option=在补充或选择舱位编号、航司、航班号,写法不限;"
|
||||
"collab_fields=在补是否含电/是否含磁;"
|
||||
|
||||
@@ -20,6 +20,7 @@ from agent.policy import inquiry_copy as copy
|
||||
from agent.routing.air_group_intent import (
|
||||
INTENT_LOCK,
|
||||
INTENT_RELEASE,
|
||||
INTENT_RELEASE_ASK,
|
||||
classify_air_group_text,
|
||||
)
|
||||
from agent.routing.dispatch import dispatch_inbound
|
||||
@@ -201,7 +202,12 @@ class AirGroupCollabTests(unittest.TestCase):
|
||||
|
||||
def test_intent_lock_is_not_hardcoded(self) -> None:
|
||||
self.assertEqual(classify_air_group_text("帮我锁舱 WO202609160001", allow_network=False), INTENT_LOCK)
|
||||
self.assertEqual(classify_air_group_text("WO202609160001释放舱位", allow_network=False), INTENT_RELEASE)
|
||||
self.assertEqual(classify_air_group_text("WO202609160001取消舱位", allow_network=False), INTENT_RELEASE)
|
||||
self.assertEqual(classify_air_group_text("放舱", allow_network=False), INTENT_RELEASE)
|
||||
self.assertEqual(classify_air_group_text("解锁舱", allow_network=False), INTENT_RELEASE)
|
||||
self.assertEqual(classify_air_group_text("取消锁舱", allow_network=False), INTENT_RELEASE)
|
||||
self.assertEqual(classify_air_group_text("WO202609160001释放舱位", allow_network=False), INTENT_RELEASE_ASK)
|
||||
self.assertEqual(classify_air_group_text("把舱位释放了", allow_network=False), INTENT_RELEASE_ASK)
|
||||
|
||||
def test_airline_fee_wording_is_quote_not_adjust(self) -> None:
|
||||
"""航线写「空运费改为900」是手工报价,不能先判成调价。比例和改总价仍是调价。"""
|
||||
@@ -1278,9 +1284,84 @@ class AirGroupCollabTests(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(phase, "release_ok")
|
||||
added = "\n".join(self._texts()[before:])
|
||||
self.assertIn("释放", added)
|
||||
self.assertIn("取消舱位", added)
|
||||
self.assertNotIn("请确认成交状态", added)
|
||||
|
||||
def test_release_wording_asks_before_cancel(self) -> None:
|
||||
"""说出释放舱位只提问。销售回「是」不算,航线确认后才取消。"""
|
||||
wo = self._create_air()
|
||||
handle_air_group(
|
||||
self._msg(sender="air1", text=f"{wo}锁舱", chat="wr_air_ask", mid="ask0"),
|
||||
flow=self.flow,
|
||||
ledger=self.ledger,
|
||||
injected_intent="air_lock",
|
||||
)
|
||||
self.groups.sent.clear()
|
||||
phase = handle_air_group(
|
||||
self._msg(sender="air1", text=f"{wo}释放舱位", chat="wr_air_ask", mid="ask1"),
|
||||
flow=self.flow,
|
||||
ledger=self.ledger,
|
||||
)
|
||||
self.assertEqual(phase, "release_ask")
|
||||
self.assertIn("是否需要取消舱位?", "\n".join(self._texts()))
|
||||
self.assertNotIn("已通知TMS执行空运取消舱位成功", "\n".join(self._texts()))
|
||||
phase = handle_air_group(
|
||||
self._msg(sender="sales1", text="是", chat="wr_air_ask", mid="ask2"),
|
||||
flow=self.flow,
|
||||
ledger=self.ledger,
|
||||
)
|
||||
self.assertEqual(phase, "not_airline")
|
||||
self.assertNotIn("已通知TMS执行空运取消舱位成功", "\n".join(self._texts()))
|
||||
phase = handle_air_group(
|
||||
self._msg(sender="air1", text="是", chat="wr_air_ask", mid="ask3"),
|
||||
flow=self.flow,
|
||||
ledger=self.ledger,
|
||||
)
|
||||
self.assertEqual(phase, "release_ok")
|
||||
self.assertIn("已通知TMS执行空运取消舱位成功", "\n".join(self._texts()))
|
||||
|
||||
def test_release_wording_can_be_declined(self) -> None:
|
||||
wo = self._create_air()
|
||||
handle_air_group(
|
||||
self._msg(sender="air1", text=f"{wo}锁舱", chat="wr_air_ask_no", mid="no0"),
|
||||
flow=self.flow,
|
||||
ledger=self.ledger,
|
||||
injected_intent="air_lock",
|
||||
)
|
||||
self.groups.sent.clear()
|
||||
handle_air_group(
|
||||
self._msg(sender="air1", text=f"{wo}把舱位释放了", chat="wr_air_ask_no", mid="no1"),
|
||||
flow=self.flow,
|
||||
ledger=self.ledger,
|
||||
)
|
||||
phase = handle_air_group(
|
||||
self._msg(sender="air1", text="不用", chat="wr_air_ask_no", mid="no2"),
|
||||
flow=self.flow,
|
||||
ledger=self.ledger,
|
||||
)
|
||||
self.assertEqual(phase, "release_ask_dropped")
|
||||
self.assertIn("已取消这次操作", "\n".join(self._texts()))
|
||||
self.assertNotIn("已通知TMS执行空运取消舱位成功", "\n".join(self._texts()))
|
||||
|
||||
def test_cancel_cabin_words_release_immediately(self) -> None:
|
||||
wo = self._create_air()
|
||||
handle_air_group(
|
||||
self._msg(sender="air1", text=f"{wo}锁舱", chat="wr_air_now", mid="now0"),
|
||||
flow=self.flow,
|
||||
ledger=self.ledger,
|
||||
injected_intent="air_lock",
|
||||
)
|
||||
self.groups.sent.clear()
|
||||
phase = handle_air_group(
|
||||
self._msg(sender="air1", text=f"{wo}取消舱位", chat="wr_air_now", mid="now1"),
|
||||
flow=self.flow,
|
||||
ledger=self.ledger,
|
||||
)
|
||||
self.assertEqual(phase, "release_ok")
|
||||
joined = "\n".join(self._texts())
|
||||
self.assertIn("已通知TMS执行空运取消舱位成功", joined)
|
||||
self.assertNotIn("是否需要取消舱位?", joined)
|
||||
|
||||
def test_sales_cannot_lock(self) -> None:
|
||||
wo = self._create_air()
|
||||
phase = handle_air_group(
|
||||
@@ -1825,9 +1906,9 @@ class AirGroupCollabTests(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(phase, "system_exception")
|
||||
joined = "\n".join(self._texts())
|
||||
self.assertIn(f"工单{wo} 空运释放舱位失败。", joined)
|
||||
self.assertIn(f"工单{wo} 空运取消舱位失败。", joined)
|
||||
self.assertIn("操作人:HangXian", joined)
|
||||
self.assertIn("释放舱位失败的原因:舱位不存在", joined)
|
||||
self.assertIn("取消舱位失败的原因:舱位不存在", joined)
|
||||
self.assertIn("已通知IT运维排查,请稍等。", joined)
|
||||
self.assertNotIn("TMS接口异常,IT运维排查中", joined)
|
||||
|
||||
|
||||
@@ -624,6 +624,79 @@ AIR_QUOTE_SHEET = """
|
||||
"""
|
||||
|
||||
|
||||
class CargoHandoverSynonymTests(unittest.TestCase):
|
||||
"""货交是提货地址,不能当成起运地。"""
|
||||
|
||||
def test_huojiao_shanghai_is_pickup_not_origin(self) -> None:
|
||||
text = (
|
||||
"KUL 空运 普货 散货\n"
|
||||
"8686KG//9PLT//11.6CBM\n"
|
||||
"110*110*118CM*7\n"
|
||||
"110*110*80CM*1\n"
|
||||
"110*110*53CM*1\n"
|
||||
"货交上海\n"
|
||||
"看看价格 几号"
|
||||
)
|
||||
guessed = parse_extract_payload(
|
||||
{
|
||||
"transport_mode": "AIR",
|
||||
"fields": {
|
||||
"起运港": "上海",
|
||||
"目的港": "KUL",
|
||||
"品名": "普货",
|
||||
"件数": "9",
|
||||
"毛重": "8686KG",
|
||||
"体积": "11.6CBM",
|
||||
"包装方式": "散货",
|
||||
},
|
||||
}
|
||||
)
|
||||
facts = extract_inquiry_snapshot(text, b_result=guessed)["facts"]
|
||||
self.assertEqual(facts.get("提货地址"), "上海")
|
||||
self.assertNotIn("起运港", facts)
|
||||
self.assertEqual(facts.get("目的港"), "KUL")
|
||||
|
||||
def test_huojiao_colon_and_dao_same_as_pickup(self) -> None:
|
||||
for spoken in ("货交:上海", "货交到上海", "货交地:上海"):
|
||||
guessed = parse_extract_payload(
|
||||
{
|
||||
"transport_mode": "AIR",
|
||||
"fields": {"起运港": "上海", "目的港": "KUL", "品名": "普货"},
|
||||
}
|
||||
)
|
||||
facts = extract_inquiry_snapshot(
|
||||
f"空运 {spoken} 目的地KUL", b_result=guessed
|
||||
)["facts"]
|
||||
self.assertEqual(facts.get("提货地址"), "上海", spoken)
|
||||
self.assertNotIn("起运港", facts, spoken)
|
||||
|
||||
def test_explicit_route_keeps_origin(self) -> None:
|
||||
text = "SZX-CGK 空运 货交深圳"
|
||||
guessed = parse_extract_payload(
|
||||
{
|
||||
"transport_mode": "AIR",
|
||||
"fields": {"起运港": "SZX", "目的港": "CGK", "品名": "普货"},
|
||||
}
|
||||
)
|
||||
facts = extract_inquiry_snapshot(text, b_result=guessed)["facts"]
|
||||
self.assertEqual(facts.get("提货地址"), "深圳")
|
||||
self.assertEqual(facts.get("起运港"), "SZX")
|
||||
self.assertEqual(facts.get("目的港"), "CGK")
|
||||
|
||||
def test_fly_from_city_keeps_origin(self) -> None:
|
||||
text = "从南京飞吉隆坡 空运 货交上海"
|
||||
guessed = parse_extract_payload(
|
||||
{
|
||||
"transport_mode": "AIR",
|
||||
"fields": {"起运港": "南京", "目的港": "吉隆坡", "品名": "普货"},
|
||||
}
|
||||
)
|
||||
facts = extract_inquiry_snapshot(text, b_result=guessed)["facts"]
|
||||
self.assertEqual(facts.get("提货地址"), "上海")
|
||||
self.assertEqual(facts.get("起运港"), "南京")
|
||||
self.assertEqual(facts.get("目的港"), "吉隆坡")
|
||||
|
||||
|
||||
class AirQuoteSheetInquiryOnlyTests(unittest.TestCase):
|
||||
def test_quote_sheet_keeps_inquiry_fields_only(self) -> None:
|
||||
"""费用明细、报价条件、落款不能进补问。起运地不能收成操作费。"""
|
||||
|
||||
@@ -123,7 +123,7 @@ class LandCopyTest(unittest.TestCase):
|
||||
self.assertIn("始发站(必填):广州", text)
|
||||
self.assertIn(copy.CLARIFY_PASTE_HINT, text)
|
||||
self.assertIn("1.体积(CBM)(必填):\n(如:100CBM)", text)
|
||||
self.assertIn("2.通关口岸(非必填):\n(如:皇岗)", text)
|
||||
self.assertIn("2.通关口岸(非必填):\n(如:友谊关)", text)
|
||||
self.assertNotIn("体积(必填):(如:", text)
|
||||
self.assertNotIn(copy.LAND_CONFIRM_TAIL, text)
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class TestSystemExceptionCopy(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(
|
||||
copy.system_exception_impact(copy.STEP_TMS_RELEASE),
|
||||
"释放舱位失败,工单状态保持不变",
|
||||
"取消舱位失败,工单状态保持不变",
|
||||
)
|
||||
|
||||
def test_alert_title_never_has_test_prefix(self) -> None:
|
||||
@@ -118,9 +118,9 @@ class TestSystemExceptionCopy(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(
|
||||
text,
|
||||
"工单WO202609210001 空运释放舱位失败。\n"
|
||||
"工单WO202609210001 空运取消舱位失败。\n"
|
||||
"操作人:吴季林\n"
|
||||
"释放舱位失败的原因:舱位不存在\n"
|
||||
"取消舱位失败的原因:舱位不存在\n"
|
||||
"已通知IT运维排查,请稍等。",
|
||||
)
|
||||
|
||||
@@ -409,7 +409,7 @@ class TestConfirmSystemException(unittest.TestCase):
|
||||
)
|
||||
card = queued[0]["payload"]["template_card"]
|
||||
values = {row["keyname"]: row["value"] for row in card["horizontal_content_list"]}
|
||||
self.assertEqual(values["影响范围"], "释放舱位失败,工单状态保持不变")
|
||||
self.assertEqual(values["影响范围"], "取消舱位失败,工单状态保持不变")
|
||||
|
||||
def test_closed_ticket_not_marked(self) -> None:
|
||||
self.ledger.transition(work_order_no=self.wo, to_status="已关闭")
|
||||
|
||||
+41
-10
@@ -235,6 +235,8 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
|
||||
|
||||
int nextVer = nextVersionNo(template.getId());
|
||||
String sha = DigestUtils.sha256Hex(fileBytes);
|
||||
// 本地 by-sha 镜像:MinIO 对象损坏时仍能按版本 sha 回退出完好模板
|
||||
objectStore.writeByShaMirror(fileBytes, sha);
|
||||
|
||||
InquiryQuoteTemplateVersion version = new InquiryQuoteTemplateVersion();
|
||||
version.setTemplateId(template.getId());
|
||||
@@ -564,7 +566,7 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
|
||||
if (!"excel".equals(ver.getFormat())) {
|
||||
throw new IllegalStateException("仅 Excel 支持样例回填预览");
|
||||
}
|
||||
Path source = resolveObjectPath(ver.getObjectKey());
|
||||
Path source = resolveObjectPath(ver.getObjectKey(), ver.getSha256());
|
||||
JSONObject contract = QuoteTemplateExcelSupport.loadContract(resolveContractPath());
|
||||
JSONObject mapping;
|
||||
try {
|
||||
@@ -599,7 +601,7 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
|
||||
if (!"excel".equals(ver.getFormat())) {
|
||||
throw new IllegalStateException("仅 Excel 支持表格预览");
|
||||
}
|
||||
Path source = resolveObjectPath(ver.getObjectKey());
|
||||
Path source = resolveObjectPath(ver.getObjectKey(), ver.getSha256());
|
||||
JSONObject mapping;
|
||||
try {
|
||||
mapping = StringUtils.isNotBlank(ver.getMappingJson())
|
||||
@@ -681,7 +683,7 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
|
||||
Files.createDirectories(previewDir);
|
||||
Path cachedPng = previewDir.resolve(ver.getId() + "-snapshot-v5.png");
|
||||
Path cachedPdf = previewDir.resolve(ver.getId() + "-snapshot-v5.pdf");
|
||||
Path source = resolveObjectPath(ver.getObjectKey());
|
||||
Path source = resolveObjectPath(ver.getObjectKey(), ver.getSha256());
|
||||
QuoteTemplateSnapshotRenderer.PreviewBytes rendered = snapshotRenderer.render(source, ver.getId());
|
||||
Path target = rendered.isImage() ? cachedPng : cachedPdf;
|
||||
Files.write(target, rendered.getBytes());
|
||||
@@ -696,6 +698,13 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
|
||||
return objectStore.resolve(objectKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 带版本 sha256 的解析:远程缓存/对象与指纹不一致时删缓存并回退 by-sha 镜像。
|
||||
*/
|
||||
public Path resolveObjectPath(String objectKey, String expectedSha256) {
|
||||
return objectStore.resolve(objectKey, expectedSha256);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> listEnabledForAgent(boolean enabledOnly) {
|
||||
QueryWrapper<InquiryQuoteTemplate> qw = new QueryWrapper<>();
|
||||
@@ -750,13 +759,16 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
|
||||
}
|
||||
String objectKey = String.valueOf(picked.getOrDefault("objectKey", ""));
|
||||
String mappingJson = String.valueOf(picked.getOrDefault("mappingJson", ""));
|
||||
String expectedSha = String.valueOf(picked.getOrDefault("sha256", ""));
|
||||
if (StringUtils.isBlank(objectKey) || "null".equalsIgnoreCase(objectKey)) {
|
||||
log.warn("报价出单模板无文件 wo={} template={}", workOrderNo, picked.get("templateId"));
|
||||
return fail;
|
||||
}
|
||||
Path source;
|
||||
try {
|
||||
source = resolveObjectPath(objectKey);
|
||||
// 传入版本 sha:防止 MinIO/缓存被掏空后仍出「费目名全空」的坏表
|
||||
source = resolveObjectPath(objectKey,
|
||||
("null".equalsIgnoreCase(expectedSha) ? null : expectedSha));
|
||||
} catch (Exception e) {
|
||||
log.warn("报价出单找不到模板文件 wo={} err={}", workOrderNo, e.getMessage());
|
||||
return fail;
|
||||
@@ -1043,6 +1055,18 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
|
||||
out.put("chargeable_weight_kg", chargeable);
|
||||
out.put("chargeableWeightKg", chargeable);
|
||||
}
|
||||
// 重量单位:仅供「已有费用行」时写入报价明细「单位」;无报价不出费用行,也不填单位。
|
||||
String weightUnitEarly = first(src, "重量单位", "weight_unit", "weightUnit", "毛重单位");
|
||||
if (StringUtils.isBlank(weightUnitEarly)) {
|
||||
String rawW = first(src, "毛重", "重量", "重量(KG)", "weight_kg");
|
||||
if (StringUtils.isNotBlank(rawW) && rawW.matches("(?i).*\\b(KG|KGS|公斤)\\b.*")) {
|
||||
weightUnitEarly = "KG";
|
||||
}
|
||||
}
|
||||
if (looksAirInquiry(src, q, businessLine)) {
|
||||
out.put("weight_unit", QuoteTemplateExcelSupport.normalizeWeightUnit(weightUnitEarly));
|
||||
out.put("重量单位", out.getString("weight_unit"));
|
||||
}
|
||||
for (Map.Entry<String, String> e : QuoteTemplateExcelSupport.LAND_TMS_KEY_TO_CODE.entrySet()) {
|
||||
String val = first(q, e.getKey(), e.getValue());
|
||||
if (StringUtils.isNotBlank(val) && !"-".equals(val) && StringUtils.isBlank(out.getString(e.getValue()))) {
|
||||
@@ -1080,8 +1104,8 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
|
||||
}
|
||||
}
|
||||
}
|
||||
// 空运:已落库的旧明细若只有费率,出单时按计费重补 单位/单价/数量/行金额
|
||||
if (!rows.isEmpty() && StringUtils.isNotBlank(chargeable)) {
|
||||
// 空运:补单位/数量/单价(手工常只有金额,WO020 空运费与增点费)
|
||||
if (!rows.isEmpty()) {
|
||||
List<Map<String, String>> lineMaps = new ArrayList<>();
|
||||
for (int i = 0; i < rows.size(); i++) {
|
||||
JSONObject one = rows.getJSONObject(i);
|
||||
@@ -1097,8 +1121,15 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
|
||||
}
|
||||
lineMaps.add(m);
|
||||
}
|
||||
// 出单路径自带重算(单位/单价/数量/金额)
|
||||
QuoteTemplateExcelSupport.enrichAirWeightFeeRows(lineMaps, chargeable);
|
||||
String weightUnit = first(src, "重量单位", "weight_unit", "weightUnit", "毛重单位");
|
||||
if (StringUtils.isBlank(weightUnit)) {
|
||||
// 从「262 KG」「重量:262KG」里剥单位
|
||||
String rawW = first(src, "毛重", "重量", "重量(KG)", "weight_kg");
|
||||
if (StringUtils.isNotBlank(rawW) && rawW.matches("(?i).*\\b(KG|KGS|公斤)\\b.*")) {
|
||||
weightUnit = "KG";
|
||||
}
|
||||
}
|
||||
QuoteTemplateExcelSupport.enrichAirWeightFeeRows(lineMaps, chargeable, weightUnit);
|
||||
JSONArray enriched = new JSONArray();
|
||||
for (Map<String, String> m : lineMaps) {
|
||||
// Fastjson 只要 Map<String,Object>,不能直接塞 Map<String,String>。
|
||||
@@ -1573,7 +1604,7 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
|
||||
throw new IllegalArgumentException("模板不存在");
|
||||
}
|
||||
try {
|
||||
Path local = resolveObjectPath(ver.getObjectKey());
|
||||
Path local = resolveObjectPath(ver.getObjectKey(), ver.getSha256());
|
||||
byte[] fileBytes = Files.readAllBytes(local);
|
||||
ver.setParseStatus("pending");
|
||||
ver.setParseMessage("解析中,请稍候");
|
||||
@@ -1642,7 +1673,7 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
|
||||
org.apache.poi.ss.usermodel.Workbook wb = null;
|
||||
try {
|
||||
if (StringUtils.isNotBlank(ver.getObjectKey())) {
|
||||
Path local = resolveObjectPath(ver.getObjectKey());
|
||||
Path local = resolveObjectPath(ver.getObjectKey(), ver.getSha256());
|
||||
try (InputStream in = Files.newInputStream(local)) {
|
||||
wb = org.apache.poi.ss.usermodel.WorkbookFactory.create(in);
|
||||
}
|
||||
|
||||
+472
-29
@@ -2213,9 +2213,8 @@ public final class QuoteTemplateExcelSupport {
|
||||
continue;
|
||||
}
|
||||
JSONArray rows = resolveRegionFeeRows(facts, region);
|
||||
if (rows.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
// 有费用的才出行:无单价/金额的行不占明细(对齐空运到港;到门模板样例名不得冒充有费)
|
||||
rows = filterFeeRowsWithCharge(rows);
|
||||
String anchor = region.getString("anchor");
|
||||
JSONObject columns = region.getJSONObject("columns");
|
||||
if (StringUtils.isBlank(anchor) || columns == null) {
|
||||
@@ -2235,6 +2234,12 @@ public final class QuoteTemplateExcelSupport {
|
||||
continue;
|
||||
}
|
||||
int stopRow = findStopRow(sheet, region.getJSONArray("stopAtText"), startRow);
|
||||
// 无明细:保留项目列骨架(空运段/起运港/目的港/其他),清掉样例费目名。
|
||||
// 对齐到港「有费用的才显示行」——到门模板样例(操作费/目的港派送费…)无报价时不得残留。
|
||||
if (rows.isEmpty()) {
|
||||
clearFeeRowsAfter(sheet, startRow, stopRow, columns, yellow, sheet.getSheetName(), true);
|
||||
continue;
|
||||
}
|
||||
int styleCopy = region.getIntValue("styleCopyRows");
|
||||
if (styleCopy <= 0) {
|
||||
styleCopy = 1;
|
||||
@@ -2255,9 +2260,34 @@ public final class QuoteTemplateExcelSupport {
|
||||
// 不整行跳过:备注「发生时收取」常标黄,整行跳过会把费用名留成模板样例(如 ZUH)。
|
||||
// 黄格仍由 writeFeeCol 逐格跳过。
|
||||
JSONObject rowObj = rows.getJSONObject(r);
|
||||
writeFeeCol(sheet, rowIdx, columns.getString("project"),
|
||||
firstNonBlank(rowObj.getString("project"), rowObj.getString("segment")),
|
||||
yellow, sheet.getSheetName());
|
||||
String projectVal = firstNonBlank(rowObj.getString("project"), rowObj.getString("segment"));
|
||||
// 增点/操作等禁止落在模板首行「空运段」骨架上:无 project 时按费目名归类
|
||||
if (StringUtils.isBlank(projectVal)) {
|
||||
projectVal = isAirWeightFeeName(rowObj.getString("name")) ? "空运段" : "起运港";
|
||||
} else if (!isAirWeightFeeName(rowObj.getString("name"))
|
||||
&& ("空运段".equals(projectVal) || "空运".equals(projectVal))) {
|
||||
projectVal = "起运港";
|
||||
}
|
||||
String projectBefore = readCellText(
|
||||
sheet.getRow(rowIdx) == null || StringUtils.isBlank(columns.getString("project"))
|
||||
? null
|
||||
: sheet.getRow(rowIdx).getCell(
|
||||
CellReference.convertColStringToIndex(columns.getString("project").trim())));
|
||||
writeFeeCol(sheet, rowIdx, columns.getString("project"), projectVal, yellow, sheet.getSheetName());
|
||||
String projectAfter = readCellText(
|
||||
sheet.getRow(rowIdx) == null || StringUtils.isBlank(columns.getString("project"))
|
||||
? null
|
||||
: sheet.getRow(rowIdx).getCell(
|
||||
CellReference.convertColStringToIndex(columns.getString("project").trim())));
|
||||
// writeFeeCol 可能因黄底/保护跳过:项目骨架必须能改成费目归属(增点费→起运港)
|
||||
if (StringUtils.isNotBlank(projectVal) && !projectVal.equals(projectAfter)
|
||||
&& StringUtils.isNotBlank(columns.getString("project"))) {
|
||||
forceWriteProjectSkeleton(sheet, rowIdx,
|
||||
CellReference.convertColStringToIndex(columns.getString("project").trim()),
|
||||
projectVal);
|
||||
projectAfter = readCellText(sheet.getRow(rowIdx).getCell(
|
||||
CellReference.convertColStringToIndex(columns.getString("project").trim())));
|
||||
}
|
||||
writeFeeCol(sheet, rowIdx, columns.getString("name"), rowObj.getString("name"), yellow, sheet.getSheetName());
|
||||
writeFeeCol(sheet, rowIdx, columns.getString("unit"), rowObj.getString("unit"), yellow, sheet.getSheetName());
|
||||
writeFeeCol(sheet, rowIdx, columns.getString("quantity"),
|
||||
@@ -2296,20 +2326,121 @@ public final class QuoteTemplateExcelSupport {
|
||||
}
|
||||
}
|
||||
}
|
||||
// 明细行数少于模板占位时,清掉后面非黄底样例行(避免 ZUH/文件费残留)
|
||||
clearFeeRowsAfter(sheet, startRow + rows.size(), stopRow, columns, yellow, sheet.getSheetName());
|
||||
// 明细行数少于模板占位时,清掉后面样例行(含黄底「发生时收取」备注),只留有费用的行
|
||||
clearFeeRowsAfter(sheet, startRow + rows.size(), stopRow, columns, yellow, sheet.getSheetName(), true);
|
||||
// 有明细时再扫一遍:防止 enrich 未覆盖到的空运费行单位仍空
|
||||
fillAirWeightUnitOnTemplateRows(sheet, startRow, startRow + rows.size(), columns, facts, yellow);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空 [fromRow, stopRow) 费用列;黄底固定行保留(如「发生时收取」占位)。
|
||||
* 只保留有单价或金额的费用行;纯名称占位不写出(有费用的才显示行)。
|
||||
*/
|
||||
static JSONArray filterFeeRowsWithCharge(JSONArray rows) {
|
||||
JSONArray out = new JSONArray();
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
return out;
|
||||
}
|
||||
for (int i = 0; i < rows.size(); i++) {
|
||||
JSONObject row = rows.getJSONObject(i);
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
String amount = StringUtils.trimToEmpty(firstNonBlank(row.getString("amount"), row.getString("salePrice")));
|
||||
String unitPrice = StringUtils.trimToEmpty(firstNonBlank(row.getString("unit_price"),
|
||||
row.getString("unitPrice")));
|
||||
if ((amount.isEmpty() || "-".equals(amount)) && (unitPrice.isEmpty() || "-".equals(unitPrice))) {
|
||||
continue;
|
||||
}
|
||||
out.add(row);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 已写费用行:空运重量计价费目缺「单位」时,填入询价重量单位(默认 KG)。
|
||||
* <p>
|
||||
* stopAtText 未命中时 {@link #findStopRow} 会回 Integer.MAX_VALUE。
|
||||
* 若原样循环清空,会捅到 Excel 最大行(1048576)并抛 IllegalArgumentException,整张出单失败。
|
||||
* 因此未命中时只清到表内已有末行,绝不 createRow 扩到上限。
|
||||
* 只动空运运输费行,不起运港操作费/文件费等(那些不是按毛重计价)。
|
||||
* 副作用:写 Excel 单位格。线程:调用方线程。
|
||||
*/
|
||||
static int fillAirWeightUnitOnTemplateRows(Sheet sheet, int startRow, int stopRow, JSONObject columns,
|
||||
JSONObject facts, Set<String> yellow) {
|
||||
if (sheet == null || columns == null || startRow < 0) {
|
||||
return 0;
|
||||
}
|
||||
String unitCol = columns.getString("unit");
|
||||
String nameCol = columns.getString("name");
|
||||
if (StringUtils.isBlank(unitCol) || StringUtils.isBlank(nameCol)) {
|
||||
return 0;
|
||||
}
|
||||
String weightUnit = resolveWeightUnitFromFacts(facts);
|
||||
int lastExisting = sheet.getLastRowNum();
|
||||
int end = stopRow;
|
||||
if (end == Integer.MAX_VALUE || end > lastExisting + 1) {
|
||||
end = lastExisting + 1;
|
||||
}
|
||||
end = Math.min(end, 1048575 + 1);
|
||||
if (startRow >= end) {
|
||||
return 0;
|
||||
}
|
||||
int nameIdx = CellReference.convertColStringToIndex(nameCol.trim());
|
||||
int unitIdx = CellReference.convertColStringToIndex(unitCol.trim());
|
||||
int filled = 0;
|
||||
for (int r = startRow; r < end; r++) {
|
||||
Row row = sheet.getRow(r);
|
||||
if (row == null) {
|
||||
continue;
|
||||
}
|
||||
String name = readCellText(row.getCell(nameIdx));
|
||||
if (!isAirWeightFeeName(name)) {
|
||||
continue;
|
||||
}
|
||||
String existing = readCellText(row.getCell(unitIdx));
|
||||
if (StringUtils.isNotBlank(existing) && !"-".equals(existing.trim())) {
|
||||
continue;
|
||||
}
|
||||
writeFeeCol(sheet, r, unitCol, weightUnit, yellow, sheet.getSheetName());
|
||||
filled++;
|
||||
}
|
||||
return filled;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从填表事实取重量单位:显式字段优先,其次毛重/重量原文里的 KG/公斤,默认 KG。
|
||||
*/
|
||||
static String resolveWeightUnitFromFacts(JSONObject facts) {
|
||||
if (facts == null) {
|
||||
return "KG";
|
||||
}
|
||||
String raw = firstNonBlank(facts.getString("weight_unit"), facts.getString("重量单位"),
|
||||
facts.getString("weightUnit"), facts.getString("毛重单位"));
|
||||
if (StringUtils.isBlank(raw)) {
|
||||
String w = firstNonBlank(facts.getString("毛重"), facts.getString("重量"),
|
||||
facts.getString("重量(KG)"), facts.getString("weight_kg"));
|
||||
if (StringUtils.isNotBlank(w) && w.matches("(?i).*\\b(KG|KGS|公斤)\\b.*")) {
|
||||
raw = "KG";
|
||||
}
|
||||
}
|
||||
return normalizeWeightUnit(raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空 [fromRow, stopRow) 费用列。
|
||||
* <p>
|
||||
* 项目列「空运段/起运港/目的港/其他」是模板骨架,禁止擦掉。
|
||||
* {@code clearSampleRemarks=true} 时连备注样例(含黄底「发生时收取」)一并清掉,
|
||||
* 实现空运到门与到港一致的「有费用的才显示行」。
|
||||
* <p>
|
||||
* stopAtText 未命中时 {@link #findStopRow} 会回 Integer.MAX_VALUE;
|
||||
* 未命中时只清到表内已有末行,绝不 createRow 扩到上限。
|
||||
*/
|
||||
private static void clearFeeRowsAfter(Sheet sheet, int fromRow, int stopRow, JSONObject columns,
|
||||
Set<String> yellow, String sheetName) {
|
||||
clearFeeRowsAfter(sheet, fromRow, stopRow, columns, yellow, sheetName, false);
|
||||
}
|
||||
|
||||
private static void clearFeeRowsAfter(Sheet sheet, int fromRow, int stopRow, JSONObject columns,
|
||||
Set<String> yellow, String sheetName, boolean clearSampleRemarks) {
|
||||
if (sheet == null || columns == null || fromRow < 0) {
|
||||
return;
|
||||
}
|
||||
@@ -2323,19 +2454,104 @@ public final class QuoteTemplateExcelSupport {
|
||||
if (fromRow >= end) {
|
||||
return;
|
||||
}
|
||||
// 备注列常黄底「发生时收取」:不清 remark,只清费用数据列;黄格由 writeFeeCol 跳过
|
||||
String[] keys = {"project", "name", "unit", "quantity", "unit_price", "amount", "currency", "container_rate"};
|
||||
// 有费才出行时:映射若缺备注列,按表头补上,否则「发生时收取」清不掉
|
||||
if (clearSampleRemarks && StringUtils.isBlank(columns.getString("remark"))) {
|
||||
Map<String, Integer> header = findFeeTableColumnsAbove(sheet, Math.max(fromRow, 0));
|
||||
if (header == null || header.isEmpty()) {
|
||||
header = findFeeTableColumns(sheet);
|
||||
}
|
||||
if (header != null && header.get("remark") != null) {
|
||||
columns.put("remark", CellReference.convertNumToColString(header.get("remark")));
|
||||
}
|
||||
}
|
||||
int projectCol = -1;
|
||||
if (StringUtils.isNotBlank(columns.getString("project"))) {
|
||||
projectCol = CellReference.convertColStringToIndex(columns.getString("project").trim());
|
||||
}
|
||||
// 项目列保留骨架;费用名/金额等可清;有费才出行时备注样例也清。
|
||||
String[] keys = clearSampleRemarks
|
||||
? new String[]{"name", "unit", "quantity", "unit_price", "amount", "currency",
|
||||
"container_rate", "remark"}
|
||||
: new String[]{"name", "unit", "quantity", "unit_price", "amount", "currency", "container_rate"};
|
||||
for (int r = fromRow; r < end; r++) {
|
||||
for (String key : keys) {
|
||||
String colLetter = columns.getString(key);
|
||||
if (StringUtils.isBlank(colLetter)) {
|
||||
continue;
|
||||
}
|
||||
writeFeeCol(sheet, r, colLetter, "", yellow, sheetName);
|
||||
int col = CellReference.convertColStringToIndex(colLetter.trim());
|
||||
// 绝对不清项目列(含误配成 name=A 的情况)
|
||||
if (projectCol >= 0 && col == projectCol) {
|
||||
continue;
|
||||
}
|
||||
int[] origin = resolveMergeOrigin(sheet, r, col);
|
||||
// 合并区顶落在已写费用行:禁止经 origin 误清
|
||||
if (origin[0] < fromRow) {
|
||||
continue;
|
||||
}
|
||||
// 合并原点若落在项目列(到门 A18:A21 起运港),只清本格,绝不擦骨架
|
||||
if (projectCol >= 0 && origin[1] == projectCol) {
|
||||
origin = new int[]{r, col};
|
||||
}
|
||||
if (clearSampleRemarks) {
|
||||
// 黄底样例备注/费目名也要清,否则到门模板仍像「有一行费用」
|
||||
forceBlankFeeCell(sheet, origin[0], origin[1], projectCol);
|
||||
} else {
|
||||
writeFeeCol(sheet, r, colLetter, "", yellow, sheetName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制写入项目骨架文案(空运段/起运港/目的港/其他),绕过黄底与 writeFeeCol 保护。
|
||||
* 用于「增点费」落到模板首行时把「空运段」改成「起运港」。
|
||||
*/
|
||||
private static void forceWriteProjectSkeleton(Sheet sheet, int rowIdx, int colIdx, String value) {
|
||||
if (sheet == null || rowIdx < 0 || colIdx < 0 || StringUtils.isBlank(value)) {
|
||||
return;
|
||||
}
|
||||
Row row = sheet.getRow(rowIdx);
|
||||
if (row == null) {
|
||||
row = sheet.createRow(rowIdx);
|
||||
}
|
||||
Cell cell = row.getCell(colIdx);
|
||||
if (cell == null) {
|
||||
cell = row.createCell(colIdx);
|
||||
}
|
||||
cell.setCellValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制清空费用格(绕过黄底保护)。仅用于清模板样例占位,不用于写业务值。
|
||||
*
|
||||
* @param projectCol 项目列索引;该列及「空运段/起运港/目的港/其他」文案禁止清空
|
||||
*/
|
||||
private static void forceBlankFeeCell(Sheet sheet, int rowIdx, int colIdx, int projectCol) {
|
||||
if (sheet == null || rowIdx < 0 || rowIdx > 1048575 || colIdx < 0) {
|
||||
return;
|
||||
}
|
||||
if (projectCol >= 0 && colIdx == projectCol) {
|
||||
return;
|
||||
}
|
||||
Row row = sheet.getRow(rowIdx);
|
||||
if (row == null) {
|
||||
return;
|
||||
}
|
||||
Cell cell = row.getCell(colIdx);
|
||||
if (cell == null) {
|
||||
return;
|
||||
}
|
||||
String exist = readCellText(cell);
|
||||
// 项目骨架与表头/章节标题不碰
|
||||
if (isSectionTitle(sheet, cell) || isFeeTableHeader(exist)
|
||||
|| "空运段".equals(exist) || "起运港".equals(exist) || "目的港".equals(exist)
|
||||
|| "其他".equals(exist) || "其它".equals(exist)) {
|
||||
return;
|
||||
}
|
||||
cell.setBlank();
|
||||
}
|
||||
|
||||
/**
|
||||
* 把费用区表头「箱型(动态填充箱型)」替换为真实箱型码(20GP / 40HQ…)。
|
||||
*/
|
||||
@@ -4837,7 +5053,9 @@ public final class QuoteTemplateExcelSupport {
|
||||
boolean needPrice = StringUtils.isBlank(out.getString("unit_price"));
|
||||
boolean needQty = StringUtils.isBlank(out.getString("quantity"));
|
||||
boolean needProject = StringUtils.isBlank(out.getString("project"));
|
||||
if (!needUnit && !needPrice && !needQty && !needProject) {
|
||||
boolean needRemark = StringUtils.isBlank(out.getString("remark"));
|
||||
if (!needUnit && !needPrice && !needQty && !needProject && !needRemark
|
||||
&& StringUtils.isNotBlank(out.getString("name"))) {
|
||||
return out;
|
||||
}
|
||||
Map<String, Integer> header = findFeeTableColumnsAbove(sheet, Math.max(dataStartRow, 0));
|
||||
@@ -4859,6 +5077,9 @@ public final class QuoteTemplateExcelSupport {
|
||||
if (needProject && header.get("project") != null) {
|
||||
out.put("project", CellReference.convertNumToColString(header.get("project")));
|
||||
}
|
||||
if (needRemark && header.get("remark") != null) {
|
||||
out.put("remark", CellReference.convertNumToColString(header.get("remark")));
|
||||
}
|
||||
if (StringUtils.isBlank(out.getString("name")) && header.get("name") != null) {
|
||||
out.put("name", CellReference.convertNumToColString(header.get("name")));
|
||||
}
|
||||
@@ -4867,7 +5088,11 @@ public final class QuoteTemplateExcelSupport {
|
||||
|
||||
/**
|
||||
* 空运 airOptions[].departureCharges → 费用行(出单用)。
|
||||
* <p>
|
||||
* 已落库 payload 常把 airOptions 存成 JSON 字符串。
|
||||
* TMS 常把「空运费」只放在舱位 salePrice/unitPrice,departureCharges 只有增点费/拆板费;
|
||||
* 若 firstNonNull 只取 departureCharges,出单会缺空运费,且模板样例「空运段|增点费」会残留。
|
||||
* 这里合并 departureCharges+feeItems,缺运费时用舱位价注入「空运费」,并保证项目列归类。
|
||||
*/
|
||||
public static JSONArray parseAirDepartureChargeRows(Object airOptions, Object airOptionsAlt,
|
||||
String chargeableWeightKg, String headerCurrency) {
|
||||
@@ -4883,9 +5108,11 @@ public final class QuoteTemplateExcelSupport {
|
||||
if (opt == null) {
|
||||
continue;
|
||||
}
|
||||
JSONArray charges = parseFeeRows(firstNonNull(opt.get("departureCharges"), opt.get("departure_charges"),
|
||||
opt.get("charges"), opt.get("feeItems")));
|
||||
// 合并起运附加费与 feeItems,禁止 firstNonNull 只吃一边丢掉空运费
|
||||
JSONArray charges = mergeAirOptionChargeArrays(opt);
|
||||
String optCcy = firstNonBlank(opt.getString("currency"), headerCurrency);
|
||||
String optCw = firstNonBlank(opt.getString("chargeableWeightKg"), opt.getString("chargeable_weight_kg"),
|
||||
chargeableWeightKg);
|
||||
for (int c = 0; c < charges.size(); c++) {
|
||||
JSONObject ch = charges.getJSONObject(c);
|
||||
if (ch == null) {
|
||||
@@ -4921,17 +5148,113 @@ public final class QuoteTemplateExcelSupport {
|
||||
}
|
||||
lines.add(line);
|
||||
}
|
||||
// departureCharges 只有附加费时,用舱位 salePrice/unitPrice 补「空运费」行
|
||||
injectAirFreightLineIfMissing(lines, opt, optCw, optCcy);
|
||||
if (!lines.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
enrichAirWeightFeeRows(lines, chargeableWeightKg);
|
||||
// 空运段(运费)在前,起运港附加费在后,避免盖住模板首行样例「空运段」
|
||||
lines.sort((a, b) -> {
|
||||
boolean aAir = a != null && isAirWeightFeeName(a.get("name"));
|
||||
boolean bAir = b != null && isAirWeightFeeName(b.get("name"));
|
||||
if (aAir == bAir) {
|
||||
return 0;
|
||||
}
|
||||
return aAir ? -1 : 1;
|
||||
});
|
||||
for (Map<String, String> line : lines) {
|
||||
out.add(JSON.parseObject(JSON.toJSONString(line)));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合并舱位上的 departureCharges 与 feeItems(去重:同名只留先出现的)。
|
||||
* 副作用:无。线程:调用方线程。
|
||||
*/
|
||||
static JSONArray mergeAirOptionChargeArrays(JSONObject opt) {
|
||||
JSONArray out = new JSONArray();
|
||||
if (opt == null) {
|
||||
return out;
|
||||
}
|
||||
Set<String> seen = new HashSet<>();
|
||||
for (Object key : new Object[]{"departureCharges", "departure_charges", "charges", "feeItems", "fee_items"}) {
|
||||
JSONArray part = parseFeeRows(opt.get(String.valueOf(key)));
|
||||
for (int i = 0; i < part.size(); i++) {
|
||||
JSONObject ch = part.getJSONObject(i);
|
||||
if (ch == null) {
|
||||
continue;
|
||||
}
|
||||
String name = firstNonBlank(ch.getString("chargeName"), ch.getString("feeName"), ch.getString("name"));
|
||||
if (StringUtils.isBlank(name)) {
|
||||
continue;
|
||||
}
|
||||
String dedupe = name.trim().toLowerCase(Locale.ROOT);
|
||||
if (!seen.add(dedupe)) {
|
||||
continue;
|
||||
}
|
||||
out.add(ch);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 明细里没有运输/空运费时,用舱位 unitPrice×计费重或 salePrice 注入一行「空运费」。
|
||||
* WO202610090014:departureCharges 只有增点/拆板,salePrice=4750.95、计费重=500.1。
|
||||
*/
|
||||
static void injectAirFreightLineIfMissing(List<Map<String, String>> lines, JSONObject opt,
|
||||
String chargeableWeightKg, String currency) {
|
||||
if (lines == null || opt == null) {
|
||||
return;
|
||||
}
|
||||
for (Map<String, String> line : lines) {
|
||||
if (line != null && isAirWeightFeeName(line.get("name"))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
String unitPrice = firstNonBlank(opt.getString("unitPrice"), opt.getString("unit_price"),
|
||||
opt.getString("pricePerKg"), opt.getString("freightRate"));
|
||||
String salePrice = firstNonBlank(opt.getString("salePrice"), opt.getString("sale_price"),
|
||||
opt.getString("totalSalePrice"), opt.getString("airFreight"), opt.getString("freight"));
|
||||
String cw = StringUtils.trimToEmpty(chargeableWeightKg);
|
||||
if (cw.isEmpty() || "-".equals(cw)) {
|
||||
cw = "";
|
||||
}
|
||||
String amount = "";
|
||||
String price = unitPrice;
|
||||
if (StringUtils.isNotBlank(unitPrice) && StringUtils.isNotBlank(cw)) {
|
||||
amount = multiplyDecimal(unitPrice, cw);
|
||||
} else if (StringUtils.isNotBlank(salePrice) && !"-".equals(salePrice)) {
|
||||
amount = salePrice;
|
||||
if (StringUtils.isBlank(price) && StringUtils.isNotBlank(cw)) {
|
||||
price = divideDecimal(salePrice, cw);
|
||||
}
|
||||
}
|
||||
if (StringUtils.isBlank(amount) || "-".equals(amount)) {
|
||||
return;
|
||||
}
|
||||
Map<String, String> air = new LinkedHashMap<>();
|
||||
air.put("name", "空运费");
|
||||
air.put("project", "空运段");
|
||||
air.put("amount", amount);
|
||||
if (StringUtils.isNotBlank(price)) {
|
||||
air.put("unit_price", price);
|
||||
} else {
|
||||
air.put("unit_price", amount);
|
||||
}
|
||||
if (StringUtils.isNotBlank(cw)) {
|
||||
air.put("quantity", cw);
|
||||
air.put("unit", "KG");
|
||||
}
|
||||
if (StringUtils.isNotBlank(currency)) {
|
||||
air.put("currency", currency);
|
||||
}
|
||||
lines.add(0, air);
|
||||
}
|
||||
|
||||
private static Object firstNonNull(Object... vals) {
|
||||
if (vals == null) {
|
||||
return null;
|
||||
@@ -4944,43 +5267,146 @@ public final class QuoteTemplateExcelSupport {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 空运运输费:单价 × 计费重 = 行金额。
|
||||
* 出单时调用;有单价+数量则重算金额(数值比较,避免 11.00≠11.0 漏算)。
|
||||
* 空运运输费:单价 × 计费重 = 行金额;缺单位时用询价重量单位(默认 KG)。
|
||||
* <p>
|
||||
* 手工报价常只有金额(WO020):无计费重时补 数量=1、单价=金额,避免单价/数量空白。
|
||||
*/
|
||||
public static void enrichAirWeightFeeRows(List<Map<String, String>> lines, String chargeableWeightKg) {
|
||||
enrichAirWeightFeeRows(lines, chargeableWeightKg, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param weightUnit 询价重量单位(如 KG/KGS/公斤);空则按 KG
|
||||
*/
|
||||
public static void enrichAirWeightFeeRows(List<Map<String, String>> lines, String chargeableWeightKg,
|
||||
String weightUnit) {
|
||||
if (lines == null || lines.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String chargeable = StringUtils.trimToEmpty(chargeableWeightKg);
|
||||
if (chargeable.isEmpty() || "-".equals(chargeable)) {
|
||||
return;
|
||||
if ("-".equals(chargeable)) {
|
||||
chargeable = "";
|
||||
}
|
||||
String unitDefault = normalizeWeightUnit(weightUnit);
|
||||
for (Map<String, String> line : lines) {
|
||||
if (line == null || !isAirWeightFeeName(line.get("name"))) {
|
||||
continue;
|
||||
}
|
||||
// 无 TMS / 手工报价常缺单位:先补单位,再按计费重或金额补数量/单价
|
||||
if (StringUtils.isBlank(line.get("unit"))) {
|
||||
line.put("unit", unitDefault);
|
||||
}
|
||||
String unitPrice = firstNonBlank(line.get("unit_price"), line.get("unitPrice"));
|
||||
String qty = StringUtils.trimToEmpty(line.get("quantity"));
|
||||
String amount = StringUtils.trimToEmpty(line.get("amount"));
|
||||
String unit = StringUtils.trimToEmpty(line.get("unit"));
|
||||
if ("-".equals(qty)) {
|
||||
qty = "";
|
||||
}
|
||||
if ("-".equals(amount)) {
|
||||
amount = "";
|
||||
}
|
||||
if (chargeable.isEmpty()) {
|
||||
// 无计费重:手工只有总额 → 数量 1、单价=金额(WO020 空运费)
|
||||
if (qty.isEmpty() && !amount.isEmpty()) {
|
||||
line.put("quantity", "1");
|
||||
qty = "1";
|
||||
}
|
||||
if (unitPrice.isEmpty() && !amount.isEmpty()) {
|
||||
if ("1".equals(qty) || qty.isEmpty()) {
|
||||
line.put("unit_price", amount);
|
||||
} else {
|
||||
String divided = divideDecimal(amount, qty);
|
||||
if (!divided.isEmpty()) {
|
||||
line.put("unit_price", divided);
|
||||
} else {
|
||||
line.put("unit_price", amount);
|
||||
}
|
||||
}
|
||||
} else if (!unitPrice.isEmpty() && qty.isEmpty()) {
|
||||
line.put("quantity", "1");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (qty.isEmpty()) {
|
||||
line.put("quantity", chargeable);
|
||||
qty = chargeable;
|
||||
}
|
||||
// TMS 常给「板数」;按计费重计价统一 KG
|
||||
line.put("unit", "KG");
|
||||
// 有计费重时统一按重量计价单位
|
||||
line.put("unit", unitDefault);
|
||||
if (unitPrice.isEmpty() && !amount.isEmpty()) {
|
||||
line.put("unit_price", amount);
|
||||
unitPrice = amount;
|
||||
String divided = divideDecimal(amount, qty);
|
||||
line.put("unit_price", StringUtils.isNotBlank(divided) ? divided : amount);
|
||||
unitPrice = line.get("unit_price");
|
||||
}
|
||||
if (!unitPrice.isEmpty() && !qty.isEmpty()) {
|
||||
String product = multiplyDecimal(unitPrice, qty);
|
||||
if (!product.isEmpty() && (amount.isEmpty() || !sameDecimal(amount, product))) {
|
||||
line.put("amount", product);
|
||||
// 已有明确总额时不要用单价×数量覆盖(手工总额优先)
|
||||
if (amount.isEmpty()) {
|
||||
line.put("amount", product);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 起运港固定费(增点费等):补单位/数量/单价
|
||||
enrichFixedAirAddonFeeRows(lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* 空运起运附加费(增点/操作/文件等):手工常只有金额。
|
||||
* 补单位=票、数量=1、单价=金额(WO020 增点费)。
|
||||
*/
|
||||
public static void enrichFixedAirAddonFeeRows(List<Map<String, String>> lines) {
|
||||
if (lines == null || lines.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (Map<String, String> line : lines) {
|
||||
if (line == null || isAirWeightFeeName(line.get("name"))) {
|
||||
continue;
|
||||
}
|
||||
String name = StringUtils.trimToEmpty(line.get("name"));
|
||||
if (name.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
// 增点费等禁止留在「空运段」(手工/产品报价可能误带 project=空运段)
|
||||
line.put("project", "起运港");
|
||||
if (StringUtils.isBlank(line.get("unit"))) {
|
||||
line.put("unit", "票");
|
||||
}
|
||||
String qty = StringUtils.trimToEmpty(line.get("quantity"));
|
||||
String amount = StringUtils.trimToEmpty(line.get("amount"));
|
||||
String unitPrice = firstNonBlank(line.get("unit_price"), line.get("unitPrice"));
|
||||
if (qty.isEmpty() || "-".equals(qty)) {
|
||||
line.put("quantity", "1");
|
||||
qty = "1";
|
||||
}
|
||||
if ((unitPrice.isEmpty() || "-".equals(unitPrice)) && StringUtils.isNotBlank(amount) && !"-".equals(amount)) {
|
||||
if ("1".equals(qty)) {
|
||||
line.put("unit_price", amount);
|
||||
} else {
|
||||
String divided = divideDecimal(amount, qty);
|
||||
line.put("unit_price", StringUtils.isNotBlank(divided) ? divided : amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 询价重量单位归一:KG / KGS / 公斤 → KG;空默认 KG。
|
||||
*/
|
||||
public static String normalizeWeightUnit(String raw) {
|
||||
String u = StringUtils.trimToEmpty(raw);
|
||||
if (u.isEmpty() || "-".equals(u)) {
|
||||
return "KG";
|
||||
}
|
||||
String compact = u.replaceAll("\\s+", "").toUpperCase(Locale.ROOT);
|
||||
if (compact.contains("公斤") || "KG".equals(compact) || "KGS".equals(compact)
|
||||
|| "KILOGRAM".equals(compact) || "KILOGRAMS".equals(compact)) {
|
||||
return "KG";
|
||||
}
|
||||
return u;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -5003,12 +5429,15 @@ public final class QuoteTemplateExcelSupport {
|
||||
return feeQuantityOrDefault(quantity, "");
|
||||
}
|
||||
|
||||
|
||||
public static boolean isAirWeightFeeName(String name) {
|
||||
String n = StringUtils.trimToEmpty(name);
|
||||
if (n.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (n.contains("提") || n.contains("送") || n.contains("人工") || n.contains("报关")
|
||||
// 起运附加费禁止归进「空运段」(WO014/图2:增点费曾误留在空运段样例行)
|
||||
if (n.contains("增点") || n.contains("拆板") || n.contains("打板") || n.contains("提")
|
||||
|| n.contains("送") || n.contains("人工") || n.contains("报关")
|
||||
|| n.contains("操作") || n.contains("文件") || n.contains("杂费")) {
|
||||
return false;
|
||||
}
|
||||
@@ -5035,6 +5464,20 @@ public final class QuoteTemplateExcelSupport {
|
||||
}
|
||||
}
|
||||
|
||||
/** 除法:空运费总额 ÷ 计费重 → 单价;除数为 0 或非法时返回空串。 */
|
||||
static String divideDecimal(String left, String right) {
|
||||
try {
|
||||
java.math.BigDecimal a = new java.math.BigDecimal(left.trim().replace(",", ""));
|
||||
java.math.BigDecimal b = new java.math.BigDecimal(right.trim().replace(",", ""));
|
||||
if (b.compareTo(java.math.BigDecimal.ZERO) == 0) {
|
||||
return "";
|
||||
}
|
||||
return a.divide(b, 4, java.math.RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 金额/数量/单价写成数字,SUM 才能加算;名称等仍写文本。
|
||||
*/
|
||||
|
||||
+128
-9
@@ -22,7 +22,8 @@ import java.util.Locale;
|
||||
* <p>
|
||||
* Jeecg MinIO/OSS 上传返回完整 http(s) URL,Windows 上 {@code Paths.get("http://...")}
|
||||
* 会在冒号处抛 Illegal char <:>。本类先认远程 URL,拉到本地缓存再给 POI / 下载。
|
||||
* 副作用:写 {@code upload/inquiry/quote-templates/_remote-cache/}。
|
||||
* 副作用:写 {@code upload/inquiry/quote-templates/_remote-cache/},以及
|
||||
* {@code upload/inquiry/quote-templates/by-sha/{sha256}.xlsx} 本地镜像(上传时写入,远程损坏时可回退)。
|
||||
* 线程:跟随调用方 HTTP 线程;不持有全局锁。
|
||||
*/
|
||||
@Slf4j
|
||||
@@ -70,18 +71,75 @@ public class QuoteTemplateObjectStore {
|
||||
* @return 已存在的本地文件,或从对象存储落地后的缓存文件
|
||||
*/
|
||||
public Path resolve(String objectKey) {
|
||||
return resolve(objectKey, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析模板文件,并在提供 expectedSha256 时校验内容指纹。
|
||||
* <p>
|
||||
* 为何:MinIO 对象偶发被掏空/覆盖后,旧逻辑只要缓存「非空」就直接用,导致空运报价费目名全空。
|
||||
* 有 sha 时:缓存/远程不匹配则删缓存重拉;仍不匹配则回退 {@code by-sha/{sha}.xlsx}。
|
||||
*
|
||||
* @param objectKey 主账 version.object_key(本地相对路径或 http(s) URL)
|
||||
* @param expectedSha256 版本表记录的 sha256(可空;空则只做路径解析,与历史行为一致)
|
||||
* @return 可读本地文件
|
||||
*/
|
||||
public Path resolve(String objectKey, String expectedSha256) {
|
||||
if (StringUtils.isBlank(objectKey)) {
|
||||
throw new IllegalArgumentException("objectKey 空");
|
||||
}
|
||||
String key = objectKey.trim();
|
||||
String want = normalizeSha(expectedSha256);
|
||||
|
||||
if (want != null) {
|
||||
Path bySha = tryByShaMirror(want);
|
||||
if (bySha != null) {
|
||||
return bySha;
|
||||
}
|
||||
}
|
||||
|
||||
Path resolved;
|
||||
if (isRemoteUrl(key)) {
|
||||
return fetchRemoteToCache(key);
|
||||
resolved = fetchRemoteToCache(key, want);
|
||||
} else {
|
||||
resolved = tryLocalFile(key);
|
||||
if (resolved == null) {
|
||||
throw new IllegalStateException("找不到模板文件: " + key);
|
||||
}
|
||||
if (want != null && !shaMatches(resolved, want)) {
|
||||
Path fallback = tryByShaMirror(want);
|
||||
if (fallback != null) {
|
||||
log.warn("本地模板 sha 不匹配,改用 by-sha 镜像 key={}", key);
|
||||
return fallback;
|
||||
}
|
||||
throw new IllegalStateException("模板文件 sha256 不匹配: " + key);
|
||||
}
|
||||
}
|
||||
Path local = tryLocalFile(key);
|
||||
if (local != null) {
|
||||
return local;
|
||||
|
||||
return resolved;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传成功后写一份按内容指纹命名的本地镜像,供远程损坏时回退。
|
||||
* <p>
|
||||
* 副作用:写 {@code upload/inquiry/quote-templates/by-sha/{sha256}.xlsx}。
|
||||
* 失败只记日志,不阻断上传主流程。
|
||||
*/
|
||||
public void writeByShaMirror(byte[] fileBytes, String sha256Hex) {
|
||||
String sha = normalizeSha(sha256Hex);
|
||||
if (fileBytes == null || fileBytes.length == 0 || sha == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Path dir = Paths.get(StringUtils.defaultIfBlank(uploadPath, System.getProperty("java.io.tmpdir")),
|
||||
BIZ_PATH, "by-sha");
|
||||
Files.createDirectories(dir);
|
||||
Path target = dir.resolve(sha + ".xlsx");
|
||||
Files.write(target, fileBytes);
|
||||
log.info("模板 by-sha 镜像已写入 sha={} bytes={}", sha.substring(0, 12), fileBytes.length);
|
||||
} catch (Exception e) {
|
||||
log.warn("模板 by-sha 镜像写入失败 sha={} err={}", sha, e.getMessage());
|
||||
}
|
||||
throw new IllegalStateException("找不到模板文件: " + key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,9 +196,11 @@ public class QuoteTemplateObjectStore {
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 MinIO/OSS 拉到本地缓存。同一 URL 只落一次(文件名带时间戳,一般不会覆盖)。
|
||||
* 从 MinIO/OSS 拉到本地缓存。同一 URL 缓存文件名 = sha256(url)。
|
||||
* <p>
|
||||
* 有 expectedSha 时:已有缓存若指纹不对则删除重拉;重拉后仍不对则回退 by-sha 镜像。
|
||||
*/
|
||||
private Path fetchRemoteToCache(String url) {
|
||||
private Path fetchRemoteToCache(String url, String expectedSha) {
|
||||
Path cacheDir = Paths.get(StringUtils.defaultIfBlank(uploadPath, System.getProperty("java.io.tmpdir")),
|
||||
BIZ_PATH, "_remote-cache");
|
||||
try {
|
||||
@@ -152,7 +212,11 @@ public class QuoteTemplateObjectStore {
|
||||
Path cacheFile = cacheDir.resolve(DigestUtils.sha256Hex(url) + ext);
|
||||
try {
|
||||
if (Files.isRegularFile(cacheFile) && Files.size(cacheFile) > 0) {
|
||||
return cacheFile;
|
||||
if (expectedSha == null || shaMatches(cacheFile, expectedSha)) {
|
||||
return cacheFile;
|
||||
}
|
||||
log.warn("模板远程缓存 sha 不匹配,删除后重拉 file={}", cacheFile.getFileName());
|
||||
Files.deleteIfExists(cacheFile);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// 读缓存失败则重新拉取
|
||||
@@ -161,11 +225,66 @@ public class QuoteTemplateObjectStore {
|
||||
Files.copy(in, cacheFile, StandardCopyOption.REPLACE_EXISTING);
|
||||
} catch (Exception e) {
|
||||
log.error("对象存储落地失败 url={}", url, e);
|
||||
if (expectedSha != null) {
|
||||
Path fallback = tryByShaMirror(expectedSha);
|
||||
if (fallback != null) {
|
||||
log.warn("对象存储读取失败,改用 by-sha 镜像 url={}", url);
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("对象存储读取失败: " + e.getMessage(), e);
|
||||
}
|
||||
if (expectedSha != null && !shaMatches(cacheFile, expectedSha)) {
|
||||
log.error("对象存储模板 sha256 与版本表不一致 urlHash={}",
|
||||
DigestUtils.sha256Hex(url).substring(0, 12));
|
||||
try {
|
||||
Files.deleteIfExists(cacheFile);
|
||||
} catch (Exception ignored) {
|
||||
// ignore
|
||||
}
|
||||
Path fallback = tryByShaMirror(expectedSha);
|
||||
if (fallback != null) {
|
||||
log.warn("远程模板损坏,改用 by-sha 镜像");
|
||||
return fallback;
|
||||
}
|
||||
throw new IllegalStateException("对象存储模板内容与版本 sha256 不一致");
|
||||
}
|
||||
return cacheFile;
|
||||
}
|
||||
|
||||
private Path tryByShaMirror(String sha) {
|
||||
if (StringUtils.isBlank(sha)) {
|
||||
return null;
|
||||
}
|
||||
Path p = Paths.get(StringUtils.defaultIfBlank(uploadPath, System.getProperty("java.io.tmpdir")),
|
||||
BIZ_PATH, "by-sha", sha + ".xlsx");
|
||||
try {
|
||||
if (Files.isRegularFile(p) && Files.size(p) > 0 && shaMatches(p, sha)) {
|
||||
return p;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String normalizeSha(String sha) {
|
||||
if (StringUtils.isBlank(sha)) {
|
||||
return null;
|
||||
}
|
||||
String s = sha.trim().toLowerCase(Locale.ROOT);
|
||||
return s.matches("[0-9a-f]{64}") ? s : null;
|
||||
}
|
||||
|
||||
private static boolean shaMatches(Path file, String expectedSha) {
|
||||
try {
|
||||
String actual = DigestUtils.sha256Hex(Files.readAllBytes(file)).toLowerCase(Locale.ROOT);
|
||||
return expectedSha.equals(actual);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private InputStream openRemoteStream(String url) {
|
||||
String[] parts = splitStorageUrl(url, MinioUtil.getMinioUrl());
|
||||
if (parts != null) {
|
||||
|
||||
+7
-2
@@ -11,6 +11,7 @@ import org.jeecg.modules.inquiry.entity.InquiryQuote;
|
||||
import org.jeecg.modules.inquiry.entity.InquiryTicket;
|
||||
import org.jeecg.modules.inquiry.mapper.InquiryQuoteMapper;
|
||||
import org.jeecg.modules.inquiry.service.IInquiryWorkOrderService;
|
||||
import org.jeecg.modules.inquiry.template.QuoteTemplateExcelSupport;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -294,7 +295,7 @@ public class InquiryTmsCabinService {
|
||||
return fail("release_need_lock", "本单还没有成功锁舱记录");
|
||||
}
|
||||
if (!properties.lockConfigured()) {
|
||||
return fail("lock_disabled", "主账未开放释放");
|
||||
return fail("lock_disabled", "主账未开放取消舱位");
|
||||
}
|
||||
Map<String, Object> req = new LinkedHashMap<>();
|
||||
req.put("lockId", lockId);
|
||||
@@ -363,7 +364,7 @@ public class InquiryTmsCabinService {
|
||||
return out;
|
||||
} catch (RuntimeException ex) {
|
||||
log.warn("tms.release fail wo={} err={}", ticket.getWorkOrderNo(), ex.getMessage());
|
||||
return fail("release_fail", firstNonBlank(ex.getMessage(), "释放失败"));
|
||||
return fail("release_fail", firstNonBlank(ex.getMessage(), "取消舱位失败"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1050,6 +1051,10 @@ public class InquiryTmsCabinService {
|
||||
item.put("currency", currency);
|
||||
}
|
||||
String unit = text(row, "unit", "单位");
|
||||
// 手工报价常只有金额无单位;空运运输费锁舱必须带 unit(WO007:单位未传 TMS)
|
||||
if (QuoteTemplateExcelSupport.isAirWeightFeeName(name)) {
|
||||
unit = QuoteTemplateExcelSupport.normalizeWeightUnit(unit);
|
||||
}
|
||||
if (StringUtils.isNotBlank(unit)) {
|
||||
item.put("unit", unit);
|
||||
}
|
||||
|
||||
+96
-8
@@ -20,9 +20,12 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
@@ -803,17 +806,13 @@ public class InquiryTmsQueryService {
|
||||
continue;
|
||||
}
|
||||
Map<?, ?> opt = (Map<?, ?>) optObj;
|
||||
Object charges = first(opt.get("departureCharges"), opt.get("departure_charges"),
|
||||
opt.get("charges"), opt.get("feeItems"));
|
||||
if (!(charges instanceof List)) {
|
||||
continue;
|
||||
}
|
||||
// 合并 departureCharges + feeItems,避免只取附加费丢掉空运费
|
||||
List<Map<?, ?>> charges = mergeAirOptionChargeMaps(opt);
|
||||
String optCcy = firstText(opt.get("currency"), headerCurrency);
|
||||
for (Object one : (List<?>) charges) {
|
||||
if (!(one instanceof Map)) {
|
||||
for (Map<?, ?> ch : charges) {
|
||||
if (ch == null) {
|
||||
continue;
|
||||
}
|
||||
Map<?, ?> ch = (Map<?, ?>) one;
|
||||
String name = firstText(ch.get("chargeName"), ch.get("feeName"), ch.get("name"));
|
||||
String unitPrice = firstText(ch.get("unitPrice"), ch.get("unit_price"), ch.get("salePrice"), ch.get("amount"));
|
||||
if (StringUtils.isBlank(name) || StringUtils.isBlank(unitPrice)) {
|
||||
@@ -830,6 +829,8 @@ public class InquiryTmsQueryService {
|
||||
// 先把单价写入 amount;运输费会在 enrich 里改成 单价×计费重
|
||||
addFeeLine(out, name, unitPrice, lineCcy, extras);
|
||||
}
|
||||
// departureCharges 只有附加费时,用舱位 salePrice 补空运费(与出单 parse 对齐)
|
||||
injectAirFreightFeeLineIfMissing(out, opt, headerCurrency);
|
||||
// 通常只用首个舱位选项的费用明细
|
||||
if (!out.isEmpty()) {
|
||||
break;
|
||||
@@ -838,6 +839,93 @@ public class InquiryTmsQueryService {
|
||||
return out;
|
||||
}
|
||||
|
||||
/** 合并舱位 departureCharges / feeItems,同名去重。 */
|
||||
@SuppressWarnings("unchecked")
|
||||
static List<Map<?, ?>> mergeAirOptionChargeMaps(Map<?, ?> opt) {
|
||||
List<Map<?, ?>> out = new ArrayList<>();
|
||||
if (opt == null) {
|
||||
return out;
|
||||
}
|
||||
Set<String> seen = new HashSet<>();
|
||||
for (Object key : new Object[]{"departureCharges", "departure_charges", "charges", "feeItems", "fee_items"}) {
|
||||
Object raw = opt.get(key);
|
||||
if (!(raw instanceof List)) {
|
||||
continue;
|
||||
}
|
||||
for (Object one : (List<?>) raw) {
|
||||
if (!(one instanceof Map)) {
|
||||
continue;
|
||||
}
|
||||
Map<?, ?> ch = (Map<?, ?>) one;
|
||||
String name = firstText(ch.get("chargeName"), ch.get("feeName"), ch.get("name"));
|
||||
if (StringUtils.isBlank(name)) {
|
||||
continue;
|
||||
}
|
||||
String dedupe = name.trim().toLowerCase(Locale.ROOT);
|
||||
if (!seen.add(dedupe)) {
|
||||
continue;
|
||||
}
|
||||
out.add(ch);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查价投影 fee_lines:明细无运输/空运费时,用舱位 salePrice/unitPrice 注入。
|
||||
* 与 QuoteTemplateExcelSupport.injectAirFreightLineIfMissing 口径一致。
|
||||
*/
|
||||
static void injectAirFreightFeeLineIfMissing(List<Map<String, String>> lines, Map<?, ?> opt, String headerCurrency) {
|
||||
if (lines == null || opt == null) {
|
||||
return;
|
||||
}
|
||||
for (Map<String, String> line : lines) {
|
||||
if (line != null && isAirWeightFeeName(line.get("name"))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
String unitPrice = firstText(opt.get("unitPrice"), opt.get("unit_price"), opt.get("pricePerKg"), opt.get("freightRate"));
|
||||
String salePrice = firstText(opt.get("salePrice"), opt.get("sale_price"), opt.get("totalSalePrice"),
|
||||
opt.get("airFreight"), opt.get("freight"));
|
||||
String cw = firstText(opt.get("chargeableWeightKg"), opt.get("chargeable_weight_kg"));
|
||||
String amount = "";
|
||||
String price = unitPrice;
|
||||
if (StringUtils.isNotBlank(unitPrice) && StringUtils.isNotBlank(cw)) {
|
||||
amount = multiplyDecimal(unitPrice, cw);
|
||||
} else if (StringUtils.isNotBlank(salePrice) && !"-".equals(salePrice)) {
|
||||
amount = salePrice;
|
||||
if (StringUtils.isBlank(price) && StringUtils.isNotBlank(cw)) {
|
||||
try {
|
||||
java.math.BigDecimal a = new java.math.BigDecimal(salePrice.trim().replace(",", ""));
|
||||
java.math.BigDecimal b = new java.math.BigDecimal(cw.trim().replace(",", ""));
|
||||
if (b.compareTo(java.math.BigDecimal.ZERO) != 0) {
|
||||
price = a.divide(b, 4, java.math.RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
price = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StringUtils.isBlank(amount) || "-".equals(amount)) {
|
||||
return;
|
||||
}
|
||||
String ccy = firstText(opt.get("currency"), headerCurrency);
|
||||
Map<String, String> extras = new LinkedHashMap<>();
|
||||
putExtra(extras, "project", "空运段");
|
||||
putExtra(extras, "unit_price", StringUtils.isNotBlank(price) ? price : amount);
|
||||
if (StringUtils.isNotBlank(cw)) {
|
||||
putExtra(extras, "quantity", cw);
|
||||
putExtra(extras, "unit", "KG");
|
||||
}
|
||||
// 先 append 再挪到最前:空运段在附加费之前
|
||||
int before = lines.size();
|
||||
addFeeLine(lines, "空运费", amount, ccy, extras);
|
||||
if (lines.size() > before) {
|
||||
Map<String, String> injected = lines.remove(lines.size() - 1);
|
||||
lines.add(0, injected);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 空运运输费:单价 × 计费重 = 行金额。
|
||||
* <p>
|
||||
|
||||
+147
-10
@@ -2,6 +2,7 @@ package org.jeecg.modules.inquiry.template;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.poi.ss.usermodel.DataFormatter;
|
||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||
import org.apache.poi.ss.usermodel.PrintSetup;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
@@ -38,6 +39,31 @@ public class QuoteTemplateFillTest {
|
||||
assertEquals("14669.60", rows.getJSONObject(0).getString("amount"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void manualAirFeesOnlyAmountFillsUnitPriceQtyAndUnit() {
|
||||
// WO020:手工只有金额 → 空运费补 KG/1/单价;增点费补 票/1/单价
|
||||
java.util.List<Map<String, String>> lines = new java.util.ArrayList<>();
|
||||
Map<String, String> air = new HashMap<>();
|
||||
air.put("name", "空运费");
|
||||
air.put("amount", "150");
|
||||
air.put("currency", "CNY");
|
||||
lines.add(air);
|
||||
Map<String, String> add = new HashMap<>();
|
||||
add.put("name", "增点费");
|
||||
add.put("amount", "200");
|
||||
add.put("currency", "CNY");
|
||||
add.put("project", "空运段"); // 误归空运段也要纠正
|
||||
lines.add(add);
|
||||
QuoteTemplateExcelSupport.enrichAirWeightFeeRows(lines, "", "KG");
|
||||
assertEquals("KG", lines.get(0).get("unit"));
|
||||
assertEquals("1", lines.get(0).get("quantity"));
|
||||
assertEquals("150", lines.get(0).get("unit_price"));
|
||||
assertEquals("票", lines.get(1).get("unit"));
|
||||
assertEquals("1", lines.get(1).get("quantity"));
|
||||
assertEquals("200", lines.get(1).get("unit_price"));
|
||||
assertEquals("起运港", lines.get(1).get("project"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseFeeLinesDoubleEncoded() {
|
||||
JSONArray rows = QuoteTemplateExcelSupport.parseFeeRows("[{\"name\":\"空运费\",\"amount\":\"14669.60\"}]");
|
||||
@@ -242,8 +268,8 @@ public class QuoteTemplateFillTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* 回归:无 TMS 费用行时,费用表「项目=起运港」不得把 pol 写进右侧「费用名称」。
|
||||
* 对应 WO202609230026 空运协同出单:空运段旁费用名称被写成「广州」。
|
||||
* 回归:无 TMS 费用行时,不得把 pol 写进费用名称;
|
||||
* 并保留模板项目骨架「空运段/起运港」(图2),禁止掏空项目列。
|
||||
*/
|
||||
@Test
|
||||
public void airNoTmsMustNotWritePolIntoFeeNameColumn() throws Exception {
|
||||
@@ -267,13 +293,17 @@ public class QuoteTemplateFillTest {
|
||||
head.createCell(7).setCellValue("备注");
|
||||
org.apache.poi.ss.usermodel.Row airSeg = sheet.createRow(16);
|
||||
airSeg.createCell(0).setCellValue("空运段");
|
||||
airSeg.createCell(1).setCellValue("");
|
||||
airSeg.createCell(1).setCellValue("空运费");
|
||||
org.apache.poi.ss.usermodel.Row polSeg = sheet.createRow(17);
|
||||
polSeg.createCell(0).setCellValue("起运港");
|
||||
polSeg.createCell(1).setCellValue("");
|
||||
org.apache.poi.ss.usermodel.Row otherSeg = sheet.createRow(18);
|
||||
polSeg.createCell(1).setCellValue("操作费");
|
||||
org.apache.poi.ss.usermodel.Row destSeg = sheet.createRow(18);
|
||||
destSeg.createCell(0).setCellValue("目的港");
|
||||
destSeg.createCell(1).setCellValue("目的港派送费");
|
||||
org.apache.poi.ss.usermodel.Row otherSeg = sheet.createRow(19);
|
||||
otherSeg.createCell(0).setCellValue("其他");
|
||||
otherSeg.createCell(1).setCellValue("");
|
||||
otherSeg.createCell(1).setCellValue("*其他杂费");
|
||||
otherSeg.createCell(7).setCellValue("发生时收取");
|
||||
try (java.io.OutputStream os = Files.newOutputStream(src)) {
|
||||
wb.write(os);
|
||||
}
|
||||
@@ -300,13 +330,22 @@ public class QuoteTemplateFillTest {
|
||||
b16 = fmt.formatCellValue(sheet.getRow(16).getCell(1));
|
||||
b17 = fmt.formatCellValue(sheet.getRow(17).getCell(1));
|
||||
b18 = fmt.formatCellValue(sheet.getRow(18).getCell(1));
|
||||
String b19 = fmt.formatCellValue(sheet.getRow(19).getCell(1));
|
||||
String h19 = fmt.formatCellValue(sheet.getRow(19).getCell(7));
|
||||
String cargoPol = fmt.formatCellValue(sheet.getRow(5).getCell(1));
|
||||
assertTrue(cargoPol.contains("广州"), "货物区起运港应写入广州,实际=" + cargoPol);
|
||||
assertFalse(b16.contains("广州"), "空运段旁费用名称不应是起运港,实际=" + b16);
|
||||
assertFalse(b17.contains("广州"), "起运港项目旁费用名称不应是起运港,实际=" + b17);
|
||||
assertFalse(b18.contains("广州"), "其他旁费用名称不应是起运港,实际=" + b18);
|
||||
assertEquals("起运港", fmt.formatCellValue(sheet.getRow(17).getCell(0)));
|
||||
assertFalse(b16.contains("广州"), "费用名称不应是起运港,实际=" + b16);
|
||||
assertFalse(b17.contains("广州"), "费用名称不应是起运港,实际=" + b17);
|
||||
assertFalse(b18.contains("广州"), "费用名称不应是起运港,实际=" + b18);
|
||||
// 无 fee_rows:项目骨架保留;样例费目名/备注清掉(有费用的才显示行)
|
||||
assertEquals("空运段", fmt.formatCellValue(sheet.getRow(16).getCell(0)));
|
||||
assertEquals("起运港", fmt.formatCellValue(sheet.getRow(17).getCell(0)));
|
||||
assertEquals("目的港", fmt.formatCellValue(sheet.getRow(18).getCell(0)));
|
||||
assertEquals("", b16.trim(), "无费用时空运费样例名应清空,实际=" + b16);
|
||||
assertEquals("", b17.trim(), "无费用时操作费样例名应清空,实际=" + b17);
|
||||
assertEquals("", b18.trim(), "无费用时目的港派送费样例名应清空,实际=" + b18);
|
||||
assertEquals("", b19.trim(), "无费用时其他杂费样例名应清空,实际=" + b19);
|
||||
assertEquals("", h19.trim(), "无费用时样例备注应清空,实际=" + h19);
|
||||
} finally {
|
||||
Files.deleteIfExists(src);
|
||||
Files.deleteIfExists(out);
|
||||
@@ -857,6 +896,104 @@ public class QuoteTemplateFillTest {
|
||||
assertEquals("16670", QuoteTemplateExcelSupport.feeQuantityOrDefault("16670", "运输费"));
|
||||
}
|
||||
|
||||
/**
|
||||
* WO014:departureCharges 只有增点/拆板时,必须注入空运费,且项目列归类正确。
|
||||
*/
|
||||
@Test
|
||||
public void parseAirDepartureChargesInjectsFreightAndProjects() {
|
||||
String airOptions = "["
|
||||
+ "{\"optionNo\":\"AIR-OPT01\",\"salePrice\":4750.95,\"currency\":\"CNY\","
|
||||
+ "\"chargeableWeightKg\":500.1,"
|
||||
+ "\"departureCharges\":["
|
||||
+ "{\"chargeName\":\"增点费\",\"unitPrice\":100.0,\"unit\":\"点\",\"currency\":\"CNY\"},"
|
||||
+ "{\"chargeName\":\"拆板费\",\"unitPrice\":100.0,\"unit\":\"板数\",\"currency\":\"USD\"}"
|
||||
+ "]}]";
|
||||
JSONArray rows = QuoteTemplateExcelSupport.parseAirDepartureChargeRows(
|
||||
airOptions, null, "500.1", "CNY");
|
||||
assertEquals(3, rows.size());
|
||||
assertEquals("空运费", rows.getJSONObject(0).getString("name"));
|
||||
assertEquals("空运段", rows.getJSONObject(0).getString("project"));
|
||||
assertEquals("4750.95", rows.getJSONObject(0).getString("amount"));
|
||||
assertEquals("增点费", rows.getJSONObject(1).getString("name"));
|
||||
assertEquals("起运港", rows.getJSONObject(1).getString("project"));
|
||||
assertEquals("拆板费", rows.getJSONObject(2).getString("name"));
|
||||
assertEquals("起运港", rows.getJSONObject(2).getString("project"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 映射未标 project 列时,表头「项目」仍要写入,增点费不能留在模板样例「空运段」。
|
||||
*/
|
||||
@Test
|
||||
public void airFeeProjectColumnFilledFromHeaderWhenMappingOmitsIt() throws Exception {
|
||||
Path src = Files.createTempFile("quote-air-proj-src", ".xlsx");
|
||||
Path out = Files.createTempFile("quote-air-proj-out", ".xlsx");
|
||||
try (Workbook wb = new XSSFWorkbook()) {
|
||||
Sheet sheet = wb.createSheet("Sheet2");
|
||||
org.apache.poi.ss.usermodel.Row head = sheet.createRow(15);
|
||||
head.createCell(0).setCellValue("项目");
|
||||
head.createCell(1).setCellValue("费用名称");
|
||||
head.createCell(2).setCellValue("单位");
|
||||
head.createCell(3).setCellValue("币别");
|
||||
head.createCell(4).setCellValue("单价");
|
||||
head.createCell(5).setCellValue("数量");
|
||||
head.createCell(6).setCellValue("金额");
|
||||
org.apache.poi.ss.usermodel.Row r1 = sheet.createRow(16);
|
||||
r1.createCell(0).setCellValue("空运段");
|
||||
r1.createCell(1).setCellValue("样例费");
|
||||
r1.createCell(6).setCellValue(1.0);
|
||||
org.apache.poi.ss.usermodel.Row r2 = sheet.createRow(17);
|
||||
r2.createCell(0).setCellValue("起运港");
|
||||
r2.createCell(1).setCellValue("样例2");
|
||||
r2.createCell(6).setCellValue(1.0);
|
||||
org.apache.poi.ss.usermodel.Row total = sheet.createRow(22);
|
||||
total.createCell(0).setCellValue("预估费用");
|
||||
total.createCell(6).setCellFormula("SUM(G17:G22)");
|
||||
try (java.io.OutputStream os = Files.newOutputStream(src)) {
|
||||
wb.write(os);
|
||||
}
|
||||
}
|
||||
JSONObject mapping = new JSONObject();
|
||||
mapping.put("fields", new JSONObject());
|
||||
JSONObject region = new JSONObject(true);
|
||||
region.put("id", "air_fee_detail");
|
||||
region.put("anchor", "Sheet2!A17");
|
||||
region.put("stopAtText", java.util.Collections.singletonList("预估费用"));
|
||||
JSONObject cols = new JSONObject(true);
|
||||
cols.put("name", "B");
|
||||
cols.put("unit", "C");
|
||||
cols.put("currency", "D");
|
||||
cols.put("unit_price", "E");
|
||||
cols.put("quantity", "F");
|
||||
cols.put("amount", "G");
|
||||
// 故意不写 project,验证 mergeFeeColumnsFromHeader 补 A 列
|
||||
region.put("columns", cols);
|
||||
mapping.put("feeRegions", new JSONArray(java.util.Collections.singletonList(region)));
|
||||
JSONObject facts = new JSONObject(true);
|
||||
facts.put("total_amount", "5001");
|
||||
facts.put("currency", "CNY");
|
||||
facts.put("fee_rows", QuoteTemplateExcelSupport.parseAirDepartureChargeRows(
|
||||
"[{\"salePrice\":4750.95,\"currency\":\"CNY\",\"chargeableWeightKg\":500.1,"
|
||||
+ "\"departureCharges\":["
|
||||
+ "{\"chargeName\":\"增点费\",\"unitPrice\":100.0,\"unit\":\"点\",\"currency\":\"CNY\"},"
|
||||
+ "{\"chargeName\":\"拆板费\",\"unitPrice\":100.0,\"unit\":\"板数\",\"currency\":\"USD\"}"
|
||||
+ "]}]",
|
||||
null, "500.1", "CNY"));
|
||||
QuoteTemplateExcelSupport.fillWorkbook(src, out, mapping, facts);
|
||||
try (Workbook got = new XSSFWorkbook(Files.newInputStream(out))) {
|
||||
Sheet sheet = got.getSheet("Sheet2");
|
||||
DataFormatter fmt = new DataFormatter();
|
||||
assertEquals("空运段", fmt.formatCellValue(sheet.getRow(16).getCell(0)));
|
||||
assertEquals("空运费", fmt.formatCellValue(sheet.getRow(16).getCell(1)));
|
||||
assertEquals("起运港", fmt.formatCellValue(sheet.getRow(17).getCell(0)));
|
||||
assertEquals("增点费", fmt.formatCellValue(sheet.getRow(17).getCell(1)));
|
||||
assertEquals("起运港", fmt.formatCellValue(sheet.getRow(18).getCell(0)));
|
||||
assertEquals("拆板费", fmt.formatCellValue(sheet.getRow(18).getCell(1)));
|
||||
} finally {
|
||||
Files.deleteIfExists(src);
|
||||
Files.deleteIfExists(out);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 出单后必须 A4 水平居中,抬头行高够放下中英文公司名。
|
||||
* 否则转 PDF 会顶部裁字、整页偏左。
|
||||
|
||||
+7
@@ -42,4 +42,11 @@ public class QuoteTemplateObjectStoreTest {
|
||||
public void splitRejectsBlank() {
|
||||
assertNull(QuoteTemplateObjectStore.splitStorageUrl(" ", "http://127.0.0.1:9000/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void remoteUrlStillDetectedAfterShaOverload() {
|
||||
// 回归:增加 resolve(objectKey, sha) 后,URL 识别不能回退成 Paths.get
|
||||
assertTrue(QuoteTemplateObjectStore.isRemoteUrl(
|
||||
"http://127.0.0.1:9000/inquiry-robot/inquiry/quote-templates/空运到门报价单模板_1790069791709.xlsx"));
|
||||
}
|
||||
}
|
||||
|
||||
+24
@@ -193,6 +193,30 @@ public class InquiryTmsCabinServiceTest {
|
||||
java.util.List<Map<String, Object>> fees =
|
||||
(java.util.List<Map<String, Object>>) req.get("feeItems");
|
||||
assertEquals("空运费", fees.get(0).get("feeName"));
|
||||
// 空运费缺单位时锁舱补 KG(WO007)
|
||||
assertEquals("KG", fees.get(0).get("unit"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void manualFeeLinesWithoutUnitGetsKgOnLock() {
|
||||
Map<String, Object> quote = new HashMap<>();
|
||||
quote.put("source", "PRODUCT");
|
||||
Map<String, Object> line = new HashMap<>();
|
||||
line.put("name", "空运费");
|
||||
line.put("unit_price", "10.00");
|
||||
line.put("quantity", "5063");
|
||||
line.put("amount", "50630");
|
||||
line.put("currency", "CNY");
|
||||
quote.put("fee_lines", java.util.Arrays.asList(line));
|
||||
Map<String, Object> req = new HashMap<>();
|
||||
InquiryTmsCabinService.fillLockQuoteExtras(req, quote, new HashMap<>());
|
||||
@SuppressWarnings("unchecked")
|
||||
java.util.List<Map<String, Object>> fees =
|
||||
(java.util.List<Map<String, Object>>) req.get("feeItems");
|
||||
assertNotNull(fees);
|
||||
assertEquals(1, fees.size());
|
||||
assertEquals("空运费", fees.get(0).get("feeName"));
|
||||
assertEquals("KG", fees.get(0).get("unit"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -190,8 +190,8 @@ export const mockReplyCategories: ReplyCategory[] = [
|
||||
{
|
||||
id: "brv10000000000000000000000000024",
|
||||
replyCode: "inquiring.air_lock_need_wo",
|
||||
trigger: "空运锁舱/释放未带工单号",
|
||||
text: "锁舱或释放舱位请带上工单号,例如 WO202609160001锁舱。",
|
||||
trigger: "空运锁舱/取消舱位未带工单号",
|
||||
text: "锁舱或取消舱位请带上工单号,例如 WO202609160001取消舱位。",
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
@@ -205,7 +205,7 @@ export const mockReplyCategories: ReplyCategory[] = [
|
||||
id: "brv10000000000000000000000000026",
|
||||
replyCode: "inquiring.air_airline_only_cabin",
|
||||
trigger: "只有航线能锁舱或释放",
|
||||
text: "只有岗位为「航线·空运」的人能锁舱或释放舱位。",
|
||||
text: "只有岗位为「航线·空运」的人能锁舱或取消舱位。",
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
@@ -225,29 +225,29 @@ export const mockReplyCategories: ReplyCategory[] = [
|
||||
{
|
||||
id: "brv10000000000000000000000000029",
|
||||
replyCode: "inquiring.air_release_ok",
|
||||
trigger: "空运释放成功",
|
||||
text: "工单{{ticket_no}} 已通知TMS执行空运释放舱位成功\n操作人:{{operator}}\n舱位选项:{{option_no}}\n执行编号:{{exec_no}}\n报价编号:{{quote_no}}",
|
||||
trigger: "空运取消舱位成功",
|
||||
text: "工单{{ticket_no}} 已通知TMS执行空运取消舱位成功\n操作人:{{operator}}\n舱位选项:{{option_no}}\n执行编号:{{exec_no}}\n报价编号:{{quote_no}}",
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
id: "brv10000000000000000000000000030",
|
||||
replyCode: "inquiring.air_release_fail",
|
||||
trigger: "空运释放失败",
|
||||
text: "工单{{ticket_no}} 空运释放舱位失败。\n操作人:{{operator}}\n释放舱位失败的原因:{{reason}}\n已通知IT运维排查,请稍等。",
|
||||
trigger: "空运取消舱位失败",
|
||||
text: "工单{{ticket_no}} 空运取消舱位失败。\n操作人:{{operator}}\n取消舱位失败的原因:{{reason}}\n已通知IT运维排查,请稍等。",
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
id: "brv10000000000000000000000000031",
|
||||
replyCode: "inquiring.air_release_deal_blocked",
|
||||
trigger: "已成交不能释放舱位",
|
||||
text: "释放舱位失败,工单{{ticket_no}}已成交。",
|
||||
trigger: "已成交不能取消舱位",
|
||||
text: "取消舱位失败,工单{{ticket_no}}已成交。",
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
id: "brv10000000000000000000000000032",
|
||||
replyCode: "inquiring.air_release_need_lock",
|
||||
trigger: "没有有效锁舱不能释放",
|
||||
text: "工单{{ticket_no}}还没有有效锁舱,不能释放。",
|
||||
trigger: "没有有效锁舱不能取消舱位",
|
||||
text: "工单{{ticket_no}}还没有有效锁舱,不能取消舱位。",
|
||||
enabled: true,
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user