package com.bonus.material.clz.mapper;

import com.bonus.common.biz.domain.TypeTreeNode;
import com.bonus.common.biz.domain.lease.LeaseOutDetails;
import com.bonus.material.back.domain.vo.MaCodeVo;
import com.bonus.material.basic.domain.BmAgreementInfo;
import com.bonus.material.basic.domain.BmQrcodeInfo;
import com.bonus.material.clz.domain.vo.MaterialMaCodeVo;
import com.bonus.material.ma.domain.Type;
import com.bonus.material.clz.domain.lease.LeaseApplyDetailsInfo;
import com.bonus.material.clz.domain.vo.MaterialSltAgreementInfo;
import com.bonus.material.clz.domain.vo.lease.LeaseTotalInfo;
import com.bonus.material.clz.domain.lease.MaterialLeaseApplyDetails;
import com.bonus.material.clz.domain.lease.MaterialLeaseApplyInfo;
import com.bonus.common.biz.domain.lease.MaterialLeaseMaCodeDto;
import org.apache.ibatis.annotations.Param;

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

/**
 * @Author ma_sh
 * @create 2025/6/24 14:43
 */
public interface MaterialLeaseInfoMapper {

    /**
     * 查询领料任务列表
     * @param leaseApplyInfo
     * @return
     */
    List<MaterialLeaseApplyInfo> selectLeaseApplyInfoList(MaterialLeaseApplyInfo leaseApplyInfo);

    /**
     * 查询总站点领料记录数据
     * @param leaseApplyInfo
     * @return
     */
    List<MaterialLeaseApplyInfo> getTotalList(MaterialLeaseApplyInfo leaseApplyInfo);

    /**
     * 查询总站点领料详情数据
     * @param leaseApplyInfo
     * @return
     */
    List<MaterialLeaseApplyInfo> getDetailsList(MaterialLeaseApplyInfo leaseApplyInfo);

    /**
     * 查询站点领料记录数据
     * @param leaseApplyInfo
     * @return
     */
    MaterialLeaseApplyInfo selectLeaseApplyInfoById(MaterialLeaseApplyInfo leaseApplyInfo);

    /**
     * 查询站点领料详情数据
     * @param materialLeaseApplyDetails
     * @return
     */
    List<MaterialLeaseApplyDetails> selectLeaseApplyDetailsList(MaterialLeaseApplyDetails materialLeaseApplyDetails);

    /**
     * 查询站点领料出库数据
     * @param id
     * @return
     */
    List<MaterialLeaseApplyDetails> selectLeaseOutList(Long id);

    /**
     * 查询站点领料出库数据
     * @param id
     * @param typeId
     * @return
     */
    List<MaterialLeaseMaCodeDto> getCodeList(@Param("id") Long id, @Param("typeId") Long typeId);

    /**
     * 批量获取编码详情，优化N+1查询问题
     * @param id 申请ID
     * @param typeIds 类型ID列表
     * @return 编码详情列表
     */
    List<MaterialLeaseMaCodeDto> getCodeListBatch(@Param("id") Long id, @Param("typeIds") List<Long> typeIds);

    /**
     * 批量查询设备是否已被领料
     * @param maIds 设备ID列表
     * @return 已被领料的设备ID集合
     */
    Set<Long> getUsedMaIdsBatch(@Param("maIds") List<Long> maIds);

    /**
     * 查询站点领料出库数据
     * @param leaseApplyDetails
     * @return
     */
    List<MaterialLeaseApplyDetails> getOutNum(MaterialLeaseApplyDetails leaseApplyDetails);

    /**
     * 查询站点领料出库数据
     * @param leaseApplyDetails
     * @return
     */
    List<MaterialLeaseApplyDetails> getOutNumList(MaterialLeaseApplyDetails leaseApplyDetails);

    /**
     * 查询站点领料出库数据
     * @param dto
     * @return
     */
    List<MaterialLeaseApplyDetails> getOutDetailsById(MaterialLeaseApplyInfo dto);

    /**
     * 查询站点领料出库数据
     * @param dto
     * @return
     */
    List<LeaseApplyDetailsInfo> getLeaseInfo(LeaseApplyDetailsInfo dto);

    /**
     * 添加站点领料记录
     * @param leaseApplyInfo
     * @return
     */
    int insertLeaseApplyInfo(MaterialLeaseApplyInfo leaseApplyInfo);

    /**
     * 添加站点领料出库数据
     * @param record
     * @return
     */
    int insertLeaseOutDetails(LeaseOutDetails record);

    /**
     * 添加站点领料详情数据
     * @param leaseApplyDetailsList
     * @return
     */
    int insertLeaseApplyDetailsList(List<MaterialLeaseApplyDetails> leaseApplyDetailsList);

    /**
     * 删除站点领料详情数据
     * @param id
     * @return
     */
    int deleteLeaseApplyDetailsByParentIds(Long id);

    /**
     * 删除站点领料记录
     * @param id
     */
    int deleteById(Long id);

    /**
     * 修改领料任务
     * @param leaseApplyInfo
     */
    int updateLeaseApplyInfo(MaterialLeaseApplyInfo leaseApplyInfo);

    /**
     * 领料任务电子签名
     * @param leaseApplyInfo
     * @return
     */
    int updateLeaseApplyInfoSign(MaterialLeaseApplyInfo leaseApplyInfo);

    /**
     * 二维码出库：根据qrcode查询在库机具信息
     * @param bmQrcodeInfo
     * @return
     */
    List<LeaseOutDetails> getInfoByQrcode(BmQrcodeInfo bmQrcodeInfo);

    /**
     * 获取领料任务ID
     * @param id
     * @return
     */
    String getTaskId(Long id);

    /**
     * 删除站点领料记录
     * @param id
     * @return
     */
    int deleteLeaseApplyInfoByIds(Long id);

    /**
     * 工器具领料记录
     * @param info
     * @return
     */
    List<LeaseTotalInfo> getLeaseInfoDetails(LeaseTotalInfo info);

    /**
     * 工器具领料记录总数
     * @param leaseTotalInfo
     * @return
     */
    LeaseTotalInfo getTotalInfo(LeaseTotalInfo leaseTotalInfo);

    /**
     * 工器具领料二级页面记录
     * @param info
     * @return
     */
    List<MaCodeVo> getSecondLeaseInfo(LeaseTotalInfo info);

    /**
     * 获取工器具领料协议信息
     * @param record
     * @return
     */
    MaterialSltAgreementInfo getSltAgreementInfo(LeaseOutDetails record);

    /**
     * 修改工器具领料协议信息
     * @param sltAgreementInfo
     * @return
     */
    int updSltInfo(MaterialSltAgreementInfo sltAgreementInfo);

    /**
     * 添加工器具领料协议信息
     * @param record
     * @param agreementId
     * @param maType
     * @return
     */
    int insSltInfo(@Param("record") LeaseOutDetails record, @Param("agreementId") String agreementId, @Param("ma") Type maType);

    /**
     * 获取领料任务树结构
     * @param bean
     * @return
     */
    List<TypeTreeNode> getUseTypeTree(MaterialLeaseApplyInfo bean);

    /**
     * 根据id查询协议id
     * @param id
     * @return
     */
    Long getAgreementId(Long id);

    /**
     * 根据id查询领料任务信息
     * @param maCodeVo
     * @return
     */
    MaterialLeaseApplyInfo selectInfoById(MaterialLeaseMaCodeDto maCodeVo);

    /**
     * 根据id查询工器具信息
     * @param dto
     * @return
     */
    List<MaterialMaCodeVo> getMachineById(MaterialLeaseApplyInfo dto);

    /**
     * 根据id查询工器具信息
     * @param dto
     * @return
     */
    List<MaterialMaCodeVo> getUseMachineById(MaterialLeaseApplyInfo dto);

    /**
     * 查询发布列表
     * @param leaseApplyInfo
     * @return
     */
    List<MaterialLeaseApplyInfo> selectPublishList(MaterialLeaseApplyInfo leaseApplyInfo);

    /**
     * 获取工器具领料协议库存数量
     * @param agreementId
     * @param typeId
     * @return
     */
    BigDecimal getStorageNum(@Param("agreementId") Long agreementId, @Param("typeId") Long typeId);

    /**
     * 根据工程id去协议表中查询协议id
     * @param bean
     * @return
     */
    List<BmAgreementInfo> getAgreementIdByProId(MaterialLeaseApplyInfo bean);

    /**
     * 根据工程和班组id查询协议id
     * @param bean
     * @return
     */
    BmAgreementInfo getAgreeId(MaterialLeaseApplyInfo bean);

    /**
     * 二维码出库：根据qrcode查询在库机具信息
     * @param bmQrcodeInfo
     * @return
     */
    List<LeaseOutDetails> getInfoByQrcodeClz(BmQrcodeInfo bmQrcodeInfo);

    /**
     * 添加站点领料出库数据
     * @param record
     * @return
     */
    int insertLeaseApplyDetails(LeaseOutDetails record);

    /**
     * 根据任务id查询领料任务信息
     * @param taskId
     * @return
     */
    MaterialLeaseApplyInfo selectId(Long taskId);

    /**
     * 根据任务id查询领料任务详情信息
     * @param info
     * @return
     */
    MaterialLeaseApplyDetails selectDetailsById(MaterialLeaseApplyInfo info);

    /**
     * 修改站点领料详情数据
     * @param details
     * @return
     */
    int updateLeaseApplyDetails(@Param("record") MaterialLeaseApplyDetails details);

    /**
     * 根据工器具id查询工器具领料详情数据
     * @param record
     * @return
     */
    LeaseOutDetails selectInfoByTypeId(LeaseOutDetails record);

    /**
     * 修改站点领料详情数据
     * @param leaseOutDetails
     * @return
     */
    int updateLeaseOutDetails(@Param("record") LeaseOutDetails leaseOutDetails);

    /**
     * 根据任务id和工器具id查询工器具领料详情数据
     * @param id
     * @param typeId
     * @return
     */
    List<MaterialLeaseMaCodeDto> getList(@Param("id") Long id, @Param("typeId") Long typeId);

    /**
     * 根据任务id查询领料任务ID
     * @param id
     * @return
     */
    Long getTaskIds(Long id);

    /**
     * ocr出库：根据code查询在库机具信息
     * @param bmQrcodeInfo
     * @return
     */
    List<LeaseOutDetails> getMaCodeList(BmQrcodeInfo bmQrcodeInfo);

    /**
     * ocr出库：根据code查询在库机具信息
     * @param bmQrcodeInfo
     * @return
     */
    List<LeaseOutDetails> getInfoByCode(BmQrcodeInfo bmQrcodeInfo);

    /**
     * 删除协议表数据
     * @param id
     * @return
     */
    int deleteSltInfo(Long id);

    /**
     * 先根据id查询该领料单是否已经退料
     * @param id
     * @return
     */
    List<MaterialLeaseApplyInfo> getSltInfoList(Long id);
}
