package com.yhy.module.core.dal.mysql.infoprice;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yhy.module.core.controller.admin.infoprice.vo.InfoPriceBookPageReqVO;
import com.yhy.module.core.dal.dataobject.infoprice.InfoPriceBookDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 信息价册 Mapper
 *
 * @author yhy
 */
@Mapper
public interface InfoPriceBookMapper extends BaseMapperX<InfoPriceBookDO> {

    /**
     * 分页查询信息价册
     *
     * @param reqVO 查询条件
     * @return 分页结果
     */
    default PageResult<InfoPriceBookDO> selectPage(InfoPriceBookPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InfoPriceBookDO>()
                .eqIfPresent(InfoPriceBookDO::getTreeNodeId, reqVO.getTreeNodeId())
                .likeIfPresent(InfoPriceBookDO::getName, reqVO.getName())
                .eqIfPresent(InfoPriceBookDO::getPublishStatus, reqVO.getPublishStatus())
                .betweenIfPresent(InfoPriceBookDO::getStartTime, reqVO.getStartTimeBegin(), reqVO.getStartTimeEnd())
                .betweenIfPresent(InfoPriceBookDO::getEndTime, reqVO.getEndTimeBegin(), reqVO.getEndTimeEnd())
                .orderByDesc(InfoPriceBookDO::getStartTime));
    }

    /**
     * 统计节点下的信息价册数量
     *
     * @param treeNodeId 树节点ID
     * @return 数量
     */
    default Long countByTreeNodeId(Long treeNodeId) {
        return selectCount(new LambdaQueryWrapperX<InfoPriceBookDO>()
                .eq(InfoPriceBookDO::getTreeNodeId, treeNodeId));
    }
}
