package cn.iocoder.yudao.module.llm.dal.mysql.learningresources;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.llm.dal.dataobject.learningresources.LearningResourcesDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.llm.controller.admin.learningresources.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 学习资源 Mapper
 *
 * @author 华大大模型
 */
@Mapper
public interface LearningResourcesMapper extends BaseMapperX<LearningResourcesDO> {

    default PageResult<LearningResourcesDO> selectPage(LearningResourcesPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<LearningResourcesDO>()
                .eqIfPresent(LearningResourcesDO::getResourceCategory, reqVO.getResourceCategory())
                .eqIfPresent(LearningResourcesDO::getResourceTitle, reqVO.getResourceTitle())
                .eqIfPresent(LearningResourcesDO::getResourceIntro, reqVO.getResourceIntro())
                .eqIfPresent(LearningResourcesDO::getFileId, reqVO.getFileId())
                .eqIfPresent(LearningResourcesDO::getFileUrl, reqVO.getFileUrl())
                .betweenIfPresent(LearningResourcesDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(LearningResourcesDO::getId));
    }
    @Update("update llm_learning_resources set down_count = down_count + 1 where id = #{id}")
    void updateDownCount(LearningResourcesDO learningResourcesDO);

}
