package com.xindazhou.business.dal.community.mysql.post;

import com.xindazhou.business.dal.community.dataobject.post.PostDO;
import com.xindazhou.business.controller.app.community.post.vo.PostPageReqVO;
import com.xindazhou.framework.common.pojo.PageResult;
import com.xindazhou.framework.mybatis.core.mapper.BaseMapperX;
import com.xindazhou.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.apache.ibatis.annotations.Mapper;

/**
 * 帖子 Mapper
 *
 * @author xindazhou
 */
@Mapper
public interface CommunityPostMapper extends BaseMapperX<PostDO> {

    default PageResult<PostDO> selectPage(PostPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PostDO>()
                .eqIfPresent(PostDO::getStatus, reqVO.getStatus())
                .eqIfPresent(PostDO::getUserId, reqVO.getUserId())
                .likeIfPresent(PostDO::getTitle, reqVO.getTitle())
                .orderByDesc(PostDO::getIsTop)
                .orderByDesc(PostDO::getCreateTime));
    }

    default PageResult<PostDO> selectPageAdmin(com.xindazhou.business.controller.admin.community.post.vo.PostPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PostDO>()
                .eqIfPresent(PostDO::getStatus, reqVO.getStatus())
                .eqIfPresent(PostDO::getUserId, reqVO.getUserId())
                .likeIfPresent(PostDO::getTitle, reqVO.getTitle())
                .eqIfPresent(PostDO::getIsTop, reqVO.getIsTop())
                .eqIfPresent(PostDO::getIsEssence, reqVO.getIsEssence())
                .betweenIfPresent(PostDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PostDO::getIsTop)
                .orderByDesc(PostDO::getCreateTime));
    }

    // 注意：增量更新需要在Service层实现，先查询再更新

}

