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

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.prolog.common.util.DateUtils;
import com.prolog.cs.basic.chain.model.CompanyScope;
import com.prolog.cs.basic.warehouse.model.vo.ContainerQueryVO;
import com.prolog.cs.biz.inbound.constant.BizConstant;
import com.prolog.cs.biz.inbound.dao.rcv.RcvLinesMapper;
import com.prolog.cs.biz.inbound.dto.CargoChangeIn;
import com.prolog.cs.biz.inbound.dto.RcvCommonLine;
import com.prolog.cs.biz.inbound.dto.rcv.RcvHeadersDTO;
import com.prolog.cs.biz.inbound.dto.rcv.RcvLinesDTO;
import com.prolog.cs.biz.inbound.dto.rcv.RcvLinesProfilesDTO;
import com.prolog.cs.biz.inbound.model.rcv.RcvLines;
import com.prolog.cs.biz.inbound.remote.BaseInventoryRemoteCaller;
import com.prolog.cs.biz.inbound.remote.BaseItemRemoteCaller;
import com.prolog.cs.biz.inbound.remote.BaseWmsWarehouseCaller;
import com.prolog.cs.biz.inbound.remote.ChainRemoteCaller;
import com.prolog.cs.biz.inbound.service.impl.processor.Helper.TaskHelper;
import com.prolog.cs.biz.inbound.service.rcv.RcvLinesService;
import com.prolog.framework.authority.core.dto.UserDTO;
import com.prolog.framework.bz.common.search.SearchApi;
import com.prolog.framework.bz.common.search.SearchException;
import com.prolog.framework.bz.core.collection.ValidList;
import com.prolog.framework.bz.core.util.ObjectUtils;
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.utils.*;
import com.prolog.upcloud.base.inventory.vo.InvStockBatchNumber;
import com.prolog.upcloud.base.inventory.vo.InvStockBatchNumberResult;
import com.prolog.upcloud.base.inventory.vo.InvStockBatchNumberUpdate;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;

/**
 * 不同收货类型的处理
 *
 * @author Xiong
 */
@Service
public class RcvTypeService {

    @Resource
    private RcvLinesService rcvLinesService;

    @Resource
    private ChainRemoteCaller chainRemoteCaller;

    @Resource
    private SearchApi searchApi;

    @Value("${prolog.wms.enableVaildateBatchInfo2Web:false}")
    private boolean enableVaildateBatchInfo2Web;

    @Value("${prolog.wms.enableErrorGenBatchInfo:true}")
    private boolean enableErrorGenBatchInfo;

    @Value("${prolog.wms.enableSaleReturnGenBatchInfo:false}")
    private boolean enableSaleReturnGenBatchInfo;

    @Value("${prolog.wms.enableVaildateConclusion:true}")
    private boolean enableVaildateConclusion;

    @Resource
    private RcvLinesMapper mapper;

    private static Logger logger = LoggerFactory.getLogger(RcvTypeService.class);

    @Resource
    private BaseInventoryRemoteCaller baseInventoryRemoteCaller;

    @Resource
    private BaseItemRemoteCaller baseItemRemoteCaller;

    @Resource
    private BaseWmsWarehouseCaller baseWmsWarehouseCaller;

    @Resource
    private TaskHelper taskHelper;

    /**
     * 处理收货行(可根据不同的收货类型先做些前置处理)
     *
     * @param rcvHeadersDTO
     * @param rcvLinesDTOList
     * @param userDTO
     * @param cargoChangeIn
     * @return
     */
    public Object excuteRcvLine(RcvHeadersDTO rcvHeadersDTO, List<RcvLinesDTO> rcvLinesDTOList, UserDTO userDTO,
                                CargoChangeIn cargoChangeIn,boolean ztFlag) {
        String rcvType = rcvHeadersDTO.getRcvType();
        List<RcvCommonLine> clList = new ArrayList<>();
        Date now = new Date();
        excuteHandlerLotNum(rcvType, rcvLinesDTOList, now, userDTO, clList);

        String warehouseId = rcvHeadersDTO.getWarehouseId();
        String mtlOwnerId = rcvHeadersDTO.getMtlOwnerId();
        // 查询业务参数是否校验结论
        String businessControlValue = taskHelper.getBusinessControlValue(warehouseId, mtlOwnerId, "0",
                BizConstant.ENABLE_VAILDATE_CONCLUSION);

        if (enableVaildateConclusion && businessControlValue.equals("1")) {
            vaildateConclusion(clList, rcvLinesDTOList);
        }

        Object info = excuteHandlerBatchInfo(rcvHeadersDTO, rcvType, rcvLinesDTOList, now);
        Object batchAdd = rcvLinesService.batchAdd(rcvLinesDTOList, rcvHeadersDTO, userDTO, cargoChangeIn, ztFlag);
        if (!ObjectUtils.isNull(info)) {
            return info;
        } else {
            return batchAdd;
        }
    }

    public Object rfExcuteRcvLine(RcvHeadersDTO rcvHeadersDTO, List<RcvLinesDTO> rcvLinesDTOList, UserDTO userDTO,
                                  CargoChangeIn cargoChangeIn) {
        String rcvType = rcvHeadersDTO.getRcvType();
        List<RcvCommonLine> clList = new ArrayList<>();

        Date now = new Date();
        excuteHandlerLotNum(rcvType, rcvLinesDTOList, now, userDTO, clList);

        String warehouseId = rcvHeadersDTO.getWarehouseId();
        String mtlOwnerId = rcvHeadersDTO.getMtlOwnerId();
        // 查询业务参数是否校验结论
        String businessControlValue = taskHelper.getBusinessControlValue(warehouseId, mtlOwnerId, "0",
                BizConstant.ENABLE_VAILDATE_CONCLUSION);

        if (enableVaildateConclusion && businessControlValue.equals("1")) {
            vaildateConclusion(clList, rcvLinesDTOList);
        }

        Object info = excuteHandlerBatchInfo(rcvHeadersDTO, rcvType, rcvLinesDTOList, now);
        boolean ztFlag =false;
        Object batchAdd = rcvLinesService.batchAdd(rcvLinesDTOList, rcvHeadersDTO, userDTO, cargoChangeIn,ztFlag);
        if (!ObjectUtils.isNull(info)) {
            return info;
        } else {
            return batchAdd;
        }
    }


    private void vaildateConclusion(List<RcvCommonLine> clList, List<RcvLinesDTO> rcvLinesDTOList) {
        // 校验结论
        List<RcvCommonLine> conclusion = rcvLinesService.getConclusion(clList);
        if (ObjectUtils.isEmpty(conclusion)) {
            return;
        }
        Map<String, List<RcvCommonLine>> collect = conclusion.stream()
                .collect(Collectors.groupingBy(RcvCommonLine::getRefId));
        int row = 0;
        for (RcvLinesDTO rcvLinesDTO : rcvLinesDTOList) {
            row++;
            String rcvLineId = rcvLinesDTO.getRcvLineId();
            List<RcvCommonLine> list = collect.get(rcvLineId);
            if (ObjectUtils.isEmpty(list)) {
                continue;
            }
            RcvCommonLine rcvCommonLine = list.get(0);
            String stockStatus = rcvLinesDTO.getStockStatus();
            List<Map<String, String>> conclusionList = rcvCommonLine.getConclusionList();
            if (!ObjectUtils.isEmpty(conclusionList)) {
                List<String> conclusionCodes = new ArrayList<>();
                for (Map<String, String> map : conclusionList) {
                    String string = map.get("code");
                    conclusionCodes.add(string);
                }
                if (!conclusionCodes.contains(stockStatus)) {
                    throw new BizException(String.format("第[%d]行,结论选择有误!请重新选择!", row));
                }
            }
        }
    }

    /**
     * 处理批号,以及校验数据
     *
     * @param rcvType
     * @param rcvLinesDTOList
     * @param now
     * @param userDTO
     * @param clList
     */
    @SuppressWarnings("unchecked")
    private void excuteHandlerLotNum(String rcvType, List<RcvLinesDTO> rcvLinesDTOList, Date now, UserDTO userDTO,
                                     List<RcvCommonLine> clList) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        int row = 0;
        String enterpriseId = userDTO.getEnterpriseId();
        Set<String> zjContainerCode = new HashSet<>();
        Set<String> sjContainerCode = new HashSet<>();

        Map iqueryMap = new HashMap<>();
        List<Map> iqList = new ArrayList<>();
        Map<String, String> cc = new HashMap<>();

        RcvLinesDTO rcvLinesDTO2 = rcvLinesDTOList.get(0);
        String warehouseId = rcvLinesDTO2.getWarehouseId();
        String mtlOwnerId = rcvLinesDTO2.getMtlOwnerId();
        // 0否1是
        String businessControlValue = taskHelper.getBusinessControlValue(warehouseId, mtlOwnerId, "1",
                BizConstant.ENABLE_VAILDATE_CONTAINER);

        for (RcvLinesDTO rcvLinesDTO : rcvLinesDTOList) {
            row++;

            String containerCode = rcvLinesDTO.getContainerCode();

            Integer lineNum = rcvLinesDTO.getLineNum();
            if (lineNum == null) {
                rcvLinesDTO.setLineNum(row);
            }
            String inventoryOpType = rcvLinesDTO.getInventoryOpType();
            if (!StringUtils.isBlank(inventoryOpType)) {
                rcvLinesDTO.setEditFlag(2);
            }

            String stockStatus = rcvLinesDTO.getStockStatus();
            if (BizConstant.REJECT.equals(stockStatus)) {
                String lotNum = rcvLinesDTO.getManufacturerLotNum();
                String showProduction = rcvLinesDTO.getShowProductionDate();
                String showExpired = rcvLinesDTO.getShowExpiredDate();
                String batchId = rcvLinesDTO.getBatchId();
                if (StringUtils.isBlank(rcvLinesDTO.getBatchNum())) {
                    rcvLinesDTO.setBatchNum("");
                }
                if (StringUtils.isBlank(batchId)) {
                    rcvLinesDTO.setBatchId(rcvLinesDTO.getBatchNum());
                }
                if (StringUtils.isBlank(lotNum) || StringUtils.isBlank(showProduction)
                        || StringUtils.isBlank(showExpired)) {
                    continue;
                }
            }else{
                if(StringUtils.isEmpty(containerCode)){
                    throw new BizException("入库容器号不能为空");
                }
                //校验容器号是否可用
                ContainerQueryVO queryVO = new ContainerQueryVO();
                queryVO.setWarehouseId(warehouseId);
                queryVO.setEnterpriseId(userDTO.getEnterpriseId());
                List<String> codeList = new ArrayList<>();
                codeList.add(rcvLinesDTO.getContainerCode());
                queryVO.setContainerCodeList(codeList);
                RestMessage<Object> containerCodeMsg = baseWmsWarehouseCaller.batchVaildateEnable(queryVO);
                if(containerCodeMsg.getData()==null||!containerCodeMsg.isSuccess()){
                    throw new BizException("请检查容器号是否可用");
                }
                if(!(Boolean) containerCodeMsg.getData()){
                    throw new BizException("请检查容器号是否可用");
                }
            }

            String showExpiredDate2 = rcvLinesDTO.getShowExpiredDate();
            String showProductionDate2 = rcvLinesDTO.getShowProductionDate();
            if (StringUtils.isBlank(showProductionDate2)) {
                rcvLinesDTO.setShowProductionDate("*");
            }
            if (StringUtils.isBlank(showExpiredDate2)) {
                rcvLinesDTO.setShowExpiredDate("*");
            }
            // 校验日期格式
            String showExpiredDate = rcvLinesDTO.getShowExpiredDate();
            String showProductionDate = rcvLinesDTO.getShowProductionDate();
            if (StringUtils.isBlank(showExpiredDate) || StringUtils.isBlank(showProductionDate)) {
                throw new BizException(String.format("第[%d]行,显示生产日期或显示有效期至为空!请检查!", row));
            }

            // 数据准确性计算
            BigDecimal pieceQty = rcvLinesDTO.getPieceQty();
            BigDecimal conversionRate = rcvLinesDTO.getConversionRate();
            if (conversionRate == null) {
                conversionRate = BigDecimal.ONE;
                rcvLinesDTO.setConversionRate(conversionRate);
            }
            if (pieceQty == null) {
                pieceQty = BigDecimal.ZERO;
                rcvLinesDTO.setPieceQty(pieceQty);
            }
            BigDecimal caseQty = pieceQty.divide(conversionRate, 0, RoundingMode.DOWN); // 整件
            BigDecimal multiply = caseQty.multiply(conversionRate);
            BigDecimal oddPieceQty = pieceQty.subtract(multiply); // 零散
            BigDecimal qty = pieceQty.divide(conversionRate, 4, RoundingMode.DOWN); // 包装总量
            // 保证数据正确性再次进行计算
            rcvLinesDTO.setOddCaseQty(caseQty);
            rcvLinesDTO.setOddPieceQty(oddPieceQty);
            rcvLinesDTO.setQty(qty);
            // 普通采购入库处理
            // 批号判断 为*或空增加当前时间100年
            if (StringUtils.isEmpty(rcvLinesDTO.getManufacturerLotNum())||rcvLinesDTO.getManufacturerLotNum().equals("*")) {
                rcvLinesDTO.setManufacturerLotNum("*");
                Date batchExpiredDate = rcvLinesDTO.getBatchExpiredDate();
                Date batchProductionDate = rcvLinesDTO.getBatchProductionDate();
                if (null == batchExpiredDate || null == batchProductionDate) {
                    // 日期归零
                    Date date = now;
                    date.setHours(0);
                    date.setMinutes(0);
                    date.setSeconds(0);
                    Date parse = null;
                    try {
                        parse = dateFormat.parse("2099-01-01");
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    rcvLinesDTO.setBatchProductionDate(date);
                    rcvLinesDTO.setBatchExpiredDate(parse);
                }
            }
//			}

            // 显示生产日期,有效期至为*号的处理
            Date date = now;
            if ("*".equals(showProductionDate)) {
                date.setHours(0);
                date.setMinutes(0);
                date.setSeconds(0);
                rcvLinesDTO.setBatchProductionDate(date);
            }
            if ("*".equals(showExpiredDate)) {
                Date parse = null;
                try {
                    parse = dateFormat.parse("2099-01-01");
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                if (parse == null) {
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(date);// 设置起时间
                    cal.add(Calendar.YEAR, 100);// 增加100年
                    parse = cal.getTime();
                }
                rcvLinesDTO.setBatchExpiredDate(parse);
            }

            // 生产日期,效期,时分秒归零
            Date batchExpiredDate = rcvLinesDTO.getBatchExpiredDate();
            Date batchProductionDate = rcvLinesDTO.getBatchProductionDate();
            if (batchExpiredDate == null || batchProductionDate == null) {
                throw new BizException(String.format("第[%d]行,日期格式的生产日期或有效期至为空!请检查!", row));
            }

            batchExpiredDate.setHours(0);
            batchExpiredDate.setMinutes(0);
            batchExpiredDate.setSeconds(0);
            rcvLinesDTO.setBatchExpiredDate(batchExpiredDate);
            batchProductionDate.setHours(0);
            batchProductionDate.setMinutes(0);
            batchProductionDate.setSeconds(0);
            rcvLinesDTO.setBatchProductionDate(batchProductionDate);

            String batchId = rcvLinesDTO.getBatchId();
            if (StringUtils.isBlank(batchId)) {
                rcvLinesDTO.setBatchId(rcvLinesDTO.getBatchNum());
            }

            rcvLinesDTO.setRcvLineId(String.valueOf(SnowFlakeUtils.getId()));

            //if (!StringUtils.isBlank(businessControlValue) && businessControlValue.equals("1")) {
                String whAreaCategoryCode = rcvLinesDTO.getWhAreaCategoryCode();
                String itemId = rcvLinesDTO.getItemId();
                String itemName = rcvLinesDTO.getItemName();
                String manufacturerLotNum = rcvLinesDTO.getManufacturerLotNum();
                String productionDateStr = "";
                if(rcvLinesDTO.getBatchProductionDate()!=null){
                    productionDateStr = DateUtils.format(rcvLinesDTO.getBatchProductionDate(),"yyyy-MM-dd");
                }
                String expiredDateStr = "";
                if(rcvLinesDTO.getBatchExpiredDate()!=null){
                    expiredDateStr = DateUtils.format(rcvLinesDTO.getBatchExpiredDate(),"yyyy-MM-dd");
                }
//                if (!StringUtils.isBlank(whAreaCategoryCode) && BizConstant.AGVK.equals(whAreaCategoryCode)) {
                if (!StringUtils.isBlank(whAreaCategoryCode) && ("AGVZ".equals(whAreaCategoryCode) ||"MJK".equals(whAreaCategoryCode) ||"ZJK".equals(whAreaCategoryCode)) ) {
                        // 校验是否在同一容器,商品id+商品批号
                    if (!StringUtils.isBlank(containerCode) && !"N/A".equals(containerCode)) {
                        String itemLot = cc.get(containerCode);
                        if (StringUtils.isBlank(itemLot)) {
                            cc.put(containerCode, itemId + manufacturerLotNum + productionDateStr + expiredDateStr);
                        } else {
                            if (!itemLot.equals(itemId + manufacturerLotNum + productionDateStr + expiredDateStr)) {
                                throw new BizException(String.format("AGV库不同品批不可选同容器,容器[%s],商品[%s],批号[%s]",
                                        containerCode, itemName, manufacturerLotNum));
                            }
                        }
                    }
                }else{
                    Map<String,String> dd = new HashMap<>();
                    BigDecimal oddCaseQty = rcvLinesDTO.getOddCaseQty();
                    BigDecimal oddPieceQty1 = rcvLinesDTO.getOddPieceQty();
                    if(oddCaseQty.compareTo(BigDecimal.ZERO)>0&&oddPieceQty1.compareTo(BigDecimal.ZERO)==0){
                        String itemLot = dd.get(containerCode);
                        if (StringUtils.isBlank(itemLot)) {
                            dd.put(containerCode, manufacturerLotNum + productionDateStr + expiredDateStr);
                        } else {
                            if (!itemLot.equals(manufacturerLotNum + productionDateStr + expiredDateStr)) {
                                throw new BizException(String.format("同容器整件收货可混品不可混批,容器[%s],商品[%s],批号[%s]",
                                        containerCode, itemName, manufacturerLotNum));
                            }
                        }
                    }
                }
            //}

            Long subtract = null;
            if (!ObjectUtils.isNull(batchExpiredDate)) {
                subtract = DateUtils.subtract(now, batchExpiredDate, ChronoUnit.DAYS);
            }
//            if (subtract != null && subtract <= 0 && (rcvType.equals(BizConstant.SALE_RETURN_IN)
//                    || rcvType.equals(BizConstant.ALLOT_IN) || rcvType.equals(BizConstant.MOVE_IN))) {
//                // 销退/调拨/移库过期处理
//                // 过期了,入不合格库
//                // 无需双人质检,直接推荐
//                rcvLinesDTO.setWhAreaCategoryCode(BizConstant.THK);
//                // 库存状态为不合格
//                rcvLinesDTO.setStockStatus("1"); // 结论不合格
//            }

            vaildateLotInfo(rcvLinesDTO, row);

            Map qmap = new HashMap<>();
            qmap.put("itemId", rcvLinesDTO.getItemId());
            qmap.put("itemCategoryCode", rcvLinesDTO.getCategoryId());
            qmap.put("refId", row);
            qmap.put("flag", false);
            qmap.put("message", "");
            iqList.add(qmap);

            RcvCommonLine rcl = convert2RcvCommonLine(rcvType, rcvLinesDTO);
            clList.add(rcl);
        }
        // 商品同容器校验 重复的校验还有商品未复核完成方法,预留多余
        vaildateItemContainerSame(rcvLinesDTOList);

        RestMessage<List<CompanyScope>> companyScopeResult = chainRemoteCaller.findByCompanyId(warehouseId);// 暂时未独立经营范围接口
        if (companyScopeResult.isSuccess() && companyScopeResult.getData() != null) {
            List<String> list1 = iqList.stream().map(t -> t.get("itemCategoryCode").toString())
                    .collect(Collectors.toList());
            List<String> list2 = companyScopeResult.getData().stream().filter(t -> "2".equals(t.getContype()))
                    .map(t -> t.getScopeCode()).collect(Collectors.toList());
            if (list2 != null && list2.size() > 0 && !list2.containsAll(list1)) {
                logger.error("商品大类不在仓库经营范围内,list1=" + JSON.toJSONString(list1) + ",list2=" + JSON.toJSONString(list1));
                throw new BizException("商品大类不在仓库经营范围内");
            }
        }

        iqueryMap.put("queryMap", iqList);
        iqueryMap.put("type", "in");
        iqueryMap.put("cargoOwnerId", rcvLinesDTOList.get(0).getMtlOwnerId());
        //暂时注释，查询货主信息失败
//        excuteVaildteItem(iqueryMap, rcvLinesDTOList, userDTO, now);
    }

    private RcvCommonLine convert2RcvCommonLine(String rcvType, RcvLinesDTO rcvLinesDTO) {
        // 收货行转换为结论校验行
        RcvCommonLine rcl = new RcvCommonLine();
        rcl.setBatchExpiredDate(rcvLinesDTO.getBatchExpiredDate());
        rcl.setMtlOwnerId(rcvLinesDTO.getMtlOwnerId());
        rcl.setWarehouseId(rcvLinesDTO.getWarehouseId());
        rcl.setRcvType(rcvType);
        rcl.setRefId(rcvLinesDTO.getRcvLineId());
        rcl.setRefType(3); // 来源asn
        return rcl;
    }

    private void vaildateItemContainerSame(List<RcvLinesDTO> rcvLinesDTOList) {
        // 商品大类
        Map<String, String> categoryIdMap = new HashMap<>();
        // 收货结论
        Map<String, String> stockStatusMap = new HashMap<>();
        // 存储分类
        Map<String, String> itemHealthStoreCategoryMap = new HashMap<>();
        // 库别
        Map<String, String> whAreaCategoryCodeMap = new HashMap<>();

        // 存储条件
        Map<String, String> itemStoreTempMap = new HashMap<>();

        Set<String> zjContainerCode = new HashSet<>();
        Set<String> sjContainerCode = new HashSet<>();
        for (RcvLinesDTO dto : rcvLinesDTOList) {
            String storeTemperature = "";
            RcvLinesProfilesDTO rcvLinesProfilesDTO = dto.getRcvLinesProfilesDTO();
            if (rcvLinesProfilesDTO != null) {
                storeTemperature = rcvLinesProfilesDTO.getStoreTemperature();
            }
            String containerCode = dto.getContainerCode();
            String categoryId = dto.getCategoryId();
            String stockStatus = dto.getStockStatus();
            String itemHealthStoreCategory = dto.getItemHealthStoreCategory();
            String whAreaCategoryCode = dto.getWhAreaCategoryCode();
            BigDecimal caseQty = dto.getOddCaseQty();
            BigDecimal oddPieceQty = dto.getOddPieceQty();
            if (!StringUtils.isBlank(containerCode) && !"N/A".equals(containerCode)) {
                String itemLot1 = categoryIdMap.get(containerCode);
                String itemLot2 = stockStatusMap.get(containerCode);
                String itemLot4 = itemHealthStoreCategoryMap.get(containerCode);
                String itemLot5 = whAreaCategoryCodeMap.get(containerCode);
                String itemLot6 = itemStoreTempMap.get(containerCode);
				if (StringUtils.isBlank(itemLot1)) {
					categoryIdMap.put(containerCode, categoryId);
				} else {
					if (!itemLot1.equals(categoryId)) {
						throw new BizException(
								String.format("商品大类不同不可选同容器,容器[%s],商品[%s]", containerCode, dto.getItemName()));
					}
				}
//				if (StringUtils.isBlank(itemLot2)) {
//					stockStatusMap.put(containerCode, stockStatus);
//				} else {
//					if (!itemLot2.equals(stockStatus)) {
//						throw new BizException(
//								String.format("收货结论不同不可选同容器,容器[%s],商品[%s]", containerCode, dto.getItemName()));
//					}
//				}
				if (StringUtils.isBlank(itemLot4)) {
					itemHealthStoreCategoryMap.put(containerCode, itemHealthStoreCategory);
				} else {
					if (!itemLot4.equals(itemHealthStoreCategory)) {
						throw new BizException(
								String.format("存储分类不同不可选同容器,容器[%s],商品[%s]", containerCode, dto.getItemName()));
					}
				}
//				
                if (!StringUtils.isBlank(whAreaCategoryCode)) {
                    if (StringUtils.isBlank(itemLot5)) {
                        whAreaCategoryCodeMap.put(containerCode, whAreaCategoryCode);
                    } else {
                        if (!itemLot5.equals(whAreaCategoryCode)) {
                            throw new BizException(
                                    String.format("库别不同不可选同容器,容器[%s],商品[%s]", containerCode, dto.getItemName()));
                        }
                    }
                }

				// 存储温度
				if (!StringUtils.isBlank(storeTemperature)) {
					if (StringUtils.isBlank(itemLot6)) {
						itemStoreTempMap.put(containerCode, storeTemperature);
					} else {
						if (!itemLot6.equals(storeTemperature)) {
							throw new BizException(
									String.format("存储条件不同不可选同容器,容器[%s],商品[%s]", containerCode, dto.getItemName()));
						}
					}
				}

                // 校验整件零散不能同容器
                if (BigDecimal.ZERO.compareTo(caseQty) == 0) {
                    // 散件
                    zjContainerCode.add(containerCode);
                } else if (BigDecimal.ZERO.compareTo(caseQty) == -1 && BigDecimal.ZERO.compareTo(oddPieceQty) == 0) {
                    // 整件
                    sjContainerCode.add(containerCode);
                }
            }
        }
        if (!ObjectUtils.isNull(zjContainerCode) && !ObjectUtils.isNull(sjContainerCode)) {
            Collection intersection = CollectionUtils.intersection(zjContainerCode, sjContainerCode);
            if (!ObjectUtils.isNull(intersection)) {
                throw new BizException("整件散件容器不可选一样的!" + intersection.toString());
            }
        }
    }

    private void excuteVaildteItem(Map iqueryMap, List<RcvLinesDTO> rcvLinesDTOList, UserDTO userDTO, Date now) {
        RcvLinesDTO rcvLinesDTO = rcvLinesDTOList.get(0);
        String mtlOwnerId = rcvLinesDTO.getMtlOwnerId();
        Map<String, Object> queryMap = new HashMap<>();
        queryMap.put("cargoOwnerId", mtlOwnerId);
        List<Map> searchForMap = null;
        try {
            searchForMap = searchApi.searchForMap("getCargoOwnerProp", queryMap);
        } catch (Exception e) {
            logger.info("获取货主属性失败,原因{}", e);
        }
        if (!ObjectUtils.isNull(searchForMap)) {
            Map map = searchForMap.get(0);
            String flag1 = (String) map.get("vaildateItemLicense");
            String flag2 = (String) map.get("vaildateItemVol");
            String flag3 = (String) map.get("vaildateItemCategory");
            String flag4 = (String) map.get("vaildateItemInbound");
            String flag5 = (String) map.get("vaildateCargoOwnerScop");
            String flag6 = (String) map.get("vaildateContainer");
            String flag7 = (String) map.get("vaildateLotNum");
            // 校验商品证照
            vaildateItemLicense(flag1, iqueryMap, rcvLinesDTOList, userDTO, now);
            // 校验商品体积信息
            vaildateItemVol(flag2, iqueryMap, rcvLinesDTOList, userDTO, now);
            // 校验商品大类是否维护
            vaildateItemCategory(flag3, iqueryMap, rcvLinesDTOList, userDTO, now);
            // 校验商品是否停售召回
            vaildateItemInbound(flag4, iqueryMap, rcvLinesDTOList, userDTO, now);
            // 校验货主-商品大类关系(即货主的经营范围)
            vaildateCargoOwnerScop(flag5, iqueryMap, rcvLinesDTOList, userDTO, now);
            // 校验入库商品绑定容器是否正确
            vaildateItemContainer(flag6, iqueryMap, rcvLinesDTOList, userDTO, now);
            // 校验入库商品批号效期(全部的货主批号)
            vaildateLotNum(flag7, iqueryMap, rcvLinesDTOList, userDTO, now);
        }
    }

    private void vaildateLotNum(String flag7, Map iqueryMap, List<RcvLinesDTO> rcvLinesDTOList, UserDTO userDTO,
                                Date now) {
        if (!StringUtils.isBlank(flag7) && "1".equals(flag7)) {
            Set<String> itemIds = new HashSet<>();
            Set<String> manufacturerLotNums = new HashSet<>();
            for (RcvLinesDTO rcvLinesDTO : rcvLinesDTOList) {
                String itemId = rcvLinesDTO.getItemId();
                String manufacturerLotNum = rcvLinesDTO.getManufacturerLotNum();
                itemIds.add(itemId);
                manufacturerLotNums.add(manufacturerLotNum);
            }
            Map<String, Object> queryMap = new HashMap<>();
            queryMap.put("itemIds", itemIds);
            queryMap.put("manufacturerLotNums", manufacturerLotNums);
            List<Map> searchForMap = null;
            try {
                searchForMap = searchApi.searchForMap("getBatchInfo", queryMap);
            } catch (Exception e) {
                logger.info("获取批次批号集合失败,原因{}", e);
            }
            if (!ObjectUtils.isNull(searchForMap)) {
                Map<String, List<Map>> collect = searchForMap.stream()
                        .collect(Collectors.groupingBy(p -> fetchGroup(p)));
                for (List<Map> mapList : collect.values()) {
                    Map<String, Integer> showProductionDateMap = new HashMap<>();
                    Map<String, Integer> showExpiredDateMap = new HashMap<>();
                    for (Map map : mapList) {
                        String itemId = (String) map.get("itemId");
                        String manufacturerLotNum = (String) map.get("manufacturerLotNum");
                        String showProductionDate = (String) map.get("showProductionDate");
                        if (showProductionDateMap.size() == 0) {
                            showProductionDateMap.put(showProductionDate, 1);
                        } else {
                            if (!showProductionDateMap.containsKey(showProductionDate)) {
                                throw new BizException(String.format("商品id[%s],批号[%s],存在不同的生产日期[%s],请检查!", itemId,
                                        manufacturerLotNum, showProductionDate));
                            }
                        }

                        String showExpiredDate = (String) map.get("showExpiredDate");
                        if (showExpiredDateMap.size() == 0) {
                            showExpiredDateMap.put(showExpiredDate, 1);
                        } else {
                            if (!showExpiredDateMap.containsKey(showExpiredDate)) {
                                throw new BizException(String.format("商品id[%s],批号[%s],存在不同的有效期至日期[%s],请检查!", itemId,
                                        manufacturerLotNum, showExpiredDate));
                            }
                        }
                    }
                }
            }

        }
    }

    private String fetchGroup(Map p) {
        return (String) p.get("itemId") + (String) p.get("manufacturerLotNum");
    }

    private void vaildateItemContainer(String flag6, Map iqueryMap, List<RcvLinesDTO> rcvLinesDTOList, UserDTO userDTO,
                                       // 校验入库商品绑定容器是否正确
                                       Date now) {
        if (!StringUtils.isBlank(flag6) && "1".equals(flag6)) {
            this.rcvLinesService.vaildateContainer(rcvLinesDTOList);
        }
    }

    private void vaildateCargoOwnerScop(String flag5, Map queryMap, List<RcvLinesDTO> rcvLinesDTOList, UserDTO userDTO,
                                        Date now) {
        // 校验货主经营范围
        if (!StringUtils.isBlank(flag5) && "1".equals(flag5)) {
            RestMessage<Object> vaildateScope = null;
            try {
                vaildateScope = chainRemoteCaller.vaildateScope(queryMap);
            } catch (Exception e) {
                logger.error("调用远程供应链服务校验货主-商品大类关系失败,原因{}", e.getMessage());
            }
            if (vaildateScope != null) {
                if (!vaildateScope.isSuccess()) {
                    throw new BizException("校验货主-商品大类关系失败,原因->" + vaildateScope.getMessage());
                } else {
                    Map rMap = (Map) vaildateScope.getData();
                    List<Map> queryList = (List) rMap.get("queryMap");
                    for (Map map2 : queryList) {
                        Integer row = (Integer) map2.get("refId");
                        Boolean flag = (Boolean) map2.get("flag");
                        String itemId = (String) map2.get("itemId");
                        String message = (String) map2.get("message");
                        if (!flag) {
                            throw new BizException(
                                    String.format("第[%d]行,商品id[%s],商品-货主大类关联校验失败.原因->[%s]", row, itemId, message));
                        }
                    }
                }
            }
        }
    }

    private void vaildateItemInbound(String flag4, Map queryMap, List<RcvLinesDTO> rcvLinesDTOList, UserDTO userDTO,
                                     Date now) {
        // 校验商品是否停售召回
        if (!StringUtils.isBlank(flag4) && "1".equals(flag4)) {
            RestMessage<Object> vaildatePurchaseAndSales = null;
            try {
                vaildatePurchaseAndSales = baseItemRemoteCaller.vaildatePurchaseAndSales(queryMap);
            } catch (Exception e) {
                logger.error("调用远程商品服务校验商品是否召回停售失败,原因{}", e.getMessage());
            }
            if (vaildatePurchaseAndSales != null) {
                if (!vaildatePurchaseAndSales.isSuccess()) {
                    throw new BizException("校验商品是否停售召回失败,原因->" + vaildatePurchaseAndSales.getMessage());
                } else {
                    Map rMap = (Map) vaildatePurchaseAndSales.getData();
                    List<Map> queryList = (List) rMap.get("queryMap");
                    for (Map map2 : queryList) {
                        Integer row = (Integer) map2.get("refId");
                        Boolean flag = (Boolean) map2.get("flag");
                        String itemId = (String) map2.get("itemId");
                        String message = (String) map2.get("message");
                        if (!flag) {
                            throw new BizException(
                                    String.format("第[%d]行,商品id[%s],商品停售,召回校验失败.原因->[%s]", row, itemId, message));
                        }
                    }
                }
            }
        }
    }

    private void vaildateItemCategory(String flag3, Map queryMap, List<RcvLinesDTO> rcvLinesDTOList, UserDTO userDTO,
                                      Date now) {
        // 校验商品大类是否存在
        if (!StringUtils.isBlank(flag3) && "1".equals(flag3)) {
            RestMessage<Object> vaildateCategory = null;
            try {
                vaildateCategory = baseItemRemoteCaller.vaildateCategory(queryMap);
            } catch (Exception e) {
                logger.error("调用远程商品服务校验商品大类是否维护失败,原因{}", e.getMessage());
            }
            if (vaildateCategory != null) {
                if (!vaildateCategory.isSuccess()) {
                    throw new BizException("校验商品大类是否维护失败,原因->" + vaildateCategory.getMessage());
                } else {
                    Map rMap = (Map) vaildateCategory.getData();
                    List<Map> queryList = (List) rMap.get("queryMap");
                    for (Map map2 : queryList) {
                        Integer row = (Integer) map2.get("refId");
                        Boolean flag = (Boolean) map2.get("flag");
                        String itemId = (String) map2.get("itemId");
                        String message = (String) map2.get("message");
                        if (!flag) {
                            throw new BizException(
                                    String.format("第[%d]行,商品id[%s],商品大类校验失败.原因->[%s]", row, itemId, message));
                        }
                    }
                }
            }
        }
    }

    private void vaildateItemVol(String flag2, Map iqueryMap, List<RcvLinesDTO> rcvLinesDTOList, UserDTO userDTO,
                                 Date now) {
        // 校验长款高
        if (!StringUtils.isBlank(flag2) && "1".equals(flag2)) {
            // 校验商品长宽高
            RestMessage vaildateVolInfo = null;
            try {
                vaildateVolInfo = baseItemRemoteCaller.vaildateVolInfo(iqueryMap);
            } catch (Exception e) {
                logger.error("调用远程商品服务失败,原因{}", e.getMessage());
            }
            if (vaildateVolInfo != null) {
                if (!vaildateVolInfo.isSuccess()) {
                    throw new BizException("校验商品长宽高失败,原因->" + vaildateVolInfo.getMessage());
                } else {
                    Map rMap = (Map) vaildateVolInfo.getData();
                    List<Map> queryList = (List) rMap.get("queryMap");
                    for (Map map2 : queryList) {
                        Integer row = (Integer) map2.get("refId");
                        Boolean flag = (Boolean) map2.get("flag");
                        String itemId = (String) map2.get("itemId");
                        String message = (String) map2.get("message");
                        if (!flag) {
                            throw new BizException(
                                    String.format("第[%d]行,商品id[%s],商品长宽高校验失败.原因->[%s]", row, itemId, message));
                        }
                    }
                }
            }
        }
    }

    private void vaildateItemLicense(String flag1, Map iqueryMap, List<RcvLinesDTO> rcvLinesDTOList, UserDTO userDTO,
                                     Date now) {
        // 校验商品证照
        if (!StringUtils.isBlank(flag1) && "1".equals(flag1)) {
            RestMessage batchVaildateCertificate = null;
            try {
                batchVaildateCertificate = baseItemRemoteCaller.batchVaildateCertificate(iqueryMap);
            } catch (Exception e) {
                logger.error("调用远程商品服务失败,原因{}", e.getMessage());
            }
            if (batchVaildateCertificate != null) {
                if (!batchVaildateCertificate.isSuccess()) {
                    throw new BizException("校验商品失败,原因->" + batchVaildateCertificate.getMessage());
                } else {
                    Map rMap = (Map) batchVaildateCertificate.getData();
                    List<Map> queryList = (List) rMap.get("queryMap");
                    for (Map map2 : queryList) {
                        Integer row = (Integer) map2.get("refId");
                        Boolean flag = (Boolean) map2.get("flag");
                        String itemId = (String) map2.get("itemId");
                        String message = (String) map2.get("message");
                        if (!flag) {
                            throw new BizException(
                                    String.format("第[%d]行,商品id[%s],证照效期校验失败.原因->[%s]", row, itemId, message));
                        }
                    }
                }
            }
        }
    }

    private void vaildateLotInfo(RcvLinesDTO rcvLinesDTO, int i) {
        String stockStatus = rcvLinesDTO.getStockStatus();
        if (!BizConstant.REJECT.equals(stockStatus)) {
            String manufacturerLotNum = rcvLinesDTO.getManufacturerLotNum();
            String showProductionDate = rcvLinesDTO.getShowProductionDate();
            String showExpiredDate = rcvLinesDTO.getShowExpiredDate();
            if (StringUtils.isBlank(manufacturerLotNum) || StringUtils.isBlank(showProductionDate)
                    || StringUtils.isBlank(showExpiredDate)) {
                throw new BizException(String.format("第[%d]行,请检查批号,生产日期,有效期至是否为空!", i));
            }
        }

    }

    private Object excuteHandlerBatchInfo(RcvHeadersDTO rcvHeadersDTO, String rcvType,
                                          List<RcvLinesDTO> rcvLinesDTOList, Date now) {
        Object obj = null;
        // 根据条件分组是否是新增还是更新
        Map<Integer, List<RcvLinesDTO>> collect = rcvLinesDTOList.stream().filter(p -> p.getEditFlag() != null)
                .collect(Collectors.groupingBy(RcvLinesDTO::getEditFlag));
        if (!ObjectUtils.isNull(collect)) {
            for (Entry<Integer, List<RcvLinesDTO>> entry : collect.entrySet()) {
                Integer key = entry.getKey();
                List<RcvLinesDTO> value = entry.getValue();
                if (key == 1) {
                    // 批号信息更新
//					value.stream().anyMatch(p -> StringUtils.isBlank(p.getBatchId()));
                    ValidList<InvStockBatchNumberUpdate> batchNumbers = new ValidList<>();
                    for (RcvLinesDTO rcvLinesDTO : value) {
                        String stockStatus = rcvLinesDTO.getStockStatus();
                        if (BizConstant.REJECT.equals(stockStatus)) {
                            String lotNum = rcvLinesDTO.getManufacturerLotNum();
                            String showProduction = rcvLinesDTO.getShowProductionDate();
                            String showExpired = rcvLinesDTO.getShowExpiredDate();
                            if (StringUtils.isBlank(lotNum) || StringUtils.isBlank(showProduction)
                                    || StringUtils.isBlank(showExpired)) {
                                continue;
                            }
                        }

                        String batchId = rcvLinesDTO.getBatchId();
                        if (StringUtils.isBlank(batchId)) {
                            continue;
                        }
                        InvStockBatchNumberUpdate ibnu = new InvStockBatchNumberUpdate();
                        ibnu.setBatchExpiredDate(rcvLinesDTO.getBatchExpiredDate());
                        ibnu.setBatchProductionDate(rcvLinesDTO.getBatchExpiredDate());
                        ibnu.setManufacturerLotNum(rcvLinesDTO.getManufacturerLotNum());
                        ibnu.setBatchId(batchId);
                        // 显示日期格式字段 TODO
                        ibnu.setBatchProductionDateShow(rcvLinesDTO.getShowProductionDate());
                        ibnu.setBatchExpiredDateShow(rcvLinesDTO.getShowExpiredDate());
                        batchNumbers.add(ibnu);
                    }
                    if (!ObjectUtils.isNull(batchNumbers)) {
                        baseInventoryRemoteCaller.updateBatchNumber(batchNumbers);
                    }

                    // 更新其他批次的信息 TODO
                    excuteUpdateOtherBatchInfo(value);
                } else if (key == 0) {
                    List<RcvLinesDTO> needGen = new ArrayList<>();
                    for (RcvLinesDTO rcvLinesDTO : value) {
                        String stockStatus = rcvLinesDTO.getStockStatus();
                        if (BizConstant.REJECT.equals(stockStatus)) {
                            String lotNum = rcvLinesDTO.getManufacturerLotNum();
                            String showProduction = rcvLinesDTO.getShowProductionDate();
                            String showExpired = rcvLinesDTO.getShowExpiredDate();
                            if (StringUtils.isBlank(lotNum) || StringUtils.isBlank(showProduction)
                                    || StringUtils.isBlank(showExpired)) {
                                continue;
                            }
                        }
                        needGen.add(rcvLinesDTO);

                    }
                    if (!ObjectUtils.isNull(needGen)) {
                        // 批号插入
                        ValidList<InvStockBatchNumber> invStockBatchNumberList = new ValidList<InvStockBatchNumber>();
                        excuteBuildGetBatchIdCondition(rcvHeadersDTO, rcvType, needGen, invStockBatchNumberList, now);
                        // Step2.1: 错误处理以及获取返回值 (会报错,库存服务,唯一约束)
                        excuteGenBatchId(invStockBatchNumberList, needGen);
                    }

                } else {
                    // 不变 不处理
                    List<RcvLinesDTO> needGen = new ArrayList<>();
                    for (RcvLinesDTO rcvLinesDTO : value) {
                        String stockStatus = rcvLinesDTO.getStockStatus();
                        if (BizConstant.REJECT.equals(stockStatus)) {
                            String lotNum = rcvLinesDTO.getManufacturerLotNum();
                            String showProduction = rcvLinesDTO.getShowProductionDate();
                            String showExpired = rcvLinesDTO.getShowExpiredDate();
                            if (StringUtils.isBlank(lotNum) || StringUtils.isBlank(showProduction)
                                    || StringUtils.isBlank(showExpired)) {
                                continue;
                            }
                        }
                        needGen.add(rcvLinesDTO);
                    }
                    if (!ObjectUtils.isNull(needGen)) {
                        // 需要判断当前批号是否存在
                        boolean flag = needGen.stream().anyMatch(p -> StringUtils.isBlank(p.getBatchId()));
                        if (flag) {
                            throw new BizException("批次id为空(batchId),请检查自己的批次信息!");
                        }

                        obj = vaildateBatchInfo(rcvHeadersDTO, rcvType, needGen);
                    }
                }

            }
        } else {
            // 默认处理
            List<RcvLinesDTO> needGen = new ArrayList<>();
            for (RcvLinesDTO rcvLinesDTO : rcvLinesDTOList) {
                String stockStatus = rcvLinesDTO.getStockStatus();
                if (BizConstant.REJECT.equals(stockStatus)) {
                    String lotNum = rcvLinesDTO.getManufacturerLotNum();
                    String showProduction = rcvLinesDTO.getShowProductionDate();
                    String showExpired = rcvLinesDTO.getShowExpiredDate();
                    if (StringUtils.isBlank(lotNum) || StringUtils.isBlank(showProduction)
                            || StringUtils.isBlank(showExpired)) {
                        continue;
                    }
                }
                needGen.add(rcvLinesDTO);
            }
            if (!ObjectUtils.isNull(needGen)) {
                obj = vaildateBatchInfo(rcvHeadersDTO, rcvType, needGen);
            }
        }
        return obj;
    }

    private Object vaildateBatchInfo2(RcvHeadersDTO rcvHeadersDTO, String rcvType, List<RcvLinesDTO> value) {
        Object obj = null;
        if (!StringUtils.isBlank(rcvType) && (rcvType.equals(BizConstant.SALE_RETURN_IN)
                || rcvType.equals(BizConstant.BLANK_RETURN_ENTITY_IN) || rcvType.equals(BizConstant.BLANK_RETURN_IN)
                || rcvType.equals(BizConstant.MOVE_IN) || rcvType.equals(BizConstant.ALLOT_IN))) {
            if (enableSaleReturnGenBatchInfo) {
                // 看配置,默认都会生成新批次信息
                ValidList<InvStockBatchNumber> invStockBatchNumberList = new ValidList<InvStockBatchNumber>();
                excuteBuildGetBatchIdCondition(rcvHeadersDTO, rcvType, value, invStockBatchNumberList, new Date());
                // Step2.1: 错误处理以及获取返回值 (会报错,库存服务,唯一约束)
                excuteGenBatchId(invStockBatchNumberList, value);

            } else {

                if (enableVaildateBatchInfo2Web) {
                    // 根据配置抛错给前端处理
                    Set<String> itemIds = value.stream().map(RcvLinesDTO::getItemId).collect(Collectors.toSet());
                    Set<String> batchIds = value.stream().map(RcvLinesDTO::getBatchId).collect(Collectors.toSet());
                    Set<String> manufacturerLotNums = value.stream().map(RcvLinesDTO::getManufacturerLotNum)
                            .collect(Collectors.toSet());
                    Map<String, Object> queryMap = new HashMap<>();
                    queryMap.put("batchIds", batchIds);
                    queryMap.put("itemIds", itemIds);
                    queryMap.put("manufacturerLotNums", manufacturerLotNums);
//				String warehouseId = rcvHeadersDTO.getWarehouseId();
//				// 仓库
//				queryMap.put("warehouseId", warehouseId);
                    String mtlOwnerId = rcvHeadersDTO.getMtlOwnerId();
                    // 货主
                    queryMap.put("cargoOwnerId", mtlOwnerId);
                    List<Map> searchForMap2 = null;
                    try {
                        searchForMap2 = searchApi.searchForMap("getBatchInfo", queryMap);
                    } catch (Exception e1) {
                        logger.info("找寻商品批次信息失败,原因{}", e1);
                        if (!enableErrorGenBatchInfo) {
                            throw new BizException("找寻商品批次信息失败,调用查询服务,请联系管理员检查!");
                        }
                    }
                    if (!ObjectUtils.isNull(searchForMap2)) {
                        // 匹配入库已有批次和wms已存在的批次
                        return matchBatchInfo(searchForMap2, value);

                    } else {
                        logger.info("找寻商品批次信息为空!请联系管理员检查!");
                        if (!enableErrorGenBatchInfo) {
                            throw new BizException("找寻商品批次信息为空!请联系管理员检查!");
                        }
                    }

                } else {
                    // 默认缺批次就生成批次
                    Set<RcvLinesDTO> res = new HashSet<>();
                    Map<String, List<RcvLinesDTO>> collect3 = value.stream()
                            .filter(p -> !StringUtils.isBlank(p.getBatchId()))
                            .collect(Collectors.groupingBy(RcvLinesDTO::getBatchId));
                    if (ObjectUtils.isNull(collect3)) {
                        res.addAll(value);
                    } else {
                        for (List<RcvLinesDTO> rcvLinesDTOlist : collect3.values()) {
                            RcvLinesDTO rcvLinesDTO = rcvLinesDTOlist.get(0);
                            if (rcvLinesDTO != null) {
                                String manufacturerLotNum = rcvLinesDTO.getManufacturerLotNum();
                                String showExpiredDate = rcvLinesDTO.getShowExpiredDate();
                                String showProductionDate = rcvLinesDTO.getShowProductionDate();
                                String itemId = rcvLinesDTO.getItemId();
                                String batchId = rcvLinesDTO.getBatchId();
                                Set<String> set = new HashSet<>();
                                if (!StringUtils.isBlank(batchId)) {
                                    set.add(batchId);
                                }
                                Set<String> set2 = new HashSet<>();
                                Set<String> set3 = new HashSet<>();
                                set2.add(itemId);
                                set3.add(manufacturerLotNum);
                                Map<String, Object> queryMap = new HashMap<>();
                                queryMap.put("batchIds", set);
                                queryMap.put("itemIds", set2);
                                queryMap.put("manufacturerLotNums", set3);
                                queryMap.put("showProductionDate", showProductionDate);
                                queryMap.put("showExpiredDate", showExpiredDate);
                                String mtlOwnerId = rcvHeadersDTO.getMtlOwnerId();
                                // 货主
                                queryMap.put("cargoOwnerId", mtlOwnerId);

                                String format = String.format(
                                        "商品id[%s],批次id[%s],批号[%s],生产日期[%s],有效期至[%s],商品批次信息表中不存在,请检查后联系管理员处理!", itemId,
                                        batchId, manufacturerLotNum, showProductionDate, showExpiredDate);
                                List<Map> searchForMap = null;
                                try {
                                    searchForMap = searchApi.searchForMap("getBatchInfo", queryMap);
                                } catch (Exception e1) {
                                    logger.info(format + "查询服务报错,找寻商品批次信息失败,原因{}", e1);
                                    if (!enableErrorGenBatchInfo) {
                                        throw new BizException(format);
                                    }
                                }
                                if (!ObjectUtils.isNull(searchForMap)) {
                                    boolean updateFlag = true;
                                    for (Map map : searchForMap) {
                                        // 如果batchId匹配成功,则不发生改变
                                        String batchId2 = (String) map.get("batchId");
                                        String itemId2 = (String) map.get("itemId");
                                        if (!StringUtils.isBlank(batchId) && batchId2.equals(batchId)) {
                                            String showProductionDate2 = (String) map.get("showProductionDate");
                                            String showExpiredDate2 = (String) map.get("showExpiredDate");
                                            String manufacturerLotNum2 = (String) map.get("manufacturerLotNum");
                                            if (!StringUtils.isBlank(manufacturerLotNum2)
                                                    && !StringUtils.isBlank(showProductionDate2)
                                                    && !StringUtils.isBlank(showExpiredDate2)
                                                    && !StringUtils.isBlank(itemId2) && itemId.equals(itemId2)
                                                    && manufacturerLotNum2.equals(manufacturerLotNum)
                                                    && showProductionDate2.equals(showProductionDate)
                                                    && showExpiredDate2.equals(showExpiredDate)) {
                                                updateFlag = false;
                                            }
                                        }
                                    }
                                    // 需要更新batchId,batchNum
                                    if (updateFlag) {
                                        Map map = searchForMap.get(0);
                                        if (!ObjectUtils.isNull(map)) {
                                            String batchId2 = (String) map.get("batchId");
                                            String itemId2 = (String) map.get("itemId");
                                            String batchNum = (String) map.get("batchNum");
                                            String manufacturerLotNum2 = (String) map.get("manufacturerLotNum");
                                            String showProductionDate2 = (String) map.get("showProductionDate");
                                            String showExpiredDate2 = (String) map.get("showExpiredDate");
                                            if (!StringUtils.isBlank(manufacturerLotNum2)
                                                    && !StringUtils.isBlank(showProductionDate2)
                                                    && !StringUtils.isBlank(showExpiredDate2)
                                                    && !StringUtils.isBlank(itemId2) && itemId.equals(itemId2)
                                                    && manufacturerLotNum2.equals(manufacturerLotNum)
                                                    && showProductionDate2.equals(showProductionDate)
                                                    && showExpiredDate2.equals(showExpiredDate)) {
                                                for (RcvLinesDTO rcvLinesDTO2 : rcvLinesDTOlist) {
                                                    rcvLinesDTO2.setBatchId(batchId2);
                                                    rcvLinesDTO2.setBatchNum(batchNum);
//												rcvLinesDTO2.setManufacturerLotNum(manufacturerLotNum2);
//												rcvLinesDTO2.setShowProductionDate(showProductionDate2);
//												rcvLinesDTO2.setShowExpiredDate(showExpiredDate2);
                                                    // 操作日期格式
                                                    excuteHandleDate(rcvLinesDTO2, map);
                                                    // 更新收货行
                                                    this.mapper.updateMapById(rcvLinesDTO2.getRcvLineId(), MapUtils
//														.put("batchProductionDate", rcvLinesDTO2.getBatchProductionDate())
//														.put("batchExpiredDate", rcvLinesDTO2.getBatchExpiredDate())
                                                            .put("batchId", batchId2).put("batchNum", batchNum)
                                                            .getMap(), RcvLines.class);

                                                }
                                            } else {
                                                res.addAll(rcvLinesDTOlist);
                                            }

                                        } else {
                                            logger.info("查询的批次集合数据为空," + format);
                                            if (!enableErrorGenBatchInfo) {
                                                throw new BizException(format);
                                            }
                                        }
                                    }

                                } else {
                                    logger.info("查询的批次集合数据为空," + format);
                                    if (!enableErrorGenBatchInfo) {
                                        throw new BizException(format);
                                    }
                                    res.addAll(rcvLinesDTOlist);
                                }
                            }
                        }
                    }

                    if (enableErrorGenBatchInfo && !ObjectUtils.isNull(res)) {
                        if (!ObjectUtils.isNull(res)) {
                            List<RcvLinesDTO> collect4 = res.stream().distinct().collect(Collectors.toList());
                            ValidList<InvStockBatchNumber> invStockBatchNumberList = new ValidList<InvStockBatchNumber>();
                            excuteBuildGetBatchIdCondition(rcvHeadersDTO, rcvType, collect4, invStockBatchNumberList,
                                    new Date());
                            // Step2.1: 错误处理以及获取返回值 (会报错,库存服务,唯一约束)
                            excuteGenBatchId(invStockBatchNumberList, collect4);
                        }
                    }
                }
            }
        }
        return obj;
    }

    /**
     * 匹配erp给的批次信息
     *
     * @param searchForMap2
     * @param value
     * @return
     */
    private Object matchBatchInfo(List<Map> searchForMap2, List<RcvLinesDTO> value) {
        Map<String, List<Map>> collect = searchForMap2.stream()
                .filter(p -> !StringUtils.isBlank((String) p.get("itemId"))
                        && !StringUtils.isBlank((String) p.get("manufacturerLotNum")))
                .collect(Collectors.groupingBy(p -> (String) p.get("itemId") + (String) p.get("manufacturerLotNum")));
        Map<Object, Object> res = new HashMap<>();

        for (RcvLinesDTO rcvLinesDTO : value) {
            Integer lineNum = rcvLinesDTO.getLineNum();
            String itemNum = rcvLinesDTO.getItemNum();
            String itemName = rcvLinesDTO.getItemName();
            String itemId = rcvLinesDTO.getItemId();
            String manufacturerLotNum = rcvLinesDTO.getManufacturerLotNum();
            String showProductionDate = rcvLinesDTO.getShowProductionDate();
            String showExpiredDate = rcvLinesDTO.getShowExpiredDate();
            List<Map> list = collect.get(itemId + manufacturerLotNum);
            if (!ObjectUtils.isNull(list)) {
                for (Map map : list) {
                    String batchId = (String) map.get("batchId");
                    String batchNum = (String) map.get("batchNum");
                    String itemId2 = (String) map.get("itemId");
                    String manufacturerLotNum2 = (String) map.get("manufacturerLotNum");
                    String showProductionDate2 = (String) map.get("showProductionDate");
                    String showExpiredDate2 = (String) map.get("showExpiredDate");
                    if (itemId.equals(itemId2) && manufacturerLotNum.equals(manufacturerLotNum2)
                            && showProductionDate.equals(showProductionDate2)
                            && showExpiredDate.equals(showExpiredDate2)) {
                        // 匹配成功
                        rcvLinesDTO.setBatchId(batchId);
                        rcvLinesDTO.setBatchNum(batchNum);
                        // 操作日期格式
                        excuteHandleDate(rcvLinesDTO, map);
                        this.mapper.updateMapById(rcvLinesDTO.getRcvLineId(),
                                MapUtils.put("batchId", batchId).put("batchNum", batchNum)
                                        .put("batchProductionDate", rcvLinesDTO.getBatchProductionDate())
                                        .put("batchExpiredDate", rcvLinesDTO.getBatchExpiredDate()).getMap(),
                                RcvLines.class);
                        break;
                    } else {
                        // 没能匹配
                        res.put(String.valueOf(lineNum), String.format(
                                "收货明细第[%d]行,商品[%s],批号[%s],所属生产日期[%s],有效期至[%s]匹配不成功!存在其他生产日期[%s],有效期至[%s],是否重新生成批次信息?或者尝试使用商品批次调整此批号.",
                                lineNum, itemNum + "-" + itemName, manufacturerLotNum, showProductionDate,
                                showExpiredDate, showProductionDate2, showExpiredDate2));
                        return res;
                    }
                }

            } else {
                res.put(String.valueOf(lineNum),
                        String.format("收货明细第[%d]行,商品[%s],批号[%s],生产日期[%s],有效期至[%s],在wms系统中不存在!是否重新生成?", lineNum,
                                itemNum + "-" + itemName, manufacturerLotNum, showProductionDate, showExpiredDate));
                return res;
            }
        }
        return null;
    }

    private void excuteHandleDate(RcvLinesDTO rcvLinesDTO2, Map map) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMM");

        String showProductionDate2 = (String) map.get("showProductionDate");
        String showExpiredDate2 = (String) map.get("showExpiredDate");

        Object productionDateObj = map.get("productionDate");
        Object expiredDateObj = map.get("expiredDate");
        Date productionDate = null;
        if (productionDateObj != null) {
            if (productionDateObj instanceof java.util.Date) {
                productionDate = (Date) productionDateObj;
            }
            if (productionDateObj instanceof Long) {
                Long productionDateL = (Long) productionDateObj;
                productionDate = new Date(productionDateL);
            }
            if (productionDateObj instanceof String) {
                String productionDateStr = (String) productionDateObj;
                try {
                    productionDate = sdf.parse(productionDateStr);
                } catch (ParseException e1) {
                    e1.printStackTrace();
                }
            }
        }
        Date expiredDate = null;
        if (expiredDateObj != null) {
            if (expiredDateObj instanceof java.util.Date) {
                expiredDate = (Date) expiredDateObj;
            }
            if (expiredDateObj instanceof Long) {
                Long expiredDateL = (Long) expiredDateObj;
                expiredDate = new Date(expiredDateL);
            }
            if (expiredDateObj instanceof String) {
                String expiredDateStr = (String) expiredDateObj;
                try {
                    expiredDate = sdf.parse(expiredDateStr);
                } catch (ParseException e1) {
                    e1.printStackTrace();
                }
            }
        }

        Date date = new Date();
        if (productionDate == null) {
            if (StringUtils.isBlank(showProductionDate2)) {
                Date parse1 = null;
                if ("*".equals(showProductionDate2)) {
                    date.setHours(0);
                    date.setMinutes(0);
                    date.setSeconds(0);
                    parse1 = date;
                } else if (showProductionDate2.length() == 6) {
                    try {
                        parse1 = sdf2.parse(showProductionDate2);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                } else if (showProductionDate2.length() == 8) {
                    try {
                        parse1 = sdf1.parse(showProductionDate2);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
                if (parse1 == null) {
                    parse1 = date;
                }
                productionDate = parse1;
            }
        }
        if (expiredDate == null) {
            if (StringUtils.isBlank(showExpiredDate2)) {
                Date parse = null;
                if ("*".equals(showExpiredDate2)) {
                    try {
                        parse = sdf1.parse("20990101");
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                } else if (showExpiredDate2.length() == 6) {
                    try {
                        parse = sdf2.parse(showExpiredDate2);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }

                } else if (showExpiredDate2.length() == 8) {
                    try {
                        parse = sdf1.parse(showExpiredDate2);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                }
                if (parse == null) {
                    Calendar cal = Calendar.getInstance();
                    cal.setTime(date);// 设置起时间
                    cal.add(Calendar.YEAR, 100);// 增加100年
                    parse = cal.getTime();
                }
                expiredDate = parse;
            }
        }
        rcvLinesDTO2.setBatchProductionDate(productionDate);
        rcvLinesDTO2.setBatchExpiredDate(expiredDate);

    }

    private Object vaildateBatchInfo(RcvHeadersDTO rcvHeadersDTO, String rcvType, List<RcvLinesDTO> value) {
        return vaildateBatchInfo2(rcvHeadersDTO, rcvType, value);
    }

    private void excuteUpdateOtherBatchInfo(List<RcvLinesDTO> value) {
        // 操作其它拥有批次信息的表 暂不处理 TODO

    }

    private void excuteGenBatchId(ValidList<InvStockBatchNumber> invStockBatchNumberList,
                                  List<RcvLinesDTO> rcvLinesDTOList) {

        RestMessage<List<InvStockBatchNumberResult>> genBatchNumber = null;
        List<InvStockBatchNumberResult> data = excuteHandlerRemoteError(invStockBatchNumberList, genBatchNumber);
        AssertUtils.isNotEmpty(data, "生成的批次信息为空!");

        Map<String, List<InvStockBatchNumberResult>> collect2 = Optional.ofNullable(data)
                .orElse(Collections.emptyList()).stream().filter(p -> !StringUtils.isBlank(p.getRcvLineId()))
                .collect(Collectors.groupingBy(InvStockBatchNumberResult::getRcvLineId));
        // Step3: 更新收货行的batchNum,batchId
        for (RcvLinesDTO rcvLinesDTO : rcvLinesDTOList) {
            String rcvLineId = rcvLinesDTO.getRcvLineId();
            List<InvStockBatchNumberResult> list = collect2.get(rcvLineId);
            if (!ObjectUtils.isNull(list)) {
                InvStockBatchNumberResult invStockBatchNumberResult = list.get(0);
                String batchId = invStockBatchNumberResult.getBatchId();
                String batchNum = invStockBatchNumberResult.getBatchNum();
                this.mapper.updateMapById(rcvLineId,
                        MapUtils.put("batchId", batchId).put("batchNum", batchNum).getMap(), RcvLines.class);
                rcvLinesDTO.setBatchId(batchId);
                rcvLinesDTO.setBatchNum(batchNum);
            }

        }

    }

    private List<InvStockBatchNumberResult> excuteHandlerRemoteError(
            ValidList<InvStockBatchNumber> invStockBatchNumberList,
            RestMessage<List<InvStockBatchNumberResult>> genBatchNumber) {
        if (ObjectUtils.isNull(invStockBatchNumberList)) {
            return null;
        }
        try {
            // logger.info("调用库存接口genBatchNumber，入参："+
            // JsonUtils.toString(invStockBatchNumberList));
            logger.info("调用库存接口genBatchNumber，入参：" + JsonUtils.toString(invStockBatchNumberList));
            genBatchNumber = baseInventoryRemoteCaller.genBatchNumber(invStockBatchNumberList);
            if (genBatchNumber != null) {
                logger.info("返回结果：" + JsonUtils.toString(genBatchNumber));
            }
        } catch (Exception e) {
            logger.error("调用远程生成批次信息出现错误错误!", e);
            throw new BizException("调用远程库存服务生成批次信息错误!请联系管理员处理!");
        }
        if (genBatchNumber == null)
            throw new BizException("远程调用库存服务获取数据为空!请联系管理员处理!");

        if (genBatchNumber.isSuccess() && genBatchNumber.getData() == null)
            throw new BizException("生成批次信息为空!请联系管理员处理!");

        if (!genBatchNumber.isSuccess()) {
            if (!ObjectUtils.isNull(genBatchNumber.getData())) {
                throw new BizException("远程调用库存服务错误!原因->" + genBatchNumber.getMessage() + genBatchNumber.getData());
            } else {
                throw new BizException("远程调用库存服务错误!原因->" + genBatchNumber.getMessage());
            }

        }

        List<InvStockBatchNumberResult> data = genBatchNumber.getData();
        return data;
    }

    private void excuteBuildGetBatchIdCondition(RcvHeadersDTO rcvHeadersDTO, String rcvType,
                                                List<RcvLinesDTO> rcvLinesDTOList, ValidList<InvStockBatchNumber> invStockBatchNumberList, Date now) {
        String asnHeaderId = rcvHeadersDTO.getAsnHeaderId();
        Date rcvDate = rcvHeadersDTO.getRcvDate();
        String mtlOwnerId = rcvHeadersDTO.getMtlOwnerId();
        String vendorId = rcvHeadersDTO.getVendorId();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        for (RcvLinesDTO rcvLinesDTO : rcvLinesDTOList) {
            InvStockBatchNumber result = new InvStockBatchNumber();
            Date batchExpiredDate = rcvLinesDTO.getBatchExpiredDate();
            Date batchProductionDate = rcvLinesDTO.getBatchProductionDate();
            String erpBatchNum = rcvLinesDTO.getErpBatchNum();
            String itemId = rcvLinesDTO.getItemId();
            String manufacturerLotNum = rcvLinesDTO.getManufacturerLotNum();
            String orgId = rcvLinesDTO.getOrgId();
            BigDecimal piecePriceTe = rcvLinesDTO.getPiecePriceTe();
            BigDecimal piecePriceTi = rcvLinesDTO.getPiecePriceTi();
            String productionPlace = rcvLinesDTO.getProductionPlace();
            BigDecimal shelfLifeDays = rcvLinesDTO.getShelfLifeDays();
            BigDecimal taxRate = rcvLinesDTO.getTaxRate();
            if (null == piecePriceTe)
                piecePriceTe = BigDecimal.ZERO; // 不含税
            if (null == piecePriceTi)
                piecePriceTi = BigDecimal.ZERO; // 含税
            // 税率 = (含税-不含税)/不含税
            if (null == taxRate && BigDecimal.ZERO.compareTo(piecePriceTe) != 0)
                taxRate = (piecePriceTi.subtract(piecePriceTe)).divide(piecePriceTe, 4, RoundingMode.HALF_UP);
            if (null == taxRate)
                taxRate = BigDecimal.ONE;
            String vendorBatchNum = rcvLinesDTO.getVendorBatchNum();
            String rcvLineId = rcvLinesDTO.getRcvLineId();

            // 需要加入批次id的处理 TODO

            result.setRcvLineId(rcvLineId);
            result.setAsnId(asnHeaderId);
            result.setBatchExpiredDate(batchExpiredDate);
            result.setBatchProductionDate(batchProductionDate);
            result.setCargoOwnerId(mtlOwnerId);
            result.setErpBatchNum(erpBatchNum);
            result.setGradeId("9");
            result.setItemId(itemId);
            result.setManufacturerLotNum(manufacturerLotNum);
            result.setOrgnId(orgId);
            result.setPieceCostTe(piecePriceTe);
            result.setPieceCostTi(piecePriceTi);
            result.setProductionPlace(productionPlace);
            result.setRcvDate(rcvDate);
            if (shelfLifeDays != null) {
                result.setShelfLifeDays(shelfLifeDays);
            } else {
                result.setShelfLifeDays(BigDecimal.valueOf(90));
            }
            result.setTaxRate(taxRate);
            result.setVendorBatchNum(vendorBatchNum);
            result.setVendorId(vendorId);
            String showProductionDate = rcvLinesDTO.getShowProductionDate();
            String showExpiredDate = rcvLinesDTO.getShowExpiredDate();
            if (StringUtils.isBlank(showProductionDate)) {
                showProductionDate = sdf.format(batchProductionDate);
            }
            if (StringUtils.isBlank(showExpiredDate)) {
                showExpiredDate = sdf.format(batchExpiredDate);
            }
            result.setBatchProductionDateShow(showProductionDate);
            result.setBatchExpiredDateShow(showExpiredDate);
            invStockBatchNumberList.add(result);
        }
    }

    /**
     * 需求: 11.收货时收货员可以选择受托生产企业，且需回传至OMS/ERP，
     * 且系统需校验受托生产企业的《药品生产许可证》证照效期和委托书效期，校验不通过时进行提示且拦截；(供应商) 校验有受托生产企业的收货行明细
     *
     * @param rcvLinesDTOList
     * @throws JsonProcessingException
     * @throws InstantiationException
     * @throws IllegalAccessException
     * @throws SearchException
     */
    private void excuteVaildteDelegationParty(List<RcvLinesDTO> rcvLinesDTOList, UserDTO userDTO)
            throws SearchException, IllegalAccessException, InstantiationException, JsonProcessingException {
        // 组装待校验的数据

        String enterpriseId = userDTO.getEnterpriseId();
        Set<String> delegationPartyIds = new HashSet<>();
        for (RcvLinesDTO rcvLinesDTO : rcvLinesDTOList) {
            String delegationPartyId = rcvLinesDTO.getDelegationPartyId();
            if (StringUtils.isBlank(delegationPartyId))
                continue;
            delegationPartyIds.add(delegationPartyId);
        }
        if (ObjectUtils.isEmpty(delegationPartyIds))
            return;

        // 远程调用presto的search服务
        Map<String, Object> queryMap = new HashMap<>();
//		queryMap.put("enterpriseId", enterpriseId);
        queryMap.put("mtlOwnerId", rcvLinesDTOList.get(0).getMtlOwnerId());
        queryMap.put("delegationPartyIds", delegationPartyIds);
        List<Map> searchForMap = searchApi.searchForMap("rcv_oem_choose", queryMap);
        if (ObjectUtils.isEmpty(searchForMap))
            return;
        Date now = new Date();
        List<String> oemIdList = new ArrayList<>();
        for (Map map : searchForMap) {
            // 委托书效期
            Date date1 = (Date) map.get("authorizationEdate");
            // 药品生产证件效期
            Date date2 = (Date) map.get("licenseExpiryDate");
            String oemId = (String) map.get("oemId");
            if (now.before(date1) || now.before(date2))
                oemIdList.add(oemId);
        }
        if (ObjectUtils.isEmpty(oemIdList))
            return;

        int row = 0;
        StringBuilder sb = new StringBuilder();
        for (RcvLinesDTO rcvLinesDTO : rcvLinesDTOList) {
            row++;
            String delegationPartyId = rcvLinesDTO.getDelegationPartyId();
            if (StringUtils.isBlank(delegationPartyId))
                continue;
            if (oemIdList.contains(delegationPartyId))
                sb.append(String.format("第[%d]行;", row));
        }
        String result = sb.toString();
        if (StringUtils.isBlank(result)) {
            return;
        } else {
            sb.append("受托生产企业的委托书效期或药品生产许可证效期已失效,请注意检查!");
            throw new BizException(sb.toString());
        }
        // 校验成功,回传oms/erp TODO
    }
    // 调用供应商远程....
//	private void excuteVaildteDelegationParty(List<RcvLinesDTO> rcvLinesDTOList, UserDTO userDTO) {
//		// 组装待校验的数据
//		int row = 0;
//		String enterpriseId = userDTO.getEnterpriseId();
//		List<Map<String, Object>> mapList = new ArrayList<>();
//		for (RcvLinesDTO rcvLinesDTO : rcvLinesDTOList) {
//			row++;
//			String delegationPartyId = rcvLinesDTO.getDelegationPartyId();
//			if (StringUtils.isBlank(delegationPartyId))
//				continue;
//			Map<String, Object> map = new HashMap<>();
//			map.put("delegationPartyId", delegationPartyId);
//			map.put("row", String.valueOf(row));
//			map.put("enterpriseId", enterpriseId);
//			mapList.add(map);
//		}
//		// 远程调用供应链服务,校验受托生产供应商是否可用
//		if (ObjectUtils.isEmpty(mapList))
//			return;
//		
//		RestMessage<?> healthLicenseVaildate = chainRemoteCaller.healthLicenseVaildate(mapList);
//		if (healthLicenseVaildate.isSuccess() && healthLicenseVaildate.getData() != null) {
//			@SuppressWarnings("unchecked")
//			Map<String, Object> resultMap = (Map<String, Object>) healthLicenseVaildate.getData();
//			if (ObjectUtils.isEmpty(resultMap)) {
//				return;
//			} else {
//				throw new BizException(resultMap.values().toString());
//			}
//		}
//		if (!healthLicenseVaildate.isSuccess()) {
//			String message = healthLicenseVaildate.getMessage();
//			throw new BizException(message);
//		}
//		// 校验成功,回传oms/erp TODO
//	}

}
