//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.google.common.collect.Lists;
//import com.prolog.cs.basic.common.model.BaseCommonDict;
//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.BaseWmsWarehouseArea;
//import com.prolog.cs.basic.warehouse.model.BaseWmsWarehouseMst;
//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.check.CheckConfirmDTO;
//import com.prolog.cs.biz.outbound.model.dto.check.CheckInfoDTO;
//import com.prolog.cs.biz.outbound.model.dto.check.CheckMakeRedDTO;
//import com.prolog.cs.biz.outbound.model.dto.check.LclAdjustDTO;
//import com.prolog.cs.biz.outbound.model.entity.*;
//import com.prolog.cs.biz.outbound.model.print.LclDetailHeadVO;
//import com.prolog.cs.biz.outbound.model.print.LclDetailTableVO;
//import com.prolog.cs.biz.outbound.model.vo.PrintVO;
//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.InnerCheckService;
//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.common.print.PrintData;
//import com.prolog.framework.bz.common.print.ReportData;
//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.strategy.model.BusinessControl;
//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.cglib.beans.BeanMap;
//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.atomic.AtomicInteger;
//import java.util.concurrent.atomic.AtomicReference;
//import java.util.stream.Collectors;
//
///**
// * @Description: 初版内复核，新版已在界面交互、接口响应作重大优化，旧版仅作参考，建议在新版升级
// * @Author: 田海龙
// * @Date: 2022/6/23 9:52
// */
//@Service
//public class InnerCheckServiceImpl implements InnerCheckService {
//
//    private static Logger log = LoggerFactory.getLogger(InnerCheckServiceImpl.class);
//
//    @Autowired
//    private WorkStationUserMapper workStationUserMapper;
//
//    @Autowired
//    private ControlResource controlResource;
//
//    @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 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;
//
//    @Autowired
//    private RedisTemplate redisTemplate;
//
//    @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;
//
//    private ValidPrintBoxFunc validPrintBoxFunc;
//    private PrintLclFunc printLclFunc;
//    private ValidPrintBoxDetailFunc validPrintBoxDetailFunc;
//    private PrintLclDetail printLclDetail;
//    private ValidLCLFunc validLCLFunc;
//    private LCLFunc lclFunc;
//    private FindPickupByContainerFunc findPickupByContainerFunc;
//    private UpdatePickupStatusFunc updatePickupStatusFunc;
//    private ValidInnerCheckFunc validInnerCheckFunc;
//    private UpdatePickupDInnerCheckInfoFunc updatePickupDInnerCheckInfoFunc;
//    private CreateBarcodeFunc createBarcodeFunc;
//    private ValidCaseSplitFunc validCaseSplitFunc;
//    private CaseSplitBoxFunc caseSplitBoxFunc;
//    private ValidRedFunc validRedFunc;
//    private RedFunc redFunc;
//    private ValidInnerCheckConfirmFunc validInnerCheckConfirmFunc;
//    private InnerCheckConfirmFunc innerCheckConfirmFunc;
//
//    @PostConstruct
//    public void init() {
//        findPickupByContainerFunc = this::findPickupByContainerFunc;
//        updatePickupStatusFunc = this::updatePickupStatusFunc;
//        validInnerCheckFunc = this::validInnerCheckFunc;
//        updatePickupDInnerCheckInfoFunc = this::updatePickupDInnerCheckInfoFunc;
//        createBarcodeFunc = this::createBarcodeFunc;
//        validPrintBoxFunc = this::validPrintLclFunc;
//        printLclFunc = this::printLclFunc;
//        validPrintBoxDetailFunc = this::validPrintBoxDetailFunc;
//        printLclDetail = this::printLclDetail;
//        validLCLFunc = this::validLCLFunc;
//        lclFunc = this::lclFunc;
//
//        validCaseSplitFunc = this::validCaseSplitFunc;
//        caseSplitBoxFunc = this::caseSplitBoxFunc;
//        validRedFunc = this::validRedFunc;
//        redFunc = this::redFunc;
//        validInnerCheckConfirmFunc = this::validInnerCheckConfirmFunc;
//        innerCheckConfirmFunc = this::innerCheckConfirmFunc;
//    }
//
//    @Override
//    @Deprecated
//    @Transactional
//    @Flow(name = "内复核索取", category = "出库/复核管理/内复核/内复核索取", index = 1, description = "1、查询容器内任务明细 2、更新状态为已索取：pick_task_h status=3,pick_task_d flow_status=4")
//    public RestMessage<InnerCheckBillVO> getCurrentContainer(String containerCode, String stationCode) {
//        InnerCheckBillVO containerInfo = findPickupByContainerFunc.findPickupByContainerFunc(containerCode, stationCode, null);
//        updatePickupStatusFunc.updatePickupStatusFunc(containerCode, stationCode, null, containerInfo);
//        log.info("内复核索取containerInfo:"+ JSON.toJSONString(containerInfo));
//        return RestMessage.doSuccess(containerInfo);
//    }
//
//    @FuncImpl(name = "更新任务状态为已索取", func = UpdatePickupStatusFunc.class, description = "更新任务状态为已索取")
//    public void updatePickupStatusFunc(String containerCode, String stationCode, String pickTaskDId, InnerCheckBillVO innerCheckBillVO) {
//        if(pickTaskDId != null){
//            innerCheckBillVO.setCurrentCheckId(pickTaskDId);
//            return;
//        }
//        //查询未复核完成的容器
//        Criteria crt = Criteria.forClass(PickTaskH.class);
//        crt.restrictionBuilder().in("status", new String[]{"0", "1", "2", "3"}).
//                eq("containerCode", containerCode).eq("stationCode", stationCode);
//        crt.buildRestriction();
//        List<PickTaskH> pckTaskHs = pickTaskHMapper.findByCriteria(crt);
//        if (pckTaskHs.isEmpty()) {
//            throw new BizException("找不到对应容器任务");
//        } else if (pckTaskHs.size() > 1) {
//            throw new BizException("容器绑定错误，该容器绑定了多个未完成任务");
//        }
//        if (!"3".equals(pckTaskHs.get(0).getStatus())) {
//            String pickTaskHId = innerCheckBillVO.getPickTaskHId();
//            pickTaskHMapper.updateMapById(pickTaskHId, MapUtils.put("status", "3").getMap(), PickTaskH.class);
//            updateFlowStatus(pickTaskHId, 4);
//        }
//    }
//
//    @FuncImpl(name = "获取容器内任务汇总&明细", func = FindPickupByContainerFunc.class, description = "获取容器内任务汇总&明细")
//    public InnerCheckBillVO findPickupByContainerFunc(String containerCode, String stationCode, String pickTaskDId) {
//        AssertUtils.isNotBlank(stationCode, "入参复核台不能为空");
//        AssertUtils.isNotBlank(containerCode, "入参容器号不能为空");
//        List<InnerCheckBillVO> containerInfos = pickTaskHMapper.getContainerInfo(containerCode, stationCode);
//        if (containerInfos.isEmpty()) {
//            throw new BizException("容器找不到对应的订单");
//        }
//
//        InnerCheckBillVO innerCheckBillVO = containerInfos.stream().reduce((a, b) -> {
//            String concat = a.getBillCode().concat("|").concat(b.getBillCode());
//            a.setBillCode(concat);
//            String billType = a.getBillType().concat("|").concat(b.getBillType());
//            a.setBillType(billType);
//            return a;
//        }).get();
//
//        String pickTaskHId = innerCheckBillVO.getPickTaskHId();
//        AssertUtils.isNotBlank(pickTaskHId,"任务单号不能为空");
//        String stationCodeDb = containerInfos.get(0).getStationCode();
//        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 = (StringUtils.isBlank(stationCodeDb) || "-1".equals(stationCodeDb)) ? null : Restrictions.eq("stationCode", stationCode);
//        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("容器绑定错误，该容器绑定了多个未完成任务");
//        }
//        if (pickTaskDId != null) {
//            innerCheckBillVO.setCurrentCheckId(pickTaskDId);
//        }else{
//            if(!"3".equals(pckTaskHs.get(0).getStatus())){
//                pickTaskHMapper.updateMapById(pickTaskHId, MapUtils.put("status", "3").getMap(), PickTaskH.class);
//                updateFlowStatus(pickTaskHId, 4);
//            }
//        }
//
//        if(StringUtils.isBlank(stationCodeDb) || "-1".equals(stationCodeDb)){//机动复核台逻辑
//            Criteria crt1 = Criteria.forClass(PickTaskH.class);
//            String[] pickTaskIds = containerInfos.stream().map(InnerCheckBillVO::getPickTaskHId).distinct().toArray(String[]::new);
//            crt1.setRestriction(Restrictions.and(Restrictions.in("pickTaskId", pickTaskIds)));
//            WhWorkstationQueryVO workstationQueryVO=new WhWorkstationQueryVO();
//            workstationQueryVO.setWarehouseId(containerInfos.get(0).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.updateMapByCriteria(tempStation.getMap(),crt1);
//        }
//
//        boolean showLcl=false;
//        if(pckTaskHs.get(0).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<InnerCheckTaskDVO> pickTasks = pickTaskDMapper.getPickTaskd(pickTaskHId,showLcl);
//        pickTasks = pickTasks.stream().filter(x -> x.getPickQty() != null).collect(Collectors.toList());
//        //阶段：0=入库质检 1=PC拣货 2=PC内复核 3=PC外复核 4=补录 5=PDA拣货 6=PDA内复核 7=PDA外复核
//        if(pickTasks!=null && pickTasks.size()>0){
//            try {
//                RestMessage<List<? extends IsSuperviseDTO>> rest = inBoundClient.isSupervise(pickTasks, 2);
//                if (rest.isSuccess() && rest.getData() != null && rest.getData().size() == pickTasks.size()) {
//                    for (int i = 0; i < rest.getData().size(); i++) {
//                        BeanUtils.copyProperties(rest.getData().get(i), pickTasks.get(i));
//                    }
//                }
//            } catch (Exception e) {
//                log.error("调用监管码接口异常", e);
//            }
//        }
//
//        for (int i = 0; i < pickTasks.size(); i++) {
//            InnerCheckTaskDVO innerCheckTaskDVO = pickTasks.get(i);
//            Criteria cr = Criteria.forClass(OmsDoBillHDO.class);
//            Restriction restriction = Restrictions.eq("billno", innerCheckTaskDVO.getBillCode());
//            cr.setRestriction(restriction);
//            List<OmsDoBillHDO> billHList = omsDoBillHMapper.findByCriteria(cr);
//            if (billHList != null && billHList.size() > 0) {
//                OmsDoBillHDO bill = billHList.get(0);
//                innerCheckTaskDVO.setSalespersonName(bill.getSalespersonName());
//                innerCheckTaskDVO.setPaymentType(bill.getPaymentDayTypeCode());
//                innerCheckTaskDVO.setCreateby(bill.getCreateby());
//                innerCheckTaskDVO.setRemark(bill.getRemark());
//            }
//        }
//        innerCheckBillVO.setInnerCheckTaskDVOS(pickTasks);
//        InnerCheckContainerVO containerVO = new InnerCheckContainerVO();
//        //已经复核的明细行
//        List<InnerCheckTaskDVO> checkedTasks = pickTasks.stream().filter(pickTask -> isChecked(pickTask)).collect(Collectors.toList());
//
//        long totalVarieties = pickTasks.stream().map(InnerCheckTaskDVO::getItemId).distinct().count();
//        containerVO.setTotalVarieties((int) totalVarieties);
//        long checkedVarieties = checkedTasks.stream().map(InnerCheckTaskDVO::getItemId).distinct().count();
//
//        containerVO.setCheckedVarieties((int) checkedVarieties);
//        innerCheckBillVO.setContainerInfo(containerVO);
//
//        //未复核的明细行
//        List<InnerCheckTaskDVO> uncheckedTasks = pickTasks.stream().filter(pickTask -> !isChecked(pickTask)
//        ).collect(Collectors.toList());
//
//        long unCheckedVarieties = uncheckedTasks.stream().map(InnerCheckTaskDVO::getItemId).distinct().count();
//        containerVO.setUnCheckedVarieties((int) unCheckedVarieties);
//
//        long totalLot = pickTasks.stream().map(InnerCheckTaskDVO::getLotNo).
//                filter(x -> !StringUtils.isBlank(x)).distinct().count();
//        containerVO.setTotalLot((int) totalLot);
//
//        long checkedLot = checkedTasks.stream().map(InnerCheckTaskDVO::getLotNo).
//                filter(x -> !StringUtils.isBlank(x)).distinct().count();
//        containerVO.setCheckedLot((int) checkedLot);
//
//        long unCheckedLot = uncheckedTasks.stream().map(InnerCheckTaskDVO::getLotNo).
//                filter(x -> !StringUtils.isBlank(x)).distinct().count();
//        containerVO.setUnCheckedLot((int) unCheckedLot);
//
//        BigDecimal redNum = pickTasks.stream().filter(x -> x.getRedQty() != null).map(InnerCheckTaskDVO::getRedQty)
//                .reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
//        containerVO.setRedNum(redNum);
//        BigDecimal totalNum=BigDecimal.ZERO;
//        BigDecimal checkedNum=BigDecimal.ZERO;
//        Set set=new HashSet();
//        for (int i = 0; i < pickTasks.size(); i++) {
//            InnerCheckTaskDVO innerCheckTaskDVO = pickTasks.get(i);
//            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.setTotalNum(totalNum);
//        containerVO.setCheckedNum(checkedNum);
//        BigDecimal unCheckedNum = totalNum.subtract(checkedNum).subtract(redNum);
//        containerVO.setUnCheckedNum(unCheckedNum);
//
//        //查询未复核完成的容器
//        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));
//        return innerCheckBillVO;
//    }
//
//    private boolean isChecked(InnerCheckTaskDVO 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;
//    }
//
//    @Override
//    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);
//        }
//    }
//
//    @Override
//    public RestMessage<List<InnerCheckBillVO>> getContainersInfo(String stationCode) {
//        List<PickTaskH> pickTaskHS = pickTaskHMapper.findByMap(MapUtils.put("stationCode", stationCode).getMap(),
//                PickTaskH.class);
//        List<InnerCheckBillVO> billVOS = new ArrayList<>();
//        for (PickTaskH pickTaskH : pickTaskHS) {
//            String containerCode = pickTaskH.getContainerCode();
//            String billGroupId = pickTaskH.getBillGroupId();
//            InnerCheckBillVO billVO = findPickupByContainerFunc(containerCode, billGroupId, stationCode);
//            billVOS.add(billVO);
//        }
//        return RestMessage.doSuccess(billVOS);
//    }
//
//    @Override
//    @Flow(name = "打印拼箱", category = "出库/复核管理/内复核/打印", index = 3, description = "1、校验数据 2、查询获取拼箱数据 3、更新打印次数+1")
//    public PrintVO printLcl(String containerCode, String billGroupId, String lclNo) {
//        List<WaveBillDO> billDOs = validPrintBoxFunc.validPrintLclFunc(containerCode, billGroupId, lclNo);
//        PrintVO printVO = printLclFunc.PrintLclFunc(containerCode, billGroupId, lclNo, billDOs);
//        return printVO;
//    }
//
//    @FuncImpl(name = "拼箱打印校验", func = ValidPrintBoxFunc.class, description = "拼箱打印校验")
//    public List<WaveBillDO> validPrintLclFunc(String containerCode, String billGroupId, String lclNo) {
//        if (StringUtils.isBlank(containerCode) || StringUtils.isBlank(billGroupId) || StringUtils.isBlank(lclNo))
//            throw new ParameterException("容器号/订单编号/拼箱编号不能为空！");
//
//        List<WaveBillDO> billDOs = billMapper.findByMap(MapUtils.put("billGroupId", billGroupId).getMap(), WaveBillDO.class);
//        if (billDOs.size() < 1) {
//            log.error("找不到对应的订单");
//            throw new BizException("找不到对应的订单");
//        }
//        return billDOs;
//    }
//
//    @FuncImpl(name = "打印拼箱", func = PrintLclFunc.class, description = "打印拼箱")
//    public PrintVO printLclFunc(String containerCode, String billGroupId, String lclNo, List<WaveBillDO> billDOs) {
//        PrintVO printVO = new PrintVO();
//        MapToolKit billGroupIdCond = MapUtils.put("billGroupId", billGroupId);
//        WaveBillDO billDO = billDOs.get(0);
//
//        Map<String, Object> map = MapUtils.put("billid", billDO.getSrcId()).getMap();
//
//        List<OmsDoBillHDO> omsDoBillHDOS = omsDoBillHMapper.findByMap(map, OmsDoBillHDO.class);
//        if (omsDoBillHDOS.size() < 1) {
//            log.error("找不到对应的oms订单");
//            throw new BizException("找不到对应的oms订单");
//        }
//        OmsDoBillHDO omsDoBillHDO = omsDoBillHDOS.get(0);
//
//        LclPrintParameterVO lclPrintParameterVO = new LclPrintParameterVO();
//        lclPrintParameterVO.setBillNo(billDO.getSrcCode());
//        lclPrintParameterVO.setCargoOwnerName(omsDoBillHDO.getConsignorname());
//        lclPrintParameterVO.setDeptName(omsDoBillHDO.getSaleBranchname());
//        lclPrintParameterVO.setPaymentDayType(omsDoBillHDO.getPaymentDayTypeCode());
//        String billType = OUT_BILL_TYPE.getName(billDO.getType());
//        lclPrintParameterVO.setBillType(billType);
//        lclPrintParameterVO.setAddress(billDO.getReceiveAddress());
//        lclPrintParameterVO.setCompany(billDO.getShipperName());
//        lclPrintParameterVO.setDate(new Date());
//        lclPrintParameterVO.setRouteNo(omsDoBillHDO.getLineName());
//        lclPrintParameterVO.setTelephone(billDO.getContactTel());
//        lclPrintParameterVO.setContacts(billDO.getContactName());
//        lclPrintParameterVO.setBizUser(omsDoBillHDO.getSalespersonName());
//        lclPrintParameterVO.setRemark(omsDoBillHDO.getRemark());
//        lclPrintParameterVO.setDJBHQ(billGroupId);//丽江增加打印单据编号
//
//        List<BarcodeHDO> barcodeHDOs = barcodeHMapper.findByMap(billGroupIdCond.put("lclNo", lclNo).getMap(), BarcodeHDO.class);
//        AssertUtils.isTrue(barcodeHDOs.size() == 1,"拼箱号必须唯一存在");
//        BarcodeHDO barcodeHDO = barcodeHDOs.get(0);
//        barcodeHDO.setPrintCount(barcodeHDO.getPrintCount()==null?0:barcodeHDO.getPrintCount()+1);
//        barcodeHDO.setStatus('1');
//        barcodeHMapper.update(barcodeHDO);
//        lclPrintParameterVO.setBarcode(barcodeHDO.getBarcode());
//
//        List<PickTaskH> pickTaskHList=pickTaskHMapper.findByMap(billGroupIdCond.put("containerCode", containerCode).getMap(), PickTaskH.class);
//        AssertUtils.isTrue(pickTaskHList.size() == 1,"容器对应任务必须唯一存在");
//        PickTaskH pickTaskH =pickTaskHList.get(0);
//        List<PickTaskD> pickTaskDList=pickTaskDMapper.findByMap(MapUtils.put("pickTaskId", pickTaskH.getPickTaskId()).getMap(),PickTaskD.class);
//        Set<String> checkerNameSet = pickTaskDList.stream().filter(x -> !StringUtils.isBlank(x.getCheckerName())).
//                map(PickTaskD::getCheckerName).collect(Collectors.toSet());
//        if(checkerNameSet!=null && checkerNameSet.size()>0){
//            lclPrintParameterVO.setChecker1(String.join(",", checkerNameSet));
//            lclPrintParameterVO.setChecker(String.join(",", checkerNameSet));
//        }
//        Set<String> checkerName2Set = pickTaskDList.stream().filter(x -> !StringUtils.isBlank(x.getCheckerName2()))
//                .map(PickTaskD::getCheckerName2).collect(Collectors.toSet());
//        if(checkerName2Set!=null && checkerName2Set.size()>0){
//            lclPrintParameterVO.setChecker2(String.join(",", checkerName2Set));
//            lclPrintParameterVO.setChecker(String.join(",", checkerName2Set));
//        }
//        if(checkerNameSet!=null && checkerNameSet.size()>0 && checkerName2Set!=null && checkerName2Set.size()>0){
//            checkerNameSet.addAll(checkerName2Set);
//            lclPrintParameterVO.setChecker(String.join(",", checkerNameSet));
//        }
//        String checker = lclPrintParameterVO.getChecker1() + "," + lclPrintParameterVO.getChecker2();
//        lclPrintParameterVO.setLclNo(lclNo);
//        List<WorkStageRuntimeDO> workStages = workStageRuntimeMapper.findByMap(billGroupIdCond.getMap(),
//                WorkStageRuntimeDO.class);
//        String workStageCodes = workStages.stream().
//                map(WorkStageRuntimeDO::getStageCode).
//                filter(s -> !StringUtils.isBlank(s)).
//                distinct().collect(Collectors.joining(","));
//        if(!StringUtils.isBlank(workStageCodes) && workStageCodes.length()>0){
//            lclPrintParameterVO.setWorkstageCode(workStageCodes);
//        }else if(pickTaskH.getPickTaskType()==2){
//            RestMessage<List<BaseWmsWarehouseArea>> areas = warehouseResource.getByAreaCodes(pickTaskH.getWarehouseId(),
//                    new String[]{pickTaskH.getWarehouseAreaCode()});
//            if(areas!=null && areas.isSuccess() && areas.getData()!=null && areas.getData().size()>0){
//                lclPrintParameterVO.setWorkstageCode(areas.getData().get(0).getWarehouseAreaName()+"暂存区");
//            }else{
//                lclPrintParameterVO.setWorkstageCode("功能库房暂存区");
//            }
//        }
//
//        lclPrintParameterVO.setWorkstation(pickTaskH.getStationCode());
//        printVO.addParameter(lclPrintParameterVO);
//
//        return printVO;
//    }
//
//    @Override
//    public RestMessage<LclVO> queryLcl(String stationCode, String billGroupId, String lclNo,
//                                       String containerCode, Integer isDoubleCheck) {
//        UserDTO userDTO = userTemplate.getUserDTO();
//        String checkerNo= (isDoubleCheck!=null && isDoubleCheck==0 && !StringUtils.isBlank(containerCode))? userDTO.getUserBizModel().getEmployeeNo():null;
//        List<BarcodeHDO> lclNos = barcodeHMapper.getLclNo(stationCode, billGroupId, null,checkerNo);
//        if (lclNos.isEmpty()) {
//            log.info("当前订单暂无拼箱");
//            return RestMessage.success("暂无拼箱", null);
//        }
//        Integer currLclNo = lclNos.get(0).getLclNo();
//        List<BarCodeHVO> collect = lclNos.stream().map(entity -> getLclVo(entity)).collect(Collectors.toList());
//        List<String> itemIdList = collect.stream().flatMap(barCodeHVO -> barCodeHVO.getBarcodeDList().stream()) // Stream
//                .map(barcodeD ->barcodeD.getItemId()).distinct().collect(Collectors.toList());
//        RestMessage<List<WaveItemInfoVO>> waveItemInfos = itemClient.getWaveItemInfo(itemIdList);
//        List<WaveItemInfoVO> itemVOs = waveItemInfos.getData();
//        if(itemVOs!=null && itemVOs.size()>0){
//            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);
//                    for (int k = 0; k < itemVOs.size(); k++) {
//                        WaveItemInfoVO waveItemInfoVO = itemVOs.get(k);
//                        if(barCodeDVO.getItemId().equals(waveItemInfoVO.getItemId())){
//                            barCodeDVO.setItemName(waveItemInfoVO.getItemName());
//                            barCodeDVO.setCaseConversionRate(waveItemInfoVO.getCaseConversionRate());
//                        }
//                    }
//                }
//            }
//        }
//        LclVO lclVO = new LclVO();
//        if(lclNos.get(lclNos.size()-1).getLclNo()!=0){
//            lclVO.setLcls(collect);
//        }else{
//            List<BarCodeDVO> caseBarcodeDList=new ArrayList<>();
//            List<BarCodeHVO> pieceBarCodeHVOList=new ArrayList<>();
//            for (int i = 0; i < collect.size(); i++) {
//                BarCodeHVO barCodeHVO = collect.get(i);
//                if(barCodeHVO.getLclNo()!=0){
//                    pieceBarCodeHVOList.add(barCodeHVO);
//                }else{
//                    List<BarCodeDVO> barcodeDList = barCodeHVO.getBarcodeDList();
//                    for (int j = 0; j < barcodeDList.size(); j++) {
//                        BarCodeDVO barCodeDVO = barcodeDList.get(j);
//                        PickTaskD d = pickTaskDMapper.findById(barCodeDVO.getPickTaskDId(),PickTaskD.class);
//                        barCodeDVO.setPrintCount(d.getPrintCount());
//                        barCodeDVO.setUomQty(barCodeDVO.getQty().divide(barCodeDVO.getCaseConversionRate(),BigDecimal.ROUND_DOWN));
//                    }
//                    caseBarcodeDList.addAll(barcodeDList);
//                }
//            }
//            BarCodeHVO barCodeHVO=new BarCodeHVO();
//            BeanUtils.copyProperties(collect.get(0), barCodeHVO);
//            barCodeHVO.setLclNo(0);
//            barCodeHVO.setBarcode(null);
//            barCodeHVO.setBarcodeDList(caseBarcodeDList);
//            List<BarCodeHVO> retCollect=new ArrayList<>();
//            retCollect.add(barCodeHVO);
//            retCollect.addAll(pieceBarCodeHVOList);
//            lclVO.setLcls(retCollect);
//        }
//        lclVO.setCurrLclNo(currLclNo);
//        return RestMessage.doSuccess(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<InnerCheckBillVO> makeCheckRed(CheckMakeRedDTO redDTO) {
//        PickTaskD pickTaskD=new PickTaskD();
//        PickTaskH pickTaskH=new PickTaskH();
//        validRedFunc.validRedFunc(redDTO,pickTaskD,pickTaskH);
//        RestMessage<InnerCheckBillVO> innerCheckBillVORestMessage = redFunc.redFunc(redDTO,pickTaskD,pickTaskH);
//        return innerCheckBillVORestMessage;
//    }
//
//    @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();
//        AssertUtils.isNotNull(billId, billDId, srcId, srcLineId, reason, containerCode, stationCode, pickTaskDId);
//        log.debug("冲红操作，原订单id 时 {}  ,订单行id={}", srcId, srcLineId);
//        BeanUtils.copyProperties(pickTaskDMapper.findById(pickTaskDId, PickTaskD.class),pickTaskD);
//        BeanUtils.copyProperties(pickTaskHMapper.findById(pickTaskD.getPickTaskId(), PickTaskH.class),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<InnerCheckBillVO> 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);
//        saleRedRecord.setWarehouseId(pickTaskH.getWarehouseId());
//        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", pickTaskH.getWarehouseId());
//            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);
//        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", pickTaskH.getWarehouseId());
//                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(pickTaskH.getWarehouseId());
//            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(), pickTaskH.getWarehouseId(), "do");
//            strategyHandle.execute(Arrays.asList(srcId), "内复核红冲变为整单红冲 回传ERP，rabbitmq发送消息失败！");
//            return RestMessage.doSuccess(new InnerCheckBillVO());
//        }
//        InnerCheckBillVO containerInfo = findPickupByContainerFunc(containerCode, stationCode, pickTaskDId);
//        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());
//        }
//    }
//
//    @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);
//    }
//
//    @Override
//    @Transactional
//    @Flow(name = "整件拆分", category = "出库/复核管理/内复核/整件拆分", index = 6, description = "1、校验功能库房拣货才可以整单拆分" +
//            "2、除以商品包装数获取整箱数量和零散数 3、删除已有拼箱数据，整箱数量重新生成新的拼箱数据 4、如果零散数不为0，则生成零散拼箱")
//    public RestMessage<Boolean> pieceBreak(String billGroupId, String containerCode, String stationCode) {
//        List<InnerCheckDDO> innerCheckD=new ArrayList<>();
//        validCaseSplitFunc.validCaseSplitFunc(billGroupId,  containerCode,  stationCode, innerCheckD);
//        RestMessage<Boolean> booleanRestMessage = caseSplitBoxFunc.caseSplitBoxFunc(billGroupId, containerCode, stationCode, innerCheckD);
//        return booleanRestMessage;
//    }
//
//    @FuncImpl(name = "整件拆分校验", func = ValidCaseSplitFunc.class, description = "整件拆分校验")
//    public void validCaseSplitFunc(String billGroupId, String containerCode, String stationCode,List<InnerCheckDDO> innerCheckD) {
//        Criteria crt = Criteria.forClass(PickTaskH.class);
//        Restriction r1 = Restrictions.eq("billGroupId", billGroupId);
//        Restriction r2 = Restrictions.eq("containerCode", containerCode);
//        Restriction r3 = Restrictions.eq("stationCode", stationCode);
//        Restriction r4 = Restrictions.ne("pickTaskType", 2);
//        crt.setRestriction(Restrictions.and(r1, r2, r3, r4));
//        long count = pickTaskHMapper.findCountByCriteria(crt);
//        if(count!=0){
//            throw new BizException("功能库房拣货才可以整单拆分");
//        }
//    }
//
//    @FuncImpl(name = "整件拆分生成", func = CaseSplitBoxFunc.class, description = "整件拆分生成")
//    public RestMessage<Boolean> caseSplitBoxFunc(String billGroupId, String containerCode, String stationCode,List<InnerCheckDDO> innerCheckD) {
//        innerCheckD = innerCheckDMapper.getInnerCheckD(billGroupId, containerCode);
//        List<BarcodeHDO> barcodeHDOS = barcodeHMapper.findByMap(
//                MapUtils.put("billGroupId", billGroupId).put("stationCode", stationCode).put("type", "0").getMap(), BarcodeHDO.class);
//        List<String> collect = CollectionUtil.isEmpty(barcodeHDOS)?Lists.newArrayList():barcodeHDOS.stream().map(BarcodeHDO::getId).collect(Collectors.toList());
//        barcodeHMapper.deleteByIds(collect.toArray(),BarcodeHDO.class);
//        List<BarcodeHDO> barcodeHDONo1 = Lists.newArrayList();
//        AssertUtils.isNotEmpty(innerCheckD,"数据为空，功能库房才能整件拆分");
//        innerCheckD.forEach(x -> {
//            String billDId = x.getBillDId();
//            WaveBillDDO billDDO = billDMapper.findById(billDId, WaveBillDDO.class);
//            BigDecimal caseConversionRate = billDDO.getCaseConversionRate();
//            BigDecimal pickQty = x.getPickQty();
//            List<SaleRedRecord> redRecords = saleRedRecordMapper.findByMap(
//                    MapUtils.put("pickTaskDId", x.getPickTaskDId()).put("type", 4).getMap(), SaleRedRecord.class);
//            if(redRecords!=null && redRecords.size()>0) {
//                BigDecimal lineRedQty = redRecords.stream().map(SaleRedRecord::getQty).reduce(BigDecimal.ZERO, BigDecimal::add);
//                pickQty=pickQty.subtract(lineRedQty);
//                if(pickQty.compareTo(BigDecimal.ZERO)<=0){
//                    return;
//                }
//            }
//            BigDecimal[] results = pickQty.divideAndRemainder(caseConversionRate);
//            int divide=results[0].intValue();
//            String pickTaskDId = x.getPickTaskDId();
//            List<BarCodeDDO> dList = barcodeDMapper.findByMap(MapUtils.put("wmsPickTaskDId", pickTaskDId).getMap(), BarCodeDDO.class);
//            for (int i = 0; i < dList.size(); i++) {
//                barcodeDMapper.deleteById(dList.get(i).getId(),BarCodeDDO.class);
//            }
//
//            String warehouseId = x.getWarehouseId();
//            for (int i = 0; i < divide; i++) {
//                BarcodeHDO barcodeHDO = lclFunc(stationCode, billGroupId, containerCode,null,0);
//                barcodeHDO.setStatus('1');
//                updateLcl(barcodeHDO.getId(), billDDO.getItemCode(), billDDO.getItemId(), caseConversionRate,
//                        containerCode, pickTaskDId,0, warehouseId);
//            }
//            if(results[1].compareTo(BigDecimal.ZERO)>0){
//                if(barcodeHDONo1!=null && barcodeHDONo1.size()>0){
//                    updateLcl(barcodeHDONo1.get(0).getId(), billDDO.getItemCode(), billDDO.getItemId(), results[1],
//                            containerCode, pickTaskDId,1, warehouseId);
//                }else{
//                    BarcodeHDO barcodeHDO = lclFunc(stationCode, billGroupId, containerCode,null,1);
//                    //散件放1号拼箱
//                    barcodeHDONo1.add(barcodeHDO);
//                    updateLcl(barcodeHDO.getId(), billDDO.getItemCode(), billDDO.getItemId(), results[1],
//                            containerCode, pickTaskDId,1, warehouseId);
//                }
//            }
//        });
//        barcodeHMapper.deleteBarcodeHNoExistD(billGroupId,stationCode);
//        return RestMessage.doSuccess(Boolean.TRUE);
//    }
//
//    @Override
//    @Transactional
//    public RestMessage<Boolean> lclDelete(String stationCode, String billGroupId, String containerCode, String lclNo) {
//        Map<String, Object> map = MapUtils.put("billGroupId", billGroupId).
//                put("lclNo", lclNo).
//                put("stationCode", stationCode).getMap();
//
//        List<BarcodeHDO> lcls = barcodeHMapper.findByMap(map, BarcodeHDO.class);
//        if (lcls.isEmpty()) {
//            throw new BizException("找不到对应的拼箱");
//        } else if (lcls.size() > 1) {
//            log.error("找到重复拼箱");
//        }
//        BarcodeHDO barcodeHDO = lcls.get(0);
//        String checkStatus = barcodeHDO.getCheckStatus();
//        if (!StringUtils.isBlank(checkStatus)) {
//            throw new PrologException("已复核确认，不能删除");
//        }
//        String barcodeId = barcodeHDO.getId();
//        if(!StringUtils.isBlank(containerCode)){
//            Criteria crt = Criteria.forClass(BarCodeDDO.class);
//            Restriction r1 = Restrictions.eq("barcodeId", barcodeId);
//            crt.setRestriction(Restrictions.and(r1));
//            List<BarCodeDDO> list = barcodeDMapper.findByCriteria(crt);
//            if(list.stream().filter(t->!t.getContainerCode().equals(containerCode)).count()>0L){
//                throw new BizException("不能删除含其他容器商品拼箱");
//            }
//        }
//        barcodeHMapper.deleteById(barcodeId, BarcodeHDO.class);
//        barcodeDMapper.deleteByBarcodeLong(barcodeId);
//        return RestMessage.doSuccess(true);
//
//    }
//
//    @Override
//    @Flow(name = "打印拼箱明细", category = "出库/复核管理/内复核/打印", index = 4, description = "1、校验数据 2、查询获取拼箱数据 3、更新打印次数+1")
//    public PrintData printLclDetail(String stationCode, String billGroupId, String lclNo) {
//        List<PickTaskH> billDOs = validPrintBoxDetailFunc.ValidPrintBoxDetailFunc(stationCode, billGroupId, lclNo);
//        PrintData printData = printLclDetail.PrintLclDetail(stationCode, billGroupId, lclNo, billDOs);
//        return printData;
//    }
//
//    @FuncImpl(name = "打印拼箱明细", func = ValidPrintBoxDetailFunc.class, description = "打印拼箱明细")
//    public List<PickTaskH> validPrintBoxDetailFunc(String stationCode, String billGroupId, String lclNo) {
//        Criteria criteria = Criteria.forClass(PickTaskH.class);
//        criteria.restrictionBuilder().eq("billGroupId", billGroupId);
//        criteria.buildRestriction();
//        List<PickTaskH> pickTaskHList = pickTaskHMapper.findByCriteria(criteria);
//        if (pickTaskHList.isEmpty()) {
//            throw new BizException("找不到复核信息");
//        }
//        return pickTaskHList;
//    }
//
//    @FuncImpl(name = "打印拼箱明细", func = PrintLclDetail.class, description = "打印拼箱明细")
//    public PrintData printLclDetail(String stationCode, String billGroupId, String lclNo, List<PickTaskH> pickTaskHList) {
//        PrintData printData = new PrintData();
//        List<ReportData> reportDatas = new ArrayList<>();
//        printData.setData(reportDatas);
//        ReportData reportData = new ReportData();
//
//        Map<String, Object> head = new HashMap<>();
//        List<Map<String, Object>> tables = new ArrayList<>();
//        reportData.setHead(head);
//        reportData.setTable(tables);
//        reportDatas.add(reportData);
//        List<LclDetailHeadVO> lclDetaiHeadForPrints = billMapper.getLclDetaiHeadForPrint(billGroupId);
//        if (lclDetaiHeadForPrints.isEmpty()) {
//            throw new BizException("找不到对应的订单");
//        }
//        String billCodes = lclDetaiHeadForPrints.stream().
//                map(LclDetailHeadVO::getErpBillNo).
//                distinct().
//                collect(Collectors.joining(","));
//        List<WorkStageRuntimeDO> workStages =
//                workStageRuntimeMapper.findByMap(MapUtils.put("billGroupId", billGroupId).getMap(),
//                        WorkStageRuntimeDO.class);
//
//
//        String stageCodes = workStages.stream().
//                map(WorkStageRuntimeDO::getStageCode).
//                distinct().
//                collect(Collectors.joining(","));
//        PickTaskH pickTaskH =pickTaskHList.get(0);
//        List<PickTaskD> pickTaskDList=pickTaskDMapper.findByMap(MapUtils.put("pickTaskId", pickTaskH.getPickTaskId()).getMap(),PickTaskD.class);
//        Set<String> checkerNameSet = pickTaskDList.stream().map(PickTaskD::getCheckerName).collect(Collectors.toSet());
//        LclDetailHeadVO lclDetailHeadVO = lclDetaiHeadForPrints.get(0);
//        if(checkerNameSet!=null && checkerNameSet.size()>0){
//            lclDetailHeadVO.setChecker(String.join(",", checkerNameSet));
//        }
//
//        lclDetailHeadVO.setBillNo(billCodes);
//        lclDetailHeadVO.setStageCode(stageCodes);
//        List<BarcodeHDO> barcodeHDOS = barcodeHMapper.findByMap(MapUtils.put("billGroupId", billGroupId).getMap(), BarcodeHDO.class);
//
//        int totalCaseQty = barcodeHDOS.size();
//        lclDetailHeadVO.setTotalCaseQty(String.valueOf(totalCaseQty));
//
//
//        long zxQty = barcodeHDOS.stream().filter(barcodeHDO -> barcodeHDO.getLclNo() == null).count();
//        long lclQty = totalCaseQty - zxQty;
//        lclDetailHeadVO.setZxQty(String.valueOf(zxQty));
//        lclDetailHeadVO.setLclQty(String.valueOf(lclQty));
//        BeanMap beanMap = BeanMap.create(lclDetailHeadVO);
//        head.putAll(beanMap);
//
//        List<LclDetailTableVO> lclDetailTables = barcodeDMapper.getLclDetail(billGroupId, Integer.valueOf(lclNo));
//        if (lclDetailTables.isEmpty()) {
//            throw new BizException("找不到对应的拼箱");
//        }
//        for (int i = 0; i < lclDetailTables.size(); i++) {
//            LclDetailTableVO lclDetailTableVO = lclDetailTables.get(i);
//            BigDecimal conversionRate = lclDetailTableVO.getConversionRate();
//            BigDecimal pieceQty = lclDetailTableVO.getPieceQty();
//            if (conversionRate != null && (!conversionRate.equals(BigDecimal.ZERO))) {
//                BigDecimal[] bigDecimals = pieceQty.divideAndRemainder(conversionRate);
//                lclDetailTableVO.setCaseQty(bigDecimals[0]);
//                lclDetailTableVO.setOddPieceQty(bigDecimals[1]);
//            }
//            lclDetailTableVO.setLineNum(String.valueOf(i + 1));
//            BeanMap tableMap = BeanMap.create(lclDetailTableVO);
//            tables.add(tableMap);
//        }
//
//        return printData;
//    }
//
//    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;
//    }
//
//    @Deprecated
//    private void updateLclD(String stationCode, String billGroupId, String itemCode,
//                            String itemId, BigDecimal qty,
//                            String containerCode,
//                            PickTaskD pickTaskD) {
//        BarcodeHDO lclNo = getDefaultLclNo(stationCode, billGroupId, containerCode,pickTaskD);
//        String lclHId = lclNo.getId();
//        updateLcl(lclHId, itemCode, itemId, qty, containerCode, pickTaskD.getPickTaskDId(),pickTaskD.getPickTaskType(),pickTaskD.getWarehouseId());
//    }
//
//    private void addLclDQty(String stationCode, String billGroupId, String itemCode,
//                            String itemId,
//                            BigDecimal addQty, String containerCode, String pickTaskDId) {
//        BarcodeHDO lclNo = getDefaultLclNo(stationCode, billGroupId, containerCode,null);
//        String lclHId = lclNo.getId();
//        long id = SnowFlakeUtils.getId(dataCenterId,machineId);
//        updateLclQtyTemp(lclHId, itemCode, itemId ,addQty,  containerCode,
//                pickTaskDId, 1,lclNo.getWarehouseId());
//
//    }
//
//
//    @Deprecated
//    @Override
//    @Transactional
//    public RestMessage<InnerCheckBillVO> checkItemByNum(CheckInfoDTO checkInfoDTO) {
//        PickTaskD pickTaskD=new PickTaskD();
//        ItemBarCodeVO itemBarCodeVO=new ItemBarCodeVO();
//        validInnerCheckFunc.validInnerCheckFunc(checkInfoDTO, false, true, false,pickTaskD,itemBarCodeVO);
//        updatePickupDInnerCheckInfoFunc.updatePickupDInnerCheckInfoFunc(checkInfoDTO, false, true, false,pickTaskD,itemBarCodeVO);
//        RestMessage<InnerCheckBillVO> innerCheckBillVORestMessage = createBarcodeFunc.createBarcodeFunc(checkInfoDTO,
//                false, true, false,pickTaskD,itemBarCodeVO);
//        return innerCheckBillVORestMessage;
//    }
//
//    //扫码复核
//    @Deprecated
//    @Override
//    @Transactional
//    @Flow(name = "商品内复核", category = "出库/复核管理/内复核/商品内复核", index = 2, description = "1、数据校验2、更新拼箱数量WMS_PICK_TASK_D" +
//            "3、判断是否为2次复核，二次复核不生成拼箱数据，一次复核生成拼箱数据")
//    public RestMessage<InnerCheckBillVO> checkItem(CheckInfoDTO checkInfoDTO) {
//        PickTaskD pickTaskD=new PickTaskD();
//        ItemBarCodeVO itemBarCodeVO=new ItemBarCodeVO();
//        validInnerCheckFunc.validInnerCheckFunc(checkInfoDTO, true, false, false,pickTaskD,itemBarCodeVO);
//        updatePickupDInnerCheckInfoFunc.updatePickupDInnerCheckInfoFunc(checkInfoDTO, true, false, false,pickTaskD,itemBarCodeVO);
//        RestMessage<InnerCheckBillVO> innerCheckBillVORestMessage = createBarcodeFunc.createBarcodeFunc(checkInfoDTO,
//                true, false, false,pickTaskD,itemBarCodeVO);
//        return innerCheckBillVORestMessage;
//    }
//
//    @FuncImpl(name = "波次创建入参校验", func = ValidInnerCheckFunc.class, description = "波次创建入参校验")
//    public void validInnerCheckFunc(CheckInfoDTO checkInfoDTO, boolean byScan, boolean isByNum,
//                                    boolean redCheck,PickTaskD pickTaskD, ItemBarCodeVO itemBarCodeVO) {
//        String itemBarcode = checkInfoDTO.getItemBarcode();
//        String containerCode = checkInfoDTO.getContainerCode();
//        String stationCode = checkInfoDTO.getStationCode();
//        String billGroupId = checkInfoDTO.getBillGroupId();
//        AssertUtils.isNotNull(containerCode, stationCode, billGroupId);
//        String pickTaskDId = checkInfoDTO.getPickTaskDId();
//        List<WaveStorageDO> storageDOS = storageMapper.getStorageByPickTaskDId(pickTaskDId);
//        if (storageDOS.size() != 1) {
//            throw new PrologException("找不到对应的库存预占信息");
//        }
//        WaveStorageDO waveStorageDO = storageDOS.get(0);
//        ItemBarCodeVO data = itemClient.getItemByBarCode(checkInfoDTO.getItemBarcode(), waveStorageDO.getItemId()).getData();
//        if (data == null) {
//            throw new ParameterException("该商品信息不存在");
//        }
//        BeanUtils.copyProperties(data,itemBarCodeVO);
//        PickTaskD byId = pickTaskDMapper.findById(pickTaskDId, PickTaskD.class);
//        if (byId == null) {
//            throw new BizException("找不到对应的复核信息");
//        }
//        BeanUtils.copyProperties(byId,pickTaskD);
//        BigDecimal inputQty = checkInfoDTO.getQty();
//        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(inputQty)<0){
//                throw new BizException("数据异常：复核数量 > 拣货数量-红冲数量");
//            }
//        }
//    }
//
//    @FuncImpl(name = "波次创建入参校验", func = UpdatePickupDInnerCheckInfoFunc.class, description = "波次创建入参校验")
//    public void updatePickupDInnerCheckInfoFunc(CheckInfoDTO checkInfoDTO,
//                                                boolean byScan, boolean isByNum, boolean redCheck,PickTaskD pickTaskD, ItemBarCodeVO itemBarCodeVO) {
//        String itemBarcode = checkInfoDTO.getItemBarcode();
//        String containerCode = checkInfoDTO.getContainerCode();
//        String stationCode = checkInfoDTO.getStationCode();
//        String billGroupId = checkInfoDTO.getBillGroupId();
//        AssertUtils.isNotNull(containerCode, stationCode, billGroupId);
//        String pickTaskDId = checkInfoDTO.getPickTaskDId();
//        UserDTO userDTO = userTemplate.getUserDTO();
//        String nickName = userDTO.getNickname();
//        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 = checkInfoDTO.getQty();
//        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);
//    }
//
//    @FuncImpl(name = "波次创建入参校验", func = CreateBarcodeFunc.class, description = "波次创建入参校验")
//    public RestMessage<InnerCheckBillVO> createBarcodeFunc(CheckInfoDTO checkInfoDTO, boolean byScan, boolean isByNum, boolean redCheck, PickTaskD pickTaskD, ItemBarCodeVO itemBarCodeVO) {
//        String itemBarcode = checkInfoDTO.getItemBarcode();
//        String containerCode = checkInfoDTO.getContainerCode();
//        String stationCode = checkInfoDTO.getStationCode();
//        String billGroupId = checkInfoDTO.getBillGroupId();
//        AssertUtils.isNotNull(containerCode, stationCode, billGroupId);
//        String pickTaskDId = checkInfoDTO.getPickTaskDId();
//        UserDTO userDTO = userTemplate.getUserDTO();
//        String nickName = userDTO.getNickname();
//        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 = checkInfoDTO.getQty();
//        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(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, pickTaskDId);
//        }
//        AssertUtils.isNotBlank(pickTaskDId);
//        InnerCheckBillVO containerInfo = findPickupByContainerFunc(containerCode, stationCode, pickTaskDId);
//        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);
//        }
//    }
//
//    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("复核员没有权限复核该商品");
//    }
//
//
//    @Deprecated
//    private void checkByPickTask(String containerCode, String billId, String itemCode, BigDecimal newQty, String user1, String user2) {
//        List<InnerCheckTaskDVO> pickTaskds = pickTaskHMapper.getPickTaskds(billId, containerCode, itemCode);
//
//        boolean isSuccess = false;
//        for (InnerCheckTaskDVO innerCheckTaskDVO : pickTaskds) {
//            String pickTaskDId = innerCheckTaskDVO.getPickTaskDId();
//            log.info(innerCheckTaskDVO.toString());
//            BigDecimal checkQty = innerCheckTaskDVO.getCheckQty();
//            BigDecimal totalQty = innerCheckTaskDVO.getQty();
//            BigDecimal left = totalQty.subtract(checkQty);
//            if (left.compareTo(BigDecimal.ZERO) <= 0) {
//                continue;
//            }
//            int compare = left.subtract(newQty).compareTo(BigDecimal.ZERO);
//            if (compare >= 0) {
//                //@TODO 集群操作 use returning into
//                pickTaskDMapper.addNum(pickTaskDId, user1, user2, newQty);
//                isSuccess = true;
//                innerCheckTaskDVO.setCheckQty(checkQty.add(newQty));
//                break;
//            } else {
//                innerCheckTaskDVO.setCheckQty(totalQty);
//                pickTaskDMapper.addNum(pickTaskDId, user1, user2, left);
//                newQty = newQty.subtract(left);
//            }
//        }
//    }
//
//    private List<InnerCheckTaskDVO> getInnerCheckDetail(String innerCheckHId) {
//        List<InnerCheckDDO> allInnerCheckItems = innerCheckDMapper.findByMap(
//                MapUtils.put("innerCheckHId", innerCheckHId).getMap(),
//                InnerCheckDDO.class);
//
//        List<InnerCheckTaskDVO> collect = allInnerCheckItems.stream().map(s -> {
//            InnerCheckTaskDVO innerCheckTaskDVO = new InnerCheckTaskDVO();
//            innerCheckTaskDVO.setInnerCheckDId(s.getId());
//            BeanUtils.copyProperties(s, innerCheckTaskDVO);
//            return innerCheckTaskDVO;
//        }).collect(Collectors.toList());
//        return collect;
//    }
//
//
//    @Override
//    public RestMessage<Boolean> pickTaskDCheckConfirm(CheckConfirmDTO checkInfoDTO) {
//        String pickTaskDId = checkInfoDTO.getPickTaskDId();
//        AssertUtils.isNotBlank(pickTaskDId);
//        PickTaskD byId = pickTaskDMapper.findById(pickTaskDId, PickTaskD.class);
//        AssertUtils.isNotNull(byId);
//        boolean equals = byId.getQty().equals(byId.getCheckQty());
//        if (equals) {
//            return RestMessage.doSuccess(true);
//        } else {
//            return RestMessage.doError("数量不一致，请更新补偿后确认");
//        }
//    }
//
//
//    @Override
//    @Transactional
//    @Flow(name = "拼箱", category = "出库/复核管理/内复核/拼箱", index = 5, description = "1、校验数据 2、查询获取拼箱数据 3、更新打印次数+1")
//    public RestMessage<BarcodeHDO> addLcl(String stationCode, String billGroupId, String containerCode) {
//        validLCLFunc.validLCLFunc(stationCode, billGroupId, containerCode, new PickTaskD());
//        BarcodeHDO barcodeHDO = lclFunc.LCLFunc(stationCode, billGroupId, containerCode, null,1);
//        BarcodeHDO lclInDB = barcodeHDO;
//        return RestMessage.doSuccess(lclInDB);
//    }
//
//    @FuncImpl(name = "验证拼箱", func = ValidLCLFunc.class, description = "验证拼箱")
//    public void validLCLFunc(String stationCode, String billGroupId, String containerCode, PickTaskD pickTaskD) {
//
//    }
//
//    @FuncImpl(name = "增加箱子", func = LCLFunc.class, description = "增加箱子")
//    public BarcodeHDO lclFunc(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(stationCode, billGroupId, 0, containerCode,pickTaskD,isPiece));
//                }else{
//                    List<BarcodeHDO> lclNo = barcodeHMapper.getLclNo(null, billGroupId, null,null);
//                    if (lclNo.isEmpty()) {
//                        startNum.set(1);
//                    } else {
//                        startNum.set(Optional.ofNullable(lclNo.get(0).getLclNo()).orElse(0) + 1);
//                    }
//                    lclInDB.set(createLclInDB(stationCode, billGroupId, startNum.get(), 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 getDefaultLclNo(String stationCode, String billGroupId, String containerCode, PickTaskD pickTaskD) {
//        if(pickTaskD!=null && pickTaskD.getPickTaskType()==0){//整件生成新的拼箱
//            return lclFunc(stationCode, billGroupId, containerCode, pickTaskD,0);
//        }
//        List<BarcodeHDO> lclNo = barcodeHMapper.getLclNo(stationCode, billGroupId, '0',null);
//        List<BarcodeHDO> List = lclNo.stream().filter(x -> x.getLclNo() != 0).collect(Collectors.toList());
//        if (List==null || List.isEmpty()) {
//            log.info("找不到合适的拼箱，create one");
//            return lclFunc(stationCode, billGroupId, containerCode, pickTaskD,1);
//        } else {
//            BarcodeHDO barCodeHDO = List.get(0);
//            return barCodeHDO;
//        }
//    }
//
//    private BarcodeHDO createLclInDB(String stationCode, String billGroupId,
//                                     Integer startNum, 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(startNum);
//        if(pickTaskH.getPickTaskType()==3 && startNum==null){
//            barCodeHDO.setLclNo(0);
//        }else{
//            barCodeHDO.setLclNo(startNum);
//        }
//
//        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;
//    }
//
//    @Override
//    public RestMessage<String> getItemInfo(String itemBarcode, String billGroupId) {
//        AssertUtils.isNotBlank(billGroupId);
//        ItemBarCodeVO itemByBarCode = itemClient.getItemByBarCode(itemBarcode,null).getData();
//        AssertUtils.isNotNull(itemByBarCode);
//        String itemCode = itemByBarCode.getItemCode();
//        return RestMessage.doSuccess(itemCode);
//    }
//
//    @Override
//    @Transactional
//    public void saveInnerCheckDetails(CheckConfirmDTO checkConfirmDTO) {
//        List<InnerCheckTaskDVO> innerCheckTaskDVOS=checkConfirmDTO.getInnerCheckTaskDVOS();
//        String[] arr= innerCheckTaskDVOS.stream().map(t->t.getPickTaskDId()).toArray(String[]::new);
//        if(arr!=null && arr.length>0){
//            PickTaskD pickTaskD=pickTaskDMapper.findById(arr[0],PickTaskD.class);
//            String pickTaskId = pickTaskD.getPickTaskId();
//            PickTaskH pickTaskH=pickTaskHMapper.findById(pickTaskId,PickTaskH.class);
//            if(pickTaskH!=null && 3==pickTaskH.getPickTaskType()){
//                throw new BizException("整单拣选，不需要修改拼箱号");
//            }
//            Criteria cr1 = Criteria.forClass(PickTaskD.class);
//            //明细流程状态：1-生成拣货任务 2-拣货已索取 3-拣货已确认 4-内复核已索取 5-内复核已确认 6-外复核已索取 7-外复核已确认 8-拣货冲红
//
//            cr1.restrictionBuilder().eq("pickTaskId", pickTaskId).in("flowStatus",new String[]{"1","2","3","4"});
//            cr1.buildRestriction();
//            if(pickTaskDMapper.findCountByCriteria(cr1)>0L){
//                throw new BizException("容器所有商品复核完成后才可以修改拼箱");
//            }
//        }
//        if(innerCheckTaskDVOS!=null && innerCheckTaskDVOS.size()>0){
//            for (int i = 0; i < innerCheckTaskDVOS.size(); i++) {
//                InnerCheckTaskDVO innerCheckTaskDVO=innerCheckTaskDVOS.get(i);
//                List<BarcodeHDO> list = barcodeHMapper.findByMap(MapUtils.put("billGroupId", checkConfirmDTO.getBillGroupId()).
//                        put("lclNo", innerCheckTaskDVO.getLclNo()).getMap(), BarcodeHDO.class);
//                if(list==null || list.size()==0){
//                    throw new BizException("拼箱号不存在");
//                }
//                String barcodeHId = list.get(0).getId();
//                if(!checkConfirmDTO.getStationCode().equals(list.get(0).getStationCode())){
//                    throw new BizException("不能修改修改拼箱号到不同复核台");
//                }
//                String barcodeDId = innerCheckTaskDVO.getBarcodeDId();
//                if(StringUtils.isBlank(barcodeDId)){
//                    BarCodeDDO barCodeDDO = new BarCodeDDO();
//                    barCodeDDO.setBarcodeId(barcodeHId);
//                    barCodeDDO.setWmsPickTaskDId(innerCheckTaskDVO.getPickTaskDId());
//                    barCodeDDO.setContainerCode(checkConfirmDTO.getContainerCode());
//                    barCodeDDO.setId(String.valueOf(SnowFlakeUtils.getId(dataCenterId,machineId)));
//                    barCodeDDO.setEnterpriseId(userTemplate.getUserDTO().getEnterpriseId());
//                    barCodeDDO.setWarehouseId(innerCheckTaskDVO.getWarehouseId());
//                    barCodeDDO.setItemId(innerCheckTaskDVO.getItemId());
//                    barCodeDDO.setItemCode(innerCheckTaskDVO.getItemCode());
//                    BigDecimal check2Qty = innerCheckTaskDVO.getCheck2Qty();
//                    if(check2Qty !=null && check2Qty.compareTo(BigDecimal.ZERO)>0){
//                        barCodeDDO.setQty(check2Qty);
//                    }else{
//                        barCodeDDO.setQty(innerCheckTaskDVO.getCheckQty());
//                    }
//                    barCodeDDO.setIsPiece(1);
//                    barcodeDMapper.save(barCodeDDO);
//                }else{
//                    barcodeDMapper.updateMapById(barcodeDId, MapUtils.put("barcodeId", barcodeHId).getMap(),BarCodeDDO.class);
//                }
//            }
//        }
//    }
//
//    @Flow(name = "内复核确认", category = "出库/复核管理/内复核/内复核确认", index = 7, description = "1、校验：复核数量&是否打印等 2、更新pick_task_h status=10 3、更新barcode_h check_status=0")
//    @Override
//    @Transactional
//    public RestMessage<List> containerCheckConfirm(CheckConfirmDTO checkConfirmDTO) {
//        List<InnerCheckDDO> innerCheckDs = validInnerCheckConfirmFunc.validInnerCheckConfirmFunc(checkConfirmDTO);
//        RestMessage<List> stringRestMessage = innerCheckConfirmFunc.innerCheckConfirmFunc(checkConfirmDTO, innerCheckDs);
//        return stringRestMessage;
//    }
//
//    @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<List> 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 = barcodeHMapper.getLclNo(stationCode, billGroupId, null,null);
//        if(lclNos==null || lclNos.size()==0){
//            throw new BizException("拼箱数据不能为空");
//        }
//        List<Integer> lclLists = lclNos.stream().filter(barcodeH -> barcodeH.getLclNo() != 0 ).
//                map(BarcodeHDO::getLclNo).collect(Collectors.toList());
//        Set<Integer> 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());
//        return RestMessage.doSuccess(oneCarOneBillTasks.stream().map(t->t.getContainerCode()).collect(Collectors.toList()));
//    }
//
//    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);
//    }
//
//    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 Map innerCheckConfig(String warehouseId){
//        Map<String,Object> map=new HashMap();
//        RestMessage<BaseWmsWarehouseMst> itemResultWarehouse = warehouseResource.warehouse(warehouseId);
//        if (itemResultWarehouse.isSuccess() && itemResultWarehouse.getData() != null) {
//            BaseWmsWarehouseMst wmsWarehouseMst=itemResultWarehouse.getData();
//            //扫描监管码节点：0=整件拣货、零货拣货 1=整件外复核、零货拣货 2=整件拣货、零货内复核 3=整件外复核、零货内复核
//            if(wmsWarehouseMst!=null){
//                map.put("scanSupervisionCodeStage",wmsWarehouseMst.getScanSupervisionCodeStage());
//            }
//        }
//        RestMessage<BusinessControl> rest = strategyResource.getControlByCode("PICK_TASK_ASK_WAY",
//                warehouseId, null, userTemplate.getUserDTO().getEnterpriseId(), null);
//        if (rest.isSuccess() && rest.getData() != null) {
//            map.put("pickWay",rest.getData().getRegValue());
//        }
//        return map;
//    }
//}
