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

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.prolog.common.util.DateUtils;
import com.prolog.common.util.ToolKits;
import com.prolog.framework.authority.core.dto.UserDTO;
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.*;
import com.prolog.framework.dao.util.PageUtils;
import com.prolog.product.core.framework.entity.UserEntity;
import com.prolog.product.core.framework.util.PlgFxUsrUtils;
import com.prolog.rdc.tms.constant.BussinessConstant;
import com.prolog.rdc.tms.constant.DataDictionaryConstant;
import com.prolog.rdc.tms.constant.StatusConstant;
import com.prolog.rdc.tms.dao.mapper.*;
import com.prolog.rdc.tms.model.constant.RedisConstant;
import com.prolog.rdc.tms.model.dto.*;
import com.prolog.rdc.tms.model.dto.basicConfigure.SignconfigPopDTO;
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.model.vo.*;
import com.prolog.rdc.tms.model.vo.basicConfigure.SignconfigPopVO;
import com.prolog.rdc.tms.proxy.UserProxy;
import com.prolog.rdc.tms.rmi.feign.MaindataFeign;
import com.prolog.rdc.tms.service.ShipbillCommonService;
import com.prolog.rdc.tms.service.ShipbillNodeTrackingService;
import com.prolog.rdc.tms.service.ShipbillOperateLogService;
import com.prolog.rdc.tms.service.WaitDeliveredService;
import com.prolog.rdc.tms.util.DateRdcUtils;
import com.prolog.rdc.tms.util.MessageUtil;
import com.prolog.rdc.tms.util.PublicMethods;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * Company: 湖北普罗格科技股份有限公司
 *
 * @author zhangsj
 * @since 2022/6/15 9:47
 */
@Slf4j
@Service
public class WaitDeliveredServiceImpl implements WaitDeliveredService {

	@Autowired
	private TmsLoadingBillHeaderMapper tmsLoadingBillHeaderMapper;

	@Autowired
	private TmsLoadingBillDetailMapper tmsLoadingBillDetailMapper;

	@Autowired
	private TmsShipbillHeaderMapper tmsShipbillHeaderMapper;

	@Autowired
	private TmsShipbillDetailMapper tmsShipbillDetailMapper;

	@Autowired
	private TmsShipbillPackageMapper tmsShipbillPackageMapper;

	@Autowired
	private MaindataFeign maindataTmsResource;

	@Autowired
	private ShipbillOperateLogService shipbillOperateLogService;

	@Autowired
	private ShipbillNodeTrackingService shipbillNodeTrackingService;

	@Autowired
	private TmsShipbillTransportLogMapper tmsShipbillTransportLogMapper;

	@Autowired
	private ShipbillCommonService shipbillCommonService;

	@Autowired
	private RedisTemplate redisTemplate;

	@Autowired
	private TmsShipbillContainerTempMapper shipbillContainerTempMapper;

	@Autowired
	private UserProxy userProxy;

	@Value("${prolog.system.username}")
	private String systemUsername;

	/**
	 * 运单模式分页查询
	 *
	 * @param waitDeliveredQueryByShipbillVO
	 * @return
	 */
	@Override
	public Page<WaitDeliveredQueryByShipbillDTO> queryTypeByShipbillPageData(WaitDeliveredQueryByShipbillVO waitDeliveredQueryByShipbillVO) {
		ToolKits.isParamNull(waitDeliveredQueryByShipbillVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(waitDeliveredQueryByShipbillVO.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>> 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();

		// 订单类型
		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>>> restMessage8 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPBILL_STATUS, null, null, null);
		if (!restMessage8.isSuccess()) {
			throw new RuntimeException("运单状态翻译失败!");
		} else {
			data8 = restMessage8.getData();
		}

		// 承运方类型
		RestMessage<List<Map<String, Object>>> restMessage9 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LINE_CARRIER_TYPE, 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();
		}

		// 权限控制
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 判断是否是部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				waitDeliveredQueryByShipbillVO.setIsDept(StatusConstant.IS_DEPT_YES);
				waitDeliveredQueryByShipbillVO.setDepts(user.getDepts().toArray(new String[] {}));
			} else {
				waitDeliveredQueryByShipbillVO.setIsDept(StatusConstant.IS_DEPT_NO);
				// 设置部门权限
				waitDeliveredQueryByShipbillVO.setDepts(user.getDepts().toArray(new String[] {}));
				// 设置数据权限
				waitDeliveredQueryByShipbillVO.setConsignors(user.getConsignors().toArray(new Long[] {}));
				waitDeliveredQueryByShipbillVO.setWsarehouses(user.getWarehouses().toArray(new Long[] {}));
				waitDeliveredQueryByShipbillVO.setCustomers(user.getCustomers().toArray(new Long[] {}));
				waitDeliveredQueryByShipbillVO.setSuppliers(user.getSuppliers().toArray(new Long[] {}));
			}
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
			waitDeliveredQueryByShipbillVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			throw new PrologException("当前人员没有操作权限");
		}
		waitDeliveredQueryByShipbillVO.setUserType(user.getUserType());
		waitDeliveredQueryByShipbillVO.setEnterpriseId(user.getEnterpriseId());

		PageUtils.startPage(waitDeliveredQueryByShipbillVO.getPageNum(), waitDeliveredQueryByShipbillVO.getPageSize());
		List<WaitDeliveredQueryByShipbillDTO> waitDeliveredQueryByShipbillDTOS = tmsLoadingBillHeaderMapper.waitDeliveredQueryByShipbillPage(waitDeliveredQueryByShipbillVO);

		for (WaitDeliveredQueryByShipbillDTO waitDeliveredQueryByShipbillDTO : waitDeliveredQueryByShipbillDTOS) {
			// 类型翻译
			waitDeliveredQueryByShipbillDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(waitDeliveredQueryByShipbillDTO.getOrderType())));
			waitDeliveredQueryByShipbillDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(waitDeliveredQueryByShipbillDTO.getOrderBusinessType())));
			waitDeliveredQueryByShipbillDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(waitDeliveredQueryByShipbillDTO.getDeliveryMethodType())));
			waitDeliveredQueryByShipbillDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(waitDeliveredQueryByShipbillDTO.getTransportType())));
			waitDeliveredQueryByShipbillDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(waitDeliveredQueryByShipbillDTO.getTemperatureRequirement())));
			waitDeliveredQueryByShipbillDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(waitDeliveredQueryByShipbillDTO.getShipperType())));
			waitDeliveredQueryByShipbillDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(waitDeliveredQueryByShipbillDTO.getConsigneeType())));
			waitDeliveredQueryByShipbillDTO.setStatusName(PublicMethods.change(data8, String.valueOf(waitDeliveredQueryByShipbillDTO.getStatus())));
			waitDeliveredQueryByShipbillDTO.setCarrierTypeName(PublicMethods.change(data9, String.valueOf(waitDeliveredQueryByShipbillDTO.getCarrierType())));
			waitDeliveredQueryByShipbillDTO.setTransportStatusName(PublicMethods.change(data10, String.valueOf(waitDeliveredQueryByShipbillDTO.getTransportStatus())));
			waitDeliveredQueryByShipbillDTO.setAbnormalStatusName(PublicMethods.change(data11, String.valueOf(waitDeliveredQueryByShipbillDTO.getAbnormalStatus())));
			waitDeliveredQueryByShipbillDTO.setScanStatusName(PublicMethods.change(data12, String.valueOf(waitDeliveredQueryByShipbillDTO.getScanStatus())));

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

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

	/**
	 * 运单模式高级查询
	 *
	 * @param waitDeliveredAdvancedQueryByShipbillVO
	 * @return
	 */
	@Override
	public Page<WaitDeliveredQueryByShipbillDTO> advancedQueryTypeByShipbillPageData(WaitDeliveredAdvancedQueryByShipbillVO waitDeliveredAdvancedQueryByShipbillVO) {
		ToolKits.isParamNull(waitDeliveredAdvancedQueryByShipbillVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(waitDeliveredAdvancedQueryByShipbillVO.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>> 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();

		// 订单类型
		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>>> restMessage8 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPBILL_STATUS, null, null, null);
		if (!restMessage8.isSuccess()) {
			throw new RuntimeException("运单状态翻译失败!");
		} else {
			data8 = restMessage8.getData();
		}

		// 承运方类型
		RestMessage<List<Map<String, Object>>> restMessage9 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LINE_CARRIER_TYPE, 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();
		}

		// 权限控制
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 判断是否是部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				waitDeliveredAdvancedQueryByShipbillVO.setIsDept(StatusConstant.IS_DEPT_YES);
				waitDeliveredAdvancedQueryByShipbillVO.setDepts(user.getDepts().toArray(new String[] {}));
			} else {
				waitDeliveredAdvancedQueryByShipbillVO.setIsDept(StatusConstant.IS_DEPT_NO);
				// 设置部门权限
				waitDeliveredAdvancedQueryByShipbillVO.setDepts(user.getDepts().toArray(new String[] {}));
				// 设置数据权限
				waitDeliveredAdvancedQueryByShipbillVO.setConsignors(user.getConsignors().toArray(new Long[] {}));
				waitDeliveredAdvancedQueryByShipbillVO.setWsarehouses(user.getWarehouses().toArray(new Long[] {}));
				waitDeliveredAdvancedQueryByShipbillVO.setCustomers(user.getCustomers().toArray(new Long[] {}));
				waitDeliveredAdvancedQueryByShipbillVO.setSuppliers(user.getSuppliers().toArray(new Long[] {}));
			}
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
			waitDeliveredAdvancedQueryByShipbillVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			throw new PrologException("当前人员没有操作权限");
		}
		waitDeliveredAdvancedQueryByShipbillVO.setUserType(user.getUserType());
		waitDeliveredAdvancedQueryByShipbillVO.setEnterpriseId(user.getEnterpriseId());

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

		PageUtils.startPage(waitDeliveredAdvancedQueryByShipbillVO.getPageNum(), waitDeliveredAdvancedQueryByShipbillVO.getPageSize());
		List<WaitDeliveredQueryByShipbillDTO> waitDeliveredQueryByShipbillDTOS = tmsLoadingBillHeaderMapper.waitDeliveredAdvancedQueryByShipbillPage(waitDeliveredAdvancedQueryByShipbillVO);

		for (WaitDeliveredQueryByShipbillDTO waitDeliveredQueryByShipbillDTO : waitDeliveredQueryByShipbillDTOS) {
			// 类型翻译
			waitDeliveredQueryByShipbillDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(waitDeliveredQueryByShipbillDTO.getOrderType())));
			waitDeliveredQueryByShipbillDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(waitDeliveredQueryByShipbillDTO.getOrderBusinessType())));
			waitDeliveredQueryByShipbillDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(waitDeliveredQueryByShipbillDTO.getDeliveryMethodType())));
			waitDeliveredQueryByShipbillDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(waitDeliveredQueryByShipbillDTO.getTransportType())));
			waitDeliveredQueryByShipbillDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(waitDeliveredQueryByShipbillDTO.getTemperatureRequirement())));
			waitDeliveredQueryByShipbillDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(waitDeliveredQueryByShipbillDTO.getShipperType())));
			waitDeliveredQueryByShipbillDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(waitDeliveredQueryByShipbillDTO.getConsigneeType())));
			waitDeliveredQueryByShipbillDTO.setStatusName(PublicMethods.change(data8, String.valueOf(waitDeliveredQueryByShipbillDTO.getStatus())));
			waitDeliveredQueryByShipbillDTO.setCarrierTypeName(PublicMethods.change(data9, String.valueOf(waitDeliveredQueryByShipbillDTO.getCarrierType())));
			waitDeliveredQueryByShipbillDTO.setTransportStatusName(PublicMethods.change(data10, String.valueOf(waitDeliveredQueryByShipbillDTO.getTransportStatus())));
			waitDeliveredQueryByShipbillDTO.setAbnormalStatusName(PublicMethods.change(data11, String.valueOf(waitDeliveredQueryByShipbillDTO.getAbnormalStatus())));
			waitDeliveredQueryByShipbillDTO.setScanStatusName(PublicMethods.change(data12, String.valueOf(waitDeliveredQueryByShipbillDTO.getScanStatus())));

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

	/**
	 * 收货方模式分页查询
	 *
	 * @param waitDeliveredQueryTypeByReceiverVO
	 * @return
	 */
	@Override
	public Page<WaitDeliveredQueryTypeByReceiverDTO> queryTypeByReceiverPageData(WaitDeliveredQueryTypeByReceiverVO waitDeliveredQueryTypeByReceiverVO) {
		ToolKits.isParamNull(waitDeliveredQueryTypeByReceiverVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(waitDeliveredQueryTypeByReceiverVO.getPageSize(), "每页条数不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		// 权限控制
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 判断是否是部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				waitDeliveredQueryTypeByReceiverVO.setIsDept(StatusConstant.IS_DEPT_YES);
				waitDeliveredQueryTypeByReceiverVO.setDepts(user.getDepts().toArray(new String[] {}));
			} else {
				waitDeliveredQueryTypeByReceiverVO.setIsDept(StatusConstant.IS_DEPT_NO);
				// 设置部门权限
				waitDeliveredQueryTypeByReceiverVO.setDepts(user.getDepts().toArray(new String[] {}));
				// 设置数据权限
				waitDeliveredQueryTypeByReceiverVO.setConsignors(user.getConsignors().toArray(new Long[] {}));
				waitDeliveredQueryTypeByReceiverVO.setWsarehouses(user.getWarehouses().toArray(new Long[] {}));
				waitDeliveredQueryTypeByReceiverVO.setCustomers(user.getCustomers().toArray(new Long[] {}));
				waitDeliveredQueryTypeByReceiverVO.setSuppliers(user.getSuppliers().toArray(new Long[] {}));
			}
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
			waitDeliveredQueryTypeByReceiverVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			throw new PrologException("当前人员没有操作权限");
		}
		waitDeliveredQueryTypeByReceiverVO.setUserType(user.getUserType());
		waitDeliveredQueryTypeByReceiverVO.setEnterpriseId(user.getEnterpriseId());

		PageUtils.startPage(waitDeliveredQueryTypeByReceiverVO.getPageNum(), waitDeliveredQueryTypeByReceiverVO.getPageSize());

		List<WaitDeliveredQueryTypeByReceiverDTO> waitDeliveredQueryTypeByReceiverDTOS = tmsLoadingBillHeaderMapper.waitDeliveredQueryTypeByReceiverPage(waitDeliveredQueryTypeByReceiverVO);

		// 行号
		int id = 1;
		for (WaitDeliveredQueryTypeByReceiverDTO dto : waitDeliveredQueryTypeByReceiverDTOS) {
			// 设置行id
			dto.setId(id);
			// 目的地
			dto.setConsigneeProvinceCityDistrict(dto.getConsigneeProvinceName() + dto.getConsigneeCityName() + dto.getConsigneeDistrictName());
			dto.setEstimatedDeliveryTime(DateRdcUtils.timeSplicing(dto.getEstimatedDeliveryStartTime(), dto.getEstimatedDeliveryEndTime()));

			// 行号自增长
			id++;
		}

		return PageUtils.getPage(waitDeliveredQueryTypeByReceiverDTOS);
	}

	/**
	 * 配载运单查询
	 *
	 * @param waitDeliveredReceiverGetShipbillVO
	 * @return
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<WaitDeliveredReceiverGetShipbillDTO> receiverGetShipbillData(WaitDeliveredReceiverGetShipbillVO waitDeliveredReceiverGetShipbillVO) {
		ToolKits.isParamNull(waitDeliveredReceiverGetShipbillVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(waitDeliveredReceiverGetShipbillVO.getPageSize(), "每页条数不为空");
		ToolKits.isParamNull(waitDeliveredReceiverGetShipbillVO.getShipbillIds(), "运单ID不为空");

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

		if (!user.getUserType().equals(BussinessConstant.USER_TYPE_ZY) && !user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
			ToolKits.isParamNull(user, "当前人员没有操作权限");
		}

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

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

		// 封装运单明细
		Criteria criteria = Criteria.forClass(TmsLoadingBillDetailModel.class);
		Restriction r1 = Restrictions.in("shipbillId", waitDeliveredReceiverGetShipbillVO.getShipbillIds().toArray());
		criteria.setRestriction(r1);
		criteria.setOrder(Order.newInstance().asc(new String[] { "shippingOrder" }));

		PageUtils.startPage(waitDeliveredReceiverGetShipbillVO.getPageNum(), waitDeliveredReceiverGetShipbillVO.getPageSize());
		List<TmsLoadingBillDetailModel> tmsLoadingBillDetailModels = tmsLoadingBillDetailMapper.findByCriteria(criteria);

		// 明细集合
		List<WaitDeliveredReceiverGetShipbillDTO> list = Lists.newArrayList();

		for (TmsLoadingBillDetailModel model : tmsLoadingBillDetailModels) {

			WaitDeliveredReceiverGetShipbillDTO waitDeliveredReceiverGetShipbillDTO = new WaitDeliveredReceiverGetShipbillDTO();
			BeanUtils.copyProperties(model, waitDeliveredReceiverGetShipbillDTO);

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

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

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

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

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

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

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

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

							waitDeliveredReceiverGetShipbillDTO.setSignConfigId(signconfigPopDTO.getId());

							break Signconfig;
						}
					}
					break;
				}
			}

			list.add(waitDeliveredReceiverGetShipbillDTO);
		}

		// 分页重组
		Page<WaitDeliveredReceiverGetShipbillDTO> page = PageUtils.getPage(list);
		if (tmsLoadingBillDetailModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsLoadingBillDetailModel> p0 = (com.github.pagehelper.Page<TmsLoadingBillDetailModel>) tmsLoadingBillDetailModels;
			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 waitDeliveredItemDetailVO
	 * @return
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<WaitDeliveredItemDetailDTO> itemDetailData(WaitDeliveredItemDetailVO waitDeliveredItemDetailVO) {
		ToolKits.isParamNull(waitDeliveredItemDetailVO.getShipbillIds(), "运单ID不为空");
		ToolKits.isParamNull(waitDeliveredItemDetailVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(waitDeliveredItemDetailVO.getPageSize(), "每页条数不为空");

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

		if (!user.getUserType().equals(BussinessConstant.USER_TYPE_ZY) && !user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
			ToolKits.isParamNull(user, "当前人员没有操作权限");
		}

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

		// 包装类型
		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();
		}

		// 根据运单ID查询明细数据
		Criteria criteria = Criteria.forClass(TmsShipbillDetailModel.class);
		Restriction r1 = Restrictions.in("shipbillId", waitDeliveredItemDetailVO.getShipbillIds().toArray());
		criteria.setRestriction(r1);

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

		// 返回数据集
		List<WaitDeliveredItemDetailDTO> list = Lists.newArrayList();

		for (TmsShipbillDetailModel tmsShipbillDetailModel : tmsShipbillDetailModels) {
			WaitDeliveredItemDetailDTO dto = new WaitDeliveredItemDetailDTO();
			BeanUtils.copyProperties(tmsShipbillDetailModel, dto);

			// 数据字典翻译
			dto.setPackTypeName(PublicMethods.change(data1, String.valueOf(dto.getPackType())));
			dto.setCargoThermosphereName(PublicMethods.change(data2, String.valueOf(dto.getCargoThermosphere())));
			dto.setWeight(NumberUtil.mul(dto.getPickUpPcs(), dto.getUnitWeight()));
			dto.setVolume(NumberUtil.mul(dto.getPickUpPcs(), dto.getUnitVolume()));

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

		// 分页重组
		Page<WaitDeliveredItemDetailDTO> page = PageUtils.getPage(list);
		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 waitDeliveredPackageDetailVO
	 * @return
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<WaitDeliveredPackageDetailDTO> packageDetailData(WaitDeliveredPackageDetailVO waitDeliveredPackageDetailVO) {
		ToolKits.isParamNull(waitDeliveredPackageDetailVO.getShipbillIds(), "运单ID不为空");
		ToolKits.isParamNull(waitDeliveredPackageDetailVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(waitDeliveredPackageDetailVO.getPageSize(), "每页条数不为空");

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

		if (!user.getUserType().equals(BussinessConstant.USER_TYPE_ZY) && !user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
			ToolKits.isParamNull(user, "当前人员没有操作权限");
		}

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

		// 包裹类型
		RestMessage<List<Map<String, Object>>> restMessage1 = maindataTmsResource.getDropDownById(DataDictionaryConstant.PACKAGE_TYPE, null, null, null);
		if (!restMessage1.isSuccess()) {
			throw new RuntimeException("包裹类型翻译失败!");
		} else {
			data1 = restMessage1.getData();
		}
		// 根据运单ID查询明细数据
		Criteria criteria = Criteria.forClass(TmsShipbillPackageModel.class);
		Restriction r1 = Restrictions.in("shipbillId", waitDeliveredPackageDetailVO.getShipbillIds().toArray());
		criteria.setRestriction(r1);

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

		// 返回数据集
		List<WaitDeliveredPackageDetailDTO> list = Lists.newArrayList();

		for (TmsShipbillPackageModel tmsShipbillPackageModel : tmsShipbillPackageModels) {
			WaitDeliveredPackageDetailDTO dto = new WaitDeliveredPackageDetailDTO();
			BeanUtils.copyProperties(tmsShipbillPackageModel, dto);

			// 数据字典翻译
			dto.setPackageTypeName(PublicMethods.change(data1, String.valueOf(dto.getPackageType())));

			// 设备类型翻译
			if (ToolKits.isNotEmpty(tmsShipbillPackageModel.getDeviceId())) {
				RestMessage<DeviceByOneDTO> deviceByOneDTORestMessage = maindataTmsResource.deviceGetOne(tmsShipbillPackageModel.getDeviceId());
				if (!deviceByOneDTORestMessage.isSuccess()) {
					throw new RuntimeException("获取设备失败!");
				}
				DeviceByOneDTO data = deviceByOneDTORestMessage.getData();
				ToolKits.isParamNull(data, "获取设备为空");

				dto.setDeviceTypeName(data.getTypeName());
			}

			list.add(dto);
		}

		// 分页重组
		Page<WaitDeliveredPackageDetailDTO> page = PageUtils.getPage(list);
		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 waitDeliveredExportAllVO
	 * @return
	 */
	@Override
	public List<WaitDeliveredExportShipbillDTO> exportAllShipbillData(WaitDeliveredExportAllVO waitDeliveredExportAllVO) {
		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>> 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();

		// 订单类型
		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>>> restMessage8 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPBILL_STATUS, null, null, null);
		if (!restMessage8.isSuccess()) {
			throw new RuntimeException("运单状态翻译失败!");
		} else {
			data8 = restMessage8.getData();
		}

		// 承运方类型
		RestMessage<List<Map<String, Object>>> restMessage9 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LINE_CARRIER_TYPE, 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();
		}

		// 权限控制
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 判断是否是部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				waitDeliveredExportAllVO.setIsDept(StatusConstant.IS_DEPT_YES);
				waitDeliveredExportAllVO.setDepts(user.getDepts().toArray(new String[] {}));
			} else {
				waitDeliveredExportAllVO.setIsDept(StatusConstant.IS_DEPT_NO);
				// 设置部门权限
				waitDeliveredExportAllVO.setDepts(user.getDepts().toArray(new String[] {}));
				// 设置数据权限
				waitDeliveredExportAllVO.setConsignors(user.getConsignors().toArray(new Long[] {}));
				waitDeliveredExportAllVO.setWsarehouses(user.getWarehouses().toArray(new Long[] {}));
				waitDeliveredExportAllVO.setCustomers(user.getCustomers().toArray(new Long[] {}));
				waitDeliveredExportAllVO.setSuppliers(user.getSuppliers().toArray(new Long[] {}));
			}
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
			waitDeliveredExportAllVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			throw new PrologException("当前人员没有操作权限");
		}
		waitDeliveredExportAllVO.setUserType(user.getUserType());
		waitDeliveredExportAllVO.setEnterpriseId(user.getEnterpriseId());

		// 返回数据集
		List<WaitDeliveredExportShipbillDTO> list = Lists.newArrayList();

		List<WaitDeliveredQueryByShipbillDTO> waitDeliveredQueryByShipbillDTOS = tmsLoadingBillHeaderMapper.waitDeliveredExportAllShipbillData(waitDeliveredExportAllVO);

		for (WaitDeliveredQueryByShipbillDTO waitDeliveredQueryByShipbillDTO : waitDeliveredQueryByShipbillDTOS) {

			WaitDeliveredExportShipbillDTO waitDeliveredExportShipbillDTO = new WaitDeliveredExportShipbillDTO();
			BeanUtils.copyProperties(waitDeliveredQueryByShipbillDTO, waitDeliveredExportShipbillDTO);

			// 类型翻译
			waitDeliveredExportShipbillDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(waitDeliveredQueryByShipbillDTO.getOrderType())));
			waitDeliveredExportShipbillDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(waitDeliveredQueryByShipbillDTO.getOrderBusinessType())));
			waitDeliveredExportShipbillDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(waitDeliveredQueryByShipbillDTO.getDeliveryMethodType())));
			waitDeliveredExportShipbillDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(waitDeliveredQueryByShipbillDTO.getTransportType())));
			waitDeliveredExportShipbillDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(waitDeliveredQueryByShipbillDTO.getTemperatureRequirement())));
			waitDeliveredExportShipbillDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(waitDeliveredQueryByShipbillDTO.getShipperType())));
			waitDeliveredExportShipbillDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(waitDeliveredQueryByShipbillDTO.getConsigneeType())));
			waitDeliveredExportShipbillDTO.setStatusName(PublicMethods.change(data8, String.valueOf(waitDeliveredQueryByShipbillDTO.getStatus())));
			waitDeliveredExportShipbillDTO.setCarrierTypeName(PublicMethods.change(data9, String.valueOf(waitDeliveredQueryByShipbillDTO.getCarrierType())));
			waitDeliveredExportShipbillDTO.setTransportStatusName(PublicMethods.change(data10, String.valueOf(waitDeliveredQueryByShipbillDTO.getTransportStatus())));
			waitDeliveredExportShipbillDTO.setAbnormalStatusName(PublicMethods.change(data11, String.valueOf(waitDeliveredQueryByShipbillDTO.getAbnormalStatus())));
			waitDeliveredExportShipbillDTO.setScanStatusName(PublicMethods.change(data12, String.valueOf(waitDeliveredQueryByShipbillDTO.getScanStatus())));

			StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
			// 目的地
			consigneeProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getConsigneeProvinceName());
			consigneeProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getConsigneeCityName());
			consigneeProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getConsigneeDistrictName());
			waitDeliveredExportShipbillDTO.setConsigneeProvinceCity(consigneeProvinceCityDistrict.toString());

			// 始发地
			StringBuffer shipperProvinceCityDistrict = new StringBuffer();
			shipperProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getShipperProvinceName());
			shipperProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getShipperCityName());
			shipperProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getShipperDistrictName());
			waitDeliveredExportShipbillDTO.setShipperProvinceCity(shipperProvinceCityDistrict.toString());

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

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

			list.add(waitDeliveredExportShipbillDTO);
		}
		return list;
	}

	/**
	 * 导出当前页数据
	 *
	 * @param waitDeliveredExportPageVO
	 * @return
	 */
	@SuppressWarnings("resource")
	@Override
	public List<WaitDeliveredExportShipbillDTO> exportPageShipbill(WaitDeliveredExportPageVO waitDeliveredExportPageVO) {
		ToolKits.isParamNull(waitDeliveredExportPageVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(waitDeliveredExportPageVO.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>> 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();

		// 订单类型
		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>>> restMessage8 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPBILL_STATUS, null, null, null);
		if (!restMessage8.isSuccess()) {
			throw new RuntimeException("运单状态翻译失败!");
		} else {
			data8 = restMessage8.getData();
		}

		// 承运方类型
		RestMessage<List<Map<String, Object>>> restMessage9 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LINE_CARRIER_TYPE, 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();
		}

		// 权限控制
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 判断是否是部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				waitDeliveredExportPageVO.setIsDept(StatusConstant.IS_DEPT_YES);
				waitDeliveredExportPageVO.setDepts(user.getDepts().toArray(new String[] {}));
			} else {
				waitDeliveredExportPageVO.setIsDept(StatusConstant.IS_DEPT_NO);
				// 设置部门权限
				waitDeliveredExportPageVO.setDepts(user.getDepts().toArray(new String[] {}));
				// 设置数据权限
				waitDeliveredExportPageVO.setConsignors(user.getConsignors().toArray(new Long[] {}));
				waitDeliveredExportPageVO.setWsarehouses(user.getWarehouses().toArray(new Long[] {}));
				waitDeliveredExportPageVO.setCustomers(user.getCustomers().toArray(new Long[] {}));
				waitDeliveredExportPageVO.setSuppliers(user.getSuppliers().toArray(new Long[] {}));
			}
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
			waitDeliveredExportPageVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			throw new PrologException("当前人员没有操作权限");
		}
		waitDeliveredExportPageVO.setUserType(user.getUserType());
		waitDeliveredExportPageVO.setEnterpriseId(user.getEnterpriseId());

		// 返回数据集
		List<WaitDeliveredExportShipbillDTO> list = Lists.newArrayList();

		PageUtils.startPage(waitDeliveredExportPageVO.getPageNum(), waitDeliveredExportPageVO.getPageSize());
		List<WaitDeliveredQueryByShipbillDTO> waitDeliveredQueryByShipbillDTOS = tmsLoadingBillHeaderMapper.waitDeliveredExportPageShipbillData(waitDeliveredExportPageVO);

		for (WaitDeliveredQueryByShipbillDTO waitDeliveredQueryByShipbillDTO : waitDeliveredQueryByShipbillDTOS) {

			WaitDeliveredExportShipbillDTO waitDeliveredExportShipbillDTO = new WaitDeliveredExportShipbillDTO();
			BeanUtils.copyProperties(waitDeliveredQueryByShipbillDTO, waitDeliveredExportShipbillDTO);

			// 类型翻译
			waitDeliveredExportShipbillDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(waitDeliveredQueryByShipbillDTO.getOrderType())));
			waitDeliveredExportShipbillDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(waitDeliveredQueryByShipbillDTO.getOrderBusinessType())));
			waitDeliveredExportShipbillDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(waitDeliveredQueryByShipbillDTO.getDeliveryMethodType())));
			waitDeliveredExportShipbillDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(waitDeliveredQueryByShipbillDTO.getTransportType())));
			waitDeliveredExportShipbillDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(waitDeliveredQueryByShipbillDTO.getTemperatureRequirement())));
			waitDeliveredExportShipbillDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(waitDeliveredQueryByShipbillDTO.getShipperType())));
			waitDeliveredExportShipbillDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(waitDeliveredQueryByShipbillDTO.getConsigneeType())));
			waitDeliveredExportShipbillDTO.setStatusName(PublicMethods.change(data8, String.valueOf(waitDeliveredQueryByShipbillDTO.getStatus())));
			waitDeliveredExportShipbillDTO.setCarrierTypeName(PublicMethods.change(data9, String.valueOf(waitDeliveredQueryByShipbillDTO.getCarrierType())));
			waitDeliveredExportShipbillDTO.setTransportStatusName(PublicMethods.change(data10, String.valueOf(waitDeliveredQueryByShipbillDTO.getTransportStatus())));
			waitDeliveredExportShipbillDTO.setAbnormalStatusName(PublicMethods.change(data11, String.valueOf(waitDeliveredQueryByShipbillDTO.getAbnormalStatus())));
			waitDeliveredExportShipbillDTO.setScanStatusName(PublicMethods.change(data12, String.valueOf(waitDeliveredQueryByShipbillDTO.getScanStatus())));

			StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
			// 目的地
			consigneeProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getConsigneeProvinceName());
			consigneeProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getConsigneeCityName());
			consigneeProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getConsigneeDistrictName());
			waitDeliveredExportShipbillDTO.setConsigneeProvinceCity(consigneeProvinceCityDistrict.toString());

			// 始发地
			StringBuffer shipperProvinceCityDistrict = new StringBuffer();
			shipperProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getShipperProvinceName());
			shipperProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getShipperCityName());
			shipperProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getShipperDistrictName());
			waitDeliveredExportShipbillDTO.setShipperProvinceCity(shipperProvinceCityDistrict.toString());

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

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

			list.add(waitDeliveredExportShipbillDTO);
		}

		Page<WaitDeliveredExportShipbillDTO> page = PageUtils.getPage(list);
		if (waitDeliveredQueryByShipbillDTOS instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<WaitDeliveredQueryByShipbillDTO> p0 = (com.github.pagehelper.Page<WaitDeliveredQueryByShipbillDTO>) waitDeliveredQueryByShipbillDTOS;
			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 shipbillIds
	 * @return
	 */
	@Override
	public List<WaitDeliveredExportShipbillDTO> exportSelectLineShipbillData(List<String> shipbillIds) {
		ToolKits.isParamNull(shipbillIds, "运单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>> 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();

		// 订单类型
		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>>> restMessage8 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPBILL_STATUS, null, null, null);
		if (!restMessage8.isSuccess()) {
			throw new RuntimeException("运单状态翻译失败!");
		} else {
			data8 = restMessage8.getData();
		}
		// 承运方类型
		RestMessage<List<Map<String, Object>>> restMessage9 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LINE_CARRIER_TYPE, 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();
		}

		// 返回数据集
		List<WaitDeliveredExportShipbillDTO> list = Lists.newArrayList();

		List<WaitDeliveredQueryByShipbillDTO> waitDeliveredQueryByShipbillDTOS = tmsLoadingBillHeaderMapper.waitDeliveredExportSelectLineShipbillData(shipbillIds.toArray(new String[] {}));

		for (WaitDeliveredQueryByShipbillDTO waitDeliveredQueryByShipbillDTO : waitDeliveredQueryByShipbillDTOS) {

			WaitDeliveredExportShipbillDTO waitDeliveredExportShipbillDTO = new WaitDeliveredExportShipbillDTO();
			BeanUtils.copyProperties(waitDeliveredQueryByShipbillDTO, waitDeliveredExportShipbillDTO);

			// 类型翻译
			waitDeliveredExportShipbillDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(waitDeliveredQueryByShipbillDTO.getOrderType())));
			waitDeliveredExportShipbillDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(waitDeliveredQueryByShipbillDTO.getOrderBusinessType())));
			waitDeliveredExportShipbillDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(waitDeliveredQueryByShipbillDTO.getDeliveryMethodType())));
			waitDeliveredExportShipbillDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(waitDeliveredQueryByShipbillDTO.getTransportType())));
			waitDeliveredExportShipbillDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(waitDeliveredQueryByShipbillDTO.getTemperatureRequirement())));
			waitDeliveredExportShipbillDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(waitDeliveredQueryByShipbillDTO.getShipperType())));
			waitDeliveredExportShipbillDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(waitDeliveredQueryByShipbillDTO.getConsigneeType())));
			waitDeliveredExportShipbillDTO.setStatusName(PublicMethods.change(data8, String.valueOf(waitDeliveredQueryByShipbillDTO.getStatus())));
			waitDeliveredExportShipbillDTO.setCarrierTypeName(PublicMethods.change(data9, String.valueOf(waitDeliveredQueryByShipbillDTO.getCarrierType())));
			waitDeliveredExportShipbillDTO.setTransportStatusName(PublicMethods.change(data10, String.valueOf(waitDeliveredQueryByShipbillDTO.getTransportStatus())));
			waitDeliveredExportShipbillDTO.setAbnormalStatusName(PublicMethods.change(data11, String.valueOf(waitDeliveredQueryByShipbillDTO.getAbnormalStatus())));
			waitDeliveredExportShipbillDTO.setScanStatusName(PublicMethods.change(data12, String.valueOf(waitDeliveredQueryByShipbillDTO.getScanStatus())));

			StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
			// 目的地
			consigneeProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getConsigneeProvinceName());
			consigneeProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getConsigneeCityName());
			consigneeProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getConsigneeDistrictName());
			waitDeliveredExportShipbillDTO.setConsigneeProvinceCity(consigneeProvinceCityDistrict.toString());

			// 始发地
			StringBuffer shipperProvinceCityDistrict = new StringBuffer();
			shipperProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getShipperProvinceName());
			shipperProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getShipperCityName());
			shipperProvinceCityDistrict.append(waitDeliveredQueryByShipbillDTO.getShipperDistrictName());
			waitDeliveredExportShipbillDTO.setShipperProvinceCity(shipperProvinceCityDistrict.toString());

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

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

			list.add(waitDeliveredExportShipbillDTO);
		}
		return list;
	}

	/**
	 * 待送达打印
	 *
	 * @param shipbillId
	 * @return
	 */
	@Override
	public Map<String, Object> printShipbillData(String shipbillId) {
		ToolKits.isParamNull(shipbillId, "运单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>> 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();
		List<Map<String, Object>> data14 = 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>>> restMessage8 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPBILL_STATUS, null, null, null);
		if (!restMessage8.isSuccess()) {
			throw new RuntimeException("运单状态翻译失败!");
		} else {
			data8 = restMessage8.getData();
		}
		// 承运方类型
		RestMessage<List<Map<String, Object>>> restMessage9 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LINE_CARRIER_TYPE, 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.PACK_TYPE, null, null, null);
		if (!restMessage13.isSuccess()) {
			throw new RuntimeException("包装类型翻译失败!");
		} else {
			data13 = restMessage13.getData();
		}
		// 货物温层
		RestMessage<List<Map<String, Object>>> restMessage14 = maindataTmsResource.getDropDownById(DataDictionaryConstant.CARGO_THERMOSPHERE, null, null, null);
		if (!restMessage14.isSuccess()) {
			throw new RuntimeException("货物温层翻译失败!");
		} else {
			data14 = restMessage14.getData();
		}

		// 查询条件
		String[] shipbillIds = new String[] { shipbillId };

		List<WaitPickUpGoodsQueryByShipbillDTO> waitPickUpGoodsQueryByShipbillDTOS = tmsLoadingBillHeaderMapper.waitPickUpGoodsExportSelectLineShipbillData(shipbillIds);
		ToolKits.isParamNull(waitPickUpGoodsQueryByShipbillDTOS, "运单ID[" + shipbillId + "]有误,查询为空!");

		WaitDeliveredPrintHeadDTO waitDeliveredPrintHeadDTO = new WaitDeliveredPrintHeadDTO();
		WaitPickUpGoodsQueryByShipbillDTO waitPickUpGoodsQueryByShipbillDTO = waitPickUpGoodsQueryByShipbillDTOS.get(0);
		BeanUtils.copyProperties(waitPickUpGoodsQueryByShipbillDTO, waitDeliveredPrintHeadDTO);

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

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

		// 类型翻译
		waitDeliveredPrintHeadDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(waitPickUpGoodsQueryByShipbillDTO.getOrderType())));
		waitDeliveredPrintHeadDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(waitPickUpGoodsQueryByShipbillDTO.getOrderBusinessType())));
		waitDeliveredPrintHeadDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(waitPickUpGoodsQueryByShipbillDTO.getDeliveryMethodType())));
		waitDeliveredPrintHeadDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(waitPickUpGoodsQueryByShipbillDTO.getTransportType())));
		waitDeliveredPrintHeadDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(waitPickUpGoodsQueryByShipbillDTO.getTemperatureRequirement())));
		waitDeliveredPrintHeadDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(waitPickUpGoodsQueryByShipbillDTO.getShipperType())));
		waitDeliveredPrintHeadDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(waitPickUpGoodsQueryByShipbillDTO.getConsigneeType())));
		waitDeliveredPrintHeadDTO.setStatusName(PublicMethods.change(data8, String.valueOf(waitPickUpGoodsQueryByShipbillDTO.getStatus())));
		waitDeliveredPrintHeadDTO.setCarrierTypeName(PublicMethods.change(data9, String.valueOf(waitPickUpGoodsQueryByShipbillDTO.getCarrierType())));
		waitDeliveredPrintHeadDTO.setTransportStatusName(PublicMethods.change(data10, String.valueOf(waitPickUpGoodsQueryByShipbillDTO.getTransportStatus())));
		waitDeliveredPrintHeadDTO.setAbnormalStatusName(PublicMethods.change(data11, String.valueOf(waitPickUpGoodsQueryByShipbillDTO.getAbnormalStatus())));
		waitDeliveredPrintHeadDTO.setScanStatusName(PublicMethods.change(data12, String.valueOf(waitPickUpGoodsQueryByShipbillDTO.getScanStatus())));

		// 查询运单明细
		Criteria criteria = Criteria.forClass(TmsShipbillDetailModel.class);
		Restriction r1 = Restrictions.eq("shipbillId", shipbillId);
		criteria.setRestriction(r1);
		List<TmsShipbillDetailModel> tmsShipbillDetailModels = tmsShipbillDetailMapper.findByCriteria(criteria);

		List<WaitDeliveredPrintDetailDTO> waitDeliveredPrintDetailDTOS = new ArrayList<>();

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

		// TODO print

		return null;
	}

	/**
	 * 待送达-送达确认
	 *
	 * @param waitDeliveredDeliveredConfirmVO
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void deliveredConfirmData(WaitDeliveredDeliveredConfirmVO waitDeliveredDeliveredConfirmVO) {
		ToolKits.isParamNull(waitDeliveredDeliveredConfirmVO.getShipbillIds(), "运单ID不能为空");
		ToolKits.isParamNull(waitDeliveredDeliveredConfirmVO.getDeliveryTime(), "送达时间不能为空");
		ToolKits.isParamNull(waitDeliveredDeliveredConfirmVO.getDeliveryStatus(), "配送状态不能为空");

		// 判断配送状态是滞留还是失败
		if (waitDeliveredDeliveredConfirmVO.getDeliveryStatus() == DataDictionaryConstant.DELIVERY_STATUS_STAY) {
			ToolKits.isParamNull(waitDeliveredDeliveredConfirmVO.getDeliveryStrandedReason(), "送达滞留原因不能为空");
		} else if (waitDeliveredDeliveredConfirmVO.getDeliveryStatus() == DataDictionaryConstant.DELIVERY_STATUS_FAILED) {
			ToolKits.isParamNull(waitDeliveredDeliveredConfirmVO.getDeliveryFailureReason(), "送达失败原因不能为空");
		}

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

		if (!user.getUserType().equals(BussinessConstant.USER_TYPE_ZY) && !user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
			ToolKits.isParamNull(user, "当前人员没有操作权限");
		}

		// 当前时间
		Date date = DateUtils.nowDate();
		// 签到时间是否为空
		boolean deliverySignTime = false;
		// 货物图片
		String goodsPhoto = "";
		// 回单图片
		String receiptPhoto = "";

		// 节点内容
		StringBuffer nodeEvent = new StringBuffer();
		nodeEvent.append("送达确认 送达签收人:");
		nodeEvent.append(ToolKits.isEmpty(waitDeliveredDeliveredConfirmVO.getDeliverySignPerson()) ? "" : waitDeliveredDeliveredConfirmVO.getDeliverySignPerson());
		nodeEvent.append(" 送达备注:");
		nodeEvent.append(ToolKits.isEmpty(waitDeliveredDeliveredConfirmVO.getDeliveryMemo()) ? "" : waitDeliveredDeliveredConfirmVO.getDeliveryMemo());

		List<TmsShipbillHeaderModel> tmsShipbillHeaderMapperByIds = tmsShipbillHeaderMapper.findByIds(TmsShipbillHeaderModel.class, waitDeliveredDeliveredConfirmVO.getShipbillIds().toArray(), null);

		if (ToolKits.isEmpty(tmsShipbillHeaderMapperByIds)) {
			throw new BizException("运单" + waitDeliveredDeliveredConfirmVO.getShipbillIds().stream().collect(Collectors.joining(",")) + "不存在");
		}
		if (tmsShipbillHeaderMapperByIds.stream().anyMatch(h->NumberUtil.isGreater(BigDecimal.valueOf(h.getStatus()),BigDecimal.valueOf(150)))) {
			throw new BizException("运单已送达");
		}
		/*tmsShipbillHeaderMapperByIds.forEach(tmsShipbillHeaderModel -> {
			if (!DataDictionaryConstant.TEMPERATURE_REQUIREMENT_CW.equals(tmsShipbillHeaderModel.getTemperatureRequirement())) {
				if (ObjectUtil.isNull(waitDeliveredDeliveredConfirmVO.getTemperatureVOList())) {
					throw new BizException("送达温度不能为空");
				}
				waitDeliveredDeliveredConfirmVO.getTemperatureVOList().forEach(vo -> {
					if (ObjectUtil.isNull(vo.getTemperature())) {
						throw new BizException("容器" + vo.getContainerName() + "温度为空");
					}
				});
			}
		});
		if (ToolKits.isNotEmpty(waitDeliveredDeliveredConfirmVO.getTemperatureVOList())) {
			updateTmsShipbillContainer(waitDeliveredDeliveredConfirmVO.getTemperatureVOList(),waitDeliveredDeliveredConfirmVO.getShipbillIds(),user);
		}*/

		// 判断签到时间是否需要必填
		List<TmsShipbillHeaderModel> tmsShipbillHeaderModels = tmsShipbillHeaderMapperByIds.stream().filter(o -> StatusConstant.WHETHER_YES == o.getConsigneeDeliverySign()).collect(Collectors.toList());
		if (ToolKits.isNotEmpty(tmsShipbillHeaderModels)) {
			ToolKits.isParamNull(waitDeliveredDeliveredConfirmVO.getDeliverySignTime(), "签到时间不能为空");
		}

		// 判断货物图片是否需要必填
		List<TmsShipbillHeaderModel> tmsShipbillHeaderModels2 = tmsShipbillHeaderMapperByIds.stream().filter(o -> StatusConstant.WHETHER_YES == o.getConsigneeDeliveryPicture()).collect(Collectors.toList());
		if (ToolKits.isNotEmpty(tmsShipbillHeaderModels2)) {
			ToolKits.isParamNull(waitDeliveredDeliveredConfirmVO.getGoodsPhoto(), "货物图片不能为空");
			goodsPhoto = waitDeliveredDeliveredConfirmVO.getGoodsPhoto();
		}

		if (CollectionUtil.isNotEmpty(waitDeliveredDeliveredConfirmVO.getItemVOList())) {
			Map<String, List<SignInItemVO>> listMap = waitDeliveredDeliveredConfirmVO.getItemVOList().stream().
					collect(Collectors.groupingBy(SignInItemVO::getShipbillId));
			listMap.forEach((key, value) -> updateSignInPcs(key, value));
		}

		Criteria criteriaTransport = Criteria.forClass(TmsShipbillTransLogModel.class);

		Map<String, Object> mapTransportLogUpdate = Maps.newHashMap();
		mapTransportLogUpdate.put("updateperson", user.getNickname());
		mapTransportLogUpdate.put("updatetime", date);
		// 送达时间
		mapTransportLogUpdate.put("deliveryTime", waitDeliveredDeliveredConfirmVO.getDeliveryTime());
		// 配送状态
		mapTransportLogUpdate.put("deliveryStatus", waitDeliveredDeliveredConfirmVO.getDeliveryStatus());
		// 签到时间
		if (ToolKits.isNotEmpty(waitDeliveredDeliveredConfirmVO.getDeliverySignTime())) {
			mapTransportLogUpdate.put("deliverySignTime", waitDeliveredDeliveredConfirmVO.getDeliverySignTime());
		}
		// 备注
		if (ToolKits.isNotEmpty(waitDeliveredDeliveredConfirmVO.getDeliveryMemo())) {
			mapTransportLogUpdate.put("deliveryMemo", waitDeliveredDeliveredConfirmVO.getDeliveryMemo());
		}
		// 签到时间
		if (ToolKits.isNotEmpty(waitDeliveredDeliveredConfirmVO.getDeliveryFailureReason())) {
			mapTransportLogUpdate.put("deliveryFailureReason", waitDeliveredDeliveredConfirmVO.getDeliveryFailureReason());
		}
		// 备注
		if (ToolKits.isNotEmpty(waitDeliveredDeliveredConfirmVO.getDeliveryStrandedReason())) {
			mapTransportLogUpdate.put("deliveryStrandedReason", waitDeliveredDeliveredConfirmVO.getDeliveryStrandedReason());
		}
		List<String> ids  = Lists.newArrayList();
		for (TmsShipbillHeaderModel tmsShipbillHeaderModel : tmsShipbillHeaderMapperByIds) {
			int status = DataDictionaryConstant.SHIPBILL_STATUS_END;
			Map<String, Object> mapDetailUpdate = Maps.newHashMap();

			// 修改运单
			tmsShipbillHeaderModel.setTransportStatus(DataDictionaryConstant.TRANSPORT_STATUS_ARRIVED);
			tmsShipbillHeaderModel.setUpdateperson(user.getNickname());
			tmsShipbillHeaderModel.setUpdatetime(date);

			Restriction r1 = Restrictions.eq("shipbillId", tmsShipbillHeaderModel.getShipbillId());
			criteriaTransport.setRestriction(r1);
			// 更新订单运输记录表
			tmsShipbillTransportLogMapper.updateMapByCriteria(mapTransportLogUpdate, criteriaTransport);

			// 运单节点信息
			ShipbillNodeTrackingSaveNewVO shipbillNodeTrackingSaveNewVO = new ShipbillNodeTrackingSaveNewVO();
			shipbillNodeTrackingSaveNewVO.setNodeDate(date);
			shipbillNodeTrackingSaveNewVO.setShipbillId(tmsShipbillHeaderModel.getShipbillId());
			shipbillNodeTrackingSaveNewVO.setShipbillNo(tmsShipbillHeaderModel.getShipbillId());
			shipbillNodeTrackingSaveNewVO.setUserId(user.getUserid());
			shipbillNodeTrackingSaveNewVO.setUserName(user.getNickname());
			shipbillNodeTrackingSaveNewVO.setEnterpriseId(user.getEnterpriseId());
			shipbillNodeTrackingSaveNewVO.setEnterpriseName(user.getEnterpriseName());

			// 运单日志信息
			ShipbillOperateLogSaveNewVO shipbillOperateLogSaveNewVO = new ShipbillOperateLogSaveNewVO();
			shipbillOperateLogSaveNewVO.setShipbillId(tmsShipbillHeaderModel.getShipbillId());
			shipbillOperateLogSaveNewVO.setShipbillNo(tmsShipbillHeaderModel.getShipbillId());
			shipbillOperateLogSaveNewVO.setOperateDate(date);
			shipbillOperateLogSaveNewVO.setEnterpriseId(user.getEnterpriseId());
			shipbillOperateLogSaveNewVO.setEnterpriseName(user.getEnterpriseName());
			shipbillOperateLogSaveNewVO.setUserId(user.getUserid());
			shipbillOperateLogSaveNewVO.setUserName(user.getNickname());

			if (ToolKits.isNotEmpty(waitDeliveredDeliveredConfirmVO.getDeliverySignTime())) {
				// 运单节点保存
				shipbillNodeTrackingSaveNewVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_SD);
				shipbillNodeTrackingSaveNewVO.setNodeEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_SDQD);
				shipbillNodeTrackingService.addShipbillNodeTrackingNewData(shipbillNodeTrackingSaveNewVO);

				// 运单日志保存
				shipbillOperateLogSaveNewVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_SDQD);
				shipbillOperateLogSaveNewVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_QY);
				shipbillOperateLogSaveNewVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_SD);
				shipbillOperateLogService.addShipbillOperateLogNewData(shipbillOperateLogSaveNewVO);

				deliverySignTime = true;
			}

			// 运单节点保存
			shipbillNodeTrackingSaveNewVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_SD);
			shipbillNodeTrackingSaveNewVO.setNodeEvent(nodeEvent.toString());
			shipbillNodeTrackingSaveNewVO.setPicUrl(waitDeliveredDeliveredConfirmVO.getGoodsPhoto());
			shipbillNodeTrackingService.addShipbillNodeTrackingNewData(shipbillNodeTrackingSaveNewVO);

			// 运单日志保存
			shipbillOperateLogSaveNewVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_SD);
			shipbillOperateLogSaveNewVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_QY);
			shipbillOperateLogSaveNewVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_SD);
			shipbillOperateLogService.addShipbillOperateLogNewData(shipbillOperateLogSaveNewVO);

			if (ToolKits.isNotEmpty(waitDeliveredDeliveredConfirmVO.getReceiptPhoto())) {
				if (tmsShipbillHeaderModel.getReturnOrderFlag() == DataDictionaryConstant.WHETHER_YES) {
					status = DataDictionaryConstant.SHIPBILL_STATUS_HD_ZB;
				}
				// 运单节点保存
				shipbillNodeTrackingSaveNewVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_HD_PIC);
				shipbillNodeTrackingSaveNewVO.setNodeEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_HD_PIC);
				shipbillNodeTrackingSaveNewVO.setPicUrl(waitDeliveredDeliveredConfirmVO.getReceiptPhoto());
				shipbillNodeTrackingService.addShipbillNodeTrackingNewData(shipbillNodeTrackingSaveNewVO);

				// 运单日志保存
				shipbillOperateLogSaveNewVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_HD_PIC);
				shipbillOperateLogSaveNewVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_QY);
				shipbillOperateLogSaveNewVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_HD_PIC);
				shipbillOperateLogService.addShipbillOperateLogNewData(shipbillOperateLogSaveNewVO);

				receiptPhoto = waitDeliveredDeliveredConfirmVO.getReceiptPhoto();

				mapDetailUpdate.put("status", status);
			} else {
				if (tmsShipbillHeaderModel.getConsigneeReturnOrderPicture() == DataDictionaryConstant.WHETHER_YES) {
					status = DataDictionaryConstant.SHIPBILL_STATUS_HD_PIC;
				} else if (tmsShipbillHeaderModel.getReturnOrderFlag() == DataDictionaryConstant.WHETHER_YES) {
					status = DataDictionaryConstant.SHIPBILL_STATUS_HD_ZB;
				}
				mapDetailUpdate.put("status", status);
			}

			// 运单修改操作
			tmsShipbillHeaderModel.setStatus(status);
			tmsShipbillHeaderModel.setDeliveryTemperature(waitDeliveredDeliveredConfirmVO.getDeliveryTemperature());
			tmsShipbillHeaderModel.setDeliveryTime(waitDeliveredDeliveredConfirmVO.getDeliveryTime());

			TmsShipbillHeaderModel headerModel = tmsShipbillHeaderMapper.findById(tmsShipbillHeaderModel.getShipbillId(),TmsShipbillHeaderModel.class);
			if (DataDictionaryConstant.SHIPBILL_STATUS_SD.intValue() < headerModel.getStatus().intValue()) {
				throw new PrologException(StrUtil.format("运单{}已送达确认",tmsShipbillHeaderModel.getShipbillNo()));
			}
			tmsShipbillHeaderMapper.update(tmsShipbillHeaderModel);

			// 修改派车单明细
			Criteria criteriaDetail = Criteria.forClass(TmsLoadingBillDetailModel.class);
			r1 = Restrictions.eq("shipbillId", tmsShipbillHeaderModel.getShipbillId());
			Restriction r2 = Restrictions.eq(TmsLoadingBillDetailModel::getEnterpriseId, user.getEnterpriseId());
			criteriaDetail.setRestriction(Restrictions.and(r1, r2));
			criteriaDetail.setOrder(Order.newInstance().desc(new String[] { "createtime" }));
			List<TmsLoadingBillDetailModel> tmsLoadingBillDetails = tmsLoadingBillDetailMapper.findByCriteria(criteriaDetail);
			if (ToolKits.isEmpty(tmsLoadingBillDetails)) {
				throw new PrologException("装车单明细【" + tmsShipbillHeaderModel.getShipbillId() + "】查询失败");
			}
			TmsLoadingBillDetailModel tmsLoadingBillDetail = tmsLoadingBillDetails.get(0);

			mapDetailUpdate.put("transportStatus", DataDictionaryConstant.TRANSPORT_STATUS_ARRIVED);
			mapDetailUpdate.put("updateperson", user.getNickname());
			mapDetailUpdate.put("updatetime", date);
			mapDetailUpdate.put("deliveryTemperature", waitDeliveredDeliveredConfirmVO.getDeliveryTemperature());
			tmsLoadingBillDetailMapper.updateMapById(tmsLoadingBillDetail.getId(), mapDetailUpdate, TmsLoadingBillDetailModel.class);

			// 父运单的同步送达
			String fatherShipbillId = tmsShipbillHeaderModel.getShipbillId();
			while (ToolKits.isNotEmpty(fatherShipbillId)) {
				fatherShipbillId = fatherDeliveredConfirm(status, fatherShipbillId, date, user, deliverySignTime, goodsPhoto, receiptPhoto, nodeEvent.toString(), mapTransportLogUpdate);
				deliverySignTime = false;
			}

			// STD-BUG20220823 lhb 4649启运登记、送达确认 需要同步回写 派车单的状态 20220915 start
			// 更新调度单状态
			Restriction r3 = Restrictions.eq("loadingBillId", tmsLoadingBillDetail.getLoadingBillId());
			Restriction r4 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
			criteriaDetail.setRestriction(Restrictions.and(r3, r4));
			List<TmsLoadingBillDetailModel> tmsLoadingBillDetailModels = tmsLoadingBillDetailMapper.findByCriteria(criteriaDetail);
			int cnt = 0;
			if (ToolKits.isNotEmpty(tmsLoadingBillDetailModels)) {
				TmsLoadingBillHeaderModel secondLoadingBillHeaderModel = tmsLoadingBillHeaderMapper.findById(tmsLoadingBillDetail.getLoadingBillId(), TmsLoadingBillHeaderModel.class);

				// 运单，第一次调度，调度给承运商，第二次调度，承运商调度给司机或者承运商时，根据第二调度单，查询第一次的调度单
				criteriaDetail = Criteria.forClass(TmsLoadingBillDetailModel.class);
				r1 = Restrictions.eq(TmsLoadingBillDetailModel::getShipbillId, tmsShipbillHeaderModel.getShipbillId());
				r2 = Restrictions.eq(TmsLoadingBillDetailModel::getEnterpriseId, user.getEnterpriseId());
				r3 = Restrictions.ne(TmsLoadingBillDetailModel::getLoadingBillId, tmsLoadingBillDetail.getLoadingBillId());
				criteriaDetail.setRestriction(Restrictions.and(r1, r2, r3));
				List<TmsLoadingBillDetailModel> firstLoadingBillDetails = tmsLoadingBillDetailMapper.findByCriteria(criteriaDetail);
				cnt = tmsLoadingBillDetailModels.stream().filter(t -> t.getStatus().intValue() < DataDictionaryConstant.SHIPBILL_STATUS_HD_PIC.intValue()).collect(Collectors.toList()).size();
				if (cnt == 0) {
					// 更新状态为送达确认
					secondLoadingBillHeaderModel.setStatus(DataDictionaryConstant.LOADING_BILL_STATUS_SD);
					tmsLoadingBillHeaderMapper.update(secondLoadingBillHeaderModel);
					// 第一次调度单状态更新
					if (ToolKits.isNotEmpty(firstLoadingBillDetails)) {
						TmsLoadingBillHeaderModel firstLoadingBillHeaderModel = tmsLoadingBillHeaderMapper.findById(firstLoadingBillDetails.get(0).getLoadingBillId(), TmsLoadingBillHeaderModel.class);
						firstLoadingBillHeaderModel.setStatus(DataDictionaryConstant.LOADING_BILL_STATUS_SD);
						tmsLoadingBillHeaderMapper.update(firstLoadingBillHeaderModel);
					}
				} else {
					// 更新状态为部分送达确认
					if (!secondLoadingBillHeaderModel.getStatus().equals(DataDictionaryConstant.LOADING_BILL_STATUS_SD_PART)) {
						secondLoadingBillHeaderModel.setStatus(DataDictionaryConstant.LOADING_BILL_STATUS_SD_PART);
						tmsLoadingBillHeaderMapper.update(secondLoadingBillHeaderModel);
						// 第一次调度单状态更新
						if (ToolKits.isNotEmpty(firstLoadingBillDetails)) {
							TmsLoadingBillHeaderModel firstLoadingBillHeaderModel = tmsLoadingBillHeaderMapper.findById(firstLoadingBillDetails.get(0).getLoadingBillId(), TmsLoadingBillHeaderModel.class);
							firstLoadingBillHeaderModel.setStatus(DataDictionaryConstant.LOADING_BILL_STATUS_SD_PART);
							tmsLoadingBillHeaderMapper.update(firstLoadingBillHeaderModel);
						}
					}
				}
			}
			// STD-BUG20220823 lhb 4649启运登记、送达确认 需要同步回写 派车单的状态 20220915 end

			// 运单同步BMS
			if (status == DataDictionaryConstant.SHIPBILL_STATUS_END.intValue() &&
					!DataDictionaryConstant.SHIPBILL_ABNORMAL_STATUS.equals(tmsShipbillHeaderModel.getAbnormalStatus())) {
				ids.add(tmsLoadingBillDetail.getId());
			}

			TmsLoadingBillHeaderModel tmsLoadingBillHeaderModel = tmsLoadingBillHeaderMapper.findById(tmsLoadingBillDetail.getLoadingBillId(), TmsLoadingBillHeaderModel.class);
			if (StrUtil.isNotBlank(tmsLoadingBillHeaderModel.getVehicleDeviceId()) && StrUtil.isNotBlank(tmsLoadingBillHeaderModel.getVehicleDeviceCode())) {
				Criteria criteria = Criteria.forClass(TmsLoadingBillHeaderModel.class);
				Restriction restriction1 = Restrictions.eq(TmsLoadingBillHeaderModel::getVehicleDeviceCode, tmsLoadingBillHeaderModel.getVehicleDeviceCode());
				Restriction restriction2 = Restrictions.in(TmsLoadingBillHeaderModel::getStatus, Lists.newArrayList(DataDictionaryConstant.LOADING_BILL_STATUS_QY_PART, DataDictionaryConstant.LOADING_BILL_STATUS_QY, DataDictionaryConstant.LOADING_BILL_STATUS_SD_PART));
				criteria.setRestriction(Restrictions.and(restriction1, restriction2));
				if (tmsLoadingBillHeaderMapper.findCountByCriteria(criteria) == 0) {
					String deviceId = tmsLoadingBillHeaderModel.getVehicleDeviceId().split(",")[0];
					try {
						RestMessage<DeviceByOneDTO> restMessage = maindataTmsResource.deviceGetOne(Long.valueOf(deviceId));
						DeviceByOneDTO deviceByOneDTO = restMessage.getData();
						if (BussinessConstant.E6.equals(deviceByOneDTO.getCompanyName())) {
							redisTemplate.opsForSet().remove(RedisConstant.PULL_GPS_DEVICE_E6_KEY, tmsLoadingBillHeaderModel.getVehicleDeviceCode());
							log.info("易流 remove loadingBillId={},vehicle={},deviceCode={}", tmsLoadingBillDetail.getLoadingBillId(), tmsLoadingBillHeaderModel.getVehiclePlateNumber(), deviceByOneDTO.getCode());
						} else if (BussinessConstant.G7.equals(deviceByOneDTO.getCompanyName())) {
							redisTemplate.opsForSet().remove(RedisConstant.PULL_GPS_DEVICE_G7_KEY, tmsLoadingBillHeaderModel.getVehicleDeviceCode());
							log.info("g7 remove loadingBillId={},vehicle={},deviceCode={}", tmsLoadingBillDetail.getLoadingBillId(), tmsLoadingBillHeaderModel.getVehiclePlateNumber(), deviceByOneDTO.getCode());
						}
					} catch (Exception e) {
						log.error("移除redis队列错误", e);
					}
				}
			}

			MessageUtil.addMessage(new SendMessageDTO(MessageOrderTypeEnum.SHIP_NO.getCode(), MessageTypeEnum.DELIVERY.getCode(), Lists.newArrayList(tmsShipbillHeaderModel.getShipbillId())));
		}
		// 运单同步BMS
		if (ToolKits.isNotEmpty(ids)) {
			shipbillCommonService.pushShipbillBmsData(ids);
		}

	}

	private void updateSignInPcs(String shipBillId, List<SignInItemVO> itemVOList) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		// 修改运单明细签收数量
		Map<Long, SignInItemVO> itemVOMap = itemVOList.stream().collect(Collectors.toMap(t1 -> t1.getItemId(), t2 -> t2, (t1, t2) -> t2));
		Criteria criteria = Criteria.forClass(TmsShipbillDetailModel.class);
		Restriction restriction = new RestrictionBuilder()
				.eq("shipbillId", shipBillId)
				.build();
		criteria.setRestriction(restriction);
		List<TmsShipbillDetailModel> shipBillDetailModelList = tmsShipbillDetailMapper.findByCriteria(criteria);
		shipBillDetailModelList.stream().forEach(shipBillDetailModel -> {
			SignInItemVO itemVO = itemVOMap.get(shipBillDetailModel.getItemId());
			if (ObjectUtil.isNotNull(itemVO)) {
				shipBillDetailModel.setUpdatetime(new Date());
				shipBillDetailModel.setUpdateperson(user.getNickname());
				shipBillDetailModel.setSignInPcs(NumberUtil.add(shipBillDetailModel.getSignInPcs(), itemVO.getSignInPcs()));
				tmsShipbillDetailMapper.update(shipBillDetailModel);
			}
		});
		TmsShipbillHeaderModel tmsShipBillHeaderModel =
				tmsShipbillHeaderMapper.findById(shipBillId, TmsShipbillHeaderModel.class);
		// 递归更新父级运单明细签收数量
		String fatherShipBillId = tmsShipBillHeaderModel.getFatherShipbillId();
		while(StrUtil.isNotBlank(fatherShipBillId)){
			Criteria fatherDetailCriteria = Criteria.forClass(TmsShipbillDetailModel.class);
			Restriction fatherDetailRestriction = new RestrictionBuilder()
					.eq("shipbillId", fatherShipBillId)
					.build();
			fatherDetailCriteria.setRestriction(fatherDetailRestriction);
			List<TmsShipbillDetailModel> fatherDetail = tmsShipbillDetailMapper.findByCriteria(fatherDetailCriteria);
			// 父级明细统计下一级明细数量并更新
			List<TmsShipbillHeaderModel> tmsShipBillHeaderModelList = getChildTmsShipBillHeaderModel(fatherShipBillId);
			if (CollectionUtil.isNotEmpty(tmsShipBillHeaderModelList)) {
				List<String> shipBillIdList = tmsShipBillHeaderModelList.stream().map(TmsShipbillHeaderModel::getShipbillId).collect(Collectors.toList());
				//查询子单对应商品的明细
				List<TmsShipbillDetailModel> childDetail = getTmsShipBillDetailModel(shipBillIdList, Lists.newArrayList(itemVOMap.keySet()));
				Map<Long, List<TmsShipbillDetailModel>> itemMap = childDetail.stream().collect(Collectors.groupingBy(TmsShipbillDetailModel::getItemId));
				fatherDetail.stream().forEach(shipBillDetailModel -> {
					List<TmsShipbillDetailModel> childDetailList = itemMap.get(shipBillDetailModel.getItemId());
					if (CollectionUtil.isNotEmpty(childDetailList)) {
						shipBillDetailModel.setUpdatetime(new Date());
						shipBillDetailModel.setUpdateperson(user.getNickname());
						shipBillDetailModel.setSignInPcs(childDetailList.stream().map(TmsShipbillDetailModel::getSignInPcs).reduce(BigDecimal.ZERO, NumberUtil::add));
						tmsShipbillDetailMapper.update(shipBillDetailModel);
					}
				});
			}
			TmsShipbillHeaderModel fatherHeader =
					tmsShipbillHeaderMapper.findById(fatherShipBillId, TmsShipbillHeaderModel.class);
			if (ObjectUtil.isNotNull(fatherHeader)) {
				fatherShipBillId = fatherHeader.getFatherShipbillId();
			} else {
				fatherShipBillId = StrUtil.EMPTY;
			}
		}
	}

	/**
	 * 通过父级运单找子单
	 * @param shipBillId
	 * @return
	 */
	private List<TmsShipbillHeaderModel> getChildTmsShipBillHeaderModel(String shipBillId) {
		Criteria criteria = Criteria.forClass(TmsShipbillHeaderModel.class);
		Restriction restriction = new RestrictionBuilder()
				.eq("fatherShipbillId", shipBillId)
				.build();
		criteria.setRestriction(restriction);
		return tmsShipbillHeaderMapper.findByCriteria(criteria);
	}

	/**
	 * 通过运单和商品id找运单明细
	 * @param shipBillIdList
	 * @param itemIdList
	 * @return
	 */
	private List<TmsShipbillDetailModel> getTmsShipBillDetailModel(List<String> shipBillIdList, List<Long> itemIdList) {
		Criteria criteria = Criteria.forClass(TmsShipbillDetailModel.class);
		Restriction restriction = new RestrictionBuilder()
				.in("shipbillId", shipBillIdList.toArray())
				.in("itemId", itemIdList.toArray())
				.build();
		criteria.setRestriction(restriction);
		return tmsShipbillDetailMapper.findByCriteria(criteria);
	}

	/**
	 * 父运单同步送达
	 *
	 * @param shipbillId
	 * @param date
	 * @param user
	 * @param deliverySignTime
	 * @param goodsPhoto
	 * @param receiptPhoto
	 * @param mapTransportLogUpdate
	 * @return
	 */
	private String fatherDeliveredConfirm(Integer status, String shipbillId, Date date, UserEntity user, boolean deliverySignTime, String goodsPhoto, String receiptPhoto, String nodeEvent, Map<String, Object> mapTransportLogUpdate) {
		// 查询运单
		TmsShipbillHeaderModel tmsShipbillHeaderModel = tmsShipbillHeaderMapper.findById(shipbillId, TmsShipbillHeaderModel.class);

		// 判断是否为原始单号
		if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getFatherShipbillId()) && !tmsShipbillHeaderModel.getFatherShipbillId().equals(shipbillId)) {
			// 查找父级单号
			TmsShipbillHeaderModel fatherShipbillHeaderModel = tmsShipbillHeaderMapper.findById(tmsShipbillHeaderModel.getFatherShipbillId(), TmsShipbillHeaderModel.class);

			// 查找同级的所有子单
			Criteria criteria = Criteria.forClass(TmsShipbillHeaderModel.class);
			Restriction r1 = Restrictions.eq("fatherShipbillId", tmsShipbillHeaderModel.getFatherShipbillId());
			criteria.setRestriction(r1);
			List<TmsShipbillHeaderModel> tmsShipbillHeaderModelList = tmsShipbillHeaderMapper.findByCriteria(criteria);

			// 查找是否还有未完成的运单
			List<TmsShipbillHeaderModel> tmsShipbillHeaderModels = tmsShipbillHeaderModelList.stream().filter(o -> o.getStatus().intValue() <= DataDictionaryConstant.SHIPBILL_STATUS_SD.intValue()).collect(Collectors.toList());

			// 判断子单是否全部完成
			if (ToolKits.isEmpty(tmsShipbillHeaderModels)) {
				// 修改父级运单状态
				fatherShipbillHeaderModel.setStatus(status);
				fatherShipbillHeaderModel.setTransportStatus(DataDictionaryConstant.TRANSPORT_STATUS_ARRIVED);
				fatherShipbillHeaderModel.setUpdatetime(date);
				fatherShipbillHeaderModel.setUpdateperson(user.getNickname());

				// 修改父级运单运输记录表
				Criteria criteriaTransport = Criteria.forClass(TmsShipbillTransLogModel.class);
				r1 = Restrictions.eq("shipbillId", fatherShipbillHeaderModel.getShipbillId());
				criteriaTransport.setRestriction(r1);
				// 更新订单运输记录表
				tmsShipbillTransportLogMapper.updateMapByCriteria(mapTransportLogUpdate, criteriaTransport);

				// 运单节点信息
				ShipbillNodeTrackingSaveNewVO shipbillNodeTrackingSaveNewVO = new ShipbillNodeTrackingSaveNewVO();
				shipbillNodeTrackingSaveNewVO.setNodeDate(date);
				shipbillNodeTrackingSaveNewVO.setShipbillId(fatherShipbillHeaderModel.getShipbillId());
				shipbillNodeTrackingSaveNewVO.setShipbillNo(fatherShipbillHeaderModel.getShipbillId());
				shipbillNodeTrackingSaveNewVO.setUserId(user.getUserid());
				shipbillNodeTrackingSaveNewVO.setUserName(user.getNickname());
				shipbillNodeTrackingSaveNewVO.setEnterpriseId(user.getEnterpriseId());
				shipbillNodeTrackingSaveNewVO.setEnterpriseName(user.getEnterpriseName());

				// 运单日志信息
				ShipbillOperateLogSaveNewVO shipbillOperateLogSaveNewVO = new ShipbillOperateLogSaveNewVO();
				shipbillOperateLogSaveNewVO.setShipbillId(fatherShipbillHeaderModel.getShipbillId());
				shipbillOperateLogSaveNewVO.setShipbillNo(fatherShipbillHeaderModel.getShipbillId());
				shipbillOperateLogSaveNewVO.setOperateDate(date);
				shipbillOperateLogSaveNewVO.setEnterpriseId(user.getEnterpriseId());
				shipbillOperateLogSaveNewVO.setEnterpriseName(user.getEnterpriseName());
				shipbillOperateLogSaveNewVO.setUserId(user.getUserid());
				shipbillOperateLogSaveNewVO.setUserName(user.getNickname());

				// 判断第一个子单是否有签到时间
				if (deliverySignTime) {
					// 运单节点保存
					shipbillNodeTrackingSaveNewVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_SD);
					shipbillNodeTrackingSaveNewVO.setNodeEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_SDQD);
					shipbillNodeTrackingService.addShipbillNodeTrackingNewData(shipbillNodeTrackingSaveNewVO);

					// 运单日志保存
					shipbillOperateLogSaveNewVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_SDQD);
					shipbillOperateLogSaveNewVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_QY);
					shipbillOperateLogSaveNewVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_SD);
					shipbillOperateLogService.addShipbillOperateLogNewData(shipbillOperateLogSaveNewVO);
				}

				// 运单节点保存
				shipbillNodeTrackingSaveNewVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_SD);
				shipbillNodeTrackingSaveNewVO.setNodeEvent(nodeEvent);
				shipbillNodeTrackingSaveNewVO.setPicUrl(goodsPhoto);
				shipbillNodeTrackingService.addShipbillNodeTrackingNewData(shipbillNodeTrackingSaveNewVO);

				// 运单日志保存
				shipbillOperateLogSaveNewVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_SD);
				shipbillOperateLogSaveNewVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_QY);
				shipbillOperateLogSaveNewVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_SD);
				shipbillOperateLogService.addShipbillOperateLogNewData(shipbillOperateLogSaveNewVO);

				// 回单日志
				if (ToolKits.isNotEmpty(receiptPhoto)) {
					// 运单节点保存
					shipbillNodeTrackingSaveNewVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_HD_PIC);
					shipbillNodeTrackingSaveNewVO.setNodeEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_HD_PIC);
					shipbillNodeTrackingSaveNewVO.setPicUrl(receiptPhoto);
					shipbillNodeTrackingService.addShipbillNodeTrackingNewData(shipbillNodeTrackingSaveNewVO);

					// 运单日志保存
					shipbillOperateLogSaveNewVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_HD_PIC);
					shipbillOperateLogSaveNewVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_SD);
					shipbillOperateLogSaveNewVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_HD_PIC);
					shipbillOperateLogService.addShipbillOperateLogNewData(shipbillOperateLogSaveNewVO);

					fatherShipbillHeaderModel.setStatus(DataDictionaryConstant.LOADING_BILL_STATUS_HD_ZB);
				}

				tmsShipbillHeaderMapper.update(fatherShipbillHeaderModel);
				return fatherShipbillHeaderModel.getShipbillId();
			}
		}
		return null;
	}

	/**
	 * 待送达-运单容器查询
	 *
	 * @param shipbillIds
	 */
	public List<TmsShipbillContainerDTO> deliveredContainerQuery(List<String> shipbillIds) {
		ToolKits.isParamNull(shipbillIds, "容器查询请求不为空");

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

		List<TmsShipbillContainerDTO> containerDTOS = Lists.newArrayList();

		Criteria criteria = Criteria.forClass(TmsShipbillContainerTemp.class);
		Restriction r1 = Restrictions.eq(TmsShipbillContainerTemp::getEnterpriseId, user.getEnterpriseId());
		Restriction r2 = Restrictions.in(TmsShipbillContainerTemp::getShipbillId, shipbillIds.stream().toArray());
		criteria.setRestriction(Restrictions.and(r1, r2));
		List<TmsShipbillContainerTemp> containerTemps = shipbillContainerTempMapper.findByCriteria(criteria);
		if (ToolKits.isEmpty(containerTemps)) {
			return containerDTOS;
		}
		containerTemps = containerTemps.stream().
				collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(TmsShipbillContainerTemp::getContainerId))), ArrayList::new));
		for (TmsShipbillContainerTemp containerTemp:containerTemps) {
			TmsShipbillContainerDTO containerDTO = new TmsShipbillContainerDTO();
			BeanUtil.copyProperties(containerTemp,containerDTO);
			containerDTO.setTemperature(containerTemp.getDepartureTemp());
			containerDTOS.add(containerDTO);
		}

		return containerDTOS;
	}
	@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRES_NEW)
	public void autoDeliveredConfirmData(WaitDeliveredDeliveredConfirmVO waitDeliveredDeliveredConfirmVO) {
		ToolKits.isParamNull(waitDeliveredDeliveredConfirmVO.getShipbillIds(), "运单ID不能为空");
		ToolKits.isParamNull(waitDeliveredDeliveredConfirmVO.getDeliveryTime(), "送达时间不能为空");
		log.info("运单{}自动送达开始...", JSONObject.toJSONString(waitDeliveredDeliveredConfirmVO.getShipbillIds()));
		// 当前时间
		Date date = DateUtils.nowDate();
		// 节点内容
		StringBuffer nodeEvent = new StringBuffer();
		nodeEvent.append("送达确认 送达签收人:");
		nodeEvent.append(ToolKits.isEmpty(waitDeliveredDeliveredConfirmVO.getDeliverySignPerson()) ? "" : waitDeliveredDeliveredConfirmVO.getDeliverySignPerson());
		nodeEvent.append(" 送达备注:");
		nodeEvent.append(ToolKits.isEmpty(waitDeliveredDeliveredConfirmVO.getDeliveryMemo()) ? "" : waitDeliveredDeliveredConfirmVO.getDeliveryMemo());

		List<TmsShipbillHeaderModel> tmsShipbillHeaderMapperByIds = tmsShipbillHeaderMapper.findByIds(TmsShipbillHeaderModel.class, waitDeliveredDeliveredConfirmVO.getShipbillIds().toArray(), null);

		Criteria criteriaTransport = Criteria.forClass(TmsShipbillTransLogModel.class);

		Map<String, Object> mapTransportLogUpdate = Maps.newHashMap();
		mapTransportLogUpdate.put("updatetime", date);
		// 送达时间
		mapTransportLogUpdate.put("deliveryTime", waitDeliveredDeliveredConfirmVO.getDeliveryTime());
		// 配送状态
		mapTransportLogUpdate.put("deliveryStatus", waitDeliveredDeliveredConfirmVO.getDeliveryStatus());
		// 签到时间
		if (ToolKits.isNotEmpty(waitDeliveredDeliveredConfirmVO.getDeliverySignTime())) {
			mapTransportLogUpdate.put("deliverySignTime", waitDeliveredDeliveredConfirmVO.getDeliverySignTime());
		}
		// 备注
		if (ToolKits.isNotEmpty(waitDeliveredDeliveredConfirmVO.getDeliveryMemo())) {
			mapTransportLogUpdate.put("deliveryMemo", waitDeliveredDeliveredConfirmVO.getDeliveryMemo());
		}
		// 签到时间
		if (ToolKits.isNotEmpty(waitDeliveredDeliveredConfirmVO.getDeliveryFailureReason())) {
			mapTransportLogUpdate.put("deliveryFailureReason", waitDeliveredDeliveredConfirmVO.getDeliveryFailureReason());
		}
		// 备注
		if (ToolKits.isNotEmpty(waitDeliveredDeliveredConfirmVO.getDeliveryStrandedReason())) {
			mapTransportLogUpdate.put("deliveryStrandedReason", waitDeliveredDeliveredConfirmVO.getDeliveryStrandedReason());
		}
		int status = DataDictionaryConstant.SHIPBILL_STATUS_END;
		List<String> ids  = Lists.newArrayList();
		UserDTO userDTO = userProxy.getUserInfo(systemUsername);
		UserEntity user = new UserEntity();
		user.setNickname(userDTO.getNickname());
		user.setUserid(Long.valueOf(userDTO.getId()));
		user.setEnterpriseId(Long.valueOf(userDTO.getEnterpriseId()));
		user.setEnterpriseName(userDTO.getEnterpriseName());
		for (TmsShipbillHeaderModel tmsShipbillHeaderModel : tmsShipbillHeaderMapperByIds) {
			if (DataDictionaryConstant.SHIPBILL_STATUS_SD.intValue() < tmsShipbillHeaderModel.getStatus().intValue()) {
				throw new PrologException(StrUtil.format("运单{}已送达",tmsShipbillHeaderModel.getShipbillNo()));
			}
			Map<String, Object> mapDetailUpdate = Maps.newHashMap();

			// 修改运单
			tmsShipbillHeaderModel.setTransportStatus(DataDictionaryConstant.TRANSPORT_STATUS_ARRIVED);
			tmsShipbillHeaderModel.setUpdatetime(date);

			Restriction r1 = Restrictions.eq("shipbillId", tmsShipbillHeaderModel.getShipbillId());
			criteriaTransport.setRestriction(r1);
			// 更新订单运输记录表
			tmsShipbillTransportLogMapper.updateMapByCriteria(mapTransportLogUpdate, criteriaTransport);

			// 运单节点信息
			ShipbillNodeTrackingSaveNewVO shipbillNodeTrackingSaveNewVO = new ShipbillNodeTrackingSaveNewVO();
			shipbillNodeTrackingSaveNewVO.setNodeDate(date);
			shipbillNodeTrackingSaveNewVO.setShipbillId(tmsShipbillHeaderModel.getShipbillId());
			shipbillNodeTrackingSaveNewVO.setShipbillNo(tmsShipbillHeaderModel.getShipbillId());
			shipbillNodeTrackingSaveNewVO.setUserId(Long.valueOf(userDTO.getId()));
			shipbillNodeTrackingSaveNewVO.setUserName(userDTO.getNickname());
			shipbillNodeTrackingSaveNewVO.setEnterpriseId(tmsShipbillHeaderMapperByIds.get(0).getEnterpriseId());
			shipbillNodeTrackingSaveNewVO.setEnterpriseName(tmsShipbillHeaderMapperByIds.get(0).getEnterpriseName());

			// 运单日志信息
			ShipbillOperateLogSaveNewVO shipbillOperateLogSaveNewVO = new ShipbillOperateLogSaveNewVO();
			shipbillOperateLogSaveNewVO.setShipbillId(tmsShipbillHeaderModel.getShipbillId());
			shipbillOperateLogSaveNewVO.setShipbillNo(tmsShipbillHeaderModel.getShipbillId());
			shipbillOperateLogSaveNewVO.setOperateDate(date);
			shipbillOperateLogSaveNewVO.setUserId(Long.valueOf(userDTO.getId()));
			shipbillOperateLogSaveNewVO.setUserName(userDTO.getNickname());
			shipbillOperateLogSaveNewVO.setEnterpriseId(tmsShipbillHeaderMapperByIds.get(0).getEnterpriseId());
			shipbillOperateLogSaveNewVO.setEnterpriseName(tmsShipbillHeaderMapperByIds.get(0).getEnterpriseName());


			// 运单节点保存
			shipbillNodeTrackingSaveNewVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_SD);
			shipbillNodeTrackingSaveNewVO.setNodeEvent(nodeEvent.toString());
			shipbillNodeTrackingSaveNewVO.setPicUrl(waitDeliveredDeliveredConfirmVO.getGoodsPhoto());
			shipbillNodeTrackingService.addShipbillNodeTrackingNewData(shipbillNodeTrackingSaveNewVO);

			// 运单日志保存
			shipbillOperateLogSaveNewVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_SD);
			shipbillOperateLogSaveNewVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_QY);
			shipbillOperateLogSaveNewVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_SD);
			shipbillOperateLogService.addShipbillOperateLogNewData(shipbillOperateLogSaveNewVO);

			if (DataDictionaryConstant.WHETHER_YES.equals(tmsShipbillHeaderModel.getConsigneeReturnOrderPicture())) {
				status = DataDictionaryConstant.SHIPBILL_STATUS_HD_PIC;
			} else if (DataDictionaryConstant.WHETHER_YES.equals(tmsShipbillHeaderModel.getReturnOrderFlag())) {
				status = DataDictionaryConstant.SHIPBILL_STATUS_HD_ZB;
			}
			mapDetailUpdate.put("status", status);

			// 运单修改操作
			tmsShipbillHeaderModel.setStatus(status);
			tmsShipbillHeaderModel.setDeliveryTemperature(waitDeliveredDeliveredConfirmVO.getDeliveryTemperature());
			tmsShipbillHeaderModel.setDeliveryTime(waitDeliveredDeliveredConfirmVO.getDeliveryTime());
			tmsShipbillHeaderModel.setUpdatetime(DateUtil.date());
			tmsShipbillHeaderModel.setUpdateperson(userDTO.getNickname());
			tmsShipbillHeaderMapper.update(tmsShipbillHeaderModel);

			// 修改派车单明细
			Criteria criteriaDetail = Criteria.forClass(TmsLoadingBillDetailModel.class);
			r1 = Restrictions.eq("shipbillId", tmsShipbillHeaderModel.getShipbillId());
			criteriaDetail.setRestriction(Restrictions.and(r1));
			criteriaDetail.setOrder(Order.newInstance().desc(new String[] { "createtime" }));
			List<TmsLoadingBillDetailModel> tmsLoadingBillDetails = tmsLoadingBillDetailMapper.findByCriteria(criteriaDetail);
			if (ToolKits.isEmpty(tmsLoadingBillDetails)) {
				throw new PrologException("装车单明细【" + tmsShipbillHeaderModel.getShipbillId() + "】查询失败");
			}
			TmsLoadingBillDetailModel tmsLoadingBillDetail = tmsLoadingBillDetails.get(0);

			mapDetailUpdate.put("transportStatus", DataDictionaryConstant.TRANSPORT_STATUS_ARRIVED);
			mapDetailUpdate.put("updatetime", date);
			mapDetailUpdate.put("deliveryTemperature", waitDeliveredDeliveredConfirmVO.getDeliveryTemperature());
			tmsLoadingBillDetailMapper.updateMapById(tmsLoadingBillDetail.getId(), mapDetailUpdate, TmsLoadingBillDetailModel.class);

			// 父运单的同步送达
			String fatherShipbillId = tmsShipbillHeaderModel.getShipbillId();
			while (ToolKits.isNotEmpty(fatherShipbillId)) {
				fatherShipbillId = autoFatherDeliveredConfirm(status, fatherShipbillId, date, nodeEvent.toString(), mapTransportLogUpdate,userDTO);
			}

			// 更新调度单状态
			Restriction r3 = Restrictions.eq("loadingBillId", tmsLoadingBillDetail.getLoadingBillId());
			criteriaDetail.setRestriction(Restrictions.and(r3));
			List<TmsLoadingBillDetailModel> tmsLoadingBillDetailModels = tmsLoadingBillDetailMapper.findByCriteria(criteriaDetail);
			int cnt = 0;
			if (ToolKits.isNotEmpty(tmsLoadingBillDetailModels)) {
				TmsLoadingBillHeaderModel secondLoadingBillHeaderModel = tmsLoadingBillHeaderMapper.findById(tmsLoadingBillDetail.getLoadingBillId(), TmsLoadingBillHeaderModel.class);

				criteriaDetail = Criteria.forClass(TmsLoadingBillDetailModel.class);
				r1 = Restrictions.eq(TmsLoadingBillDetailModel::getShipbillId, tmsShipbillHeaderModel.getShipbillId());
				r3 = Restrictions.ne(TmsLoadingBillDetailModel::getLoadingBillId, tmsLoadingBillDetail.getLoadingBillId());
				criteriaDetail.setRestriction(Restrictions.and(r1, r3));
				List<TmsLoadingBillDetailModel> firstLoadingBillDetails = tmsLoadingBillDetailMapper.findByCriteria(criteriaDetail);
				cnt = tmsLoadingBillDetailModels.stream().filter(t -> t.getStatus().intValue() < DataDictionaryConstant.SHIPBILL_STATUS_HD_PIC.intValue()).collect(Collectors.toList()).size();
				if (cnt == 0) {
					// 更新状态为送达确认
					secondLoadingBillHeaderModel.setStatus(DataDictionaryConstant.LOADING_BILL_STATUS_SD);
					tmsLoadingBillHeaderMapper.update(secondLoadingBillHeaderModel);
					// 第一次调度单状态更新
					if (ToolKits.isNotEmpty(firstLoadingBillDetails)) {
						TmsLoadingBillHeaderModel firstLoadingBillHeaderModel = tmsLoadingBillHeaderMapper.findById(firstLoadingBillDetails.get(0).getLoadingBillId(), TmsLoadingBillHeaderModel.class);
						firstLoadingBillHeaderModel.setStatus(DataDictionaryConstant.LOADING_BILL_STATUS_SD);
						tmsLoadingBillHeaderMapper.update(firstLoadingBillHeaderModel);
					}
				} else {
					// 更新状态为部分送达确认
					if (!secondLoadingBillHeaderModel.getStatus().equals(DataDictionaryConstant.LOADING_BILL_STATUS_SD_PART)) {
						secondLoadingBillHeaderModel.setStatus(DataDictionaryConstant.LOADING_BILL_STATUS_SD_PART);
						tmsLoadingBillHeaderMapper.update(secondLoadingBillHeaderModel);
						// 第一次调度单状态更新
						if (ToolKits.isNotEmpty(firstLoadingBillDetails)) {
							TmsLoadingBillHeaderModel firstLoadingBillHeaderModel = tmsLoadingBillHeaderMapper.findById(firstLoadingBillDetails.get(0).getLoadingBillId(), TmsLoadingBillHeaderModel.class);
							firstLoadingBillHeaderModel.setStatus(DataDictionaryConstant.LOADING_BILL_STATUS_SD_PART);
							tmsLoadingBillHeaderMapper.update(firstLoadingBillHeaderModel);
						}
					}
				}
			}

			// 运单同步BMS
			if (status == DataDictionaryConstant.SHIPBILL_STATUS_END.intValue() &&
					!DataDictionaryConstant.SHIPBILL_ABNORMAL_STATUS.equals(tmsShipbillHeaderModel.getAbnormalStatus())) {
				ids.add(tmsLoadingBillDetail.getId());
			}

			TmsLoadingBillHeaderModel tmsLoadingBillHeaderModel = tmsLoadingBillHeaderMapper.findById(tmsLoadingBillDetail.getLoadingBillId(), TmsLoadingBillHeaderModel.class);
			if (StrUtil.isNotBlank(tmsLoadingBillHeaderModel.getVehicleDeviceId()) && StrUtil.isNotBlank(tmsLoadingBillHeaderModel.getVehicleDeviceCode())) {
				Criteria criteria = Criteria.forClass(TmsLoadingBillHeaderModel.class);
				Restriction restriction1 = Restrictions.eq(TmsLoadingBillHeaderModel::getVehicleDeviceCode, tmsLoadingBillHeaderModel.getVehicleDeviceCode());
				Restriction restriction2 = Restrictions.in(TmsLoadingBillHeaderModel::getStatus, Lists.newArrayList(DataDictionaryConstant.LOADING_BILL_STATUS_QY_PART, DataDictionaryConstant.LOADING_BILL_STATUS_QY, DataDictionaryConstant.LOADING_BILL_STATUS_SD_PART));
				criteria.setRestriction(Restrictions.and(restriction1, restriction2));
				if (tmsLoadingBillHeaderMapper.findCountByCriteria(criteria) == 0) {
					String deviceId = tmsLoadingBillHeaderModel.getVehicleDeviceId().split(",")[0];
					try {
						RestMessage<DeviceByOneDTO> restMessage = maindataTmsResource.deviceGetOne(Long.valueOf(deviceId));
						DeviceByOneDTO deviceByOneDTO = restMessage.getData();
						if (BussinessConstant.E6.equals(deviceByOneDTO.getCompanyName())) {
							redisTemplate.opsForSet().remove(RedisConstant.PULL_GPS_DEVICE_E6_KEY, tmsLoadingBillHeaderModel.getVehicleDeviceCode());
							log.info("易流 remove loadingBillId={},vehicle={},deviceCode={}", tmsLoadingBillDetail.getLoadingBillId(), tmsLoadingBillHeaderModel.getVehiclePlateNumber(), deviceByOneDTO.getCode());
						} else if (BussinessConstant.G7.equals(deviceByOneDTO.getCompanyName())) {
							redisTemplate.opsForSet().remove(RedisConstant.PULL_GPS_DEVICE_G7_KEY, tmsLoadingBillHeaderModel.getVehicleDeviceCode());
							log.info("g7 remove loadingBillId={},vehicle={},deviceCode={}", tmsLoadingBillDetail.getLoadingBillId(), tmsLoadingBillHeaderModel.getVehiclePlateNumber(), deviceByOneDTO.getCode());
						}
					} catch (Exception e) {
						log.error("移除redis队列错误", e);
					}
				}
			}
			MessageUtil.addMessage(new SendMessageDTO(MessageOrderTypeEnum.SHIP_NO.getCode(), MessageTypeEnum.DELIVERY.getCode(), Lists.newArrayList(tmsShipbillHeaderModel.getShipbillId())));
		}
		// 运单同步BMS
		if (ToolKits.isNotEmpty(ids)) {
			shipbillCommonService.pushShipbillBmsData(ids,user);
		}
	}

	private String autoFatherDeliveredConfirm(Integer status, String shipbillId, Date date, String nodeEvent, Map<String, Object> mapTransportLogUpdate,UserDTO userDTO) {
		// 查询运单
		TmsShipbillHeaderModel tmsShipbillHeaderModel = tmsShipbillHeaderMapper.findById(shipbillId, TmsShipbillHeaderModel.class);

		// 判断是否为原始单号
		if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getFatherShipbillId()) && !tmsShipbillHeaderModel.getFatherShipbillId().equals(shipbillId)) {
			// 查找父级单号
			TmsShipbillHeaderModel fatherShipbillHeaderModel = tmsShipbillHeaderMapper.findById(tmsShipbillHeaderModel.getFatherShipbillId(), TmsShipbillHeaderModel.class);

			// 查找同级的所有子单
			Criteria criteria = Criteria.forClass(TmsShipbillHeaderModel.class);
			Restriction r1 = Restrictions.eq("fatherShipbillId", tmsShipbillHeaderModel.getFatherShipbillId());
			criteria.setRestriction(r1);
			List<TmsShipbillHeaderModel> tmsShipbillHeaderModelList = tmsShipbillHeaderMapper.findByCriteria(criteria);

			// 查找是否还有未完成的运单
			List<TmsShipbillHeaderModel> tmsShipbillHeaderModels = tmsShipbillHeaderModelList.stream().filter(o -> o.getStatus().intValue() <= DataDictionaryConstant.SHIPBILL_STATUS_SD.intValue()).collect(Collectors.toList());

			// 判断子单是否全部完成
			if (ToolKits.isEmpty(tmsShipbillHeaderModels)) {
				// 修改父级运单状态
				fatherShipbillHeaderModel.setStatus(status);
				fatherShipbillHeaderModel.setTransportStatus(DataDictionaryConstant.TRANSPORT_STATUS_ARRIVED);
				fatherShipbillHeaderModel.setUpdatetime(date);

				// 修改父级运单运输记录表
				Criteria criteriaTransport = Criteria.forClass(TmsShipbillTransLogModel.class);
				r1 = Restrictions.eq("shipbillId", fatherShipbillHeaderModel.getShipbillId());
				criteriaTransport.setRestriction(r1);
				// 更新订单运输记录表
				tmsShipbillTransportLogMapper.updateMapByCriteria(mapTransportLogUpdate, criteriaTransport);

				// 运单节点信息
				ShipbillNodeTrackingSaveNewVO shipbillNodeTrackingSaveNewVO = new ShipbillNodeTrackingSaveNewVO();
				shipbillNodeTrackingSaveNewVO.setNodeDate(date);
				shipbillNodeTrackingSaveNewVO.setShipbillId(fatherShipbillHeaderModel.getShipbillId());
				shipbillNodeTrackingSaveNewVO.setShipbillNo(fatherShipbillHeaderModel.getShipbillId());
				shipbillNodeTrackingSaveNewVO.setUserId(Long.valueOf(userDTO.getId()));
				shipbillNodeTrackingSaveNewVO.setUserName(userDTO.getNickname());
				shipbillNodeTrackingSaveNewVO.setEnterpriseId(tmsShipbillHeaderModel.getEnterpriseId());
				shipbillNodeTrackingSaveNewVO.setEnterpriseName(tmsShipbillHeaderModel.getEnterpriseName());

				// 运单日志信息
				ShipbillOperateLogSaveNewVO shipbillOperateLogSaveNewVO = new ShipbillOperateLogSaveNewVO();
				shipbillOperateLogSaveNewVO.setShipbillId(fatherShipbillHeaderModel.getShipbillId());
				shipbillOperateLogSaveNewVO.setShipbillNo(fatherShipbillHeaderModel.getShipbillId());
				shipbillOperateLogSaveNewVO.setOperateDate(date);
				shipbillOperateLogSaveNewVO.setUserId(Long.valueOf(userDTO.getId()));
				shipbillOperateLogSaveNewVO.setUserName(userDTO.getNickname());
				shipbillOperateLogSaveNewVO.setEnterpriseId(tmsShipbillHeaderModel.getEnterpriseId());
				shipbillOperateLogSaveNewVO.setEnterpriseName(tmsShipbillHeaderModel.getEnterpriseName());

				// 运单节点保存
				shipbillNodeTrackingSaveNewVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_SD);
				shipbillNodeTrackingSaveNewVO.setNodeEvent(nodeEvent);
				shipbillNodeTrackingService.addShipbillNodeTrackingNewData(shipbillNodeTrackingSaveNewVO);

				// 运单日志保存
				shipbillOperateLogSaveNewVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_SD);
				shipbillOperateLogSaveNewVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_QY);
				shipbillOperateLogSaveNewVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_SD);
				shipbillOperateLogService.addShipbillOperateLogNewData(shipbillOperateLogSaveNewVO);

				tmsShipbillHeaderMapper.update(fatherShipbillHeaderModel);
				return fatherShipbillHeaderModel.getShipbillId();
			}
		}
		return null;
	}
}
