|
|
@@ -20,6 +20,7 @@ import com.sckw.core.web.context.LoginUserHolder;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
import com.sckw.mongo.enums.BusinessTypeEnum;
|
|
|
import com.sckw.mongo.model.SckwLogisticsOrder;
|
|
|
+import com.sckw.order.api.dubbo.RemoteTradeOrderAmountService;
|
|
|
import com.sckw.order.api.dubbo.TradeOrderInfoService;
|
|
|
import com.sckw.order.api.model.*;
|
|
|
import com.sckw.redis.config.RedisLockUtil;
|
|
|
@@ -34,13 +35,11 @@ import com.sckw.transport.api.model.vo.LogisticsOrderVO;
|
|
|
import com.sckw.transport.common.config.MessageUrlConfig;
|
|
|
import com.sckw.transport.dao.*;
|
|
|
import com.sckw.transport.model.*;
|
|
|
-import com.sckw.transport.model.dto.CancelOrderDTO;
|
|
|
-import com.sckw.transport.model.dto.DocumentParamDTO;
|
|
|
-import com.sckw.transport.model.dto.OrderGoodsLoadingDto;
|
|
|
-import com.sckw.transport.model.dto.OrderManualCompletionDto;
|
|
|
+import com.sckw.transport.model.dto.*;
|
|
|
import com.sckw.transport.model.param.ContractParam;
|
|
|
import com.sckw.transport.model.param.LogisticsOrderParam;
|
|
|
import com.sckw.transport.model.vo.*;
|
|
|
+import io.seata.spring.annotation.GlobalTransactional;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
@@ -69,6 +68,9 @@ public class KwtTransportCommonService {
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false, timeout = 10000)
|
|
|
TradeOrderInfoService tradeOrderInfoService;
|
|
|
|
|
|
+ @DubboReference(version = "1.0.0", group = "design", check = false, timeout = 10000)
|
|
|
+ RemoteTradeOrderAmountService tradeOrderAmountService;
|
|
|
+
|
|
|
@DubboReference(version = "1.0.0", group = "design", check = false, timeout = 10000)
|
|
|
RemoteContractService remoteContractService;
|
|
|
|
|
|
@@ -1010,6 +1012,27 @@ public class KwtTransportCommonService {
|
|
|
return BigDecimal.ZERO;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 完结参数
|
|
|
+ * @param unit 单位
|
|
|
+ * @param type 装卸货类型
|
|
|
+ * @desc 获取装卸货量
|
|
|
+ * @author zk
|
|
|
+ * @date 2023/9/18
|
|
|
+ **/
|
|
|
+ public BigDecimal getLoadingV42(LogisticsOrderFinishDto params, String unit, int type) {
|
|
|
+ List<OrderGoodsLoadingDto> loadings = params.getLoading();
|
|
|
+ if (CollectionUtils.isNotEmpty(loadings)) {
|
|
|
+ for (OrderGoodsLoadingDto loading : loadings) {
|
|
|
+ if (loading.getUnit().equals(unit)) {
|
|
|
+ return type == NumberConstant.ONE ? loading.getLoadAmount() : loading.getUnloadAmount();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 物流订单完结订单-修改物流表+新增物流状态记录
|
|
|
*
|
|
|
@@ -1433,4 +1456,205 @@ public class KwtTransportCommonService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param params 手动完结参数
|
|
|
+ * @desc 完结物流订单-采购/销售/托运/承运-v4.2
|
|
|
+ * @author lfdc
|
|
|
+ * @date 2024/03/08
|
|
|
+ **/
|
|
|
+ @GlobalTransactional
|
|
|
+ public HttpResult logisticsOrderFinish(LogisticsOrderFinishDto params) {
|
|
|
+ /** 订单完结 物流运单状态为【待派车】、【运输中】可操作*/
|
|
|
+ /**完结拦截 必须车辆运单无正在运输中的单据才能完结 状态有 待接单之后已核弹之前的状态 都不能完结*/
|
|
|
+ /**完结订单-对应物流订单下子订单都要进行完结*/
|
|
|
+ /**完结订单 不做页面填写数量与数据库数量进行计算验证-直接获取页面填写数据进行保存处理*/
|
|
|
+ Long id = params.getId();
|
|
|
+ String key = String.format(RedisConstant.LOGISTICS_ORDER_FINISH_KEY, params.getId());
|
|
|
+ if (redisLockUtil.tryLock(key)) {
|
|
|
+ try {
|
|
|
+ KwtLogisticsOrder logisticsOrder = logisticsOrderMapper.selectById(id);
|
|
|
+ if (logisticsOrder == null) {
|
|
|
+ throw new BusinessException("完结订单-物流单据不存在!");
|
|
|
+ }
|
|
|
+ String billingMode = logisticsOrder.getBillingMode();
|
|
|
+ if (DictEnum.CHARGING_TYPE_4.getValue().equals(billingMode)) {
|
|
|
+ List<LogisticsOrderLineFreightRateDto> lineFreightRate = params.getLineFreightRate();
|
|
|
+ if (CollectionUtils.isEmpty(lineFreightRate)) {
|
|
|
+ throw new BusinessException("按里程计费时,数量不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**订单状态验证*/
|
|
|
+ if (!LogisticsOrderEnum.WAIT_DELIVERY.getStatus().equals(String.valueOf(logisticsOrder.getStatus()))
|
|
|
+ && !LogisticsOrderEnum.IN_TRANSIT.getStatus().equals(String.valueOf(logisticsOrder.getStatus()))) {
|
|
|
+ throw new BusinessException("当前订单并不属于【待派车】,【运输中】状态");
|
|
|
+ }
|
|
|
+ //验证当前物流订单是否还存在进行的车辆运单
|
|
|
+ boolean flag = commonService.judgmentWaybillOrderIsFinish(String.valueOf(id));
|
|
|
+ if (flag) {
|
|
|
+ throw new BusinessException("检测您现在有运单正在执行中,该订单目前不可完结,请先将运单执行完毕!");
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改单据本身数据
|
|
|
+ BigDecimal loadAmount = getLoadingV42(params, logisticsOrder.getUnit(), NumberConstant.ONE);
|
|
|
+ BigDecimal unloadAmount = getLoadingV42(params, logisticsOrder.getUnit(), NumberConstant.TWO);
|
|
|
+ BigDecimal ignoreAmount = logisticsOrder.getAmount().subtract(loadAmount == null ? NumberConstant.ZERO_TWO : logisticsOrder.getLoadAmount());
|
|
|
+ logisticsOrder.setTotalLoadAmount(loadAmount);
|
|
|
+ logisticsOrder.setTotalUnloadAmount(unloadAmount);
|
|
|
+ logisticsOrder.setStatus(LogisticsOrderEnum.HAVE_FINISHED.getCode());
|
|
|
+ logisticsOrder.setUpdateTime(new Date());
|
|
|
+ logisticsOrder.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ logisticsOrder.setIgnoreAmount(ignoreAmount);
|
|
|
+ logisticsOrderMapper.updateById(logisticsOrder);
|
|
|
+ //物流订单状态记录
|
|
|
+ updateLogisticOrderTrack(logisticsOrder.getId(), LogisticsOrderEnum.HAVE_FINISHED.getCode(), params.getRemark());
|
|
|
+ //修改mongodb的数据
|
|
|
+ updateMongoDbByLogisticsOrder(logisticsOrder);
|
|
|
+ //更新商品辅助单位信息
|
|
|
+ logisticsOrderGoodsService.editLogisticsOrderGoodsTotalLoadingV42(params);
|
|
|
+
|
|
|
+ //获取物流订单下的子单
|
|
|
+ /**完结订单-对应物流订单下子订单都要进行完结*/
|
|
|
+ List<KwtLogisticsOrder> kwtLogisticsOrders = logisticsOrderMapper.selectList(new LambdaQueryWrapper<KwtLogisticsOrder>()
|
|
|
+ .eq(KwtLogisticsOrder::getDelFlag, NumberConstant.ZERO)
|
|
|
+ .apply(id != null, "FIND_IN_SET ('" + id + "', pids)").ne(KwtLogisticsOrder::getId, id));
|
|
|
+ if (!CollectionUtils.isEmpty(kwtLogisticsOrders)) {
|
|
|
+ //修改单据剩余运输量
|
|
|
+ kwtLogisticsOrders.forEach(kwtLogisticsOrder -> {
|
|
|
+ BigDecimal subtract = kwtLogisticsOrder.getAmount().subtract(kwtLogisticsOrder.getTotalLoadAmount());
|
|
|
+ //更新忽略剩余量
|
|
|
+ updateLogisticOrderAndTrack(kwtLogisticsOrder);
|
|
|
+ //更新Mongodb
|
|
|
+ updateMongoDbByLogisticsOrder(kwtLogisticsOrder);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**是否是一级订单,是->推送至贸易*/
|
|
|
+ if (logisticsOrder.getPid() == null && "1".equals(logisticsOrder.getType())) {
|
|
|
+ //todo: 原来逻辑
|
|
|
+
|
|
|
+ List<GoodsLoadingV1Param> loadings = new ArrayList<>();
|
|
|
+ List<OrderGoodsLoadingDto> loading = params.getLoading();
|
|
|
+ loading.forEach(e -> {
|
|
|
+ loadings.add(new GoodsLoadingV1Param(e.getUnit(), e.getLoadAmount(), e.getUnloadAmount()));
|
|
|
+ });
|
|
|
+ //数据推送至贸易订单-更新总装卸货量
|
|
|
+ HttpResult httpResult = tradeOrderInfoService.completeLogisticsOrderV1(LoginUserHolder.getUserId(), LoginUserHolder.getUserName(), logisticsOrder.getTOrderId(), loadings);
|
|
|
+ if (httpResult.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
|
+ log.info("贸易订单手动完结订单异常,传递信息:{}{},返回信息:{}", logisticsOrder.getTOrderId(), loadings, JSONObject.toJSONString(httpResult));
|
|
|
+ throw new BusinessException("单据完结出现错误!" + httpResult.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ //数据推送至贸易订单-更新时间装货量
|
|
|
+ List<GoodsLoadingParam> goodsLoading = logisticsOrderGoodsService.goodsLoadingParams(logisticsOrder, loading);
|
|
|
+// httpResult = tradeOrderInfoService.createOrCancelLogisticsOrderV1(logisticsOrder.getTOrderId(), goodsLoading);
|
|
|
+ httpResult = tradeOrderInfoService.createOrCancelLogisticsOrderV1(LoginUserHolder.getUserId(), LoginUserHolder.getUserName(), logisticsOrder.getTOrderId(), goodsLoading);
|
|
|
+ if (httpResult.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
|
+ log.info("手动完结订单-完结订单,传递信息:{},返回信息:{}",
|
|
|
+ "userId:" + LoginUserHolder.getUserId() +
|
|
|
+ "userName:" + LoginUserHolder.getUserName() +
|
|
|
+ "id:" + logisticsOrder.getTOrderId() +
|
|
|
+ "orderNo" + logisticsOrder.getTOrderNo(),
|
|
|
+ JSONObject.toJSONString(httpResult))
|
|
|
+ ;
|
|
|
+ throw new BusinessException("{" + logisticsOrder.getTOrderNo() + "} 手动完结订单-完结订单!" + httpResult.getMsg());
|
|
|
+ }
|
|
|
+ //todo:新的逻辑 多装多卸
|
|
|
+ updateTradeOrderAddressAmount(logisticsOrder);
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改合同履约量
|
|
|
+ commonService.updatePerformed(logisticsOrder, loadAmount, unloadAmount);
|
|
|
+
|
|
|
+ //完结物流订单数据处理-上级物流订单分包量计算
|
|
|
+ closeHandleByOrderFinish(logisticsOrder.getId());
|
|
|
+
|
|
|
+ //关闭运单
|
|
|
+ waybillOrderService.cancelSendCar(logisticsOrder.getId());
|
|
|
+ } finally {
|
|
|
+ redisLockUtil.unlock(key);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ HttpResult.error("当前数据正在处理,请稍后再试");
|
|
|
+ }
|
|
|
+ return HttpResult.ok("托运订单-完结订单成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateTradeOrderAddressAmount(KwtLogisticsOrder logisticsOrder) {
|
|
|
+ Long tOrderId = logisticsOrder.getTOrderId();
|
|
|
+ if (!Objects.isNull(tOrderId)) {
|
|
|
+ List<KwtLogisticsOrderAddress> logisticsOrderAddressList = logisticsOrderAddressMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<KwtLogisticsOrderAddress>()
|
|
|
+ .eq(KwtLogisticsOrderAddress::getLOrderId, logisticsOrder.getId()));
|
|
|
+ if (CollectionUtils.isNotEmpty(logisticsOrderAddressList)) {
|
|
|
+ Map<Integer, List<KwtLogisticsOrderAddress>> map = logisticsOrderAddressList.stream()
|
|
|
+ .collect(Collectors.groupingBy(KwtLogisticsOrderAddress::getAddressType));
|
|
|
+
|
|
|
+ List<KwtLogisticsOrderAddress> loadingLogisticsOrderAddresses = map.get(NumberConstant.ONE);
|
|
|
+ List<Long> loadAddressIds = loadingLogisticsOrderAddresses.stream().map(KwtLogisticsOrderAddress::getId).collect(Collectors.toList());
|
|
|
+ List<KwtLogisticsOrderAmount> kwtLogisticsOrderAmounts = logisticsOrderAmountMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<KwtLogisticsOrderAmount>()
|
|
|
+ .eq(KwtLogisticsOrderAmount::getLOrderId, logisticsOrder.getId())
|
|
|
+ .eq(KwtLogisticsOrderAmount::getDelFlag, NumberConstant.ZERO)
|
|
|
+ .in(KwtLogisticsOrderAmount::getLAddressId, loadAddressIds)
|
|
|
+ );
|
|
|
+ //总装货量
|
|
|
+ BigDecimal resultLoadAmount = new BigDecimal("0.00");
|
|
|
+ if (CollectionUtils.isNotEmpty(kwtLogisticsOrderAmounts)) {
|
|
|
+ resultLoadAmount = kwtLogisticsOrderAmounts.stream()
|
|
|
+ .map(KwtLogisticsOrderAmount::getTotalLoadAmount)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+ List<KwtLogisticsOrderAddress> unloadLogisticsOrderAddresses = map.get(NumberConstant.TWO);
|
|
|
+ List<Long> unloadAddressIds = unloadLogisticsOrderAddresses.stream().map(KwtLogisticsOrderAddress::getId).collect(Collectors.toList());
|
|
|
+ List<KwtLogisticsOrderAmount> unloadLogisticsOrderAmounts = logisticsOrderAmountMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<KwtLogisticsOrderAmount>()
|
|
|
+ .eq(KwtLogisticsOrderAmount::getLOrderId, logisticsOrder.getId())
|
|
|
+ .eq(KwtLogisticsOrderAmount::getDelFlag, NumberConstant.ZERO)
|
|
|
+ .in(KwtLogisticsOrderAmount::getLAddressId, unloadAddressIds)
|
|
|
+ );
|
|
|
+ //总卸货量
|
|
|
+ BigDecimal resultUnLoadAmount = new BigDecimal("0.00");
|
|
|
+ if (CollectionUtils.isNotEmpty(unloadLogisticsOrderAmounts)) {
|
|
|
+ resultUnLoadAmount = kwtLogisticsOrderAmounts.stream()
|
|
|
+ .map(KwtLogisticsOrderAmount::getTotalLoadAmount)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+ //对应地址id装货量+卸货量
|
|
|
+ List<LogisticsOrderFinishAmountVo> loadAddressAmount = logisticsOrderAmountMapper.countAddressAmount(logisticsOrder.getId(), NumberConstant.ONE);
|
|
|
+ List<LogisticsOrderFinishAmountVo> unloadAddressAmount = logisticsOrderAmountMapper.countAddressAmount(logisticsOrder.getId(), NumberConstant.TWO);
|
|
|
+ List<AddressActualAmountParam> paramList = new ArrayList<>();
|
|
|
+ loadAddressAmount.forEach(addressAmount -> {
|
|
|
+ Long tOrderAddressId = addressAmount.getTOrderAddressId();
|
|
|
+ BigDecimal countLoadAmount = addressAmount.getLoadAmount();
|
|
|
+ AddressActualAmountParam amountParam = new AddressActualAmountParam();
|
|
|
+ amountParam.setTAddressId(tOrderAddressId);
|
|
|
+ amountParam.setActualAmount(countLoadAmount);
|
|
|
+ paramList.add(amountParam);
|
|
|
+ });
|
|
|
+ unloadAddressAmount.forEach(addressAmount -> {
|
|
|
+ Long tOrderAddressId = addressAmount.getTOrderAddressId();
|
|
|
+ BigDecimal countUnloadAmount = addressAmount.getUnloadAmount();
|
|
|
+ AddressActualAmountParam amountParam = new AddressActualAmountParam();
|
|
|
+ amountParam.setTAddressId(tOrderAddressId);
|
|
|
+ amountParam.setActualAmount(countUnloadAmount);
|
|
|
+ paramList.add(amountParam);
|
|
|
+ });
|
|
|
+ if (paramList.size() > 0) {
|
|
|
+ UpdateAddressActualAmountParam param = new UpdateAddressActualAmountParam();
|
|
|
+ param.setTOrderId(tOrderId);
|
|
|
+ param.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ param.setUpdateByName(LoginUserHolder.getUserName());
|
|
|
+ param.setAddressActualAmountParams(paramList);
|
|
|
+ tradeOrderAmountService.updateAddressActualAmount(param);
|
|
|
+ } else {
|
|
|
+ log.info("完结订单--返回上游贸易订单地址数据异常---> lOrderId:{},tOrderId:{},tOrderNo:{}",
|
|
|
+ logisticsOrder.getId(), logisticsOrder.getTOrderId(), logisticsOrder.getTOrderNo());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|