|
@@ -42,7 +42,6 @@ import com.sckw.fleet.api.model.vo.*;
|
|
|
import com.sckw.mongo.model.SckwWaybillOrder;
|
|
import com.sckw.mongo.model.SckwWaybillOrder;
|
|
|
import com.sckw.order.api.dubbo.TradeOrderInfoService;
|
|
import com.sckw.order.api.dubbo.TradeOrderInfoService;
|
|
|
import com.sckw.order.api.model.OrderDetailVo;
|
|
import com.sckw.order.api.model.OrderDetailVo;
|
|
|
-import com.sckw.order.api.model.OrderUnitInfoDetailVO;
|
|
|
|
|
import com.sckw.order.api.model.TradeOrderContractVo;
|
|
import com.sckw.order.api.model.TradeOrderContractVo;
|
|
|
import com.sckw.order.api.model.TradeOrderSettlePara;
|
|
import com.sckw.order.api.model.TradeOrderSettlePara;
|
|
|
import com.sckw.payment.api.feign.PaymentFeignService;
|
|
import com.sckw.payment.api.feign.PaymentFeignService;
|
|
@@ -190,6 +189,14 @@ public class KwtWaybillOrderV1Service {
|
|
|
* 代理商企业类型。
|
|
* 代理商企业类型。
|
|
|
*/
|
|
*/
|
|
|
private static final int SUPPLY_AGENT_ENT_TYPE = 4;
|
|
private static final int SUPPLY_AGENT_ENT_TYPE = 4;
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 物流订单企业表代理单位类型。
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final int LOGISTICS_AGENT_UNIT_TYPE = 4;
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 物流订单企业表供应单位类型。
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final int LOGISTICS_SUPPLY_UNIT_TYPE = 6;
|
|
|
/**
|
|
/**
|
|
|
* @param params 请求参数
|
|
* @param params 请求参数
|
|
|
* @desc 统计
|
|
* @desc 统计
|
|
@@ -3217,7 +3224,7 @@ public class KwtWaybillOrderV1Service {
|
|
|
private boolean shouldReturnEmptyResultForLogistics(WaybillOrderReq req, Set<Long> logOrderIds) {
|
|
private boolean shouldReturnEmptyResultForLogistics(WaybillOrderReq req, Set<Long> logOrderIds) {
|
|
|
boolean hasLogisticsFilter = Stream.of(
|
|
boolean hasLogisticsFilter = Stream.of(
|
|
|
req.getLogisticsOrderNo(), req.getGoodsName(),
|
|
req.getLogisticsOrderNo(), req.getGoodsName(),
|
|
|
- req.getCarrierId(), req.getConsignorId(), req.getLogisticsOrderId())
|
|
|
|
|
|
|
+ req.getCarrierId(), req.getConsignorId(), req.getAgentEntId(), req.getLogisticsOrderId())
|
|
|
.anyMatch(StringUtils::isNotBlank);
|
|
.anyMatch(StringUtils::isNotBlank);
|
|
|
|
|
|
|
|
boolean hasEnterpriseFilter = Objects.nonNull(LoginUserHolder.getEntId());
|
|
boolean hasEnterpriseFilter = Objects.nonNull(LoginUserHolder.getEntId());
|
|
@@ -3651,6 +3658,19 @@ public class KwtWaybillOrderV1Service {
|
|
|
log.debug("企业ID集合为空,跳过基于企业的物流订单ID查询");
|
|
log.debug("企业ID集合为空,跳过基于企业的物流订单ID查询");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 如果指定了代理单位,基于物流订单企业表代理单位记录过滤物流订单ID
|
|
|
|
|
+ if (StringUtils.isNotBlank(req.getAgentEntId())) {
|
|
|
|
|
+ Set<Long> orderIdsByAgentEnt = getLogOrderIdsByAgentEntId(req.getAgentEntId(), logOrderIds);
|
|
|
|
|
+ log.debug("根据代理单位查询到物流订单ID数量: {}", orderIdsByAgentEnt.size());
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(orderIdsByAgentEnt)) {
|
|
|
|
|
+ intersectLogOrderIds(logOrderIds, orderIdsByAgentEnt);
|
|
|
|
|
+ log.debug("代理单位查询后,当前物流订单ID数量: {}", logOrderIds.size());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.debug("根据代理单位未查询到物流订单,返回空集合");
|
|
|
|
|
+ return Collections.emptySet();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 如果指定了物流订单号,根据订单号查询
|
|
// 如果指定了物流订单号,根据订单号查询
|
|
|
if (StringUtils.isNotBlank(req.getLogisticsOrderNo())) {
|
|
if (StringUtils.isNotBlank(req.getLogisticsOrderNo())) {
|
|
|
Set<Long> orderIdsByNo = getLogOrderIdsByNo(req.getLogisticsOrderNo());
|
|
Set<Long> orderIdsByNo = getLogOrderIdsByNo(req.getLogisticsOrderNo());
|
|
@@ -3723,9 +3743,97 @@ public class KwtWaybillOrderV1Service {
|
|
|
return entIds;
|
|
return entIds;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * 获取当前登录用户的数据权限配置
|
|
|
|
|
|
|
+ * 根据代理单位ID查询关联的物流订单ID集合。
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 业务逻辑说明:
|
|
|
|
|
+ * 1. 校验并解析代理单位ID,确保格式合法。
|
|
|
|
|
+ * 2. 根据是否存在前置过滤的物流订单ID集合(logOrderIds),选择不同的查询策略以优化性能:
|
|
|
|
|
+ * - 若 logOrderIds 为空:直接根据代理单位ID和单位类型(代理/承运)查询所有关联的物流订单单位记录。
|
|
|
|
|
+ * - 若 logOrderIds 不为空:在指定的物流订单ID范围内,查询属于该代理单位的记录,缩小查询范围。
|
|
|
|
|
+ * 3. 从查询结果中提取并返回符合条件的物流订单ID集合。
|
|
|
|
|
+ * </p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param agentEntId 代理单位ID字符串
|
|
|
|
|
+ * @param logOrderIds 前置条件过滤后的物流订单ID集合,可为空
|
|
|
|
|
+ * @return 关联的物流订单ID集合
|
|
|
|
|
+ * @throws BusinessException 当代理单位ID格式非法时抛出
|
|
|
|
|
+ */
|
|
|
|
|
+ private Set<Long> getLogOrderIdsByAgentEntId(String agentEntId, Set<Long> logOrderIds) {
|
|
|
|
|
+ log.debug("开始根据代理单位ID查询物流订单,agentEntId: {}, 前置物流订单ID数量: {}",
|
|
|
|
|
+ agentEntId, CollectionUtils.isEmpty(logOrderIds) ? 0 : logOrderIds.size());
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 解析代理单位ID
|
|
|
|
|
+ Long parsedAgentEntId;
|
|
|
|
|
+ try {
|
|
|
|
|
+ parsedAgentEntId = Long.valueOf(agentEntId);
|
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
|
+ log.warn("代理单位查询失败:代理单位ID格式非法,agentEntId={}", agentEntId, e);
|
|
|
|
|
+ throw new BusinessException("代理单位ID格式错误");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 查询物流订单单位信息(类型为代理/承运)
|
|
|
|
|
+ List<KwtLogisticsOrderUnit> agentUnits;
|
|
|
|
|
+ if (CollectionUtils.isEmpty(logOrderIds)) {
|
|
|
|
|
+ // 场景A:无前置订单ID限制,全量查询该代理单位关联的所有物流订单单位
|
|
|
|
|
+ log.debug("执行全量查询:根据代理单位ID [{}] 和单位类型 [{}] 查询物流订单单位", parsedAgentEntId, LOGISTICS_AGENT_UNIT_TYPE);
|
|
|
|
|
+ agentUnits = kwtLogisticsOrderUnitRepository.queryByEntIdAndUnitType(parsedAgentEntId, LOGISTICS_AGENT_UNIT_TYPE);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 场景B:有前置订单ID限制,仅在指定订单范围内查询,提高查询效率
|
|
|
|
|
+ log.debug("执行范围查询:在 {} 个物流订单ID中,筛选代理单位ID [{}] 和单位类型 [{}] 的记录",
|
|
|
|
|
+ logOrderIds.size(), parsedAgentEntId, LOGISTICS_AGENT_UNIT_TYPE);
|
|
|
|
|
+ agentUnits = kwtLogisticsOrderUnitRepository.queryByLOrderIdsAndUnitType(logOrderIds, LOGISTICS_AGENT_UNIT_TYPE);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.debug("查询到物流订单单位记录数量: {}", CollectionUtils.isEmpty(agentUnits) ? 0 : agentUnits.size());
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 提取物流订单ID
|
|
|
|
|
+ Set<Long> result = extractAgentLogOrderIdsByLogisticsUnit(agentUnits, parsedAgentEntId);
|
|
|
|
|
+ log.debug("根据代理单位ID [{}] 最终筛选出的物流订单ID数量: {}", parsedAgentEntId, result.size());
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 从物流订单企业表记录中提取指定代理单位关联的物流订单ID。
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 业务逻辑说明:
|
|
|
|
|
+ * 1. 基础校验:若代理单位ID为空或待处理的企业列表为空,直接返回空集合,避免无效计算。
|
|
|
|
|
+ * 2. 流式过滤:
|
|
|
|
|
+ * - 过滤掉列表中的空对象,防止NPE。
|
|
|
|
|
+ * - 筛选出企业ID(entId)与目标代理单位ID(agentEntId)一致的记录。
|
|
|
|
|
+ * 3. 提取与清洗:
|
|
|
|
|
+ * - 提取匹配记录的物流订单ID(lOrderId)。
|
|
|
|
|
+ * - 再次过滤掉可能为空的订单ID,确保结果集的纯净性。
|
|
|
|
|
+ * 4. 结果收集:将符合条件的物流订单ID收集到Set集合中并返回,自动去重。
|
|
|
|
|
+ * </p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param agentUnits 物流订单企业表代理单位记录列表
|
|
|
|
|
+ * @param agentEntId 目标代理单位ID
|
|
|
|
|
+ * @return 关联的物流订单ID集合,若无匹配数据则返回空集合
|
|
|
*/
|
|
*/
|
|
|
|
|
+ static Set<Long> extractAgentLogOrderIdsByLogisticsUnit(List<KwtLogisticsOrderUnit> agentUnits, Long agentEntId) {
|
|
|
|
|
+ // 1. 参数有效性校验
|
|
|
|
|
+ if (Objects.isNull(agentEntId) || CollectionUtils.isEmpty(agentUnits)) {
|
|
|
|
|
+ log.debug("提取代理单位关联物流订单ID失败:参数无效,agentEntId={}, listSize={}",
|
|
|
|
|
+ agentEntId, agentUnits == null ? 0 : agentUnits.size());
|
|
|
|
|
+ return Sets.newHashSet();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 流式处理:过滤、映射、收集
|
|
|
|
|
+ Set<Long> result = agentUnits.stream()
|
|
|
|
|
+ .filter(Objects::nonNull) // 过滤空对象
|
|
|
|
|
+ .filter(unit -> Objects.equals(unit.getEntId(), agentEntId)) // 匹配代理单位ID
|
|
|
|
|
+ .map(KwtLogisticsOrderUnit::getLOrderId) // 提取物流订单ID
|
|
|
|
|
+ .filter(Objects::nonNull) // 过滤空订单ID
|
|
|
|
|
+ .collect(Collectors.toSet()); // 收集结果并去重
|
|
|
|
|
+
|
|
|
|
|
+ log.debug("提取代理单位[{}]关联的物流订单ID完成,数量: {}", agentEntId, result.size());
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private DataPermissionDTO fetchDataPermissionForCurrentUser() {
|
|
private DataPermissionDTO fetchDataPermissionForCurrentUser() {
|
|
|
try {
|
|
try {
|
|
|
DataPermissionFilterReqDto reqDto = new DataPermissionFilterReqDto();
|
|
DataPermissionFilterReqDto reqDto = new DataPermissionFilterReqDto();
|
|
@@ -4305,14 +4413,12 @@ public class KwtWaybillOrderV1Service {
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 通过贸易订单代理商名称关键字查询关联的运单ID集合。
|
|
|
|
|
|
|
+ * 通过物流订单企业表代理单位名称关键字查询关联的运单ID集合。
|
|
|
* <p>
|
|
* <p>
|
|
|
* 业务逻辑链路:
|
|
* 业务逻辑链路:
|
|
|
- * 1. 根据代理商名称关键字查询贸易订单单位信息(包含承运/代理单位)。
|
|
|
|
|
- * 2. 筛选出类型为“代理/承运”(UnitType=2)的单位,提取对应的贸易订单ID。
|
|
|
|
|
- * 3. 根据贸易订单ID查询贸易订单详情,并进一步过滤出代理商名称匹配且标记为代理的订单ID。
|
|
|
|
|
- * 4. 根据贸易订单ID查询关联的物流订单ID。
|
|
|
|
|
- * 5. 根据物流订单ID查询关联的子运单,最终提取主运单ID集合。
|
|
|
|
|
|
|
+ * 1. 根据代理商名称关键字查询物流订单企业表中的代理单位记录(UnitType=4)。
|
|
|
|
|
+ * 2. 提取代理单位关联的物流订单ID。
|
|
|
|
|
+ * 3. 根据物流订单ID查询关联的子运单,最终提取主运单ID集合。
|
|
|
* </p>
|
|
* </p>
|
|
|
*
|
|
*
|
|
|
* @param keywords 代理商名称关键字
|
|
* @param keywords 代理商名称关键字
|
|
@@ -4328,58 +4434,25 @@ public class KwtWaybillOrderV1Service {
|
|
|
log.info("开始通过代理商名称关键字查询运单,keywords: {}", keywords);
|
|
log.info("开始通过代理商名称关键字查询运单,keywords: {}", keywords);
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- // 1. 根据代理商名称查询贸易订单单位信息
|
|
|
|
|
- List<OrderUnitInfoDetailVO> orderUnits = tradeOrderInfoService.queryOrderUnitInfByEntName(keywords);
|
|
|
|
|
- if (CollectionUtils.isEmpty(orderUnits)) {
|
|
|
|
|
- log.debug("通过代理商名称[{}]未查询到贸易订单单位信息", keywords);
|
|
|
|
|
|
|
+ // 1. 根据代理商名称查询物流订单企业表中的代理单位记录
|
|
|
|
|
+ List<KwtLogisticsOrderUnit> agentUnits = kwtLogisticsOrderUnitRepository.queryByFirmNameAndUnitType(
|
|
|
|
|
+ keywords, LOGISTICS_AGENT_UNIT_TYPE);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(agentUnits)) {
|
|
|
|
|
+ log.debug("通过代理商名称[{}]未查询到物流订单代理单位信息", keywords);
|
|
|
return Sets.newHashSet();
|
|
return Sets.newHashSet();
|
|
|
}
|
|
}
|
|
|
- log.debug("查询到贸易订单单位数量: {}", orderUnits.size());
|
|
|
|
|
|
|
+ log.debug("查询到物流订单代理单位数量: {}", agentUnits.size());
|
|
|
|
|
|
|
|
- // 2. 筛选单位为代理/承运类型(UnitType=2),并提取贸易订单ID
|
|
|
|
|
- Set<Long> tradeOrderIds = orderUnits.stream()
|
|
|
|
|
- .filter(Objects::nonNull)
|
|
|
|
|
- .filter(unit -> Objects.equals(unit.getUnitType(), String.valueOf(NumberConstant.TWO)))
|
|
|
|
|
- .map(OrderUnitInfoDetailVO::getTOrderId)
|
|
|
|
|
- .filter(Objects::nonNull)
|
|
|
|
|
- .collect(Collectors.toSet());
|
|
|
|
|
-
|
|
|
|
|
- if (CollectionUtils.isEmpty(tradeOrderIds)) {
|
|
|
|
|
- log.debug("通过代理商名称[{}]未筛选到有效的代理类型贸易订单ID", keywords);
|
|
|
|
|
- return Sets.newHashSet();
|
|
|
|
|
- }
|
|
|
|
|
- log.debug("筛选到代理类型贸易订单ID数量: {}", tradeOrderIds.size());
|
|
|
|
|
-
|
|
|
|
|
- // 3. 查询贸易订单详情,并二次过滤确认代理商名称匹配
|
|
|
|
|
- List<OrderDetailVo> tradeOrderDetails = tradeOrderInfoService.queryByTradeOrderIds(tradeOrderIds);
|
|
|
|
|
- Set<Long> agentTradeOrderIds = extractAgentTradeOrderIdsByAgentName(tradeOrderDetails, keywords);
|
|
|
|
|
-
|
|
|
|
|
- if (CollectionUtils.isEmpty(agentTradeOrderIds)) {
|
|
|
|
|
- log.debug("通过代理商名称[{}]在贸易订单详情中未匹配到有效订单", keywords);
|
|
|
|
|
- return Sets.newHashSet();
|
|
|
|
|
- }
|
|
|
|
|
- log.debug("二次过滤后匹配的贸易订单ID数量: {}", agentTradeOrderIds.size());
|
|
|
|
|
-
|
|
|
|
|
- // 4. 根据贸易订单ID查询关联的物流订单
|
|
|
|
|
- List<KwtLogisticsOrder> logisticsOrders = logisticsOrderRepository.queryByTradeOrderIds(agentTradeOrderIds);
|
|
|
|
|
- if (CollectionUtils.isEmpty(logisticsOrders)) {
|
|
|
|
|
- log.debug("贸易订单ID集合[{}]未关联到任何物流订单", agentTradeOrderIds);
|
|
|
|
|
- return Sets.newHashSet();
|
|
|
|
|
- }
|
|
|
|
|
- log.debug("查询到关联的物流订单数量: {}", logisticsOrders.size());
|
|
|
|
|
-
|
|
|
|
|
- // 5. 提取物流订单ID
|
|
|
|
|
- Set<Long> logOrderIds = logisticsOrders.stream()
|
|
|
|
|
- .map(KwtLogisticsOrder::getId)
|
|
|
|
|
- .filter(Objects::nonNull)
|
|
|
|
|
- .collect(Collectors.toSet());
|
|
|
|
|
|
|
+ // 2. 提取物流订单ID
|
|
|
|
|
+ Set<Long> logOrderIds = extractAgentLogOrderIdsByAgentFirmName(agentUnits, keywords);
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(logOrderIds)) {
|
|
if (CollectionUtils.isEmpty(logOrderIds)) {
|
|
|
- log.warn("物流订单列表中ID为空,无法继续查询子运单");
|
|
|
|
|
|
|
+ log.warn("物流订单代理单位记录中物流订单ID为空,无法继续查询子运单,keywords: {}", keywords);
|
|
|
return Sets.newHashSet();
|
|
return Sets.newHashSet();
|
|
|
}
|
|
}
|
|
|
|
|
+ log.debug("通过代理商名称[{}]匹配到物流订单ID数量: {}", keywords, logOrderIds.size());
|
|
|
|
|
|
|
|
- // 6. 根据物流订单ID查询子运单,并提取主运单ID
|
|
|
|
|
|
|
+ // 3. 根据物流订单ID查询子运单,并提取主运单ID
|
|
|
List<KwtWaybillOrderSubtask> subtasks = waybillOrderSubtaskRepository.queryByLogIds(new ArrayList<>(logOrderIds));
|
|
List<KwtWaybillOrderSubtask> subtasks = waybillOrderSubtaskRepository.queryByLogIds(new ArrayList<>(logOrderIds));
|
|
|
Set<Long> resultBillOrderIds = Optional.ofNullable(subtasks)
|
|
Set<Long> resultBillOrderIds = Optional.ofNullable(subtasks)
|
|
|
.orElseGet(Collections::emptyList)
|
|
.orElseGet(Collections::emptyList)
|
|
@@ -4398,25 +4471,42 @@ public class KwtWaybillOrderV1Service {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * 从贸易订单详情中过滤代理商名称命中的代理订单ID。
|
|
|
|
|
|
|
+ * 从物流订单企业表代理单位记录中,根据代理商名称关键字过滤并提取关联的物流订单ID。
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 业务逻辑说明:
|
|
|
|
|
+ * 1. 基础校验:若代理单位列表为空或搜索关键字为空/空白,直接返回空集合,避免无效计算。
|
|
|
|
|
+ * 2. 流式过滤与映射:
|
|
|
|
|
+ * - 过滤掉列表中的空对象,防止NPE。
|
|
|
|
|
+ * - 使用 StringUtils.contains 进行模糊匹配,筛选出企业名称包含关键字的记录。
|
|
|
|
|
+ * - 提取匹配记录的物流订单ID(lOrderId)。
|
|
|
|
|
+ * - 再次过滤掉可能为空的订单ID,确保结果集的纯净性。
|
|
|
|
|
+ * 3. 结果收集:将符合条件的物流订单ID收集到Set集合中并返回,自动去重。
|
|
|
|
|
+ * </p>
|
|
|
*
|
|
*
|
|
|
- * @param tradeOrderDetails 贸易订单详情集合
|
|
|
|
|
- * @param keywords 代理商名称关键字
|
|
|
|
|
- * @return 代理商名称命中的贸易订单ID集合
|
|
|
|
|
|
|
+ * @param agentUnits 物流订单企业表代理单位记录列表
|
|
|
|
|
+ * @param keywords 代理商名称关键字
|
|
|
|
|
+ * @return 代理商名称命中的物流订单ID集合,若无匹配数据则返回空集合
|
|
|
*/
|
|
*/
|
|
|
- static Set<Long> extractAgentTradeOrderIdsByAgentName(List<OrderDetailVo> tradeOrderDetails, String keywords) {
|
|
|
|
|
- if (CollectionUtils.isEmpty(tradeOrderDetails)
|
|
|
|
|
- || org.apache.commons.lang3.StringUtils.isBlank(keywords)) {
|
|
|
|
|
|
|
+ static Set<Long> extractAgentLogOrderIdsByAgentFirmName(List<KwtLogisticsOrderUnit> agentUnits, String keywords) {
|
|
|
|
|
+ // 1. 参数有效性校验
|
|
|
|
|
+ if (CollectionUtils.isEmpty(agentUnits) || org.apache.commons.lang3.StringUtils.isBlank(keywords)) {
|
|
|
|
|
+ log.debug("提取代理商名称关联物流订单ID失败:参数无效,agentUnitsSize={}, keywords={}",
|
|
|
|
|
+ agentUnits == null ? 0 : agentUnits.size(), keywords);
|
|
|
return Sets.newHashSet();
|
|
return Sets.newHashSet();
|
|
|
}
|
|
}
|
|
|
- return tradeOrderDetails.stream()
|
|
|
|
|
- .filter(Objects::nonNull)
|
|
|
|
|
- .filter(order -> Objects.equals(order.getAgentFlag(), Global.YES))
|
|
|
|
|
- .filter(order -> org.apache.commons.lang3.StringUtils.contains(order.getAgentFirmName(), keywords))
|
|
|
|
|
- .map(OrderDetailVo::getId)
|
|
|
|
|
- .filter(Objects::nonNull)
|
|
|
|
|
- .collect(Collectors.toSet());
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 流式处理:过滤、映射、收集
|
|
|
|
|
+ Set<Long> result = agentUnits.stream()
|
|
|
|
|
+ .filter(Objects::nonNull) // 过滤空对象
|
|
|
|
|
+ .filter(unit -> org.apache.commons.lang3.StringUtils.contains(unit.getFirmName(), keywords)) // 模糊匹配代理商名称
|
|
|
|
|
+ .map(KwtLogisticsOrderUnit::getLOrderId) // 提取物流订单ID
|
|
|
|
|
+ .filter(Objects::nonNull) // 过滤空订单ID
|
|
|
|
|
+ .collect(Collectors.toSet()); // 收集结果并去重
|
|
|
|
|
+
|
|
|
|
|
+ log.debug("根据代理商名称关键字[{}]提取物流订单ID完成,命中数量: {}", keywords, result.size());
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -4638,10 +4728,16 @@ public class KwtWaybillOrderV1Service {
|
|
|
Integer agentFlag = Objects.nonNull(record.getAgentFlag()) ? record.getAgentFlag() : billOrder.getAgentFlag();
|
|
Integer agentFlag = Objects.nonNull(record.getAgentFlag()) ? record.getAgentFlag() : billOrder.getAgentFlag();
|
|
|
waybillOrderResp.setAgentFlag(agentFlag);
|
|
waybillOrderResp.setAgentFlag(agentFlag);
|
|
|
waybillOrderResp.setAgentFlagDesc(Objects.equals(agentFlag, Global.YES) ? "是" : "否");
|
|
waybillOrderResp.setAgentFlagDesc(Objects.equals(agentFlag, Global.YES) ? "是" : "否");
|
|
|
- KwtLogisticsOrderUnit consignUnit = finalLogOrderIdUnitTypeKeyAndUnitMap.getOrDefault(record.getLOrderId() + "-" + NumberConstant.ONE,
|
|
|
|
|
- new KwtLogisticsOrderUnit());
|
|
|
|
|
- waybillOrderResp.setConsignUnitId(String.valueOf(consignUnit.getEntId()));
|
|
|
|
|
- waybillOrderResp.setConsignUnitName(consignUnit.getFirmName());
|
|
|
|
|
|
|
+ KwtLogisticsOrderUnit agentUnit = finalLogOrderIdUnitTypeKeyAndUnitMap.getOrDefault(
|
|
|
|
|
+ record.getLOrderId() + "-" + LOGISTICS_AGENT_UNIT_TYPE, new KwtLogisticsOrderUnit());
|
|
|
|
|
+ KwtLogisticsOrderUnit supplyUnit = finalLogOrderIdUnitTypeKeyAndUnitMap.getOrDefault(
|
|
|
|
|
+ record.getLOrderId() + "-" + LOGISTICS_SUPPLY_UNIT_TYPE, new KwtLogisticsOrderUnit());
|
|
|
|
|
+ KwtLogisticsOrderUnit consignUnit = finalLogOrderIdUnitTypeKeyAndUnitMap.getOrDefault(
|
|
|
|
|
+ record.getLOrderId() + "-" + NumberConstant.ONE, new KwtLogisticsOrderUnit());
|
|
|
|
|
+ KwtLogisticsOrderUnit displayConsignUnit = chooseWaybillConsignUnit(agentUnit, supplyUnit, consignUnit);
|
|
|
|
|
+ waybillOrderResp.setConsignUnitId(String.valueOf(displayConsignUnit.getEntId()));
|
|
|
|
|
+ waybillOrderResp.setConsignUnitName(displayConsignUnit.getFirmName());
|
|
|
|
|
+ setListAgentUnitInfo(waybillOrderResp, agentUnit);
|
|
|
KwtLogisticsOrderUnit carriageUnit =
|
|
KwtLogisticsOrderUnit carriageUnit =
|
|
|
finalLogOrderIdUnitTypeKeyAndUnitMap.getOrDefault(record.getLOrderId() + "-" + NumberConstant.TWO,
|
|
finalLogOrderIdUnitTypeKeyAndUnitMap.getOrDefault(record.getLOrderId() + "-" + NumberConstant.TWO,
|
|
|
new KwtLogisticsOrderUnit());
|
|
new KwtLogisticsOrderUnit());
|
|
@@ -5191,21 +5287,39 @@ public class KwtWaybillOrderV1Service {
|
|
|
resp.setUnloadAmount(formatAmount(subtask.getUnloadAmount()) + unit);
|
|
resp.setUnloadAmount(formatAmount(subtask.getUnloadAmount()) + unit);
|
|
|
|
|
|
|
|
// 企业信息
|
|
// 企业信息
|
|
|
|
|
+ String agentEntKey = logOrder.getId() + "-" + LOGISTICS_AGENT_UNIT_TYPE;
|
|
|
|
|
+ String supplyEntKey = logOrder.getId() + "-" + LOGISTICS_SUPPLY_UNIT_TYPE;
|
|
|
String transEntKey = logOrder.getId() + "-" + UnitTypeEnum.CONSIGN.getCode();
|
|
String transEntKey = logOrder.getId() + "-" + UnitTypeEnum.CONSIGN.getCode();
|
|
|
String carrierEntKey = logOrder.getId() + "-" + UnitTypeEnum.CARRIAGE.getCode();
|
|
String carrierEntKey = logOrder.getId() + "-" + UnitTypeEnum.CARRIAGE.getCode();
|
|
|
|
|
+ KwtLogisticsOrderUnit agentEnt = logisticsOrderUnitMap.getOrDefault(agentEntKey, new KwtLogisticsOrderUnit());
|
|
|
|
|
+ KwtLogisticsOrderUnit supplyEnt = logisticsOrderUnitMap.getOrDefault(supplyEntKey, new KwtLogisticsOrderUnit());
|
|
|
KwtLogisticsOrderUnit transEnt = logisticsOrderUnitMap.getOrDefault(transEntKey, new KwtLogisticsOrderUnit());
|
|
KwtLogisticsOrderUnit transEnt = logisticsOrderUnitMap.getOrDefault(transEntKey, new KwtLogisticsOrderUnit());
|
|
|
KwtLogisticsOrderUnit carrierEnt = logisticsOrderUnitMap.getOrDefault(carrierEntKey, new KwtLogisticsOrderUnit());
|
|
KwtLogisticsOrderUnit carrierEnt = logisticsOrderUnitMap.getOrDefault(carrierEntKey, new KwtLogisticsOrderUnit());
|
|
|
- resp.setTransEntName(transEnt.getFirmName());
|
|
|
|
|
|
|
+ resp.setTransEntName(chooseWaybillConsignUnit(agentEnt, supplyEnt, transEnt).getFirmName());
|
|
|
resp.setCarrierEntName(carrierEnt.getFirmName());
|
|
resp.setCarrierEntName(carrierEnt.getFirmName());
|
|
|
|
|
+ setDetailAgentUnitInfo(resp, agentEnt);
|
|
|
|
|
|
|
|
// 供应商信息
|
|
// 供应商信息
|
|
|
- if (!CollectionUtils.isEmpty(tradeContractUnitDtos)) {
|
|
|
|
|
|
|
+ // 设置供应单位名称:优先使用物流订单中的供应单位,若无则从贸易合同单位中查找供应商类型的单位
|
|
|
|
|
+ if (hasValidLogisticsUnit(supplyEnt)) {
|
|
|
|
|
+ log.debug("运单详情-设置供应单位名称,来源:物流订单供应单位,名称:{}", supplyEnt.getFirmName());
|
|
|
|
|
+ resp.setSupplyEntName(supplyEnt.getFirmName());
|
|
|
|
|
+ } else if (!CollectionUtils.isEmpty(tradeContractUnitDtos)) {
|
|
|
|
|
+ // 从贸易合同单位列表中过滤出类型为“供应商”的单位,并取第一个匹配项
|
|
|
tradeContractUnitDtos.stream()
|
|
tradeContractUnitDtos.stream()
|
|
|
.filter(x -> org.apache.commons.lang3.StringUtils.equals(x.getUnitType(), String.valueOf(CooperateTypeEnum.SUPPLIER.getCode())))
|
|
.filter(x -> org.apache.commons.lang3.StringUtils.equals(x.getUnitType(), String.valueOf(CooperateTypeEnum.SUPPLIER.getCode())))
|
|
|
.findFirst()
|
|
.findFirst()
|
|
|
- .ifPresent(x -> resp.setSupplyEntName(x.getFirmName()));
|
|
|
|
|
|
|
+ .ifPresent(x -> {
|
|
|
|
|
+ log.debug("运单详情-设置供应单位名称,来源:贸易合同供应商单位,名称:{}", x.getFirmName());
|
|
|
|
|
+ resp.setSupplyEntName(x.getFirmName());
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 设置代理单位信息:若物流订单中无有效代理单位,则尝试从贸易订单详情中获取代理信息
|
|
|
|
|
+ if (!hasValidLogisticsUnit(agentEnt)) {
|
|
|
|
|
+ log.debug("运单详情-物流订单无有效代理单位,尝试从贸易订单详情中获取代理信息");
|
|
|
|
|
+ setAgentUnitInfo(resp, orderDetailVo);
|
|
|
}
|
|
}
|
|
|
- setAgentUnitInfo(resp, orderDetailVo);
|
|
|
|
|
|
|
|
|
|
// 状态信息
|
|
// 状态信息
|
|
|
resp.setStatus(subtask.getStatus());
|
|
resp.setStatus(subtask.getStatus());
|
|
@@ -5249,20 +5363,151 @@ public class KwtWaybillOrderV1Service {
|
|
|
return resp;
|
|
return resp;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * 设置代理单位信息,仅代理贸易订单返回代理单位。
|
|
|
|
|
|
|
+ * 按运单展示规则选择托运单位:有代理单位展示代理单位,否则展示供应单位,最后兼容原托运单位。
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 业务逻辑说明:
|
|
|
|
|
+ * 1. 优先展示代理单位(Agent Unit):若存在有效的代理单位信息,则直接返回。
|
|
|
|
|
+ * 2. 其次展示供应单位(Supply Unit):若无代理单位但存在有效的供应单位,则返回供应单位。
|
|
|
|
|
+ * 3. 兜底展示原托运单位(Consign Unit):若上述两者均无效,则返回原托运单位;若原托运单位也为空,则返回空对象以避免NPE。
|
|
|
|
|
+ * </p>
|
|
|
*
|
|
*
|
|
|
- * @param resp 运单详情响应
|
|
|
|
|
- * @param orderDetailVo 贸易订单详情
|
|
|
|
|
|
|
+ * @param agentUnit 物流订单代理单位
|
|
|
|
|
+ * @param supplyUnit 物流订单供应单位
|
|
|
|
|
+ * @param consignUnit 原物流订单托运单位
|
|
|
|
|
+ * @return 运单列表/详情需要展示的托运单位
|
|
|
|
|
+ */
|
|
|
|
|
+ static KwtLogisticsOrderUnit chooseWaybillConsignUnit(KwtLogisticsOrderUnit agentUnit,
|
|
|
|
|
+ KwtLogisticsOrderUnit supplyUnit,
|
|
|
|
|
+ KwtLogisticsOrderUnit consignUnit) {
|
|
|
|
|
+ // 1. 优先判断代理单位是否有效
|
|
|
|
|
+ if (hasValidLogisticsUnit(agentUnit)) {
|
|
|
|
|
+ log.debug("选择托运单位:命中代理单位,EntId: {}, FirmName: {}", agentUnit.getEntId(), agentUnit.getFirmName());
|
|
|
|
|
+ return agentUnit;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 其次判断供应单位是否有效
|
|
|
|
|
+ if (hasValidLogisticsUnit(supplyUnit)) {
|
|
|
|
|
+ log.debug("选择托运单位:无代理单位,命中供应单位,EntId: {}, FirmName: {}", supplyUnit.getEntId(), supplyUnit.getFirmName());
|
|
|
|
|
+ return supplyUnit;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 兜底返回原托运单位或空对象
|
|
|
|
|
+ if (Objects.isNull(consignUnit)) {
|
|
|
|
|
+ log.debug("选择托运单位:代理及供应单位均无效,且原托运单位为空,返回空对象");
|
|
|
|
|
+ return new KwtLogisticsOrderUnit();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.debug("选择托运单位:代理及供应单位均无效,返回原托运单位,EntId: {}, FirmName: {}", consignUnit.getEntId(), consignUnit.getFirmName());
|
|
|
|
|
+ return consignUnit;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 判断物流订单单位是否具备有效企业信息。
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param logisticsOrderUnit 物流订单单位
|
|
|
|
|
+ * @return true-有效,false-无效
|
|
|
|
|
+ */
|
|
|
|
|
+ static boolean hasValidLogisticsUnit(KwtLogisticsOrderUnit logisticsOrderUnit) {
|
|
|
|
|
+ return Objects.nonNull(logisticsOrderUnit) && Objects.nonNull(logisticsOrderUnit.getEntId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 设置运单列表响应对象中的代理单位信息。
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 业务逻辑说明:
|
|
|
|
|
+ * 1. 校验响应对象和代理单位数据的有效性,若任一为空或无效则直接返回,避免空指针异常。
|
|
|
|
|
+ * 2. 将代理单位的企业ID转换为字符串并设置到响应对象中。
|
|
|
|
|
+ * 3. 安全地获取代理单位名称,若名称为空则设置为默认空字符串,防止前端展示null。
|
|
|
|
|
+ * </p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param resp 运单列表响应对象,用于承载展示数据
|
|
|
|
|
+ * @param agentUnit 物流订单中的代理单位实体,包含企业ID和名称等信息
|
|
|
|
|
+ */
|
|
|
|
|
+ static void setListAgentUnitInfo(WaybillOrderResp resp, KwtLogisticsOrderUnit agentUnit) {
|
|
|
|
|
+ // 1. 基础参数校验:若响应对象为空或代理单位无效(无有效企业ID),则无需处理,直接返回
|
|
|
|
|
+ if (Objects.isNull(resp) || !hasValidLogisticsUnit(agentUnit)) {
|
|
|
|
|
+ log.debug("跳过设置代理单位信息:响应对象为空或代理单位无效");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 设置代理企业ID:确保非空转换,记录日志以便追踪数据来源
|
|
|
|
|
+ String agentEntId = String.valueOf(agentUnit.getEntId());
|
|
|
|
|
+ resp.setAgentEntId(agentEntId);
|
|
|
|
|
+ log.debug("设置运单列表代理企业ID: {}", agentEntId);
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 设置代理企业名称:使用StringUtils.defaultString处理可能的null值,确保前端展示友好
|
|
|
|
|
+ String agentFirmName = org.apache.commons.lang3.StringUtils.defaultString(agentUnit.getFirmName());
|
|
|
|
|
+ resp.setAgentFirmName(agentFirmName);
|
|
|
|
|
+ log.debug("设置运单列表代理企业名称: {}", agentFirmName);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 设置运单详情响应对象中的代理单位信息。
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 业务逻辑说明:
|
|
|
|
|
+ * 1. 校验响应对象和代理单位数据的有效性,若任一为空或无效则直接返回,避免空指针异常及无效赋值。
|
|
|
|
|
+ * 2. 将代理单位的企业ID转换为字符串并设置到响应对象中。
|
|
|
|
|
+ * 3. 安全地获取代理单位名称,若名称为空则设置为默认空字符串,防止前端展示null,提升用户体验。
|
|
|
|
|
+ * 4. 记录调试日志,便于追踪代理单位信息的赋值过程及排查数据问题。
|
|
|
|
|
+ * </p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param resp 运单详情响应对象,用于承载展示数据
|
|
|
|
|
+ * @param agentUnit 物流订单中的代理单位实体,包含企业ID和名称等信息
|
|
|
|
|
+ */
|
|
|
|
|
+ static void setDetailAgentUnitInfo(WaybillOrderDetailResp resp, KwtLogisticsOrderUnit agentUnit) {
|
|
|
|
|
+ // 1. 基础参数校验:若响应对象为空或代理单位无效(无有效企业ID),则无需处理,直接返回
|
|
|
|
|
+ if (Objects.isNull(resp) || !hasValidLogisticsUnit(agentUnit)) {
|
|
|
|
|
+ log.debug("跳过设置运单详情代理单位信息:响应对象为空或代理单位无效");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 提取并设置代理企业ID
|
|
|
|
|
+ String agentEntId = String.valueOf(agentUnit.getEntId());
|
|
|
|
|
+ resp.setAgentEntId(agentEntId);
|
|
|
|
|
+ log.debug("设置运单详情代理企业ID: {}", agentEntId);
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 提取并设置代理企业名称,使用StringUtils.defaultString处理可能的null值,确保前端展示友好
|
|
|
|
|
+ String agentFirmName = org.apache.commons.lang3.StringUtils.defaultString(agentUnit.getFirmName());
|
|
|
|
|
+ resp.setAgentFirmName(agentFirmName);
|
|
|
|
|
+ log.debug("设置运单详情代理企业名称: {}", agentFirmName);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 设置运单详情响应对象中的代理单位信息。
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 业务逻辑说明:
|
|
|
|
|
+ * 1. 校验响应对象、贸易订单详情数据的有效性,以及是否为代理贸易订单(agentFlag == Global.YES)。
|
|
|
|
|
+ * 2. 若满足条件,则从贸易订单详情中提取代理企业ID和代理企业名称,并设置到响应对象中。
|
|
|
|
|
+ * 3. 对代理企业名称进行空值处理,确保前端展示友好。
|
|
|
|
|
+ * </p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param resp 运单详情响应对象,用于承载展示数据
|
|
|
|
|
+ * @param orderDetailVo 贸易订单详情对象,包含代理标识、代理企业ID及名称等信息
|
|
|
*/
|
|
*/
|
|
|
static void setAgentUnitInfo(WaybillOrderDetailResp resp, OrderDetailVo orderDetailVo) {
|
|
static void setAgentUnitInfo(WaybillOrderDetailResp resp, OrderDetailVo orderDetailVo) {
|
|
|
|
|
+ // 1. 基础参数校验:若响应对象为空、贸易订单详情为空,或非代理订单,则直接返回,无需设置代理信息
|
|
|
if (Objects.isNull(resp) || Objects.isNull(orderDetailVo)
|
|
if (Objects.isNull(resp) || Objects.isNull(orderDetailVo)
|
|
|
|| !Objects.equals(orderDetailVo.getAgentFlag(), Global.YES)) {
|
|
|| !Objects.equals(orderDetailVo.getAgentFlag(), Global.YES)) {
|
|
|
|
|
+ log.debug("跳过设置代理单位信息:响应对象为空、订单详情为空或非代理订单(agentFlag={})",
|
|
|
|
|
+ orderDetailVo != null ? orderDetailVo.getAgentFlag() : "null");
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- resp.setAgentEntId(Objects.isNull(orderDetailVo.getAgentEntId())
|
|
|
|
|
- ? null : String.valueOf(orderDetailVo.getAgentEntId()));
|
|
|
|
|
- resp.setAgentFirmName(org.apache.commons.lang3.StringUtils.defaultString(orderDetailVo.getAgentFirmName()));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 提取并设置代理企业ID
|
|
|
|
|
+ Long agentEntId = orderDetailVo.getAgentEntId();
|
|
|
|
|
+ String agentEntIdStr = Objects.isNull(agentEntId) ? null : String.valueOf(agentEntId);
|
|
|
|
|
+ resp.setAgentEntId(agentEntIdStr);
|
|
|
|
|
+ log.debug("设置运单详情代理企业ID: {}", agentEntIdStr);
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 提取并设置代理企业名称,使用StringUtils.defaultString处理可能的null值,防止前端展示null
|
|
|
|
|
+ String agentFirmName = org.apache.commons.lang3.StringUtils.defaultString(orderDetailVo.getAgentFirmName());
|
|
|
|
|
+ resp.setAgentFirmName(agentFirmName);
|
|
|
|
|
+ log.debug("设置运单详情代理企业名称: {}", agentFirmName);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|