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

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Properties;
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.prolog.common.util.ToolKits;
import com.prolog.cs.platform.power.model.Organization;
import com.prolog.cs.platform.power.model.enterprise.Role;
import com.prolog.cs.platform.power.model.enterprise.User;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.exception.BizException;
import com.prolog.framework.core.exception.ParameterException;
import com.prolog.framework.core.exception.PrologException;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.core.restriction.Criteria;
import com.prolog.framework.core.restriction.Order;
import com.prolog.framework.core.restriction.Restriction;
import com.prolog.framework.core.restriction.Restrictions;
import com.prolog.framework.dao.util.PageUtils;
import com.prolog.product.core.framework.entity.UserEntity;
import com.prolog.product.core.framework.util.PlgFxUsrUtils;
import com.prolog.rdc.tms.constant.BussinessConstant;
import com.prolog.rdc.tms.constant.DataDictionaryConstant;
import com.prolog.rdc.tms.constant.RabbitMQConstant;
import com.prolog.rdc.tms.constant.SeriaNnumberConstant;
import com.prolog.rdc.tms.constant.StatusConstant;
import com.prolog.rdc.tms.dao.mapper.TmsBaseCarriersMapper;
import com.prolog.rdc.tms.dao.mapper.TmsBaseDeliverymanMapper;
import com.prolog.rdc.tms.dao.mapper.TmsBasePaperMapper;
import com.prolog.rdc.tms.dao.mapper.TmsDeliverymanPaperLinkMapper;
import com.prolog.rdc.tms.model.dto.basicConfigure.StandardTemplateDetailsListDTO;
import com.prolog.rdc.tms.model.dto.fleetManagement.DeliverymanCheckDTO;
import com.prolog.rdc.tms.model.dto.fleetManagement.DeliverymanImportPageDTO;
import com.prolog.rdc.tms.model.dto.fleetManagement.DeliverymanPagingQueryDTO;
import com.prolog.rdc.tms.model.dto.fleetManagement.DeliverymanPaperCheckDTO;
import com.prolog.rdc.tms.model.dto.fleetManagement.DeliverymanPaperLinkCheckDTO;
import com.prolog.rdc.tms.model.dto.fleetManagement.DeliverymanPopupDTO;
import com.prolog.rdc.tms.model.entity.line.TmsBaseCarriersModel;
import com.prolog.rdc.tms.model.entity.line.TmsBaseDeliverymanModel;
import com.prolog.rdc.tms.model.entity.line.TmsBasePaperModel;
import com.prolog.rdc.tms.model.entity.line.TmsDeliverymanPaperLink;
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.fleetManagement.DeliverymanAddVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanByIdVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanCheckVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanDeleteVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanModifyVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanPagingQueryVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanPaperAddVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanPaperByIdVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanPaperCheckVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanPaperDeleteVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanPaperLinkAddVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanPaperLinkCheckVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanPaperLinkModifyVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanPaperModifyVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanPaperWhetherEnableVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanPopupVO;
import com.prolog.rdc.tms.model.vo.fleetManagement.DeliverymanWhetherEnableVO;
import com.prolog.rdc.tms.model.vo.xlsimport.DeliverymanImportStdVO;
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.fleetManagement.DeliverymanService;
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.date.DateUtil;
import cn.hutool.core.lang.Validator;
import lombok.extern.slf4j.Slf4j;

/**
 *
 *
 * 车队管理-送货员管理实现层
 *
 * @className :DeliverymanServiceImpl
 * @author :fanzw
 * @creationTime :2022/03/16
 * @description :
 *
 * @modifier :fanzw
 * @modifyTime :2022/03/16
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@Slf4j
@Service
public class DeliverymanServiceImpl implements DeliverymanService {

	@Autowired
	private TmsBaseDeliverymanMapper tmsBaseDeliverymanMapper;

	@Autowired
	private TmsDeliverymanPaperLinkMapper tmsDeliverymanPaperLinkMapper;

	@Autowired
	private TmsBasePaperMapper tmsBasePaperMapper;

	@Autowired
	private SysCodeengineService sysCodeengineService;

	@Autowired
	private SysRefdatadService sysRefdatadService;

	@Autowired
	private ImportLogService importLogService;

	@Autowired
	private SysImportTemplethService sysImportTemplethService;

	@Autowired
	private TmsBaseCarriersMapper tmsBaseCarriersMapper;

	@Autowired
	private UserFeign userTmsResource;

	@Autowired
	private AmqpTemplate amqpTemplate;

	/**
	 * 送货员资料分页查询
	 */
	@SuppressWarnings("resource")
	@Override
	public Page<DeliverymanPagingQueryDTO> pageDeliverymanData(DeliverymanPagingQueryVO deliverymanPagingQueryVO) {
		ToolKits.isParamNull(deliverymanPagingQueryVO, "送货员资料查询请求不为空");
		ToolKits.isParamNull(deliverymanPagingQueryVO.getPageNum(), "页码不为空");
		ToolKits.isParamNull(deliverymanPagingQueryVO.getPageSize(), "页数不为空");

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

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

		// 送货员类型
		List<Map<String, Object>> restMessage1 = sysRefdatadService.getDropDownById(DataDictionaryConstant.DELIVERYMAN_TYPE, null, null, null);
		// 送货员状态
		List<Map<String, Object>> restMessage2 = sysRefdatadService.getDropDownById(DataDictionaryConstant.MAINDATA_STATUS, null, null, null);

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

		Criteria criteria = Criteria.forClass(TmsBaseDeliverymanModel.class);
		Restriction r1 = ToolKits.isEmpty(deliverymanPagingQueryVO.getCode()) ? null : Restrictions.like("code", "%" + deliverymanPagingQueryVO.getCode() + "%");
		Restriction r2 = ToolKits.isEmpty(deliverymanPagingQueryVO.getName()) ? null : Restrictions.like("name", "%" + deliverymanPagingQueryVO.getName() + "%");
		Restriction r3 = Restrictions.eq("enterpriseId", user.getEnterpriseId());

		// 权限控制
		Restriction r4 = null;
		// 判断账号类型
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			r4 = Restrictions.in("departmentId", user.getDepts().toArray());
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {// 非自有账号 主要为承运商
			// 显示隶属机构id为当前登录账号单位id 的送货员
			r4 = Restrictions.eq("affiliationId", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			throw new BizException("当前人员没有操作权限！");
		}

		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		List<TmsBaseDeliverymanModel> tmsBaseDeliverymanModels = tmsBaseDeliverymanMapper.findByCriteria(criteria);
		for (TmsBaseDeliverymanModel tmsBaseDeliverymanModel : tmsBaseDeliverymanModels) {
			// 响应对象
			DeliverymanPagingQueryDTO deliverymanPagingQueryDTO = new DeliverymanPagingQueryDTO();
			BeanUtils.copyProperties(tmsBaseDeliverymanModel, deliverymanPagingQueryDTO);
			deliverymanPagingQueryDTO.setTypeName(PublicMethods.change(restMessage1, String.valueOf(deliverymanPagingQueryDTO.getType())));
			deliverymanPagingQueryDTO.setStatusName(PublicMethods.change(restMessage2, String.valueOf(deliverymanPagingQueryDTO.getStatus())));
			deliverymanPagingQueryDTOs.add(deliverymanPagingQueryDTO);
		}

		Page<DeliverymanPagingQueryDTO> page = PageUtils.getPage(deliverymanPagingQueryDTOs);
		if (tmsBaseDeliverymanModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsBaseDeliverymanModel> p0 = (com.github.pagehelper.Page<TmsBaseDeliverymanModel>) tmsBaseDeliverymanModels;
			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<DeliverymanPopupDTO> popupDeliverymanData(DeliverymanPopupVO deliverymanPopupVO) {
		ToolKits.isParamNull(deliverymanPopupVO, "送货员资料查询请求不为空");
		ToolKits.isParamNull(deliverymanPopupVO.getPageNum(), "页码不为空");
		ToolKits.isParamNull(deliverymanPopupVO.getPageSize(), "页数不为空");

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

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

		// 送货员类型
		List<Map<String, Object>> restMessage1 = sysRefdatadService.getDropDownById(DataDictionaryConstant.DELIVERYMAN_TYPE, null, null, null);

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

		Criteria criteria = Criteria.forClass(TmsBaseDeliverymanModel.class);
		Restriction r1 = ToolKits.isEmpty(deliverymanPopupVO.getCode()) ? null : Restrictions.like("code", "%" + deliverymanPopupVO.getCode() + "%");
		Restriction r2 = ToolKits.isEmpty(deliverymanPopupVO.getName()) ? null : Restrictions.like("name", "%" + deliverymanPopupVO.getName() + "%");
		Restriction r3 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		Restriction r4 = Restrictions.eq("status", StatusConstant.STATUS_ENABLE);

		// 权限控制
		Restriction r5 = null;
		// 判断账号类型
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
			r5 = Restrictions.in("departmentId", user.getDepts().toArray());
		} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {// 非自有账号 主要为承运商
			// 显示隶属机构id为当前登录账号单位id 的送货员
			r5 = Restrictions.eq("affiliationId", Long.valueOf(user.getLoginUserCompanyInfo().getId()));
		} else {
			throw new BizException("当前人员没有操作权限！");
		}

		criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5));
		criteria.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		List<TmsBaseDeliverymanModel> tmsBaseDeliverymanModels = tmsBaseDeliverymanMapper.findByCriteria(criteria);
		for (TmsBaseDeliverymanModel tmsBaseDeliverymanModel : tmsBaseDeliverymanModels) {
			// 响应对象
			DeliverymanPopupDTO deliverymanPopupDTO = new DeliverymanPopupDTO();
			BeanUtils.copyProperties(tmsBaseDeliverymanModel, deliverymanPopupDTO);
			deliverymanPopupDTO.setTypeName(PublicMethods.change(restMessage1, String.valueOf(deliverymanPopupDTO.getType())));
			deliverymanPopupDTOs.add(deliverymanPopupDTO);
		}

		Page<DeliverymanPopupDTO> page = PageUtils.getPage(deliverymanPopupDTOs);
		if (tmsBaseDeliverymanModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsBaseDeliverymanModel> p0 = (com.github.pagehelper.Page<TmsBaseDeliverymanModel>) tmsBaseDeliverymanModels;
			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
	public DeliverymanCheckDTO getDeliverymanData(DeliverymanCheckVO deliverymanCheckVO) {
		ToolKits.isParamNull(deliverymanCheckVO, "送货员资料查看请求不为空");
		ToolKits.isParamNull(deliverymanCheckVO.getId(), "送货员ID不为空");

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

		// 送货员状态
		List<Map<String, Object>> restMessage = sysRefdatadService.getDropDownById(DataDictionaryConstant.MAINDATA_STATUS, null, null, null);

		Criteria criteria = Criteria.forClass(TmsBaseDeliverymanModel.class);
		Restriction r1 = Restrictions.eq("id", deliverymanCheckVO.getId());
		Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2));
		List<TmsBaseDeliverymanModel> tmsBaseDeliverymanModels = tmsBaseDeliverymanMapper.findByCriteria(criteria);

		Assert.isTrue(tmsBaseDeliverymanModels.size() == 1, "送货员ID【" + deliverymanCheckVO.getId() + "】存在重复数据，查询失败");

		// 送货员资料对象
		TmsBaseDeliverymanModel tmsBaseDeliverymanModel = tmsBaseDeliverymanModels.get(0);

		// 响应对象
		DeliverymanCheckDTO deliverymanCheckDTO = new DeliverymanCheckDTO();
		BeanUtils.copyProperties(tmsBaseDeliverymanModel, deliverymanCheckDTO);
		deliverymanCheckDTO.setStatusName(PublicMethods.change(restMessage, String.valueOf(deliverymanCheckDTO.getStatus())));

		return deliverymanCheckDTO;
	}

	/**
	 * 送货员资料是否启用
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void whetherEnableDeliverymanData(DeliverymanWhetherEnableVO deliverymanWhetherEnableVO) {
		ToolKits.isParamNull(deliverymanWhetherEnableVO, "送货员资料是否启用请求不为空");
		ToolKits.isParamNull(deliverymanWhetherEnableVO.getDeliverymanIds(), "送货员ID集不为空");
		ToolKits.isParamNull(deliverymanWhetherEnableVO.getStatus(), "状态不为空");

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

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

		for (DeliverymanByIdVO deliverymanByIdVO : deliverymanWhetherEnableVO.getDeliverymanIds()) {
			ToolKits.isParamNull(deliverymanByIdVO.getId(), "送货员ID不为空");

			// 根据ID查询送货员对象
			TmsBaseDeliverymanModel tmsBaseDeliverymanModel = tmsBaseDeliverymanMapper.findById(deliverymanByIdVO.getId(), TmsBaseDeliverymanModel.class);
			ToolKits.isParamNull(tmsBaseDeliverymanModel, "送货员ID【" + deliverymanByIdVO.getId() + "】不存在");

			tmsBaseDeliverymanModel.setStatus(deliverymanWhetherEnableVO.getStatus().intValue() == 1 ? StatusConstant.STATUS_ENABLE : StatusConstant.STATUS_DISABLE);
			tmsBaseDeliverymanModel.setUpdateperson(user.getNickname());
			tmsBaseDeliverymanModel.setUpdatetime(date);
			tmsBaseDeliverymanMapper.update(tmsBaseDeliverymanModel);
		}
	}

	/**
	 * 送货员资料新增
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public String addDeliverymanData(DeliverymanAddVO deliverymanAddVO) {
		ToolKits.isParamNull(deliverymanAddVO, "送货员资料新增请求不为空");
		ToolKits.isParamNull(deliverymanAddVO.getCode(), "送货员编码不为空");
		ToolKits.isParamNull(deliverymanAddVO.getName(), "送货员名称不为空");
		ToolKits.isParamNull(deliverymanAddVO.getType(), "送货员类型不为空");

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

		// 用户为承运商时
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
			ToolKits.isParamNull(deliverymanAddVO.getAffiliationId(), "隶属机构ID不为空");
			ToolKits.isParamNull(deliverymanAddVO.getAffiliationCode(), "隶属机构编码不为空");
			ToolKits.isParamNull(deliverymanAddVO.getAffiliationName(), "隶属机构名称不为空");
			ToolKits.isParamNull(deliverymanAddVO.getAffiliationType(), "隶属机构类型不为空");
		}

		// 判断送货员编码是否已存在
		PublicMethods.isThereAnyinformation(TmsBaseDeliverymanModel.class, "code", deliverymanAddVO.getCode(), "enterpriseId", user.getEnterpriseId(), tmsBaseDeliverymanMapper, "送货员编码已存在");

		// 送货员ID
		String deliverymanId = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.DELIVERYMAN_ID, "L");
		ToolKits.isParamNull(deliverymanId, "送货员ID生成失败");

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

		// 送货员资料对象保存
		TmsBaseDeliverymanModel tmsBaseDeliverymanModel = new TmsBaseDeliverymanModel();
		BeanUtils.copyProperties(deliverymanAddVO, tmsBaseDeliverymanModel);
		tmsBaseDeliverymanModel.setId(Long.valueOf(deliverymanId));
		tmsBaseDeliverymanModel.setStatus(StatusConstant.STATUS_ENABLE);
		tmsBaseDeliverymanModel.setSource(DataDictionaryConstant.SOURCE_ADD);
		tmsBaseDeliverymanModel.setEnterpriseId(user.getEnterpriseId());
		tmsBaseDeliverymanModel.setEnterpriseName(user.getEnterpriseName());
		tmsBaseDeliverymanModel.setCreateperson(user.getNickname());
		tmsBaseDeliverymanModel.setCreatetime(date);
		tmsBaseDeliverymanModel.setUpdateperson(user.getNickname());
		tmsBaseDeliverymanModel.setUpdatetime(date);
		tmsBaseDeliverymanModel.setDepartmentId(deliverymanAddVO.getDepartmentId());
		tmsBaseDeliverymanModel.setDepartmentCode(deliverymanAddVO.getDepartmentCode());
		tmsBaseDeliverymanModel.setDepartmentName(deliverymanAddVO.getDepartmentName());
		tmsBaseDeliverymanMapper.save(tmsBaseDeliverymanModel);

		// 送货员证件关联不为空新增
		if (ToolKits.isNotEmpty(deliverymanAddVO.getDeliverymanPaperLinks())) {
			for (DeliverymanPaperLinkAddVO deliverymanPaperLink : deliverymanAddVO.getDeliverymanPaperLinks()) {
				ToolKits.isParamNull(deliverymanPaperLink.getId(), "证件ID不为空");
				ToolKits.isParamNull(deliverymanPaperLink.getCode(), "证件编码不为空");
				ToolKits.isParamNull(deliverymanPaperLink.getType(), "证件类型不为空");

				// 判断送货员证件编码是否已存在
				PublicMethods.isThereAnyinformation(TmsBasePaperModel.class, "code", deliverymanPaperLink.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_ENABLE, tmsBasePaperMapper, "送货员证件编码已存在");
				PublicMethods.isThereAnyinformation(TmsBasePaperModel.class, "code", deliverymanPaperLink.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_DISABLE, tmsBasePaperMapper, "送货员证件编码已存在，请直接启用");

				// 送货员证件保存
				TmsBasePaperModel tmsBasePaperModel = new TmsBasePaperModel();
				BeanUtils.copyProperties(deliverymanPaperLink, tmsBasePaperModel);
				tmsBasePaperModel.setPaperObjectType(DataDictionaryConstant.PAPER_OBJECT_DELIVERY);
				tmsBasePaperModel.setPaperObjectId(tmsBaseDeliverymanModel.getId());
				tmsBasePaperModel.setPaperObjectCode(tmsBaseDeliverymanModel.getCode());
				tmsBasePaperModel.setPaperObjectName(tmsBaseDeliverymanModel.getName());
				tmsBasePaperModel.setStatus(StatusConstant.STATUS_ENABLE);
				tmsBasePaperModel.setEnterpriseId(user.getEnterpriseId());
				tmsBasePaperModel.setEnterpriseName(user.getEnterpriseName());
				tmsBasePaperModel.setCreateperson(user.getNickname());
				tmsBasePaperModel.setCreatetime(date);
				tmsBasePaperModel.setUpdateperson(user.getNickname());
				tmsBasePaperModel.setUpdatetime(date);
				tmsBasePaperMapper.save(tmsBasePaperModel);

				// 送货员证件关联保存
				TmsDeliverymanPaperLink tmsDeliverymanPaperLinkModel = new TmsDeliverymanPaperLink();
				tmsDeliverymanPaperLinkModel.setLineid(ToolKits.getUUID());
				tmsDeliverymanPaperLinkModel.setDeliverymanId(tmsBaseDeliverymanModel.getId());
				tmsDeliverymanPaperLinkModel.setDeliverymanCode(tmsBaseDeliverymanModel.getCode());
				tmsDeliverymanPaperLinkModel.setDeliverymanName(tmsBaseDeliverymanModel.getName());
				tmsDeliverymanPaperLinkModel.setPaperId(tmsBasePaperModel.getId());
				tmsDeliverymanPaperLinkModel.setPaperCode(tmsBasePaperModel.getCode());
				tmsDeliverymanPaperLinkModel.setPaperObjectType(tmsBasePaperModel.getPaperObjectType());
				tmsDeliverymanPaperLinkModel.setCreateperson(user.getNickname());
				tmsDeliverymanPaperLinkModel.setCreatetime(date);
				tmsDeliverymanPaperLinkModel.setUpdateperson(user.getNickname());
				tmsDeliverymanPaperLinkModel.setUpdatetime(date);
				tmsDeliverymanPaperLinkMapper.save(tmsDeliverymanPaperLinkModel);
			}
		}

		// 注册送货员账号
		User adduser = new User();
		adduser.setCompanyId(ToolKits.isEmpty(tmsBaseDeliverymanModel.getAffiliationId()) ? null : tmsBaseDeliverymanModel.getAffiliationId().toString());
		adduser.setCompanyCode(ToolKits.isEmpty(tmsBaseDeliverymanModel.getAffiliationCode()) ? null : tmsBaseDeliverymanModel.getAffiliationCode());
		adduser.setCompanyName(ToolKits.isEmpty(tmsBaseDeliverymanModel.getAffiliationName()) ? null : tmsBaseDeliverymanModel.getAffiliationName());
		adduser.setCreateDate(date);
		adduser.setDisable(false);
		adduser.setEmailAddr(null);
		adduser.setEmployeeNum(null);
		adduser.setExpireDate(null);
		adduser.setEnterpriseId(user.getEnterpriseId().toString());
		adduser.setId(tmsBaseDeliverymanModel.getId().toString());
		adduser.setNickname(tmsBaseDeliverymanModel.getName());
		adduser.setPassword(ToolKits.isEmpty(tmsBaseDeliverymanModel.getPassword()) ? BussinessConstant.PASSWORD : tmsBaseDeliverymanModel.getPassword());
		adduser.setPersonType(BussinessConstant.PERSON_TYPE_PT);
		adduser.setPhoneNumber(tmsBaseDeliverymanModel.getPhoneNumber());
		adduser.setRoleId(BussinessConstant.ROLEID_DRIVER_ID);
		adduser.setServiceId(null);
		adduser.setUserCategory(BussinessConstant.USER_TYPE_SHY);
		adduser.setUsername(tmsBaseDeliverymanModel.getPhoneNumber());
		adduser.setUserState("0");
		// 角色信息
		List<Role> roles = new ArrayList<Role>();
		Role role = new Role();
		role.setAllAuth(BussinessConstant.ALLAUTH_NO);
		role.setEnterpriseId(user.getEnterpriseId().toString());
		role.setId(BussinessConstant.ROLEID_DRIVER_ID);
		role.setName(BussinessConstant.ROLEID_DRIVER_NAME);
		role.setNum(BussinessConstant.ROLEID_DRIVER_ID);
		roles.add(role);
		adduser.setRoles(roles);

		RestMessage<String> restMessage = userTmsResource.addTmsUser(adduser);
		if (!restMessage.isSuccess()) {
			throw new ParameterException("送货员账号注册失败:" + restMessage.getMessage());
		}

		return deliverymanId;
	}

	/**
	 * 送货员资料修改
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void modifyDeliverymanData(DeliverymanModifyVO deliverymanModifyVO) {
		ToolKits.isParamNull(deliverymanModifyVO, "送货员资料修改请求不为空");
		ToolKits.isParamNull(deliverymanModifyVO.getId(), "送货员ID不为空");
		ToolKits.isParamNull(deliverymanModifyVO.getType(), "送货员类型不为空");

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

		// 用户为承运商时
		if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
			ToolKits.isParamNull(deliverymanModifyVO.getAffiliationId(), "隶属机构ID不为空");
			ToolKits.isParamNull(deliverymanModifyVO.getAffiliationCode(), "隶属机构编码不为空");
			ToolKits.isParamNull(deliverymanModifyVO.getAffiliationName(), "隶属机构名称不为空");
			ToolKits.isParamNull(deliverymanModifyVO.getAffiliationType(), "隶属机构类型不为空");
		}

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

		// 根据ID查询送货员信息
		TmsBaseDeliverymanModel tmsBaseDeliverymanModel = tmsBaseDeliverymanMapper.findById(deliverymanModifyVO.getId(), TmsBaseDeliverymanModel.class);
		ToolKits.isParamNull(tmsBaseDeliverymanModel, "送货员ID【" + deliverymanModifyVO.getId() + "】不存在");

		Assert.isTrue(tmsBaseDeliverymanModel.getStatus() == StatusConstant.STATUS_ENABLE, "送货员已停用不能修改");

		// 送货员资料对象修改
		tmsBaseDeliverymanModel.setType(deliverymanModifyVO.getType());
		tmsBaseDeliverymanModel.setAffiliationId(deliverymanModifyVO.getAffiliationId());
		tmsBaseDeliverymanModel.setAffiliationCode(deliverymanModifyVO.getAffiliationCode());
		tmsBaseDeliverymanModel.setAffiliationName(deliverymanModifyVO.getAffiliationName());
		tmsBaseDeliverymanModel.setAffiliationType(deliverymanModifyVO.getAffiliationType());
		tmsBaseDeliverymanModel.setPhoneNumber(deliverymanModifyVO.getPhoneNumber());
		tmsBaseDeliverymanModel.setPassword(deliverymanModifyVO.getPassword());
		tmsBaseDeliverymanModel.setMemo(deliverymanModifyVO.getMemo());
		tmsBaseDeliverymanModel.setExtStr1(deliverymanModifyVO.getExtStr1());
		tmsBaseDeliverymanModel.setExtStr2(deliverymanModifyVO.getExtStr2());
		tmsBaseDeliverymanModel.setExtStr3(deliverymanModifyVO.getExtStr3());
		tmsBaseDeliverymanModel.setExtStr4(deliverymanModifyVO.getExtStr4());
		tmsBaseDeliverymanModel.setExtStr5(deliverymanModifyVO.getExtStr5());
		tmsBaseDeliverymanModel.setExtNum1(deliverymanModifyVO.getExtNum1());
		tmsBaseDeliverymanModel.setExtNum2(deliverymanModifyVO.getExtNum2());
		tmsBaseDeliverymanModel.setExtNum3(deliverymanModifyVO.getExtNum3());
		tmsBaseDeliverymanModel.setExtNum4(deliverymanModifyVO.getExtNum4());
		tmsBaseDeliverymanModel.setExtNum5(deliverymanModifyVO.getExtNum5());
		tmsBaseDeliverymanModel.setExtDate1(deliverymanModifyVO.getExtDate1());
		tmsBaseDeliverymanModel.setExtDate2(deliverymanModifyVO.getExtDate2());
		tmsBaseDeliverymanModel.setExtDate3(deliverymanModifyVO.getExtDate3());
		tmsBaseDeliverymanModel.setExtDate4(deliverymanModifyVO.getExtDate4());
		tmsBaseDeliverymanModel.setExtDate5(deliverymanModifyVO.getExtDate5());
		tmsBaseDeliverymanModel.setUpdateperson(user.getNickname());
		tmsBaseDeliverymanModel.setUpdatetime(date);
		tmsBaseDeliverymanModel.setDepartmentId(deliverymanModifyVO.getDepartmentId());
		tmsBaseDeliverymanModel.setDepartmentCode(deliverymanModifyVO.getDepartmentCode());
		tmsBaseDeliverymanModel.setDepartmentName(deliverymanModifyVO.getDepartmentName());
		tmsBaseDeliverymanMapper.update(tmsBaseDeliverymanModel);

		// 送货员证件关联不为空新增或修改
		if (ToolKits.isNotEmpty(deliverymanModifyVO.getDeliverymanPaperLinks())) {
			for (DeliverymanPaperLinkModifyVO deliverymanPaperLinkModifyVO : deliverymanModifyVO.getDeliverymanPaperLinks()) {
				ToolKits.isParamNull(deliverymanPaperLinkModifyVO.getId(), "证件ID不为空");

				// 根据ID查询证件对象
				TmsBasePaperModel tmsBasePaperModel = tmsBasePaperMapper.findById(deliverymanPaperLinkModifyVO.getId(), TmsBasePaperModel.class);
				// 证件对象为空新增，否则修改
				if (ToolKits.isEmpty(tmsBasePaperModel)) {
					ToolKits.isParamNull(deliverymanPaperLinkModifyVO.getCode(), "证件编码不为空");
					ToolKits.isParamNull(deliverymanPaperLinkModifyVO.getType(), "证件类型不为空");

					// 判断送货员证件编码是否已存在
					PublicMethods.isThereAnyinformation(TmsBasePaperModel.class, "code", deliverymanPaperLinkModifyVO.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_ENABLE, tmsBasePaperMapper, "送货员证件编码已存在");
					PublicMethods.isThereAnyinformation(TmsBasePaperModel.class, "code", deliverymanPaperLinkModifyVO.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_DISABLE, tmsBasePaperMapper, "送货员证件编码已存在，请直接启用");

					// 送货员证件保存
					tmsBasePaperModel = new TmsBasePaperModel();
					BeanUtils.copyProperties(deliverymanPaperLinkModifyVO, tmsBasePaperModel);
					tmsBasePaperModel.setPaperObjectType(DataDictionaryConstant.PAPER_OBJECT_DELIVERY);
					tmsBasePaperModel.setPaperObjectId(tmsBaseDeliverymanModel.getId());
					tmsBasePaperModel.setPaperObjectCode(tmsBaseDeliverymanModel.getCode());
					tmsBasePaperModel.setPaperObjectName(tmsBaseDeliverymanModel.getName());
					tmsBasePaperModel.setStatus(StatusConstant.STATUS_ENABLE);
					tmsBasePaperModel.setEnterpriseId(user.getEnterpriseId());
					tmsBasePaperModel.setEnterpriseName(user.getEnterpriseName());
					tmsBasePaperModel.setCreateperson(user.getNickname());
					tmsBasePaperModel.setCreatetime(date);
					tmsBasePaperModel.setUpdateperson(user.getNickname());
					tmsBasePaperModel.setUpdatetime(date);
					tmsBasePaperMapper.save(tmsBasePaperModel);

					// 送货员证件关联保存
					TmsDeliverymanPaperLink tmsDeliverymanPaperLinkModel = new TmsDeliverymanPaperLink();
					tmsDeliverymanPaperLinkModel.setLineid(ToolKits.getUUID());
					tmsDeliverymanPaperLinkModel.setDeliverymanId(tmsBaseDeliverymanModel.getId());
					tmsDeliverymanPaperLinkModel.setDeliverymanCode(tmsBaseDeliverymanModel.getCode());
					tmsDeliverymanPaperLinkModel.setDeliverymanName(tmsBaseDeliverymanModel.getName());
					tmsDeliverymanPaperLinkModel.setPaperId(tmsBasePaperModel.getId());
					tmsDeliverymanPaperLinkModel.setPaperCode(tmsBasePaperModel.getCode());
					tmsDeliverymanPaperLinkModel.setPaperObjectType(tmsBasePaperModel.getPaperObjectType());
					tmsDeliverymanPaperLinkModel.setCreateperson(user.getNickname());
					tmsDeliverymanPaperLinkModel.setCreatetime(date);
					tmsDeliverymanPaperLinkModel.setUpdateperson(user.getNickname());
					tmsDeliverymanPaperLinkModel.setUpdatetime(date);
					tmsDeliverymanPaperLinkMapper.save(tmsDeliverymanPaperLinkModel);
				} else {
					Assert.isTrue(tmsBasePaperModel.getStatus() == StatusConstant.STATUS_ENABLE, "证件已停用不能修改");

					tmsBasePaperModel.setIssuingAuthority(deliverymanPaperLinkModifyVO.getIssuingAuthority());
					tmsBasePaperModel.setIssuingDate(deliverymanPaperLinkModifyVO.getIssuingDate());
					tmsBasePaperModel.setStartDate(deliverymanPaperLinkModifyVO.getStartDate());
					tmsBasePaperModel.setEndDate(deliverymanPaperLinkModifyVO.getEndDate());
					tmsBasePaperModel.setPicture(deliverymanPaperLinkModifyVO.getPicture());
					tmsBasePaperModel.setMemo(deliverymanPaperLinkModifyVO.getMemo());
					tmsBasePaperModel.setUpdateperson(user.getNickname());
					tmsBasePaperModel.setUpdatetime(date);
					tmsBasePaperMapper.update(tmsBasePaperModel);
				}
			}
		}
	}

	/**
	 * 送货员资料删除
	 *
	 * @param list
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void deleteDeliverymanData(List<DeliverymanDeleteVO> list) {
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");

		for (DeliverymanDeleteVO vo : list) {
			ToolKits.isParamNull(vo.getId(), "送货员ID不能为空");

			TmsBaseDeliverymanModel model = tmsBaseDeliverymanMapper.findById(vo.getId(), TmsBaseDeliverymanModel.class);
			ToolKits.isParamNull(model, "送货员ID[" + vo.getId() + "]有误,查询为空!");

			// 关联删除
			Criteria criteria = Criteria.forClass(TmsDeliverymanPaperLink.class);
			Restriction r1 = Restrictions.eq("deliverymanId", model.getId());
			criteria.setRestriction(r1);
			List<TmsDeliverymanPaperLink> tmsDeliverymanPaperLinks = tmsDeliverymanPaperLinkMapper.findByCriteria(criteria);
			if (ToolKits.isNotEmpty(tmsDeliverymanPaperLinks)) {
				List<Long> paperIds = tmsDeliverymanPaperLinks.stream().filter(o -> ToolKits.isNotEmpty(o.getPaperId())).distinct().map(TmsDeliverymanPaperLink::getPaperId).collect(Collectors.toList());
				List<String> lineIds = tmsDeliverymanPaperLinks.stream().filter(o -> ToolKits.isNotEmpty(o.getLineid())).distinct().map(TmsDeliverymanPaperLink::getLineid).collect(Collectors.toList());
				// 删除证件
				tmsBasePaperMapper.deleteByIds(paperIds.toArray(), TmsBasePaperModel.class);
				// 删除送货员证件link表
				tmsDeliverymanPaperLinkMapper.deleteByIds(lineIds.toArray(), TmsDeliverymanPaperLink.class);
			}

			// 删除送货员
			tmsBaseDeliverymanMapper.deleteById(model.getId(), TmsBaseDeliverymanModel.class);
		}

	}

	/**
	 * 送货员证件关联查看
	 */
	@Override
	public List<DeliverymanPaperLinkCheckDTO> listDeliverymanPaperLinkCheckData(DeliverymanPaperLinkCheckVO deliverymanPaperLinkCheckVO) {
		ToolKits.isParamNull(deliverymanPaperLinkCheckVO, "送货员证件资料查看请求不为空");
		ToolKits.isParamNull(deliverymanPaperLinkCheckVO.getId(), "送货员ID为空");

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

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

		// 查询送货员证件关联数据
		Criteria criteria1 = Criteria.forClass(TmsDeliverymanPaperLink.class);
		Restriction r11 = Restrictions.eq("deliverymanId", deliverymanPaperLinkCheckVO.getId());
		criteria1.setRestriction(Restrictions.and(r11));
		List<TmsDeliverymanPaperLink> tmsDeliverymanPaperLinkModels = tmsDeliverymanPaperLinkMapper.findByCriteria(criteria1);

		// 获取证件ID
		Long[] paperIds = (tmsDeliverymanPaperLinkModels.stream().map(TmsDeliverymanPaperLink::getPaperId).distinct().collect(Collectors.toList())).stream().toArray(Long[]::new);

		// 查询对应的证件
		Criteria criteria2 = Criteria.forClass(TmsBasePaperModel.class);
		Restriction r21 = Restrictions.in("id", paperIds);
		Restriction r23 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria2.setRestriction(Restrictions.and(r21, r23));
		criteria2.setOrder(Order.newInstance().desc(new String[] { "updatetime" }));
		List<TmsBasePaperModel> tmsBasePaperModels = tmsBasePaperMapper.findByCriteria(criteria2);
		for (TmsBasePaperModel tmsBasePaperModel : tmsBasePaperModels) {
			// 响应对象
			DeliverymanPaperLinkCheckDTO deliverymanPaperLinkCheckDTO = new DeliverymanPaperLinkCheckDTO();
			BeanUtils.copyProperties(tmsBasePaperModel, deliverymanPaperLinkCheckDTO);
			deliverymanPaperLinkCheckDTOs.add(deliverymanPaperLinkCheckDTO);
		}

		return deliverymanPaperLinkCheckDTOs;
	}

	/**
	 * 送货员证件资料查看
	 */
	@Override
	public DeliverymanPaperCheckDTO getDeliverymanPaperCheckData(DeliverymanPaperCheckVO deliverymanPaperCheckVO) {
		ToolKits.isParamNull(deliverymanPaperCheckVO, "送货员证件资料查看请求不为空");
		ToolKits.isParamNull(deliverymanPaperCheckVO.getId(), "证件ID不为空");

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

		Criteria criteria = Criteria.forClass(TmsBasePaperModel.class);
		Restriction r1 = Restrictions.eq("id", deliverymanPaperCheckVO.getId());
		Restriction r2 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
		criteria.setRestriction(Restrictions.and(r1, r2));
		List<TmsBasePaperModel> tmsBasePaperModels = tmsBasePaperMapper.findByCriteria(criteria);

		Assert.isTrue(tmsBasePaperModels.size() == 1, "送货员ID【" + deliverymanPaperCheckVO.getId() + "】存在重复数据，查询失败");

		// 送货员证件资料对象
		TmsBasePaperModel tmsBasePaperModel = tmsBasePaperModels.get(0);

		// 响应对象
		DeliverymanPaperCheckDTO deliverymanPaperCheckDTO = new DeliverymanPaperCheckDTO();
		BeanUtils.copyProperties(tmsBasePaperModel, deliverymanPaperCheckDTO);

		return deliverymanPaperCheckDTO;
	}

	/**
	 * 送货员证件资料新增
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void addDeliverymanPaperData(DeliverymanPaperAddVO deliverymanPaperAddVO) {
		ToolKits.isParamNull(deliverymanPaperAddVO, "送货员证件资料新增请求不为空");
		ToolKits.isParamNull(deliverymanPaperAddVO.getDeliverymanId(), "送货员ID不为空");
		ToolKits.isParamNull(deliverymanPaperAddVO.getDeliverymanCode(), "送货员编码不为空");
		ToolKits.isParamNull(deliverymanPaperAddVO.getDeliverymanName(), "送货员名称不为空");
		ToolKits.isParamNull(deliverymanPaperAddVO.getId(), "证件编码不为空");
		ToolKits.isParamNull(deliverymanPaperAddVO.getCode(), "证件编码不为空");
		ToolKits.isParamNull(deliverymanPaperAddVO.getType(), "证件类型不为空");

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

		// 判断送货员证件编码是否已存在
		PublicMethods.isThereAnyinformation(TmsBasePaperModel.class, "code", deliverymanPaperAddVO.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_ENABLE, tmsBasePaperMapper, "送货员证件编码已存在");
		PublicMethods.isThereAnyinformation(TmsBasePaperModel.class, "code", deliverymanPaperAddVO.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_DISABLE, tmsBasePaperMapper, "送货员证件编码已存在，请直接启用");

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

		// 送货员证件保存
		TmsBasePaperModel tmsBasePaperModel = new TmsBasePaperModel();
		BeanUtils.copyProperties(deliverymanPaperAddVO, tmsBasePaperModel);
		tmsBasePaperModel.setPaperObjectType(DataDictionaryConstant.PAPER_OBJECT_DELIVERY);
		tmsBasePaperModel.setPaperObjectId(deliverymanPaperAddVO.getDeliverymanId());
		tmsBasePaperModel.setPaperObjectCode(deliverymanPaperAddVO.getDeliverymanCode());
		tmsBasePaperModel.setPaperObjectName(deliverymanPaperAddVO.getDeliverymanName());
		tmsBasePaperModel.setStatus(StatusConstant.STATUS_ENABLE);
		tmsBasePaperModel.setEnterpriseId(user.getEnterpriseId());
		tmsBasePaperModel.setEnterpriseName(user.getEnterpriseName());
		tmsBasePaperModel.setCreateperson(user.getNickname());
		tmsBasePaperModel.setCreatetime(date);
		tmsBasePaperModel.setUpdateperson(user.getNickname());
		tmsBasePaperModel.setUpdatetime(date);
		tmsBasePaperMapper.save(tmsBasePaperModel);

		// 送货员证件关联保存
		TmsDeliverymanPaperLink tmsDeliverymanPaperLinkModel = new TmsDeliverymanPaperLink();
		tmsDeliverymanPaperLinkModel.setLineid(ToolKits.getUUID());
		tmsDeliverymanPaperLinkModel.setDeliverymanId(deliverymanPaperAddVO.getDeliverymanId());
		tmsDeliverymanPaperLinkModel.setDeliverymanCode(deliverymanPaperAddVO.getDeliverymanCode());
		tmsDeliverymanPaperLinkModel.setDeliverymanName(deliverymanPaperAddVO.getDeliverymanName());
		tmsDeliverymanPaperLinkModel.setPaperId(tmsBasePaperModel.getId());
		tmsDeliverymanPaperLinkModel.setPaperCode(tmsBasePaperModel.getCode());
		tmsDeliverymanPaperLinkModel.setPaperObjectType(tmsBasePaperModel.getPaperObjectType());
		tmsDeliverymanPaperLinkModel.setCreateperson(user.getNickname());
		tmsDeliverymanPaperLinkModel.setCreatetime(date);
		tmsDeliverymanPaperLinkModel.setUpdateperson(user.getNickname());
		tmsDeliverymanPaperLinkModel.setUpdatetime(date);
		tmsDeliverymanPaperLinkMapper.save(tmsDeliverymanPaperLinkModel);
	}

	/**
	 * 送货员证件资料修改
	 */
	@Override
	public void modifyDeliverymanPaperData(DeliverymanPaperModifyVO deliverymanPaperModifyVO) {
		ToolKits.isParamNull(deliverymanPaperModifyVO, "送货员证件资料修改请求不为空");
		ToolKits.isParamNull(deliverymanPaperModifyVO.getId(), "送货员证件ID不为空");

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

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

		// 根据ID查询送货员证件信息
		TmsBasePaperModel tmsBasePaperModel = tmsBasePaperMapper.findById(deliverymanPaperModifyVO.getId(), TmsBasePaperModel.class);
		ToolKits.isParamNull(tmsBasePaperModel, "证件ID【" + deliverymanPaperModifyVO.getId() + "】不存在");

		Assert.isTrue(tmsBasePaperModel.getStatus() == StatusConstant.STATUS_ENABLE, "证件已停用不能修改");

		tmsBasePaperModel.setIssuingAuthority(deliverymanPaperModifyVO.getIssuingAuthority());
		tmsBasePaperModel.setIssuingDate(deliverymanPaperModifyVO.getIssuingDate());
		tmsBasePaperModel.setStartDate(deliverymanPaperModifyVO.getStartDate());
		tmsBasePaperModel.setEndDate(deliverymanPaperModifyVO.getEndDate());
		tmsBasePaperModel.setPicture(deliverymanPaperModifyVO.getPicture());
		tmsBasePaperModel.setMemo(deliverymanPaperModifyVO.getMemo());
		tmsBasePaperModel.setUpdateperson(user.getNickname());
		tmsBasePaperModel.setUpdatetime(date);
		tmsBasePaperMapper.update(tmsBasePaperModel);
	}

	/**
	 * 送货员证件资料是否启用
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void whetherEnableDeliverymanPaperData(DeliverymanPaperWhetherEnableVO deliverymanPaperWhetherEnableVO) {
		ToolKits.isParamNull(deliverymanPaperWhetherEnableVO, "送货员证件资料是否启用请求不为空");
		ToolKits.isParamNull(deliverymanPaperWhetherEnableVO.getDeliverymanPaperIds(), "送货员证件ID集不为空");
		ToolKits.isParamNull(deliverymanPaperWhetherEnableVO.getStatus(), "状态不为空");

		Assert.isTrue(deliverymanPaperWhetherEnableVO.getStatus() == StatusConstant.STATUS_ENABLE || deliverymanPaperWhetherEnableVO.getStatus() == StatusConstant.STATUS_DISABLE, "证件状态【" + deliverymanPaperWhetherEnableVO.getStatus() + "】错误");

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

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

		for (DeliverymanPaperByIdVO deliverymanPaperByIdVO : deliverymanPaperWhetherEnableVO.getDeliverymanPaperIds()) {
			ToolKits.isParamNull(deliverymanPaperByIdVO.getId(), "送货员证件ID不为空");

			// 根据ID查询证件对象
			TmsBasePaperModel tmsBasePaperModel = tmsBasePaperMapper.findById(deliverymanPaperByIdVO.getId(), TmsBasePaperModel.class);
			ToolKits.isParamNull(tmsBasePaperModel, "送货员证件ID【" + deliverymanPaperByIdVO.getId() + "】不存在");

			tmsBasePaperModel.setStatus(deliverymanPaperWhetherEnableVO.getStatus());
			tmsBasePaperModel.setUpdateperson(user.getNickname());
			tmsBasePaperModel.setUpdatetime(date);
			tmsBasePaperMapper.update(tmsBasePaperModel);
		}
	}

	/**
	 * 送货员证件资料删除
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void deleteDeliverymanPaperData(List<DeliverymanPaperDeleteVO> deliverymanPaperDeleteVOs) {
		ToolKits.isParamNull(deliverymanPaperDeleteVOs, "送货员证件资料删除请求不为空");

		for (DeliverymanPaperDeleteVO deliverymanPaperDeleteVO : deliverymanPaperDeleteVOs) {
			ToolKits.isParamNull(deliverymanPaperDeleteVO.getDeliverymanId(), "送货员ID不为空");
			ToolKits.isParamNull(deliverymanPaperDeleteVO.getPaperId(), "证件ID不为空");

			// 证件资料删除
			long count = tmsBasePaperMapper.deleteById(deliverymanPaperDeleteVO.getPaperId(), TmsBasePaperModel.class);
			if (count == 1) {
				// 送货员证件关联删除
				Criteria criteria = Criteria.forClass(TmsDeliverymanPaperLink.class);
				Restriction r1 = Restrictions.eq("deliverymanId", deliverymanPaperDeleteVO.getDeliverymanId());
				Restriction r2 = Restrictions.eq("paperId", deliverymanPaperDeleteVO.getPaperId());
				criteria.setRestriction(Restrictions.and(r1, r2));
				tmsDeliverymanPaperLinkMapper.deleteByCriteria(criteria);
			} else {
				throw new ParameterException("证件资料删除失败");
			}
		}
	}

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

		Criteria criteria = Criteria.forClass(TmsBaseDeliverymanModel.class);
		Restriction r1 = Restrictions.eq("importBatchNumber", batchno);
		criteria.setRestriction(r1);
		List<TmsBaseDeliverymanModel> tmsBaseDeliverymanModels = tmsBaseDeliverymanMapper.findByCriteria(criteria);
		if (ToolKits.isEmpty(tmsBaseDeliverymanModels)) {
			throw new RuntimeException("批次号[" + batchno + "]错误,查询为空!");
		}

		for (TmsBaseDeliverymanModel model : tmsBaseDeliverymanModels) {
			ToolKits.isParamNull(model.getId(), "送货员ID不能为空");

			// 关联删除
			criteria = Criteria.forClass(TmsDeliverymanPaperLink.class);
			r1 = Restrictions.eq("deliverymanId", model.getId());
			criteria.setRestriction(r1);
			List<TmsDeliverymanPaperLink> tmsDeliverymanPaperLinks = tmsDeliverymanPaperLinkMapper.findByCriteria(criteria);
			if (ToolKits.isNotEmpty(tmsDeliverymanPaperLinks)) {
				List<Long> paperIds = tmsDeliverymanPaperLinks.stream().filter(o -> ToolKits.isNotEmpty(o.getPaperId())).distinct().map(TmsDeliverymanPaperLink::getPaperId).collect(Collectors.toList());
				List<String> lineIds = tmsDeliverymanPaperLinks.stream().filter(o -> ToolKits.isNotEmpty(o.getLineid())).distinct().map(TmsDeliverymanPaperLink::getLineid).collect(Collectors.toList());
				// 删除证件
				tmsBasePaperMapper.deleteByIds(paperIds.toArray(), TmsBasePaperModel.class);
				// 删除送货员证件link表
				tmsDeliverymanPaperLinkMapper.deleteByIds(lineIds.toArray(), TmsDeliverymanPaperLink.class);
			}

			// 删除送货员
			tmsBaseDeliverymanMapper.deleteById(model.getId(), TmsBaseDeliverymanModel.class);
		}
	}

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

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

		// 送货员类型
		List<Map<String, Object>> restMessage1 = sysRefdatadService.getDropDownById(DataDictionaryConstant.DELIVERYMAN_TYPE, null, null, null);
		// 送货员状态
		List<Map<String, Object>> restMessage2 = sysRefdatadService.getDropDownById(DataDictionaryConstant.MAINDATA_STATUS, null, null, null);

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

		Criteria criteria = Criteria.forClass(TmsBaseDeliverymanModel.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<TmsBaseDeliverymanModel> tmsBaseDeliverymanModels = tmsBaseDeliverymanMapper.findByCriteria(criteria);
		for (TmsBaseDeliverymanModel tmsBaseDeliverymanModel : tmsBaseDeliverymanModels) {
			// 响应对象
			DeliverymanImportPageDTO deliverymanImportPageDTO = new DeliverymanImportPageDTO();
			BeanUtils.copyProperties(tmsBaseDeliverymanModel, deliverymanImportPageDTO);
			deliverymanImportPageDTO.setTypeName(PublicMethods.change(restMessage1, String.valueOf(deliverymanImportPageDTO.getType())));
			deliverymanImportPageDTO.setStatusName(PublicMethods.change(restMessage2, String.valueOf(deliverymanImportPageDTO.getStatus())));
			deliverymanImportPageDTOs.add(deliverymanImportPageDTO);
		}

		Page<DeliverymanImportPageDTO> page = PageUtils.getPage(deliverymanImportPageDTOs);
		if (tmsBaseDeliverymanModels instanceof com.github.pagehelper.Page) {
			com.github.pagehelper.Page<TmsBaseDeliverymanModel> p0 = (com.github.pagehelper.Page<TmsBaseDeliverymanModel>) tmsBaseDeliverymanModels;
			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 batchImportDeliverymanData(MultipartFile file, String importBatchNumber) throws Exception {
		// 人员权限
		UserEntity user = PlgFxUsrUtils.getUserEntity();
		ToolKits.isParamNull(user, "当前人员没有操作权限");
		// 导入文件判断
		FileUtils.multipartFileJudge(file);
		// 导入日志对象
		ImportLogAddVO logAddVO = new ImportLogAddVO();
		logAddVO.setImportObjNo(DataDictionaryConstant.DELIVERYMAN_IMPORT);
		logAddVO.setImportBatchNumber(importBatchNumber);
		// 导入统计
		int count = 0;
		try {
			// 导入执行
			count = this.batchInsertProcess(file, importBatchNumber, user);
			logAddVO.setStatus(DataDictionaryConstant.IMPORT_STATUS_YES);
			logAddVO.setSuccessNum(count);
			logAddVO.setFailNum(0);
			importLogService.addImportLogData(logAddVO);
		} catch (Exception e) {
			Class<DeliverymanImportStdVO> importVOClass = DeliverymanImportStdVO.class;
			List<DeliverymanImportStdVO> 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.DELIVERYMAN_IMPORT_LOG, logAddVO);
			e.printStackTrace();
			throw new ParameterException(e.getMessage());
		}
	}

	// 异步保存导入失败日志
	@RabbitListener(queues = RabbitMQConstant.DELIVERYMAN_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 batchInsertProcess(MultipartFile file, String importBatchNumber, UserEntity user) {
		Date date = new Date();
		Properties properties = new Properties();
		// 待转换的对象
		Class<DeliverymanImportStdVO> importVOClass = DeliverymanImportStdVO.class;
		// 标准模板查询
		List<StandardTemplateDetailsListDTO> standardTemplateDetailsListDTOs = sysImportTemplethService.listStandardTemplateDetailsData(DataDictionaryConstant.DELIVERYMAN_IMPORT);
		for (StandardTemplateDetailsListDTO standardTemplateDetailsListDTO : standardTemplateDetailsListDTOs) {
			// 属性字段和注解属性字段值 键值对
			properties.setProperty(standardTemplateDetailsListDTO.getStdColNo(), standardTemplateDetailsListDTO.getCustColName());
		}
		// @ExcelProperty注解属性修改
		ImportUtils.setHeaderValue(properties, importVOClass);
		// EXCEL转对象
		List<DeliverymanImportStdVO> 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 (DeliverymanImportStdVO importVO : importVOs) {
			if (ToolKits.isEmpty(importVO.getCode())) {
				throw new PrologException("第" + i + "行导入数据,送货员编码不能为空");
			}
			if (ToolKits.isEmpty(importVO.getName())) {
				throw new PrologException("第" + i + "行导入数据,送货员姓名不能为空");
			}
			if (ToolKits.isEmpty(importVO.getDepartmentName())) {
				throw new PrologException("第" + i + "行导入数据,部门名称不能为空");
			}
			if (ToolKits.isEmpty(importVO.getType())) {
				throw new PrologException("第" + i + "行导入数据,归属为必选项");
			}
			if (ToolKits.isEmpty(importVO.getPhoneNumber())) {
				throw new PrologException("第" + i + "行导入数据,手机号不能为空");
			}
			if (ToolKits.isEmpty(importVO.getPassword())) {
				throw new PrologException("第" + i + "行导入数据,密码不能为空");
			}
			i++;
		}
		// 验证导入文件中送货员编号是否重复
		Map<String, Long> codeMap = importVOs.stream().collect(Collectors.groupingBy(DeliverymanImportStdVO::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(DeliverymanImportStdVO::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 (DeliverymanImportStdVO vo : importVOs) {
			if (ToolKits.isNotEmpty(vo.getAffiliationCode()) || ToolKits.isNotEmpty(vo.getAffiliationName())) {
				ToolKits.isParamNull(vo.getAffiliationCode(), "隶属机构编码不为空");
				ToolKits.isParamNull(vo.getAffiliationName(), "隶属机构名称不为空");
			}

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

			TmsBaseDeliverymanModel model = new TmsBaseDeliverymanModel();
			BeanUtils.copyProperties(vo, model);
			model.setType(Integer.parseInt(vo.getType()));
			// 判断送货员编码是否已存在
			PublicMethods.isThereAnyinformation(TmsBaseDeliverymanModel.class, "code", vo.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_ENABLE, tmsBaseDeliverymanMapper, "送货员编码[" + vo.getCode() + "]已存在");
			PublicMethods.isThereAnyinformation(TmsBaseDeliverymanModel.class, "code", vo.getCode(), "enterpriseId", user.getEnterpriseId(), "status", StatusConstant.STATUS_DISABLE, tmsBaseDeliverymanMapper, "送货员编码[" + vo.getCode() + "]已停用,请直接启用!");

			List<Organization> data1 = Lists.newArrayList();
			// 判断隶属机构
			// if (ToolKits.isNotEmpty(vo.getAffiliationCode())) {
			if (user.getUserType().equals(BussinessConstant.USER_TYPE_ZY)) {
				// 自有账号
				// 所属部门名称判定是否存在
				RestMessage<List<Organization>> departMents = userTmsResource.search(null, vo.getDepartmentName(), null, String.valueOf(user.getEnterpriseId()));
				if (!departMents.isSuccess()) {
					throw new RuntimeException("部门【" + vo.getDepartmentName() + "】不存在!");
				} else {
					data1 = departMents.getData();
					if (!(user.getDepts().contains(data1.get(0).getId()))) {
						throw new RuntimeException("部门【" + vo.getDepartmentName() + "】不存在，请先维护部门!");
					}
				}
				if (DataDictionaryConstant.DELIVERYMAN_TYPE_ZY.equals(vo.getType())) {
					if (ToolKits.isNotEmpty(vo.getAffiliationCode()) || ToolKits.isNotEmpty(vo.getAffiliationName())) {
						// throw new BizException("自有账号导入,司机归属为自有时，隶属机构不需填写!");
						model.setAffiliationCode(null);
						model.setAffiliationName(null);
					}

					/*
					 * Criteria criteria = Criteria.forClass(TmsBaseCargoOwnerModel.class);
					 * Restriction r1 = Restrictions.eq("cargoOwnerCode", vo.getAffiliationCode());
					 * Restriction r2 = Restrictions.eq("cargoOwnerName", vo.getAffiliationName());
					 * criteria.setRestriction(Restrictions.and(r1, r2));
					 * List<TmsBaseCargoOwnerModel> tmsBaseCargoOwnerModels =
					 * tmsBaseCargoOwnerMapper.findByCriteria(criteria);
					 * ToolKits.isParamNull(tmsBaseCargoOwnerModels, "未找到对应的隶属机构[" +
					 * vo.getAffiliationName() + "]"); TmsBaseCargoOwnerModel tmsBaseCargoOwnerModel
					 * = tmsBaseCargoOwnerModels.get(0);
					 * Assert.isTrue(tmsBaseCargoOwnerModel.getStatus() !=
					 * StatusConstant.STATUS_DISABLE, "隶属机构【" + vo.getAffiliationName() + "】已被停用");
					 * 
					 * model.setAffiliationType(DataDictionaryConstant.DELIVERYMAN_TYPE_OWN);
					 * model.setAffiliationId(tmsBaseCargoOwnerModel.getCargoOwnerId());
					 */
				} else {
					ToolKits.isParamNull(vo.getAffiliationCode(), "隶属机构编码不为空");
					ToolKits.isParamNull(vo.getAffiliationName(), "隶属机构名称不为空");

					Criteria criteria = Criteria.forClass(TmsBaseCarriersModel.class);
					Restriction r1 = Restrictions.eq("code", vo.getAffiliationCode());
					Restriction r2 = Restrictions.eq("name", vo.getAffiliationName());
					Restriction r3 = null;
					Restriction r4 = null;
					Restriction r5 = Restrictions.eq("enterpriseId", user.getEnterpriseId());

					// 判断是否为部门权限
					if (user.getOwnedAllDataAuthFlag().equals(BussinessConstant.USER_DEPARTMENT_AUTH_Y)) {
						// 部门权限
						r3 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
					} else {
						r3 = Restrictions.in("departmentId", user.getDepts().stream().toArray(String[]::new));
						r4 = Restrictions.in("id", user.getCarriers().stream().toArray(Long[]::new));
					}

					criteria.setRestriction(Restrictions.and(r1, r2, r3, r4, r5));
					List<TmsBaseCarriersModel> tmsBaseCarriersModels = tmsBaseCarriersMapper.findByCriteria(criteria);
					ToolKits.isParamNull(tmsBaseCarriersModels, "未找到对应的隶属机构[" + vo.getAffiliationName() + "]");
					TmsBaseCarriersModel tmsBaseCarriersModel = tmsBaseCarriersModels.get(0);
					Assert.isTrue(tmsBaseCarriersModel.getStatus() != StatusConstant.STATUS_DISABLE, "隶属机构【" + vo.getAffiliationName() + "】已被停用");

					if (DataDictionaryConstant.DELIVERYMAN_TYPE_GK.equals(vo.getType())) {
						model.setAffiliationType(DataDictionaryConstant.DELIVERYMAN_TYPE_ANCHORED);
					} else {
						model.setAffiliationType(DataDictionaryConstant.DELIVERYMAN_TYPE_TEMPORARY);
					}
					model.setAffiliationId(tmsBaseCarriersModel.getId());
				}
			} else if (user.getUserType().equals(BussinessConstant.USER_TYPE_CYS)) {
				// 非自有账号 顶级部门取得
				RestMessage<List<Organization>> departMents2 = userTmsResource.search("0", null, null, String.valueOf(user.getEnterpriseId()));
				if (!departMents2.isSuccess()) {
					throw new RuntimeException("供应商的顶级部门不存在!");
				} else {
					data1 = departMents2.getData();
				}

				if (DataDictionaryConstant.DELIVERYMAN_TYPE_ZY.equals(vo.getType())) {
					// 自有送货员
					model.setAffiliationId(Long.valueOf(user.getLoginUserCompanyInfo().getId()));
					model.setAffiliationCode(user.getLoginUserCompanyInfo().getCode());
					model.setAffiliationName(user.getLoginUserCompanyInfo().getName());
				} else {
					ToolKits.isParamNull(vo.getAffiliationCode(), "隶属机构编码不为空");
					ToolKits.isParamNull(vo.getAffiliationName(), "隶属机构名称不为空");

					Criteria criteria = Criteria.forClass(TmsBaseCarriersModel.class);
					Restriction r1 = Restrictions.eq("code", vo.getAffiliationCode());
					Restriction r2 = Restrictions.eq("name", vo.getAffiliationName());
					Restriction r3 = Restrictions.eq("enterpriseId", user.getEnterpriseId());
					Restriction r4 = null;
					r4 = Restrictions.eq("id", Long.valueOf(user.getLoginUserCompanyInfo().getId()));

					criteria.setRestriction(Restrictions.and(r1, r2, r3, r4));
					List<TmsBaseCarriersModel> tmsBaseCarriersModels = tmsBaseCarriersMapper.findByCriteria(criteria);
					ToolKits.isParamNull(tmsBaseCarriersModels, "未找到对应的隶属机构[" + vo.getAffiliationName() + "]");
					TmsBaseCarriersModel tmsBaseCarriersModel = tmsBaseCarriersModels.get(0);
					Assert.isTrue(tmsBaseCarriersModel.getStatus() != StatusConstant.STATUS_DISABLE, "隶属机构【" + vo.getAffiliationName() + "】已被停用");

					model.setAffiliationId(tmsBaseCarriersModel.getId());
					if (DataDictionaryConstant.DELIVERYMAN_TYPE_GK.equals(vo.getType())) {
						model.setAffiliationType(DataDictionaryConstant.DELIVERYMAN_TYPE_ANCHORED);
					} else {
						model.setAffiliationType(DataDictionaryConstant.DELIVERYMAN_TYPE_TEMPORARY);
					}
				}
			}
			// }

			// 送货员ID
			String deliverymanId = sysCodeengineService.getCodeNumberByCode(SeriaNnumberConstant.DELIVERYMAN_ID, "L");
			ToolKits.isParamNull(deliverymanId, "送货员ID生成失败");
			// 送货员对象
			model.setId(Long.valueOf(deliverymanId));
			model.setStatus(StatusConstant.STATUS_ENABLE);
			model.setSource(DataDictionaryConstant.SOURCE_EXCEL);
			model.setImportBatchNumber(importBatchNumber);
			model.setCreatetime(new Date());
			model.setCreateperson(user.getNickname());
			model.setEnterpriseId(user.getEnterpriseId());
			model.setEnterpriseName(user.getEnterpriseName());
			model.setUpdateperson(user.getNickname());
			model.setUpdatetime(date);
			// 部门
			model.setDepartmentId(data1.get(0).getId());
			model.setDepartmentCode(data1.get(0).getCode());
			model.setDepartmentName(data1.get(0).getName());
			tmsBaseDeliverymanMapper.save(model);
			i++;
		}
		return i;
	}

}
