|
@@ -119,6 +119,11 @@ import java.util.stream.Collectors;
|
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
|
public class KwoTradeOrderService {
|
|
public class KwoTradeOrderService {
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 供应单位代理属性类型。
|
|
|
|
|
+ */
|
|
|
|
|
+ static final int SUPPLY_AGENT_ENT_TYPE = 4;
|
|
|
|
|
+
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false)
|
|
@DubboReference(version = "1.0.0", group = "design", check = false)
|
|
|
private RemoteSystemService remoteSystemService;
|
|
private RemoteSystemService remoteSystemService;
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false)
|
|
@DubboReference(version = "1.0.0", group = "design", check = false)
|
|
@@ -1750,6 +1755,7 @@ public class KwoTradeOrderService {
|
|
|
vo.setActualPrice(actualAmount.multiply(unitPrice).setScale(2, RoundingMode.HALF_UP)).setUnitPrice(setScale(e.getUnitPrice())).setPrice(setScale(e.getPrice())).setUnit(e.getUnit()).setUnitLabel(unitType == null ? e.getUnit() : (unitType.get(e.getUnit()) == null ? e.getUnit() : unitType.get(e.getUnit()).getLabel())).setAmount(setScale(vo.getAmount())).setEntrustAmount(setScale(e.getEntrustAmount())).setActualAmount(setScale(e.getActualAmount())).setCreateByName(Objects.isNull(userCache) ? null : userCache.getName());
|
|
vo.setActualPrice(actualAmount.multiply(unitPrice).setScale(2, RoundingMode.HALF_UP)).setUnitPrice(setScale(e.getUnitPrice())).setPrice(setScale(e.getPrice())).setUnit(e.getUnit()).setUnitLabel(unitType == null ? e.getUnit() : (unitType.get(e.getUnit()) == null ? e.getUnit() : unitType.get(e.getUnit()).getLabel())).setAmount(setScale(vo.getAmount())).setEntrustAmount(setScale(e.getEntrustAmount())).setActualAmount(setScale(e.getActualAmount())).setCreateByName(Objects.isNull(userCache) ? null : userCache.getName());
|
|
|
vo.setDeliveryTypeLabel(DictEnum.getLabel(DictTypeEnum.LOAD_UNLOAD_WAY.getType(), String.valueOf(e.getChargeType())));
|
|
vo.setDeliveryTypeLabel(DictEnum.getLabel(DictTypeEnum.LOAD_UNLOAD_WAY.getType(), String.valueOf(e.getChargeType())));
|
|
|
vo.setAddVehicles(e.getAddVehicles());
|
|
vo.setAddVehicles(e.getAddVehicles());
|
|
|
|
|
+ vo.setAgentFlagDesc(Objects.equals(e.getAgentFlag(), Global.YES) ? "是" : "否");
|
|
|
if (Objects.equals(e.getChargeType(), 1)) { //按装货量
|
|
if (Objects.equals(e.getChargeType(), 1)) { //按装货量
|
|
|
vo.setDealAmount(e.getLoadAmount());
|
|
vo.setDealAmount(e.getLoadAmount());
|
|
|
} else {
|
|
} else {
|
|
@@ -2177,6 +2183,143 @@ public class KwoTradeOrderService {
|
|
|
return kwoTradeOrderMapper.querySaleOrder(start, end);
|
|
return kwoTradeOrderMapper.querySaleOrder(start, end);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据贸易合同ID查询订单的代理属性标识。
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 逻辑说明:
|
|
|
|
|
+ * 1. 校验贸易合同ID是否为空。
|
|
|
|
|
+ * 2. 调用远程服务查询该合同下的所有单位信息。
|
|
|
|
|
+ * 3. 筛选出类型为“供应方”(unitType="1")的单位,并获取其企业ID。
|
|
|
|
|
+ * 4. 根据供应方企业ID,进一步查询该企业是否具备“代理”属性。
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param tradeContractId 贸易合同ID
|
|
|
|
|
+ * @return 代理属性标识:1-是代理,0-非代理
|
|
|
|
|
+ * @throws BusinessException 当合同ID为空、未找到供应单位或查询过程异常时抛出
|
|
|
|
|
+ */
|
|
|
|
|
+ private Integer queryOrderAgentFlag(Long tradeContractId) {
|
|
|
|
|
+ // 参数校验:贸易合同ID不能为空
|
|
|
|
|
+ if (Objects.isNull(tradeContractId)) {
|
|
|
|
|
+ throw new BusinessException("贸易合同ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 记录开始查询日志
|
|
|
|
|
+ log.debug("开始查询贸易合同代理属性,tradeContractId={}", tradeContractId);
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 调用远程服务获取合同关联的单位列表
|
|
|
|
|
+ List<TradeContractUnitDto> unitList = remoteContractService.queryContractUnitByContractId(tradeContractId);
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 从单位列表中筛选出供应方(unitType="1")的企业ID
|
|
|
|
|
+ Long supplyEntId = Optional.ofNullable(unitList)
|
|
|
|
|
+ .orElseGet(Collections::emptyList)
|
|
|
|
|
+ .stream()
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ // 过滤出单位类型为供应方的记录 (假设 "1" 代表供应方)
|
|
|
|
|
+ .filter(item -> StrUtil.equals("1", item.getUnitType()))
|
|
|
|
|
+ .map(TradeContractUnitDto::getEntId)
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .findFirst()
|
|
|
|
|
+ .orElseThrow(() -> {
|
|
|
|
|
+ log.warn("贸易合同中未找到有效的供应单位,tradeContractId={}", tradeContractId);
|
|
|
|
|
+ return new BusinessException("贸易合同供应单位不存在");
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ log.debug("找到供应单位ID,supplyEntId={},准备查询代理属性", supplyEntId);
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 根据供应方企业ID查询其是否具备代理属性
|
|
|
|
|
+ Integer agentFlag = querySupplyAgentFlag(supplyEntId);
|
|
|
|
|
+
|
|
|
|
|
+ log.debug("贸易合同代理属性查询完成,tradeContractId={}, agentFlag={}", tradeContractId, agentFlag);
|
|
|
|
|
+ return agentFlag;
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 捕获其他未知异常,记录详细堆栈日志,并抛出通用业务异常
|
|
|
|
|
+ log.error("查询贸易订单代理属性发生系统异常,tradeContractId={}", tradeContractId, e);
|
|
|
|
|
+ throw new BusinessException("查询贸易订单代理属性失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 查询供应单位企业类型,判断是否包含代理属性。
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 业务逻辑:
|
|
|
|
|
+ * 1. 校验供应单位ID有效性。
|
|
|
|
|
+ * 2. 调用远程系统服务获取该企业的类型信息列表。
|
|
|
|
|
+ * 3. 通过辅助方法 {@link #hasSupplyAgentAttribute(List, Long)} 判断企业类型中是否包含“供应代理”标识(类型为4)。
|
|
|
|
|
+ * 4. 返回全局常量标识:Global.YES (1) 表示是代理,Global.NO (0) 表示非代理。
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param supplyEntId 供应单位ID
|
|
|
|
|
+ * @return 代理属性标识:1-是代理,0-非代理
|
|
|
|
|
+ * @throws BusinessException 当供应单位ID为空或查询过程发生异常时抛出
|
|
|
|
|
+ */
|
|
|
|
|
+ private Integer querySupplyAgentFlag(Long supplyEntId) {
|
|
|
|
|
+ // 参数校验:确保供应单位ID不为空
|
|
|
|
|
+ if (Objects.isNull(supplyEntId)) {
|
|
|
|
|
+ log.warn("查询供应单位代理属性失败,原因:供应单位ID为空");
|
|
|
|
|
+ throw new BusinessException("供应单位不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 记录调试日志,开始查询流程
|
|
|
|
|
+ log.debug("开始查询供应单位代理属性,supplyEntId={}", supplyEntId);
|
|
|
|
|
+
|
|
|
|
|
+ // 调用远程系统服务,根据企业ID查询企业类型信息
|
|
|
|
|
+ // 使用 Collections.singleton 包装单个ID以符合接口参数要求
|
|
|
|
|
+ List<EntTypeResDto> entTypeList = remoteSystemService.queryEntTypeByIds(Collections.singleton(supplyEntId));
|
|
|
|
|
+
|
|
|
|
|
+ // 判断该企业是否具有供应代理属性
|
|
|
|
|
+ boolean isAgent = hasSupplyAgentAttribute(entTypeList, supplyEntId);
|
|
|
|
|
+
|
|
|
|
|
+ // 记录结果日志
|
|
|
|
|
+ log.debug("供应单位代理属性查询完成,supplyEntId={}, isAgent={}", supplyEntId, isAgent);
|
|
|
|
|
+
|
|
|
|
|
+ // 根据判断结果返回对应的全局常量标识
|
|
|
|
|
+ return isAgent ? Global.YES : Global.NO;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 捕获异常,记录错误日志(包含堆栈信息以便排查)
|
|
|
|
|
+ log.error("查询供应单位代理属性发生系统异常,supplyEntId={}", supplyEntId, e);
|
|
|
|
|
+ // 抛出统一的业务异常,避免暴露底层技术细节
|
|
|
|
|
+ throw new BusinessException("查询供应单位代理属性失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 判断指定供应企业是否具有代理属性。
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 业务逻辑:
|
|
|
|
|
+ * 1. 校验参数有效性:若供应企业ID为空或企业类型列表为空,直接返回false。
|
|
|
|
|
+ * 2. 遍历企业类型列表,筛选出与给定supplyEntId匹配的企业记录。
|
|
|
|
|
+ * 3. 检查匹配记录的企业类型(type)是否等于预设的供应单位代理属性类型(SUPPLY_AGENT_ENT_TYPE,值为4)。
|
|
|
|
|
+ * 4. 若存在至少一条匹配且类型为代理的记录,则返回true,否则返回false。
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param entTypeList 企业类型信息列表,来自远程系统服务查询结果
|
|
|
|
|
+ * @param supplyEntId 待校验的供应企业ID
|
|
|
|
|
+ * @return boolean true-该企业具有代理属性; false-该企业不具有代理属性或参数无效
|
|
|
|
|
+ */
|
|
|
|
|
+ static boolean hasSupplyAgentAttribute(List<EntTypeResDto> entTypeList, Long supplyEntId) {
|
|
|
|
|
+ // 参数预校验:确保企业ID和企业类型列表非空
|
|
|
|
|
+ if (Objects.isNull(supplyEntId) || CollUtil.isEmpty(entTypeList)) {
|
|
|
|
|
+ log.debug("判断供应单位代理属性:参数无效,supplyEntId={}, entTypeListSize={}", supplyEntId, CollUtil.size(entTypeList));
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 流式处理:过滤非空对象 -> 匹配企业ID -> 判断是否为代理类型
|
|
|
|
|
+ boolean isAgent = entTypeList.stream()
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .filter(item -> Objects.equals(item.getEntId(), supplyEntId))
|
|
|
|
|
+ .anyMatch(item -> {
|
|
|
|
|
+ boolean match = Objects.equals(item.getType(), SUPPLY_AGENT_ENT_TYPE);
|
|
|
|
|
+ if (match) {
|
|
|
|
|
+ log.debug("找到供应单位代理属性匹配项,entId={}, type={}", item.getEntId(), item.getType());
|
|
|
|
|
+ }
|
|
|
|
|
+ return match;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ log.debug("供应单位代理属性判断结果,supplyEntId={}, isAgent={}", supplyEntId, isAgent);
|
|
|
|
|
+ return isAgent;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 新增贸易订单
|
|
* 新增贸易订单
|
|
|
*
|
|
*
|
|
@@ -2190,6 +2333,7 @@ public class KwoTradeOrderService {
|
|
|
KwpGoods goodsById = goodsInfoService.getGoodsById(tradeOrderParam.getGoodsId());
|
|
KwpGoods goodsById = goodsInfoService.getGoodsById(tradeOrderParam.getGoodsId());
|
|
|
|
|
|
|
|
TradeContractResDto tradeContractResDto = checkPara(tradeOrderParam, order, goodsById);
|
|
TradeContractResDto tradeContractResDto = checkPara(tradeOrderParam, order, goodsById);
|
|
|
|
|
+ order.setAgentFlag(queryOrderAgentFlag(tradeOrderParam.getTradeContractId()));
|
|
|
|
|
|
|
|
// ====== 下单前校验 start ======
|
|
// ====== 下单前校验 start ======
|
|
|
|
|
|