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

import com.alibaba.fastjson.JSON;
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.api.dto.ProdPonoSlabRequestDTO;
import com.xisc.pm.api.dto.ctevent.PmSlabApplyMakeDTO;
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.PmPdContSum;
import com.xisc.pm.domain.entity.PmProContProdTtr;
import com.xisc.pm.domain.entity.PmSlabEstaPlan;
import com.xisc.pm.domain.entity.PmSmallPltPos;
import com.xisc.pm.domain.repository.PmPdCcSlabRepository;
import com.xisc.pm.domain.repository.PmSlabEstaPlanRepository;
import com.xisc.pm.infra.client.EventClient;
import com.xisc.pm.infra.constant.Constants;
import com.xisc.pm.infra.enums.PdMatType;
import com.xisc.pm.infra.enums.PdRuleSetType;
import com.xisc.pm.infra.util.PlatePreProcUtils;
import com.xisc.pm.infra.util.Utils;
import io.choerodon.core.exception.CommonException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
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.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * (连铸出钢材)二次设计
 * 
 * @author jun.zeng
 *
 */
@Slf4j
@Component
public class CcSlabSecondaryDesignStrategy extends DefaultSecondaryDesignStrategy<PmPdCcSlab> {

    @Autowired
    private PmPdCcSlabRepository pmPdCcSlabRepository;

    @Autowired
    private EventClient eventClient;

    @Autowired
    private PmSlabEstaPlanRepository pmSlabEstaPlanRepository;
    
    @Override
    protected boolean hasPmCmdSlab() {
        return true;
    }

    @Override
    protected Map<String, PmPdCcSlab> selectByMatNo(List<String> virtualSlabNo, Long tenantId) {
        List<PmPdCcSlab> pmPdCcSlabs = pmPdCcSlabRepository.selectByCondition(Condition.builder(PmPdCcSlab.class)
                .andWhere(Sqls.custom().andEqualTo(PmPdCcSlab.FIELD_TENANT_ID, tenantId)
                        .andIn(PmPdCcSlab.FIELD_VIRTUAL_SLAB_NO, virtualSlabNo))
                .build());
        if (pmPdCcSlabs == null || pmPdCcSlabs.isEmpty()) {
            Maps.newHashMap();
        }
        return Maps.uniqueIndex(pmPdCcSlabs, PmPdCcSlab::getVirtualSlabNo);
    }

    @Override
    protected PmProContFilterRequestDTO buildPmProContFilterRequestDTO(PmProContYieldRequestDTO pmProContYieldRequestDTO,PmPdCcSlab salbInfo,
            PmCmdLargePlt pmCmdLargePlt) {
        PmProContFilterRequestDTO pmContFilterRequest = new PmProContFilterRequestDTO();
        pmContFilterRequest.setMoldThick(salbInfo.getMoldThick());
        pmContFilterRequest.setMoldWidth(salbInfo.getMoldWid());
        pmContFilterRequest.setStNo(salbInfo.getStNo());
        pmContFilterRequest.setSgSign(salbInfo.getSgSign());
        pmContFilterRequest.setFurType(salbInfo.getFurType());
        pmContFilterRequest.setCcType(salbInfo.getCcType());
        pmContFilterRequest.setMatDesignKind(salbInfo.getMatDesignKind());
        pmContFilterRequest.setSampleLenGice(salbInfo.getFixSlabLen());
        pmContFilterRequest.setFixSlabLenFlag(salbInfo.getFixSlabLenFlag());
        pmContFilterRequest.setFixSlabLen(salbInfo.getFixSlabLen());
        pmContFilterRequest.setMscLineNo(salbInfo.getMscLineNo());
        pmContFilterRequest.setFormPlateMode(salbInfo.getFormPlateMode());
        pmContFilterRequest.setRollDirectCode(salbInfo.getRollDirectCode());
        pmContFilterRequest.setTransFlag(salbInfo.getTransFlag());
        return pmContFilterRequest;
    }

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

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void execUpdateSlabInfo(List<PmPdCcSlab> slabInfoList) {
        // 会有重复的数据，因为大板表在组炉会多存合并的一条
        List<PmPdCcSlab> deduplicatedList = slabInfoList.stream()
                .collect(Collectors.toMap(PmPdCcSlab::getVirtualSlabId, Function.identity(), (k, v) -> k)).values().stream().collect(Collectors.toList());
        pmPdCcSlabRepository.batchUpdateByPrimaryKeySelective(deduplicatedList);
    }
    
    @Override
    protected void checkSlabInfo(PmPdCcSlab salbInfo , String virtualSlabNo) {
        if(salbInfo == null) {
            throw new CommonException("pm.pd_cc_slab_006", virtualSlabNo);
        }
    }

    @Override
    protected PdMatType getMatDesignKind() {
        return PdMatType.C;
    }
    
    @Override
    protected PdRuleSetType buildRuleParam() {
        return PdRuleSetType.C06;
    }
    
    @Override
    protected void updatePmCmdSlabProcInfo(PmPdCcSlab pmPdCcSlab, PmCmdLargePlt pmCmdLargePltDb, PmCmdSlab updatePmCmdSlab, PmContMscTech axisPmContMscTech,
            PmProContProdTtr axisPmProContProdTtr) {
        if (Constants.MergeStatus.MERGE_B.equals(updatePmCmdSlab.getIsMerge())) {
//            updatePmCmdSlab.setSlabPreProc1(PlatePreProcUtils.secondaryCuttingProc(axisPmContMscTech.getMscLineNo(), axisPmProContProdTtr.getShpCode()));
            updatePmCmdSlab.setSlabPreProc1(PlatePreProcUtils.rollSmallProc(Utils.mscLineNoToRoolLineNo(axisPmContMscTech.getMscLineNo())));
        } else {
            updatePmCmdSlab.setSlabPreProc1(PlatePreProcUtils.secondaryCuttingProc(axisPmContMscTech.getMscLineNo(), axisPmProContProdTtr.getShpCode()));
            if (StringUtils.isEmpty(updatePmCmdSlab.getSlabPreProc1())) {
                updatePmCmdSlab.setSlabPreProc1(PlatePreProcUtils.rollSmallProc(Utils.mscLineNoToRoolLineNo(axisPmContMscTech.getMscLineNo())));
            } else {
                updatePmCmdSlab.setSlabPreProc2(PlatePreProcUtils.rollSmallProc(Utils.mscLineNoToRoolLineNo(axisPmContMscTech.getMscLineNo())));
            }
        }
    }


    @Transactional(rollbackFor = Exception.class)
    @Override
    public void abandonContractEvent(List<String> virtualSlabNoList, Long tenantId, String pdMatStatus, String prodcCd,
                                        String wholeBacklogCode, String eventCode) {
        List<PmPdCcSlab> pmPdCcSlabs = pmPdCcSlabRepository.selectByCondition(Condition.builder(PmPdCcSlab.class)
                .andWhere(Sqls.custom().andEqualTo(PmPdCcSlab.FIELD_TENANT_ID, tenantId)
                        .andIn(PmPdCcSlab.FIELD_VIRTUAL_SLAB_NO, virtualSlabNoList))
                .build());

        List<PmSmallPltPos> pmSmallPltPosList = pmSmallPltPosRepository.selectByCondition(Condition.builder(PmSmallPltPos.class)
                .andWhere(Sqls.custom().andIn(PmSmallPltPos.FIELD_PD_MAT_NO, virtualSlabNoList))
                .andWhere(Sqls.custom().andEqualTo(PmSmallPltPos.FIELD_TENANT_ID, tenantId))
                .build());
        Map<String, List<PmSmallPltPos>> pmSmallPltPosMap = new HashMap<>(pmSmallPltPosList.size());
        if (org.apache.commons.collections.CollectionUtils.isNotEmpty(pmSmallPltPosList)) {
            pmSmallPltPosMap = pmSmallPltPosList.stream().collect(Collectors.groupingBy(PmSmallPltPos::getPdMatNo));
        }
        List<PmSlabApplyMakeDTO> resList = new ArrayList<>();
        for (PmPdCcSlab pmpdCcSlab : pmPdCcSlabs) {
            // 虚拟板坯号信息
            PmSlabApplyMakeDTO applyMakeDTO = new PmSlabApplyMakeDTO();
            applyMakeDTO.setMatNo(pmpdCcSlab.getVirtualSlabNo());
            // 钢锭连铸
            /*if (Constants.CcType.TYPE_5.equals(pmpdCcSlab.getCcType())) {
                applyMakeDTO.setPpFlag(8);
            } else {
                applyMakeDTO.setPpFlag(0);
            }*/
            applyMakeDTO.setPpFlag(0);
            applyMakeDTO.setOrdFlag("1");
            applyMakeDTO.setPdMatStatus(pdMatStatus);
            applyMakeDTO.setProcCd(prodcCd);
            applyMakeDTO.setWholeBacklogCode(wholeBacklogCode);
            resList.add(applyMakeDTO);
            // 大板信息
            PmSlabApplyMakeDTO applyMakeDTO1 = new PmSlabApplyMakeDTO();
            applyMakeDTO1.setMatNo(pmpdCcSlab.getVirtualSlabNo());
            applyMakeDTO1.setPpFlag(1);
            applyMakeDTO.setOrdFlag("1");
            applyMakeDTO1.setPdMatStatus(pdMatStatus);
            applyMakeDTO1.setProcCd(prodcCd);
            applyMakeDTO1.setWholeBacklogCode(wholeBacklogCode);
            resList.add(applyMakeDTO1);
            // 子板信息
            if (!pmSmallPltPosMap.containsKey(pmpdCcSlab.getVirtualSlabNo())) {
                throw new CommonException("pm.small_plt_pos", pmpdCcSlab.getVirtualSlabNo());
            }
            List<PmSmallPltPos> pmSmallPltPos = pmSmallPltPosMap.get(pmpdCcSlab.getVirtualSlabNo());
            for (PmSmallPltPos pmSmallPltPo : pmSmallPltPos) {
                PmSlabApplyMakeDTO makeDTO = new PmSlabApplyMakeDTO();
                makeDTO.setMoMatNo(pmSmallPltPo.getPdMatNo());
                makeDTO.setMatNo(pmSmallPltPo.getPdMatNo() + pmSmallPltPo.getSmallPlateDivNo());
                makeDTO.setPpFlag(2);
                makeDTO.setOrdFlag("1");
                makeDTO.setPdMatStatus(pdMatStatus);
                makeDTO.setProcCd(prodcCd);
                makeDTO.setWholeBacklogCode(wholeBacklogCode);
                resList.add(makeDTO);
            }
        }
        log.info("<=====出钢材调用试样添加事件，事件编码:{}, 入参为{}=====>", eventCode, JSON.toJSONString(resList));
        eventClient.sendEventWithOutResponse(tenantId, eventCode, resList);
    }

    @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 ,PmPdCcSlab> slabInfo, Map<String, List<PmPdContSum>> pmPdContSumListMap,
            Long tenantId) {
        
    }

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

    @Override
    protected void callSampleGensRemove(List<String> tmpSlapNoList, Long tenantId) {
        List<ProdPonoSlabRequestDTO> requestList = new ArrayList<>();

        List<PmCmdSlab> pmCmdSlabList = pmCmdSlabRepository.selectByCondition(Condition.builder(PmCmdSlab.class)
                .andWhere(Sqls.custom().andIn(PmCmdSlab.FIELD_TMP_SLAB_NO, tmpSlapNoList))
                .andWhere(Sqls.custom().andEqualTo(PmCmdSlab.FIELD_TENANT_ID, tenantId)).build());
        // 一次只能勾选一炉的
        List<String> ponoList = pmCmdSlabList.stream().map(PmCmdSlab::getPono).distinct().collect(Collectors.toList());
        if (ponoList.size() > 1) {
             throw new CommonException("pm.cmd_slab_002");
        }
        // 获取这一炉的所有数据
        List<PmCmdSlab> cmdSlabList = pmCmdSlabRepository.selectByCondition(Condition.builder(PmCmdSlab.class)
                .andWhere(Sqls.custom().andEqualTo(PmCmdSlab.FIELD_PONO, ponoList.get(0)))
                .andWhere(Sqls.custom().andEqualTo(PmCmdSlab.FIELD_TENANT_ID, tenantId)).build());
        List<String> allTmpSlabNoList = cmdSlabList.stream().map(PmCmdSlab::getTmpSlabNo).distinct().collect(Collectors.toList());
        List<PmPdCcSlab> pmPdCcSlabList = pmPdCcSlabRepository.selectByCondition(Condition.builder(PmPdCcSlab.class)
                .andWhere(Sqls.custom().andIn(PmPdCcSlab.FIELD_TMP_SLAB_NO, allTmpSlabNoList))
                .andWhere(Sqls.custom().andEqualTo(PmPdCcSlab.FIELD_TENANT_ID, tenantId)).build());
        Map<String, String> pmPdCcSlabMap = new HashMap<>(pmPdCcSlabList.size());
        if (CollectionUtils.isNotEmpty(pmPdCcSlabList)) {
             pmPdCcSlabMap = pmPdCcSlabList.stream().collect(Collectors.toMap(PmPdCcSlab::getTmpSlabNo, PmPdCcSlab::getMatDesignKind));
        }
        for (String tmpSlabNo : allTmpSlabNoList) {
            ProdPonoSlabRequestDTO dto = new ProdPonoSlabRequestDTO();
            dto.setTmpSlabNo(tmpSlabNo);
            dto.setMatDesignKind(pmPdCcSlabMap.get(tmpSlabNo));
            requestList.add(dto);
        }
        log.info("<=====连铸出钢材试样添加回退调用【callSampleGensRemove】, 入参={}", JSON.toJSONString(requestList));
        qeApiClient.sampleGensRemove(tenantId, requestList);
    }

    @Override
    protected List<PmCmdLargePlt> getAllCmdLargePltList(List<String> pmCmdLargePltIdList, Long tenantId) {
        // 获取同一炉其他命令板坯号
        List<PmCmdLargePlt> pmCmdLargePltList = pmCmdLargePltRepository.selectByIds(String.join(",", pmCmdLargePltIdList));
        List<String> tmpSlabNoList = pmCmdLargePltList.stream().map(PmCmdLargePlt::getTmpSlabNo).collect(Collectors.toList());
        return getPmCmdLargePltList(tmpSlabNoList, tenantId);
    }

    @Override
    protected List<PmCmdLargePlt> getPmCmdLargePltList(List<String> tmpSlabNoList, Long tenantId) {
        List<PmCmdSlab> pmCmdSlabList = pmCmdSlabRepository.selectByTmpSlabNoList(tmpSlabNoList, tenantId);
        // 一次只能勾选一炉的
        List<String> ponoList = pmCmdSlabList.stream().map(PmCmdSlab::getPono).distinct().collect(Collectors.toList());
        if (ponoList.size() > 1) {
            throw new CommonException("pm.cmd_slab_002");
        }
        // 获取这一炉的所有数据
        List<PmCmdSlab> cmdSlabList = pmCmdSlabRepository.selectByCondition(Condition.builder(PmCmdSlab.class)
                .andWhere(Sqls.custom().andEqualTo(PmCmdSlab.FIELD_PONO, ponoList.get(0)))
                .andWhere(Sqls.custom().andEqualTo(PmCmdSlab.FIELD_TENANT_ID, tenantId)).build());
        List<String> allTmpSlabNoList = cmdSlabList.stream().map(PmCmdSlab::getTmpSlabNo).distinct().collect(Collectors.toList());

        List<PmCmdLargePlt> largePltList = pmCmdLargePltRepository.selectByTmpSlabNoList(allTmpSlabNoList, tenantId);
        return largePltList;
    }

    @Override
    protected PmCmdSlab updatePmCmdSlab(PmCmdSlab oldPmCmdSlab, PmProContYieldResposeDTO pmProContYieldRespose,
                                        Map<String, List<String>> pmSlabMergeMap, Map<String, PmCmdSlab> pmCmdSlabMap , String pdStatusHp) {
        PmCmdSlab newPmCmdSlab = new PmCmdSlab();
       if (Constants.MergeStatus.MERGE_A.equals(oldPmCmdSlab.getIsMerge())) {
           // 查询合并板坯的数据
          if (!pmSlabMergeMap.containsKey(oldPmCmdSlab.getTmpSlabNo())) {
              throw new CommonException("pm.slab_merge_004", oldPmCmdSlab.getTmpSlabNo());
          }
           BigDecimal preCleanSlabLen = BigDecimal.ZERO;
           BigDecimal infurSlabLen = BigDecimal.ZERO;
           BigDecimal needSlabLen = BigDecimal.ZERO;
           BigDecimal preCleanSlabWt = BigDecimal.ZERO;
           BigDecimal infurSlabWt = BigDecimal.ZERO;
           BigDecimal needSlabWt = BigDecimal.ZERO;
           for (String tmpSlabNo : pmSlabMergeMap.get(oldPmCmdSlab.getTmpSlabNo())) {
               PmCmdSlab pmCmdSlab = pmCmdSlabMap.get(tmpSlabNo);
               preCleanSlabLen =  preCleanSlabLen.add(pmCmdSlab.getPreCleanSlabLen() == null ? BigDecimal.ZERO : pmCmdSlab.getPreCleanSlabLen());
               infurSlabLen =  infurSlabLen.add(pmCmdSlab.getInfurSlabLen() == null ? BigDecimal.ZERO : pmCmdSlab.getInfurSlabLen());
               needSlabLen = needSlabLen.add(pmCmdSlab.getNeedSlabLen() == null ? BigDecimal.ZERO : pmCmdSlab.getNeedSlabLen());
               preCleanSlabWt = preCleanSlabWt.add(pmCmdSlab.getPreCleanSlabWt() == null ? BigDecimal.ZERO : pmCmdSlab.getPreCleanSlabWt());
               infurSlabWt = infurSlabWt.add(pmCmdSlab.getInfurSlabWt() == null ? BigDecimal.ZERO : pmCmdSlab.getInfurSlabWt());
               needSlabWt = needSlabWt.add(pmCmdSlab.getNeedSlabWt() == null ? BigDecimal.ZERO : pmCmdSlab.getNeedSlabWt());
           }
           newPmCmdSlab.setPreCleanSlabLen(preCleanSlabLen);
           newPmCmdSlab.setInfurSlabLen(infurSlabLen);
           newPmCmdSlab.setNeedSlabLen(needSlabLen);
           newPmCmdSlab.setPreCleanSlabWt(preCleanSlabWt);
           newPmCmdSlab.setInfurSlabWt(infurSlabWt);
           newPmCmdSlab.setNeedSlabWt(needSlabWt);
           newPmCmdSlab.setPdStatusHp(pdStatusHp);
           newPmCmdSlab.setObjectVersionNumber(oldPmCmdSlab.getObjectVersionNumber());
           newPmCmdSlab.setPmCmdSlabId(oldPmCmdSlab.getPmCmdSlabId());
           newPmCmdSlab.setTmpSlabNo(oldPmCmdSlab.getTmpSlabNo());
           newPmCmdSlab.setIsMerge(oldPmCmdSlab.getIsMerge());
       }else {
           newPmCmdSlab = super.updatePmCmdSlab(oldPmCmdSlab, pmProContYieldRespose, pmSlabMergeMap, pmCmdSlabMap , pdStatusHp);
       }
        return newPmCmdSlab;
    }
}
