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

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

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
@@ -44,13 +44,16 @@
and bu.tenant_id = #{user.tenantId}
</if>
<if test="user.account!=null and user.account != ''">
and bu.account = #{user.account}
and bu.account like concat(concat('%', #{user.account}), '%')
</if>
<if test="user.realName!=null and user.realName != ''">
and bu.real_name = #{user.realName}
and bu.real_name like concat(concat('%', #{user.realName}), '%')
</if>
<if test="user.phone!=null and user.phone != ''">
and bu.phone = #{user.phone}
and (
bu.phone like concat(concat('%', #{user.phone}), '%')
or bu.account like concat(concat('%', #{user.phone}), '%')
)
</if>
<if test="user.userType!=null and user.userType != ''">
and bu.user_type = #{user.userType}
@@ -437,7 +437,7 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements ID
if (Func.isEmpty(dept.getTenantId())) {
throw new ServiceException("租户ID不能为空");
}
validateDeptCategory(dept, parent);
validateDeptCategory(dept);
validateDeptCode(dept, parent);
return saveOrUpdate(dept);
}
@@ -619,27 +619,8 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements ID
return "Basic " + value;
}
private void validateDeptCategory(Dept dept, Dept parent) {
// 顶级组织不要求选择上级组织
if (parent == null) {
if (Integer.valueOf(6).equals(dept.getDeptCategory()) && Func.isEmpty(dept.getCarrierCustomerId())) {
throw new ServiceException("请选择承运商");
}
return;
}
List<Integer> allowedCategories;
if (BladeConstant.TOP_PARENT_ID.equals(parent.getParentId())) {
allowedCategories = "外部组织".equals(parent.getDeptName()) ? List.of(6) : List.of(1);
} else if (Integer.valueOf(1).equals(parent.getDeptCategory())) {
allowedCategories = List.of(2, 3);
} else if (List.of(2, 3).contains(parent.getDeptCategory())) {
allowedCategories = List.of(4, 5, 6);
} else {
throw new ServiceException("上级组织层级不支持新增下级组织");
}
if (!allowedCategories.contains(dept.getDeptCategory())) {
throw new ServiceException("组织类型不符合上级组织层级规则");
}
private void validateDeptCategory(Dept dept) {
// 组织树层级仅由 parentId / ancestors 决定,组织类型不再做上下级约束
if (Integer.valueOf(6).equals(dept.getDeptCategory()) && Func.isEmpty(dept.getCarrierCustomerId())) {
throw new ServiceException("请选择承运商");
}
@@ -50,7 +50,7 @@ public class MeasurementUnitServiceImpl extends BaseServiceImpl<MeasurementUnitM
private static final int UNIT_NAME_MAX_LENGTH = 50;
private static final int DIMENSION_MAX_LENGTH = 20;
private static final int REMARK_MAX_LENGTH = 200;
private static final Set<String> DIMENSIONS = Set.of("重量", "体积", "数量");
private static final Set<String> DIMENSIONS = Set.of("重量", "体积", "数量", "整车", "里程", "吨·公里");
@Override
public IPage<MeasurementUnitVO> selectMeasurementUnitPage(IPage<MeasurementUnitVO> page,
@@ -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(), "客户合同不能为空");