✨ 放开组织类型层级约束,并修复调度数量单位回填

组织树不再按类型约束上下级;计量维度扩展整车/里程/吨·公里;运单从货物明细补齐数量单位,用户查询支持模糊匹配。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-04 20:26:16 +08:00
parent a5e89aa6dc
commit 683351d764
4 changed files with 77 additions and 28 deletions
@@ -1458,7 +1458,9 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
}
/**
* 完整录入多货物时,运单主表 quantity 按 goodsJson 数量合计回写,避免只落首行数量。
* 从 goodsJson 回写运单主表货物字段:
* 1. 顶层数量单位 / 货物名称 / 货物类型为空时,取首条有效货物补齐;
* 2. 完整录入多货物时,数量按 goodsJson 合计回写。
*/
private void syncQuantityFromGoodsJson(Waybill waybill) {
if (waybill == null || Func.isEmpty(waybill.getGoodsJson())) {
@@ -1470,7 +1472,53 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
} catch (Exception exception) {
return;
}
if (Func.isEmpty(goodsList) || goodsList.size() <= 1) {
if (Func.isEmpty(goodsList)) {
return;
}
Map firstGoods = null;
for (Map goods : goodsList) {
if (goods == null) {
continue;
}
firstGoods = goods;
break;
}
if (firstGoods != null) {
if (Func.isEmpty(waybill.getQuantityUnit())) {
String quantityUnit = firstNonBlank(firstGoods, "quantityUnit", "goodsQuantityUnit", "unit");
if (Func.isNotEmpty(quantityUnit)) {
waybill.setQuantityUnit(quantityUnit);
}
}
if (Func.isEmpty(waybill.getCargoName())) {
String cargoName = firstNonBlank(firstGoods, "cargoName", "goodsName");
if (Func.isNotEmpty(cargoName)) {
waybill.setCargoName(cargoName);
}
}
if (Func.isEmpty(waybill.getCargoType())) {
String cargoType = firstNonBlank(firstGoods, "cargoType", "goodsType");
if (Func.isNotEmpty(cargoType)) {
waybill.setCargoType(cargoType);
}
}
if (waybill.getQuantity() == null && goodsList.size() == 1) {
Object quantityValue = firstGoods.get("quantity");
if (quantityValue == null) {
quantityValue = firstGoods.get("cargoQuantity");
}
if (quantityValue == null) {
quantityValue = firstGoods.get("goodsQuantity");
}
if (quantityValue != null && Func.isNotEmpty(String.valueOf(quantityValue).trim())) {
BigDecimal quantity = new BigDecimal(String.valueOf(quantityValue).trim());
if (!isSentinelMinusOne(quantity)) {
waybill.setQuantity(quantity);
}
}
}
}
if (goodsList.size() <= 1) {
return;
}
BigDecimal total = BigDecimal.ZERO;
@@ -1491,6 +1539,23 @@ public class WaybillServiceImpl extends BaseServiceImpl<WaybillMapper, Waybill>
}
}
private String firstNonBlank(Map goods, String... keys) {
if (goods == null || keys == null) {
return null;
}
for (String key : keys) {
Object value = goods.get(key);
if (value == null) {
continue;
}
String text = String.valueOf(value).trim();
if (Func.isNotEmpty(text)) {
return text;
}
}
return null;
}
private void validate(Waybill waybill) {
TransportBusinessSupport.validateRequired(waybill.getProjectName(), "项目不能为空");
TransportBusinessSupport.validateRequired(waybill.getContractName(), "客户合同不能为空");