转人工协同按运输方式各自落地:海运说转人工直接建正式单建群发摘要和空白表,陆运先选业务类型和报价场景再建群,空运先落正式单让销售把工单号发进原群,转人工后群里报价不再被当成冻结单拦住。产品报价只发摘要和成交卡,要 Excel/PDF 说「生成报价单」再出,多段逐段出、没价出空白表,出表后补推成交跟进不涨版本、不重置等待计时。结束询价口令不再进模型,直接清上下文。卡片回执按本次入站消息号去重,第二次点提交不会再被静默吞掉。陆转人工按选定模板名直取,避免陆运七种业务靠关键词猜错;空运舱位只回一条时直接出价,TMS 分桶费用落到对应段。后台工单补需求字段与模板预览样例,新增 AIR_NEED_WO 回复语、协同模式、陆运岗位与陆运超时卡迁移脚本;测服文档改为独立企微应用 1000015。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
linmianxun
2026-11-19 14:07:52 +08:00
co-authored by Cursor
parent b878a094b5
commit b3637f3fc4
84 changed files with 9293 additions and 572 deletions
@@ -265,6 +265,8 @@ public class InquiryAgentController {
String workOrderNo = firstStr(body, "workOrderNo", "work_order_no");
String businessLine = firstStr(body, "businessLine", "business_line");
String sales = firstStr(body, "salesWecomId", "sales_wecom_id");
// 转人工卡片选定的业务模板名;空=按关键词匹配(其余业务线行为不变)。
String templateName = firstStr(body, "templateName", "template_name");
@SuppressWarnings("unchecked")
Map<String, Object> facts = asMap(body == null ? null : body.get("facts"));
@SuppressWarnings("unchecked")
@@ -272,7 +274,7 @@ public class InquiryAgentController {
// 默认 false:激活发模版只发群、不进后台附件;确认落库由智能体显式传 true。
boolean persistAttachment = boolFlag(body, "persistAttachment", "persist_attachment", false);
Map<String, Object> rendered = quoteTemplateService.renderForAgent(
workOrderNo, businessLine, facts, quote, sales, persistAttachment);
workOrderNo, businessLine, facts, quote, sales, persistAttachment, templateName);
if (rendered != null && Boolean.TRUE.equals(rendered.get("ok"))) {
workOrderService.markQuoteFileIssued(workOrderNo);
}
@@ -21,6 +21,20 @@ public class AgentTicketCreateRequest {
@ApiModelProperty("SEA/AIR/LAND")
private String businessLine;
/**
* 展示用业务类型。转人工陆运按卡片选的具体类型(例如「国内城配/打包」)传,
* 不传则主账按 SEA/AIR/LAND 给默认中文名。
*/
@ApiModelProperty("展示业务类型(可选,陆运细分类型)")
private String bizTypeLabel;
/**
* 协同模式:auto=系统自动;handoff=销售转人工、产品群内手工报价。
* 不传按 auto,保证旧调用方行为不变。
*/
@ApiModelProperty("协同模式 auto/handoff")
private String collabMode;
@ApiModelProperty("已确认查价字段(内部键)")
private Map<String, String> facts;
@@ -39,6 +39,12 @@ public class InquiryAttachment implements Serializable {
/** 上传人:企微 userid、后台登录名或 agent;详情接口会解析成可读姓名。 */
private String createBy;
/**
* 报价版本号:产品在群里报的是哪一个版本,附件就挂到 inq_quote.quote_version。
* 可空:普通询价附件、TMS 定单附件不属于某个手工报价版本。
*/
private String quoteId;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@@ -36,6 +36,17 @@ public class InquiryQuote implements Serializable {
private Integer highlighted;
private String payloadJson;
/**
* 产品在群里发的原始报价文字(含图片/附件说明)。只做参考留档,不参与结构化解析。
* <p>
* 为什么留原文:转人工报价可能是「一个40HQ 2800美金含码头费」这种非模板话术,
* 解析不出来时不能伪造金额,但销售/后台仍要看到产品到底怎么说的。
*/
private String rawText;
/** 原文来源:text=文字,image=图片,file=附件,nonstandard=非标话术。 */
private String rawSource;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@@ -225,6 +225,16 @@ public class InquiryTicket implements Serializable {
@ApiModelProperty("协同群成员 userid JSON")
private String collabMemberIds;
/**
* 协同模式:auto=系统自动协同报价;handoff=销售转人工,产品在群里手工报价。
* <p>
* 为什么单开一列:转人工不能再借六态「转人工」表达。六态是业务生命周期,
* 写成「转人工」会冻结报价、把群消息全部丢掉;这里只记「谁在报价」,六态仍走询价中→已报价。
* 旧单没有本列,库默认 auto,行为与改造前一致。
*/
@ApiModelProperty("协同模式 auto/handoff")
private String collabMode;
private String createBy;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@@ -116,8 +116,11 @@ public interface IInquiryQuoteTemplateService extends IService<InquiryQuoteTempl
*
* @param persistAttachment true 时登记 inq_attachment(确认报价落库等);
* false 只回文件供企微发出(激活发模版),不进后台附件列
* @param templateName 转人工卡片选定的业务模板名;非空时按名直取,
* 找不到才退回关键词匹配(陆运 7 种业务不能靠猜)
*/
Map<String, Object> renderForAgent(String workOrderNo, String businessLine,
Map<String, Object> facts, Map<String, Object> quote,
String salesWecomId, boolean persistAttachment);
String salesWecomId, boolean persistAttachment,
String templateName);
}
@@ -254,10 +254,17 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
if (fileBytes.length == 0) {
throw new IllegalArgumentException("上传文件为空");
}
// 空运到港/到门:上传时若货物信息缺「比例」标签,先补进 Excel 再入库,避免后台旧表漏印
if (!isPdf) {
byte[] patched = QuoteTemplateExcelSupport.ensureAirVolumeRatioLabelBytes(fileBytes);
if (patched != null && patched.length > 0) {
fileBytes = patched;
}
}
String objectKey;
try {
objectKey = CommonUtils.upload(file, BIZ_PATH, uploadType);
objectKey = CommonUtils.upload(bytesAsMultipart(original, fileBytes), BIZ_PATH, uploadType);
} catch (Exception e) {
log.error("模板上传失败", e);
throw new IllegalStateException("文件上传失败: " + e.getMessage(), e);
@@ -278,7 +285,7 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
version.setFormat(format);
version.setObjectKey(objectKey);
version.setSha256(sha);
version.setFileSize(file.getSize());
version.setFileSize((long) fileBytes.length);
version.setEnabled(0);
version.setCreateBy(operator);
version.setCreateTime(new Date());
@@ -749,8 +756,9 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
private Path findCachedSnapshot(String versionId) throws Exception {
Path previewDir = Paths.get(StringUtils.defaultIfBlank(uploadPath, "."), BIZ_PATH, "preview");
Files.createDirectories(previewDir);
Path cachedPng = previewDir.resolve(versionId + "-snapshot-v10.png");
Path cachedPdf = previewDir.resolve(versionId + "-snapshot-v10.pdf");
// v12:空运「比例」已改为深色标签样式后需重渲;旧 v11 可能仍是浅字不可见
Path cachedPng = previewDir.resolve(versionId + "-snapshot-v12.png");
Path cachedPdf = previewDir.resolve(versionId + "-snapshot-v12.pdf");
if (Files.isRegularFile(cachedPng) && Files.size(cachedPng) > 0) {
return cachedPng;
}
@@ -763,13 +771,33 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
private Path generateAndCacheSnapshot(InquiryQuoteTemplateVersion ver) throws Exception {
Path previewDir = Paths.get(StringUtils.defaultIfBlank(uploadPath, "."), BIZ_PATH, "preview");
Files.createDirectories(previewDir);
Path cachedPng = previewDir.resolve(ver.getId() + "-snapshot-v10.png");
Path cachedPdf = previewDir.resolve(ver.getId() + "-snapshot-v10.pdf");
Path cachedPng = previewDir.resolve(ver.getId() + "-snapshot-v12.png");
Path cachedPdf = previewDir.resolve(ver.getId() + "-snapshot-v12.pdf");
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());
return target;
// 截图前补空运「比例」标签(只改临时副本,不改对象存储原文)
Path renderSource = source;
Path patched = null;
try {
byte[] raw = Files.readAllBytes(source);
byte[] withRatio = QuoteTemplateExcelSupport.ensureAirVolumeRatioLabelBytes(raw);
if (withRatio != null && withRatio != raw) {
patched = previewDir.resolve(ver.getId() + "-air-ratio-tmp.xlsx");
Files.write(patched, withRatio);
renderSource = patched;
}
QuoteTemplateSnapshotRenderer.PreviewBytes rendered = snapshotRenderer.render(renderSource, ver.getId());
Path target = rendered.isImage() ? cachedPng : cachedPdf;
Files.write(target, rendered.getBytes());
return target;
} finally {
if (patched != null) {
try {
Files.deleteIfExists(patched);
} catch (Exception ignored) {
// 临时文件删失败不影响预览结果
}
}
}
}
/**
@@ -829,14 +857,26 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
@Override
public Map<String, Object> renderForAgent(String workOrderNo, String businessLine,
Map<String, Object> facts, Map<String, Object> quote,
String salesWecomId, boolean persistAttachment) {
String salesWecomId, boolean persistAttachment,
String templateName) {
Map<String, Object> fail = new LinkedHashMap<>();
fail.put("ok", false);
fail.put("error", "NO_TEMPLATE");
fail.put("message", QuoteTemplateMatcher.FAIL_MESSAGE);
List<Map<String, Object>> enabled = listEnabledForAgent(true);
Map<String, Object> picked = QuoteTemplateMatcher.pick(enabled, businessLine, facts, quote);
// 转人工卡片指定了业务模板:先按名直取,避免陆运 7 种业务被关键词猜错。
// 没指定 / 没命中才走原来的关键词 + 默认模板,保证其他业务线行为不变。
Map<String, Object> picked = null;
if (StringUtils.isNotBlank(templateName)) {
picked = QuoteTemplateMatcher.pickByName(enabled, templateName, businessLine);
if (picked == null) {
log.warn("转人工指定模板未命中 wo={} name={},退回关键词匹配", workOrderNo, templateName);
}
}
if (picked == null) {
picked = QuoteTemplateMatcher.pick(enabled, businessLine, facts, quote);
}
if (picked == null) {
log.warn("报价出单无模板 wo={} biz={}", workOrderNo, businessLine);
fail.put("failStage", "PICK_NULL");
@@ -1242,6 +1282,20 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
out.put("chargeable_weight_kg", chargeable);
out.put("chargeableWeightKg", chargeable);
}
// 空运比例(货型/泡重比,如 1:212):写到模板「比例」格;与企微「货型」同源
String volumeRatio = resolveAirVolumeRatio(q, src);
if (StringUtils.isNotBlank(volumeRatio) && !"-".equals(volumeRatio)) {
out.put("volume_ratio", volumeRatio);
out.put("比例", volumeRatio);
out.put("货型", volumeRatio);
out.put("cargoType", volumeRatio);
}
// 空运尺寸(非必填):询价事实原文;模板有尺寸格才落字
String cargoSize = first(src, "尺寸", "货物尺寸", "cargo_size", "cargoSize");
if (StringUtils.isNotBlank(cargoSize) && !"-".equals(cargoSize)) {
out.put("cargo_size", cargoSize);
out.put("尺寸", cargoSize);
}
// 重量单位:仅供「已有费用行」时写入报价明细「单位」;无报价不出费用行,也不填单位。
String weightUnitEarly = first(src, "重量单位", "weight_unit", "weightUnit", "毛重单位");
if (StringUtils.isBlank(weightUnitEarly)) {
@@ -1800,6 +1854,126 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
return val.isEmpty() || "-".equals(val) || "—".equals(val) || "-".equals(val);
}
/**
* 空运比例:优先已选舱位,再整单 quote,再询价事实。
* <p>
* 与企微「货型」同源(如 1:212)。TMS 键名不统一,按常见别名依次取。
* 无值返回空串,禁止本地编比例。
*/
private static String resolveAirVolumeRatio(Map<String, Object> quote, Map<String, Object> facts) {
JSONObject selected = asJsonObject(quote == null ? null : firstObj(quote,
"selected_air_option", "selectedAirOption"));
String fromOpt = firstFromMap(selected,
"cargoType", "goodsType", "cargoRatio", "weightVolumeRatio", "volumeWeightRatio",
"heavyBubbleRatio", "bubbleRatio", "densityRatio", "volume_ratio", "比例", "货型");
if (StringUtils.isNotBlank(fromOpt)) {
return fromOpt;
}
String fromQuote = first(quote,
"cargoType", "goodsType", "cargoRatio", "weightVolumeRatio", "volumeWeightRatio",
"heavyBubbleRatio", "bubbleRatio", "densityRatio", "volume_ratio", "比例", "货型");
if (StringUtils.isNotBlank(fromQuote)) {
return fromQuote;
}
// 舱位列表仅一条时也可取
Object airRaw = quote == null ? null : firstObj(quote, "airOptions", "air_options");
JSONArray opts = null;
if (airRaw instanceof JSONArray) {
opts = (JSONArray) airRaw;
} else if (airRaw != null) {
try {
opts = JSON.parseArray(String.valueOf(airRaw));
} catch (Exception ignored) {
opts = null;
}
}
if (opts != null && opts.size() == 1) {
String one = firstFromMap(opts.getJSONObject(0),
"cargoType", "goodsType", "cargoRatio", "weightVolumeRatio", "volumeWeightRatio",
"heavyBubbleRatio", "bubbleRatio", "densityRatio", "volume_ratio", "比例", "货型");
if (StringUtils.isNotBlank(one)) {
return one;
}
}
return first(facts, "比例", "货型", "volume_ratio", "cargoType");
}
private static Object firstObj(Map<String, Object> map, String... keys) {
if (map == null || keys == null) {
return null;
}
for (String k : keys) {
Object v = map.get(k);
if (v != null) {
return v;
}
}
return null;
}
private static String firstFromMap(JSONObject obj, String... keys) {
if (obj == null || keys == null) {
return "";
}
for (String k : keys) {
String v = StringUtils.trimToEmpty(obj.getString(k));
if (StringUtils.isNotBlank(v) && !"-".equals(v)) {
return v;
}
}
return "";
}
/**
* 把已补标签的字节包装成 MultipartFile,供 CommonUtils / MinIO 上传。
* 为何:上传流只能走 MultipartFile;补比例后必须与 sha、by-sha 镜像同一份字节。
*/
private static MultipartFile bytesAsMultipart(String filename, byte[] bytes) {
final byte[] data = bytes == null ? new byte[0] : bytes;
final String name = StringUtils.defaultIfBlank(filename, "template.xlsx");
return new MultipartFile() {
@Override
public String getName() {
return "file";
}
@Override
public String getOriginalFilename() {
return name;
}
@Override
public String getContentType() {
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
}
@Override
public boolean isEmpty() {
return data.length == 0;
}
@Override
public long getSize() {
return data.length;
}
@Override
public byte[] getBytes() {
return data;
}
@Override
public InputStream getInputStream() {
return new ByteArrayInputStream(data);
}
@Override
public void transferTo(java.io.File dest) throws java.io.IOException {
Files.write(dest.toPath(), data);
}
};
}
/**
* 空运销售面没有时效:出单不把 eta / transit_* 填进模板。
* 业务线 AIR / 运输方式含空运 / 报价带 airOptions 都算空运。
@@ -2346,7 +2520,7 @@ public class InquiryQuoteTemplateServiceImpl extends ServiceImpl<InquiryQuoteTem
}
// 提示词扩展字段(合同可能尚未列全)
codes.addAll(Arrays.asList(
"chargeable_weight_kg", "delivery_address", "pickup_address", "transit_time",
"chargeable_weight_kg", "volume_ratio", "delivery_address", "pickup_address", "transit_time",
"cargo_value", "hs_code", "oil_elec_mag", "has_battery", "on_board_date",
"special_remarks", "eta_request", "sailing_schedule", "shipping_line",
"flight_no", "transfer_airport", "effective_date", "fuel_surcharge_rate", "tax_rate",
@@ -65,6 +65,8 @@ public class InquiryResponseTimeoutServiceImpl
ID_TO_TIMEOUT_CODE.put("rt100000000000000000000000000008", "land_hk_cross");
ID_TO_TIMEOUT_CODE.put("rt100000000000000000000000000009", "land_hk_special");
ID_TO_TIMEOUT_CODE.put("rt100000000000000000000000000010", "land_hk_express");
// 转人工报价场景卡新增:中欧、中亚 24 小时一档。
ID_TO_TIMEOUT_CODE.put("rt100000000000000000000000000031", "land_ca_eu");
// 成交跟进:协商中再问(跨业务线,transport_mode=DEAL)
ID_TO_TIMEOUT_CODE.put("rt100000000000000000000000000030", "deal_negotiate");
}
@@ -806,7 +806,11 @@ public class InquiryWorkOrderServiceImpl extends ServiceImpl<InquiryTicketMapper
ticket.setSalesWecomId(req.getSalesWecomId());
ticket.setSalesName(resolveStaffDisplayName(req.getSalesWecomId()));
ticket.setBusinessLine(req.getBusinessLine().trim().toUpperCase());
ticket.setBizTypeLabel(bizLabel(ticket.getBusinessLine()));
// 陆运转人工卡片选的具体业务类型(如「国内城配/打包」)优先;否则按业务线给默认中文名。
String bizLabelReq = StringUtils.trimToNull(req.getBizTypeLabel());
ticket.setBizTypeLabel(bizLabelReq != null ? bizLabelReq : bizLabel(ticket.getBusinessLine()));
// 协同模式:转人工单由智能体显式传 handoff;旧调用方不传按 auto,行为不变。
ticket.setCollabMode(normalizeCollabMode(req.getCollabMode()));
// 摘要占位「-」不落库:空运不起运地应空串出站,横杠会骗 TMS 回 1003。
ticket.setOrigin(placeOrNull(facts.get("起运港")));
ticket.setDestination(placeOrNull(facts.get("目的港")));
@@ -962,6 +966,20 @@ public class InquiryWorkOrderServiceImpl extends ServiceImpl<InquiryTicketMapper
return line;
}
/**
* 协同模式归一:只认 auto / handoff 两种。
* <p>
* 为什么不在建单时把空值写成 null:老库列有默认 auto,
* 但 MyBatis-Plus 插入 null 会显式写 NULL;显式归到 auto,读侧不用到处判空。
*/
private static String normalizeCollabMode(String mode) {
String m = StringUtils.trimToEmpty(mode).toLowerCase();
if ("handoff".equals(m)) {
return "handoff";
}
return "auto";
}
private static String fingerprint(AgentTicketCreateRequest req) {
Map<String, String> facts = req.getFacts() == null ? new HashMap<>() : req.getFacts();
return String.join("|",
@@ -1205,6 +1223,10 @@ public class InquiryWorkOrderServiceImpl extends ServiceImpl<InquiryTicketMapper
out.put("ok", true);
out.put("status", status);
out.put("business_line", StringUtils.defaultString(ticket.getBusinessLine()));
// 陆运转人工按卡片选过业务类型,落在这里;智能体按需出表时用它反查模板名,
// 避免 7 种陆运业务靠关键词猜错表(中港整车/中港拼车名字互相包含)。
out.put("biz_type_label", StringUtils.defaultString(ticket.getBizTypeLabel()));
out.put("bizTypeLabel", StringUtils.defaultString(ticket.getBizTypeLabel()));
String ticketSalesWecomId = StringUtils.defaultString(ticket.getSalesWecomId());
out.put("salesWecomId", ticketSalesWecomId);
out.put("sales_wecom_id", ticketSalesWecomId);
@@ -1224,6 +1246,9 @@ public class InquiryWorkOrderServiceImpl extends ServiceImpl<InquiryTicketMapper
out.put("next_followup_at", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(ticket.getNextFollowupAt()));
}
out.put("collab_chat_id", StringUtils.defaultString(ticket.getCollabChatId()));
// 智能体据此判断:handoff 单的产品群报价只留档、不发成交跟进。
out.put("collab_mode", normalizeCollabMode(ticket.getCollabMode()));
out.put("collabMode", normalizeCollabMode(ticket.getCollabMode()));
Map<String, String> collabFacts = new LinkedHashMap<>();
if (StringUtils.isNotBlank(ticket.getCollabFactsJson())) {
JSONObject parsed = JSON.parseObject(ticket.getCollabFactsJson());
@@ -1390,6 +1415,11 @@ public class InquiryWorkOrderServiceImpl extends ServiceImpl<InquiryTicketMapper
}
ticket.setCollabChatId(chatId);
ticket.setCollabMemberIds(memberIdsJson(body));
// 允许把已有单标成转人工协同(空运:销售手动拉群后绑定);不传则保留原值。
String mode = StringUtils.trimToNull(text(body, "collabMode", "collab_mode"));
if (mode != null) {
ticket.setCollabMode(normalizeCollabMode(mode));
}
ticket.setUpdateTime(new Date());
unbindOtherTicketsInRoom(chatId, no);
updateById(ticket);
@@ -1688,13 +1718,33 @@ public class InquiryWorkOrderServiceImpl extends ServiceImpl<InquiryTicketMapper
sale = (ccy == null ? "" : String.valueOf(ccy) + " ") + total;
row.setPriceText(sale.trim());
} else {
row.setPriceText(String.valueOf(quote.getOrDefault("total", "")));
// 上游可能显式传 total=null;String.valueOf(null) 会变成字面量 "null",
// 那样「只有原话」的行会被当成有金额,所以这里归成空串。
String blankTotal = total == null ? "" : StringUtils.trimToEmpty(String.valueOf(total));
row.setPriceText("null".equals(blankTotal) ? "" : blankTotal);
}
row.setHighlighted(1);
row.setPayloadJson(JSON.toJSONString(quote));
// 群内原始报价留档:解析不出来时不能编金额,但产品原话必须可回看。
String rawText = text(body, "rawText", "raw_text");
if (StringUtils.isBlank(rawText)) {
Object q = quote.get("raw_text");
rawText = q == null ? "" : String.valueOf(q);
}
row.setRawText(StringUtils.trimToNull(rawText));
row.setRawSource(StringUtils.trimToNull(text(body, "rawSource", "raw_source")));
// 只有原话、没有金额:不是候选报价,不参与成本/销售价,也不高亮。
boolean rawOnly = StringUtils.isBlank(row.getPriceText()) && row.getRawText() != null;
if (rawOnly) {
row.setSourceLabel(InquiryQuoteDisplaySupport.RAW_LABEL);
row.setHighlighted(0);
}
row.setCreateTime(new Date());
quoteMapper.insert(row);
ticket.setManualQuote(1);
// 只有原话的行不是一次报价:不要把工单标成「已有手工报价」。
if (!rawOnly) {
ticket.setManualQuote(1);
}
List<InquiryQuote> quotes = quoteMapper.selectList(new LambdaQueryWrapper<InquiryQuote>()
.eq(InquiryQuote::getWorkOrderNo, no)
.orderByAsc(InquiryQuote::getCreateTime));
@@ -1719,6 +1769,8 @@ public class InquiryWorkOrderServiceImpl extends ServiceImpl<InquiryTicketMapper
}
out.put("ok", true);
out.put("quote_version", ver);
// 附件回链用:产品同一版报价带的图/文件可挂到这一条报价。
out.put("quote_id", row.getId());
out.put("status", ticket.getStatus());
return out;
}
@@ -1772,6 +1824,9 @@ public class InquiryWorkOrderServiceImpl extends ServiceImpl<InquiryTicketMapper
out.put("facts", parseFactsJson(ticket.getFactsJson()));
out.put("quote", latestQuotePayload(no));
out.put("collab_chat_id", room);
// 空运转人工单:激活进群后仍要知道是人工协同,产品报价只留档不生成交跟进。
out.put("collab_mode", normalizeCollabMode(ticket.getCollabMode()));
out.put("collabMode", normalizeCollabMode(ticket.getCollabMode()));
out.put("collab_facts", parseFactsJson(ticket.getCollabFactsJson()));
return out;
}
@@ -14,6 +14,8 @@ public final class InquiryQuoteDisplaySupport {
public static final String TMS_LABEL = "TMS标准报价";
public static final String MANUAL_LABEL = "手工报价";
public static final String ADJUST_LABEL = "销售调价";
/** 转人工群:只有产品原话、没有结构化金额的那条报价行。 */
public static final String RAW_LABEL = "产品群原话";
public static final String ACTION_ADJUST = "quote_adjust";
public static final String ACTION_MANUAL = "manual_quote";
@@ -53,4 +55,21 @@ public final class InquiryQuoteDisplaySupport {
}
return StringUtils.startsWith(StringUtils.trimToEmpty(remark), "销售调价");
}
/**
* 只有产品原话、没有金额的留档行。
* <p>
* 为什么单独判:这类行不该参与成本/销售价取最后一条,
* 否则产品先说一句「我再问下航线」就会把上一版解析出来的金额盖空。
*
* @param sourceLabel 入库时写的来源名({@link #RAW_LABEL})
* @param priceText 金额列;有金额说明是正常报价,不是纯原话
*/
public static boolean isRawNote(String sourceLabel, String priceText) {
if (StringUtils.isNotBlank(priceText) && !"-".equals(priceText.trim())) {
return false;
}
String label = StringUtils.trimToEmpty(sourceLabel);
return RAW_LABEL.equals(label) || StringUtils.contains(label, "原话");
}
}
@@ -53,6 +53,10 @@ public final class InquiryQuoteLineSupport {
if (quote == null) {
continue;
}
// 纯原话留档行没有明细:跳过,避免最新一条是闲聊时把费用行清空。
if (InquiryQuoteDisplaySupport.isRawNote(quote.getSourceLabel(), quote.getPriceText())) {
continue;
}
if (InquiryQuoteDisplaySupport.isSalesAdjust(quote.getSource(), quote.getSourceLabel())) {
lastAdjust = quote;
} else if (InquiryQuoteDisplaySupport.isTms(quote.getSource(), quote.getSourceLabel())) {
@@ -44,6 +44,10 @@ public final class InquiryTicketPriceSupport {
if (q == null) {
continue;
}
// 纯原话留档行没有金额:跳过,避免把上一版真实报价盖成空。
if (InquiryQuoteDisplaySupport.isRawNote(q.getSourceLabel(), q.getPriceText())) {
continue;
}
if (InquiryQuoteDisplaySupport.isSalesAdjust(q.getSource(), q.getSourceLabel())) {
lastAdjust = q;
} else if (InquiryQuoteDisplaySupport.isTms(q.getSource(), q.getSourceLabel())) {
@@ -95,6 +95,19 @@ public final class QuoteTemplateExcelSupport {
FILL_BY_LABEL.put("计费重", "chargeable_weight_kg");
FILL_BY_LABEL.put("计费重量", "chargeable_weight_kg");
FILL_BY_LABEL.put("Chargeable Weight", "chargeable_weight_kg");
// 空运到港/到门:计费重右侧「比例」= TMS 货型/泡重比(如 1:212);「货型」同码
FILL_BY_LABEL.put("比例", "volume_ratio");
FILL_BY_LABEL.put("货型", "volume_ratio");
FILL_BY_LABEL.put("泡比", "volume_ratio");
FILL_BY_LABEL.put("重泡比", "volume_ratio");
// 空运尺寸(非必填):询价事实「尺寸」原文;模板有「尺寸」格才写
FILL_BY_LABEL.put("尺寸", "cargo_size");
FILL_BY_LABEL.put("货物尺寸", "cargo_size");
FILL_BY_LABEL.put("是否带电", "has_battery");
FILL_BY_LABEL.put("时效要求", "transit_time");
FILL_BY_LABEL.put("派送地址", "delivery_address");
FILL_BY_LABEL.put("送货地址", "delivery_address");
FILL_BY_LABEL.put("提货地址", "pickup_address");
FILL_BY_LABEL.put("始发地", "origin");
FILL_BY_LABEL.put("始发站", "origin");
FILL_BY_LABEL.put("起始地", "origin");
@@ -466,6 +479,8 @@ public final class QuoteTemplateExcelSupport {
out.put("error", "empty_workbook");
return out;
}
// 后台预览:空运到港/到门缺「比例」时先补标签,再画格子(不改对象存储原文)
ensureAirVolumeRatioLabel(wb);
String prefer = mapping == null ? null : mapping.getString("sheet");
Sheet sheet = null;
if (StringUtils.isNotBlank(prefer)) {
@@ -619,6 +634,8 @@ public final class QuoteTemplateExcelSupport {
m.put("weight_kg", "重量(KG)");
m.put("volume_cbm", "体积(CBM)");
m.put("chargeable_weight_kg", "计费重");
m.put("volume_ratio", "比例");
m.put("cargo_size", "尺寸");
m.put("total_amount", "报价合计");
return m;
}
@@ -646,6 +663,8 @@ public final class QuoteTemplateExcelSupport {
seaDrawParts = readSeaDrawingParts(sourceXlsx);
}
}
// 空运到港/到门:货物信息计费重右侧若缺「比例」标签,出单前补上,避免后台旧模板漏印。
ensureAirVolumeRatioLabel(wb);
JSONObject fieldMeta = mapping.getJSONObject("fieldMeta");
JSONObject fields = mapping.getJSONObject("fields");
LandTemplateLook landLook = snapshotLandTemplateLook(wb);
@@ -821,6 +840,219 @@ public final class QuoteTemplateExcelSupport {
}
}
/**
* 空运到港/到门报价单:货物信息「计费重」右侧补「比例」标签。
* <p>
* 产品口径:与截图一致,比例与计费重同行、落在右侧标签列(是否带电/贸易条款/货好时间/时效要求那一列)。
* 已有「比例/货型」标签则不动;非空运表不动。只改内存工作簿,副作用由调用方决定是否落盘。
* 线程:跟随调用方,无全局锁。
*
* @param wb 已打开的工作簿
* @return 是否写入了新标签
*/
public static boolean ensureAirVolumeRatioLabel(Workbook wb) {
if (wb == null || wb.getNumberOfSheets() <= 0) {
return false;
}
boolean changed = false;
DataFormatter fmt = new DataFormatter();
for (int s = 0; s < wb.getNumberOfSheets(); s++) {
Sheet sheet = wb.getSheetAt(s);
if (sheet == null || !sheetLooksLikeAirCargoQuote(sheet, fmt)) {
continue;
}
if (sheetHasVolumeRatioLabel(sheet, fmt)) {
continue;
}
int[] chargeable = findLabelCell(sheet, fmt, "计费重", "计费重量");
int rightCol = findAirRightLabelColumn(sheet, fmt);
if (chargeable == null || rightCol < 0) {
continue;
}
int rowIdx = chargeable[0];
Row row = sheet.getRow(rowIdx);
if (row == null) {
row = sheet.createRow(rowIdx);
}
Cell target = row.getCell(rightCol);
if (target == null) {
target = row.createCell(rightCol);
}
String existing = StringUtils.trimToEmpty(fmt.formatCellValue(target));
if (StringUtils.isNotBlank(existing)) {
// 右侧已有别的字(如派送地址),不要盖掉
continue;
}
Cell styleSrc = findStyleSourceCell(sheet, fmt, rightCol, "时效要求", "货好时间", "贸易条款", "是否带电", "是否含电");
if (styleSrc != null && styleSrc.getCellStyle() != null) {
target.setCellStyle(styleSrc.getCellStyle());
}
// 与同列「时效要求:」「货好时间:」一致,带中文冒号,后台预览一眼能看出是表单标签
target.setCellValue("比例:");
changed = true;
}
return changed;
}
/**
* 把空运模板字节补上「比例」标签后返回新字节;非空运或已有标签则原样返回。
* <p>
* 上传新版本时调用,让对象存储里的到港/到门模板自带比例格。
*/
public static byte[] ensureAirVolumeRatioLabelBytes(byte[] xlsxBytes) {
if (xlsxBytes == null || xlsxBytes.length < 64) {
return xlsxBytes;
}
try (InputStream in = new java.io.ByteArrayInputStream(xlsxBytes);
Workbook wb = WorkbookFactory.create(in);
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream()) {
if (!ensureAirVolumeRatioLabel(wb)) {
return xlsxBytes;
}
wb.write(out);
return out.toByteArray();
} catch (Exception e) {
log.warn("空运模板补比例标签失败,沿用原文件: {}", e.getMessage());
return xlsxBytes;
}
}
/** 表上是否已有比例/货型标签(含冒号与空格变体)。 */
private static boolean sheetHasVolumeRatioLabel(Sheet sheet, DataFormatter fmt) {
int lastRow = Math.min(sheet.getLastRowNum(), 40);
for (int r = 0; r <= lastRow; r++) {
Row row = sheet.getRow(r);
if (row == null) {
continue;
}
short lastCol = row.getLastCellNum();
if (lastCol < 0) {
continue;
}
for (int c = 0; c < lastCol; c++) {
Cell cell = row.getCell(c);
if (cell == null) {
continue;
}
String compact = compactLabel(fmt.formatCellValue(cell));
if ("比例".equals(compact) || "货型".equals(compact)
|| "泡比".equals(compact) || "重泡比".equals(compact)) {
return true;
}
}
}
return false;
}
/**
* 是否空运货物信息表:标题含空运,或同时有计费重 + 是否带电/贸易条款(到港到门同版式)。
*/
private static boolean sheetLooksLikeAirCargoQuote(Sheet sheet, DataFormatter fmt) {
boolean hasAirTitle = false;
boolean hasChargeable = false;
boolean hasRightBand = false;
int lastRow = Math.min(sheet.getLastRowNum(), 40);
for (int r = 0; r <= lastRow; r++) {
Row row = sheet.getRow(r);
if (row == null) {
continue;
}
short lastCol = row.getLastCellNum();
if (lastCol < 0) {
continue;
}
for (int c = 0; c < lastCol; c++) {
Cell cell = row.getCell(c);
if (cell == null) {
continue;
}
String text = StringUtils.trimToEmpty(fmt.formatCellValue(cell));
if (text.isEmpty()) {
continue;
}
if (text.contains("空运报价") || text.contains("空运到港") || text.contains("空运到门")) {
hasAirTitle = true;
}
String compact = compactLabel(text);
if ("计费重".equals(compact) || "计费重量".equals(compact)) {
hasChargeable = true;
}
if ("是否带电".equals(compact) || "是否含电".equals(compact)
|| "贸易条款".equals(compact) || "时效要求".equals(compact)) {
hasRightBand = true;
}
}
}
return hasAirTitle || (hasChargeable && hasRightBand);
}
/** 右侧标签列:优先「是否带电/贸易条款/货好时间/时效要求」所在列。 */
private static int findAirRightLabelColumn(Sheet sheet, DataFormatter fmt) {
String[] markers = {"是否带电", "是否含电", "贸易条款", "货好时间", "时效要求"};
for (String marker : markers) {
int[] found = findLabelCell(sheet, fmt, marker);
if (found != null) {
return found[1];
}
}
return -1;
}
/** 在表内找标签格,返回 [row, col];找不到返回 null。 */
private static int[] findLabelCell(Sheet sheet, DataFormatter fmt, String... labels) {
if (sheet == null || labels == null || labels.length == 0) {
return null;
}
java.util.Set<String> want = new java.util.HashSet<>();
for (String label : labels) {
if (StringUtils.isNotBlank(label)) {
want.add(compactLabel(label));
}
}
int lastRow = Math.min(sheet.getLastRowNum(), 40);
for (int r = 0; r <= lastRow; r++) {
Row row = sheet.getRow(r);
if (row == null) {
continue;
}
short lastCol = row.getLastCellNum();
if (lastCol < 0) {
continue;
}
for (int c = 0; c < lastCol; c++) {
Cell cell = row.getCell(c);
if (cell == null) {
continue;
}
if (want.contains(compactLabel(fmt.formatCellValue(cell)))) {
return new int[]{r, c};
}
}
}
return null;
}
/** 同列找一个已有标签格,用来抄字体边框样式。 */
private static Cell findStyleSourceCell(Sheet sheet, DataFormatter fmt, int col, String... labels) {
int[] found = findLabelCell(sheet, fmt, labels);
if (found == null || found[1] != col) {
// 列不一致时仍可用找到的标签格样式
if (found == null) {
return null;
}
}
Row row = sheet.getRow(found[0]);
return row == null ? null : row.getCell(found[1]);
}
/** 去冒号与空白,便于认「计 费 重:」这类版式。 */
private static String compactLabel(String text) {
if (text == null) {
return "";
}
return text.replace(":", "").replace(":", "").replaceAll("\\s+", "").trim();
}
/**
* 源模板是否海运询价单:看 sheet/SST 是否含「国际海运/海运询价」,或已有运输分类 Form Control。
* <p>
@@ -269,8 +269,71 @@ public final class QuoteTemplateMatcher {
return out;
}
private static boolean isDefault(Object raw) {
if (raw instanceof Boolean) {
/**
* 模板名归一:小写、去标点、去业务线与「模板/报价单」等噪声。
* <p>
* 只用于出单时按名取模板,不写回库、不影响后台展示。
* 「陆运国内城配、打包」与「国内城配/打包」要能对上。
*/
public static String normalizeTemplateName(String raw) {
if (StringUtils.isBlank(raw)) {
return "";
}
String text = raw.trim().toLowerCase(Locale.ROOT);
for (char ch : " \t\r\n-_/\\|、,,。.()()[]【】".toCharArray()) {
text = text.replace(String.valueOf(ch), "");
}
for (String noise : new String[] {"陆运", "空运", "海运", "报价单", "报价模板", "模板", "报价", "新版", "v1", "v2"}) {
text = text.replace(noise, "");
}
return text;
}
/**
* 按模板名直接取表:先全等,再互相包含,取名字更长(更具体)的那张。
* <p>
* 返回 null 表示没找到,调用方退回 {@link #pick} 的关键词匹配,
* 绝不能因为后台改了模板名就整条业务线出不了单。
*
* @param templates 主账 listEnabledForAgent 行
* @param templateName 转人工卡片上该业务类型的模板名
* @param businessLine 业务线;非空时只在该业务线里找
*/
public static Map<String, Object> pickByName(
List<Map<String, Object>> templates, String templateName, String businessLine) {
String wantName = normalizeTemplateName(templateName);
if (wantName.isEmpty() || templates == null) {
return null;
}
String wantBiz = normalizeBiz(businessLine);
Map<String, Object> fuzzy = null;
int fuzzyLen = 0;
for (Map<String, Object> t : templates) {
if (t == null) {
continue;
}
String biz = normalizeBiz(String.valueOf(t.getOrDefault("bizType", "")));
if (StringUtils.isNotBlank(wantBiz) && StringUtils.isNotBlank(biz) && !wantBiz.equals(biz)) {
continue;
}
String have = normalizeTemplateName(String.valueOf(t.getOrDefault("name", "")));
if (have.isEmpty()) {
continue;
}
if (have.equals(wantName)) {
return withMatchType(t, "name");
}
if (have.contains(wantName) || wantName.contains(have)) {
if (have.length() > fuzzyLen) {
fuzzy = t;
fuzzyLen = have.length();
}
}
}
return fuzzy == null ? null : withMatchType(fuzzy, "name");
}
private static boolean isDefault(Object raw) { if (raw instanceof Boolean) {
return Boolean.TRUE.equals(raw);
}
if (raw instanceof Number) {
@@ -99,6 +99,8 @@
{ "code": "weight_kg", "label": "重量(KG)", "requiredHint": false },
{ "code": "volume_cbm", "label": "体积(CBM)", "requiredHint": false },
{ "code": "chargeable_weight_kg", "label": "计费重", "requiredHint": false },
{ "code": "volume_ratio", "label": "比例", "requiredHint": false },
{ "code": "cargo_size", "label": "尺寸", "requiredHint": false },
{ "code": "delivery_address", "label": "派送地址", "requiredHint": false },
{ "code": "pickup_address", "label": "提货地址", "requiredHint": false },
{ "code": "transit_time", "label": "时效", "requiredHint": false },
@@ -169,6 +171,12 @@
"计费重": "chargeable_weight_kg",
"计费重量": "chargeable_weight_kg",
"Chargeable Weight": "chargeable_weight_kg",
"比例": "volume_ratio",
"货型": "volume_ratio",
"泡比": "volume_ratio",
"重泡比": "volume_ratio",
"尺寸": "cargo_size",
"货物尺寸": "cargo_size",
"费用总计": "total_amount",
"报价合计": "total_amount",
"RFQ No": "quote_no",
@@ -196,6 +204,9 @@
"pieces": "10",
"weight_kg": "1200",
"volume_cbm": "8.5",
"chargeable_weight_kg": "1419.5",
"volume_ratio": "1:167",
"cargo_size": "1.1*2.1*2.2",
"total_amount": "3680.00",
"fee_rows": [
{ "name": "O/F 海运费", "amount": "2900", "remark": "" },
@@ -0,0 +1,38 @@
-- 机器人回复语:询价/空运协同群没识别到工单号时,教销售怎么给机器人下达任务。
-- 仅改 inquiry_robot.inq_bot_reply;可重复执行。
-- 智能体调用点:agent/policy/inquiry_copy.py::air_need_work_order
-- {{bot_name}} 由 agent.policy.bot_reply.render 按后台 system.bot_display_name 自动填充。
--
-- 为什么不再用「固定 id + ON DUPLICATE KEY UPDATE」:
-- 旧版把 id 写死为 brv...052,而现网/测服的 brv...052 已被 system.bot_display_name 占用,
-- 于是 ON DUPLICATE 命中主键,把机器人显示名那条话术的正文、分类、排序全部改写掉了(2026-11-17 测服实测)。
-- 现在改为:先按 reply_code 更新(幂等),不存在时才插入;
-- 插入时若 052 仍被别的回复码占着,就自动生成 brv+uuid 的新 id,绝不动别人的行。
SET NAMES utf8mb4;
-- inq_bot_reply.reply_code 是 utf8mb4_general_ci,而 MySQL 8 默认连接排序规则是 utf8mb4_0900_ai_ci,
-- 直接比较会报 1267(Illegal mix of collations),所以显式统一连接排序规则。
SET collation_connection = 'utf8mb4_general_ci';
SET @want_id := 'brv10000000000000000000000000052';
SET @new_id := IF(EXISTS(SELECT 1 FROM `inq_bot_reply` WHERE `id` = @want_id),
CONCAT('brv', LEFT(REPLACE(UUID(), '-', ''), 29)),
@want_id);
UPDATE `inq_bot_reply`
SET `category_code` = 'inquiring',
`category_title` = '询价中',
`trigger_scene` = '询价/空运协同群未识别到工单号',
`reply_text` = '请以“已成交WO****@{{bot_name}}”方式给{{bot_name}}下达任务、“WO****已成交@{{bot_name}}”方式给{{bot_name}}下达任务。',
`enabled` = 1,
`sort_no` = 33
WHERE `reply_code` = 'inquiring.air_need_wo';
INSERT INTO `inq_bot_reply`
(`id`,`category_code`,`category_title`,`reply_code`,`trigger_scene`,`reply_text`,`enabled`,`sort_no`,`create_by`,`create_time`)
SELECT @new_id,'inquiring','询价中','inquiring.air_need_wo','询价/空运协同群未识别到工单号','请以“已成交WO****@{{bot_name}}”方式给{{bot_name}}下达任务、“WO****已成交@{{bot_name}}”方式给{{bot_name}}下达任务。',1,33,'admin',NOW()
FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `inq_bot_reply` WHERE `reply_code` = 'inquiring.air_need_wo');
-- 自检:应恰好 1 行 inquiring.air_need_wo,且 052 仍是 system.bot_display_name
SELECT `id`,`reply_code`,`category_code`,`sort_no` FROM `inq_bot_reply`
WHERE `reply_code` IN ('inquiring.air_need_wo','system.bot_display_name');
@@ -65,6 +65,7 @@ VALUES
已通知IT运维排查,请稍等。',1,30,'admin',NOW()),
('brv10000000000000000000000000031','inquiring','询价中','inquiring.air_release_deal_blocked','已成交不能释放舱位','释放舱位失败,工单{{ticket_no}}已成交。',1,31,'admin',NOW()),
('brv10000000000000000000000000032','inquiring','询价中','inquiring.air_release_need_lock','没有有效锁舱不能释放','工单{{ticket_no}}还没有有效锁舱,不能释放。',1,32,'admin',NOW()),
('brv10000000000000000000000000052','inquiring','询价中','inquiring.air_need_wo','询价/空运协同群未识别到工单号','请以“已成交WO****@{{bot_name}}”方式给{{bot_name}}下达任务、“WO****已成交@{{bot_name}}”方式给{{bot_name}}下达任务。',1,33,'admin',NOW()),
('brv10000000000000000000000000033','quoted','已报价','quoted.reject_ack','销售选择「不采用」','请问如何调整报价单,以满足您的需求?请说明要调哪一项费用,例如「提货费加 10%」。',1,1,'admin',NOW()),
('brv10000000000000000000000000034','quoted','已报价','quoted.adopt_excel','销售确认采用 → 生成 Excel','已确认采用该方案,正在生成 Excel 最终报价单…',1,2,'admin',NOW()),
('brv10000000000000000000000000035','quoted','已报价','quoted.adopt_pdf','销售确认采用 → 生成 PDF','已确认采用该方案,正在生成PDF最终报价单…',1,3,'admin',NOW()),
@@ -0,0 +1,94 @@
-- 转人工群报价改造(第 1 步:共用底座 + 空运)。
--
-- 背景:原实现把「转人工」写成六态终态,报价被冻结(handoff_frozen)、
-- 群消息被 is_handoff_ticket 丢掉。新流程要求:转人工后产品仍能在群里报价,
-- 六态照常 询价中 → 已报价;「谁在报价」用 collab_mode 单列表达。
--
-- 执行:mysql -h127.0.0.1 -u<user> -p -D inquiry_robot < migration_inq_handoff_collab_v1.sql
-- 只改 inquiry_robot;不写现网库 jeecg-boot,不做任何删除。
-- 幂等:ADD COLUMN 用 information_schema 先判存在,重复执行不会报错
-- (MySQL 8 的 ADD COLUMN 不支持 IF NOT EXISTS)。
SET NAMES utf8mb4;
-- ---------------------------------------------------------------------------
-- 1) inq_ticket.collab_mode:auto=系统自动协同;handoff=销售转人工、产品群内手工报价。
-- 旧单默认 auto,行为与改造前一致;历史「转人工」冻结单在第 4 段标成 handoff。
-- ---------------------------------------------------------------------------
SET @col := (
SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'inq_ticket' AND COLUMN_NAME = 'collab_mode'
);
SET @ddl := IF(@col = 0,
'ALTER TABLE `inq_ticket` ADD COLUMN `collab_mode` varchar(16) NOT NULL DEFAULT ''auto'' COMMENT ''协同模式 auto=自动协同 handoff=转人工产品群报价'' AFTER `collab_member_ids`',
'DO 0');
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- ---------------------------------------------------------------------------
-- 2) inq_quote.raw_text:产品非模板话术/图片说明解析不出来时的原话留档。
-- 不能编金额,但销售与后台要能回看产品到底怎么说的。
-- ---------------------------------------------------------------------------
SET @col := (
SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'inq_quote' AND COLUMN_NAME = 'raw_text'
);
SET @ddl := IF(@col = 0,
'ALTER TABLE `inq_quote` ADD COLUMN `raw_text` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT ''群内原始报价文字(参考留档,不参与结构化解析)'' AFTER `payload_json`',
'DO 0');
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- 2b) raw_source:原文来源 text/image/file/nonstandard。
SET @col := (
SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'inq_quote' AND COLUMN_NAME = 'raw_source'
);
SET @ddl := IF(@col = 0,
'ALTER TABLE `inq_quote` ADD COLUMN `raw_source` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT ''原文来源 text/image/file/nonstandard'' AFTER `raw_text`',
'DO 0');
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- ---------------------------------------------------------------------------
-- 3) inq_attachment.quote_id:产品第 3 版报价带的图/文件,后台要能点回第 3 版。
-- 可空:普通询价附件、锁舱附件不属于某个手工报价版本。
-- 放在 file_size 之后,不依赖 create_by 列(各环境补列进度可能不同)。
-- ---------------------------------------------------------------------------
SET @col := (
SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'inq_attachment' AND COLUMN_NAME = 'quote_id'
);
SET @ddl := IF(@col = 0,
'ALTER TABLE `inq_attachment` ADD COLUMN `quote_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT ''关联 inq_quote.id,可空'' AFTER `file_size`',
'DO 0');
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- ---------------------------------------------------------------------------
-- 4) 老单兜底:历史上确实被冻结在「转人工」的单,协同模式标 handoff,
-- 保持原冻结行为,不被新逻辑当成可自动跟进的单。
-- 新逻辑不再写状态「转人工」,所以这条只会命中改造前的存量。
-- ---------------------------------------------------------------------------
UPDATE `inq_ticket`
SET `collab_mode` = 'handoff'
WHERE `status` = '转人工'
AND (`collab_mode` IS NULL OR `collab_mode` = '' OR `collab_mode` = 'auto');
-- ---------------------------------------------------------------------------
-- 自检:应为 1 行 collab_mode、2 行 raw_text/raw_source、1 行 quote_id。
-- 陆运产品岗位(马涛)修正不在本脚本,放到第 3 步陆运迁移,避免提前改线上岗位权限。
-- ---------------------------------------------------------------------------
SELECT TABLE_NAME, COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, COLUMN_DEFAULT
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND (
(TABLE_NAME = 'inq_ticket' AND COLUMN_NAME = 'collab_mode')
OR (TABLE_NAME = 'inq_quote' AND COLUMN_NAME IN ('raw_text', 'raw_source'))
OR (TABLE_NAME = 'inq_attachment' AND COLUMN_NAME = 'quote_id')
)
ORDER BY TABLE_NAME, COLUMN_NAME;
@@ -0,0 +1,21 @@
-- 陆运产品岗位修正(第 3 步陆运专用,请在第 3 步发版时再执行)。
--
-- 背景:马涛在种子里是销售,陆运转人工按岗位匹配会漏人;
-- 第 1 步只发转人工底座,不动线上岗位权限,所以单独一份。
--
-- 只改这一条岗位的 role_code/role_label/routes:
-- 不动账号、不动企微 userid、不动密码、不动其它岗位。
-- 条件带原角色 sales,避免把已经人工改过的岗位再覆盖(幂等)。
SET NAMES utf8mb4;
UPDATE `inq_staff_role`
SET `role_code` = 'land',
`role_label` = '产品·陆运',
`routes` = '国内长途/零担,国内城配/拖车/打包'
WHERE `name` = '马涛'
AND `role_code` = 'sales';
SELECT `name`, `role_code`, `role_label`, `routes`
FROM `inq_staff_role`
WHERE `name` = '马涛';
@@ -0,0 +1,66 @@
-- 陆运转人工报价场景卡:按产品终版表补齐 5 档报价时效。
-- 新增 land_ca_eu(普件(涉及中欧、中亚) 24 小时),并把其余 4 档小时数对齐终版表:
-- 普件(常用线路) 2h / 普件(涉及国内+国外段) 8h / 定制化 48h / 急件 0=不监测。
-- 只改编码与小时数,不改员工、不改销售超时规则、不新建表。
-- 仅改 inquiry_robot;幂等可重复执行。
SET NAMES utf8mb4;
-- 1) 新增「普件(涉及中欧、中亚)」24 小时。产品口径:中欧/中亚比东南亚多一轮境外询价。
INSERT INTO `inq_response_timeout` (
`id`, `timeout_code`, `transport_mode`, `role_code`, `route_category`,
`transport_type`, `timeout_hours`, `sort_no`, `create_by`, `create_time`, `update_by`, `update_time`
)
SELECT
'rt100000000000000000000000000031',
'land_ca_eu',
'LAND',
'product',
'',
CONVERT(UNHEX('e699aee4bbb628e6b689e58f8ae4b8ade6aca7e38081e4b8ade4ba9a29') USING utf8mb4),
24,
IFNULL((
SELECT `sort_no` FROM (
SELECT `sort_no` FROM `inq_response_timeout` WHERE `timeout_code`='land_hk_cross' LIMIT 1
) AS `cross`
), 8) + 1,
'system',
NOW(),
'system',
NOW()
FROM DUAL
WHERE NOT EXISTS (
SELECT 1 FROM (
SELECT `id` FROM `inq_response_timeout` WHERE `timeout_code`='land_ca_eu'
) AS `existed`
);
-- 2) 4 档小时数对齐终版表(原来 land_common 是 0,销售侧看不到报价时效)。
UPDATE `inq_response_timeout`
SET `timeout_hours`=2,
`update_by`='system',
`update_time`=NOW()
WHERE `timeout_code`='land_common'
AND `timeout_hours` <> 2;
UPDATE `inq_response_timeout`
SET `timeout_hours`=8,
`update_by`='system',
`update_time`=NOW()
WHERE `timeout_code`='land_hk_cross'
AND `timeout_hours` <> 8;
UPDATE `inq_response_timeout`
SET `timeout_hours`=48,
`update_by`='system',
`update_time`=NOW()
WHERE `timeout_code`='land_hk_special'
AND `timeout_hours` <> 48;
-- 急件:0 表示不监测,禁止写成 1 或空值。
UPDATE `inq_response_timeout`
SET `timeout_hours`=0,
`update_by`='system',
`update_time`=NOW()
WHERE `timeout_code`='land_hk_express'
AND `timeout_hours` <> 0;
@@ -212,6 +212,67 @@ public class QuoteTemplateFillTest {
}
}
/**
* 空运到港/到门:计费重右侧缺「比例」时自动补标签;已有则不改。
* 出单事实 volume_ratio 来自 TMS 货型/泡重比,写到比例格。
*/
@Test
public void ensureAirVolumeRatioLabelAndFillFromTmsCargoType() throws Exception {
Path dir = Files.createTempDirectory("air-ratio");
Path src = dir.resolve("air-tpl.xlsx");
Path outXlsx = dir.resolve("air-out.xlsx");
try (XSSFWorkbook wb = new XSSFWorkbook()) {
Sheet sheet = wb.createSheet("Sheet2");
sheet.createRow(0).createCell(0).setCellValue("空运报价单");
Row r8 = sheet.createRow(7);
r8.createCell(0).setCellValue("品名");
r8.createCell(4).setCellValue("是否带电");
Row r9 = sheet.createRow(8);
r9.createCell(0).setCellValue("件数");
r9.createCell(4).setCellValue("贸易条款");
Row r10 = sheet.createRow(9);
r10.createCell(0).setCellValue("重量");
r10.createCell(4).setCellValue("货好时间");
Row r11 = sheet.createRow(10);
r11.createCell(0).setCellValue("体积");
r11.createCell(4).setCellValue("时效要求");
Row r12 = sheet.createRow(11);
r12.createCell(0).setCellValue("计费重");
r12.createCell(1).setCellValue("");
// 右侧空着:应补「比例」
r12.createCell(4).setCellValue("");
try (java.io.OutputStream os = Files.newOutputStream(src)) {
wb.write(os);
}
}
try (Workbook probe = org.apache.poi.ss.usermodel.WorkbookFactory.create(Files.newInputStream(src))) {
assertTrue(QuoteTemplateExcelSupport.ensureAirVolumeRatioLabel(probe));
}
// fillWorkbook 内会再补一次标签并写入 TMS 比例
Map<String, Object> facts = new HashMap<>();
facts.put("运输方式", "空运");
facts.put("品名", "普货");
Map<String, Object> quote = new HashMap<>();
quote.put("chargeableWeightKg", "500.1");
quote.put("cargoType", "1:212");
quote.put("total", "4750.95");
quote.put("currency", "CNY");
JSONObject fill = org.jeecg.modules.inquiry.service.impl.InquiryQuoteTemplateServiceImpl
.buildFillFacts("WO202611080001", facts, quote, "LinMianXun", "AIR");
assertEquals("1:212", fill.getString("volume_ratio"));
assertEquals("1:212", fill.getString("比例"));
JSONObject mapping = new JSONObject(true);
mapping.put("fields", new JSONObject(true));
QuoteTemplateExcelSupport.fillWorkbook(src, outXlsx, mapping, fill);
try (Workbook got = org.apache.poi.ss.usermodel.WorkbookFactory.create(Files.newInputStream(outXlsx))) {
Sheet sheet = got.getSheet("Sheet2");
DataFormatter fmt = new DataFormatter();
assertEquals("比例:", fmt.formatCellValue(sheet.getRow(11).getCell(4)));
assertEquals("1:212", fmt.formatCellValue(sheet.getRow(11).getCell(5)));
}
}
/**
* 空运没有时效:即便 TMS 回了 eta,出单也不填 transit_* / 时效。
* 报价有效期仍要留下。
@@ -1066,11 +1127,6 @@ public class QuoteTemplateFillTest {
*/
@Test
public void parseAirChargesAssignProjectByTmsBucket() {
System.setProperty("ytd.agent.debug.log",
java.nio.file.Paths.get("").toAbsolutePath().getParent() != null
? java.nio.file.Paths.get("debug-4c500b.log").toAbsolutePath().toString()
: "debug-4c500b.log");
System.setProperty("ytd.agent.debug.runId", "pre-fix-bucket");
String airOptions = "["
+ "{\"optionNo\":\"AIR-OPT01\",\"salePrice\":183370.0,\"currency\":\"CNY\","
+ "\"chargeableWeightKg\":16670.0,"
@@ -1216,9 +1272,6 @@ public class QuoteTemplateFillTest {
*/
@Test
public void airManualOriginFeeWritesIntoOriginBandNotAirSegment() throws Exception {
System.setProperty("ytd.agent.debug.log",
new java.io.File("debug-4c500b.log").getAbsolutePath());
System.setProperty("ytd.agent.debug.runId", "post-fix-place");
Path src = Files.createTempFile("quote-air-band-src", ".xlsx");
Path out = Files.createTempFile("quote-air-band-out", ".xlsx");
try (Workbook wb = new XSSFWorkbook()) {
@@ -2504,7 +2557,6 @@ public class QuoteTemplateFillTest {
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);
@@ -2559,11 +2611,10 @@ public class QuoteTemplateFillTest {
/**
* WO202610140014 复现:单腿广西→胡志明;模板 3T 有尺寸 vs 无尺寸。
* 用于对照 debug-67d875:切片是否把目的地/起始地留空,以及填表是否清掉 3T 尺寸。
* 用于对照:切片是否把目的地/起始地留空,以及填表是否清掉 3T 尺寸。
*/
@Test
public void landCrossBorderFtlWo014OdAnd3tDimProbe() throws Exception {
System.setProperty("ytd.agent.debug.runId", "wo014-junit");
Path src = Files.createTempFile("quote-land-wo014-src", ".xlsx");
Path out = Files.createTempFile("quote-land-wo014-out", ".xlsx");
try (Workbook wb = new XSSFWorkbook()) {