package com.xisc.pm.app.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.xisc.pm.api.dto.PmCompositeSlabCalcDTO;
import com.xisc.pm.api.dto.PmProContFilterResposeDTO;
import com.xisc.pm.api.dto.PmProContYieldDTO;
import com.xisc.pm.api.dto.PmProContYieldRequestDTO;
import com.xisc.pm.api.dto.PmProContYieldResposeDTO;
import com.xisc.pm.api.dto.ctevent.ProContConsumeDTO;
import com.xisc.pm.app.service.PmCmdSlabService;
import com.xisc.pm.app.service.PmPdPlateService;
import com.xisc.pm.app.service.strategy.PdMatTypeStrategyFactory;
import com.xisc.pm.app.service.strategy.SecondaryDesignStrategyFactory;
import com.xisc.pm.app.service.strategy.pdmattype.PdMatTypeStrategy;
import com.xisc.pm.app.service.strategy.secondarydesign.SecondaryDesignStrategy;
import com.xisc.pm.domain.entity.MmSlab;
import com.xisc.pm.domain.entity.PmCmdLargePlt;
import com.xisc.pm.domain.entity.PmCmdSmallPlt;
import com.xisc.pm.domain.entity.PmContMscTech;
import com.xisc.pm.domain.entity.PmPdContSum;
import com.xisc.pm.domain.entity.PmPdPlate;
import com.xisc.pm.domain.entity.PmPdPlateInfo;
import com.xisc.pm.domain.entity.PmProContProdTtr;
import com.xisc.pm.domain.entity.PmSmallPltPos;
import com.xisc.pm.domain.repository.MmPlateRepository;
import com.xisc.pm.domain.repository.MmSlabRepository;
import com.xisc.pm.domain.repository.PmCmdLargePltRepository;
import com.xisc.pm.domain.repository.PmCmdSmallPltRepository;
import com.xisc.pm.domain.repository.PmPdBlockPosRepository;
import com.xisc.pm.domain.repository.PmPdContSumRepository;
import com.xisc.pm.domain.repository.PmPdPlateCutRepository;
import com.xisc.pm.domain.repository.PmPdPlateInfoRepository;
import com.xisc.pm.domain.repository.PmPdPlateRepository;
import com.xisc.pm.domain.repository.PmSmallPltPosRepository;
import com.xisc.pm.domain.repository.PmWmMatPileRepository;
import com.xisc.pm.domain.vo.EventFeignVO;
import com.xisc.pm.domain.vo.MatStatusModifyVO;
import com.xisc.pm.domain.vo.MmPlateVO;
import com.xisc.pm.domain.vo.MmRollingVo;
import com.xisc.pm.domain.vo.WmMatPileVo;
import com.xisc.pm.infra.client.EventClient;
import com.xisc.pm.infra.client.MmEventClient;
import com.xisc.pm.infra.constant.Constants;
import com.xisc.pm.infra.constant.Constants.PdStatusHp;
import com.xisc.pm.infra.constant.CtEventConstants;
import com.xisc.pm.infra.enums.PdMatType;
import com.xisc.pm.infra.enums.PdProdFlag;
import com.xisc.pm.infra.util.Utils;
import io.choerodon.core.domain.Page;
import io.choerodon.core.exception.CommonException;
import io.choerodon.core.oauth.CustomUserDetails;
import io.choerodon.core.oauth.DetailsHelper;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import io.seata.spring.annotation.GlobalTransactional;
import org.apache.commons.lang3.StringUtils;
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.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
 * 组板钢板表(PmPdPlate)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-31 16:31:09
 */
@Service
public class PmPdPlateServiceImpl implements PmPdPlateService {

    @Autowired
    private PmCmdLargePltRepository pmCmdLargePltRepository;
    @Autowired
    private MmPlateRepository mmPlateRepository;

    @Autowired
    private PmPdPlateInfoRepository pmPdPlateInfoRepository;

    @Autowired
    private PmPdContSumRepository pmPdContSumRepository;

    @Autowired
    private PmPdPlateCutRepository pmPdPlateCutRepository;

    @Autowired
    private PmSmallPltPosRepository pmSmallPltPosRepository;

    @Autowired
    private PmPdBlockPosRepository pmPdBlockPosRepository;

    @Autowired
    private PmCmdSlabService pmCmdSlabService;

    @Autowired
    private MmSlabRepository mmSlabRepository;

    @Autowired
    private PmWmMatPileRepository wmMatPileRepository;
    
    @Autowired
    private EventClient eventClient;
    
    @Autowired
    private MmEventClient mmEventClient;

    @Autowired
    private PmCmdSmallPltRepository pmCmdSmallPltRepository;

    private PmPdPlateRepository pmPdPlateRepository;

    public PmPdPlateServiceImpl(PmPdPlateRepository pmPdPlateRepository) {
        this.pmPdPlateRepository = pmPdPlateRepository;
    }

    @Override
    public Page<PmPdPlate> selectList(PageRequest pageRequest, PmPdPlate pmPdPlate) {
        return PageHelper.doPageAndSort(pageRequest, () -> pmPdPlateRepository.selectList(pmPdPlate));
    }

    @Override
    public void saveData(List<PmPdPlate> pmPdPlates) {
        List<PmPdPlate> insertList = pmPdPlates.stream().filter(line -> line.getPmPdPlateId() == null)
                .collect(Collectors.toList());
        List<PmPdPlate> updateList = pmPdPlates.stream().filter(line -> line.getPmPdPlateId() != null)
                .collect(Collectors.toList());
        pmPdPlateRepository.batchInsertSelective(insertList);
        pmPdPlateRepository.batchUpdateByPrimaryKeySelective(updateList);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public PmPdPlate createPmPdPlate(PmProContYieldRequestDTO pmProContYield, PmContMscTech axisPmContMscTech,
            PmProContProdTtr axisPmProContProdTtr, Map<String, PmProContFilterResposeDTO> filterOrderMap,
            PmProContYieldResposeDTO pmProContYieldRespose, PmCompositeSlabCalcDTO pmCompositeSlabCalc) {
        // 获取钢板信息
        MmPlateVO mmPlate = mmPlateRepository.selectByPrimary(pmProContYield.getPmContFilterRequest().getPlateId());

        MmSlab mmSlab = new MmSlab();
        mmSlab.setSlabNo(mmPlate.getSlabNo());
        mmSlab.setTenantId(pmProContYield.getTenantId());
        List<MmSlab> mmSlabs = mmSlabRepository.selectList(mmSlab);
        if(mmSlabs == null || mmSlabs.isEmpty()) {
            throw new CommonException("pm.pm_pd_plate_info_001", mmPlate.getSlabNo());
        }
        mmSlab = mmSlabs.get(0);
        PmPdPlateInfo pmPdPlateInfo = buildPmPdPlateInfo(mmSlab, mmPlate, pmProContYield ,axisPmProContProdTtr);
        // 获取库位
        WmMatPileVo wmMatPileVo = wmMatPileRepository.selectWmMatPileByMatNo(mmPlate.getMatNo(), pmProContYield.getTenantId());
        pmPdPlateInfo.setStockNo(wmMatPileVo == null ? "" : wmMatPileVo.getStockCode());

        MmRollingVo mmRollingVo = mmPlateRepository.selectMmRolling(pmProContYield.getTenantId(), mmPlate.getMatNo(),
                mmPlate.getProdYear(), Utils.mscLineNoToRoolLineNo(mmPlate.getMscLineNo()));
        if (mmRollingVo != null) {
            pmPdPlateInfo.setAdModeCode(mmRollingVo.getAdModeCode());
            pmPdPlateInfo.setCtrlRollCode(mmRollingVo.getCtrlRollCode());
        }

        pmPdPlateInfoRepository.insertSelective(pmPdPlateInfo);
        PmPdPlate pdPlate = buildPmPdPlate(pmPdPlateInfo, mmPlate, pmProContYield, pmProContYieldRespose,
                pmCompositeSlabCalc, filterOrderMap);
        this.pmPdPlateRepository.insertSelective(pdPlate);
        return pdPlate;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void releasePlate(Long organizationId, String plateNo) {
        List<String> matNoList = new ArrayList<String>(1);
        matNoList.add(plateNo);
        
        PmPdPlateInfo info = new PmPdPlateInfo();
        info.setPlateNo(plateNo);
        info.setTenantId(organizationId);
        
        info = pmPdPlateInfoRepository.selectOne(info);
        
        List<PmPdContSum> pdPmPdContSums = pmPdContSumRepository.selectByPdMatNoList(organizationId , matNoList);
        List<PmSmallPltPos> pmSmallPltPosList = pmSmallPltPosRepository.selectByPdMatNoList(matNoList, organizationId);
        
        PdMatTypeStrategy pdMatTypeStrategy = PdMatTypeStrategyFactory.matchStrategy(PdMatType.P);
        pdMatTypeStrategy.pdDeleteEvent(pdPmPdContSums, plateNo
                , info.getMscLineNo(), Constants.PdProgram.PLATE_DELETE_PD_PROGRAM, organizationId);
        
        pmPdContSumRepository.deleteByMatNo(organizationId, matNoList);
        pmPdPlateCutRepository.deleteByMatNo(organizationId, matNoList);
        pmSmallPltPosRepository.deleteByMatNo(organizationId, matNoList);
        pmPdBlockPosRepository.deleteByMatNo(organizationId, matNoList);
        pmCmdSlabService.removePmCmdByPlateNoList(organizationId, plateNo);
        PmPdPlate record = new PmPdPlate();
        record.setPlateNo(plateNo);
        record.setTenantId(organizationId);
        List<PmPdPlate> pmPdPlates = pmPdPlateRepository.select(record);
        pmPdPlateRepository.delete(record );

        pmPdPlateInfoRepository.deleteByPrimaryKey(info.getPmPdPlateInfoId());
        String pdMatNo = Utils.removeLastThreeChars(plateNo);
        List<ProContConsumeDTO> proContConsumeDTOs = new ArrayList<>();
        proContConsumeDTOs.add(new ProContConsumeDTO(plateNo, PdProdFlag.VIRTUAL_SLAB.getCode(), BaseConstants.Flag.NO.longValue()));
        proContConsumeDTOs.add(new ProContConsumeDTO(plateNo, PdProdFlag.VIRTUAL_COMPOSITE_SLAB.getCode(), BaseConstants.Flag.NO.longValue()));
        for (PmSmallPltPos pmSmallPltPos : pmSmallPltPosList) {
            proContConsumeDTOs.add(new ProContConsumeDTO(pdMatNo + pmSmallPltPos.getSmallPlateDivNo(), PdProdFlag.ACTUAL_SUB_SLAB.getCode(), BaseConstants.Flag.NO.longValue()));
        }
        MmPlateVO mmPlate = mmPlateRepository.selectByPrimary(pmPdPlates.get(0).getMmPlateId());
        // 调用轧钢在制品余材释放事件
        MatStatusModifyVO matStatusModifyVO = new MatStatusModifyVO();
        List<EventFeignVO> ctEventList = new ArrayList<>();
        EventFeignVO eventFeignVO = new EventFeignVO();
        eventFeignVO.setEventCode(CtEventConstants.EVENT_PM_CONTRACT_RESIDUE_BOARD_CONSUME);
        eventFeignVO.setEventContext(JSONObject.toJSONString(proContConsumeDTOs));
        ctEventList.add(eventFeignVO);
        matStatusModifyVO.setCtEventList(ctEventList );
        matStatusModifyVO.setMatNo(plateNo);
        matStatusModifyVO.setPpFlag(mmPlate.getProdCd());
        Map<String, Object> informationMap = new HashMap<>(16);
        informationMap.put("relTime", new Date());
        informationMap.put("relMaker", DetailsHelper.getUserDetails().getUserId());
        matStatusModifyVO.setMatInformationString(JSONObject.toJSONString(informationMap));
        matStatusModifyVO.setPpFlag(mmPlate.getProdCd());
        mmEventClient.matStatusModify(organizationId, Constants.EventCode.MM_IN_PROCESS_SUR_MATERIAL_RELEASE,
                matStatusModifyVO);
//        List<ProContConsumeDTO> proContConsumeDTOs = new ArrayList<>();
//        proContConsumeDTOs.add(new ProContConsumeDTO(plateNo, PdProdFlag.ACTUAL_COMPOSITE_SLAB.getCode(), BaseConstants.Flag.NO.longValue()));
//        eventClient.sendEventWithOutResponse(organizationId, CtEventConstants.EVENT_PM_CONTRACT_RESIDUE_BOARD_CONSUME, proContConsumeDTOs);
    }
    
    @Override
    @GlobalTransactional(rollbackFor = Exception.class)
    @Transactional(rollbackFor = Exception.class)
    public void singlePlateConfirm(Long organizationId, PmPdPlate pmPdPlate) {
        SecondaryDesignStrategy secondaryDesignStrategy = SecondaryDesignStrategyFactory.matchStrategy(PdMatType.P);
        List<PmCmdLargePlt> pmCmdLargePltList = pmCmdLargePltRepository.selectByCondition(Condition.builder(PmCmdLargePlt.class).andWhere(Sqls.custom()
                .andEqualTo(PmCmdLargePlt.FIELD_TENANT_ID, organizationId).andEqualTo(PmCmdLargePlt.FIELD_PLATE_NO, pmPdPlate.getPlateNo())).build());
        if(pmCmdLargePltList != null && !pmCmdLargePltList.isEmpty()) {
            MmPlateVO mmPlate = mmPlateRepository.selectByPrimary(pmPdPlate.getMmPlateId());
            if(mmPlate == null) {
                throw new CommonException("pm.pm_pd_plate_001");
            }
            // 前端勾选试样添加，或者综判代码不为1,则试样添加
            if(BaseConstants.Flag.YES.longValue()==pmPdPlate.getAddSampleFlag() || !BaseConstants.Flag.YES.toString().equals(mmPlate.getComplexDecideCode())) {
                secondaryDesignStrategy.sampleAddition(organizationId, pmCmdLargePltList);
            }else {
                // 清空命令大板和命令板坯的特定字段的值
                List<String> tmpSlabNoList = pmCmdLargePltList.stream().map(PmCmdLargePlt::getTmpSlabNo).collect(Collectors.toList());
                List<PmCmdSmallPlt> cmdSmallPltList = pmCmdSmallPltRepository.selectByTmpSlabNoList(tmpSlabNoList, organizationId);
                for (PmCmdSmallPlt pmCmdSmallPlt : cmdSmallPltList) {
                    pmCmdSmallPlt.setSampleLenGive(BigDecimal.ZERO);
                    pmCmdSmallPlt.setSampleHeadLenFree(BigDecimal.ZERO);
                    pmCmdSmallPlt.setSampleTailLenFree(BigDecimal.ZERO);
                    pmCmdSmallPlt.setSampleHeadLenPlate(BigDecimal.ZERO);
                    pmCmdSmallPlt.setSampleTailLenPlate(BigDecimal.ZERO);
                }
                for (PmCmdLargePlt largePlt : pmCmdLargePltList) {
                    largePlt.setSampleLenHead(BigDecimal.ZERO);
                    largePlt.setSampleLenTail(BigDecimal.ZERO);
                    largePlt.setSampleLenMid(BigDecimal.ZERO);
                    largePlt.setSampleLenGive(BigDecimal.ZERO);
                    largePlt.setSampleLen(BigDecimal.ZERO);
                    largePlt.setSampleHeadLenFree(BigDecimal.ZERO);
                    largePlt.setSampleTailLenFree(BigDecimal.ZERO);
                    largePlt.setSampleHeadLenPlate(BigDecimal.ZERO);
                    largePlt.setSampleTailLenPlate(BigDecimal.ZERO);
                    largePlt.setPdStatusHp(PdStatusHp.PD_STATUS_HP_20);
                }
//                pmCmdLargePltList.forEach(item->item.setPdStatusHp(PdStatusHp.PD_STATUS_HP_20));
                pmCmdSmallPltRepository.batchUpdateByPrimaryKeySelective(cmdSmallPltList);
                pmCmdLargePltRepository.batchUpdateByPrimaryKeySelective(pmCmdLargePltList);
            }
            secondaryDesignStrategy.secondaryDesign(organizationId, pmCmdLargePltList);
            secondaryDesignStrategy.commandCreate(organizationId, pmCmdLargePltList);
        }
    }

    /**
     *
     * @param pmPdPlateInfo
     * @param mmPlate
     * @param pmProContYield
     * @param pmProContYieldRespose
     * @param pmCompositeSlabCalc
     * @return
     */
    private PmPdPlate buildPmPdPlate(PmPdPlateInfo pmPdPlateInfo, MmPlateVO mmPlate,
            PmProContYieldRequestDTO pmProContYield, PmProContYieldResposeDTO pmProContYieldRespose,
            PmCompositeSlabCalcDTO pmCompositeSlabCalc , Map<String, PmProContFilterResposeDTO> filterOrderMap) {
        PmPdPlate pmPdPlate = new PmPdPlate();
        pmPdPlate.setTenantId(pmPdPlateInfo.getTenantId());
        pmPdPlate.setPlateNo(mmPlate.getMatNo());
        pmPdPlate.setMmPlateId(mmPlate.getPlateId());
        pmPdPlate.setCommandYield(pmProContYieldRespose.getCommandYield());
        pmPdPlate.setPdStatusHp(Constants.PdStatusHp.PD_STATUS_HP_18);
        pmPdPlate.setFormPlateMode(pmProContYield.getPmContFilterRequest().getFormPlateMode());
        pmPdPlate.setRollDirectCode(pmProContYield.getPmContFilterRequest().getRollDirectCode());
        pmPdPlate.setMatDesignKind(pmProContYield.getPmContFilterRequest().getMatDesignKind());
        pmPdPlate.setPickModeLenDir(pmProContYield.getCompositeBoard().getPickModeLenDir().longValue());
        pmPdPlate.setPickModeWidDir(pmProContYield.getCompositeBoard().getPickModeWidDir().longValue());
        pmPdPlate.setTotSmallPlateNum(pmProContYield.getCompositeBoard().getSpCount().longValue());
        pmPdPlate.setCombinePlateLen(pmProContYieldRespose.getCombinePlateLen());
        pmPdPlate.setCombinePlateWidth(pmProContYieldRespose.getCombinePlateWidth());
        pmPdPlate.setSampleLenHead(pmCompositeSlabCalc.getSampleLenHead());
        pmPdPlate.setSampleLenMid(pmCompositeSlabCalc.getSampleLenMid());
        pmPdPlate.setSampleLenTail(pmCompositeSlabCalc.getSampleLenTail());
        pmPdPlate.setOrderNumInPlate(pmProContYield.getCompositeBoard().getOrderCount().longValue());
        pmPdPlate.setWithSideFlag(pmPdPlateInfo.getWithSideFlag());
        pmPdPlate.setCutModeCode(pmPdPlateInfo.getActCutMode());
        pmPdPlate.setRollThickTolMax(pmProContYieldRespose.getRollThickTolMax());
        pmPdPlate.setRollThickTolMin(pmProContYieldRespose.getRollThickTolMin());
        pmPdPlate.setHeadCut(pmProContYieldRespose.getHeadCut());
        pmPdPlate.setTailCut(pmProContYieldRespose.getTailCut());
        pmPdPlate.setRollAimThick(pmProContYieldRespose.getTaim());
        Set<String> ultCode = new TreeSet<>();
        for (PmProContYieldDTO order : pmProContYield.getPmProContYieldList()) {
            PmProContFilterResposeDTO resposeDTO = filterOrderMap.get(order.getOrderNo());
            if (StringUtils.isNotBlank(resposeDTO.getErpUtSpec1())) {
                ultCode.add(resposeDTO.getErpUtSpec1());
             }
             if (StringUtils.isNotBlank(resposeDTO.getErpUtSpec2())) {
                 ultCode.add(resposeDTO.getErpUtSpec2());
             }
             if (StringUtils.isNotBlank(resposeDTO.getErpUtSpec3())) {
                 ultCode.add(resposeDTO.getErpUtSpec3());
             }
        }
        if(ultCode != null && !ultCode.isEmpty()) {
            pmPdPlate.setUltCode(String.join("@", ultCode));
        }
        // 余材计算时不生成轧制目标长宽厚重
//        pmPdPlate.setRollAimLen(pmProContYieldRespose.getLaim());
//        pmPdPlate.setRollAimWidth(pmProContYieldRespose.getWaim());
//      pmPdPlate.setRollWtHp(pmProContYieldRespose.getRollWtHp());
        pmPdPlate.setSgSign(pmPdPlateInfo.getSgSign());
        pmPdPlate.setStNo(pmPdPlateInfo.getStNo());
        pmPdPlate.setAutoManualFlag(Constants.AutoManualFlag.AUTO_MANUA_FLAG_M);
        pmPdPlate.setShpCode(pmPdPlateInfo.getShpCode());
        return pmPdPlate;
    }

    /**
     *
     * @param mmPlate
     * @param pmProContYield
     * @param axisPmProContProdTtr
     * @return
     */
    private PmPdPlateInfo buildPmPdPlateInfo(MmSlab mmSlab, MmPlateVO mmPlate, PmProContYieldRequestDTO pmProContYield, PmProContProdTtr axisPmProContProdTtr) {
        PmPdPlateInfo pmPdPlateInfo = new PmPdPlateInfo();
        if (mmSlab != null && mmSlab.getSlabActThk() != null && mmPlate.getMatActThk() != null
                && mmPlate.getMatActThk().compareTo(BigDecimal.ZERO) != 0) {
            pmPdPlateInfo.setActBroadRatio(mmSlab.getSlabActThk().divide(mmPlate.getMatActThk() , BaseConstants.Digital.TWO, RoundingMode.HALF_UP));
            pmPdPlateInfo.setActPressRate(mmSlab.getSlabActWid().divide(mmPlate.getMatActWid() , BaseConstants.Digital.ONE, RoundingMode.HALF_UP));
        }
        if(mmSlab != null) {
            pmPdPlateInfo.setOldApn(mmSlab.getApn()); 
            pmPdPlateInfo.setOldMsc(mmSlab.getMsc());
            pmPdPlateInfo.setOldMscLine(mmSlab.getMscLineNo());
            pmPdPlateInfo.setOldPsc(mmSlab.getPsc());
        }
        pmPdPlateInfo.setTenantId(pmProContYield.getTenantId());
        pmPdPlateInfo.setActCutMode(mmPlate.getFinalCutSurfaceCode());
        pmPdPlateInfo.setApn(mmPlate.getApn());
        pmPdPlateInfo.setAutoManualFlag(Constants.AutoManualFlag.AUTO_MANUA_FLAG_M);
        pmPdPlateInfo.setBetterSurfWardCode(mmPlate.getBetterSurfWardCode());
        pmPdPlateInfo.setCanAssignFlag(BaseConstants.Flag.YES.toString());
        pmPdPlateInfo.setCtrlRollCode(mmPlate.getCtrlRollCode());
        pmPdPlateInfo.setFurType(pmProContYield.getPmContFilterRequest().getFurType());
        pmPdPlateInfo.setHeatTreatPlateFlag(BaseConstants.Flag.YES.toString());
        pmPdPlateInfo.setMatActLen(mmPlate.getMatActLen());
        pmPdPlateInfo.setMatActThick(mmPlate.getMatActThk());
        pmPdPlateInfo.setMatActWidth(mmPlate.getMatActWid());
        pmPdPlateInfo.setMatActWt(mmPlate.getMatActWgt());
        pmPdPlateInfo.setMatStatus(null);
        pmPdPlateInfo.setMsc(mmPlate.getMsc());
        pmPdPlateInfo.setMscLineNo(mmPlate.getMscLineNo());
        pmPdPlateInfo.setNextWholeBacklogCode(mmPlate.getNextWholeBacklogCode());
        pmPdPlateInfo.setNextWholeBacklogSeq(mmPlate.getNextWholeBacklogSeq());
//        pmPdPlateInfo.setPdAutoFlag(mmPlate.getou);
//        pmPdPlateInfo.setPdBacklogCode(mmPlate.get);
//        pmPdPlateInfo.setPdBacklogSeq(ouBacklogSeq);
//        pmPdPlateInfo.setPdBeginTime(ouBeginTime);
//        pmPdPlateInfo.setPdEndTime(ouEndTime);
        pmPdPlateInfo.setPdProgram(Constants.PdProgram.PLATE_INFO_PD_PROGRAM);
        CustomUserDetails userDetails = DetailsHelper.getUserDetails();
        pmPdPlateInfo.setPdResp(userDetails == null ? "" : userDetails.getUserId().toString());
//        pmPdPlateInfo.setPdRespAuto(ouRespAuto);
        pmPdPlateInfo.setPdStatusHp(PdStatusHp.PD_STATUS_HP_18);
//        pmPdPlateInfo.setPdTimeAuto(pdTimeAuto);
        pmPdPlateInfo.setOuBacklogCode("13");
        pmPdPlateInfo.setOuBacklogSeq(3L);
        pmPdPlateInfo.setUoeFlag(BaseConstants.Flag.NO.toString());
        pmPdPlateInfo.setPlateNo(mmPlate.getMatNo());
        pmPdPlateInfo.setPsc(mmPlate.getPsc());
        pmPdPlateInfo.setPono(mmPlate.getPono());
        pmPdPlateInfo.setRemainCauseCode(mmPlate.getRemainCauseCode());
        pmPdPlateInfo.setRemainMaxThick(mmPlate.getMatActThk());
        pmPdPlateInfo.setRemainMinThick(mmPlate.getMatActThk());
        pmPdPlateInfo.setRollDirectCode(mmPlate.getRollDirectCode()); 
        pmPdPlateInfo.setSgSign(mmPlate.getSgSign());
        pmPdPlateInfo.setSgStd(mmPlate.getSgStd());
        pmPdPlateInfo.setShpCode(mmPlate.getShpCode());
        pmPdPlateInfo.setSlabNo(mmPlate.getSlabNo());
        pmPdPlateInfo.setStNo(mmPlate.getStNo());
        pmPdPlateInfo.setStockNo(mmPlate.getStockCode());
//        pmPdPlateInfo.setWholeBacklogAct(mmPlate.getWholeBacklog());
        pmPdPlateInfo.setWholeBacklogCode(mmPlate.getWholeBacklogCode());
        pmPdPlateInfo.setWholeBacklogSeq(mmPlate.getWholeBacklogSeq());

        pmPdPlateInfo.setWithSideFlag(axisPmProContProdTtr.getProdSideMark());
        return pmPdPlateInfo;
    }

}
