package com.prolog.rdc.tms.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import cn.hutool.core.util.NumberUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestBody;

import com.google.common.collect.Lists;
import com.prolog.common.util.ToolKits;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.exception.PrologException;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.core.restriction.Criteria;
import com.prolog.framework.core.restriction.Order;
import com.prolog.framework.core.restriction.Restriction;
import com.prolog.framework.core.restriction.Restrictions;
import com.prolog.framework.dao.util.PageUtils;
import com.prolog.product.core.framework.entity.UserEntity;
import com.prolog.product.core.framework.util.PlgFxUsrUtils;
import com.prolog.rdc.tms.constant.BussinessConstant;
import com.prolog.rdc.tms.constant.DataDictionaryConstant;
import com.prolog.rdc.tms.constant.StatusConstant;
import com.prolog.rdc.tms.dao.mapper.TmsLoadingBillDetailMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillDetailMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillPackageMapper;
import com.prolog.rdc.tms.model.dto.ExportFinishShipbillDTO;
import com.prolog.rdc.tms.model.dto.FinishShipBillDetailDTO;
import com.prolog.rdc.tms.model.dto.FinishShipbillDTO;
import com.prolog.rdc.tms.model.dto.FinishShipbillPackageDTO;
import com.prolog.rdc.tms.model.dto.PendingReceiptPrintDetailDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.SignconfigPopDTO;
import com.prolog.rdc.tms.model.entity.TmsShipbillDetailModel;
import com.prolog.rdc.tms.model.entity.TmsShipbillPackageModel;
import com.prolog.rdc.tms.model.vo.FinishAdsQueryVO;
import com.prolog.rdc.tms.model.vo.FinishShipbillDetailVO;
import com.prolog.rdc.tms.model.vo.FinishShipbillPrintVO;
import com.prolog.rdc.tms.model.vo.FinishShipbillQueryVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.SignconfigPopVO;
import com.prolog.rdc.tms.rmi.feign.MaindataFeign;
import com.prolog.rdc.tms.service.FinishShipbillService;
import com.prolog.rdc.tms.util.PublicMethods;

import cn.hutool.core.util.ObjectUtil;

/**
 * 运输管理-完成运单实现层
 *
 * @author lhb
 * @since 2022-06-01 14:45:00
 */
@Service
public class FinishShipbillServiceImpl implements FinishShipbillService {

    @Autowired
    private TmsShipbillDetailMapper tmsShipbillDetailMapper;

    @Autowired
    private TmsShipbillPackageMapper tmsShipbillPackageMapper;

    @Autowired
    private MaindataFeign maindataTmsResource;

    @Autowired
    private TmsLoadingBillDetailMapper tmsLoadingBillDetailMapper;

    /**
     * 完成运单分页查询
     *
     * @param vo
     * @return
     */
    @SuppressWarnings("resource")
    @Override
    public Page<FinishShipbillDTO> queryFinishShipbillPage(FinishShipbillQueryVO vo) {
        ToolKits.isParamNull(vo, "完成运单分页查询请求不为空");
        ToolKits.isParamNull(vo.getPageNum(), "当前页码不为空");
        ToolKits.isParamNull(vo.getPageSize(), "每页条数不为空");

        UserEntity user = PlgFxUsrUtils.getUserEntity();
        ToolKits.isParamNull(user, "当前人员没有操作权限");

        // 数据字典翻译数据集合
        List<Map<String, Object>> data1 = Lists.newArrayList();
        List<Map<String, Object>> data2 = Lists.newArrayList();
        List<Map<String, Object>> data3 = Lists.newArrayList();
        List<Map<String, Object>> data4 = Lists.newArrayList();
        List<Map<String, Object>> data5 = Lists.newArrayList();
        List<Map<String, Object>> data6 = Lists.newArrayList();
        List<Map<String, Object>> data7 = Lists.newArrayList();
        List<SignconfigPopDTO> data8 = Lists.newArrayList();
        List<Map<String, Object>> data9 = Lists.newArrayList();
        List<Map<String, Object>> data10 = Lists.newArrayList();
        List<Map<String, Object>> data11 = Lists.newArrayList();
        List<Map<String, Object>> data12 = Lists.newArrayList();
        List<Map<String, Object>> data13 = Lists.newArrayList();

        // 订单类型
        RestMessage<List<Map<String, Object>>> restMessage1 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_TYPE, null, null, null);
        if (!restMessage1.isSuccess()) {
            throw new RuntimeException("订单类型翻译失败!");
        } else {
            data1 = restMessage1.getData();
        }
        // 订单业务类型
        RestMessage<List<Map<String, Object>>> restMessage2 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_BUSINESS_TYPE, null, null, null);
        if (!restMessage2.isSuccess()) {
            throw new RuntimeException("订单业务类型翻译失败!");
        } else {
            data2 = restMessage2.getData();
        }
        // 配送方式
        RestMessage<List<Map<String, Object>>> restMessage3 = maindataTmsResource.getDropDownById(DataDictionaryConstant.DELIVERY_METHOD_TYPE, null, null, null);
        if (!restMessage3.isSuccess()) {
            throw new RuntimeException("配送方式翻译失败!");
        } else {
            data3 = restMessage3.getData();
        }
        // 运输类型(运输模式)
        RestMessage<List<Map<String, Object>>> restMessage4 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_TYPE, null, null, null);
        if (!restMessage4.isSuccess()) {
            throw new RuntimeException("运输类型(运输模式)翻译失败!");
        } else {
            data4 = restMessage4.getData();
        }
        // 温度要求
        RestMessage<List<Map<String, Object>>> restMessage5 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TEMPERATURE_REQUIREMENT, null, null, null);
        if (!restMessage5.isSuccess()) {
            throw new RuntimeException("温度要求翻译失败!");
        } else {
            data5 = restMessage5.getData();
        }
        // 发货方类型
        RestMessage<List<Map<String, Object>>> restMessage6 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPPER_TYPE, null, null, null);
        if (!restMessage6.isSuccess()) {
            throw new RuntimeException("发货方类型翻译失败!");
        } else {
            data6 = restMessage6.getData();
        }
        // 收货方类型
        RestMessage<List<Map<String, Object>>> restMessage7 = maindataTmsResource.getDropDownById(DataDictionaryConstant.CONSIGNEE_TYPE, null, null, null);
        if (!restMessage7.isSuccess()) {
            throw new RuntimeException("收货方类型翻译失败!");
        } else {
            data7 = restMessage7.getData();
        }
        // 标记配置
        SignconfigPopVO signconfigPopVO = new SignconfigPopVO();
        RestMessage<List<SignconfigPopDTO>> restMessage8 = maindataTmsResource.getSignConfig(signconfigPopVO);
        if (!restMessage8.isSuccess()) {
            throw new RuntimeException("标记配置查询失败!");
        } else {
            data8 = restMessage8.getData();
        }

        // 运单状态
        RestMessage<List<Map<String, Object>>> restMessage9 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPBILL_STATUS, null, null, null);
        if (!restMessage9.isSuccess()) {
            throw new RuntimeException("运单状态翻译失败!");
        } else {
            data9 = restMessage9.getData();
        }
        // 运输状态
        RestMessage<List<Map<String, Object>>> restMessage10 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_STATUS, null, null, null);
        if (!restMessage10.isSuccess()) {
            throw new RuntimeException("运输状态翻译失败!");
        } else {
            data10 = restMessage10.getData();
        }
        // 异常状态
        RestMessage<List<Map<String, Object>>> restMessage11 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ABNORMAL_STATUS, null, null, null);
        if (!restMessage11.isSuccess()) {
            throw new RuntimeException("异常状态翻译失败!");
        } else {
            data11 = restMessage11.getData();
        }
        // 扫描状态
        RestMessage<List<Map<String, Object>>> restMessage12 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SCAN_STATUS, null, null, null);
        if (!restMessage12.isSuccess()) {
            throw new RuntimeException("扫描状态翻译失败!");
        } else {
            data12 = restMessage12.getData();
        }

        // 承运方类型
        RestMessage<List<Map<String, Object>>> restMessage13 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LINE_CARRIER_TYPE, null, null, null);
        if (!restMessage13.isSuccess()) {
            throw new RuntimeException("承运方类型翻译失败!");
        } else {
            data13 = restMessage13.getData();
        }

        if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
            // 判断是否为部门权限
            if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
                vo.setDepartmentIds(user.getDepts().stream().toArray(String[]::new));
            } else {
                vo.setDepartmentIds(user.getDepts().stream().toArray(String[]::new));
                vo.setCargoOwnerIds(user.getConsignors().stream().toArray(Long[]::new));

                StringBuffer sqlBuff = new StringBuffer();
                if (ToolKits.isNotEmpty(user.getWarehouses())) {
                    sqlBuff.append(" t2.consignee_unit_id in (" + user.getWarehouses().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                    sqlBuff.append(" or t2.shipper_unit_id in (" + user.getWarehouses().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                }
                if (ToolKits.isNotEmpty(user.getSuppliers())) {
                    if (sqlBuff.toString().length() > 0) {
                        sqlBuff.append(" or t2.consignee_unit_id in (" + user.getSuppliers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                    } else {
                        sqlBuff.append(" t2.consignee_unit_id in (" + user.getSuppliers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                    }
                    sqlBuff.append(" or t2.shipper_unit_id in (" + user.getSuppliers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                }
                if (ToolKits.isNotEmpty(user.getCustomers())) {
                    if (sqlBuff.toString().length() > 0) {
                        sqlBuff.append(" or t2.consignee_unit_id in (" + user.getCustomers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                    } else {
                        sqlBuff.append(" t2.consignee_unit_id in (" + user.getCustomers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                    }
                    sqlBuff.append(" or t2.shipper_unit_id in (" + user.getCustomers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                }
                if (sqlBuff.toString().length() > 0) {
                    vo.setSqlBuff("( " + sqlBuff.toString() + " )");
                }
            }
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_CYS)) {// 承运商账号
            vo.setScheduleType(DataDictionaryConstant.SCHEDULE_TYPE_CYS);
            vo.setCarrierId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
            vo.setCarrierShipbillStatus(DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_DISPATCHED_CHECK);
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_HZ)) {// 货主账号
            vo.setCargoOwnerUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_GYS)) {// 供应商账号
            vo.setSupplierUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_KH)) {// 客户账号
            vo.setCustomerUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
        }
        List<FinishShipbillDTO> pageFinishShipbillDTOs = Lists.newArrayList();
        vo.setEnterpriseId(user.getEnterpriseId());

        PageUtils.startPage(vo.getPageNum(), vo.getPageSize());
        List<FinishShipbillDTO> queryFinishShipbillDTOs = tmsLoadingBillDetailMapper.queryFinishShipbill(vo);

        // 行号
        int id = 1;
        for (FinishShipbillDTO loadingBillDetailModel : queryFinishShipbillDTOs) {
            FinishShipbillDTO finishShipbillDTO = new FinishShipbillDTO();
            BeanUtils.copyProperties(loadingBillDetailModel, finishShipbillDTO);

            finishShipbillDTO.setId(id);
            id++;

            // 收货方位置(经纬度判断)
            if (ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLatitude())) {
                finishShipbillDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
            } else {
                finishShipbillDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
            }
            // 发货方位置(经纬度判断)
            if (ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLatitude())) {
                finishShipbillDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
            } else {
                finishShipbillDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
            }

            StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
            // 目的地
            consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeProvinceName());
            consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeCityName());
            consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeDistrictName());
            finishShipbillDTO.setConsigneeProvinceCityDistrict(consigneeProvinceCityDistrict.toString());
            // 始发地
            StringBuffer shipperProvinceCityDistrict = new StringBuffer();
            shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperProvinceName());
            shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperCityName());
            shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperDistrictName());
            finishShipbillDTO.setShipperProvinceCityDistrict(shipperProvinceCityDistrict.toString());

            if (ObjectUtil.equal(DataDictionaryConstant.LINE_CARRIER_TYPE_SJ, finishShipbillDTO.getCarrierType())) {// 承运方类型为司机时展示司机姓名
                finishShipbillDTO.setCarrierName(finishShipbillDTO.getDriverName());
                finishShipbillDTO.setCarrierPhoneNumber(finishShipbillDTO.getDriverPhoneNumber());
                finishShipbillDTO.setAffiliationName(finishShipbillDTO.getDriverAffiliationName());
            }

            // 类型翻译
            finishShipbillDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(finishShipbillDTO.getOrderType())));
            finishShipbillDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(finishShipbillDTO.getOrderBusinessType())));
            finishShipbillDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(finishShipbillDTO.getDeliveryMethodType())));
            finishShipbillDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(finishShipbillDTO.getTransportType())));
            finishShipbillDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(finishShipbillDTO.getTemperatureRequirement())));
            finishShipbillDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(finishShipbillDTO.getShipperType())));
            finishShipbillDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(finishShipbillDTO.getConsigneeType())));
            // 运单状态
            finishShipbillDTO.setStatusName(PublicMethods.change(data9, String.valueOf(finishShipbillDTO.getStatus())));
            // 运输状态
            finishShipbillDTO.setTransportStatusName(PublicMethods.change(data10, String.valueOf(finishShipbillDTO.getTransportStatus())));
            // 异常状态
            finishShipbillDTO.setAbnormalStatusName(PublicMethods.change(data11, String.valueOf(finishShipbillDTO.getAbnormalStatus())));
            // 扫描状态
            finishShipbillDTO.setScanStatusName(PublicMethods.change(data12, String.valueOf(finishShipbillDTO.getScanStatus())));

            // 获取背景颜色和字体颜色
            Signconfig:
            for (SignconfigPopDTO signconfigPopDTO : data8) {
                // 标记类型匹配
                switch (signconfigPopDTO.getType()) {
                    case DataDictionaryConstant.SIGNCONFIG_TYPE_DDLX: // 订单类型
                        if (ToolKits.isNotEmpty(signconfigPopDTO.getMatching())) {
                            // 判断是否匹配
                            if (PublicMethods.compare(signconfigPopDTO.getMatching(), ToolKits.isNotEmpty(signconfigPopDTO.getStoredValue()) ? signconfigPopDTO.getStoredValue() : "", ToolKits.isNotEmpty(finishShipbillDTO.getOrderTypeName()) ? finishShipbillDTO.getOrderTypeName() : "")) {
                                finishShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
                                finishShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

                                finishShipbillDTO.setSignConfigId(signconfigPopDTO.getId());

                                // 匹配上结束循环
                                break Signconfig;
                            }
                        }
                        break;
                    case DataDictionaryConstant.SIGNCONFIG_TYPE_YWLX: // 业务类型
                        if (ToolKits.isNotEmpty(signconfigPopDTO.getMatching())) {
                            if (PublicMethods.compare(signconfigPopDTO.getMatching(), ToolKits.isNotEmpty(signconfigPopDTO.getStoredValue()) ? signconfigPopDTO.getStoredValue() : "", ToolKits.isNotEmpty(finishShipbillDTO.getOrderBusinessTypeName()) ? finishShipbillDTO.getOrderBusinessTypeName() : "")) {
                                finishShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
                                finishShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

                                finishShipbillDTO.setSignConfigId(signconfigPopDTO.getId());

                                break Signconfig;
                            }
                        }
                        break;
                    case DataDictionaryConstant.SIGNCONFIG_TYPE_WDYQ: // 温度要求
                        if (ToolKits.isNotEmpty(signconfigPopDTO.getMatching())) {
                            if (PublicMethods.compare(signconfigPopDTO.getMatching(), ToolKits.isNotEmpty(signconfigPopDTO.getStoredValue()) ? signconfigPopDTO.getStoredValue() : "", ToolKits.isNotEmpty(finishShipbillDTO.getTemperatureRequirementName()) ? finishShipbillDTO.getTemperatureRequirementName() : "")) {
                                finishShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
                                finishShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

                                finishShipbillDTO.setSignConfigId(signconfigPopDTO.getId());

                                break Signconfig;
                            }
                        }
                        break;
                    case DataDictionaryConstant.SIGNCONFIG_TYPE_PSFS: // 配送方式
                        if (ToolKits.isNotEmpty(signconfigPopDTO.getMatching())) {
                            if (PublicMethods.compare(signconfigPopDTO.getMatching(), ToolKits.isNotEmpty(signconfigPopDTO.getStoredValue()) ? signconfigPopDTO.getStoredValue() : "", ToolKits.isNotEmpty(finishShipbillDTO.getDeliveryMethodTypeName()) ? finishShipbillDTO.getDeliveryMethodTypeName() : "")) {
                                finishShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
                                finishShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

                                finishShipbillDTO.setSignConfigId(signconfigPopDTO.getId());

                                break Signconfig;
                            }
                        }
                        break;
                    case DataDictionaryConstant.SIGNCONFIG_TYPE_DDBZ: // 订单备注
                        if (ToolKits.isNotEmpty(signconfigPopDTO.getMatching())) {
                            if (PublicMethods.compare(signconfigPopDTO.getMatching(), ToolKits.isNotEmpty(signconfigPopDTO.getStoredValue()) ? signconfigPopDTO.getStoredValue() : "", ToolKits.isNotEmpty(finishShipbillDTO.getMemo()) ? finishShipbillDTO.getMemo() : "")) {
                                finishShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
                                finishShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

                                finishShipbillDTO.setSignConfigId(signconfigPopDTO.getId());

                                break Signconfig;
                            }
                        }
                        break;
                }
            }
            // 承运方类型
            finishShipbillDTO.setCarrierTypeName(PublicMethods.change(data13, String.valueOf(loadingBillDetailModel.getCarrierType())));
            // 调度单号
            finishShipbillDTO.setLoadingBillNo(loadingBillDetailModel.getLoadingBillNo());
            // 承运方名称
            // finishShipbillDTO.setCarrierName(loadingBillDetailModel.getCarrierName());
            // 送货员姓名
            finishShipbillDTO.setDeliverymanName(loadingBillDetailModel.getDeliverymanName());
            // 车牌号
            finishShipbillDTO.setVehiclePlateNumber(loadingBillDetailModel.getVehiclePlateNumber());

            pageFinishShipbillDTOs.add(finishShipbillDTO);

        }
        // 分页重组
        Page<FinishShipbillDTO> page = PageUtils.getPage(pageFinishShipbillDTOs);
        if (queryFinishShipbillDTOs instanceof com.github.pagehelper.Page) {
            com.github.pagehelper.Page<FinishShipbillDTO> p0 = (com.github.pagehelper.Page<FinishShipbillDTO>) queryFinishShipbillDTOs;
            page.setPageCount(p0.getPages());
            page.setPageNum(p0.getPageNum());
            page.setPageSize(p0.getPageSize());
            page.setTotalCount(p0.getTotal());
            page.setStartRow(p0.getStartRow());
            page.setEndRow(p0.getEndRow());
        }
        return page;

    }

    /**
     * 完成运单高级查询
     *
     * @param adsQueryVO
     * @return
     */
    @SuppressWarnings("resource")
    public Page<FinishShipbillDTO> pageAdvanced(@RequestBody FinishAdsQueryVO adsQueryVO) {
        ToolKits.isParamNull(adsQueryVO, "完成运单高级查询请求不为空");
        ToolKits.isParamNull(adsQueryVO.getPageNum(), "当前页码不为空");
        ToolKits.isParamNull(adsQueryVO.getPageSize(), "每页条数不为空");

        UserEntity user = PlgFxUsrUtils.getUserEntity();
        ToolKits.isParamNull(user, "当前人员没有操作权限");

        // 数据字典翻译数据集合
        List<Map<String, Object>> data1 = Lists.newArrayList();
        List<Map<String, Object>> data2 = Lists.newArrayList();
        List<Map<String, Object>> data3 = Lists.newArrayList();
        List<Map<String, Object>> data4 = Lists.newArrayList();
        List<Map<String, Object>> data5 = Lists.newArrayList();
        List<Map<String, Object>> data6 = Lists.newArrayList();
        List<Map<String, Object>> data7 = Lists.newArrayList();
        List<SignconfigPopDTO> data8 = Lists.newArrayList();
        List<Map<String, Object>> data9 = Lists.newArrayList();
        List<Map<String, Object>> data10 = Lists.newArrayList();
        List<Map<String, Object>> data11 = Lists.newArrayList();
        List<Map<String, Object>> data12 = Lists.newArrayList();
        List<Map<String, Object>> data13 = Lists.newArrayList();

        // 订单类型
        RestMessage<List<Map<String, Object>>> restMessage1 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_TYPE, null, null, null);
        if (!restMessage1.isSuccess()) {
            throw new RuntimeException("订单类型翻译失败!");
        } else {
            data1 = restMessage1.getData();
        }
        // 订单业务类型
        RestMessage<List<Map<String, Object>>> restMessage2 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_BUSINESS_TYPE, null, null, null);
        if (!restMessage2.isSuccess()) {
            throw new RuntimeException("订单业务类型翻译失败!");
        } else {
            data2 = restMessage2.getData();
        }
        // 配送方式
        RestMessage<List<Map<String, Object>>> restMessage3 = maindataTmsResource.getDropDownById(DataDictionaryConstant.DELIVERY_METHOD_TYPE, null, null, null);
        if (!restMessage3.isSuccess()) {
            throw new RuntimeException("配送方式翻译失败!");
        } else {
            data3 = restMessage3.getData();
        }
        // 运输类型(运输模式)
        RestMessage<List<Map<String, Object>>> restMessage4 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_TYPE, null, null, null);
        if (!restMessage4.isSuccess()) {
            throw new RuntimeException("运输类型(运输模式)翻译失败!");
        } else {
            data4 = restMessage4.getData();
        }
        // 温度要求
        RestMessage<List<Map<String, Object>>> restMessage5 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TEMPERATURE_REQUIREMENT, null, null, null);
        if (!restMessage5.isSuccess()) {
            throw new RuntimeException("温度要求翻译失败!");
        } else {
            data5 = restMessage5.getData();
        }
        // 发货方类型
        RestMessage<List<Map<String, Object>>> restMessage6 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPPER_TYPE, null, null, null);
        if (!restMessage6.isSuccess()) {
            throw new RuntimeException("发货方类型翻译失败!");
        } else {
            data6 = restMessage6.getData();
        }
        // 收货方类型
        RestMessage<List<Map<String, Object>>> restMessage7 = maindataTmsResource.getDropDownById(DataDictionaryConstant.CONSIGNEE_TYPE, null, null, null);
        if (!restMessage7.isSuccess()) {
            throw new RuntimeException("收货方类型翻译失败!");
        } else {
            data7 = restMessage7.getData();
        }
        // 标记配置
        SignconfigPopVO signconfigPopVO = new SignconfigPopVO();
        RestMessage<List<SignconfigPopDTO>> restMessage8 = maindataTmsResource.getSignConfig(signconfigPopVO);
        if (!restMessage8.isSuccess()) {
            throw new RuntimeException("标记配置查询失败!");
        } else {
            data8 = restMessage8.getData();
        }

        // 运单状态
        RestMessage<List<Map<String, Object>>> restMessage9 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPBILL_STATUS, null, null, null);
        if (!restMessage9.isSuccess()) {
            throw new RuntimeException("运单状态翻译失败!");
        } else {
            data9 = restMessage9.getData();
        }
        // 运输状态
        RestMessage<List<Map<String, Object>>> restMessage10 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_STATUS, null, null, null);
        if (!restMessage10.isSuccess()) {
            throw new RuntimeException("运输状态翻译失败!");
        } else {
            data10 = restMessage10.getData();
        }
        // 异常状态
        RestMessage<List<Map<String, Object>>> restMessage11 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ABNORMAL_STATUS, null, null, null);
        if (!restMessage11.isSuccess()) {
            throw new RuntimeException("异常状态翻译失败!");
        } else {
            data11 = restMessage11.getData();
        }
        // 扫描状态
        RestMessage<List<Map<String, Object>>> restMessage12 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SCAN_STATUS, null, null, null);
        if (!restMessage12.isSuccess()) {
            throw new RuntimeException("扫描状态翻译失败!");
        } else {
            data12 = restMessage12.getData();
        }

        // 承运方类型
        RestMessage<List<Map<String, Object>>> restMessage13 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LINE_CARRIER_TYPE, null, null, null);
        if (!restMessage13.isSuccess()) {
            throw new RuntimeException("承运方类型翻译失败!");
        } else {
            data13 = restMessage13.getData();
        }
        if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY)) {
            // 自有账号
            adsQueryVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_REVIEW);
            adsQueryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
            if (BussinessConstant.USER_DEPARTMENT_AUTH_Y.equals(user.getOwnedAllDataAuthFlag())) {
                adsQueryVO.setIsDept("YES");
            } else {
                adsQueryVO.setIsDept("NO");
                // 其它权限
                // 货主
                adsQueryVO.setConsignors(user.getConsignors().stream().toArray(Long[]::new));
                // 客户
                adsQueryVO.setCustomers(user.getCustomers().stream().toArray(Long[]::new));
                // 供应商
                adsQueryVO.setSuppliers(user.getSuppliers().stream().toArray(Long[]::new));
                // 仓库
                adsQueryVO.setWsarehouses(user.getWarehouses().stream().toArray(Long[]::new));
            }
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_CYS)) {// 承运商账号
            // 承运商账号 单位ID
            adsQueryVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_HZ)) {// 货主账号
            adsQueryVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_GYS)) {// 供应商账号
            adsQueryVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_KH)) {// 客户账号
            adsQueryVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
        } else {
            throw new PrologException("当前人员没有操作权限！");
        }
        // 获取高级查询配置
        String conditions = null;
        RestMessage<String> restMessageAdvancedCfg = maindataTmsResource.getQueryConfiguration(DataDictionaryConstant.BIZ_TYPE_FINISH);
        if (!restMessageAdvancedCfg.isSuccess()) {
            // throw new RuntimeException("订单类型翻译失败!");
        } else {
            conditions = restMessageAdvancedCfg.getData();
        }
        adsQueryVO.setSql(conditions);
        List<FinishShipbillDTO> pageFinishShipbillDTOs = Lists.newArrayList();
        adsQueryVO.setEnterpriseId(user.getEnterpriseId());

        PageUtils.startPage(adsQueryVO.getPageNum(), adsQueryVO.getPageSize());
        List<FinishShipbillDTO> queryFinishShipbillDTOs = tmsLoadingBillDetailMapper.finishAdvancedQuery(adsQueryVO);

        // 行号
        int id = 1;
        for (FinishShipbillDTO loadingBillDetailModel : queryFinishShipbillDTOs) {
            FinishShipbillDTO finishShipbillDTO = new FinishShipbillDTO();
            BeanUtils.copyProperties(loadingBillDetailModel, finishShipbillDTO);

            finishShipbillDTO.setId(id);
            id++;

            // 收货方位置(经纬度判断)
            if (ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLatitude())) {
                finishShipbillDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
            } else {
                finishShipbillDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
            }
            // 发货方位置(经纬度判断)
            if (ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLatitude())) {
                finishShipbillDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
            } else {
                finishShipbillDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
            }

            StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
            // 目的地
            consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeProvinceName());
            consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeCityName());
            consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeDistrictName());
            finishShipbillDTO.setConsigneeProvinceCityDistrict(consigneeProvinceCityDistrict.toString());
            // 始发地
            StringBuffer shipperProvinceCityDistrict = new StringBuffer();
            shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperProvinceName());
            shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperCityName());
            shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperDistrictName());
            finishShipbillDTO.setShipperProvinceCityDistrict(shipperProvinceCityDistrict.toString());

            // 类型翻译
            finishShipbillDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(finishShipbillDTO.getOrderType())));
            finishShipbillDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(finishShipbillDTO.getOrderBusinessType())));
            finishShipbillDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(finishShipbillDTO.getDeliveryMethodType())));
            finishShipbillDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(finishShipbillDTO.getTransportType())));
            finishShipbillDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(finishShipbillDTO.getTemperatureRequirement())));
            finishShipbillDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(finishShipbillDTO.getShipperType())));
            finishShipbillDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(finishShipbillDTO.getConsigneeType())));
            // 运单状态
            finishShipbillDTO.setStatusName(PublicMethods.change(data9, String.valueOf(finishShipbillDTO.getStatus())));
            // 运输状态
            finishShipbillDTO.setTransportStatusName(PublicMethods.change(data10, String.valueOf(finishShipbillDTO.getTransportStatus())));
            // 异常状态
            finishShipbillDTO.setAbnormalStatusName(PublicMethods.change(data11, String.valueOf(finishShipbillDTO.getAbnormalStatus())));
            // 扫描状态
            finishShipbillDTO.setScanStatusName(PublicMethods.change(data12, String.valueOf(finishShipbillDTO.getScanStatus())));

            // 获取背景颜色和字体颜色
            Signconfig:
            for (SignconfigPopDTO signconfigPopDTO : data8) {
                // 标记类型匹配
                switch (signconfigPopDTO.getType()) {
                    case DataDictionaryConstant.SIGNCONFIG_TYPE_DDLX: // 订单类型
                        if (ToolKits.isNotEmpty(signconfigPopDTO.getMatching())) {
                            // 判断是否匹配
                            if (PublicMethods.compare(signconfigPopDTO.getMatching(), ToolKits.isNotEmpty(signconfigPopDTO.getStoredValue()) ? signconfigPopDTO.getStoredValue() : "", ToolKits.isNotEmpty(finishShipbillDTO.getOrderTypeName()) ? finishShipbillDTO.getOrderTypeName() : "")) {
                                finishShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
                                finishShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

                                finishShipbillDTO.setSignConfigId(signconfigPopDTO.getId());

                                // 匹配上结束循环
                                break Signconfig;
                            }
                        }
                        break;
                    case DataDictionaryConstant.SIGNCONFIG_TYPE_YWLX: // 业务类型
                        if (ToolKits.isNotEmpty(signconfigPopDTO.getMatching())) {
                            if (PublicMethods.compare(signconfigPopDTO.getMatching(), ToolKits.isNotEmpty(signconfigPopDTO.getStoredValue()) ? signconfigPopDTO.getStoredValue() : "", ToolKits.isNotEmpty(finishShipbillDTO.getOrderBusinessTypeName()) ? finishShipbillDTO.getOrderBusinessTypeName() : "")) {
                                finishShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
                                finishShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

                                finishShipbillDTO.setSignConfigId(signconfigPopDTO.getId());

                                break Signconfig;
                            }
                        }
                        break;
                    case DataDictionaryConstant.SIGNCONFIG_TYPE_WDYQ: // 温度要求
                        if (ToolKits.isNotEmpty(signconfigPopDTO.getMatching())) {
                            if (PublicMethods.compare(signconfigPopDTO.getMatching(), ToolKits.isNotEmpty(signconfigPopDTO.getStoredValue()) ? signconfigPopDTO.getStoredValue() : "", ToolKits.isNotEmpty(finishShipbillDTO.getTemperatureRequirementName()) ? finishShipbillDTO.getTemperatureRequirementName() : "")) {
                                finishShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
                                finishShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

                                finishShipbillDTO.setSignConfigId(signconfigPopDTO.getId());

                                break Signconfig;
                            }
                        }
                        break;
                    case DataDictionaryConstant.SIGNCONFIG_TYPE_PSFS: // 配送方式
                        if (ToolKits.isNotEmpty(signconfigPopDTO.getMatching())) {
                            if (PublicMethods.compare(signconfigPopDTO.getMatching(), ToolKits.isNotEmpty(signconfigPopDTO.getStoredValue()) ? signconfigPopDTO.getStoredValue() : "", ToolKits.isNotEmpty(finishShipbillDTO.getDeliveryMethodTypeName()) ? finishShipbillDTO.getDeliveryMethodTypeName() : "")) {
                                finishShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
                                finishShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

                                finishShipbillDTO.setSignConfigId(signconfigPopDTO.getId());

                                break Signconfig;
                            }
                        }
                        break;
                    case DataDictionaryConstant.SIGNCONFIG_TYPE_DDBZ: // 订单备注
                        if (ToolKits.isNotEmpty(signconfigPopDTO.getMatching())) {
                            if (PublicMethods.compare(signconfigPopDTO.getMatching(), ToolKits.isNotEmpty(signconfigPopDTO.getStoredValue()) ? signconfigPopDTO.getStoredValue() : "", ToolKits.isNotEmpty(finishShipbillDTO.getMemo()) ? finishShipbillDTO.getMemo() : "")) {
                                finishShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
                                finishShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

                                finishShipbillDTO.setSignConfigId(signconfigPopDTO.getId());

                                break Signconfig;
                            }
                        }
                        break;
                }
            }
            // 承运方类型
            finishShipbillDTO.setScanStatusName(PublicMethods.change(data13, String.valueOf(loadingBillDetailModel.getCarrierType())));
            // 调度单号
            finishShipbillDTO.setLoadingBillNo(loadingBillDetailModel.getLoadingBillNo());
            // 承运方名称
            // finishShipbillDTO.setCarrierName(loadingBillDetailModel.getCarrierName());
            // 送货员姓名
            finishShipbillDTO.setDeliverymanName(loadingBillDetailModel.getDeliverymanName());
            // 车牌号
            finishShipbillDTO.setVehiclePlateNumber(loadingBillDetailModel.getVehiclePlateNumber());

            pageFinishShipbillDTOs.add(finishShipbillDTO);

        }
        // 分页重组
        Page<FinishShipbillDTO> page = PageUtils.getPage(pageFinishShipbillDTOs);
        if (queryFinishShipbillDTOs instanceof com.github.pagehelper.Page) {
            com.github.pagehelper.Page<FinishShipbillDTO> p0 = (com.github.pagehelper.Page<FinishShipbillDTO>) queryFinishShipbillDTOs;
            page.setPageCount(p0.getPages());
            page.setPageNum(p0.getPageNum());
            page.setPageSize(p0.getPageSize());
            page.setTotalCount(p0.getTotal());
            page.setStartRow(p0.getStartRow());
            page.setEndRow(p0.getEndRow());
        }
        return page;
    }

    /**
     * 完成运单商品查询
     *
     * @param vo
     * @return
     */
    @SuppressWarnings("resource")
    @Override
    public Page<FinishShipBillDetailDTO> queryFinishShipbillDetail(FinishShipbillDetailVO vo) {
        ToolKits.isParamNull(vo, "商品查询请求不为空");
        ToolKits.isParamNull(vo.getPageNum(), "当前页码不为空");
        ToolKits.isParamNull(vo.getPageSize(), "每页条数不为空");

        UserEntity user = PlgFxUsrUtils.getUserEntity();
        ToolKits.isParamNull(user, "当前人员没有操作权限");

        // 数据字典翻译数据集合
        List<Map<String, Object>> data1 = Lists.newArrayList();
        List<Map<String, Object>> data2 = Lists.newArrayList();

        // 包装类型
        RestMessage<List<Map<String, Object>>> restMessage1 = maindataTmsResource.getDropDownById(DataDictionaryConstant.PACK_TYPE, null, null, null);
        if (!restMessage1.isSuccess()) {
            throw new RuntimeException("包装类型翻译失败!");
        } else {
            data1 = restMessage1.getData();
        }
        // 货物温层
        RestMessage<List<Map<String, Object>>> restMessage2 = maindataTmsResource.getDropDownById(DataDictionaryConstant.CARGO_THERMOSPHERE, null, null, null);
        if (!restMessage2.isSuccess()) {
            throw new RuntimeException("货物温层翻译失败!");
        } else {
            data2 = restMessage2.getData();
        }

        // 获取商品信息
        Criteria criteria = Criteria.forClass(TmsShipbillDetailModel.class);
        Restriction r1 = Restrictions.eq("shipbillId", vo.getShipbillId());
        Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
        criteria.setRestriction(Restrictions.and(r1, r2));
        criteria.setOrder(Order.newInstance().desc(new String[]{"updatetime"}));

        PageUtils.startPage(vo.getPageNum(), vo.getPageSize());
        List<TmsShipbillDetailModel> tmsShipbillDetailModels = tmsShipbillDetailMapper.findByCriteria(criteria);

        // 响应对象集合
        List<FinishShipBillDetailDTO> pageFinishShipBillDetailDTOs = new ArrayList<>();

        if (ToolKits.isNotEmpty(tmsShipbillDetailModels)) {
            for (TmsShipbillDetailModel tmsShipbillDetailModel : tmsShipbillDetailModels) {
                // 响应对象
                FinishShipBillDetailDTO finishShipBillDetailDTO = new FinishShipBillDetailDTO();
                BeanUtils.copyProperties(tmsShipbillDetailModel, finishShipBillDetailDTO);
                finishShipBillDetailDTO.setPackTypeName(PublicMethods.change(data1, String.valueOf(finishShipBillDetailDTO.getPackType())));
                finishShipBillDetailDTO.setCargoThermosphereName(PublicMethods.change(data2, String.valueOf(finishShipBillDetailDTO.getCargoThermosphere())));

                finishShipBillDetailDTO.setDeliveryPcs(ToolKits.isEmpty(tmsShipbillDetailModel.getDeliveryPcs())? BigDecimal.ZERO:tmsShipbillDetailModel.getDeliveryPcs());
                finishShipBillDetailDTO.setDeliveryWeight(NumberUtil.mul(finishShipBillDetailDTO.getDeliveryPcs(), tmsShipbillDetailModel.getUnitWeight()));
                finishShipBillDetailDTO.setDeliveryVolume(NumberUtil.mul(finishShipBillDetailDTO.getDeliveryPcs(), tmsShipbillDetailModel.getUnitVolume()));
                finishShipBillDetailDTO.setWeight(NumberUtil.mul(finishShipBillDetailDTO.getPcs(), tmsShipbillDetailModel.getUnitWeight()));
                finishShipBillDetailDTO.setVolume(NumberUtil.mul(finishShipBillDetailDTO.getPcs(), tmsShipbillDetailModel.getUnitVolume()));
                pageFinishShipBillDetailDTOs.add(finishShipBillDetailDTO);
            }
        }

        // 分页重组
        Page<FinishShipBillDetailDTO> page = PageUtils.getPage(pageFinishShipBillDetailDTOs);
        if (tmsShipbillDetailModels instanceof com.github.pagehelper.Page) {
            com.github.pagehelper.Page<TmsShipbillDetailModel> p0 = (com.github.pagehelper.Page<TmsShipbillDetailModel>) tmsShipbillDetailModels;
            page.setPageCount(p0.getPages());
            page.setPageNum(p0.getPageNum());
            page.setPageSize(p0.getPageSize());
            page.setTotalCount(p0.getTotal());
            page.setStartRow(p0.getStartRow());
            page.setEndRow(p0.getEndRow());
        }
        return page;
    }

    /**
     * 完成运单包裹查询
     *
     * @param vo
     * @return
     */
    @SuppressWarnings("resource")
    @Override
    public Page<FinishShipbillPackageDTO> queryFinishShipbillPackage(FinishShipbillDetailVO vo) {
        ToolKits.isParamNull(vo, "包裹查询请求不为空");
        ToolKits.isParamNull(vo.getPageNum(), "当前页码不为空");
        ToolKits.isParamNull(vo.getPageSize(), "每页条数不为空");

        UserEntity user = PlgFxUsrUtils.getUserEntity();
        ToolKits.isParamNull(user, "当前人员没有操作权限");

        // 数据字典翻译数据集合
        List<Map<String, Object>> data1 = Lists.newArrayList();
        List<Map<String, Object>> data2 = Lists.newArrayList();

        // 包裹类型
        RestMessage<List<Map<String, Object>>> restMessage1 = maindataTmsResource.getDropDownById(DataDictionaryConstant.PACKAGE_TYPE, null, null, null);
        if (!restMessage1.isSuccess()) {
            throw new RuntimeException("包裹类型翻译失败!");
        } else {
            data1 = restMessage1.getData();
        }

        // 设备类型
        RestMessage<List<Map<String, Object>>> restMessage2 = maindataTmsResource.getDropDownById(DataDictionaryConstant.DEVICE_COMPANY, null, null, null);
        if (!restMessage2.isSuccess()) {
            throw new RuntimeException("设备类型翻译失败!");
        } else {
            data2 = restMessage2.getData();
        }

        // 添加查询条件
        Criteria criteria = Criteria.forClass(TmsShipbillPackageModel.class);
        Restriction r1 = Restrictions.eq("shipbillId", vo.getShipbillId());
        Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
        criteria.setRestriction(Restrictions.and(r1, r2));
        criteria.setOrder(Order.newInstance().desc(new String[]{"updatetime"}));
        List<TmsShipbillPackageModel> tmsShipbillPackageModels = tmsShipbillPackageMapper.findByCriteria(criteria);

        // 响应对象集合
        List<FinishShipbillPackageDTO> pageFinishShipbillPackageDTOs = new ArrayList<>();

        if (ToolKits.isNotEmpty(tmsShipbillPackageModels)) {
            for (TmsShipbillPackageModel tmsShipbillPackageModel : tmsShipbillPackageModels) {
                // 响应对象
                FinishShipbillPackageDTO finishShipbillPackageDTO = new FinishShipbillPackageDTO();
                BeanUtils.copyProperties(tmsShipbillPackageModel, finishShipbillPackageDTO);
                finishShipbillPackageDTO.setPackageTypeName(PublicMethods.change(data1, String.valueOf(finishShipbillPackageDTO.getPackageType())));
                finishShipbillPackageDTO.setDeviceCompanyName(PublicMethods.change(data2, String.valueOf(finishShipbillPackageDTO.getDeviceCompany())));

                pageFinishShipbillPackageDTOs.add(finishShipbillPackageDTO);
            }
        }
        // 分页重组
        Page<FinishShipbillPackageDTO> page = PageUtils.getPage(pageFinishShipbillPackageDTOs);
        if (tmsShipbillPackageModels instanceof com.github.pagehelper.Page) {
            com.github.pagehelper.Page<TmsShipbillPackageModel> p0 = (com.github.pagehelper.Page<TmsShipbillPackageModel>) tmsShipbillPackageModels;
            page.setPageCount(p0.getPages());
            page.setPageNum(p0.getPageNum());
            page.setPageSize(p0.getPageSize());
            page.setTotalCount(p0.getTotal());
            page.setStartRow(p0.getStartRow());
            page.setEndRow(p0.getEndRow());
        }
        return page;
    }

    /**
     * 导出所有数据
     *
     * @param vo
     * @return
     */
    @Override
    public List<ExportFinishShipbillDTO> exportAllShipbill(FinishShipbillQueryVO vo) {

        ToolKits.isParamNull(vo, "导出所有数据请求不为空");

        UserEntity user = PlgFxUsrUtils.getUserEntity();
        ToolKits.isParamNull(user, "当前人员没有操作权限");

        // 数据字典翻译数据集合
        List<Map<String, Object>> data1 = Lists.newArrayList();
        List<Map<String, Object>> data2 = Lists.newArrayList();
        List<Map<String, Object>> data3 = Lists.newArrayList();
        List<Map<String, Object>> data4 = Lists.newArrayList();
        List<Map<String, Object>> data5 = Lists.newArrayList();
        List<Map<String, Object>> data6 = Lists.newArrayList();
        List<Map<String, Object>> data7 = Lists.newArrayList();
        List<Map<String, Object>> data9 = Lists.newArrayList();
        List<Map<String, Object>> data10 = Lists.newArrayList();
        List<Map<String, Object>> data11 = Lists.newArrayList();
        List<Map<String, Object>> data12 = Lists.newArrayList();
        List<Map<String, Object>> data13 = Lists.newArrayList();

        // 订单类型
        RestMessage<List<Map<String, Object>>> restMessage1 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_TYPE, null, null, null);
        if (!restMessage1.isSuccess()) {
            throw new RuntimeException("订单类型翻译失败!");
        } else {
            data1 = restMessage1.getData();
        }
        // 订单业务类型
        RestMessage<List<Map<String, Object>>> restMessage2 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_BUSINESS_TYPE, null, null, null);
        if (!restMessage2.isSuccess()) {
            throw new RuntimeException("订单业务类型翻译失败!");
        } else {
            data2 = restMessage2.getData();
        }
        // 配送方式
        RestMessage<List<Map<String, Object>>> restMessage3 = maindataTmsResource.getDropDownById(DataDictionaryConstant.DELIVERY_METHOD_TYPE, null, null, null);
        if (!restMessage3.isSuccess()) {
            throw new RuntimeException("配送方式翻译失败!");
        } else {
            data3 = restMessage3.getData();
        }
        // 运输类型(运输模式)
        RestMessage<List<Map<String, Object>>> restMessage4 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_TYPE, null, null, null);
        if (!restMessage4.isSuccess()) {
            throw new RuntimeException("运输类型(运输模式)翻译失败!");
        } else {
            data4 = restMessage4.getData();
        }
        // 温度要求
        RestMessage<List<Map<String, Object>>> restMessage5 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TEMPERATURE_REQUIREMENT, null, null, null);
        if (!restMessage5.isSuccess()) {
            throw new RuntimeException("温度要求翻译失败!");
        } else {
            data5 = restMessage5.getData();
        }
        // 发货方类型
        RestMessage<List<Map<String, Object>>> restMessage6 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPPER_TYPE, null, null, null);
        if (!restMessage6.isSuccess()) {
            throw new RuntimeException("发货方类型翻译失败!");
        } else {
            data6 = restMessage6.getData();
        }
        // 收货方类型
        RestMessage<List<Map<String, Object>>> restMessage7 = maindataTmsResource.getDropDownById(DataDictionaryConstant.CONSIGNEE_TYPE, null, null, null);
        if (!restMessage7.isSuccess()) {
            throw new RuntimeException("收货方类型翻译失败!");
        } else {
            data7 = restMessage7.getData();
        }

        // 运单状态
        RestMessage<List<Map<String, Object>>> restMessage9 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPBILL_STATUS, null, null, null);
        if (!restMessage9.isSuccess()) {
            throw new RuntimeException("运单状态翻译失败!");
        } else {
            data9 = restMessage9.getData();
        }
        // 运输状态
        RestMessage<List<Map<String, Object>>> restMessage10 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_STATUS, null, null, null);
        if (!restMessage10.isSuccess()) {
            throw new RuntimeException("运输状态翻译失败!");
        } else {
            data10 = restMessage10.getData();
        }
        // 异常状态
        RestMessage<List<Map<String, Object>>> restMessage11 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ABNORMAL_STATUS, null, null, null);
        if (!restMessage11.isSuccess()) {
            throw new RuntimeException("异常状态翻译失败!");
        } else {
            data11 = restMessage11.getData();
        }
        // 扫描状态
        RestMessage<List<Map<String, Object>>> restMessage12 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SCAN_STATUS, null, null, null);
        if (!restMessage12.isSuccess()) {
            throw new RuntimeException("扫描状态翻译失败!");
        } else {
            data12 = restMessage12.getData();
        }

        // 承运方类型
        RestMessage<List<Map<String, Object>>> restMessage13 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LINE_CARRIER_TYPE, null, null, null);
        if (!restMessage13.isSuccess()) {
            throw new RuntimeException("承运方类型翻译失败!");
        } else {
            data13 = restMessage13.getData();
        }

        if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
            // 判断是否为部门权限
            if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
                vo.setDepartmentIds(user.getDepts().stream().toArray(String[]::new));
            } else {
                vo.setDepartmentIds(user.getDepts().stream().toArray(String[]::new));
                vo.setCargoOwnerIds(user.getConsignors().stream().toArray(Long[]::new));

                StringBuffer sqlBuff = new StringBuffer();
                if (ToolKits.isNotEmpty(user.getWarehouses())) {
                    sqlBuff.append(" t2.consignee_unit_id in (" + user.getWarehouses().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                    sqlBuff.append(" or t2.shipper_unit_id in (" + user.getWarehouses().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                }
                if (ToolKits.isNotEmpty(user.getSuppliers())) {
                    if (sqlBuff.toString().length() > 0) {
                        sqlBuff.append(" or t2.consignee_unit_id in (" + user.getSuppliers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                    } else {
                        sqlBuff.append(" t2.consignee_unit_id in (" + user.getSuppliers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                    }
                    sqlBuff.append(" or t2.shipper_unit_id in (" + user.getSuppliers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                }
                if (ToolKits.isNotEmpty(user.getCustomers())) {
                    if (sqlBuff.toString().length() > 0) {
                        sqlBuff.append(" or t2.consignee_unit_id in (" + user.getCustomers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                    } else {
                        sqlBuff.append(" t2.consignee_unit_id in (" + user.getCustomers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                    }
                    sqlBuff.append(" or t2.shipper_unit_id in (" + user.getCustomers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                }
                if (sqlBuff.toString().length() > 0) {
                    vo.setSqlBuff("( " + sqlBuff.toString() + " )");
                }
            }
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_CYS)) {// 承运商账号
            vo.setScheduleType(DataDictionaryConstant.SCHEDULE_TYPE_CYS);
            vo.setCarrierId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
            vo.setCarrierShipbillStatus(DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_DISPATCHED_CHECK);
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_HZ)) {// 货主账号
            vo.setCargoOwnerUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_GYS)) {// 供应商账号
            vo.setSupplierUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_KH)) {// 客户账号
            vo.setCustomerUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
        }
        List<ExportFinishShipbillDTO> rsExportFinishShipbillDTOs = Lists.newArrayList();
        vo.setEnterpriseId(user.getEnterpriseId());
        List<FinishShipbillDTO> queryFinishShipbillDTOs = tmsLoadingBillDetailMapper.queryFinishShipbill(vo);

        for (FinishShipbillDTO loadingBillDetailModel : queryFinishShipbillDTOs) {
            ExportFinishShipbillDTO finishShipbillDTO = new ExportFinishShipbillDTO();
            BeanUtils.copyProperties(loadingBillDetailModel, finishShipbillDTO);
            // 收货方位置(经纬度判断)
            if (ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLatitude())) {
                finishShipbillDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
            } else {
                finishShipbillDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
            }
            // 发货方位置(经纬度判断)
            if (ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLatitude())) {
                finishShipbillDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
            } else {
                finishShipbillDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
            }

            StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
            // 目的地
            consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeProvinceName());
            consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeCityName());
            consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeDistrictName());
            finishShipbillDTO.setConsigneeProvinceCity(consigneeProvinceCityDistrict.toString());
            // 始发地
            StringBuffer shipperProvinceCityDistrict = new StringBuffer();
            shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperProvinceName());
            shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperCityName());
            shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperDistrictName());
            finishShipbillDTO.setShipperProvinceCity(shipperProvinceCityDistrict.toString());

            if (ObjectUtil.equal(DataDictionaryConstant.LINE_CARRIER_TYPE_SJ, loadingBillDetailModel.getCarrierType())) {// 承运方类型为司机时展示司机姓名
                finishShipbillDTO.setCarrierName(loadingBillDetailModel.getDriverName());
                finishShipbillDTO.setCarrierPhoneNumber(loadingBillDetailModel.getDriverPhoneNumber());
            }

            // 类型翻译
            finishShipbillDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(loadingBillDetailModel.getOrderType())));
            finishShipbillDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(loadingBillDetailModel.getOrderBusinessType())));
            finishShipbillDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(loadingBillDetailModel.getDeliveryMethodType())));
            finishShipbillDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(loadingBillDetailModel.getTransportType())));
            finishShipbillDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(loadingBillDetailModel.getTemperatureRequirement())));
            finishShipbillDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(loadingBillDetailModel.getShipperType())));
            finishShipbillDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(loadingBillDetailModel.getConsigneeType())));
            // 运单状态
            finishShipbillDTO.setStatusName(PublicMethods.change(data9, String.valueOf(loadingBillDetailModel.getStatus())));
            // 运输状态
            finishShipbillDTO.setTransportStatusName(PublicMethods.change(data10, String.valueOf(loadingBillDetailModel.getTransportStatus())));
            // 异常状态
            finishShipbillDTO.setAbnormalStatusName(PublicMethods.change(data11, String.valueOf(loadingBillDetailModel.getAbnormalStatus())));
            // 扫描状态
            finishShipbillDTO.setScanStatusName(PublicMethods.change(data12, String.valueOf(loadingBillDetailModel.getScanStatus())));

            // 承运方类型
            finishShipbillDTO.setCarrierTypeName(PublicMethods.change(data13, String.valueOf(loadingBillDetailModel.getCarrierType())));
            // 调度单号
            finishShipbillDTO.setLoadingBillNo(loadingBillDetailModel.getLoadingBillNo());
            // 承运方名称
            // finishShipbillDTO.setCarrierName(loadingBillDetailModel.getCarrierName());
            // 送货员姓名
            finishShipbillDTO.setDeliverymanName(loadingBillDetailModel.getDeliverymanName());
            // 车牌号
            finishShipbillDTO.setVehiclePlateNumber(loadingBillDetailModel.getVehiclePlateNumber());
            rsExportFinishShipbillDTOs.add(finishShipbillDTO);
        }
        return rsExportFinishShipbillDTOs;
    }

    /**
     * 导出当前页数据
     *
     * @param vo
     * @return
     */
    @SuppressWarnings("resource")
    public List<ExportFinishShipbillDTO> exportCurrentPageShipbill(FinishShipbillQueryVO vo) {
        ToolKits.isParamNull(vo, "导出当前页数据请求不为空");
        ToolKits.isParamNull(vo.getPageNum(), "当前页码不为空");
        ToolKits.isParamNull(vo.getPageSize(), "每页条数不为空");

        UserEntity user = PlgFxUsrUtils.getUserEntity();
        ToolKits.isParamNull(user, "当前人员没有操作权限");

        // 数据字典翻译数据集合
        List<Map<String, Object>> data1 = Lists.newArrayList();
        List<Map<String, Object>> data2 = Lists.newArrayList();
        List<Map<String, Object>> data3 = Lists.newArrayList();
        List<Map<String, Object>> data4 = Lists.newArrayList();
        List<Map<String, Object>> data5 = Lists.newArrayList();
        List<Map<String, Object>> data6 = Lists.newArrayList();
        List<Map<String, Object>> data7 = Lists.newArrayList();
        List<Map<String, Object>> data9 = Lists.newArrayList();
        List<Map<String, Object>> data10 = Lists.newArrayList();
        List<Map<String, Object>> data11 = Lists.newArrayList();
        List<Map<String, Object>> data12 = Lists.newArrayList();
        List<Map<String, Object>> data13 = Lists.newArrayList();

        // 订单类型
        RestMessage<List<Map<String, Object>>> restMessage1 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_TYPE, null, null, null);
        if (!restMessage1.isSuccess()) {
            throw new RuntimeException("订单类型翻译失败!");
        } else {
            data1 = restMessage1.getData();
        }
        // 订单业务类型
        RestMessage<List<Map<String, Object>>> restMessage2 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_BUSINESS_TYPE, null, null, null);
        if (!restMessage2.isSuccess()) {
            throw new RuntimeException("订单业务类型翻译失败!");
        } else {
            data2 = restMessage2.getData();
        }
        // 配送方式
        RestMessage<List<Map<String, Object>>> restMessage3 = maindataTmsResource.getDropDownById(DataDictionaryConstant.DELIVERY_METHOD_TYPE, null, null, null);
        if (!restMessage3.isSuccess()) {
            throw new RuntimeException("配送方式翻译失败!");
        } else {
            data3 = restMessage3.getData();
        }
        // 运输类型(运输模式)
        RestMessage<List<Map<String, Object>>> restMessage4 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_TYPE, null, null, null);
        if (!restMessage4.isSuccess()) {
            throw new RuntimeException("运输类型(运输模式)翻译失败!");
        } else {
            data4 = restMessage4.getData();
        }
        // 温度要求
        RestMessage<List<Map<String, Object>>> restMessage5 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TEMPERATURE_REQUIREMENT, null, null, null);
        if (!restMessage5.isSuccess()) {
            throw new RuntimeException("温度要求翻译失败!");
        } else {
            data5 = restMessage5.getData();
        }
        // 发货方类型
        RestMessage<List<Map<String, Object>>> restMessage6 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPPER_TYPE, null, null, null);
        if (!restMessage6.isSuccess()) {
            throw new RuntimeException("发货方类型翻译失败!");
        } else {
            data6 = restMessage6.getData();
        }
        // 收货方类型
        RestMessage<List<Map<String, Object>>> restMessage7 = maindataTmsResource.getDropDownById(DataDictionaryConstant.CONSIGNEE_TYPE, null, null, null);
        if (!restMessage7.isSuccess()) {
            throw new RuntimeException("收货方类型翻译失败!");
        } else {
            data7 = restMessage7.getData();
        }

        // 运单状态
        RestMessage<List<Map<String, Object>>> restMessage9 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPBILL_STATUS, null, null, null);
        if (!restMessage9.isSuccess()) {
            throw new RuntimeException("运单状态翻译失败!");
        } else {
            data9 = restMessage9.getData();
        }
        // 运输状态
        RestMessage<List<Map<String, Object>>> restMessage10 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_STATUS, null, null, null);
        if (!restMessage10.isSuccess()) {
            throw new RuntimeException("运输状态翻译失败!");
        } else {
            data10 = restMessage10.getData();
        }
        // 异常状态
        RestMessage<List<Map<String, Object>>> restMessage11 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ABNORMAL_STATUS, null, null, null);
        if (!restMessage11.isSuccess()) {
            throw new RuntimeException("异常状态翻译失败!");
        } else {
            data11 = restMessage11.getData();
        }
        // 扫描状态
        RestMessage<List<Map<String, Object>>> restMessage12 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SCAN_STATUS, null, null, null);
        if (!restMessage12.isSuccess()) {
            throw new RuntimeException("扫描状态翻译失败!");
        } else {
            data12 = restMessage12.getData();
        }

        // 承运方类型
        RestMessage<List<Map<String, Object>>> restMessage13 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LINE_CARRIER_TYPE, null, null, null);
        if (!restMessage13.isSuccess()) {
            throw new RuntimeException("承运方类型翻译失败!");
        } else {
            data13 = restMessage13.getData();
        }

        if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
            // 判断是否为部门权限
            if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
                vo.setDepartmentIds(user.getDepts().stream().toArray(String[]::new));
            } else {
                vo.setDepartmentIds(user.getDepts().stream().toArray(String[]::new));
                vo.setCargoOwnerIds(user.getConsignors().stream().toArray(Long[]::new));

                StringBuffer sqlBuff = new StringBuffer();
                if (ToolKits.isNotEmpty(user.getWarehouses())) {
                    sqlBuff.append(" t2.consignee_unit_id in (" + user.getWarehouses().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                    sqlBuff.append(" or t2.shipper_unit_id in (" + user.getWarehouses().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                }
                if (ToolKits.isNotEmpty(user.getSuppliers())) {
                    if (sqlBuff.toString().length() > 0) {
                        sqlBuff.append(" or t2.consignee_unit_id in (" + user.getSuppliers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                    } else {
                        sqlBuff.append(" t2.consignee_unit_id in (" + user.getSuppliers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                    }
                    sqlBuff.append(" or t2.shipper_unit_id in (" + user.getSuppliers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                }
                if (ToolKits.isNotEmpty(user.getCustomers())) {
                    if (sqlBuff.toString().length() > 0) {
                        sqlBuff.append(" or t2.consignee_unit_id in (" + user.getCustomers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                    } else {
                        sqlBuff.append(" t2.consignee_unit_id in (" + user.getCustomers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                    }
                    sqlBuff.append(" or t2.shipper_unit_id in (" + user.getCustomers().stream().map(l -> String.valueOf(l)).collect(Collectors.joining(",")) + ")");
                }
                if (sqlBuff.toString().length() > 0) {
                    vo.setSqlBuff("( " + sqlBuff.toString() + " )");
                }
            }
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_CYS)) {// 承运商账号
            vo.setScheduleType(DataDictionaryConstant.SCHEDULE_TYPE_CYS);
            vo.setCarrierId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
            vo.setCarrierShipbillStatus(DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_DISPATCHED_CHECK);
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_HZ)) {// 货主账号
            vo.setCargoOwnerUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_GYS)) {// 供应商账号
            vo.setSupplierUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
        } else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_KH)) {// 客户账号
            vo.setCustomerUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
        }
        List<ExportFinishShipbillDTO> rsExportFinishShipbillDTOs = Lists.newArrayList();
        vo.setEnterpriseId(user.getEnterpriseId());

        PageUtils.startPage(vo.getPageNum(), vo.getPageSize());
        List<FinishShipbillDTO> queryFinishShipbillDTOs = tmsLoadingBillDetailMapper.queryFinishShipbill(vo);

        for (FinishShipbillDTO loadingBillDetailModel : queryFinishShipbillDTOs) {
            ExportFinishShipbillDTO finishShipbillDTO = new ExportFinishShipbillDTO();
            BeanUtils.copyProperties(loadingBillDetailModel, finishShipbillDTO);
            // 收货方位置(经纬度判断)
            if (ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLatitude())) {
                finishShipbillDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
            } else {
                finishShipbillDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
            }
            // 发货方位置(经纬度判断)
            if (ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLatitude())) {
                finishShipbillDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
            } else {
                finishShipbillDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
            }

            StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
            // 目的地
            consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeProvinceName());
            consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeCityName());
            consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeDistrictName());
            finishShipbillDTO.setConsigneeProvinceCity(consigneeProvinceCityDistrict.toString());
            // 始发地
            StringBuffer shipperProvinceCityDistrict = new StringBuffer();
            shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperProvinceName());
            shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperCityName());
            shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperDistrictName());
            finishShipbillDTO.setShipperProvinceCity(shipperProvinceCityDistrict.toString());

            if (ObjectUtil.equal(DataDictionaryConstant.LINE_CARRIER_TYPE_SJ, loadingBillDetailModel.getCarrierType())) {// 承运方类型为司机时展示司机姓名
                finishShipbillDTO.setCarrierName(loadingBillDetailModel.getDriverName());
                finishShipbillDTO.setCarrierPhoneNumber(loadingBillDetailModel.getDriverPhoneNumber());
            }

            // 类型翻译
            finishShipbillDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(loadingBillDetailModel.getOrderType())));
            finishShipbillDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(loadingBillDetailModel.getOrderBusinessType())));
            finishShipbillDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(loadingBillDetailModel.getDeliveryMethodType())));
            finishShipbillDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(loadingBillDetailModel.getTransportType())));
            finishShipbillDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(loadingBillDetailModel.getTemperatureRequirement())));
            finishShipbillDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(loadingBillDetailModel.getShipperType())));
            finishShipbillDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(loadingBillDetailModel.getConsigneeType())));
            // 运单状态
            finishShipbillDTO.setStatusName(PublicMethods.change(data9, String.valueOf(loadingBillDetailModel.getStatus())));
            // 运输状态
            finishShipbillDTO.setTransportStatusName(PublicMethods.change(data10, String.valueOf(loadingBillDetailModel.getTransportStatus())));
            // 异常状态
            finishShipbillDTO.setAbnormalStatusName(PublicMethods.change(data11, String.valueOf(loadingBillDetailModel.getAbnormalStatus())));
            // 扫描状态
            finishShipbillDTO.setScanStatusName(PublicMethods.change(data12, String.valueOf(loadingBillDetailModel.getScanStatus())));

            // 承运方类型
            finishShipbillDTO.setCarrierTypeName(PublicMethods.change(data13, String.valueOf(loadingBillDetailModel.getCarrierType())));
            // 调度单号
            finishShipbillDTO.setLoadingBillNo(loadingBillDetailModel.getLoadingBillNo());
            // 承运方名称
            // finishShipbillDTO.setCarrierName(loadingBillDetailModel.getCarrierName());
            // 送货员姓名
            finishShipbillDTO.setDeliverymanName(loadingBillDetailModel.getDeliverymanName());
            // 车牌号
            finishShipbillDTO.setVehiclePlateNumber(loadingBillDetailModel.getVehiclePlateNumber());
            rsExportFinishShipbillDTOs.add(finishShipbillDTO);
        }

        Page<ExportFinishShipbillDTO> page = PageUtils.getPage(rsExportFinishShipbillDTOs);
        if (queryFinishShipbillDTOs instanceof com.github.pagehelper.Page) {
            com.github.pagehelper.Page<FinishShipbillDTO> p0 = (com.github.pagehelper.Page<FinishShipbillDTO>) queryFinishShipbillDTOs;
            page.setPageCount(p0.getPages());
            page.setPageNum(p0.getPageNum());
            page.setPageSize(p0.getPageSize());
            page.setTotalCount(p0.getTotal());
            page.setStartRow(p0.getStartRow());
            page.setEndRow(p0.getEndRow());
        }
        return page.getList();
    }

    /**
     * 导出选择行数据
     *
     * @param shipbillIdList
     * @return
     */
    public List<ExportFinishShipbillDTO> exportSelectLineShipbill(List<String> shipbillIdList) {
        ToolKits.isParamNull(shipbillIdList, "导出选择行数据请求不为空");

        UserEntity user = PlgFxUsrUtils.getUserEntity();
        ToolKits.isParamNull(user, "当前人员没有操作权限");

        // 数据字典翻译数据集合
        List<Map<String, Object>> data1 = Lists.newArrayList();
        List<Map<String, Object>> data2 = Lists.newArrayList();
        List<Map<String, Object>> data3 = Lists.newArrayList();
        List<Map<String, Object>> data4 = Lists.newArrayList();
        List<Map<String, Object>> data5 = Lists.newArrayList();
        List<Map<String, Object>> data6 = Lists.newArrayList();
        List<Map<String, Object>> data7 = Lists.newArrayList();
        List<Map<String, Object>> data9 = Lists.newArrayList();
        List<Map<String, Object>> data10 = Lists.newArrayList();
        List<Map<String, Object>> data11 = Lists.newArrayList();
        List<Map<String, Object>> data12 = Lists.newArrayList();
        List<Map<String, Object>> data13 = Lists.newArrayList();

        // 订单类型
        RestMessage<List<Map<String, Object>>> restMessage1 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_TYPE, null, null, null);
        if (!restMessage1.isSuccess()) {
            throw new RuntimeException("订单类型翻译失败!");
        } else {
            data1 = restMessage1.getData();
        }
        // 订单业务类型
        RestMessage<List<Map<String, Object>>> restMessage2 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_BUSINESS_TYPE, null, null, null);
        if (!restMessage2.isSuccess()) {
            throw new RuntimeException("订单业务类型翻译失败!");
        } else {
            data2 = restMessage2.getData();
        }
        // 配送方式
        RestMessage<List<Map<String, Object>>> restMessage3 = maindataTmsResource.getDropDownById(DataDictionaryConstant.DELIVERY_METHOD_TYPE, null, null, null);
        if (!restMessage3.isSuccess()) {
            throw new RuntimeException("配送方式翻译失败!");
        } else {
            data3 = restMessage3.getData();
        }
        // 运输类型(运输模式)
        RestMessage<List<Map<String, Object>>> restMessage4 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_TYPE, null, null, null);
        if (!restMessage4.isSuccess()) {
            throw new RuntimeException("运输类型(运输模式)翻译失败!");
        } else {
            data4 = restMessage4.getData();
        }
        // 温度要求
        RestMessage<List<Map<String, Object>>> restMessage5 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TEMPERATURE_REQUIREMENT, null, null, null);
        if (!restMessage5.isSuccess()) {
            throw new RuntimeException("温度要求翻译失败!");
        } else {
            data5 = restMessage5.getData();
        }
        // 发货方类型
        RestMessage<List<Map<String, Object>>> restMessage6 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPPER_TYPE, null, null, null);
        if (!restMessage6.isSuccess()) {
            throw new RuntimeException("发货方类型翻译失败!");
        } else {
            data6 = restMessage6.getData();
        }
        // 收货方类型
        RestMessage<List<Map<String, Object>>> restMessage7 = maindataTmsResource.getDropDownById(DataDictionaryConstant.CONSIGNEE_TYPE, null, null, null);
        if (!restMessage7.isSuccess()) {
            throw new RuntimeException("收货方类型翻译失败!");
        } else {
            data7 = restMessage7.getData();
        }

        // 运单状态
        RestMessage<List<Map<String, Object>>> restMessage9 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPBILL_STATUS, null, null, null);
        if (!restMessage9.isSuccess()) {
            throw new RuntimeException("运单状态翻译失败!");
        } else {
            data9 = restMessage9.getData();
        }
        // 运输状态
        RestMessage<List<Map<String, Object>>> restMessage10 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_STATUS, null, null, null);
        if (!restMessage10.isSuccess()) {
            throw new RuntimeException("运输状态翻译失败!");
        } else {
            data10 = restMessage10.getData();
        }
        // 异常状态
        RestMessage<List<Map<String, Object>>> restMessage11 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ABNORMAL_STATUS, null, null, null);
        if (!restMessage11.isSuccess()) {
            throw new RuntimeException("异常状态翻译失败!");
        } else {
            data11 = restMessage11.getData();
        }
        // 扫描状态
        RestMessage<List<Map<String, Object>>> restMessage12 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SCAN_STATUS, null, null, null);
        if (!restMessage12.isSuccess()) {
            throw new RuntimeException("扫描状态翻译失败!");
        } else {
            data12 = restMessage12.getData();
        }

        // 承运方类型
        RestMessage<List<Map<String, Object>>> restMessage13 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LINE_CARRIER_TYPE, null, null, null);
        if (!restMessage13.isSuccess()) {
            throw new RuntimeException("承运方类型翻译失败!");
        } else {
            data13 = restMessage13.getData();
        }

        List<ExportFinishShipbillDTO> rsExportFinishShipbillDTOs = Lists.newArrayList();
        List<FinishShipbillDTO> queryFinishShipbillDTOs = tmsLoadingBillDetailMapper.exportFinishSelectLineShipbill(shipbillIdList.stream().toArray(String[]::new));

        for (FinishShipbillDTO loadingBillDetailModel : queryFinishShipbillDTOs) {
            ExportFinishShipbillDTO finishShipbillDTO = new ExportFinishShipbillDTO();
            BeanUtils.copyProperties(loadingBillDetailModel, finishShipbillDTO);
            // 收货方位置(经纬度判断)
            if (ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLatitude())) {
                finishShipbillDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
            } else {
                finishShipbillDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
            }
            // 发货方位置(经纬度判断)
            if (ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLatitude())) {
                finishShipbillDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
            } else {
                finishShipbillDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
            }

            StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
            // 目的地
            consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeProvinceName());
            consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeCityName());
            consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeDistrictName());
            finishShipbillDTO.setConsigneeProvinceCity(consigneeProvinceCityDistrict.toString());
            // 始发地
            StringBuffer shipperProvinceCityDistrict = new StringBuffer();
            shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperProvinceName());
            shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperCityName());
            shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperDistrictName());
            finishShipbillDTO.setShipperProvinceCity(shipperProvinceCityDistrict.toString());

            if (ObjectUtil.equal(DataDictionaryConstant.LINE_CARRIER_TYPE_SJ, loadingBillDetailModel.getCarrierType())) {// 承运方类型为司机时展示司机姓名
                finishShipbillDTO.setCarrierName(loadingBillDetailModel.getDriverName());
                finishShipbillDTO.setCarrierPhoneNumber(loadingBillDetailModel.getDriverPhoneNumber());
            }

            // 类型翻译
            finishShipbillDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(loadingBillDetailModel.getOrderType())));
            finishShipbillDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(loadingBillDetailModel.getOrderBusinessType())));
            finishShipbillDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(loadingBillDetailModel.getDeliveryMethodType())));
            finishShipbillDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(loadingBillDetailModel.getTransportType())));
            finishShipbillDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(loadingBillDetailModel.getTemperatureRequirement())));
            finishShipbillDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(loadingBillDetailModel.getShipperType())));
            finishShipbillDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(loadingBillDetailModel.getConsigneeType())));
            // 运单状态
            finishShipbillDTO.setStatusName(PublicMethods.change(data9, String.valueOf(loadingBillDetailModel.getStatus())));
            // 运输状态
            finishShipbillDTO.setTransportStatusName(PublicMethods.change(data10, String.valueOf(loadingBillDetailModel.getTransportStatus())));
            // 异常状态
            finishShipbillDTO.setAbnormalStatusName(PublicMethods.change(data11, String.valueOf(loadingBillDetailModel.getAbnormalStatus())));
            // 扫描状态
            finishShipbillDTO.setScanStatusName(PublicMethods.change(data12, String.valueOf(loadingBillDetailModel.getScanStatus())));

            // 承运方类型
            finishShipbillDTO.setCarrierTypeName(PublicMethods.change(data13, String.valueOf(loadingBillDetailModel.getCarrierType())));
            // 调度单号
            finishShipbillDTO.setLoadingBillNo(loadingBillDetailModel.getLoadingBillNo());
            // 承运方名称
            // finishShipbillDTO.setCarrierName(loadingBillDetailModel.getCarrierName());
            // 送货员姓名
            finishShipbillDTO.setDeliverymanName(loadingBillDetailModel.getDeliverymanName());
            // 车牌号
            finishShipbillDTO.setVehiclePlateNumber(loadingBillDetailModel.getVehiclePlateNumber());
            rsExportFinishShipbillDTOs.add(finishShipbillDTO);
        }
        return rsExportFinishShipbillDTOs;
    }

    /**
     * 完成打印
     *
     * @param finishShipbillPrintVO
     * @return
     */
    @Override
    public Map<String, Object> shipbillPrint(FinishShipbillPrintVO finishShipbillPrintVO) {
        ToolKits.isParamNull(finishShipbillPrintVO, "打印请求不为空");
        ToolKits.isParamNull(finishShipbillPrintVO.getShipbillId(), "运单ID不为空");

        UserEntity user = PlgFxUsrUtils.getUserEntity();
        ToolKits.isParamNull(user, "当前人员没有操作权限");

        // 数据字典翻译数据集合
        List<Map<String, Object>> data1 = Lists.newArrayList();
        List<Map<String, Object>> data2 = Lists.newArrayList();
        List<Map<String, Object>> data3 = Lists.newArrayList();
        List<Map<String, Object>> data4 = Lists.newArrayList();
        List<Map<String, Object>> data5 = Lists.newArrayList();
        List<Map<String, Object>> data6 = Lists.newArrayList();
        List<Map<String, Object>> data7 = Lists.newArrayList();
        List<Map<String, Object>> data9 = Lists.newArrayList();
        List<Map<String, Object>> data10 = Lists.newArrayList();
        List<Map<String, Object>> data11 = Lists.newArrayList();
        List<Map<String, Object>> data12 = Lists.newArrayList();
        List<Map<String, Object>> data13 = Lists.newArrayList();

        // 订单类型
        RestMessage<List<Map<String, Object>>> restMessage1 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_TYPE, null, null, null);
        if (!restMessage1.isSuccess()) {
            throw new RuntimeException("订单类型翻译失败!");
        } else {
            data1 = restMessage1.getData();
        }
        // 订单业务类型
        RestMessage<List<Map<String, Object>>> restMessage2 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_BUSINESS_TYPE, null, null, null);
        if (!restMessage2.isSuccess()) {
            throw new RuntimeException("订单业务类型翻译失败!");
        } else {
            data2 = restMessage2.getData();
        }
        // 配送方式
        RestMessage<List<Map<String, Object>>> restMessage3 = maindataTmsResource.getDropDownById(DataDictionaryConstant.DELIVERY_METHOD_TYPE, null, null, null);
        if (!restMessage3.isSuccess()) {
            throw new RuntimeException("配送方式翻译失败!");
        } else {
            data3 = restMessage3.getData();
        }
        // 运输类型(运输模式)
        RestMessage<List<Map<String, Object>>> restMessage4 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_TYPE, null, null, null);
        if (!restMessage4.isSuccess()) {
            throw new RuntimeException("运输类型(运输模式)翻译失败!");
        } else {
            data4 = restMessage4.getData();
        }
        // 温度要求
        RestMessage<List<Map<String, Object>>> restMessage5 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TEMPERATURE_REQUIREMENT, null, null, null);
        if (!restMessage5.isSuccess()) {
            throw new RuntimeException("温度要求翻译失败!");
        } else {
            data5 = restMessage5.getData();
        }
        // 发货方类型
        RestMessage<List<Map<String, Object>>> restMessage6 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPPER_TYPE, null, null, null);
        if (!restMessage6.isSuccess()) {
            throw new RuntimeException("发货方类型翻译失败!");
        } else {
            data6 = restMessage6.getData();
        }
        // 收货方类型
        RestMessage<List<Map<String, Object>>> restMessage7 = maindataTmsResource.getDropDownById(DataDictionaryConstant.CONSIGNEE_TYPE, null, null, null);
        if (!restMessage7.isSuccess()) {
            throw new RuntimeException("收货方类型翻译失败!");
        } else {
            data7 = restMessage7.getData();
        }
        // 运单状态
        RestMessage<List<Map<String, Object>>> restMessage9 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPBILL_STATUS, null, null, null);
        if (!restMessage9.isSuccess()) {
            throw new RuntimeException("运单状态翻译失败!");
        } else {
            data9 = restMessage9.getData();
        }
        // 运输状态
        RestMessage<List<Map<String, Object>>> restMessage10 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_STATUS, null, null, null);
        if (!restMessage10.isSuccess()) {
            throw new RuntimeException("运输状态翻译失败!");
        } else {
            data10 = restMessage10.getData();
        }
        // 异常状态
        RestMessage<List<Map<String, Object>>> restMessage11 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ABNORMAL_STATUS, null, null, null);
        if (!restMessage11.isSuccess()) {
            throw new RuntimeException("异常状态翻译失败!");
        } else {
            data11 = restMessage11.getData();
        }
        // 扫描状态
        RestMessage<List<Map<String, Object>>> restMessage12 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SCAN_STATUS, null, null, null);
        if (!restMessage12.isSuccess()) {
            throw new RuntimeException("扫描状态翻译失败!");
        } else {
            data12 = restMessage12.getData();
        }

        // 承运方类型
        RestMessage<List<Map<String, Object>>> restMessage13 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LINE_CARRIER_TYPE, null, null, null);
        if (!restMessage13.isSuccess()) {
            throw new RuntimeException("承运方类型翻译失败!");
        } else {
            data13 = restMessage13.getData();
        }
        String[] shipbills = {finishShipbillPrintVO.getShipbillId()};
        List<FinishShipbillDTO> finishShipbillDTOs = tmsLoadingBillDetailMapper.exportFinishSelectLineShipbill(shipbills);
        Assert.isTrue(ToolKits.isNotEmpty(finishShipbillDTOs), "运单【" + finishShipbillPrintVO.getShipbillId() + "】不存在");

        FinishShipbillDTO printHeadDTO = new FinishShipbillDTO();
        FinishShipbillDTO loadingBillDetailModel = finishShipbillDTOs.get(0);
        BeanUtils.copyProperties(loadingBillDetailModel, printHeadDTO);
        // 收货方位置(经纬度判断)
        if (ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLatitude())) {
            printHeadDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
        } else {
            printHeadDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
        }
        // 发货方位置(经纬度判断)
        if (ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLatitude())) {
            printHeadDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
        } else {
            printHeadDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
        }

        StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
        // 目的地
        consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeProvinceName());
        consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeCityName());
        consigneeProvinceCityDistrict.append(loadingBillDetailModel.getConsigneeDistrictName());
        printHeadDTO.setConsigneeProvinceCityDistrict(consigneeProvinceCityDistrict.toString());
        // 始发地
        StringBuffer shipperProvinceCityDistrict = new StringBuffer();
        shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperProvinceName());
        shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperCityName());
        shipperProvinceCityDistrict.append(loadingBillDetailModel.getShipperDistrictName());
        printHeadDTO.setShipperProvinceCityDistrict(shipperProvinceCityDistrict.toString());

        // 类型翻译
        printHeadDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(loadingBillDetailModel.getOrderType())));
        printHeadDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(loadingBillDetailModel.getOrderBusinessType())));
        printHeadDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(loadingBillDetailModel.getDeliveryMethodType())));
        printHeadDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(loadingBillDetailModel.getTransportType())));
        printHeadDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(loadingBillDetailModel.getTemperatureRequirement())));
        printHeadDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(loadingBillDetailModel.getShipperType())));
        printHeadDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(loadingBillDetailModel.getConsigneeType())));
        // 运单状态
        printHeadDTO.setStatusName(PublicMethods.change(data9, String.valueOf(loadingBillDetailModel.getStatus())));
        // 运输状态
        printHeadDTO.setTransportStatusName(PublicMethods.change(data10, String.valueOf(loadingBillDetailModel.getTransportStatus())));
        // 异常状态
        printHeadDTO.setAbnormalStatusName(PublicMethods.change(data11, String.valueOf(loadingBillDetailModel.getAbnormalStatus())));
        // 扫描状态
        printHeadDTO.setScanStatusName(PublicMethods.change(data12, String.valueOf(loadingBillDetailModel.getScanStatus())));
        // 承运方类型
        printHeadDTO.setScanStatusName(PublicMethods.change(data13, String.valueOf(loadingBillDetailModel.getCarrierType())));
        // 调度单号
        printHeadDTO.setLoadingBillNo(loadingBillDetailModel.getLoadingBillNo());
        // 承运方名称
        printHeadDTO.setCarrierName(loadingBillDetailModel.getCarrierName());
        // 送货员姓名
        printHeadDTO.setDeliverymanName(loadingBillDetailModel.getDeliverymanName());
        // 车牌号
        printHeadDTO.setVehiclePlateNumber(loadingBillDetailModel.getVehiclePlateNumber());

        // 获取商品信息
        // 数据字典翻译数据集合
        List<Map<String, Object>> data14 = Lists.newArrayList();
        List<Map<String, Object>> data15 = Lists.newArrayList();

        // 包装类型
        RestMessage<List<Map<String, Object>>> restMessage14 = maindataTmsResource.getDropDownById(DataDictionaryConstant.PACK_TYPE, null, null, null);
        if (!restMessage14.isSuccess()) {
            throw new RuntimeException("包装类型翻译失败!");
        } else {
            data14 = restMessage14.getData();
        }
        // 货物温层
        RestMessage<List<Map<String, Object>>> restMessage15 = maindataTmsResource.getDropDownById(DataDictionaryConstant.CARGO_THERMOSPHERE, null, null, null);
        if (!restMessage15.isSuccess()) {
            throw new RuntimeException("货物温层翻译失败!");
        } else {
            data15 = restMessage15.getData();
        }

        Criteria criteria = Criteria.forClass(TmsShipbillDetailModel.class);
        Restriction r1 = Restrictions.eq("shipbillId", finishShipbillPrintVO.getShipbillId());
        criteria.setRestriction(r1);
        List<TmsShipbillDetailModel> tmsShipbillDetailModels = tmsShipbillDetailMapper.findByCriteria(criteria);

        List<PendingReceiptPrintDetailDTO> shipbillPSPrintTableDTOs = new ArrayList<>();

        for (TmsShipbillDetailModel detail : tmsShipbillDetailModels) {
            PendingReceiptPrintDetailDTO dto = new PendingReceiptPrintDetailDTO();
            BeanUtils.copyProperties(detail, dto);
            dto.setPackTypeName(PublicMethods.change(data14, String.valueOf(detail.getPackType())));
            dto.setCargoThermosphereName(PublicMethods.change(data15, String.valueOf(detail.getCargoThermosphere())));
            shipbillPSPrintTableDTOs.add(dto);
        }

        // TODO print
        return null;
    }

}
