package com.xisc.pm.infra.mapper;

import com.xisc.pm.api.dto.PmFinishedProductsServeAsStatisticsDTO;
import com.xisc.pm.api.dto.WmConfmPlanMatDTO;
import com.xisc.pm.domain.entity.MmSlab;
import com.xisc.pm.domain.vo.CtMainVO;
import com.xisc.pm.domain.vo.MmPlateSmallProVO;
import com.xisc.pm.domain.vo.MmPlateVO;
import com.xisc.pm.domain.vo.MmRollingVo;
import com.xisc.pm.domain.vo.MmUstRsltVO;
import com.xisc.pm.domain.vo.QdToLineupResultHeattreatVO;
import com.xisc.pm.domain.vo.QdToLineupResultRollingVO;
import com.xisc.pm.domain.vo.QdToLineupResultSizingVO1;
import com.xisc.pm.domain.vo.QdToLineupResultUTVO;
import com.xisc.pm.domain.vo.QdToPoOrderVO;
import com.xisc.pm.domain.vo.QdToPoOrderVO1;
import com.xisc.pm.domain.vo.WmMatPileVO1;
import com.xisc.pm.domain.vo.WmStockInfoVO;
import io.choerodon.mybatis.common.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.data.repository.query.Param;

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

/**
 * 钢板主数据表(MmPlate)应用服务
 *
 * @author 蒋雨航 yuhang.jiang02@hand-china.com
 * @since 2024-08-14 15:37:09
 */
@Mapper
public interface PmMmPlateMapper extends BaseMapper<MmPlateVO> {
    /**
     * 基础查询
     *
     * @param mmPlateVO 查询条件
     * @return 返回值
     */
    List<MmPlateVO> selectList(MmPlateVO mmPlateVO);

    /**
     * 根据主键id查询
     *
     * @param mmPlateVO
     * @return
     */
    MmPlateVO selectMmPlatePrimary(MmPlateVO mmPlateVO);

    /**
     * 余材钢板充当材料信息列表
     * @param dto
     * @return
     */
    List<MmPlateVO> surplusSteelPlateList(MmPlateVO dto);

    /**
     * 小工序代码NT数量
     * @param matNoList
     * @return
     */
    int smallProcessCodeNtNum(List<String> matNoList);

    /**
     * 小工序代码QT数量
     * @param matNoList
     * @return
     */
    int smallProcessCodeQtNum(List<String> matNoList);

    /**
     * 根据材料号mat_no查询热处理实绩表MM_HTMRSLT中最大生产流水号PROD_SEQ_NO所在行的热处理方式代码HOT_TREAT_METHOD_CODE
     * @param maxProdSeqNo
     * @return
     */
    String selectHeatTreatmentMethodCode(String maxProdSeqNo);

    /**
     * 查询最大PROD_SEQ_NO流水号
     * @param matNoList
     * @return
     */
    String selectMaxProdSeqNo(List<String> matNoList);

    /**
     * 根据小板号small_plate_no等于材料号mat_no查询探伤实绩表MM_UST_RSLT中最大生产流水号PROD_SEQ_NO
     * @param matNoList
     * @return
     */
    String selectMaxProdSeqNoByMatNo(List<String> matNoList);

    /**
     * 最大生产流水号PROD_SEQ_NO记录行的UST综合评价UST_VALUE_LAST
     * @param maxProdSeqNo
     * @return
     */
    String selectUstValueLast(String maxProdSeqNo);

    /**
     * 查询所有钢板号
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @return
     */
    List<String> selectSgsing(Date timeTo, Date timeFrom, Integer orderTypeCode, Long createdBy);

    /**
     * 查询记录数和查询重量和
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSignList
     * @return
     */
    List<PmFinishedProductsServeAsStatisticsDTO> selectPlateInfo(Date timeTo, Date timeFrom, Integer orderTypeCode, List<String> sgSignList, List<String> slabNoList);

    /**
     * 余材钢板组板数量、材料实际重量mat_act_wt总和记为余材钢板组板重量。
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSign
     * @param slabNoList
     * @return
     */
    PmFinishedProductsServeAsStatisticsDTO selectHpouupAndHpouupnInfo(Date timeTo, Date timeFrom, Integer orderTypeCode, String sgSign, List<String> slabNoList);

    /**
     * 生产合同产品属性表(PM_PRO_CONT_PROD_ATTR)的合同性质代码order_type_code不等于YZA,关联查询组板合同总量表（PM_PD_CONT_SUM）的板坯号SLAB_NO（通过合同号order_no关联）
     * @return
     */
    List<String> selectSlabNoList();

    /**
     * 查询5米余材钢板组板重量和数量
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSignList
     * @return
     */
    List<PmFinishedProductsServeAsStatisticsDTO> selectHpouup5mAndpouupn5m(Date timeTo, Date timeFrom, Integer orderTypeCode, List<String> sgSignList);

    /**
     * 查询5米余材钢板组板重量和数量
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSign
     * @return
     */
    PmFinishedProductsServeAsStatisticsDTO selectHpouup5mAndpouupn5mInfo(Date timeTo, Date timeFrom, Integer orderTypeCode, String sgSign, List<String> slabNoList);

    /**
     * 查询3.8米余材钢板组板重量和数量
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSignList
     * @return
     */
    List<PmFinishedProductsServeAsStatisticsDTO> selectHpouup3mAndpouupn3m(Date timeTo, Date timeFrom, Integer orderTypeCode, List<String> sgSignList);

    /**
     * 查询3.8米余材钢板组板重量和数量
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSign
     * @return
     */
    PmFinishedProductsServeAsStatisticsDTO selectHpouup3mAndpouupn3mInfo(Date timeTo, Date timeFrom, Integer orderTypeCode, String sgSign, List<String> slabNoList);

    /**
     * 余材钢板直接充当数量,余材钢板直接充当重量
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSignList
     * @return
     */
    List<PmFinishedProductsServeAsStatisticsDTO> selectHpoaupAndSghpoaupnSign(Date timeTo, Date timeFrom, Integer orderTypeCode, List<String> sgSignList, List<String> matNoList, List<String> orderNoList);

    /**
     * 余材钢板直接充当数量,余材钢板直接充当重量
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSign
     * @param matNoList
     * @param orderNoList
     * @return
     */
    PmFinishedProductsServeAsStatisticsDTO selectHpoaupAndSghpoaupnSignInfo(Date timeTo, Date timeFrom, Integer orderTypeCode,String sgSign, List<String> matNoList, List<String> orderNoList);

    /**
     *根据记录创建时间CREATE_DATE在统计时间[起]之前、功能标识func_id等于'pmoahp02_putup'查询转用充当履历PM_CD_CONT_LOG的材料号
     * @param timeTo
     * @return
     */
    List<String> selectMatNoList(Date timeTo);

    /**
     * 产合同产品属性表(PM_PRO_CONT_PROD_ATTR)的合同性质代码order_type_code不等于YZA且以N开头的合同号order_no
     * @return
     */
    List<String> selectOrderNoList();

    /**
     * 5米余材钢板直接充当数量,5米余材钢板直接充当重量
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSignList
     * @param matNoList
     * @param orderNoList
     * @return
     */
    List<PmFinishedProductsServeAsStatisticsDTO> selectHpoaup5mAndHpoaupn5m(Date timeTo, Date timeFrom, Integer orderTypeCode, List<String> sgSignList, List<String> matNoList, List<String> orderNoList);

    /**
     * 米余材钢板直接充当数量,5米余材钢板直接充当重量
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSign
     * @param matNoList
     * @param orderNoList
     * @return
     */
    PmFinishedProductsServeAsStatisticsDTO selectHpoaup5mAndHpoaupn5mInfo(Date timeTo, Date timeFrom, Integer orderTypeCode, String sgSign, List<String> matNoList, List<String> orderNoList);

    /**
     * 3.8米余材钢板直接充当数量,3.8米余材钢板直接充当重量
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSignList
     * @param matNoList
     * @param orderNoList
     * @return
     */
    List<PmFinishedProductsServeAsStatisticsDTO> selectHpoaup3mAndHpoaupn3m(Date timeTo, Date timeFrom, Integer orderTypeCode, List<String> sgSignList, List<String> matNoList, List<String> orderNoList);

    /**
     * 3.8米余材钢板直接充当数量,3.8米余材钢板直接充当重量
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSign
     * @param matNoList
     * @param orderNoList
     * @return
     */
    PmFinishedProductsServeAsStatisticsDTO selectHpoaup3mAndHpoaupn3mInfo(Date timeTo, Date timeFrom, Integer orderTypeCode, String sgSign, List<String> matNoList, List<String> orderNoList);

    /**
     * 余材板坯组板数量,余材板坯组板重量
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSignList
     * @return
     */
    List<PmFinishedProductsServeAsStatisticsDTO> selectSmouupAndSmouupn(Date timeTo, Date timeFrom, Integer orderTypeCode, List<String> sgSignList, List<String> slabNoList);

    /**
     * 余材板坯组板数量,余材板坯组板重量
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSign
     * @param slabNoList
     * @return
     */
    PmFinishedProductsServeAsStatisticsDTO selectSmouupAndSmouupnInfo(Date timeTo, Date timeFrom, Integer orderTypeCode, String sgSign, List<String> slabNoList);

    /**
     * 生产合同产品属性表(PM_PRO_CONT_PROD_ATTR)的合同性质代码order_type_code不等于YZA,关联查询组板合同总量表（PM_PD_CONT_SUM）的板坯号SLAB_NO（通过合同号order_no关联）
     * @return
     */
    List<String> selectSlabNo();

    /**
     * 余材板坯直接充当数量,余材板坯直接充当重量
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSignList
     * @param slabNos
     * @return
     */
    List<PmFinishedProductsServeAsStatisticsDTO> selectSmoaupAndSmoaupn(Date timeTo, Date timeFrom, Integer orderTypeCode, List<String> sgSignList, List<String> slabNos);

    /**
     * 余材板坯直接充当数量,余材板坯直接充当重量
     * @param timeTo
     * @param timeFrom
     * @param orderTypeCode
     * @param sgSign
     * @param slabNoList
     * @return
     */
    PmFinishedProductsServeAsStatisticsDTO selectSmoaupAndSmoaupnInfo(Date timeTo, Date timeFrom, Integer orderTypeCode, String sgSign, List<String> slabNoList);

    /**
     * 根据合同查询合同状态
     *
     * @param orderNoList 合同号
     * @param tenantId    租户
     * @return
     */
    List<CtMainVO> selectOrderStatus(List<String> orderNoList, Long tenantId);

    /**
     * QD_TO_PO_ORDER的奉送样标记give_sample_flag
     *
     * @param orderNoList 合同号
     * @param tenantId    租户
     * @return
     */
    List<QdToPoOrderVO> selectGiveSampleFlag(List<String> orderNoList, Long tenantId);

    /**
     * 根据合同号查询合同状态
     * @param orderNo
     * @return
     */
    String selectOrderStatusByOrderNo(String orderNo);

    /**
     * 根据板坯号SLAB_NO查询材料的板坯主数据主表MM_SLAB信息并校验存在。
     * @return
     */
    List<MmSlab> selectMmSlabList(List<String> slabNoList);

    /**
     * 根据合同号order_no、全程工序代码WHOLE_BACKLOG_CODE=9A、小工序代码SUB_BACKLOG_CODE为空查询合同跟踪详细表CT_DET的差欠重量LACK_WGT。
     * @param orderNo
     * @return
     */
    BigDecimal selectLackWgt(String orderNo);

    /**
     * 通过“材料号”mat_no关联“材料垛位信息表”WM_MAT_PILE
     * @param slabNoList
     * @return
     */
    List<WmMatPileVO1> selectWmMatPileList(List<String> slabNoList);

    /**
     * 查询已产出的材料信息
     * @param matNoList
     * @return
     */
    List<MmPlateVO> selectMmPateList(List<String> matNoList, String matStatus);

    /**
     * 批量查询合同信息
     * @param orderNoList
     * @return
     */
    List<QdToPoOrderVO1> selectOrderInfo(List<String> orderNoList, Long tenantId);

    /**
     * 据合同号order_no、钢板主数据表(状态代码为已产出)MM_PLATE的产线号msc_line_no查询合同处理轧钢工艺标准QD_TO_LINEUP_RESULT_ROLLING的轧制方向代码ROLL_DIRECT_CODE、控轧代码CTRL_ROLL_CODE并校验存在。
     * @param orderNo
     * @param mscLineNoList
     * @return
     */
    List<QdToLineupResultRollingVO> selectQdtoLineupResultRolling(String orderNo, List<String> mscLineNoList, Long tenantId);

    /**
     * 根据原合同号order_no查询合同处理精整工艺标准QD_TO_LINEUP_RESULT_SIZING中第一行记录的超声探伤代码ULT_CODE并校验存在
     * @param orgOrderNoList
     * @return
     */
    List<QdToLineupResultSizingVO1> selectQdToLineupResultSizing(List<String> orgOrderNoList);

    /**
     * 根据合同号order_no查询合同处理产线组合QD_TO_PO_LINE_COMB的产线号msc_line_no并校验存在。
     * @param orderNo
     * @return
     */
    String selectMscLineNo(String orderNo);

    /**
     * 读取钢板主数据表（MM_PLATE）中材料号为当前命令板坯号的综判代码complex_decide_code，取值为1时代表已完成综判。
     * @param ponoSlabNo
     * @return
     */
    String selectComplexDecideCode(String ponoSlabNo);

    /**
     * 根据合同号（ORDER_NO）去合同跟踪主表CT_MAIN获取到得差欠件数ORD_REM_NUM，进行如下比对：
     * @param orderNo
     * @return
     */
    Long selectOrdRemNum(String orderNo);

    /**
     * 根据合同号（ORDER_NO）去合同跟踪主表CT_MAIN获取到得差欠重量
     * @param orderNo
     * @return
     */
    BigDecimal selectOrdRemWgt(String orderNo);

    /**
     * @param tenantId
     * @param matNo
     * @param prodYear
     * @param rollLineNo
     * @return
     */
    MmRollingVo selectMmRolling(Long tenantId, String matNo, String prodYear, String rollLineNo);

    List<PmFinishedProductsServeAsStatisticsDTO> batchSelectHpouupAndHpouupnInfo(Date timeTo, Date timeFrom, Integer orderTypeCode,
                                                                                 List<String> sgSignList, List<String> slabNoList);

    List<PmFinishedProductsServeAsStatisticsDTO> batchSelectHpouup5mAndpouupn5mInfo(Date timeTo, Date timeFrom, Integer orderTypeCode,
                                                                                    List<String> sgSignList, List<String> slabNoList);

    List<PmFinishedProductsServeAsStatisticsDTO> batchSelectHpouup3mAndpouupn3mInfo(Date timeTo, Date timeFrom, Integer orderTypeCode,
                                                                                    List<String> sgSignList, List<String> slabNoList);

    List<PmFinishedProductsServeAsStatisticsDTO> batchSelectHpoaupAndSghpoaupnSignInfo(Date timeTo, Date timeFrom, Integer orderTypeCode,
                                                                                       List<String> sgSignList, List<String> matNoList,
                                                                                       List<String> orderNoList);

    List<PmFinishedProductsServeAsStatisticsDTO> batchSelectHpoaup5mAndHpoaupn5mInfo(Date timeTo, Date timeFrom, Integer orderTypeCode,
                                                                                     List<String> sgSignList, List<String> matNoList,
                                                                                     List<String> orderNoList);

    List<PmFinishedProductsServeAsStatisticsDTO> batchSelectHpoaup3mAndHpoaupn3mInfo(Date timeTo, Date timeFrom, Integer orderTypeCode,
                                                                                     List<String> sgSignList, List<String> matNoList,
                                                                                     List<String> orderNoList);

    List<PmFinishedProductsServeAsStatisticsDTO> batchSelectSmouupAndSmouupnInfo(Date timeTo, Date timeFrom, Integer orderTypeCode,
                                                                                 List<String> sgSignList, List<String> slabNoList);

    List<PmFinishedProductsServeAsStatisticsDTO> batchSelectSmoaupAndSmoaupnInfo(Date timeTo, Date timeFrom, Integer orderTypeCode,
                                                                                 List<String> sgSignList, List<String> slabNoList);

    String selectGiveSampleFlagByOrderNo(String orderNo);

    List<WmConfmPlanMatDTO> selectMscLineNoList(List<String> matNoList);

    QdToPoOrderVO1 selectOrderInfoByOrderNo(String orderNo);

    String selectRollDirectCode(String orderNo, Long tenantId);

    List<MmPlateVO> selectRollDirectCodeList(List<String> orgOrderNoList, List<String> mscLineNoList, Long tenantId);

    List<QdToPoOrderVO1> selectOrderTypeCodeList(List<String> orderNoList);

    /**
     * 根据合同号查询合同状态
     * @param orderNoList
     * @return
     */
    List<CtMainVO> selectListOrderStatusByOrderNo(List<String> orderNoList, Long tenantId);


    List<QdToPoOrderVO> selectGiveSampleFlagListByOrderNo(List<String> orderNoList, Long tenantId);

    List<MmPlateSmallProVO> getSubBacklogCode(List<String> matNoList, Long tenantId);

    List<QdToLineupResultHeattreatVO> getHeatTreatType( List<String> orderNoAllList,List<String> mscLineNoList, Long tenantId);

    List<QdToLineupResultUTVO> selectUtCode(List<String> orderNoList, Long tenantId);

    List<MmUstRsltVO> selectResutCode(List<String> matNoList, List<String> utCodeList, Long tenantId);

    List<WmStockInfoVO> queryStockLineByMatNo(List<String> matNoList, Long tenantId);

    List<MmPlateVO> getMmPlateByMatNo(@Param("matNoList")List<String> matNoList, @Param("tenantId")Long tenantId);

    List<MmPlateVO> getMmPlateByPrimaryPlateId(@Param("mmPlateIdList")List<Long> mmPlateIdList, @Param("tenantId") Long tenantId);
}

