//package com.prolog.cs.biz.outbound.service.impl;
//
//import cn.hutool.core.collection.CollectionUtil;
//import com.alibaba.fastjson.JSON;
//import com.codingapi.tx.annotation.TxTransaction;
//import com.prolog.cs.basic.common.model.BaseCommonDict;
//import com.prolog.cs.basic.item.model.*;
//import com.prolog.cs.basic.item.model.vo.ItemBarCodeVO;
//import com.prolog.cs.basic.item.model.vo.WaveItemInfoVO;
//import com.prolog.cs.basic.warehouse.model.BaseWmsWhWorkstation;
//import com.prolog.cs.basic.warehouse.model.vo.ContainerQueryVO;
//import com.prolog.cs.basic.warehouse.model.vo.WhWorkstationQueryVO;
//import com.prolog.cs.biz.inbound.dto.IsSuperviseDTO;
//import com.prolog.cs.biz.outbound.dao.*;
//import com.prolog.cs.biz.outbound.funcflow.innnercheckfunc.*;
//import com.prolog.cs.biz.outbound.model.OmsDoBillHDO;
//import com.prolog.cs.biz.outbound.model.PickTaskD;
//import com.prolog.cs.biz.outbound.model.PickTaskH;
//import com.prolog.cs.biz.outbound.model.SaleRedRecord;
//import com.prolog.cs.biz.outbound.model.dto.PickTaskDDTO;
//import com.prolog.cs.biz.outbound.model.dto.check.*;
//import com.prolog.cs.biz.outbound.model.entity.*;
//import com.prolog.cs.biz.outbound.model.vo.WorkgroupVO;
//import com.prolog.cs.biz.outbound.model.vo.check.*;
//import com.prolog.cs.biz.outbound.resource.*;
//import com.prolog.cs.biz.outbound.service.InnerCheckV3Service;
//import com.prolog.cs.biz.outbound.service.strategy.STRATEGY_CODE;
//import com.prolog.cs.biz.outbound.service.strategy.StrategySelector;
//import com.prolog.cs.biz.outbound.service.strategy.handles.IStrategyHandle;
//import com.prolog.cs.data.exchange.client.ExchangeSender;
//import com.prolog.framework.authority.core.dto.UserDTO;
//import com.prolog.framework.authority.user.UserTemplate;
//import com.prolog.framework.bz.core.collection.ValidList;
//import com.prolog.framework.bz.core.model.ModelUtils;
//import com.prolog.framework.common.message.RestMessage;
//import com.prolog.framework.core.exception.BizException;
//import com.prolog.framework.core.exception.ParameterException;
//import com.prolog.framework.core.exception.PrologException;
//import com.prolog.framework.core.restriction.Criteria;
//import com.prolog.framework.core.restriction.Restriction;
//import com.prolog.framework.core.restriction.Restrictions;
//import com.prolog.framework.lock.DistributedLock;
//import com.prolog.framework.toolkit.MapToolKit;
//import com.prolog.framework.utils.*;
//import com.prolog.function.annotation.Flow;
//import com.prolog.function.annotation.FuncImpl;
//import com.prolog.upcloud.base.inventory.vo.InvStockOut;
//import com.prolog.upcloud.base.inventory.vo.InvStockOutDetail;
//import com.prolog.upcloud.base.wh.operate.vo.WmsAdjustAddVO;
//import org.apache.commons.compress.utils.Lists;
//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.data.redis.core.RedisTemplate;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import javax.annotation.PostConstruct;
//import java.math.BigDecimal;
//import java.util.*;
//import java.util.concurrent.TimeUnit;
//import java.util.concurrent.atomic.AtomicReference;
//import java.util.function.Function;
//import java.util.stream.Collectors;
//
//@Service
//public class InnerCheckV3ServiceImpl implements InnerCheckV3Service {
//
//    private static Logger log = LoggerFactory.getLogger(InnerCheckV3ServiceImpl.class);
//
//    @Autowired
//    private ControlResource controlResource;
//
//    @Autowired
//    private OperateResource operateResource;
//
//    @Autowired
//    PickTaskHMapper pickTaskHMapper;
//
//    @Autowired
//    PickTaskDMapper pickTaskDMapper;
//
//    @Autowired
//    UserTemplate userTemplate;
//
//    @Autowired
//    WaveBillDMapper billDMapper;
//
//    @Autowired
//    ItemClient itemClient;
//
//    @Autowired
//    BarcodeHMapper barcodeHMapper;
//
//    @Autowired
//    BarcodeDMapper barcodeDMapper;
//
//    @Autowired
//    private WaveBillMapper billMapper;
//
//    @Autowired
//    private InnerCheckHMapper innerCheckHMapper;
//
//    @Autowired
//    WorkStageRuntimeMapper workStageRuntimeMapper;
//
//    @Autowired
//    private InnerCheckDMapper innerCheckDMapper;
//
//    @Autowired
//    private WaveStorageMapper storageMapper;
//
//    @Autowired
//    private OmsDoBillHMapper omsDoBillHMapper;
//
//    @Autowired
//    private OmsDoBillDMapper omsDoBillDMapper;
//
//    @Autowired
//    private WarehouseResource warehouseResource;
//
//    @Autowired
//    private InventoryResource inventoryResource;
//
//    @Autowired
//    private InBoundClient inBoundClient;
//
//    @Autowired
//    private DistributedLock distributedLock;
//
//    @Autowired
//    private SaleRedRecordMapper saleRedRecordMapper;
//
//    @Autowired
//    private ExchangeSender exchangeSender;
//
//    @Autowired
//    private CommonClient commonClient;
//
//    @Autowired
//    private StrategyResource strategyResource;
//
//    @Value("${prolog.dao.keyGenerator.snowFlake.dataCenterId:15}")
//    private long dataCenterId;
//
//    @Value("${prolog.dao.keyGenerator.snowFlake.machineId:2}")
//    private long machineId;
//
//    // 业务参数配置内/外复核回传ERP by Huanglh 20220112
//    @Autowired
//    private StrategySelector strategySelector;
//
//    @Autowired
//    private RedisTemplate redisTemplate;
//
//    private ValidInnerCheckConfirmFunc validInnerCheckConfirmFunc;
//    private InnerCheckConfirmFunc innerCheckConfirmFunc;
//
//
//    @PostConstruct
//    public void init() {
//        validInnerCheckConfirmFunc = this::validInnerCheckConfirmFunc;
//        innerCheckConfirmFunc = this::innerCheckConfirmFunc;
//    }
//
//    @Override
//    @Transactional
//    @Flow(name = "内复核索取", category = "出库/复核管理/内复核/内复核索取", index = 1, description = "1、查询容器内任务明细 2、更新状态为已索取：pick_task_h status=3,pick_task_d flow_status=4")
//    public RestMessage<InnerCheckBillV2VO> getCurrentContainer(
//            String containerCode,
//            String stationCode,
//            String billGroupId,
//            String lclNo,
//            Integer isDoubleCheck,
//            String warehouseId
//    ){
//        long start = System.currentTimeMillis();
//        InnerCheckBillV2VO containerInfo = findPickupByContainerFuncV2(containerCode, stationCode, null,billGroupId,lclNo,isDoubleCheck,warehouseId);
//        long end = System.currentTimeMillis();
//        log.info("getCurrentContainer接口耗时："+(end-start));
//
////        List<InnerCheckTaskDV2VO> innerCheckTaskDVOS = containerInfo.getInnerCheckTaskDVOS();
////        for (InnerCheckTaskDV2VO innerCheckTaskDVO : innerCheckTaskDVOS) {
////            addLclDQty(containerInfo.getShipBillNo(),stationCode,containerInfo.getBillGroupId(),innerCheckTaskDVO.getItemCode(),innerCheckTaskDVO.getItemId(),innerCheckTaskDVO.getQty(),containerCode,innerCheckTaskDVO.getPickTaskDId());
////        }
//        //现在逻辑为：当前扫描的周转箱所在滑道和任务是否有未封箱的拼箱，有则返回当前拼箱，无则返回新拼箱
//
//        return RestMessage.doSuccess(containerInfo);
//    }
//
//    private LclVO getLclVo(){
//        LclVO lclVO = new LclVO();
//        return lclVO;
//    }
//
//    @Override
//    @Transactional
//    @TxTransaction(isStart = true)
//    @Flow(name = "红冲", category = "出库/复核管理/内复核/红冲", index = 3, description = "1、校验 2、生成WMS_SALE_RED_RECORD记录 " +
//            "3、非整条明细红冲更新拼箱数量(WMS_BARCODE_D qty) 4、整条明细红冲删除WMS_BARCODE_D记录 5、整箱红冲删除WMS_BARCODE_H")
//    public RestMessage<InnerCheckBillV2VO> makeCheckRed(CheckMakeRedDTO redDTO) {
//        PickTaskD pickTaskD=new PickTaskD();
//        PickTaskH pickTaskH=new PickTaskH();
//        validRedFunc(redDTO,pickTaskD,pickTaskH);
//        RestMessage<InnerCheckBillV2VO> innerCheckBillVORestMessage = redFunc(redDTO,pickTaskD,pickTaskH);
//        return innerCheckBillVORestMessage;
//    }
//
//    @Override
//    @Transactional
//    public RestMessage<InnerCheckBillV2VO> checkItemByNum(CheckInfoDTO checkInfoDTO){
//        List<PickTaskD> pickTaskDList = Lists.newArrayList();
//        ItemBarCodeVO itemBarCodeVO=new ItemBarCodeVO();
//        validInnerCheckFunc(checkInfoDTO, false, true, false,pickTaskDList,itemBarCodeVO);
//        updatePickupDInnerCheckInfoFunc(checkInfoDTO, false, true, false,pickTaskDList,itemBarCodeVO);
//        RestMessage<InnerCheckBillV2VO> innerCheckBillVORestMessage = createBarcodeFunc(checkInfoDTO,
//                false, true, false,pickTaskDList,itemBarCodeVO);
//        return innerCheckBillVORestMessage;
//    }
//
//
//    @Flow(name = "内复核确认", category = "出库/复核管理/内复核/内复核确认", index = 7, description = "1、校验：复核数量&是否打印等 2、更新pick_task_h status=10 3、更新barcode_h check_status=0")
//    @Override
//    @Transactional
//    public RestMessage<InnerCheckConfirmCheckVO> containerCheckConfirm(CheckConfirmDTO checkConfirmDTO) {
//        List<InnerCheckDDO> innerCheckDs = validInnerCheckConfirmFunc.validInnerCheckConfirmFunc(checkConfirmDTO);
//        RestMessage<InnerCheckConfirmCheckVO> stringRestMessage = innerCheckConfirmFunc.innerCheckConfirmFunc(checkConfirmDTO, innerCheckDs);
//        return stringRestMessage;
//    }
//
//    @Override
//    public RestMessage<InnerCheckConfirmCheckVO> confirmCheck(CheckConfirmDTO checkConfirmDTO) {
//        InnerCheckConfirmCheckVO result = new InnerCheckConfirmCheckVO();
//        result.setIsComplete(0);
//        //如果运单号为空，则返回全部复核完成
//        if(StringUtils.isBlank(checkConfirmDTO.getShipBillNo())){
//            result.setIsComplete(1);
//        }else {
//            List<BarcodeHDO> lclNoList = barcodeHMapper.getLclNo(checkConfirmDTO.getShipBillNo(), checkConfirmDTO.getStationCode(), null, '0', null);
//            if(lclNoList != null && lclNoList.size() > 0){
//                result.setMsg("同票号（运单号）\\订单中还有未内复核的周转筐，请确认封箱或者继续等待");
//            }else {
//                result.setIsComplete(1);
//            }
//
//        }
//        //
//        if(result.getIsComplete() == 1){
//            containerCheckConfirm(checkConfirmDTO);
//        }
//        return RestMessage.doSuccess(result);
//    }
//
//    @Override
//    public LclVO queryLcl(
//            String shipBillNo,
//            String stationCode,
//            PickTaskH pickTaskH,
//            String lclNo,
//            String containerCode,
//            Integer isDoubleCheck,
//            List<BaseMtlItemMst> itemList
//    ) {
//        UserDTO userDTO = userTemplate.getUserDTO();
//        String checkerNo= (isDoubleCheck!=null && isDoubleCheck==0 && !StringUtils.isBlank(containerCode))? userDTO.getUserBizModel().getEmployeeNo():null;
//        List<BarcodeHDO> lclNos;
//        if(StringUtils.isBlank(shipBillNo)){
//            lclNos = barcodeHMapper.getLclNoV2(shipBillNo, stationCode, pickTaskH.getBillGroupId(), null,checkerNo);
//        }else {
//            lclNos = barcodeHMapper.getLclNoV2(shipBillNo,null, null, null,checkerNo);
//        }
//
//        List<InnerCheckTaskDV2VO> dBInnerCheckTaskDVOs = pickTaskDMapper.getPickTaskdAndWareHouseV2(pickTaskH.getPickTaskId(),false,null);
//        Map<String, List<InnerCheckTaskDV2VO>> collectMap = dBInnerCheckTaskDVOs.stream().collect(Collectors.groupingBy(InnerCheckTaskDV2VO::getPickTaskDId));
//
//        if (lclNos.isEmpty()) {
//            log.info("当前订单暂无拼箱");
//            return null;
//        }
//        List<BarCodeHVO> collect = lclNos.stream().map(this::getLclVo).collect(Collectors.toList());
//        Set<String> pickTaskDIdSet=new HashSet<>();
//        for (int i = 0; i < collect.size(); i++) {
//            BarCodeHVO barCodeHVO=collect.get(i);
//            for (int j = 0; j < barCodeHVO.getBarcodeDList().size(); j++) {
//                BarCodeDVO barCodeDVO = barCodeHVO.getBarcodeDList().get(j);
//                pickTaskDIdSet.add(barCodeDVO.getPickTaskDId());
//                if(itemList!=null && itemList.size()>0){
//                    for (int k = 0; k < itemList.size(); k++) {
//                        BaseMtlItemMst waveItemInfoVO = itemList.get(k);
//                        if(barCodeDVO.getItemId().equals(waveItemInfoVO.getItemId())){
//                            barCodeDVO.setItemName(waveItemInfoVO.getItemName());
//                            barCodeDVO.setBatchNum(collectMap.get(barCodeDVO.getPickTaskDId())==null?"":collectMap.get(barCodeDVO.getPickTaskDId()).get(0).getBatchNum());
//                            List<BaseMtlItemUomConversions> uomList = waveItemInfoVO.getBaseMtlItemUomConversionsList();
//                            if(uomList!=null && uomList.size()>0){
//                                barCodeDVO.setCaseConversionRate(uomList.get(0).getConversionRate());
//                            }
//                        }
//                    }
//                }
//            }
//        }
//        LclVO lclVO = new LclVO();
//        lclVO.setLcls(collect);
//        List<BarCodeDVO> caseBarcodeDList=new ArrayList<>();
//        List<BarCodeHVO> pieceBarCodeHVOList=new ArrayList<>();
//        List<PickTaskD> list=pickTaskDMapper.findByIds(PickTaskD.class, pickTaskDIdSet.toArray(), null);
//
//        for (int i = 0; i < collect.size(); i++) {
//            BarCodeHVO barCodeHVO = collect.get(i);
//            List<BarCodeDVO> barcodeDList = barCodeHVO.getBarcodeDList();
//            for (int j = 0; j < barcodeDList.size(); j++) {
//                BarCodeDVO barCodeDVO = barcodeDList.get(j);
//                PickTaskD d = list.stream().filter(t->t.getPickTaskDId().equals(barCodeDVO.getPickTaskDId())).
//                        findFirst().orElse(null);
//                if(d!=null){
//                    barCodeDVO.setPrintCount(d.getPrintCount());
//                    if(barCodeDVO.getCaseConversionRate() != null && barCodeDVO.getCaseConversionRate().compareTo(new BigDecimal(0)) != 0){
//                        barCodeDVO.setUomQty(barCodeDVO.getQty().divide(barCodeDVO.getCaseConversionRate(),BigDecimal.ROUND_DOWN));
//                    }
//                }
//            }
//            caseBarcodeDList.addAll(barcodeDList);
//        }
//        BarCodeHVO barCodeHVO=new BarCodeHVO();
//        BeanUtils.copyProperties(collect.get(0), barCodeHVO);
//        barCodeHVO.setBarcode(null);
//        barCodeHVO.setBarcodeDList(caseBarcodeDList);
//        List<BarCodeHVO> retCollect=new ArrayList<>();
//        retCollect.add(barCodeHVO);
//        retCollect.addAll(pieceBarCodeHVOList);
//        lclVO.setLcls(retCollect);
//        lclVO.setCurrLclNo(barCodeHVO.getLclNo());
//        return lclVO;
//    }
//
//    public InnerCheckBillV2VO findPickupByContainerFunc(String containerCode, String stationCode, String pickTaskDId,
//                                                        String billGroupId, String lclNo, Integer isDoubleCheck) {
//        AssertUtils.isNotBlank(stationCode, "入参复核台不能为空");
//        AssertUtils.isNotBlank(containerCode, "入参容器号不能为空");
//        Criteria crt = Criteria.forClass(PickTaskH.class);//查询未复核完成的容器
//        Restriction r1 = Restrictions.in("status", new String[]{"0", "1", "2", "3"});
//        Restriction r2 = Restrictions.eq("containerCode", containerCode);
//        Restriction r3 = Restrictions.or(Restrictions.isnull("stationCode"),
//                Restrictions.in("stationCode",new String[]{"-1",stationCode}));
//        //使用or实现，业务设计，只能查出一个pick_task_h
//        crt.setRestriction(Restrictions.and(r1, r2, r3));
//
//        List<PickTaskH> pckTaskHs = pickTaskHMapper.findByCriteria(crt);
//        if (pckTaskHs.isEmpty()) {
//            throw new BizException("找不到对应容器任务");
//        } else if (pckTaskHs.size() > 1) {
//            throw new BizException("容器绑定错误，该容器绑定了多个未完成任务");
//        }
//        PickTaskH pckTaskH=pckTaskHs.get(0);
//        String pickTaskHId=pckTaskH.getPickTaskId();
//        String stationCodeDb = pckTaskH.getStationCode();
//        //分支代码，本次不优化
//        if(StringUtils.isBlank(stationCodeDb) || "-1".equals(stationCodeDb)){//机动复核台逻辑
//            WhWorkstationQueryVO workstationQueryVO=new WhWorkstationQueryVO();
//            workstationQueryVO.setWarehouseId(pckTaskH.getWarehouseId());
//            workstationQueryVO.setCode(stationCode);//条件没生效，后续优化
//            RestMessage<List<BaseWmsWhWorkstation>> rest=warehouseResource.queryList(workstationQueryVO);
//            MapToolKit tempStation = MapUtils.put("stationCode", stationCode);
//            if (rest.isSuccess() && rest.getData()!=null){
//                BaseWmsWhWorkstation vo=rest.getData().stream().filter(t->t.getStationCode().
//                        equals(stationCode)).findFirst().orElse(null);
//                if(vo!=null){
//                    tempStation.put("stationId",vo.getStationId());
//                    tempStation.put("stationName",vo.getStationName());
//                }
//            }
//            pickTaskHMapper.updateMapById(pickTaskHId,tempStation.getMap(),PickTaskH.class);
//        }
//
//        boolean showLcl=false;
//        if(pckTaskH.getPickTaskType()!=3){
//            Criteria cr1 = Criteria.forClass(PickTaskD.class);
//            //明细流程状态：1-生成拣货任务 2-拣货已索取 3-拣货已确认 4-内复核已索取 5-内复核已确认 6-外复核已索取 7-外复核已确认 8-拣货冲红
//            cr1.restrictionBuilder().eq("pickTaskId", pickTaskHId).in("flowStatus",new String[]{"1","2","3","4"});
//            cr1.buildRestriction();
//            if(pickTaskDMapper.findCountByCriteria(cr1)==0L){
//                showLcl=true;
//            }
//        }
//        List<InnerCheckTaskDV2VO> dBInnerCheckTaskDVOs = pickTaskDMapper.getPickTaskdV2(pickTaskHId,showLcl);
//        Criteria redCrt = Criteria.forClass(SaleRedRecord.class);
//        redCrt.restrictionBuilder().in("pickTaskDId",
//                dBInnerCheckTaskDVOs.stream().map(t->t.getPickTaskDId()).distinct().toArray());
//        redCrt.buildRestriction();
//        List<SaleRedRecord> saleRedRecords=saleRedRecordMapper.findByCriteria(redCrt);
//        dBInnerCheckTaskDVOs = dBInnerCheckTaskDVOs.stream().filter(x -> x.getPickQty() != null).collect(Collectors.toList());
//        String redisKey = "wms:innerCheck:" + pickTaskHId;
//        Map redisMap =(Map) redisTemplate.opsForValue().get(redisKey);
//        InnerCheckBillV2VO innerCheckBillVO=new InnerCheckBillV2VO();
//        innerCheckBillVO.setStationCode(stationCode);
//        List<BaseMtlItemMst> itemList =null;
//        if(redisMap !=null){
//            innerCheckBillVO=JSON.parseObject(redisMap.get("vo").toString(),InnerCheckBillV2VO.class);
//            itemList= JSON.parseArray(redisMap.get("items").toString(),BaseMtlItemMst.class);
//            for (int i = 0; i < dBInnerCheckTaskDVOs.size(); i++) {
//                InnerCheckTaskDV2VO dBInnerCheckTaskDV2VO = dBInnerCheckTaskDVOs.get(i);
//                String tempPickTaskDId= dBInnerCheckTaskDV2VO.getPickTaskDId();
//                InnerCheckTaskDV2VO redisInnerCheckTaskDV2VO=innerCheckBillVO.getInnerCheckTaskDVOS().stream().
//                        filter(t->t.getPickTaskDId().equals(tempPickTaskDId)).findFirst().orElse(null);
//                if(redisInnerCheckTaskDV2VO!=null){
//                    dBInnerCheckTaskDV2VO.setIsSupervise(redisInnerCheckTaskDV2VO.getIsSupervise());
//                    //dBInnerCheckTaskDV2VO.setNoSuperviseReason(redisInnerCheckTaskDV2VO.getNoSuperviseReason());
//                    dBInnerCheckTaskDV2VO.setSalespersonName(redisInnerCheckTaskDV2VO.getSalespersonName());
//                    dBInnerCheckTaskDV2VO.setPaymentType(redisInnerCheckTaskDV2VO.getPaymentType());
//                    dBInnerCheckTaskDV2VO.setCreateby(redisInnerCheckTaskDV2VO.getCreateby());
//                    dBInnerCheckTaskDV2VO.setRemark(redisInnerCheckTaskDV2VO.getRemark());
//                    dBInnerCheckTaskDV2VO.setShipperId(redisInnerCheckTaskDV2VO.getShipperId());
//                    dBInnerCheckTaskDV2VO.setConsignorId(redisInnerCheckTaskDV2VO.getConsignorId());
//                    dBInnerCheckTaskDV2VO.setBillCode(redisInnerCheckTaskDV2VO.getBillCode());
//                    dBInnerCheckTaskDV2VO.setBillType(redisInnerCheckTaskDV2VO.getBillType());
//                    dBInnerCheckTaskDV2VO.setCargoOwnerName(redisInnerCheckTaskDV2VO.getCargoOwnerName());
//                    dBInnerCheckTaskDV2VO.setSrcId(redisInnerCheckTaskDV2VO.getSrcId());
//                }
//                extractedItem(itemList, dBInnerCheckTaskDV2VO);
//            }
//        } else {
//            innerCheckBillVO.setWarehouseId(pckTaskH.getWarehouseId());
//            innerCheckBillVO.setPickTaskHId(pickTaskHId);
//            innerCheckBillVO.setBillGroupId(pckTaskH.getBillGroupId());
//            innerCheckBillVO.setContainerCode(containerCode);
//            Criteria cr = Criteria.forClass(WaveBillDO.class);
//            Restriction restriction = Restrictions.in("id", dBInnerCheckTaskDVOs.stream().map(t->t.getBillId()).
//                    distinct().collect(Collectors.toList()));
//            cr.setRestriction(restriction);
//            List<WaveBillDO> billHList =billMapper.findByCriteria(cr);
//            if(billHList!=null && billHList.size()>0){
//                WaveBillDO waveBillDO = billHList.get(0);
//                innerCheckBillVO.setShipperId(waveBillDO.getShipperId());
//                innerCheckBillVO.setShipperName(waveBillDO.getShipperName());
//                innerCheckBillVO.setConsignorId(waveBillDO.getConsignorId());
//                innerCheckBillVO.setConsignorName(waveBillDO.getConsignorName());
//                innerCheckBillVO.setBillCode(waveBillDO.getSrcCode());
//                innerCheckBillVO.setBillType(waveBillDO.getType());
//            }
//
//            //查询运单号
//            List<WaveBillDDO> billDDOS = billDMapper.findByMap(MapUtils.put("mergedBillId", pckTaskH.getBillGroupId()).getMap(),
//                    WaveBillDDO.class);
////            Criteria criteria = Criteria.forClass(WaveBillDDO.class);
////            Restriction restriction1 = Restrictions.eq("merged_bill_id", pckTaskH.getBillGroupId());
////            criteria.setRestriction(Restrictions.and(restriction1));
////            List<WaveBillDDO> billDDOS = billDMapper.findByCriteria(criteria);
//            if(billDDOS != null && billDDOS.size() > 0){
//                innerCheckBillVO.setShipBillNo(billDDOS.get(0).getShipBillNo());
//            }
//            //此sql优化，次优先级
//            // 根据id查询商品批次信息，用来获取有效期
//            Set<String> itemIdSet=dBInnerCheckTaskDVOs.stream().map(t->t.getItemId()).collect(Collectors.toSet());
//            if(itemIdSet!=null && itemIdSet.size()>0 && !StringUtils.isBlank(itemIdSet.iterator().next())){
//                itemList=itemClient.getListByIds(itemIdSet).getData();
//            }
//            for (int i = 0; i < dBInnerCheckTaskDVOs.size(); i++) {
//                InnerCheckTaskDV2VO innerCheckTaskDVO = dBInnerCheckTaskDVOs.get(i);
//                if (billHList != null && billHList.size() > 0) {
//                    WaveBillDO bill = billHList.stream().filter(t->t.getId().equals(innerCheckTaskDVO.getBillId())).findFirst().orElse(null);
//                    if(bill!=null){
//                        innerCheckTaskDVO.setSalespersonName(bill.getSalesPersonName());
//                        innerCheckTaskDVO.setPaymentType(bill.getPaymentDayType());
//                        innerCheckTaskDVO.setCreateby(bill.getCreateBy());
//                        innerCheckTaskDVO.setRemark(bill.getRemark());
//                        innerCheckTaskDVO.setShipperId(bill.getShipperId());
//                        innerCheckTaskDVO.setConsignorId(bill.getConsignorId());
//                        innerCheckTaskDVO.setBillCode(bill.getSrcCode());
//                        innerCheckTaskDVO.setBillType(bill.getType());
//                        innerCheckTaskDVO.setCargoOwnerName(bill.getConsignorName());
//                    }
//                }
//                extractedItem(itemList, innerCheckTaskDVO);
//            }
//            //扫码监管码必须要传参数：货主+客户+商品，顺序必须在后
//            //阶段：0=入库质检 1=PC拣货 2=PC内复核 3=PC外复核 4=补录 5=PDA拣货 6=PDA内复核 7=PDA外复核
//            if(dBInnerCheckTaskDVOs!=null && dBInnerCheckTaskDVOs.size()>0){
//                try {
//                    RestMessage<List<? extends IsSuperviseDTO>> rest = inBoundClient.isSupervise(dBInnerCheckTaskDVOs, 2);
//                    if (rest.isSuccess() && rest.getData() != null && rest.getData().size() == dBInnerCheckTaskDVOs.size()) {
//                        for (int i = 0; i < rest.getData().size(); i++) {
//                            BeanUtils.copyProperties(rest.getData().get(i), dBInnerCheckTaskDVOs.get(i));
//                        }
//                    }
//                } catch (Exception e) {
//                    log.error("调用监管码接口异常", e);
//                }
//            }
//        }
//        innerCheckBillVO.setInnerCheckTaskDVOS(dBInnerCheckTaskDVOs);
//        if (pickTaskDId != null) {
//            innerCheckBillVO.setCurrentCheckId(pickTaskDId);
//        }else{
//            if(!"3".equals(pckTaskH.getStatus())){
//                pickTaskHMapper.updateMapById(pickTaskHId, MapUtils.put("status", "3").getMap(), PickTaskH.class);
//                updateFlowStatus(pickTaskHId, 4);
//            }
//        }
//
//        InnerCheckContainerVO containerVO = new InnerCheckContainerVO();
//        Set totalItemSet =new HashSet();
//        Set checkedItemSet =new HashSet();
//        Set totalLotNoSet= new HashSet();
//        Set checkedLotNoSet = new HashSet();
//        BigDecimal redNum = BigDecimal.ZERO;
//        BigDecimal totalNum=BigDecimal.ZERO;
//        BigDecimal checkedNum=BigDecimal.ZERO;
//        Set set=new HashSet();
//        for (int i = 0; i < dBInnerCheckTaskDVOs.size(); i++) {
//            InnerCheckTaskDV2VO innerCheckTaskDVO = dBInnerCheckTaskDVOs.get(i);
//            List<SaleRedRecord> subRedList = saleRedRecords.stream().filter(t -> t.getPickTaskDId().
//                    equals(innerCheckTaskDVO.getPickTaskDId())).collect(Collectors.toList());
//            innerCheckTaskDVO.setRedQty(subRedList.stream().map(t->t.getQty()).reduce(BigDecimal.ZERO, BigDecimal::add));
//            innerCheckTaskDVO.setRedReason(subRedList.stream().filter(t->!StringUtils.isBlank(t.getReason())).
//                    map(t->t.getReason()).collect(Collectors.joining("|")));
//
//            //计算容器信息
//            //1.总品种
//            totalItemSet.add(innerCheckTaskDVO.getItemId());
//            //2.已经检查的品种数量
//            if(isChecked(innerCheckTaskDVO)){
//                checkedItemSet.add(innerCheckTaskDVO.getItemId());
//                if(!StringUtils.isBlank(innerCheckTaskDVO.getLotNo())){
//                    checkedLotNoSet.add(innerCheckTaskDVO.getLotNo());
//                }
//
//            }
//            //4.合计批号
//            if(!StringUtils.isBlank(innerCheckTaskDVO.getLotNo())){
//                totalLotNoSet.add(innerCheckTaskDVO.getLotNo());
//            }
//            //5.订单红冲数量
//            if(innerCheckTaskDVO.getRedQty() != null){
//                redNum = redNum.add(innerCheckTaskDVO.getRedQty());
//            }
//
//            if(!set.contains(innerCheckTaskDVO.getPickTaskDId())){
//                BigDecimal pickQty = innerCheckTaskDVO.getPickQty();
//                totalNum=totalNum.add(pickQty ==null?BigDecimal.ZERO: pickQty);
//                if(isChecked(innerCheckTaskDVO)){
//                    if(StringUtils.isBlank(innerCheckTaskDVO.getChecker2())){
//                        checkedNum=checkedNum.add(innerCheckTaskDVO.getCheckQty());
//                    }else{
//                        checkedNum=checkedNum.add(innerCheckTaskDVO.getCheck2Qty());
//                    }
//                }
//                set.add(innerCheckTaskDVO.getPickTaskDId());
//            }
//
//        }
//        innerCheckBillVO.setInnerCheckTaskDVOS(dBInnerCheckTaskDVOs);
//        containerVO.setTotalVarieties(totalItemSet.size());
//        containerVO.setCheckedVarieties(checkedItemSet.size());
//        containerVO.setUnCheckedVarieties(containerVO.getTotalVarieties()-containerVO.getCheckedVarieties());
//        containerVO.setTotalLot(totalLotNoSet.size());
//        containerVO.setCheckedLot(checkedLotNoSet.size());
//        containerVO.setUnCheckedLot(containerVO.getTotalLot()-containerVO.getCheckedLot());
//        containerVO.setRedNum(redNum);
//        containerVO.setTotalNum(totalNum);
//        containerVO.setCheckedNum(checkedNum);
//        BigDecimal unCheckedNum = totalNum.subtract(checkedNum).subtract(redNum);
//        containerVO.setUnCheckedNum(unCheckedNum);
//        innerCheckBillVO.setContainerInfo(containerVO);
//
//        //查询未复核完成的容器
//        Criteria crt1 = Criteria.forClass(PickTaskH.class);
//        Restriction r11 = Restrictions.in("status", new String[]{"0", "1"});
//        Restriction r21 = Restrictions.eq("billGroupId", innerCheckBillVO.getBillGroupId());
//        crt1.setRestriction(Restrictions.and(r11, r21));
//        containerVO.setOrderUncheckedTaskNum(pickTaskHMapper.findCountByCriteria(crt1));
//        if("3".equals(pckTaskH.getStatus())){
//            innerCheckBillVO.setLclVO(queryLcl(innerCheckBillVO.getShipBillNo(),stationCode, pckTaskH, lclNo, containerCode, isDoubleCheck,itemList));
//        }
//        if(redisMap ==null){
//            Map map=new HashMap();
//            map.put("vo", JSON.toJSONString(innerCheckBillVO));
//            map.put("items",JSON.toJSONString(itemList));
//            redisTemplate.opsForValue().set(redisKey,map,60, TimeUnit.MINUTES);
//        }
//        return innerCheckBillVO;
//    }
//
//    private void extractedItem(List<BaseMtlItemMst> itemList, InnerCheckTaskDV2VO innerCheckTaskDVO) {
//        if(itemList==null){
//            return;
//        }
//        BaseMtlItemMst baseMtlItemMst= itemList.stream().filter(t->t.getItemId().equals(innerCheckTaskDVO.getItemId())).
//                findFirst().orElse(null);
//        if(baseMtlItemMst!=null){
//            innerCheckTaskDVO.setItemCode(baseMtlItemMst.getItemCode());
//            innerCheckTaskDVO.setItemName(baseMtlItemMst.getItemName());
//            innerCheckTaskDVO.setItemAssistantCode(baseMtlItemMst.getItemAssistantCode());
//            innerCheckTaskDVO.setSpecification(baseMtlItemMst.getSpecification());
//            innerCheckTaskDVO.setCountryOriginId(baseMtlItemMst.getCountryOriginId());
//            innerCheckTaskDVO.setManufacturerId(baseMtlItemMst.getManufacturerId());
//            innerCheckTaskDVO.setCaseBarcode(baseMtlItemMst.getCaseBarcode());
//            innerCheckTaskDVO.setPieceBarcode(baseMtlItemMst.getPieceBarcode());
//            BaseMtlItemWms baseMtlItemWms = baseMtlItemMst.getBaseMtlItemWms();
//            if(baseMtlItemWms!=null){
//                innerCheckTaskDVO.setIsCaseOrPiece(baseMtlItemWms.getIsCaseOrPiece());
//                innerCheckTaskDVO.setIsHosted(baseMtlItemWms.getIsHosted());
//                innerCheckTaskDVO.setItemIsFragile(baseMtlItemWms.getItemIsFragile());
//                innerCheckTaskDVO.setItemIsRecheck(baseMtlItemWms.getItemIsRecheck());
//                innerCheckTaskDVO.setItemIsValuable(baseMtlItemWms.getItemIsValuable());
//            }
//            BaseMtlItemHealth baseMtlItemHealth = baseMtlItemMst.getBaseMtlItemHealth();
//            if(baseMtlItemHealth!=null){
//                innerCheckTaskDVO.setIsCheck(baseMtlItemHealth.getIsCheck());
//                innerCheckTaskDVO.setIsDelegate(baseMtlItemHealth.getIsDelegate());
//                innerCheckTaskDVO.setItemHealthApprovalNbr(baseMtlItemHealth.getItemHealthApprovalNbr());
//                innerCheckTaskDVO.setItemHealthListedLicensor(baseMtlItemHealth.getItemHealthListedLicensor());
//                innerCheckTaskDVO.setItemHealthProduceLicense(baseMtlItemHealth.getItemHealthProduceLicense());
//                innerCheckTaskDVO.setItemHealthIsDouble(baseMtlItemHealth.getItemHealthIsDouble().toString());
//                innerCheckTaskDVO.setItemHealthRecordNbr(baseMtlItemHealth.getItemHealthRecordNbr());
//                innerCheckTaskDVO.setItemHealthRegisterNbr(baseMtlItemHealth.getItemHealthRegisterNbr());
//                innerCheckTaskDVO.setItemHealthCategoryName(baseMtlItemHealth.getItemHealthCategoryName());
//                innerCheckTaskDVO.setIsBacteria(baseMtlItemHealth.getIsBacteria());
//            }
//            List<BaseMtlItemUomConversions> uomList = baseMtlItemMst.getBaseMtlItemUomConversionsList();
//            if(uomList!=null && uomList.size()>0){
//                innerCheckTaskDVO.setBarCode(uomList.get(0).getBarcode());
//                innerCheckTaskDVO.setBarcodeOld(uomList.get(0).getBarcodeOld());
//            }
//            BaseMtlItemProfiles baseMtlItemProfiles = baseMtlItemMst.getBaseMtlItemProfiles();
//            if(baseMtlItemProfiles!=null){
//                innerCheckTaskDVO.setErpItemBarcode(baseMtlItemProfiles.getErpItemBarcode());
//            }
//        }
//    }
//
//    private boolean isChecked(InnerCheckTaskDV2VO pickTask) {
//        BigDecimal redQty = Optional.ofNullable(pickTask.getRedQty()).orElse(BigDecimal.ZERO);
//        BigDecimal pickQty = Optional.ofNullable(pickTask.getPickQty()).orElse(BigDecimal.ZERO);
//        if ("1".equals(pickTask.getItemHealthIsDouble())) {
//            BigDecimal checkQty2 = Optional.ofNullable(pickTask.getCheck2Qty()).orElse(BigDecimal.ZERO);
//            boolean equals = checkQty2.add(redQty).equals(pickQty);
//            if (!equals) {
//                return false;
//            }
//        }
//        BigDecimal checkQty = Optional.ofNullable(pickTask.getCheckQty()).orElse(BigDecimal.ZERO);
//        boolean equals = checkQty.add(redQty).equals(pickQty);
//        return equals;
//    }
//
//    private BarCodeHVO getLclVo(BarcodeHDO lcl) {
//        BarCodeHVO barCodeHVO = new BarCodeHVO();
//        BeanUtils.copyProperties(lcl, barCodeHVO);
//        String barcodeId = lcl.getId();
//        List<BarCodeDDO> barCodeDDOS = barcodeDMapper.findByMap(MapUtils.put("barcodeId", barcodeId).getMap(),
//                BarCodeDDO.class);
//        List<BarCodeDVO> barCodeDVOs = barCodeDDOS.stream().filter(p -> p.getQty()!=null && p.getQty().compareTo(BigDecimal.ZERO)>0).
//                map(barCodeDDO -> {
//                    BarCodeDVO barCodeDVO = new BarCodeDVO();
//                    barCodeDVO.setBarcodeDId(barCodeDDO.getId());
//                    barCodeDVO.setPickTaskDId(barCodeDDO.getWmsPickTaskDId());
//                    barCodeDVO.setContainerCode(barCodeDDO.getContainerCode());
//                    BeanUtils.copyProperties(barCodeDDO, barCodeDVO);
//                    barCodeDVO.setPrintCount(lcl.getPrintCount());
//                    return barCodeDVO;
//                }).collect(Collectors.toList());
//        barCodeHVO.setBarcodeDList(barCodeDVOs);
//        return barCodeHVO;
//    }
//
//    private void updateFlowStatus(String pickTaskId, int flowStatus) {
//        Criteria crt = Criteria.forClass(PickTaskD.class);
//        Restriction r1 = Restrictions.eq("pickTaskId", pickTaskId);
//        Restriction r2 = Restrictions.eq("enterpriseId", userTemplate.getUserDTO().getEnterpriseId());
//        crt.setRestriction(Restrictions.and(r1, r2));
//        pickTaskDMapper.updateMapByCriteria(MapUtils.put("flowStatus", flowStatus).getMap(), crt);
//    }
//
//
//
//
//    @FuncImpl(name = "红冲校验", func = ValidRedFunc.class, description = "红冲校验")
//    public void validRedFunc(CheckMakeRedDTO redDTO,PickTaskD pickTaskD,PickTaskH pickTaskH) {
//        String billId = redDTO.getBillId();
//        String srcId = redDTO.getSrcId();
//        String billDId = redDTO.getBillDId();
//        String srcLineId = redDTO.getSrcLineId();
//        String reason = redDTO.getRedReason();
//        BigDecimal redQty = redDTO.getRedQty();
//        String pickTaskDId = redDTO.getPickTaskDId();
//        String stationCode = redDTO.getStationCode();
//        String containerCode = redDTO.getContainerCode();
//        //设置srcId;
//        PickTaskD pickTaskDInfo = pickTaskDMapper.findById(pickTaskDId, PickTaskD.class);
//        PickTaskH pickTaskHInfo = pickTaskHMapper.findById(pickTaskDInfo.getPickTaskId(), PickTaskH.class);
//        List<WaveBillDO> billDOs = billMapper.findByMap(MapUtils.put("billGroupId", pickTaskHInfo.getBillGroupId()).getMap(), WaveBillDO.class);
//        WaveBillDDO billDDO = billDMapper.findById(billDId, WaveBillDDO.class);
//        if(billDDO != null){
//            srcLineId = billDDO.getSrcLineId();
//            redDTO.setSrcLineId(srcLineId);
//        }
//
//        if(CollectionUtil.isNotEmpty(billDOs)){
//            Map<String, Object> map = MapUtils.put("lineid", srcLineId).getMap();
//            List<OmsDoBillDDO> omsDoBillDDOS = omsDoBillDMapper.findByMap(map, OmsDoBillDDO.class);
//            if(CollectionUtil.isNotEmpty(omsDoBillDDOS)){
//                srcId = omsDoBillDDOS.get(0).getBillid();
//            }
//            redDTO.setSrcId(srcId);
//        }
//
//        AssertUtils.isNotNull(billId, billDId, srcId,srcLineId, containerCode, stationCode, pickTaskDId);
//        log.debug("冲红操作，原订单id 时 {}  ,订单行id={}", srcId, srcLineId);
//        BeanUtils.copyProperties(pickTaskDInfo,pickTaskD);
//        BeanUtils.copyProperties(pickTaskHInfo,pickTaskH);
//        List<BarCodeDDO> dList = barcodeDMapper.findByMap(MapUtils.put("wmsPickTaskDId", pickTaskDId).put("isPiece", 0).getMap(), BarCodeDDO.class);
//        if (pickTaskH.getPickTaskType()==2 && dList.size() > 0){
//            throw new BizException("整件拆分后不能红冲！");
//        }
//        if(pickTaskH!=null && pickTaskH.getPickTaskType()==3 && pickTaskD.getPickTaskType()==0){//整单拣选
//            //WaveBillDDO billDDO = billDMapper.findById(billDId, WaveBillDDO.class);
//            BigDecimal[] results = redQty.divideAndRemainder(billDDO.getCaseConversionRate());
//            if(results[1].compareTo(BigDecimal.ZERO)!=0){
//                throw new BizException("整件不能红冲零散件！");
//            }
//        }
//    }
//
//
//    @FuncImpl(name = "红冲", func = RedFunc.class, description = "红冲")
//    public RestMessage<InnerCheckBillV2VO> redFunc(CheckMakeRedDTO redDTO,PickTaskD pickTaskD,PickTaskH pickTaskH) {
//        String billId = redDTO.getBillId();
//        String srcId = redDTO.getSrcId();
//        String billDId = redDTO.getBillDId();
//        String srcLineId = redDTO.getSrcLineId();
//        String reason = redDTO.getRedReason();
//        BigDecimal redQty = redDTO.getRedQty();
//        String pickTaskDId = redDTO.getPickTaskDId();
//        String stationCode = redDTO.getStationCode();
//        String containerCode = redDTO.getContainerCode();
//        UserDTO userDTO = userTemplate.getUserDTO();
//        //内复核冲红
//        SaleRedRecord saleRedRecord = new SaleRedRecord();
//        saleRedRecord.setSrcLineId(srcLineId);
//        saleRedRecord.setBillDId(billDId);
//        saleRedRecord.setBillId(billId);
//        saleRedRecord.setCheckerName(userDTO.getNickname());
//        saleRedRecord.setSrcId(srcId);
//        saleRedRecord.setQty(redQty);
//        String warehouseId = pickTaskH.getWarehouseId();
//        saleRedRecord.setWarehouseId(warehouseId);
//        saleRedRecord.setType(4);
//        saleRedRecord.setReason(redDTO.getRedReason());
//        saleRedRecord.setPickTaskDId(pickTaskDId);
//        ModelUtils.setBaseInfo(saleRedRecord, ModelUtils.OpType.INSERT, userDTO);
//        saleRedRecordMapper.save(saleRedRecord);
//
//        if("5".equals(pickTaskD.getFlowStatus())){//已经商品复核
//            List<SaleRedRecord> redRecords = saleRedRecordMapper.findByMap(
//                    MapUtils.put("pickTaskDId", pickTaskDId).put("type", 4).getMap(), SaleRedRecord.class);
//            if(redRecords!=null && redRecords.size()>0){
//                BigDecimal lineRedQty = redRecords.stream().map(SaleRedRecord::getQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//                BigDecimal subtract = pickTaskD.getPickQty().subtract(lineRedQty);
//                if(subtract.compareTo(BigDecimal.ZERO)<0){
//                    throw new BizException("复核数量不能为负数！");
//                }
//                if(userDTO.getId().equals(pickTaskD.getCheckerId())){
//                    Map<String, Object> map = subtract.compareTo(BigDecimal.ZERO)==0?MapUtils.put("checkQty", subtract).put("flowStatus", 8).getMap():
//                            MapUtils.put("checkQty", subtract).getMap();
//                    pickTaskDMapper.updateMapById(pickTaskDId, map, PickTaskD.class);
//                }else{
//                    Map<String, Object> map = subtract.compareTo(BigDecimal.ZERO)==0?MapUtils.put("checker2Qty", subtract).put("flowStatus", 8).getMap():
//                            MapUtils.put("checker2Qty", subtract).getMap();
//                    pickTaskDMapper.updateMapById(pickTaskDId, map, PickTaskD.class);
//                }
//                Criteria crt = Criteria.forClass(BarCodeDDO.class);
//                Restriction r1 = Restrictions.eq("wmsPickTaskDId", pickTaskDId);
//                crt.setRestriction(Restrictions.and(r1));
//                if(subtract.compareTo(BigDecimal.ZERO)!=0){
//                    barcodeDMapper.updateMapByCriteria(MapUtils.put("qty",subtract).getMap(),crt);
//                }else{
//                    List<BarCodeDDO> list =barcodeDMapper.findByCriteria(crt);
//                    if(list!=null && list.size()==1){
//                        String barcodeId = list.get(0).getBarcodeId();
//                        int count=(int) barcodeDMapper.findCountByMap(MapUtils.put("barcodeId", barcodeId).getMap(), BarCodeDDO.class);
//                        if(count==1){
//                            barcodeHMapper.deleteById(barcodeId,BarcodeHDO.class);
//                        }
//                    }
//                    barcodeDMapper.deleteByCriteria(crt);
//                }
//            }
//        }
//        String locatorId = null;//盘点库货位id
//        Integer redDoMethod = redDTO.getRedDoMethod();
//        //转移到盘点库
//        if(redDoMethod!=null && redDoMethod==1){
//            RestMessage<String> rest =  warehouseResource.getLocatorIdByCategory("PDK", warehouseId);
//            if (!rest.isSuccess() || rest.getData()==null){
//                throw new PrologException("查询盘点库货位出错,或货位为空:"+rest.getMessage());
//            }
//            locatorId = rest.getData();
//        }
//        //生成无计划损溢盘点单
//        //冲红调整库存
//        this.updateStock(billId, billDId, redQty, pickTaskD, locatorId);
//        //该sql等于0标识整单红冲
//        long wholeBillMakeRed = saleRedRecordMapper.isWholeBillMakeRed(srcId);
//
//        //修复有整散，零货任务都红冲了外复核索取不到问题
//        //1表示该TaskH下的明细都红冲了
//        long taskHRed = saleRedRecordMapper.isWholeTaskHRed(pickTaskH.getPickTaskId());
//
//        if (wholeBillMakeRed == 0) {
//            log.info("整单已经被红冲"+srcId);
//            Map<String, Object> isCancelled = MapUtils.
//                    put("isCancelled", 1).put("partlyRed", null).getMap();
//            omsDoBillHMapper.updateMapById(srcId, isCancelled, OmsDoBillHDO.class);
//
//            Criteria cr = Criteria.forClass(WaveBillDO.class);
//            cr.restrictionBuilder().eq("srcId", srcId).eq("isMerged", 1);
//            cr.buildRestriction();
//            if(billMapper.findCountByCriteria(cr)==0L){//不是合单的
//                Criteria crt1 = Criteria.forClass(PickTaskH.class);
//                Restriction r1 = Restrictions.eq("billId", billId);
//                Restriction r2 = Restrictions.eq("warehouseId", warehouseId);
//                Restriction r3 = Restrictions.ne("status", "10");
//                crt1.setRestriction(Restrictions.and(r1, r2,r3));
//                pickTaskHMapper.updateMapByCriteria(MapUtils.put("status","10").getMap(),crt1);
//            }
//
//            //释放容器
//            ContainerQueryVO containerQueryVO = new ContainerQueryVO();
//            containerQueryVO.setContainerCode(containerCode);
//            containerQueryVO.setWarehouseId(warehouseId);
//            warehouseResource.release(containerQueryVO);
//
//            // ERP回传方式写中间表，通过mq立刻通知oms处理，使用 PostBackErpHandle by Huanglh 20220112
////            EtlMessage etlMessage = new EtlMessage();
////            etlMessage.setId(srcId);
////            etlMessage.setEtlType(EtlTypeConstants.out_do_w2o);
////            try {
////                exchangeSender.send(etlMessage);
////            } catch (Exception e) {
////                throw new BizException("内复核红冲变为整单红冲 回传ERP，rabbitmq发送消息失败！");
////            }
//            // 红冲只需要需要判断一个业务配置参数
//            IStrategyHandle strategyHandle = strategySelector.selectHandle(Arrays.asList(
//                    STRATEGY_CODE.POST_BACK_ERP__MQ__ON), userDTO.getEnterpriseId(), warehouseId, "do");
//            strategyHandle.execute(Arrays.asList(srcId), "内复核红冲变为整单红冲 回传ERP，rabbitmq发送消息失败！");
//            return RestMessage.doSuccess(new InnerCheckBillV2VO());
//        }
//        InnerCheckBillV2VO containerInfo = this.findPickupByContainerFunc(containerCode, stationCode, pickTaskDId,
//                null,redDTO.getLclNo(),redDTO.getIsDoubleCheck());
//        if(taskHRed == 1){
//            //更新taskH为10
//            pickTaskHMapper.updateMapById(pickTaskH.getPickTaskId(), MapUtils.put("status", "10").getMap(), PickTaskH.class);
//
//        }
//        return RestMessage.doSuccess(containerInfo);
//    }
//
//
//    //冲红调整库存
//    private void updateStock(String billId, String billDId, BigDecimal redQty, PickTaskD innerCheckDDO,String locatorId) {
//        ValidList<InvStockOut> validList = new ValidList<>();
//        InvStockOut invStockOut = new InvStockOut();
//
//        validList.add(invStockOut);
//        List<InvStockOutDetail> details = new ArrayList<>();
//        InvStockOutDetail detail = new InvStockOutDetail();
//        details.add(detail);
//        invStockOut.setDetails(details);
//
//        invStockOut.setBillId(billId);
//        invStockOut.setLineBillId(billDId);
//        invStockOut.setWarehouseId(innerCheckDDO.getWarehouseId());
//
//        List<WaveStorageDO> storageDOS = storageMapper.getStorageByPickTaskDId(innerCheckDDO.getPickTaskDId());
//        if (storageDOS.size() != 1) {
//            throw new PrologException("找不到对应的库存预占信息");
//        }
//        WaveStorageDO waveStorageDO = storageDOS.get(0);
//        detail.setBatchId(waveStorageDO.getBatchId());
//        detail.setQuantity(redQty);
//        detail.setLocatorId(waveStorageDO.getLocatorId());
//        if(locatorId != null){
//            detail.setExtParams(MapUtils.put("adjustType","2").put("takeLocatorId",locatorId).getMap());
//        }
//        RestMessage restMessage = inventoryResource.redAdjustStock(validList);
//        if (!restMessage.isSuccess()) {
//            log.error("红冲失败： {},请求如下：{} ", restMessage.getMessage(), invStockOut);
//            throw new BizException("红冲失败: " + restMessage.getMessage());
//        }
//
//        // 通过billId查询得到订单数据
//        List<WmsAdjustAddVO> adjustAddVOList = new ArrayList<>();
//        WaveBillDO bill = billMapper.findById(billId, WaveBillDO.class);
//        WaveBillDDO billD = billDMapper.findById(billDId, WaveBillDDO.class);
//        if (null != locatorId) {
//            // 无计划损溢VO
//            WmsAdjustAddVO wmsAdjustAddVO = new WmsAdjustAddVO();
//            wmsAdjustAddVO.setDcId(waveStorageDO.getBldgId());
//            wmsAdjustAddVO.setWarehouseId(waveStorageDO.getWarehouseId());
//            wmsAdjustAddVO.setCargoOwnerId(bill.getConsignorId());
//            wmsAdjustAddVO.setWhLocatorId(locatorId);
//            wmsAdjustAddVO.setItemId(billD.getItemId());
//            wmsAdjustAddVO.setBatchId(billD.getBatchNum());
//            wmsAdjustAddVO.setProductionDate(waveStorageDO.getProductionDate());
//            wmsAdjustAddVO.setBatchExpiredDate(waveStorageDO.getExpiredDate());
//            wmsAdjustAddVO.setQuantity(redQty);
//            wmsAdjustAddVO.setConversionRate(billD.getConversionRate());
//            wmsAdjustAddVO.setBatchNum(billD.getBatchNum());
//            wmsAdjustAddVO.setUom(billD.getCaseUom());
//            wmsAdjustAddVO.setStockStatus(billD.getStockStatus());
//            wmsAdjustAddVO.setAdjustType("1"); // 无计划盘点
//            wmsAdjustAddVO.setManufacturerLotNum(billD.getManufacturerLotNum());
//            wmsAdjustAddVO.setPieceQuantity(redQty); // 损溢数量
//            wmsAdjustAddVO.setPieceAccount(BigDecimal.ZERO);
//            wmsAdjustAddVO.setPieceAccountFact(redQty);
//            wmsAdjustAddVO.setType(1); // 数量调整
//            wmsAdjustAddVO.setIsAdd(1); // 是否是是新增账存(0否1是)
//            wmsAdjustAddVO.setAdjustHeaderId(billId);
//            wmsAdjustAddVO.setAutoBillNum(bill.getSrcCode());
//            adjustAddVOList.add(wmsAdjustAddVO);
//        }
//        if (CollectionUtil.isNotEmpty(adjustAddVOList)) {
//            for (WmsAdjustAddVO wmsAdjustAddVO:adjustAddVOList) {
//                operateResource.saveAdjust(wmsAdjustAddVO);
//            }
//        }
//    }
//
//
//    @FuncImpl(name = "F1复核商品校验", func = ValidInnerCheckFunc.class, description = "F1复核商品校验")
//    public void validInnerCheckFunc(CheckInfoDTO checkInfoDTO, boolean byScan, boolean isByNum,
//                                    boolean redCheck, List<PickTaskD> pickTaskDList, ItemBarCodeVO itemBarCodeVO) {
//        String containerCode = checkInfoDTO.getContainerCode();
//        String stationCode = checkInfoDTO.getStationCode();
//        String billGroupId = checkInfoDTO.getBillGroupId();
//        String warehouseId = checkInfoDTO.getWarehouseId();
//        List<CheckPickTaskDDTO> checkPickTaskDDTOList = checkInfoDTO.getCheckPickTaskDDTOList();
//        AssertUtils.isNotNull(warehouseId,containerCode, stationCode, billGroupId,checkPickTaskDDTOList);
//        List<String> pickTaskDIds = checkPickTaskDDTOList.stream().map(pickTaskD -> pickTaskD.getPickTaskDId()).collect(Collectors.toList());
//
//        List<WaveStorageDO> storageDOS = storageMapper.getStorageByPickTaskDIds(pickTaskDIds);
//        if (storageDOS.size() != pickTaskDIds.size()) {
//            throw new PrologException("对应的库存预占信息不匹配");
//        }
//        WaveStorageDO waveStorageDO = storageDOS.get(0);
//        Set<String> set = new HashSet<>();
//        set.add(waveStorageDO.getItemId());
//        RestMessage<List<BaseMtlItemMst>> listByIds = itemClient.getListByIds(set);
//        if(listByIds == null || !listByIds.isSuccess() || listByIds.getData() == null || listByIds.getData().size() <= 0){
//            throw new ParameterException("该商品信息不存在");
//        }
////        ItemBarCodeVO data = itemClient.getItemByBarCode(checkInfoDTO.getItemBarcode(), waveStorageDO.getItemId()).getData();
////        if (data == null) {
////            throw new ParameterException("该商品信息不存在");
////        }
//        BeanUtils.copyProperties(listByIds.getData().get(0),itemBarCodeVO);
//        //PickTaskD byId = pickTaskDMapper.findById(pickTaskDId, PickTaskD.class);
//        List<PickTaskD> pickTaskDListByIds = pickTaskDMapper.findByIds(PickTaskD.class, pickTaskDIds.toArray(new String[pickTaskDIds.size()]), null);
//        if (pickTaskDIds.size() != pickTaskDListByIds.size() ) {
//            throw new BizException("找不到对应的复核信息,明细数量不匹配");
//        }
//        pickTaskDList.addAll(pickTaskDListByIds);
//
//        Map<String, PickTaskD> pickTaskDMap = pickTaskDListByIds.stream().collect(Collectors.toMap(PickTaskD::getPickTaskDId, Function.identity()));
//        for (CheckPickTaskDDTO checkPickTaskDDTO : checkPickTaskDDTOList) {
//            PickTaskD pickTaskD = pickTaskDMap.get(checkPickTaskDDTO.getPickTaskDId());
//
//            BigDecimal inputQty = checkPickTaskDDTO.getQty();
//            Criteria criteria = Criteria.forClass(SaleRedRecord.class);
//            criteria.restrictionBuilder().eq("pickTaskDId", checkPickTaskDDTO.getPickTaskDId()).eq("type", 4);
//            criteria.buildRestriction();
//            List<SaleRedRecord> redRecords = saleRedRecordMapper.findByCriteria(criteria);
//            if(redRecords!=null && redRecords.size()>0){
//                BigDecimal lineRedQty = redRecords.stream().map(SaleRedRecord::getQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//                BigDecimal allPickQty = pickTaskD.getPickQty();
//                BigDecimal subtract = allPickQty.subtract(lineRedQty);
//                if(subtract.subtract(inputQty) != BigDecimal.ZERO){
//                    throw new BizException("数据异常：复核数量 != 拣货数量-红冲数量, "+checkPickTaskDDTO.getPickTaskDId());
//                }
//            }
//        }
//
//    }
//
//    @FuncImpl(name = "F1商品复核", func = UpdatePickupDInnerCheckInfoFunc.class, description = "F1商品复核")
//    public void updatePickupDInnerCheckInfoFunc(CheckInfoDTO checkInfoDTO,
//                                                boolean byScan, boolean isByNum, boolean redCheck,List<PickTaskD> pickTaskDList, ItemBarCodeVO itemBarCodeVO) {
//        String containerCode = checkInfoDTO.getContainerCode();
//        String stationCode = checkInfoDTO.getStationCode();
//        String billGroupId = checkInfoDTO.getBillGroupId();
//        AssertUtils.isNotNull(containerCode, stationCode, billGroupId);
//        UserDTO userDTO = userTemplate.getUserDTO();
//        String nickName = userDTO.getNickname();
//
//        Map<String, BigDecimal> checkPickTaskDMap = checkInfoDTO.getCheckPickTaskDDTOList().stream().collect(Collectors.toMap(CheckPickTaskDDTO::getPickTaskDId, CheckPickTaskDDTO::getQty));
//        for (PickTaskD pickTaskD : pickTaskDList) {
//            pickTaskD.setCheckTime(new Date());
//            if (checkInfoDTO.getIsDoubleCheck() == 1) {
//                pickTaskD.setCheckerName2(userDTO.getNickname());
//                pickTaskD.setCheckerId2(userDTO.getId());
//                pickTaskD.setCheckerNo2(userDTO.getUserBizModel().getEmployeeNo());
//            } else {
//                pickTaskD.setCheckerName(userDTO.getNickname());
//                pickTaskD.setCheckerId(userDTO.getId());
//                pickTaskD.setCheckerNo(userDTO.getUserBizModel().getEmployeeNo());
//            }
//            BigDecimal inputQty = checkPickTaskDMap.get(pickTaskD.getPickTaskDId());
//            if (isByNum) {
//                spellQty(nickName, pickTaskD, inputQty, checkInfoDTO,itemBarCodeVO);
//            }
//
//            BigDecimal newQty;
//            if (byScan) {
//                Integer isDoubleCheck = checkInfoDTO.getIsDoubleCheck();
//                newQty = itemBarCodeVO.getConversionRate();
//                if (isDoubleCheck == 1) {
//                    newQty = newQty.add(pickTaskD.getCheckQty());
//                } else {
//                    newQty = newQty.add(pickTaskD.getChecker2Qty());
//                }
//                spellQty(nickName, pickTaskD, newQty, checkInfoDTO,itemBarCodeVO);
//            }
//            if(pickTaskD.getChecker2Qty()!=null){
//                if(pickTaskD.getCheckQty()==null || pickTaskD.getCheckQty().compareTo(pickTaskD.getChecker2Qty())<0){
//                    throw new BizException("复核数量异常");
//                }
//            }
//            pickTaskD.setFlowStatus("5");
//            pickTaskDMapper.update(pickTaskD);
//
//
//            if (isByNum && checkInfoDTO.getIsDoubleCheck() != 1) {
//                String itemId = itemBarCodeVO.getItemId();
//                String itemCode = checkInfoDTO.getItemCode();
//                AssertUtils.isNotBlank(itemCode);
//                updateLclD(checkInfoDTO.getShipBillNo(),stationCode, billGroupId, itemCode, itemId, inputQty, containerCode, pickTaskD);
//            }
////
////            if (byScan && checkInfoDTO.getIsDoubleCheck() != 1) {
////                String itemId = itemBarCodeVO.getItemId();
////                String itemCode = itemBarCodeVO.getItemCode();
////                newQty = itemBarCodeVO.getConversionRate();
////                addLclDQty(stationCode, billGroupId, itemCode, itemId, newQty, containerCode, pickTaskD.getPickTaskDId());
////            }
//        }
//    }
//
//    //@FuncImpl(name = "波次创建入参校验", description = "波次创建入参校验")
//    public RestMessage<InnerCheckBillV2VO> createBarcodeFunc(CheckInfoDTO checkInfoDTO, boolean byScan, boolean isByNum, boolean redCheck, List<PickTaskD> pickTaskDList, ItemBarCodeVO itemBarCodeVO){
//        String itemBarcode = checkInfoDTO.getItemBarcode();
//        String containerCode = checkInfoDTO.getContainerCode();
//        String stationCode = checkInfoDTO.getStationCode();
//        String billGroupId = checkInfoDTO.getBillGroupId();
//        String warehouseId = checkInfoDTO.getWarehouseId();
//
//        InnerCheckBillV2VO containerInfo = findPickupByContainerFuncV2(containerCode, stationCode, checkInfoDTO.getCheckPickTaskDDTOList(),
//                billGroupId,checkInfoDTO.getLclNo(),checkInfoDTO.getIsDoubleCheck(),warehouseId);
//        return RestMessage.doSuccess(containerInfo);
//    }
//
//
//    private void spellQty(String nickName,
//                          PickTaskD pickTaskD,
//                          BigDecimal qty,
//                          CheckInfoDTO checkInfoDTO,
//                          ItemBarCodeVO itemByBarCode) {
//        BigDecimal pickQty = pickTaskD.getPickQty();
//        if (pickQty.compareTo(qty) < 0) {
//            throw new BizException("复核数量已经超过拣货数量，请核对");
//        }
////        if (isChecker2(pickTaskD, checkInfoDTO, nickName,itemByBarCode)) {
////            pickTaskD.setCheckerName2(nickName);
////            pickTaskD.setChecker2Qty(qty);
////        } else {
//////            String checker2 = pickTaskD.getCheckerName2();
//////            if (nickName.equals(checker2)) {
//////                log.error("不能同一个人员操作");
//////                throw new BizException("不能同一个人员操作");
//////            }
////            pickTaskD.setCheckQty(qty);
////            pickTaskD.setCheckerName(nickName);
////        }
//        pickTaskD.setCheckQty(qty);
//        pickTaskD.setCheckerName(nickName);
//    }
//
////    private boolean isUserHaveAuthority(String workerCode, String itemCategoryCode, String stationCode, String warehouseId) {
////        WorkgroupVO workgroupVO = new WorkgroupVO();
////        workgroupVO.setItemCategoryCode(itemCategoryCode);
////        workgroupVO.setStationCode(stationCode);
////        workgroupVO.setWorkercode(workerCode);
////        controlResource.checkerAuthorityCheck(workgroupVO);
////
////        return true;
////    }
//
////    private boolean isChecker2(PickTaskD pickTaskD,
////                               CheckInfoDTO checkInfoDTO,
////                               String checkerName,
////                               ItemBarCodeVO itemByBarCode
////    ) {
////        String workerCode = checkInfoDTO.getWorkerCode();
////        String warehouseId = checkInfoDTO.getWarehouseId();
////        String stationCode = checkInfoDTO.getStationCode();
////        Integer needDoubleCheck = itemByBarCode.getItemHealthIsDouble();
////        if(needDoubleCheck==null){
////            throw new BizException("商品资料异常，是否双人复核字段为空");
////        }
////        if (needDoubleCheck != 1) {
////            return false;
////        }
////
////        Integer isDoubleCheck = checkInfoDTO.getIsDoubleCheck();
////        if (isDoubleCheck == 0) {
////            return false;
////        }
////
////        String itemCategoryCode = itemByBarCode.getItemCategoryCode();
////        boolean haveAuthority = isUserHaveAuthority(workerCode, itemCategoryCode, stationCode, warehouseId);
////
////        if (haveAuthority) {
////            String checker1 = pickTaskD.getCheckerName();
////            if (checkerName.equals(checker1)) {
////                log.error("复核员2与复核员1名称相同");
////                throw new BizException("复核员2与复核员1名称相同");
////            }
////            return true;
////        }
////        log.error("该复核员没有权限复核改商品" + workerCode);
////        throw new BizException("复核员没有权限复核该商品");
////    }
//
//    /**
//     * 新增或更新拼箱信息
//     * @param shipBillNo
//     * @param stationCode
//     * @param billGroupId
//     * @param itemCode
//     * @param itemId
//     * @param addQty
//     * @param containerCode
//     * @param pickTaskDId
//     */
//    private void addLclDQty(
//            String shipBillNo,
//            String stationCode,
//            String billGroupId,
//            String itemCode,
//            String itemId,
//            BigDecimal addQty,
//            String containerCode,
//            String pickTaskDId
//    ) {
//        BarcodeHDO barcodeHDO = getDefaultLclNo(shipBillNo,stationCode, billGroupId, containerCode,null);
//        String lclHId = barcodeHDO.getId();
//        updateLclQtyTemp(lclHId, itemCode, itemId ,addQty,  containerCode,
//                pickTaskDId, 1,barcodeHDO.getWarehouseId());
//
//    }
//
//
//    /**
//     * 更新拼箱信息
//     * @param stationCode
//     * @param billGroupId
//     * @param itemCode
//     * @param itemId
//     * @param qty
//     * @param containerCode
//     * @param pickTaskD
//     */
//    private void updateLclD(String shipBillNo,String stationCode, String billGroupId, String itemCode,
//                            String itemId, BigDecimal qty,
//                            String containerCode,
//                            PickTaskD pickTaskD) {
//        BarcodeHDO lclNo = getDefaultLclNo(shipBillNo,stationCode, billGroupId, containerCode,pickTaskD);
//        String lclHId = lclNo.getId();
//        updateLcl(lclHId, itemCode, itemId, qty, containerCode, pickTaskD.getPickTaskDId(),pickTaskD.getPickTaskType(),pickTaskD.getWarehouseId());
//    }
//
//    //获得默认的拼箱
//    private BarcodeHDO getDefaultLclNo(String shipBillNo,String stationCode, String billGroupId, String containerCode, PickTaskD pickTaskD) {
//        if(pickTaskD!=null && pickTaskD.getPickTaskType()==0){//整件生成新的拼箱
//            return lclFunc(shipBillNo,stationCode, billGroupId, containerCode, pickTaskD,0);
//        }
//        List<BarcodeHDO> List;
//        if(StringUtils.isBlank(shipBillNo)){
//            List = barcodeHMapper.getLclNo(null,stationCode, billGroupId, '0',null);
//        }else {
//            List = barcodeHMapper.getLclNo(shipBillNo,null, null, '0',null);
//        }
//        if (List == null || List.isEmpty()) {
//            log.info("找不到合适的拼箱，create one");
//            return lclFunc(shipBillNo,stationCode, billGroupId, containerCode, pickTaskD,1);
//        } else {
//            BarcodeHDO barCodeHDO = List.get(0);
//            return barCodeHDO;
//        }
//    }
//
//    public void updateLcl(String barcodeHId, String itemCode, String itemId, BigDecimal qty,
//                          String containerCode, String pickTaskDId, Integer isPiece, String warehouseId) {
//        List<BarCodeDDO> dList = barcodeDMapper.findByMap(MapUtils.put("wmsPickTaskDId", pickTaskDId).put("barcodeId", barcodeHId).
//                put("containerCode", containerCode).getMap(), BarCodeDDO.class);
//        if (dList.size() > 0){
//            Criteria crt = Criteria.forClass(BarCodeDDO.class);
//            Restriction r1 = Restrictions.in("id", dList.stream().map(BarCodeDDO::getId).toArray(String[]::new));
//            crt.setRestriction(Restrictions.and(r1));
//            barcodeDMapper.updateMapByCriteria(MapUtils.put("qty",qty).getMap(),crt);
//        }else{
//            BarCodeDDO barCodeDDO = new BarCodeDDO();
//            barCodeDDO.setBarcodeId(barcodeHId);
//            barCodeDDO.setWmsPickTaskDId(pickTaskDId);
//            barCodeDDO.setContainerCode(containerCode);
//            barCodeDDO.setId(String.valueOf(SnowFlakeUtils.getId(dataCenterId,machineId)));
//            barCodeDDO.setEnterpriseId(userTemplate.getUserDTO().getEnterpriseId());
//            barCodeDDO.setWarehouseId(warehouseId);
//            barCodeDDO.setItemId(itemId);
//            barCodeDDO.setItemCode(itemCode);
//            barCodeDDO.setQty(qty);
//            barCodeDDO.setIsPiece(isPiece!=null && isPiece==2?1:isPiece);
//            barcodeDMapper.save(barCodeDDO);
//        }
//    }
//
//    public void updateLclQtyTemp(String barcodeHId, String itemCode, String itemId, BigDecimal qty,
//                                 String containerCode, String pickTaskDId, Integer isPiece, String warehouseId) {
//        List<BarCodeDDO> dList = barcodeDMapper.findByMap(MapUtils.put("wmsPickTaskDId", pickTaskDId).put("barcodeId", barcodeHId).
//                put("containerCode", containerCode).getMap(), BarCodeDDO.class);
//        if (dList.size() > 0){
//            for (int i = 0; i < dList.size(); i++) {
//                BarCodeDDO barCodeDDO = dList.get(i);
//                barcodeDMapper.updateMapById(barCodeDDO.getId(),MapUtils.put("qty",qty.add(barCodeDDO.getQty())).getMap(), BarCodeDDO.class);
//            }
//        }else{
//            BarCodeDDO barCodeDDO = new BarCodeDDO();
//            barCodeDDO.setBarcodeId(barcodeHId);
//            barCodeDDO.setWmsPickTaskDId(pickTaskDId);
//            barCodeDDO.setContainerCode(containerCode);
//            barCodeDDO.setId(String.valueOf(SnowFlakeUtils.getId(dataCenterId,machineId)));
//            barCodeDDO.setEnterpriseId(userTemplate.getUserDTO().getEnterpriseId());
//            barCodeDDO.setWarehouseId(warehouseId);
//            barCodeDDO.setItemId(itemId);
//            barCodeDDO.setItemCode(itemCode);
//            barCodeDDO.setQty(qty);
//            barCodeDDO.setIsPiece(isPiece!=null && isPiece==2?1:isPiece);
//            barcodeDMapper.save(barCodeDDO);
//        }
//    }
//
//    @FuncImpl(name = "增加箱子", func = LCLFunc.class, description = "增加箱子")
//    public BarcodeHDO lclFunc(String shipBillNo,String stationCode, String billGroupId, String containerCode, PickTaskD pickTaskD, Integer isPiece) {
////        AtomicInteger startNum = new AtomicInteger();
//        AtomicReference<BarcodeHDO> lclInDB = new AtomicReference<>();
//        try {
//            distributedLock.execute(billGroupId, 3000, () -> {
////                if((pickTaskD!=null && pickTaskD.getPickTaskType()==0) || (isPiece!=null && isPiece==0)){//整件，统一设置拼箱号为0
////                    lclInDB.set(createLclInDB(shipBillNo,stationCode, billGroupId, containerCode,pickTaskD,isPiece));
////                }else{
////                    List<BarcodeHDO> lclNo = barcodeHMapper.getLclNo(shipBillNo,stationCode, billGroupId, null,null);
////                    if (lclNo.isEmpty()) {
////                        startNum.set(1);
////                    } else {
////                        startNum.set(Optional.ofNullable(lclNo.get(0).getLclNo()).orElse(0) + 1);
////                    }
////                    lclInDB.set(createLclInDB(shipBillNo,stationCode, billGroupId, containerCode,null,isPiece));
////                }
//                lclInDB.set(createLclInDB(shipBillNo,stationCode, billGroupId, containerCode,null,isPiece));
//                return true;
//            });
//        } catch (Exception e) {
//            String msg = StringUtils.isBlank(e.getMessage()) ? "执行分布式锁失败" : e.getMessage();
//            log.error(msg,e);
//            throw new BizException(msg, e);
//        }
//        return lclInDB.get();
//    }
//
//    private BarcodeHDO createLclInDB(String shipBillNo,String stationCode, String billGroupId, String containerCode, PickTaskD pickTaskD, Integer isPiece) {
//        Criteria criteria = Criteria.forClass(PickTaskH.class);
//        criteria.restrictionBuilder().eq("billGroupId", billGroupId).eq("containerCode", containerCode).ne("status","10");
//        criteria.buildRestriction();
//        List<PickTaskH> pickTaskHS = pickTaskHMapper.findByCriteria(criteria);
//        if (pickTaskHS.size() != 1) {
//            throw new BizException("找不到对应的容器任务");
//        }
//        PickTaskH pickTaskH = pickTaskHS.get(0);
//        BarcodeHDO barCodeHDO = new BarcodeHDO();
//        barCodeHDO.setWarehouseId(pickTaskH.getWarehouseId());
//        barCodeHDO.setBldgId(pickTaskH.getBldgId());
//        String bldgName = pickTaskH.getBldgName();
//        barCodeHDO.setBldgName(bldgName);
//        UserDTO userDTO = userTemplate.getUserDTO();
//        ModelUtils.setBaseInfo(barCodeHDO, ModelUtils.OpType.INSERT, userDTO);
//        barCodeHDO.setLclNo(UUIDUtils.generateUUID().toString().replaceAll("-",""));
//        barCodeHDO.setShipBillNo(shipBillNo);
//
//        String skidWayCode="";
//        List<WaveBillDO> billDOList = billMapper.findByMap(MapUtils.put("id", pickTaskH.getBillId()).getMap(), WaveBillDO.class);
//        if(billDOList!=null && billDOList.size()>0){
//            OmsDoBillHDO omsDoBillHDO=omsDoBillHMapper.findById(billDOList.get(0).getSrcId(),  OmsDoBillHDO.class);
//            if(omsDoBillHDO!=null && !StringUtils.isBlank(omsDoBillHDO.getLineCode())){
//                RestMessage<List<BaseCommonDict>> rest=commonClient.getDictBasicListByCodes("common_shiplineid",
//                        new String[]{omsDoBillHDO.getLineCode()});
//                if (rest.isSuccess() && rest.getData()!=null && rest.getData().size()>0 && rest.getData().get(0)!=null){
//                    skidWayCode=rest.getData().get(0).getDictDesc();
//                }
//            }
//        }
//        if(pickTaskH.getPickTaskType()==3  && pickTaskD !=null && pickTaskD.getPickTaskType()==0){
//            barCodeHDO.setBarcode(StringUtils.isBlank(skidWayCode)?pickTaskD.getPickTaskDId():skidWayCode+pickTaskD.getPickTaskDId());
//        }else {
//            long id = SnowFlakeUtils.getId(dataCenterId,machineId);
//            barCodeHDO.setBarcode(StringUtils.isBlank(skidWayCode)?String.valueOf(id):skidWayCode+id);
//        }
//
//        //散货箱
//        if(isPiece==null){
//            barCodeHDO.setType("0");
//        }else if(isPiece==0){
//            barCodeHDO.setType("1");
//        }else if(isPiece==1){
//            barCodeHDO.setType("0");
//        }
//        barCodeHDO.setStationCode(stationCode);
//        barCodeHDO.setContainerCode(containerCode);
//        barCodeHDO.setBillGroupId(billGroupId);
//        //未使用状态
//        barCodeHDO.setStatus('0');
//        barcodeHMapper.save(barCodeHDO);
//        return barCodeHDO;
//    }
//
//
//
//    public InnerCheckBillV2VO findPickupByContainerFuncV2(
//            String containerCode,
//            String stationCode,
//            List<CheckPickTaskDDTO> checkPickTaskDDTOList,
//            String billGroupId,
//            String lclNo,
//            Integer isDoubleCheck,
//            String warehouseId
//    ) {
//        Criteria crt = Criteria.forClass(PickTaskH.class);//查询未复核完成的容器
//        Restriction r1 = Restrictions.in("status", new String[]{"0", "1", "2", "3"});
//        Restriction r2 = Restrictions.eq("containerCode", containerCode);
//        Restriction r3 = Restrictions.or(Restrictions.isnull("stationCode"),
//                Restrictions.in("stationCode",new String[]{"-1",stationCode}));
//        Restriction r4 = Restrictions.eq("warehouseId", warehouseId);
//        //使用or实现，业务设计，只能查出一个pick_task_h
//        crt.setRestriction(Restrictions.and(r1, r2, r3,r4));
//        List<PickTaskH> pckTaskHs = pickTaskHMapper.findByCriteria(crt);
//        if (pckTaskHs.isEmpty()) {
//            throw new BizException("没有待复核任务");
//        } else if (pckTaskHs.size() > 1) {
//            throw new BizException("容器绑定错误，该容器绑定了多个未完成任务");
//        }
//        PickTaskH pckTaskH=pckTaskHs.get(0);
//        String pickTaskHId=pckTaskH.getPickTaskId();
//        String stationCodeDb = pckTaskH.getStationCode();
//        //分支代码，本次不优化
//        if(StringUtils.isBlank(stationCodeDb) || "-1".equals(stationCodeDb)){//机动复核台逻辑
//            //查询复核台信息
//            WhWorkstationQueryVO workstationQueryVO = new WhWorkstationQueryVO();
//            workstationQueryVO.setWarehouseId(pckTaskH.getWarehouseId());
//            workstationQueryVO.setCode(stationCode);//条件没生效，后续优化
//            RestMessage<List<BaseWmsWhWorkstation>> rest = warehouseResource.queryList(workstationQueryVO);
//            MapToolKit tempStation = MapUtils.put("stationCode", stationCode);
//            if (rest.isSuccess() && rest.getData()!=null){
//                BaseWmsWhWorkstation vo=rest.getData().stream().filter(t->t.getStationCode().equals(stationCode)).findFirst().orElse(null);
//                if(vo!=null){
//                    tempStation.put("stationId",vo.getStationId());
//                    tempStation.put("stationName",vo.getStationName());
//                }
//            }
//            //写入复核台信息
//            pickTaskHMapper.updateMapById(pickTaskHId,tempStation.getMap(),PickTaskH.class);
//        }
//
//        boolean showLcl = false;
//        if(pckTaskH.getPickTaskType()!=3){
//            Criteria cr1 = Criteria.forClass(PickTaskD.class);
//            //明细流程状态：1-生成拣货任务 2-拣货已索取 3-拣货已确认 4-内复核已索取 5-内复核已确认 6-外复核已索取 7-外复核已确认 8-拣货冲红
//            cr1.restrictionBuilder().eq("pickTaskId", pickTaskHId).in("flowStatus",new String[]{"1","2","3","4"});
//            cr1.buildRestriction();
//            if(pickTaskDMapper.findCountByCriteria(cr1)==0L){
//                showLcl=true;
//            }
//        }
//        //查询拣货任务明细
//        List<InnerCheckTaskDV2VO> dBInnerCheckTaskDVOs = pickTaskDMapper.getPickTaskdAndWareHouseV2(pickTaskHId, showLcl, warehouseId);
//        //查询红冲记录
//        Criteria redCrt = Criteria.forClass(SaleRedRecord.class);
//        redCrt.restrictionBuilder().in("pickTaskDId",
//                dBInnerCheckTaskDVOs.stream().map(InnerCheckTaskDV2VO::getPickTaskDId).distinct().toArray());
//        redCrt.buildRestriction();
//        List<SaleRedRecord> saleRedRecords=saleRedRecordMapper.findByCriteria(redCrt);
//
//        dBInnerCheckTaskDVOs = dBInnerCheckTaskDVOs.stream().filter(x -> x.getPickQty() != null).collect(Collectors.toList());
//        String redisKey = "wms:innerCheck:" + pickTaskHId;
//        Map redisMap =(Map) redisTemplate.opsForValue().get(redisKey);
//        InnerCheckBillV2VO innerCheckBillVO = new InnerCheckBillV2VO();
//        innerCheckBillVO.setStationCode(stationCode);
//        List<BaseMtlItemMst> itemList = null;
//        if(redisMap !=null){
//            innerCheckBillVO=JSON.parseObject(redisMap.get("vo").toString(),InnerCheckBillV2VO.class);
//            itemList= JSON.parseArray(redisMap.get("items").toString(),BaseMtlItemMst.class);
//            for (int i = 0; i < dBInnerCheckTaskDVOs.size(); i++) {
//                InnerCheckTaskDV2VO dBInnerCheckTaskDV2VO = dBInnerCheckTaskDVOs.get(i);
//                String tempPickTaskDId= dBInnerCheckTaskDV2VO.getPickTaskDId();
//                InnerCheckTaskDV2VO redisInnerCheckTaskDV2VO = innerCheckBillVO.getInnerCheckTaskDVOS().stream().
//                        filter(t->t.getPickTaskDId().equals(tempPickTaskDId)).findFirst().orElse(null);
//                if(redisInnerCheckTaskDV2VO!=null){
//                    dBInnerCheckTaskDV2VO.setIsSupervise(redisInnerCheckTaskDV2VO.getIsSupervise());
//                    dBInnerCheckTaskDV2VO.setNoSuperviseReason(redisInnerCheckTaskDV2VO.getNoSuperviseReason());
//                    dBInnerCheckTaskDV2VO.setSalespersonName(redisInnerCheckTaskDV2VO.getSalespersonName());
//                    dBInnerCheckTaskDV2VO.setPaymentType(redisInnerCheckTaskDV2VO.getPaymentType());
//                    dBInnerCheckTaskDV2VO.setCreateby(redisInnerCheckTaskDV2VO.getCreateby());
//                    dBInnerCheckTaskDV2VO.setRemark(redisInnerCheckTaskDV2VO.getRemark());
//                    dBInnerCheckTaskDV2VO.setShipperId(redisInnerCheckTaskDV2VO.getShipperId());
//                    dBInnerCheckTaskDV2VO.setConsignorId(redisInnerCheckTaskDV2VO.getConsignorId());
//                    dBInnerCheckTaskDV2VO.setBillCode(redisInnerCheckTaskDV2VO.getBillCode());
//                    dBInnerCheckTaskDV2VO.setBillType(redisInnerCheckTaskDV2VO.getBillType());
//                    dBInnerCheckTaskDV2VO.setCargoOwnerName(redisInnerCheckTaskDV2VO.getCargoOwnerName());
//                    dBInnerCheckTaskDV2VO.setSrcId(redisInnerCheckTaskDV2VO.getSrcId());
//                }
//                extractedItem(itemList, dBInnerCheckTaskDV2VO);
//            }
//        }else{
//            innerCheckBillVO.setWarehouseId(pckTaskH.getWarehouseId());
//            innerCheckBillVO.setPickTaskHId(pickTaskHId);
//            innerCheckBillVO.setBillGroupId(pckTaskH.getBillGroupId());
//            innerCheckBillVO.setContainerCode(containerCode);
//            innerCheckBillVO.setStationCode(stationCode);
//            Criteria cr = Criteria.forClass(WaveBillDO.class);
//            Restriction restriction = Restrictions.in("id", dBInnerCheckTaskDVOs.stream().map(InnerCheckTaskDV2VO::getBillId).
//                    distinct().collect(Collectors.toList()));
//            cr.setRestriction(restriction);
//            List<WaveBillDO> billHList =billMapper.findByCriteria(cr);
//            if(billHList!=null && billHList.size()>0){
//                WaveBillDO waveBillDO = billHList.get(0);
//                innerCheckBillVO.setShipperId(waveBillDO.getShipperId());
//                innerCheckBillVO.setShipperName(waveBillDO.getShipperName());
//                innerCheckBillVO.setConsignorId(waveBillDO.getConsignorId());
//                innerCheckBillVO.setConsignorName(waveBillDO.getConsignorName());
//                innerCheckBillVO.setBillCode(waveBillDO.getSrcCode());
//                innerCheckBillVO.setBillType(waveBillDO.getType());
//            }
//
//            //查询运单号
//            List<WaveBillDDO> billDDOS = billDMapper.findByMap(MapUtils.put("mergedBillId", pckTaskH.getBillGroupId()).getMap(),
//                    WaveBillDDO.class);
////            Criteria criteria = Criteria.forClass(WaveBillDDO.class);
////            Restriction restriction1 = Restrictions.eq("merged_bill_id", pckTaskH.getBillGroupId());
////            criteria.setRestriction(Restrictions.and(restriction1));
////            List<WaveBillDDO> billDDOS = billDMapper.findByCriteria(criteria);
//            if(billDDOS != null && billDDOS.size() > 0){
//                innerCheckBillVO.setShipBillNo(billDDOS.get(0).getShipBillNo());
//            }
//
//            //此sql优化，次优先级
//            // 根据id查询商品批次信息，用来获取有效期
//            Set<String> itemIdSet=dBInnerCheckTaskDVOs.stream().map(InnerCheckTaskDV2VO::getItemId).collect(Collectors.toSet());
//            if(itemIdSet!=null && itemIdSet.size()>0 && !StringUtils.isBlank(itemIdSet.iterator().next())){
//                itemList=itemClient.getListByIds(itemIdSet).getData();
//            }
//            for (int i = 0; i < dBInnerCheckTaskDVOs.size(); i++) {
//                InnerCheckTaskDV2VO innerCheckTaskDVO = dBInnerCheckTaskDVOs.get(i);
//                if (billHList != null && billHList.size() > 0) {
//                    WaveBillDO bill = billHList.stream().filter(t->t.getId().equals(innerCheckTaskDVO.getBillId())).findFirst().orElse(null);
//                    if(bill!=null){
//                        innerCheckTaskDVO.setSalespersonName(bill.getSalesPersonName());
//                        innerCheckTaskDVO.setPaymentType(bill.getPaymentDayType());
//                        innerCheckTaskDVO.setCreateby(bill.getCreateBy());
//                        innerCheckTaskDVO.setRemark(bill.getRemark());
//                        innerCheckTaskDVO.setShipperId(bill.getShipperId());
//                        innerCheckTaskDVO.setCreateby(bill.getCreateBy());
//                        innerCheckTaskDVO.setConsignorId(bill.getConsignorId());
//                        innerCheckTaskDVO.setBillCode(bill.getSrcCode());
//                        innerCheckTaskDVO.setBillType(bill.getType());
//                        innerCheckTaskDVO.setSrcId(bill.getSrcId());
//                    }
//                }
//                extractedItem(itemList, innerCheckTaskDVO);
//            }
//
//            //阶段：0=入库质检 1=PC拣货 2=PC内复核 3=PC外复核 4=补录 5=PDA拣货 6=PDA内复核 7=PDA外复核
//            if(dBInnerCheckTaskDVOs!=null && dBInnerCheckTaskDVOs.size()>0){
//                try {
//                    RestMessage<List<? extends IsSuperviseDTO>> rest = inBoundClient.isSupervise(dBInnerCheckTaskDVOs, 2);
//                    if (rest.isSuccess() && rest.getData() != null && rest.getData().size() == dBInnerCheckTaskDVOs.size()) {
//                        for (int i = 0; i < rest.getData().size(); i++) {
//                            BeanUtils.copyProperties(rest.getData().get(i), dBInnerCheckTaskDVOs.get(i));
//                        }
//                    }
//                } catch (Exception e) {
//                    log.error("调用监管码接口异常", e);
//                }
//            }
//        }
//
//        //List<InnerCheckTaskDV2VO> dbSortCheckTaskDV2Sort = sortInnerCheckTaskDV2VOS(checkPickTaskDDTOList, dBInnerCheckTaskDVOs);
//        innerCheckBillVO.setInnerCheckTaskDVOS(dBInnerCheckTaskDVOs);
//
//        if (CollectionUtil.isNotEmpty(checkPickTaskDDTOList)) {
//            List<String> pickTaskDIdList = checkPickTaskDDTOList.stream().map(CheckPickTaskDDTO::getPickTaskDId).collect(Collectors.toList());
//            innerCheckBillVO.setCurrentCheckIdList(pickTaskDIdList);
//        }else{
//            if(!"3".equals(pckTaskH.getStatus())){
//                pickTaskHMapper.updateMapById(pickTaskHId, MapUtils.put("status", "3").getMap(), PickTaskH.class);
//                updateFlowStatus(pickTaskHId, 4);
//            }
//        }
//        InnerCheckContainerVO containerVO = new InnerCheckContainerVO();
//
//        Set<String> totalItemSet =new HashSet<>();
//        Set<String> checkedItemSet =new HashSet<>();
//        Set<String> totalLotNoSet= new HashSet<>();
//        Set<String> checkedLotNoSet = new HashSet<>();
//        BigDecimal redNum = BigDecimal.ZERO;
//        BigDecimal totalNum=BigDecimal.ZERO;
//        BigDecimal checkedNum=BigDecimal.ZERO;
//        Set<String> set=new HashSet<>();
//        for (int i = 0; i < dBInnerCheckTaskDVOs.size(); i++) {
//            InnerCheckTaskDV2VO innerCheckTaskDVO = dBInnerCheckTaskDVOs.get(i);
//            List<SaleRedRecord> subRedList = saleRedRecords.stream().filter(t -> t.getPickTaskDId().
//                    equals(innerCheckTaskDVO.getPickTaskDId())).collect(Collectors.toList());
//            innerCheckTaskDVO.setRedQty(subRedList.stream().map(SaleRedRecord::getQty).reduce(BigDecimal.ZERO, BigDecimal::add));
//            innerCheckTaskDVO.setRedReason(subRedList.stream().filter(t->!StringUtils.isBlank(t.getReason())).
//                    map(t->t.getReason()).collect(Collectors.joining("|")));
//            extractedItem(itemList, innerCheckTaskDVO);
//            //计算容器信息
//
//            //总品种
//            totalItemSet.add(innerCheckTaskDVO.getItemId());
//            //已经检查的品种数量
//            if(isChecked(innerCheckTaskDVO)){
//                checkedItemSet.add(innerCheckTaskDVO.getItemId());
//                if(!StringUtils.isBlank(innerCheckTaskDVO.getLotNo())){
//                    checkedLotNoSet.add(innerCheckTaskDVO.getLotNo());
//                }
//
//            }
//            //合计批号
//            if(!StringUtils.isBlank(innerCheckTaskDVO.getLotNo())){
//                totalLotNoSet.add(innerCheckTaskDVO.getLotNo());
//            }
//
//            if(innerCheckTaskDVO.getRedQty() != null){
//                redNum = redNum.add(innerCheckTaskDVO.getRedQty());
//            }
//
//            if(!set.contains(innerCheckTaskDVO.getPickTaskDId())){
//                BigDecimal pickQty = innerCheckTaskDVO.getPickQty();
//                totalNum=totalNum.add(pickQty ==null?BigDecimal.ZERO: pickQty);
//                if(isChecked(innerCheckTaskDVO)){
//                    if(StringUtils.isBlank(innerCheckTaskDVO.getChecker2())){
//                        checkedNum=checkedNum.add(innerCheckTaskDVO.getCheckQty());
//                    }else{
//                        checkedNum=checkedNum.add(innerCheckTaskDVO.getCheck2Qty());
//                    }
//                }
//                set.add(innerCheckTaskDVO.getPickTaskDId());
//            }
//        }
//
//        containerVO.setTotalVarieties(totalItemSet.size());
//        containerVO.setCheckedVarieties(checkedItemSet.size());
//        containerVO.setUnCheckedVarieties(containerVO.getTotalVarieties()-containerVO.getCheckedVarieties());
//        containerVO.setTotalLot(totalLotNoSet.size());
//        containerVO.setCheckedLot(checkedLotNoSet.size());
//        containerVO.setUnCheckedLot(containerVO.getTotalLot()-containerVO.getCheckedLot());
//        BigDecimal unCheckedNum = totalNum.subtract(checkedNum).subtract(redNum);
//        containerVO.setUnCheckedNum(unCheckedNum);
//        containerVO.setTotalNum(totalNum);
//        containerVO.setCheckedNum(checkedNum);
//        containerVO.setRedNum(redNum);
//        innerCheckBillVO.setContainerInfo(containerVO);
//
//
//        if("3".equals(pckTaskH.getStatus())){
//            //扫描容器才查询拼箱信息
//            innerCheckBillVO.setLclVO(queryLcl(innerCheckBillVO.getShipBillNo(),stationCode, pckTaskH, lclNo, containerCode, isDoubleCheck,itemList));
//        }
//
//        if(redisMap ==null){
//            Map map=new HashMap();
//            map.put("vo", JSON.toJSONString(innerCheckBillVO));
//            map.put("items",JSON.toJSONString(itemList));
//            redisTemplate.opsForValue().set(redisKey,map,60, TimeUnit.MINUTES);
//        }
//
//        if(CollectionUtil.isNotEmpty(checkPickTaskDDTOList)){
//            //计算当前复核明细Id集合数据
//            InnerCurrentCheckVO innerCurrentCheckVO = new InnerCurrentCheckVO();
//            List<InnerCurrentCheckVO.LotAndNum> lotAndNumList =  Lists.newArrayList();
//            List<InnerCheckTaskDV2VO> innerCheckTaskDVOS = innerCheckBillVO.getInnerCheckTaskDVOS();
//            List<String> currentTaskIds = checkPickTaskDDTOList.stream().map(c -> c.getPickTaskDId()).collect(Collectors.toList());
//            List<InnerCheckTaskDV2VO> currenTasks = innerCheckTaskDVOS.stream().filter(t -> currentTaskIds.contains(t.getPickTaskDId())).collect(Collectors.toList());
//
//            Map<String, List<InnerCheckTaskDV2VO>> collectMap = currenTasks.stream().collect(Collectors.groupingBy(InnerCheckTaskDV2VO::getLotNo));
//            for (String lotNo : collectMap.keySet()) {
//                InnerCurrentCheckVO.LotAndNum lotAndNum = innerCurrentCheckVO.new LotAndNum();
//                List<InnerCheckTaskDV2VO> innerCheckTaskDV2VOS = collectMap.get(lotNo);
//                List<InnerCheckTaskDV2VO> redTaskVos = innerCheckTaskDV2VOS.stream().filter(t -> t.getRedQty() != null).collect(Collectors.toList());
//                BigDecimal batchRedQty = CollectionUtil.isEmpty(redTaskVos)? BigDecimal.ZERO:redTaskVos.stream().map(InnerCheckTaskDV2VO::getRedQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//                BigDecimal num = innerCheckTaskDV2VOS.stream().map(InnerCheckTaskDV2VO::getPickQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//                lotAndNum.setLotNo(lotNo);
//                lotAndNum.setNum(num.subtract(batchRedQty));
//                lotAndNumList.add(lotAndNum);
//            }
//
//            BigDecimal checkQty = currenTasks.stream().map(InnerCheckTaskDV2VO::getCheckQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//            BigDecimal pickQty = currenTasks.stream().map(InnerCheckTaskDV2VO::getPickQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//            BigDecimal qty = currenTasks.stream().map(InnerCheckTaskDV2VO::getQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//            innerCurrentCheckVO.setLotAndNumList(lotAndNumList);
//            innerCurrentCheckVO.setCheckQty(checkQty.subtract(redNum));
//            innerCurrentCheckVO.setPickQty(pickQty);
//            innerCurrentCheckVO.setQty(qty);
//            innerCurrentCheckVO.setPickTaskDId(currentTaskIds);
//            innerCheckBillVO.setCurrentCheckInfoVo(innerCurrentCheckVO);
//        }
//        return innerCheckBillVO;
//    }
//
//    @FuncImpl(name = "内复核确认校验", func = ValidInnerCheckConfirmFunc.class, description = "内复核确认校验")
//    public List<InnerCheckDDO> validInnerCheckConfirmFunc(CheckConfirmDTO checkConfirmDTO) {
//        String containerCode = checkConfirmDTO.getContainerCode();
//        String billGroupId = checkConfirmDTO.getBillGroupId();
//        String stationCode = checkConfirmDTO.getStationCode();
//        AssertUtils.isNotBlank(billGroupId);
//        AssertUtils.isNotBlank(containerCode);
//        AssertUtils.isNotBlank(stationCode);
//        //商品组装,查询两个服务
//        List<InnerCheckDDO> innerCheckDs = innerCheckDMapper.getInnerCheckD(billGroupId, containerCode);
//
//        return innerCheckDs;
//    }
//
//    @FuncImpl(name = "内复核确认", func = InnerCheckConfirmFunc.class, description = "内复核确认")
//    public RestMessage<InnerCheckConfirmCheckVO> innerCheckConfirmFunc(CheckConfirmDTO checkConfirmDTO, List<InnerCheckDDO> innerCheckDs) {
//        String billGroupId = checkConfirmDTO.getBillGroupId();
//        String containerCode = checkConfirmDTO.getContainerCode();
//        String stationCode = checkConfirmDTO.getStationCode();
//        Criteria criteria = Criteria.forClass(PickTaskH.class);
//        criteria.restrictionBuilder().eq("billGroupId", billGroupId).eq("stationCode", stationCode).
//                eq("containerCode", containerCode).ne("status","10");
//        criteria.buildRestriction();
//        List<PickTaskH> pickTaskHS = pickTaskHMapper.findByCriteria(criteria);
//        AssertUtils.isNotEmpty(pickTaskHS);
//        PickTaskH pickTaskH = pickTaskHS.get(0);
//
//        List<String> itemIds = innerCheckDs.stream().map(InnerCheckDDO::getItemId).distinct().collect(Collectors.toList());
//        RestMessage<List<WaveItemInfoVO>> waveItemInfos = itemClient.getWaveItemInfo(itemIds);
//        List<WaveItemInfoVO> itemVOs = waveItemInfos.getData();
//
//        Criteria critic = Criteria.forClass(PickTaskH.class);
//        critic.restrictionBuilder().eq("billGroupId", billGroupId).eq("stationCode", stationCode).
//                eq("pickOrderId", pickTaskH.getPickOrderId()).ne("containerCode", containerCode).
//                ne("status","10");
//        critic.buildRestriction();
//        List<PickTaskH> oneCarOneBillTasks = pickTaskHMapper.findByCriteria(critic);
//        if(innerCheckDs!=null && innerCheckDs.size()>0 && itemVOs!=null && itemVOs.size()>0){
//            for (int i = 0; i < innerCheckDs.size(); i++) {
//                InnerCheckDDO innerCheckDDO = innerCheckDs.get(i);
//                Integer pickTaskType = innerCheckDDO.getPickTaskType();
//                Integer printCount = innerCheckDDO.getPrintCount();
//                BigDecimal redQty = innerCheckDDO.getRedQty();
//                if(redQty!=null && redQty.compareTo(innerCheckDDO.getPickQty())<0 &&
//                        pickTaskType !=null && pickTaskType ==0 && printCount !=null && printCount ==0 && oneCarOneBillTasks.size()==0){
//                    throw new PrologException("整件标签未全部打印，请打印完成后确认");
//                }
//                for (int j = 0; j < itemVOs.size(); j++) {
//                    WaveItemInfoVO waveItemInfoVO = itemVOs.get(j);
//                    if(innerCheckDDO.getItemId().equals(waveItemInfoVO.getItemId())){
//                        innerCheckDDO.setItemName(waveItemInfoVO.getItemName());
////                        innerCheckDDO.setNeedDoubleCheck(Integer.parseInt(waveItemInfoVO.getItemHealthIsDouble()));
//                        break;
//                    }
//                }
//            }
//        }
//
//        List<InnerCheckDDO> collect = innerCheckDs.stream().
//                filter(innerCheckDDO -> !isItemChecked(innerCheckDDO)).collect(Collectors.toList());
//        if (!collect.isEmpty()) {
////            String itemNames = collect.stream().filter(x -> x.getNeedDoubleCheck() == 1).
////                    filter(x -> (StringUtils.isBlank(x.getChecker1()) ||
////                            StringUtils.isBlank(x.getChecker2())  || x.getChecker1().equals(x.getChecker2()))).
////                    map(InnerCheckDDO::getItemName).collect(Collectors.joining(","));
////            if (!StringUtils.isBlank(itemNames)) {
////                throw new BizException("商品需要2次复核，请复核员2 登录并完成复核后再确认: "+ itemNames);
////            }
//            String failedItems = collect.stream().map(InnerCheckDDO::getItemName).collect(Collectors.joining(","));
//            throw new BizException("还有商品未复核完成: " + failedItems);
//        }
//
//
//        List<LclCheckResultVO> lclCheckResultVOS = innerCheckHMapper.checkLclDetail(billGroupId, containerCode);
//        if (!lclCheckResultVOS.isEmpty()) {
//            return RestMessage.doError("复核失败，请调整拼箱商品数量后再确认");
//        }
//        List<BarcodeHDO> lclNos;
//        if(StringUtils.isBlank(checkConfirmDTO.getShipBillNo())){
//            lclNos = barcodeHMapper.getLclNo(null,stationCode, billGroupId, null,null);
//        }else {
//            lclNos = barcodeHMapper.getLclNo(checkConfirmDTO.getShipBillNo(),null, null, null,null);
//        }
//
//        if(lclNos==null || lclNos.size()==0){
//            throw new BizException("拼箱数据不能为空");
//        }
//        List<String> lclLists = lclNos.stream().
//                map(BarcodeHDO::getLclNo).collect(Collectors.toList());
//        Set<String> lclSet = new HashSet<>(lclLists);
//        if (lclLists.size() != lclSet.size()) {
//            throw new BizException("存在重复拼箱，请删除后确认");
//        }
//        Integer pickTaskType = pickTaskH.getPickTaskType();
//        for (BarcodeHDO barcodeH : lclNos) {
//            if (barcodeH.getLclNo() != null) {
//                String barcodeId = barcodeH.getId();
//                List<BarCodeDDO> barCodeDDOS = barcodeDMapper.findByMap(MapUtils.put("barcodeId", barcodeId).getMap(), BarCodeDDO.class);
//                if (barCodeDDOS.isEmpty()) {
//                    barcodeHMapper.deleteById(barcodeId, BarcodeHDO.class);
//                    log.info("拼箱" + barcodeH.getLclNo() + "为空，请检查或者刪除该拼箱确认，barcodeId="+barcodeId);
//                    continue;
//                    //throw new BizException("拼箱" + barcodeH.getLclNo() + "为空，请检查或者刪除该拼箱确认");
//                }
//                for (int i = 0; i < barCodeDDOS.size(); i++) {
//                    BarCodeDDO barCodeDDO = barCodeDDOS.get(i);
//                    if(pickTaskType !=null && pickTaskType ==2){
//                        for (int j = 0; j < innerCheckDs.size(); j++) {
//                            InnerCheckDDO innerCheckDDO = innerCheckDs.get(j);
//                            if(innerCheckDDO.getItemId()!=null && innerCheckDDO.getItemId().equals(barCodeDDO.getItemId())){
//                                WaveBillDDO billDDO = billDMapper.findById(innerCheckDDO.getBillDId(), WaveBillDDO.class);
//                                if(billDDO!=null && billDDO.getCaseConversionRate()!=null){
//                                    BigDecimal caseConversionRate = billDDO.getCaseConversionRate();
//                                    if((barCodeDDO.getQty().floatValue()/(caseConversionRate.floatValue()))>1){
//                                        throw new PrologException("商品编号为：【" + barCodeDDO.getItemCode() + "】规定要求必须整件拆分");
//                                    }
//                                }
//                            }
//                        }
//                    }
//                }
//            }
//        }
//
//        for (BarcodeHDO lcl : lclNos) {
//            char status = lcl.getStatus();
//            if ('0' == status && oneCarOneBillTasks.size()==0) {
//                throw new PrologException("还有标签未打印，请打印完成后确认");
//            }
//        }
//
//        //设置为已经完成
//        pickTaskH.setStatus("10");
//        pickTaskHMapper.update(pickTaskH);
//
//        Criteria crt = Criteria.forClass(BarcodeHDO.class);
//        Restriction r1 = Restrictions.eq("billGroupId", billGroupId);
//        Restriction r2 = Restrictions.eq("containerCode", containerCode);
//        crt.setRestriction(Restrictions.and(r1, r2));
//        barcodeHMapper.updateMapByCriteria(MapUtils.put("checkStatus","0").getMap(),crt);
//
//        //释放容器
//        ContainerQueryVO containerQueryVO = new ContainerQueryVO();
//        containerQueryVO.setContainerCode(containerCode);
//        containerQueryVO.setWarehouseId(pickTaskH.getWarehouseId());
//        warehouseResource.release(containerQueryVO);
//
//        // 业务参数配置内/外复核回传ERP，使用 PostBackErpHandle by Huanglh 20220112
//        UserDTO userDTO = userTemplate.getUserDTO();
//        String enterpriseId = userDTO.getEnterpriseId();
//        // 内复核需要判断两个业务配置参数，需要先扣减库存
//        List<String> omsBillIds = barcodeHMapper.getOmsBillIds(billGroupId, enterpriseId);
//        String warehouseId = pickTaskH.getWarehouseId();
//        IStrategyHandle strategyHandle = strategySelector.selectHandle(Arrays.asList(
//                STRATEGY_CODE.POST_BACK_ERP__IN_CHECK__ON,
//                STRATEGY_CODE.POST_BACK_ERP__MQ__ON), enterpriseId, warehouseId, "in");
//        strategyHandle.execute(omsBillIds, "内复核 回传ERP，rabbitmq发送消息失败！", Arrays.asList(billGroupId), warehouseId);
//        redisTemplate.delete("wms:innerCheck:" + pickTaskH.getPickTaskId());
//
//        //校验同票号（运单号）订单中是否还有未内复核的周转筐
//        InnerCheckConfirmCheckVO result = new InnerCheckConfirmCheckVO();
//        result.setIsShow(0);
//        result.setIsComplete(0);
//        //如果运单号为空，则返回全部复核完成
//        if(StringUtils.isBlank(checkConfirmDTO.getShipBillNo())){
//            result.setIsComplete(1);
//            result.setMsg("复核完成");
//        }else {
//
//            List<PickTaskD> pickTaskDS =  pickTaskDMapper.getPickTaskdByBillGroupId(checkConfirmDTO.getBillGroupId());
//            if(pickTaskDS == null || pickTaskDS.size() <= 0){
//                throw new BizException("根据合单号查询拣货明细失败");
//            }
//            //判断是否还有未复核完成的任务明细
//            List<PickTaskD> pickTaskDList = pickTaskDS.stream().filter(item -> Integer.valueOf(item.getFlowStatus()) < 5).collect(Collectors.toList());
//            if(pickTaskDList != null && pickTaskDList.size() > 0){
//                result.setIsShow(1);
//                result.setMsg("同票号（运单号）订单中还有未内复核的周转筐，请确认封箱或者继续等待");
//            }else {
//                result.setIsComplete(1);
//                result.setMsg("复核完成");
//            }
//
//        }
//        return RestMessage.doSuccess(result);
////        return RestMessage.doSuccess(oneCarOneBillTasks.stream().map(t->t.getContainerCode()).collect(Collectors.toList()));
//    }
//
//    private boolean isItemChecked(InnerCheckDDO innerCheckDDO) {
//        if(innerCheckDDO.getCheckQty()==null){
//            return false;
//        }
////        int needDoubleCheck = innerCheckDDO.getNeedDoubleCheck();
//        BigDecimal redQty = innerCheckDDO.getRedQty()==null ? BigDecimal.ZERO:innerCheckDDO.getRedQty();
//        BigDecimal checkQty = innerCheckDDO.getCheckQty().add(redQty);
//        BigDecimal checker2QtyTemp = innerCheckDDO.getChecker2Qty()==null ? BigDecimal.ZERO:innerCheckDDO.getChecker2Qty();
//        BigDecimal checker2Qty = checker2QtyTemp.add(redQty);
//        BigDecimal pickQty = innerCheckDDO.getPickQty();
////        if (needDoubleCheck == 1) {
////            return pickQty.equals(checker2Qty) ? true : false;
////        }
//        return pickQty.equals(checkQty) ? true : false;
//    }
//
//
//
//
////    @Override
////    public List<BarCodeDVO> queryLclByBarcodeId(String barcodeId) {
////        AssertUtils.isNotBlank(barcodeId,"参数不能为空");
////
////        List<BarCodeDDO> barCodeDDOS = barcodeDMapper.findByMap(MapUtils.put("barcodeId", barcodeId).getMap(),
////                BarCodeDDO.class);
////        if(CollectionUtil.isEmpty(barCodeDDOS)){
////            return null;
////        }
////        List<BarCodeDVO> barCodeDVOs = barCodeDDOS.stream().filter(p -> p.getQty()!=null && p.getQty().compareTo(BigDecimal.ZERO)>0).
////                map(barCodeDDO -> {
////                    BarCodeDVO barCodeDVO = new BarCodeDVO();
////                    barCodeDVO.setBarcodeDId(barCodeDDO.getId());
////                    barCodeDVO.setPickTaskDId(barCodeDDO.getWmsPickTaskDId());
////                    barCodeDVO.setContainerCode(barCodeDDO.getContainerCode());
////                    BeanUtils.copyProperties(barCodeDDO, barCodeDVO);
////                    //barCodeDVO.setPrintCount(lcl.getPrintCount());
////                    return barCodeDVO;
////                }).collect(Collectors.toList());
////
////
////        PickTaskD pickTaskD = pickTaskDMapper.findById(barCodeDVOs.get(0).getPickTaskDId(), PickTaskD.class);
////        AssertUtils.isNotNull(pickTaskD,"查询拣选任务异常，拣选明细单号："+barCodeDVOs.get(0).getPickTaskDId());
////        String pickTaskHId = pickTaskD.getPickTaskId();
////        String redisKey = "wms:innerCheck:" + pickTaskHId;
////        Map redisMap =(Map) redisTemplate.opsForValue().get(redisKey);
////        List<InnerCheckTaskDV2VO> dBInnerCheckTaskDVOs = pickTaskDMapper.getPickTaskdAndWareHouseV2(pickTaskHId,false,null);
////        Map<String, List<InnerCheckTaskDV2VO>> collect = dBInnerCheckTaskDVOs.stream().collect(Collectors.groupingBy(InnerCheckTaskDV2VO::getPickTaskDId));
////        List<BaseMtlItemMst> itemList =null;
////        if(redisMap !=null){
////            itemList= JSON.parseArray(redisMap.get("items").toString(),BaseMtlItemMst.class);
////        }else{
////            Set<String> itemIdSet=dBInnerCheckTaskDVOs.stream().map(t->t.getItemId()).collect(Collectors.toSet());
////            if(itemIdSet!=null && itemIdSet.size()>0 && !StringUtils.isBlank(itemIdSet.iterator().next())){
////                itemList=itemClient.getListByIds(itemIdSet).getData();
////            }
////        }
////        Map<String, BaseMtlItemMst> itemMap = null;
////        if(CollectionUtil.isNotEmpty(itemList)){
////            itemMap = itemList.stream().collect(Collectors.toMap(BaseMtlItemMst::getItemId, Function.identity()));
////        }
////
////
////        for (int i = 0; i < barCodeDVOs.size(); i++) {
////            BarCodeDVO barCodeDVO = barCodeDVOs.get(i);
////            barCodeDVO.setBatchNum(collect.get(barCodeDVO.getPickTaskDId())==null?"":collect.get(barCodeDVO.getPickTaskDId()).get(0).getBatchNum());
////            if(CollectionUtil.isNotEmpty(itemMap)){
////                BaseMtlItemMst baseMtlItemMst = itemMap.get(barCodeDVO.getItemId());
////                barCodeDVO.setItemName(baseMtlItemMst==null?"":baseMtlItemMst.getItemName());
////                List<BaseMtlItemUomConversions> uomList = baseMtlItemMst.getBaseMtlItemUomConversionsList();
////                if(uomList!=null && uomList.size()>0){
////                    barCodeDVO.setCaseConversionRate(uomList.get(0).getConversionRate());
////                }
////            }
////        }
////        return barCodeDVOs;
////    }
//
//
////    @Override
////    @Transactional
////    public RestMessage<Boolean> lclAdjust(List<LclAdjustDTO> lclInfos) {
////        for (LclAdjustDTO adjustInfo : lclInfos) {
////            if(adjustInfo.getQty()==null || adjustInfo.getQty().compareTo(BigDecimal.ZERO)<0){
////                throw new BizException("数量必须大于0");
////            }
////            Integer lclNo = adjustInfo.getLclNo();
////            AssertUtils.isNotNull(lclNo);
////            String containerCode = adjustInfo.getContainerCode();
////            String billGroupId = adjustInfo.getBillGroupId();
////            AssertUtils.isNotBlank(billGroupId);
////            Map<String, Object> map = MapUtils.put("billGroupId", billGroupId).put("lclNo", lclNo).getMap();
////
////            List<BarcodeHDO> barcodeHs = barcodeHMapper.findByMap(map, BarcodeHDO.class);
////            if (barcodeHs.isEmpty()) {
////                throw new BizException("找不到对应的拼箱 ");
////            }
////
////            if (barcodeHs.size() > 1) {
////                throw new BizException("找到多个拼箱");
////            }
////
////            String itemCode = adjustInfo.getItemCode();
////            BigDecimal qty = adjustInfo.getQty();
////            BarcodeHDO barcodeHDO = barcodeHs.get(0);
////            String barcodeId = barcodeHDO.getId();
////            String itemId = adjustInfo.getItemId();
////            String pickTaskDId = adjustInfo.getPickTaskDId();
////            updateLcl(barcodeId, itemCode, itemId, qty, containerCode, pickTaskDId,1,barcodeHDO.getWarehouseId());
////        }
////
////        return RestMessage.doSuccess(true);
////    }
//
//}
