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

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.web.multipart.MultipartFile;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.prolog.common.util.ToolKits;
import com.prolog.cs.platform.power.model.Organization;
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.RabbitMQConstant;
import com.prolog.rdc.tms.constant.SeriaNnumberConstant;
import com.prolog.rdc.tms.constant.StatusConstant;
import com.prolog.rdc.tms.dao.mapper.LmsTmsZoneMapper;
import com.prolog.rdc.tms.dao.mapper.TmsBaseCargoOwnerMapper;
import com.prolog.rdc.tms.dao.mapper.TmsBaseProviderMapper;
import com.prolog.rdc.tms.dao.mapper.TmsBaseShipperMapper;
import com.prolog.rdc.tms.dao.mapper.TmsProviderShipperLinkMapper;
import com.prolog.rdc.tms.model.dto.IntfErrorLogDTO;
import com.prolog.rdc.tms.model.dto.SysRefdatadDTO;
import com.prolog.rdc.tms.model.dto.basicConfigure.StandardTemplateDetailsListDTO;
import com.prolog.rdc.tms.model.dto.basicData.ImportMatchingDataDTO;
import com.prolog.rdc.tms.model.dto.basicData.ProviderByCargoOwnerPopupDTO;
import com.prolog.rdc.tms.model.dto.basicData.ProviderByIdsDTO;
import com.prolog.rdc.tms.model.dto.basicData.ProviderCheckDTO;
import com.prolog.rdc.tms.model.dto.basicData.ProviderConsigneeAndShipperPopupDTO;
import com.prolog.rdc.tms.model.dto.basicData.ProviderImportPageDTO;
import com.prolog.rdc.tms.model.dto.basicData.ProviderPagingQueryDTO;
import com.prolog.rdc.tms.model.dto.basicData.ProviderQueryPopupDTO;
import com.prolog.rdc.tms.model.dto.basicData.ProviderShipperCheckDTO;
import com.prolog.rdc.tms.model.dto.basicData.ProviderShipperImportPageDTO;
import com.prolog.rdc.tms.model.dto.basicData.ProviderShipperPagingQueryDTO;
import com.prolog.rdc.tms.model.dto.basicData.ProviderShipperPopupDTO;
import com.prolog.rdc.tms.model.dto.basicData.ShipperByIdsDTO;
import com.prolog.rdc.tms.model.dto.basicData.UserProviderPopupDTO;
import com.prolog.rdc.tms.model.entity.LmsTmsZoneModel;
import com.prolog.rdc.tms.model.entity.line.TmsBaseCargoOwnerModel;
import com.prolog.rdc.tms.model.entity.line.TmsBaseProviderModel;
import com.prolog.rdc.tms.model.entity.line.TmsBaseShipperModel;
import com.prolog.rdc.tms.model.entity.line.TmsProviderShipperLinkModel;
import com.prolog.rdc.tms.model.vo.IntfProviderSaveVO;
import com.prolog.rdc.tms.model.vo.IntfProviderShipperSaveVO;
import com.prolog.rdc.tms.model.vo.SysRefdatadQueryVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.ImportLogAddVO;
import com.prolog.rdc.tms.model.vo.basicConfigure.ImportPageVO;
import com.prolog.rdc.tms.model.vo.basicData.ImportMatchingDataVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderAddVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderByCargoOwnerPopupVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderByIdVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderByIdsVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderCheckVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderConsigneeAndShipperPopupVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderCopyVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderGeocodingVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderModifyVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderPagingQueryVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderPopupVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderShipperAddVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderShipperByIdVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderShipperCheckVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderShipperModifyVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderShipperPagingQueryVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderShipperPopupVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderShipperWhetherEnableVO;
import com.prolog.rdc.tms.model.vo.basicData.ProviderWhetherEnableVO;
import com.prolog.rdc.tms.model.vo.basicData.ShipperByIdsVO;
import com.prolog.rdc.tms.model.vo.basicData.UserProviderPopupVO;
import com.prolog.rdc.tms.model.vo.xlsimport.ProviderImportStdVO;
import com.prolog.rdc.tms.model.vo.xlsimport.ShipperImportStdVO;
import com.prolog.rdc.tms.rmi.feign.UserFeign;
import com.prolog.rdc.tms.service.SysCodeengineService;
import com.prolog.rdc.tms.service.SysRefdatadService;
import com.prolog.rdc.tms.service.basicConfigure.ImportLogService;
import com.prolog.rdc.tms.service.basicConfigure.SysImportTemplethService;
import com.prolog.rdc.tms.service.basicData.ProviderService;
import com.prolog.rdc.tms.util.FileUtils;
import com.prolog.rdc.tms.util.ImportUtils;
import com.prolog.rdc.tms.util.PublicMethods;
import com.prolog.wms.base.util.ExcelUtils;
import com.prolog.wms.base.util.JsonMapper;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Validator;
import lombok.extern.slf4j.Slf4j;

/**
 * 基础资料-供应商服务实现层
 *
 * @author Eton Woo
 * @date 2022/03/25
 */
@Slf4j
@Service
public class ProviderServiceImpl implements ProviderService {

	@Autowired
	private TmsBaseProviderMapper tmsBaseProviderMapper;

	@Autowired
	private TmsBaseShipperMapper tmsBaseShipperMapper;

	@Autowired
	private TmsProviderShipperLinkMapper tmsProviderShipperLinkMapper;

	@Autowired
	private SysCodeengineService sysCodeengineService;

	@Autowired
	private SysRefdatadService sysRefdatadService;

	@Autowired
	private SysImportTemplethService sysImportTemplethService;

	@Autowired
	private ImportLogService importLogService;

	@Autowired
	private LmsTmsZoneMapper lmsTmsZoneMapper;

	@Autowired
	private TmsBaseCargoOwnerMapper tmsBaseCargoOwnerMapper;

	@Autowired
	private UserFeign userFeign;

	@Autowired
	private AmqpTemplate amqpTemplate;

	/**
	 * 供应商资料分页查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<ProviderPagingQueryDTO> pageProviderData(ProviderPagingQueryVO providerPagingQueryVO) {
		ToolKits.isParamNull(providerPagingQueryVO, "供应商资料查询请求不为空");
		ToolKits.isParamNull(providerPagingQueryVO.getPageNum(), "页码不为空");
		ToolKits.isParamNull(providerPagingQueryVO.getPageSize(), "页数不为空");

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

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

		// 合同性质
		List<Map<String, Object>> restMessage1 = sysRefdatadService.getDropDownById(DataDictionaryConstant.CONTRACT_NATURE, null, null, null);
		// 开户行
		List<Map<String, Object>> restMessage2 = sysRefdatadService.getDropDownById(DataDictionaryConstant.BANK, null, null, null);
		// 供应商状态
		List<Map<String, Object>> restMessage3 = sysRefdatadService.getDropDownById(DataDictionaryConstant.MAINDATA_STATUS, null, null, null);
		// 提货签到 自动提货签到 提货图片 送达签到 自动送达签到 送货图片
		List<Map<String, Object>> restMessage4 = sysRefdatadService.getDropDownById(DataDictionaryConstant.WHETHER, null, null, null);

		SysRefdatadQueryVO sysrefdatadqueryvo = new SysRefdatadQueryVO();
		String[] objectcodes = { DataDictionaryConstant.PICK_UP_SIGN_TIME, // 提货签到时间点
				DataDictionaryConstant.DELIVERY_SIGN_TIME, // 送达签到时间点
				DataDictionaryConstant.SIGN_TIME_UNIT // 签到时间单位
		};
		sysrefdatadqueryvo.setObjectcodes(objectcodes);
		List<SysRefdatadDTO> sysrefdataddtos = new ArrayList<SysRefdatadDTO>();
		try {
			sysrefdataddtos = sysRefdatadService.getSysRefdatadData(sysrefdatadqueryvo);
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException("获取数据字典失败");
		}

		// 分页
		PageUtils.startPage(providerPagingQueryVO.getPageNum(), providerPagingQueryVO.getPageSize());

		Criteria criteria = Criteria.forClass(TmsBaseProviderModel.class);
		Restriction r1 = ToolKits.isEmpty(providerPagingQueryVO.getCode()) ? null : Restrictions.like("code", "%" + providerPagingQueryVO.getCode() + "%");
		Restriction r2 = ToolKits.isEmpty(providerPagingQueryVO.getName()) ? null : Restrictions.like("name", "%" + providerPagingQueryVO.getName() + "%");
		Restriction r3 = ToolKits.isEmpty(providerPagingQueryVO.getCargoOwnerName()) ? null : Restrictions.like("cargoOwnerName", "%" + providerPagingQueryVO.getCargoOwnerName() + "%");
		Restriction r4 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		Restriction r5 = null;
		Restriction r6 = null;
		// 判断账号类型
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 自有账号
			// 判断是否为部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				r6 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
			} else {
				r6 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
				r5 = Restrictions.in("id", user.getSuppliers().stream().toArray(Long[]::new));
			}
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_HZ)) {
			// 货主账号
			r5 = Restrictions.eq("cargoOwnerId", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_GYS)) {
			// 供应商账号
			r5 = Restrictions.eq("id", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			// 其他账号
			throw new RuntimeException("当前账号没有权限");
		}
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		List<TmsBaseProviderModel> tmsBaseProviderModels = tmsBaseProviderMapper.findByCriteria(criteria);
		for (TmsBaseProviderModel tmsBaseProviderModel : tmsBaseProviderModels) {
			// 响应对象
			ProviderPagingQueryDTO providerPagingQueryDTO = new ProviderPagingQueryDTO();
			BeanUtils.copyProperties(tmsBaseProviderModel, providerPagingQueryDTO);
			providerPagingQueryDTO.setContractNatureName(PublicMethods.change(restMessage1, String.valueOf(providerPagingQueryDTO.getContractNature())));
			providerPagingQueryDTO.setBankName(PublicMethods.change(restMessage2, String.valueOf(providerPagingQueryDTO.getBank())));
			providerPagingQueryDTO.setStatusName(PublicMethods.change(restMessage3, String.valueOf(providerPagingQueryDTO.getStatus())));
			providerPagingQueryDTO.setPickUpPictureName(PublicMethods.change(restMessage4, String.valueOf(providerPagingQueryDTO.getPickUpPicture())));
			providerPagingQueryDTO.setPickUpSignName(PublicMethods.change(restMessage4, String.valueOf(providerPagingQueryDTO.getPickUpSign())));
			providerPagingQueryDTO.setAutoPickUpSignName(PublicMethods.change(restMessage4, String.valueOf(providerPagingQueryDTO.getAutoPickUpSign())));
			providerPagingQueryDTO.setDeliveryPictureName(PublicMethods.change(restMessage4, String.valueOf(providerPagingQueryDTO.getDeliveryPicture())));
			providerPagingQueryDTO.setDeliverySignName(PublicMethods.change(restMessage4, String.valueOf(providerPagingQueryDTO.getDeliverySign())));
			providerPagingQueryDTO.setAutoDeliverySignName(PublicMethods.change(restMessage4, String.valueOf(providerPagingQueryDTO.getAutoDeliverySign())));

			for (SysRefdatadDTO sysrefdataddto : sysrefdataddtos) {
				if (DataDictionaryConstant.PICK_UP_SIGN_TIME.equals(sysrefdataddto.getObjectcode()) && sysrefdataddto.getCode().equals(String.valueOf(providerPagingQueryDTO.getPickUpSignTime()))) {
					providerPagingQueryDTO.setPickUpSignTimeName(sysrefdataddto.getName());
				}
				if (DataDictionaryConstant.SIGN_TIME_UNIT.equals(sysrefdataddto.getObjectcode()) && sysrefdataddto.getCode().equals(String.valueOf(providerPagingQueryDTO.getPickUpSignTimeUnit()))) {
					providerPagingQueryDTO.setPickUpSignTimeUnitName(sysrefdataddto.getName());
				}
				if (DataDictionaryConstant.DELIVERY_SIGN_TIME.equals(sysrefdataddto.getObjectcode()) && sysrefdataddto.getCode().equals(String.valueOf(providerPagingQueryDTO.getDeliverySignTime()))) {
					providerPagingQueryDTO.setDeliverySignTimeName(sysrefdataddto.getName());
				}
				if (DataDictionaryConstant.SIGN_TIME_UNIT.equals(sysrefdataddto.getObjectcode()) && sysrefdataddto.getCode().equals(String.valueOf(providerPagingQueryDTO.getDeliverySignTimeUnit()))) {
					providerPagingQueryDTO.setDeliverySignTimeUnitName(sysrefdataddto.getName());
				}
			}

			providerPagingQueryDTOs.add(providerPagingQueryDTO);
		}

		Page<ProviderPagingQueryDTO> page = PageUtils.getPage(providerPagingQueryDTOs);
		if (tmsBaseProviderModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsBaseProviderModel> p0 = (com.github.pagehelper.Page<TmsBaseProviderModel>) tmsBaseProviderModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/**
	 * 供应商根据货主查询弹窗
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<ProviderByCargoOwnerPopupDTO> popupProviderByCargoOwnerData(ProviderByCargoOwnerPopupVO providerByCargoOwnerPopupVO) {
		ToolKits.isParamNull(providerByCargoOwnerPopupVO, "供应商根据货主查询弹窗请求不为空");
		ToolKits.isParamNull(providerByCargoOwnerPopupVO.getPageNum(), "页码不为空");
		ToolKits.isParamNull(providerByCargoOwnerPopupVO.getPageSize(), "页数不为空");
		ToolKits.isParamNull(providerByCargoOwnerPopupVO.getCargoOwnerId(), "货主ID不为空");

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

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

		// 合同性质
		List<Map<String, Object>> restMessage1 = sysRefdatadService.getDropDownById(DataDictionaryConstant.CONTRACT_NATURE, null, null, null);
		// 开户行
		List<Map<String, Object>> restMessage2 = sysRefdatadService.getDropDownById(DataDictionaryConstant.BANK, null, null, null);
		// 提货签到 自动提货签到 提货图片 送达签到 自动送达签到 送货图片
		List<Map<String, Object>> restMessage4 = sysRefdatadService.getDropDownById(DataDictionaryConstant.WHETHER, null, null, null);

		SysRefdatadQueryVO sysrefdatadqueryvo = new SysRefdatadQueryVO();
		String[] objectcodes = { DataDictionaryConstant.PICK_UP_SIGN_TIME, // 提货签到时间点
				DataDictionaryConstant.DELIVERY_SIGN_TIME, // 送达签到时间点
				DataDictionaryConstant.SIGN_TIME_UNIT // 签到时间单位
		};
		sysrefdatadqueryvo.setObjectcodes(objectcodes);
		List<SysRefdatadDTO> sysrefdataddtos = new ArrayList<SysRefdatadDTO>();
		try {
			sysrefdataddtos = sysRefdatadService.getSysRefdatadData(sysrefdatadqueryvo);
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException("获取数据字典失败");
		}

		// 分页
		PageUtils.startPage(providerByCargoOwnerPopupVO.getPageNum(), providerByCargoOwnerPopupVO.getPageSize());

		Criteria criteria = Criteria.forClass(TmsBaseProviderModel.class);
		Restriction r1 = ToolKits.isEmpty(providerByCargoOwnerPopupVO.getCode()) ? null : Restrictions.like("code", "%" + providerByCargoOwnerPopupVO.getCode() + "%");
		Restriction r2 = ToolKits.isEmpty(providerByCargoOwnerPopupVO.getName()) ? null : Restrictions.like("name", "%" + providerByCargoOwnerPopupVO.getName() + "%");
		Restriction r3 = Restrictions.eq("cargoOwnerId", providerByCargoOwnerPopupVO.getCargoOwnerId());
		Restriction r4 = Restrictions.eq("status", StatusConstant.STATUS_ENABLE);
		Restriction r5 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		Restriction r6 = null;
		Restriction r7 = null;
		// 判断账号类型
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 自有账号
			// 判断是否为部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				r7 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
			} else {
				r7 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
				r6 = Restrictions.in("id", user.getSuppliers().stream().toArray(Long[]::new));
			}
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_HZ)) {
			// 货主账号
			r6 = Restrictions.eq("cargoOwnerId", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_GYS)) {
			// 供应商账号
			r6 = Restrictions.eq("id", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			// 其他账号
			throw new RuntimeException("当前账号没有权限");
		}
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		List<TmsBaseProviderModel> tmsBaseProviderModels = tmsBaseProviderMapper.findByCriteria(criteria);
		for (TmsBaseProviderModel tmsBaseProviderModel : tmsBaseProviderModels) {
			// 响应对象
			ProviderByCargoOwnerPopupDTO providerByCargoOwnerPopupDTO = new ProviderByCargoOwnerPopupDTO();
			BeanUtils.copyProperties(tmsBaseProviderModel, providerByCargoOwnerPopupDTO);
			providerByCargoOwnerPopupDTO.setContractNatureName(PublicMethods.change(restMessage1, String.valueOf(providerByCargoOwnerPopupDTO.getContractNature())));
			providerByCargoOwnerPopupDTO.setBankName(PublicMethods.change(restMessage2, String.valueOf(providerByCargoOwnerPopupDTO.getBank())));
			providerByCargoOwnerPopupDTO.setPickUpPictureName(PublicMethods.change(restMessage4, String.valueOf(providerByCargoOwnerPopupDTO.getPickUpPicture())));
			providerByCargoOwnerPopupDTO.setPickUpSignName(PublicMethods.change(restMessage4, String.valueOf(providerByCargoOwnerPopupDTO.getPickUpSign())));
			providerByCargoOwnerPopupDTO.setAutoPickUpSignName(PublicMethods.change(restMessage4, String.valueOf(providerByCargoOwnerPopupDTO.getAutoPickUpSign())));
			providerByCargoOwnerPopupDTO.setDeliveryPictureName(PublicMethods.change(restMessage4, String.valueOf(providerByCargoOwnerPopupDTO.getDeliveryPicture())));
			providerByCargoOwnerPopupDTO.setDeliverySignName(PublicMethods.change(restMessage4, String.valueOf(providerByCargoOwnerPopupDTO.getDeliverySign())));
			providerByCargoOwnerPopupDTO.setAutoDeliverySignName(PublicMethods.change(restMessage4, String.valueOf(providerByCargoOwnerPopupDTO.getAutoDeliverySign())));

			for (SysRefdatadDTO sysrefdataddto : sysrefdataddtos) {
				if (DataDictionaryConstant.PICK_UP_SIGN_TIME.equals(sysrefdataddto.getObjectcode()) && sysrefdataddto.getCode().equals(String.valueOf(providerByCargoOwnerPopupDTO.getPickUpSignTime()))) {
					providerByCargoOwnerPopupDTO.setPickUpSignTimeName(sysrefdataddto.getName());
				}
				if (DataDictionaryConstant.SIGN_TIME_UNIT.equals(sysrefdataddto.getObjectcode()) && sysrefdataddto.getCode().equals(String.valueOf(providerByCargoOwnerPopupDTO.getPickUpSignTimeUnit()))) {
					providerByCargoOwnerPopupDTO.setPickUpSignTimeUnitName(sysrefdataddto.getName());
				}
				if (DataDictionaryConstant.DELIVERY_SIGN_TIME.equals(sysrefdataddto.getObjectcode()) && sysrefdataddto.getCode().equals(String.valueOf(providerByCargoOwnerPopupDTO.getDeliverySignTime()))) {
					providerByCargoOwnerPopupDTO.setDeliverySignTimeName(sysrefdataddto.getName());
				}
				if (DataDictionaryConstant.SIGN_TIME_UNIT.equals(sysrefdataddto.getObjectcode()) && sysrefdataddto.getCode().equals(String.valueOf(providerByCargoOwnerPopupDTO.getDeliverySignTimeUnit()))) {
					providerByCargoOwnerPopupDTO.setDeliverySignTimeUnitName(sysrefdataddto.getName());
				}
			}

			providerByCargoOwnerPopupDTOs.add(providerByCargoOwnerPopupDTO);
		}

		Page<ProviderByCargoOwnerPopupDTO> page = PageUtils.getPage(providerByCargoOwnerPopupDTOs);
		if (tmsBaseProviderModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsBaseProviderModel> p0 = (com.github.pagehelper.Page<TmsBaseProviderModel>) tmsBaseProviderModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/**
	 * 供应商收发货方弹窗
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<ProviderConsigneeAndShipperPopupDTO> popupProviderConsigneeAndShipperData(ProviderConsigneeAndShipperPopupVO providerConsigneeAndShipperPopupVO) {
		ToolKits.isParamNull(providerConsigneeAndShipperPopupVO, "供应商弹窗请求不为空");
		ToolKits.isParamNull(providerConsigneeAndShipperPopupVO.getPageNum(), "页码不为空");
		ToolKits.isParamNull(providerConsigneeAndShipperPopupVO.getPageSize(), "页数不为空");
		ToolKits.isParamNull(providerConsigneeAndShipperPopupVO.getCargoOwnerId(), "货主ID不为空");

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

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

		// 查询供应商信息
		Criteria criteria = Criteria.forClass(TmsBaseProviderModel.class);
		Restriction r1 = ToolKits.isEmpty(providerConsigneeAndShipperPopupVO.getCode()) ? null : Restrictions.like("code", "%" + providerConsigneeAndShipperPopupVO.getCode() + "%");
		Restriction r2 = ToolKits.isEmpty(providerConsigneeAndShipperPopupVO.getName()) ? null : Restrictions.like("name", "%" + providerConsigneeAndShipperPopupVO.getName() + "%");
		Restriction r3 = Restrictions.eq("cargoOwnerId", providerConsigneeAndShipperPopupVO.getCargoOwnerId());
		Restriction r4 = Restrictions.eq("status", StatusConstant.STATUS_ENABLE);
		Restriction r5 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		Restriction r6 = null;
		Restriction r7 = null;
		// 判断账号类型
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 自有账号
			// 判断是否为部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				r7 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
			} else {
				r7 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
				r6 = Restrictions.in("id", user.getSuppliers().stream().toArray(Long[]::new));
			}
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_HZ)) {
			// 货主账号
			r6 = Restrictions.eq("cargoOwnerId", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_GYS)) {
			// 供应商账号
			r6 = Restrictions.eq("id", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			// 其他账号
			throw new RuntimeException("当前账号没有权限");
		}
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5, r6, r7));
		List<TmsBaseProviderModel> tmsBaseProviderModels = tmsBaseProviderMapper.findByCriteria(criteria);
		if (ToolKits.isNotEmpty(tmsBaseProviderModels)) {
			// 获取供应商ID
			Long[] providerIds = (tmsBaseProviderModels.stream().map(TmsBaseProviderModel::getId).distinct().collect(Collectors.toList())).stream().toArray(Long[]::new);

			// 查询供应商发货方关联表
			Criteria linkCriteria = Criteria.forClass(TmsProviderShipperLinkModel.class);
			Restriction linkR1 = Restrictions.in(TmsProviderShipperLinkModel::getProviderId, providerIds);
			linkCriteria.setRestriction(linkR1);
			List<TmsProviderShipperLinkModel> tmsProviderShipperLinkModels = tmsProviderShipperLinkMapper.findByCriteria(linkCriteria);

			// 获取发货方ID
			Long[] shipperIds = (tmsProviderShipperLinkModels.stream().map(TmsProviderShipperLinkModel::getShipperId).distinct().collect(Collectors.toList())).stream().toArray(Long[]::new);

			// 查询供应商发货方表
			Criteria criteria1 = Criteria.forClass(TmsBaseShipperModel.class);
			Restriction r11 = Restrictions.in("id", shipperIds);
			Restriction r12 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
			criteria1.setRestriction(Restrictions.and(r11, r12));
			criteria1.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
			PageUtils.startPage(providerConsigneeAndShipperPopupVO.getPageNum(), providerConsigneeAndShipperPopupVO.getPageSize());
			List<TmsBaseShipperModel> tmsBaseShipperModels = tmsBaseShipperMapper.findByCriteria(criteria1);
			for (TmsBaseShipperModel tmsBaseShipperModel : tmsBaseShipperModels) {
				// 筛选供应商发货方关联对象
				TmsProviderShipperLinkModel tmsProviderShipperLinkModel = tmsProviderShipperLinkModels.stream().filter(s -> s.getShipperId().longValue() == tmsBaseShipperModel.getId().longValue()).collect(Collectors.toList()).get(0);
				// 筛选供应商对象
				TmsBaseProviderModel tmsBaseProviderModel = tmsBaseProviderModels.stream().filter(s -> s.getId().longValue() == tmsProviderShipperLinkModel.getProviderId().longValue()).collect(Collectors.toList()).get(0);

				// 响应对象
				ProviderConsigneeAndShipperPopupDTO providerConsigneeAndShipperPopupDTO = new ProviderConsigneeAndShipperPopupDTO();
				providerConsigneeAndShipperPopupDTO.setShipperUnitId(tmsBaseProviderModel.getId());
				providerConsigneeAndShipperPopupDTO.setShipperUnitCode(tmsBaseProviderModel.getCode());
				providerConsigneeAndShipperPopupDTO.setShipperUnitName(tmsBaseProviderModel.getName());
				providerConsigneeAndShipperPopupDTO.setShipperId(tmsBaseShipperModel.getId());
				providerConsigneeAndShipperPopupDTO.setShipperCode(tmsBaseShipperModel.getCode());
				providerConsigneeAndShipperPopupDTO.setShipperName(tmsBaseShipperModel.getName());
				providerConsigneeAndShipperPopupDTO.setShipperContact(tmsBaseShipperModel.getContact());
				providerConsigneeAndShipperPopupDTO.setShipperPhoneNumber(tmsBaseShipperModel.getPhoneNumber());
				providerConsigneeAndShipperPopupDTO.setShipperLandlineNumber(tmsBaseShipperModel.getLandlineNumber());
				providerConsigneeAndShipperPopupDTO.setShipperEmail(tmsBaseShipperModel.getEmail());
				providerConsigneeAndShipperPopupDTO.setShipperRelatedPhoneNumber(null);
				providerConsigneeAndShipperPopupDTO.setShipperProvince(tmsBaseShipperModel.getProvince());
				providerConsigneeAndShipperPopupDTO.setShipperProvinceName(tmsBaseShipperModel.getProvinceName());
				providerConsigneeAndShipperPopupDTO.setShipperCity(tmsBaseShipperModel.getCity());
				providerConsigneeAndShipperPopupDTO.setShipperCityName(tmsBaseShipperModel.getCityName());
				providerConsigneeAndShipperPopupDTO.setShipperDistrict(tmsBaseShipperModel.getDistrict());
				providerConsigneeAndShipperPopupDTO.setShipperDistrictName(tmsBaseShipperModel.getDistrictName());
				providerConsigneeAndShipperPopupDTO.setShipperAddress(tmsBaseShipperModel.getAddress());
				providerConsigneeAndShipperPopupDTO.setShipperLongitude(tmsBaseShipperModel.getLongitude());
				providerConsigneeAndShipperPopupDTO.setShipperLatitude(tmsBaseShipperModel.getLatitude());
				providerConsigneeAndShipperPopupDTO.setShipperMemo(tmsBaseShipperModel.getMemo());
				providerConsigneeAndShipperPopupDTO.setShipperPickUpSign(tmsBaseProviderModel.getPickUpSign());
				providerConsigneeAndShipperPopupDTO.setShipperAutoPickUpSign(tmsBaseProviderModel.getAutoPickUpSign());
				providerConsigneeAndShipperPopupDTO.setShipperPickUpPicture(tmsBaseProviderModel.getPickUpPicture());
				providerConsigneeAndShipperPopupDTO.setShipperPickUpRail(tmsBaseProviderModel.getDefaultPickUpRail());

				providerConsigneeAndShipperPopupDTO.setConsigneeUnitId(tmsBaseProviderModel.getId());
				providerConsigneeAndShipperPopupDTO.setConsigneeUnitCode(tmsBaseProviderModel.getCode());
				providerConsigneeAndShipperPopupDTO.setConsigneeUnitName(tmsBaseProviderModel.getName());
				providerConsigneeAndShipperPopupDTO.setConsigneeId(tmsBaseShipperModel.getId());
				providerConsigneeAndShipperPopupDTO.setConsigneeCode(tmsBaseShipperModel.getCode());
				providerConsigneeAndShipperPopupDTO.setConsigneeName(tmsBaseShipperModel.getName());
				providerConsigneeAndShipperPopupDTO.setConsigneeContact(tmsBaseShipperModel.getContact());
				providerConsigneeAndShipperPopupDTO.setConsigneePhoneNumber(tmsBaseShipperModel.getPhoneNumber());
				providerConsigneeAndShipperPopupDTO.setConsigneeLandlineNumber(tmsBaseShipperModel.getLandlineNumber());
				providerConsigneeAndShipperPopupDTO.setConsigneeEmail(tmsBaseShipperModel.getEmail());
				providerConsigneeAndShipperPopupDTO.setConsigneeRelatedPhoneNumber(null);
				providerConsigneeAndShipperPopupDTO.setConsigneeProvince(tmsBaseShipperModel.getProvince());
				providerConsigneeAndShipperPopupDTO.setConsigneeProvinceName(tmsBaseShipperModel.getProvinceName());
				providerConsigneeAndShipperPopupDTO.setConsigneeCity(tmsBaseShipperModel.getCity());
				providerConsigneeAndShipperPopupDTO.setConsigneeCityName(tmsBaseShipperModel.getCityName());
				providerConsigneeAndShipperPopupDTO.setConsigneeDistrict(tmsBaseShipperModel.getDistrict());
				providerConsigneeAndShipperPopupDTO.setConsigneeDistrictName(tmsBaseShipperModel.getDistrictName());
				providerConsigneeAndShipperPopupDTO.setConsigneeAddress(tmsBaseShipperModel.getAddress());
				providerConsigneeAndShipperPopupDTO.setConsigneeLongitude(tmsBaseShipperModel.getLongitude());
				providerConsigneeAndShipperPopupDTO.setConsigneeLatitude(tmsBaseShipperModel.getLatitude());
				providerConsigneeAndShipperPopupDTO.setConsigneeMemo(tmsBaseShipperModel.getMemo());
				providerConsigneeAndShipperPopupDTO.setConsigneeDeliverySign(tmsBaseProviderModel.getDeliverySign());
				providerConsigneeAndShipperPopupDTO.setConsigneeAutoDeliverySign(tmsBaseProviderModel.getAutoDeliverySign());
				providerConsigneeAndShipperPopupDTO.setConsigneeDeliveryPicture(tmsBaseProviderModel.getDeliveryPicture());
				providerConsigneeAndShipperPopupDTO.setConsigneeDeliveryRail(tmsBaseProviderModel.getDefaultDeliveryRail());
				providerConsigneeAndShipperPopupDTO.setReturnOrderFlag(null);
				providerConsigneeAndShipperPopupDTO.setReturnOrderDeadline(null);
				providerConsigneeAndShipperPopupDTO.setConsigneeReturnOrderPicture(tmsBaseProviderModel.getReturnOrderPicture());

				providerConsigneeAndShipperPopupDTO.setPickUpSignTime(tmsBaseProviderModel.getPickUpSignTime());
				providerConsigneeAndShipperPopupDTO.setPickUpSignTimeDura(tmsBaseProviderModel.getPickUpSignTimeDura());
				providerConsigneeAndShipperPopupDTO.setPickUpSignTimeUnit(tmsBaseProviderModel.getPickUpSignTimeUnit());
				providerConsigneeAndShipperPopupDTO.setDeliverySignTime(tmsBaseProviderModel.getDeliverySignTime());
				providerConsigneeAndShipperPopupDTO.setDeliverySignTimeDura(tmsBaseProviderModel.getDeliverySignTimeDura());
				providerConsigneeAndShipperPopupDTO.setDeliverySignTimeUnit(tmsBaseProviderModel.getDeliverySignTimeUnit());

				providerConsigneeAndShipperPopupDTOs.add(providerConsigneeAndShipperPopupDTO);
			}

			Page<ProviderConsigneeAndShipperPopupDTO> page = PageUtils.getPage(providerConsigneeAndShipperPopupDTOs);
			if (tmsBaseShipperModels instanceof com.github.pagehelper.Page) {
				com.github.pagehelper.Page<TmsBaseShipperModel> p0 = (com.github.pagehelper.Page<TmsBaseShipperModel>) tmsBaseShipperModels;
				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;
		}

		return null;
	}

	/**
	 * 供应商查询弹窗
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<ProviderQueryPopupDTO> popupProviderData(ProviderPopupVO providerPopupVO) {
		ToolKits.isParamNull(providerPopupVO, "供应商查询弹窗请求不为空");
		ToolKits.isParamNull(providerPopupVO.getPageNum(), "页码不为空");
		ToolKits.isParamNull(providerPopupVO.getPageSize(), "页数不为空");

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

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

		// 分页
		PageUtils.startPage(providerPopupVO.getPageNum(), providerPopupVO.getPageSize());

		Criteria criteria = Criteria.forClass(TmsBaseProviderModel.class);
		Restriction r1 = ToolKits.isEmpty(providerPopupVO.getCode()) ? null : Restrictions.like("code", "%" + providerPopupVO.getCode() + "%");
		Restriction r2 = ToolKits.isEmpty(providerPopupVO.getName()) ? null : Restrictions.like("name", "%" + providerPopupVO.getName() + "%");
		Restriction r4 = Restrictions.eq("status", StatusConstant.STATUS_ENABLE);
		Restriction r5 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		Restriction r6 = null;
		Restriction r7 = null;
		// 判断账号类型
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 自有账号
			// 判断是否为部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				r7 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
			} else {
				r7 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
				r6 = Restrictions.in("id", user.getSuppliers().stream().toArray(Long[]::new));
			}
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_HZ)) {
			// 货主账号
			r6 = Restrictions.eq("cargoOwnerId", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_GYS)) {
			// 供应商账号
			r6 = Restrictions.eq("id", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			// 其他账号
			throw new RuntimeException("当前账号没有权限");
		}
		criteria.setRestriction(Restrictions.and(r1, r2, r4, r5, r6, r7));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		List<TmsBaseProviderModel> tmsBaseProviderModels = tmsBaseProviderMapper.findByCriteria(criteria);
		for (TmsBaseProviderModel tmsBaseProviderModel : tmsBaseProviderModels) {
			// 响应对象
			ProviderQueryPopupDTO providerQueryPopupDTO = new ProviderQueryPopupDTO();
			BeanUtils.copyProperties(tmsBaseProviderModel, providerQueryPopupDTO);

			providerQueryPopupDTOs.add(providerQueryPopupDTO);
		}

		Page<ProviderQueryPopupDTO> page = PageUtils.getPage(providerQueryPopupDTOs);
		if (tmsBaseProviderModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsBaseProviderModel> p0 = (com.github.pagehelper.Page<TmsBaseProviderModel>) tmsBaseProviderModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/**
	 * 用户供应商弹窗
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<UserProviderPopupDTO> popupUserProviderData(UserProviderPopupVO userProviderPopupVO) {
		ToolKits.isParamNull(userProviderPopupVO, "供应商弹窗请求不为空");
		ToolKits.isParamNull(userProviderPopupVO.getPageNum(), "页码不为空");
		ToolKits.isParamNull(userProviderPopupVO.getPageSize(), "页数不为空");

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

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

		// 分页
		PageUtils.startPage(userProviderPopupVO.getPageNum(), userProviderPopupVO.getPageSize());

		Criteria criteria = Criteria.forClass(TmsBaseProviderModel.class);
		Restriction r1 = Restrictions.like("code", "%" + userProviderPopupVO.getSearch() + "%");
		Restriction r2 = Restrictions.like("name", "%" + userProviderPopupVO.getSearch() + "%");
		Restriction r3 = ToolKits.isEmpty(userProviderPopupVO.getSearch()) ? null : Restrictions.or(r1, r2);

		Restriction r10 = Restrictions.like("code", "%" + userProviderPopupVO.getSupplierNoName() + "%");
		Restriction r11 = Restrictions.like("name", "%" + userProviderPopupVO.getSupplierNoName() + "%");
		Restriction r12 = ToolKits.isEmpty(userProviderPopupVO.getSupplierNoName()) ? null : Restrictions.or(r10, r11);

		Restriction r4 = Restrictions.eq("status", StatusConstant.STATUS_ENABLE);
		Restriction r5 = Restrictions.eq("enterpriseId", user.getEnterpriseId());

		Restriction r6 = null;
		Restriction r7 = null;
		// 判断账号类型
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			// 自有账号
			// 判断是否为部门权限
			if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
				r6 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
			} else {
				r6 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
				r7 = Restrictions.in("id", user.getSuppliers().stream().toArray(Long[]::new));
			}
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_HZ)) {
			// 货主账号
			r6 = Restrictions.eq("cargoOwnerId", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_GYS)) {
			// 供应商账号
			r6 = Restrictions.eq("id", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			// 其他账号
			throw new RuntimeException("当前账号没有权限");
		}
		criteria.setRestriction(Restrictions.and(r3, r4, r5, r6, r7, r12));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		List<TmsBaseProviderModel> tmsBaseProviderModels = tmsBaseProviderMapper.findByCriteria(criteria);
		for (TmsBaseProviderModel tmsBaseProviderModel : tmsBaseProviderModels) {
			// 响应对象
			UserProviderPopupDTO userProviderPopupDTO = new UserProviderPopupDTO();
			userProviderPopupDTO.setId(tmsBaseProviderModel.getId());
			userProviderPopupDTO.setSupplierId(tmsBaseProviderModel.getId());
			userProviderPopupDTO.setSupplierCode(tmsBaseProviderModel.getCode());
			userProviderPopupDTO.setSupplierName(tmsBaseProviderModel.getName());
			userProviderPopupDTOs.add(userProviderPopupDTO);
		}

		Page<UserProviderPopupDTO> page = PageUtils.getPage(userProviderPopupDTOs);
		if (tmsBaseProviderModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsBaseProviderModel> p0 = (com.github.pagehelper.Page<TmsBaseProviderModel>) tmsBaseProviderModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/**
	 * 供应商发货方资料分页查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<ProviderShipperPagingQueryDTO> pageProviderShipperData(ProviderShipperPagingQueryVO providerShipperPagingQueryVO) {
		ToolKits.isParamNull(providerShipperPagingQueryVO, "供应商发货方资料查询请求不为空");
		ToolKits.isParamNull(providerShipperPagingQueryVO.getPageNum(), "页码不为空");
		ToolKits.isParamNull(providerShipperPagingQueryVO.getPageSize(), "页数不为空");

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

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

		// 供应商发货方状态
		List<Map<String, Object>> restMessage1 = sysRefdatadService.getDropDownById(DataDictionaryConstant.MAINDATA_STATUS, null, null, null);

		Criteria linkCriteria = Criteria.forClass(TmsProviderShipperLinkModel.class);
		Restriction linkR1 = ToolKits.isEmpty(providerShipperPagingQueryVO.getProviderId()) ? null : Restrictions.eq("providerId", providerShipperPagingQueryVO.getProviderId());
		linkCriteria.setRestriction(linkR1);
		List<TmsProviderShipperLinkModel> tmsProviderShipperLinkModels = tmsProviderShipperLinkMapper.findByCriteria(linkCriteria);

		// 获取发货方ID
		Long[] shipperIds = (tmsProviderShipperLinkModels.stream().map(TmsProviderShipperLinkModel::getShipperId).distinct().collect(Collectors.toList())).stream().toArray(Long[]::new);

		Criteria criteria = Criteria.forClass(TmsBaseShipperModel.class);
		Restriction r1 = Restrictions.in("id", shipperIds);
		Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		PageUtils.startPage(providerShipperPagingQueryVO.getPageNum(), providerShipperPagingQueryVO.getPageSize());
		List<TmsBaseShipperModel> tmsBaseShipperModels = tmsBaseShipperMapper.findByCriteria(criteria);
		for (TmsBaseShipperModel tmsBaseShipperModel : tmsBaseShipperModels) {
			// 响应对象
			ProviderShipperPagingQueryDTO providerShipperPagingQueryDTO = new ProviderShipperPagingQueryDTO();
			BeanUtils.copyProperties(tmsBaseShipperModel, providerShipperPagingQueryDTO);
			providerShipperPagingQueryDTO.setStatusName(PublicMethods.change(restMessage1, String.valueOf(providerShipperPagingQueryDTO.getStatus())));
			providerShipperPagingQueryDTOs.add(providerShipperPagingQueryDTO);
		}

		Page<ProviderShipperPagingQueryDTO> page = PageUtils.getPage(providerShipperPagingQueryDTOs);
		if (tmsBaseShipperModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsBaseShipperModel> p0 = (com.github.pagehelper.Page<TmsBaseShipperModel>) tmsBaseShipperModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/**
	 * 供应商发货方弹窗
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<ProviderShipperPopupDTO> popupProviderShipperData(ProviderShipperPopupVO providerShipperPopupVO) {
		ToolKits.isParamNull(providerShipperPopupVO, "供应商发货方弹窗请求不为空");
		//ToolKits.isParamNull(providerShipperPopupVO.getProviderId(), "供应商ID不为空");
		ToolKits.isParamNull(providerShipperPopupVO.getPageNum(), "页码不为空");
		ToolKits.isParamNull(providerShipperPopupVO.getPageSize(), "页数不为空");

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

		// 响应对象集合
		List<ProviderShipperPopupDTO> providerShipperPopupDTOs = new ArrayList<ProviderShipperPopupDTO>();
		List<Long> shipperIds = Lists.newArrayList();
		if (ToolKits.isNotEmpty(providerShipperPopupVO.getProviderId())) {
			// 查询供应商与发货方关联关系
			Criteria linkCriteria = Criteria.forClass(TmsProviderShipperLinkModel.class);
			Restriction linkR1 = Restrictions.eq("providerId", providerShipperPopupVO.getProviderId());
			linkCriteria.setRestriction(linkR1);
			List<TmsProviderShipperLinkModel> tmsProviderShipperLinkModels = tmsProviderShipperLinkMapper.findByCriteria(linkCriteria);

			// 获取发货方ID
			shipperIds = tmsProviderShipperLinkModels.stream().map(TmsProviderShipperLinkModel::getShipperId).distinct().collect(Collectors.toList());

		}

		Criteria criteria = Criteria.forClass(TmsBaseShipperModel.class);
		Restriction r1 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		Restriction r2 = Restrictions.eq("status", StatusConstant.STATUS_ENABLE);
		Restriction r3 = ToolKits.isEmpty(shipperIds) ? null:Restrictions.in("id", shipperIds.stream().toArray(Long[]::new));
		Restriction r4 = ToolKits.isEmpty(providerShipperPopupVO.getCode()) ? null : Restrictions.like("code", "%" + providerShipperPopupVO.getCode() + "%");
		Restriction r5 = ToolKits.isEmpty(providerShipperPopupVO.getName()) ? null : Restrictions.like("name", "%" + providerShipperPopupVO.getName() + "%");
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		PageUtils.startPage(providerShipperPopupVO.getPageNum(), providerShipperPopupVO.getPageSize());
		List<TmsBaseShipperModel> tmsBaseShipperModels = tmsBaseShipperMapper.findByCriteria(criteria);
		for (TmsBaseShipperModel tmsBaseShipperModel : tmsBaseShipperModels) {
			// 响应对象
			ProviderShipperPopupDTO providerShipperPopupDTO = new ProviderShipperPopupDTO();
			BeanUtils.copyProperties(tmsBaseShipperModel, providerShipperPopupDTO);

			providerShipperPopupDTOs.add(providerShipperPopupDTO);
		}

		Page<ProviderShipperPopupDTO> page = PageUtils.getPage(providerShipperPopupDTOs);
		if (tmsBaseShipperModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsBaseShipperModel> p0 = (com.github.pagehelper.Page<TmsBaseShipperModel>) tmsBaseShipperModels;
			page.setPageCount(p0.getPages());
			page.setPageNum(p0.getPageNum());
			page.setPageSize(p0.getPageSize());
			page.setTotalCount(p0.getTotal());
			page.setStartRow(p0.getStartRow());
			page.setEndRow(p0.getEndRow());
		}
		return page;
	}

	/**
	 * 供应商资料批量删除
	 */
	@Transactional(rollbackFor = Exception.class)
	@Override
	public void batchDeleteProviderData(List<Long> ids) throws Exception {
		ToolKits.isParamNull(ids, "供应商资料批量删除请求不为空");

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

		for (Long id : ids) {
			ToolKits.isParamNull(id, "供应商ID不为空");

			tmsBaseProviderMapper.deleteById(id, TmsBaseProviderModel.class);

			// 供应商发货方关联
			Criteria criteria = Criteria.forClass(TmsProviderShipperLinkModel.class);
			Restriction r1 = Restrictions.eq("providerId", id);
			criteria.setRestriction(r1);
			List<TmsProviderShipperLinkModel> tmsProviderShipperLinkModels = tmsProviderShipperLinkMapper.findByCriteria(criteria);

			// 删除发货方
			for (TmsProviderShipperLinkModel item : tmsProviderShipperLinkModels) {
				tmsBaseShipperMapper.deleteById(item.getShipperId(), TmsBaseShipperModel.class);
			}

			// 删除关联关系
			tmsProviderShipperLinkMapper.deleteByCriteria(criteria);
		}
	}

	/**
	 * 供应商资料是否启用
	 */
	@Transactional(rollbackFor = Exception.class)
	@Override
	public void whetherEnableProviderData(ProviderWhetherEnableVO providerWhetherEnableVO) throws Exception {
		ToolKits.isParamNull(providerWhetherEnableVO, "供应商资料是否启用请求不为空");
		ToolKits.isParamNull(providerWhetherEnableVO.getProviderIds(), "车型ID集不为空");
		ToolKits.isParamNull(providerWhetherEnableVO.getStatus(), "状态不为空");

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

		// 当前日期
		Date date = DateUtil.date();

		for (ProviderByIdVO providerByIdVO : providerWhetherEnableVO.getProviderIds()) {
			ToolKits.isParamNull(providerByIdVO.getProviderId(), "供应商ID不为空");

			// 根据ID查询供应商
			TmsBaseProviderModel tmsBaseProviderModel = tmsBaseProviderMapper.findById(providerByIdVO.getProviderId(), TmsBaseProviderModel.class);
			ToolKits.isParamNull(tmsBaseProviderModel, "供应商ID【" + providerByIdVO.getProviderId() + "】不存在");

			tmsBaseProviderModel.setStatus(providerWhetherEnableVO.getStatus() == 1 ? StatusConstant.STATUS_ENABLE : StatusConstant.STATUS_DISABLE);
			tmsBaseProviderModel.setUpdateperson(user.getNickname());
			tmsBaseProviderModel.setUpdatetime(date);
			tmsBaseProviderMapper.update(tmsBaseProviderModel);
		}
	}

	/**
	 * 供应商资料新增
	 */
	@Transactional(rollbackFor = Exception.class)
	@Override
	public String addProviderData(ProviderAddVO providerAddVO) throws Exception {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		ToolKits.isParamNull(providerAddVO, "供应商资料新增请求不为空");
		ToolKits.isParamNull(providerAddVO.getCode(), "供应商编码不为空");
		ToolKits.isParamNull(providerAddVO.getName(), "供应商名称不为空");
		ToolKits.isParamNull(providerAddVO.getCargoOwnerId(), "所属货主ID不为空");
		ToolKits.isParamNull(providerAddVO.getCargoOwnerCode(), "所属货主编码不为空");
		ToolKits.isParamNull(providerAddVO.getCargoOwnerName(), "所属货主名称不为空");
		ToolKits.isParamNull(providerAddVO.getContractNature(), "合同性质不为空");

		ToolKits.isParamNull(providerAddVO.getDepartmentId(), "所属部门ID不能为空");
		ToolKits.isParamNull(providerAddVO.getDepartmentCode(), "所属部门编号不能为空");
		ToolKits.isParamNull(providerAddVO.getDepartmentName(), "所属部门名称不能为空");

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

		// 判断供应商编码是否已存在
		PublicMethods.isThereAnyinformation(TmsBaseProviderModel.class, "code", providerAddVO.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_ENABLE, tmsBaseProviderMapper, "供应商编码已存在");
		PublicMethods.isThereAnyinformation(TmsBaseProviderModel.class, "code", providerAddVO.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_DISABLE, tmsBaseProviderMapper, "供应商编码已存在，请直接启用");

		// 判断供应商名称是否已存在
		PublicMethods.isThereAnyinformation(TmsBaseProviderModel.class, "name", providerAddVO.getName(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_ENABLE, tmsBaseProviderMapper, "供应商名称已存在");
		PublicMethods.isThereAnyinformation(TmsBaseProviderModel.class, "name", providerAddVO.getName(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_DISABLE, tmsBaseProviderMapper, "供应商名称已存在，请直接启用");

		// 供应商ID
		String vehicleTypeId = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_BASE_PROVIDER_ID, "L");
		ToolKits.isParamNull(vehicleTypeId, "供应商ID生成失败");

		// 当前日期
		Date date = DateUtil.date();

		// 供应商资料对象
		TmsBaseProviderModel tmsBaseProviderModel = new TmsBaseProviderModel();
		BeanUtils.copyProperties(providerAddVO, tmsBaseProviderModel);
		tmsBaseProviderModel.setId(Long.valueOf(vehicleTypeId));

		tmsBaseProviderModel.setPickUpSign(ToolKits.isEmpty(providerAddVO.getPickUpSign()) ? StatusConstant.WHETHER_NO : providerAddVO.getPickUpSign());
		tmsBaseProviderModel.setAutoPickUpSign(ToolKits.isEmpty(providerAddVO.getAutoPickUpSign()) ? StatusConstant.WHETHER_NO : providerAddVO.getAutoPickUpSign());
		tmsBaseProviderModel.setPickUpPicture(ToolKits.isEmpty(providerAddVO.getPickUpPicture()) ? StatusConstant.WHETHER_NO : providerAddVO.getPickUpPicture());
		tmsBaseProviderModel.setDeliverySign(ToolKits.isEmpty(providerAddVO.getDeliverySign()) ? StatusConstant.WHETHER_NO : providerAddVO.getDeliverySign());
		tmsBaseProviderModel.setAutoDeliverySign(ToolKits.isEmpty(providerAddVO.getAutoDeliverySign()) ? StatusConstant.WHETHER_NO : providerAddVO.getAutoDeliverySign());
		tmsBaseProviderModel.setDeliveryPicture(ToolKits.isEmpty(providerAddVO.getDeliveryPicture()) ? StatusConstant.WHETHER_NO : providerAddVO.getDeliveryPicture());
		tmsBaseProviderModel.setReturnOrderPicture(ToolKits.isEmpty(providerAddVO.getReturnOrderPicture()) ? StatusConstant.WHETHER_NO : providerAddVO.getReturnOrderPicture());

		tmsBaseProviderModel.setStatus(StatusConstant.STATUS_ENABLE);
		tmsBaseProviderModel.setSource(DataDictionaryConstant.SOURCE_ADD);
		tmsBaseProviderModel.setEnterpriseId(user.getEnterpriseId());
		tmsBaseProviderModel.setEnterpriseName(user.getEnterpriseName());
		tmsBaseProviderModel.setCreateperson(user.getNickname());
		tmsBaseProviderModel.setCreatetime(date);
		tmsBaseProviderModel.setUpdateperson(user.getNickname());
		tmsBaseProviderModel.setUpdatetime(date);
		tmsBaseProviderMapper.save(tmsBaseProviderModel);

		return vehicleTypeId;
	}

	/**
	 * 供应商资料查看
	 */
	@Override
	public ProviderCheckDTO getProviderData(ProviderCheckVO providerCheckVO) {
		ToolKits.isParamNull(providerCheckVO, "供应商资料查看请求不为空");
		ToolKits.isParamNull(providerCheckVO.getProviderId(), "供应商ID不为空");

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

		Criteria criteria = Criteria.forClass(TmsBaseProviderModel.class);
		Restriction r1 = Restrictions.eq("id", providerCheckVO.getProviderId());
		Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2));
		List<TmsBaseProviderModel> tmsBaseProviderModels = tmsBaseProviderMapper.findByCriteria(criteria);

		if (tmsBaseProviderModels.size() == 0) {
			throw new ParameterException("供应商ID【" + providerCheckVO.getProviderId() + "】数据不存在，查询失败");
		} else if (tmsBaseProviderModels.size() > 1) {
			throw new ParameterException("供应商ID【" + providerCheckVO.getProviderId() + "】存在重复数据，查询失败");
		}

		// 供应商资料对象
		TmsBaseProviderModel tmsBaseProviderModel = tmsBaseProviderModels.get(0);

		// 响应对象
		ProviderCheckDTO providerCheckDTO = new ProviderCheckDTO();
		BeanUtils.copyProperties(tmsBaseProviderModel, providerCheckDTO);

		return providerCheckDTO;
	}

	/**
	 * 供应商资料复制
	 */
	@Transactional(rollbackFor = Exception.class)
	@Override
	public void copyProviderData(ProviderCopyVO providerCopyVO) throws Exception {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		ToolKits.isParamNull(providerCopyVO, "供应商资料复制请求不为空");
		ToolKits.isParamNull(providerCopyVO.getCode(), "供应商编码不为空");
		ToolKits.isParamNull(providerCopyVO.getName(), "供应商名称不为空");
		ToolKits.isParamNull(providerCopyVO.getCargoOwnerId(), "所属货主ID不为空");
		ToolKits.isParamNull(providerCopyVO.getCargoOwnerCode(), "所属货主编码不为空");
		ToolKits.isParamNull(providerCopyVO.getCargoOwnerName(), "所属货主名称不为空");
		ToolKits.isParamNull(providerCopyVO.getContractNature(), "合同性质不为空");
		ToolKits.isParamNull(providerCopyVO.getDepartmentId(), "所属部门ID不能为空");
		ToolKits.isParamNull(providerCopyVO.getDepartmentCode(), "所属部门编号不能为空");
		ToolKits.isParamNull(providerCopyVO.getDepartmentName(), "所属部门名称不能为空");

		if (!user.getUserType().equals(BussinessConstant.USER_TYPE_ZY) && !user.getUserType().equals(BussinessConstant.USER_TYPE_HZ)) {
			ToolKits.isParamNull(user, "当前人员没有操作权限");
		}
		// 判断供应商编码是否已存在
		PublicMethods.isThereAnyinformation(TmsBaseProviderModel.class, "code", providerCopyVO.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_ENABLE, tmsBaseProviderMapper, "供应商编码已存在");
		PublicMethods.isThereAnyinformation(TmsBaseProviderModel.class, "code", providerCopyVO.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_DISABLE, tmsBaseProviderMapper, "供应商编码已存在，请直接启用");

		// 判断供应商名称是否已存在
		PublicMethods.isThereAnyinformation(TmsBaseProviderModel.class, "name", providerCopyVO.getName(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_ENABLE, tmsBaseProviderMapper, "供应商名称已存在");
		PublicMethods.isThereAnyinformation(TmsBaseProviderModel.class, "name", providerCopyVO.getName(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_DISABLE, tmsBaseProviderMapper, "供应商名称已存在，请直接启用");

		// 供应商ID
		String vehicleTypeId = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_BASE_PROVIDER_ID, "L");
		ToolKits.isParamNull(vehicleTypeId, "车型ID生成失败");

		// 当前日期
		Date date = DateUtil.date();

		// 供应商资料对象
		TmsBaseProviderModel tmsBaseProviderModel = new TmsBaseProviderModel();
		BeanUtils.copyProperties(providerCopyVO, tmsBaseProviderModel);
		tmsBaseProviderModel.setId(Long.valueOf(vehicleTypeId));

		tmsBaseProviderModel.setPickUpSign(ToolKits.isEmpty(providerCopyVO.getPickUpSign()) ? StatusConstant.WHETHER_NO : providerCopyVO.getPickUpSign());
		tmsBaseProviderModel.setAutoPickUpSign(ToolKits.isEmpty(providerCopyVO.getAutoPickUpSign()) ? StatusConstant.WHETHER_NO : providerCopyVO.getAutoPickUpSign());
		tmsBaseProviderModel.setPickUpPicture(ToolKits.isEmpty(providerCopyVO.getPickUpPicture()) ? StatusConstant.WHETHER_NO : providerCopyVO.getPickUpPicture());
		tmsBaseProviderModel.setDeliverySign(ToolKits.isEmpty(providerCopyVO.getDeliverySign()) ? StatusConstant.WHETHER_NO : providerCopyVO.getDeliverySign());
		tmsBaseProviderModel.setAutoDeliverySign(ToolKits.isEmpty(providerCopyVO.getAutoDeliverySign()) ? StatusConstant.WHETHER_NO : providerCopyVO.getAutoDeliverySign());
		tmsBaseProviderModel.setDeliveryPicture(ToolKits.isEmpty(providerCopyVO.getDeliveryPicture()) ? StatusConstant.WHETHER_NO : providerCopyVO.getDeliveryPicture());
		tmsBaseProviderModel.setReturnOrderPicture(ToolKits.isEmpty(providerCopyVO.getReturnOrderPicture()) ? StatusConstant.WHETHER_NO : providerCopyVO.getReturnOrderPicture());

		tmsBaseProviderModel.setStatus(StatusConstant.STATUS_ENABLE);
		tmsBaseProviderModel.setSource(DataDictionaryConstant.SOURCE_ADD);
		tmsBaseProviderModel.setEnterpriseId(user.getEnterpriseId());
		tmsBaseProviderModel.setEnterpriseName(user.getEnterpriseName());
		tmsBaseProviderModel.setCreateperson(user.getNickname());
		tmsBaseProviderModel.setCreatetime(date);
		tmsBaseProviderModel.setUpdateperson(user.getNickname());
		tmsBaseProviderModel.setUpdatetime(date);
		tmsBaseProviderMapper.save(tmsBaseProviderModel);
	}

	/**
	 * 供应商资料修改
	 */
	@Transactional(rollbackFor = Exception.class)
	@Override
	public void modifyProviderData(ProviderModifyVO providerModifyVO) throws Exception {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		ToolKits.isParamNull(providerModifyVO, "供应商资料新增请求不为空");
		ToolKits.isParamNull(providerModifyVO.getId(), "供应商ID不为空");
		ToolKits.isParamNull(providerModifyVO.getCargoOwnerId(), "所属货主ID不为空");
		ToolKits.isParamNull(providerModifyVO.getCargoOwnerCode(), "所属货主编码不为空");
		ToolKits.isParamNull(providerModifyVO.getCargoOwnerName(), "所属货主名称不为空");
		ToolKits.isParamNull(providerModifyVO.getContractNature(), "合同性质不为空");

		ToolKits.isParamNull(providerModifyVO.getDepartmentId(), "所属部门ID不能为空");
		ToolKits.isParamNull(providerModifyVO.getDepartmentCode(), "所属部门编号不能为空");
		ToolKits.isParamNull(providerModifyVO.getDepartmentName(), "所属部门名称不能为空");

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

		// 根据ID查询供应商资料
		TmsBaseProviderModel tmsBaseProviderModel = tmsBaseProviderMapper.findById(providerModifyVO.getId(), TmsBaseProviderModel.class);
		ToolKits.isParamNull(tmsBaseProviderModel, "供应商ID【" + providerModifyVO.getId() + "】不存在");

		if (user.getUserType().equals(BussinessConstant.USER_TYPE_HZ)) {
			if (!tmsBaseProviderModel.getDepartmentId().equals(providerModifyVO.getDepartmentId()) || !tmsBaseProviderModel.getDepartmentCode().equals(providerModifyVO.getDepartmentCode()) || !tmsBaseProviderModel.getDepartmentName().equals(providerModifyVO.getDepartmentName())) {
				ToolKits.isParamNull(user, "当前人员所属部门不可修改");
			}
		}

		Assert.isTrue(tmsBaseProviderModel.getStatus() == StatusConstant.STATUS_ENABLE, "供应商已停用不能修改");

		BeanUtils.copyProperties(providerModifyVO, tmsBaseProviderModel);
		tmsBaseProviderModel.setUpdateperson(user.getNickname());
		tmsBaseProviderModel.setUpdatetime(DateUtil.date());
		tmsBaseProviderMapper.update(tmsBaseProviderModel);
	}

	/**
	 * 供应商发货方资料新增
	 */
	@Transactional(rollbackFor = Exception.class)
	@Override
	public String addShipperData(ProviderShipperAddVO providerShipperAddVO) throws Exception {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		ToolKits.isParamNull(providerShipperAddVO, "供应商发货方资料新增请求不为空");
		ToolKits.isParamNull(providerShipperAddVO.getProviderId(), "供应商ID不为空");
		ToolKits.isParamNull(providerShipperAddVO.getCode(), "发货方编码不为空");
		ToolKits.isParamNull(providerShipperAddVO.getName(), "发货方名称不为空");

		// 判断发货方编码是否已存在
		PublicMethods.isThereAnyinformation(TmsBaseShipperModel.class, "code", providerShipperAddVO.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_ENABLE, tmsBaseShipperMapper, "发货方编码已存在");
		PublicMethods.isThereAnyinformation(TmsBaseShipperModel.class, "code", providerShipperAddVO.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_DISABLE, tmsBaseShipperMapper, "发货方编码已存在，请直接启用");

		// 判断发货方名称是否已存在
		PublicMethods.isThereAnyinformation(TmsBaseShipperModel.class, "name", providerShipperAddVO.getName(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_ENABLE, tmsBaseShipperMapper, "发货方名称已存在");
		PublicMethods.isThereAnyinformation(TmsBaseShipperModel.class, "name", providerShipperAddVO.getName(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_DISABLE, tmsBaseShipperMapper, "发货方名称已存在，请直接启用");

		// 校验供应商
		Criteria prodiverCriteria = Criteria.forClass(TmsBaseProviderModel.class);
		Restriction providerR1 = Restrictions.eq("id", providerShipperAddVO.getProviderId());
		Restriction providerR2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		prodiverCriteria.setRestriction(Restrictions.and(providerR1, providerR2));
		List<TmsBaseProviderModel> tmsBaseProviderModels = tmsBaseProviderMapper.findByCriteria(prodiverCriteria);

		Assert.isTrue(tmsBaseProviderModels.size() == 1, "供应商数据不存在或重复");

		// 发货方ID
		String shipperId = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_BASE_SHIPPER_ID, "L");
		ToolKits.isParamNull(shipperId, "发货方ID生成失败");

		// 当前日期
		Date date = DateUtil.date();

		// 发货方资料对象
		TmsBaseShipperModel tmsBaseShipperModel = new TmsBaseShipperModel();
		BeanUtils.copyProperties(providerShipperAddVO, tmsBaseShipperModel);
		tmsBaseShipperModel.setId(Long.valueOf(shipperId));
		tmsBaseShipperModel.setStatus(StatusConstant.STATUS_ENABLE);
		tmsBaseShipperModel.setSource(DataDictionaryConstant.SOURCE_ADD);
		tmsBaseShipperModel.setEnterpriseId(user.getEnterpriseId());
		tmsBaseShipperModel.setEnterpriseName(user.getEnterpriseName());
		tmsBaseShipperModel.setCreateperson(user.getNickname());
		tmsBaseShipperModel.setCreatetime(date);
		tmsBaseShipperModel.setUpdateperson(user.getNickname());
		tmsBaseShipperModel.setUpdatetime(date);
		tmsBaseShipperMapper.save(tmsBaseShipperModel);

		// 供应商发货方关联表
		TmsProviderShipperLinkModel tmsProviderShipperLinkModel = new TmsProviderShipperLinkModel();
		tmsProviderShipperLinkModel.setLineid(ToolKits.getUUID());
		tmsProviderShipperLinkModel.setProviderId(tmsBaseProviderModels.get(0).getId());
		tmsProviderShipperLinkModel.setProviderCode(tmsBaseProviderModels.get(0).getCode());
		tmsProviderShipperLinkModel.setProviderName(tmsBaseProviderModels.get(0).getName());
		tmsProviderShipperLinkModel.setShipperId(Long.valueOf(shipperId));
		tmsProviderShipperLinkModel.setShipperCode(tmsBaseShipperModel.getCode());
		tmsProviderShipperLinkModel.setShipperName(tmsBaseShipperModel.getName());
		tmsProviderShipperLinkModel.setCreateperson(user.getNickname());
		tmsProviderShipperLinkModel.setCreatetime(date);
		tmsProviderShipperLinkModel.setUpdateperson(user.getNickname());
		tmsProviderShipperLinkModel.setUpdatetime(date);
		tmsProviderShipperLinkMapper.save(tmsProviderShipperLinkModel);

		return shipperId;
	}

	/**
	 * 供应商发货方资料是否启用
	 */
	@Transactional(rollbackFor = Exception.class)
	@Override
	public void whetherEnableShipperData(ProviderShipperWhetherEnableVO providerShipperWhetherEnableVO) throws Exception {
		ToolKits.isParamNull(providerShipperWhetherEnableVO, "供应商发货方资料是否启用请求不为空");
		ToolKits.isParamNull(providerShipperWhetherEnableVO.getShipperIds(), "发货方ID集不为空");
		ToolKits.isParamNull(providerShipperWhetherEnableVO.getStatus(), "状态不为空");

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

		// 当前日期
		Date date = DateUtil.date();

		for (ProviderShipperByIdVO providerShipperByIdVO : providerShipperWhetherEnableVO.getShipperIds()) {
			ToolKits.isParamNull(providerShipperByIdVO.getShipperId(), "发货方ID不为空");

			// 根据ID查询发货方
			TmsBaseShipperModel tmsBaseShipperModel = tmsBaseShipperMapper.findById(providerShipperByIdVO.getShipperId(), TmsBaseShipperModel.class);
			ToolKits.isParamNull(tmsBaseShipperModel, "发货方ID【" + providerShipperByIdVO.getShipperId() + "】不存在");

			tmsBaseShipperModel.setStatus(providerShipperWhetherEnableVO.getStatus() == 1 ? StatusConstant.STATUS_ENABLE : StatusConstant.STATUS_DISABLE);
			tmsBaseShipperModel.setUpdateperson(user.getNickname());
			tmsBaseShipperModel.setUpdatetime(date);
			tmsBaseShipperMapper.update(tmsBaseShipperModel);
		}
	}

	/**
	 * 供应商发货方资料批量删除
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void batchDeleteShipperData(List<Long> ids) throws Exception {
		ToolKits.isParamNull(ids, "供应商发货方资料批量删除请求不为空");

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

		for (Long id : ids) {
			ToolKits.isParamNull(id, "发货方ID不为空");

			// 供应商发货方关联
			Criteria criteria = Criteria.forClass(TmsProviderShipperLinkModel.class);
			Restriction r1 = Restrictions.eq("shipperId", id);
			criteria.setRestriction(r1);
			// 删除关联关系
			tmsProviderShipperLinkMapper.deleteByCriteria(criteria);

			// 删除发货方
			tmsBaseShipperMapper.deleteById(id, TmsBaseShipperModel.class);
		}
	}

	/**
	 * 供应商发货方资料查看
	 */
	@Override
	public ProviderShipperCheckDTO getShipperData(ProviderShipperCheckVO providerShipperCheckVO) {
		ToolKits.isParamNull(providerShipperCheckVO, "供应商发货方资料查看请求不为空");
		ToolKits.isParamNull(providerShipperCheckVO.getShipperId(), "供应商发货方ID不为空");

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

		Criteria criteria = Criteria.forClass(TmsBaseShipperModel.class);
		Restriction r1 = Restrictions.eq("id", providerShipperCheckVO.getShipperId());
		Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2));
		List<TmsBaseShipperModel> tmsBaseShipperModels = tmsBaseShipperMapper.findByCriteria(criteria);

		if (tmsBaseShipperModels.size() == 0) {
			throw new ParameterException("供应商发货方ID【" + providerShipperCheckVO.getShipperId() + "】数据不存在，查询失败");
		} else if (tmsBaseShipperModels.size() > 1) {
			throw new ParameterException("供应商发货方ID【" + providerShipperCheckVO.getShipperId() + "】存在重复数据，查询失败");
		}

		// 供应商发货方资料对象
		TmsBaseShipperModel tmsBaseShipperModel = tmsBaseShipperModels.get(0);

		// 响应对象
		ProviderShipperCheckDTO providerShipperCheckDTO = new ProviderShipperCheckDTO();
		BeanUtils.copyProperties(tmsBaseShipperModel, providerShipperCheckDTO);

		return providerShipperCheckDTO;
	}

	/**
	 * 供应商发货方资料修改
	 */
	@Transactional(rollbackFor = Exception.class)
	@Override
	public void modifyShipperData(ProviderShipperModifyVO providerShipperModifyVO) throws Exception {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		ToolKits.isParamNull(providerShipperModifyVO, "供应商发货方商资料新增请求不为空");
		ToolKits.isParamNull(providerShipperModifyVO.getId(), "供应商发货方ID不为空");

		// 根据ID查询供应商发货方资料
		TmsBaseShipperModel tmsBaseShipperModel = tmsBaseShipperMapper.findById(providerShipperModifyVO.getId(), TmsBaseShipperModel.class);
		ToolKits.isParamNull(tmsBaseShipperModel, "供应商发货方ID【" + providerShipperModifyVO.getId() + "】不存在");

		Assert.isTrue(tmsBaseShipperModel.getStatus() == StatusConstant.STATUS_ENABLE, "供应商发货方已停用不能修改");

		BeanUtils.copyProperties(providerShipperModifyVO, tmsBaseShipperModel);
		tmsBaseShipperModel.setUpdateperson(user.getNickname());
		tmsBaseShipperModel.setUpdatetime(DateUtil.date());
		tmsBaseShipperMapper.update(tmsBaseShipperModel);
	}

	/**
	 * 供应商发货方导入撤销
	 */
	@Transactional(rollbackFor = Exception.class)
	@Override
	public void rollbackShipperData(String batchno) throws Exception {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限！");
		ToolKits.isParamNull(batchno, "导入批次号不能为空");

		Criteria criteria = Criteria.forClass(TmsBaseShipperModel.class);
		Restriction r1 = Restrictions.eq("importBatchNumber", batchno);
		criteria.setRestriction(r1);
		List<TmsBaseShipperModel> tmsBaseShipperModels = tmsBaseShipperMapper.findByCriteria(criteria);

		if (ToolKits.isEmpty(tmsBaseShipperModels)) {
			throw new ParameterException("批次号[" + batchno + "]错误，查询为空");
		}

		tmsBaseShipperMapper.deleteByCriteria(criteria);
	}

	/**
	 * 供应商导入撤销
	 */
	@Transactional(rollbackFor = Exception.class)
	@Override
	public void rollbackData(String batchno) throws Exception {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限！");
		ToolKits.isParamNull(batchno, "导入批次号不能为空");

		Criteria criteria = Criteria.forClass(TmsBaseShipperModel.class);
		Restriction r1 = Restrictions.eq("importBatchNumber", batchno);
		criteria.setRestriction(r1);
		List<TmsBaseShipperModel> tmsBaseShipperModels = tmsBaseShipperMapper.findByCriteria(criteria);

		if (ToolKits.isEmpty(tmsBaseShipperModels)) {
			throw new ParameterException("批次号[" + batchno + "]错误，查询为空");
		}

		for (TmsBaseShipperModel model : tmsBaseShipperModels) {
			// 供应商发货方关联
			Criteria linkCriteria = Criteria.forClass(TmsProviderShipperLinkModel.class);
			Restriction linkR1 = Restrictions.eq("providerId", model.getId());
			linkCriteria.setRestriction(linkR1);
			List<TmsProviderShipperLinkModel> tmsProviderShipperLinkModels = tmsProviderShipperLinkMapper.findByCriteria(linkCriteria);

			// 删除发货方
			for (TmsProviderShipperLinkModel item : tmsProviderShipperLinkModels) {
				tmsBaseShipperMapper.deleteById(item.getShipperId(), TmsBaseShipperModel.class);
			}

			// 删除关联关系
			tmsProviderShipperLinkMapper.deleteByCriteria(linkCriteria);
		}

		tmsBaseShipperMapper.deleteByCriteria(criteria);
	}

	/**
	 * 根据供应商ID集合分页查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<ProviderByIdsDTO> pageProviderByIdsData(ProviderByIdsVO providerByIdsVO) {
		ToolKits.isParamNull(providerByIdsVO, "根据供应商ID集合分页查询请求不为空");
		ToolKits.isParamNull(providerByIdsVO.getPageNum(), "页码不为空");
		ToolKits.isParamNull(providerByIdsVO.getPageSize(), "页数不为空");

		Long[] providerIds = new Long[providerByIdsVO.getProviderIds().size()];
		for (int i = 0; i < providerByIdsVO.getProviderIds().size(); i++) {
			providerIds[i] = providerByIdsVO.getProviderIds().get(i).getProviderId();
		}

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

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

		// 分页
		PageUtils.startPage(providerByIdsVO.getPageNum(), providerByIdsVO.getPageSize());

		Criteria criteria = Criteria.forClass(TmsBaseProviderModel.class);
		Restriction r1 = Restrictions.in("id", providerIds);
		Restriction r2 = ToolKits.isEmpty(providerByIdsVO.getSearch()) ? null : Restrictions.like("name", "%" + providerByIdsVO.getSearch() + "%");
		Restriction r3 = ToolKits.isEmpty(providerByIdsVO.getCargoOwnerName()) ? null : Restrictions.like("cargoOwnerName", "%" + providerByIdsVO.getCargoOwnerName() + "%");
		Restriction r4 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		List<TmsBaseProviderModel> tmsBaseProviderModels = tmsBaseProviderMapper.findByCriteria(criteria);
		for (TmsBaseProviderModel tmsBaseProviderModel : tmsBaseProviderModels) {
			// 响应对象
			ProviderByIdsDTO providerByIdsDTO = new ProviderByIdsDTO();
			BeanUtils.copyProperties(tmsBaseProviderModel, providerByIdsDTO);
			providerByIdsDTOs.add(providerByIdsDTO);
		}

		Page<ProviderByIdsDTO> page = PageUtils.getPage(providerByIdsDTOs);
		if (tmsBaseProviderModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsBaseProviderModel> p0 = (com.github.pagehelper.Page<TmsBaseProviderModel>) tmsBaseProviderModels;
			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;
	}

	/**
	 * 根据供应商发货方ID集合分页查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<ShipperByIdsDTO> pageShipperByIdsData(ShipperByIdsVO shipperByIdsVO) {
		ToolKits.isParamNull(shipperByIdsVO, "根据供应商发货方ID集合分页查询请求不为空");
		ToolKits.isParamNull(shipperByIdsVO.getPageNum(), "页码不为空");
		ToolKits.isParamNull(shipperByIdsVO.getPageSize(), "页数不为空");

		Long[] shipperIds = new Long[shipperByIdsVO.getShipperIds().size()];
		for (int i = 0; i < shipperByIdsVO.getShipperIds().size(); i++) {
			shipperIds[i] = shipperByIdsVO.getShipperIds().get(i).getId();
		}

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

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

		// 分页
		PageUtils.startPage(shipperByIdsVO.getPageNum(), shipperByIdsVO.getPageSize());

		Criteria criteria = Criteria.forClass(TmsBaseShipperModel.class);
		Restriction r1 = Restrictions.in("id", shipperIds);
		Restriction r2 = ToolKits.isEmpty(shipperByIdsVO.getSearch()) ? null : Restrictions.like("name", "%" + shipperByIdsVO.getSearch() + "%");
		Restriction r3 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2, r3));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		List<TmsBaseShipperModel> tmsBaseShipperModels = tmsBaseShipperMapper.findByCriteria(criteria);
		for (TmsBaseShipperModel tmsBaseShipperModel : tmsBaseShipperModels) {
			// 响应对象
			ShipperByIdsDTO shipperByIdsDTO = new ShipperByIdsDTO();
			BeanUtils.copyProperties(tmsBaseShipperModel, shipperByIdsDTO);
			shipperByIdsDTOs.add(shipperByIdsDTO);
		}

		Page<ShipperByIdsDTO> page = PageUtils.getPage(shipperByIdsDTOs);
		if (tmsBaseShipperModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsBaseShipperModel> p0 = (com.github.pagehelper.Page<TmsBaseShipperModel>) tmsBaseShipperModels;
			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;
	}

	/**
	 * 供应商导入分页查询
	 */
	@Override
	@SuppressWarnings("resource")
	public RestMessage<Object> pageProviderByImportBatchNumberData(ImportPageVO importPageVO) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

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

		// 分页
		PageUtils.startPage(importPageVO.getPageNum(), importPageVO.getPageSize());

		// 合同性质
		List<Map<String, Object>> restMessage1 = sysRefdatadService.getDropDownById(DataDictionaryConstant.CONTRACT_NATURE, null, null, null);
		// 开户行
		List<Map<String, Object>> restMessage2 = sysRefdatadService.getDropDownById(DataDictionaryConstant.BANK, null, null, null);
		// 供应商状态
		List<Map<String, Object>> restMessage3 = sysRefdatadService.getDropDownById(DataDictionaryConstant.MAINDATA_STATUS, null, null, null);
		// 提货签到 自动提货签到 提货图片 送达签到 自动送达签到 送货图片
		List<Map<String, Object>> restMessage4 = sysRefdatadService.getDropDownById(DataDictionaryConstant.WHETHER, null, null, null);

		SysRefdatadQueryVO sysrefdatadqueryvo = new SysRefdatadQueryVO();
		String[] objectcodes = { DataDictionaryConstant.PICK_UP_SIGN_TIME, // 提货签到时间点
				DataDictionaryConstant.DELIVERY_SIGN_TIME, // 送达签到时间点
				DataDictionaryConstant.SIGN_TIME_UNIT // 签到时间单位
		};
		sysrefdatadqueryvo.setObjectcodes(objectcodes);
		List<SysRefdatadDTO> sysrefdataddtos = new ArrayList<SysRefdatadDTO>();
		try {
			sysrefdataddtos = sysRefdatadService.getSysRefdatadData(sysrefdatadqueryvo);
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException("获取数据字典失败");
		}

		Criteria criteria = Criteria.forClass(TmsBaseProviderModel.class);
		Restriction r1 = Restrictions.eq("importBatchNumber", importPageVO.getImportBatchNumber());
		Restriction r2 = Restrictions.eq("source", DataDictionaryConstant.SOURCE_EXCEL);
		Restriction r3 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2, r3));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		List<TmsBaseProviderModel> tmsBaseProviderModels = tmsBaseProviderMapper.findByCriteria(criteria);

		for (TmsBaseProviderModel tmsBaseProviderModel : tmsBaseProviderModels) {
			// 响应对象
			ProviderImportPageDTO providerImportPageDTO = new ProviderImportPageDTO();
			BeanUtils.copyProperties(tmsBaseProviderModel, providerImportPageDTO);
			providerImportPageDTO.setContractNatureName(PublicMethods.change(restMessage1, String.valueOf(providerImportPageDTO.getContractNature())));
			providerImportPageDTO.setBankName(PublicMethods.change(restMessage2, String.valueOf(providerImportPageDTO.getBank())));
			providerImportPageDTO.setStatusName(PublicMethods.change(restMessage3, String.valueOf(providerImportPageDTO.getStatus())));
			providerImportPageDTO.setPickUpPictureName(PublicMethods.change(restMessage4, String.valueOf(providerImportPageDTO.getPickUpPicture())));
			providerImportPageDTO.setPickUpSignName(PublicMethods.change(restMessage4, String.valueOf(providerImportPageDTO.getPickUpSign())));
			providerImportPageDTO.setAutoPickUpSignName(PublicMethods.change(restMessage4, String.valueOf(providerImportPageDTO.getAutoPickUpSign())));
			providerImportPageDTO.setDeliveryPictureName(PublicMethods.change(restMessage4, String.valueOf(providerImportPageDTO.getDeliveryPicture())));
			providerImportPageDTO.setDeliverySignName(PublicMethods.change(restMessage4, String.valueOf(providerImportPageDTO.getDeliverySign())));
			providerImportPageDTO.setAutoDeliverySignName(PublicMethods.change(restMessage4, String.valueOf(providerImportPageDTO.getAutoDeliverySign())));

			for (SysRefdatadDTO sysrefdataddto : sysrefdataddtos) {
				if (DataDictionaryConstant.PICK_UP_SIGN_TIME.equals(sysrefdataddto.getObjectcode()) && sysrefdataddto.getCode().equals(String.valueOf(providerImportPageDTO.getPickUpSignTime()))) {
					providerImportPageDTO.setPickUpSignTimeName(sysrefdataddto.getName());
				}
				if (DataDictionaryConstant.SIGN_TIME_UNIT.equals(sysrefdataddto.getObjectcode()) && sysrefdataddto.getCode().equals(String.valueOf(providerImportPageDTO.getPickUpSignTimeUnit()))) {
					providerImportPageDTO.setPickUpSignTimeUnitName(sysrefdataddto.getName());
				}
				if (DataDictionaryConstant.DELIVERY_SIGN_TIME.equals(sysrefdataddto.getObjectcode()) && sysrefdataddto.getCode().equals(String.valueOf(providerImportPageDTO.getDeliverySignTime()))) {
					providerImportPageDTO.setDeliverySignTimeName(sysrefdataddto.getName());
				}
				if (DataDictionaryConstant.SIGN_TIME_UNIT.equals(sysrefdataddto.getObjectcode()) && sysrefdataddto.getCode().equals(String.valueOf(providerImportPageDTO.getDeliverySignTimeUnit()))) {
					providerImportPageDTO.setDeliverySignTimeUnitName(sysrefdataddto.getName());
				}
			}

			providerImportPageDTOs.add(providerImportPageDTO);
		}

		Page<ProviderImportPageDTO> page = PageUtils.getPage(providerImportPageDTOs);
		if (tmsBaseProviderModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsBaseProviderModel> p0 = (com.github.pagehelper.Page<TmsBaseProviderModel>) tmsBaseProviderModels;
			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 RestMessage.newInstance(true, "查询成功", page);
	}

	/**
	 * 供应商发货方导入分页查询
	 */
	@Override
	@SuppressWarnings("resource")
	public RestMessage<Object> pageProviderShipperByImportBatchNumberData(ImportPageVO importPageVO) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

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

		// 分页
		PageUtils.startPage(importPageVO.getPageNum(), importPageVO.getPageSize());

		Criteria criteria = Criteria.forClass(TmsBaseShipperModel.class);
		Restriction r1 = Restrictions.eq("importBatchNumber", importPageVO.getImportBatchNumber());
		Restriction r2 = Restrictions.eq("source", DataDictionaryConstant.SOURCE_EXCEL);
		Restriction r3 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2, r3));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		List<TmsBaseShipperModel> tmsBaseShipperModels = tmsBaseShipperMapper.findByCriteria(criteria);

		for (TmsBaseShipperModel tmsBaseShipperModel : tmsBaseShipperModels) {
			// 响应对象
			ProviderShipperImportPageDTO providerShipperImportPageDTO = new ProviderShipperImportPageDTO();
			BeanUtils.copyProperties(tmsBaseShipperModel, providerShipperImportPageDTO);
			providerShipperImportPageDTOs.add(providerShipperImportPageDTO);
		}

		Page<ProviderShipperImportPageDTO> page = PageUtils.getPage(providerShipperImportPageDTOs);
		if (tmsBaseShipperModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsBaseShipperModel> p0 = (com.github.pagehelper.Page<TmsBaseShipperModel>) tmsBaseShipperModels;
			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 RestMessage.newInstance(true, "操作成功", page);
	}

	/**
	 * 发货方地址解析
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void parseProviderShipperAddress(Long id, BigDecimal longitude, BigDecimal latitude, String address) throws Exception {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		TmsBaseShipperModel tmsBaseShipperModel = tmsBaseShipperMapper.findById(id, TmsBaseShipperModel.class);

		ToolKits.isParamNull(tmsBaseShipperModel, "供应商发货方不存在");

		tmsBaseShipperModel.setLongitude(longitude);
		tmsBaseShipperModel.setLatitude(latitude);
		tmsBaseShipperModel.setAddress(ToolKits.isEmpty(address) ? null : address);
		tmsBaseShipperModel.setUpdateperson(user.getNickname());
		tmsBaseShipperModel.setUpdatetime(DateUtil.date());
		tmsBaseShipperMapper.update(tmsBaseShipperModel);
	}

	/**
	 * 供应商资料导入(新)
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void batchInsertProviderData(MultipartFile file) throws Exception {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		// 导入文件判断
		FileUtils.multipartFileJudge(file);
		if (file.getSize() == 0 || file == null) {
			throw new ParameterException("文件大小为0字节，请上传正确的文件！");
		}
		if (String.valueOf(file.getSize()).length() > 20971520) {
			throw new ParameterException("上传文件大小超过15M,请拆分导入");
		}
		if (!file.getOriginalFilename().endsWith("xls") && !file.getOriginalFilename().endsWith("xlsx")) {
			throw new ParameterException("文件不是excel");
		}

		// 导入批次
		String importBatchNumber = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.IMPORT_BATCHNO, "L");
		ToolKits.isParamNull(importBatchNumber, "导入批次获取失败");

		// 导入日志对象
		ImportLogAddVO logAddVO = new ImportLogAddVO();
		logAddVO.setImportObjNo(DataDictionaryConstant.PROVIDER_IMPORT);
		logAddVO.setImportBatchNumber(importBatchNumber);
		// 导入统计
		int count = 0;
		try {
			// 导入执行
			count = this.batchInsertProviderProcess(file, importBatchNumber, user);
			logAddVO.setStatus(DataDictionaryConstant.IMPORT_STATUS_YES);
			logAddVO.setSuccessNum(count);
			logAddVO.setFailNum(0);
			importLogService.addImportLogData(logAddVO);
		} catch (Exception e) {
			Class<ProviderImportStdVO> importVOClass = ProviderImportStdVO.class;
			List<ProviderImportStdVO> importVOs = ExcelUtils.read(file, importVOClass);

			logAddVO.setStatus(DataDictionaryConstant.IMPORT_STATUS_NO);
			logAddVO.setSuccessNum(0);
			logAddVO.setFailNum(importVOs.size());
			logAddVO.setFailReason(e.getMessage());
			// 为了避免导入失败时导入日志的保存事务也被回滚,所以采用消息队列异步保存导入失败的日志
			amqpTemplate.convertAndSend(RabbitMQConstant.PROVIDER_IMPORT_LOG, logAddVO);
			e.printStackTrace();
			throw new ParameterException(e.getMessage());
		}
	}

	// 供应商异步保存导入失败日志
	@RabbitListener(queues = RabbitMQConstant.PROVIDER_IMPORT_LOG)
	@Transactional(rollbackFor = Exception.class)
	public void saveFailImportLog(ImportLogAddVO logAddVO) {
		try {
			importLogService.addImportLogData(logAddVO);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 供应商导入过程(新)
	 *
	 * @param file
	 * @param
	 * @param
	 * @return
	 * @throws Exception
	 */
	public int batchInsertProviderProcess(MultipartFile file, String importBatchNumber, UserEntity user) {
		Date date = new Date();
		Properties properties = new Properties();
		// 待转换的对象
		Class<ProviderImportStdVO> importVOClass = ProviderImportStdVO.class;
		// 标准模板查询
		List<StandardTemplateDetailsListDTO> standardTemplateDetailsListDTOs = sysImportTemplethService.listStandardTemplateDetailsData(DataDictionaryConstant.ITEM_CATEGORY_IMPORT);
		for (StandardTemplateDetailsListDTO standardTemplateDetailsListDTO : standardTemplateDetailsListDTOs) {
			// 属性字段和注解属性字段值 键值对
			properties.setProperty(standardTemplateDetailsListDTO.getStdColNo(), standardTemplateDetailsListDTO.getCustColName());
		}
		// @ExcelProperty注解属性修改
		ImportUtils.setHeaderValue(properties, importVOClass);
		// EXCEL转对象
		List<ProviderImportStdVO> importVOs = null;
		try {
			importVOs = ExcelUtils.read(file, importVOClass);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ParameterException("EXCEL转对象失败:" + e.getMessage());
		}
		ToolKits.isParamNull(importVOs, "EXCEL文件内容为空,请重新导入");
		log.info("供应商导入详情:{}", JsonMapper.toJson(importVOs));

		int i = 1;
		for (ProviderImportStdVO importVO : importVOs) {
			if (ToolKits.isEmpty(importVO.getCode())) {
				throw new PrologException("第" + i + "行导入数据,供应商编码不能为空");
			}
			if (ToolKits.isEmpty(importVO.getName())) {
				throw new PrologException("第" + i + "行导入数据,供应商名称不能为空");
			}
			if (ToolKits.isEmpty(importVO.getCargoOwnerCode())) {
				throw new PrologException("第" + i + "行导入数据,货主编码不能为空");
			}
			if (ToolKits.isEmpty(importVO.getCargoOwnerName())) {
				throw new PrologException("第" + i + "行导入数据,货主名称不能为空");
			}
			if (ToolKits.isEmpty(importVO.getContractNatureName())) {
				throw new PrologException("第" + i + "行导入数据,合同性质不能为空");
			}
			i++;
		}
		// 验证导入文件中供应商编号是否重复
		Map<String, Long> codeMap = importVOs.stream().collect(Collectors.groupingBy(ProviderImportStdVO::getCode, Collectors.counting()));
		for (Map.Entry<String, Long> longEntry : codeMap.entrySet()) {
			if (longEntry.getValue() > 1) {
				throw new ParameterException(String.format("导入文件中，供应商编号[%s]重复", longEntry.getKey()));
			}
		}
		// 验证导入文件中供应商名称是否重复
		Map<String, Long> nameMap = importVOs.stream().collect(Collectors.groupingBy(ProviderImportStdVO::getName, Collectors.counting()));
		for (Map.Entry<String, Long> longEntry : nameMap.entrySet()) {
			if (longEntry.getValue() > 1) {
				throw new ParameterException(String.format("导入文件中，供应商名称[%s]重复", longEntry.getKey()));
			}
		}

		i = 0;
		for (ProviderImportStdVO importVO : importVOs) {
			TmsBaseProviderModel tmsBaseProviderModel = new TmsBaseProviderModel();
			BeanUtils.copyProperties(importVO, tmsBaseProviderModel);
			if (!user.getUserType().equals(BussinessConstant.USER_TYPE_ZY) && !user.getUserType().equals(BussinessConstant.USER_TYPE_HZ)) {
				ToolKits.isParamNull(user, "当前人员没有操作权限");
			}

			if (ToolKits.isNotEmpty(importVO.getPhoneNumber()) && !Validator.isMobile(importVO.getPhoneNumber())) {
				// throw new ParameterException(String.format("%s手机号不符合规范",
				// importVO.getPhoneNumber()));
				throw new ParameterException("第" + (i + 1) + "行导入数据,手机号格式不符合规范!");
			}

			if (ToolKits.isNotEmpty(importVO.getEmail()) && !Validator.isEmail(importVO.getEmail())) {
				// throw new ParameterException(String.format("%邮箱不符合规范", importVO.getEmail()));
				throw new ParameterException("第" + (i + 1) + "行导入数据,邮箱格式不符合规范!");
			}

			if (ToolKits.isNotEmpty(importVO.getPostCode()) && !Validator.isZipCode(importVO.getPostCode())) {
				// throw new ParameterException(String.format("%邮编不符合规范",
				// importVO.getPostCode()));
				throw new ParameterException("第" + (i + 1) + "行导入数据,邮编格式不符合规范!");
			}

			if (ToolKits.isNotEmpty(importVO.getLandlineNumber())) {
				Matcher matcher = null;
				Pattern p1 = Pattern.compile("^[0][1-9]{2,3}-[0-9]{5,10}$"); // 验证带区号的
				Pattern p2 = Pattern.compile("^[1-9]{1}[0-9]{5,8}$"); // 验证没有区号的
				if (importVO.getLandlineNumber().length() > 9) {
					matcher = p1.matcher(importVO.getLandlineNumber());
					if (!matcher.matches()) {
						throw new ParameterException("座机号不符合规范");
					}
				} else {
					matcher = p2.matcher(importVO.getLandlineNumber());
					if (!matcher.matches()) {
						throw new ParameterException("座机号不符合规范");
					}
				}
			}

			Map<String, Object> map = Maps.newHashMap();
			map.put("code", importVO.getCode());
			map.put("enterpriseId", user.getEnterpriseId());
			map.put("status", StatusConstant.STATUS_ENABLE);

			Map<String, Object> map2 = Maps.newHashMap();
			map2.put("name", importVO.getName());
			map2.put("enterpriseId", user.getEnterpriseId());
			map2.put("status", StatusConstant.STATUS_ENABLE);

			// 判断供应商编码 供应商名称 是否已存在
			PublicMethods.doesItExistByMap(tmsBaseProviderMapper, map, TmsBaseProviderModel.class, "供应商编码[" + importVO.getCode() + "]已存在");
			PublicMethods.doesItExistByMap(tmsBaseProviderMapper, map2, TmsBaseProviderModel.class, "供应商名称[" + importVO.getName() + "]已存在");

			// 判断供应商编码 供应商名称 是否已停用
			map.put("status", StatusConstant.STATUS_DISABLE);
			map2.put("status", StatusConstant.STATUS_DISABLE);
			PublicMethods.doesItExistByMap(tmsBaseProviderMapper, map, TmsBaseProviderModel.class, "供应商编码[" + importVO.getCode() + "]已停用,请直接启用");
			PublicMethods.doesItExistByMap(tmsBaseProviderMapper, map2, TmsBaseProviderModel.class, "供应商名称[" + importVO.getName() + "]已停用,请直接启用");

			// 登录为自有账号时
			if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
				ToolKits.isParamNull(importVO.getDepartmentName(), "所属部门名称不为空");

				// 调用获取部门信息API
				RestMessage<List<Organization>> restMessage = userFeign.search(null, importVO.getDepartmentName(), null, String.valueOf(user.getEnterpriseId()));
				if (!restMessage.isSuccess()) {
					throw new RuntimeException("获取部门信息API错误!");
				}
				List<Organization> data = restMessage.getData();
				// 校验部门是否存在
				if (ToolKits.isNotEmpty(data)) {
					if (data.size() > 1) {
						throw new RuntimeException(importVO.getDepartmentName() + "部门名称重复!");
					}
					Organization organization = data.get(0);
					// 判断是否在登录账号的所属部门或下级部门内
					if (!user.getDepts().contains(organization.getId())) {
						throw new RuntimeException(importVO.getDepartmentName() + "不存在,请先维护部门!");
					}
					// 部门信息赋值
					tmsBaseProviderModel.setDepartmentId(organization.getId());
					tmsBaseProviderModel.setDepartmentCode(organization.getCode());
				} else {
					throw new RuntimeException(importVO.getDepartmentName() + "不存在,请先维护部门!");
				}

				// 校验货主
				Criteria criteria = Criteria.forClass(TmsBaseCargoOwnerModel.class);
				Restriction r1 = Restrictions.eq("cargoOwnerName", importVO.getCargoOwnerName());
				Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());

				// 判断是否为部门权限
				if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
					Restriction r3 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
					criteria.setRestriction(Restrictions.and(r1, r2, r3));
					List<TmsBaseCargoOwnerModel> tmsBaseCargoOwnerModels = tmsBaseCargoOwnerMapper.findByCriteria(criteria);

					if (ToolKits.isEmpty(tmsBaseCargoOwnerModels)) {
						throw new ParameterException("货主名称[" + importVO.getCargoOwnerName() + "]不存在");
					}

					// 所属货主赋值
					TmsBaseCargoOwnerModel tmsBaseCargoOwnerModel = tmsBaseCargoOwnerModels.get(0);
					tmsBaseProviderModel.setCargoOwnerId(tmsBaseCargoOwnerModel.getCargoOwnerId());
					tmsBaseProviderModel.setCargoOwnerCode(tmsBaseCargoOwnerModel.getCargoOwnerCode());
					tmsBaseProviderModel.setCargoOwnerName(tmsBaseCargoOwnerModel.getCargoOwnerName());
				} else {
					Restriction r3 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
					Restriction r4 = Restrictions.in("cargoOwnerId", user.getConsignors().stream().toArray(Long[]::new));
					criteria.setRestriction(Restrictions.and(r1, r2, r3, r4));
					List<TmsBaseCargoOwnerModel> tmsBaseCargoOwnerModels = tmsBaseCargoOwnerMapper.findByCriteria(criteria);

					if (ToolKits.isEmpty(tmsBaseCargoOwnerModels)) {
						throw new ParameterException("货主名称[" + importVO.getCargoOwnerName() + "]不存在");
					}
				}
			} else {
				// 登录为货主账号时
				// 获取当前账号的顶级部门
				RestMessage<List<Organization>> restMessage = userFeign.search("0", null, null, String.valueOf(user.getEnterpriseId()));
				if (!restMessage.isSuccess()) {
					throw new RuntimeException("获取部门信息API错误!");
				}
				List<Organization> data = restMessage.getData();
				// 校验部门是否存在
				if (ToolKits.isNotEmpty(data)) {
					if (data.size() > 1) {
						throw new RuntimeException("登录账号顶级部门重复!");
					}
					Organization organization = data.get(0);
					// 部门信息赋值
					tmsBaseProviderModel.setDepartmentId(organization.getId());
					tmsBaseProviderModel.setDepartmentCode(organization.getCode());
					tmsBaseProviderModel.setDepartmentName(organization.getName());
				} else {
					throw new RuntimeException("顶级部门不存在,请先维护部门!");
				}

				// 所属货主赋值
				TmsBaseCargoOwnerModel tmsBaseCargoOwnerModel = tmsBaseCargoOwnerMapper.findById(Long.valueOf(user.getLoginUserCompanyInfo().getId()), TmsBaseCargoOwnerModel.class);
				ToolKits.isParamNull(tmsBaseCargoOwnerModel, "当前登录账号的货主不存在");
				tmsBaseProviderModel.setCargoOwnerId(tmsBaseCargoOwnerModel.getCargoOwnerId());
				tmsBaseProviderModel.setCargoOwnerCode(tmsBaseCargoOwnerModel.getCargoOwnerCode());
				tmsBaseProviderModel.setCargoOwnerName(tmsBaseCargoOwnerModel.getCargoOwnerName());

			}
			// 校验合同性质
			List<Map<String, Object>> restMessage1 = sysRefdatadService.getDropDownById(DataDictionaryConstant.CONTRACT_NATURE, null, null, null);

			if (importVO.getContractNatureName().equals(PublicMethods.reverseChange(restMessage1, importVO.getContractNatureName())) || ToolKits.isEmpty(PublicMethods.reverseChange(restMessage1, importVO.getContractNatureName()))) {
				throw new ParameterException("合同性质[" + importVO.getContractNatureName() + "]不存在，请先维护合同性质");
			}
			tmsBaseProviderModel.setContractNature(Integer.parseInt(PublicMethods.reverseChange(restMessage1, importVO.getContractNatureName())));

			if (ToolKits.isNotEmpty(importVO.getBankName())) {
				// 校验开户行
				List<Map<String, Object>> restMessage2 = sysRefdatadService.getDropDownById(DataDictionaryConstant.BANK, null, null, null);

				if (importVO.getContractNatureName().equals(PublicMethods.reverseChange(restMessage2, importVO.getBankName())) || ToolKits.isEmpty(PublicMethods.reverseChange(restMessage2, importVO.getBankName()))) {
					throw new ParameterException("开户行[" + importVO.getBankName() + "]不存在，请先维护开户行");
				}
				tmsBaseProviderModel.setBank(Integer.parseInt(PublicMethods.reverseChange(restMessage2, importVO.getBankName())));
			}

			// 判断省市区
			if (ToolKits.isNotEmpty(importVO.getProvinceName())) {
				List<LmsTmsZoneModel> lmsTmsZoneModels = lmsTmsZoneMapper.getZoneListByZname(importVO.getProvinceName(), "2", null);
				if (ToolKits.isEmpty(lmsTmsZoneModels)) {
					throw new ParameterException("省名称[" + importVO.getProvinceName() + "]错误");
				}

				tmsBaseProviderModel.setProvince(lmsTmsZoneModels.get(0).getZoneid());
			}
			if (ToolKits.isNotEmpty(importVO.getCityName())) {
				List<LmsTmsZoneModel> lmsTmsZoneModels = lmsTmsZoneMapper.getZoneListByZname(importVO.getCityName(), "3", importVO.getProvinceName());

				if (ToolKits.isEmpty(lmsTmsZoneModels)) {
					throw new ParameterException("市名称[" + importVO.getCityName() + "]错误");
				}

				tmsBaseProviderModel.setCity(lmsTmsZoneModels.get(0).getZoneid());
			}
			if (ToolKits.isNotEmpty(importVO.getDistrictName())) {
				List<LmsTmsZoneModel> lmsTmsZoneModels = lmsTmsZoneMapper.getZoneListByZname(importVO.getDistrictName(), "4", importVO.getCityName());

				if (ToolKits.isEmpty(lmsTmsZoneModels)) {
					throw new ParameterException("区名称[" + importVO.getDistrictName() + "]错误");
				}

				tmsBaseProviderModel.setDistrict(lmsTmsZoneModels.get(0).getZoneid());
			}

			String id = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_BASE_PROVIDER_ID, "L");
			if (ToolKits.isEmpty(id)) {
				throw new ParameterException("供应商ID获取失败");
			}

			// 数据字典
			List<Map<String, Object>> restMessage = sysRefdatadService.getDropDownById(DataDictionaryConstant.WHETHER, null, null, null);

			// 判断供应商编码是否已存在
			PublicMethods.isThereAnyinformation(TmsBaseProviderModel.class, "code", importVO.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_ENABLE, tmsBaseProviderMapper, "供应商编码【" + importVO.getCode() + "】已存在");
			PublicMethods.isThereAnyinformation(TmsBaseProviderModel.class, "code", importVO.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_DISABLE, tmsBaseProviderMapper, "供应商编码【" + importVO.getCode() + "】已停用,请直接启用");
			// 判断供应商名称是否已存在
			PublicMethods.isThereAnyinformation(TmsBaseProviderModel.class, "code", importVO.getName(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_ENABLE, tmsBaseProviderMapper, "商品品类名称【" + importVO.getName() + "】已存在");
			PublicMethods.isThereAnyinformation(TmsBaseProviderModel.class, "code", importVO.getName(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_DISABLE, tmsBaseProviderMapper, "商品品类名称【" + importVO.getName() + "】已停用,请直接启用!");

			// 供应商ID
			String providerId = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_BASE_PROVIDER_ID, "L");
			ToolKits.isParamNull(providerId, "供应商ID生成失败");

			// 供应商资料对象
			tmsBaseProviderModel.setId(Long.valueOf(providerId));
			tmsBaseProviderModel.setStatus(StatusConstant.STATUS_ENABLE);
			tmsBaseProviderModel.setSource(DataDictionaryConstant.SOURCE_EXCEL);
			tmsBaseProviderModel.setImportBatchNumber(importBatchNumber);
			if (ToolKits.isNotEmpty(importVO.getPickUpPictureName())) {
				tmsBaseProviderModel.setPickUpPicture(Integer.parseInt(PublicMethods.reverseChange(restMessage, importVO.getPickUpPictureName())));
			}
			if (ToolKits.isNotEmpty(importVO.getAutoPickUpSignName())) {
				tmsBaseProviderModel.setAutoPickUpSign(Integer.parseInt(PublicMethods.reverseChange(restMessage, importVO.getAutoPickUpSignName())));
			}
			if (ToolKits.isNotEmpty(importVO.getPickUpSignName())) {
				tmsBaseProviderModel.setPickUpSign(Integer.parseInt(PublicMethods.reverseChange(restMessage, importVO.getPickUpSignName())));
			}
			if (ToolKits.isNotEmpty(importVO.getDeliveryPictureName())) {
				tmsBaseProviderModel.setDeliveryPicture(Integer.parseInt(PublicMethods.reverseChange(restMessage, importVO.getDeliveryPictureName())));
			}
			if (ToolKits.isNotEmpty(importVO.getAutoDeliverySignName())) {
				tmsBaseProviderModel.setAutoDeliverySign(Integer.parseInt(PublicMethods.reverseChange(restMessage, importVO.getAutoDeliverySignName())));
			}
			if (ToolKits.isNotEmpty(importVO.getDeliverySignName())) {
				tmsBaseProviderModel.setDeliverySign(Integer.parseInt(PublicMethods.reverseChange(restMessage, importVO.getDeliverySignName())));
			}
			if (ToolKits.isNotEmpty(importVO.getPickUpSignTime())) {
				tmsBaseProviderModel.setPickUpSignTime(Integer.valueOf(importVO.getPickUpSignTime()));
			}
			if (ToolKits.isNotEmpty(importVO.getPickUpSignTimeUnit())) {
				tmsBaseProviderModel.setPickUpSignTimeUnit(Integer.valueOf(importVO.getPickUpSignTimeUnit()));
			}
			if (ToolKits.isNotEmpty(importVO.getDeliverySignTime())) {
				tmsBaseProviderModel.setDeliverySignTime(Integer.valueOf(importVO.getDeliverySignTime()));
			}
			if (ToolKits.isNotEmpty(importVO.getDeliverySignTimeUnit())) {
				tmsBaseProviderModel.setDeliverySignTimeUnit(Integer.valueOf(importVO.getDeliverySignTimeUnit()));
			}
			tmsBaseProviderModel.setCreatetime(date);
			tmsBaseProviderModel.setCreateperson(user.getNickname());
			tmsBaseProviderModel.setUpdateperson(user.getNickname());
			tmsBaseProviderModel.setUpdatetime(date);
			tmsBaseProviderModel.setEnterpriseId(user.getEnterpriseId());
			tmsBaseProviderModel.setEnterpriseName(user.getEnterpriseName());
			tmsBaseProviderMapper.save(tmsBaseProviderModel);
			i++;
		}
		return i;
	}

	/**
	 * 供应商发货方资料导入(新)
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void batchInsertProviderShipperData(MultipartFile file) throws Exception {
		// 人员权限
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		// 导入文件判断
		FileUtils.multipartFileJudge(file);

		// 导入批次
		String importBatchNumber = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.IMPORT_BATCHNO, "L");
		ToolKits.isParamNull(importBatchNumber, "导入批次获取失败");

		// 导入日志对象
		ImportLogAddVO logAddVO = new ImportLogAddVO();
		logAddVO.setImportObjNo(DataDictionaryConstant.PROVIDER_SHIPPER_IMPORT);
		logAddVO.setImportBatchNumber(importBatchNumber);
		// 导入统计
		int count = 0;
		try {
			// 导入执行
			count = this.batchInsertProviderShipperProcess(file, importBatchNumber, user);
			logAddVO.setStatus(DataDictionaryConstant.IMPORT_STATUS_YES);
			logAddVO.setSuccessNum(count);
			logAddVO.setFailNum(0);
			importLogService.addImportLogData(logAddVO);
		} catch (Exception e) {
			Class<ShipperImportStdVO> importVOClass = ShipperImportStdVO.class;
			List<ShipperImportStdVO> importVOs = ExcelUtils.read(file, importVOClass);

			logAddVO.setStatus(DataDictionaryConstant.IMPORT_STATUS_NO);
			logAddVO.setSuccessNum(0);
			logAddVO.setFailNum(importVOs.size());
			logAddVO.setFailReason(e.getMessage());
			// 为了避免导入失败时导入日志的保存事务也被回滚,所以采用消息队列异步保存导入失败的日志
			amqpTemplate.convertAndSend(RabbitMQConstant.PROVIDER_SHIPPER_IMPORT_LOG, logAddVO);
			e.printStackTrace();
			throw new ParameterException(e.getMessage());
		}
	}

	// 供应商发货方异步保存导入失败日志
	@RabbitListener(queues = RabbitMQConstant.PROVIDER_SHIPPER_IMPORT_LOG)
	@Transactional(rollbackFor = Exception.class)
	public void saveFailImportLog2(ImportLogAddVO logAddVO) {
		try {
			importLogService.addImportLogData(logAddVO);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 供应商发货方导入过程(新)
	 *
	 * @param file
	 * @param
	 * @param
	 * @return
	 * @throws Exception
	 */
	public int batchInsertProviderShipperProcess(MultipartFile file, String importBatchNumber, UserEntity user) {
		Date date = new Date();
		Properties properties = new Properties();
		// 待转换的对象
		Class<ShipperImportStdVO> importVOClass = ShipperImportStdVO.class;
		// 标准模板查询
		List<StandardTemplateDetailsListDTO> standardTemplateDetailsListDTOs = sysImportTemplethService.listStandardTemplateDetailsData(DataDictionaryConstant.ITEM_CATEGORY_IMPORT);
		for (StandardTemplateDetailsListDTO standardTemplateDetailsListDTO : standardTemplateDetailsListDTOs) {
			// 属性字段和注解属性字段值 键值对
			properties.setProperty(standardTemplateDetailsListDTO.getStdColNo(), standardTemplateDetailsListDTO.getCustColName());
		}
		// @ExcelProperty注解属性修改
		ImportUtils.setHeaderValue(properties, importVOClass);
		// EXCEL转对象
		List<ShipperImportStdVO> importVOs = null;
		try {
			importVOs = ExcelUtils.read(file, importVOClass);
		} catch (Exception e) {
			e.printStackTrace();

			throw new ParameterException("EXCEL转对象失败:" + e.getMessage());
		}

		ToolKits.isParamNull(importVOs, "EXCEL文件内容为空,请重新导入");
		log.info("供应商发货方导入详情:{}", JsonMapper.toJson(importVOs));

		int i = 1;
		for (ShipperImportStdVO importVO : importVOs) {
			ToolKits.isParamNull(importVO.getProviderCode(), "第" + i + "行导入数据,供应商编码不能为空");
			ToolKits.isParamNull(importVO.getProviderName(), "第" + i + "行导入数据,供应商名称不能为空");
			ToolKits.isParamNull(importVO.getCode(), "第" + i + "行导入数据,发货方编码不能为空");
			ToolKits.isParamNull(importVO.getName(), "第" + i + "行导入数据,发货方名称不能为空");
			i++;
		}
		// 验证导入文件中供应商发货方编号是否重复
		Map<String, Long> codeMap = importVOs.stream().collect(Collectors.groupingBy(ShipperImportStdVO::getCode, Collectors.counting()));
		for (Map.Entry<String, Long> longEntry : codeMap.entrySet()) {
			if (longEntry.getValue() > 1) {
				throw new ParameterException(String.format("导入文件中，供应商发货方编号[%s]重复", longEntry.getKey()));
			}
		}
		// 验证导入文件中供应商发货方名称是否重复
		Map<String, Long> nameMap = importVOs.stream().collect(Collectors.groupingBy(ShipperImportStdVO::getName, Collectors.counting()));
		for (Map.Entry<String, Long> longEntry : nameMap.entrySet()) {
			if (longEntry.getValue() > 1) {
				throw new ParameterException(String.format("导入文件中，供应商发货方名称[%s]重复", longEntry.getKey()));
			}
		}

		i = 0;
		for (ShipperImportStdVO importVO : importVOs) {
			if (ToolKits.isNotEmpty(importVO.getPhoneNumber()) && !Validator.isMobile(importVO.getPhoneNumber())) {
				// throw new ParameterException(String.format("%s手机号不符合规范",
				// importVO.getPhoneNumber()));
				throw new ParameterException("第" + (i + 1) + "行导入数据,手机号格式不符合规范!");
			}

			if (ToolKits.isNotEmpty(importVO.getEmail()) && !Validator.isEmail(importVO.getEmail())) {
				// throw new ParameterException(String.format("%邮箱不符合规范", importVO.getEmail()));
				throw new ParameterException("第" + (i + 1) + "行导入数据,邮箱格式不符合规范!");
			}

			if (ToolKits.isNotEmpty(importVO.getLandlineNumber())) {
				Matcher matcher = null;
				Pattern p1 = Pattern.compile("^[0][1-9]{2,3}-[0-9]{5,10}$"); // 验证带区号的
				Pattern p2 = Pattern.compile("^[1-9]{1}[0-9]{5,8}$"); // 验证没有区号的
				if (importVO.getLandlineNumber().length() > 9) {
					matcher = p1.matcher(importVO.getLandlineNumber());
					if (!matcher.matches()) {
						throw new ParameterException("座机号不符合规范");
					}
				} else {
					matcher = p2.matcher(importVO.getLandlineNumber());
					if (!matcher.matches()) {
						throw new ParameterException("座机号不符合规范");
					}
				}
			}

			// 供应商发货方对象
			TmsBaseShipperModel tmsBaseShipperModel = new TmsBaseShipperModel();
			BeanUtils.copyProperties(importVO, tmsBaseShipperModel);

			Map<String, Object> map = Maps.newHashMap();
			map.put("code", importVO.getCode());
			map.put("enterpriseId", user.getEnterpriseId());
			map.put("status", StatusConstant.STATUS_ENABLE);

			Map<String, Object> map2 = Maps.newHashMap();
			map2.put("name", importVO.getName());
			map2.put("enterpriseId", user.getEnterpriseId());
			map2.put("status", StatusConstant.STATUS_ENABLE);

			// 判断发货方编码 发货方名称 是否已存在
			PublicMethods.doesItExistByMap(tmsBaseShipperMapper, map, TmsBaseShipperModel.class, "供应商发货方编码[" + importVO.getCode() + "]已存在");
			PublicMethods.doesItExistByMap(tmsBaseShipperMapper, map2, TmsBaseShipperModel.class, "供应商发货方名称[" + importVO.getName() + "]已存在");

			// 判断发货方编码 发货方名称 是否已停用
			map.put("status", StatusConstant.STATUS_DISABLE);
			map2.put("status", StatusConstant.STATUS_DISABLE);
			PublicMethods.doesItExistByMap(tmsBaseShipperMapper, map, TmsBaseShipperModel.class, "供应商发货方编码[" + importVO.getCode() + "]已停用,请直接启用");
			PublicMethods.doesItExistByMap(tmsBaseShipperMapper, map2, TmsBaseShipperModel.class, "供应商发货方名称[" + importVO.getName() + "]已停用,请直接启用");

			// 校验供应商编码和供应商名称是否匹配
			Criteria providerCriteria = Criteria.forClass(TmsBaseProviderModel.class);
			Restriction providerR1 = Restrictions.eq("code", importVO.getProviderCode());
			Restriction providerR2 = Restrictions.eq("name", importVO.getProviderName());
			Restriction providerR3 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
			providerCriteria.setRestriction(Restrictions.and(providerR1, providerR2, providerR3));
			List<TmsBaseProviderModel> tmsBaseProviderModels = tmsBaseProviderMapper.findByCriteria(providerCriteria);

			if (ToolKits.isEmpty(tmsBaseProviderModels)) {
				throw new ParameterException("供应商编码[" + importVO.getProviderCode() + "]与供应商名称[" + importVO.getProviderName() + "]不匹配，或者供应商不存在");
			}
			// 供应商发货方ID
			String shipperId = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_BASE_SHIPPER_ID, "L");
			ToolKits.isParamNull(shipperId, "供应商发货方ID生成失败");
			// 供应商发货方资料对象
			tmsBaseShipperModel.setId(Long.valueOf(shipperId));
			tmsBaseShipperModel.setStatus(StatusConstant.STATUS_ENABLE);
			tmsBaseShipperModel.setSource(DataDictionaryConstant.SOURCE_EXCEL);
			tmsBaseShipperModel.setImportBatchNumber(importBatchNumber);
			tmsBaseShipperModel.setEnterpriseId(user.getEnterpriseId());
			tmsBaseShipperModel.setEnterpriseName(user.getEnterpriseName());
			tmsBaseShipperModel.setCreateperson(user.getNickname());
			tmsBaseShipperModel.setCreatetime(date);
			tmsBaseShipperModel.setUpdateperson(user.getNickname());
			tmsBaseShipperModel.setUpdatetime(date);
			tmsBaseShipperMapper.save(tmsBaseShipperModel);

			// 生成供应商发货方关联数据
			TmsProviderShipperLinkModel tmsProviderShipperLinkModel = new TmsProviderShipperLinkModel();
			tmsProviderShipperLinkModel.setLineid(ToolKits.getUUID());
			tmsProviderShipperLinkModel.setProviderId(tmsBaseProviderModels.get(0).getId());
			tmsProviderShipperLinkModel.setProviderCode(tmsBaseProviderModels.get(0).getCode());
			tmsProviderShipperLinkModel.setProviderName(tmsBaseProviderModels.get(0).getName());
			tmsProviderShipperLinkModel.setShipperId(Long.valueOf(shipperId));
			tmsProviderShipperLinkModel.setShipperCode(tmsBaseShipperModel.getCode());
			tmsProviderShipperLinkModel.setShipperName(tmsBaseShipperModel.getName());
			tmsProviderShipperLinkModel.setCreateperson(user.getNickname());
			tmsProviderShipperLinkModel.setCreatetime(date);
			tmsProviderShipperLinkModel.setUpdateperson(user.getNickname());
			tmsProviderShipperLinkModel.setUpdatetime(date);
			tmsProviderShipperLinkMapper.save(tmsProviderShipperLinkModel);
			i++;
		}
		return i;
	}

	/**
	 * 运单导入时匹配供应商资料
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public ImportMatchingDataDTO importMatchingData(ImportMatchingDataVO importMatchingDataVO) {
		ToolKits.isParamNull(importMatchingDataVO, "请求参数不为空");
		ToolKits.isParamNull(importMatchingDataVO.getCargoOwnerId(), "货主ID不为空");

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

		// 查询供应商
		Criteria criteria = Criteria.forClass(TmsBaseProviderModel.class);
		Restriction r1 = ToolKits.isEmpty(importMatchingDataVO.getUnitCode()) ? null : Restrictions.eq(TmsBaseProviderModel::getCode, importMatchingDataVO.getUnitCode());
		Restriction r2 = Restrictions.eq(TmsBaseProviderModel::getName, importMatchingDataVO.getUnitName());
		Restriction r3 = Restrictions.eq(TmsBaseProviderModel::getEnterpriseId, user.getEnterpriseId());
		Restriction r4 = Restrictions.eq(TmsBaseProviderModel::getCargoOwnerId, importMatchingDataVO.getCargoOwnerId());
		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4));
		List<TmsBaseProviderModel> baseProviderModels = tmsBaseProviderMapper.findByCriteria(criteria);
		if (baseProviderModels.size() > 0) {
			Assert.isTrue(baseProviderModels.size() <= 1, "供应商资料【" + importMatchingDataVO.getUnitName() + "】维护重复");

			// 供应商对象
			TmsBaseProviderModel tmsBaseProviderModel = baseProviderModels.get(0);
			Assert.isTrue(tmsBaseProviderModel.getCargoOwnerId().intValue() == importMatchingDataVO.getCargoOwnerId().intValue(), "供应商资料【" + importMatchingDataVO.getUnitName() + "】不属于当前货主");

			// 供应商发货方关联查询
			Criteria criteria1 = Criteria.forClass(TmsProviderShipperLinkModel.class);
			Restriction r11 = Restrictions.eq(TmsProviderShipperLinkModel::getProviderId, tmsBaseProviderModel.getId());
			Restriction r12 = ToolKits.isEmpty(importMatchingDataVO.getCode()) ? null : Restrictions.eq(TmsProviderShipperLinkModel::getShipperCode, importMatchingDataVO.getCode());
			Restriction r13 = Restrictions.eq(TmsProviderShipperLinkModel::getShipperName, importMatchingDataVO.getName());
			criteria1.setRestriction(Restrictions.and(r11, r12, r13));
			List<TmsProviderShipperLinkModel> providerShipperLinkModels = tmsProviderShipperLinkMapper.findByCriteria(criteria1);

			// 供应商发货方
			TmsBaseShipperModel baseShipperModel = null;
			if (providerShipperLinkModels.size() > 0) {
				Assert.isTrue(providerShipperLinkModels.size() <= 1, "供应商关联资料【" + importMatchingDataVO.getName() + "】维护重复");

				// 供应商发货方关联对象
				TmsProviderShipperLinkModel providerShipperLinkModel = providerShipperLinkModels.get(0);

				// 供应商发货方资料查询
				Criteria criteria2 = Criteria.forClass(TmsBaseShipperModel.class);
				Restriction r21 = Restrictions.eq(TmsBaseShipperModel::getId, providerShipperLinkModel.getShipperId());
				Restriction r22 = Restrictions.eq(TmsBaseShipperModel::getEnterpriseId, user.getEnterpriseId());
				criteria2.setRestriction(Restrictions.and(r21, r22));
				List<TmsBaseShipperModel> tmsBaseShipperModels = tmsBaseShipperMapper.findByCriteria(criteria2);

				// 供应商发货方资料对象
				baseShipperModel = tmsBaseShipperModels.get(0);
			} else {
				Assert.isTrue(importMatchingDataVO.isNoSave(), "供应商发货方资料【" + importMatchingDataVO.getName() + "】未维护");

				// 供应商发货方对象
				String shipperId = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_BASE_SHIPPER_ID, "L");
				Assert.isTrue(ToolKits.isNotEmpty(shipperId), "供应商发货方ID生成为空");

				baseShipperModel = new TmsBaseShipperModel();
				baseShipperModel.setId(Long.valueOf(shipperId));
				if (ToolKits.isNotEmpty(importMatchingDataVO.getShipperName())) {
					baseShipperModel.setCode(ToolKits.isEmpty(importMatchingDataVO.getShipperCode()) ? "GYS-" + shipperId : importMatchingDataVO.getShipperCode());
					baseShipperModel.setName(importMatchingDataVO.getShipperName());
					baseShipperModel.setShortName(importMatchingDataVO.getShipperName());
					baseShipperModel.setContact(importMatchingDataVO.getShipperContact());
					baseShipperModel.setPhoneNumber(importMatchingDataVO.getShipperPhoneNumber());
					baseShipperModel.setLandlineNumber(importMatchingDataVO.getShipperLandlineNumber());
					baseShipperModel.setEmail(importMatchingDataVO.getShipperEmail());
					baseShipperModel.setProvince(importMatchingDataVO.getShipperProvince());
					baseShipperModel.setProvinceName(importMatchingDataVO.getShipperProvinceName());
					baseShipperModel.setCity(importMatchingDataVO.getShipperCity());
					baseShipperModel.setCityName(importMatchingDataVO.getShipperCityName());
					baseShipperModel.setDistrict(importMatchingDataVO.getShipperDistrict());
					baseShipperModel.setDistrictName(importMatchingDataVO.getShipperDistrictName());
					baseShipperModel.setAddress(importMatchingDataVO.getShipperAddress());
					baseShipperModel.setLongitude(importMatchingDataVO.getShipperLongitude());
					baseShipperModel.setLatitude(importMatchingDataVO.getShipperLatitude());
					baseShipperModel.setMemo(importMatchingDataVO.getShipperMemo());
				} else {
					baseShipperModel.setCode(ToolKits.isEmpty(importMatchingDataVO.getConsigneeCode()) ? "GYS-" + shipperId : importMatchingDataVO.getConsigneeCode());
					baseShipperModel.setName(importMatchingDataVO.getConsigneeName());
					baseShipperModel.setShortName(importMatchingDataVO.getConsigneeName());
					baseShipperModel.setContact(importMatchingDataVO.getConsigneeContact());
					baseShipperModel.setPhoneNumber(importMatchingDataVO.getConsigneePhoneNumber());
					baseShipperModel.setLandlineNumber(importMatchingDataVO.getConsigneeLandlineNumber());
					baseShipperModel.setEmail(importMatchingDataVO.getConsigneeEmail());
					baseShipperModel.setProvince(importMatchingDataVO.getConsigneeProvince());
					baseShipperModel.setProvinceName(importMatchingDataVO.getConsigneeProvinceName());
					baseShipperModel.setCity(importMatchingDataVO.getConsigneeCity());
					baseShipperModel.setCityName(importMatchingDataVO.getConsigneeCityName());
					baseShipperModel.setDistrict(importMatchingDataVO.getConsigneeDistrict());
					baseShipperModel.setDistrictName(importMatchingDataVO.getConsigneeDistrictName());
					baseShipperModel.setAddress(importMatchingDataVO.getConsigneeAddress());
					baseShipperModel.setLongitude(importMatchingDataVO.getConsigneeLongitude());
					baseShipperModel.setLatitude(importMatchingDataVO.getConsigneeLatitude());
					baseShipperModel.setMemo(importMatchingDataVO.getConsigneeMemo());
				}

				baseShipperModel.setStatus(StatusConstant.STATUS_ENABLE);
				baseShipperModel.setSource(DataDictionaryConstant.SOURCE_EXCEL);
				baseShipperModel.setEnterpriseId(user.getEnterpriseId());
				baseShipperModel.setEnterpriseName(user.getEnterpriseName());
				baseShipperModel.setCreatetime(DateUtil.date());
				baseShipperModel.setCreateperson(user.getNickname());
				baseShipperModel.setUpdateperson(user.getNickname());
				baseShipperModel.setUpdatetime(DateUtil.date());
				tmsBaseShipperMapper.save(baseShipperModel);

				// 供应商发货方关联对象
				TmsProviderShipperLinkModel tmsProviderShipperLinkModel = new TmsProviderShipperLinkModel();
				tmsProviderShipperLinkModel.setLineid(ToolKits.getUUID());
				tmsProviderShipperLinkModel.setProviderId(tmsBaseProviderModel.getId());
				tmsProviderShipperLinkModel.setProviderCode(tmsBaseProviderModel.getCode());
				tmsProviderShipperLinkModel.setProviderName(tmsBaseProviderModel.getName());
				tmsProviderShipperLinkModel.setShipperId(baseShipperModel.getId());
				tmsProviderShipperLinkModel.setShipperCode(baseShipperModel.getCode());
				tmsProviderShipperLinkModel.setShipperName(baseShipperModel.getName());
				tmsProviderShipperLinkModel.setCreateperson(baseShipperModel.getCreateperson());
				tmsProviderShipperLinkModel.setCreatetime(baseShipperModel.getCreatetime());
				tmsProviderShipperLinkModel.setUpdateperson(baseShipperModel.getUpdateperson());
				tmsProviderShipperLinkModel.setUpdatetime(baseShipperModel.getUpdatetime());
				tmsProviderShipperLinkMapper.save(tmsProviderShipperLinkModel);
			}

			// 响应对象
			ImportMatchingDataDTO importMatchingDataDTO = new ImportMatchingDataDTO();
			importMatchingDataDTO.setShipperUnitId(tmsBaseProviderModel.getId());
			importMatchingDataDTO.setShipperUnitCode(tmsBaseProviderModel.getCode());
			importMatchingDataDTO.setShipperUnitName(tmsBaseProviderModel.getName());
			importMatchingDataDTO.setShipperId(baseShipperModel.getId());
			importMatchingDataDTO.setShipperCode(baseShipperModel.getCode());
			importMatchingDataDTO.setShipperName(baseShipperModel.getName());
			importMatchingDataDTO.setShipperContact(baseShipperModel.getContact());
			importMatchingDataDTO.setShipperPhoneNumber(baseShipperModel.getPhoneNumber());
			importMatchingDataDTO.setShipperLandlineNumber(baseShipperModel.getLandlineNumber());
			importMatchingDataDTO.setShipperEmail(baseShipperModel.getEmail());
			importMatchingDataDTO.setShipperRelatedPhoneNumber(null);
			importMatchingDataDTO.setShipperProvince(baseShipperModel.getProvince());
			importMatchingDataDTO.setShipperProvinceName(baseShipperModel.getProvinceName());
			importMatchingDataDTO.setShipperCity(baseShipperModel.getCity());
			importMatchingDataDTO.setShipperCityName(baseShipperModel.getCityName());
			importMatchingDataDTO.setShipperDistrict(baseShipperModel.getDistrict());
			importMatchingDataDTO.setShipperDistrictName(baseShipperModel.getDistrictName());
			importMatchingDataDTO.setShipperAddress(baseShipperModel.getAddress());
			importMatchingDataDTO.setShipperLongitude(baseShipperModel.getLongitude());
			importMatchingDataDTO.setShipperLatitude(baseShipperModel.getLatitude());
			importMatchingDataDTO.setShipperMemo(baseShipperModel.getMemo());
			importMatchingDataDTO.setShipperPickUpSign(tmsBaseProviderModel.getPickUpSign());
			importMatchingDataDTO.setShipperAutoPickUpSign(tmsBaseProviderModel.getAutoPickUpSign());
			importMatchingDataDTO.setShipperPickUpPicture(tmsBaseProviderModel.getPickUpPicture());
			importMatchingDataDTO.setShipperPickUpRail(tmsBaseProviderModel.getDefaultPickUpRail());

			importMatchingDataDTO.setConsigneeUnitId(tmsBaseProviderModel.getId());
			importMatchingDataDTO.setConsigneeUnitCode(tmsBaseProviderModel.getCode());
			importMatchingDataDTO.setConsigneeUnitName(tmsBaseProviderModel.getName());
			importMatchingDataDTO.setConsigneeId(baseShipperModel.getId());
			importMatchingDataDTO.setConsigneeCode(baseShipperModel.getCode());
			importMatchingDataDTO.setConsigneeName(baseShipperModel.getName());
			importMatchingDataDTO.setConsigneeContact(baseShipperModel.getContact());
			importMatchingDataDTO.setConsigneePhoneNumber(baseShipperModel.getPhoneNumber());
			importMatchingDataDTO.setConsigneeLandlineNumber(baseShipperModel.getLandlineNumber());
			importMatchingDataDTO.setConsigneeEmail(baseShipperModel.getEmail());
			importMatchingDataDTO.setConsigneeRelatedPhoneNumber(null);
			importMatchingDataDTO.setConsigneeProvince(baseShipperModel.getProvince());
			importMatchingDataDTO.setConsigneeProvinceName(baseShipperModel.getProvinceName());
			importMatchingDataDTO.setConsigneeCity(baseShipperModel.getCity());
			importMatchingDataDTO.setConsigneeCityName(baseShipperModel.getCityName());
			importMatchingDataDTO.setConsigneeDistrict(baseShipperModel.getDistrict());
			importMatchingDataDTO.setConsigneeDistrictName(baseShipperModel.getDistrictName());
			importMatchingDataDTO.setConsigneeAddress(baseShipperModel.getAddress());
			importMatchingDataDTO.setConsigneeLongitude(baseShipperModel.getLongitude());
			importMatchingDataDTO.setConsigneeLatitude(baseShipperModel.getLatitude());
			importMatchingDataDTO.setConsigneeMemo(baseShipperModel.getMemo());
			importMatchingDataDTO.setConsigneeDeliverySign(tmsBaseProviderModel.getDeliverySign());
			importMatchingDataDTO.setConsigneeAutoDeliverySign(tmsBaseProviderModel.getAutoDeliverySign());
			importMatchingDataDTO.setConsigneeDeliveryPicture(tmsBaseProviderModel.getDeliveryPicture());
			importMatchingDataDTO.setConsigneeDeliveryRail(tmsBaseProviderModel.getDefaultDeliveryRail());
			importMatchingDataDTO.setReturnOrderFlag(StatusConstant.WHETHER_NO);
			importMatchingDataDTO.setReturnOrderDeadline(null);
			importMatchingDataDTO.setConsigneeReturnOrderPicture(tmsBaseProviderModel.getReturnOrderPicture());

			importMatchingDataDTO.setShipperSignTime(tmsBaseProviderModel.getPickUpSignTime());
			importMatchingDataDTO.setShipperSignTimeDura(tmsBaseProviderModel.getPickUpSignTimeDura());
			importMatchingDataDTO.setShipperSignTimeUnit(tmsBaseProviderModel.getPickUpSignTimeUnit());

			importMatchingDataDTO.setConsigneeSignTime(tmsBaseProviderModel.getDeliverySignTime());
			importMatchingDataDTO.setConsigneeSignTimeDura(tmsBaseProviderModel.getDeliverySignTimeDura());
			importMatchingDataDTO.setConsigneeSignTimeUnit(tmsBaseProviderModel.getDeliverySignTimeUnit());

			return importMatchingDataDTO;
		} else {
			Assert.isTrue(importMatchingDataVO.isNoSave(), "供应商资料【" + importMatchingDataVO.getUnitName() + "】未维护");

			String id = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_BASE_PROVIDER_ID, "L");
			Assert.isTrue(ToolKits.isNotEmpty(id), "供应商ID生成为空");

			TmsBaseProviderModel tmsBaseProviderModel = new TmsBaseProviderModel();
			tmsBaseProviderModel.setId(Long.valueOf(id));
			if (ToolKits.isNotEmpty(importMatchingDataVO.getShipperUnitName())) {
				tmsBaseProviderModel.setCode(ToolKits.isEmpty(importMatchingDataVO.getShipperUnitCode()) ? "GYS-" + id : importMatchingDataVO.getShipperUnitCode());
				tmsBaseProviderModel.setName(importMatchingDataVO.getShipperUnitName());
				tmsBaseProviderModel.setShortName(importMatchingDataVO.getShipperUnitName());

				tmsBaseProviderModel.setContractNature(DataDictionaryConstant.COOPERATIVE_NATURE_LS);
				tmsBaseProviderModel.setMemo(importMatchingDataVO.getShipperMemo());
				tmsBaseProviderModel.setContact(importMatchingDataVO.getShipperContact());
				tmsBaseProviderModel.setPhoneNumber(importMatchingDataVO.getShipperPhoneNumber());
				tmsBaseProviderModel.setLandlineNumber(importMatchingDataVO.getShipperLandlineNumber());
				tmsBaseProviderModel.setEmail(importMatchingDataVO.getShipperEmail());
				tmsBaseProviderModel.setPostCode(null);
				tmsBaseProviderModel.setProvince(importMatchingDataVO.getShipperProvince());
				tmsBaseProviderModel.setProvinceName(importMatchingDataVO.getShipperProvinceName());
				tmsBaseProviderModel.setCity(importMatchingDataVO.getShipperCity());
				tmsBaseProviderModel.setCityName(importMatchingDataVO.getShipperCityName());
				tmsBaseProviderModel.setDistrict(importMatchingDataVO.getShipperDistrict());
				tmsBaseProviderModel.setDistrictName(importMatchingDataVO.getShipperDistrictName());
				tmsBaseProviderModel.setAddress(importMatchingDataVO.getShipperAddress());
				tmsBaseProviderModel.setLongitude(importMatchingDataVO.getShipperLongitude());
				tmsBaseProviderModel.setLatitude(importMatchingDataVO.getShipperLatitude());

				tmsBaseProviderModel.setPickUpSign(ToolKits.isEmpty(importMatchingDataVO.getShipperPickUpSign()) ? StatusConstant.WHETHER_NO : importMatchingDataVO.getShipperPickUpSign());
				tmsBaseProviderModel.setAutoPickUpSign(ToolKits.isEmpty(importMatchingDataVO.getShipperAutoPickUpSign()) ? StatusConstant.WHETHER_NO : importMatchingDataVO.getShipperAutoPickUpSign());
				tmsBaseProviderModel.setPickUpPicture(ToolKits.isEmpty(importMatchingDataVO.getShipperPickUpPicture()) ? StatusConstant.WHETHER_NO : importMatchingDataVO.getShipperPickUpPicture());
				tmsBaseProviderModel.setDefaultPickUpRail(importMatchingDataVO.getShipperPickUpRail());
				tmsBaseProviderModel.setPickUpSignTime(importMatchingDataVO.getShipperSignTime());
				tmsBaseProviderModel.setPickUpSignTimeDura(importMatchingDataVO.getShipperSignTimeDura());
				tmsBaseProviderModel.setPickUpSignTimeUnit(importMatchingDataVO.getShipperSignTimeUnit());

				tmsBaseProviderModel.setDeliverySign(StatusConstant.WHETHER_NO);
				tmsBaseProviderModel.setAutoDeliverySign(StatusConstant.WHETHER_NO);
				tmsBaseProviderModel.setDeliveryPicture(StatusConstant.WHETHER_NO);
				tmsBaseProviderModel.setReturnOrderPicture(StatusConstant.WHETHER_NO);
				tmsBaseProviderModel.setDefaultDeliveryRail(null);
				tmsBaseProviderModel.setDeliverySignTime(null);
				tmsBaseProviderModel.setDeliverySignTimeDura(null);
				tmsBaseProviderModel.setDeliverySignTimeUnit(null);
			} else {
				tmsBaseProviderModel.setCode(ToolKits.isEmpty(importMatchingDataVO.getConsigneeUnitCode()) ? "GYS-" + id : importMatchingDataVO.getConsigneeUnitCode());
				tmsBaseProviderModel.setName(importMatchingDataVO.getConsigneeUnitName());
				tmsBaseProviderModel.setShortName(importMatchingDataVO.getConsigneeUnitName());

				tmsBaseProviderModel.setContractNature(DataDictionaryConstant.COOPERATIVE_NATURE_LS);
				tmsBaseProviderModel.setMemo(importMatchingDataVO.getConsigneeMemo());
				tmsBaseProviderModel.setContact(importMatchingDataVO.getConsigneeContact());
				tmsBaseProviderModel.setPhoneNumber(importMatchingDataVO.getConsigneePhoneNumber());
				tmsBaseProviderModel.setLandlineNumber(importMatchingDataVO.getConsigneeLandlineNumber());
				tmsBaseProviderModel.setEmail(importMatchingDataVO.getConsigneeEmail());
				tmsBaseProviderModel.setPostCode(null);
				tmsBaseProviderModel.setProvince(importMatchingDataVO.getConsigneeProvince());
				tmsBaseProviderModel.setProvinceName(importMatchingDataVO.getConsigneeProvinceName());
				tmsBaseProviderModel.setCity(importMatchingDataVO.getConsigneeCity());
				tmsBaseProviderModel.setCityName(importMatchingDataVO.getConsigneeCityName());
				tmsBaseProviderModel.setDistrict(importMatchingDataVO.getConsigneeDistrict());
				tmsBaseProviderModel.setDistrictName(importMatchingDataVO.getConsigneeDistrictName());
				tmsBaseProviderModel.setAddress(importMatchingDataVO.getConsigneeAddress());
				tmsBaseProviderModel.setLongitude(importMatchingDataVO.getConsigneeLongitude());
				tmsBaseProviderModel.setLatitude(importMatchingDataVO.getConsigneeLatitude());

				tmsBaseProviderModel.setPickUpSign(StatusConstant.WHETHER_NO);
				tmsBaseProviderModel.setAutoPickUpSign(StatusConstant.WHETHER_NO);
				tmsBaseProviderModel.setPickUpPicture(StatusConstant.WHETHER_NO);
				tmsBaseProviderModel.setDefaultPickUpRail(null);
				tmsBaseProviderModel.setPickUpSignTime(null);
				tmsBaseProviderModel.setPickUpSignTimeDura(null);
				tmsBaseProviderModel.setPickUpSignTimeUnit(null);

				tmsBaseProviderModel.setDeliverySign(ToolKits.isEmpty(importMatchingDataVO.getConsigneeDeliverySign()) ? StatusConstant.WHETHER_NO : importMatchingDataVO.getConsigneeDeliverySign());
				tmsBaseProviderModel.setAutoDeliverySign(ToolKits.isEmpty(importMatchingDataVO.getConsigneeAutoDeliverySign()) ? StatusConstant.WHETHER_NO : importMatchingDataVO.getConsigneeAutoDeliverySign());
				tmsBaseProviderModel.setDeliveryPicture(ToolKits.isEmpty(importMatchingDataVO.getConsigneeDeliveryPicture()) ? StatusConstant.WHETHER_NO : importMatchingDataVO.getConsigneeDeliveryPicture());
				tmsBaseProviderModel.setReturnOrderPicture(ToolKits.isEmpty(importMatchingDataVO.getConsigneeReturnOrderPicture()) ? StatusConstant.WHETHER_NO : importMatchingDataVO.getConsigneeReturnOrderPicture());
				tmsBaseProviderModel.setDefaultDeliveryRail(importMatchingDataVO.getConsigneeDeliveryRail());
				tmsBaseProviderModel.setDeliverySignTime(importMatchingDataVO.getConsigneeSignTime());
				tmsBaseProviderModel.setDeliverySignTimeDura(importMatchingDataVO.getConsigneeSignTimeDura());
				tmsBaseProviderModel.setDeliverySignTimeUnit(importMatchingDataVO.getConsigneeSignTimeUnit());
			}

			tmsBaseProviderModel.setCargoOwnerId(importMatchingDataVO.getCargoOwnerId());
			tmsBaseProviderModel.setCargoOwnerCode(importMatchingDataVO.getCargoOwnerCode());
			tmsBaseProviderModel.setCargoOwnerName(importMatchingDataVO.getCargoOwnerName());
			tmsBaseProviderModel.setStatus(StatusConstant.STATUS_ENABLE);
			tmsBaseProviderModel.setSource(DataDictionaryConstant.SOURCE_EXCEL);
			tmsBaseProviderModel.setDepartmentId(importMatchingDataVO.getDepartmentId());
			tmsBaseProviderModel.setDepartmentCode(importMatchingDataVO.getDepartmentCode());
			tmsBaseProviderModel.setDepartmentName(importMatchingDataVO.getDepartmentName());
			tmsBaseProviderModel.setEnterpriseId(user.getEnterpriseId());
			tmsBaseProviderModel.setEnterpriseName(user.getEnterpriseName());
			tmsBaseProviderModel.setCreatetime(DateUtil.date());
			tmsBaseProviderModel.setCreateperson(user.getNickname());
			tmsBaseProviderModel.setUpdatetime(DateUtil.date());
			tmsBaseProviderModel.setUpdateperson(user.getNickname());
			tmsBaseProviderMapper.save(tmsBaseProviderModel);

			// 供应商发货方对象
			String shipperId = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_BASE_SHIPPER_ID, "L");
			Assert.isTrue(ToolKits.isNotEmpty(shipperId), "供应商发货方ID生成为空");

			TmsBaseShipperModel tmsBaseShipperModel = new TmsBaseShipperModel();
			tmsBaseShipperModel.setId(Long.valueOf(shipperId));
			tmsBaseShipperModel.setCode(ToolKits.isEmpty(importMatchingDataVO.getCode()) ? "GYS-" + shipperId : importMatchingDataVO.getCode());
			tmsBaseShipperModel.setName(importMatchingDataVO.getName());
			tmsBaseShipperModel.setShortName(importMatchingDataVO.getName());
			tmsBaseShipperModel.setStatus(tmsBaseProviderModel.getStatus());
			tmsBaseShipperModel.setContact(tmsBaseProviderModel.getContact());
			tmsBaseShipperModel.setPhoneNumber(tmsBaseProviderModel.getPhoneNumber());
			tmsBaseShipperModel.setLandlineNumber(tmsBaseProviderModel.getLandlineNumber());
			tmsBaseShipperModel.setEmail(tmsBaseProviderModel.getEmail());
			tmsBaseShipperModel.setProvince(tmsBaseProviderModel.getProvince());
			tmsBaseShipperModel.setProvinceName(tmsBaseProviderModel.getProvinceName());
			tmsBaseShipperModel.setCity(tmsBaseProviderModel.getCity());
			tmsBaseShipperModel.setCityName(tmsBaseProviderModel.getCityName());
			tmsBaseShipperModel.setDistrict(tmsBaseProviderModel.getDistrict());
			tmsBaseShipperModel.setDistrictName(tmsBaseProviderModel.getDistrictName());
			tmsBaseShipperModel.setAddress(tmsBaseProviderModel.getAddress());
			tmsBaseShipperModel.setLongitude(tmsBaseProviderModel.getLongitude());
			tmsBaseShipperModel.setLatitude(tmsBaseProviderModel.getLatitude());
			tmsBaseShipperModel.setMemo(tmsBaseProviderModel.getMemo());
			tmsBaseShipperModel.setSource(tmsBaseProviderModel.getSource());
			tmsBaseShipperModel.setEnterpriseId(tmsBaseProviderModel.getEnterpriseId());
			tmsBaseShipperModel.setEnterpriseName(tmsBaseProviderModel.getEnterpriseName());
			tmsBaseShipperModel.setCreatetime(tmsBaseProviderModel.getCreatetime());
			tmsBaseShipperModel.setCreateperson(tmsBaseProviderModel.getCreateperson());
			tmsBaseShipperModel.setUpdatetime(tmsBaseProviderModel.getUpdatetime());
			tmsBaseShipperModel.setUpdateperson(tmsBaseProviderModel.getUpdateperson());
			tmsBaseShipperMapper.save(tmsBaseShipperModel);

			// 供应商发货方关联对象
			TmsProviderShipperLinkModel tmsProviderShipperLinkModel = new TmsProviderShipperLinkModel();
			tmsProviderShipperLinkModel.setLineid(ToolKits.getUUID());
			tmsProviderShipperLinkModel.setProviderId(tmsBaseProviderModel.getId());
			tmsProviderShipperLinkModel.setProviderCode(tmsBaseProviderModel.getCode());
			tmsProviderShipperLinkModel.setProviderName(tmsBaseProviderModel.getName());
			tmsProviderShipperLinkModel.setShipperId(tmsBaseShipperModel.getId());
			tmsProviderShipperLinkModel.setShipperCode(tmsBaseShipperModel.getCode());
			tmsProviderShipperLinkModel.setShipperName(tmsBaseShipperModel.getName());
			tmsProviderShipperLinkModel.setCreateperson(tmsBaseProviderModel.getCreateperson());
			tmsProviderShipperLinkModel.setCreatetime(tmsBaseProviderModel.getCreatetime());
			tmsProviderShipperLinkModel.setUpdateperson(tmsBaseProviderModel.getUpdateperson());
			tmsProviderShipperLinkModel.setUpdatetime(tmsBaseProviderModel.getUpdatetime());
			tmsProviderShipperLinkMapper.save(tmsProviderShipperLinkModel);

			// 响应对象
			ImportMatchingDataDTO importMatchingDataDTO = new ImportMatchingDataDTO();
			importMatchingDataDTO.setShipperUnitId(tmsBaseProviderModel.getId());
			importMatchingDataDTO.setShipperUnitCode(tmsBaseProviderModel.getCode());
			importMatchingDataDTO.setShipperUnitName(tmsBaseProviderModel.getName());
			importMatchingDataDTO.setShipperId(tmsBaseShipperModel.getId());
			importMatchingDataDTO.setShipperCode(tmsBaseShipperModel.getCode());
			importMatchingDataDTO.setShipperName(tmsBaseShipperModel.getName());
			importMatchingDataDTO.setShipperContact(tmsBaseShipperModel.getContact());
			importMatchingDataDTO.setShipperPhoneNumber(tmsBaseShipperModel.getPhoneNumber());
			importMatchingDataDTO.setShipperLandlineNumber(tmsBaseShipperModel.getLandlineNumber());
			importMatchingDataDTO.setShipperEmail(tmsBaseShipperModel.getEmail());
			importMatchingDataDTO.setShipperRelatedPhoneNumber(null);
			importMatchingDataDTO.setShipperProvince(tmsBaseShipperModel.getProvince());
			importMatchingDataDTO.setShipperProvinceName(tmsBaseShipperModel.getProvinceName());
			importMatchingDataDTO.setShipperCity(tmsBaseShipperModel.getCity());
			importMatchingDataDTO.setShipperCityName(tmsBaseShipperModel.getCityName());
			importMatchingDataDTO.setShipperDistrict(tmsBaseShipperModel.getDistrict());
			importMatchingDataDTO.setShipperDistrictName(tmsBaseShipperModel.getDistrictName());
			importMatchingDataDTO.setShipperAddress(tmsBaseShipperModel.getAddress());
			importMatchingDataDTO.setShipperLongitude(tmsBaseShipperModel.getLongitude());
			importMatchingDataDTO.setShipperLatitude(tmsBaseShipperModel.getLatitude());
			importMatchingDataDTO.setShipperMemo(tmsBaseShipperModel.getMemo());
			importMatchingDataDTO.setShipperPickUpSign(tmsBaseProviderModel.getPickUpSign());
			importMatchingDataDTO.setShipperAutoPickUpSign(tmsBaseProviderModel.getAutoPickUpSign());
			importMatchingDataDTO.setShipperPickUpPicture(tmsBaseProviderModel.getPickUpPicture());
			importMatchingDataDTO.setShipperPickUpRail(tmsBaseProviderModel.getDefaultPickUpRail());

			importMatchingDataDTO.setConsigneeUnitId(tmsBaseProviderModel.getId());
			importMatchingDataDTO.setConsigneeUnitCode(tmsBaseProviderModel.getCode());
			importMatchingDataDTO.setConsigneeUnitName(tmsBaseProviderModel.getName());
			importMatchingDataDTO.setConsigneeId(tmsBaseShipperModel.getId());
			importMatchingDataDTO.setConsigneeCode(tmsBaseShipperModel.getCode());
			importMatchingDataDTO.setConsigneeName(tmsBaseShipperModel.getName());
			importMatchingDataDTO.setConsigneeContact(tmsBaseShipperModel.getContact());
			importMatchingDataDTO.setConsigneePhoneNumber(tmsBaseShipperModel.getPhoneNumber());
			importMatchingDataDTO.setConsigneeLandlineNumber(tmsBaseShipperModel.getLandlineNumber());
			importMatchingDataDTO.setConsigneeEmail(tmsBaseShipperModel.getEmail());
			importMatchingDataDTO.setConsigneeRelatedPhoneNumber(null);
			importMatchingDataDTO.setConsigneeProvince(tmsBaseShipperModel.getProvince());
			importMatchingDataDTO.setConsigneeProvinceName(tmsBaseShipperModel.getProvinceName());
			importMatchingDataDTO.setConsigneeCity(tmsBaseShipperModel.getCity());
			importMatchingDataDTO.setConsigneeCityName(tmsBaseShipperModel.getCityName());
			importMatchingDataDTO.setConsigneeDistrict(tmsBaseShipperModel.getDistrict());
			importMatchingDataDTO.setConsigneeDistrictName(tmsBaseShipperModel.getDistrictName());
			importMatchingDataDTO.setConsigneeAddress(tmsBaseShipperModel.getAddress());
			importMatchingDataDTO.setConsigneeLongitude(tmsBaseShipperModel.getLongitude());
			importMatchingDataDTO.setConsigneeLatitude(tmsBaseShipperModel.getLatitude());
			importMatchingDataDTO.setConsigneeMemo(tmsBaseShipperModel.getMemo());
			importMatchingDataDTO.setConsigneeDeliverySign(tmsBaseProviderModel.getDeliverySign());
			importMatchingDataDTO.setConsigneeAutoDeliverySign(tmsBaseProviderModel.getAutoDeliverySign());
			importMatchingDataDTO.setConsigneeDeliveryPicture(tmsBaseProviderModel.getDeliveryPicture());
			importMatchingDataDTO.setConsigneeDeliveryRail(tmsBaseProviderModel.getDefaultDeliveryRail());
			importMatchingDataDTO.setReturnOrderFlag(StatusConstant.WHETHER_NO);
			importMatchingDataDTO.setReturnOrderDeadline(null);
			importMatchingDataDTO.setConsigneeReturnOrderPicture(tmsBaseProviderModel.getReturnOrderPicture());

			importMatchingDataDTO.setShipperSignTime(tmsBaseProviderModel.getPickUpSignTime());
			importMatchingDataDTO.setShipperSignTimeDura(tmsBaseProviderModel.getPickUpSignTimeDura());
			importMatchingDataDTO.setShipperSignTimeUnit(tmsBaseProviderModel.getPickUpSignTimeUnit());

			importMatchingDataDTO.setConsigneeSignTime(tmsBaseProviderModel.getDeliverySignTime());
			importMatchingDataDTO.setConsigneeSignTimeDura(tmsBaseProviderModel.getDeliverySignTimeDura());
			importMatchingDataDTO.setConsigneeSignTimeUnit(tmsBaseProviderModel.getDeliverySignTimeUnit());

			return importMatchingDataDTO;
		}
	}

	/**
	 * 供应商接口转TMS
	 */
	@Override
	public List<IntfErrorLogDTO> saveProviderInterfaceData(List<IntfProviderSaveVO> intfProviderSaveVOs) {
		// 响应集合
		List<IntfErrorLogDTO> intfErrorLogDTOs = Lists.newArrayList();

		Date date = DateUtil.date();

		// 循环处理
		for (IntfProviderSaveVO intfProviderSaveVO : intfProviderSaveVOs) {
			// 响应对象
			IntfErrorLogDTO intfErrorLogDTO = new IntfErrorLogDTO();

			try {
				// 货主校验
				Criteria criteria1 = Criteria.forClass(TmsBaseCargoOwnerModel.class);
				Restriction r11 = Restrictions.eq(TmsBaseCargoOwnerModel::getCargoOwnerCode, intfProviderSaveVO.getCargoOwnerCode());
				Restriction r12 = Restrictions.eq(TmsBaseCargoOwnerModel::getCargoOwnerName, intfProviderSaveVO.getCargoOwnerName());
				Restriction r13 = Restrictions.eq(TmsBaseCargoOwnerModel::getEnterpriseId, intfProviderSaveVO.getEnterpriseId());
				criteria1.setRestriction(Restrictions.and(r11, r12, r13));
				List<TmsBaseCargoOwnerModel> tmsBaseCargoOwnerModels = tmsBaseCargoOwnerMapper.findByCriteria(criteria1);
				Assert.isTrue(tmsBaseCargoOwnerModels.size() > 0, "货主【" + intfProviderSaveVO.getCargoOwnerName() + "】不存在");
				Assert.isTrue(tmsBaseCargoOwnerModels.size() <= 1, "货主【" + intfProviderSaveVO.getCargoOwnerName() + "】资料重复");

				// 货主对象
				TmsBaseCargoOwnerModel baseCargoOwnerModel = tmsBaseCargoOwnerModels.get(0);
				Assert.isTrue(baseCargoOwnerModel.getStatus().intValue() == StatusConstant.STATUS_ENABLE.intValue(), "货主【" + intfProviderSaveVO.getCargoOwnerName() + "】已停用");

				// 校验供应商
				Criteria criteria = Criteria.forClass(TmsBaseProviderModel.class);
				Restriction r1 = Restrictions.eq(TmsBaseProviderModel::getCode, intfProviderSaveVO.getCode());
				Restriction r2 = Restrictions.eq(TmsBaseProviderModel::getCargoOwnerId, baseCargoOwnerModel.getCargoOwnerId());
				Restriction r3 = Restrictions.eq(TmsBaseProviderModel::getEnterpriseId, intfProviderSaveVO.getEnterpriseId());
				criteria.setRestriction(Restrictions.and(r1, r2, r3));
				List<TmsBaseProviderModel> tmsBaseProviderModels = tmsBaseProviderMapper.findByCriteria(criteria);
				if (tmsBaseProviderModels.size() > 0) {
					Assert.isTrue(tmsBaseProviderModels.size() <= 1, "供应商编码[" + intfProviderSaveVO.getCode() + "]维护重复");

					// 供应商资料对象
					TmsBaseProviderModel tmsBaseProviderModel = tmsBaseProviderModels.get(0);
					tmsBaseProviderModel.setName(intfProviderSaveVO.getName());
					tmsBaseProviderModel.setShortName(intfProviderSaveVO.getShortName());
					tmsBaseProviderModel.setCargoOwnerId(baseCargoOwnerModel.getCargoOwnerId());
					tmsBaseProviderModel.setCargoOwnerCode(baseCargoOwnerModel.getCargoOwnerCode());
					tmsBaseProviderModel.setCargoOwnerName(baseCargoOwnerModel.getCargoOwnerName());
					tmsBaseProviderModel.setContractNature(intfProviderSaveVO.getContractNature());
					tmsBaseProviderModel.setStatus(intfProviderSaveVO.getStatus());
					tmsBaseProviderModel.setTaxRegisterNumber(intfProviderSaveVO.getTaxRegisterNumber());
					tmsBaseProviderModel.setBusinessLicenseNumber(intfProviderSaveVO.getBusinessLicenseNumber());
					tmsBaseProviderModel.setMemo(intfProviderSaveVO.getMemo());
					tmsBaseProviderModel.setContact(intfProviderSaveVO.getContact());
					tmsBaseProviderModel.setPhoneNumber(intfProviderSaveVO.getPhoneNumber());
					tmsBaseProviderModel.setLandlineNumber(intfProviderSaveVO.getLandlineNumber());
					tmsBaseProviderModel.setEmail(intfProviderSaveVO.getEmail());
					tmsBaseProviderModel.setPostCode(intfProviderSaveVO.getPostCode());
					tmsBaseProviderModel.setProvince(intfProviderSaveVO.getProvince());
					tmsBaseProviderModel.setProvinceName(intfProviderSaveVO.getProvinceName());
					tmsBaseProviderModel.setCity(intfProviderSaveVO.getCity());
					tmsBaseProviderModel.setCityName(intfProviderSaveVO.getCityName());
					tmsBaseProviderModel.setDistrict(intfProviderSaveVO.getDistrict());
					tmsBaseProviderModel.setDistrictName(intfProviderSaveVO.getDistrictName());
					tmsBaseProviderModel.setAddress(intfProviderSaveVO.getAddress());
					tmsBaseProviderModel.setLongitude(intfProviderSaveVO.getLongitude());
					tmsBaseProviderModel.setLatitude(intfProviderSaveVO.getLatitude());
					tmsBaseProviderModel.setLegalman(intfProviderSaveVO.getLegalman());
					tmsBaseProviderModel.setInvoice(intfProviderSaveVO.getInvoice());
					tmsBaseProviderModel.setInvoiceTaxNumber(intfProviderSaveVO.getInvoiceTaxNumber());
					tmsBaseProviderModel.setRegisteredCapital(intfProviderSaveVO.getRegisteredCapital());
					tmsBaseProviderModel.setBank(intfProviderSaveVO.getBank());
					tmsBaseProviderModel.setBankAccount(intfProviderSaveVO.getBankAccount());
					tmsBaseProviderModel.setEstablished(intfProviderSaveVO.getEstablished());
					tmsBaseProviderModel.setRegisteredAddress(intfProviderSaveVO.getRegisteredAddress());
					tmsBaseProviderModel.setPickUpSign(ToolKits.isEmpty(intfProviderSaveVO.getPickUpSign()) ? StatusConstant.WHETHER_NO : intfProviderSaveVO.getPickUpSign());
					tmsBaseProviderModel.setAutoPickUpSign(ToolKits.isEmpty(intfProviderSaveVO.getAutoPickUpSign()) ? StatusConstant.WHETHER_NO : intfProviderSaveVO.getAutoPickUpSign());
					tmsBaseProviderModel.setPickUpPicture(ToolKits.isEmpty(intfProviderSaveVO.getPickUpPicture()) ? StatusConstant.WHETHER_NO : intfProviderSaveVO.getPickUpPicture());
					tmsBaseProviderModel.setDefaultPickUpRail(intfProviderSaveVO.getDefaultPickUpRail());
					tmsBaseProviderModel.setDeliverySign(ToolKits.isEmpty(intfProviderSaveVO.getDeliverySign()) ? StatusConstant.WHETHER_NO : intfProviderSaveVO.getDeliverySign());
					tmsBaseProviderModel.setAutoDeliverySign(ToolKits.isEmpty(intfProviderSaveVO.getAutoDeliverySign()) ? StatusConstant.WHETHER_NO : intfProviderSaveVO.getAutoDeliverySign());
					tmsBaseProviderModel.setDeliveryPicture(ToolKits.isEmpty(intfProviderSaveVO.getDeliveryPicture()) ? StatusConstant.WHETHER_NO : intfProviderSaveVO.getDeliveryPicture());
					tmsBaseProviderModel.setDefaultDeliveryRail(intfProviderSaveVO.getDefaultDeliveryRail());
					tmsBaseProviderModel.setReturnOrderPicture(ToolKits.isEmpty(intfProviderSaveVO.getReturnOrderPicture()) ? StatusConstant.WHETHER_NO : intfProviderSaveVO.getReturnOrderPicture());
					tmsBaseProviderModel.setUpdatetime(date);
					tmsBaseProviderMapper.update(tmsBaseProviderModel);

					// 更新供应商发货方
					Criteria criteria3 = Criteria.forClass(TmsProviderShipperLinkModel.class);
					Restriction r31 = Restrictions.eq(TmsProviderShipperLinkModel::getProviderId, tmsBaseProviderModel.getId());
					Restriction r32 = Restrictions.eq(TmsProviderShipperLinkModel::getProviderCode, tmsBaseProviderModel.getCode());
					Restriction r33 = Restrictions.eq(TmsProviderShipperLinkModel::getShipperCode, tmsBaseProviderModel.getCode());
					criteria3.setRestriction(Restrictions.and(r31, r32, r33));
					List<TmsProviderShipperLinkModel> providerShipperLinkModels = tmsProviderShipperLinkMapper.findByCriteria(criteria3);
					if (providerShipperLinkModels.size() > 0) {
						Assert.isTrue(providerShipperLinkModels.size() <= 1, "供应商发货方关联供应商[" + intfProviderSaveVO.getName() + "]重复");

						// 供应商发货方关联对象
						TmsProviderShipperLinkModel tmsProviderShipperLinkModel = providerShipperLinkModels.get(0);
						tmsProviderShipperLinkModel.setProviderName(tmsBaseProviderModel.getName());
						tmsProviderShipperLinkModel.setShipperName(tmsBaseProviderModel.getName());
						tmsProviderShipperLinkModel.setUpdatetime(date);
						tmsProviderShipperLinkMapper.update(tmsProviderShipperLinkModel);

						// 供应商发货方对象
						TmsBaseShipperModel tmsBaseShipperModel = tmsBaseShipperMapper.findById(tmsProviderShipperLinkModel.getShipperId(), TmsBaseShipperModel.class);
						tmsBaseShipperModel.setName(tmsBaseProviderModel.getName());
						tmsBaseShipperModel.setShortName(tmsBaseProviderModel.getShortName());
						tmsBaseShipperModel.setStatus(tmsBaseProviderModel.getStatus());
						tmsBaseShipperModel.setContact(tmsBaseProviderModel.getContact());
						tmsBaseShipperModel.setPhoneNumber(tmsBaseProviderModel.getPhoneNumber());
						tmsBaseShipperModel.setLandlineNumber(tmsBaseProviderModel.getLandlineNumber());
						tmsBaseShipperModel.setEmail(tmsBaseProviderModel.getEmail());
						tmsBaseShipperModel.setProvince(tmsBaseProviderModel.getProvince());
						tmsBaseShipperModel.setProvinceName(tmsBaseProviderModel.getProvinceName());
						tmsBaseShipperModel.setCity(tmsBaseProviderModel.getCity());
						tmsBaseShipperModel.setCityName(tmsBaseProviderModel.getCityName());
						tmsBaseShipperModel.setDistrict(tmsBaseProviderModel.getDistrict());
						tmsBaseShipperModel.setDistrictName(tmsBaseProviderModel.getDistrictName());
						tmsBaseShipperModel.setAddress(tmsBaseProviderModel.getAddress());
						tmsBaseShipperModel.setLongitude(tmsBaseProviderModel.getLongitude());
						tmsBaseShipperModel.setLatitude(tmsBaseProviderModel.getLatitude());
						tmsBaseShipperModel.setMemo(tmsBaseProviderModel.getMemo());
						tmsBaseShipperModel.setExtStr1(tmsBaseProviderModel.getExtStr1());
						tmsBaseShipperModel.setExtStr2(tmsBaseProviderModel.getExtStr2());
						tmsBaseShipperModel.setExtStr3(tmsBaseProviderModel.getExtStr3());
						tmsBaseShipperModel.setExtStr4(tmsBaseProviderModel.getExtStr4());
						tmsBaseShipperModel.setExtStr5(tmsBaseProviderModel.getExtStr5());
						tmsBaseShipperModel.setExtDate1(tmsBaseProviderModel.getExtDate1());
						tmsBaseShipperModel.setExtDate2(tmsBaseProviderModel.getExtDate2());
						tmsBaseShipperModel.setExtDate3(tmsBaseProviderModel.getExtDate3());
						tmsBaseShipperModel.setExtDate4(tmsBaseProviderModel.getExtDate4());
						tmsBaseShipperModel.setExtDate5(tmsBaseProviderModel.getExtDate5());
						tmsBaseShipperModel.setExtNum1(tmsBaseProviderModel.getExtNum1());
						tmsBaseShipperModel.setExtNum2(tmsBaseProviderModel.getExtNum2());
						tmsBaseShipperModel.setExtNum3(tmsBaseProviderModel.getExtNum3());
						tmsBaseShipperModel.setExtNum4(tmsBaseProviderModel.getExtNum4());
						tmsBaseShipperModel.setExtNum5(tmsBaseProviderModel.getExtNum5());
						tmsBaseShipperModel.setUpdatetime(date);
						tmsBaseShipperMapper.update(tmsBaseShipperModel);
					} else {
						// 供应商发货方对象
						String shipperId = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_BASE_SHIPPER_ID, "L");
						Assert.isTrue(ToolKits.isNotEmpty(shipperId), "供应商发货方ID生成为空");

						TmsBaseShipperModel tmsBaseShipperModel = new TmsBaseShipperModel();
						tmsBaseShipperModel.setId(Long.valueOf(shipperId));
						tmsBaseShipperModel.setCode(tmsBaseProviderModel.getCode());
						tmsBaseShipperModel.setName(tmsBaseProviderModel.getName());
						tmsBaseShipperModel.setShortName(tmsBaseProviderModel.getShortName());
						tmsBaseShipperModel.setStatus(tmsBaseProviderModel.getStatus());
						tmsBaseShipperModel.setContact(tmsBaseProviderModel.getContact());
						tmsBaseShipperModel.setPhoneNumber(tmsBaseProviderModel.getPhoneNumber());
						tmsBaseShipperModel.setLandlineNumber(tmsBaseProviderModel.getLandlineNumber());
						tmsBaseShipperModel.setEmail(tmsBaseProviderModel.getEmail());
						tmsBaseShipperModel.setProvince(tmsBaseProviderModel.getProvince());
						tmsBaseShipperModel.setProvinceName(tmsBaseProviderModel.getProvinceName());
						tmsBaseShipperModel.setCity(tmsBaseProviderModel.getCity());
						tmsBaseShipperModel.setCityName(tmsBaseProviderModel.getCityName());
						tmsBaseShipperModel.setDistrict(tmsBaseProviderModel.getDistrict());
						tmsBaseShipperModel.setDistrictName(tmsBaseProviderModel.getDistrictName());
						tmsBaseShipperModel.setAddress(tmsBaseProviderModel.getAddress());
						tmsBaseShipperModel.setLongitude(tmsBaseProviderModel.getLongitude());
						tmsBaseShipperModel.setLatitude(tmsBaseProviderModel.getLatitude());
						tmsBaseShipperModel.setMemo(tmsBaseProviderModel.getMemo());
						tmsBaseShipperModel.setSource(DataDictionaryConstant.SOURCE_INTERFACE);
						tmsBaseShipperModel.setEnterpriseId(tmsBaseProviderModel.getEnterpriseId());
						tmsBaseShipperModel.setEnterpriseName(tmsBaseProviderModel.getEnterpriseName());
						tmsBaseShipperModel.setExtStr1(tmsBaseProviderModel.getExtStr1());
						tmsBaseShipperModel.setExtStr2(tmsBaseProviderModel.getExtStr2());
						tmsBaseShipperModel.setExtStr3(tmsBaseProviderModel.getExtStr3());
						tmsBaseShipperModel.setExtStr4(tmsBaseProviderModel.getExtStr4());
						tmsBaseShipperModel.setExtStr5(tmsBaseProviderModel.getExtStr5());
						tmsBaseShipperModel.setExtDate1(tmsBaseProviderModel.getExtDate1());
						tmsBaseShipperModel.setExtDate2(tmsBaseProviderModel.getExtDate2());
						tmsBaseShipperModel.setExtDate3(tmsBaseProviderModel.getExtDate3());
						tmsBaseShipperModel.setExtDate4(tmsBaseProviderModel.getExtDate4());
						tmsBaseShipperModel.setExtDate5(tmsBaseProviderModel.getExtDate5());
						tmsBaseShipperModel.setExtNum1(tmsBaseProviderModel.getExtNum1());
						tmsBaseShipperModel.setExtNum2(tmsBaseProviderModel.getExtNum2());
						tmsBaseShipperModel.setExtNum3(tmsBaseProviderModel.getExtNum3());
						tmsBaseShipperModel.setExtNum4(tmsBaseProviderModel.getExtNum4());
						tmsBaseShipperModel.setExtNum5(tmsBaseProviderModel.getExtNum5());
						tmsBaseShipperModel.setCreateperson(tmsBaseProviderModel.getCreateperson());
						tmsBaseShipperModel.setCreatetime(date);
						tmsBaseShipperModel.setUpdateperson(tmsBaseProviderModel.getUpdateperson());
						tmsBaseShipperModel.setUpdatetime(date);
						tmsBaseShipperMapper.save(tmsBaseShipperModel);

						// 供应商发货方关联对象
						TmsProviderShipperLinkModel tmsProviderShipperLinkModel = new TmsProviderShipperLinkModel();
						tmsProviderShipperLinkModel.setLineid(ToolKits.getUUID());
						tmsProviderShipperLinkModel.setProviderId(tmsBaseProviderModel.getId());
						tmsProviderShipperLinkModel.setProviderCode(tmsBaseProviderModel.getCode());
						tmsProviderShipperLinkModel.setProviderName(tmsBaseProviderModel.getName());
						tmsProviderShipperLinkModel.setShipperId(tmsBaseShipperModel.getId());
						tmsProviderShipperLinkModel.setShipperCode(tmsBaseShipperModel.getCode());
						tmsProviderShipperLinkModel.setShipperName(tmsBaseShipperModel.getName());
						tmsProviderShipperLinkModel.setCreateperson(tmsBaseProviderModel.getCreateperson());
						tmsProviderShipperLinkModel.setCreatetime(date);
						tmsProviderShipperLinkModel.setUpdateperson(tmsBaseProviderModel.getUpdateperson());
						tmsProviderShipperLinkModel.setUpdatetime(date);
						tmsProviderShipperLinkMapper.save(tmsProviderShipperLinkModel);
					}
				} else {
					String id = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_BASE_PROVIDER_ID, "L");
					Assert.isTrue(ToolKits.isNotEmpty(id), "供应商ID生成为空");

					TmsBaseProviderModel tmsBaseProviderModel = new TmsBaseProviderModel();
					BeanUtils.copyProperties(intfProviderSaveVO, tmsBaseProviderModel);
					tmsBaseProviderModel.setId(Long.valueOf(id));
					tmsBaseProviderModel.setCargoOwnerId(baseCargoOwnerModel.getCargoOwnerId());
					tmsBaseProviderModel.setPickUpSign(ToolKits.isEmpty(intfProviderSaveVO.getPickUpSign()) ? StatusConstant.WHETHER_NO : intfProviderSaveVO.getPickUpSign());
					tmsBaseProviderModel.setAutoPickUpSign(ToolKits.isEmpty(intfProviderSaveVO.getAutoPickUpSign()) ? StatusConstant.WHETHER_NO : intfProviderSaveVO.getAutoPickUpSign());
					tmsBaseProviderModel.setPickUpPicture(ToolKits.isEmpty(intfProviderSaveVO.getPickUpPicture()) ? StatusConstant.WHETHER_NO : intfProviderSaveVO.getPickUpPicture());
					tmsBaseProviderModel.setDeliverySign(ToolKits.isEmpty(intfProviderSaveVO.getDeliverySign()) ? StatusConstant.WHETHER_NO : intfProviderSaveVO.getDeliverySign());
					tmsBaseProviderModel.setAutoDeliverySign(ToolKits.isEmpty(intfProviderSaveVO.getAutoDeliverySign()) ? StatusConstant.WHETHER_NO : intfProviderSaveVO.getAutoDeliverySign());
					tmsBaseProviderModel.setDeliveryPicture(ToolKits.isEmpty(intfProviderSaveVO.getDeliveryPicture()) ? StatusConstant.WHETHER_NO : intfProviderSaveVO.getDeliveryPicture());
					tmsBaseProviderModel.setReturnOrderPicture(ToolKits.isEmpty(intfProviderSaveVO.getReturnOrderPicture()) ? StatusConstant.WHETHER_NO : intfProviderSaveVO.getReturnOrderPicture());
					tmsBaseProviderModel.setStatus(StatusConstant.STATUS_ENABLE);
					tmsBaseProviderModel.setSource(DataDictionaryConstant.SOURCE_INTERFACE);
					tmsBaseProviderModel.setCreatetime(date);
					tmsBaseProviderModel.setUpdatetime(date);
					tmsBaseProviderMapper.save(tmsBaseProviderModel);

					// 供应商发货方对象
					String shipperId = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_BASE_SHIPPER_ID, "L");
					Assert.isTrue(ToolKits.isNotEmpty(shipperId), "供应商发货方ID生成为空");

					TmsBaseShipperModel tmsBaseShipperModel = new TmsBaseShipperModel();
					tmsBaseShipperModel.setId(Long.valueOf(shipperId));
					tmsBaseShipperModel.setCode(tmsBaseProviderModel.getCode());
					tmsBaseShipperModel.setName(tmsBaseProviderModel.getName());
					tmsBaseShipperModel.setShortName(tmsBaseProviderModel.getShortName());
					tmsBaseShipperModel.setStatus(tmsBaseProviderModel.getStatus());
					tmsBaseShipperModel.setContact(tmsBaseProviderModel.getContact());
					tmsBaseShipperModel.setPhoneNumber(tmsBaseProviderModel.getPhoneNumber());
					tmsBaseShipperModel.setLandlineNumber(tmsBaseProviderModel.getLandlineNumber());
					tmsBaseShipperModel.setEmail(tmsBaseProviderModel.getEmail());
					tmsBaseShipperModel.setProvince(tmsBaseProviderModel.getProvince());
					tmsBaseShipperModel.setProvinceName(tmsBaseProviderModel.getProvinceName());
					tmsBaseShipperModel.setCity(tmsBaseProviderModel.getCity());
					tmsBaseShipperModel.setCityName(tmsBaseProviderModel.getCityName());
					tmsBaseShipperModel.setDistrict(tmsBaseProviderModel.getDistrict());
					tmsBaseShipperModel.setDistrictName(tmsBaseProviderModel.getDistrictName());
					tmsBaseShipperModel.setAddress(tmsBaseProviderModel.getAddress());
					tmsBaseShipperModel.setLongitude(tmsBaseProviderModel.getLongitude());
					tmsBaseShipperModel.setLatitude(tmsBaseProviderModel.getLatitude());
					tmsBaseShipperModel.setMemo(tmsBaseProviderModel.getMemo());
					tmsBaseShipperModel.setSource(DataDictionaryConstant.SOURCE_INTERFACE);
					tmsBaseShipperModel.setEnterpriseId(tmsBaseProviderModel.getEnterpriseId());
					tmsBaseShipperModel.setEnterpriseName(tmsBaseProviderModel.getEnterpriseName());
					tmsBaseShipperModel.setExtStr1(tmsBaseProviderModel.getExtStr1());
					tmsBaseShipperModel.setExtStr2(tmsBaseProviderModel.getExtStr2());
					tmsBaseShipperModel.setExtStr3(tmsBaseProviderModel.getExtStr3());
					tmsBaseShipperModel.setExtStr4(tmsBaseProviderModel.getExtStr4());
					tmsBaseShipperModel.setExtStr5(tmsBaseProviderModel.getExtStr5());
					tmsBaseShipperModel.setExtDate1(tmsBaseProviderModel.getExtDate1());
					tmsBaseShipperModel.setExtDate2(tmsBaseProviderModel.getExtDate2());
					tmsBaseShipperModel.setExtDate3(tmsBaseProviderModel.getExtDate3());
					tmsBaseShipperModel.setExtDate4(tmsBaseProviderModel.getExtDate4());
					tmsBaseShipperModel.setExtDate5(tmsBaseProviderModel.getExtDate5());
					tmsBaseShipperModel.setExtNum1(tmsBaseProviderModel.getExtNum1());
					tmsBaseShipperModel.setExtNum2(tmsBaseProviderModel.getExtNum2());
					tmsBaseShipperModel.setExtNum3(tmsBaseProviderModel.getExtNum3());
					tmsBaseShipperModel.setExtNum4(tmsBaseProviderModel.getExtNum4());
					tmsBaseShipperModel.setExtNum5(tmsBaseProviderModel.getExtNum5());
					tmsBaseShipperModel.setCreateperson(tmsBaseProviderModel.getCreateperson());
					tmsBaseShipperModel.setCreatetime(date);
					tmsBaseShipperModel.setUpdateperson(tmsBaseProviderModel.getUpdateperson());
					tmsBaseShipperModel.setUpdatetime(date);
					tmsBaseShipperMapper.save(tmsBaseShipperModel);

					// 供应商发货方关联对象
					TmsProviderShipperLinkModel tmsProviderShipperLinkModel = new TmsProviderShipperLinkModel();
					tmsProviderShipperLinkModel.setLineid(ToolKits.getUUID());
					tmsProviderShipperLinkModel.setProviderId(tmsBaseProviderModel.getId());
					tmsProviderShipperLinkModel.setProviderCode(tmsBaseProviderModel.getCode());
					tmsProviderShipperLinkModel.setProviderName(tmsBaseProviderModel.getName());
					tmsProviderShipperLinkModel.setShipperId(tmsBaseShipperModel.getId());
					tmsProviderShipperLinkModel.setShipperCode(tmsBaseShipperModel.getCode());
					tmsProviderShipperLinkModel.setShipperName(tmsBaseShipperModel.getName());
					tmsProviderShipperLinkModel.setCreateperson(tmsBaseProviderModel.getCreateperson());
					tmsProviderShipperLinkModel.setCreatetime(date);
					tmsProviderShipperLinkModel.setUpdateperson(tmsBaseProviderModel.getUpdateperson());
					tmsProviderShipperLinkModel.setUpdatetime(date);
					tmsProviderShipperLinkMapper.save(tmsProviderShipperLinkModel);
				}

				// 成功信息
				intfErrorLogDTO.setErrorInfo(null);
				intfErrorLogDTO.setDataId(intfProviderSaveVO.getId());
				intfErrorLogDTO.setStatus(true);

				intfErrorLogDTOs.add(intfErrorLogDTO);
			} catch (Exception e) {
				e.printStackTrace();

				log.info("供应商资料接口处理失败:{}", e);

				// 错误信息
				intfErrorLogDTO.setErrorInfo(e.getMessage());
				intfErrorLogDTO.setDataId(intfProviderSaveVO.getId());
				intfErrorLogDTO.setStatus(false);

				intfErrorLogDTOs.add(intfErrorLogDTO);
			}
		}

		// 修改接口数据状态
		return intfErrorLogDTOs;
	}

	/**
	 * 供应商发货方接口转TMS
	 */
	@Override
	public List<IntfErrorLogDTO> saveProviderShipperInterfaceData(List<IntfProviderShipperSaveVO> intfProviderShipperSaveVOs) {
		// 响应集合
		List<IntfErrorLogDTO> intfErrorLogDTOs = Lists.newArrayList();

		Date date = DateUtil.date();

		// 循环处理
		for (IntfProviderShipperSaveVO intfProviderShipperSaveVO : intfProviderShipperSaveVOs) {
			// 响应对象
			IntfErrorLogDTO intfErrorLogDTO = new IntfErrorLogDTO();

			try {
				// 货主校验
				Criteria criteria1 = Criteria.forClass(TmsBaseCargoOwnerModel.class);
				Restriction r11 = Restrictions.eq(TmsBaseCargoOwnerModel::getCargoOwnerCode, intfProviderShipperSaveVO.getCargoOwnerCode());
				Restriction r12 = Restrictions.eq(TmsBaseCargoOwnerModel::getCargoOwnerName, intfProviderShipperSaveVO.getCargoOwnerName());
				Restriction r13 = Restrictions.eq(TmsBaseCargoOwnerModel::getEnterpriseId, intfProviderShipperSaveVO.getEnterpriseId());
				criteria1.setRestriction(Restrictions.and(r11, r12, r13));
				List<TmsBaseCargoOwnerModel> tmsBaseCargoOwnerModels = tmsBaseCargoOwnerMapper.findByCriteria(criteria1);
				Assert.isTrue(tmsBaseCargoOwnerModels.size() > 0, "货主【" + intfProviderShipperSaveVO.getCargoOwnerName() + "】不存在");
				Assert.isTrue(tmsBaseCargoOwnerModels.size() <= 1, "货主【" + intfProviderShipperSaveVO.getCargoOwnerName() + "】资料重复");

				// 货主对象
				TmsBaseCargoOwnerModel baseCargoOwnerModel = tmsBaseCargoOwnerModels.get(0);
				Assert.isTrue(baseCargoOwnerModel.getStatus().intValue() == StatusConstant.STATUS_ENABLE.intValue(), "货主【" + intfProviderShipperSaveVO.getCargoOwnerName() + "】已停用");

				// 校验供应商
				Criteria criteria = Criteria.forClass(TmsBaseProviderModel.class);
				Restriction r1 = Restrictions.eq(TmsBaseProviderModel::getCode, intfProviderShipperSaveVO.getProviderCode());
				Restriction r2 = Restrictions.eq(TmsBaseProviderModel::getCargoOwnerId, baseCargoOwnerModel.getCargoOwnerId());
				Restriction r3 = Restrictions.eq(TmsBaseProviderModel::getEnterpriseId, intfProviderShipperSaveVO.getEnterpriseId());
				criteria.setRestriction(Restrictions.and(r1, r2, r3));
				List<TmsBaseProviderModel> tmsBaseProviderModels = tmsBaseProviderMapper.findByCriteria(criteria);
				Assert.isTrue(tmsBaseProviderModels.size() > 0, "供应商【" + intfProviderShipperSaveVO.getProviderName() + "】不存在");
				Assert.isTrue(tmsBaseProviderModels.size() <= 1, "供应商【" + intfProviderShipperSaveVO.getProviderName() + "】资料重复");

				// 供应商对象
				TmsBaseProviderModel baseProviderModel = tmsBaseProviderModels.get(0);
				Assert.isTrue(baseProviderModel.getStatus().intValue() == StatusConstant.STATUS_ENABLE.intValue(), "供应商【" + intfProviderShipperSaveVO.getProviderName() + "】已停用");

				// 校验供应商发货方
				Criteria criteria2 = Criteria.forClass(TmsBaseShipperModel.class);
				Restriction r21 = Restrictions.eq(TmsBaseShipperModel::getCode, intfProviderShipperSaveVO.getCode());
				Restriction r22 = Restrictions.eq(TmsBaseShipperModel::getEnterpriseId, intfProviderShipperSaveVO.getEnterpriseId());
				criteria2.setRestriction(Restrictions.and(r21, r22));
				List<TmsBaseShipperModel> baseShipperModels = tmsBaseShipperMapper.findByCriteria(criteria2);
				if (baseShipperModels.size() > 0) {
					Assert.isTrue(baseShipperModels.size() <= 1, "供应商发货方编码[" + intfProviderShipperSaveVO.getCode() + "]维护重复");

					// 供应商发货方资料对象
					TmsBaseShipperModel baseShipperModel = baseShipperModels.get(0);
					baseShipperModel.setName(intfProviderShipperSaveVO.getName());
					baseShipperModel.setShortName(intfProviderShipperSaveVO.getShortName());
					baseShipperModel.setStatus(intfProviderShipperSaveVO.getStatus());
					baseShipperModel.setContact(intfProviderShipperSaveVO.getContact());
					baseShipperModel.setPhoneNumber(intfProviderShipperSaveVO.getPhoneNumber());
					baseShipperModel.setLandlineNumber(intfProviderShipperSaveVO.getLandlineNumber());
					baseShipperModel.setEmail(intfProviderShipperSaveVO.getEmail());
					baseShipperModel.setProvince(intfProviderShipperSaveVO.getProvince());
					baseShipperModel.setProvinceName(intfProviderShipperSaveVO.getProvinceName());
					baseShipperModel.setCity(intfProviderShipperSaveVO.getCity());
					baseShipperModel.setCityName(intfProviderShipperSaveVO.getCityName());
					baseShipperModel.setDistrict(intfProviderShipperSaveVO.getDistrict());
					baseShipperModel.setDistrictName(intfProviderShipperSaveVO.getDistrictName());
					baseShipperModel.setAddress(intfProviderShipperSaveVO.getAddress());
					baseShipperModel.setLongitude(intfProviderShipperSaveVO.getLongitude());
					baseShipperModel.setLatitude(intfProviderShipperSaveVO.getLatitude());
					baseShipperModel.setMemo(intfProviderShipperSaveVO.getMemo());
					baseShipperModel.setExtStr1(intfProviderShipperSaveVO.getExtStr1());
					baseShipperModel.setExtStr2(intfProviderShipperSaveVO.getExtStr2());
					baseShipperModel.setExtStr3(intfProviderShipperSaveVO.getExtStr3());
					baseShipperModel.setExtStr4(intfProviderShipperSaveVO.getExtStr4());
					baseShipperModel.setExtStr5(intfProviderShipperSaveVO.getExtStr5());
					baseShipperModel.setExtNum1(intfProviderShipperSaveVO.getExtNum1());
					baseShipperModel.setExtNum2(intfProviderShipperSaveVO.getExtNum2());
					baseShipperModel.setExtNum3(intfProviderShipperSaveVO.getExtNum3());
					baseShipperModel.setExtNum4(intfProviderShipperSaveVO.getExtNum4());
					baseShipperModel.setExtNum5(intfProviderShipperSaveVO.getExtNum5());
					baseShipperModel.setExtDate1(intfProviderShipperSaveVO.getExtDate1());
					baseShipperModel.setExtDate2(intfProviderShipperSaveVO.getExtDate2());
					baseShipperModel.setExtDate3(intfProviderShipperSaveVO.getExtDate3());
					baseShipperModel.setExtDate4(intfProviderShipperSaveVO.getExtDate4());
					baseShipperModel.setExtDate5(intfProviderShipperSaveVO.getExtDate5());
					baseShipperModel.setUpdatetime(date);
					tmsBaseShipperMapper.update(baseShipperModel);

					// 判断供应商与发货方是否关联
					// 校验供应商发货方
					Criteria criteria3 = Criteria.forClass(TmsProviderShipperLinkModel.class);
					Restriction r31 = Restrictions.eq(TmsProviderShipperLinkModel::getProviderId, baseProviderModel.getId());
					Restriction r32 = Restrictions.eq(TmsProviderShipperLinkModel::getShipperId, baseShipperModel.getId());
					criteria3.setRestriction(Restrictions.and(r31, r32));
					List<TmsProviderShipperLinkModel> providerShipperLinkModels = tmsProviderShipperLinkMapper.findByCriteria(criteria3);
					if (providerShipperLinkModels.size() > 0) {
						Assert.isTrue(providerShipperLinkModels.size() <= 1, "供应商发货方关联供应商[" + intfProviderShipperSaveVO.getProviderName() + "]重复");

						TmsProviderShipperLinkModel tmsProviderShipperLinkModel = providerShipperLinkModels.get(0);
						tmsProviderShipperLinkModel.setShipperName(baseShipperModel.getName());
						tmsProviderShipperLinkModel.setUpdatetime(date);
						tmsProviderShipperLinkMapper.update(tmsProviderShipperLinkModel);

					} else {
						// 供应商发货方关联对象
						TmsProviderShipperLinkModel tmsProviderShipperLinkModel = new TmsProviderShipperLinkModel();
						tmsProviderShipperLinkModel.setLineid(ToolKits.getUUID());
						tmsProviderShipperLinkModel.setProviderId(baseProviderModel.getId());
						tmsProviderShipperLinkModel.setProviderCode(baseProviderModel.getCode());
						tmsProviderShipperLinkModel.setProviderName(baseProviderModel.getName());
						tmsProviderShipperLinkModel.setShipperId(baseShipperModel.getId());
						tmsProviderShipperLinkModel.setShipperCode(baseShipperModel.getCode());
						tmsProviderShipperLinkModel.setShipperName(baseShipperModel.getName());
						tmsProviderShipperLinkModel.setCreateperson(baseShipperModel.getCreateperson());
						tmsProviderShipperLinkModel.setCreatetime(date);
						tmsProviderShipperLinkModel.setUpdateperson(baseShipperModel.getUpdateperson());
						tmsProviderShipperLinkModel.setUpdatetime(date);
						tmsProviderShipperLinkMapper.save(tmsProviderShipperLinkModel);
					}
				} else {
					String id = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.TMS_BASE_SHIPPER_ID, "L");
					Assert.isTrue(ToolKits.isNotEmpty(id), "供应商发货方ID生成为空");

					// 供应商发货方对象
					TmsBaseShipperModel tmsBaseShipperModel = new TmsBaseShipperModel();
					BeanUtils.copyProperties(intfProviderShipperSaveVO, tmsBaseShipperModel);
					tmsBaseShipperModel.setId(Long.valueOf(id));
					tmsBaseShipperModel.setStatus(StatusConstant.STATUS_ENABLE);
					tmsBaseShipperModel.setSource(DataDictionaryConstant.SOURCE_INTERFACE);
					tmsBaseShipperModel.setCreatetime(date);
					tmsBaseShipperModel.setUpdatetime(date);
					tmsBaseShipperMapper.save(tmsBaseShipperModel);

					// 供应商发货方关联对象
					TmsProviderShipperLinkModel tmsProviderShipperLinkModel = new TmsProviderShipperLinkModel();
					tmsProviderShipperLinkModel.setLineid(ToolKits.getUUID());
					tmsProviderShipperLinkModel.setProviderId(baseProviderModel.getId());
					tmsProviderShipperLinkModel.setProviderCode(baseProviderModel.getCode());
					tmsProviderShipperLinkModel.setProviderName(baseProviderModel.getName());
					tmsProviderShipperLinkModel.setShipperId(tmsBaseShipperModel.getId());
					tmsProviderShipperLinkModel.setShipperCode(tmsBaseShipperModel.getCode());
					tmsProviderShipperLinkModel.setShipperName(tmsBaseShipperModel.getName());
					tmsProviderShipperLinkModel.setCreateperson(tmsBaseShipperModel.getCreateperson());
					tmsProviderShipperLinkModel.setCreatetime(date);
					tmsProviderShipperLinkModel.setUpdateperson(tmsBaseShipperModel.getUpdateperson());
					tmsProviderShipperLinkModel.setUpdatetime(date);
					tmsProviderShipperLinkMapper.save(tmsProviderShipperLinkModel);
				}

				// 成功信息
				intfErrorLogDTO.setErrorInfo(null);
				intfErrorLogDTO.setDataId(intfProviderShipperSaveVO.getId());
				intfErrorLogDTO.setStatus(true);

				intfErrorLogDTOs.add(intfErrorLogDTO);
			} catch (Exception e) {
				e.printStackTrace();

				log.info("供应商发货方资料接口处理失败:{}", e);

				// 错误信息
				intfErrorLogDTO.setErrorInfo(e.getMessage());
				intfErrorLogDTO.setDataId(intfProviderShipperSaveVO.getId());
				intfErrorLogDTO.setStatus(false);

				intfErrorLogDTOs.add(intfErrorLogDTO);
			}
		}

		return intfErrorLogDTOs;
	}

	@Override
	public void geocodingData(ProviderGeocodingVO vo) {
		ToolKits.isParamNull(vo, "供应商资料地址解析请求不为空");
		ToolKits.isParamNull(vo.getId(), "供应商ID不为空");
		ToolKits.isParamNull(vo.getLongitude(), "经度不为空");
		ToolKits.isParamNull(vo.getLatitude(), "纬度不为空");
		ToolKits.isParamNull(vo.getAddress(), "详细地址不为空");
		// 根据ID查询货主对象
		TmsBaseProviderModel tmsBaseProviderModel = tmsBaseProviderMapper.findById(vo.getId(), TmsBaseProviderModel.class);
		ToolKits.isParamNull(tmsBaseProviderModel, "供应商信息不存在，经纬度更新失败");
		// 更新经纬度信息
		tmsBaseProviderModel.setLongitude(vo.getLongitude());
		tmsBaseProviderModel.setLatitude(vo.getLatitude());
		tmsBaseProviderModel.setAddress(vo.getAddress());
		tmsBaseProviderMapper.update(tmsBaseProviderModel);
	}

	/**
	 * 更新发货方经纬度
	 * @param idList
	 * @param latitude
	 * @param longitude
	 */
	@Override
	public void updateShipperLatitudeAndLongitude(List<Long> idList, BigDecimal latitude, BigDecimal longitude) {
		List<TmsBaseShipperModel> tmsBaseShipperModelList = tmsBaseShipperMapper.findByIds(TmsBaseShipperModel.class, idList.toArray(), null);
		if (CollectionUtil.isNotEmpty(tmsBaseShipperModelList)) {
			UserEntity user = PlgFxUsrUtils.getUserEntity();
			tmsBaseShipperModelList.forEach(tmsBaseShipperModel -> {
				tmsBaseShipperModel.setUpdateperson(user.getNickname());
				tmsBaseShipperModel.setUpdatetime(new Date());
				tmsBaseShipperModel.setLongitude(longitude);
				tmsBaseShipperModel.setLatitude(latitude);
				tmsBaseShipperMapper.update(tmsBaseShipperModel);
			});
		}
	}

	/**
	 * 供应商资料查看
	 */
	@Override
	public ProviderCheckDTO getProviderByName(ProviderCheckVO providerCheckVO) {
		ToolKits.isParamNull(providerCheckVO, "供应商资料查看请求不为空");
		if (ToolKits.isEmpty(providerCheckVO.getName())) {
			throw new PrologException("供应商名称不为空");
		}

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

		Criteria criteria = Criteria.forClass(TmsBaseProviderModel.class);
		Restriction r1 = Restrictions.eq(TmsBaseProviderModel::getName, providerCheckVO.getName());
		Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2));
		List<TmsBaseProviderModel> tmsBaseProviderModels = tmsBaseProviderMapper.findByCriteria(criteria);

		if (tmsBaseProviderModels.size() == 0) {
			throw new ParameterException("供应商【" + providerCheckVO.getName() + "】数据不存在，查询失败");
		} else if (tmsBaseProviderModels.size() > 1) {
			throw new ParameterException("供应商【" + providerCheckVO.getName() + "】存在重复数据，查询失败");
		}

		// 供应商资料对象
		TmsBaseProviderModel tmsBaseProviderModel = tmsBaseProviderModels.get(0);

		// 响应对象
		ProviderCheckDTO providerCheckDTO = new ProviderCheckDTO();
		BeanUtils.copyProperties(tmsBaseProviderModel, providerCheckDTO);

		return providerCheckDTO;
	}

}
