Просмотр исходного кода

运营端物流订单接口新增-订单详情

lengfaqiang 2 лет назад
Родитель
Сommit
a93629eeec

+ 22 - 6
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/controller/operationManagement/ManagementLogisticsOrderController.java

@@ -11,14 +11,12 @@ import com.sckw.transport.model.vo.execlVo.ManagementLogisticsOrderExcelVo;
 import com.sckw.transport.service.ManagementLogisticsOrderService;
 import jakarta.servlet.http.HttpServletResponse;
 import jakarta.validation.Valid;
+import jakarta.validation.constraints.NotBlank;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
@@ -38,7 +36,6 @@ public class ManagementLogisticsOrderController {
     ManagementLogisticsOrderService managementLogisticsOrderService;
 
 
-
     /**
      * 运营管理端-物流订单-首页条件查询
      *
@@ -71,7 +68,7 @@ public class ManagementLogisticsOrderController {
             HttpResult result = managementLogisticsOrderService.statisticsLogisticsOrder(query);
             return result;
         } catch (Exception e) {
-            log.error("运营管理端-物流订单-top统计 失败 :{}", e.getMessage(),e);
+            log.error("运营管理端-物流订单-top统计 失败 :{}", e.getMessage(), e);
             return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
         }
     }
@@ -94,4 +91,23 @@ public class ManagementLogisticsOrderController {
         return HttpResult.ok("没有可导出的数据");
     }
 
+
+    /**
+     * 运营端-物流订单-获取订单详情
+     *
+     * @param orderId
+     * @return
+     */
+    @RequestMapping(value = "/getOrderDetail", method = RequestMethod.GET)
+    public HttpResult getOrderDetail(@RequestParam("orderId") @NotBlank(message = "订单id不能为空") String orderId,
+                                     @RequestParam("orderNo") @NotBlank(message = "订单编号不能为空") String orderNo) {
+        log.info("运营端-物流订单-获取订单详情参数:单据id:{},单据编号:{}", orderId, orderNo);
+        try {
+            return managementLogisticsOrderService.getOrderDetail(orderId, orderNo);
+        } catch (Exception e) {
+            log.error("运营端-物流订单-获取订单详情失败:error :单据id:{},单据编号:{} errorMessage:{}", orderId, orderNo, e.getMessage(), e);
+            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
+        }
+    }
+
 }

+ 216 - 1
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/ManagementLogisticsOrderService.java

@@ -1,14 +1,19 @@
 package com.sckw.transport.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.sckw.contract.api.RemoteContractService;
+import com.sckw.contract.api.model.dto.res.ContractCommonInfoResDto;
 import com.sckw.core.common.enums.NumberConstant;
+import com.sckw.core.common.enums.enums.DictEnum;
 import com.sckw.core.common.enums.enums.DictTypeEnum;
 import com.sckw.core.model.constant.Global;
 import com.sckw.core.model.enums.LogisticsOrderEnum;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.utils.CollectionUtils;
 import com.sckw.core.utils.StringUtils;
+import com.sckw.core.web.constant.HttpStatus;
 import com.sckw.core.web.context.LoginUserHolder;
 import com.sckw.core.web.response.HttpResult;
 import com.sckw.mongo.model.TableTops;
@@ -16,16 +21,20 @@ import com.sckw.order.api.dubbo.TradeOrderInfoService;
 import com.sckw.order.api.model.OrderDetailRes;
 import com.sckw.order.api.model.UnitInfoDetailRes;
 import com.sckw.system.api.RemoteSystemService;
+import com.sckw.system.api.model.dto.res.SysDictResDto;
 import com.sckw.system.api.model.dto.res.UserCacheResDto;
-import com.sckw.transport.dao.KwtLogisticsOrderMapper;
+import com.sckw.transport.dao.*;
+import com.sckw.transport.model.*;
 import com.sckw.transport.model.param.ManagementLogisticsOrderQuery;
 import com.sckw.transport.model.vo.ManagementLogsiticsOrderVO;
+import com.sckw.transport.model.vo.OrderDetailVO;
 import com.sckw.transport.model.vo.execlVo.ManagementLogisticsOrderExcelVo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.ObjectUtils;
 
 import java.math.BigDecimal;
 import java.text.DecimalFormat;
@@ -52,6 +61,27 @@ public class ManagementLogisticsOrderService {
     @DubboReference(version = "1.0.0", group = "design", check = false, timeout = 6000)
     TradeOrderInfoService tradeOrderInfoService;
 
+    @DubboReference(version = "1.0.0", group = "design", check = false, timeout = 6000)
+    RemoteContractService remoteContractService;
+
+    @Autowired
+    public KwtLogisticsOrderGoodsMapper logisticsOrderGoodsMapper;
+
+    @Autowired
+    public KwtLogisticsOrderContractMapper logisticsOrderContractMapper;
+
+    @Autowired
+    public KwtLogisticsOrderAddressMapper logisticsOrderAddressMapper;
+
+    @Autowired
+    public KwtLogisticsOrderTrackMapper logisticsOrderTrackMapper;
+
+    @Autowired
+    public KwtLogisticsOrderUnitMapper logisticsOrderUnitMapper;
+
+    @Autowired
+    public KwtWaybillOrderMapper waybillOrderMapper;
+
     /**
      * @param query
      * @return
@@ -322,4 +352,189 @@ public class ManagementLogisticsOrderService {
         }
         return exportList;
     }
+
+    public HttpResult getOrderDetail(String orderIdStr, String orderNo) {
+        HttpResult httpResult = new HttpResult();
+        httpResult.setCode(HttpStatus.SUCCESS_CODE);
+        List<Long> orderIds = StringUtils.splitStrToList(orderIdStr, Long.class);
+        Long orderId = orderIds.get(0);
+        KwtLogisticsOrder logisticsOrder = logisticsOrderMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrder>()
+                        .eq(KwtLogisticsOrder::getId, orderId)
+                        .eq(StringUtils.isNotBlank(orderNo), KwtLogisticsOrder::getLOrderNo, orderNo)
+                /**.eq(KwtLogisticsOrder::getEntId, LoginUserHolder.getEntId())*/);
+        if (logisticsOrder == null) {
+            log.info("运营端-物流订单-获取订单详情参数:单据id:{},单据编号:{}", orderId, orderNo);
+            throw new RuntimeException("查无单据");
+
+        }
+        KwtLogisticsOrderContract contract = logisticsOrderContractMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrderContract>()
+                .eq(StringUtils.isNotBlank(orderId), KwtLogisticsOrderContract::getLOrderId, orderId));
+        KwtLogisticsOrderUnit unitOne = logisticsOrderUnitMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrderUnit>()
+                .eq(StringUtils.isNotBlank(orderId), KwtLogisticsOrderUnit::getLOrderId, orderId)
+                .eq(KwtLogisticsOrderUnit::getUnitType, NumberConstant.ONE));
+        KwtLogisticsOrderUnit unitTwo = logisticsOrderUnitMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrderUnit>()
+                .eq(StringUtils.isNotBlank(orderId), KwtLogisticsOrderUnit::getLOrderId, orderId)
+                .eq(KwtLogisticsOrderUnit::getUnitType, NumberConstant.TWO));
+        KwtLogisticsOrderAddress loadOrderAddress = logisticsOrderAddressMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrderAddress>()
+                .eq(StringUtils.isNotBlank(orderId), KwtLogisticsOrderAddress::getLOrderId, orderId)
+                .eq(KwtLogisticsOrderAddress::getAddressType, NumberConstant.ONE));
+        KwtLogisticsOrderAddress unloadOrderAddress = logisticsOrderAddressMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrderAddress>()
+                .eq(StringUtils.isNotBlank(orderId), KwtLogisticsOrderAddress::getLOrderId, orderId)
+                .eq(KwtLogisticsOrderAddress::getAddressType, NumberConstant.TWO));
+        KwtLogisticsOrderGoods orderGoods = logisticsOrderGoodsMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrderGoods>()
+                .eq(StringUtils.isNotBlank(logisticsOrder.getId()), KwtLogisticsOrderGoods::getLOrderId, logisticsOrder.getId()));
+        OrderDetailVO orderDetailVO = new OrderDetailVO();
+        orderDetailVO.setId(String.valueOf(logisticsOrder.getId()));
+        if (contract != null) {
+            orderDetailVO.setContractId(contract.getContractId() == null ? null : String.valueOf(contract.getContractId()));
+            //todo 接口调用合同服务查询合同信息
+            List<Long> list = new ArrayList<>(NumberConstant.SIXTEEN);
+            list.add(contract.getContractId());
+            Map<Long, ContractCommonInfoResDto> contractBaseInfo = remoteContractService.queryContractBaseInfo(list);
+            if (CollectionUtils.isNotEmpty(contractBaseInfo) && !ObjectUtils.isEmpty(contractBaseInfo.get(contract.getContractId()))) {
+                orderDetailVO.setContractName(contractBaseInfo.get(contract.getContractId()).getContactName());
+                orderDetailVO.setContractNo(contractBaseInfo.get(contract.getContractId()).getContractCode());
+                orderDetailVO.setSigningWay(contractBaseInfo.get(contract.getContractId()).getSigningWay());
+            }
+        }
+        if (unitOne != null) {
+            orderDetailVO.setConsignCompanyId(unitOne.getId());
+            orderDetailVO.setConsignCompany(unitOne.getFirmName());
+            orderDetailVO.setConsignContacts(unitOne.getContacts());
+            orderDetailVO.setConsignPhone(unitOne.getPhone());
+            orderDetailVO.setCollectionCompany(unitOne.getFirmName());
+        }
+        if (unitTwo != null) {
+            orderDetailVO.setCarrierCompanyId(unitTwo.getId());
+            orderDetailVO.setCarrierCompany(unitTwo.getFirmName());
+            orderDetailVO.setCarrierContacts(unitTwo.getContacts());
+            orderDetailVO.setCarrierPhone(unitTwo.getPhone());
+        }
+        orderDetailVO.setGoodsId(String.valueOf(orderGoods == null ? null : orderGoods.getGoodsId()));
+        orderDetailVO.setGoodsName(orderGoods == null ? null : orderGoods.getGoodsName());
+        orderDetailVO.setNumber(logisticsOrder.getAmount() == null ? null : logisticsOrder.getAmount());
+        orderDetailVO.setPrice(logisticsOrder.getPrice() == null ? null : logisticsOrder.getPrice());
+        orderDetailVO.setLoss(logisticsOrder.getLoss() == null ? null : logisticsOrder.getLoss());
+        orderDetailVO.setDeduct(logisticsOrder.getGoodsPrice() == null ? null : logisticsOrder.getGoodsPrice());
+        orderDetailVO.setLoadName(loadOrderAddress.getName());
+        orderDetailVO.setLoadAddress(loadOrderAddress.getCityName());
+        orderDetailVO.setLoadContacts(loadOrderAddress.getContacts());
+        orderDetailVO.setLoadPhone(loadOrderAddress.getPhone());
+        orderDetailVO.setLoadAddressDetail(loadOrderAddress.getDetailAddress());
+        orderDetailVO.setUnloadName(unloadOrderAddress.getName());
+        orderDetailVO.setUnloadAddress(unloadOrderAddress.getCityName());
+        orderDetailVO.setUnloadContacts(unloadOrderAddress.getContacts());
+        orderDetailVO.setUnloadPhone(unloadOrderAddress.getPhone());
+        orderDetailVO.setUnloadAddressDetail(unloadOrderAddress.getDetailAddress());
+        orderDetailVO.setSettlementCycle(logisticsOrder.getSettlementCycle() == null ? null : String.valueOf(logisticsOrder.getSettlementCycle()));
+        if (logisticsOrder.getSettlementCycle() != null) {
+            Map<String, SysDictResDto> dtoMap = remoteSystemService.queryDictMapByType(DictTypeEnum.SETTLEMENT_CYCLE.getType());
+            orderDetailVO.setSettlementCycleLabel(dtoMap.isEmpty() ? null :
+                    (dtoMap.get(String.valueOf(logisticsOrder.getSettlementCycle())) == null ? null : dtoMap.get(String.valueOf(logisticsOrder.getSettlementCycle())).getLabel()));
+        }
+        orderDetailVO.setBillingMode(logisticsOrder.getBillingMode());
+        if (logisticsOrder.getBillingMode() != null) {
+            Map<String, SysDictResDto> dictResDtoMap = remoteSystemService.queryDictMapByType(DictTypeEnum.CHARGING_TYPE.getType());
+            orderDetailVO.setBillingModeLabel(dictResDtoMap.isEmpty() ? null :
+                    (dictResDtoMap.get(logisticsOrder.getBillingMode()) == null ? null : dictResDtoMap.get(logisticsOrder.getBillingMode()).getLabel()));
+        }
+        orderDetailVO.setScheduleStartTime(logisticsOrder.getStartTime() == null ? null : logisticsOrder.getStartTime());
+        orderDetailVO.setScheduleEndTime(logisticsOrder.getEndTime() == null ? null : logisticsOrder.getEndTime());
+        if (logisticsOrder.getBillingMode().equals(String.valueOf(NumberConstant.ONE))) {
+            orderDetailVO.setPerformanceAmount(logisticsOrder.getTotalLoadAmount() == null ? null : logisticsOrder.getTotalLoadAmount());
+        } else if (logisticsOrder.getBillingMode().equals(String.valueOf(NumberConstant.TWO))) {
+            orderDetailVO.setPerformanceAmount(logisticsOrder.getUnloadAmount() == null ? null : logisticsOrder.getUnloadAmount());
+        }
+//        orderDetailVO.setPerformanceAmount(logisticsOrder.getLoadAmount() == null ? null : logisticsOrder.getLoadAmount());
+        orderDetailVO.setTotalLoadAmount(logisticsOrder.getTotalLoadAmount() == null ? new BigDecimal("0.00") : logisticsOrder.getTotalLoadAmount());
+        orderDetailVO.setTotalUnloadAmount(logisticsOrder.getTotalUnloadAmount() == null ? new BigDecimal("0.00") : logisticsOrder.getTotalUnloadAmount());
+        orderDetailVO.setCreateTime(logisticsOrder.getCreateTime());
+        orderDetailVO.setPayment(logisticsOrder.getPayment());
+        if (logisticsOrder.getPayment() != null) {
+            Map<String, SysDictResDto> dictResDtoMap = remoteSystemService.queryDictMapByType(DictTypeEnum.TRADE_TYPE.getType());
+            if (dictResDtoMap.isEmpty()) {
+                orderDetailVO.setPaymentLabel(null);
+            } else {
+                if (dictResDtoMap.get(logisticsOrder.getPayment().toString()) != null) {
+                    orderDetailVO.setPaymentLabel(dictResDtoMap.get(logisticsOrder.getPayment().toString()).getLabel());
+                }
+            }
+        }
+        if (orderDetailVO.getSigningWay() != null) {
+            Map<String, SysDictResDto> dictResDtoMap = remoteSystemService.queryDictMapByType(DictTypeEnum.SIGNING_TYPE.getType());
+            if (dictResDtoMap.isEmpty()) {
+                orderDetailVO.setPaymentLabel(null);
+            } else {
+                if (dictResDtoMap.get(String.valueOf(orderDetailVO.getSigningWay())) != null) {
+                    orderDetailVO.setSigningWayLabel(dictResDtoMap.get(orderDetailVO.getSigningWay().toString()).getLabel());
+                }
+            }
+        }
+        if (logisticsOrder.getGoodsPriceUnit() != null) {
+            SysDictResDto sysDictResDto = remoteSystemService.queryDictByTypeAndValue(DictTypeEnum.PRICE_TYPE.getType(), logisticsOrder.getGoodsPriceUnit());
+            orderDetailVO.setDeductLabel(sysDictResDto == null ? null : sysDictResDto.getLabel());
+        }
+        if (logisticsOrder.getLossUnit() != null) {
+            SysDictResDto sysDictResDto = remoteSystemService.queryDictByTypeAndValue(DictTypeEnum.TAX_RATE_TYPE.getType(), logisticsOrder.getLossUnit());
+            orderDetailVO.setLossLabel(sysDictResDto == null ? null : sysDictResDto.getLabel());
+        }
+        if (logisticsOrder.getUnit() != null) {
+            SysDictResDto sysDictResDto = remoteSystemService.queryDictByTypeAndValue(DictTypeEnum.UNIT_TYPE.getType(), logisticsOrder.getUnit());
+            orderDetailVO.setNumberLabel(sysDictResDto == null ? null : sysDictResDto.getLabel());
+        }
+        if (logisticsOrder.getPriceType() != null) {
+            SysDictResDto sysDictResDto = remoteSystemService.queryDictByTypeAndValue(DictTypeEnum.PRICE_TYPE.getType(), String.valueOf(logisticsOrder.getPriceType()));
+            orderDetailVO.setPriceLabel(sysDictResDto == null ? null : sysDictResDto.getLabel());
+        }
+        orderDetailVO.setRemark(logisticsOrder.getRemark());
+        /**亏吨量/吨->装货量-卸货量
+         * 合理损耗值=装货量*合理损耗
+         扣亏量/吨->亏吨量-合理损耗值
+         罚款值 扣亏量/吨*扣亏货值
+         总运价:
+         按照装货量 运输运价*装货量
+         按照卸货量 卸货量*运输单价-罚款值
+         按照趟次=运输运价
+         */
+        //合理损耗
+        BigDecimal loss = logisticsOrder.getLoss() == null ? new BigDecimal("0.00") : logisticsOrder.getLoss();
+
+        Integer status = logisticsOrder.getStatus();
+        List<Integer> orderStatusFinish = new ArrayList<>();
+        orderStatusFinish.add(LogisticsOrderEnum.HAVE_FINISHED.getCode());
+        orderStatusFinish.add(LogisticsOrderEnum.HAVE_RECONCILED.getCode());
+        orderStatusFinish.add(LogisticsOrderEnum.HAVE_ALREADY_SETTLED.getCode());
+        /**根据当前单据状态进行订单金额计算*/
+        if (orderStatusFinish.contains(status)) {
+            /**亏吨量/吨->装货量-卸货量
+             扣亏量/吨->亏吨量-合理损耗值
+             扣亏量/吨->亏吨量-合理损耗值(装货量*合理损耗)*/
+            BigDecimal loadAmount = logisticsOrder.getLoadAmount() == null ? new BigDecimal("0.00") : logisticsOrder.getLoadAmount();
+            BigDecimal unloadAmount = logisticsOrder.getUnloadAmount() == null ? new BigDecimal("0.00") : logisticsOrder.getUnloadAmount();
+            //运价
+            BigDecimal price = logisticsOrder.getPrice() == null ? new BigDecimal("0.00") : logisticsOrder.getPrice();
+            //亏吨量
+            BigDecimal defectiveWeighNumber = loadAmount.subtract(unloadAmount);
+            //合理损耗值
+            BigDecimal lossAmount = loadAmount.multiply(loss);
+            //扣亏量/吨
+            BigDecimal deductWeighNumber = defectiveWeighNumber.subtract(lossAmount);
+            if (deductWeighNumber.compareTo(new BigDecimal("0")) < 0) {
+                deductWeighNumber = new BigDecimal("0.00");
+            }
+            //罚款值
+            BigDecimal fineValue = (logisticsOrder.getGoodsPrice() == null ? new BigDecimal("0.00") : logisticsOrder.getGoodsPrice()).multiply(deductWeighNumber);
+            if (DictEnum.CHARGING_TYPE_1.getValue().equals(logisticsOrder.getBillingMode())) {
+                orderDetailVO.setOrderAmount(price.multiply(loadAmount));
+            } else if (DictEnum.CHARGING_TYPE_2.getValue().equals(logisticsOrder.getBillingMode())) {
+                orderDetailVO.setOrderAmount(unloadAmount.multiply(price).subtract(fineValue));
+            } else if (DictEnum.CHARGING_TYPE_3.getValue().equals(logisticsOrder.getBillingMode())) {
+                orderDetailVO.setOrderAmount(price);
+            }
+        } else {
+            orderDetailVO.setOrderAmount(logisticsOrder.getAmount().multiply(logisticsOrder.getPrice()));
+        }
+        httpResult.setData(orderDetailVO);
+        return httpResult;
+    }
 }