package com.prolog.cs.biz.inbound.service.impl.task;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert;
import com.codingapi.tx.annotation.TxTransaction;
import com.esotericsoftware.minlog.Log;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Lists;
import com.prolog.common.util.ToolKits;
import com.prolog.cs.basic.chain.model.customer.BaseCustomerMst;
import com.prolog.cs.basic.chain.model.supplier.BaseSupplierMst;
import com.prolog.cs.basic.common.model.BaseCommonDict;
import com.prolog.cs.basic.item.model.BaseMtlItemHealth;
import com.prolog.cs.basic.item.model.BaseMtlItemMst;
import com.prolog.cs.basic.item.model.BaseMtlItemWms;
import com.prolog.cs.basic.warehouse.model.BaseWmsWarehouseLocator;
import com.prolog.cs.basic.warehouse.model.BaseWmsWarehouseMst;
import com.prolog.cs.basic.warehouse.model.BaseWmsWhContainer;
import com.prolog.cs.basic.warehouse.model.vo.ContainerQueryVO;
import com.prolog.cs.biz.control.model.vo.LocatorQueryVO;
import com.prolog.cs.biz.inbound.constant.BizConstant;
import com.prolog.cs.biz.inbound.constant.InboundBizConstant;
import com.prolog.cs.biz.inbound.dao.OmsAsnBillDMapper;
import com.prolog.cs.biz.inbound.dao.OmsAsnBillHMapper;
import com.prolog.cs.biz.inbound.dao.SupervisionCodeMapper;
import com.prolog.cs.biz.inbound.dao.rcv.*;
import com.prolog.cs.biz.inbound.dao.rqc.RqcLinesMapper;
import com.prolog.cs.biz.inbound.dao.task.TaskInstockDetailMapper;
import com.prolog.cs.biz.inbound.dao.task.TaskQcDetailMapper;
import com.prolog.cs.biz.inbound.dto.PageParam;
import com.prolog.cs.biz.inbound.dto.print.InstockTaskPrintDTO;
import com.prolog.cs.biz.inbound.dto.rcv.*;
import com.prolog.cs.biz.inbound.dto.rqc.RqcDTO;
import com.prolog.cs.biz.inbound.dto.rqc.RqcHeadersDTO;
import com.prolog.cs.biz.inbound.dto.rqc.RqcLinesDTO;
import com.prolog.cs.biz.inbound.dto.rqc.WmsInRqcSampleDTO;
import com.prolog.cs.biz.inbound.dto.task.TaskInstockDetailDTO;
import com.prolog.cs.biz.inbound.model.OmsAsnBillD;
import com.prolog.cs.biz.inbound.model.OmsAsnBillH;
import com.prolog.cs.biz.inbound.model.SupervisionCode;
import com.prolog.cs.biz.inbound.model.rcv.*;
import com.prolog.cs.biz.inbound.model.rqc.RqcLines;
import com.prolog.cs.biz.inbound.model.task.TaskInstockDetail;
import com.prolog.cs.biz.inbound.model.task.TaskQcDetail;
import com.prolog.cs.biz.inbound.remote.*;
import com.prolog.cs.biz.inbound.service.impl.BaseServiceImpl;
import com.prolog.cs.biz.inbound.service.impl.CommonRemoteService;
import com.prolog.cs.biz.inbound.service.impl.rcv.RcvHeadersServiceImpl;
import com.prolog.cs.biz.inbound.service.impl.rcv.RcvTypeService;
import com.prolog.cs.biz.inbound.service.impl.strategy.WhAreaCategoryContext;
import com.prolog.cs.biz.inbound.service.rcv.RcvHeadersProfilesService;
import com.prolog.cs.biz.inbound.service.rcv.RcvHeadersService;
import com.prolog.cs.biz.inbound.service.rcv.RcvHeadersSrcBillsService;
import com.prolog.cs.biz.inbound.service.rcv.RcvInstockLinesService;
import com.prolog.cs.biz.inbound.service.rqc.RqcHeadersService;
import com.prolog.cs.biz.inbound.service.rqc.RqcLinesService;
import com.prolog.cs.biz.inbound.service.rqc.WmsInRqcSampleService;
import com.prolog.cs.biz.inbound.service.task.TaskInstockDetailService;
import com.prolog.cs.biz.inbound.service.task.TaskStraightService;
import com.prolog.cs.biz.inbound.utils.ObjectUtils;
import com.prolog.cs.biz.inbound.utils.UserUtils;
import com.prolog.cs.biz.inbound.vo.InsockTaskRcvQueryVO;
import com.prolog.cs.biz.inbound.vo.RqcDQueryVO;
import com.prolog.cs.biz.inbound.vo.task.TaskQueryVO;
import com.prolog.framework.authority.core.dto.UserDTO;
import com.prolog.framework.bz.common.integration.IntegrationApi;
import com.prolog.framework.bz.common.integration.IntegrationSearchData;
import com.prolog.framework.bz.common.integration.IntegrationSearchException;
import com.prolog.framework.bz.common.print.PrintData;
import com.prolog.framework.bz.common.print.ReportData;
import com.prolog.framework.bz.common.search.SearchApi;
import com.prolog.framework.bz.core.collection.ValidList;
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.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.framework.utils.*;
import com.prolog.upcloud.base.inventory.dto.InstockItemInfo;
import com.prolog.upcloud.base.inventory.vo.InvStockCancel;
import com.prolog.upcloud.base.inventory.vo.InvStockIn;
import com.prolog.upcloud.base.inventory.vo.InvStockInDetail;
import com.prolog.upcloud.base.strategy.domain.core.Strategy;
import com.prolog.upcloud.base.strategy.dto.StrategyDTO;
import com.prolog.wms.base.util.mapper.MapperCustom;
import io.swagger.annotations.ApiModelProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@Service
public class TaskStraightServiceImpl implements TaskStraightService {

	@Resource
	private UserUtils userUtils;

	@Autowired
	private ChainRemoteCaller chainRemoteCaller;

	@Resource
	private BaseItemRemoteCaller baseItemRemoteCaller;

	@Resource
	private CommonCaller commonCaller;

	@Resource
	private BaseWmsWarehouseCaller baseWmsWarehouseCaller;

	@Resource
	private CommonRemoteService commonRemoteService;

	@Resource
	private RcvTypeService rcvTypeService;

	@Resource
	private OmsAsnBillHMapper omsAsnBillHMapper;

	@Resource
	private OmsAsnBillDMapper omsAsnBillDMapper;

	@Resource
	private RcvHeadersService rcvHeadersService;

	@Resource
	private WmsInRqcSampleService wmsInRqcSampleService;

	@Resource
	private RqcLinesService rqcLinesService;

	@Resource
	private RqcHeadersService rqcHeadersService;

	@Resource
	private RcvLinesMapper rcvLineMapper;

	@Resource
	private RcvLinesProfilesMapper rcvLinesProfilesMapper;

	@Resource
	private TaskQcDetailMapper taskQcDetailMapper;

	@Resource
	private RcvHeadersMapper rcvHeadersMapper;

	@Resource
	private RcvHeadersProfilesMapper rcvHeadersProfilesMapper;

	@Resource
	private RcvInstockLinesService rcvInstockLinesService;

	@Resource
	private RcvInstockLinesMapper rcvInstockLinesMapper;

	@Resource
	private RqcLinesMapper rqcLinesMapper;

	@Resource
	private TaskInstockDetailMapper taskInstockDetailMapper;

	@Resource
	private RcvHeadersProfilesService rcvHeadersProfilesService;

	@Resource
	private RcvHeadersSrcBillsService rcvHeadersSrcBillsService;

	@Resource
	private SupervisionCodeMapper supervisionCodeMapper;

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void taskExecute() {
		//查询直通入库单
		OmsAsnBillH asnBillH = MapperCustom.builder(omsAsnBillHMapper, OmsAsnBillH.class)
				.andEq(OmsAsnBillH::getBilltype, "6")
				.andEq(OmsAsnBillH::getStraightTaskCompleteFlag, "0")
				.findFirst();

		if (ToolKits.isEmpty(asnBillH)) {
			return;
		}
		//查询直通入库单明细
		Criteria cr1 = Criteria.forClass(OmsAsnBillD.class);
		Restriction r1 = Restrictions.eq("billid", asnBillH.getBillid());
		cr1.setRestriction(r1);
		List<OmsAsnBillD> omsBillDList = omsAsnBillDMapper.findByCriteria(cr1);
		if (ToolKits.isEmpty(omsBillDList)) {
			return;
		}
		//1.生成收货单相关数据
		UserDTO userDTO = userUtils.getUserDTO();
		//组装相关参数
		RcvHeadersDTO rcvHeadersDTO = createHeadersDTO(asnBillH,userDTO);
		rcvHeadersDTO.setAccessLevel("0");
		//生成收货记录汇总表wms_in_rcv_headers
		String masterId = (String)rcvHeadersService.add(rcvHeadersDTO,userDTO);
		//生成收货记录汇总对应的附属表 wms_in_rcv_headers_profiles 和 wms_in_rcv_headers_src_bills
		RcvHeadersProfilesDTO rcvHeadersProfilesDTO = createHeaderssProfilesDTO(asnBillH,rcvHeadersDTO,masterId);
		rcvHeadersProfilesService.add(rcvHeadersProfilesDTO);
		List<RcvHeadersSrcBillsDTO> rcvHeadersSrcBillsDTOList = createHeaderssSrcBillsDTO(asnBillH,rcvHeadersDTO,masterId);
		rcvHeadersSrcBillsService.batchAdd(rcvHeadersSrcBillsDTOList, masterId, userDTO);

		rcvHeadersDTO.setRcvHeaderId(masterId);
		//生成 库存批次表 wms_inv_batch_number和 收货记录明细表wms_in_rcv_lines 和 质检任务池wms_in_task_qc_detail
		List<RcvLinesDTO> rcvLinesDTOList = createRcvLinesDTOList(asnBillH,omsBillDList);
		boolean ztFlag =true;
		Object excuteRcvLine = rcvTypeService.excuteRcvLine(rcvHeadersDTO, rcvLinesDTOList, userDTO, null,ztFlag);

		//查询对应的生成监管码
		//查询RcvLines
		Criteria cr2 = Criteria.forClass(RcvLines.class);
		Restriction r2 = Restrictions.eq("asnHeaderId", asnBillH.getBillid());
		cr2.setRestriction(r2);
		List<RcvLines> rcvLinesList = rcvLineMapper.findByCriteria(cr2);
		List<String> itemIds = rcvLinesList.stream().map(RcvLines::getItemId).distinct().collect(Collectors.toList());
		List<SupervisionCode> supervisionCodes = MapperCustom.builder(supervisionCodeMapper,SupervisionCode.class)
				.andEq(SupervisionCode::getRefBillId,masterId)
				.andIn(SupervisionCode::getItemId,itemIds)
				.andEq(SupervisionCode::getUploadFlag,"0")
				.findByCriteria();
		if(ToolKits.isNotEmpty(supervisionCodes)){
			for (RcvLines rcvLines : rcvLinesList) {
				SupervisionCode supervisionCode = 	supervisionCodes.stream().filter(x -> x.getItemId().equals(rcvLines.getItemId())).findFirst().orElse(null);
				//更新对应的监管码
				supervisionCode.setRefBillLineId(rcvLines.getRcvLineId());
				supervisionCode.setContainerCode(rcvLines.getContainerCode());
				supervisionCode.setPieceQty(rcvLines.getPieceQty().toString());
				supervisionCode.setWhAreaCategoryCode(rcvLines.getWhAreaCategoryCode());
				supervisionCode.setGmtCreate(rcvLines.getGmtCreate());
				supervisionCode.setCreator(rcvLines.getCreator());
				supervisionCode.setGmtModified(rcvLines.getGmtModified());
				supervisionCode.setModifier(rcvLines.getModifier());
				supervisionCodeMapper.update(supervisionCode);
			}
		}

		//2.生成质检抽样表相关数据
		//组装相关参数
		List<WmsInRqcSampleDTO> wmsInRqcSampleDTOList = createRqcSampleDTO(asnBillH);
		String type ="straight";
		wmsInRqcSampleService.batchAdd(wmsInRqcSampleDTOList,type);

		//3.生成验收单相关数据
		RqcDTO rqcDTO = createRqcDTO(asnBillH);
		addWithRelatedAll(rqcDTO,false,true);

		//4.生成上架单相关单据
		List<RcvInstockLinesDTO> rcvInstockLinesDTOLis = createInstockLinesDTO(asnBillH);
		rcvInstockLinesService.batchAdd(rcvInstockLinesDTOLis);

		//5.更新asnBillH定时任务标识
		asnBillH.setStraightTaskCompleteFlag("1");
		omsAsnBillHMapper.update(asnBillH);

	}

	private List<RcvHeadersSrcBillsDTO> createHeaderssSrcBillsDTO(OmsAsnBillH asnBillH, RcvHeadersDTO rcvHeadersDTO, String masterId) {
		List<RcvHeadersSrcBillsDTO> rcvHeadersSrcBillsDTOList = new ArrayList<>();
		RcvHeadersSrcBillsDTO rcvHeadersSrcBillsDTO = new RcvHeadersSrcBillsDTO();
		rcvHeadersSrcBillsDTO.setRcvHeaderId(masterId);
		rcvHeadersSrcBillsDTO.setSrcHeaderType(asnBillH.getRefBilltype());
		rcvHeadersSrcBillsDTO.setRcvType(asnBillH.getBilltype());
		rcvHeadersSrcBillsDTO.setAsnHeaderId(asnBillH.getBillid());
		rcvHeadersSrcBillsDTO.setAsnAutoBillNum(asnBillH.getBillno());
		rcvHeadersSrcBillsDTO.setRcvDate(rcvHeadersDTO.getRcvDate());
		rcvHeadersSrcBillsDTOList.add(rcvHeadersSrcBillsDTO);

		return rcvHeadersSrcBillsDTOList;
	}

	private RcvHeadersProfilesDTO createHeaderssProfilesDTO(OmsAsnBillH asnBillH, RcvHeadersDTO rcvHeadersDTO,String masterId) {
		RcvHeadersProfilesDTO rcvHeadersProfilesDTO =new RcvHeadersProfilesDTO();
		rcvHeadersProfilesDTO.setRcvHeaderId(masterId);
		rcvHeadersProfilesDTO.setRcvType(rcvHeadersDTO.getRcvType());
		rcvHeadersProfilesDTO.setArrivalMode(rcvHeadersDTO.getArrivalMode());
		rcvHeadersProfilesDTO.setVendorNum(asnBillH.getShippercode());
		rcvHeadersProfilesDTO.setVendorName(asnBillH.getShippername());
		rcvHeadersProfilesDTO.setWarehouseNum(asnBillH.getBranchcode());
		rcvHeadersProfilesDTO.setMtlOwnerName(asnBillH.getConsignorname());
		rcvHeadersProfilesDTO.setMtlOwnerNum(asnBillH.getConsignorcode());
		return rcvHeadersProfilesDTO;
	}

	private List<RcvInstockLinesDTO> createInstockLinesDTO(OmsAsnBillH asnBillH) {
		List<RcvInstockLinesDTO> instockLinesDTOS =new ArrayList<>();
		//查询上架任务池信息
		Criteria cr1 = Criteria.forClass(TaskInstockDetail.class);
		Restriction r1 = Restrictions.eq("asnHeaderId", asnBillH.getBillid());
		cr1.setRestriction(r1);
		List<TaskInstockDetail> taskInstockDetails = taskInstockDetailMapper.findByCriteria(cr1);
		for(TaskInstockDetail taskInstockDetail : taskInstockDetails){
			//查询仓库信息
			BaseWmsWarehouseMst baseWmsWarehouseMst = getWarehouse(taskInstockDetail.getWarehouseId());
			//查询直通货位信息
			RestMessage<Page<BaseWmsWarehouseLocator>> page = baseWmsWarehouseCaller.getLocatorPage(null, null, null,
					baseWmsWarehouseMst.getWarehouseId(), 1000, 1);
			boolean success = page.isSuccess();
			if(!success){
				throw new ParameterException("查询货位信息失败");
			}
			List<BaseWmsWarehouseLocator> list = page.getData().getList();
			BaseWmsWarehouseLocator wmsWarehouseLocator = list.stream().filter(x-> x.getWarehouseAreaCategory().equals("ZTK")).findFirst().orElse(null);
			if(ToolKits.isEmpty(wmsWarehouseLocator)){
				throw new ParameterException("未查询到直通货位信息");
			}

			//查询验收单明细记录表
			RqcLines rqcLines = rqcLinesMapper.findById(taskInstockDetail.getRqcLineId(), RqcLines.class);
			//查询RcvLines表信息
			RcvLines rcvLines = rcvLineMapper.findById(taskInstockDetail.getRcvLineId(), RcvLines.class);
			//查询RcvLines附属表信息
			RcvLinesProfiles rcvLinesProfiles = rcvLinesProfilesMapper.findById(taskInstockDetail.getRcvLineId(), RcvLinesProfiles.class);

			RcvInstockLinesDTO rcvInstockLinesDTO =new RcvInstockLinesDTO();
			rcvInstockLinesDTO.setMtlOwnerId(taskInstockDetail.getMtlOwnerId());
			rcvInstockLinesDTO.setWarehouseId(taskInstockDetail.getWarehouseId());
			rcvInstockLinesDTO.setAsnHeaderId(taskInstockDetail.getAsnHeaderId());
			rcvInstockLinesDTO.setAsnLineId(taskInstockDetail.getAsnLineId());
			rcvInstockLinesDTO.setRcvHeaderId(taskInstockDetail.getRcvHeaderId());
			rcvInstockLinesDTO.setRcvLineId(taskInstockDetail.getRcvLineId());
			rcvInstockLinesDTO.setItemId(taskInstockDetail.getItemId());
			rcvInstockLinesDTO.setUom(taskInstockDetail.getUom());
			rcvInstockLinesDTO.setConversionRate(taskInstockDetail.getConversionRate());
			rcvInstockLinesDTO.setPieceQty(taskInstockDetail.getPieceQty());
			rcvInstockLinesDTO.setBatchId(taskInstockDetail.getBatchId());
			rcvInstockLinesDTO.setBatchNum(taskInstockDetail.getBatchNum());
			rcvInstockLinesDTO.setManufacturerLotNum(taskInstockDetail.getManufacturerLotNum());
			rcvInstockLinesDTO.setContainerCode(taskInstockDetail.getContainerCode());
			rcvInstockLinesDTO.setWhLocatorId(wmsWarehouseLocator.getWarehouseLocatorId());
			rcvInstockLinesDTO.setWhLocatorCode(wmsWarehouseLocator.getWarehouseLocatorCode());
			rcvInstockLinesDTO.setWhLocatorName(wmsWarehouseLocator.getWarehouseLocatorName());
			rcvInstockLinesDTO.setWhAreaCategoryCode(wmsWarehouseLocator.getAreaCategory());
			rcvInstockLinesDTO.setWhAreaCategoryName("直通库");
			rcvInstockLinesDTO.setWhAreaCode(wmsWarehouseLocator.getAreaCategory());
			rcvInstockLinesDTO.setRealWhLocatorId(wmsWarehouseLocator.getWarehouseLocatorId());
			rcvInstockLinesDTO.setRealWhLocatorCode(wmsWarehouseLocator.getWarehouseLocatorCode());
			rcvInstockLinesDTO.setRealWhLocatorName(wmsWarehouseLocator.getWarehouseLocatorName());
			rcvInstockLinesDTO.setWarehouseName(baseWmsWarehouseMst.getWarehouseName());
			rcvInstockLinesDTO.setItemNum(rcvLinesProfiles.getItemNum());
			rcvInstockLinesDTO.setItemName(rcvLinesProfiles.getItemName());
			rcvInstockLinesDTO.setCategoryName(rcvLinesProfiles.getCategoryName());
			rcvInstockLinesDTO.setCategoryId(rcvLinesProfiles.getCategoryId());
			rcvInstockLinesDTO.setOddPieceQty(rqcLines.getOddPieceQty());
			rcvInstockLinesDTO.setBatchProductionDate(taskInstockDetail.getBatchProductionDate());
			rcvInstockLinesDTO.setBatchExpiredDate(taskInstockDetail.getBatchExpiredDate());
			rcvInstockLinesDTO.setVendorId(taskInstockDetail.getVendorId());
			rcvInstockLinesDTO.setProductionPlace(taskInstockDetail.getProductionPlace());
			rcvInstockLinesDTO.setPiecePriceTi(taskInstockDetail.getPiecePriceTi());
			rcvInstockLinesDTO.setPiecePriceTe(taskInstockDetail.getPiecePriceTe());
			rcvInstockLinesDTO.setTaxRate(taskInstockDetail.getTaxRate());
			rcvInstockLinesDTO.setIsLock(taskInstockDetail.getIsLock());
			rcvInstockLinesDTO.setItemIsPieceOrCase(taskInstockDetail.getItemIsPieceOrCase());
			rcvInstockLinesDTO.setRcvType(taskInstockDetail.getRcvType());
			rcvInstockLinesDTO.setSpecification(rcvLinesProfiles.getSpecification());
			rcvInstockLinesDTO.setItemHealthStoreCategory(rcvLinesProfiles.getItemHealthStoreCategory());
			rcvInstockLinesDTO.setItemIsImported(rcvLinesProfiles.getItemIsImported());
			rcvInstockLinesDTO.setItemIsRecheck(rcvLinesProfiles.getItemIsRecheck());
			rcvInstockLinesDTO.setIsInstrument(rcvLinesProfiles.getIsInstrument());
			rcvInstockLinesDTO.setRcvDate(rcvLines.getRcvDate());
			rcvInstockLinesDTO.setInventoryStatus(taskInstockDetail.getInventoryStatus());
			rcvInstockLinesDTO.setInstockLabel(taskInstockDetail.getInstockLabel());
			rcvInstockLinesDTO.setManufacturerName(rcvLinesProfiles.getManufacturerName());
			rcvInstockLinesDTO.setManufacturerId(rcvLinesProfiles.getManufacturerId());
			rcvInstockLinesDTO.setShowExpiredDate(rcvLines.getShowExpiredDate());
			rcvInstockLinesDTO.setShowProductionDate(rcvLines.getShowProductionDate());
			rcvInstockLinesDTO.setItemZjm(rcvLines.getItemZjm());
			rcvInstockLinesDTO.setMtlOwnerName(rcvLines.getMtlOwnerName());
			rcvInstockLinesDTO.setItemHealthRegisterNbr(rcvLinesProfiles.getItemHealthRegisterNbr());
			rcvInstockLinesDTO.setApprovalNumber(rcvLines.getApprovalNumber());
			rcvInstockLinesDTO.setStoreTemperature(rcvLinesProfiles.getStoreTemperature());
			rcvInstockLinesDTO.setEnterpriseId(rcvLinesProfiles.getEnterpriseId());
			rcvInstockLinesDTO.setShipperName(asnBillH.getShippername());
			rcvInstockLinesDTO.setCreator(taskInstockDetail.getCreator());
			rcvInstockLinesDTO.setCreatorName(taskInstockDetail.getCreatorName());
			rcvInstockLinesDTO.setCreatorName(taskInstockDetail.getCreatorName());
			rcvInstockLinesDTO.setTaskId(taskInstockDetail.getTaskInboundId());
			rcvInstockLinesDTO.setOddCaseQty(rcvLines.getOddCaseQty());

			instockLinesDTOS.add(rcvInstockLinesDTO);
		}
		//查询验收单明细记录

		return  instockLinesDTOS;
	}

	private RqcDTO createRqcDTO(OmsAsnBillH asnBillH) {
		RqcDTO rqcDTO =new RqcDTO();
		//查询RcvHeaders
		Criteria cr1 = Criteria.forClass(RcvHeaders.class);
		Restriction r1 = Restrictions.eq("asnHeaderId", asnBillH.getBillid());
		cr1.setRestriction(r1);
		List<RcvHeaders> rcvHeadersList = rcvHeadersMapper.findByCriteria(cr1);

		//查询RcvLines
		Criteria cr2 = Criteria.forClass(RcvLines.class);
		Restriction r2 = Restrictions.eq("asnHeaderId", asnBillH.getBillid());
		cr2.setRestriction(r2);
		List<RcvLines> rcvLinesList = rcvLineMapper.findByCriteria(cr2);
		RcvHeaders rcvHeaders =rcvHeadersList.get(0);
		//查询RcvHeaders的附属表
		RcvHeadersProfiles rcvHeadersProfiles = rcvHeadersProfilesMapper.findById(rcvHeaders.getRcvHeaderId(), RcvHeadersProfiles.class);

		RqcHeadersDTO rqcHeadersDTO = new RqcHeadersDTO();
		rqcHeadersDTO.setRcvHeaderId(rcvHeaders.getRcvHeaderId());
		rqcHeadersDTO.setWarehouseId(rcvHeaders.getWarehouseId());
		rqcHeadersDTO.setMtlOwnerId(rcvHeaders.getMtlOwnerId());
		rqcHeadersDTO.setVendorId(rcvHeaders.getVendorId());
		rqcHeadersDTO.setRcvType(rcvHeaders.getRcvType());
		rqcHeadersDTO.setMtlOwnerName(asnBillH.getConsignorname());
		rqcHeadersDTO.setAsnHeaderId(rcvHeaders.getAsnHeaderId());
		rqcHeadersDTO.setVendorName(rcvHeadersProfiles.getVendorName());
		rqcHeadersDTO.setBuyerMane(rcvHeadersProfiles.getBuyerMane());
		rqcHeadersDTO.setRcvDate(rcvHeaders.getRcvDate());
		rqcHeadersDTO.setRcvUser(rcvHeaders.getExecutorUser());
		rqcHeadersDTO.setRcvUser(rcvHeaders.getExecutorUser());
		rqcHeadersDTO.setIsInstockPrint(0);//不打印上架标签
		rqcHeadersDTO.setBillDate(new Date());//不打印上架标签
		rqcDTO.setRqcHeadersDTO(rqcHeadersDTO);

		List<RqcLinesDTO> rqcLinesDTOList =new ArrayList<>();
		for(RcvLines rcvLine : rcvLinesList){
			//查询仓库信息
			BaseWmsWarehouseMst baseWmsWarehouseMst = getWarehouse(rcvLine.getWarehouseId());
			//查询RcvLines附属表信息
			RcvLinesProfiles rcvLinesProfiles = rcvLinesProfilesMapper.findById(rcvLine.getRcvLineId(), RcvLinesProfiles.class);
			//查询质检任务
			TaskQcDetail taskQcDetail = MapperCustom.builder(taskQcDetailMapper, TaskQcDetail.class)
					.andEq(TaskQcDetail::getRcvLineId, rcvLine.getRcvLineId())
					.findFirst();
			RqcLinesDTO rqcLinesDTO =new RqcLinesDTO();
			rqcLinesDTO.setIsAgv("1");
			rqcLinesDTO.setWarehouseId(rcvHeaders.getWarehouseId());
			rqcLinesDTO.setItemId(rcvLine.getItemId());
			rqcLinesDTO.setMinSu("1");//????包装数从那里查询的
			rqcLinesDTO.setMiddleSu("2");
			rqcLinesDTO.setMaxSu("10");
			rqcLinesDTO.setIsSupervise(2);
			rqcLinesDTO.setItemNum(rcvLinesProfiles.getItemNum());
			rqcLinesDTO.setItemName(rcvLinesProfiles.getItemName());
			rqcLinesDTO.setCategoryName(rcvLinesProfiles.getCategoryName());
			rqcLinesDTO.setSpecification(rcvLinesProfiles.getSpecification());
			rqcLinesDTO.setUom(rcvLine.getUom());
			rqcLinesDTO.setConversionRate(rcvLine.getConversionRate());
			rqcLinesDTO.setPieceQty(rcvLine.getPieceQty());
			rqcLinesDTO.setOddCaseQty(rcvLine.getOddCaseQty());
			rqcLinesDTO.setOddPieceQty(rcvLine.getOddPieceQty());
			rqcLinesDTO.setManufacturerLotNum(rcvLine.getManufacturerLotNum());
			rqcLinesDTO.setShowProductionDate(rcvLine.getShowProductionDate());
			rqcLinesDTO.setShowExpiredDate(rcvLine.getShowExpiredDate());
			rqcLinesDTO.setManufacturerName(rcvLinesProfiles.getManufacturerName());
			rqcLinesDTO.setProductionPlace(rcvLine.getProductionPlace());
			rqcLinesDTO.setApprovalNumber(rcvLine.getApprovalNumber());
			rqcLinesDTO.setRcvLineId(rcvLine.getRcvLineId());
			rqcLinesDTO.setTaskRqcId(taskQcDetail.getTaskRqcId());
			rqcLinesDTO.setMtlOwnerId(rcvLine.getMtlOwnerId());
			rqcLinesDTO.setAsnHeaderId(rcvLine.getAsnHeaderId());
			rqcLinesDTO.setAsnLineId(rcvLine.getAsnLineId());
			rqcLinesDTO.setRcvHeaderId(rcvLine.getRcvHeaderId());
			rqcLinesDTO.setBatchId(rcvLine.getBatchId());
			rqcLinesDTO.setBatchNum(rcvLine.getBatchNum());
			rqcLinesDTO.setContainerCode(rcvLine.getContainerCode());
			rqcLinesDTO.setGoodsCaseCode(rcvLine.getGoodsCaseCode());
			rqcLinesDTO.setTimes(0);
			rqcLinesDTO.setWarehouseName(rcvLine.getWarehouseName());
			rqcLinesDTO.setWarehouseName(rcvLine.getWarehouseName());
			rqcLinesDTO.setIsLock(rcvLinesProfiles.getIsLock());
			rqcLinesDTO.setBatchProductionDate(rcvLine.getBatchProductionDate());
			rqcLinesDTO.setBatchExpiredDate(rcvLine.getBatchExpiredDate());
			rqcLinesDTO.setCategoryId(rcvLinesProfiles.getCategoryId());
			rqcLinesDTO.setWarehouseCode(baseWmsWarehouseMst.getWarehouseCode());
			rqcLinesDTO.setVendorId(rcvHeaders.getVendorId());
			rqcLinesDTO.setPiecePriceTi(rcvLinesProfiles.getPiecePriceTi());
			rqcLinesDTO.setPiecePriceTe(rcvLinesProfiles.getPiecePriceTe());
			rqcLinesDTO.setTaxRate(rcvLinesProfiles.getTaxRate());
			rqcLinesDTO.setItemIsPieceOrCase(rcvLine.getItemIsPieceOrCase());
			rqcLinesDTO.setRcvType(rcvLine.getRcvType());
			rqcLinesDTO.setItemIsImported(rcvLinesProfiles.getItemIsImported());
			rqcLinesDTO.setItemIsRecheck(rcvLinesProfiles.getItemIsRecheck());
			rqcLinesDTO.setIsInstrument(rcvLinesProfiles.getIsInstrument());
			rqcLinesDTO.setIsHosted(rcvLinesProfiles.getIsHosted());
			rqcLinesDTO.setManufacturerId(rcvLinesProfiles.getManufacturerId());
			rqcLinesDTO.setShelfLifeDays(rcvLinesProfiles.getShelfLifeDays());
			rqcLinesDTO.setShelfLifeUnit(rcvLinesProfiles.getShelfLifeUnit());
			rqcLinesDTO.setItemIsSpecial(rcvLinesProfiles.getItemIsSpecial());
			rqcLinesDTO.setIsBacteria(rcvLinesProfiles.getIsBacteria());
			rqcLinesDTO.setIsRechecked(rcvLinesProfiles.getIsBacteria());
			rqcLinesDTO.setIsDelegate(rcvLine.getIsDelegate());
			rqcLinesDTO.setItemZjm(rcvLine.getItemZjm());
			rqcLinesDTO.setRefLineId(rcvLine.getRcvLineId());
			rqcLinesDTO.setRefType(Integer.parseInt(rcvLine.getRcvType()));
			rqcLinesDTO.setItemHealthStoreCategory(rcvLinesProfiles.getItemHealthStoreCategory());
			rqcLinesDTO.setStockStatus(rcvLine.getStockStatus());
			rqcLinesDTO.setAllowDecimal(rcvLinesProfiles.getAllowDecimal());
			rqcLinesDTO.setWhAreaCategory(rcvLine.getWhAreaCategoryCode());
			rqcLinesDTO.setVendorName(rcvHeadersProfiles.getVendorName());
			rqcLinesDTO.setQcOpcode1(rcvHeaders.getExecutorUser());
			rqcLinesDTO.setQcOddCaseActQty(new BigDecimal(1));
			rqcLinesDTO.setQcOddPieceActQty(new BigDecimal(0));
			rqcLinesDTO.setQcResult1("0");
			rqcLinesDTOList.add(rqcLinesDTO);
		}

		rqcDTO.setRqcLinesDTOList(rqcLinesDTOList);
		return rqcDTO;
	}

	private List<WmsInRqcSampleDTO> createRqcSampleDTO(OmsAsnBillH asnBillH) {
		List<WmsInRqcSampleDTO> rqcSampleDTOList =new ArrayList<>();
		Criteria cr1 = Criteria.forClass(RcvLines.class);
		Restriction r1 = Restrictions.eq("asnHeaderId", asnBillH.getBillid());
		cr1.setRestriction(r1);
		List<RcvLines> rcvLinesList = rcvLineMapper.findByCriteria(cr1);
		for(RcvLines rcvLine : rcvLinesList){
			//查询仓库信息
			BaseWmsWarehouseMst baseWmsWarehouseMst = getWarehouse(rcvLine.getWarehouseId());
			//查询RcvLines附属表信息
			RcvLinesProfiles rcvLinesProfiles = rcvLinesProfilesMapper.findById(rcvLine.getRcvLineId(), RcvLinesProfiles.class);
			OmsAsnBillD omsAsnBillD = omsAsnBillDMapper.findById(rcvLine.getAsnLineId(), OmsAsnBillD.class);
			//查询质检任务
			TaskQcDetail taskQcDetail = MapperCustom.builder(taskQcDetailMapper, TaskQcDetail.class)
					.andEq(TaskQcDetail::getRcvLineId, rcvLine.getRcvLineId())
					.findFirst();
			WmsInRqcSampleDTO sampleDTO =new WmsInRqcSampleDTO();
			BeanUtils.copyProperties(rcvLine, sampleDTO);
			sampleDTO.setQcOddCaseQty(new BigDecimal(1));
			sampleDTO.setQcOddPieceQty(new BigDecimal(0));
			sampleDTO.setQcOddCaseActQty(new BigDecimal(1));
			sampleDTO.setQcOddPieceActQty(new BigDecimal(0));
			sampleDTO.setMtlOwnerCode(rcvLine.getMtlOwnerName());
			sampleDTO.setWarehouseCode(baseWmsWarehouseMst.getWarehouseCode());
			sampleDTO.setItemCode(omsAsnBillD.getItemcode());
			sampleDTO.setItemName(omsAsnBillD.getItemname());
			sampleDTO.setTaskRqcId(taskQcDetail.getTaskRqcId());
			sampleDTO.setSpecification(rcvLinesProfiles.getSpecification());
			sampleDTO.setManufacturerName(rcvLinesProfiles.getManufacturerName());
			sampleDTO.setItemHealthRegisterNbr(rcvLinesProfiles.getItemHealthRegisterNbr());
			sampleDTO.setItemHealthListedLicensor(rcvLinesProfiles.getItemHealthListedLicensor());
			sampleDTO.setAllowDecimal(rcvLinesProfiles.getAllowDecimal());
			rqcSampleDTOList.add(sampleDTO);
		}

		return rqcSampleDTOList;
	}

	private List<RcvLinesDTO> createRcvLinesDTOList(OmsAsnBillH asnBillH, List<OmsAsnBillD> omsBillDList) {
		List<RcvLinesDTO> rcvLinesDTOS =new ArrayList<>();
		Set<String> itemSet = omsBillDList.stream().map(OmsAsnBillD::getItemid).collect(Collectors.toSet());
		RestMessage<List<BaseMtlItemMst>> itemResult = baseItemRemoteCaller.getListByIds(itemSet);
		Assert.isFalse(itemResult == null, "商品信息不存在,请检查");
		if (!itemResult.isSuccess()) {
			throw BizException.newInstance("商品信息" + itemResult.getMessage());
		}
		List<BaseMtlItemMst> itemDetailList = itemResult.getData();
		int i=0;
		for(OmsAsnBillD asnBillD:omsBillDList ){
			i++;
			//查询空闲的容器
			Page<BaseWmsWhContainer> containerPage = commonRemoteService.getContainerPage(null, null, asnBillH.getBranchid(), 1000, 1);
			List<BaseWmsWhContainer> list = containerPage.getList();
			List<BaseWmsWhContainer> containerList = list.stream().filter(x-> x.getContainerStatus().equals("10")).collect(Collectors.toList());
			if(ToolKits.isEmpty(containerList)){
				throw new BizException("容器信息查询失败");
			}
			if(containerList.size() < omsBillDList.size()){
				throw new BizException("空闲容器数量不足");
			}
			//查询商品信息
			BaseMtlItemMst itemMst = itemDetailList.stream().filter(x -> x.getItemId().equals(asnBillD.getItemid())).findFirst().orElse(null);
			BaseMtlItemWms baseMtlItemWms = itemMst.getBaseMtlItemWms();
			BaseMtlItemHealth baseMtlItemHealth = itemMst.getBaseMtlItemHealth();
			//查询字典信息
			RestMessage<List<BaseCommonDict>> replenishSlidMsg = commonCaller.getDictBasicListByCodes("replenish_qy", null);
			BaseCommonDict dict = replenishSlidMsg.getData().stream().filter(var -> var.getDictCode().equals(baseMtlItemHealth.getItemHealthCategory())).findFirst().orElse(null);

			RcvLinesDTO rcvLinesDTO = new RcvLinesDTO();
			rcvLinesDTO.setPieceConversionRate(itemMst.getPieceConversionRate());
			rcvLinesDTO.setPieceQty(asnBillD.getItemQty());
			rcvLinesDTO.setItemZjm(itemMst.getItemAssistantCode());
			String isCaseOrPiece = ToolKits.isNotEmpty(baseMtlItemWms.getIsCaseOrPiece().toString()) ? baseMtlItemWms.getIsCaseOrPiece().toString() : "1";
			rcvLinesDTO.setIsCaseOrPiece(isCaseOrPiece);
			rcvLinesDTO.setItemName(asnBillD.getItemname());
			String uom = ToolKits.isNotEmpty(itemMst.getCaseUom()) ? itemMst.getCaseUom() : "盒";
			rcvLinesDTO.setUom(uom);
			rcvLinesDTO.setIsBacteria(baseMtlItemHealth.getIsBacteria());
			rcvLinesDTO.setRcvType(asnBillH.getBilltype());
			rcvLinesDTO.setIsInstrument(baseMtlItemHealth.getIsInstrument());
			rcvLinesDTO.setItemId(asnBillD.getItemid());
			rcvLinesDTO.setWarehouseId(asnBillH.getBranchid());
			rcvLinesDTO.setShelfLifeDays(baseMtlItemWms.getShelfLifeDays());
			rcvLinesDTO.setIsDelegate(baseMtlItemHealth.getIsDelegate());
			rcvLinesDTO.setAsnHeaderId(asnBillD.getBillid());
			rcvLinesDTO.setItemNum(asnBillD.getItemcode());
			rcvLinesDTO.setAsnLineId(asnBillD.getLineid());
			String shelfLifeUnit = ToolKits.isNotEmpty(baseMtlItemWms.getShelfLifeUnit()) ? itemMst.getCaseUom() : "日";
			rcvLinesDTO.setShelfLifeUnit(shelfLifeUnit);
			rcvLinesDTO.setMtlOwnerId(asnBillH.getConsignorid());
			rcvLinesDTO.setManufacturerId(itemMst.getManufacturerId());
			rcvLinesDTO.setOddPieceQty(asnBillD.getItemOdd());
			rcvLinesDTO.setItemIsRecheck(baseMtlItemWms.getItemIsRecheck());
			rcvLinesDTO.setManufacturerName(itemMst.getManufacturerId());
			rcvLinesDTO.setShowProductionDate(asnBillD.getPdateFrom());
			rcvLinesDTO.setItemHealthType(baseMtlItemHealth.getItemHealthType());
			rcvLinesDTO.setManufacturerLotNum(asnBillD.getLotNo());
			rcvLinesDTO.setManufacturerCode(itemMst.getManufacturerId());
			rcvLinesDTO.setIsRetrospect(0);
			rcvLinesDTO.setFreeQty(new BigDecimal(0));
			String productionPlace =ToolKits.isNotEmpty(asnBillD.getProductionPlace())? asnBillD.getProductionPlace() : itemMst.getCountryOriginId();
			rcvLinesDTO.setProductionPlace(productionPlace);
			rcvLinesDTO.setItemIsSpecial(baseMtlItemWms.getItemIsSpecial());
			rcvLinesDTO.setItemHealthIsDouble(baseMtlItemHealth.getItemHealthIsDouble());
			if(ToolKits.isNotEmpty(dict)){
				rcvLinesDTO.setCategoryName(dict.getDictName());
			}
			//查询仓库信息
			BaseWmsWarehouseMst baseWmsWarehouseMst = getWarehouse(asnBillD.getBranchid());
			if(baseWmsWarehouseMst!=null){
				rcvLinesDTO.setWarehouseCode(baseWmsWarehouseMst.getWarehouseCode());
			}
			rcvLinesDTO.setIsLock(baseMtlItemWms.getIsLock());
			rcvLinesDTO.setShowExpiredDate(asnBillD.getValidUntil());
			rcvLinesDTO.setOddPieceQty(asnBillD.getItemPcs());
			rcvLinesDTO.setIsHosted(baseMtlItemWms.getIsHosted());
			rcvLinesDTO.setItemIsImported(baseMtlItemWms.getItemIsImported());
			rcvLinesDTO.setSpecification(itemMst.getSpecification());
			rcvLinesDTO.setApprovalNumber(baseMtlItemHealth.getItemHealthApprovalNbr());
			rcvLinesDTO.setConversionRate(itemMst.getCaseConversionRate());
			BigDecimal piecePriceTi = ToolKits.isNotEmpty(asnBillD.getPrice())? asnBillD.getPrice() : new BigDecimal(1);
			rcvLinesDTO.setPiecePriceTi(piecePriceTi);
			BigDecimal piecePriceTe = ToolKits.isNotEmpty(asnBillD.getTniAmt())? asnBillD.getTniAmt() : new BigDecimal(1);
			rcvLinesDTO.setPiecePriceTe(piecePriceTe);
			if(!StringUtils.isEmpty(asnBillD.getValidUntil())){
				Date parseDate = com.prolog.framework.utils.DateUtils.parse(asnBillD.getPdateFrom(), "yyyy-MM-dd hh:mm:ss");
				rcvLinesDTO.setBatchExpiredDate(parseDate);
			}
			rcvLinesDTO.setInStoreDay(baseMtlItemWms.getInStoreDay());
			rcvLinesDTO.setCategoryId(baseMtlItemHealth.getItemHealthCategory());
			if(!StringUtils.isEmpty(asnBillD.getPdateFrom())){
				Date parseDate = com.prolog.framework.utils.DateUtils.parse(asnBillD.getPdateFrom(), "yyyy-MM-dd hh:mm:ss");
				rcvLinesDTO.setBatchProductionDate(parseDate);
			}
			rcvLinesDTO.setStockStatus("0");
			rcvLinesDTO.setQty(asnBillD.getItemQty());
			rcvLinesDTO.setLocNo("");//todo 页面上输入的数据拼箱号
			rcvLinesDTO.setContainerCode(containerList.get(i).getContainerCode());
			rcvLinesDTO.setWhAreaCategoryCode("ZTK");//库别，默认直通库别
			rcvLinesDTO.setComments("直通入库");
			rcvLinesDTO.setMtlOwnerName(baseWmsWarehouseMst.getWarehouseCode());
			rcvLinesDTO.setWarehouseName(baseWmsWarehouseMst.getWarehouseName());
			rcvLinesDTO.setEditFlag(0);//新增标识

			//组装收货单明细扩展表信息
			RcvLinesProfilesDTO rcvLinesProfilesDTO = new RcvLinesProfilesDTO();
			BeanUtil.copyProperties(rcvLinesDTO, rcvLinesProfilesDTO);
			rcvLinesProfilesDTO.setStoreTemperature(baseMtlItemWms.getStoreTemperature());
			rcvLinesDTO.setRcvLinesProfilesDTO(rcvLinesProfilesDTO);

			rcvLinesDTOS.add(rcvLinesDTO);
		}
		return rcvLinesDTOS;
	}

	private RcvHeadersDTO createHeadersDTO(OmsAsnBillH asnBillH,UserDTO userDTO) {
		//获取客户和供应商信息
		Set<String> supperCodes = new HashSet<>();
		Set<String> customCodes = new HashSet<>();
		List<BaseSupplierMst> supplierMstList = new ArrayList<>();
		List<BaseCustomerMst> customerMstList = new ArrayList<>();
		if(asnBillH.getShipperType().equals("1")){
			customCodes.add(asnBillH.getShippercode());
			RestMessage<List<BaseCustomerMst>> byCode = chainRemoteCaller.getByCustomerCode(customCodes);
			if(byCode.getData()!=null&&byCode.isSuccess()){
				customerMstList = byCode.getData();
				if(customerMstList.size()==0){
					throw new BizException("客户信息查询失败");
				}
			}else{
				throw new BizException("客户信息查询失败");
			}
		}else {
			supperCodes.add(asnBillH.getShippercode());
			RestMessage<List<BaseSupplierMst>> byCode = chainRemoteCaller.getBySupperCode(supperCodes);
			if(byCode.getData()!=null&&byCode.isSuccess()){
				supplierMstList = byCode.getData();
				if(supplierMstList.size()==0){
					throw new BizException("供应商信息查询失败");
				}
			}else{
				throw new BizException("供应商信息查询失败");
			}
		}
		RcvHeadersDTO rcvHeadersDTO =new RcvHeadersDTO();
		rcvHeadersDTO.setPieceQty(new BigDecimal(1));
		rcvHeadersDTO.setCaseQty(new BigDecimal(1));
		rcvHeadersDTO.setWarehouseId(asnBillH.getBranchid());
		rcvHeadersDTO.setVendorId(asnBillH.getShipperid());
		rcvHeadersDTO.setMtlOwnerId(asnBillH.getConsignorid());
		if(ToolKits.isNotEmpty(supplierMstList)){
			rcvHeadersDTO.setShipperZjm(supplierMstList.get(0).getSupplierKeywords());
		}
		if(ToolKits.isNotEmpty(customerMstList)){
			rcvHeadersDTO.setShipperZjm(customerMstList.get(0).getCustomerKeywords());
		}
		rcvHeadersDTO.setAsnHeaderId(asnBillH.getBillid());
		rcvHeadersDTO.setAutoBillNum("");//todo
		rcvHeadersDTO.setRcvType(asnBillH.getBilltype());
		rcvHeadersDTO.setNeedUser(asnBillH.getEnquirysalesman());
		rcvHeadersDTO.setDepartment(asnBillH.getEnquirydepartment());
		rcvHeadersDTO.setSrcAutoBillNum(asnBillH.getRefBillno());
		rcvHeadersDTO.setRcvDate(new Date());
		rcvHeadersDTO.setExecutorUser(userDTO.getUsername());
		rcvHeadersDTO.setStatus("1");

		return rcvHeadersDTO;
	}

	//请求仓库信息
	private BaseWmsWarehouseMst getWarehouse(String warehouseId){
		if(com.prolog.framework.utils.StringUtils.isBlank(warehouseId)){
			return null;
		}
		RestMessage<BaseWmsWarehouseMst> itemResultWarehouse = baseWmsWarehouseCaller.warehouse(warehouseId);
		if (itemResultWarehouse.isSuccess() && itemResultWarehouse.getData() != null) {
			return itemResultWarehouse.getData();
		}
		return null;
	}

	private void addWithRelatedAll(RqcDTO rqcDTO, boolean isPad, boolean isAdd) {
		AssertUtils.notNull(rqcDTO, "入参数据不可为空!");
		AssertUtils.notNull(rqcDTO.getRqcHeadersDTO(), "主表数据不可为空!");
		UserDTO userDTO = userUtils.getUserDTO();
		//极联保存关联数据
		RqcHeadersDTO rqcHeadersDTO = rqcDTO.getRqcHeadersDTO();
		Date autoTime = rqcDTO.getAutoTime() == null ? new Date() : rqcDTO.getAutoTime();
		//直调自动验收上架逻辑 极联保存关联数据
		List<RqcLinesDTO> rqcLinesDTOList = rqcDTO.getRqcLinesDTOList();

		long count = rqcLinesDTOList.stream().filter(x -> x.getRcvHeaderId().equals(rqcHeadersDTO.getRcvHeaderId())).count();
		if(count==0){
			throw new BizException("验收单主表与明细不一致，请检查！");
		}

		String masterId = rqcHeadersDTO.getRqcHeaderId();
		if (isAdd) {
			//保存rqcHeader数据，返回主表id
			masterId = (String) rqcHeadersService.add(rqcHeadersDTO);
			rqcHeadersDTO.setRqcHeaderId(masterId);
		}
		String asnHeaderId = "";
		if (ObjectUtils.isNotNull(rqcLinesDTOList)) {
			// 执行保存质检明细操作
			asnHeaderId = rqcLinesDTOList.get(0).getAsnHeaderId();
			rqcLinesService.batchAdd(rqcLinesDTOList, rqcHeadersDTO, userDTO, autoTime, isPad);
		}

		//TODO 调用接口平台推送订单状态记录数据到OMS
//		orderStatusBackService.sendInboundOrderStatusOms(asnHeaderId,rqcHeadersDTO.getRemark(),"",userDTO.getUsername(),"","120");
	}




}
