package com.xisc.pm.app.service.strategy.secondarydesign;

import com.google.common.collect.Maps;
import com.xisc.pm.api.dto.PmProContFilterRequestDTO;
import com.xisc.pm.api.dto.PmProContYieldRequestDTO;
import com.xisc.pm.api.dto.PmProContYieldResposeDTO;
import com.xisc.pm.domain.entity.PmCmdLargePlt;
import com.xisc.pm.domain.entity.PmCmdSlab;
import com.xisc.pm.domain.entity.PmContMscTech;
import com.xisc.pm.domain.entity.PmPdCcSlab;
import com.xisc.pm.domain.entity.PmPdConstBt;
import com.xisc.pm.domain.entity.PmPdContSum;
import com.xisc.pm.domain.entity.PmPdSlab;
import com.xisc.pm.domain.entity.PmProContProdTtr;
import com.xisc.pm.domain.entity.PmSlabEstaPlan;
import com.xisc.pm.domain.repository.PmPdCcSlabRepository;
import com.xisc.pm.domain.repository.PmPdConstBtRepository;
import com.xisc.pm.domain.repository.PmPdSlabRepository;
import com.xisc.pm.domain.repository.PmSlabEstaPlanRepository;
import com.xisc.pm.infra.constant.Constants;
import com.xisc.pm.infra.constant.PmPlateConstants;
import com.xisc.pm.infra.enums.PdMatType;
import com.xisc.pm.infra.enums.PdRuleSetType;
import com.xisc.pm.infra.mapper.WmMatPileMapper;
import com.xisc.pm.infra.util.PlatePreProcUtils;
import com.xisc.pm.infra.util.Utils;
import io.choerodon.core.exception.CommonException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.compress.utils.Lists;
import org.hzero.core.base.BaseConstants;
import org.hzero.mybatis.domian.Condition;
import org.hzero.mybatis.util.Sqls;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * (钢锭余坯)二次设计
 *
 * @author jun.zeng
 */
@Component
public class IgSlabSecondaryDesignStrategy extends DefaultSecondaryDesignStrategy<PmPdSlab> {

    @Autowired
    private PmPdSlabRepository pmPdSlabRepository;

    @Autowired
    private PmPdCcSlabRepository pmPdCcSlabRepository;

    @Autowired
    private PmPdConstBtRepository pmPdConstBtRepository;

    @Autowired
    private WmMatPileMapper wmMatPileMapper;

    @Autowired
    private PmSlabEstaPlanRepository pmSlabEstaPlanRepository;

    @Override
    protected boolean hasPmCmdSlab() {
        return true;
    }

    @Override
    protected void remove() {
        PM_PD_CONST_LOCAL.remove();
        PM_PD_CC_SLAB_LOCAL.remove();
        PM_PD_SLAB_INFO_REMAIN_LEN_LOCAL.remove();
        super.remove();
    }

    // 本地变量
    private static final ThreadLocal<Map<String, PmPdCcSlab>> PM_PD_CC_SLAB_LOCAL = new ThreadLocal<>();
    // 余坯剩余板坯长
    private static final ThreadLocal<Map<String, BigDecimal>> PM_PD_SLAB_INFO_REMAIN_LEN_LOCAL = new ThreadLocal<>();
    // 组板常量配置表
    private static final ThreadLocal<Map<String, PmPdConstBt>> PM_PD_CONST_LOCAL = new ThreadLocal<>();

    @Override
    protected Map<String, PmPdSlab> selectByMatNo(List<String> virtualSlabNo, Long tenantId) {
        List<PmPdSlab> pmPdSlabs = pmPdSlabRepository.selectByCondition(
                Condition.builder(PmPdSlab.class).andWhere(Sqls.custom().andEqualTo(PmPdSlab.FIELD_TENANT_ID, tenantId)
                        .andIn(PmPdSlab.FIELD_VIRTUAL_SLAB_NO, virtualSlabNo)).build());
        Map<String, PmPdSlab> pmPdSlabMap = Maps.newHashMap();
        Map<String, PmPdCcSlab> pmPdCcSlabMap = Maps.newHashMap();
        Map<String, BigDecimal> remainSlabLenMap = Maps.newHashMap();
        Map<String, PmPdConstBt> pmPdConstBtMap = Maps.newHashMap();
        if (pmPdSlabs == null || pmPdSlabs.isEmpty()) {
            PM_PD_CC_SLAB_LOCAL.set(pmPdCcSlabMap);
            return pmPdSlabMap;
        }
        List<String> slabNoList = Lists.newArrayList();
        for (PmPdSlab pmPdSlab : pmPdSlabs) {
            pmPdSlabMap.put(pmPdSlab.getVirtualSlabNo(), pmPdSlab);
            slabNoList.add(pmPdSlab.getSlabNo());
        }
        List<PmPdCcSlab> pmPdcSlabList = pmPdCcSlabRepository.selectByCondition(Condition
                .builder(PmPdCcSlab.class).andWhere(Sqls.custom().andEqualTo(PmPdCcSlab.FIELD_TENANT_ID, tenantId)
                        .andIn(PmPdCcSlab.FIELD_VIRTUAL_SLAB_NO, slabNoList))
                .build());
        List<String> rollLineNoList = Lists.newArrayList();
        if (pmPdcSlabList != null && !pmPdcSlabList.isEmpty()) {
            for (PmPdCcSlab pmPdCcSlab : pmPdcSlabList) {
                pmPdCcSlabMap.put(pmPdCcSlab.getVirtualSlabNo(), pmPdCcSlab);
                remainSlabLenMap.put(pmPdCcSlab.getVirtualSlabNo(), pmPdCcSlab.getRollAimLen());
                rollLineNoList.add(Utils.mscLineNoToRoolLineNo(pmPdCcSlab.getMscLineNo()));
            }
        }

        List<PmPdSlab> allPmPdSlabs = pmPdSlabRepository.selectByCondition(Condition.builder(PmPdSlab.class).andWhere(
                        Sqls.custom().andEqualTo(PmPdSlab.FIELD_TENANT_ID, tenantId).andIn(PmPdSlab.FIELD_SLAB_NO, slabNoList))
                .build());
        for (PmPdSlab pmPdSlab : allPmPdSlabs) {
            if (!pmPdSlabMap.containsKey(pmPdSlab.getVirtualSlabNo()) && !BaseConstants.Flag.NO.toString().equals(pmPdSlab.getOrderRemainDiv())) {
                // 余坯组版二次设计，必须选中全部分割坯，余坯【{0}】的分割坯【{1}】未选中。
                throw new CommonException("pm.pm_pd_slab_001", pmPdSlab.getSlabNo(), pmPdSlab.getVirtualSlabNo());
            }
        }

        List<PmPdConstBt> pmPdConstBtList = pmPdConstBtRepository.selectByCondition(Condition.builder(PmPdConstBt.class)
                .andWhere(Sqls.custom().andIn(PmPdConstBt.FIELD_ROLL_LINE_NO, rollLineNoList))
                .andWhere(Sqls.custom().andEqualTo(PmPdConstBt.FIELD_TENANT_ID, tenantId)).build());
        if (pmPdConstBtList != null && !pmPdConstBtList.isEmpty()) {
            for (PmPdConstBt pmPdConstBt : pmPdConstBtList) {
                pmPdConstBtMap.put(pmPdConstBt.getRollLineNo(), pmPdConstBt);
            }
        }
        PM_PD_CONST_LOCAL.set(pmPdConstBtMap);
        PM_PD_CC_SLAB_LOCAL.set(pmPdCcSlabMap);
        PM_PD_SLAB_INFO_REMAIN_LEN_LOCAL.set(remainSlabLenMap);
        return pmPdSlabMap;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void secondaryDesign(Long tenantId, List<PmCmdLargePlt> pmCmdLargePltList) {
        if (pmCmdLargePltList == null || pmCmdLargePltList.isEmpty()) {
            return;
        }
        super.secondaryDesign(tenantId, pmCmdLargePltList);
    }

    @Override
    protected PmProContYieldResposeDTO yiledCalc(PmCmdLargePlt pmCmdLargePlt, PmProContYieldRequestDTO pmProContYield,
                                                 PmProContProdTtr axisPmProContProdTtr) {
        PmProContYieldResposeDTO resposeDTO = super.yiledCalc(pmCmdLargePlt, pmProContYield, axisPmProContProdTtr);
        // 计算完成之后更新剩余板坯长
        BigDecimal remainSlabLen = PM_PD_SLAB_INFO_REMAIN_LEN_LOCAL.get().get(pmCmdLargePlt.getSlabNo());
        PmPdConstBt pmPdConstBt = PM_PD_CONST_LOCAL.get()
                .get(Utils.mscLineNoToRoolLineNo(pmCmdLargePlt.getMscLineNo()));
        remainSlabLen = remainSlabLen.subtract(resposeDTO.getPreCleanSlabLen());
        if (pmPdConstBt != null && pmPdConstBt.getSlabCutGap() != null) {
            remainSlabLen = remainSlabLen.subtract(pmPdConstBt.getSlabCutGap());
        }
        PM_PD_SLAB_INFO_REMAIN_LEN_LOCAL.get().put(pmCmdLargePlt.getSlabNo(), remainSlabLen);
        return resposeDTO;
    }

    @Override
    protected PmProContFilterRequestDTO buildPmProContFilterRequestDTO(
            PmProContYieldRequestDTO pmProContYieldRequestDTO, PmPdSlab salbInfo, PmCmdLargePlt pmCmdLargePlt) {
        pmProContYieldRequestDTO.setPmPdSlab(salbInfo);
        Map<String, PmPdCcSlab> pmPdSlabInfoMap = PM_PD_CC_SLAB_LOCAL.get();
        PmPdCcSlab pmPdCcSlab = pmPdSlabInfoMap.get(salbInfo.getSlabNo());
        PmProContFilterRequestDTO pmContFilterRequest = new PmProContFilterRequestDTO();
        pmContFilterRequest.setTransFlag(salbInfo.getTransFlag() == null ? null : salbInfo.getTransFlag().toString());
        pmContFilterRequest.setMoldThick(pmPdCcSlab.getMoldThick());
        pmContFilterRequest.setMoldWidth(pmPdCcSlab.getMoldWid());
        pmContFilterRequest.setStNo(salbInfo.getStNo());
        pmContFilterRequest.setSgSign(salbInfo.getSgSign());
        pmContFilterRequest.setFurType(salbInfo.getFurType());
        pmContFilterRequest.setCcType(pmPdCcSlab.getCcType());
        pmContFilterRequest.setMatDesignKind(salbInfo.getMatDesignKind());
        pmContFilterRequest.setFixSlabLenFlag(salbInfo.getFixSlabLenFlag());
        pmContFilterRequest.setFixSlabLen(salbInfo.getFixSlabLen());
        pmContFilterRequest.setSampleLenGice(salbInfo.getFixSlabLen());
        pmContFilterRequest.setMscLineNo(salbInfo.getMscLineNo());
        pmContFilterRequest.setFormPlateMode(salbInfo.getFormPlateMode());
        pmContFilterRequest.setRollDirectCode(salbInfo.getRollDirectCode());
        pmContFilterRequest.setRemainSlabLen(PM_PD_SLAB_INFO_REMAIN_LEN_LOCAL.get().get(salbInfo.getSlabNo()));
        return pmContFilterRequest;
    }

    @Override
    protected PmPdSlab updateSlabInfo(PmPdSlab salbInfo, PmProContYieldResposeDTO pmProContYieldRespose,
                                      String pdStatusHp) {
        PmPdSlab updatePmPdSlab = new PmPdSlab();
        if (pmProContYieldRespose != null) {
            updatePmPdSlab.setPreCleanSlabLen(pmProContYieldRespose.getPreCleanSlabLen());
            updatePmPdSlab.setPreCleanSlabMaxLen(pmProContYieldRespose.getPreCleanSlabMaxLen());
            updatePmPdSlab.setPreCleanSlabMinLen(pmProContYieldRespose.getPreCleanSlabMinLen());
            updatePmPdSlab.setPreCleanSlabWt(pmProContYieldRespose.getPreCleanSlabWt());
            updatePmPdSlab.setPreCleanSlabMaxWt(pmProContYieldRespose.getPreCleanSlabMaxWt());
            updatePmPdSlab.setPreCleanSlabMinWt(pmProContYieldRespose.getPreCleanSlabMinWt());
            updatePmPdSlab.setInfurSlabLen(pmProContYieldRespose.getInfurSlabLen());
            updatePmPdSlab.setInfurSlabMaxLen(pmProContYieldRespose.getInfurSlabMaxLen());
            updatePmPdSlab.setInfurSlabMinLen(pmProContYieldRespose.getInfurSlabMinLen());
            updatePmPdSlab.setInfurSlabWt(pmProContYieldRespose.getInfurSlabWt());
            updatePmPdSlab.setInfurSlabMaxWt(pmProContYieldRespose.getInfurSlabMaxWt());
            updatePmPdSlab.setInfurSlabMinWt(pmProContYieldRespose.getInfurSlabMinWt());
            updatePmPdSlab.setNeedSlabLen(pmProContYieldRespose.getNeedSlabLen());
            updatePmPdSlab.setNeedSlabWt(pmProContYieldRespose.getNeedSlabWt());
            updatePmPdSlab.setRollAimThick(pmProContYieldRespose.getTaim());
            updatePmPdSlab.setRollAimWidth(pmProContYieldRespose.getWaim());
            updatePmPdSlab.setRollAimLen(pmProContYieldRespose.getLaim());
            updatePmPdSlab.setRollYield(pmProContYieldRespose.getRollYield());
            updatePmPdSlab.setCommandYield(pmProContYieldRespose.getCommandYield());
            updatePmPdSlab.setNormYield(pmProContYieldRespose.getNormYield());
            updatePmPdSlab.setHeadCut(pmProContYieldRespose.getHeadCut());
            updatePmPdSlab.setTailCut(pmProContYieldRespose.getTailCut());
        }
        updatePmPdSlab.setPdStatusHp(pdStatusHp);
        updatePmPdSlab.setObjectVersionNumber(salbInfo.getObjectVersionNumber());
        updatePmPdSlab.setPmPdSlabId(salbInfo.getPmPdSlabId());
        return updatePmPdSlab;
    }

    /**
     * 二次设计如果存在余材/无合同区分，需要更新最后一块板坯
     *
     * @param pmPdSlab
     * @return
     */
    private PmCmdSlab dealOrderRemainFiv(PmPdSlab pmPdSlab) {
        List<PmCmdSlab> pmCmdSlabs = this.pmCmdSlabRepository.selectByCondition(Condition.builder(PmCmdSlab.class)
                .andWhere(Sqls.custom().andEqualTo(PmCmdSlab.FIELD_TENANT_ID, pmPdSlab.getTenantId()).andEqualTo(PmCmdSlab.FIELD_SLAB_NO
                        , pmPdSlab.getSlabNo()).andEqualTo(PmCmdSlab.FIELD_ORDER_REMAIN_DIV, BaseConstants.Flag.NO.toString())).build());
        if (pmCmdSlabs == null || pmCmdSlabs.isEmpty()) {
            return null;
        }
        BigDecimal remainLen = PM_PD_SLAB_INFO_REMAIN_LEN_LOCAL.get().get(pmPdSlab.getSlabNo());
        pmPdSlab.setPreCleanSlabLen(remainLen);
        pmPdSlab.setPreCleanSlabMaxLen(pmPdSlab.getPreCleanSlabLen());
        pmPdSlab.setPreCleanSlabMinLen(pmPdSlab.getPreCleanSlabLen());
        // 体积
        BigDecimal volume = pmPdSlab.getPreCleanSlabLen().multiply(pmPdSlab.getPreCleanSlabThick()).multiply(pmPdSlab.getPreCleanSlabWidth());
        // 立方毫米转化为立方厘米
        volume = volume.divide(PmPlateConstants.CM3_TO_MM3).setScale(PmPlateConstants.TEM_SCALE, RoundingMode.HALF_UP);
        // 体积*密度 再转化为吨；
        BigDecimal wt = volume.multiply(PmPlateConstants.DEFAULT_PROD_DENCITY).divide(PmPlateConstants.GRAM_TO_TON).setScale(PmPlateConstants.WT_SCALE, RoundingMode.HALF_UP);
        pmPdSlab.setPreCleanSlabWt(wt);
        pmPdSlab.setPreCleanSlabMaxWt(wt);
        pmPdSlab.setPreCleanSlabMinWt(wt);

        pmPdSlab.setInfurSlabLen(pmPdSlab.getPreCleanSlabLen());
        pmPdSlab.setInfurSlabMaxLen(pmPdSlab.getPreCleanSlabLen());
        pmPdSlab.setInfurSlabMinLen(pmPdSlab.getPreCleanSlabLen());
        pmPdSlab.setInfurSlabWt(wt);
        pmPdSlab.setInfurSlabMaxWt(wt);
        pmPdSlab.setInfurSlabMinWt(wt);
        pmPdSlab.setNeedSlabLen(pmPdSlab.getPreCleanSlabLen());
        pmPdSlab.setNeedSlabWt(wt);
        PmCmdSlab newPmCmdSlab = new PmCmdSlab();
        newPmCmdSlab.setPreCleanSlabLen(pmPdSlab.getPreCleanSlabLen());
        newPmCmdSlab.setPreCleanSlabMaxLen(pmPdSlab.getPreCleanSlabMaxLen());
        newPmCmdSlab.setPreCleanSlabMinLen(pmPdSlab.getPreCleanSlabMinLen());
        newPmCmdSlab.setPreCleanSlabWt(pmPdSlab.getPreCleanSlabWt());
        newPmCmdSlab.setPreCleanSlabMaxWt(pmPdSlab.getPreCleanSlabMaxWt());
        newPmCmdSlab.setPreCleanSlabMinWt(pmPdSlab.getPreCleanSlabMinWt());
        newPmCmdSlab.setInfurSlabLen(pmPdSlab.getInfurSlabLen());
        newPmCmdSlab.setInfurSlabMaxLen(pmPdSlab.getInfurSlabMaxLen());
        newPmCmdSlab.setInfurSlabMinLen(pmPdSlab.getInfurSlabMinLen());
        newPmCmdSlab.setInfurSlabWt(pmPdSlab.getInfurSlabWt());
        newPmCmdSlab.setInfurSlabMaxWt(pmPdSlab.getInfurSlabMaxWt());
        newPmCmdSlab.setInfurSlabMinWt(pmPdSlab.getInfurSlabMinWt());
        newPmCmdSlab.setNeedSlabLen(pmPdSlab.getNeedSlabLen());
        newPmCmdSlab.setNeedSlabWt(pmPdSlab.getNeedSlabWt());
        newPmCmdSlab.setPdStatusHp(Constants.PdStatusHp.PD_STATUS_HP_23);
        newPmCmdSlab.setObjectVersionNumber(pmCmdSlabs.get(0).getObjectVersionNumber());
        newPmCmdSlab.setPmCmdSlabId(pmCmdSlabs.get(0).getPmCmdSlabId());
        return newPmCmdSlab;
    }

    @Override
    protected void execUpdateSlabInfo(List<PmPdSlab> slabInfoList) {
        // 会有重复的数据，因为大板表在组炉会多存合并的一条
        List<PmPdSlab> deduplicatedList = slabInfoList.stream().collect(Collectors.toMap(PmPdSlab::getPmPdSlabId, Function.identity(), (k, v) -> k)).values().stream().collect(Collectors.toList());
        List<String> slabNoList = new ArrayList<>();
        String pdStatusHp = null;
        List<PmCmdSlab> pmCmdSlabs = new ArrayList<>();
        for (PmPdSlab pmPdSlab : deduplicatedList) {
            slabNoList.add(pmPdSlab.getSlabNo());
            pdStatusHp = pmPdSlab.getPdStatusHp();
            if (Constants.PdStatusHp.PD_STATUS_HP_23.equals(pmPdSlab.getPdStatusHp()) && BaseConstants.Flag.NO.toString().equals(pmPdSlab.getOrderRemainDiv())) {
                // 如果是二次设计状态
                PmCmdSlab pmCmdSlab = dealOrderRemainFiv(pmPdSlab);
                if (pmCmdSlab != null) {
                    pmCmdSlabs.add(pmCmdSlab);
                }
            }
        }
        List<PmPdCcSlab> updatePmPdSlabInfos = new ArrayList<PmPdCcSlab>();
        if (PM_PD_CC_SLAB_LOCAL.get() != null && PM_PD_CC_SLAB_LOCAL.get().values() != null
                && !PM_PD_CC_SLAB_LOCAL.get().values().isEmpty()) {
            for (PmPdCcSlab pmPdCcSlab : PM_PD_CC_SLAB_LOCAL.get().values()) {
                PmPdCcSlab updatePmPdSlabInfo = new PmPdCcSlab();
                updatePmPdSlabInfo.setPdStatusHp(pdStatusHp);
                updatePmPdSlabInfo.setVirtualSlabId(pmPdCcSlab.getVirtualSlabId());
                updatePmPdSlabInfo.setObjectVersionNumber(pmPdCcSlab.getObjectVersionNumber());
                updatePmPdSlabInfos.add(updatePmPdSlabInfo);
            }
            pmPdCcSlabRepository.batchUpdateByPrimaryKeySelective(updatePmPdSlabInfos);
        }
        pmPdSlabRepository.batchUpdateByPrimaryKeySelective(deduplicatedList);
        if (pmCmdSlabs != null) {
            // 如果命令板坯表不为空，需要更新命令板坯数据
            pmCmdSlabRepository.batchUpdateByPrimaryKeySelective(pmCmdSlabs);
        }
    }


    @Override
    protected void checkSlabInfo(PmPdSlab salbInfo, String virtualSlabNo) {
    }

    @Override
    protected PdMatType getMatDesignKind() {
        return PdMatType.A;
    }

    @Override
    protected PdRuleSetType buildRuleParam() {
        return PdRuleSetType.S06;
    }

    @Override
    protected void updatePmCmdSlabProcInfo(PmPdSlab pmPdSlab, PmCmdLargePlt pmCmdLargePltDb, PmCmdSlab updatePmCmdSlab, PmContMscTech axisPmContMscTech,
                                           PmProContProdTtr axisPmProContProdTtr) {
        // TODO 怎么取库位获取二次切断工序
//        PmPdCcSlab pmPdSlabInfo = null;
//        WmStockInfoVO wmStockInfoVO = null;
//        if (PM_PD_CC_SLAB_LOCAL.get() != null) {
//            pmPdSlabInfo = PM_PD_CC_SLAB_LOCAL.get().get(pmCmdLargePltDb.getSlabNo());
//        }
//        if (pmPdSlabInfo != null && StringUtils.isNotBlank(pmPdSlabInfo.getStockCode())) {
//            List<WmStockInfoVO> wmStockInfoVOs = wmMatPileMapper.getStockLineByCode(pmPdSlabInfo.getStockCode(),
//                    pmCmdLargePltDb.getTenantId());
//            if (wmStockInfoVOs != null && !wmStockInfoVOs.isEmpty()) {
//                wmStockInfoVO = wmStockInfoVOs.get(0);
//            }
//        }
//        if (wmStockInfoVO != null) {
//            updatePmCmdSlab.setSlabPreProc1(PlatePreProcUtils.secondaryCuttingProc(pmCmdLargePltDb.getMscLineNo(),
//                    pmPdSlab.getSlabNo(), pmPdSlab.getIngotType(), wmStockInfoVO.getStockLine(),
//                    pmPdSlabInfo.getRollAimLen(), pmPdSlab.getInfurSlabLen()));
//        }
        updatePmCmdSlab.setSlabPreProc1(
                PlatePreProcUtils.rollSmallProc(Utils.mscLineNoToRoolLineNo(axisPmContMscTech.getMscLineNo())));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateSlabEstaPlan(List<String> tmpSlabNoList, Long tenantId) {
        if (CollectionUtils.isEmpty(tmpSlabNoList)) {
            return ;
        }
        List<PmCmdSlab> pmCmdSlabList = pmCmdSlabRepository.selectByCondition(Condition.builder(PmCmdSlab.class)
                .andWhere(Sqls.custom().andEqualTo(PmCmdSlab.FIELD_TENANT_ID, tenantId)
                        .andIn(PmCmdSlab.FIELD_TMP_SLAB_NO, tmpSlabNoList))
                .build());
        if (CollectionUtils.isEmpty(pmCmdSlabList)) {
            throw new CommonException("pm.cmd_slab_001", tmpSlabNoList);
        }
        List<String> ponoList = pmCmdSlabList.stream().map(PmCmdSlab::getPono).distinct().collect(Collectors.toList());
        // 根据预制造命令号查询组炉编制表获取数据并更新
        List<PmSlabEstaPlan> pmSlabEstaPlanList = pmSlabEstaPlanRepository.selectByCondition(Condition.builder(PmSlabEstaPlan.class)
                .andWhere(Sqls.custom().andEqualTo(PmSlabEstaPlan.FIELD_TENANT_ID, tenantId)
                        .andIn(PmSlabEstaPlan.FIELD_PREC_PONO, ponoList))
                .build());
        for (PmSlabEstaPlan pmSlabEstaPlan : pmSlabEstaPlanList) {
            pmSlabEstaPlan.setCsPrecPlanStatus(Constants.CsPrecPlanStatus.STATUS_03);
        }
        pmSlabEstaPlanRepository.batchUpdateByPrimaryKey(pmSlabEstaPlanList);
    }
    
    @Override
    public void abandonContractEventCommand(List<String> virtualSlabNoList ,Map<String ,PmPdSlab> slabInfo, Map<String, List<PmPdContSum>> pmPdContSumListMap, Long tenantId) {
        
    }

    @Override
    public void callMmMatStatusModify(Long tenantId, List<PmPdSlab> slabInfoList, List<String> tmpSlabNoList) {
          // 不抛轧钢的材料状态变更
    }
}
