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

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

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

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.prolog.common.util.ToolKits;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.exception.BizException;
import com.prolog.framework.core.exception.ParameterException;
import com.prolog.framework.core.exception.PrologException;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.core.restriction.Criteria;
import com.prolog.framework.core.restriction.Order;
import com.prolog.framework.core.restriction.Restriction;
import com.prolog.framework.core.restriction.Restrictions;
import com.prolog.framework.dao.util.PageUtils;
import com.prolog.product.core.framework.entity.UserEntity;
import com.prolog.product.core.framework.util.PlgFxUsrUtils;
import com.prolog.rdc.tms.constant.BussinessConstant;
import com.prolog.rdc.tms.constant.DataDictionaryConstant;
import com.prolog.rdc.tms.constant.SeriaNnumberConstant;
import com.prolog.rdc.tms.constant.StatusConstant;
import com.prolog.rdc.tms.constant.enums.DriverReceiveStatusEnum;
import com.prolog.rdc.tms.constant.enums.ShipBillTypeEnum;
import com.prolog.rdc.tms.constant.enums.SignInStatusEnum;
import com.prolog.rdc.tms.constant.enums.intelligent.IntelligentLockEnum;
import com.prolog.rdc.tms.dao.mapper.TmsLoadingBillDetailMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillDetailMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillHeaderMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillNodeTrackingMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillPackageDetailMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillPackageMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillTransportLogMapper;
import com.prolog.rdc.tms.model.dto.PendingReviewDetailDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewExportDetailDataDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewPackageDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewPackageDetailDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewPageDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewParseAddressPageDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewPrintHeadDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewPrintTableDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewViewDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewViewDetailDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewViewPackageDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.ShipbillFitBusinessFlowDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.ShipbillMatchLineDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.SignconfigPopDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.StrategySplitMatchingDTO;
import com.prolog.rdc.tms.model.dto.basicData.ItemCheckDTO;
import com.prolog.rdc.tms.model.dto.basicData.TmsBaseBranchDTO;
import com.prolog.rdc.tms.model.dto.fleetManagement.DriverPopupDTO;
import com.prolog.rdc.tms.model.dto.message.SendMessageDTO;
import com.prolog.rdc.tms.model.entity.ShipbillNodeTracking;
import com.prolog.rdc.tms.model.entity.SysParamConfigModel;
import com.prolog.rdc.tms.model.entity.SysRefdatadModel;
import com.prolog.rdc.tms.model.entity.TmsLoadingBillDetailModel;
import com.prolog.rdc.tms.model.entity.TmsShipbillDetailModel;
import com.prolog.rdc.tms.model.entity.TmsShipbillHeaderModel;
import com.prolog.rdc.tms.model.entity.TmsShipbillPackageModel;
import com.prolog.rdc.tms.model.entity.TmsShipbillPkgDetailModel;
import com.prolog.rdc.tms.model.entity.TmsShipbillTransLogModel;
import com.prolog.rdc.tms.model.enums.MessageOrderTypeEnum;
import com.prolog.rdc.tms.model.enums.MessageTypeEnum;
import com.prolog.rdc.tms.model.vo.LoadingBillDetailVO;
import com.prolog.rdc.tms.model.vo.LoadingBillHeaderVO;
import com.prolog.rdc.tms.model.vo.PendingDispatchVO;
import com.prolog.rdc.tms.model.vo.PendingReviewAdvancedQueryVO;
import com.prolog.rdc.tms.model.vo.PendingReviewDetailByPackageVO;
import com.prolog.rdc.tms.model.vo.PendingReviewDetailVO;
import com.prolog.rdc.tms.model.vo.PendingReviewExportAllDataVO;
import com.prolog.rdc.tms.model.vo.PendingReviewExportCurrentPageDataVO;
import com.prolog.rdc.tms.model.vo.PendingReviewPackageByDetailVO;
import com.prolog.rdc.tms.model.vo.PendingReviewPageVO;
import com.prolog.rdc.tms.model.vo.PendingReviewParseAddressPageVO;
import com.prolog.rdc.tms.model.vo.PendingReviewParseAddressVO;
import com.prolog.rdc.tms.model.vo.PendingReviewShipbillPackageListVO;
import com.prolog.rdc.tms.model.vo.PendingReviewViewVO;
import com.prolog.rdc.tms.model.vo.ShipbillGoBackVO;
import com.prolog.rdc.tms.model.vo.ShipbillNodeTrackingSaveNewVO;
import com.prolog.rdc.tms.model.vo.ShipbillNodeTrackingSaveVO;
import com.prolog.rdc.tms.model.vo.ShipbillOperateLogSaveNewVO;
import com.prolog.rdc.tms.model.vo.ShipbillOperateLogSaveVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.BusinessFlowShipbillVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.ShipbillMatchLineVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.SignconfigPopVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.StrategySplitMatchingVO;
import com.prolog.rdc.tms.model.vo.basicData.ItemCheckVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DriverPopupVO;
import com.prolog.rdc.tms.rmi.feign.MaindataFeign;
import com.prolog.rdc.tms.service.PendingDispatchService;
import com.prolog.rdc.tms.service.PendingReviewService;
import com.prolog.rdc.tms.service.ShipbillNodeTrackingService;
import com.prolog.rdc.tms.service.ShipbillOperateLogService;
import com.prolog.rdc.tms.util.BusinessFlowUtil;
import com.prolog.rdc.tms.util.ConvertorUtil;
import com.prolog.rdc.tms.util.MessageUtil;
import com.prolog.rdc.tms.util.PublicMethods;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * 调度管理-待审核实现层
 *
 * @author lhb
 * @since 2022-04-11 14:45:00
 */
@Service
@Slf4j
public class PendingReviewServiceImpl implements PendingReviewService {
	@Autowired
	private TmsShipbillHeaderMapper tmsShipbillHeaderMapper;

	@Autowired
	private TmsShipbillDetailMapper tmsShipbillDetailMapper;

	@Autowired
	private TmsShipbillPackageMapper tmsShipbillPackageMapper;

	@Autowired
	private TmsShipbillPackageDetailMapper tmsShipbillPackageDetailMapper;

	@Autowired
	private MaindataFeign maindataTmsResource;

	@Autowired
	private ShipbillNodeTrackingService shipbillNodeTrackingService;

	@Autowired
	private ShipbillOperateLogService shipbillOperateLogService;

	@Autowired
	private TmsShipbillNodeTrackingMapper tmsShipbillNodeTrackingMapper;

	@Autowired
	private PendingDispatchService pendingDispatchService;

	@Autowired
	private TmsShipbillTransportLogMapper tmsShipbillTransportLogMapper;

	@Autowired
	private TmsLoadingBillDetailMapper tmsLoadingBillDetailMapper;

	@Autowired
	private ConvertorUtil convertorUtil;

	@Autowired
	private BusinessFlowUtil businessFlowUtil;

	/**
	 * 待审核分页查询
	 *
	 * @param pendingReviewPageVO
	 * @return
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<PendingReviewPageDTO> pagePendingReviewData(PendingReviewPageVO pendingReviewPageVO) {
		ToolKits.isParamNull(pendingReviewPageVO, "待审核分页查询请求不为空");
		ToolKits.isParamNull(pendingReviewPageVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(pendingReviewPageVO.getPageSize(), "每页条数不为空");

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

		// 数据字典翻译数据集合
		List<SysRefdatadModel> dicData = convertorUtil.getDictionary(new String[] {
				DataDictionaryConstant.DELIVERY_METHOD_TYPE, // 配送方式
				DataDictionaryConstant.TRANSPORT_TYPE, // 运输类型(运输模式)
				DataDictionaryConstant.TEMPERATURE_REQUIREMENT, // 温度要求
				DataDictionaryConstant.SHIPPER_TYPE, // 发货方类型
				DataDictionaryConstant.CONSIGNEE_TYPE, // 收货方类型
				DataDictionaryConstant.ORDER_TYPE, // 订单类型
				DataDictionaryConstant.LINE_DIRECTION, // 线路方向
				DataDictionaryConstant.ORDER_BUSINESS_TYPE // 订单业务类型
		});
		List<SignconfigPopDTO> data8 = Lists.newArrayList();

		// 标记配置
		SignconfigPopVO signconfigPopVO = new SignconfigPopVO();
		RestMessage<List<SignconfigPopDTO>> restMessage8 = maindataTmsResource.getSignConfig(signconfigPopVO);
		if (!restMessage8.isSuccess()) {
			throw new RuntimeException("标记配置查询失败!");
		} else {
			data8 = restMessage8.getData();
		}

		// 添加查询条件
		Criteria criteria = Criteria.forClass(TmsShipbillHeaderModel.class);
		Restriction r1 = ToolKits.isEmpty(pendingReviewPageVO.getCargoOwnerName()) ? null : Restrictions.like("cargoOwnerName", "%" + pendingReviewPageVO.getCargoOwnerName() + "%");
		Restriction r2 = ToolKits.isEmpty(pendingReviewPageVO.getOrderNo()) ? null : Restrictions.like("orderNo", "%" + pendingReviewPageVO.getOrderNo() + "%");
		Restriction r3 = ToolKits.isEmpty(pendingReviewPageVO.getShipbillNo()) ? null : Restrictions.like("shipbillNo", "%" + pendingReviewPageVO.getShipbillNo() + "%");
		Restriction r4 = ToolKits.isEmpty(pendingReviewPageVO.getOrderBusinessType()) ? null : Restrictions.eq("orderBusinessType", pendingReviewPageVO.getOrderBusinessType());
		Restriction r5 = ToolKits.isEmpty(pendingReviewPageVO.getEstimatedPickupStartTime()) ? null : Restrictions.ge("estimatedPickupStartTime", pendingReviewPageVO.getEstimatedPickupStartTime());
		Restriction r6 = ToolKits.isEmpty(pendingReviewPageVO.getEstimatedPickupEndTime()) ? null : Restrictions.le("estimatedPickupEndTime", pendingReviewPageVO.getEstimatedPickupEndTime());
		Restriction r7 = ToolKits.isEmpty(pendingReviewPageVO.getEstimatedDeliveryStartTime()) ? null : Restrictions.ge("estimatedDeliveryStartTime", pendingReviewPageVO.getEstimatedDeliveryStartTime());
		Restriction r8 = ToolKits.isEmpty(pendingReviewPageVO.getEstimatedDeliveryEndTime()) ? null : Restrictions.le("estimatedDeliveryEndTime", pendingReviewPageVO.getEstimatedDeliveryEndTime());

		Restriction r9 = null;
		if (ToolKits.isNotEmpty(pendingReviewPageVO.getShipperLocation()) && pendingReviewPageVO.getShipperLocation().intValue() == 0) {
			Restriction r13 = Restrictions.isnull("shipperLongitude");
			Restriction r14 = Restrictions.isnull("shipperLatitude");
			r9 = Restrictions.or(r13, r14);
		} else if (ToolKits.isNotEmpty(pendingReviewPageVO.getShipperLocation()) && pendingReviewPageVO.getShipperLocation().intValue() == 1) {
			Restriction r13 = Restrictions.isNotNull("shipperLongitude");
			Restriction r14 = Restrictions.isNotNull("shipperLatitude");
			r9 = Restrictions.and(r13, r14);
		}
		Restriction r10 = null;
		if (ToolKits.isNotEmpty(pendingReviewPageVO.getConsigneeLocation()) && pendingReviewPageVO.getConsigneeLocation().intValue() == 0) {
			Restriction r15 = Restrictions.isnull("consigneeLongitude");
			Restriction r16 = Restrictions.isnull("consigneeLatitude");
			r10 = Restrictions.or(r15, r16);
		} else if (ToolKits.isNotEmpty(pendingReviewPageVO.getConsigneeLocation()) && pendingReviewPageVO.getConsigneeLocation().intValue() == 1) {
			Restriction r15 = Restrictions.isNotNull("consigneeLongitude");
			Restriction r16 = Restrictions.isNotNull("consigneeLatitude");
			r10 = Restrictions.and(r15, r16);
		}
		Restriction r12 = Restrictions.eq("enterpriseId", user.getEnterpriseId());

		Restriction r11 = null;
		Restriction r19 = null;
		Restriction r25 = null;
		Restriction r30 = null;
		// 权限控制
		if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY)) {
			// 自有账号
			// 拆单状态 0未拆单
			Restriction r31 = Restrictions.eq("splitOrderStatus", DataDictionaryConstant.SPLIT_ORDER_STATUS_UN);
			// 承运商拆单类型 1未拆单
			Restriction r32 = Restrictions.eq("carrierSplitOrderType", DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_UN);
			Restriction r33 = Restrictions.and(r31, r32);
			// 承运商拆单类型 2拆分主单
			Restriction r34 = Restrictions.eq("carrierSplitOrderType", DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_SPLIT_MASTER);
			// 承运商拆单类型 2中转主单
			Restriction r35 = Restrictions.eq("carrierSplitOrderType", DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_TRANSIT_MASTER);
			r30 = Restrictions.or(r33, r34, r35);

			// 判断是否为部门权限
			Integer[] stsArr = { DataDictionaryConstant.SHIPBILL_STATUS_YTJ, DataDictionaryConstant.SHIPBILL_STATUS_WZ, DataDictionaryConstant.SHIPBILL_STATUS_WS };
			r11 = Restrictions.in("status", stsArr);
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				r19 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
			} else {
				r19 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
				Restriction r20 = Restrictions.in("cargoOwnerId", user.getConsignors().stream().toArray(Long[]::new));

				Restriction r21 = Restrictions.in("consigneeUnitId", user.getWarehouses().stream().toArray(Long[]::new));
				Restriction r22 = Restrictions.in("consigneeUnitId", user.getSuppliers().stream().toArray(Long[]::new));
				Restriction r23 = Restrictions.in("consigneeUnitId", user.getCustomers().stream().toArray(Long[]::new));

				Restriction r43 = Restrictions.in(TmsShipbillHeaderModel::getShipperUnitId, user.getWarehouses().stream().toArray(Long[]::new));
				Restriction r44 = Restrictions.in(TmsShipbillHeaderModel::getShipperUnitId, user.getSuppliers().stream().toArray(Long[]::new));
				Restriction r45 = Restrictions.in(TmsShipbillHeaderModel::getShipperUnitId, user.getCustomers().stream().toArray(Long[]::new));

				Restriction r24 = Restrictions.or(r21, r22, r23, r43, r44, r45);
				r25 = Restrictions.and(r20, r24);
			}
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_CYS)) {
			// 承运商账号
			// 查询调度类型为承运商的运单
			r30 = Restrictions.eq("carrierSplitOrderStatus", DataDictionaryConstant.CARRIER_SPLIT_ORDER_STATUS_UN);
			Restriction r26 = Restrictions.eq("carrierId", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
			Restriction r27 = Restrictions.eq("status", DataDictionaryConstant.SHIPBILL_STATUS_DISPATCH_CHECK);
			Restriction r28 = Restrictions.eq("carrierShipbillStatus", DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_COMMIT);
			r25 = Restrictions.and(r26, r27, r28);
		} else {
			throw new PrologException("当前人员没有操作权限！");
		}

		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r19, r25, r30));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));

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

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

		for (TmsShipbillHeaderModel tmsShipbillHeaderModel : tmsShipbillHeaderModels) {
			PendingReviewPageDTO pendingReviewPageDTO = new PendingReviewPageDTO();
			BeanUtils.copyProperties(tmsShipbillHeaderModel, pendingReviewPageDTO);
			// 收货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLatitude())) {
				pendingReviewPageDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
			} else {
				pendingReviewPageDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
			}
			// 发货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLatitude())) {
				pendingReviewPageDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
			} else {
				pendingReviewPageDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
			}
			StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
			// 目的地
			consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeProvinceName()) ? "" : tmsShipbillHeaderModel.getConsigneeProvinceName());
			consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeCityName()) ? "" : tmsShipbillHeaderModel.getConsigneeCityName());
			consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeDistrictName()) ? "" : tmsShipbillHeaderModel.getConsigneeDistrictName());
			pendingReviewPageDTO.setConsigneeProvinceCityDistrict(consigneeProvinceCityDistrict.toString());
			// 始发地
			StringBuffer shipperProvinceCityDistrict = new StringBuffer();
			shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperProvinceName()) ? "" : tmsShipbillHeaderModel.getShipperProvinceName());
			shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperCityName()) ? "" : tmsShipbillHeaderModel.getShipperCityName());
			shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperDistrictName()) ? "" : tmsShipbillHeaderModel.getShipperDistrictName());
			pendingReviewPageDTO.setShipperProvinceCityDistrict(shipperProvinceCityDistrict.toString());

			// 类型翻译
			pendingReviewPageDTO.setOrderTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ORDER_TYPE, String.valueOf(pendingReviewPageDTO.getOrderType())));
			pendingReviewPageDTO.setOrderBusinessTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ORDER_BUSINESS_TYPE, String.valueOf(pendingReviewPageDTO.getOrderBusinessType())));
			pendingReviewPageDTO.setDeliveryMethodTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.DELIVERY_METHOD_TYPE, String.valueOf(pendingReviewPageDTO.getDeliveryMethodType())));
			pendingReviewPageDTO.setTransportTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TRANSPORT_TYPE, String.valueOf(pendingReviewPageDTO.getTransportType())));
			pendingReviewPageDTO.setTemperatureRequirementName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TEMPERATURE_REQUIREMENT, String.valueOf(pendingReviewPageDTO.getTemperatureRequirement())));
			pendingReviewPageDTO.setShipperTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.SHIPPER_TYPE, String.valueOf(pendingReviewPageDTO.getShipperType())));
			pendingReviewPageDTO.setConsigneeTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.CONSIGNEE_TYPE, String.valueOf(pendingReviewPageDTO.getConsigneeType())));
			pendingReviewPageDTO.setLineDirectionName(ConvertorUtil.getName(dicData, DataDictionaryConstant.LINE_DIRECTION, String.valueOf(pendingReviewPageDTO.getLineDirection())));
			// 获取背景颜色和字体颜色
			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(pendingReviewPageDTO.getOrderTypeName()) ? pendingReviewPageDTO.getOrderTypeName() : "")) {
							pendingReviewPageDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							pendingReviewPageDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());

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

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

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

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

							// 返回前端所需标记ID
							pendingReviewPageDTO.setSignConfigId(signconfigPopDTO.getId());

							break Signconfig;
						}
					}
					break;
				}
			}

			pendingReviewPageDTOs.add(pendingReviewPageDTO);
		}

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

	/**
	 * 待审核高级查询
	 *
	 * @param advancedQueryVO
	 * @return
	 */
	@SuppressWarnings("resource")
	public Page<PendingReviewPageDTO> pageAdvanced(PendingReviewAdvancedQueryVO advancedQueryVO) {
		ToolKits.isParamNull(advancedQueryVO, "待审核分页查询请求不为空");
		ToolKits.isParamNull(advancedQueryVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(advancedQueryVO.getPageSize(), "每页条数不为空");

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

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

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

		// 添加查询条件
		// 企业ID
		advancedQueryVO.setEnterpriseId(user.getEnterpriseId());

		// 权限控制
		// 用户类型
		advancedQueryVO.setUserType(user.getUserType());
		if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY)) {
			// 自有账号
			Integer[] stsArr = { DataDictionaryConstant.SHIPBILL_STATUS_YTJ, DataDictionaryConstant.SHIPBILL_STATUS_WZ, DataDictionaryConstant.SHIPBILL_STATUS_WS };
			advancedQueryVO.setStatusList(stsArr);
			if (BussinessConstant.USER_DEPARTMENT_AUTH_Y.equals(user.getOwnedAllDataAuthFlag())) {
				advancedQueryVO.setIsDept("YES");
			} else {
				advancedQueryVO.setIsDept("NO");
				// 其它权限
				// 货主
				advancedQueryVO.setConsignors(user.getConsignors().stream().toArray(Long[]::new));
				// 客户
				advancedQueryVO.setCustomers(user.getCustomers().stream().toArray(Long[]::new));
				// 供应商
				advancedQueryVO.setSuppliers(user.getSuppliers().stream().toArray(Long[]::new));
				// 仓库
				advancedQueryVO.setWsarehouses(user.getWarehouses().stream().toArray(Long[]::new));
			}
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_CYS)) {// 承运商账号
			// 承运商账号 单位ID
			advancedQueryVO.setUnitId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
			// 承运商运单状态
			Integer[] carrierStsList = new Integer[] { DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_COMMIT };
			advancedQueryVO.setCarrierStatusList(carrierStsList);
		} else {
			throw new PrologException("当前人员没有操作权限！");
		}
		// 获取高级查询配置
		String conditions = null;
		RestMessage<String> restMessageAdvancedCfg = maindataTmsResource.getQueryConfiguration(DataDictionaryConstant.BIZ_TYPE_PENDING_REVIEW);
		if (!restMessageAdvancedCfg.isSuccess()) {
			// throw new RuntimeException("订单类型翻译失败!");
		} else {
			conditions = restMessageAdvancedCfg.getData();
		}
		advancedQueryVO.setSql(conditions);

		PageUtils.startPage(advancedQueryVO.getPageNum(), advancedQueryVO.getPageSize());
		List<PendingReviewPageDTO> tmsShipbillHeaderModels = tmsShipbillHeaderMapper.pendingReviewAdvancedQuery(advancedQueryVO);

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

		for (PendingReviewPageDTO tmsShipbillHeaderModel : tmsShipbillHeaderModels) {
			PendingReviewPageDTO pendingReviewPageDTO = new PendingReviewPageDTO();
			BeanUtils.copyProperties(tmsShipbillHeaderModel, pendingReviewPageDTO);
			// 收货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLatitude())) {
				pendingReviewPageDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
			} else {
				pendingReviewPageDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
			}
			// 发货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLatitude())) {
				pendingReviewPageDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
			} else {
				pendingReviewPageDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
			}
			StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
			// 目的地
			consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeProvinceName()) ? "" : tmsShipbillHeaderModel.getConsigneeProvinceName());
			consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeCityName()) ? "" : tmsShipbillHeaderModel.getConsigneeCityName());
			consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeDistrictName()) ? "" : tmsShipbillHeaderModel.getConsigneeDistrictName());
			pendingReviewPageDTO.setConsigneeProvinceCityDistrict(consigneeProvinceCityDistrict.toString());
			// 始发地
			StringBuffer shipperProvinceCityDistrict = new StringBuffer();
			shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperProvinceName()) ? "" : tmsShipbillHeaderModel.getShipperProvinceName());
			shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperCityName()) ? "" : tmsShipbillHeaderModel.getShipperCityName());
			shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperDistrictName()) ? "" : tmsShipbillHeaderModel.getShipperDistrictName());
			pendingReviewPageDTO.setShipperProvinceCityDistrict(shipperProvinceCityDistrict.toString());

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

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

							pendingReviewPageDTO.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(pendingReviewPageDTO.getTemperatureRequirementName()) ? pendingReviewPageDTO.getTemperatureRequirementName() : "")) {
							pendingReviewPageDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							pendingReviewPageDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());
							pendingReviewPageDTO.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(pendingReviewPageDTO.getDeliveryMethodTypeName()) ? pendingReviewPageDTO.getDeliveryMethodTypeName() : "")) {
							pendingReviewPageDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							pendingReviewPageDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());
							pendingReviewPageDTO.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(pendingReviewPageDTO.getMemo()) ? pendingReviewPageDTO.getMemo() : "")) {
							pendingReviewPageDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							pendingReviewPageDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());
							// 返回前端所需标记ID
							pendingReviewPageDTO.setSignConfigId(signconfigPopDTO.getId());
							break Signconfig;
						}
					}
					break;
				}
			}

			pendingReviewPageDTOs.add(pendingReviewPageDTO);
		}

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

	/**
	 * 待审核商品信息查询
	 *
	 * @param pendingReviewDetailVO
	 * @return
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<PendingReviewDetailDTO> listShipbillDetailData(PendingReviewDetailVO pendingReviewDetailVO) {
		ToolKits.isParamNull(pendingReviewDetailVO, "待审核商品信息查询请求不为空");
		ToolKits.isParamNull(pendingReviewDetailVO.getShipbillId(), "运单ID不为空");
		ToolKits.isParamNull(pendingReviewDetailVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(pendingReviewDetailVO.getPageSize(), "每页条数不为空");

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

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

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

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

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

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

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

				pendingReviewDetailDTOS.add(pendingReviewDetailDTO);
			}
		}

		// 分页重组
		Page<PendingReviewDetailDTO> page = PageUtils.getPage(pendingReviewDetailDTOS);
		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 pendingReviewShipbillPackageListVO
	 * @return
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<PendingReviewPackageDTO> listShipbillPackageData(PendingReviewShipbillPackageListVO pendingReviewShipbillPackageListVO) {
		ToolKits.isParamNull(pendingReviewShipbillPackageListVO, "待审核包裹信息查询请求不为空");
		ToolKits.isParamNull(pendingReviewShipbillPackageListVO.getShipbillId(), "运单ID不为空");
		ToolKits.isParamNull(pendingReviewShipbillPackageListVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(pendingReviewShipbillPackageListVO.getPageSize(), "每页条数不为空");

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

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

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

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

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

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

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

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

				pendingReviewPackageDTOS.add(pendingReviewPackageDTO);
			}
		}

		// 分页重组
		Page<PendingReviewPackageDTO> page = PageUtils.getPage(pendingReviewPackageDTOS);
		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 shipbillIds
	 * @return
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void reviewShipbillData(List<String> shipbillIds) {
		ToolKits.isParamNull(shipbillIds, "运单审核请求不为空");

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

		// 当前时间
		Date date = DateUtil.date();
		autoReview(shipbillIds, user, date);

	}

	/**
	 * 自动运单审核
	 *
	 * @param shipbillIds
	 * @return
	 */
	@Override
	public void autoReview(List<String> shipbillIds, UserEntity user, Date date) {
		for (String id : shipbillIds) {
			ToolKits.isParamNull(id, "运单ID不为空");
			// 更新
			TmsShipbillHeaderModel tmsShipbillHeaderModel = tmsShipbillHeaderMapper.findById(id, TmsShipbillHeaderModel.class);
			ShipbillNodeTrackingSaveVO shipbillNodeTrackingSaveVO = new ShipbillNodeTrackingSaveVO();
			ShipbillOperateLogSaveVO shipbillOperateLogSaveVO = new ShipbillOperateLogSaveVO();
			if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY)) {
				// 自有账号
				if (!DataDictionaryConstant.SHIPBILL_STATUS_YTJ.equals(tmsShipbillHeaderModel.getStatus()) && !DataDictionaryConstant.SHIPBILL_STATUS_WZ.equals(tmsShipbillHeaderModel.getStatus())) {
					throw new PrologException("运单【" + tmsShipbillHeaderModel.getShipbillNo() + "】非待审核状态,审核失败");
				}
				int status = businessFlowUtil.judgmentNextFlowSts(tmsShipbillHeaderModel.getFlowConfig(), DataDictionaryConstant.FLOW_CONFIG_REVIEW);
				tmsShipbillHeaderModel.setStatus(status);
				shipbillNodeTrackingSaveVO.setNodeEvent(DataDictionaryConstant.SHIPBILL_NODE_STATUSNAME_RE);
				shipbillOperateLogSaveVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_NODE_STATUSNAME_RE);
			} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_CYS)) {
				// 承运商账号
				if (!DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_COMMIT.equals(tmsShipbillHeaderModel.getCarrierShipbillStatus())) {
					throw new PrologException("运单【" + tmsShipbillHeaderModel.getShipbillNo() + "】非待审核状态,审核失败");
				}
				tmsShipbillHeaderModel.setCarrierShipbillStatus(DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_AUDITED);
				shipbillNodeTrackingSaveVO.setNodeEvent(DataDictionaryConstant.CARRIER_SHIPBILL_NODE_STATUSNAME_RE);
				shipbillOperateLogSaveVO.setOperateEvent(DataDictionaryConstant.CARRIER_SHIPBILL_NODE_STATUSNAME_RE);
			}

			// 运单审核
			tmsShipbillHeaderModel.setUpdateperson(user.getNickname());
			tmsShipbillHeaderModel.setUpdatetime(date);
			tmsShipbillHeaderMapper.update(tmsShipbillHeaderModel);

			// 运单节点保存
			shipbillNodeTrackingSaveVO.setShipbillId(tmsShipbillHeaderModel.getShipbillId());
			shipbillNodeTrackingSaveVO.setShipbillNo(tmsShipbillHeaderModel.getShipbillNo());
			shipbillNodeTrackingSaveVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_REVIEW);
			shipbillNodeTrackingService.addShipbillNodeTrackingData(shipbillNodeTrackingSaveVO);

			// 运单日志保存
			shipbillOperateLogSaveVO.setShipbillId(tmsShipbillHeaderModel.getShipbillId());
			shipbillOperateLogSaveVO.setShipbillNo(tmsShipbillHeaderModel.getShipbillNo());
			shipbillOperateLogSaveVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_YTJ);
			shipbillOperateLogSaveVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_REVIEW);
			shipbillOperateLogService.addShipbillOperateLogData(shipbillOperateLogSaveVO);

			// 更新运输记录表的审核时间
			Criteria criteriaTransLog = Criteria.forClass(TmsShipbillTransLogModel.class);
			Restriction r1 = Restrictions.eq(TmsShipbillTransLogModel::getShipbillId, tmsShipbillHeaderModel.getShipbillId());
			Restriction r2 = Restrictions.eq(TmsShipbillTransLogModel::getEnterpriseId, user.getEnterpriseId());
			criteriaTransLog.setRestriction(Restrictions.and(r1, r2));

			Map<String, Object> mapUpdate = Maps.newHashMap();
			mapUpdate.put("updateperson", user.getNickname());
			mapUpdate.put("updatetime", date);
			mapUpdate.put("reviewDt", date);
			if (tmsShipbillHeaderModel.getDeliveryMethodType().equals(DataDictionaryConstant.DELIVERY_METHOD_TYPE_ZT)) {
				mapUpdate.put("disDt", date);
				mapUpdate.put("disCheckDt", date);
			}
			tmsShipbillTransportLogMapper.updateMapByCriteria(mapUpdate, criteriaTransLog);

			TmsShipbillHeaderModel shipbillHeaderModel = tmsShipbillHeaderMapper.findById(id, TmsShipbillHeaderModel.class);
			boolean autoSplit = false;
			if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY)) {
				if (shipbillHeaderModel.getFlowConfig().contains(DataDictionaryConstant.FLOW_CONFIG_REVIEW_SPLIT)) {
					autoSplit = true;
				}
			}
			// 自动拆分
			List<TmsShipbillHeaderModel> autoDispatchOjbs = Lists.newArrayList();
			if (autoSplit) {
				autoDispatchOjbs.addAll(autoSplit(id, date, user));
			}
			// 自动拆分做了时，子单参加调度，没有自动拆分时，原单参加自动调度
			if (ToolKits.isEmpty(autoDispatchOjbs)) {
				autoDispatchOjbs.add(shipbillHeaderModel);
			}

			// 是否执行自动调度
			for (TmsShipbillHeaderModel disHeaderModel : autoDispatchOjbs) {
				// 非指定承运商按业务流程执行是否自动调度，指定承运商时三方快递执行自定调度，三方物流手工调度
				if (ToolKits.isEmpty(disHeaderModel.getCarriersId())) {
					// 收货方类型是客户时，自动调度
					if (!DataDictionaryConstant.DELIVERY_METHOD_TYPE_SEND.equals(shipbillHeaderModel.getDeliveryMethodType())) {
						continue;
					}
					if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY)) {
						if (!shipbillHeaderModel.getFlowConfig().contains(DataDictionaryConstant.FLOW_CONFIG_REVIEW_DISPATCH)) {
							continue;
						}
					} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_CYS)) {
						if (!shipbillHeaderModel.getCarrierFlowConfig().contains(DataDictionaryConstant.FLOW_CONFIG_REVIEW_DISPATCH)) {
							continue;
						}
					}
					DriverPopupVO driverPopupVO = new DriverPopupVO();
					driverPopupVO.setCarriersId(disHeaderModel.getCarriersId());
					RestMessage<DriverPopupDTO> driverInfo = maindataTmsResource.getDriverForCarriersAutoDis(driverPopupVO);
					if (!driverInfo.isSuccess()) {
						throw new RuntimeException("获取承运商的司机,车辆信息失败");
					}
					DriverPopupDTO carrierDTO = driverInfo.getData();
					PendingDispatchVO pendingDispatchVO = new PendingDispatchVO();
					LoadingBillHeaderVO loadingBillHeaderVO = new LoadingBillHeaderVO();
					List<LoadingBillDetailVO> loadingBillDetailVOS = Lists.newArrayList();
					LoadingBillDetailVO loadingBillDetailVO = new LoadingBillDetailVO();
					if (ToolKits.isNotEmpty(carrierDTO)) {
						// 承运方类型
						loadingBillHeaderVO.setCarrierType(2);

						// 司机ID
						loadingBillHeaderVO.setDriverId(carrierDTO.getId().toString());
						loadingBillHeaderVO.setDriverCode(carrierDTO.getCode());
						loadingBillHeaderVO.setDriverName(carrierDTO.getName());
						// 车辆
						loadingBillHeaderVO.setVehicleId(carrierDTO.getVehicleId());
						loadingBillHeaderVO.setVehicleCode(carrierDTO.getVehicleCode());
						loadingBillHeaderVO.setVehiclePlateNumber(carrierDTO.getVehiclePlateNumber());
						loadingBillHeaderVO.setVehicleAscription(carrierDTO.getVehicleAscription());
						// 车型
						loadingBillHeaderVO.setVehicleTypeId(carrierDTO.getVehicleTypeId());
						loadingBillHeaderVO.setVehicleTypeCode(carrierDTO.getVehicleTypeCode());
						loadingBillHeaderVO.setVehicleTypeName(carrierDTO.getVehicleTypeName());

						if (ToolKits.isNotEmpty(carrierDTO.getVehicleTypeCategory())) {
							loadingBillHeaderVO.setVehicleTypeCategory(String.valueOf(carrierDTO.getVehicleTypeCategory()));
						}
						loadingBillHeaderVO.setVehicleAffiliationId(String.valueOf(disHeaderModel.getCarriersId()));
						loadingBillHeaderVO.setVehicleAffiliationCode(String.valueOf(disHeaderModel.getCarriersCode()));
						loadingBillHeaderVO.setVehicleAffiliationName(String.valueOf(disHeaderModel.getCarriersName()));
						// 承运商ID
						loadingBillHeaderVO.setCarrierId(Long.valueOf(disHeaderModel.getCarriersId()));
						loadingBillHeaderVO.setCarrierCode(disHeaderModel.getCarriersCode());
						loadingBillHeaderVO.setCarrierName(disHeaderModel.getCarriersName());
						// 司机手机号
						loadingBillHeaderVO.setDriverPhoneNumber(carrierDTO.getPhoneNumber());
						// 车牌号
						loadingBillHeaderVO.setVehiclePlateNumber(carrierDTO.getVehiclePlateNumber());
						// 运单数
						loadingBillHeaderVO.setShipbillNumber(1);
						// 站点数
						loadingBillHeaderVO.setSiteNumber(1);
						// 客户数
						loadingBillHeaderVO.setCustomerNumber(1);
						// 总件数
						loadingBillHeaderVO.setTotalPcs(disHeaderModel.getTotalPcs());
						// 总体积
						loadingBillHeaderVO.setTotalVolume(disHeaderModel.getTotalVolume());
						// 总重量
						loadingBillHeaderVO.setTotalWeight(disHeaderModel.getTotalWeight());
						// 实际总件数
						loadingBillHeaderVO.setActualTotalPcs(disHeaderModel.getTotalPcs());
						// 实际总体积
						loadingBillHeaderVO.setActualTotalVolume(disHeaderModel.getTotalVolume());
						// 实际总重量
						loadingBillHeaderVO.setActualTotalWeight(disHeaderModel.getTotalWeight());
						// 总整件数
						loadingBillHeaderVO.setTotalWholePiece(disHeaderModel.getPackageWholePiece());
						// 总拼箱数
						loadingBillHeaderVO.setTotalLclPiece(disHeaderModel.getPackageLclPiece());
						// 备注
						loadingBillHeaderVO.setMemo("待审核后自动调度");

						// 设置调度单数据
						pendingDispatchVO.setLoadingBillHeaderVO(loadingBillHeaderVO);
						// 设置调度单明细
						BeanUtils.copyProperties(disHeaderModel, loadingBillDetailVO);
						loadingBillDetailVO.setShippingOrder(1);
						loadingBillDetailVO.setPickUpOrder(1);
						loadingBillDetailVOS.add(loadingBillDetailVO);
						pendingDispatchVO.setLoadingBillDetailVO(loadingBillDetailVOS);
						// 自动调度
						pendingDispatchService.autoDispatch(pendingDispatchVO, user, date, "");
					}
				} else {
					// 指定承运商时三方快递执行自定调度，三方物流手工调度
					if (disHeaderModel.getCarriersType().equals(DataDictionaryConstant.CARRIERS_TYPE_EXPRESS)) {
						DriverPopupVO driverPopupVO = new DriverPopupVO();
						driverPopupVO.setCarriersId(disHeaderModel.getCarriersId());
						RestMessage<DriverPopupDTO> driverInfo = maindataTmsResource.getDriverForCarriersAutoDis(driverPopupVO);
						if (!driverInfo.isSuccess()) {
							throw new RuntimeException("获取承运商的司机,车辆信息失败");
						}

						DriverPopupDTO carrierDTO = driverInfo.getData();
						PendingDispatchVO pendingDispatchVO = new PendingDispatchVO();
						LoadingBillHeaderVO loadingBillHeaderVO = new LoadingBillHeaderVO();
						List<LoadingBillDetailVO> loadingBillDetailVOS = Lists.newArrayList();
						LoadingBillDetailVO loadingBillDetailVO = new LoadingBillDetailVO();
						if (ToolKits.isNotEmpty(carrierDTO)) {
							// 承运方类型
							loadingBillHeaderVO.setCarrierType(2);

							// 司机ID
							loadingBillHeaderVO.setDriverId(carrierDTO.getId().toString());
							loadingBillHeaderVO.setDriverCode(carrierDTO.getCode());
							loadingBillHeaderVO.setDriverName(carrierDTO.getName());
							// 车辆
							loadingBillHeaderVO.setVehicleId(carrierDTO.getVehicleId());
							loadingBillHeaderVO.setVehicleCode(carrierDTO.getVehicleCode());
							loadingBillHeaderVO.setVehiclePlateNumber(carrierDTO.getVehiclePlateNumber());
							loadingBillHeaderVO.setVehicleAscription(carrierDTO.getVehicleAscription());
							// 车型
							loadingBillHeaderVO.setVehicleTypeId(carrierDTO.getVehicleTypeId());
							loadingBillHeaderVO.setVehicleTypeCode(carrierDTO.getVehicleTypeCode());
							loadingBillHeaderVO.setVehicleTypeName(carrierDTO.getVehicleTypeName());

							if (ToolKits.isNotEmpty(carrierDTO.getVehicleTypeCategory())) {
								loadingBillHeaderVO.setVehicleTypeCategory(String.valueOf(carrierDTO.getVehicleTypeCategory()));
							}
							loadingBillHeaderVO.setVehicleAffiliationId(String.valueOf(disHeaderModel.getCarriersId()));
							loadingBillHeaderVO.setVehicleAffiliationCode(String.valueOf(disHeaderModel.getCarriersCode()));
							loadingBillHeaderVO.setVehicleAffiliationName(String.valueOf(disHeaderModel.getCarriersName()));
							// 承运商ID
							loadingBillHeaderVO.setCarrierId(Long.valueOf(disHeaderModel.getCarriersId()));
							loadingBillHeaderVO.setCarrierCode(disHeaderModel.getCarriersCode());
							loadingBillHeaderVO.setCarrierName(disHeaderModel.getCarriersName());
							// 司机手机号
							loadingBillHeaderVO.setDriverPhoneNumber(carrierDTO.getPhoneNumber());
							// 车牌号
							loadingBillHeaderVO.setVehiclePlateNumber(carrierDTO.getVehiclePlateNumber());
							// 运单数
							loadingBillHeaderVO.setShipbillNumber(1);
							// 站点数
							loadingBillHeaderVO.setSiteNumber(1);
							// 客户数
							loadingBillHeaderVO.setCustomerNumber(1);
							// 总件数
							loadingBillHeaderVO.setTotalPcs(disHeaderModel.getTotalPcs());
							// 总体积
							loadingBillHeaderVO.setTotalVolume(disHeaderModel.getTotalVolume());
							// 总重量
							loadingBillHeaderVO.setTotalWeight(disHeaderModel.getTotalWeight());
							// 实际总件数
							loadingBillHeaderVO.setActualTotalPcs(disHeaderModel.getTotalPcs());
							// 实际总体积
							loadingBillHeaderVO.setActualTotalVolume(disHeaderModel.getTotalVolume());
							// 实际总重量
							loadingBillHeaderVO.setActualTotalWeight(disHeaderModel.getTotalWeight());
							// 总整件数
							loadingBillHeaderVO.setTotalWholePiece(disHeaderModel.getPackageWholePiece());
							// 总拼箱数
							loadingBillHeaderVO.setTotalLclPiece(disHeaderModel.getPackageLclPiece());
							// 备注
							loadingBillHeaderVO.setMemo("待审核后自动调度");

							// 设置调度单数据
							pendingDispatchVO.setLoadingBillHeaderVO(loadingBillHeaderVO);
							// 设置调度单明细
							BeanUtils.copyProperties(disHeaderModel, loadingBillDetailVO);
							loadingBillDetailVO.setShippingOrder(1);
							loadingBillDetailVO.setPickUpOrder(1);
							loadingBillDetailVOS.add(loadingBillDetailVO);
							pendingDispatchVO.setLoadingBillDetailVO(loadingBillDetailVOS);
							// 自动调度
							pendingDispatchService.autoDispatch(pendingDispatchVO, user, date, "");
						}
					}
				}
			}

			MessageTypeEnum messageTypeEnum = MessageTypeEnum.SELF_AUDIT;
			if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
				messageTypeEnum = MessageTypeEnum.CARRIER_AUDIT;
			}
			MessageUtil.addMessage(new SendMessageDTO(MessageOrderTypeEnum.SHIP_NO.getCode(), messageTypeEnum.getCode(), Lists.newArrayList(id)));
		}
	}

	/**
	 * 运单待审核-回退
	 *
	 * @param vo
	 * @return
	 */
	@Transactional(rollbackFor = Exception.class)
	@Override
	public void goBackShipbill(ShipbillGoBackVO vo) {
		ToolKits.isParamNull(vo.getBackType(), "回退类型不为空");
		ToolKits.isParamNull(vo.getShipbillIdList(), "运单ID不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		// 当前时间
		Date date = DateUtil.date();

		for (String id : vo.getShipbillIdList()) {
			ToolKits.isParamNull(id, "运单ID不为空");
			// 更新
			TmsShipbillHeaderModel tmsShipbillHeaderModel = tmsShipbillHeaderMapper.findById(id, TmsShipbillHeaderModel.class);
			Restriction r3 = null;
			ShipbillOperateLogSaveVO shipbillOperateLogSaveVO = new ShipbillOperateLogSaveVO();
			ShipbillNodeTrackingSaveVO shipbillNodeTrackingSaveVO = new ShipbillNodeTrackingSaveVO();
			if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY)) {
				// 自有账号
				Assert.isTrue(tmsShipbillHeaderModel.getStatus() != DataDictionaryConstant.SHIPBILL_STATUS_YTH, "运单【" + tmsShipbillHeaderModel.getShipbillNo() + "】已回退");
				// 运单状态更新为5已回退
				tmsShipbillHeaderModel.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_YTH);
				r3 = Restrictions.eq("status", DataDictionaryConstant.SHIPBILL_STATUS_YTJ);

				shipbillNodeTrackingSaveVO.setNodeEvent(DataDictionaryConstant.SHIPBILL_NODE_STATUSNAME_HT);

				shipbillOperateLogSaveVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_NODE_STATUSNAME_HT);
				shipbillOperateLogSaveVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_YTJ);
				shipbillOperateLogSaveVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_YTH);
			} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_CYS)) {
				// 承运商账号
				Assert.isTrue(tmsShipbillHeaderModel.getCarrierShipbillStatus() != DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_ROLLBACK, "运单【" + tmsShipbillHeaderModel.getShipbillNo() + "】已回退");
				// 运单状态更新为5已回退
				tmsShipbillHeaderModel.setCarrierShipbillStatus(DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_ROLLBACK);
				r3 = Restrictions.eq("status", DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_COMMIT);

				shipbillNodeTrackingSaveVO.setNodeEvent(DataDictionaryConstant.CARRIER_SHIPBILL_STATUSNAME_YTH);

				shipbillOperateLogSaveVO.setOperateEvent(DataDictionaryConstant.CARRIER_SHIPBILL_STATUSNAME_YTH);
				shipbillOperateLogSaveVO.setOldStatus(DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_COMMIT);
				shipbillOperateLogSaveVO.setNewStatus(DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_ROLLBACK);
			}
			tmsShipbillHeaderModel.setBackReason(vo.getBackReason());
			tmsShipbillHeaderModel.setBackType(vo.getBackType());
			tmsShipbillHeaderModel.setUpdateperson(user.getNickname());
			tmsShipbillHeaderModel.setUpdatetime(date);
			tmsShipbillHeaderMapper.update(tmsShipbillHeaderModel);

			// 运单确认节点删除
			Criteria criteria = Criteria.forClass(ShipbillNodeTracking.class);
			Restriction r1 = Restrictions.eq("shipbillId", id);
			Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
			criteria.setRestriction(Restrictions.and(r1, r2, r3));
			tmsShipbillNodeTrackingMapper.deleteByCriteria(criteria);

			// 运单日志保存
			shipbillOperateLogSaveVO.setShipbillId(tmsShipbillHeaderModel.getShipbillId());
			shipbillOperateLogSaveVO.setShipbillNo(tmsShipbillHeaderModel.getShipbillNo());
			shipbillOperateLogService.addShipbillOperateLogData(shipbillOperateLogSaveVO);

			// 节点保存
			shipbillNodeTrackingSaveVO.setNodeDate(date);
			shipbillNodeTrackingSaveVO.setShipbillId(tmsShipbillHeaderModel.getShipbillId());
			shipbillNodeTrackingSaveVO.setShipbillNo(tmsShipbillHeaderModel.getShipbillNo());
			shipbillNodeTrackingSaveVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_REVIEW);
			shipbillNodeTrackingService.addShipbillNodeTrackingData(shipbillNodeTrackingSaveVO);
		}
	}

	/**
	 * 地址解析查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<PendingReviewParseAddressPageDTO> parseAddressQueryData(PendingReviewParseAddressPageVO pendingReviewParseAddressPageVO) {
		ToolKits.isParamNull(pendingReviewParseAddressPageVO, "地址解析查询请求不为空");
		ToolKits.isParamNull(pendingReviewParseAddressPageVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(pendingReviewParseAddressPageVO.getPageSize(), "每页条数不为空");
		ToolKits.isParamNull(pendingReviewParseAddressPageVO.getShipbillIds(), "运单ID集不为空");

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

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

		// 发货方类型
		RestMessage<List<Map<String, Object>>> restMessage1 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPPER_TYPE, null, null, null);
		if (!restMessage1.isSuccess()) {
			throw new RuntimeException("发货方类型翻译失败!");
		} else {
			data1 = restMessage1.getData();
		}
		// 收货方类型
		RestMessage<List<Map<String, Object>>> restMessage2 = maindataTmsResource.getDropDownById(DataDictionaryConstant.CONSIGNEE_TYPE, null, null, null);
		if (!restMessage2.isSuccess()) {
			throw new RuntimeException("收货方类型翻译失败!");
		} else {
			data2 = restMessage2.getData();
		}

		// 添加查询条件
		Criteria criteria = Criteria.forClass(TmsShipbillHeaderModel.class);
		Restriction r1 = ToolKits.isEmpty(pendingReviewParseAddressPageVO.getOrderNo()) ? null : Restrictions.like("orderNo", "%" + pendingReviewParseAddressPageVO.getOrderNo() + "%");
		Restriction r2 = ToolKits.isEmpty(pendingReviewParseAddressPageVO.getShipbillNo()) ? null : Restrictions.like("shipbillNo", "%" + pendingReviewParseAddressPageVO.getShipbillNo() + "%");
		Restriction r3 = ToolKits.isEmpty(pendingReviewParseAddressPageVO.getCargoOwnerName()) ? null : Restrictions.like("cargoOwnerName", "%" + pendingReviewParseAddressPageVO.getCargoOwnerName() + "%");
		Restriction r4 = ToolKits.isEmpty(pendingReviewParseAddressPageVO.getShipperUnitName()) ? null : Restrictions.like("shipperUnitName", "%" + pendingReviewParseAddressPageVO.getShipperUnitName() + "%");
		Restriction r5 = ToolKits.isEmpty(pendingReviewParseAddressPageVO.getConsigneeUnitName()) ? null : Restrictions.like("consigneeUnitName", "%" + pendingReviewParseAddressPageVO.getConsigneeUnitName() + "%");
		Restriction r6 = Restrictions.in("shipbillId", pendingReviewParseAddressPageVO.getShipbillIds().toArray());
		Restriction r8 = Restrictions.eq("enterpriseId", user.getEnterpriseId());

		// 权限控制
		Restriction r7 = null;
		Restriction r11 = null;
		Restriction r12 = null;
		Restriction r13 = null;
		Restriction r14 = null;
		Restriction r15 = null;
		Restriction r16 = null;
		// 判断账号类型
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 自有账号
			// 判断是否为部门权限
			r7 = Restrictions.in("status", new Integer[] { DataDictionaryConstant.SHIPBILL_STATUS_YTJ, DataDictionaryConstant.SHIPBILL_STATUS_WZ, DataDictionaryConstant.SHIPBILL_STATUS_WS });
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				r11 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
			} else {
				r11 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
				// 其它权限
				// 货主
				r12 = Restrictions.in("cargoOwnerId", user.getConsignors().toArray());
				// 客户
				r13 = Restrictions.in("consigneeUnitId", user.getCustomers().toArray());
				// 供应商
				r14 = Restrictions.in("consigneeUnitId", user.getSuppliers().toArray());
				// 仓库
				r15 = Restrictions.in("consigneeUnitId", user.getWarehouses().toArray());

				r16 = Restrictions.or(r13, r14, r15);
			}
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
			// 运单状态
			r7 = Restrictions.in("status", new Integer[] { DataDictionaryConstant.SHIPBILL_STATUS_DISPATCH });
			// 承运商账号
			r11 = Restrictions.eq("carrierId", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
			// 承运商运单状态
			r12 = Restrictions.in("carrierShipbillStatus", new Integer[] { DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_COMMIT });
		} else {
			throw new BizException("当前人员没有操作权限！");
		}

		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7, r8, r11, r12, r16));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		PageUtils.startPage(pendingReviewParseAddressPageVO.getPageNum(), pendingReviewParseAddressPageVO.getPageSize());
		List<TmsShipbillHeaderModel> tmsShipbillHeaderModels = tmsShipbillHeaderMapper.findByCriteria(criteria);

		List<PendingReviewParseAddressPageDTO> pendingReviewParseAddressPageDTOs = Lists.newArrayList();
		for (TmsShipbillHeaderModel tmsShipbillHeaderModel : tmsShipbillHeaderModels) {
			PendingReviewParseAddressPageDTO pendingReviewParseAddressPageDTO = new PendingReviewParseAddressPageDTO();
			BeanUtils.copyProperties(tmsShipbillHeaderModel, pendingReviewParseAddressPageDTO);
			pendingReviewParseAddressPageDTO.setShipperTypeName(PublicMethods.change(data1, String.valueOf(pendingReviewParseAddressPageDTO.getShipperType())));
			pendingReviewParseAddressPageDTO.setConsigneeTypeName(PublicMethods.change(data2, String.valueOf(pendingReviewParseAddressPageDTO.getConsigneeType())));

			pendingReviewParseAddressPageDTOs.add(pendingReviewParseAddressPageDTO);
		}

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

	/**
	 * 待审核-地址解析
	 */
	@Transactional(rollbackFor = Exception.class)
	@Override
	public void parseAddressData(PendingReviewParseAddressVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		ToolKits.isParamNull(vo, "运单地址解析请求不为空！");
		ToolKits.isParamNull(vo.getShipperId(), "运单ID不为空");

		// 是否更新发货方
		Boolean updateShipperSign = false;
		// 是否更新收货方
		Boolean updateConsigneeSign = false;

		if (ToolKits.isNotEmpty(vo.getConsigneeAddress()) || ToolKits.isNotEmpty(vo.getConsigneeLatitude()) || ToolKits.isNotEmpty(vo.getConsigneeLongitude())) {
			ToolKits.isParamNull(vo.getConsigneeId(), "收货方ID不为空");
			updateConsigneeSign = true;
		}

		if (ToolKits.isNotEmpty(vo.getShipperAddress()) || ToolKits.isNotEmpty(vo.getShipperLatitude()) || ToolKits.isNotEmpty(vo.getShipperLongitude())) {
			ToolKits.isParamNull(vo.getShipperId(), "发货方ID不为空");
			updateShipperSign = true;
		}

		TmsShipbillHeaderModel model = tmsShipbillHeaderMapper.findById(vo.getShipbillId(), TmsShipbillHeaderModel.class);

		RestMessage<String> restMessage = new RestMessage<String>();
		// 更新发货方数据
		if (updateShipperSign) {
			if (DataDictionaryConstant.SHIPPER_TYPE_KH.equals(model.getShipperType())) {
				restMessage = maindataTmsResource.parseCustomerConsigneeAddress(vo.getShipperId(), vo.getShipperLongitude(), vo.getShipperLatitude(), vo.getShipperAddress());
			} else if (DataDictionaryConstant.SHIPPER_TYPE_CK.equals(model.getShipperType())) {
				restMessage = maindataTmsResource.parseBranchAddress(vo.getShipperId(), vo.getShipperLongitude(), vo.getShipperLatitude(), vo.getShipperAddress());
			} else if (DataDictionaryConstant.SHIPPER_TYPE_GYS.equals(model.getShipperType())) {
				restMessage = maindataTmsResource.parseProviderShipperAddress(vo.getShipperId(), vo.getShipperLongitude(), vo.getShipperLatitude(), vo.getShipperAddress());
			}

			if (!restMessage.isSuccess()) {
				throw new ParameterException("更新发货方失败");
			}
		}

		// 更新收货方数据
		if (updateConsigneeSign) {
			if (DataDictionaryConstant.CONSIGNEE_TYPE_KH.equals(model.getConsigneeType())) {
				restMessage = maindataTmsResource.parseCustomerConsigneeAddress(vo.getConsigneeId(), vo.getConsigneeLongitude(), vo.getConsigneeLatitude(), vo.getConsigneeAddress());
			} else if (DataDictionaryConstant.CONSIGNEE_TYPE_CK.equals(model.getConsigneeType())) {
				restMessage = maindataTmsResource.parseBranchAddress(vo.getConsigneeId(), vo.getConsigneeLongitude(), vo.getConsigneeLatitude(), vo.getConsigneeAddress());
			} else if (DataDictionaryConstant.CONSIGNEE_TYPE_GYS.equals(model.getConsigneeType())) {
				restMessage = maindataTmsResource.parseProviderShipperAddress(vo.getConsigneeId(), vo.getConsigneeLongitude(), vo.getConsigneeLatitude(), vo.getConsigneeAddress());
			}

			if (!restMessage.isSuccess()) {
				throw new ParameterException("更新收货方失败");
			}
		}

		model.setShipperLatitude(vo.getShipperLatitude());
		model.setShipperLongitude(vo.getShipperLongitude());
		model.setShipperAddress(ToolKits.isEmpty(vo.getShipperAddress()) ? null : vo.getShipperAddress());

		model.setConsigneeLatitude(vo.getConsigneeLatitude());
		model.setConsigneeLatitude(vo.getConsigneeLatitude());
		model.setConsigneeAddress(ToolKits.isEmpty(vo.getConsigneeAddress()) ? null : vo.getConsigneeAddress());

		model.setUpdateperson(user.getNickname());
		model.setUpdatetime(DateUtil.date());

		tmsShipbillHeaderMapper.update(model);

		// 运单操作日志保存
		ShipbillOperateLogSaveVO shipbillOperateLogSaveVO = new ShipbillOperateLogSaveVO();
		shipbillOperateLogSaveVO.setShipbillId(model.getShipbillId());
		shipbillOperateLogSaveVO.setShipbillNo(model.getShipbillNo());
		shipbillOperateLogSaveVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_OPERATENAME_XG);
		shipbillOperateLogSaveVO.setOldStatus(model.getStatus());
		shipbillOperateLogSaveVO.setNewStatus(model.getStatus());
		shipbillOperateLogService.addShipbillOperateLogData(shipbillOperateLogSaveVO);
	}

	/**
	 * 待审核导出所有数据
	 *
	 * @param pendingReviewExportAllDataVO
	 * @return
	 */
	public List<PendingReviewExportDetailDataDTO> exportAllDetailData(PendingReviewExportAllDataVO pendingReviewExportAllDataVO) {
		ToolKits.isParamNull(pendingReviewExportAllDataVO, "导出所有数据查询条件不为空");

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

		// 数据字典翻译数据集合
		List<SysRefdatadModel> dicData = convertorUtil.getDictionary(new String[] {
				DataDictionaryConstant.DELIVERY_METHOD_TYPE, // 配送方式
				DataDictionaryConstant.TRANSPORT_TYPE, // 运输类型(运输模式)
				DataDictionaryConstant.TEMPERATURE_REQUIREMENT, // 温度要求
				DataDictionaryConstant.SHIPPER_TYPE, // 发货方类型
				DataDictionaryConstant.CONSIGNEE_TYPE, // 收货方类型
				DataDictionaryConstant.ORDER_TYPE, // 订单类型
				DataDictionaryConstant.ORDER_BUSINESS_TYPE // 订单业务类型
		});

		// 添加查询条件
		Criteria criteria = Criteria.forClass(TmsShipbillHeaderModel.class);
		Restriction r1 = ToolKits.isEmpty(pendingReviewExportAllDataVO.getCargoOwnerName()) ? null : Restrictions.like("cargoOwnerName", "%" + pendingReviewExportAllDataVO.getCargoOwnerName() + "%");
		Restriction r2 = ToolKits.isEmpty(pendingReviewExportAllDataVO.getOrderNo()) ? null : Restrictions.like("orderNo", "%" + pendingReviewExportAllDataVO.getOrderNo() + "%");
		Restriction r3 = ToolKits.isEmpty(pendingReviewExportAllDataVO.getShipbillNo()) ? null : Restrictions.like("shipbillNo", "%" + pendingReviewExportAllDataVO.getShipbillNo() + "%");
		Restriction r4 = ToolKits.isEmpty(pendingReviewExportAllDataVO.getOrderBusinessType()) ? null : Restrictions.eq("orderBusinessType", pendingReviewExportAllDataVO.getOrderBusinessType());
		Restriction r5 = ToolKits.isEmpty(pendingReviewExportAllDataVO.getEstimatedPickupStartTime()) ? null : Restrictions.ge("estimatedPickupStartTime", pendingReviewExportAllDataVO.getEstimatedPickupStartTime());
		Restriction r6 = ToolKits.isEmpty(pendingReviewExportAllDataVO.getEstimatedPickupEndTime()) ? null : Restrictions.le("estimatedPickupEndTime", pendingReviewExportAllDataVO.getEstimatedPickupEndTime());
		Restriction r7 = ToolKits.isEmpty(pendingReviewExportAllDataVO.getEstimatedDeliveryStartTime()) ? null : Restrictions.ge("estimatedDeliveryStartTime", pendingReviewExportAllDataVO.getEstimatedDeliveryStartTime());
		Restriction r8 = ToolKits.isEmpty(pendingReviewExportAllDataVO.getEstimatedDeliveryEndTime()) ? null : Restrictions.le("estimatedDeliveryEndTime", pendingReviewExportAllDataVO.getEstimatedDeliveryEndTime());

		Restriction r9 = null;
		if (ToolKits.isNotEmpty(pendingReviewExportAllDataVO.getShipperLocation()) && pendingReviewExportAllDataVO.getShipperLocation().intValue() == 0) {
			Restriction r13 = Restrictions.isnull("shipperLongitude");
			Restriction r14 = Restrictions.isnull("shipperLatitude");
			r9 = Restrictions.or(r13, r14);
		} else if (ToolKits.isNotEmpty(pendingReviewExportAllDataVO.getShipperLocation()) && pendingReviewExportAllDataVO.getShipperLocation().intValue() == 1) {
			Restriction r13 = Restrictions.isNotNull("shipperLongitude");
			Restriction r14 = Restrictions.isNotNull("shipperLatitude");
			r9 = Restrictions.and(r13, r14);
		}
		Restriction r10 = null;
		if (ToolKits.isNotEmpty(pendingReviewExportAllDataVO.getConsigneeLocation()) && pendingReviewExportAllDataVO.getConsigneeLocation().intValue() == 0) {
			Restriction r15 = Restrictions.isnull("consigneeLongitude");
			Restriction r16 = Restrictions.isnull("consigneeLatitude");
			r10 = Restrictions.or(r15, r16);
		} else if (ToolKits.isNotEmpty(pendingReviewExportAllDataVO.getConsigneeLocation()) && pendingReviewExportAllDataVO.getConsigneeLocation().intValue() == 1) {
			Restriction r15 = Restrictions.isNotNull("consigneeLongitude");
			Restriction r16 = Restrictions.isNotNull("consigneeLatitude");
			r10 = Restrictions.and(r15, r16);
		}
		Restriction r11 = null;
		Restriction r19 = null;
		Restriction r25 = null;
		Restriction r30 = null;
		Restriction r12 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		// 权限控制
		if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY)) {
			// 自有账号
			// 拆单状态 0未拆单
			Restriction r31 = Restrictions.eq("splitOrderStatus", DataDictionaryConstant.SPLIT_ORDER_STATUS_UN);
			// 承运商拆单类型 1未拆单
			Restriction r32 = Restrictions.eq("carrierSplitOrderType", DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_UN);
			Restriction r33 = Restrictions.and(r31, r32);
			// 承运商拆单类型 2拆分主单
			Restriction r34 = Restrictions.eq("carrierSplitOrderType", DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_SPLIT_MASTER);
			// 承运商拆单类型 2中转主单
			Restriction r35 = Restrictions.eq("carrierSplitOrderType", DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_TRANSIT_MASTER);
			r30 = Restrictions.or(r33, r34, r35);
			// 判断是否为部门权限
			Integer[] stsArr = { DataDictionaryConstant.SHIPBILL_STATUS_YTJ, DataDictionaryConstant.SHIPBILL_STATUS_WZ, DataDictionaryConstant.SHIPBILL_STATUS_WS };
			r11 = Restrictions.in("status", stsArr);
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				r19 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
			} else {
				r19 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
				Restriction r20 = Restrictions.in("cargoOwnerId", user.getConsignors().stream().toArray(Long[]::new));

				Restriction r21 = Restrictions.in("consigneeUnitId", user.getWarehouses().stream().toArray(Long[]::new));
				Restriction r22 = Restrictions.in("consigneeUnitId", user.getSuppliers().stream().toArray(Long[]::new));
				Restriction r23 = Restrictions.in("consigneeUnitId", user.getCustomers().stream().toArray(Long[]::new));

				Restriction r43 = Restrictions.in(TmsShipbillHeaderModel::getShipperUnitId, user.getWarehouses().stream().toArray(Long[]::new));
				Restriction r44 = Restrictions.in(TmsShipbillHeaderModel::getShipperUnitId, user.getSuppliers().stream().toArray(Long[]::new));
				Restriction r45 = Restrictions.in(TmsShipbillHeaderModel::getShipperUnitId, user.getCustomers().stream().toArray(Long[]::new));

				Restriction r24 = Restrictions.or(r21, r22, r23, r43, r44, r45);
				r25 = Restrictions.and(r20, r24);
			}
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_CYS)) {
			// 承运商账号
			// 查询调度类型为承运商的运单
			r30 = Restrictions.eq("carrierSplitOrderStatus", DataDictionaryConstant.CARRIER_SPLIT_ORDER_STATUS_UN);
			Restriction r26 = Restrictions.eq("carrierId", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
			Restriction r27 = Restrictions.gt("status", DataDictionaryConstant.SHIPBILL_STATUS_DISPATCH);
			Restriction r28 = Restrictions.eq("carrierShipbillStatus", DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_COMMIT);
			r25 = Restrictions.and(r26, r27, r28);
		} else {
			throw new PrologException("当前人员没有操作权限！");
		}
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r19, r25, r30));
		List<TmsShipbillHeaderModel> tmsShipbillHeaderModels = tmsShipbillHeaderMapper.findByCriteria(criteria);

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

		for (TmsShipbillHeaderModel tmsShipbillHeaderModel : tmsShipbillHeaderModels) {
			PendingReviewExportDetailDataDTO pendingReviewExportDetailDataDTO = new PendingReviewExportDetailDataDTO();
			BeanUtils.copyProperties(tmsShipbillHeaderModel, pendingReviewExportDetailDataDTO);
			// 收货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLatitude())) {
				pendingReviewExportDetailDataDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
			} else {
				pendingReviewExportDetailDataDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
			}
			// 发货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLatitude())) {
				pendingReviewExportDetailDataDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
			} else {
				pendingReviewExportDetailDataDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
			}
			StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
			// 目的地
			consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeProvinceName()) ? "" : tmsShipbillHeaderModel.getConsigneeProvinceName());
			consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeCityName()) ? "" : tmsShipbillHeaderModel.getConsigneeCityName());
			consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeDistrictName()) ? "" : tmsShipbillHeaderModel.getConsigneeDistrictName());
			pendingReviewExportDetailDataDTO.setConsigneeProvinceCityDistrict(consigneeProvinceCityDistrict.toString());
			// 始发地
			StringBuffer shipperProvinceCityDistrict = new StringBuffer();
			shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperProvinceName()) ? "" : tmsShipbillHeaderModel.getShipperProvinceName());
			shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperCityName()) ? "" : tmsShipbillHeaderModel.getShipperCityName());
			shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperDistrictName()) ? "" : tmsShipbillHeaderModel.getShipperDistrictName());
			pendingReviewExportDetailDataDTO.setShipperProvinceCityDistrict(shipperProvinceCityDistrict.toString());

			// 类型翻译
			pendingReviewExportDetailDataDTO.setOrderTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ORDER_TYPE, String.valueOf(tmsShipbillHeaderModel.getOrderType())));
			pendingReviewExportDetailDataDTO.setOrderBusinessTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ORDER_BUSINESS_TYPE, String.valueOf(tmsShipbillHeaderModel.getOrderBusinessType())));
			pendingReviewExportDetailDataDTO.setDeliveryMethodTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.DELIVERY_METHOD_TYPE, String.valueOf(tmsShipbillHeaderModel.getDeliveryMethodType())));
			pendingReviewExportDetailDataDTO.setTransportTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TRANSPORT_TYPE, String.valueOf(tmsShipbillHeaderModel.getTransportType())));
			pendingReviewExportDetailDataDTO.setTemperatureRequirementName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TEMPERATURE_REQUIREMENT, String.valueOf(tmsShipbillHeaderModel.getTemperatureRequirement())));
			pendingReviewExportDetailDataDTO.setShipperTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.SHIPPER_TYPE, String.valueOf(tmsShipbillHeaderModel.getShipperType())));
			pendingReviewExportDetailDataDTO.setConsigneeTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.CONSIGNEE_TYPE, String.valueOf(tmsShipbillHeaderModel.getConsigneeType())));

			pendingReviewExportDetailDataDTOList.add(pendingReviewExportDetailDataDTO);
		}
		return pendingReviewExportDetailDataDTOList;
	}

	/**
	 * 待审核导出当前页数据
	 *
	 * @param pendingReviewExportCurrentPageDataVO
	 * @return
	 */
	public List<PendingReviewExportDetailDataDTO> exportCurrentPageDetailData(PendingReviewExportCurrentPageDataVO pendingReviewExportCurrentPageDataVO) {
		ToolKits.isParamNull(pendingReviewExportCurrentPageDataVO, "导出当前页数据查询条件不为空");

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

		// 数据字典翻译数据集合
		List<SysRefdatadModel> dicData = convertorUtil.getDictionary(new String[] {
				DataDictionaryConstant.DELIVERY_METHOD_TYPE, // 配送方式
				DataDictionaryConstant.TRANSPORT_TYPE, // 运输类型(运输模式)
				DataDictionaryConstant.TEMPERATURE_REQUIREMENT, // 温度要求
				DataDictionaryConstant.SHIPPER_TYPE, // 发货方类型
				DataDictionaryConstant.CONSIGNEE_TYPE, // 收货方类型
				DataDictionaryConstant.ORDER_TYPE, // 订单类型
				DataDictionaryConstant.ORDER_BUSINESS_TYPE // 订单业务类型
		});

		// 添加查询条件
		Criteria criteria = Criteria.forClass(TmsShipbillHeaderModel.class);
		Restriction r1 = ToolKits.isEmpty(pendingReviewExportCurrentPageDataVO.getCargoOwnerName()) ? null : Restrictions.like("cargoOwnerName", "%" + pendingReviewExportCurrentPageDataVO.getCargoOwnerName() + "%");
		Restriction r2 = ToolKits.isEmpty(pendingReviewExportCurrentPageDataVO.getOrderNo()) ? null : Restrictions.like("orderNo", "%" + pendingReviewExportCurrentPageDataVO.getOrderNo() + "%");
		Restriction r3 = ToolKits.isEmpty(pendingReviewExportCurrentPageDataVO.getShipbillNo()) ? null : Restrictions.like("shipbillNo", "%" + pendingReviewExportCurrentPageDataVO.getShipbillNo() + "%");
		Restriction r4 = ToolKits.isEmpty(pendingReviewExportCurrentPageDataVO.getOrderBusinessType()) ? null : Restrictions.eq("orderBusinessType", pendingReviewExportCurrentPageDataVO.getOrderBusinessType());
		Restriction r5 = ToolKits.isEmpty(pendingReviewExportCurrentPageDataVO.getEstimatedPickupStartTime()) ? null : Restrictions.ge("estimatedPickupStartTime", pendingReviewExportCurrentPageDataVO.getEstimatedPickupStartTime());
		Restriction r6 = ToolKits.isEmpty(pendingReviewExportCurrentPageDataVO.getEstimatedPickupEndTime()) ? null : Restrictions.le("estimatedPickupEndTime", pendingReviewExportCurrentPageDataVO.getEstimatedPickupEndTime());
		Restriction r7 = ToolKits.isEmpty(pendingReviewExportCurrentPageDataVO.getEstimatedDeliveryStartTime()) ? null : Restrictions.ge("estimatedDeliveryStartTime", pendingReviewExportCurrentPageDataVO.getEstimatedDeliveryStartTime());
		Restriction r8 = ToolKits.isEmpty(pendingReviewExportCurrentPageDataVO.getEstimatedDeliveryEndTime()) ? null : Restrictions.le("estimatedDeliveryEndTime", pendingReviewExportCurrentPageDataVO.getEstimatedDeliveryEndTime());

		Restriction r9 = null;
		if (ToolKits.isNotEmpty(pendingReviewExportCurrentPageDataVO.getShipperLocation()) && pendingReviewExportCurrentPageDataVO.getShipperLocation().intValue() == 0) {
			Restriction r13 = Restrictions.isnull("shipperLongitude");
			Restriction r14 = Restrictions.isnull("shipperLatitude");
			r9 = Restrictions.or(r13, r14);
		} else if (ToolKits.isNotEmpty(pendingReviewExportCurrentPageDataVO.getShipperLocation()) && pendingReviewExportCurrentPageDataVO.getShipperLocation().intValue() == 1) {
			Restriction r13 = Restrictions.isNotNull("shipperLongitude");
			Restriction r14 = Restrictions.isNotNull("shipperLatitude");
			r9 = Restrictions.and(r13, r14);
		}
		Restriction r10 = null;
		if (ToolKits.isNotEmpty(pendingReviewExportCurrentPageDataVO.getConsigneeLocation()) && pendingReviewExportCurrentPageDataVO.getConsigneeLocation().intValue() == 0) {
			Restriction r15 = Restrictions.isnull("consigneeLongitude");
			Restriction r16 = Restrictions.isnull("consigneeLatitude");
			r10 = Restrictions.or(r15, r16);
		} else if (ToolKits.isNotEmpty(pendingReviewExportCurrentPageDataVO.getConsigneeLocation()) && pendingReviewExportCurrentPageDataVO.getConsigneeLocation().intValue() == 1) {
			Restriction r15 = Restrictions.isNotNull("consigneeLongitude");
			Restriction r16 = Restrictions.isNotNull("consigneeLatitude");
			r10 = Restrictions.and(r15, r16);
		}
		Restriction r11 = null;
		Restriction r19 = null;
		Restriction r25 = null;
		Restriction r30 = null;
		Restriction r12 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		// 权限控制
		if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY)) {
			// 自有账号
			// 拆单状态 0未拆单
			Restriction r31 = Restrictions.eq("splitOrderStatus", DataDictionaryConstant.SPLIT_ORDER_STATUS_UN);
			// 承运商拆单类型 1未拆单
			Restriction r32 = Restrictions.eq("carrierSplitOrderType", DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_UN);
			Restriction r33 = Restrictions.and(r31, r32);
			// 承运商拆单类型 2拆分主单
			Restriction r34 = Restrictions.eq("carrierSplitOrderType", DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_SPLIT_MASTER);
			// 承运商拆单类型 2中转主单
			Restriction r35 = Restrictions.eq("carrierSplitOrderType", DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_TRANSIT_MASTER);
			r30 = Restrictions.or(r33, r34, r35);
			// 判断是否为部门权限
			Integer[] stsArr = { DataDictionaryConstant.SHIPBILL_STATUS_YTJ, DataDictionaryConstant.SHIPBILL_STATUS_WZ, DataDictionaryConstant.SHIPBILL_STATUS_WS };
			r11 = Restrictions.in("status", stsArr);
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				r19 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
			} else {
				r19 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
				Restriction r20 = Restrictions.in("cargoOwnerId", user.getConsignors().stream().toArray(Long[]::new));

				Restriction r21 = Restrictions.in("consigneeUnitId", user.getWarehouses().stream().toArray(Long[]::new));
				Restriction r22 = Restrictions.in("consigneeUnitId", user.getSuppliers().stream().toArray(Long[]::new));
				Restriction r23 = Restrictions.in("consigneeUnitId", user.getCustomers().stream().toArray(Long[]::new));

				Restriction r43 = Restrictions.in(TmsShipbillHeaderModel::getShipperUnitId, user.getWarehouses().stream().toArray(Long[]::new));
				Restriction r44 = Restrictions.in(TmsShipbillHeaderModel::getShipperUnitId, user.getSuppliers().stream().toArray(Long[]::new));
				Restriction r45 = Restrictions.in(TmsShipbillHeaderModel::getShipperUnitId, user.getCustomers().stream().toArray(Long[]::new));

				Restriction r24 = Restrictions.or(r21, r22, r23, r43, r44, r45);
				r25 = Restrictions.and(r20, r24);
			}
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_CYS)) {
			// 承运商账号
			// 查询调度类型为承运商的运单
			r30 = Restrictions.eq("carrierSplitOrderStatus", DataDictionaryConstant.CARRIER_SPLIT_ORDER_STATUS_UN);
			Restriction r26 = Restrictions.eq("carrierId", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
			Restriction r27 = Restrictions.gt("status", DataDictionaryConstant.SHIPBILL_STATUS_DISPATCH);
			Restriction r28 = Restrictions.eq("carrierShipbillStatus", DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_COMMIT);
			r25 = Restrictions.and(r26, r27, r28);
		} else {
			throw new PrologException("当前人员没有操作权限！");
		}
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r19, r25, r30));

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

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

		for (TmsShipbillHeaderModel tmsShipbillHeaderModel : tmsShipbillHeaderModels) {
			PendingReviewExportDetailDataDTO pendingReviewExportDetailDataDTO = new PendingReviewExportDetailDataDTO();
			BeanUtils.copyProperties(tmsShipbillHeaderModel, pendingReviewExportDetailDataDTO);
			// 收货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLatitude())) {
				pendingReviewExportDetailDataDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
			} else {
				pendingReviewExportDetailDataDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
			}
			// 发货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLatitude())) {
				pendingReviewExportDetailDataDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
			} else {
				pendingReviewExportDetailDataDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
			}
			StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
			// 目的地
			consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeProvinceName()) ? "" : tmsShipbillHeaderModel.getConsigneeProvinceName());
			consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeCityName()) ? "" : tmsShipbillHeaderModel.getConsigneeCityName());
			consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeDistrictName()) ? "" : tmsShipbillHeaderModel.getConsigneeDistrictName());
			pendingReviewExportDetailDataDTO.setConsigneeProvinceCityDistrict(consigneeProvinceCityDistrict.toString());
			// 始发地
			StringBuffer shipperProvinceCityDistrict = new StringBuffer();
			shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperProvinceName()) ? "" : tmsShipbillHeaderModel.getShipperProvinceName());
			shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperCityName()) ? "" : tmsShipbillHeaderModel.getShipperCityName());
			shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperDistrictName()) ? "" : tmsShipbillHeaderModel.getShipperDistrictName());
			pendingReviewExportDetailDataDTO.setShipperProvinceCityDistrict(shipperProvinceCityDistrict.toString());

			// 类型翻译
			pendingReviewExportDetailDataDTO.setOrderTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ORDER_TYPE, String.valueOf(tmsShipbillHeaderModel.getOrderType())));
			pendingReviewExportDetailDataDTO.setOrderBusinessTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ORDER_BUSINESS_TYPE, String.valueOf(tmsShipbillHeaderModel.getOrderBusinessType())));
			pendingReviewExportDetailDataDTO.setDeliveryMethodTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.DELIVERY_METHOD_TYPE, String.valueOf(tmsShipbillHeaderModel.getDeliveryMethodType())));
			pendingReviewExportDetailDataDTO.setTransportTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TRANSPORT_TYPE, String.valueOf(tmsShipbillHeaderModel.getTransportType())));
			pendingReviewExportDetailDataDTO.setTemperatureRequirementName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TEMPERATURE_REQUIREMENT, String.valueOf(tmsShipbillHeaderModel.getTemperatureRequirement())));
			pendingReviewExportDetailDataDTO.setShipperTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.SHIPPER_TYPE, String.valueOf(tmsShipbillHeaderModel.getShipperType())));
			pendingReviewExportDetailDataDTO.setConsigneeTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.CONSIGNEE_TYPE, String.valueOf(tmsShipbillHeaderModel.getConsigneeType())));

			pendingReviewExportDetailDataDTOList.add(pendingReviewExportDetailDataDTO);
		}
		return pendingReviewExportDetailDataDTOList;
	}

	/**
	 * 待审核导出选择行数据
	 *
	 * @param shipbillIdList
	 * @return
	 */
	public List<PendingReviewExportDetailDataDTO> exportSelectLineData(List<String> shipbillIdList) {
		ToolKits.isParamNull(shipbillIdList, "导出选择行数据查询条件不为空");

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

		// 数据字典翻译数据集合
		List<SysRefdatadModel> dicData = convertorUtil.getDictionary(new String[] {
				DataDictionaryConstant.DELIVERY_METHOD_TYPE, // 配送方式
				DataDictionaryConstant.TRANSPORT_TYPE, // 运输类型(运输模式)
				DataDictionaryConstant.TEMPERATURE_REQUIREMENT, // 温度要求
				DataDictionaryConstant.SHIPPER_TYPE, // 发货方类型
				DataDictionaryConstant.CONSIGNEE_TYPE, // 收货方类型
				DataDictionaryConstant.ORDER_TYPE, // 订单类型
				DataDictionaryConstant.ORDER_BUSINESS_TYPE // 订单业务类型
		});

		// 添加查询条件
		Criteria criteria = Criteria.forClass(TmsShipbillHeaderModel.class);
		Integer[] stsArr = { DataDictionaryConstant.SHIPBILL_STATUS_YTJ, DataDictionaryConstant.SHIPBILL_STATUS_WZ, DataDictionaryConstant.SHIPBILL_STATUS_WS };
		Restriction r1 = Restrictions.in("status", stsArr);
		Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		String[] shipbillIdArray = shipbillIdList.stream().toArray(String[]::new);
		Restriction r3 = Restrictions.in("shipbillId", shipbillIdArray);

		criteria.setRestriction(Restrictions.and(r1, r2, r3));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));

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

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

		for (TmsShipbillHeaderModel tmsShipbillHeaderModel : tmsShipbillHeaderModels) {
			PendingReviewExportDetailDataDTO pendingReviewExportDetailDataDTO = new PendingReviewExportDetailDataDTO();
			BeanUtils.copyProperties(tmsShipbillHeaderModel, pendingReviewExportDetailDataDTO);
			// 收货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLatitude())) {
				pendingReviewExportDetailDataDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
			} else {
				pendingReviewExportDetailDataDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
			}
			// 发货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLatitude())) {
				pendingReviewExportDetailDataDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
			} else {
				pendingReviewExportDetailDataDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
			}
			StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
			// 目的地
			consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeProvinceName()) ? "" : tmsShipbillHeaderModel.getConsigneeProvinceName());
			consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeCityName()) ? "" : tmsShipbillHeaderModel.getConsigneeCityName());
			consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeDistrictName()) ? "" : tmsShipbillHeaderModel.getConsigneeDistrictName());
			pendingReviewExportDetailDataDTO.setConsigneeProvinceCityDistrict(consigneeProvinceCityDistrict.toString());
			// 始发地
			StringBuffer shipperProvinceCityDistrict = new StringBuffer();
			shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperProvinceName()) ? "" : tmsShipbillHeaderModel.getShipperProvinceName());
			shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperCityName()) ? "" : tmsShipbillHeaderModel.getShipperCityName());
			shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperDistrictName()) ? "" : tmsShipbillHeaderModel.getShipperDistrictName());
			pendingReviewExportDetailDataDTO.setShipperProvinceCityDistrict(shipperProvinceCityDistrict.toString());

			// 类型翻译
			pendingReviewExportDetailDataDTO.setOrderTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ORDER_TYPE, String.valueOf(tmsShipbillHeaderModel.getOrderType())));
			pendingReviewExportDetailDataDTO.setOrderBusinessTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ORDER_BUSINESS_TYPE, String.valueOf(tmsShipbillHeaderModel.getOrderBusinessType())));
			pendingReviewExportDetailDataDTO.setDeliveryMethodTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.DELIVERY_METHOD_TYPE, String.valueOf(tmsShipbillHeaderModel.getDeliveryMethodType())));
			pendingReviewExportDetailDataDTO.setTransportTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TRANSPORT_TYPE, String.valueOf(tmsShipbillHeaderModel.getTransportType())));
			pendingReviewExportDetailDataDTO.setTemperatureRequirementName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TEMPERATURE_REQUIREMENT, String.valueOf(tmsShipbillHeaderModel.getTemperatureRequirement())));
			pendingReviewExportDetailDataDTO.setShipperTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.SHIPPER_TYPE, String.valueOf(tmsShipbillHeaderModel.getShipperType())));
			pendingReviewExportDetailDataDTO.setConsigneeTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.CONSIGNEE_TYPE, String.valueOf(tmsShipbillHeaderModel.getConsigneeType())));

			pendingReviewExportDetailDataDTOList.add(pendingReviewExportDetailDataDTO);
		}
		return pendingReviewExportDetailDataDTOList;
	}

	/**
	 * 待审核运单打印
	 *
	 * @param shipbillId
	 * @return
	 */
	@Override
	public Map<String, Object> shipbillPrint(String shipbillId) {
		ToolKits.isParamNull(shipbillId, "运单ID集合不为空");

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

		// 数据字典翻译数据集合
		List<SysRefdatadModel> dicData = convertorUtil.getDictionary(new String[] {
				DataDictionaryConstant.DELIVERY_METHOD_TYPE, // 配送方式
				DataDictionaryConstant.TRANSPORT_TYPE, // 运输类型(运输模式)
				DataDictionaryConstant.TEMPERATURE_REQUIREMENT, // 温度要求
				DataDictionaryConstant.SHIPPER_TYPE, // 发货方类型
				DataDictionaryConstant.CONSIGNEE_TYPE, // 收货方类型
				DataDictionaryConstant.ORDER_TYPE, // 订单类型
				DataDictionaryConstant.PACK_TYPE, // 包装类型
				DataDictionaryConstant.CARGO_THERMOSPHERE, // 货物温层
				DataDictionaryConstant.ORDER_BUSINESS_TYPE // 订单业务类型
		});

		// 查询运单信息
		TmsShipbillHeaderModel tmsShipbillHeaderModel = tmsShipbillHeaderMapper.findById(shipbillId, TmsShipbillHeaderModel.class);

		ToolKits.isParamNull(tmsShipbillHeaderModel, "运单ID[" + shipbillId + "]信息不存在");

		// 打印头部数据
		PendingReviewPrintHeadDTO printHeadDTO = new PendingReviewPrintHeadDTO();
		BeanUtils.copyProperties(tmsShipbillHeaderModel, printHeadDTO);
		// 收货方位置(经纬度判断)
		if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLatitude())) {
			printHeadDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
		} else {
			printHeadDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
		}
		// 发货方位置(经纬度判断)
		if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLatitude())) {
			printHeadDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
		} else {
			printHeadDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
		}

		StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
		// 目的地
		consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeProvinceName()) ? "" : tmsShipbillHeaderModel.getConsigneeProvinceName());
		consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeCityName()) ? "" : tmsShipbillHeaderModel.getConsigneeCityName());
		consigneeProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getConsigneeDistrictName()) ? "" : tmsShipbillHeaderModel.getConsigneeDistrictName());
		printHeadDTO.setConsigneeProvinceCityDistrict(consigneeProvinceCityDistrict.toString());
		// 始发地
		StringBuffer shipperProvinceCityDistrict = new StringBuffer();
		shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperProvinceName()) ? "" : tmsShipbillHeaderModel.getShipperProvinceName());
		shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperCityName()) ? "" : tmsShipbillHeaderModel.getShipperCityName());
		shipperProvinceCityDistrict.append(ToolKits.isEmpty(tmsShipbillHeaderModel.getShipperDistrictName()) ? "" : tmsShipbillHeaderModel.getShipperDistrictName());
		printHeadDTO.setShipperProvinceCityDistrict(shipperProvinceCityDistrict.toString());

		// 类型翻译
		printHeadDTO.setOrderTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ORDER_TYPE, String.valueOf(tmsShipbillHeaderModel.getOrderType())));
		printHeadDTO.setOrderBusinessTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ORDER_BUSINESS_TYPE, String.valueOf(tmsShipbillHeaderModel.getOrderBusinessType())));
		printHeadDTO.setDeliveryMethodTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.DELIVERY_METHOD_TYPE, String.valueOf(tmsShipbillHeaderModel.getDeliveryMethodType())));
		printHeadDTO.setTransportTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TRANSPORT_TYPE, String.valueOf(tmsShipbillHeaderModel.getTransportType())));
		printHeadDTO.setTemperatureRequirementName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TEMPERATURE_REQUIREMENT, String.valueOf(tmsShipbillHeaderModel.getTemperatureRequirement())));
		printHeadDTO.setShipperTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.SHIPPER_TYPE, String.valueOf(tmsShipbillHeaderModel.getShipperType())));
		printHeadDTO.setConsigneeTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.CONSIGNEE_TYPE, String.valueOf(tmsShipbillHeaderModel.getConsigneeType())));

		// 获取商品信息
		Criteria criteria = Criteria.forClass(TmsShipbillDetailModel.class);
		Restriction r1 = Restrictions.eq("shipbillId", shipbillId);
		criteria.setRestriction(r1);
		List<TmsShipbillDetailModel> tmsShipbillDetailModels = tmsShipbillDetailMapper.findByCriteria(criteria);

		List<PendingReviewPrintTableDTO> pendingReviewPrintTableDTOs = new ArrayList<PendingReviewPrintTableDTO>();

		if (ToolKits.isNotEmpty(tmsShipbillDetailModels)) {
			for (TmsShipbillDetailModel item : tmsShipbillDetailModels) {
				PendingReviewPrintTableDTO dto = new PendingReviewPrintTableDTO();
				BeanUtils.copyProperties(item, dto);
				dto.setPackTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.PACK_TYPE, String.valueOf(item.getPackType())));
				dto.setCargoThermosphereName(ConvertorUtil.getName(dicData, DataDictionaryConstant.CARGO_THERMOSPHERE, String.valueOf(item.getCargoThermosphere())));
				pendingReviewPrintTableDTOs.add(dto);
			}
		}

		// TODO print
		return null;
	}

	/**
	 * 待审核运单查看
	 *
	 * @param pendingReviewViewVO
	 * @return
	 */
	@Override
	public PendingReviewViewDTO viewShipbillData(PendingReviewViewVO pendingReviewViewVO) {
		ToolKits.isParamNull(pendingReviewViewVO, "待审核运单查看请求不为空");
		ToolKits.isParamNull(pendingReviewViewVO.getShipbillId(), "运单ID不为空");

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

		// 数据字典翻译数据集合
		List<Map<String, Object>> data1 = Lists.newArrayList();
		List<Map<String, Object>> data2 = Lists.newArrayList();
		List<Map<String, Object>> data3 = Lists.newArrayList();
		List<Map<String, Object>> data4 = Lists.newArrayList();
		List<Map<String, Object>> data5 = Lists.newArrayList();
		List<Map<String, Object>> data6 = Lists.newArrayList();
		List<Map<String, Object>> data7 = Lists.newArrayList();
		List<Map<String, Object>> data8 = Lists.newArrayList();
		List<Map<String, Object>> data9 = Lists.newArrayList();
		List<Map<String, Object>> data10 = Lists.newArrayList();
		List<Map<String, Object>> data11 = 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.PACK_TYPE, null, null, null);
		if (!restMessage8.isSuccess()) {
			throw new RuntimeException("包装类型翻译失败!");
		} else {
			data8 = restMessage8.getData();
		}
		// 货物温层
		RestMessage<List<Map<String, Object>>> restMessage9 = maindataTmsResource.getDropDownById(DataDictionaryConstant.CARGO_THERMOSPHERE, null, null, null);
		if (!restMessage9.isSuccess()) {
			throw new RuntimeException("货物温层翻译失败!");
		} else {
			data9 = restMessage9.getData();
		}

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

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

		// 查询运单汇总信息
		TmsShipbillHeaderModel model = tmsShipbillHeaderMapper.findById(pendingReviewViewVO.getShipbillId(), TmsShipbillHeaderModel.class);
		PendingReviewViewDTO dto = new PendingReviewViewDTO();
		BeanUtils.copyProperties(model, dto);

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

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

		// 运单明细数据集
		List<PendingReviewViewDetailDTO> pendingReviewDetailDTOs = Lists.newArrayList();

		// 查询运单明细
		Criteria criteria = Criteria.forClass(TmsShipbillDetailModel.class);
		Restriction r1 = Restrictions.eq("shipbillId", pendingReviewViewVO.getShipbillId());
		Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2));
		criteria.setOrder(Order.newInstance().asc(new String[] { "seqno" }));
		List<TmsShipbillDetailModel> tmsShipbillDetailModels = tmsShipbillDetailMapper.findByCriteria(criteria);
		// 商品总件数
		BigDecimal goodsTotalPcs = new BigDecimal(0);
		// 商品总体积
		BigDecimal goodsTotalVolume = new BigDecimal(0);
		// 商品总重量
		BigDecimal goodsTotalWeight = new BigDecimal(0);
		if (ToolKits.isNotEmpty(tmsShipbillDetailModels)) {
			for (TmsShipbillDetailModel tmsShipbillDetailModel : tmsShipbillDetailModels) {
				PendingReviewViewDetailDTO detailDTO = new PendingReviewViewDetailDTO();
				BeanUtils.copyProperties(tmsShipbillDetailModel, detailDTO);
				// 数据字典翻译
				detailDTO.setPackTypeName(PublicMethods.change(data8, String.valueOf(detailDTO.getPackType())));
				detailDTO.setCargoThermosphereName(PublicMethods.change(data9, String.valueOf(detailDTO.getCargoThermosphere())));
				pendingReviewDetailDTOs.add(detailDTO);
				goodsTotalPcs = goodsTotalPcs.add(detailDTO.getPcs());
				goodsTotalVolume = goodsTotalVolume.add(detailDTO.getVolume());
				goodsTotalWeight = goodsTotalWeight.add(detailDTO.getWeight());
			}
			dto.setPendingReviewDetailDTOs(pendingReviewDetailDTOs);
			dto.setGoodsTotalPcs(goodsTotalPcs);
			dto.setGoodsTotalVolume(goodsTotalVolume);
			dto.setGoodsTotalWeight(goodsTotalWeight);
		}

		// 运单包裹数据集
		List<PendingReviewViewPackageDTO> pendingReviewPackageDTOs = Lists.newArrayList();

		// 查询运单包裹明细
		Criteria criteriaPkg = Criteria.forClass(TmsShipbillPackageModel.class);
		Restriction r3 = Restrictions.eq("shipbillId", pendingReviewViewVO.getShipbillId());
		Restriction r4 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteriaPkg.setRestriction(Restrictions.and(r3, r4));
		criteriaPkg.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		List<TmsShipbillPackageModel> tmsShipbillPackageModels = tmsShipbillPackageMapper.findByCriteria(criteriaPkg);
		// 包裹总件数
		BigDecimal pkgTotalPcs = new BigDecimal(0);
		// 包裹总拼箱数
		BigDecimal pkgTotalLclPiece = new BigDecimal(0);
		// 包裹总整件数
		BigDecimal pkgTotalWholePiece = new BigDecimal(0);
		// 包裹总体积
		BigDecimal pkgTotalVolume = new BigDecimal(0);
		// 包裹总重量
		BigDecimal pkgTotalWeight = new BigDecimal(0);
		if (ToolKits.isNotEmpty(tmsShipbillPackageModels)) {
			for (TmsShipbillPackageModel tmsShipbillPackageModel : tmsShipbillPackageModels) {
				PendingReviewViewPackageDTO pkgDTO = new PendingReviewViewPackageDTO();
				BeanUtils.copyProperties(tmsShipbillPackageModel, pkgDTO);
				// 数据字典翻译
				pkgDTO.setPackageTypeName(PublicMethods.change(data10, String.valueOf(pkgDTO.getPackageType())));
				pkgDTO.setDeviceCompanyName(PublicMethods.change(data11, String.valueOf(pkgDTO.getDeviceCompany())));
				pendingReviewPackageDTOs.add(pkgDTO);

				pkgTotalPcs = pkgTotalPcs.add(pkgDTO.getLclPiece()).add(pkgDTO.getWholePiece());
				pkgTotalLclPiece = pkgTotalLclPiece.add(pkgDTO.getLclPiece());
				pkgTotalWholePiece = pkgTotalWholePiece.add(pkgDTO.getWholePiece());
				pkgTotalVolume = pkgTotalVolume.add(pkgDTO.getVolume());
				pkgTotalWeight = pkgTotalWeight.add(pkgDTO.getWeight());
			}
			dto.setPendingReviewPackageDTOs(pendingReviewPackageDTOs);
			dto.setPkgTotalPcs(pkgTotalPcs);
			dto.setPkgTotalLclPiece(pkgTotalLclPiece);
			dto.setPkgTotalWholePiece(pkgTotalWholePiece);
			dto.setPkgTotalVolume(pkgTotalVolume);
			dto.setPkgTotalWeight(pkgTotalWeight);
		}
		return dto;
	}

	/**
	 * 待审核商品包裹信息查询
	 *
	 * @param pendingReviewPackageByDetailVO
	 * @return
	 */
	@SuppressWarnings("resource")
	public Page<PendingReviewPackageDTO> viewDetailPackage(PendingReviewPackageByDetailVO pendingReviewPackageByDetailVO) {

		ToolKits.isParamNull(pendingReviewPackageByDetailVO, "待审核商品包裹信息查询请求不为空");
		ToolKits.isParamNull(pendingReviewPackageByDetailVO.getShipbillId(), "运单ID不为空");
		ToolKits.isParamNull(pendingReviewPackageByDetailVO.getItemId(), "商品ID不为空");
		ToolKits.isParamNull(pendingReviewPackageByDetailVO.getPageNum(), "当前页码不为空");
		ToolKits.isParamNull(pendingReviewPackageByDetailVO.getPageSize(), "每页条数不为空");

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

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

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

		// 设备类型
		RestMessage<List<Map<String, Object>>> restMessage2 = maindataTmsResource.getDropDownById(DataDictionaryConstant.DEVICE_COMPANY, null, null, null);
		if (!restMessage2.isSuccess()) {
			throw new RuntimeException("设备类型翻译失败!");
		} else {
			data2 = restMessage2.getData();
		}
		List<PendingReviewPackageDTO> pendingReviewPackageDTOs = new ArrayList<PendingReviewPackageDTO>();
		// 查询商品对应的包裹ID
		Criteria criteria = Criteria.forClass(TmsShipbillPkgDetailModel.class);
		Restriction r1 = Restrictions.eq("shipbillId", pendingReviewPackageByDetailVO.getShipbillId());
		Restriction r2 = Restrictions.eq("itemId", pendingReviewPackageByDetailVO.getItemId());
		Restriction r3 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2, r3));
		List<TmsShipbillPkgDetailModel> tmsShipbillPkgDetailModels = tmsShipbillPackageDetailMapper.findByCriteria(criteria);

		if (ToolKits.isEmpty(tmsShipbillPkgDetailModels)) {
			Page<PendingReviewPackageDTO> page = PageUtils.getPage(pendingReviewPackageDTOs);
			return page;
		}
		List<String> packageIds = tmsShipbillPkgDetailModels.stream().filter(o -> ToolKits.isNotEmpty(o.getPackageId())).map(TmsShipbillPkgDetailModel::getPackageId).distinct().collect(Collectors.toList());

		PageUtils.startPage(pendingReviewPackageByDetailVO.getPageNum(), pendingReviewPackageByDetailVO.getPageSize());
		List<TmsShipbillPackageModel> tmsShipbillPackageModels = tmsShipbillPackageMapper.findByIds(TmsShipbillPackageModel.class, packageIds.toArray(), null);

		// 响应对象集合
		for (TmsShipbillPackageModel tmsShipbillPackageModel : tmsShipbillPackageModels) {
			// 响应对象
			PendingReviewPackageDTO pendingReviewPackageDTO = new PendingReviewPackageDTO();
			BeanUtils.copyProperties(tmsShipbillPackageModel, pendingReviewPackageDTO);
			pendingReviewPackageDTO.setPackageTypeName(PublicMethods.change(data1, String.valueOf(pendingReviewPackageDTO.getPackageType())));
			pendingReviewPackageDTO.setDeviceCompanyName(PublicMethods.change(data2, String.valueOf(pendingReviewPackageDTO.getDeviceCompany())));
			pendingReviewPackageDTOs.add(pendingReviewPackageDTO);
		}

		// 分页重组
		Page<PendingReviewPackageDTO> page = PageUtils.getPage(pendingReviewPackageDTOs);
		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 pendingReviewDetailByPackageVO
	 * @return
	 */
	@SuppressWarnings("resource")
	public Page<PendingReviewPackageDetailDTO> viewPackageDetail(PendingReviewDetailByPackageVO pendingReviewDetailByPackageVO) {
		ToolKits.isParamNull(pendingReviewDetailByPackageVO, "待审核包裹商品信息查询请求不为空");
		ToolKits.isParamNull(pendingReviewDetailByPackageVO.getShipbillId(), "运单ID不为空");
		ToolKits.isParamNull(pendingReviewDetailByPackageVO.getPackageId(), "包裹ID不为空");

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

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

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

		// 查询商品对应的包裹ID
		Criteria criteria = Criteria.forClass(TmsShipbillPkgDetailModel.class);
		Restriction r1 = Restrictions.eq("shipbillId", pendingReviewDetailByPackageVO.getShipbillId());
		Restriction r2 = Restrictions.eq("packageId", pendingReviewDetailByPackageVO.getPackageId());
		Restriction r3 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2, r3));
		List<PendingReviewPackageDetailDTO> pendingReviewPackageDetailDTOs = Lists.newArrayList();

		PageUtils.startPage(pendingReviewDetailByPackageVO.getPageNum(), pendingReviewDetailByPackageVO.getPageSize());
		List<TmsShipbillPkgDetailModel> tmsShipbillPkgDetailModels = tmsShipbillPackageDetailMapper.findByCriteria(criteria);

		// 响应对象集合
		if (ToolKits.isNotEmpty(tmsShipbillPkgDetailModels)) {
			for (TmsShipbillPkgDetailModel tmsShipbillPkgDetailModel : tmsShipbillPkgDetailModels) {
				PendingReviewPackageDetailDTO pkgDetailDTO = new PendingReviewPackageDetailDTO();
				BeanUtils.copyProperties(tmsShipbillPkgDetailModel, pkgDetailDTO);

				pkgDetailDTO.setPackTypeName(PublicMethods.change(data1, String.valueOf(pkgDetailDTO.getPackType())));
				pkgDetailDTO.setCargoThermosphereName(PublicMethods.change(data2, String.valueOf(pkgDetailDTO.getCargoThermosphere())));
				pendingReviewPackageDetailDTOs.add(pkgDetailDTO);
			}
		}
		// 分页重组
		Page<PendingReviewPackageDetailDTO> page = PageUtils.getPage(pendingReviewPackageDetailDTOs);
		if (tmsShipbillPkgDetailModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsShipbillPkgDetailModel> p0 = (com.github.pagehelper.Page<TmsShipbillPkgDetailModel>) tmsShipbillPkgDetailModels;
			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 shipbillId
	 * @return
	 */
	public List<TmsShipbillHeaderModel> autoSplit(String shipbillId, Date date, UserEntity user) {
		// 返回数据
		List<TmsShipbillHeaderModel> smartSplitDTOS = Lists.newArrayList();

		// 获取商品集合
		Criteria criteriaDetail = Criteria.forClass(TmsShipbillDetailModel.class);
		Restriction r1 = Restrictions.eq(TmsShipbillDetailModel::getShipbillId, shipbillId);
		criteriaDetail.setRestriction(r1);
		List<TmsShipbillDetailModel> tmsShipbillDetailModels = tmsShipbillDetailMapper.findByCriteria(criteriaDetail);
		// 运单没有商品
		if (ToolKits.isEmpty(tmsShipbillDetailModels)) {
			return smartSplitDTOS;
		}
		// 查询对应运单
		TmsShipbillHeaderModel tmsShipbillHeaderModel = tmsShipbillHeaderMapper.findById(shipbillId, TmsShipbillHeaderModel.class);

		// 获取拆分策略
		StrategySplitMatchingVO strategySplitMatchingVO = new StrategySplitMatchingVO();
		BeanUtils.copyProperties(tmsShipbillHeaderModel, strategySplitMatchingVO);
		RestMessage<List<StrategySplitMatchingDTO>> restMessage = maindataTmsResource.matchingExecute(strategySplitMatchingVO);
		if (!restMessage.isSuccess()) {
			return smartSplitDTOS;
		}

		// 策略集合
		List<StrategySplitMatchingDTO> strategySplitMatchingDTOS = restMessage.getData();

		// 如果为空跳过
		if (ToolKits.isEmpty(strategySplitMatchingDTOS) || strategySplitMatchingDTOS.size() > 1) {
			return smartSplitDTOS;
		}
		StrategySplitMatchingDTO strategyDTO = strategySplitMatchingDTOS.get(0);

		// 拆分完的明细集合
		Map<Object, List<TmsShipbillDetailModel>> map = Maps.newHashMap();
		// 拆分的不足单子
		List<TmsShipbillDetailModel> modelSplitIns = Lists.newArrayList();
		// 库存足的单子
		List<TmsShipbillDetailModel> modelNotIns = Lists.newArrayList();
		// 获取库存不足单子
		List<TmsShipbillDetailModel> modelIns = Lists.newArrayList();

		switch (strategyDTO.getRuleCode().intValue()) {
		case 1: // 按商品品类拆分
			try {
				map = tmsShipbillDetailModels.stream().collect(Collectors.groupingBy(TmsShipbillDetailModel::getItemCategoryId));
				if (map.size() == 1) {
					map.clear();
				}
			} catch (Exception e) {
			}
			break;
		case 2:// 按包装类型拆分
			try {
				map = tmsShipbillDetailModels.stream().collect(Collectors.groupingBy(TmsShipbillDetailModel::getPackType));
				if (map.size() == 1) {
					map.clear();
				}
			} catch (Exception e) {
			}
			break;
		case 3:// 按货物温层拆分
			try {
				map = tmsShipbillDetailModels.stream().collect(Collectors.groupingBy(TmsShipbillDetailModel::getCargoThermosphere));
				if (map.size() == 1) {
					map.clear();
				}
			} catch (Exception e) {
			}
			break;
		case 4:// 按数量、库存数量拆分
				// 获取库存不足单子
			try {
				modelIns = tmsShipbillDetailModels.stream().filter(o -> (o.getPcs().intValue() > o.getInventoryPcs().intValue() && ToolKits.isNotEmpty(o.getInventoryPcs()) && o.getInventoryPcs().intValue() > 0)).collect(Collectors.toList());
			} catch (Exception e) {
			}
			// 没有库存不足的就不拆分
			if (ToolKits.isEmpty(modelIns)) {
				break;
			}
			// 获取库存足的单子
			modelNotIns = tmsShipbillDetailModels.stream().filter(o -> o.getPcs().intValue() < o.getInventoryPcs().intValue()).collect(Collectors.toList());
			for (TmsShipbillDetailModel model : modelIns) {
				TmsShipbillDetailModel model1 = new TmsShipbillDetailModel();
				TmsShipbillDetailModel model2 = new TmsShipbillDetailModel();
				BeanUtils.copyProperties(model, model1);
				BeanUtils.copyProperties(model, model2);
				model1.setPcs(new BigDecimal(model.getInventoryPcs()));
				model2.setPcs(model.getPcs().subtract(new BigDecimal(model.getInventoryPcs())));
				model2.setInventoryPcs(0);

				// 计算商品的体积，重量
				ItemCheckVO itemCheckVO = new ItemCheckVO();
				itemCheckVO.setItemId(model.getItemId());
				RestMessage<ItemCheckDTO> itemRestMessage = maindataTmsResource.getItem(itemCheckVO);

				if (!itemRestMessage.isSuccess()) {
					throw new PrologException("获取商品服务失败:" + itemRestMessage.getMessage());
				}
				if (ToolKits.isEmpty(itemRestMessage.getData())) {
					throw new PrologException("未找到对应商品【" + model.getItemName() + "】");
				}
				ItemCheckDTO itemCheckDTO = itemRestMessage.getData();

				if (ToolKits.isNotEmpty(itemCheckDTO.getWeight())) {
					model1.setWeight(itemCheckDTO.getWeight().multiply(model1.getPcs()));
					model2.setWeight(itemCheckDTO.getWeight().multiply(model2.getPcs()));
				}
				if (ToolKits.isNotEmpty(itemCheckDTO.getVolume())) {
					model1.setVolume(itemCheckDTO.getVolume().multiply(model1.getPcs()));
					model2.setVolume(itemCheckDTO.getVolume().multiply(model2.getPcs()));
				}
				modelNotIns.add(model1);
				modelSplitIns.add(model2);
			}
			// 封装到map集合
			// 库存足
			map.put("modelSplitIns", modelNotIns);
			// 库存不足
			map.put("modelSplitInsNo", modelSplitIns);
			break;
		case 5:// 按默认存放仓库、数量、库存数量拆分
			Map<Long, List<TmsShipbillDetailModel>> collect = Maps.newHashMap();
			try {
				collect = tmsShipbillDetailModels.stream().collect(Collectors.groupingBy(TmsShipbillDetailModel::getBranchId));
			} catch (Exception e) {
				break;
			}
			for (Long l : collect.keySet()) {
				List<TmsShipbillDetailModel> list = collect.get(l);
				// 获取库存不足单子
				List<TmsShipbillDetailModel> modelInsList = list.stream().filter(o -> (o.getPcs().intValue() > o.getInventoryPcs().intValue() && ToolKits.isNotEmpty(o.getInventoryPcs()) && o.getInventoryPcs().intValue() > 0)).collect(Collectors.toList());
				// 库存足,有分组的也拆分
				if (ToolKits.isEmpty(modelInsList)) {
					if (collect.size() > 1) {
						map.put(l + "-Ins-U-Flow", list);
					}

					continue;
				}
				// 获取库存足的单子
				List<TmsShipbillDetailModel> modelNotInsList = list.stream().filter(o -> o.getPcs().intValue() < o.getInventoryPcs().intValue()).collect(Collectors.toList());

				// 拆分的不足单子
				List<TmsShipbillDetailModel> modelSplitInsList = Lists.newArrayList();
				for (TmsShipbillDetailModel model : modelInsList) {

					TmsShipbillDetailModel model1 = new TmsShipbillDetailModel();
					TmsShipbillDetailModel model2 = new TmsShipbillDetailModel();
					BeanUtils.copyProperties(model, model1);
					BeanUtils.copyProperties(model, model2);
					model1.setPcs(new BigDecimal(model.getInventoryPcs()));
					model2.setPcs(model.getPcs().subtract(new BigDecimal(model.getInventoryPcs())));
					model2.setInventoryPcs(0);

					// 计算商品的体积，重量
					ItemCheckVO itemCheckVO = new ItemCheckVO();
					itemCheckVO.setItemId(model.getItemId());
					RestMessage<ItemCheckDTO> itemRestMessage = maindataTmsResource.getItem(itemCheckVO);

					if (!itemRestMessage.isSuccess()) {
						throw new PrologException("获取商品服务失败");
					}
					if (ToolKits.isEmpty(itemRestMessage.getData())) {
						throw new PrologException("未找到对应商品[商品:" + model.getItemName() + "]");
					}
					ItemCheckDTO itemCheckDTO = itemRestMessage.getData();

					if (ToolKits.isNotEmpty(itemCheckDTO.getWeight())) {
						model1.setWeight(itemCheckDTO.getWeight().multiply(model1.getPcs()));
						model2.setWeight(itemCheckDTO.getWeight().multiply(model2.getPcs()));
					}
					if (ToolKits.isNotEmpty(itemCheckDTO.getVolume())) {
						model1.setVolume(itemCheckDTO.getVolume().multiply(model1.getPcs()));
						model2.setVolume(itemCheckDTO.getVolume().multiply(model2.getPcs()));
					}
					modelNotInsList.add(model1);
					modelSplitInsList.add(model2);
				}
				// 封装到map集合
				// 库存足的运单
				map.put(l + "-SplitIns-U-Flow", modelNotInsList);
				// 库存不足的运单
				map.put(l + "-SplitInsNo-U-Flow", modelSplitInsList);
			}
			break;
		case 6:// 按默认存放仓库拆分
			Map<Long, List<TmsShipbillDetailModel>> collect6 = Maps.newHashMap();
			try {
				collect6 = tmsShipbillDetailModels.stream().collect(Collectors.groupingBy(TmsShipbillDetailModel::getBranchId));
			} catch (Exception e) {
				break;
			}
			if (collect6.size() > 1) {
				for (Long l : collect6.keySet()) {
					List<TmsShipbillDetailModel> list6 = collect6.get(l);
					map.put(l + "-Ins-U-Flow", list6);
				}
			}
			break;
		case 7:// 按运单明细关键字拆分
			String splitKey = strategyDTO.getShipbillDetailSplitKey();
			if (ToolKits.isNotEmpty(splitKey)) {
				List<String> keyList = Arrays.stream(splitKey.split(",")).distinct().collect(Collectors.toList());
				List<TmsShipbillDetailModel> noMatchShipbillDetails = tmsShipbillDetailModels.stream().filter(t -> ToolKits.isEmpty(t.getMemo())).collect(Collectors.toList());

				List<TmsShipbillDetailModel> matchShipbillDetails = Lists.newArrayList();

				tmsShipbillDetailModels = tmsShipbillDetailModels.stream().filter(t -> ToolKits.isNotEmpty(t.getMemo())).collect(Collectors.toList());

				Map<String, List<TmsShipbillDetailModel>> collect7 = Maps.newHashMap();
				if (ToolKits.isNotEmpty(tmsShipbillDetailModels)) {
					for (TmsShipbillDetailModel detailModel : tmsShipbillDetailModels) {
						boolean match = false;
						for (String key : keyList) {
							if (detailModel.getMemo().contains(key)) {
								detailModel.setUpdateperson(key);
								matchShipbillDetails.add(detailModel);
								match = true;
								break;
							}
						}
						if (!match) {
							noMatchShipbillDetails.add(detailModel);
						}
					}
					collect7 = matchShipbillDetails.stream().collect(Collectors.groupingBy(TmsShipbillDetailModel::getUpdateperson));
				}
				if (ToolKits.isNotEmpty(noMatchShipbillDetails)) {
					if (collect7.size() > 0) {
						for (String l : collect7.keySet()) {
							List<TmsShipbillDetailModel> list7 = collect7.get(l);
							map.put(l + "-key-split", list7);
						}
						map.put("no" + "-key-split", noMatchShipbillDetails);
					}
				} else {
					if (collect7.size() > 1) {
						for (String l : collect7.keySet()) {
							List<TmsShipbillDetailModel> list7 = collect7.get(l);
							map.put(l + "-key-split", list7);
						}
					}
				}
			}
			break;
		}
		if (ToolKits.isEmpty(map)) {
			return smartSplitDTOS;
		}
		int index = 1;
		RestMessage<SysParamConfigModel> restMessageShipbillId = maindataTmsResource.getValue(DataDictionaryConstant.SHIPBILL_ID_CREATE_RULE);
		if (!restMessageShipbillId.isSuccess()) {
			throw new RuntimeException("获取运单ID生成规则的系统参数失败!");
		}
		SysParamConfigModel sysParamConfigModel = restMessageShipbillId.getData();
		for (Object obj : map.keySet()) {
			List<TmsShipbillDetailModel> list = map.get(obj);
			if (ToolKits.isEmpty(list)) {
				continue;
			}
			String subShipbillId = "";
			if (DataDictionaryConstant.SHIPBILL_ID_CREATE_RULE_AUTO.equals(sysParamConfigModel.getValue())) {
				// 获取运单汇总ID
				RestMessage<String> restMessageAutoCreateShipbillId = maindataTmsResource.getCodeNumberByCode(SeriaNnumberConstant.TMS_SHIPBILL_HEADER_ID, "L");
				if (!restMessageAutoCreateShipbillId.isSuccess()) {
					throw new RuntimeException("生成运单汇总ID失败");
				}
				subShipbillId = restMessageAutoCreateShipbillId.getData();
			} else {
				StringBuffer buffNo1 = new StringBuffer(tmsShipbillHeaderModel.getShipbillId());
				buffNo1.append(DataDictionaryConstant.SUB_SHIPBILL_NO);
				buffNo1.append(DataDictionaryConstant.SPLIT_SHIPBILL_NO);
				buffNo1.append(index);
				subShipbillId = buffNo1.toString();
				index++;
			}

			// 商品总件数
			BigDecimal goodsTotalPcs = new BigDecimal(0);
			// 商品总体积
			BigDecimal goodsTotalVolume = new BigDecimal(0);
			// 商品总重量
			BigDecimal goodsTotalWeight = new BigDecimal(0);

			BigDecimal zero = new BigDecimal(0);

			// 保存拆分子单的运单汇总
			TmsShipbillHeaderModel subTmsShipbillHeaderModel = new TmsShipbillHeaderModel();
			BeanUtils.copyProperties(tmsShipbillHeaderModel, subTmsShipbillHeaderModel);
			Long branchId = list.get(0).getBranchId();
			if (obj.toString().contains("U-Flow")) {
				// 取新仓库信息
				RestMessage<TmsBaseBranchDTO> restMessageBranch = maindataTmsResource.viewBranch(branchId);
				if (restMessageBranch.isSuccess()) {
					TmsBaseBranchDTO tmsBaseBranchDTO = restMessageBranch.getData();
					// 重新设定发货方数据
					// 发货方类型
					subTmsShipbillHeaderModel.setShipperType(DataDictionaryConstant.SHIPPER_TYPE_CK);
					// 发货方单位ID
					subTmsShipbillHeaderModel.setShipperUnitId(tmsBaseBranchDTO.getId());
					subTmsShipbillHeaderModel.setShipperUnitCode(tmsBaseBranchDTO.getCode());
					subTmsShipbillHeaderModel.setShipperUnitName(tmsBaseBranchDTO.getName());
					// 发货方ID
					subTmsShipbillHeaderModel.setShipperId(tmsBaseBranchDTO.getId());
					subTmsShipbillHeaderModel.setShipperCode(tmsBaseBranchDTO.getCode());
					subTmsShipbillHeaderModel.setShipperName(tmsBaseBranchDTO.getName());

					// 发货方联系人
					subTmsShipbillHeaderModel.setShipperContact(tmsBaseBranchDTO.getContact());
					// 发货方手机号
					subTmsShipbillHeaderModel.setShipperPhoneNumber(tmsBaseBranchDTO.getPhoneNumber());
					// 发货方座机号
					subTmsShipbillHeaderModel.setShipperLandlineNumber(tmsBaseBranchDTO.getLandlineNumber());

					subTmsShipbillHeaderModel.setShipperEmail(tmsBaseBranchDTO.getEmail());

					subTmsShipbillHeaderModel.setShipperRelatedPhoneNumber(tmsBaseBranchDTO.getPhoneNumber());
					// 发货方省编码
					subTmsShipbillHeaderModel.setShipperProvince(tmsBaseBranchDTO.getProvince());
					// 发货方省名称
					subTmsShipbillHeaderModel.setShipperProvinceName(tmsBaseBranchDTO.getProvinceName());
					// 发货方市编码
					subTmsShipbillHeaderModel.setShipperCity(tmsBaseBranchDTO.getCity());
					subTmsShipbillHeaderModel.setShipperCityName(tmsBaseBranchDTO.getCityName());
					// 发货方区/县编码
					subTmsShipbillHeaderModel.setShipperDistrict(tmsBaseBranchDTO.getDistrict());
					subTmsShipbillHeaderModel.setShipperDistrictName(tmsBaseBranchDTO.getDistrictName());

					// 发货方详细地址
					subTmsShipbillHeaderModel.setShipperAddress(tmsBaseBranchDTO.getAddress());

					// 发货方经度
					subTmsShipbillHeaderModel.setShipperLongitude(tmsBaseBranchDTO.getLongitude());
					// 发货方纬度
					subTmsShipbillHeaderModel.setShipperLatitude(tmsBaseBranchDTO.getLatitude());
					subTmsShipbillHeaderModel.setShipperMemo(tmsBaseBranchDTO.getMemo());

					// 重新适配新业务流程,取流程失败时，此运单不做拆分
					ShipbillFitBusinessFlowDTO flowData = shipbillMatchBusinessFlow(subTmsShipbillHeaderModel, 2);
					if (ToolKits.isEmpty(flowData) || ToolKits.isEmpty(flowData.getFlowConfig())) {
						return smartSplitDTOS;
					}
					subTmsShipbillHeaderModel.setFlowConfig(flowData.getFlowConfig());
				}
				if (ToolKits.isNotEmpty(strategyDTO.getRematchLine()) && strategyDTO.getRematchLine().equals(DataDictionaryConstant.REMATCH_LINE_YES)) {
					// 子单重新匹配线路
					ShipbillMatchLineDTO lineData = shipbillMatchLine(subTmsShipbillHeaderModel);
					if (ToolKits.isNotEmpty(lineData) && ToolKits.isNotEmpty(lineData.getLineId())) {
						// 订单绑定线路
						subTmsShipbillHeaderModel.setLineId(lineData.getLineId());
						subTmsShipbillHeaderModel.setLineCode(lineData.getLineCode());
						subTmsShipbillHeaderModel.setLineName(lineData.getLineName());
						subTmsShipbillHeaderModel.setLineDirection(lineData.getLineDirection());

						subTmsShipbillHeaderModel.setShippingOrder(lineData.getShippingOrder());
						subTmsShipbillHeaderModel.setPickUpOrder(lineData.getPickUpOrder());
					}
				}
			}

			// 保存每个子单中的明细信息
			int idx = 1;
			for (TmsShipbillDetailModel detailModel : list) {
				TmsShipbillDetailModel subTmsShipbillDetailModel = new TmsShipbillDetailModel();
				// 运单明细ID
				RestMessage<String> restMessage2 = maindataTmsResource.getCodeNumberByCode(SeriaNnumberConstant.TMS_SHIPBILL_DETAIL_ID, "L");
				if (!restMessage2.isSuccess()) {
					throw new RuntimeException("生成运单明细ID失败");
				}
				String subShipbillDetailId = restMessage2.getData();

				// 取商品资料
				// STD-DEVELOP20220823 lhb 计算件重体 20220913 start
				ItemCheckVO itemCheckVO = new ItemCheckVO();
				itemCheckVO.setItemId(detailModel.getItemId());
				RestMessage<ItemCheckDTO> restMessage3 = maindataTmsResource.getItem(itemCheckVO);
				if (!restMessage3.isSuccess()) {
					throw new RuntimeException("取商品资料信息失败:" + restMessage3.getMessage());
				}
				ItemCheckDTO rsItemInfo = restMessage3.getData();
				// STD-DEVELOP20220823 lhb 计算件重体 20220913 end

				BeanUtils.copyProperties(detailModel, subTmsShipbillDetailModel);
				// ID
				subTmsShipbillDetailModel.setId(subShipbillDetailId);
				subTmsShipbillDetailModel.setSeqno(idx);
				idx++;
				subTmsShipbillDetailModel.setOriginalSeqno(subTmsShipbillDetailModel.getSeqno());
				// 运单ID
				subTmsShipbillDetailModel.setShipbillId(subShipbillId);
				// 运单编号
				subTmsShipbillDetailModel.setShipbillNo(subShipbillId);

				subTmsShipbillDetailModel.setEnterpriseId(user.getEnterpriseId());
				subTmsShipbillDetailModel.setEnterpriseName(user.getEnterpriseName());

				subTmsShipbillDetailModel.setCreateperson(user.getNickname());
				subTmsShipbillDetailModel.setCreatetime(date);
				subTmsShipbillDetailModel.setUpdateperson(user.getNickname());
				subTmsShipbillDetailModel.setUpdatetime(date);
				// STD-DEVELOP20220823 lhb 计算件重体 20220913 start
				subTmsShipbillDetailModel.setWeight(detailModel.getPcs().multiply(rsItemInfo.getWeight()));
				subTmsShipbillDetailModel.setVolume(detailModel.getPcs().multiply(rsItemInfo.getVolume()));
				// STD-DEVELOP20220823 lhb 计算件重体 20220913 end

				subTmsShipbillDetailModel.setUnitVolume(rsItemInfo.getVolume());
				subTmsShipbillDetailModel.setUnitWeight(rsItemInfo.getWeight());

				subTmsShipbillDetailModel.setOrigPcs(subTmsShipbillDetailModel.getPcs());
				subTmsShipbillDetailModel.setClosingPcs(BigDecimal.valueOf(0));
				subTmsShipbillDetailModel.setDeliveryPcs(BigDecimal.valueOf(0));
				subTmsShipbillDetailModel.setFatherId(detailModel.getId());
				subTmsShipbillDetailModel.setScanStatus(DataDictionaryConstant.SCAN_STATUS_INIT);
				tmsShipbillDetailMapper.save(subTmsShipbillDetailModel);

				// STD-DEVELOP20220823 lhb 计算件重体 20220913 start
				if (ToolKits.isNotEmpty(subTmsShipbillDetailModel.getPcs())) {
					goodsTotalPcs = goodsTotalPcs.add(subTmsShipbillDetailModel.getPcs());
				}
				if (ToolKits.isNotEmpty(subTmsShipbillDetailModel.getVolume())) {
					goodsTotalVolume = goodsTotalVolume.add(subTmsShipbillDetailModel.getVolume());
				}
				if (ToolKits.isNotEmpty(subTmsShipbillDetailModel.getWeight())) {
					goodsTotalWeight = goodsTotalWeight.add(subTmsShipbillDetailModel.getWeight());
				}
				// STD-DEVELOP20220823 lhb 计算件重体 20220913 end
			}

			subTmsShipbillHeaderModel.setShipbillId(subShipbillId);
			subTmsShipbillHeaderModel.setShipbillNo(subShipbillId);
			// 运单状态
			//subTmsShipbillHeaderModel.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_REVIEW);

			if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
				int status = businessFlowUtil.judgmentNextFlowSts(tmsShipbillHeaderModel.getFlowConfig(),DataDictionaryConstant.FLOW_CONFIG_REVIEW);
				tmsShipbillHeaderModel.setStatus(status);

				// 拆单状态 0未拆单
				subTmsShipbillHeaderModel.setSplitOrderStatus(DataDictionaryConstant.SPLIT_ORDER_STATUS_UN);
				// 拆单类型 3拆分子单
				subTmsShipbillHeaderModel.setSplitOrderType(DataDictionaryConstant.SPLIT_ORDER_TYPE_SPLIT_SUB);

				// 拆单状态 0未拆单
				subTmsShipbillHeaderModel.setCarrierSplitOrderStatus(DataDictionaryConstant.CARRIER_SPLIT_ORDER_STATUS_UN);
				// 拆单类型 3拆分子单
				subTmsShipbillHeaderModel.setCarrierSplitOrderType(DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_UN);
			} else {
				// 拆单状态 0未拆单
				subTmsShipbillHeaderModel.setCarrierSplitOrderStatus(DataDictionaryConstant.CARRIER_SPLIT_ORDER_STATUS_UN);
				// 拆单类型 3拆分子单
				subTmsShipbillHeaderModel.setCarrierSplitOrderType(DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_SPLIT_SUB);

				subTmsShipbillHeaderModel.setSplitOrderStatus(DataDictionaryConstant.SPLIT_ORDER_STATUS_UN);
				// 拆单类型 3拆分子单
				subTmsShipbillHeaderModel.setSplitOrderType(DataDictionaryConstant.SPLIT_ORDER_TYPE_UN);
			}
			// 父级运单ID
			subTmsShipbillHeaderModel.setFatherShipbillId(tmsShipbillHeaderModel.getShipbillId());
			// 父级运单编号
			subTmsShipbillHeaderModel.setFatherShipbillNo(tmsShipbillHeaderModel.getShipbillNo());
			// 原始运单ID
			String originalShipbillId = tmsShipbillHeaderModel.getOriginalShipbillId() == null ? tmsShipbillHeaderModel.getShipbillId() : tmsShipbillHeaderModel.getOriginalShipbillId();
			subTmsShipbillHeaderModel.setOriginalShipbillId(originalShipbillId);
			// 原始运单编号
			String originalShipbillNo = tmsShipbillHeaderModel.getOriginalShipbillNo() == null ? tmsShipbillHeaderModel.getShipbillNo() : tmsShipbillHeaderModel.getOriginalShipbillNo();
			subTmsShipbillHeaderModel.setOriginalShipbillNo(originalShipbillNo);
			// 总件数
			subTmsShipbillHeaderModel.setTotalPcs(goodsTotalPcs);
			// 总体积
			subTmsShipbillHeaderModel.setTotalVolume(goodsTotalVolume);
			// 总重量
			subTmsShipbillHeaderModel.setTotalWeight(goodsTotalWeight);
			// 实际总件数
			subTmsShipbillHeaderModel.setActualTotalPcs(goodsTotalPcs);
			// 实际总体积
			subTmsShipbillHeaderModel.setActualTotalVolume(goodsTotalVolume);
			// 实际总重量
			subTmsShipbillHeaderModel.setActualTotalWeight(goodsTotalWeight);
			// 包裹整件数
			subTmsShipbillHeaderModel.setPackageWholePiece(zero);
			// 包裹拼箱数
			subTmsShipbillHeaderModel.setPackageLclPiece(zero);
			// 包裹总体积
			subTmsShipbillHeaderModel.setPackageTotalVolume(zero);
			// 包裹总重量
			subTmsShipbillHeaderModel.setPackageTotalWeight(zero);

			subTmsShipbillHeaderModel.setCreateperson(user.getNickname());
			subTmsShipbillHeaderModel.setCreatetime(date);
			subTmsShipbillHeaderModel.setUpdateperson(user.getNickname());
			subTmsShipbillHeaderModel.setUpdatetime(date);
			subTmsShipbillHeaderModel.setShipbillType(ShipBillTypeEnum.NORMAL.getCode());
			subTmsShipbillHeaderModel.setSignInStatus(SignInStatusEnum.NOT_SIGN.getCode());
			subTmsShipbillHeaderModel.setDriverReceiveStatus(DriverReceiveStatusEnum.N.getCode());
			subTmsShipbillHeaderModel.setIntelligentLock(IntelligentLockEnum.UN_LOCK.getCode());
			tmsShipbillHeaderMapper.save(subTmsShipbillHeaderModel);

			// 初期化订单运输记录表
			saveTransportLog(subTmsShipbillHeaderModel.getShipbillId(), date, subTmsShipbillHeaderModel.getEstimatedPickupStartTime());

			// 子运单日志保存
			ShipbillOperateLogSaveNewVO subShipbillOperateLogSaveVO = new ShipbillOperateLogSaveNewVO();
			subShipbillOperateLogSaveVO.setShipbillId(subTmsShipbillHeaderModel.getShipbillId());
			subShipbillOperateLogSaveVO.setShipbillNo(subTmsShipbillHeaderModel.getShipbillNo());
			subShipbillOperateLogSaveVO.setOperateDate(date);
			subShipbillOperateLogSaveVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_EVENT_NAME_SPLIT_SUB);
			subShipbillOperateLogSaveVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_YTJ);
			subShipbillOperateLogSaveVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_REVIEW);

			subShipbillOperateLogSaveVO.setUserId(user.getUserid());
			subShipbillOperateLogSaveVO.setUserName(user.getNickname());
			subShipbillOperateLogSaveVO.setEnterpriseId(user.getEnterpriseId());
			subShipbillOperateLogSaveVO.setEnterpriseName(user.getEnterpriseName());
			shipbillOperateLogService.addShipbillOperateLogNewData(subShipbillOperateLogSaveVO);

			// 运单节点保存
			ShipbillNodeTrackingSaveNewVO shipbillNodeTrackingSaveVO = new ShipbillNodeTrackingSaveNewVO();
			shipbillNodeTrackingSaveVO.setShipbillId(subShipbillId);
			shipbillNodeTrackingSaveVO.setNodeDate(date);
			shipbillNodeTrackingSaveVO.setShipbillNo(subShipbillId);
			shipbillNodeTrackingSaveVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_REVIEW);
			shipbillNodeTrackingSaveVO.setNodeEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_REW);

			shipbillNodeTrackingSaveVO.setUserId(user.getUserid());
			shipbillNodeTrackingSaveVO.setUserName(user.getNickname());
			shipbillNodeTrackingSaveVO.setEnterpriseId(user.getEnterpriseId());
			shipbillNodeTrackingSaveVO.setEnterpriseName(user.getEnterpriseName());
			shipbillNodeTrackingService.addShipbillNodeTrackingNewData(shipbillNodeTrackingSaveVO);

			smartSplitDTOS.add(subTmsShipbillHeaderModel);
		}
		// 修改主单
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			tmsShipbillHeaderModel.setSplitOrderStatus(DataDictionaryConstant.SPLIT_ORDER_STATUS_ED);
			// 原始主单被拆分时，拆单类型更新为2拆分主单，子单被拆分时，不更新拆单类型
			if (ToolKits.isEmpty(tmsShipbillHeaderModel.getSplitOrderType()) || DataDictionaryConstant.SPLIT_ORDER_TYPE_UN.equals(tmsShipbillHeaderModel.getSplitOrderType())) {
				tmsShipbillHeaderModel.setSplitOrderType(DataDictionaryConstant.SPLIT_ORDER_TYPE_SPLIT_MASTER);
			}
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
			tmsShipbillHeaderModel.setCarrierSplitOrderStatus(DataDictionaryConstant.CARRIER_SPLIT_ORDER_STATUS_ED);
			// 原始主单被拆分时，拆单类型更新为2拆分主单，子单被拆分时，不更新拆单类型
			if (ToolKits.isEmpty(tmsShipbillHeaderModel.getCarrierSplitOrderType()) || DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_UN.equals(tmsShipbillHeaderModel.getCarrierSplitOrderType())) {
				tmsShipbillHeaderModel.setCarrierSplitOrderType(DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_SPLIT_MASTER);
			}

			// STD-DEVELOP20220823 lhb 承运商拆分完善 20220916 start
			// 更新装车单明细
			Map<String, Object> mapLoadingDetailUpdate = Maps.newHashMap();
			mapLoadingDetailUpdate.put("updateperson", user.getNickname());
			mapLoadingDetailUpdate.put("updatetime", date);
			mapLoadingDetailUpdate.put("carrierSplitOrderStatus", DataDictionaryConstant.CARRIER_SPLIT_ORDER_STATUS_ED);
			if (ToolKits.isEmpty(tmsShipbillHeaderModel.getCarrierSplitOrderType()) || DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_UN.equals(tmsShipbillHeaderModel.getCarrierSplitOrderType())) {
				mapLoadingDetailUpdate.put("carrierSplitOrderType", DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_SPLIT_MASTER);
			}
			Criteria criteriaLoadingDetail = Criteria.forClass(TmsLoadingBillDetailModel.class);
			Restriction r21 = Restrictions.eq(TmsLoadingBillDetailModel::getCarrierShipbillStatus, DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_AUDITED);
			Restriction r22 = Restrictions.eq(TmsLoadingBillDetailModel::getShipbillId, tmsShipbillHeaderModel.getShipbillId());
			criteriaLoadingDetail.setRestriction(Restrictions.and(r21, r22));
			tmsLoadingBillDetailMapper.updateMapByCriteria(mapLoadingDetailUpdate, criteriaLoadingDetail);
			// STD-DEVELOP20220823 lhb 承运商拆分完善 20220916 end
		}
		tmsShipbillHeaderModel.setUpdateperson(user.getNickname());
		tmsShipbillHeaderModel.setUpdatetime(date);
		tmsShipbillHeaderMapper.update(tmsShipbillHeaderModel);

		// 原运单日志保存
		ShipbillOperateLogSaveNewVO shipbillOperateLogSaveVO = new ShipbillOperateLogSaveNewVO();
		shipbillOperateLogSaveVO.setOperateDate(date);
		shipbillOperateLogSaveVO.setShipbillId(tmsShipbillHeaderModel.getShipbillId());
		shipbillOperateLogSaveVO.setShipbillNo(tmsShipbillHeaderModel.getShipbillNo());
		shipbillOperateLogSaveVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_EVENT_NAME_SPLIT);
		shipbillOperateLogSaveVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_YTJ);
		shipbillOperateLogSaveVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_REVIEW);

		shipbillOperateLogSaveVO.setUserId(user.getUserid());
		shipbillOperateLogSaveVO.setUserName(user.getNickname());
		shipbillOperateLogSaveVO.setEnterpriseId(user.getEnterpriseId());
		shipbillOperateLogSaveVO.setEnterpriseName(user.getEnterpriseName());
		shipbillOperateLogService.addShipbillOperateLogNewData(shipbillOperateLogSaveVO);

		List<String> shipbillIds = Lists.newArrayList();
		shipbillIds.add(shipbillId);
		pendingDispatchService.updatePlanBill(shipbillIds,user);

		return smartSplitDTOS;
	}

	/**
	 * 生成运输记录表
	 */
	public void saveTransportLog(String shipbillId, Date date, Date pickUpStartDt) {
		TmsShipbillTransLogModel logModel = new TmsShipbillTransLogModel();
		RestMessage<String> restMessage = maindataTmsResource.getCodeNumberByCode(SeriaNnumberConstant.TMS_SHIPBILL_TRANSPORT_LOG_ID, "L");
		if (!restMessage.isSuccess()) {
			throw new RuntimeException("生成运输记录ID失败");
		}
		String id = restMessage.getData();
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		logModel.setId(id);
		logModel.setShipbillId(shipbillId);
		logModel.setShipbillNo(shipbillId);

		logModel.setOrderDt(date);
		logModel.setCommitDt(date);
		logModel.setReviewDt(date);

		logModel.setEstimatedPickupStartTime(pickUpStartDt);
		logModel.setEnterpriseId(user.getEnterpriseId());
		logModel.setEnterpriseName(user.getEnterpriseName());
		logModel.setCreateperson(user.getNickname());
		logModel.setCreatetime(date);
		logModel.setUpdateperson(user.getNickname());
		logModel.setUpdatetime(date);

		tmsShipbillTransportLogMapper.save(logModel);
	}

	/**
	 * 运单匹配业务流程
	 *
	 * @param model
	 * @return
	 */
	public ShipbillFitBusinessFlowDTO shipbillMatchBusinessFlow(TmsShipbillHeaderModel model, Integer flowType) {
		// 新增后自动提交判定
		BusinessFlowShipbillVO matchFlowVO = new BusinessFlowShipbillVO();
		// 流程类型
		matchFlowVO.setFlowType(flowType);
		// 配送方式
		matchFlowVO.setDeliveryMethodType(model.getDeliveryMethodType());
		// 发货方类型
		matchFlowVO.setShipperType(model.getShipperType());
		// 发货方单位ID
		matchFlowVO.setShipperUnitId(model.getShipperUnitId());
		// 收货方类型
		matchFlowVO.setConsigneeType(model.getConsigneeType());
		// 收货方单位ID
		matchFlowVO.setConsigneeUnitId(model.getConsigneeUnitId());
		// 订单类型
		matchFlowVO.setOrderType(model.getOrderType());
		// 订单业务类型
		matchFlowVO.setOrderBusinessType(model.getOrderBusinessType());
		// 运输模式
		matchFlowVO.setTransportType(model.getTransportType());
		// 温度要求
		matchFlowVO.setTemperatureRequirement(model.getTemperatureRequirement());
		// 货主ID
		matchFlowVO.setCargoOwnerId(model.getCargoOwnerId());
		matchFlowVO.setCarriersType(model.getCarriersType());
		RestMessage<ShipbillFitBusinessFlowDTO> matchRs = maindataTmsResource.shipbillMatchFlowQuery(matchFlowVO);
		if (!matchRs.isSuccess()) {
			return null;
		}
		return matchRs.getData();
	}

	/**
	 * 运单匹配线路
	 *
	 * @param model
	 * @return
	 */
	public ShipbillMatchLineDTO shipbillMatchLine(TmsShipbillHeaderModel model) {
		// 新增后自动提交判定
		ShipbillMatchLineVO matchLineVO = new ShipbillMatchLineVO();
		// 配送方式
		matchLineVO.setDeliveryMethodType(model.getDeliveryMethodType());
		// 发货方类型
		matchLineVO.setShipperType(model.getShipperType());
		// 发货方单位ID
		matchLineVO.setShipperUnitId(model.getShipperUnitId());
		matchLineVO.setShipperProvince(model.getShipperProvince());
		matchLineVO.setShipperCity(model.getShipperCity());
		matchLineVO.setShipperDistrict(model.getShipperDistrict());
		// 收货方类型
		matchLineVO.setConsigneeType(model.getConsigneeType());
		// 收货方单位ID
		matchLineVO.setConsigneeUnitId(model.getConsigneeUnitId());
		matchLineVO.setConsigneeId(model.getConsigneeId());
		matchLineVO.setConsigneeProvince(model.getConsigneeProvince());
		matchLineVO.setConsigneeCity(model.getConsigneeCity());
		matchLineVO.setConsigneeDistrict(model.getConsigneeDistrict());
		// 订单类型
		matchLineVO.setOrderType(model.getOrderType());
		// 订单业务类型
		matchLineVO.setOrderBusinessType(model.getOrderBusinessType());
		// 运输模式
		matchLineVO.setTransportType(model.getTransportType());
		// 温度要求
		matchLineVO.setTemperatureRequirement(model.getTemperatureRequirement());
		// 货主ID
		matchLineVO.setCargoOwnerId(model.getCargoOwnerId());
		matchLineVO.setDepartmentId(model.getDepartmentId());
		matchLineVO.setEnterpriseId(model.getEnterpriseId());

		RestMessage<ShipbillMatchLineDTO> matchRs = maindataTmsResource.shipbillMatchLineExecute(matchLineVO);
		if (!matchRs.isSuccess()) {
			throw new PrologException("运单【" + model.getShipbillNo() + "】调用maindata服务运单匹配线路策略失败");
		}
		return matchRs.getData();
	}
}
