package com.sckw.transport.service;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson2.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sckw.core.common.enums.enums.DictTypeEnum;
import com.sckw.core.model.constant.Global;
import com.sckw.core.model.constant.NumberConstant;
import com.sckw.core.model.enums.AddressTypeEnum;
import com.sckw.core.model.enums.CarWaybillEnum;
import com.sckw.core.model.page.PageHelperUtil;
import com.sckw.core.model.page.PageResult;
import com.sckw.core.utils.*;
import com.sckw.core.web.context.LoginUserHolder;
import com.sckw.core.web.response.HttpResult;
import com.sckw.fleet.api.RemoteFleetService;
import com.sckw.system.api.RemoteSystemService;
import com.sckw.system.api.model.dto.res.EntCacheResDto;
import com.sckw.system.api.model.dto.res.UserCacheResDto;
import com.sckw.transport.dao.*;
import com.sckw.transport.model.*;
import com.sckw.transport.model.dto.*;
import com.sckw.transport.model.enuma.ApproveStatusEnum;
import com.sckw.transport.model.enuma.CarWaybillAppEnum;
import com.sckw.transport.model.enuma.CarWaybillDetailEnum;
import com.sckw.transport.model.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author jc
 * @description 运单相关服务
 * @date 2023-06-29 15:06:45
 */
@Slf4j
@Service
public class KwtWaybillManagementV1Service {

    @DubboReference(version = "1.0.0", group = "design", check = false)
    RemoteFleetService remoteFleetService;

    @DubboReference(version = "1.0.0", group = "design", check = false)
    RemoteSystemService remoteSystemService;

    @Autowired
    public KwtWaybillOrderMapper kwtWaybillOrderMapper;

    @Autowired
    public KwtWaybillOrderV1Mapper waybillOrderV1Mapper;

    @Autowired
    public KwtLogisticsOrderMapper kwtLogisticsOrderMapper;

    @Autowired
    public KwtWaybillOrderAddressMapper kwtWaybillOrderAddressMapper;

    @Autowired
    public KwtWaybillOrderTicketMapper kwtWaybillOrderTicketMapper;

    @Autowired
    private KwtLogisticsOrderCirculateMapper orderCirculateMapper;

    @Autowired
    public KwtWaybillOrderTrackMapper kwtWaybillOrderTrackMapper;

    @Autowired
    public KwtWaybillOrderSubtaskMapper waybillOrderSubtaskMapper;

    @Autowired
    public KwtLogisticsOrderGoodsMapper logisticsOrderGoodsMapper;

    @Autowired
    public KwtLogisticsOrderUnitMapper logisticsOrderUnitMapper;

    @Autowired
    KwtWaybillOrderTicketService kwtWaybillOrderTicketService;

    @Autowired
    private MongoTemplate mongoTemplate;

    @Autowired
    private KwtCommonService commonService;


    /**
     * @desc 物流订单详情-根据物流订单ID查询运单列表
     * @param query 参数
     * @author zk
     * @date 2024/4/3
     **/
    public HttpResult logisticOrderWaybillStatistic(WaybillListAppDTO query) {
        // 运单创建人或有关授权用户
        List<Long> userIds = LoginUserHolder.getAuthUserIdList();
        WaybillOrderQueryDto queryDto = new WaybillOrderQueryDto();
        query.setStatus(null);
        BeanUtil.copyProperties(query, queryDto);
        queryDto.setEntId(LoginUserHolder.getEntId());
        queryDto.setUserIds(userIds);
        Map<String, Object> statistic = waybillOrderSubtaskMapper.findWaybillOrderCount(queryDto);
        return HttpResult.ok(statistic);
    }

    /**
     * @desc 物流订单详情-根据物流订单ID查询运单列表
     * @param query 参数
     * @author zk
     * @date 2024/4/3
     **/
    public HttpResult logisticOrderWaybill(WaybillListAppDTO query) {
        query.setBusAppStatus(Objects.requireNonNull(CarWaybillAppEnum.getRemark(query.getStatus())).getValue());
        query.setStatus(null);
        Map<String, Object> params = BeanUtil.beanToMap(query);
        // 设置分页参数
        PageHelper.startPage(PageResult.getPage(params), PageResult.getPageSize(params));
        /*数据查询**/
        List<WaybillOrderSubtaskVo> list = waybillOrderV1Mapper.findWaybillOrderSubtask(params);

        //单位
        Map<String, Map<String, String>> dict = remoteSystemService.queryDictByType(List.of(DictTypeEnum.UNIT_TYPE.getType()));
        Map<String, String> unitMap = CollectionUtils.isNotEmpty(dict) ? dict.get(DictTypeEnum.UNIT_TYPE.getType()) : new HashMap<>(NumberConstant.SIXTEEN);

        List<Map<String, Object>> result = new ArrayList<>();
        for (WaybillOrderSubtaskVo subtask:list) {
            Map<String, Object> order = BeanUtil.beanToMap(subtask);
            order.put("statusLabel", CarWaybillEnum.getName(subtask.getStatus()));
            order.put("unitLabel", unitMap.get(subtask.getUnit()));
            order.put("typeLabel", subtask.getType() == NumberConstant.ONE ? "趟次" : "循环");
            result.add(order);
        }

        PageResult pageResult = PageHelperUtil.getPageResult(new PageInfo<>(result));
        return HttpResult.ok(pageResult);
    }


    /**
     * @desc 物流订单详情-根据物流订单ID查询运单列表
     * @param query 参数
     * @author zk
     * @date 2024/4/3
     **/
    public HttpResult findNdexPage(WaybillListAppDTO query) {
        // 运单创建人或有关授权用户
        List<Long> userIds = LoginUserHolder.getAuthUserIdList();
        String queryWstatus = Objects.requireNonNull(CarWaybillAppEnum.getRemark(query.getStatus())).getValue();
        WaybillOrderQueryDto queryDto = new WaybillOrderQueryDto();
        query.setStatus(null);
        BeanUtil.copyProperties(query, queryDto);
        queryDto.setQueryWstatus(queryWstatus);
        queryDto.setEntId(LoginUserHolder.getEntId());
        queryDto.setUserIds(userIds);
        /*数据查询**/
        List<WaybillOrderSelectVo> list = waybillOrderV1Mapper.findListPage(queryDto);

        //单位
        Map<String, Map<String, String>> dict = remoteSystemService.queryDictByType(List.of(DictTypeEnum.UNIT_TYPE.getType()));
        Map<String, String> unitMap = CollectionUtils.isNotEmpty(dict) ? dict.get(DictTypeEnum.UNIT_TYPE.getType()) : new HashMap<>(NumberConstant.SIXTEEN);

        //数据处理
        List<Map<String, Object>> result = new ArrayList<>();
        for (WaybillOrderSelectVo waybillOrder:list) {
            //运单地址信息
            List<KwtWaybillOrderAddress> addresses = kwtWaybillOrderAddressMapper.findByAddresses(waybillOrder.getWOrderId(), null);
            List<JSONObject> addressList = new ArrayList<>();
            for (KwtWaybillOrderAddress address:addresses) {
                //运单子单
                KwtWaybillOrderSubtask subtask = waybillOrderSubtaskMapper.selectById(address.getWSubtaskId());
                //物流订单商品信息
                KwtLogisticsOrderGoods goods = logisticsOrderGoodsMapper.findByGoods(subtask != null ? subtask.getLOrderId() : null);
                //榜单信息
                KwtWaybillOrderTicket ticket = kwtWaybillOrderTicketMapper.findWaybillOrderTicketV2(address.getId(), subtask.getUnit());
                //数据组装
                JSONObject addressJson = new JSONObject();
                addressJson.put("wAddressId", address.getId());
                addressJson.put("addressType", address.getAddressType());
                addressJson.put("addressName", address.getName());
                addressJson.put("addressCityName", address.getCityName());
                addressJson.put("addressDetail", address.getDetailAddress());
                addressJson.put("planTime", DateUtils.format(address.getPlanTime(), DateUtils.FORMAT12));

                addressJson.put("entrustAmount", address.getEntrustAmount());
                addressJson.put("goodsName", goods != null ? goods.getGoodsName() : null);
                addressJson.put("unit", subtask.getUnit());
                addressJson.put("unitName", unitMap.get(subtask.getUnit()));
                addressJson.put("amount", ticket != null ? ticket.getAmount() : null);
                addressJson.put("urls", ticket != null ? ticket.getUrls() : null);
                addressJson.put("operateStatus", ticket != null);
                addressJson.put("operateTime", ticket != null ? DateUtils.format(address.getPlanTime(), DateUtils.FORMAT11) : null);
                addressJson.put("approvalStatus", ticket != null ? ticket.getStatus() : null);
                addressList.add(addressJson);
            }

            Map<String, Object> order = BeanUtil.beanToMap(waybillOrder);
            order.put("statusLabel", CarWaybillEnum.getName(waybillOrder.getStatus()));
            order.put("addresses", addressList);
            order.put("typeLabel", waybillOrder.getType() == NumberConstant.ONE ? "趟次" : "循环");
            result.add(order);
        }

        PageResult pageResult = PageHelperUtil.getPageResult(new PageInfo<>(result));
        return HttpResult.ok(pageResult);
    }

    /**
     * @param wOrderId 运单ID
     * @desc 运单详情
     * @author zk
     * @date 2024/3/13
     **/
    public HttpResult waybillDetail1(Long wOrderId) {
        //运单信息
        KwtWaybillOrderV1 waybillOrder = waybillOrderV1Mapper.selectById(wOrderId);
        if (waybillOrder == null) {
            return HttpResult.error("运单" + wOrderId + "不存在，请确认！");
        }

        //运单状态记录
        List<KwtWaybillOrderTrack> tracks = kwtWaybillOrderTrackMapper.findTrack(wOrderId, null, null, null);
        //用户信息
        List<Long> userIds = tracks.stream().map(KwtWaybillOrderTrack::getCreateBy).toList();
        List<Long> userIdList = new ArrayList<>(NumberConstant.SIXTEEN){{add(waybillOrder.getCreateBy());}};
        userIdList.addAll(userIds);
        List<UserCacheResDto> users = remoteSystemService.queryUserCacheByIds(userIdList);
        Map<Long, UserCacheResDto> usersMap = new HashMap<>(Global.NUMERICAL_SIXTEEN);
        users.forEach(e -> usersMap.put(e.getId(), e));
        //企业ID
        List<Long> entIds = new ArrayList<>(){{add(waybillOrder.getEntId());}};
        Map<Long, EntCacheResDto> ents = remoteSystemService.queryEntCacheMapByIds(entIds);
        //单位
        Map<String, Map<String, String>> dict = remoteSystemService.queryDictByType(List.of(DictTypeEnum.UNIT_TYPE.getType()));
        Map<String, String> unitMap = CollectionUtils.isNotEmpty(dict) ? dict.get(DictTypeEnum.UNIT_TYPE.getType()) : new HashMap<>(NumberConstant.SIXTEEN);

        /*数据处理*/
        List<Map<String, Object>> trackList = new ArrayList<>();
        List<Integer> statusList = CarWaybillDetailEnum.initWaybillStatus();
        //使用for-each循环来遍历Color枚举类的所有值
        for (Integer value:statusList) {
            List<String> asList = Arrays.asList(CarWaybillDetailEnum.getValue(value).split(Global.COMMA));
            for (String status:asList) {
                KwtWaybillOrderTrack track = kwtWaybillOrderTrackMapper.findWaybillOrderTrack(wOrderId, null, null, Integer.valueOf(status));
                Map<String, Object> trackData = new HashMap<>(NumberConstant.SIXTEEN);
                trackData.put("operateByName", usersMap.get(waybillOrder.getCreateBy()) != null ? usersMap.get(waybillOrder.getCreateBy()).getName() : waybillOrder.getDriverName());
                trackData.put("operateTime", track != null ? DateUtils.format(track.getOperateTime(), DateUtils.FORMAT11) : null);
                trackData.put("operateStatus", track != null);
                trackData.put("createTime", track != null ? track.getCreateTime() : null);
                trackData.put("status", status);
                trackData.put("statusName", CarWaybillDetailEnum.getName1(Integer.valueOf(status)));
                trackList.add(trackData);
            }
        }

        //运单地址状态处理(到达装货点、已装货、到达卸货点、已卸货)
        List<KwtWaybillOrderAddress> addresses = kwtWaybillOrderAddressMapper.findByAddresses(wOrderId, null);
        for (KwtWaybillOrderAddress address:addresses) {
            //运单子单
            KwtWaybillOrderSubtask subtask = waybillOrderSubtaskMapper.selectById(address.getWSubtaskId());
            //物流订单商品信息
            KwtLogisticsOrderGoods goods = logisticsOrderGoodsMapper.findByGoods(subtask != null ? subtask.getLOrderId() : null);
            //榜单信息
            KwtWaybillOrderTicket ticket = kwtWaybillOrderTicketMapper.findWaybillOrderTicketV2(address.getId(), subtask.getUnit());
            Map<String, Object> addressData = new HashMap<>(NumberConstant.SIXTEEN);
            addressData.put("addressType", address.getAddressType());
            addressData.put("addressName", address.getName());
            addressData.put("addressCityName", address.getCityName());
            addressData.put("addressDetail", address.getDetailAddress());
            addressData.put("planTime", DateUtils.format(address.getPlanTime(), DateUtils.FORMAT12));
            addressData.put("entrustAmount", address.getEntrustAmount());
            addressData.put("goodsName", goods != null ? goods.getGoodsName() : null);
            addressData.put("unit", subtask.getUnit());
            addressData.put("unitName", unitMap.get(subtask.getUnit()));
            addressData.put("amount", ticket != null ? ticket.getAmount() : null);
            addressData.put("urls", ticket != null ? FileUtils.spliceBatch(ticket.getUrls()) : null);
            addressData.put("operateStatus", ticket != null);
            addressData.put("operateTime", ticket != null ? DateUtils.format(address.getPlanTime(), DateUtils.FORMAT11) : null);
            addressData.put("operateByName", usersMap.get(waybillOrder.getCreateBy()) != null ? usersMap.get(waybillOrder.getCreateBy()).getName() : waybillOrder.getDriverName());
            addressData.put("status", ticket != null ? ticket.getStatus() : null);
            addressData.put("statusName", ticket != null ? ApproveStatusEnum.getName(ticket.getStatus()) : null);
            trackList.add(addressData);
        }

        //审核状态
        KwtWaybillOrderTrack track = kwtWaybillOrderTrackMapper.findWaybillOrderTrackV1(wOrderId, CarWaybillDetailEnum.WAIT_APPROVAL.getValue());
        Map<String, Object> trackData = new HashMap<>(NumberConstant.SIXTEEN);
        trackData.put("operateByName", usersMap.get(waybillOrder.getCreateBy()) != null ? usersMap.get(waybillOrder.getCreateBy()).getName() : waybillOrder.getDriverName());
        trackData.put("operateTime", track != null ? DateUtils.format(track.getOperateTime(), DateUtils.FORMAT11) : null);
        trackData.put("operateStatus", track != null);
        trackData.put("createTime", track != null ? track.getCreateTime() : null);
        trackData.put("status", CarWaybillDetailEnum.WAIT_APPROVAL.getCode());
        trackData.put("statusName", CarWaybillDetailEnum.WAIT_APPROVAL.getName());
        trackList.add(trackData);

        //榜单信息
        List<KwtWaybillOrderTicket> tickets = kwtWaybillOrderTicketMapper.findWaybillOrderTicket(wOrderId, null, null);
        //数据处理
        List<String> loadUrl = new ArrayList<>(), unloadUrl = new ArrayList<>();
        for (KwtWaybillOrderTicket ticket:tickets) {
            if(ticket.getType().equals(AddressTypeEnum.SHIPMENT.getCode())){
                loadUrl.add(FileUtils.spliceBatch(ticket.getUrls()));
            } else {
                unloadUrl.add(FileUtils.spliceBatch(ticket.getUrls()));
            }
        }

        //返回信息
        Map<String, Object> waybillDetail = BeanUtil.beanToMap(waybillOrder);
        waybillDetail.put("loadUrl", loadUrl);
        waybillDetail.put("unloadUrl", unloadUrl);
        waybillDetail.put("wOrederId", waybillOrder.getId());
        waybillDetail.put("statusName", CarWaybillEnum.getName(waybillOrder.getStatus()));
        waybillDetail.put("createByName", usersMap.get(waybillOrder.getCreateBy()) != null ? usersMap.get(waybillOrder.getCreateBy()).getName() : null);
        waybillDetail.put("createByPhone", usersMap.get(waybillOrder.getCreateBy()) != null ? usersMap.get(waybillOrder.getCreateBy()).getPhone() : null);
        waybillDetail.put("firmName", ents.get(waybillOrder.getEntId()) != null ? ents.get(waybillOrder.getEntId()).getFirmName() : null);
        waybillDetail.put("trackList", trackList);
        return HttpResult.ok(waybillDetail);
    }

    public HttpResult waybillDetail(Long wOrderId) {
        //车辆运单信息
        KwtWaybillOrderV1 waybillOrder = waybillOrderV1Mapper.selectById(wOrderId);
        if (waybillOrder == null) {
            return HttpResult.ok("车辆运单信息不存在！");
        }
        //运单状态
        List<KwtWaybillOrderTrack> tracks = kwtWaybillOrderTrackMapper.findTrack(wOrderId, null, null, null);
        //操作人
        List<Long> userIds = tracks.stream().map(KwtWaybillOrderTrack::getCreateBy).toList();
        List<UserCacheResDto> users = remoteSystemService.queryUserCacheByIds(userIds);
        Map<Long, UserCacheResDto> usersMap = new HashMap<>(Global.NUMERICAL_SIXTEEN);
        users.forEach(e -> usersMap.put(e.getId(), e));
        //单位
        Map<String, Map<String, String>> dict = remoteSystemService.queryDictByType(List.of(DictTypeEnum.UNIT_TYPE.getType()));
        Map<String, String> unitMap = CollectionUtils.isNotEmpty(dict) ? dict.get(DictTypeEnum.UNIT_TYPE.getType()) : new HashMap<>(NumberConstant.SIXTEEN);

        /*数据处理*/
        List<Map<String, Object>> trackList = new ArrayList<>();
        //运单状态(待接单、待出车、出车)
        List<Integer> statusList = CarWaybillDetailEnum.initWaybillStatus();
        //使用for-each循环来遍历Color枚举类的所有值
        for (Integer value:statusList) {
            List<String> asList = Arrays.asList(CarWaybillDetailEnum.getValue(value).split(Global.COMMA));
            for (String status:asList) {
                KwtWaybillOrderTrack track = kwtWaybillOrderTrackMapper.findWaybillOrderTrack(wOrderId, null, null, Integer.valueOf(status));
                Map<String, Object> trackData = new HashMap<>(NumberConstant.SIXTEEN);
                trackData.put("operateByName", usersMap.get(waybillOrder.getCreateBy()) != null ? usersMap.get(waybillOrder.getCreateBy()).getName() : waybillOrder.getDriverName());
                trackData.put("operateTime", track != null ? DateUtils.format(track.getOperateTime(), DateUtils.FORMAT11) : null);
                trackData.put("operateStatus", track != null);
                trackData.put("createTime", track != null ? track.getCreateTime() : null);
                trackData.put("status", status);
                trackData.put("statusName", CarWaybillDetailEnum.getName1(Integer.valueOf(status)));
                trackList.add(trackData);
            }
        }

        //运单状态处理(到达装货点、已装货、到达卸货点、已卸货)
        List<KwtWaybillOrderAddress> addresses = kwtWaybillOrderAddressMapper.findByAddresses(wOrderId, null);
        for (KwtWaybillOrderAddress address:addresses) {
            if (address.getAddressType().equals(AddressTypeEnum.SHIPMENT.getCode())) {
                statusList = new ArrayList<>(){{add(CarWaybillEnum.WAIT_LOADING.getCode()); add(CarWaybillEnum.COMPLETION_LOADING.getCode());}};
            } else {
                statusList = new ArrayList<>(){{add(CarWaybillEnum.WAIT_UNLOADING.getCode()); add(CarWaybillEnum.COMPLETION_UNLOADING.getCode());}};
            }

            //子单信息
            KwtWaybillOrderSubtask subtask = waybillOrderSubtaskMapper.selectById(address.getWSubtaskId());
            //物流订单商品信息
            KwtLogisticsOrderGoods goods = logisticsOrderGoodsMapper.findByGoods(subtask != null ? subtask.getLOrderId() : null);
            for (Integer status:statusList) {
                //状态记录
                KwtWaybillOrderTrack track = kwtWaybillOrderTrackMapper.findWaybillOrderTrack(wOrderId, subtask.getId(), address.getId(), status);
                Map<String, Object> trackData = new HashMap<>(NumberConstant.SIXTEEN);
                trackData.put("id", track != null ? track.getId() : null);
                trackData.put("wOrderId", address.getWOrderId());
                trackData.put("wSubtaskId", address.getWSubtaskId());
                trackData.put("wAddressId", address.getId());
                trackData.put("operateByName", track != null ? usersMap.get(track.getCreateBy()) == null ? waybillOrder.getDriverName() : usersMap.get(track.getCreateBy()).getName() : null);
                trackData.put("operateTime", track != null ? DateUtils.format(track.getOperateTime(), DateUtils.FORMAT11) : null);
                trackData.put("operateStatus", track != null);
                trackData.put("createTime", track != null ? DateUtils.format(track.getCreateTime(), DateUtils.DATE_TIME_PATTERN) : null);
                trackData.put("status", status);
                trackData.put("statusName", CarWaybillEnum.getName(status));
                trackData.put("planTime", track != null ? address.getPlanTime() : null);
                trackData.put("entrustAmount", track != null ? address.getEntrustAmount() : null);
                trackData.put("unit", subtask.getUnit());
                trackData.put("unitName", unitMap.get(subtask.getUnit()));
                trackData.put("goodsName", goods != null ? goods.getGoodsName() : null);
                trackData.put("addressName", address.getName());
                trackData.put("addressCityName", address.getCityName());
                trackData.put("addressDetail", address.getDetailAddress());
                trackList.add(trackData);
            }
        }

        //审核状态
        KwtWaybillOrderTrack track = kwtWaybillOrderTrackMapper.findWaybillOrderTrackV1(wOrderId, CarWaybillDetailEnum.WAIT_APPROVAL.getValue());
        Map<String, Object> trackData = new HashMap<>(NumberConstant.SIXTEEN);
        trackData.put("operateByName", usersMap.get(waybillOrder.getCreateBy()) != null ? usersMap.get(waybillOrder.getCreateBy()).getName() : waybillOrder.getDriverName());
        trackData.put("operateTime", track != null ? DateUtils.format(track.getOperateTime(), DateUtils.FORMAT11) : null);
        trackData.put("operateStatus", track != null);
        trackData.put("createTime", track != null ? DateUtils.format(track.getCreateTime(), DateUtils.DATE_TIME_PATTERN) : null);
        trackData.put("status", CarWaybillDetailEnum.WAIT_APPROVAL.getCode());
        trackData.put("statusName", CarWaybillDetailEnum.WAIT_APPROVAL.getName());
        trackList.add(trackData);

        //运单子单
        List<KwtWaybillOrderSubtask> subtasks = waybillOrderSubtaskMapper.findByWOrderId(wOrderId);
        List<Long> lOrderIds = subtasks.stream().map(KwtWaybillOrderSubtask::getLOrderId).toList();
        List<KwtLogisticsOrderUnit> units = logisticsOrderUnitMapper.selectCompanyBylOrderId(lOrderIds, null);
        String checkFirmName = units.stream().filter(item -> item.getUnitType().equals(NumberConstant.ONE)).map(KwtLogisticsOrderUnit::getFirmName).collect(Collectors.joining(", "));
        String carrierFirmName = units.stream().filter(item -> item.getUnitType().equals(NumberConstant.TWO)).map(KwtLogisticsOrderUnit::getFirmName).collect(Collectors.joining(", "));

        List<KwtWaybillOrderTicket> waybillOrderTicketV1 = kwtWaybillOrderTicketMapper.findWaybillOrderTicketV1(wOrderId, null, null, null);
        String loadUrls = "";
        String downUrls = "";
        if (CollectionUtils.isNotEmpty(waybillOrderTicketV1)) {
            Map<Integer, List<KwtWaybillOrderTicket>> collect = waybillOrderTicketV1.stream().collect(Collectors.groupingBy(KwtWaybillOrderTicket::getType));
            List<KwtWaybillOrderTicket> kwtWaybillOrderTickets = collect.get(Global.NUMERICAL_ONE);
            if (CollectionUtils.isNotEmpty(kwtWaybillOrderTickets)) {
                loadUrls = kwtWaybillOrderTickets.stream().map(item -> FileUtils.splice(item.getUrls())).collect(Collectors.joining(Global.COMMA));
            }

            List<KwtWaybillOrderTicket> kwtWaybillOrderTickets1 = collect.get(Global.NUMERICAL_TWO);
            if (CollectionUtils.isNotEmpty(kwtWaybillOrderTickets1)) {
                downUrls = kwtWaybillOrderTickets1.stream().map(item -> FileUtils.splice(item.getUrls())).collect(Collectors.joining(Global.COMMA));
            }
        }

        //数据拼接
        Map<String, Object> result = new HashMap<>(Global.NUMERICAL_SIXTEEN);
        result.put("wOrderId", wOrderId);
        result.put("wOrderNo", waybillOrder.getWOrderNo());
        result.put("status", waybillOrder.getStatus());
        result.put("statusName", CarWaybillEnum.getName(waybillOrder.getStatus()));
        result.put("truckNo", waybillOrder.getTruckNo());
        result.put("driverName", waybillOrder.getDriverName());
        result.put("driverPhone", waybillOrder.getDriverPhone());
        result.put("driverIdcard", waybillOrder.getDriverIdcard());
        result.put("createTime", DateUtils.format(waybillOrder.getCreateTime(), DateUtils.DATE_TIME_PATTERN));
        result.put("checkFirmName", checkFirmName);
        result.put("carrierFirmName", carrierFirmName);
        result.put("trackList", trackList);
        result.put("loadUrls", loadUrls);
        result.put("downUrls", downUrls);
        return HttpResult.ok(result);
    }

}
