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

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.problemtype.vo.ProblemTypePageReqVO;
import com.yc.ship.module.miniapplet.controller.app.problem.vo.AppProblemReqVO;
import com.yc.ship.module.miniapplet.dal.dataobject.problemtype.ProblemTypeDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 问题类型 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface ProblemTypeMapper extends BaseMapperX<ProblemTypeDO> {

    default PageResult<ProblemTypeDO> selectPage(ProblemTypePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProblemTypeDO>()
                .likeIfPresent(ProblemTypeDO::getName, reqVO.getName())
                .eqIfPresent(ProblemTypeDO::getCode, reqVO.getCode())
                .eqIfPresent(ProblemTypeDO::getParentId, reqVO.getParentId())
                .eqIfPresent(ProblemTypeDO::getLogo, reqVO.getLogo())
                .eqIfPresent(ProblemTypeDO::getSystemType, reqVO.getSystemType())
                .eqIfPresent(ProblemTypeDO::getRemark, reqVO.getRemark())
                .eqIfPresent(ProblemTypeDO::getIsUse, reqVO.getIsUse())
                .eqIfPresent(ProblemTypeDO::getSortNum, reqVO.getSortNum())
                .betweenIfPresent(ProblemTypeDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ProblemTypeDO::getId));
    }

    default List<ProblemTypeDO> getProblemTypeListByStatus(Integer systemType, Integer status) {
        return selectList(new LambdaQueryWrapperX<ProblemTypeDO>()
                .eqIfPresent(ProblemTypeDO::getSystemType, systemType)
                .eqIfPresent(ProblemTypeDO::getIsUse, status)
                .orderByDesc(ProblemTypeDO::getCreateTime));
    }

    default List<ProblemTypeDO> getProblemTypeListByApp(AppProblemReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ProblemTypeDO>()
                .eqIfPresent(ProblemTypeDO::getIsUse, 1)
                .eqIfPresent(ProblemTypeDO::getId, reqVO.getProblemTypeId())
                .eqIfPresent(ProblemTypeDO::getParentId, reqVO.getProblemTypeParentId())
                .eqIfPresent(ProblemTypeDO::getSystemType, reqVO.getSystemType())
                .eqIfPresent(ProblemTypeDO::getCode, reqVO.getCode())
                .orderByDesc(ProblemTypeDO::getSortNum, ProblemTypeDO::getId)
        );
    }
}
