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

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

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.prolog.common.util.DateUtils;
import com.prolog.common.util.ToolKits;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.exception.BizException;
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.constant.enums.SignInStatusEnum;
import com.prolog.rdc.tms.dao.mapper.TmsLoadingBillDetailMapper;
import com.prolog.rdc.tms.dao.mapper.TmsLoadingBillHeaderMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillDetailMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillHeaderMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillNodeTrackingMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillPackageMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillTransportLogMapper;
import com.prolog.rdc.tms.model.dto.OrigReceiptLoadingPackageDTO;
import com.prolog.rdc.tms.model.dto.OrigReceiptLoadingShipBillDetailDTO;
import com.prolog.rdc.tms.model.dto.OrigReceiptLoadingShipbillDTO;
import com.prolog.rdc.tms.model.dto.PendingOrigReceiptConsigneeDTO;
import com.prolog.rdc.tms.model.dto.PendingOrigReceiptExportShipbillDTO;
import com.prolog.rdc.tms.model.dto.PendingOrigReceiptPictureDTO;
import com.prolog.rdc.tms.model.dto.PendingOrigReceiptShipbillDTO;
import com.prolog.rdc.tms.model.dto.PendingReceiptPrintDetailDTO;
import com.prolog.rdc.tms.model.dto.PendingReceiptPrintHeadDTO;
import com.prolog.rdc.tms.model.dto.PendingReceiptShipbillApprovalDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.SignconfigPopDTO;
import com.prolog.rdc.tms.model.dto.basicData.ApprovalLogDTO;
import com.prolog.rdc.tms.model.dto.basicData.ApprovalNodeSelDTO;
import com.prolog.rdc.tms.model.dto.message.SendMessageDTO;
import com.prolog.rdc.tms.model.entity.ShipbillNodeTracking;
import com.prolog.rdc.tms.model.entity.SysRefdatadModel;
import com.prolog.rdc.tms.model.entity.TmsLoadingBillDetailModel;
import com.prolog.rdc.tms.model.entity.TmsLoadingBillHeaderModel;
import com.prolog.rdc.tms.model.entity.TmsShipbillDetailModel;
import com.prolog.rdc.tms.model.entity.TmsShipbillHeaderModel;
import com.prolog.rdc.tms.model.entity.TmsShipbillPackageModel;
import com.prolog.rdc.tms.model.entity.TmsShipbillTransLogModel;
import com.prolog.rdc.tms.model.enums.MessageOrderTypeEnum;
import com.prolog.rdc.tms.model.enums.MessageTypeEnum;
import com.prolog.rdc.tms.model.vo.ApprovalVO;
import com.prolog.rdc.tms.model.vo.OrigReceiptConfirmVO;
import com.prolog.rdc.tms.model.vo.OrigReceiptLoadingShipbillPageVO;
import com.prolog.rdc.tms.model.vo.PendingOrigReceiptAdvancedPageVO;
import com.prolog.rdc.tms.model.vo.PendingOrigReceiptExportAllDataVO;
import com.prolog.rdc.tms.model.vo.PendingOrigReceiptExportCurrPgDataVO;
import com.prolog.rdc.tms.model.vo.PendingOrigReceiptPageVO;
import com.prolog.rdc.tms.model.vo.PendingOrigReceiptPrintVO;
import com.prolog.rdc.tms.model.vo.ShipbillNodeTrackingSaveVO;
import com.prolog.rdc.tms.model.vo.ShipbillOperateLogSaveVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.ApprovalBusinessNodeVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.ApprovalOpenVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.SignconfigPopVO;
import com.prolog.rdc.tms.rmi.feign.MaindataFeign;
import com.prolog.rdc.tms.service.PendingOrigReceiptService;
import com.prolog.rdc.tms.service.ShipbillCommonService;
import com.prolog.rdc.tms.service.ShipbillNodeTrackingService;
import com.prolog.rdc.tms.service.ShipbillOperateLogService;
import com.prolog.rdc.tms.util.ConvertorUtil;
import com.prolog.rdc.tms.util.MessageUtil;
import com.prolog.rdc.tms.util.PublicMethods;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;

/**
 * 运输管理-待正本回单实现层
 *
 * @author lhb
 * @since 2022-06-01 14:45:00
 */
@Service
public class PendingOrigReceiptServiceImpl implements PendingOrigReceiptService {

	@Autowired
	private TmsShipbillHeaderMapper tmsShipbillHeaderMapper;

	@Autowired
	private TmsShipbillDetailMapper tmsShipbillDetailMapper;

	@Autowired
	private TmsShipbillPackageMapper tmsShipbillPackageMapper;

	@Autowired
	private MaindataFeign maindataTmsResource;

	@Autowired
	private ShipbillOperateLogService shipbillOperateLogService;

	@Autowired
	private TmsLoadingBillHeaderMapper tmsLoadingBillHeaderMapper;

	@Autowired
	private TmsLoadingBillDetailMapper tmsLoadingBillDetailMapper;

	@Autowired
	private TmsShipbillTransportLogMapper tmsShipbillTransportLogMapper;

	@Autowired
	private ShipbillCommonService shipbillCommonService;

	@Autowired
	private ShipbillNodeTrackingService shipbillNodeTrackingService;

	@Autowired
	private ConvertorUtil convertorUtil;

	@Autowired
	private TmsShipbillNodeTrackingMapper tmsShipbillNodeTrackingMapper;

	/**
	 * 待正本回单运单模式分页查询
	 *
	 * @param pendingReceiptPageVO
	 * @return
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<PendingOrigReceiptShipbillDTO> shipbillPage(PendingOrigReceiptPageVO pendingReceiptPageVO) {

		ToolKits.isParamNull(pendingReceiptPageVO, "待正本回单运单模式分页查询请求不为空");
		ToolKits.isParamNull(pendingReceiptPageVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(pendingReceiptPageVO.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();
		}

		List<SysRefdatadModel> dicData = convertorUtil.getDictionary(new String[] {
				DataDictionaryConstant.CARRIER_SYS_FLAG // 承运商系统标志
		});
		StringBuffer splitSqlBuff = new StringBuffer();
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 拆单类型
			splitSqlBuff.append(" ((t2.split_order_status = 0 and t2.carrier_split_order_type = 1) or t2.carrier_split_order_type =2 or t2.carrier_split_order_type =4) ");
			// 判断是否为部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				pendingReceiptPageVO.setDepartmentIds(user.getDepts().stream().toArray(String[]::new));
			} else {
				pendingReceiptPageVO.setDepartmentIds(user.getDepts().stream().toArray(String[]::new));
				pendingReceiptPageVO.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) {
					pendingReceiptPageVO.setSqlBuff("( " + sqlBuff.toString() + " )");
				}
			}
		} else {
			splitSqlBuff.append(" t2.carrier_split_order_status = 0 ");
			pendingReceiptPageVO.setScheduleType(DataDictionaryConstant.SCHEDULE_TYPE_CYS);
			pendingReceiptPageVO.setCarrierId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
			pendingReceiptPageVO.setCarrierShipbillStatus(DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_DISPATCHED_CHECK);
		}
		List<PendingOrigReceiptShipbillDTO> pendingReceiptDTOs = Lists.newArrayList();
		pendingReceiptPageVO.setEnterpriseId(user.getEnterpriseId());
		pendingReceiptPageVO.setSplitSqlBuff(splitSqlBuff.toString());

		PageUtils.startPage(pendingReceiptPageVO.getPageNum(), pendingReceiptPageVO.getPageSize());
		List<PendingOrigReceiptShipbillDTO> pendingReceiptShipbillPageDTOs = tmsLoadingBillDetailMapper.queryPendingOrigReceiptShipbill(pendingReceiptPageVO);
		// 行号
		int id = 1;
		for (PendingOrigReceiptShipbillDTO loadingBillDetailModel : pendingReceiptShipbillPageDTOs) {
			PendingOrigReceiptShipbillDTO pendingReceiptDTO = new PendingOrigReceiptShipbillDTO();
			BeanUtils.copyProperties(loadingBillDetailModel, pendingReceiptDTO);
			pendingReceiptDTO.setId(id);
			id++;
			// 收货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLatitude())) {
				pendingReceiptDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
			} else {
				pendingReceiptDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
			}
			// 发货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLatitude())) {
				pendingReceiptDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
			} else {
				pendingReceiptDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
			}

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

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

			// 类型翻译
			pendingReceiptDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(pendingReceiptDTO.getOrderType())));
			pendingReceiptDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(pendingReceiptDTO.getOrderBusinessType())));
			pendingReceiptDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(pendingReceiptDTO.getDeliveryMethodType())));
			pendingReceiptDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(pendingReceiptDTO.getTransportType())));
			pendingReceiptDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(pendingReceiptDTO.getTemperatureRequirement())));
			pendingReceiptDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(pendingReceiptDTO.getShipperType())));
			pendingReceiptDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(pendingReceiptDTO.getConsigneeType())));
			// 运单状态
			pendingReceiptDTO.setStatusName(PublicMethods.change(data9, String.valueOf(pendingReceiptDTO.getStatus())));
			// 运输状态
			pendingReceiptDTO.setTransportStatusName(PublicMethods.change(data10, String.valueOf(pendingReceiptDTO.getTransportStatus())));
			// 异常状态
			pendingReceiptDTO.setAbnormalStatusName(PublicMethods.change(data11, String.valueOf(pendingReceiptDTO.getAbnormalStatus())));
			// 扫描状态
			pendingReceiptDTO.setScanStatusName(PublicMethods.change(data12, String.valueOf(pendingReceiptDTO.getScanStatus())));
			pendingReceiptDTO.setCarrierSysFlagName(ConvertorUtil.getName(dicData, DataDictionaryConstant.CARRIER_SYS_FLAG, pendingReceiptDTO.getCarrierSysFlag()));
			// 获取背景颜色和字体颜色
			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(pendingReceiptDTO.getOrderTypeName()) ? pendingReceiptDTO.getOrderTypeName() : "")) {
							pendingReceiptDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							pendingReceiptDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

							pendingReceiptDTO.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(pendingReceiptDTO.getOrderBusinessTypeName()) ? pendingReceiptDTO.getOrderBusinessTypeName() : "")) {
							pendingReceiptDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							pendingReceiptDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

							pendingReceiptDTO.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(pendingReceiptDTO.getTemperatureRequirementName()) ? pendingReceiptDTO.getTemperatureRequirementName() : "")) {
							pendingReceiptDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							pendingReceiptDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

							pendingReceiptDTO.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(pendingReceiptDTO.getDeliveryMethodTypeName()) ? pendingReceiptDTO.getDeliveryMethodTypeName() : "")) {
							pendingReceiptDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							pendingReceiptDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

							pendingReceiptDTO.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(pendingReceiptDTO.getMemo()) ? pendingReceiptDTO.getMemo() : "")) {
							pendingReceiptDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							pendingReceiptDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

							pendingReceiptDTO.setSignConfigId(signconfigPopDTO.getId());

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

			pendingReceiptDTOs.add(pendingReceiptDTO);

		}
		// 分页重组
		Page<PendingOrigReceiptShipbillDTO> page = PageUtils.getPage(pendingReceiptDTOs);
		if (pendingReceiptShipbillPageDTOs instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<PendingOrigReceiptShipbillDTO> p0 = (com.github.pagehelper.Page<PendingOrigReceiptShipbillDTO>) pendingReceiptShipbillPageDTOs;
			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;
	}

	@SuppressWarnings("resource")
	@Override
	public Page<PendingOrigReceiptShipbillDTO> advancedShipbillPage(PendingOrigReceiptAdvancedPageVO pendingOrigReceiptAdvancedPageVO) {
		ToolKits.isParamNull(pendingOrigReceiptAdvancedPageVO, "待正本回单运单模式分页查询请求不为空");
		ToolKits.isParamNull(pendingOrigReceiptAdvancedPageVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(pendingOrigReceiptAdvancedPageVO.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)) {
				pendingOrigReceiptAdvancedPageVO.setIsDept(StatusConstant.IS_DEPT_YES);
				pendingOrigReceiptAdvancedPageVO.setDepts(user.getDepts().toArray(new String[] {}));
			} else {
				pendingOrigReceiptAdvancedPageVO.setIsDept(StatusConstant.IS_DEPT_NO);
				// 设置部门权限
				pendingOrigReceiptAdvancedPageVO.setDepts(user.getDepts().toArray(new String[] {}));
				// 设置数据权限
				pendingOrigReceiptAdvancedPageVO.setConsignors(user.getConsignors().toArray(new Long[] {}));
				pendingOrigReceiptAdvancedPageVO.setWsarehouses(user.getWarehouses().toArray(new Long[] {}));
				pendingOrigReceiptAdvancedPageVO.setCustomers(user.getCustomers().toArray(new Long[] {}));
				pendingOrigReceiptAdvancedPageVO.setSuppliers(user.getSuppliers().toArray(new Long[] {}));
			}
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
			pendingOrigReceiptAdvancedPageVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			throw new PrologException("当前人员没有操作权限");
		}
		pendingOrigReceiptAdvancedPageVO.setUserType(user.getUserType());
		pendingOrigReceiptAdvancedPageVO.setEnterpriseId(user.getEnterpriseId());

		// 获取高级查询配置
		String conditions = null;
		RestMessage<String> restMessageAdvancedCfg = maindataTmsResource.getQueryConfiguration(DataDictionaryConstant.BIZ_TYPE_BILL);
		if (!restMessageAdvancedCfg.isSuccess()) {
			throw new RuntimeException("获取高级查询配置失败!");
		} else {
			conditions = restMessageAdvancedCfg.getData();
		}
		pendingOrigReceiptAdvancedPageVO.setSql(conditions);

		List<PendingOrigReceiptShipbillDTO> pendingReceiptDTOs = Lists.newArrayList();

		PageUtils.startPage(pendingOrigReceiptAdvancedPageVO.getPageNum(), pendingOrigReceiptAdvancedPageVO.getPageSize());
		List<PendingOrigReceiptShipbillDTO> pendingReceiptShipbillPageDTOs = tmsLoadingBillDetailMapper.advancedQueryPendingOrigReceiptShipbill(pendingOrigReceiptAdvancedPageVO);
		// 行号
		int id = 1;
		for (PendingOrigReceiptShipbillDTO loadingBillDetailModel : pendingReceiptShipbillPageDTOs) {
			PendingOrigReceiptShipbillDTO pendingReceiptDTO = new PendingOrigReceiptShipbillDTO();
			BeanUtils.copyProperties(loadingBillDetailModel, pendingReceiptDTO);
			pendingReceiptDTO.setId(id);
			id++;
			// 收货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getConsigneeLatitude())) {
				pendingReceiptDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
			} else {
				pendingReceiptDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
			}
			// 发货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLongitude()) && ToolKits.isNotEmpty(loadingBillDetailModel.getShipperLatitude())) {
				pendingReceiptDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
			} else {
				pendingReceiptDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
			}

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

			// 类型翻译
			pendingReceiptDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(pendingReceiptDTO.getOrderType())));
			pendingReceiptDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(pendingReceiptDTO.getOrderBusinessType())));
			pendingReceiptDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(pendingReceiptDTO.getDeliveryMethodType())));
			pendingReceiptDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(pendingReceiptDTO.getTransportType())));
			pendingReceiptDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(pendingReceiptDTO.getTemperatureRequirement())));
			pendingReceiptDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(pendingReceiptDTO.getShipperType())));
			pendingReceiptDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(pendingReceiptDTO.getConsigneeType())));
			// 运单状态
			pendingReceiptDTO.setStatusName(PublicMethods.change(data9, String.valueOf(pendingReceiptDTO.getStatus())));
			// 运输状态
			pendingReceiptDTO.setTransportStatusName(PublicMethods.change(data10, String.valueOf(pendingReceiptDTO.getTransportStatus())));
			// 异常状态
			pendingReceiptDTO.setAbnormalStatusName(PublicMethods.change(data11, String.valueOf(pendingReceiptDTO.getAbnormalStatus())));
			// 扫描状态
			pendingReceiptDTO.setScanStatusName(PublicMethods.change(data12, String.valueOf(pendingReceiptDTO.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(pendingReceiptDTO.getOrderTypeName()) ? pendingReceiptDTO.getOrderTypeName() : "")) {
							pendingReceiptDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							pendingReceiptDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

							pendingReceiptDTO.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(pendingReceiptDTO.getOrderBusinessTypeName()) ? pendingReceiptDTO.getOrderBusinessTypeName() : "")) {
							pendingReceiptDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							pendingReceiptDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

							pendingReceiptDTO.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(pendingReceiptDTO.getTemperatureRequirementName()) ? pendingReceiptDTO.getTemperatureRequirementName() : "")) {
							pendingReceiptDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							pendingReceiptDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

							pendingReceiptDTO.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(pendingReceiptDTO.getDeliveryMethodTypeName()) ? pendingReceiptDTO.getDeliveryMethodTypeName() : "")) {
							pendingReceiptDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							pendingReceiptDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

							pendingReceiptDTO.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(pendingReceiptDTO.getMemo()) ? pendingReceiptDTO.getMemo() : "")) {
							pendingReceiptDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							pendingReceiptDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

							pendingReceiptDTO.setSignConfigId(signconfigPopDTO.getId());

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

			pendingReceiptDTOs.add(pendingReceiptDTO);

		}
		// 分页重组
		Page<PendingOrigReceiptShipbillDTO> page = PageUtils.getPage(pendingReceiptDTOs);
		if (pendingReceiptShipbillPageDTOs instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<PendingOrigReceiptShipbillDTO> p0 = (com.github.pagehelper.Page<PendingOrigReceiptShipbillDTO>) pendingReceiptShipbillPageDTOs;
			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 pendingReceiptPageVO
	 * @return
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<PendingOrigReceiptConsigneeDTO> consigneePage(PendingOrigReceiptPageVO pendingReceiptPageVO) {

		ToolKits.isParamNull(pendingReceiptPageVO, "待正本回单收货方模式分页查询请求不为空");
		ToolKits.isParamNull(pendingReceiptPageVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(pendingReceiptPageVO.getPageSize(), "每页条数不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		StringBuffer splitSqlBuff = new StringBuffer();
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 拆单类型
			splitSqlBuff.append(" ((t2.split_order_status = 0 and t2.carrier_split_order_type = 1) or t2.carrier_split_order_type =2 or t2.carrier_split_order_type =4) ");
			// 判断是否为部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				pendingReceiptPageVO.setDepartmentIds(user.getDepts().stream().toArray(String[]::new));
			} else {
				pendingReceiptPageVO.setDepartmentIds(user.getDepts().stream().toArray(String[]::new));
				pendingReceiptPageVO.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(",")) + ")");
				}
				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(",")) + ")");
					}
				}
				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(",")) + ")");
					}
				}
				if (sqlBuff.toString().length() > 0) {
					pendingReceiptPageVO.setSqlBuff("( " + sqlBuff.toString() + " )");
				}
			}
		} else {
			splitSqlBuff.append(" t2.carrier_split_order_status = 0 ");
			pendingReceiptPageVO.setScheduleType(DataDictionaryConstant.SCHEDULE_TYPE_CYS);
			pendingReceiptPageVO.setCarrierId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
			pendingReceiptPageVO.setCarrierShipbillStatus(DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_DISPATCHED_CHECK);
		}
		pendingReceiptPageVO.setEnterpriseId(user.getEnterpriseId());
		pendingReceiptPageVO.setSplitSqlBuff(splitSqlBuff.toString());

		PageUtils.startPage(pendingReceiptPageVO.getPageNum(), pendingReceiptPageVO.getPageSize());
		List<PendingOrigReceiptConsigneeDTO> pendingReceiptConsigneePageDTOs = tmsLoadingBillDetailMapper.queryPendingOrigReceiptConsignee(pendingReceiptPageVO);

		List<SysRefdatadModel> dicData = convertorUtil.getDictionary(new String[] {
				DataDictionaryConstant.CARRIER_SYS_FLAG // 承运商系统标志
		});
		// 行号
		int id = 1;
		for (PendingOrigReceiptConsigneeDTO dto : pendingReceiptConsigneePageDTOs) {
			// 设置行id
			dto.setId(id);
			// 目的地
			dto.setConsigneeProvinceCityDistrict(dto.getConsigneeProvinceName() + dto.getConsigneeCityName() + dto.getConsigneeDistrictName());
			dto.setCarrierSysFlagName(ConvertorUtil.getName(dicData, DataDictionaryConstant.CARRIER_SYS_FLAG, dto.getCarrierSysFlag()));
			// 行号自增长
			id++;
		}

		// 分页重组
		Page<PendingOrigReceiptConsigneeDTO> page = PageUtils.getPage(pendingReceiptConsigneePageDTOs);
		if (pendingReceiptConsigneePageDTOs instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<PendingOrigReceiptConsigneeDTO> p0 = (com.github.pagehelper.Page<PendingOrigReceiptConsigneeDTO>) pendingReceiptConsigneePageDTOs;
			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 receiptConfirmVO
	 * @return
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void receiptConfirm(OrigReceiptConfirmVO receiptConfirmVO) {
		ToolKits.isParamNull(receiptConfirmVO, "正本回单确认请求不为空");
		ToolKits.isParamNull(receiptConfirmVO.getShipbillId(), "正本回单确认请求对象不为空");
		ToolKits.isParamNull(receiptConfirmVO.getOrigReceiptReturnTime(), "回单返回时间不为空");
		ToolKits.isParamNull(receiptConfirmVO.getOrigReceiptStatus(), "回单状态不为空");
		ToolKits.isParamNull(receiptConfirmVO.getOrigReceiptType(), "回单类型不为空");

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

		// 当前时间
		Date date = DateUtil.date();

		Map<String, Object> mapUpdate = Maps.newHashMap();
		mapUpdate.put("updateperson", user.getNickname());
		mapUpdate.put("updatetime", date);
		mapUpdate.put("status", DataDictionaryConstant.SHIPBILL_STATUS_END);

		// 更新调度单
		Map<String, Object> mapHeaderUpdate = Maps.newHashMap();
		mapHeaderUpdate.put("updateperson", user.getNickname());
		mapHeaderUpdate.put("updatetime", date);
		mapHeaderUpdate.put("status", DataDictionaryConstant.LOADING_BILL_SHIPBILL_STATUS_END);

		Criteria criteriaLoadingBillDetail = Criteria.forClass(TmsLoadingBillDetailModel.class);
		Criteria criteriaShipbillHeader = Criteria.forClass(TmsShipbillHeaderModel.class);
		Criteria criteriaLoadingHeader = Criteria.forClass(TmsLoadingBillHeaderModel.class);

		Criteria criteriaTransport = Criteria.forClass(TmsShipbillTransLogModel.class);
		Map<String, Object> mapTransportLogUpdate = Maps.newHashMap();
		mapTransportLogUpdate.put("updateperson", user.getNickname());
		mapTransportLogUpdate.put("updatetime", date);
		// 回单返回时间
		mapTransportLogUpdate.put("origReceiptReturnTime", receiptConfirmVO.getOrigReceiptReturnTime());
		// 回单状态
		mapTransportLogUpdate.put("origReceiptStatus", receiptConfirmVO.getOrigReceiptStatus());
		// 回单类型
		mapTransportLogUpdate.put("origReceiptType", receiptConfirmVO.getOrigReceiptType());
		// 回单时效
		mapTransportLogUpdate.put("origReceiptAging", receiptConfirmVO.getOrigReceiptAging());
		// 回单接收人
		mapTransportLogUpdate.put("origReceiptReceivePerson", receiptConfirmVO.getOrigReceiptReceivePerson());
		// 回单份数
		mapTransportLogUpdate.put("origReceiptNum", receiptConfirmVO.getOrigReceiptNum());
		// 备注
		mapTransportLogUpdate.put("origReceiptMemo", receiptConfirmVO.getMemo());

		List<Map<String, Object>> data1 = Lists.newArrayList();
		List<Map<String, Object>> data2 = Lists.newArrayList();
		// 回单状态
		RestMessage<List<Map<String, Object>>> restMessage1 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORIG_RECEIPT_STATUS, null, null, null);
		if (!restMessage1.isSuccess()) {
			throw new RuntimeException("回单状态翻译失败!");
		} else {
			data1 = restMessage1.getData();
		}
		String origReceiptStatus = PublicMethods.change(data1, String.valueOf(receiptConfirmVO.getOrigReceiptStatus()));
		// 回单类型
		RestMessage<List<Map<String, Object>>> restMessage2 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORIG_RECEIPT_TYPE, null, null, null);
		if (!restMessage2.isSuccess()) {
			throw new RuntimeException("回单类型翻译失败!");
		} else {
			data2 = restMessage1.getData();
		}
		String origReceiptType = PublicMethods.change(data2, String.valueOf(receiptConfirmVO.getOrigReceiptType()));
		String[] shipbillIds = receiptConfirmVO.getShipbillId().split(",");
		List<String> loadingDetailIds = Lists.newArrayList();
		for (String shipbillId : shipbillIds) {

			TmsShipbillHeaderModel tmsShipbillHeaderModel = tmsShipbillHeaderMapper.findById(shipbillId, TmsShipbillHeaderModel.class);
			if (StrUtil.isNotBlank(tmsShipbillHeaderModel.getFlowConfig()) && tmsShipbillHeaderModel.getFlowConfig().contains(DataDictionaryConstant.FLOW_CONFIG_SIGN_IN)) {
				if (!SignInStatusEnum.SIGN.getCode().equals(tmsShipbillHeaderModel.getSignInStatus())) {
					throw new BizException("存在未签收完成的运单【" + shipbillId + "】，请签收后再操作");
				}
			}

			// 更新装车单明细
			Restriction r1 = Restrictions.eq("shipbillId", shipbillId);
			Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
			criteriaLoadingBillDetail.setOrder(Order.newInstance().desc(new String[] { "createtime" }));
			criteriaLoadingBillDetail.setRestriction(Restrictions.and(r1, r2));

			// 确认运单是否正本回单了
			List<TmsLoadingBillDetailModel> tmsLoadingBillDetailModels = tmsLoadingBillDetailMapper.findByCriteria(criteriaLoadingBillDetail);
			Assert.isTrue(tmsLoadingBillDetailModels != null && tmsLoadingBillDetailModels.size() > 0 && tmsLoadingBillDetailModels.get(0).getStatus() != DataDictionaryConstant.SHIPBILL_STATUS_END, "运单【" + shipbillId + "】已正本回单");

			Boolean matched = approvalOpen(tmsLoadingBillDetailModels.get(0), DataDictionaryConstant.APPROVAL_FLOW_TYPE_START_RECEIPT_PIC, user);

			// 更新订单运输记录表
			criteriaTransport.setRestriction(r1);
			tmsShipbillTransportLogMapper.updateMapByCriteria(mapTransportLogUpdate, criteriaTransport);

			if (matched) {
				mapHeaderUpdate.put("status", DataDictionaryConstant.SHIPBILL_STATUS_HD_ZB_APPROVAL);
				mapUpdate.put("status", DataDictionaryConstant.SHIPBILL_STATUS_HD_ZB_APPROVAL);
				// 更新调度单明细
				tmsLoadingBillDetailMapper.updateMapById(tmsLoadingBillDetailModels.get(0).getId(), mapUpdate, TmsLoadingBillDetailModel.class);

				// 更新运单表
				criteriaShipbillHeader.setRestriction(Restrictions.and(r1, r2));
				tmsShipbillHeaderMapper.updateMapByCriteria(mapUpdate, criteriaShipbillHeader);

				// 运单节点保存
				ShipbillNodeTrackingSaveVO shipbillNodeTrackingSaveVO = new ShipbillNodeTrackingSaveVO();
				shipbillNodeTrackingSaveVO.setShipbillId(shipbillId);
				shipbillNodeTrackingSaveVO.setShipbillNo(shipbillId);
				shipbillNodeTrackingSaveVO.setPicUrl(receiptConfirmVO.getPicUrl());
				shipbillNodeTrackingSaveVO.setNodeDate(receiptConfirmVO.getOrigReceiptReturnTime());
				shipbillNodeTrackingSaveVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_HD_ZB_APPROVAL);
				shipbillNodeTrackingSaveVO.setNodeEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_HD_ZB_APPROVAL + " 回单状态:" + origReceiptStatus + " 回单类型:" + origReceiptType + " 回单时效:" + (receiptConfirmVO.getOrigReceiptAging() == null ? "" : receiptConfirmVO.getOrigReceiptAging()) + " 接收人:" + (receiptConfirmVO.getOrigReceiptReceivePerson() == null ? "" : receiptConfirmVO.getOrigReceiptReceivePerson()) + " 接收份数：" + (receiptConfirmVO.getOrigReceiptNum() == null ? "" : receiptConfirmVO.getOrigReceiptNum()) + " 备注:" + (receiptConfirmVO.getMemo() == null ? "" : receiptConfirmVO.getMemo()));
				shipbillNodeTrackingService.addShipbillNodeTrackingData(shipbillNodeTrackingSaveVO);

				// 运单日志保存
				ShipbillOperateLogSaveVO shipbillOperateLogSaveVO = new ShipbillOperateLogSaveVO();
				shipbillOperateLogSaveVO.setShipbillId(shipbillId);
				shipbillOperateLogSaveVO.setShipbillNo(shipbillId);
				shipbillOperateLogSaveVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_HD_ZB_APPROVAL);
				shipbillOperateLogSaveVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_HD_PIC);
				shipbillOperateLogSaveVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_HD_ZB_APPROVAL);
				shipbillOperateLogService.addShipbillOperateLogData(shipbillOperateLogSaveVO);

				continue;
			}
			tmsLoadingBillDetailMapper.updateMapById(tmsLoadingBillDetailModels.get(0).getId(), mapUpdate, TmsLoadingBillDetailModel.class);

			// 更新运单表
			criteriaShipbillHeader.setRestriction(Restrictions.and(r1, r2));
			tmsShipbillHeaderMapper.updateMapByCriteria(mapUpdate, criteriaShipbillHeader);

			// 运单节点保存
			ShipbillNodeTrackingSaveVO shipbillNodeTrackingSaveVO = new ShipbillNodeTrackingSaveVO();
			shipbillNodeTrackingSaveVO.setShipbillId(shipbillId);
			shipbillNodeTrackingSaveVO.setShipbillNo(shipbillId);
			shipbillNodeTrackingSaveVO.setPicUrl(receiptConfirmVO.getPicUrl());
			shipbillNodeTrackingSaveVO.setNodeDate(receiptConfirmVO.getOrigReceiptReturnTime());
			shipbillNodeTrackingSaveVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_HD_ZB);
			shipbillNodeTrackingSaveVO.setNodeEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_HD_ZB + " 回单状态:" + origReceiptStatus + " 回单类型:" + origReceiptType + " 回单时效:" + (receiptConfirmVO.getOrigReceiptAging() == null ? "" : receiptConfirmVO.getOrigReceiptAging()) + " 接收人:" + (receiptConfirmVO.getOrigReceiptReceivePerson() == null ? "" : receiptConfirmVO.getOrigReceiptReceivePerson()) + " 接收份数：" + (receiptConfirmVO.getOrigReceiptNum() == null ? "" : receiptConfirmVO.getOrigReceiptNum()) + " 备注:" + (receiptConfirmVO.getMemo() == null ? "" : receiptConfirmVO.getMemo()));
			shipbillNodeTrackingService.addShipbillNodeTrackingData(shipbillNodeTrackingSaveVO);

			// 运单日志保存
			ShipbillOperateLogSaveVO shipbillOperateLogSaveVO = new ShipbillOperateLogSaveVO();
			shipbillOperateLogSaveVO.setShipbillId(shipbillId);
			shipbillOperateLogSaveVO.setShipbillNo(shipbillId);
			shipbillOperateLogSaveVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_HD_ZB);
			shipbillOperateLogSaveVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_HD_PIC);
			shipbillOperateLogSaveVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_HD_ZB);
			shipbillOperateLogService.addShipbillOperateLogData(shipbillOperateLogSaveVO);

			// 父运单的回单确认
			String fatherShipbillId = shipbillId;
			while (ToolKits.isNotEmpty(fatherShipbillId)) {
				fatherShipbillId = fatherShipbillReceiptConfirm(fatherShipbillId, receiptConfirmVO, mapTransportLogUpdate, date);
			}
			// 运单同步BMS
			if (ToolKits.isNotEmpty(tmsLoadingBillDetailModels) &&
					!DataDictionaryConstant.SHIPBILL_ABNORMAL_STATUS.equals(tmsShipbillHeaderModel.getAbnormalStatus()) ) {
				loadingDetailIds.add(tmsLoadingBillDetailModels.get(0).getId());
			}
			// 更新调度单状态
			Restriction r3 = Restrictions.eq("loadingBillId", tmsLoadingBillDetailModels.get(0).getLoadingBillId());
			Restriction r4 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
			criteriaLoadingBillDetail.setRestriction(Restrictions.and(r3, r4));
			tmsLoadingBillDetailModels = tmsLoadingBillDetailMapper.findByCriteria(criteriaLoadingBillDetail);
			if (ToolKits.isNotEmpty(tmsLoadingBillDetailModels)) {
				List<TmsLoadingBillDetailModel> filterTmsLoadingBillDetailModels = tmsLoadingBillDetailModels.stream().filter(dto -> DataDictionaryConstant.SHIPBILL_STATUS_END.equals(dto.getStatus())).collect(Collectors.toList());
				if (filterTmsLoadingBillDetailModels.size() == tmsLoadingBillDetailModels.size()) {
					// 更新状态为正本回单
					criteriaLoadingHeader.setRestriction(Restrictions.and(r3, r4));
					tmsLoadingBillHeaderMapper.updateMapByCriteria(mapHeaderUpdate, criteriaLoadingHeader);
				}
			}
			MessageUtil.addMessage(new SendMessageDTO(MessageOrderTypeEnum.SHIP_NO.getCode(), MessageTypeEnum.ORIGINAL_RECEIPT.getCode(), Lists.newArrayList(shipbillId)));
		}
		// 运单同步BMS
		if (ToolKits.isNotEmpty(loadingDetailIds)) {
			shipbillCommonService.pushShipbillBmsData(loadingDetailIds);
		}
	}

	// 父运单的正本回单确认
	public String fatherShipbillReceiptConfirm(String shipbillId, OrigReceiptConfirmVO receiptConfirmVO, Map<String, Object> mapTransportLogUpdate, Date date) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		// 回写到主单
		TmsShipbillHeaderModel tmsShipbillHeaderModel = tmsShipbillHeaderMapper.findById(shipbillId, TmsShipbillHeaderModel.class);

		if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getFatherShipbillId()) && !tmsShipbillHeaderModel.getFatherShipbillId().equals(shipbillId)) {
			// 查找父单下面的所有子单
			Criteria criteriaFatherShipbillHeader = Criteria.forClass(TmsShipbillHeaderModel.class);
			Restriction r3 = Restrictions.eq("fatherShipbillId", tmsShipbillHeaderModel.getFatherShipbillId());
			Restriction r4 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
			criteriaFatherShipbillHeader.setRestriction(Restrictions.and(r3, r4));
			List<TmsShipbillHeaderModel> tmsShipbillHeaderModels = tmsShipbillHeaderMapper.findByCriteria(criteriaFatherShipbillHeader);

			if (ToolKits.isNotEmpty(tmsShipbillHeaderModels)) {
				List<TmsShipbillHeaderModel> filterList = tmsShipbillHeaderModels.stream().filter(dto -> DataDictionaryConstant.SHIPBILL_STATUS_END.equals(dto.getStatus())).collect(Collectors.toList());

				// 所有子单都正本回单了
				if (ToolKits.isNotEmpty(filterList) && filterList.size() == tmsShipbillHeaderModels.size()) {
					// 更新装车单明细
					Map<String, Object> mapUpdate = Maps.newHashMap();
					mapUpdate.put("updateperson", user.getNickname());
					mapUpdate.put("updatetime", date);
					mapUpdate.put("status", DataDictionaryConstant.SHIPBILL_STATUS_END);

					Restriction r5 = Restrictions.eq("shipbillId", tmsShipbillHeaderModel.getFatherShipbillId());
					Restriction r6 = Restrictions.eq("enterpriseId", user.getEnterpriseId());

					// 更新运单表
					criteriaFatherShipbillHeader.setRestriction(Restrictions.and(r5, r6));
					tmsShipbillHeaderMapper.updateMapByCriteria(mapUpdate, criteriaFatherShipbillHeader);

					// 运单节点保存
					ShipbillNodeTrackingSaveVO shipbillNodeTrackingSaveVO = new ShipbillNodeTrackingSaveVO();
					shipbillNodeTrackingSaveVO.setShipbillId(tmsShipbillHeaderModel.getFatherShipbillId());
					shipbillNodeTrackingSaveVO.setShipbillNo(tmsShipbillHeaderModel.getFatherShipbillNo());
					if (ToolKits.isNotEmpty(receiptConfirmVO)) {
						shipbillNodeTrackingSaveVO.setNodeDate(receiptConfirmVO.getOrigReceiptReturnTime());
					} else {
						shipbillNodeTrackingSaveVO.setNodeDate(date);
					}
					shipbillNodeTrackingSaveVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_END);
					shipbillNodeTrackingSaveVO.setNodeEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_HD_ZB);
					shipbillNodeTrackingService.addShipbillNodeTrackingData(shipbillNodeTrackingSaveVO);

					// 运单日志保存
					ShipbillOperateLogSaveVO shipbillOperateLogSaveVO = new ShipbillOperateLogSaveVO();
					shipbillOperateLogSaveVO.setShipbillId(tmsShipbillHeaderModel.getFatherShipbillId());
					shipbillOperateLogSaveVO.setShipbillNo(tmsShipbillHeaderModel.getFatherShipbillId());
					shipbillOperateLogSaveVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_HD_ZB);
					shipbillOperateLogSaveVO.setOldStatus(tmsShipbillHeaderModel.getStatus());
					shipbillOperateLogSaveVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_END);
					shipbillOperateLogService.addShipbillOperateLogData(shipbillOperateLogSaveVO);

					if (ToolKits.isNotEmpty(mapTransportLogUpdate)) {
						// 更新订单运输记录表
						Criteria criteriaTransport = Criteria.forClass(TmsShipbillTransLogModel.class);
						criteriaTransport.setRestriction(r5);
						tmsShipbillTransportLogMapper.updateMapByCriteria(mapTransportLogUpdate, criteriaTransport);
					}

					return tmsShipbillHeaderModel.getFatherShipbillId();
				}
			}
		}
		return null;
	}

	/**
	 * 配载运单查询
	 *
	 * @param vo
	 * @return
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<OrigReceiptLoadingShipbillDTO> loadingShipbillQuery(OrigReceiptLoadingShipbillPageVO vo) {
		ToolKits.isParamNull(vo, "配载运单查询请求不为空");
		ToolKits.isParamNull(vo.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(vo.getPageSize(), "每页条数不为空");

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

		if (!user.getUserType().equals(BussinessConstant.USER_TYPE_ZY) && !user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
			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();

		// 订单类型
		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();
		}

		// 添加查询条件
		Criteria criteria = Criteria.forClass(TmsShipbillHeaderModel.class);

		Restriction r1 = Restrictions.in("shipbillId", vo.getShipbillIds().stream().toArray(String[]::new));
		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<TmsShipbillHeaderModel> tmsShipbillHeaderModels = tmsShipbillHeaderMapper.findByCriteria(criteria);

		// 响应对象集合
		List<OrigReceiptLoadingShipbillDTO> receiptLoadingShipbillDTOs = Lists.newArrayList();

		for (TmsShipbillHeaderModel tmsShipbillHeaderModel : tmsShipbillHeaderModels) {
			OrigReceiptLoadingShipbillDTO receiptLoadingShipbillDTO = new OrigReceiptLoadingShipbillDTO();
			BeanUtils.copyProperties(tmsShipbillHeaderModel, receiptLoadingShipbillDTO);
			// 收货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLatitude())) {
				receiptLoadingShipbillDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
			} else {
				receiptLoadingShipbillDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
			}
			// 发货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLatitude())) {
				receiptLoadingShipbillDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
			} else {
				receiptLoadingShipbillDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
			}

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

			// 类型翻译
			receiptLoadingShipbillDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(receiptLoadingShipbillDTO.getOrderType())));
			receiptLoadingShipbillDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(receiptLoadingShipbillDTO.getOrderBusinessType())));
			receiptLoadingShipbillDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(receiptLoadingShipbillDTO.getDeliveryMethodType())));
			receiptLoadingShipbillDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(receiptLoadingShipbillDTO.getTransportType())));
			receiptLoadingShipbillDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(receiptLoadingShipbillDTO.getTemperatureRequirement())));
			receiptLoadingShipbillDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(receiptLoadingShipbillDTO.getShipperType())));
			receiptLoadingShipbillDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(receiptLoadingShipbillDTO.getConsigneeType())));

			// 预计提货时间 estimatedPickupTime
			receiptLoadingShipbillDTO.setEstimatedPickupTime(receiptLoadingShipbillDTO.getEstimatedPickupStartTime());

			// 获取背景颜色和字体颜色
			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(receiptLoadingShipbillDTO.getOrderTypeName()) ? receiptLoadingShipbillDTO.getOrderTypeName() : "")) {
							receiptLoadingShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							receiptLoadingShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

							receiptLoadingShipbillDTO.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(receiptLoadingShipbillDTO.getOrderBusinessTypeName()) ? receiptLoadingShipbillDTO.getOrderBusinessTypeName() : "")) {
							receiptLoadingShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							receiptLoadingShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

							receiptLoadingShipbillDTO.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(receiptLoadingShipbillDTO.getTemperatureRequirementName()) ? receiptLoadingShipbillDTO.getTemperatureRequirementName() : "")) {
							receiptLoadingShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							receiptLoadingShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

							receiptLoadingShipbillDTO.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(receiptLoadingShipbillDTO.getDeliveryMethodTypeName()) ? receiptLoadingShipbillDTO.getDeliveryMethodTypeName() : "")) {
							receiptLoadingShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							receiptLoadingShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

							receiptLoadingShipbillDTO.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(receiptLoadingShipbillDTO.getMemo()) ? receiptLoadingShipbillDTO.getMemo() : "")) {
							receiptLoadingShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							receiptLoadingShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

							receiptLoadingShipbillDTO.setSignConfigId(signconfigPopDTO.getId());

							break Signconfig;
						}
					}
					break;
				}
			}
			receiptLoadingShipbillDTOs.add(receiptLoadingShipbillDTO);
		}

		// 分页重组
		Page<OrigReceiptLoadingShipbillDTO> page = PageUtils.getPage(receiptLoadingShipbillDTOs);
		if (tmsShipbillHeaderModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsShipbillHeaderModel> p0 = (com.github.pagehelper.Page<TmsShipbillHeaderModel>) tmsShipbillHeaderModels;
			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<OrigReceiptLoadingShipBillDetailDTO> loadingShipbillDetail(OrigReceiptLoadingShipbillPageVO 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.in("shipbillId", vo.getShipbillIds().stream().toArray(String[]::new));
		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<OrigReceiptLoadingShipBillDetailDTO> receiptLoadingShipBillDetailDTOs = new ArrayList<>();

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

				receiptLoadingShipBillDetailDTO.setDeliveryPcs(ToolKits.isEmpty(tmsShipbillDetailModel.getDeliveryPcs())? BigDecimal.ZERO:tmsShipbillDetailModel.getDeliveryPcs());
				receiptLoadingShipBillDetailDTO.setDeliveryWeight(NumberUtil.mul(receiptLoadingShipBillDetailDTO.getDeliveryPcs(), tmsShipbillDetailModel.getUnitWeight()));
				receiptLoadingShipBillDetailDTO.setDeliveryVolume(NumberUtil.mul(receiptLoadingShipBillDetailDTO.getDeliveryPcs(), tmsShipbillDetailModel.getUnitVolume()));

				receiptLoadingShipBillDetailDTO.setWeight(NumberUtil.mul(receiptLoadingShipBillDetailDTO.getPcs(), tmsShipbillDetailModel.getUnitWeight()));
				receiptLoadingShipBillDetailDTO.setVolume(NumberUtil.mul(receiptLoadingShipBillDetailDTO.getPcs(), tmsShipbillDetailModel.getUnitVolume()));

				receiptLoadingShipBillDetailDTOs.add(receiptLoadingShipBillDetailDTO);
			}
		}

		// 分页重组
		Page<OrigReceiptLoadingShipBillDetailDTO> page = PageUtils.getPage(receiptLoadingShipBillDetailDTOs);
		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<OrigReceiptLoadingPackageDTO> loadingShipbillPackage(OrigReceiptLoadingShipbillPageVO 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.in("shipbillId", vo.getShipbillIds().stream().toArray(String[]::new));
		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<OrigReceiptLoadingPackageDTO> receiptLoadingPackageDTOs = new ArrayList<>();

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

				receiptLoadingPackageDTOs.add(receiptLoadingPackageDTO);
			}
		}
		// 分页重组
		Page<OrigReceiptLoadingPackageDTO> page = PageUtils.getPage(receiptLoadingPackageDTOs);
		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<PendingOrigReceiptExportShipbillDTO> exportAllShipbill(PendingOrigReceiptExportAllDataVO 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();
		}
		StringBuffer splitSqlBuff = new StringBuffer();
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 拆单类型
			splitSqlBuff.append(" ((t2.split_order_status = 0 and t2.carrier_split_order_type = 1) or t2.carrier_split_order_type =2 or t2.carrier_split_order_type =4) ");
			// 判断是否为部门权限
			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 {
			splitSqlBuff.append(" t2.carrier_split_order_status = 0 ");
			vo.setScheduleType(DataDictionaryConstant.SCHEDULE_TYPE_CYS);
			vo.setCarrierId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
			vo.setCarrierShipbillStatus(DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_DISPATCHED_CHECK);
		}
		List<PendingOrigReceiptExportShipbillDTO> pendingReceiptDTOs = Lists.newArrayList();
		vo.setEnterpriseId(user.getEnterpriseId());
		vo.setSplitSqlBuff(splitSqlBuff.toString());

		List<PendingOrigReceiptShipbillDTO> pendingReceiptShipbillPageDTOs = tmsLoadingBillDetailMapper.exportAllOrigShipbillData(vo);

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

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

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

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

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

			pendingReceiptDTOs.add(pendingReceiptDTO);

		}
		return pendingReceiptDTOs;
	}

	/**
	 * 导出当前页数据
	 *
	 * @param vo
	 * @return
	 */
	@SuppressWarnings("resource")
	@Override
	public List<PendingOrigReceiptExportShipbillDTO> exportCurrentPageShipbill(PendingOrigReceiptExportCurrPgDataVO 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();
		}
		StringBuffer splitSqlBuff = new StringBuffer();
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 拆单类型
			splitSqlBuff.append(" ((t2.split_order_status = 0 and t2.carrier_split_order_type = 1) or t2.carrier_split_order_type =2 or t2.carrier_split_order_type =4) ");
			// 判断是否为部门权限
			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 {
			splitSqlBuff.append(" t2.carrier_split_order_status = 0 ");
			vo.setScheduleType(DataDictionaryConstant.SCHEDULE_TYPE_CYS);
			vo.setCarrierId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
			vo.setCarrierShipbillStatus(DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_DISPATCHED_CHECK);
		}
		List<PendingOrigReceiptExportShipbillDTO> pendingReceiptDTOs = Lists.newArrayList();
		vo.setEnterpriseId(user.getEnterpriseId());
		vo.setSplitSqlBuff(splitSqlBuff.toString());

		PageUtils.startPage(vo.getPageNum(), vo.getPageSize());
		List<PendingOrigReceiptShipbillDTO> pendingReceiptShipbillPageDTOs = tmsLoadingBillDetailMapper.exportCurrentPageOrigShipbillData(vo);

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

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

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

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

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

			pendingReceiptDTOs.add(pendingReceiptDTO);

		}

		Page<PendingOrigReceiptExportShipbillDTO> page = PageUtils.getPage(pendingReceiptDTOs);
		if (pendingReceiptShipbillPageDTOs instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<PendingOrigReceiptShipbillDTO> p0 = (com.github.pagehelper.Page<PendingOrigReceiptShipbillDTO>) pendingReceiptShipbillPageDTOs;
			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
	 */
	@Override
	public List<PendingOrigReceiptExportShipbillDTO> 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<PendingOrigReceiptExportShipbillDTO> pendingReceiptDTOs = Lists.newArrayList();
		List<PendingOrigReceiptShipbillDTO> pendingReceiptShipbillPageDTOs = tmsLoadingBillDetailMapper.querySelectLineOrigShipbillData(shipbillIdList.stream().toArray(String[]::new));

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

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

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

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

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

			pendingReceiptDTOs.add(pendingReceiptDTO);

		}
		return pendingReceiptDTOs;
	}

	/**
	 * 待正本回单打印
	 *
	 * @param pendingOrigReceiptPrintVO
	 * @return
	 */
	@Override
	public Map<String, Object> shipbillPrint(PendingOrigReceiptPrintVO pendingOrigReceiptPrintVO) {
		ToolKits.isParamNull(pendingOrigReceiptPrintVO, "打印请求不为空");
		ToolKits.isParamNull(pendingOrigReceiptPrintVO.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 = { pendingOrigReceiptPrintVO.getShipbillId() };
		List<PendingOrigReceiptShipbillDTO> pendingReceiptShipbillPageDTOs = tmsLoadingBillDetailMapper.querySelectLineOrigShipbillData(shipbills);
		Assert.isTrue(ToolKits.isNotEmpty(pendingReceiptShipbillPageDTOs), "运单【" + pendingOrigReceiptPrintVO.getShipbillId() + "】不存在");

		PendingReceiptPrintHeadDTO printHeadDTO = new PendingReceiptPrintHeadDTO();
		PendingOrigReceiptShipbillDTO loadingBillDetailModel = pendingReceiptShipbillPageDTOs.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.setCarrierTypeName(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", pendingOrigReceiptPrintVO.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;
	}

	@Override
	public PendingReceiptShipbillApprovalDTO getApprovalInfo(ApprovalVO vo) {
		ToolKits.isParamNull(vo, "审批对象查询请求不为空");
		ToolKits.isParamNull(vo.getApprovalObjectId(), "审批对象Id不为空");
		ToolKits.isParamNull(vo.getApprovalBusinessId(), "审批业务ID不为空");

		PendingReceiptShipbillApprovalDTO dto = new PendingReceiptShipbillApprovalDTO();
		dto.setShipbillId(vo.getApprovalObjectId());

		RestMessage<List<ApprovalLogDTO>> resourceBusLog = maindataTmsResource.getBusLog(String.valueOf(vo.getApprovalBusinessId()));
		if (!resourceBusLog.isSuccess()) {
			throw new PrologException("调用审批日志服务失败!");
		}
		dto.setShipbillApprovalLogDTOList(resourceBusLog.getData());

		RestMessage<List<ApprovalNodeSelDTO>> resourceBusDetail = maindataTmsResource.getBusDetail(String.valueOf(vo.getApprovalBusinessId()));
		if (!resourceBusLog.isSuccess()) {
			throw new PrologException("调用审批节点服务失败!");
		}
		dto.setShipbillApprovalNodeDTOList(resourceBusDetail.getData());

		return dto;
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void invalidApproval(ApprovalVO vo) {
		ToolKits.isParamNull(vo, "审批作废请求不为空");
		ToolKits.isParamNull(vo.getApprovalObjectId(), "审批对象Id不为空");
		ToolKits.isParamNull(vo.getApprovalBusinessId(), "审批业务ID不为空");

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

		TmsShipbillHeaderModel tmsShipbillHeaderModel = tmsShipbillHeaderMapper.findById(vo.getApprovalObjectId(), TmsShipbillHeaderModel.class);
		ToolKits.isParamNull(tmsShipbillHeaderModel, "运单ID[" + vo.getApprovalObjectId() + "]有误,查询为空!");

		// 审核业务作废
		RestMessage<Object> restMessage = maindataTmsResource.approvalInvalidExecute(String.valueOf(vo.getApprovalBusinessId()));
		if (!restMessage.isSuccess()) {
			throw new RuntimeException("调用审核作废失败:" + restMessage.getMessage());
		}
		// 运单状态回退
		tmsShipbillHeaderModel.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_HD_ZB);
		tmsShipbillHeaderMapper.update(tmsShipbillHeaderModel);
	}

	@Override
	public void retractApproval(ApprovalVO vo) {
		ToolKits.isParamNull(vo.getApprovalBusinessId(), "审批业务ID不为空");
		// 提交当前审批
		RestMessage<Object> restMessage1 = maindataTmsResource.approvalRetractExecute(vo.getApprovalBusinessId().toString());
		if (!restMessage1.isSuccess()) {
			throw new BizException("调用审核撤回失败");
		}
	}

	@Override
	public void submitApproval(ApprovalVO vo) {
		ToolKits.isParamNull(vo.getApprovalBusinessId(), "审批业务ID不为空");
		// 提交当前审批
		RestMessage<Object> restMessage1 = maindataTmsResource.approvalSubmitExecute(vo.getApprovalBusinessId().toString());
		if (!restMessage1.isSuccess()) {
			throw new BizException("调用审批提交失败");
		}
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void reviewApproval(ApprovalVO vo) {
		ToolKits.isParamNull(vo.getApprovalObjectId(), "运单ID不为空");
		ToolKits.isParamNull(vo.getApprovalBusinessId(), "审批业务ID不为空");
		ToolKits.isParamNull(vo.getApprovalObjectName(), "审批对象名称不为空");
		ToolKits.isParamNull(vo.getApprovalId(), "审批流程ID不为空");
		ToolKits.isParamNull(vo.getNextApproverNodeId(), "下一审批节点ID不为空");
		ToolKits.isParamNull(vo.getNextApprovalOrder(), "下一节点顺序不为空");
		ToolKits.isParamNull(vo.getResult(), "审批结果不为空");
		if (!vo.getResult().equals(DataDictionaryConstant.NODE_APPROVAL_RESULT_PASS)) {
			ToolKits.isParamNull(vo.getApprovalOpinion(), "驳回意见不为空");
		}
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		// 当前时间
		Date date = DateUtils.nowDate();
		// 封装审核所需数据
		ApprovalBusinessNodeVO approvalBusinessNodeVO = new ApprovalBusinessNodeVO();
		approvalBusinessNodeVO.setApprovalObjectName(vo.getApprovalObjectName());
		approvalBusinessNodeVO.setApprovalBusinessId(vo.getApprovalBusinessId());
		approvalBusinessNodeVO.setApprovalId(vo.getApprovalId());
		approvalBusinessNodeVO.setNextApprovalNodeId(vo.getNextApproverNodeId());
		approvalBusinessNodeVO.setNextApprovalOrder(vo.getNextApprovalOrder());
		approvalBusinessNodeVO.setNextApproverRoleId(vo.getNextApproverRoleId());
		approvalBusinessNodeVO.setNextApproverRoleName(vo.getNextApproverRoleName());
		approvalBusinessNodeVO.setNextApproverUserId(vo.getNextApproverUserId());
		approvalBusinessNodeVO.setNextApproverUserName(vo.getNextApproverUserName());
		approvalBusinessNodeVO.setApproverPersonId(user.getUserid());
		approvalBusinessNodeVO.setApproverPersonName(user.getNickname());
		approvalBusinessNodeVO.setApprovalOpinion(ToolKits.isEmpty(vo.getApprovalOpinion()) ? "" : vo.getApprovalOpinion());
		approvalBusinessNodeVO.setApprovalTime(date);
		approvalBusinessNodeVO.setResult(vo.getResult());
		if (CollectionUtil.isNotEmpty(user.getRoles())) {
			approvalBusinessNodeVO.setApproverPersonRoleId(user.getRoles().stream().map(role -> String.valueOf(role)).collect(Collectors.joining(",")));
		}
		approvalBusinessNodeVO.setApproverPersonRoleName("");
		// 节点审批者类型 数据字典 NODE_APPROVER_TYPE 1 角色 2 用户
		approvalBusinessNodeVO.setNodeApproverType(vo.getNodeApproverType());
		// 审批方式 数据字典 NODE_APPROVAL_TYPE: 1 会签 2 或签
		approvalBusinessNodeVO.setNodeApprovalType(vo.getNodeApprovalType());
		// 流程节点审批
		RestMessage<Boolean> restMessage1 = maindataTmsResource.nodeApprovalExecute(approvalBusinessNodeVO);
		if (!restMessage1.isSuccess()) {
			throw new BizException("调用审核失败");
		}
		Boolean isFinish = restMessage1.getData();
		List<String> loadingDetailIds = Lists.newArrayList();
		if (isFinish) {
			// 更新装车单明细
			Map<String, Object> mapUpdate = Maps.newHashMap();
			mapUpdate.put("updateperson", user.getNickname());
			mapUpdate.put("updatetime", date);
			mapUpdate.put("status", DataDictionaryConstant.SHIPBILL_STATUS_END);

			// 更新调度单
			Map<String, Object> mapHeaderUpdate = Maps.newHashMap();
			mapHeaderUpdate.put("updateperson", user.getNickname());
			mapHeaderUpdate.put("updatetime", date);
			mapHeaderUpdate.put("status", DataDictionaryConstant.LOADING_BILL_SHIPBILL_STATUS_END);

			Criteria criteriaLoadingBillDetail = Criteria.forClass(TmsLoadingBillDetailModel.class);
			Criteria criteriaShipbillHeader = Criteria.forClass(TmsShipbillHeaderModel.class);
			Criteria criteriaLoadingHeader = Criteria.forClass(TmsLoadingBillHeaderModel.class);

			Restriction r1 = Restrictions.eq("shipbillId", vo.getApprovalObjectId());
			Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
			Restriction r3 = Restrictions.eq("status", DataDictionaryConstant.SHIPBILL_STATUS_HD_ZB_APPROVAL);
			criteriaLoadingBillDetail.setRestriction(Restrictions.and(r1, r2, r3));
			criteriaLoadingBillDetail.setOrder(Order.newInstance().desc(new String[] { "createtime" }));
			List<TmsLoadingBillDetailModel> tmsLoadingBillDetailModels = tmsLoadingBillDetailMapper.findByCriteria(criteriaLoadingBillDetail);

			tmsLoadingBillDetailMapper.updateMapById(tmsLoadingBillDetailModels.get(0).getId(), mapUpdate, TmsLoadingBillDetailModel.class);

			// 更新运单表
			criteriaShipbillHeader.setRestriction(Restrictions.and(r1, r2));
			tmsShipbillHeaderMapper.updateMapByCriteria(mapUpdate, criteriaShipbillHeader);
			// 运单节点保存
			ShipbillNodeTrackingSaveVO shipbillNodeTrackingSaveVO = new ShipbillNodeTrackingSaveVO();
			shipbillNodeTrackingSaveVO.setShipbillId(vo.getApprovalObjectId());
			shipbillNodeTrackingSaveVO.setShipbillNo(vo.getApprovalObjectId());
			shipbillNodeTrackingSaveVO.setNodeDate(date);
			shipbillNodeTrackingSaveVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_END);
			shipbillNodeTrackingSaveVO.setNodeEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_HD_ZB);
			shipbillNodeTrackingService.addShipbillNodeTrackingData(shipbillNodeTrackingSaveVO);

			// 运单日志保存
			ShipbillOperateLogSaveVO shipbillOperateLogSaveVO = new ShipbillOperateLogSaveVO();
			shipbillOperateLogSaveVO.setShipbillId(vo.getApprovalObjectId());
			shipbillOperateLogSaveVO.setShipbillNo(vo.getApprovalObjectId());
			shipbillOperateLogSaveVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_HD_ZB);
			shipbillOperateLogSaveVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_HD_ZB);
			shipbillOperateLogSaveVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_END);
			shipbillOperateLogService.addShipbillOperateLogData(shipbillOperateLogSaveVO);

			String fatherShipbillId = vo.getApprovalObjectId();
			while (ToolKits.isNotEmpty(fatherShipbillId)) {
				fatherShipbillId = fatherShipbillReceiptConfirm(fatherShipbillId, null, null, date);
			}
			if (!DataDictionaryConstant.SHIPBILL_ABNORMAL_STATUS.equals(tmsLoadingBillDetailModels.get(0).getAbnormalStatus())) {
				loadingDetailIds.add(tmsLoadingBillDetailModels.get(0).getId());
			}
			// 更新调度单状态
			Restriction r4 = Restrictions.eq("loadingBillId", tmsLoadingBillDetailModels.get(0).getLoadingBillId());
			Restriction r5 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
			criteriaLoadingBillDetail.setRestriction(Restrictions.and(r4, r5));
			tmsLoadingBillDetailModels = tmsLoadingBillDetailMapper.findByCriteria(criteriaLoadingBillDetail);
			if (ToolKits.isNotEmpty(tmsLoadingBillDetailModels)) {
				List<TmsLoadingBillDetailModel> filterTmsLoadingBillDetailModels = tmsLoadingBillDetailModels.stream().filter(dto -> DataDictionaryConstant.SHIPBILL_STATUS_END.equals(dto.getStatus())).collect(Collectors.toList());
				if (filterTmsLoadingBillDetailModels.size() == tmsLoadingBillDetailModels.size()) {
					// 更新状态为正本回单
					criteriaLoadingHeader.setRestriction(Restrictions.and(r4, r5));
					tmsLoadingBillHeaderMapper.updateMapByCriteria(mapHeaderUpdate, criteriaLoadingHeader);
				}
			}

			MessageUtil.addMessage(new SendMessageDTO(MessageOrderTypeEnum.SHIP_NO.getCode(), MessageTypeEnum.ORIGINAL_RECEIPT.getCode(), Lists.newArrayList(vo.getApprovalObjectId())));
		}

		// 运单同步BMS
		if (ToolKits.isNotEmpty(loadingDetailIds)) {
			shipbillCommonService.pushShipbillBmsData(loadingDetailIds);
		}
	}

	// 正本回单匹配审批流程
	public Boolean approvalOpen(TmsLoadingBillDetailModel model, Integer approvalFlowType, UserEntity user) {
		// 封装判断所需数据
		ApprovalOpenVO approvalOpenVO = new ApprovalOpenVO();
		approvalOpenVO.setApprovalFlowType(approvalFlowType);
		approvalOpenVO.setApprovalObjectId(model.getShipbillId());
		approvalOpenVO.setApprovalObjectCode(model.getShipbillNo());
		approvalOpenVO.setApprovalObjectName(model.getShipbillNo());
		approvalOpenVO.setInitiatedUserId(user.getUserid());
		approvalOpenVO.setInitiatedUserName(user.getNickname());

		// 配送方式
		approvalOpenVO.setDeliveryMethodType(model.getDeliveryMethodType());
		// 发货方类型
		approvalOpenVO.setShipperType(model.getShipperType());
		// 发货方单位ID
		approvalOpenVO.setShipperUnitId(model.getShipperUnitId());
		// 收货方类型
		approvalOpenVO.setConsigneeType(model.getConsigneeType());
		// 收货方单位ID
		approvalOpenVO.setConsigneeUnitId(model.getConsigneeUnitId());
		// 订单类型
		approvalOpenVO.setOrderType(model.getOrderType());
		// 订单业务类型
		approvalOpenVO.setOrderBusinessType(model.getOrderBusinessType());
		// 运输模式
		approvalOpenVO.setTransportType(model.getTransportType());
		// 温度要求
		approvalOpenVO.setTemperatureRequirement(model.getTemperatureRequirement());
		// 货主ID
		approvalOpenVO.setCargoOwnerId(model.getCargoOwnerId());
		// 部门ID
		approvalOpenVO.setDepartmentId(model.getDepartmentId());

		RestMessage<Boolean> restMessage1 = maindataTmsResource.openExecute(approvalOpenVO);
		if (!restMessage1.isSuccess()) {
			throw new RuntimeException("调用maindata服务是否开启审批流接口失败:" + restMessage1.getMessage());
		}
		return restMessage1.getData();
	}

	/**
	 * 待正本回单查询回单图片
	 */
	@Override
	public PendingOrigReceiptPictureDTO listPendingOrigReceiptPictureData(List<String> shipbillIds) {
		ToolKits.isParamNull(shipbillIds, "请求参数不为空");

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

		Criteria criteria = Criteria.forClass(ShipbillNodeTracking.class);
		Restriction r1 = Restrictions.in(ShipbillNodeTracking::getShipbillId, shipbillIds.stream().toArray(String[]::new));
		Restriction r2 = Restrictions.eq(ShipbillNodeTracking::getEnterpriseId, user.getEnterpriseId());
		Restriction r3 = Restrictions.in(ShipbillNodeTracking::getStatus, new Integer[] { DataDictionaryConstant.SHIPBILL_STATUS_HD_PIC_APPROVAL, DataDictionaryConstant.SHIPBILL_STATUS_HD_ZB });
		criteria.setRestriction(Restrictions.and(r1, r2, r3));
		List<ShipbillNodeTracking> shipbillNodeTrackings = tmsShipbillNodeTrackingMapper.findByCriteria(criteria);

		List<String> picUrlList = Lists.newArrayList();
		for (ShipbillNodeTracking shipbillNodeTracking : shipbillNodeTrackings) {
			if (ToolKits.isEmpty(shipbillNodeTracking.getPicUrl())) {
				continue;
			}

			String[] str = shipbillNodeTracking.getPicUrl().split(",");
			for (int i = 0; i < str.length; i++) {
				picUrlList.add(str[i]);
			}
		}

		PendingOrigReceiptPictureDTO pendingOrigReceiptPictureDTO = new PendingOrigReceiptPictureDTO();
		pendingOrigReceiptPictureDTO.setPicUrls(ToolKits.isEmpty(picUrlList) ? null : picUrlList.stream().collect(Collectors.joining(",")));

		return pendingOrigReceiptPictureDTO;
	}
}
