package cn.iocoder.yudao.module.system.dal.mysql.project;

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 cn.iocoder.yudao.module.system.controller.admin.project.vo.ProjectPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
import cn.iocoder.yudao.module.system.dal.dataobject.project.ProjectDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Objects;

/**
 * 项目管理 Mapper
 *
 * @author 符溶馨
 */
@Mapper
public interface ProjectMapper extends BaseMapperX<ProjectDO> {

    default PageResult<ProjectDO> selectPage(ProjectPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProjectDO>()
                .eqIfPresent(ProjectDO::getProjectNo, reqVO.getProjectNo())
                .eqIfPresent(ProjectDO::getType, reqVO.getType())
                .likeIfPresent(ProjectDO::getName, reqVO.getName())
                .eqIfPresent(ProjectDO::getResponsibleDept, reqVO.getResponsibleDept())
                .eqIfPresent(ProjectDO::getDirectorUserId, reqVO.getDirectorUserId())
                .betweenIfPresent(ProjectDO::getStartDate, reqVO.getStartDate())
                .betweenIfPresent(ProjectDO::getEndDate, reqVO.getEndDate())
                .eqIfPresent(ProjectDO::getIsLongTerm, reqVO.getIsLongTerm())
                .eqIfPresent(ProjectDO::getStatus, reqVO.getStatus())
                .likeLeft(Objects.nonNull(reqVO.getParticipationDept()), ProjectDO::getParticipationDept, "-" + reqVO.getParticipationDept())
                .or()
                .likeRight(Objects.nonNull(reqVO.getParticipationDept()), ProjectDO::getParticipationDept, reqVO.getParticipationDept() + "-")
                .or()
                .like(Objects.nonNull(reqVO.getParticipationDept()), ProjectDO::getParticipationDept, "-" + reqVO.getParticipationDept() + "-")
                .orderByDesc(ProjectDO::getId));
    }
}