package com.xisc.pm.app.service;

import com.xisc.pm.api.dto.PmCompositeSlabCalcDTO;
import com.xisc.pm.api.dto.PmPdMidSplitDTO;
import com.xisc.pm.api.dto.PmPdMidSplitRequestDTO;
import com.xisc.pm.api.dto.PmPdPlateDTO;
import com.xisc.pm.api.dto.PmPdSlabDTO;
import com.xisc.pm.api.dto.PmPdSlabSplitDTO;
import com.xisc.pm.api.dto.PmPdSlabSplitRequestDTO;
import com.xisc.pm.api.dto.PmProContFilterResposeDTO;
import com.xisc.pm.api.dto.PmProContYieldRequestDTO;
import com.xisc.pm.api.dto.PmProContYieldResposeDTO;
import com.xisc.pm.api.dto.PmTwoRollInterimRequestDTO;
import com.xisc.pm.domain.entity.PmContMscTech;
import com.xisc.pm.domain.entity.PmPdSlab;
import com.xisc.pm.domain.entity.PmProContProdTtr;
import com.xisc.pm.infra.enums.PdMatType;
import io.choerodon.core.domain.Page;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 组板板坯表(PmPdSlab)应用服务
 *
 * @author 纪文桃 wentao.ji01@hand-china.com
 * @since 2024-07-31 16:30:31
 */
public interface PmPdSlabService {

    /**
     * 查询数据
     *
     * @param pageRequest 分页参数
     * @param pmPdSlabs   查询条件
     * @return 返回值
     */
    Page<PmPdSlab> selectList(PageRequest pageRequest, PmPdSlab pmPdSlabs);

    /**
     * 保存数据
     *
     * @param pmPdSlabs 数据
     */
    void saveData(List<PmPdSlab> pmPdSlabs);

    /**
     * 通过板坯号查询板坯信息
     * 
     * @param slabId
     * @param slabNo
     * @param organizationId
     * @return
     */
    PmPdSlabSplitDTO selectBySlabNo(Long slabId, String slabNo, Long organizationId);

    /**
     * 新增分割
     * 
     * @param splitInfoRequest
     * @return
     */
    PmPdSlabSplitDTO addSplitInfoBySlabNo(PmPdSlabSplitRequestDTO splitInfoRequest);

    /**
     * 
     * @param splitInfoRequest
     * @return
     */
    Boolean removeSplitInfoBySlabNo(PmPdSlabSplitRequestDTO splitInfoRequest);
    
    /**
     * 组板结构更新
     * @param pmProContYield
     * @param axisPmContMscTech
     * @param axisPmProContProdTtr
     * @param filterOrderMap
     * @param pmProContYieldRespose
     * @param pmCompositeSlabCalc
     * @return
     */
    PmPdSlab updatePmPdSlab(PmProContYieldRequestDTO pmProContYield, PmContMscTech axisPmContMscTech,
            PmProContProdTtr axisPmProContProdTtr, Map<String, PmProContFilterResposeDTO> filterOrderMap,
            PmProContYieldResposeDTO pmProContYieldRespose, PmCompositeSlabCalcDTO pmCompositeSlabCalc);
    
    /**
     * 分割确认
     * @param splitInfoRequest
     * @return
     */
    Boolean confirmSplitInfoBySlabNo(PmPdSlabSplitRequestDTO splitInfoRequest);

    /**
     * 单块组板确认
     * @param splitInfoRequest
     * @return
     */
    Boolean singleSlabConfirm(PmPdSlabSplitRequestDTO splitInfoRequest);

    /**
     * 收得率计算与执行前校验
     * @param pmProContYield
     * @param isExec 
     */
    void yiledCalcBeforeCheck(PmProContYieldRequestDTO pmProContYield, boolean isExec);

    /**
     * 余坯组板明细查询
     *
     * @param virtualSlabNo 虚拟板坯号
     * @param tenantId      租户
     * @return
     */
    PmPdSlabDTO detailQueryList(String virtualSlabNo, Long tenantId);

    /**
     * 余材组板明细查询
     *
     * @param tmpSlabNo 临时命令板坯号
     * @param tenantId  租户
     * @return
     */
    PmPdPlateDTO plateDetailQueryList(String tmpSlabNo, Long tenantId);
    
    /**
     * 组装组板板坯基础结构
     * @param pmProContYield
     * @param axisPmContMscTech
     * @param axisPmProContProdTtr
     * @param filterOrderMap
     * @return
     */
    PmPdSlab buildPmPdSlab(PmProContYieldRequestDTO pmProContYield, PmContMscTech axisPmContMscTech,
            PmProContProdTtr axisPmProContProdTtr, Map<String, PmProContFilterResposeDTO> filterOrderMap);
    
    /**
     * 组装收得率计算结果
     * @param pmPdSlab
     * @param pmProContYield
     * @param pmProContYieldRespose
     * @param pmCompositeSlabCalc
     */
    void buildPmPdSlab(PmPdSlab pmPdSlab, PmProContYieldRequestDTO pmProContYield,
            PmProContYieldResposeDTO pmProContYieldRespose, PmCompositeSlabCalcDTO pmCompositeSlabCalc);

    /**
     * 二次开坯，添加分割
     * @param splitInfoRequest
     * @return
     */
    String addMidSplit(PmPdMidSplitRequestDTO splitInfoRequest);

    /**
     * 二次开坯查询分割信息
     * @param virtualSlabNo
     * @param organizationId
     * @return
     */
    PmPdMidSplitDTO selectMidSplit(String virtualSlabNo, Long organizationId);

    /**
     * 二次开坯-删除分割
     * @param splitInfoRequest
     * @return
     */
    Boolean removeMidSplit(PmPdMidSplitRequestDTO splitInfoRequest);

    /**
     * 二次开坯-分割确认
     * @param splitInfoRequest
     * @return
     */
    Boolean midSplitConfirm(PmPdMidSplitRequestDTO splitInfoRequest);
    
    /**
     * 生成二次开坯信息
     */
    void createTwoRollInterim(PmTwoRollInterimRequestDTO request , PdMatType pdMatType);
    
    /**
     * 记录二次开坯计算日志
     * @param request
     * @param pdMatType
     */
    void twoRollInterimLog(PmTwoRollInterimRequestDTO request , Exception e , String midSlabNo);

    /**
     * 计算临时板坯长
     * @param slabNo
     * @param moldThick
     * @param moldWid
     * @param infuSlabWt
     * @param organizationId
     * @return
     */
    BigDecimal selectMidSplitTmpSlabLen(String virtualSlabNo, BigDecimal moldThick, BigDecimal moldWid,
            BigDecimal infuSlabWt, Long organizationId);

    /**
     * 余坯组板解散
     * @param tenantId
     * @param virtualSlabNoList
     */
    void disband(Long tenantId, List<String> virtualSlabNoList);

    /**
     * 余坯信息查询
     *
     * @param pageRequest
     * @param slabNo
     * @param tenantId
     * @return
     */
    Page<PmPdSlabDTO> slabList(PageRequest pageRequest, String slabNo, Long tenantId);

    /**
     * 余坯记录勾选
     *
     * @param virtualSlabNoList
     * @param tenantId
     * @return
     */
    List<PmPdSlabDTO> slabRecordCheckUi(List<String> virtualSlabNoList, Long tenantId);

    /**
     * 余材信息查询
     *
     * @param pageRequest
     * @param plateNo
     * @param tenantId
     * @return
     */
    Page<PmPdPlateDTO> plateList(PageRequest pageRequest, String plateNo, Long tenantId);

    /**
     * 余材记录勾选
     *
     * @param plateNoList
     * @param tenantId
     * @return
     */
    List<PmPdPlateDTO> plateRecordCheckUi(List<String> plateNoList, Long tenantId);

    /**
     * 查询临时收得率区间
     * @param virtualSlabNo
     * @param moldThick
     * @param moldWid
     * @param infuSlabWt
     * @param organizationId
     * @return
     */
    Map<String, Object> selectMidSplitTmpYield(String virtualSlabNo, BigDecimal moldThick, BigDecimal moldWid,
            BigDecimal infuSlabLen, Long organizationId);
}
