package com.hz.pm.api.projectlib.helper;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hz.pm.api.projectlib.model.entity.Project;
import com.hz.pm.api.projectlib.model.req.ProjectRenewalListReq;

/**
 * <p>
 * ProjectRenewFundHelper
 * </p>
 *
 * @author ZPF
 * @since 14:15 2023/11/16
 */
public class ProjectRenewFundHelper {

    private ProjectRenewFundHelper() {
    }

    /**
     * 通用项目查询
     *
     * @param req 查询条件
     * @return /
     **/
    public static LambdaQueryWrapper<Project> projectQuery(ProjectRenewalListReq req) {
        LambdaQueryWrapper<Project> query = new LambdaQueryWrapper<>();
        query.eq(req.getRegionCode() != null, Project::getAreaCode, req.getRegionCode())
                .eq(req.getUserId() != null, Project::getCreateBy, req.getUserId())
                .like(req.getProjectName() != null, Project::getProjectName, req.getProjectName())
                .eq(req.getProjectType() != null, Project::getProjectType, req.getProjectType())
                .eq(req.getStage() != null, Project::getStage, req.getStage())
                .eq(req.getStatus() != null, Project::getStatus, req.getStatus())

                //状态 阶段 list
                .in(CollUtil.isNotEmpty(req.getStageList()), Project::getStage, req.getStageList())
                .in(CollUtil.isNotEmpty(req.getStatusList()), Project::getStatus, req.getStatusList())
                .orderByDesc(Project::getUpdateOn);
        return query;
    }
}
