package com.yc.ship.module.miniapplet.dal.mysql.problem;

import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.mybatis.core.mapper.BaseMapperX;
import com.yc.ship.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yc.ship.module.miniapplet.controller.admin.problem.vo.ProblemPageReqVO;
import com.yc.ship.module.miniapplet.controller.app.problem.vo.AppProblemReqVO;
import com.yc.ship.module.miniapplet.dal.dataobject.problem.ProblemDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 问题管理 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface ProblemMapper extends BaseMapperX<ProblemDO> {

    default PageResult<ProblemDO> selectPage(ProblemPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProblemDO>()
                .eqIfPresent(ProblemDO::getTypeId, reqVO.getTypeId())
                .eqIfPresent(ProblemDO::getTitle, reqVO.getTitle())
                .eqIfPresent(ProblemDO::getKeyword, reqVO.getKeyword())
                .eqIfPresent(ProblemDO::getSystemType, reqVO.getSystemType())
                .eqIfPresent(ProblemDO::getReleaseStatus, reqVO.getReleaseStatus())
                .eqIfPresent(ProblemDO::getIsUse, reqVO.getIsUse())
                .orderByDesc(ProblemDO::getId));
    }

    default List<ProblemDO> getProblemList(AppProblemReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ProblemDO>()
                .eqIfPresent(ProblemDO::getTypeId, reqVO.getProblemTypeId())
                .likeIfPresent(ProblemDO::getTitle, reqVO.getProblemName())
                .eqIfPresent(ProblemDO::getSystemType, reqVO.getSystemType())
                .eqIfPresent(ProblemDO::getIsUse, 1)
                .orderByDesc(ProblemDO::getSortNum, ProblemDO::getId));
    }

}
