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

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import cn.hutool.core.util.StrUtil;
import com.prolog.rdc.tms.model.dto.message.SendMessageDTO;
import com.prolog.rdc.tms.model.entity.*;
import com.prolog.rdc.tms.model.enums.MessageOrderTypeEnum;
import com.prolog.rdc.tms.model.enums.MessageTypeEnum;
import com.prolog.rdc.tms.util.ConvertorUtil;
import com.prolog.rdc.tms.util.MessageUtil;
import org.apache.poi.ss.formula.functions.T;
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 org.springframework.web.bind.annotation.RequestBody;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
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.PrintConstant;
import com.prolog.rdc.tms.constant.SeriaNnumberConstant;
import com.prolog.rdc.tms.constant.StatusConstant;
import com.prolog.rdc.tms.dao.mapper.TmsAppointmentDetailMapper;
import com.prolog.rdc.tms.dao.mapper.TmsAppointmentHeaderMapper;
import com.prolog.rdc.tms.dao.mapper.TmsLoadingBillDetailMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillDetailMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillHeaderMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillPackageMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillTransportLogMapper;
import com.prolog.rdc.tms.model.dto.AppLoadingPackageDTO;
import com.prolog.rdc.tms.model.dto.AppLoadingShipBillDetailDTO;
import com.prolog.rdc.tms.model.dto.AppLoadingShipbillDTO;
import com.prolog.rdc.tms.model.dto.AppointmentConsigneeQueryDTO;
import com.prolog.rdc.tms.model.dto.AppointmentExportShipbillDTO;
import com.prolog.rdc.tms.model.dto.AppointmentLoadingBillQueryDTO;
import com.prolog.rdc.tms.model.dto.AppointmentQueryDTO;
import com.prolog.rdc.tms.model.dto.AppointmentShipperQueryDTO;
import com.prolog.rdc.tms.model.dto.AppointmentTimesDTO;
import com.prolog.rdc.tms.model.dto.AppointmentWeekDTO;
import com.prolog.rdc.tms.model.dto.BranchAppointmentInfoDTO;
import com.prolog.rdc.tms.model.dto.PickUpAppointmentDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.SignconfigPopDTO;
import com.prolog.rdc.tms.model.dto.basicData.TmsBaseBranchApTimeDTO;
import com.prolog.rdc.tms.model.dto.basicData.TmsBaseBranchDTO;
import com.prolog.rdc.tms.model.dto.print.AppointmentPrintDTO;
import com.prolog.rdc.tms.model.dto.print.AppointmentPrintDataDTO;
import com.prolog.rdc.tms.model.dto.print.AppointmentPrintDetailDTO;
import com.prolog.rdc.tms.model.dto.print.AppointmentPrintHeadDTO;
import com.prolog.rdc.tms.model.dto.print.PrinterDTO;
import com.prolog.rdc.tms.model.vo.AppConfirmShipbillVO;
import com.prolog.rdc.tms.model.vo.AppLoadingShipbillPageVO;
import com.prolog.rdc.tms.model.vo.AppointmentAdsQueryVO;
import com.prolog.rdc.tms.model.vo.AppointmentHeadQueryVO;
import com.prolog.rdc.tms.model.vo.AppointmentPrintVO;
import com.prolog.rdc.tms.model.vo.AppointmentQueryVO;
import com.prolog.rdc.tms.model.vo.PickUpAppointmentConfirmVO;
import com.prolog.rdc.tms.model.vo.PickUpAppointmentShipbillVO;
import com.prolog.rdc.tms.model.vo.PickUpAppointmentVO;
import com.prolog.rdc.tms.model.vo.ShipbillOperateLogSaveVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.SignconfigPopVO;
import com.prolog.rdc.tms.rmi.feign.MaindataFeign;
import com.prolog.rdc.tms.service.AppointmentService;
import com.prolog.rdc.tms.service.ShipbillOperateLogService;
import com.prolog.rdc.tms.util.PrinterHelper;
import com.prolog.rdc.tms.util.PublicMethods;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;

/**
 * 
 *
 * 运输管理-待预约实现层
 *
 * @className :AppointmentServiceImpl
 * @author :fanzw
 * @creationTime :2022/11/17
 * @description :
 *
 * @modifier :fanzw
 * @modifyTime :2022/11/17
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@Service
public class AppointmentServiceImpl implements AppointmentService {

	@Autowired
	private TmsShipbillHeaderMapper tmsShipbillHeaderMapper;

	@Autowired
	private TmsShipbillDetailMapper tmsShipbillDetailMapper;

	@Autowired
	private TmsShipbillPackageMapper tmsShipbillPackageMapper;

	@Autowired
	private MaindataFeign maindataTmsResource;

	@Autowired
	private TmsLoadingBillDetailMapper tmsLoadingBillDetailMapper;

	@Autowired
	private TmsAppointmentHeaderMapper tmsAppointmentHeaderMapper;

	@Autowired
	private TmsAppointmentDetailMapper tmsAppointmentDetailMapper;

	@Autowired
	private ShipbillOperateLogService shipbillOperateLogService;

	@Autowired
	private TmsShipbillTransportLogMapper tmsShipbillTransportLogMapper;

	@Autowired
	private PrinterHelper printerHelper;

	@Autowired
	private ConvertorUtil convertorUtil;

	/**
	 * 待预约运单模式分页查询
	 *
	 * @param appointmentQueryVO
	 * @return
	 */
	@SuppressWarnings("resource")
	public Page<AppointmentQueryDTO> pageAppointmentShipbill(AppointmentQueryVO appointmentQueryVO) {

		ToolKits.isParamNull(appointmentQueryVO, "待预约运单模式分页查询请求不为空");
		ToolKits.isParamNull(appointmentQueryVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(appointmentQueryVO.getPageSize(), "每页条数不为空");

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

		List<SignconfigPopDTO> data8 = Lists.newArrayList();
		// 数据字典翻译数据集合
		List<SysRefdatadModel> dicData = convertorUtil.getDictionary(new String[] { DataDictionaryConstant.DELIVERY_METHOD_TYPE, // 配送方式
				DataDictionaryConstant.TRANSPORT_TYPE, // 运输类型(运输模式)
				DataDictionaryConstant.TEMPERATURE_REQUIREMENT, // 温度要求
				DataDictionaryConstant.SHIPPER_TYPE, // 发货方类型
				DataDictionaryConstant.CONSIGNEE_TYPE, // 收货方类型
				DataDictionaryConstant.ORDER_TYPE, // 订单类型
				DataDictionaryConstant.LINE_DIRECTION, // 线路方向
				DataDictionaryConstant.SHIPBILL_STATUS, // 运单状态
				DataDictionaryConstant.TRANSPORT_STATUS, // 运输状态
				DataDictionaryConstant.ABNORMAL_STATUS, // 异常状态
				DataDictionaryConstant.SCAN_STATUS, // 扫描状态
				DataDictionaryConstant.LINE_CARRIER_TYPE, // 承运方类型
				DataDictionaryConstant.ORDER_BUSINESS_TYPE // 订单业务类型
		});
		// 标记配置
		SignconfigPopVO signconfigPopVO = new SignconfigPopVO();
		RestMessage<List<SignconfigPopDTO>> restMessage8 = maindataTmsResource.getSignConfig(signconfigPopVO);
		if (!restMessage8.isSuccess()) {
			throw new RuntimeException("标记配置查询失败!");
		} else {
			data8 = restMessage8.getData();
		}

		appointmentQueryVO.setUserType(user.getUserType());
		appointmentQueryVO.setEnterpriseId(user.getEnterpriseId());
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 判断是否为部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				appointmentQueryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
				appointmentQueryVO.setIsDept(StatusConstant.IS_DEPT_YES);
			} else {
				appointmentQueryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
				appointmentQueryVO.setIsDept(StatusConstant.IS_DEPT_NO);
				// 货主
				appointmentQueryVO.setConsignors(user.getConsignors().stream().toArray(Long[]::new));
				// 客户
				appointmentQueryVO.setCustomers(user.getCustomers().stream().toArray(Long[]::new));
				// 供应商
				appointmentQueryVO.setSuppliers(user.getSuppliers().stream().toArray(Long[]::new));
				// 仓库
				appointmentQueryVO.setWsarehouses(user.getWarehouses().stream().toArray(Long[]::new));
			}
		} else {
			appointmentQueryVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		}
		List<AppointmentQueryDTO> appointmentQueryDTOs = Lists.newArrayList();

		PageUtils.startPage(appointmentQueryVO.getPageNum(), appointmentQueryVO.getPageSize());
		List<AppointmentQueryDTO> appointmentQueryDTOS = tmsLoadingBillDetailMapper.queryAppointmentShipbill(appointmentQueryVO);

		// 行号
		int id = 1;
		for (AppointmentQueryDTO appointmentDTO : appointmentQueryDTOS) {
			AppointmentQueryDTO appointmentQueryDTO = new AppointmentQueryDTO();
			BeanUtils.copyProperties(appointmentDTO, appointmentQueryDTO);

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

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

			// 类型翻译
			appointmentQueryDTO.setOrderTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ORDER_TYPE, String.valueOf(appointmentDTO.getOrderType())));
			appointmentQueryDTO.setOrderBusinessTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ORDER_BUSINESS_TYPE, String.valueOf(appointmentDTO.getOrderBusinessType())));
			appointmentQueryDTO.setDeliveryMethodTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.DELIVERY_METHOD_TYPE, String.valueOf(appointmentDTO.getDeliveryMethodType())));
			appointmentQueryDTO.setTransportTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TRANSPORT_TYPE, String.valueOf(appointmentDTO.getTransportType())));
			appointmentQueryDTO.setTemperatureRequirementName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TEMPERATURE_REQUIREMENT, String.valueOf(appointmentDTO.getTemperatureRequirement())));
			appointmentQueryDTO.setShipperTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.SHIPPER_TYPE, String.valueOf(appointmentDTO.getShipperType())));
			appointmentQueryDTO.setConsigneeTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.CONSIGNEE_TYPE, String.valueOf(appointmentDTO.getConsigneeType())));
			appointmentQueryDTO.setStatusName(ConvertorUtil.getName(dicData, DataDictionaryConstant.SHIPBILL_STATUS, String.valueOf(appointmentDTO.getStatus())));
			appointmentQueryDTO.setTransportStatusName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TRANSPORT_STATUS, String.valueOf(appointmentDTO.getTransportStatus())));
			appointmentQueryDTO.setAbnormalStatusName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ABNORMAL_STATUS, String.valueOf(appointmentDTO.getAbnormalStatus())));
			appointmentQueryDTO.setScanStatusName(ConvertorUtil.getName(dicData, DataDictionaryConstant.SCAN_STATUS, String.valueOf(appointmentDTO.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(appointmentQueryDTO.getOrderTypeName()) ? appointmentQueryDTO.getOrderTypeName() : "")) {
							appointmentQueryDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							appointmentQueryDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

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

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

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

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

							appointmentQueryDTO.setSignConfigId(signconfigPopDTO.getId());

							break Signconfig;
						}
					}
					break;
				}
			}
			// 承运方类型
			appointmentQueryDTO.setCarrierTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.LINE_CARRIER_TYPE, String.valueOf(appointmentDTO.getCarrierType())));
			// 调度单号
			appointmentQueryDTO.setLoadingBillNo(appointmentDTO.getLoadingBillNo());
			// 承运方名称
			appointmentQueryDTO.setCarrierName(appointmentDTO.getCarrierName());
			// 送货员姓名
			appointmentQueryDTO.setDeliverymanName(appointmentDTO.getDeliverymanName());
			// 车牌号
			appointmentQueryDTO.setVehiclePlateNumber(appointmentDTO.getVehiclePlateNumber());

			// 仓库信息
			appointmentQueryDTO.setBranchId(appointmentDTO.getShipperId());
			appointmentQueryDTO.setBranchCode(appointmentDTO.getShipperCode());
			appointmentQueryDTO.setBranchName(appointmentDTO.getShipperName());

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

			appointmentQueryDTOs.add(appointmentQueryDTO);

		}
		// 分页重组
		Page<AppointmentQueryDTO> page = PageUtils.getPage(appointmentQueryDTOs);
		if (appointmentQueryDTOS instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<AppointmentQueryDTO> p0 = (com.github.pagehelper.Page<AppointmentQueryDTO>) appointmentQueryDTOS;
			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 appointmentQueryVO
	 * @return
	 */
	@Override
	public Page<AppointmentLoadingBillQueryDTO> pageAppointmentLoadingBill(AppointmentQueryVO appointmentQueryVO) {
		ToolKits.isParamNull(appointmentQueryVO, "待预约派车单模式分页查询请求不为空");
		ToolKits.isParamNull(appointmentQueryVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(appointmentQueryVO.getPageSize(), "每页条数不为空");
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		// 数据字典翻译数据集合
		List<Map<String, Object>> data1 = Lists.newArrayList();
		// 订单类型
		RestMessage<List<Map<String, Object>>> restMessage1 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LOADING_BILL_STATUS, null, null, null);
		if (!restMessage1.isSuccess()) {
			throw new RuntimeException("订单类型翻译失败!");
		} else {
			data1 = restMessage1.getData();
		}
		appointmentQueryVO.setUserType(user.getUserType());
		appointmentQueryVO.setEnterpriseId(user.getEnterpriseId());
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 判断是否为部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				appointmentQueryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
				appointmentQueryVO.setIsDept(StatusConstant.IS_DEPT_YES);
			} else {
				appointmentQueryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
				appointmentQueryVO.setIsDept(StatusConstant.IS_DEPT_NO);
				// 货主
				appointmentQueryVO.setConsignors(user.getConsignors().stream().toArray(Long[]::new));
				// 客户
				appointmentQueryVO.setCustomers(user.getCustomers().stream().toArray(Long[]::new));
				// 供应商
				appointmentQueryVO.setSuppliers(user.getSuppliers().stream().toArray(Long[]::new));
				// 仓库
				appointmentQueryVO.setWsarehouses(user.getWarehouses().stream().toArray(Long[]::new));
			}
		} else {
			appointmentQueryVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		}
		PageUtils.startPage(appointmentQueryVO.getPageNum(), appointmentQueryVO.getPageSize());
		List<AppointmentLoadingBillQueryDTO> appointmentLoadingBillQueryDTOS = tmsLoadingBillDetailMapper.queryAppointmentLoadingBill(appointmentQueryVO);
		for (AppointmentLoadingBillQueryDTO appointmentLoadingBillQueryDTO : appointmentLoadingBillQueryDTOS) {
			appointmentLoadingBillQueryDTO.setStatusName(PublicMethods.change(data1, String.valueOf(appointmentLoadingBillQueryDTO.getStatus())));
			appointmentLoadingBillQueryDTO.setBranchId(appointmentLoadingBillQueryDTO.getShipperId());
			appointmentLoadingBillQueryDTO.setBranchCode(appointmentLoadingBillQueryDTO.getShipperCode());
			appointmentLoadingBillQueryDTO.setBranchName(appointmentLoadingBillQueryDTO.getShipperName());
			appointmentLoadingBillQueryDTO.setEstimatedDeliveryTime(formatDt(appointmentLoadingBillQueryDTO.getEstimatedDeliveryStartTime(), appointmentLoadingBillQueryDTO.getEstimatedDeliveryEndTime()));
			appointmentLoadingBillQueryDTO.setEstimatedPickupTime(formatDt(appointmentLoadingBillQueryDTO.getEstimatedPickupStartTime(), appointmentLoadingBillQueryDTO.getEstimatedPickupEndTime()));
			// 始发地
			appointmentLoadingBillQueryDTO.setShipperProvinceCityDistrict(appointmentLoadingBillQueryDTO.getShipperProvinceName() + appointmentLoadingBillQueryDTO.getShipperCityName() + appointmentLoadingBillQueryDTO.getShipperDistrictName());
			// 目的地
			appointmentLoadingBillQueryDTO.setConsigneeProvinceCityDistrict(appointmentLoadingBillQueryDTO.getConsigneeProvinceName() + appointmentLoadingBillQueryDTO.getConsigneeCityName() + appointmentLoadingBillQueryDTO.getConsigneeDistrictName());

		}
		// 分页重组
		Page<AppointmentLoadingBillQueryDTO> page = PageUtils.getPage(appointmentLoadingBillQueryDTOS);
		return page;
	}

	/**
	 * 待预约高级查询
	 *
	 * @param appointmentAdsQueryVO
	 * @return
	 */
	@SuppressWarnings("resource")
	public Page<AppointmentQueryDTO> pageAdvanced(@RequestBody AppointmentAdsQueryVO appointmentAdsQueryVO) {
		ToolKits.isParamNull(appointmentAdsQueryVO, "待预约高级查询请求不为空");
		ToolKits.isParamNull(appointmentAdsQueryVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(appointmentAdsQueryVO.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();
		}
		appointmentAdsQueryVO.setUserType(user.getUserType());
		appointmentAdsQueryVO.setEnterpriseId(user.getEnterpriseId());
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 判断是否为部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				appointmentAdsQueryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
				appointmentAdsQueryVO.setIsDept(StatusConstant.IS_DEPT_YES);
			} else {
				appointmentAdsQueryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
				appointmentAdsQueryVO.setIsDept(StatusConstant.IS_DEPT_NO);
				// 货主
				appointmentAdsQueryVO.setConsignors(user.getConsignors().stream().toArray(Long[]::new));
				// 客户
				appointmentAdsQueryVO.setCustomers(user.getCustomers().stream().toArray(Long[]::new));
				// 供应商
				appointmentAdsQueryVO.setSuppliers(user.getSuppliers().stream().toArray(Long[]::new));
				// 仓库
				appointmentAdsQueryVO.setWsarehouses(user.getWarehouses().stream().toArray(Long[]::new));
			}
		} else {
			appointmentAdsQueryVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		}
		List<AppointmentQueryDTO> appointmentQueryDTOs = Lists.newArrayList();
		// 获取高级查询配置
		String conditions = null;
		RestMessage<String> restMessageAdvancedCfg = maindataTmsResource.getQueryConfiguration(DataDictionaryConstant.BIZ_TYPE_APPOINTMENT);
		if (!restMessageAdvancedCfg.isSuccess()) {
			throw new RuntimeException("获取高级查询配置失败!");
		} else {
			conditions = restMessageAdvancedCfg.getData();
		}
		appointmentAdsQueryVO.setSql(conditions);

		PageUtils.startPage(appointmentAdsQueryVO.getPageNum(), appointmentAdsQueryVO.getPageSize());
		List<AppointmentQueryDTO> appointmentQueryDTOS = tmsLoadingBillDetailMapper.queryAppointmentAdvanced(appointmentAdsQueryVO);

		// 行号
		int id = 1;
		for (AppointmentQueryDTO appointmentDTO : appointmentQueryDTOS) {
			AppointmentQueryDTO appointmentQueryDTO = new AppointmentQueryDTO();
			BeanUtils.copyProperties(appointmentDTO, appointmentQueryDTO);

			appointmentQueryDTO.setId(id);
			id++;

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

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

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

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

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

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

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

							appointmentQueryDTO.setSignConfigId(signconfigPopDTO.getId());

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

			appointmentQueryDTOs.add(appointmentQueryDTO);

		}
		// 分页重组
		Page<AppointmentQueryDTO> page = PageUtils.getPage(appointmentQueryDTOs);
		if (appointmentQueryDTOS instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<AppointmentQueryDTO> p0 = (com.github.pagehelper.Page<AppointmentQueryDTO>) appointmentQueryDTOS;
			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 appointmentQueryVO
	 * @return
	 */
	@SuppressWarnings("resource")
	public Page<AppointmentConsigneeQueryDTO> pageAppointmentConsignee(@RequestBody AppointmentQueryVO appointmentQueryVO) {
		ToolKits.isParamNull(appointmentQueryVO, "待预约收货方模式分页查询请求不为空");
		ToolKits.isParamNull(appointmentQueryVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(appointmentQueryVO.getPageSize(), "每页条数不为空");

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

		appointmentQueryVO.setUserType(user.getUserType());
		appointmentQueryVO.setEnterpriseId(user.getEnterpriseId());
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 判断是否为部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				appointmentQueryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
				appointmentQueryVO.setIsDept(StatusConstant.IS_DEPT_YES);
			} else {
				appointmentQueryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
				appointmentQueryVO.setIsDept(StatusConstant.IS_DEPT_NO);
				// 货主
				appointmentQueryVO.setConsignors(user.getConsignors().stream().toArray(Long[]::new));
				// 客户
				appointmentQueryVO.setCustomers(user.getCustomers().stream().toArray(Long[]::new));
				// 供应商
				appointmentQueryVO.setSuppliers(user.getSuppliers().stream().toArray(Long[]::new));
				// 仓库
				appointmentQueryVO.setWsarehouses(user.getWarehouses().stream().toArray(Long[]::new));
			}
		} else {
			appointmentQueryVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		}

		PageUtils.startPage(appointmentQueryVO.getPageNum(), appointmentQueryVO.getPageSize());
		List<AppointmentConsigneeQueryDTO> appointmentConsigneeQueryDTOS = tmsLoadingBillDetailMapper.queryAppointmentConsignee(appointmentQueryVO);

		// 行号
		int id = 1;
		for (AppointmentConsigneeQueryDTO dto : appointmentConsigneeQueryDTOS) {
			// 设置行id
			dto.setId(id);
			dto.setCount(dto.getCount());

			dto.setEstimatedDeliveryTime(formatDt(dto.getEstimatedDeliveryStartTime(), dto.getEstimatedDeliveryEndTime()));
			dto.setEstimatedPickupTime(formatDt(dto.getEstimatedPickupStartTime(), dto.getEstimatedPickupEndTime()));
			// 始发地
			dto.setShipperProvinceCityDistrict(dto.getShipperProvinceName() + dto.getShipperCityName() + dto.getShipperDistrictName());
			// 目的地
			dto.setConsigneeProvinceCityDistrict(dto.getConsigneeProvinceName() + dto.getConsigneeCityName() + dto.getConsigneeDistrictName());
			// 行号自增长
			id++;

			// 仓库信息
			dto.setBranchId(dto.getShipperId());
			dto.setBranchCode(dto.getShipperCode());
			dto.setBranchName(dto.getShipperName());
		}

		// 分页重组
		Page<AppointmentConsigneeQueryDTO> page = PageUtils.getPage(appointmentConsigneeQueryDTOS);
		if (appointmentConsigneeQueryDTOS instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<AppointmentConsigneeQueryDTO> p0 = (com.github.pagehelper.Page<AppointmentConsigneeQueryDTO>) appointmentConsigneeQueryDTOS;
			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 appointmentQueryVO
	 * @return
	 */
	@SuppressWarnings("resource")
	public Page<AppointmentShipperQueryDTO> pageAppointmentShipper(AppointmentQueryVO appointmentQueryVO) {
		ToolKits.isParamNull(appointmentQueryVO, "待预约收货方模式分页查询请求不为空");
		ToolKits.isParamNull(appointmentQueryVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(appointmentQueryVO.getPageSize(), "每页条数不为空");

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

		appointmentQueryVO.setUserType(user.getUserType());
		appointmentQueryVO.setEnterpriseId(user.getEnterpriseId());
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 判断是否为部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				appointmentQueryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
				appointmentQueryVO.setIsDept(StatusConstant.IS_DEPT_YES);
			} else {
				appointmentQueryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
				appointmentQueryVO.setIsDept(StatusConstant.IS_DEPT_NO);
				// 货主
				appointmentQueryVO.setConsignors(user.getConsignors().stream().toArray(Long[]::new));
				// 客户
				appointmentQueryVO.setCustomers(user.getCustomers().stream().toArray(Long[]::new));
				// 供应商
				appointmentQueryVO.setSuppliers(user.getSuppliers().stream().toArray(Long[]::new));
				// 仓库
				appointmentQueryVO.setWsarehouses(user.getWarehouses().stream().toArray(Long[]::new));
			}
		} else {
			appointmentQueryVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		}

		PageUtils.startPage(appointmentQueryVO.getPageNum(), appointmentQueryVO.getPageSize());
		List<AppointmentShipperQueryDTO> appointmentShipperQueryDTOS = tmsLoadingBillDetailMapper.queryAppointmentShipper(appointmentQueryVO);

		// 行号
		int id = 1;
		for (AppointmentShipperQueryDTO dto : appointmentShipperQueryDTOS) {
			// 设置行id
			dto.setId(id);
			dto.setCount(dto.getCount());
			dto.setEstimatedPickupTime(formatDt(dto.getEstimatedPickupStartTime(), dto.getEstimatedPickupEndTime()));
			// 始发地
			dto.setShipperProvinceCityDistrict(dto.getShipperProvinceName() + dto.getShipperCityName() + dto.getShipperDistrictName());
			// 行号自增长
			id++;

			// 仓库信息
			dto.setBranchId(dto.getShipperId());
			dto.setBranchCode(dto.getShipperCode());
			dto.setBranchName(dto.getShipperName());
		}

		// 分页重组
		Page<AppointmentShipperQueryDTO> page = PageUtils.getPage(appointmentShipperQueryDTOS);
		if (appointmentShipperQueryDTOS instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<AppointmentShipperQueryDTO> p0 = (com.github.pagehelper.Page<AppointmentShipperQueryDTO>) appointmentShipperQueryDTOS;
			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 shipbillPageVO
	 * @return
	 */
	@SuppressWarnings("resource")
	public Page<AppLoadingShipbillDTO> loadingShipbillQuery(AppLoadingShipbillPageVO shipbillPageVO) {
		ToolKits.isParamNull(shipbillPageVO, "配载运单查询请求不为空");
		ToolKits.isParamNull(shipbillPageVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(shipbillPageVO.getPageSize(), "每页条数不为空");

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

		if (!user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)
				&& !user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)
				&& !user.getUserType().equals(BussinessConstant.USER_TYPE_GYS)) {
			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(TmsShipbillHeaderModel::getShipbillId, shipbillPageVO.getShipbillIds().stream().toArray(String[]::new));
		Restriction r2 = Restrictions.eq(TmsShipbillHeaderModel::getEnterpriseId, user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));

		PageUtils.startPage(shipbillPageVO.getPageNum(), shipbillPageVO.getPageSize());
		List<TmsShipbillHeaderModel> tmsShipbillHeaderModels = tmsShipbillHeaderMapper.findByCriteria(criteria);

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

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

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

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

			// 预计提货时间 estimatedPickupTime
			appLoadingShipbillDTO.setEstimatedPickupTime(appLoadingShipbillDTO.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(appLoadingShipbillDTO.getOrderTypeName()) ? appLoadingShipbillDTO.getOrderTypeName() : "")) {
							appLoadingShipbillDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							appLoadingShipbillDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

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

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

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

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

							appLoadingShipbillDTO.setSignConfigId(signconfigPopDTO.getId());

							break Signconfig;
						}
					}
					break;
				}
			}
			appLoadingShipbillDTOs.add(appLoadingShipbillDTO);
		}

		// 分页重组
		Page<AppLoadingShipbillDTO> page = PageUtils.getPage(appLoadingShipbillDTOs);
		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 shipbillVO
	 * @return
	 */
	public List<AppLoadingShipbillDTO> confirmShipbillQuery(AppConfirmShipbillVO shipbillVO) {
		ToolKits.isParamNull(shipbillVO, "预约确认运单查询请求不为空");

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

		if (!user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)
				&& !user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)
				&& !user.getUserType().equals(BussinessConstant.USER_TYPE_GYS)) {
			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(TmsShipbillHeaderModel::getShipbillId, shipbillVO.getShipbillIds().stream().toArray(String[]::new));
		Restriction r2 = Restrictions.eq(TmsShipbillHeaderModel::getEnterpriseId, user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));

		List<TmsShipbillHeaderModel> tmsShipbillHeaderModels = tmsShipbillHeaderMapper.findByCriteria(criteria);

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

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

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

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

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

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

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

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

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

							appLoadingShipbillDTO.setSignConfigId(signconfigPopDTO.getId());

							break Signconfig;
						}
					}
					break;
				}
			}
			appLoadingShipbillDTOs.add(appLoadingShipbillDTO);
		}
		return appLoadingShipbillDTOs;
	}

	/**
	 * 配载商品查询
	 *
	 * @param vo
	 * @return
	 */
	@SuppressWarnings("resource")
	public Page<AppLoadingShipBillDetailDTO> loadingShipbillDetail(AppLoadingShipbillPageVO 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<AppLoadingShipBillDetailDTO> receiptLoadingShipBillDetailDTOs = new ArrayList<>();

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

				receiptLoadingShipBillDetailDTOs.add(appLoadingShipBillDetailDTO);
			}
		}

		// 分页重组
		Page<AppLoadingShipBillDetailDTO> 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")
	public Page<AppLoadingPackageDTO> loadingShipbillPackage(AppLoadingShipbillPageVO 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(TmsShipbillPackageModel::getShipbillId, vo.getShipbillIds().stream().toArray(String[]::new));
		Restriction r2 = Restrictions.eq(TmsShipbillPackageModel::getEnterpriseId, user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));

		PageUtils.startPage(vo.getPageNum(), vo.getPageSize());
		List<TmsShipbillPackageModel> tmsShipbillPackageModels = tmsShipbillPackageMapper.findByCriteria(criteria);

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

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

				appLoadingPackageDTOs.add(appLoadingPackageDTO);
			}
		}
		// 分页重组
		Page<AppLoadingPackageDTO> page = PageUtils.getPage(appLoadingPackageDTOs);
		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 queryVO
	 * @return
	 */
	public List<AppointmentExportShipbillDTO> exportAllShipbill(AppointmentQueryVO queryVO) {
		ToolKits.isParamNull(queryVO, "导出所有数据请求不为空");

		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();
		}

		// 判断账号类型
		// 用户类型
		queryVO.setUserType(user.getUserType());
		queryVO.setEnterpriseId(user.getEnterpriseId());
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 判断是否为部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				queryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
				queryVO.setIsDept(StatusConstant.IS_DEPT_YES);
			} else {
				queryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
				queryVO.setIsDept(StatusConstant.IS_DEPT_NO);
				// 货主
				queryVO.setConsignors(user.getConsignors().stream().toArray(Long[]::new));
				// 客户
				queryVO.setCustomers(user.getCustomers().stream().toArray(Long[]::new));
				// 供应商
				queryVO.setSuppliers(user.getSuppliers().stream().toArray(Long[]::new));
				// 仓库
				queryVO.setWsarehouses(user.getWarehouses().stream().toArray(Long[]::new));
			}
		} else {
			queryVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		}
		List<AppointmentExportShipbillDTO> appointmentQueryDTOs = Lists.newArrayList();
		List<AppointmentQueryDTO> appointmentQueryDTOS = tmsLoadingBillDetailMapper.queryAppointmentShipbill(queryVO);

		for (AppointmentQueryDTO appointmentQueryDTO : appointmentQueryDTOS) {
			AppointmentExportShipbillDTO appointmentDTO = new AppointmentExportShipbillDTO();
			BeanUtils.copyProperties(appointmentQueryDTO, appointmentDTO);
			// 收货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(appointmentQueryDTO.getConsigneeLongitude()) && ToolKits.isNotEmpty(appointmentQueryDTO.getConsigneeLatitude())) {
				appointmentDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
			} else {
				appointmentDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
			}
			// 发货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(appointmentQueryDTO.getShipperLongitude()) && ToolKits.isNotEmpty(appointmentQueryDTO.getShipperLatitude())) {
				appointmentDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
			} else {
				appointmentDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
			}

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

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

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

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

			appointmentQueryDTOs.add(appointmentDTO);

		}
		return appointmentQueryDTOs;
	}

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

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

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

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

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

		// 承运方类型
		RestMessage<List<Map<String, Object>>> restMessage13 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LINE_CARRIER_TYPE, null, null, null);
		if (!restMessage13.isSuccess()) {
			throw new RuntimeException("承运方类型翻译失败!");
		} else {
			data13 = restMessage13.getData();
		}
		queryVO.setUserType(user.getUserType());
		queryVO.setEnterpriseId(user.getEnterpriseId());
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 判断是否为部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				queryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
				queryVO.setIsDept(StatusConstant.IS_DEPT_YES);
			} else {
				queryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
				queryVO.setIsDept(StatusConstant.IS_DEPT_NO);
				// 货主
				queryVO.setConsignors(user.getConsignors().stream().toArray(Long[]::new));
				// 客户
				queryVO.setCustomers(user.getCustomers().stream().toArray(Long[]::new));
				// 供应商
				queryVO.setSuppliers(user.getSuppliers().stream().toArray(Long[]::new));
				// 仓库
				queryVO.setWsarehouses(user.getWarehouses().stream().toArray(Long[]::new));
			}
		} else {
			queryVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		}
		List<AppointmentExportShipbillDTO> appointmentQueryDTOs = Lists.newArrayList();

		PageUtils.startPage(queryVO.getPageNum(), queryVO.getPageSize());
		List<AppointmentQueryDTO> appointmentQueryDTOS = tmsLoadingBillDetailMapper.queryAppointmentShipbill(queryVO);

		for (AppointmentQueryDTO appointmentQueryDTO : appointmentQueryDTOS) {
			AppointmentExportShipbillDTO appointmentDTO = new AppointmentExportShipbillDTO();
			BeanUtils.copyProperties(appointmentQueryDTO, appointmentDTO);
			// 收货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(appointmentQueryDTO.getConsigneeLongitude()) && ToolKits.isNotEmpty(appointmentQueryDTO.getConsigneeLatitude())) {
				appointmentDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
			} else {
				appointmentDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
			}
			// 发货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(appointmentQueryDTO.getShipperLongitude()) && ToolKits.isNotEmpty(appointmentQueryDTO.getShipperLatitude())) {
				appointmentDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
			} else {
				appointmentDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
			}

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

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

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

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

			appointmentQueryDTOs.add(appointmentDTO);
		}

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

	/**
	 * 导出选择行数据
	 *
	 * @param shipbillIdList
	 * @return
	 */
	public List<AppointmentExportShipbillDTO> 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<AppointmentExportShipbillDTO> appointmentExportDTOS = Lists.newArrayList();
		List<AppointmentQueryDTO> appointmentQueryDTOs = tmsLoadingBillDetailMapper.queryAppointSelectLineData(shipbillIdList.stream().toArray(String[]::new));

		for (AppointmentQueryDTO appointmentDTO : appointmentQueryDTOs) {
			AppointmentExportShipbillDTO appointmentExportDTO = new AppointmentExportShipbillDTO();
			BeanUtils.copyProperties(appointmentDTO, appointmentExportDTO);
			// 收货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(appointmentDTO.getConsigneeLongitude()) && ToolKits.isNotEmpty(appointmentDTO.getConsigneeLatitude())) {
				appointmentExportDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
			} else {
				appointmentExportDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
			}
			// 发货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(appointmentDTO.getShipperLongitude()) && ToolKits.isNotEmpty(appointmentDTO.getShipperLatitude())) {
				appointmentExportDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
			} else {
				appointmentExportDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
			}

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

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

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

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

			appointmentExportDTOS.add(appointmentExportDTO);

		}
		return appointmentExportDTOS;
	}

	/**
	 * 待预约打印
	 *
	 * @param appointPrintVO
	 * @return
	 */
	public AppointmentPrintDTO shipbillPrint(AppointmentPrintVO appointPrintVO) {
		ToolKits.isParamNull(appointPrintVO, "打印请求不为空");
		ToolKits.isParamNull(appointPrintVO.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 = { appointPrintVO.getShipbillId() };
		List<AppointmentQueryDTO> appointmentQueryDTOs = tmsLoadingBillDetailMapper.queryAppointSelectLineData(shipbills);

		Assert.isTrue(ToolKits.isNotEmpty(appointmentQueryDTOs), "运单【" + appointPrintVO.getShipbillId() + "】不存在");

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

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

		// 类型翻译
		printHeadDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(appointmentDTO.getOrderType())));
		printHeadDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(appointmentDTO.getOrderBusinessType())));
		printHeadDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(appointmentDTO.getDeliveryMethodType())));
		printHeadDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(appointmentDTO.getTransportType())));
		printHeadDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(appointmentDTO.getTemperatureRequirement())));
		printHeadDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(appointmentDTO.getShipperType())));
		printHeadDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(appointmentDTO.getConsigneeType())));
		// 运单状态
		printHeadDTO.setStatusName(PublicMethods.change(data9, String.valueOf(appointmentDTO.getStatus())));
		// 运输状态
		printHeadDTO.setTransportStatusName(PublicMethods.change(data10, String.valueOf(appointmentDTO.getTransportStatus())));
		// 异常状态
		printHeadDTO.setAbnormalStatusName(PublicMethods.change(data11, String.valueOf(appointmentDTO.getAbnormalStatus())));
		// 扫描状态
		printHeadDTO.setScanStatusName(PublicMethods.change(data12, String.valueOf(appointmentDTO.getScanStatus())));
		// 承运方类型
		printHeadDTO.setCarrierTypeName(PublicMethods.change(data13, String.valueOf(appointmentDTO.getCarrierType())));
		// 调度单号
		printHeadDTO.setLoadingBillNo(appointmentDTO.getLoadingBillNo());
		// 承运方名称
		printHeadDTO.setCarrierName(appointmentDTO.getCarrierName());
		// 送货员姓名
		printHeadDTO.setDeliverymanName(appointmentDTO.getDeliverymanName());
		// 车牌号
		printHeadDTO.setVehiclePlateNumber(appointmentDTO.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", appointPrintVO.getShipbillId());
		criteria.setRestriction(r1);
		List<TmsShipbillDetailModel> tmsShipbillDetailModels = tmsShipbillDetailMapper.findByCriteria(criteria);

		List<AppointmentPrintDetailDTO> appointmentPrintDetailDTOs = new ArrayList<>();

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

		PrinterDTO printerDTO = printerHelper.checkAndGeneratePrinterDTO(maindataTmsResource, PrintConstant.PRINT_APPOINTMENT_SHIPBILL);
		Assert.isTrue(ToolKits.isNotEmpty(printerDTO), "获取打印机和模版信息失败,请检查打印编码【" + PrintConstant.PRINT_APPOINTMENT_SHIPBILL + "】是否配置");

		// 封装参数
		List<AppointmentPrintDataDTO> result = Lists.newArrayList();
		AppointmentPrintDataDTO appointmentPrintDataDTO = new AppointmentPrintDataDTO();
		appointmentPrintDataDTO.setHead(printHeadDTO);
		appointmentPrintDataDTO.setTable(appointmentPrintDetailDTOs);

		// 响应对象
		AppointmentPrintDTO appointmentPrintDTO = new AppointmentPrintDTO();
		appointmentPrintDTO.setData(result);
		appointmentPrintDTO.setTcp(printerDTO.getConfig().getIp());
		appointmentPrintDTO.setPrintName(printerDTO.getConfig().getPrinterName());
		appointmentPrintDTO.setUrl(printerDTO.getTemplate().getTemplatePath());
		appointmentPrintDTO.setPrintSolution("");

		return appointmentPrintDTO;
	}

	/**
	 * 提货预约
	 *
	 * @param appointmentVO
	 * @return
	 */
	public PickUpAppointmentDTO pickUpAppointmentQuery(PickUpAppointmentVO appointmentVO) throws Exception {

		ToolKits.isParamNull(appointmentVO, "提货预约查询请求不为空");
		ToolKits.isParamNull(appointmentVO.getBranchId(), "仓库ID不为空");
		ToolKits.isParamNull(appointmentVO.getPickUpAppointmentShipbillList(), "请先勾选运单");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		// 运单验证
		List<PickUpAppointmentShipbillVO> appointmentShipbillVOS = appointmentVO.getPickUpAppointmentShipbillList();

		int addressCnt = appointmentShipbillVOS.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(PickUpAppointmentShipbillVO::getShipperAddress))), ArrayList::new)).size();
		if (addressCnt > 1) {
			throw new PrologException("请勾选相同的发货地址的运单");
		}
		int driverNameCnt = appointmentShipbillVOS.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(PickUpAppointmentShipbillVO::getDriverName))), ArrayList::new)).size();

		int plateNumCnt = appointmentShipbillVOS.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(PickUpAppointmentShipbillVO::getVehiclePlateNumber))), ArrayList::new)).size();
		if (driverNameCnt > 1 || plateNumCnt > 1) {
			throw new PrologException("请勾选相同司机、车辆的运单");
		}

		List<PickUpAppointmentShipbillVO> appointmentShipbillVOList = appointmentShipbillVOS.stream().filter(o -> ToolKits.isNotEmpty(o.getEstimatedPickupStartTime())).collect(Collectors.toList());
		if (appointmentShipbillVOList.size() == appointmentShipbillVOS.size()) {
			Set<String> set1 = appointmentShipbillVOS.stream().map(vo -> DateUtil.format(vo.getEstimatedPickupStartTime(), "yyyy-MM-dd")).collect(Collectors.toSet());
			if (set1.size() > 1) {
				throw new PrologException("请勾选相同的提货时间的运单");
			}
		}
		List<String> shipbillIdStrList = appointmentVO.getPickUpAppointmentShipbillList().stream().map(PickUpAppointmentShipbillVO::getShipbillIds).collect(Collectors.toList());
		List<String> shipBillIds = Lists.newArrayList();
		shipbillIdStrList.stream().forEach(ids->{
			shipBillIds.addAll(Arrays.stream(ids.split(",")).collect(Collectors.toList()));
		});
		if (ToolKits.isEmpty(shipBillIds)) {
			throw new PrologException(StrUtil.format("运单不存在"));
		}
		List<TmsShipbillHeaderModel> shipbillHeaderModels = tmsShipbillHeaderMapper.findByIds(TmsShipbillHeaderModel.class,shipBillIds.stream().toArray(), null);
		if (ToolKits.isEmpty(shipbillHeaderModels)) {
			throw new PrologException(StrUtil.format("运单不存在"));
		}
		List<TmsShipbillHeaderModel> noTakeAndCallShipbillHeaderModels = shipbillHeaderModels.stream().filter(h->!h.getFlowConfig().contains(DataDictionaryConstant.FLOW_CONFIG_APPOINTMENT_TN_CN)).collect(Collectors.toList());
		if (ToolKits.isNotEmpty(noTakeAndCallShipbillHeaderModels) && noTakeAndCallShipbillHeaderModels.size() != shipBillIds.size()) {
			throw new PrologException("请勾选相同预约流程的运单");
		}
		List<TmsShipbillHeaderModel> hasTakeAndCallShipbillHeaderModels = shipbillHeaderModels.stream().filter(h->h.getFlowConfig().contains(DataDictionaryConstant.FLOW_CONFIG_APPOINTMENT_TN_CN)).collect(Collectors.toList());
		if (ToolKits.isNotEmpty(hasTakeAndCallShipbillHeaderModels) && hasTakeAndCallShipbillHeaderModels.size() != shipBillIds.size()) {
			throw new PrologException("请勾选相同预约流程的运单");
		}
		TmsBaseBranchDTO tmsBaseBranchDTO = new TmsBaseBranchDTO();
		PickUpAppointmentDTO pickUpAppointmentDTO = new PickUpAppointmentDTO();
		BeanUtils.copyProperties(appointmentVO, pickUpAppointmentDTO);
		RestMessage<TmsBaseBranchDTO> restMessageData = maindataTmsResource.viewBranch(appointmentVO.getBranchId());
		if (!restMessageData.isSuccess()) {
			throw new RuntimeException("获取仓库的预约信息失败!");
		} else {
			tmsBaseBranchDTO = restMessageData.getData();
		}
		if (ObjectUtil.isNull(tmsBaseBranchDTO.getAptNum())) {
			throw new BizException("仓库【" + tmsBaseBranchDTO.getName() + "】没有设置班次允许预约数");
		}
		List<Date> aptDateList = Lists.newArrayList();
		Date nonAptSpecStartDate = tmsBaseBranchDTO.getNonAptSpecStartDate();
		Date nonAptSpecEndDate = tmsBaseBranchDTO.getNonAptSpecEndDate();

		String nonAptWeek = null;
		String nonAptMonth = null;
		if (DataDictionaryConstant.NON_ABL_DT_WK.equals(tmsBaseBranchDTO.getNonAptDt())) {
			// 不可预约日期 按周
			nonAptWeek = tmsBaseBranchDTO.getNonAptDura();
		} else if (DataDictionaryConstant.NON_ABL_DT_MT.equals(tmsBaseBranchDTO.getNonAptDt())) {
			// 不可预约日期 按月
			nonAptMonth = tmsBaseBranchDTO.getNonAptDura();
		}

		// 一周内可预约的日期
		Date currentDt = DateUtil.date();
		while (aptDateList.size() < 7) {
			if (ToolKits.isNotEmpty(nonAptSpecStartDate) && ToolKits.isNotEmpty(nonAptSpecEndDate) && DateUtil.compare(currentDt, nonAptSpecStartDate) >= 0 && DateUtil.compare(currentDt, nonAptSpecEndDate) < 0) {
				currentDt = DateUtil.offsetDay(nonAptSpecEndDate, 1);
				continue;

			}
			if (ToolKits.isNotEmpty(nonAptMonth) && nonAptMonth.contains(DateUtil.format(currentDt, "dd"))) {
				currentDt = DateUtil.offsetDay(currentDt, 1);
				continue;
			}
			if (ToolKits.isNotEmpty(nonAptWeek) && nonAptWeek.contains(String.valueOf(DateUtil.dayOfWeek(currentDt)))) {
				currentDt = DateUtil.offsetDay(currentDt, 1);
				continue;
			}
			aptDateList.add(currentDt);
			currentDt = DateUtil.offsetDay(currentDt, 1);
		}
		// 已经预约次数取得
		AppointmentHeadQueryVO queryVO = new AppointmentHeadQueryVO();
		queryVO.setBranchId(appointmentVO.getBranchId());
		queryVO.setAppointmentType(DataDictionaryConstant.APPOINTMENT_TYPE_TH);
		List<BranchAppointmentInfoDTO> appointmentInfoDTOS = tmsAppointmentHeaderMapper.queryBranchAppointmentInfo(queryVO);

		Map<String, Integer> appInfoMap = Maps.newHashMap();
		for (BranchAppointmentInfoDTO infoDTO : appointmentInfoDTOS) {
			String appedDt = DateUtil.format(infoDTO.getAppointmentDate(), "yyyy-MM-dd");
			appInfoMap.put(appedDt + infoDTO.getAppointmentTime(), infoDTO.getAppointmentCnt());
		}

		// 一周的预约信息
		List<AppointmentWeekDTO> weekDTOS = Lists.newArrayList();
		// STD-DEVELOP20220823 lhb JC_CK_001仓库预约时间段可以输入分钟的需求 20220823 start
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		// STD-DEVELOP20220823 lhb JC_CK_001仓库预约时间段可以输入分钟的需求 20220823 end
		for (Date dt : aptDateList) {
			AppointmentWeekDTO weekDTO = new AppointmentWeekDTO();
			weekDTO.setAptWeek(DateUtil.dayOfWeekEnum(dt).toChinese().replace("星期", "周"));
			String aliAppDt = DateUtil.format(dt, "yyyy-MM-dd");
			weekDTO.setAptDate(aliAppDt);

			// 可预约时间段 可预约次数
			List<AppointmentTimesDTO> appointmentTimesDTOS = Lists.newArrayList();
			for (TmsBaseBranchApTimeDTO apTimeDTO : tmsBaseBranchDTO.getApTimeDTOList()) {
				// 预约时间段是否过去时间
				// STD-DEVELOP20220823 lhb JC_CK_001仓库预约时间段可以输入分钟的需求 20220823 start
				String currentDtStr = DateUtil.format(DateUtil.date(), "yyyy-MM-dd HH:mm");
				// STD-DEVELOP20220823 lhb JC_CK_001仓库预约时间段可以输入分钟的需求 20220823 end
				Date currentDate1 = sdf.parse(currentDtStr);
				// STD-DEVELOP20220823 lhb JC_CK_001仓库预约时间段可以输入分钟的需求 20220823 start
				Date lastDt = sdf.parse(aliAppDt + " " + apTimeDTO.getEndTime());
				// STD-DEVELOP20220823 lhb JC_CK_001仓库预约时间段可以输入分钟的需求 20220823 end
				if (lastDt.before(currentDate1)) {
					continue;
				}
				AppointmentTimesDTO timesDTO = new AppointmentTimesDTO();
				String appDura = apTimeDTO.getStartTime() + "-" + apTimeDTO.getEndTime();
				timesDTO.setAppDura(appDura);
				if (ToolKits.isNotEmpty(appointmentInfoDTOS)) {
					Integer appedCnt = appInfoMap.get(aliAppDt + appDura);
					if (ToolKits.isNotEmpty(appedCnt)) {
						int aliCnt = 0;
						if (tmsBaseBranchDTO.getAptNum().intValue() - appedCnt.intValue() > 0) {
							aliCnt = tmsBaseBranchDTO.getAptNum().intValue() - appedCnt.intValue();
						}
						timesDTO.setAppAliCnt(aliCnt);
						timesDTO.setAppedCnt(appedCnt);
					} else {
						timesDTO.setAppAliCnt(tmsBaseBranchDTO.getAptNum());
						timesDTO.setAppedCnt(0);
					}
				} else {
					timesDTO.setAppAliCnt(tmsBaseBranchDTO.getAptNum());
					timesDTO.setAppedCnt(0);
				}
				appointmentTimesDTOS.add(timesDTO);
			}
			weekDTO.setAppointmentTimes(appointmentTimesDTOS);

			weekDTOS.add(weekDTO);
		}
		pickUpAppointmentDTO.setAppointmentWeeks(weekDTOS);
		return pickUpAppointmentDTO;
	}

	/**
	 * 提货预约确认
	 *
	 * @param confirmVO
	 * @return
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void pickUpAppointmentConfirm(PickUpAppointmentConfirmVO confirmVO) throws Exception {
		ToolKits.isParamNull(confirmVO, "提货预约确认请求不为空");
		ToolKits.isParamNull(confirmVO.getBranchId(), "仓库ID不为空");
		ToolKits.isParamNull(confirmVO.getAppointmentDate(), "预约日期不为空");
		ToolKits.isParamNull(confirmVO.getAppointmentTime(), "预约时间段不为空");
		ToolKits.isParamNull(confirmVO.getBranchAddress(), "预约提货地址不为空");
		ToolKits.isParamNull(confirmVO.getShipbillIds(), "预约运单ID不为空");
		ToolKits.isParamNull(confirmVO.getCreateMode(), "生成模式不能为空");

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

		Date date = DateUtil.date();
		// 预约时间校验
		TmsBaseBranchDTO tmsBaseBranchDTO = new TmsBaseBranchDTO();
		RestMessage<TmsBaseBranchDTO> restMessageData = maindataTmsResource.viewBranch(confirmVO.getBranchId());
		if (!restMessageData.isSuccess()) {
			throw new RuntimeException("获取仓库的预约信息失败!");
		} else {
			tmsBaseBranchDTO = restMessageData.getData();
		}
		// 运输记录表数据查询
		Criteria criteriaTransLog = Criteria.forClass(TmsShipbillTransLogModel.class);
		Restriction r1 = Restrictions.eq(TmsShipbillTransLogModel::getEnterpriseId, user.getEnterpriseId());
		Restriction r2 = null;
		Integer aptTimeType = tmsBaseBranchDTO.getAptTime();
		Integer aptTimeUnit = tmsBaseBranchDTO.getAptUnit();

		Date appDt = confirmVO.getAppointmentDate();
		String appTime = confirmVO.getAppointmentTime();

		// 可预约的时间
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Date aliAppDtStart = null;
		Date aliAppDtEnd = null;

		String appDtStr = DateUtil.format(appDt, "yyyy-MM-dd");

		Date appTimeStart = sdf.parse(appDtStr + " " + appTime.substring(0, 5));
		Date appTimeEnd = sdf.parse(appDtStr + " " + appTime.substring(6));

		int jiaJiCnt = 0;
		List<TmsShipbillHeaderModel> headerModelList = Lists.newArrayList();
		for (String shipbillId : confirmVO.getShipbillIds().split(",")) {
			r2 = Restrictions.eq(TmsShipbillTransLogModel::getShipbillId, shipbillId);

			criteriaTransLog.setRestriction(Restrictions.and(r1, r2));
			List<TmsShipbillTransLogModel> tmsShipbillTransLogModels = tmsShipbillTransportLogMapper.findByCriteria(criteriaTransLog);

			if (ToolKits.isEmpty(tmsShipbillTransLogModels)) {
				throw new PrologException("预约时间不在仓库【" + confirmVO.getBranchName() + "】的可预约时间段内");
			} else {
				TmsShipbillTransLogModel logModel = tmsShipbillTransLogModels.get(0);
				if (DataDictionaryConstant.AVAILABLE_TIME_PICK_UP.equals(aptTimeType)) {
					aliAppDtStart = logModel.getEstimatedPickupStartTime();
				} else if (DataDictionaryConstant.AVAILABLE_TIME_ORDER.equals(aptTimeType)) {
					aliAppDtStart = logModel.getOrderDt();
				} else if (DataDictionaryConstant.AVAILABLE_TIME_COMMIT.equals(aptTimeType)) {
					aliAppDtStart = logModel.getCommitDt();
				} else if (DataDictionaryConstant.AVAILABLE_TIME_REVIEW.equals(aptTimeType)) {
					aliAppDtStart = logModel.getReviewDt();
				} else if (DataDictionaryConstant.AVAILABLE_TIME_DISPATCH.equals(aptTimeType)) {
					aliAppDtStart = logModel.getDisDt();
				} else if (DataDictionaryConstant.AVAILABLE_TIME_DISPATCH_CHECK.equals(aptTimeType)) {
					aliAppDtStart = logModel.getDisCheckDt();
				}
				if (ToolKits.isNotEmpty(aliAppDtStart)) {
					if (ToolKits.isNotEmpty(aptTimeUnit) && DataDictionaryConstant.AVAILABLE_UNIT_HOUR.equals(aptTimeUnit)) {
						aliAppDtEnd = DateUtil.offsetHour(aliAppDtStart, tmsBaseBranchDTO.getAptTimeDura().intValue());
					} else if (ToolKits.isNotEmpty(aptTimeUnit) && DataDictionaryConstant.AVAILABLE_UNIT_DAY.equals(aptTimeUnit)) {
						aliAppDtEnd = DateUtil.offsetDay(aliAppDtStart, tmsBaseBranchDTO.getAptTimeDura().intValue());
					}

					// 预约的结束时间段 < 可预约的开始时间,或者，预约的开始时间段 > 可预约的结束时间
					if (appTimeEnd.before(aliAppDtStart) || appTimeStart.after(aliAppDtEnd)) {
						throw new PrologException("预约时间不在仓库【" + confirmVO.getBranchName() + "】的可预约时间段内");
					}
				}
			}

			TmsShipbillHeaderModel headerModel = tmsShipbillHeaderMapper.findById(shipbillId, TmsShipbillHeaderModel.class);

			if (ToolKits.isEmpty(headerModel)) {
				throw new PrologException("运单【" + shipbillId + "】不存在");
			}
			if (!headerModel.getStatus().equals(DataDictionaryConstant.SHIPBILL_STATUS_PENDING_APP)) {
				throw new PrologException("运单不是待预约状态，不能预约");
			}

			if (headerModel.getOrderType().intValue() > DataDictionaryConstant.ORDER_TYPE_P.intValue()) {
				jiaJiCnt++;
			}
			headerModelList.add(headerModel);
		}
		StringBuffer newNum = new StringBuffer();
		// 预约号生成
		if (jiaJiCnt > 0) {
			confirmVO.setIsJiaJi("1");
			newNum.append(DataDictionaryConstant.RESERVE_NUMBER);
		}
		String appDtStrNum = DateUtil.format(appDt, "yyyyMMdd");
		newNum.append(appDtStrNum);
		newNum.append(appTime.substring(0, 2));
		newNum.append(appTime.substring(6, 8));
		confirmVO.setAppointmentType(DataDictionaryConstant.APPOINTMENT_TYPE_TH);
		String maxReserveNumber = tmsAppointmentHeaderMapper.queryMaxReserveNumber(confirmVO);

		if (ToolKits.isNotEmpty(maxReserveNumber)) {
			String oldNum = maxReserveNumber.substring(maxReserveNumber.length() - 3);
			String pattern = "[1-9]+";
			Pattern r = Pattern.compile(pattern);
			Matcher m = r.matcher(oldNum);
			if (m.find()) {
				int num = Integer.valueOf(m.group(0)).intValue() + 1;
				newNum.append(String.format("%03d", num));
			} else {
				newNum.append("001");
			}
		} else {
			newNum.append("001");
		}
		// 最大预约次数取得
		AppointmentHeadQueryVO queryVO = new AppointmentHeadQueryVO();
		queryVO.setBranchId(confirmVO.getBranchId());
		queryVO.setAppointmentDate(appDt);
		queryVO.setAppointmentType(DataDictionaryConstant.APPOINTMENT_TYPE_TH);
		queryVO.setAppointmentTime(appTime);
		List<BranchAppointmentInfoDTO> appointmentInfoDTOS = tmsAppointmentHeaderMapper.queryBranchAppointmentInfo(queryVO);
		if (ToolKits.isNotEmpty(appointmentInfoDTOS) && appointmentInfoDTOS.get(0).getAppointmentCnt().intValue() >= tmsBaseBranchDTO.getAptNum().intValue()) {
			throw new PrologException("仓库【" + confirmVO.getBranchName() + "】的预约时间段" + appDtStrNum + appTime + "已约满");
		}

		// 预约主表作成
		TmsAppointmentHeaderModel appointmentHeaderModel = new TmsAppointmentHeaderModel();
		BeanUtils.copyProperties(confirmVO, appointmentHeaderModel);

		// 获取预约主表ID
		RestMessage<String> restMessageId = maindataTmsResource.getCodeNumberByCode(SeriaNnumberConstant.TMS_APPOINTMENT_HEADER_ID, "L");
		if (!restMessageId.isSuccess()) {
			throw new RuntimeException("生成预约主表ID失败");
		}
		String id = restMessageId.getData();
		appointmentHeaderModel.setAppointmentId(id);
		appointmentHeaderModel.setAppointmentNo(id);
		appointmentHeaderModel.setAppointmentType(DataDictionaryConstant.APPOINTMENT_TYPE_TH);
		appointmentHeaderModel.setStatus(DataDictionaryConstant.APPOINTMENT_STATUS_DSH);
		appointmentHeaderModel.setReserveNumber(newNum.toString());
		appointmentHeaderModel.setReserveNumberTime(date);
		appointmentHeaderModel.setUrgentQuantity(jiaJiCnt);

		appointmentHeaderModel.setEnterpriseId(user.getEnterpriseId());
		appointmentHeaderModel.setEnterpriseName(user.getEnterpriseName());
		appointmentHeaderModel.setCreateperson(user.getNickname());
		appointmentHeaderModel.setCreatetime(date);

		// 预约明细表
		for (TmsShipbillHeaderModel shipbillHeaderModel : headerModelList) {
			TmsAppointmentDetailModel appointmentDetailModel = new TmsAppointmentDetailModel();

			BeanUtils.copyProperties(shipbillHeaderModel, appointmentDetailModel);

			// 获取预约明细表ID
			RestMessage<String> restMessageDetailId = maindataTmsResource.getCodeNumberByCode(SeriaNnumberConstant.TMS_APPOINTMENT_DETAIL_ID, "L");
			if (!restMessageDetailId.isSuccess()) {
				throw new RuntimeException("生成预约明细表ID失败");
			}
			String detailId = restMessageDetailId.getData();
			appointmentDetailModel.setId(detailId);
			appointmentDetailModel.setAppointmentId(id);
			appointmentDetailModel.setAppointmentNo(id);

			appointmentDetailModel.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_APP_ING);

			appointmentDetailModel.setEnterpriseId(user.getEnterpriseId());
			appointmentDetailModel.setEnterpriseName(user.getEnterpriseName());
			appointmentDetailModel.setCreateperson(user.getNickname());
			appointmentDetailModel.setCreatetime(date);

			// 更新运单状态 为预约中
			Map<String, Object> mapUpdate = Maps.newHashMap();
			mapUpdate.put("status", DataDictionaryConstant.SHIPBILL_STATUS_APP_ING);
			mapUpdate.put("updateperson", user.getNickname());
			mapUpdate.put("updatetime", date);
			tmsShipbillHeaderMapper.updateMapById(shipbillHeaderModel.getShipbillId(), mapUpdate, TmsShipbillHeaderModel.class);

			// 更新装车单明细状态 为预约中
			Criteria criteriaLoadingBillDetail = Criteria.forClass(TmsLoadingBillDetailModel.class);
			Restriction r4 = Restrictions.eq(TmsLoadingBillDetailModel::getEnterpriseId, user.getEnterpriseId());
			Restriction r5 = Restrictions.eq(TmsLoadingBillDetailModel::getShipbillId, shipbillHeaderModel.getShipbillId());
			Restriction r6 = Restrictions.eq(TmsLoadingBillDetailModel::getStatus, DataDictionaryConstant.SHIPBILL_STATUS_PENDING_APP);
			criteriaLoadingBillDetail.setRestriction(Restrictions.and(r4, r5, r6));
			criteriaLoadingBillDetail.setOrder(Order.newInstance().desc(new String[] { "createtime" }));
			List<TmsLoadingBillDetailModel> tmsLoadingBillDetails = tmsLoadingBillDetailMapper.findByCriteria(criteriaLoadingBillDetail);

			if (ToolKits.isEmpty(tmsLoadingBillDetails)) {
				throw new PrologException("装车单明细【" + shipbillHeaderModel.getShipbillId() + "】查询失败");
			}
			TmsLoadingBillDetailModel tmsLoadingBillDetail = tmsLoadingBillDetails.get(0);
			appointmentDetailModel.setLoadingBillId(tmsLoadingBillDetail.getLoadingBillId());
			tmsAppointmentDetailMapper.save(appointmentDetailModel);
			tmsLoadingBillDetailMapper.updateMapById(tmsLoadingBillDetail.getId(), mapUpdate, TmsLoadingBillDetailModel.class);

			// 日志表
			ShipbillOperateLogSaveVO shipbillOperateLogSaveVO = new ShipbillOperateLogSaveVO();
			shipbillOperateLogSaveVO.setShipbillId(shipbillHeaderModel.getShipbillId());
			shipbillOperateLogSaveVO.setShipbillNo(shipbillHeaderModel.getShipbillId());
			shipbillOperateLogSaveVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_YYQR);
			shipbillOperateLogSaveVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_DISPATCH_CHECK);
			shipbillOperateLogSaveVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_APP_ING);
			shipbillOperateLogService.addShipbillOperateLogData(shipbillOperateLogSaveVO);
		}
		appointmentHeaderModel.setTallyStatus(DataDictionaryConstant.TALLY_STATUS_WLH);
		appointmentHeaderModel.setCreateMode(confirmVO.getCreateMode());
		tmsAppointmentHeaderMapper.save(appointmentHeaderModel);
		MessageUtil.addMessage(new SendMessageDTO(MessageOrderTypeEnum.SHIP_NO.getCode(), MessageTypeEnum.APPOINTMENT.getCode(), Lists.newArrayList(confirmVO.getShipbillIds().split(","))));
	}

	public String formatDt(Date startDt, Date endDt) {
		if (ToolKits.isEmpty(startDt) && ToolKits.isEmpty(endDt)) {
			return "";
		} else if (ToolKits.isEmpty(endDt)) {
			return DateUtil.format(startDt, "yyyy-MM-dd hh:mm:ss") + " ~ ";
		} else if (ToolKits.isEmpty(startDt)) {
			return " ~ " + DateUtil.format(endDt, "yyyy-MM-dd hh:mm:ss");
		}
		return DateUtil.format(startDt, "yyyy-MM-dd hh:mm:ss") + " ~ " + DateUtil.format(endDt, "yyyy-MM-dd hh:mm:ss");
	}
}
