package com.yc.ship.module.resource.dal.mysql.project;

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.resource.controller.admin.project.vo.ProjectPageReqVO;
import com.yc.ship.module.resource.controller.admin.vo.SimpleListReqVO;
import com.yc.ship.module.resource.dal.dataobject.project.ProjectDO;
import com.yc.ship.module.resource.enums.UseStatusEnum;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;


/**
 * 产品项目 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface ProjectMapper extends BaseMapperX<ProjectDO> {

    default PageResult<ProjectDO> selectPage(ProjectPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProjectDO>()
                .likeIfPresent(ProjectDO::getName, reqVO.getName())
                .eqIfPresent(ProjectDO::getCode, reqVO.getCode())
                .likeIfPresent(ProjectDO::getSpecificationType, reqVO.getSpecificationType())
                .orderByAsc(ProjectDO::getSort));
    }

    default List<ProjectDO> getProjectList(ProjectPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ProjectDO>()
                .likeIfPresent(ProjectDO::getName, reqVO.getName())
                .eqIfPresent(ProjectDO::getCode, reqVO.getCode())
                .eqIfPresent(ProjectDO::getParentId, reqVO.getParentId())
                .eqIfPresent(ProjectDO::getSpecificationType, reqVO.getSpecificationType())
                .orderByAsc(ProjectDO::getSort));
    }

    default List<ProjectDO> getProjectList(SimpleListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ProjectDO>()
                .likeIfPresent(ProjectDO::getName, reqVO.getName())
                .eqIfPresent(ProjectDO::getUseStatus, reqVO.getStatus())
                .eqIfPresent(ProjectDO::getTenantId, reqVO.getTenantId())
        );
    }

    default List<ProjectDO> getProjectList() {
        return selectList(new LambdaQueryWrapperX<ProjectDO>()
                .eqIfPresent(ProjectDO::getUseStatus, UseStatusEnum.ENABLE.getStatus())
                .eqIfPresent(ProjectDO::getParentId, 0)
                .orderByAsc(ProjectDO::getSort)
        );
    }

}