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

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

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

import com.codingapi.tx.annotation.TxTransaction;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.prolog.common.util.DateUtils;
import com.prolog.common.util.ToolKits;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.exception.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.dao.mapper.TmsLoadingBillDetailMapper;
import com.prolog.rdc.tms.dao.mapper.TmsLoadingBillHeaderMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillDetailMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillHeaderMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillPackageMapper;
import com.prolog.rdc.tms.dao.mapper.TmsShipbillTransportLogMapper;
import com.prolog.rdc.tms.model.dto.SelfPickUpRegApprovalDTO;
import com.prolog.rdc.tms.model.dto.SelfWithdrawalConfirmQueryDTO;
import com.prolog.rdc.tms.model.dto.SelfWithdrawalDetailDTO;
import com.prolog.rdc.tms.model.dto.ShipbillInfoDTO;
import com.prolog.rdc.tms.model.dto.SmartSplitDTO;
import com.prolog.rdc.tms.model.dto.WaitForArrangeGoodsShipbillPageDTO;
import com.prolog.rdc.tms.model.dto.WaitForSelfWithdrawalExportDTO;
import com.prolog.rdc.tms.model.dto.WaitForSelfWithdrawalItemDTO;
import com.prolog.rdc.tms.model.dto.WaitForSelfWithdrawalPackageDTO;
import com.prolog.rdc.tms.model.dto.WaitForSelfWithdrawalPageDTO;
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.ApprovalLogDTO;
import com.prolog.rdc.tms.model.dto.basicData.ApprovalNodeSelDTO;
import com.prolog.rdc.tms.model.dto.basicData.ItemCheckDTO;
import com.prolog.rdc.tms.model.dto.fleetManagement.VehicleAndDriverDTO;
import com.prolog.rdc.tms.model.dto.message.SendMessageDTO;
import com.prolog.rdc.tms.model.entity.SysRefdatadModel;
import com.prolog.rdc.tms.model.entity.TmsLoadingBillDetailModel;
import com.prolog.rdc.tms.model.entity.TmsLoadingBillHeaderModel;
import com.prolog.rdc.tms.model.entity.TmsShipbillDetailModel;
import com.prolog.rdc.tms.model.entity.TmsShipbillHeaderModel;
import com.prolog.rdc.tms.model.entity.TmsShipbillPackageModel;
import com.prolog.rdc.tms.model.entity.TmsShipbillTransLogModel;
import com.prolog.rdc.tms.model.enums.MessageOrderTypeEnum;
import com.prolog.rdc.tms.model.enums.MessageTypeEnum;
import com.prolog.rdc.tms.model.vo.DetailItemSplitVO;
import com.prolog.rdc.tms.model.vo.SelfPickUpApprovalVO;
import com.prolog.rdc.tms.model.vo.SelfPickUpRegApprovalInfoVO;
import com.prolog.rdc.tms.model.vo.SelfPickUpVehicleRegisterVO;
import com.prolog.rdc.tms.model.vo.SelfWithdrawalConfirmQueryVO;
import com.prolog.rdc.tms.model.vo.SelfWithdrawalConfirmVO;
import com.prolog.rdc.tms.model.vo.ShipbillNodeTrackingSaveNewVO;
import com.prolog.rdc.tms.model.vo.ShipbillOperateLogSaveNewVO;
import com.prolog.rdc.tms.model.vo.SmartSplitStrategyVO;
import com.prolog.rdc.tms.model.vo.SmartSplitVO;
import com.prolog.rdc.tms.model.vo.SplitVO;
import com.prolog.rdc.tms.model.vo.WaitForSelfAdsQueryVO;
import com.prolog.rdc.tms.model.vo.WaitForSelfWithdrawalItemQueryVO;
import com.prolog.rdc.tms.model.vo.WaitForSelfWithdrawalPackageQueryVO;
import com.prolog.rdc.tms.model.vo.WaitForSelfWithdrawalPrintQueryVO;
import com.prolog.rdc.tms.model.vo.WaitForSelfWithdrawalQueryVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.ApprovalBusinessNodeVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.ApprovalOpenVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.SignconfigPopVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.StrategySplitMatchingVO;
import com.prolog.rdc.tms.model.vo.basicData.ItemCheckVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.VehicleAndVehicleVO;
import com.prolog.rdc.tms.rmi.feign.MaindataFeign;
import com.prolog.rdc.tms.service.PendingDispatchService;
import com.prolog.rdc.tms.service.ShipbillNodeTrackingService;
import com.prolog.rdc.tms.service.ShipbillOperateLogService;
import com.prolog.rdc.tms.service.WaitForSelfWithdrawalService;
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;

/**
 * 待自提实现层
 *
 * @author xyf
 * @since 2022/4/18 12:43
 */
@Service
public class WaitForSelfWithdrawalServiceImpl implements WaitForSelfWithdrawalService {

	@Autowired
	private ShipbillOperateLogService shipbillOperateLogService;

	@Autowired
	private TmsLoadingBillDetailMapper tmsLoadingBillDetailMapper;

	@Autowired
	private MaindataFeign maindataTmsResource;

	@Autowired
	private TmsShipbillDetailMapper tmsShipbillDetailMapper;

	@Autowired
	private TmsLoadingBillHeaderMapper tmsLoadingBillHeaderMapper;

	@Autowired
	private TmsShipbillPackageMapper tmsShipbillPackageMapper;

	@Autowired
	private TmsShipbillHeaderMapper tmsShipbillHeaderMapper;

	@Autowired
	private ShipbillNodeTrackingService shipbillNodeTrackingService;

	@Autowired
	private TmsShipbillTransportLogMapper tmsShipbillTransportLogMapper;

	@Autowired
	private BusinessFlowUtil businessFlowUtil;

	@Autowired
	private ConvertorUtil convertorUtil;
	// STD-DEVELOP20220823 lhb bwc0823003 20220824 start
	@Autowired
	private PendingDispatchService pendingDispatchService;
	// STD-DEVELOP20220823 lhb bwc0823003 20220824 end

	/**
	 * 主界面分页查询
	 */
	@Override
	public Page<WaitForSelfWithdrawalPageDTO> queryPage(WaitForSelfWithdrawalQueryVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		// 权限控制
		if (!ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_GYS) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_HZ) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_KH)) {
			throw new PrologException("当前人员没有操作权限");
		}

		List<SysRefdatadModel> dicData = convertorUtil.getDictionary(new String[] { DataDictionaryConstant.SHIPBILL_STATUS, // 运单状态
				DataDictionaryConstant.SHIPBILL_STATUS, // 运单状态
				DataDictionaryConstant.TRANSPORT_STATUS, // 运输状态
				DataDictionaryConstant.LINE_CARRIER_TYPE, // 承运方类型
				DataDictionaryConstant.ABNORMAL_STATUS, // 异常状态
				DataDictionaryConstant.SCAN_STATUS, // 扫描状态
				DataDictionaryConstant.ORDER_TYPE, // 订单类型
				DataDictionaryConstant.ORDER_BUSINESS_TYPE, // 订单业务类型
				DataDictionaryConstant.DELIVERY_METHOD_TYPE, // 配送方式
				DataDictionaryConstant.TRANSPORT_TYPE, // 运输类型(运输模式)
				DataDictionaryConstant.TEMPERATURE_REQUIREMENT// 温度要求
		});

		vo.setUserType(user.getUserType());
		// 添加查询条件
		vo.setEnterpriseId(user.getEnterpriseId());
		if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY)) {
			// 自有账号
			vo.setDepts(user.getDepts().stream().toArray(String[]::new));
			if (BussinessConstant.USER_DEPARTMENT_AUTH_Y.equals(user.getOwnedAllDataAuthFlag())) {
				vo.setIsDept("YES");
			} else {
				vo.setIsDept("NO");
				// 其它权限
				// 货主
				vo.setConsignors(user.getConsignors().stream().toArray(Long[]::new));
				// 客户
				vo.setCustomers(user.getCustomers().stream().toArray(Long[]::new));
				// 供应商
				vo.setSuppliers(user.getSuppliers().stream().toArray(Long[]::new));
				// 仓库
				vo.setWsarehouses(user.getWarehouses().stream().toArray(Long[]::new));
			}
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_HZ)) {// 货主账号
			vo.setCargoOwnerUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_GYS)) {// 供应商账号
			vo.setSupplierUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_KH)) {// 客户账号
			vo.setCustomerUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			throw new PrologException("当前人员没有操作权限！");
		}

		PageUtils.startPage(vo.getPageNum(), vo.getPageSize());
		List<WaitForSelfWithdrawalPageDTO> list = tmsShipbillHeaderMapper.queryWaitForSelfWithdrawal(vo);

		for (WaitForSelfWithdrawalPageDTO dto : list) {
			dto.setStatusName(ConvertorUtil.getName(dicData, DataDictionaryConstant.SHIPBILL_STATUS, String.valueOf(dto.getStatus())));
			dto.setTransportStatusName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TRANSPORT_STATUS, String.valueOf(dto.getTransportStatus())));
			dto.setCarrierTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.LINE_CARRIER_TYPE, String.valueOf(dto.getCarrierType())));
			dto.setAbnormalStatusName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ABNORMAL_STATUS, String.valueOf(dto.getAbnormalStatus())));
			dto.setScanStatusName(ConvertorUtil.getName(dicData, DataDictionaryConstant.SCAN_STATUS, String.valueOf(dto.getScanStatus())));
			dto.setOrderTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ORDER_TYPE, String.valueOf(dto.getOrderType())));
			dto.setOrderBusinessTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.ORDER_BUSINESS_TYPE, String.valueOf(dto.getOrderBusinessType())));
			dto.setDeliveryMethodTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.DELIVERY_METHOD_TYPE, String.valueOf(dto.getDeliveryMethodType())));
			dto.setTransportTypeName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TRANSPORT_TYPE, String.valueOf(dto.getTransportType())));
			dto.setTemperatureRequirementName(ConvertorUtil.getName(dicData, DataDictionaryConstant.TEMPERATURE_REQUIREMENT, String.valueOf(dto.getTemperatureRequirement())));

			// 目的地
			StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
			consigneeProvinceCityDistrict.append(dto.getConsigneeProvinceName());
			consigneeProvinceCityDistrict.append(dto.getConsigneeCityName());
			consigneeProvinceCityDistrict.append(dto.getConsigneeDistrictName());
			dto.setConsigneeProvinceCityDistrict(consigneeProvinceCityDistrict.toString());

			// 始发地
			StringBuffer shipperProvinceCityDistrict = new StringBuffer();
			shipperProvinceCityDistrict.append(dto.getShipperProvinceName());
			shipperProvinceCityDistrict.append(dto.getShipperCityName());
			shipperProvinceCityDistrict.append(dto.getShipperDistrictName());
			dto.setShipperProvinceCityDistrict(shipperProvinceCityDistrict.toString());
		}
		return PageUtils.getPage(list);
	}

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

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

		if (!ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_GYS) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_HZ) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_KH)) {
			throw new PrologException("当前人员没有操作权限");
		}
		List<SysRefdatadModel> dicData = convertorUtil.getDictionary(new String[] { DataDictionaryConstant.SHIPBILL_STATUS, // 运单状态
				DataDictionaryConstant.TRANSPORT_STATUS, // 运输状态
				DataDictionaryConstant.ABNORMAL_STATUS, // 异常状态
				DataDictionaryConstant.SCAN_STATUS, // 扫描状态
				DataDictionaryConstant.LINE_CARRIER_TYPE, // 承运方类型
				DataDictionaryConstant.DELIVERY_METHOD_TYPE, // 配送方式
				DataDictionaryConstant.TRANSPORT_TYPE, // 运输类型(运输模式)
				DataDictionaryConstant.TEMPERATURE_REQUIREMENT, // 温度要求
				DataDictionaryConstant.SHIPPER_TYPE, // 发货方类型
				DataDictionaryConstant.CONSIGNEE_TYPE, // 收货方类型
				DataDictionaryConstant.ORDER_TYPE, // 订单类型
				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();
		}
		adsQueryVO.setUserType(user.getUserType());
		// 添加查询条件
		adsQueryVO.setEnterpriseId(user.getEnterpriseId());
		if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY)) {
			// 自有账号
			adsQueryVO.setDepts(user.getDepts().stream().toArray(String[]::new));
			if (BussinessConstant.USER_DEPARTMENT_AUTH_Y.equals(user.getOwnedAllDataAuthFlag())) {
				adsQueryVO.setIsDept("YES");
			} else {
				adsQueryVO.setIsDept("NO");
				// 其它权限
				// 货主
				adsQueryVO.setConsignors(user.getConsignors().stream().toArray(Long[]::new));
				// 客户
				adsQueryVO.setCustomers(user.getCustomers().stream().toArray(Long[]::new));
				// 供应商
				adsQueryVO.setSuppliers(user.getSuppliers().stream().toArray(Long[]::new));
				// 仓库
				adsQueryVO.setWsarehouses(user.getWarehouses().stream().toArray(Long[]::new));
			}
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_HZ)) {// 货主账号
			adsQueryVO.setCargoOwnerUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_GYS)) {// 供应商账号
			adsQueryVO.setSupplierUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_KH)) {// 客户账号
			adsQueryVO.setCustomerUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			throw new PrologException("当前人员没有操作权限！");
		}
		// 获取高级查询配置
		String conditions = null;
		RestMessage<String> restMessageAdvancedCfg = maindataTmsResource.getQueryConfiguration(DataDictionaryConstant.BIZ_TYPE_WAITFORSELFWITHDRAWAL);
		if (!restMessageAdvancedCfg.isSuccess()) {
			// throw new RuntimeException("订单类型翻译失败!");
		} else {
			conditions = restMessageAdvancedCfg.getData();
		}
		adsQueryVO.setSql(conditions);
		adsQueryVO.setEnterpriseId(user.getEnterpriseId());

		PageUtils.startPage(adsQueryVO.getPageNum(), adsQueryVO.getPageSize());
		List<WaitForSelfWithdrawalPageDTO> tmsShipbillHeaderModels = tmsShipbillHeaderMapper.selfPickUpAdvancedQuery(adsQueryVO);
		List<WaitForSelfWithdrawalPageDTO> allShipbillPageDTOS = Lists.newArrayList();
		for (WaitForSelfWithdrawalPageDTO tmsShipbillHeaderModel : tmsShipbillHeaderModels) {
			WaitForSelfWithdrawalPageDTO allShipbillPageDTO = new WaitForSelfWithdrawalPageDTO();
			BeanUtils.copyProperties(tmsShipbillHeaderModel, allShipbillPageDTO);
			// 收货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getConsigneeLatitude())) {
				allShipbillPageDTO.setConsigneePositioning(StatusConstant.POSITIONING_YDW);
			} else {
				allShipbillPageDTO.setConsigneePositioning(StatusConstant.POSITIONING_WDW);
			}
			// 发货方位置(经纬度判断)
			if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLongitude()) && ToolKits.isNotEmpty(tmsShipbillHeaderModel.getShipperLatitude())) {
				allShipbillPageDTO.setShipperPositioning(StatusConstant.POSITIONING_YDW);
			} else {
				allShipbillPageDTO.setShipperPositioning(StatusConstant.POSITIONING_WDW);
			}

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

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

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

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

							allShipbillPageDTO.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(allShipbillPageDTO.getDeliveryMethodTypeName()) ? allShipbillPageDTO.getDeliveryMethodTypeName() : "")) {
							allShipbillPageDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							allShipbillPageDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());
							allShipbillPageDTO.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(allShipbillPageDTO.getMemo()) ? allShipbillPageDTO.getMemo() : "")) {
							allShipbillPageDTO.setBackground(ToolKits.isEmpty(signconfigPopDTO.getBackground()) ? "" : signconfigPopDTO.getBackground());
							allShipbillPageDTO.setColor(ToolKits.isEmpty(signconfigPopDTO.getColor()) ? "" : signconfigPopDTO.getColor());
							allShipbillPageDTO.setSignConfigId(signconfigPopDTO.getId());
							break Signconfig;
						}
					}
					break;
				}
			}
			allShipbillPageDTOS.add(allShipbillPageDTO);
		}

		// 分页重组
		Page<WaitForSelfWithdrawalPageDTO> page = PageUtils.getPage(allShipbillPageDTOS);
		if (tmsShipbillHeaderModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<WaitForSelfWithdrawalPageDTO> p0 = (com.github.pagehelper.Page<WaitForSelfWithdrawalPageDTO>) 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
	 * @return
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<WaitForSelfWithdrawalItemDTO> queryItemDetail(WaitForSelfWithdrawalItemQueryVO waitForSelfWithdrawalItemQueryVO) {
		ToolKits.isParamNull(waitForSelfWithdrawalItemQueryVO, "待自提运单商品请求不为空");
		ToolKits.isParamNull(waitForSelfWithdrawalItemQueryVO.getShipbillId(), "运单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();
		}

		Criteria criteria = Criteria.forClass(TmsShipbillDetailModel.class);
		Restriction r1 = Restrictions.eq("shipbillId", waitForSelfWithdrawalItemQueryVO.getShipbillId());
		Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		PageUtils.startPage(waitForSelfWithdrawalItemQueryVO.getPageNum(), waitForSelfWithdrawalItemQueryVO.getPageSize());
		List<TmsShipbillDetailModel> list = tmsShipbillDetailMapper.findByCriteria(criteria);
		List<WaitForSelfWithdrawalItemDTO> dtos = new ArrayList<WaitForSelfWithdrawalItemDTO>();
		if (ToolKits.isNotEmpty(list)) {
			for (TmsShipbillDetailModel model : list) {
				WaitForSelfWithdrawalItemDTO dto = new WaitForSelfWithdrawalItemDTO();
				BeanUtils.copyProperties(model, dto);
				dto.setPackTypeName(PublicMethods.change(data1, String.valueOf(dto.getPackType())));
				dto.setCargoThermosphereName(PublicMethods.change(data2, String.valueOf(dto.getCargoThermosphere())));
				dtos.add(dto);
			}
		}

		// 分页重组
		Page<WaitForSelfWithdrawalItemDTO> page = PageUtils.getPage(dtos);
		if (list instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsShipbillDetailModel> p0 = (com.github.pagehelper.Page<TmsShipbillDetailModel>) list;
			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
	 * @return
	 */
	@Override
	public Page<WaitForSelfWithdrawalPackageDTO> queryPackageDetail(WaitForSelfWithdrawalPackageQueryVO waitForSelfWithdrawalPackageQueryVO) {
		ToolKits.isParamNull(waitForSelfWithdrawalPackageQueryVO, "待自提运单包裹请求不为空");
		ToolKits.isParamNull(waitForSelfWithdrawalPackageQueryVO.getShipbillId(), "运单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.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", waitForSelfWithdrawalPackageQueryVO.getShipbillId());
		Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		PageUtils.startPage(waitForSelfWithdrawalPackageQueryVO.getPageNum(), waitForSelfWithdrawalPackageQueryVO.getPageSize());
		List<TmsShipbillPackageModel> list = tmsShipbillPackageMapper.findByCriteria(criteria);
		List<WaitForSelfWithdrawalPackageDTO> dtos = Lists.newArrayList();
		for (TmsShipbillPackageModel model : list) {
			WaitForSelfWithdrawalPackageDTO dto = new WaitForSelfWithdrawalPackageDTO();
			BeanUtils.copyProperties(model, dto);
			dto.setPackageTypeName(PublicMethods.change(data1, String.valueOf(dto.getPackageType())));
			dto.setDeviceCompanyName(PublicMethods.change(data2, String.valueOf(dto.getDeviceCompany())));
			dtos.add(dto);
		}
		return PageUtils.getPage(dtos);
	}

	/**
	 * 待自提——导出所有页
	 *
	 * @param
	 * @return
	 */
	@Override
	public List<WaitForSelfWithdrawalExportDTO> exportAllPage(WaitForSelfWithdrawalQueryVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		// 权限控制 仅支持自有账号
		if (!ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_GYS) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_HZ) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_KH)) {
			throw new PrologException("当前人员没有操作权限");
		}
		vo.setUserType(user.getUserType());
		vo.setEnterpriseId(user.getEnterpriseId());

		// 添加查询条件
		if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY)) {
			// 自有账号
			vo.setDepts(user.getDepts().stream().toArray(String[]::new));
			if (BussinessConstant.USER_DEPARTMENT_AUTH_Y.equals(user.getOwnedAllDataAuthFlag())) {
				vo.setIsDept("YES");
			} else {
				vo.setIsDept("NO");
				// 其它权限
				// 货主
				vo.setConsignors(user.getConsignors().stream().toArray(Long[]::new));
				// 客户
				vo.setCustomers(user.getCustomers().stream().toArray(Long[]::new));
				// 供应商
				vo.setSuppliers(user.getSuppliers().stream().toArray(Long[]::new));
				// 仓库
				vo.setWsarehouses(user.getWarehouses().stream().toArray(Long[]::new));
			}
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_HZ)) {// 货主账号
			vo.setCargoOwnerUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_GYS)) {// 供应商账号
			vo.setSupplierUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_KH)) {// 客户账号
			vo.setCustomerUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			throw new PrologException("当前人员没有操作权限！");
		}
		List<WaitForSelfWithdrawalPageDTO> list = tmsShipbillHeaderMapper.queryWaitForSelfWithdrawal(vo);

		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();
		// 运单状态
		RestMessage<List<Map<String, Object>>> restMessage1 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPBILL_STATUS, null, null, null);
		if (!restMessage1.isSuccess()) {
			throw new RuntimeException("运单状态翻译失败!");
		} else {
			data1 = restMessage1.getData();
		}
//		// 运输状态
//		RestMessage<List<Map<String, Object>>> restMessage2 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_STATUS, null, null, null);
//		if (!restMessage2.isSuccess()) {
//			throw new RuntimeException("运输状态翻译失败!");
//		} else {
//			data2 = restMessage2.getData();
//		}
//		// 异常状态
//		RestMessage<List<Map<String, Object>>> restMessage3 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ABNORMAL_STATUS, null, null, null);
//		if (!restMessage3.isSuccess()) {
//			throw new RuntimeException("异常状态翻译失败!");
//		} else {
//			data3 = restMessage3.getData();
//		}
//		// 扫描状态
//		RestMessage<List<Map<String, Object>>> restMessage4 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ABNORMAL_STATUS, null, null, null);
//		if (!restMessage4.isSuccess()) {
//			throw new RuntimeException("异常状态翻译失败!");
//		} else {
//			data4 = restMessage4.getData();
//		}
//		// 承运方类型
//		RestMessage<List<Map<String, Object>>> restMessage5 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LINE_CARRIER_TYPE, null, null, null);
//		if (!restMessage5.isSuccess()) {
//			throw new PrologException("承运方类型翻译失败!");
//		} else {
//			data5 = restMessage5.getData();
//		}
		// 订单类型
		RestMessage<List<Map<String, Object>>> restMessage6 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_TYPE, null, null, null);
		if (!restMessage6.isSuccess()) {
			throw new PrologException("订单类型翻译失败!");
		} else {
			data6 = restMessage6.getData();
		}
		// 订单业务类型
		RestMessage<List<Map<String, Object>>> restMessage7 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_BUSINESS_TYPE, null, null, null);
		if (!restMessage7.isSuccess()) {
			throw new RuntimeException("订单业务类型翻译失败!");
		} else {
			data7 = restMessage7.getData();
		}
		// 配送方式
		RestMessage<List<Map<String, Object>>> restMessage8 = maindataTmsResource.getDropDownById(DataDictionaryConstant.DELIVERY_METHOD_TYPE, null, null, null);
		if (!restMessage8.isSuccess()) {
			throw new RuntimeException("配送方式翻译失败!");
		} else {
			data8 = restMessage8.getData();
		}
		// 运输类型(运输模式)
		RestMessage<List<Map<String, Object>>> restMessage9 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_TYPE, null, null, null);
		if (!restMessage9.isSuccess()) {
			throw new RuntimeException("运输类型(运输模式)翻译失败!");
		} else {
			data9 = restMessage9.getData();
		}
		// 温度要求
		RestMessage<List<Map<String, Object>>> restMessage10 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TEMPERATURE_REQUIREMENT, null, null, null);
		if (!restMessage10.isSuccess()) {
			throw new RuntimeException("温度要求翻译失败!");
		} else {
			data10 = restMessage10.getData();
		}
		List<WaitForSelfWithdrawalExportDTO> exportDtos = Lists.newArrayList();
		for (WaitForSelfWithdrawalPageDTO dto : list) {
			WaitForSelfWithdrawalExportDTO exportDto = new WaitForSelfWithdrawalExportDTO();
			BeanUtils.copyProperties(dto, exportDto);
			exportDto.setStatus(PublicMethods.change(data1, String.valueOf(dto.getStatus())));
			/*
			 * exportDto.setTransportStatus(PublicMethods.change(data2,
			 * String.valueOf(dto.getTransportStatus())));
			 * exportDto.setAbnormalStatus(PublicMethods.change(data3,
			 * String.valueOf(dto.getAbnormalStatus())));
			 * exportDto.setScanStatus(PublicMethods.change(data4,
			 * String.valueOf(dto.getScanStatus())));
			 * exportDto.setCarrierType(PublicMethods.change(data5,
			 * String.valueOf(dto.getCarrierType())));
			 */
			exportDto.setOrderType(PublicMethods.change(data6, String.valueOf(dto.getOrderType())));
			exportDto.setOrderBusinessType(PublicMethods.change(data7, String.valueOf(dto.getOrderType())));
			exportDto.setDeliveryMethodType(PublicMethods.change(data8, String.valueOf(dto.getDeliveryMethodType())));
			exportDto.setTransportType(PublicMethods.change(data9, String.valueOf(dto.getTransportType())));
			exportDto.setTemperatureRequirement(PublicMethods.change(data10, String.valueOf(dto.getTemperatureRequirement())));

			// 目的地
			StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
			consigneeProvinceCityDistrict.append(dto.getConsigneeProvinceName());
			consigneeProvinceCityDistrict.append(dto.getConsigneeCityName());
			consigneeProvinceCityDistrict.append(dto.getConsigneeDistrictName());
			exportDto.setConsigneeProvinceCityDistrict(consigneeProvinceCityDistrict.toString());

			// 始发地
			StringBuffer shipperProvinceCityDistrict = new StringBuffer();
			shipperProvinceCityDistrict.append(dto.getShipperProvinceName());
			shipperProvinceCityDistrict.append(dto.getShipperCityName());
			shipperProvinceCityDistrict.append(dto.getShipperDistrictName());
			exportDto.setShipperProvinceCityDistrict(shipperProvinceCityDistrict.toString());
			if (ToolKits.isNotEmpty(dto.getShipperLatitude()) && ToolKits.isNotEmpty(dto.getShipperLongitude())) {
				exportDto.setShipperPoint("已定位");
			}
			if (ToolKits.isNotEmpty(dto.getConsigneeLatitude()) && ToolKits.isNotEmpty(dto.getConsigneeLongitude())) {
				exportDto.setConsigneePoint("已定位");
			}
			exportDtos.add(exportDto);
		}
		return exportDtos;
	}

	/**
	 * 导出选择行
	 *
	 * @param shipbillIdList
	 * @return
	 */
	public List<WaitForSelfWithdrawalExportDTO> exportsSelectLine(List<String> shipbillIdList) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		// 权限控制 仅支持自有账号
		if (!ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_GYS) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_HZ) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_KH)) {
			throw new PrologException("当前人员没有操作权限");
		}

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

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

		List<WaitForSelfWithdrawalPageDTO> list = tmsShipbillHeaderMapper.querySelfWithdrawalByShipbillId(shipbillIdList);

		for (WaitForSelfWithdrawalPageDTO dto : list) {
			WaitForSelfWithdrawalExportDTO exportDto = new WaitForSelfWithdrawalExportDTO();
			BeanUtils.copyProperties(dto, exportDto);
			exportDto.setStatus(PublicMethods.change(data1, String.valueOf(dto.getStatus())));
			/*
			 * exportDto.setTransportStatus(PublicMethods.change(data2,
			 * String.valueOf(dto.getTransportStatus())));
			 * exportDto.setAbnormalStatus(PublicMethods.change(data3,
			 * String.valueOf(dto.getAbnormalStatus())));
			 * exportDto.setScanStatus(PublicMethods.change(data4,
			 * String.valueOf(dto.getScanStatus())));
			 * exportDto.setCarrierType(PublicMethods.change(data5,
			 * String.valueOf(dto.getCarrierType())));
			 */
			exportDto.setOrderType(PublicMethods.change(data6, String.valueOf(dto.getOrderType())));
			exportDto.setOrderBusinessType(PublicMethods.change(data7, String.valueOf(dto.getOrderType())));
			exportDto.setDeliveryMethodType(PublicMethods.change(data8, String.valueOf(dto.getDeliveryMethodType())));
			exportDto.setTransportType(PublicMethods.change(data9, String.valueOf(dto.getTransportType())));
			exportDto.setTemperatureRequirement(PublicMethods.change(data10, String.valueOf(dto.getTemperatureRequirement())));

			// 目的地
			StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
			consigneeProvinceCityDistrict.append(dto.getConsigneeProvinceName());
			consigneeProvinceCityDistrict.append(dto.getConsigneeCityName());
			consigneeProvinceCityDistrict.append(dto.getConsigneeDistrictName());
			exportDto.setConsigneeProvinceCityDistrict(consigneeProvinceCityDistrict.toString());

			// 始发地
			StringBuffer shipperProvinceCityDistrict = new StringBuffer();
			shipperProvinceCityDistrict.append(dto.getShipperProvinceName());
			shipperProvinceCityDistrict.append(dto.getShipperCityName());
			shipperProvinceCityDistrict.append(dto.getShipperDistrictName());
			exportDto.setShipperProvinceCityDistrict(shipperProvinceCityDistrict.toString());

			if (ToolKits.isNotEmpty(dto.getShipperLatitude()) && ToolKits.isNotEmpty(dto.getShipperLongitude())) {
				exportDto.setShipperPoint("已定位");
			}
			if (ToolKits.isNotEmpty(dto.getConsigneeLatitude()) && ToolKits.isNotEmpty(dto.getConsigneeLongitude())) {
				exportDto.setConsigneePoint("已定位");
			}

			exportDtos.add(exportDto);
		}
		return exportDtos;
	}

	/**
	 * 导出当前页
	 *
	 * @param vo
	 * @return
	 */
	@SuppressWarnings("resource")
	public List<WaitForSelfWithdrawalExportDTO> exportCurrentPage(WaitForSelfWithdrawalQueryVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		// 权限控制 仅支持自有账号
		if (!ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_GYS) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_HZ) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_KH)) {
			throw new PrologException("当前人员没有操作权限");
		}
		vo.setUserType(user.getUserType());
		vo.setEnterpriseId(user.getEnterpriseId());

		// 添加查询条件
		if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY)) {
			// 自有账号
			vo.setDepts(user.getDepts().stream().toArray(String[]::new));
			if (BussinessConstant.USER_DEPARTMENT_AUTH_Y.equals(user.getOwnedAllDataAuthFlag())) {
				vo.setIsDept("YES");
			} else {
				vo.setIsDept("NO");
				// 其它权限
				// 货主
				vo.setConsignors(user.getConsignors().stream().toArray(Long[]::new));
				// 客户
				vo.setCustomers(user.getCustomers().stream().toArray(Long[]::new));
				// 供应商
				vo.setSuppliers(user.getSuppliers().stream().toArray(Long[]::new));
				// 仓库
				vo.setWsarehouses(user.getWarehouses().stream().toArray(Long[]::new));
			}
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_HZ)) {// 货主账号
			vo.setCargoOwnerUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_GYS)) {// 供应商账号
			vo.setSupplierUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else if (ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_KH)) {// 客户账号
			vo.setCustomerUserId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			throw new PrologException("当前人员没有操作权限！");
		}
		PageUtils.startPage(vo.getPageNum(), vo.getPageSize());
		List<WaitForSelfWithdrawalPageDTO> list = tmsShipbillHeaderMapper.queryWaitForSelfWithdrawal(vo);

		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();
		// 运单状态
		RestMessage<List<Map<String, Object>>> restMessage1 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPBILL_STATUS, null, null, null);
		if (!restMessage1.isSuccess()) {
			throw new RuntimeException("运单状态翻译失败!");
		} else {
			data1 = restMessage1.getData();
		}
//		// 运输状态
//		RestMessage<List<Map<String, Object>>> restMessage2 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_STATUS, null, null, null);
//		if (!restMessage2.isSuccess()) {
//			throw new RuntimeException("运输状态翻译失败!");
//		} else {
//			data2 = restMessage2.getData();
//		}
//		// 异常状态
//		RestMessage<List<Map<String, Object>>> restMessage3 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ABNORMAL_STATUS, null, null, null);
//		if (!restMessage3.isSuccess()) {
//			throw new RuntimeException("异常状态翻译失败!");
//		} else {
//			data3 = restMessage3.getData();
//		}
//		// 扫描状态
//		RestMessage<List<Map<String, Object>>> restMessage4 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ABNORMAL_STATUS, null, null, null);
//		if (!restMessage4.isSuccess()) {
//			throw new RuntimeException("异常状态翻译失败!");
//		} else {
//			data4 = restMessage4.getData();
//		}
//		// 承运方类型
//		RestMessage<List<Map<String, Object>>> restMessage5 = maindataTmsResource.getDropDownById(DataDictionaryConstant.LINE_CARRIER_TYPE, null, null, null);
//		if (!restMessage5.isSuccess()) {
//			throw new PrologException("承运方类型翻译失败!");
//		} else {
//			data5 = restMessage5.getData();
//		}
		// 订单类型
		RestMessage<List<Map<String, Object>>> restMessage6 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_TYPE, null, null, null);
		if (!restMessage6.isSuccess()) {
			throw new PrologException("订单类型翻译失败!");
		} else {
			data6 = restMessage6.getData();
		}
		// 订单业务类型
		RestMessage<List<Map<String, Object>>> restMessage7 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ORDER_BUSINESS_TYPE, null, null, null);
		if (!restMessage7.isSuccess()) {
			throw new RuntimeException("订单业务类型翻译失败!");
		} else {
			data7 = restMessage7.getData();
		}
		// 配送方式
		RestMessage<List<Map<String, Object>>> restMessage8 = maindataTmsResource.getDropDownById(DataDictionaryConstant.DELIVERY_METHOD_TYPE, null, null, null);
		if (!restMessage8.isSuccess()) {
			throw new RuntimeException("配送方式翻译失败!");
		} else {
			data8 = restMessage8.getData();
		}
		// 运输类型(运输模式)
		RestMessage<List<Map<String, Object>>> restMessage9 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_TYPE, null, null, null);
		if (!restMessage9.isSuccess()) {
			throw new RuntimeException("运输类型(运输模式)翻译失败!");
		} else {
			data9 = restMessage9.getData();
		}
		// 温度要求
		RestMessage<List<Map<String, Object>>> restMessage10 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TEMPERATURE_REQUIREMENT, null, null, null);
		if (!restMessage10.isSuccess()) {
			throw new RuntimeException("温度要求翻译失败!");
		} else {
			data10 = restMessage10.getData();
		}
		List<WaitForSelfWithdrawalExportDTO> exportDtos = Lists.newArrayList();
		for (WaitForSelfWithdrawalPageDTO dto : list) {
			WaitForSelfWithdrawalExportDTO exportDto = new WaitForSelfWithdrawalExportDTO();
			BeanUtils.copyProperties(dto, exportDto);
			exportDto.setStatus(PublicMethods.change(data1, String.valueOf(dto.getStatus())));
			/*
			 * exportDto.setTransportStatus(PublicMethods.change(data2,
			 * String.valueOf(dto.getTransportStatus())));
			 * exportDto.setAbnormalStatus(PublicMethods.change(data3,
			 * String.valueOf(dto.getAbnormalStatus())));
			 * exportDto.setScanStatus(PublicMethods.change(data4,
			 * String.valueOf(dto.getScanStatus())));
			 * exportDto.setCarrierType(PublicMethods.change(data5,
			 * String.valueOf(dto.getCarrierType())));
			 */
			exportDto.setOrderType(PublicMethods.change(data6, String.valueOf(dto.getOrderType())));
			exportDto.setOrderBusinessType(PublicMethods.change(data7, String.valueOf(dto.getOrderType())));
			exportDto.setDeliveryMethodType(PublicMethods.change(data8, String.valueOf(dto.getDeliveryMethodType())));
			exportDto.setTransportType(PublicMethods.change(data9, String.valueOf(dto.getTransportType())));
			exportDto.setTemperatureRequirement(PublicMethods.change(data10, String.valueOf(dto.getTemperatureRequirement())));
			// 目的地
			StringBuffer consigneeProvinceCityDistrict = new StringBuffer();
			consigneeProvinceCityDistrict.append(dto.getConsigneeProvinceName());
			consigneeProvinceCityDistrict.append(dto.getConsigneeCityName());
			consigneeProvinceCityDistrict.append(dto.getConsigneeDistrictName());
			exportDto.setConsigneeProvinceCityDistrict(consigneeProvinceCityDistrict.toString());

			// 始发地
			StringBuffer shipperProvinceCityDistrict = new StringBuffer();
			shipperProvinceCityDistrict.append(dto.getShipperProvinceName());
			shipperProvinceCityDistrict.append(dto.getShipperCityName());
			shipperProvinceCityDistrict.append(dto.getShipperDistrictName());
			exportDto.setShipperProvinceCityDistrict(shipperProvinceCityDistrict.toString());

			if (ToolKits.isNotEmpty(dto.getShipperLatitude()) && ToolKits.isNotEmpty(dto.getShipperLongitude())) {
				exportDto.setShipperPoint("已定位");
			}
			if (ToolKits.isNotEmpty(dto.getConsigneeLatitude()) && ToolKits.isNotEmpty(dto.getConsigneeLongitude())) {
				exportDto.setConsigneePoint("已定位");
			}

			exportDtos.add(exportDto);
		}
		Page<WaitForSelfWithdrawalExportDTO> page = PageUtils.getPage(exportDtos);
		if (list instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<WaitForSelfWithdrawalPageDTO> p0 = (com.github.pagehelper.Page<WaitForSelfWithdrawalPageDTO>) list;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page.getList();
	}

	/**
	 * 自提确认查询
	 *
	 * @param vo
	 * @return
	 */
	public SelfWithdrawalConfirmQueryDTO confirmQuery(SelfWithdrawalConfirmQueryVO vo) {

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		ToolKits.isParamNull(vo, "请选择要操作的运单");
		ToolKits.isParamNull(vo.getShipbillIds(), "请选择要操作的运单");

		Criteria criteria = Criteria.forClass(TmsShipbillTransLogModel.class);
		Restriction r1 = Restrictions.in(TmsShipbillTransLogModel::getShipbillId, vo.getShipbillIds().stream().toArray(String[]::new));
		Restriction r2 = Restrictions.eq(TmsShipbillTransLogModel::getEnterpriseId, user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2));

		List<TmsShipbillTransLogModel> logModels = tmsShipbillTransportLogMapper.findByCriteria(criteria);
		// STD-DEVELOP20220823 lhb bwc0823003 20220908 start
		SelfWithdrawalConfirmQueryDTO confirmQueryDTO = new SelfWithdrawalConfirmQueryDTO();

		if (ToolKits.isNotEmpty(logModels)) {
			Long driverNameSize = logModels.stream().map(TmsShipbillTransLogModel::getSelfPickUpPerson).distinct().count();
			Long driverPhoneSize = logModels.stream().map(TmsShipbillTransLogModel::getSelfPickUpTel).distinct().count();
			Long plateNumSize = logModels.stream().map(TmsShipbillTransLogModel::getVehiclePlateNumber).distinct().count();

			if (driverNameSize > 1 || driverPhoneSize > 1 || plateNumSize > 1) {
				throw new PrologException("请勾选相同司机、司机电话、车辆的运单");
			}
			confirmQueryDTO.setSelfWithdrawalPerson(logModels.get(0).getSelfPickUpPerson());
			confirmQueryDTO.setIdCrad(logModels.get(0).getIdCard());
			confirmQueryDTO.setContactTel(logModels.get(0).getSelfPickUpTel());
			confirmQueryDTO.setVehiclePlateNumber(logModels.get(0).getVehiclePlateNumber());
		}
		return confirmQueryDTO;
		// STD-DEVELOP20220823 lhb bwc0823003 20220908 end
	}

	/**
	 * 自提确认
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void selfWithdrawalConfirm(SelfWithdrawalConfirmVO vo) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		ToolKits.isParamNull(vo.getShipbillIds(), "请选择要操作的运单");

		if (!ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_ZY) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_GYS) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_HZ) && !ObjectUtil.equal(user.getUserType(), BussinessConstant.USER_TYPE_KH)) {
			throw new PrologException("当前人员没有操作权限");
		}

		StringBuffer nodeEvent = new StringBuffer();
		nodeEvent.append("自提确认");
		nodeEvent.append(" 自提时间:");
		nodeEvent.append(DateUtil.formatDateTime(vo.getSelfWithdrawalDate()));
		if (ToolKits.isNotEmpty(vo.getHandoverPerson())) {
			nodeEvent.append(" 交接人:");
			nodeEvent.append(vo.getHandoverPerson());
		}
		nodeEvent.append(" 自提人:");
		nodeEvent.append(vo.getSelfWithdrawalPerson());
		nodeEvent.append(" 联系方式:");
		nodeEvent.append(vo.getContactTel());
		if (ToolKits.isNotEmpty(vo.getVehiclePlateNumber())) {
			nodeEvent.append(" 车牌号：");
			nodeEvent.append(vo.getVehiclePlateNumber());
		}
		if (ToolKits.isNotEmpty(vo.getIdCrad())) {
			nodeEvent.append(" 身份证:");
			nodeEvent.append(vo.getIdCrad());
		}
		if (ToolKits.isNotEmpty(vo.getMemo())) {
			nodeEvent.append(" 备注:");
			nodeEvent.append(vo.getMemo());
		}
		Date date = DateUtil.date();
		Map<String, Object> updateLoadingHeaderMap = Maps.newHashMap();
		updateLoadingHeaderMap.put("status", DataDictionaryConstant.SHIPBILL_STATUS_END);
		updateLoadingHeaderMap.put("updatetime", date);
		updateLoadingHeaderMap.put("updateperson", user.getNickname());
		for (String id : vo.getShipbillIds()) {
			TmsShipbillHeaderModel tmsShipbillHeader = tmsShipbillHeaderMapper.findById(id, TmsShipbillHeaderModel.class);
			if (ToolKits.isEmpty(tmsShipbillHeader)) {
				throw new PrologException("运单【" + id + "】不存在");
			}
			if (tmsShipbillHeader.getStatus().intValue() > DataDictionaryConstant.SHIPBILL_STATUS_HD_ZT.intValue()) {
				throw new PrologException("运单【" + id + "】已经自提确认了");
			}
			Map<String, Object> queryMap = Maps.newHashMap();
			queryMap.put("shipbillId", id);
			// 自提车辆登记校验
			List<TmsLoadingBillDetailModel> tmsLoadingBillDetails = tmsLoadingBillDetailMapper.findByMap(queryMap, TmsLoadingBillDetailModel.class);
			if (tmsShipbillHeader.getFlowConfig().contains(DataDictionaryConstant.FLOW_CONFIG_SELF_PICKUP_VEH_REG) && ToolKits.isEmpty(tmsLoadingBillDetails)) {
				throw new PrologException("运单【" + id + "】还没有做自提车辆登记，不能自提确认!");
			}
			if (ToolKits.isNotEmpty(tmsShipbillHeader)) {
				// 修改运单明细的商品信息
				Criteria criteriaShipbillDetail = Criteria.forClass(TmsShipbillDetailModel.class);
				Restriction r11 = Restrictions.eq(TmsShipbillDetailModel::getShipbillId, tmsShipbillHeader.getShipbillId());
				Restriction r12 = Restrictions.eq(TmsShipbillDetailModel::getEnterpriseId, user.getEnterpriseId());
				Restriction r13 = Restrictions.gt(TmsShipbillDetailModel::getPcs, BigDecimal.valueOf(0));
				criteriaShipbillDetail.setRestriction(Restrictions.and(r11, r12, r13));
				List<TmsShipbillDetailModel> shipbillDetailModels = tmsShipbillDetailMapper.findByCriteria(criteriaShipbillDetail);
				BigDecimal totalDeliveryPcs = new BigDecimal(0);
				BigDecimal totalDeliveryVolume = new BigDecimal(0);
				BigDecimal totalDeliveryWeight = new BigDecimal(0);

				if (ToolKits.isNotEmpty(shipbillDetailModels)) {
					for (TmsShipbillDetailModel shipbillDetailModel : shipbillDetailModels) {
						shipbillDetailModel.setDeliveryPcs(shipbillDetailModel.getPcs());
						shipbillDetailModel.setPcs(new BigDecimal(0));
						shipbillDetailModel.setVolume(new BigDecimal(0));
						shipbillDetailModel.setWeight(new BigDecimal(0));
						tmsShipbillDetailMapper.update(shipbillDetailModel);

						ItemCheckVO itemCheckVO = new ItemCheckVO();
						itemCheckVO.setItemId(shipbillDetailModel.getItemId());
						RestMessage<ItemCheckDTO> restMessage3 = maindataTmsResource.getItem(itemCheckVO);
						if (!restMessage3.isSuccess()) {
							throw new RuntimeException("取商品资料信息失败:" + restMessage3.getMessage());
						}
						ItemCheckDTO rsItemInfo = restMessage3.getData();

						BigDecimal fatherDeliveryPcs = new BigDecimal(0);
						BigDecimal fatherDeliveryVolume = new BigDecimal(0);
						BigDecimal fatherDeliveryWeight = new BigDecimal(0);

						fatherDeliveryPcs = fatherDeliveryPcs.add(shipbillDetailModel.getDeliveryPcs());
						fatherDeliveryVolume = fatherDeliveryVolume.add(shipbillDetailModel.getDeliveryPcs().multiply(rsItemInfo.getVolume()));
						fatherDeliveryWeight = fatherDeliveryWeight.add(shipbillDetailModel.getDeliveryPcs().multiply(rsItemInfo.getWeight()));

						totalDeliveryPcs = totalDeliveryPcs.add(shipbillDetailModel.getDeliveryPcs());
						totalDeliveryVolume = totalDeliveryVolume.add(shipbillDetailModel.getDeliveryPcs().multiply(rsItemInfo.getVolume()));
						totalDeliveryWeight = totalDeliveryWeight.add(shipbillDetailModel.getDeliveryPcs().multiply(rsItemInfo.getWeight()));

						// 主单对应的运单明细
						String fatherShipbillIdForDetail = tmsShipbillHeader.getShipbillId();
						while (ToolKits.isNotEmpty(fatherShipbillIdForDetail)) {
							fatherShipbillIdForDetail = updateFatherShipbillDetail(fatherShipbillIdForDetail, shipbillDetailModel, fatherDeliveryPcs, date, user, rsItemInfo);
						}
					}
				}
				Integer oldStatus = tmsShipbillHeader.getStatus();
				if (ToolKits.isNotEmpty(tmsLoadingBillDetails) && tmsLoadingBillDetails.size() > 0) {
					// 更新调度明细
					TmsLoadingBillDetailModel tmsLoadingBillDetail = tmsLoadingBillDetails.get(0);
					tmsLoadingBillDetail.setUpdateperson(user.getNickname());
					tmsLoadingBillDetail.setUpdatetime(date);
					tmsLoadingBillDetail.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_END);
					tmsLoadingBillDetail.setTransportStatus(DataDictionaryConstant.TRANSPORT_STATUS_ARRIVED);
					tmsLoadingBillDetailMapper.update(tmsLoadingBillDetail);

					// 更新调度表
					tmsLoadingBillHeaderMapper.updateMapById(tmsLoadingBillDetail.getLoadingBillId(), updateLoadingHeaderMap, TmsLoadingBillHeaderModel.class);
				}

				// 更新运单
				tmsShipbillHeader.setUpdateperson(user.getNickname());
				tmsShipbillHeader.setUpdatetime(date);
				tmsShipbillHeader.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_END);
				tmsShipbillHeader.setTransportStatus(DataDictionaryConstant.TRANSPORT_STATUS_ARRIVED);
				tmsShipbillHeaderMapper.update(tmsShipbillHeader);

				// 更新运单运输记录
				Map<String, Object> queryMap2 = Maps.newHashMap();
				queryMap2.put("shipbillId", id);
				List<TmsShipbillTransLogModel> tmsShipbillTransportLogs = tmsShipbillTransportLogMapper.findByMap(queryMap2, TmsShipbillTransLogModel.class);
				if (ToolKits.isNotEmpty(tmsShipbillTransportLogs) && tmsShipbillTransportLogs.size() > 0) {
					TmsShipbillTransLogModel tmsShipbillTransportLog = tmsShipbillTransportLogs.get(0);
					tmsShipbillTransportLog.setSelfPickUpTime(vo.getSelfWithdrawalDate());
					tmsShipbillTransportLog.setSelfPickUpContact(vo.getHandoverPerson());// 自提交接人
					tmsShipbillTransportLog.setSelfPickUpPerson(vo.getSelfWithdrawalPerson());// 自提人
					tmsShipbillTransportLog.setSelfPickUpTel(vo.getContactTel());// 自提人联系方式
					tmsShipbillTransportLog.setVehiclePlateNumber(vo.getVehiclePlateNumber());
					tmsShipbillTransportLog.setIdCard(vo.getIdCrad());
					tmsShipbillTransportLog.setSelfPickUpMemo(vo.getMemo());
					tmsShipbillTransportLogMapper.update(tmsShipbillTransportLog);
				}

				// 运单节点保存
				ShipbillNodeTrackingSaveNewVO shipbillNodeTrackingSaveNewVO = new ShipbillNodeTrackingSaveNewVO();
				shipbillNodeTrackingSaveNewVO.setNodeDate(vo.getSelfWithdrawalDate());
				shipbillNodeTrackingSaveNewVO.setShipbillId(tmsShipbillHeader.getShipbillId());
				shipbillNodeTrackingSaveNewVO.setShipbillNo(tmsShipbillHeader.getShipbillId());
				shipbillNodeTrackingSaveNewVO.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_END);
				shipbillNodeTrackingSaveNewVO.setNodeEvent(nodeEvent.toString());
				shipbillNodeTrackingSaveNewVO.setUserId(user.getUserid());
				shipbillNodeTrackingSaveNewVO.setUserName(user.getNickname());
				shipbillNodeTrackingSaveNewVO.setPicUrl(vo.getPicUrl());
				shipbillNodeTrackingSaveNewVO.setEnterpriseId(user.getEnterpriseId());
				shipbillNodeTrackingSaveNewVO.setEnterpriseName(user.getEnterpriseName());
				shipbillNodeTrackingService.addShipbillNodeTrackingNewData(shipbillNodeTrackingSaveNewVO);

				// 运单日志保存
				ShipbillOperateLogSaveNewVO shipbillOperateLogSaveNewVO = new ShipbillOperateLogSaveNewVO();
				shipbillOperateLogSaveNewVO.setShipbillId(tmsShipbillHeader.getShipbillId());
				shipbillOperateLogSaveNewVO.setShipbillNo(tmsShipbillHeader.getShipbillId());
				shipbillOperateLogSaveNewVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_DZT);
				shipbillOperateLogSaveNewVO.setOldStatus(oldStatus);
				shipbillOperateLogSaveNewVO.setNewStatus(DataDictionaryConstant.SHIPBILL_STATUS_END);
				shipbillOperateLogSaveNewVO.setOperateDate(date);
				shipbillOperateLogSaveNewVO.setEnterpriseId(user.getEnterpriseId());
				shipbillOperateLogSaveNewVO.setEnterpriseName(user.getEnterpriseName());
				shipbillOperateLogSaveNewVO.setUserId(user.getUserid());
				shipbillOperateLogSaveNewVO.setUserName(user.getNickname());
				shipbillOperateLogService.addShipbillOperateLogNewData(shipbillOperateLogSaveNewVO);
			} else {
				throw new PrologException("自提确认的运单【" + id + "】在运单表中不存在");
			}
			MessageUtil.addMessage(new SendMessageDTO(MessageOrderTypeEnum.SHIP_NO.getCode(), MessageTypeEnum.SELF_CONFIRM.getCode(), Lists.newArrayList(id)));
		}
	}

	/**
	 * 同步更新父运单商品明细
	 *
	 * @param shipbillId
	 * @param date
	 * @param user
	 * @return
	 */
	public String updateFatherShipbillDetail(String shipbillId, TmsShipbillDetailModel subShipbillDetailModel, BigDecimal totalDeliveryPcs, Date date, UserEntity user, ItemCheckDTO rsItemInfo) {
		// 查询运单
		TmsShipbillHeaderModel tmsShipbillHeaderModel = tmsShipbillHeaderMapper.findById(shipbillId, TmsShipbillHeaderModel.class);
		// 判断是否为原始单号
		if (ToolKits.isNotEmpty(tmsShipbillHeaderModel.getFatherShipbillId()) && !tmsShipbillHeaderModel.getFatherShipbillId().equals(shipbillId)) {
			// 查找父级单号
			TmsShipbillHeaderModel fatherShipbillHeaderModel = tmsShipbillHeaderMapper.findById(tmsShipbillHeaderModel.getFatherShipbillId(), TmsShipbillHeaderModel.class);

			Criteria criteriaShipbillDetail = Criteria.forClass(TmsShipbillDetailModel.class);
			Restriction r11 = Restrictions.eq(TmsShipbillDetailModel::getShipbillId, fatherShipbillHeaderModel.getShipbillId());
			Restriction r12 = Restrictions.eq(TmsShipbillDetailModel::getEnterpriseId, user.getEnterpriseId());
			Restriction r13 = Restrictions.eq(TmsShipbillDetailModel::getItemId, subShipbillDetailModel.getItemId());
			Restriction r14 = Restrictions.gt(TmsShipbillDetailModel::getPcs, BigDecimal.valueOf(0));
			criteriaShipbillDetail.setRestriction(Restrictions.and(r11, r12, r13, r14));
			List<TmsShipbillDetailModel> shipbillDetailModels = tmsShipbillDetailMapper.findByCriteria(criteriaShipbillDetail);

			if (ToolKits.isEmpty(shipbillDetailModels)) {
				throw new PrologException("运单【" + shipbillId + "】的父运单的运单商品明细【" + subShipbillDetailModel.getItemName() + "】不存在");
			}

			BigDecimal detailDeliveryPcs = totalDeliveryPcs;
			for (TmsShipbillDetailModel fatherShipbillDetailModel : shipbillDetailModels) {
				if (detailDeliveryPcs.intValue() <= 0) {
					break;
				}
				if (fatherShipbillDetailModel.getPcs().intValue() >= detailDeliveryPcs.intValue()) {
					fatherShipbillDetailModel.setDeliveryPcs(fatherShipbillDetailModel.getDeliveryPcs().add(detailDeliveryPcs));

					// 剩余件数
					fatherShipbillDetailModel.setUpdateperson(user.getNickname());
					fatherShipbillDetailModel.setUpdatetime(date);
					fatherShipbillDetailModel.setPcs(fatherShipbillDetailModel.getOrigPcs().subtract(fatherShipbillDetailModel.getClosingPcs()).subtract(fatherShipbillDetailModel.getDeliveryPcs()));
					fatherShipbillDetailModel.setVolume(fatherShipbillDetailModel.getPcs().multiply(rsItemInfo.getVolume()));
					fatherShipbillDetailModel.setWeight(fatherShipbillDetailModel.getPcs().multiply(rsItemInfo.getWeight()));
					tmsShipbillDetailMapper.update(fatherShipbillDetailModel);
					detailDeliveryPcs = BigDecimal.valueOf(0);
					break;
				} else {
					fatherShipbillDetailModel.setDeliveryPcs(fatherShipbillDetailModel.getDeliveryPcs().add(fatherShipbillDetailModel.getPcs()));
					detailDeliveryPcs = detailDeliveryPcs.subtract(fatherShipbillDetailModel.getPcs());

					// 剩余件数
					fatherShipbillDetailModel.setUpdateperson(user.getNickname());
					fatherShipbillDetailModel.setUpdatetime(date);
					fatherShipbillDetailModel.setPcs(fatherShipbillDetailModel.getOrigPcs().subtract(fatherShipbillDetailModel.getClosingPcs()).subtract(fatherShipbillDetailModel.getDeliveryPcs()));
					fatherShipbillDetailModel.setVolume(fatherShipbillDetailModel.getPcs().multiply(rsItemInfo.getVolume()));
					fatherShipbillDetailModel.setWeight(fatherShipbillDetailModel.getPcs().multiply(rsItemInfo.getWeight()));
					tmsShipbillDetailMapper.update(fatherShipbillDetailModel);
				}
			}
			if (detailDeliveryPcs.intValue() > 0) {
				throw new PrologException("运单【" + shipbillId + "】的商品【" + subShipbillDetailModel.getItemName() + "】的件数>父运单的件数");
			}
			// 更新运单
			if (ToolKits.isEmpty(fatherShipbillHeaderModel.getTotalDeliveryPcs())) {
				fatherShipbillHeaderModel.setTotalDeliveryPcs(totalDeliveryPcs);
			} else {
				fatherShipbillHeaderModel.setTotalDeliveryPcs(fatherShipbillHeaderModel.getTotalDeliveryPcs().add(totalDeliveryPcs));
			}

			fatherShipbillHeaderModel.setTotalDeliveryVolume(fatherShipbillHeaderModel.getTotalDeliveryPcs().multiply(rsItemInfo.getVolume()));
			fatherShipbillHeaderModel.setTotalDeliveryWeight(fatherShipbillHeaderModel.getTotalDeliveryPcs().multiply(rsItemInfo.getWeight()));

			if (ToolKits.isEmpty(fatherShipbillHeaderModel.getDepartureTime())) {
				fatherShipbillHeaderModel.setDepartureTime(new Date());
			}
			fatherShipbillHeaderModel.setTotalPcs(fatherShipbillHeaderModel.getTotalPcs().subtract(totalDeliveryPcs));
			fatherShipbillHeaderModel.setTotalVolume(fatherShipbillHeaderModel.getTotalPcs().multiply(rsItemInfo.getVolume()));
			fatherShipbillHeaderModel.setTotalWeight(fatherShipbillHeaderModel.getTotalPcs().multiply(rsItemInfo.getWeight()));
			fatherShipbillHeaderModel.setActualTotalPcs(fatherShipbillHeaderModel.getTotalPcs());
			fatherShipbillHeaderModel.setActualTotalVolume(fatherShipbillHeaderModel.getTotalVolume());
			fatherShipbillHeaderModel.setActualTotalWeight(fatherShipbillHeaderModel.getTotalWeight());

			fatherShipbillHeaderModel.setUpdateperson(user.getNickname());
			fatherShipbillHeaderModel.setUpdatetime(date);
			tmsShipbillHeaderMapper.update(fatherShipbillHeaderModel);

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

	/**
	 * 自提车辆登记
	 *
	 * @param vehicleRegisterVO
	 * @return
	 */
	@Transactional(rollbackFor = Exception.class)
	public void vehicleRegister(SelfPickUpVehicleRegisterVO vehicleRegisterVO) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		ToolKits.isParamNull(vehicleRegisterVO.getShipbillIds(), "请选择要操作的运单");

		Date date = DateUtil.date();

		// 校验司机车辆信息
		VehicleAndVehicleVO vehicleAndVehicleVO = new VehicleAndVehicleVO();
		vehicleAndVehicleVO.setDriverName(vehicleRegisterVO.getSelfWithdrawalPerson());
		vehicleAndVehicleVO.setPhoneNumber(vehicleRegisterVO.getContactTel());
		vehicleAndVehicleVO.setVehiclePlateNumber(vehicleRegisterVO.getVehiclePlateNumber());
		RestMessage<VehicleAndDriverDTO> restMessage = maindataTmsResource.vehicleAutomaticExecute(vehicleAndVehicleVO);
		if (!restMessage.isSuccess()) {
			throw new ParameterException("自提车辆信息校验失败:" + restMessage.getMessage());
		}
		// 车辆司机信息
		VehicleAndDriverDTO vehicleAndDriverDTO = restMessage.getData();

		// 获取装车单ID
		RestMessage<String> restMessage1 = maindataTmsResource.getCodeNumberByCode(SeriaNnumberConstant.TMS_LOADING_BILL_HEADER_ID, "L");
		if (!restMessage1.isSuccess()) {
			throw new RuntimeException("生成装车单ID失败");
		}
		String loadingBillId = restMessage1.getData();

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

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

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

		// STD-DEVELOP20220823 lhb bwc0823003 20220824 start
		for (String shipbillId : vehicleRegisterVO.getShipbillIds()) {
			// STD-DEVELOP20220823 lhb bwc0823003 20220824 end
			TmsShipbillHeaderModel headerModel = tmsShipbillHeaderMapper.findById(shipbillId, TmsShipbillHeaderModel.class);

			if (!headerModel.getStatus().equals(DataDictionaryConstant.SHIPBILL_STATUS_REVIEW)) {
				throw new PrologException("运单【" + headerModel.getShipbillNo() + "】已自提登记");
			}
			if (!headerModel.getFlowConfig().contains(DataDictionaryConstant.FLOW_CONFIG_SELF_PICKUP_VEH_REG)) {
				// 流程没有自提车辆登记
				throw new PrologException("运单【" + shipbillId + "】没有配置车辆自提登记的流程，不能做车辆自提登记");
			}
			// 重复自提登记
			Criteria criteriaLoadingBillDetail = Criteria.forClass(TmsLoadingBillDetailModel.class);
			Restriction r2 = Restrictions.eq(TmsLoadingBillDetailModel::getShipbillId, shipbillId);
			criteriaLoadingBillDetail.setRestriction(Restrictions.and(r2));
			List<TmsLoadingBillDetailModel> tmsLoadingBillDetailModels = tmsLoadingBillDetailMapper.findByCriteria(criteriaLoadingBillDetail);
			if (ToolKits.isNotEmpty(tmsLoadingBillDetailModels)) {
				throw new PrologException("运单【" + shipbillId + "】已经做过自提车辆登记");
			}
			// 登记信息保存到运输记录表中
			transportLogMap.put("selfPickUpTime", date);
			transportLogMap.put("selfPickUpPerson", vehicleRegisterVO.getSelfWithdrawalPerson());
			transportLogMap.put("selfPickUpTel", vehicleRegisterVO.getContactTel());
			if (ToolKits.isNotEmpty(vehicleRegisterVO.getVehiclePlateNumber())) {
				transportLogMap.put("vehiclePlateNumber", vehicleRegisterVO.getVehiclePlateNumber());
			}
			if (ToolKits.isNotEmpty(vehicleRegisterVO.getIdCrad())) {
				transportLogMap.put("idCard", vehicleRegisterVO.getIdCrad());
			}
			if (ToolKits.isNotEmpty(vehicleRegisterVO.getMemo())) {
				transportLogMap.put("selfPickUpMemo", vehicleRegisterVO.getMemo());
			}

			Restriction r1 = Restrictions.eq(TmsShipbillTransLogModel::getShipbillId, shipbillId);
			criteriaTransport.setRestriction(r1);
			tmsShipbillTransportLogMapper.updateMapByCriteria(transportLogMap, criteriaTransport);
			// STD-DEVELOP20220823 lhb bwc0825001 20220905 自提登记审批 start
			boolean matched = approvalOpen(headerModel, DataDictionaryConstant.APPROVAL_FLOW_TYPE_ZT_REG, user);
			if (matched) {
				// 开启自提登记审批流
				headerModel.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_HD_ZT_APPROVAL);
				headerModel.setUpdatetime(date);
				headerModel.setUpdateperson(user.getNickname());
				tmsShipbillHeaderMapper.update(headerModel);
				continue;
			}
			// STD-DEVELOP20220823 lhb bwc0825001 20220905 自提登记审批 end

			// 运单节点表
			ShipbillNodeTrackingSaveNewVO shipbillNodeTrackingSaveNewVO = new ShipbillNodeTrackingSaveNewVO();
			shipbillNodeTrackingSaveNewVO.setNodeDate(date);
			shipbillNodeTrackingSaveNewVO.setShipbillId(shipbillId);
			shipbillNodeTrackingSaveNewVO.setShipbillNo(shipbillId);
			shipbillNodeTrackingSaveNewVO.setStatus(headerModel.getStatus());
			shipbillNodeTrackingSaveNewVO.setNodeEvent(DataDictionaryConstant.SHIPBILL_NODE_SELF_PICK_VEH_REG);
			shipbillNodeTrackingSaveNewVO.setUserId(user.getUserid());
			shipbillNodeTrackingSaveNewVO.setUserName(user.getNickname());
			shipbillNodeTrackingSaveNewVO.setEnterpriseId(user.getEnterpriseId());
			shipbillNodeTrackingSaveNewVO.setEnterpriseName(user.getEnterpriseName());
			shipbillNodeTrackingService.addShipbillNodeTrackingNewData(shipbillNodeTrackingSaveNewVO);

			goodsTotalPcs = headerModel.getTotalPcs();
			goodsTotalVolume = ToolKits.isEmpty(headerModel.getTotalVolume()) ? BigDecimal.ZERO : headerModel.getTotalVolume();
			goodsTotalWeight = ToolKits.isEmpty(headerModel.getTotalWeight()) ? BigDecimal.ZERO : headerModel.getTotalWeight();

			// 判定下一步流程
			int status = businessFlowUtil.judgmentNextFlowSts(headerModel.getFlowConfig(), DataDictionaryConstant.FLOW_CONFIG_SELF_PICKUP_VEH_REG);

			// 生成调度单明细表
			TmsLoadingBillDetailModel loadingBillDetailModel = new TmsLoadingBillDetailModel();
			RestMessage<String> restMessage2 = maindataTmsResource.getCodeNumberByCode(SeriaNnumberConstant.TMS_LOADING_BILL_DETAIL_ID, "L");
			if (!restMessage2.isSuccess()) {
				throw new RuntimeException("生成装车单明细ID失败");
			}
			String loadingBillDetailId = restMessage2.getData();

			BeanUtils.copyProperties(headerModel, loadingBillDetailModel);

			loadingBillDetailModel.setStatus(status);
			loadingBillDetailModel.setId(loadingBillDetailId);
			loadingBillDetailModel.setShippingOrder(Integer.valueOf(1));
			loadingBillDetailModel.setLoadingBillId(loadingBillId);
			loadingBillDetailModel.setLoadingBillNo(loadingBillId);
			loadingBillDetailModel.setEnterpriseId(user.getEnterpriseId());
			loadingBillDetailModel.setEnterpriseName(user.getEnterpriseName());
			loadingBillDetailModel.setCreateperson(user.getNickname());
			loadingBillDetailModel.setCreatetime(date);
			loadingBillDetailModel.setUpdateperson(user.getNickname());
			loadingBillDetailModel.setUpdatetime(date);
			loadingBillDetailModel.setCarrierId(vehicleAndDriverDTO.getDriver().getDriverId());
			loadingBillDetailModel.setCarrierCode(vehicleAndDriverDTO.getDriver().getDriverCode());
			loadingBillDetailModel.setCarrierName(vehicleRegisterVO.getSelfWithdrawalPerson());
			loadingBillDetailModel.setCarrierType(DataDictionaryConstant.LINE_CARRIER_TYPE_ZT);
			// 保存调度单明细
			tmsLoadingBillDetailMapper.save(loadingBillDetailModel);

			// 更新运单状态
			headerModel.setStatus(status);
			headerModel.setUpdatetime(date);
			headerModel.setUpdateperson(user.getNickname());
			tmsShipbillHeaderMapper.update(headerModel);

			// 运单日志保存
			ShipbillOperateLogSaveNewVO shipbillOperateLogSaveNewVO = new ShipbillOperateLogSaveNewVO();
			shipbillOperateLogSaveNewVO.setShipbillId(shipbillId);
			shipbillOperateLogSaveNewVO.setShipbillNo(shipbillId);
			shipbillOperateLogSaveNewVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_DZT_DJ);
			shipbillOperateLogSaveNewVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_REVIEW);
			shipbillOperateLogSaveNewVO.setNewStatus(status);
			shipbillOperateLogSaveNewVO.setOperateDate(date);
			shipbillOperateLogSaveNewVO.setEnterpriseId(user.getEnterpriseId());
			shipbillOperateLogSaveNewVO.setEnterpriseName(user.getEnterpriseName());
			shipbillOperateLogSaveNewVO.setUserId(user.getUserid());
			shipbillOperateLogSaveNewVO.setUserName(user.getNickname());
			shipbillOperateLogService.addShipbillOperateLogNewData(shipbillOperateLogSaveNewVO);

			TmsLoadingBillHeaderModel loadingBillHeaderModel = new TmsLoadingBillHeaderModel();
			loadingBillHeaderModel.setSiteNumber(Integer.valueOf(1));
			loadingBillHeaderModel.setCustomerNumber(Integer.valueOf(1));
			loadingBillHeaderModel.setTotalPcs(goodsTotalPcs);
			loadingBillHeaderModel.setTotalVolume(goodsTotalVolume);
			loadingBillHeaderModel.setTotalWeight(goodsTotalWeight);
			loadingBillHeaderModel.setActualTotalPcs(goodsTotalPcs);
			loadingBillHeaderModel.setActualTotalVolume(goodsTotalVolume);
			loadingBillHeaderModel.setActualTotalWeight(goodsTotalWeight);
			// 运单数
			loadingBillHeaderModel.setShipbillNumber(Integer.valueOf(1));
			loadingBillHeaderModel.setCarrierId(vehicleAndDriverDTO.getDriver().getDriverId());
			loadingBillHeaderModel.setCarrierCode(vehicleAndDriverDTO.getDriver().getDriverCode());
			loadingBillHeaderModel.setCarrierName(vehicleRegisterVO.getSelfWithdrawalPerson());
			loadingBillHeaderModel.setDeliverymanName(vehicleRegisterVO.getSelfWithdrawalPerson());
			loadingBillHeaderModel.setDriverId(vehicleAndDriverDTO.getDriver().getDriverId());
			loadingBillHeaderModel.setDriverCode(vehicleAndDriverDTO.getDriver().getDriverCode());
			loadingBillHeaderModel.setDriverName(vehicleRegisterVO.getSelfWithdrawalPerson());
			loadingBillHeaderModel.setDriverPhoneNumber(vehicleRegisterVO.getContactTel());
			loadingBillHeaderModel.setVehicleId(ToolKits.isEmpty(vehicleAndDriverDTO.getVehicle()) ? null : vehicleAndDriverDTO.getVehicle().getVehicleId());
			loadingBillHeaderModel.setVehicleCode(ToolKits.isEmpty(vehicleAndDriverDTO.getVehicle()) ? null : vehicleAndDriverDTO.getVehicle().getVehicleCode());
			loadingBillHeaderModel.setVehicleName(ToolKits.isEmpty(vehicleAndDriverDTO.getVehicle()) ? null : vehicleAndDriverDTO.getVehicle().getVehicleName());
			loadingBillHeaderModel.setVehiclePlateNumber(vehicleRegisterVO.getVehiclePlateNumber());
			// 调度类型
			loadingBillHeaderModel.setScheduleType(DataDictionaryConstant.SCHEDULE_TYPE_ZY);
			// 承运方类型
			loadingBillHeaderModel.setCarrierType(DataDictionaryConstant.LINE_CARRIER_TYPE_ZT);
			loadingBillHeaderModel.setLoadingBillId(loadingBillId);
			loadingBillHeaderModel.setLoadingBillNo(loadingBillId);
			loadingBillHeaderModel.setLoadingBillDate(date);
			// 自提
			loadingBillHeaderModel.setStatus(DataDictionaryConstant.LOADING_BILL_STATUS_YSH);
			loadingBillHeaderModel.setEnterpriseId(user.getEnterpriseId());
			loadingBillHeaderModel.setEnterpriseName(user.getEnterpriseName());
			loadingBillHeaderModel.setCreatetime(date);
			loadingBillHeaderModel.setCreateperson(user.getNickname());
			loadingBillHeaderModel.setUpdateperson(user.getNickname());
			loadingBillHeaderModel.setUpdatetime(date);
			loadingBillHeaderModel.setLoadingBillDate(date);

			loadingBillHeaderModel.setScanStatus(DataDictionaryConstant.SCAN_STATUS_INIT);
			tmsLoadingBillHeaderMapper.save(loadingBillHeaderModel);
			MessageUtil.addMessage(new SendMessageDTO(MessageOrderTypeEnum.SHIP_NO.getCode(), MessageTypeEnum.SELF_VEHICLE_REGISTER.getCode(), Lists.newArrayList(shipbillId)));
		}
	}

	/**
	 * 打印
	 */
	@Override
	public Map<String, Object> print(WaitForSelfWithdrawalPrintQueryVO waitForSelfWithdrawalPrintQueryVO) {
		ToolKits.isParamNull(waitForSelfWithdrawalPrintQueryVO, "打印请求不为空");
		ToolKits.isParamNull(waitForSelfWithdrawalPrintQueryVO.getShipbillId(), "运单ID不为空");

		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		// 查询运单信息
		TmsLoadingBillDetailModel tmsLoadingBillDetail = tmsLoadingBillDetailMapper.findById(waitForSelfWithdrawalPrintQueryVO.getShipbillId(), TmsLoadingBillDetailModel.class);
		if (ToolKits.isNotEmpty(tmsLoadingBillDetail)) {
			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();
			// 运单状态
			RestMessage<List<Map<String, Object>>> restMessage1 = maindataTmsResource.getDropDownById(DataDictionaryConstant.SHIPBILL_STATUS, null, null, null);
			if (!restMessage1.isSuccess()) {
				throw new RuntimeException("运单状态翻译失败!");
			} else {
				data1 = restMessage1.getData();
			}

			// 运输状态
			RestMessage<List<Map<String, Object>>> restMessage2 = maindataTmsResource.getDropDownById(DataDictionaryConstant.TRANSPORT_STATUS, null, null, null);
			if (!restMessage2.isSuccess()) {
				throw new RuntimeException("运输状态翻译失败!");
			} else {
				data2 = restMessage2.getData();
			}

			// 异常状态
			RestMessage<List<Map<String, Object>>> restMessage3 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ABNORMAL_STATUS, null, null, null);
			if (!restMessage3.isSuccess()) {
				throw new RuntimeException("异常状态翻译失败!");
			} else {
				data3 = restMessage3.getData();
			}

			// 扫描状态
			RestMessage<List<Map<String, Object>>> restMessage4 = maindataTmsResource.getDropDownById(DataDictionaryConstant.ABNORMAL_STATUS, null, null, null);
			if (!restMessage4.isSuccess()) {
				throw new RuntimeException("异常状态翻译失败!");
			} else {
				data3 = restMessage4.getData();
			}

			WaitForArrangeGoodsShipbillPageDTO dto = new WaitForArrangeGoodsShipbillPageDTO();
			BeanUtils.copyProperties(tmsLoadingBillDetail, dto);
			dto.setStatusName(PublicMethods.change(data1, String.valueOf(dto.getStatus())));
			dto.setTransportStatusName(PublicMethods.change(data2, String.valueOf(dto.getTransportStatus())));
			dto.setAbnormalStatusName(PublicMethods.change(data3, String.valueOf(dto.getAbnormalStatus())));
			dto.setScanStatusName(PublicMethods.change(data4, String.valueOf(dto.getScanStatus())));

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

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

			WaitForSelfWithdrawalItemQueryVO waitForSelfWithdrawalItemQueryVO = new WaitForSelfWithdrawalItemQueryVO();
			waitForSelfWithdrawalItemQueryVO.setShipbillId(dto.getShipbillId());

			// 通过运单ID查询商品信息
			Page<WaitForSelfWithdrawalItemDTO> details = this.queryItemDetail(waitForSelfWithdrawalItemQueryVO);
			if (ToolKits.isNotEmpty(details)) {
				for (WaitForSelfWithdrawalItemDTO item : details.getList()) {
					item.setPackTypeName(PublicMethods.change(data8, String.valueOf(item.getPackType())));
					item.setCargoThermosphereName(PublicMethods.change(data9, String.valueOf(item.getCargoThermosphere())));
				}
			}

			// TODO print

			return null;
		} else {
			throw new PrologException("未找到运单信息");
		}
	}

	/**
	 * 生成运输记录表
	 */
	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);
	}

	// STD-DEVELOP20220823 lhb bwc0823003 20220824 自提拆分 start
	/**
	 * 待自提折分商品信息查询
	 *
	 * @param detailItemSplitVO
	 * @return
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public List<SelfWithdrawalDetailDTO> splitListShipbillDetail(DetailItemSplitVO detailItemSplitVO) {
		ToolKits.isParamNull(detailItemSplitVO, "商品信息查询查询不为空");
		ToolKits.isParamNull(detailItemSplitVO.getShipbillId(), "运单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();
		}

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

		List<TmsShipbillDetailModel> tmsShipbillDetailModels = tmsShipbillDetailMapper.findByCriteria(criteria);

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

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

				detailDTOS.add(pendingDispatchDetailDTO);
			}
		}
		return detailDTOS;
	}

	/**
	 * 智能拆分
	 *
	 * @param smartSplitVO
	 * @return
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public List<SmartSplitDTO> smartSplitData(SmartSplitVO smartSplitVO) {
		ToolKits.isParamNull(smartSplitVO.getShipbillIds(), "运单id不能为空");

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

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

		// 返回数据
		List<SmartSplitDTO> smartSplitDTOS = Lists.newArrayList();

		// 查询对应运单
		List<TmsShipbillHeaderModel> tmsShipbillHeaderModels = tmsShipbillHeaderMapper.findByIds(TmsShipbillHeaderModel.class, smartSplitVO.getShipbillIds().toArray(), null);
		if (ToolKits.isEmpty(tmsShipbillHeaderModels)) {
			throw new PrologException("运单不存在");
		}

		for (TmsShipbillHeaderModel tmsShipbillHeaderModel : tmsShipbillHeaderModels) {
			// 获取商品集合
			Criteria criteriaDetail = Criteria.forClass(TmsShipbillDetailModel.class);
			Restriction r1 = Restrictions.eq(TmsShipbillDetailModel::getShipbillId, tmsShipbillHeaderModel.getShipbillId());
			criteriaDetail.setRestriction(r1);
			List<TmsShipbillDetailModel> tmsShipbillDetailModels = tmsShipbillDetailMapper.findByCriteria(criteriaDetail);

			if (ToolKits.isEmpty(tmsShipbillDetailModels)) {
				// 运单没商品
				continue;
			}
			// 获取拆分策略
			StrategySplitMatchingVO strategySplitMatchingVO = new StrategySplitMatchingVO();
			BeanUtils.copyProperties(tmsShipbillHeaderModel, strategySplitMatchingVO);
			RestMessage<List<StrategySplitMatchingDTO>> restMessage = maindataTmsResource.matchingExecute(strategySplitMatchingVO);
			if (!restMessage.isSuccess()) {
				throw new PrologException("获取拆分策略失败:" + restMessage.getMessage());
			}
			// 策略集合
			List<StrategySplitMatchingDTO> strategySplitMatchingDTOS = restMessage.getData();
			// 如果为空跳过
			if (ToolKits.isEmpty(strategySplitMatchingDTOS)) {
				continue;
			} else if (strategySplitMatchingDTOS.size() > 1) {// 如果为多条
				// 封装返回数据
				SmartSplitDTO smartSplitDTO = new SmartSplitDTO();
				smartSplitDTO.setShipbillId(tmsShipbillHeaderModel.getShipbillId());
				smartSplitDTO.setStrategySplitMatchingDTOS(strategySplitMatchingDTOS);
				smartSplitDTOS.add(smartSplitDTO);
				continue;
			}
			StrategySplitMatchingDTO strategyDTO = strategySplitMatchingDTOS.get(0);

			if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
				if (!DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_AUDITED.equals(tmsShipbillHeaderModel.getCarrierShipbillStatus())) {
					throw new PrologException("运单【" + tmsShipbillHeaderModel.getShipbillNo() + "】非待调度状态,拆单失败");
				}
				if (!DataDictionaryConstant.CARRIER_SPLIT_ORDER_STATUS_UN.equals(tmsShipbillHeaderModel.getCarrierSplitOrderStatus())) {
					throw new PrologException("运单【" + tmsShipbillHeaderModel.getShipbillNo() + "】非待调度状态,拆单失败");
				}
				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);
				}
			} else {
				if (!DataDictionaryConstant.SHIPBILL_STATUS_REVIEW.equals(tmsShipbillHeaderModel.getStatus())) {
					throw new PrologException("运单【" + tmsShipbillHeaderModel.getShipbillNo() + "】非待调度状态,拆单失败");
				}
				if (!DataDictionaryConstant.SPLIT_ORDER_STATUS_UN.equals(tmsShipbillHeaderModel.getSplitOrderStatus())) {
					throw new PrologException("运单【" + tmsShipbillHeaderModel.getShipbillNo() + "】非待调度状态,拆单失败");
				}

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

			}
			pendingDispatchService.autoSplit(strategyDTO, tmsShipbillHeaderModel, user, date);
		}
		return smartSplitDTOS;
	}

	/**
	 * 智能拆分(选择策略)
	 *
	 * @param smartSplitStrategyVOS
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void smartSplitStrategyData(List<SmartSplitStrategyVO> smartSplitStrategyVOS) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

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

		for (SmartSplitStrategyVO smartSplitStrategyVO : smartSplitStrategyVOS) {
			ToolKits.isParamNull(smartSplitStrategyVO.getShipbillId(), "运单id不能为空");
			ToolKits.isParamNull(smartSplitStrategyVO.getStrategyId(), "策略id不能为空");

			TmsShipbillHeaderModel tmsShipbillHeaderModel = tmsShipbillHeaderMapper.findById(smartSplitStrategyVO.getShipbillId(), TmsShipbillHeaderModel.class);
			if (ToolKits.isEmpty(tmsShipbillHeaderModel)) {
				continue;
			}

			// 获取商品集合
			Criteria criteriaDetail = Criteria.forClass(TmsShipbillDetailModel.class);
			Restriction r1 = Restrictions.eq(TmsShipbillDetailModel::getShipbillId, tmsShipbillHeaderModel.getShipbillId());
			criteriaDetail.setRestriction(r1);
			List<TmsShipbillDetailModel> tmsShipbillDetailModels = tmsShipbillDetailMapper.findByCriteria(criteriaDetail);
			if (ToolKits.isEmpty(tmsShipbillDetailModels)) {
				continue;
			}

			// 用选择的拆分策略拆分
			StrategySplitMatchingDTO strategyDTO = new StrategySplitMatchingDTO();
			BeanUtils.copyProperties(smartSplitStrategyVO, strategyDTO);

			if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
				if (!DataDictionaryConstant.CARRIER_SHIPBILL_STATUS_AUDITED.equals(tmsShipbillHeaderModel.getCarrierShipbillStatus())) {
					throw new PrologException("运单【" + tmsShipbillHeaderModel.getShipbillNo() + "】非待调度状态,拆单失败");
				}
				if (!DataDictionaryConstant.CARRIER_SPLIT_ORDER_STATUS_UN.equals(tmsShipbillHeaderModel.getCarrierSplitOrderStatus())) {
					throw new PrologException("运单【" + tmsShipbillHeaderModel.getShipbillNo() + "】非待调度状态,拆单失败");
				}

				tmsShipbillHeaderModel.setCarrierSplitOrderStatus(DataDictionaryConstant.CARRIER_SPLIT_ORDER_STATUS_ED);
				// 原始主单被拆分时，拆单类型更新为2拆分主单，子单被拆分时，不更新拆单类型
				if (ToolKits.isEmpty(tmsShipbillHeaderModel.getCarrierSplitOrderType()) || tmsShipbillHeaderModel.getCarrierSplitOrderType().equals(DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_UN)) {
					tmsShipbillHeaderModel.setCarrierSplitOrderType(DataDictionaryConstant.CARRIER_SPLIT_ORDER_TYPE_SPLIT_MASTER);
				}
			} else {
				if (!DataDictionaryConstant.SHIPBILL_STATUS_REVIEW.equals(tmsShipbillHeaderModel.getStatus())) {
					throw new PrologException("运单【" + tmsShipbillHeaderModel.getShipbillNo() + "】非待调度状态,拆单失败");
				}
				if (!DataDictionaryConstant.SPLIT_ORDER_STATUS_UN.equals(tmsShipbillHeaderModel.getSplitOrderStatus())) {
					throw new PrologException("运单【" + tmsShipbillHeaderModel.getShipbillNo() + "】非待调度状态,拆单失败");
				}

				tmsShipbillHeaderModel.setSplitOrderStatus(DataDictionaryConstant.SPLIT_ORDER_STATUS_ED);
				// 原始主单被拆分时，拆单类型更新为2拆分主单，子单被拆分时，不更新拆单类型
				if (ToolKits.isEmpty(tmsShipbillHeaderModel.getSplitOrderType()) || tmsShipbillHeaderModel.getSplitOrderType().equals(DataDictionaryConstant.SPLIT_ORDER_TYPE_UN)) {
					tmsShipbillHeaderModel.setSplitOrderType(DataDictionaryConstant.SPLIT_ORDER_TYPE_SPLIT_MASTER);
				}
			}
			pendingDispatchService.autoSplit(strategyDTO, tmsShipbillHeaderModel, user, date);
		}
	}

	/**
	 * 待自提按商品拆分
	 *
	 * @param splitVO
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void goodsSplit(SplitVO splitVO) {
		ToolKits.isParamNull(splitVO, "待调度拆分请求不为空");

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

		// 当前时间
		Date date = DateUtil.date();
		pendingDispatchService.autoGoodsSplit(splitVO, user, date);
	}
	// STD-DEVELOP20220823 lhb bwc0823003 20220824 自提拆分 end

	// STD-DEVELOP20220823 lhb bwc0825001 20220905 自提登记审批流 start
	/**
	 * 自提登记审核信息查询
	 *
	 * @param approvalInfoVO
	 */
	public SelfPickUpRegApprovalDTO getApprovalInfoData(SelfPickUpRegApprovalInfoVO approvalInfoVO) {
		ToolKits.isParamNull(approvalInfoVO, "自提登记审核信息查询请求不为空");
		ToolKits.isParamNull(approvalInfoVO.getShipbillId(), "运单ID不为空");
		ToolKits.isParamNull(approvalInfoVO.getApprovalBusinessId(), "审批业务ID不为空");

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

		SelfPickUpRegApprovalDTO approvalSCDTO = new SelfPickUpRegApprovalDTO();
		// 数据字典翻译数据集合
		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();

		TmsShipbillHeaderModel shipbillHeaderModel = tmsShipbillHeaderMapper.findById(approvalInfoVO.getShipbillId(), TmsShipbillHeaderModel.class);
		if (ToolKits.isEmpty(shipbillHeaderModel)) {
			throw new PrologException("运单【" + approvalInfoVO.getShipbillId() + "】信息不存在");
		}

		// 查询明细内容
		Criteria criteria = Criteria.forClass(TmsShipbillTransLogModel.class);
		Restriction r1 = Restrictions.eq(TmsShipbillTransLogModel::getShipbillId, approvalInfoVO.getShipbillId());
		criteria.setRestriction(r1);
		List<TmsShipbillTransLogModel> shipbillTransLogModels = tmsShipbillTransportLogMapper.findByCriteria(criteria);
		if (ToolKits.isEmpty(shipbillTransLogModels)) {
			throw new PrologException("运单【" + approvalInfoVO.getShipbillId() + "】的自提登记信息不存在");
		}

		BeanUtils.copyProperties(shipbillTransLogModels.get(0), approvalSCDTO);

		List<ShipbillInfoDTO> shipbillInfoDTOS = Lists.newArrayList();

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

		// 运单信息
		ShipbillInfoDTO shipbillInfoDTO = new ShipbillInfoDTO();
		BeanUtils.copyProperties(shipbillHeaderModel, shipbillInfoDTO);

		shipbillInfoDTO.setOrderTypeName(PublicMethods.change(data1, String.valueOf(shipbillHeaderModel.getOrderType())));
		shipbillInfoDTO.setOrderBusinessTypeName(PublicMethods.change(data2, String.valueOf(shipbillHeaderModel.getOrderBusinessType())));
		shipbillInfoDTO.setDeliveryMethodTypeName(PublicMethods.change(data3, String.valueOf(shipbillHeaderModel.getDeliveryMethodType())));
		shipbillInfoDTO.setTransportTypeName(PublicMethods.change(data4, String.valueOf(shipbillHeaderModel.getTransportType())));
		shipbillInfoDTO.setTemperatureRequirementName(PublicMethods.change(data5, String.valueOf(shipbillHeaderModel.getTemperatureRequirement())));
		shipbillInfoDTO.setShipperTypeName(PublicMethods.change(data6, String.valueOf(shipbillHeaderModel.getShipperType())));
		shipbillInfoDTO.setConsigneeTypeName(PublicMethods.change(data7, String.valueOf(shipbillHeaderModel.getConsigneeType())));
		shipbillInfoDTO.setStatusName(PublicMethods.change(data8, String.valueOf(shipbillHeaderModel.getStatus())));
		shipbillInfoDTOS.add(shipbillInfoDTO);

		approvalSCDTO.setShipbillInfoDTOList(shipbillInfoDTOS);

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

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

		return approvalSCDTO;
	}

	/**
	 * 自提登记审批作废
	 *
	 * @param approvalInvalidVO
	 */
	public void regApprovalInvalidData(SelfPickUpRegApprovalInfoVO approvalInvalidVO) {
		ToolKits.isParamNull(approvalInvalidVO, "自提登记撤回作废请求不为空");
		ToolKits.isParamNull(approvalInvalidVO.getShipbillId(), "运单ID不为空");
		ToolKits.isParamNull(approvalInvalidVO.getApprovalBusinessId(), "审批业务ID不为空");

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

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

		// 审核业务作废
		RestMessage<Object> restMessage = maindataTmsResource.approvalInvalidExecute(approvalInvalidVO.getApprovalBusinessId());
		if (!restMessage.isSuccess()) {
			throw new RuntimeException("调用审核作废失败:" + restMessage.getMessage());
		}

		// 运单状态回退
		tmsShipbillHeaderModel.setStatus(DataDictionaryConstant.SHIPBILL_STATUS_REVIEW);
		tmsShipbillHeaderMapper.update(tmsShipbillHeaderModel);
	}

	/**
	 * 自提登记审批流撤回
	 *
	 * @param approvalRetractVO
	 */
	public void regApprovalRetractData(SelfPickUpRegApprovalInfoVO approvalRetractVO) {
		ToolKits.isParamNull(approvalRetractVO, "自提登记审批撤回请求不为空");
		ToolKits.isParamNull(approvalRetractVO.getShipbillId(), "运单ID不为空");
		ToolKits.isParamNull(approvalRetractVO.getApprovalBusinessId(), "审批业务ID不为空");

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

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

		// 审核业务撤回
		RestMessage<Object> restMessage = maindataTmsResource.approvalRetractExecute(approvalRetractVO.getApprovalBusinessId());
		if (!restMessage.isSuccess()) {
			throw new RuntimeException("调用审核撤回失败:" + restMessage.getMessage());
		}
	}

	/**
	 * 自提登记审批流提交
	 *
	 * @param approvalSubmitVO
	 */
	public void regApprovalSubmitData(SelfPickUpRegApprovalInfoVO approvalSubmitVO) {
		ToolKits.isParamNull(approvalSubmitVO, "调度单审批提交请求不为空");
		ToolKits.isParamNull(approvalSubmitVO.getShipbillId(), "运单ID不为空");
		ToolKits.isParamNull(approvalSubmitVO.getApprovalBusinessId(), "审批业务ID不为空");

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

		// 提交当前审批
		RestMessage<Object> restMessage1 = maindataTmsResource.approvalSubmitExecute(approvalSubmitVO.getApprovalBusinessId());
		if (!restMessage1.isSuccess()) {
			throw new RuntimeException("调用审批提交失败:" + restMessage1.getMessage());
		}
	}

	/**
	 * 自提登记审批流审核
	 *
	 * @param approvalVO
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void regApprovalData(SelfPickUpApprovalVO approvalVO) {
		ToolKits.isParamNull(approvalVO, "自提登记审核请求不为空");
		ToolKits.isParamNull(approvalVO.getApprovalObjectId(), "运单ID不为空");
		ToolKits.isParamNull(approvalVO.getApprovalBusinessId(), "审批业务ID不为空");
		ToolKits.isParamNull(approvalVO.getApprovalObjectName(), "审批对象名称不为空");
		ToolKits.isParamNull(approvalVO.getApprovalId(), "审批流程ID不为空");
		ToolKits.isParamNull(approvalVO.getNextApproverNodeId(), "下一审批节点ID不为空");
		ToolKits.isParamNull(approvalVO.getNextApprovalOrder(), "下一节点顺序不为空");

		ToolKits.isParamNull(approvalVO.getResult(), "审批结果不为空");

		if (!approvalVO.getResult().equals(DataDictionaryConstant.NODE_APPROVAL_RESULT_PASS)) {
			ToolKits.isParamNull(approvalVO.getApprovalOpinion(), "驳回意见不为空");
		}

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

		TmsShipbillHeaderModel tmsShipbillHeaderModel = tmsShipbillHeaderMapper.findById(approvalVO.getApprovalObjectId(), TmsShipbillHeaderModel.class);
		ToolKits.isParamNull(tmsShipbillHeaderModel, "运单【" + approvalVO.getApprovalObjectId() + "】不存在");
		if (!tmsShipbillHeaderModel.getStatus().equals(DataDictionaryConstant.SHIPBILL_STATUS_HD_ZT_APPROVAL)) {
			throw new PrologException("运单【" + approvalVO.getApprovalObjectId() + "】已审批");
		}

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

		// 封装审核所需数据
		ApprovalBusinessNodeVO approvalBusinessNodeVO = new ApprovalBusinessNodeVO();
		approvalBusinessNodeVO.setApprovalObjectName(approvalVO.getApprovalObjectName());
		approvalBusinessNodeVO.setApprovalBusinessId(approvalVO.getApprovalBusinessId());
		approvalBusinessNodeVO.setApprovalId(approvalVO.getApprovalId());
		approvalBusinessNodeVO.setNextApprovalNodeId(approvalVO.getNextApproverNodeId());
		approvalBusinessNodeVO.setNextApprovalOrder(approvalVO.getNextApprovalOrder());
		approvalBusinessNodeVO.setNextApproverRoleId(approvalVO.getNextApproverRoleId());
		approvalBusinessNodeVO.setNextApproverRoleName(approvalVO.getNextApproverRoleName());
		approvalBusinessNodeVO.setNextApproverUserId(approvalVO.getNextApproverUserId());
		approvalBusinessNodeVO.setNextApproverUserName(approvalVO.getNextApproverUserName());
		approvalBusinessNodeVO.setApproverPersonId(user.getUserid());
		approvalBusinessNodeVO.setApproverPersonName(user.getNickname());
		approvalBusinessNodeVO.setApprovalOpinion(ToolKits.isEmpty(approvalVO.getApprovalOpinion()) ? "" : approvalVO.getApprovalOpinion());
		approvalBusinessNodeVO.setApprovalTime(date);
		approvalBusinessNodeVO.setResult(approvalVO.getResult());

		approvalBusinessNodeVO.setApproverPersonRoleId(user.getRoles().stream().map(role -> String.valueOf(role)).collect(Collectors.joining(",")));
		approvalBusinessNodeVO.setApproverPersonRoleName("");

		approvalBusinessNodeVO.setNodeApproverType(approvalVO.getNodeApproverType());
		approvalBusinessNodeVO.setNodeApprovalType(approvalVO.getNodeApprovalType());

		// 流程节点审批
		RestMessage<Boolean> restMessage1 = maindataTmsResource.nodeApprovalExecute(approvalBusinessNodeVO);
		if (!restMessage1.isSuccess()) {
			throw new RuntimeException("调用审核失败:" + restMessage1.getMessage());
		}
		Boolean isFinish = restMessage1.getData();

		// 判断是否已结束流程
		if (isFinish) {
			// 客户数
			int customerNumber = 0;
			Long consigneeUnitId = new Long(0);
			// 站点数
			int siteNumber = 0;
			String consigneeAddress = "";
			// 总件数
			BigDecimal goodsTotalPcs = new BigDecimal(0);
			// 总体积
			BigDecimal goodsTotalVolume = new BigDecimal(0);
			// 总重量
			BigDecimal goodsTotalWeight = new BigDecimal(0);

			// 默认配送顺序
			int shippingOrder = 1;
			TmsShipbillHeaderModel headerModel = tmsShipbillHeaderMapper.findById(approvalVO.getApprovalObjectId(), TmsShipbillHeaderModel.class);

			// 重复自提登记
			Criteria criteriaLoadingBillDetail = Criteria.forClass(TmsLoadingBillDetailModel.class);
			Restriction r2 = Restrictions.eq(TmsLoadingBillDetailModel::getShipbillId, approvalVO.getApprovalObjectId());
			criteriaLoadingBillDetail.setRestriction(Restrictions.and(r2));
			List<TmsLoadingBillDetailModel> tmsLoadingBillDetailModels = tmsLoadingBillDetailMapper.findByCriteria(criteriaLoadingBillDetail);
			if (ToolKits.isNotEmpty(tmsLoadingBillDetailModels)) {
				throw new PrologException("运单【" + approvalVO.getApprovalObjectId() + "】已经做过自提车辆登记");
			}

			// 运单节点表
			ShipbillNodeTrackingSaveNewVO shipbillNodeTrackingSaveNewVO = new ShipbillNodeTrackingSaveNewVO();
			shipbillNodeTrackingSaveNewVO.setNodeDate(date);
			shipbillNodeTrackingSaveNewVO.setShipbillId(approvalVO.getApprovalObjectId());
			shipbillNodeTrackingSaveNewVO.setShipbillNo(approvalVO.getApprovalObjectId());
			shipbillNodeTrackingSaveNewVO.setStatus(headerModel.getStatus());
			shipbillNodeTrackingSaveNewVO.setNodeEvent(DataDictionaryConstant.SHIPBILL_NODE_SELF_PICK_VEH_REG);
			shipbillNodeTrackingSaveNewVO.setUserId(user.getUserid());
			shipbillNodeTrackingSaveNewVO.setUserName(user.getNickname());
			shipbillNodeTrackingSaveNewVO.setEnterpriseId(user.getEnterpriseId());
			shipbillNodeTrackingSaveNewVO.setEnterpriseName(user.getEnterpriseName());
			shipbillNodeTrackingService.addShipbillNodeTrackingNewData(shipbillNodeTrackingSaveNewVO);

			goodsTotalPcs = goodsTotalPcs.add(headerModel.getTotalPcs());
			goodsTotalVolume = goodsTotalVolume.add(headerModel.getTotalVolume());
			goodsTotalWeight = goodsTotalWeight.add(headerModel.getTotalWeight());

			if (!consigneeUnitId.equals(headerModel.getConsigneeUnitId())) {
				customerNumber++;
				consigneeUnitId = headerModel.getConsigneeUnitId();
			}
			if (!consigneeAddress.equals(headerModel.getConsigneeAddress())) {
				siteNumber++;
				consigneeAddress = headerModel.getConsigneeAddress();
			}
			// 判定下一步流程
			int status = businessFlowUtil.judgmentNextFlowSts(headerModel.getFlowConfig(), DataDictionaryConstant.FLOW_CONFIG_SELF_PICKUP_VEH_REG);

			// 获取装车单ID
			RestMessage<String> restMessageLoad = maindataTmsResource.getCodeNumberByCode(SeriaNnumberConstant.TMS_LOADING_BILL_HEADER_ID, "L");
			if (!restMessageLoad.isSuccess()) {
				throw new RuntimeException("生成装车单ID失败");
			}
			String loadingBillId = restMessageLoad.getData();

			// 生成调度单明细表
			TmsLoadingBillDetailModel loadingBillDetailModel = new TmsLoadingBillDetailModel();
			RestMessage<String> restMessage2 = maindataTmsResource.getCodeNumberByCode(SeriaNnumberConstant.TMS_LOADING_BILL_DETAIL_ID, "L");
			if (!restMessage2.isSuccess()) {
				throw new RuntimeException("生成装车单明细ID失败");
			}
			String loadingBillDetailId = restMessage2.getData();

			// 查询明细内容
			Criteria criteria = Criteria.forClass(TmsShipbillTransLogModel.class);
			Restriction r1 = Restrictions.eq(TmsShipbillTransLogModel::getShipbillId, approvalVO.getApprovalObjectId());
			criteria.setRestriction(r1);
			List<TmsShipbillTransLogModel> shipbillTransLogModels = tmsShipbillTransportLogMapper.findByCriteria(criteria);
			if (ToolKits.isEmpty(shipbillTransLogModels)) {
				throw new PrologException("运单【" + approvalVO.getApprovalObjectId() + "】的自提登记信息不存在");
			}

			VehicleAndVehicleVO vehicleAndVehicleVO = new VehicleAndVehicleVO();
			vehicleAndVehicleVO.setDriverName(shipbillTransLogModels.get(0).getSelfPickUpPerson());
			vehicleAndVehicleVO.setPhoneNumber(shipbillTransLogModels.get(0).getSelfPickUpTel());
			vehicleAndVehicleVO.setVehiclePlateNumber(shipbillTransLogModels.get(0).getVehiclePlateNumber());
			RestMessage<VehicleAndDriverDTO> restMessageDriver = maindataTmsResource.vehicleAutomaticExecute(vehicleAndVehicleVO);
			if (!restMessageDriver.isSuccess()) {
				throw new ParameterException("自提登记司机信息取得失败:" + restMessageDriver.getMessage());
			}
			// 车辆司机信息
			VehicleAndDriverDTO vehicleAndDriverDTO = restMessageDriver.getData();

			BeanUtils.copyProperties(headerModel, loadingBillDetailModel);

			loadingBillDetailModel.setStatus(status);
			loadingBillDetailModel.setId(loadingBillDetailId);
			loadingBillDetailModel.setShippingOrder(shippingOrder++);
			loadingBillDetailModel.setLoadingBillId(loadingBillId);
			loadingBillDetailModel.setLoadingBillNo(loadingBillId);
			loadingBillDetailModel.setEnterpriseId(user.getEnterpriseId());
			loadingBillDetailModel.setEnterpriseName(user.getEnterpriseName());
			loadingBillDetailModel.setCreateperson(user.getNickname());
			loadingBillDetailModel.setCreatetime(date);
			loadingBillDetailModel.setUpdateperson(user.getNickname());
			loadingBillDetailModel.setUpdatetime(date);
			loadingBillDetailModel.setCarrierId(vehicleAndDriverDTO.getDriver().getDriverId());
			loadingBillDetailModel.setCarrierCode(vehicleAndDriverDTO.getDriver().getDriverCode());
			loadingBillDetailModel.setCarrierName(vehicleAndDriverDTO.getDriver().getDriverName());
			loadingBillDetailModel.setCarrierType(DataDictionaryConstant.LINE_CARRIER_TYPE_ZT);

			// 保存调度单明细
			tmsLoadingBillDetailMapper.save(loadingBillDetailModel);

			// 更新运单状态
			headerModel.setStatus(status);
			headerModel.setUpdatetime(date);
			headerModel.setUpdateperson(user.getNickname());
			tmsShipbillHeaderMapper.update(headerModel);
			MessageUtil.addMessage(new SendMessageDTO(MessageOrderTypeEnum.SHIP_NO.getCode(), MessageTypeEnum.SELF_VEHICLE_REGISTER.getCode(), Lists.newArrayList(headerModel.getShipbillId())));

			TmsLoadingBillHeaderModel loadingBillHeaderModel = new TmsLoadingBillHeaderModel();
			loadingBillHeaderModel.setSiteNumber(siteNumber);
			loadingBillHeaderModel.setCustomerNumber(customerNumber);
			loadingBillHeaderModel.setTotalPcs(goodsTotalPcs);
			loadingBillHeaderModel.setTotalVolume(goodsTotalVolume);
			loadingBillHeaderModel.setTotalWeight(goodsTotalWeight);
			loadingBillHeaderModel.setActualTotalPcs(goodsTotalPcs);
			loadingBillHeaderModel.setActualTotalVolume(goodsTotalVolume);
			loadingBillHeaderModel.setActualTotalWeight(goodsTotalWeight);
			// 运单数
			loadingBillHeaderModel.setShipbillNumber(1);
			loadingBillHeaderModel.setCarrierName(vehicleAndDriverDTO.getDriver().getDriverName());
			loadingBillHeaderModel.setDeliverymanName(vehicleAndDriverDTO.getDriver().getDriverName());
			loadingBillHeaderModel.setDriverId(vehicleAndDriverDTO.getDriver().getDriverId());
			loadingBillHeaderModel.setDriverCode(vehicleAndDriverDTO.getDriver().getDriverCode());
			loadingBillHeaderModel.setDriverName(vehicleAndDriverDTO.getDriver().getDriverName());
			loadingBillHeaderModel.setDriverPhoneNumber(vehicleAndDriverDTO.getDriver().getDriverPhoneNumber());
			loadingBillHeaderModel.setVehicleId(ToolKits.isEmpty(vehicleAndDriverDTO.getVehicle()) ? null : vehicleAndDriverDTO.getVehicle().getVehicleId());
			loadingBillHeaderModel.setVehicleCode(ToolKits.isEmpty(vehicleAndDriverDTO.getVehicle()) ? null : vehicleAndDriverDTO.getVehicle().getVehicleCode());
			loadingBillHeaderModel.setVehicleName(ToolKits.isEmpty(vehicleAndDriverDTO.getVehicle()) ? null : vehicleAndDriverDTO.getVehicle().getVehicleName());
			loadingBillHeaderModel.setVehiclePlateNumber(vehicleAndDriverDTO.getVehicle().getVehiclePlateNumber());
			// 调度类型
			loadingBillHeaderModel.setScheduleType(DataDictionaryConstant.SCHEDULE_TYPE_ZY);
			// 承运方类型
			loadingBillHeaderModel.setCarrierType(DataDictionaryConstant.LINE_CARRIER_TYPE_ZT);
			loadingBillHeaderModel.setLoadingBillId(loadingBillId);
			loadingBillHeaderModel.setLoadingBillNo(loadingBillId);
			loadingBillHeaderModel.setLoadingBillDate(date);
			// 自提
			loadingBillHeaderModel.setStatus(DataDictionaryConstant.LOADING_BILL_STATUS_YSH);
			loadingBillHeaderModel.setEnterpriseId(user.getEnterpriseId());
			loadingBillHeaderModel.setEnterpriseName(user.getEnterpriseName());
			loadingBillHeaderModel.setCreatetime(date);
			loadingBillHeaderModel.setCreateperson(user.getNickname());
			loadingBillHeaderModel.setUpdateperson(user.getNickname());
			loadingBillHeaderModel.setUpdatetime(date);

			loadingBillHeaderModel.setLoadingBillDate(date);

			loadingBillHeaderModel.setScanStatus(DataDictionaryConstant.SCAN_STATUS_INIT);
			tmsLoadingBillHeaderMapper.save(loadingBillHeaderModel);

			// 运单日志保存
			ShipbillOperateLogSaveNewVO shipbillOperateLogSaveNewVO = new ShipbillOperateLogSaveNewVO();
			shipbillOperateLogSaveNewVO.setShipbillId(approvalVO.getApprovalObjectId());
			shipbillOperateLogSaveNewVO.setShipbillNo(approvalVO.getApprovalObjectId());
			shipbillOperateLogSaveNewVO.setOperateEvent(DataDictionaryConstant.SHIPBILL_STATUSNAME_DZT_DJ);
			shipbillOperateLogSaveNewVO.setOldStatus(DataDictionaryConstant.SHIPBILL_STATUS_REVIEW);
			shipbillOperateLogSaveNewVO.setNewStatus(status);
			shipbillOperateLogSaveNewVO.setOperateDate(date);
			shipbillOperateLogSaveNewVO.setEnterpriseId(user.getEnterpriseId());
			shipbillOperateLogSaveNewVO.setEnterpriseName(user.getEnterpriseName());
			shipbillOperateLogSaveNewVO.setUserId(user.getUserid());
			shipbillOperateLogSaveNewVO.setUserName(user.getNickname());
			shipbillOperateLogService.addShipbillOperateLogNewData(shipbillOperateLogSaveNewVO);
		}
	}

	// 自提登记审核匹配审批流程
	public Boolean approvalOpen(TmsShipbillHeaderModel model, Integer approvalFlowType, UserEntity user) {
		// 封装判断所需数据
		ApprovalOpenVO approvalOpenVO = new ApprovalOpenVO();
		approvalOpenVO.setApprovalFlowType(approvalFlowType);
		approvalOpenVO.setApprovalObjectId(model.getShipbillId());
		approvalOpenVO.setApprovalObjectCode(model.getShipbillNo());
		approvalOpenVO.setApprovalObjectName(model.getShipbillNo());
		approvalOpenVO.setInitiatedUserId(user.getUserid());
		approvalOpenVO.setInitiatedUserName(user.getNickname());

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

		RestMessage<Boolean> restMessage1 = maindataTmsResource.openExecute(approvalOpenVO);
		if (!restMessage1.isSuccess()) {
			throw new RuntimeException("调用maindata服务是否开启审批流接口失败:" + restMessage1.getMessage());
		}
		return restMessage1.getData();
	}
	// STD-DEVELOP20220823 lhb bwc0825001 20220905 自提登记审批流 end
}
