package com.ningdatech.pmapi.projectlib.helper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ningdatech.pmapi.projectlib.model.entity.Project;
import com.ningdatech.pmapi.projectlib.model.req.ProjectListReq;

/**
 * <p>
 * ProjectHelper
 * </p>
 *
 * @author WendyYang
 * @since 14:15 2023/2/11
 */
public class ProjectHelper {

    /**
     * 通用项目查询
     *
     * @param req 查询条件
     * @return /
     **/
    public static LambdaQueryWrapper<Project> projectQuery(ProjectListReq req) {
        LambdaQueryWrapper<Project> query = new LambdaQueryWrapper<>();
        query.eq(req.getRegionCode() != null, Project::getAreaCode, req.getRegionCode());
        query.eq(req.getUserId() != null, Project::getCreateBy, req.getUserId());
        query.like(req.getProjectName() != null, Project::getProjectName, req.getProjectName());
        query.eq(req.getProjectType() != null, Project::getProjectType, req.getProjectType());
        query.eq(req.getProjectYear() != null, Project::getProjectYear, req.getProjectYear());
        query.eq(req.getStage() != null, Project::getStage, req.getStage());
        query.eq(req.getStatus() != null, Project::getStatus, req.getStatus());
        // 申报金额
        query.ge(req.getDeclareAmountMin() != null, Project::getDeclareAmount, req.getDeclareAmountMin());
        query.le(req.getDeclareAmountMax() != null, Project::getDeclareAmount, req.getDeclareAmountMax());
        // 申报时间
        query.ge(req.getCreateOnMin() != null, Project::getCreateOn, req.getCreateOnMin());
        query.le(req.getCreateOnMax() != null, Project::getCreateOn, req.getCreateOnMax());
        // 批复金额
        query.ge(req.getApproveAmountMin() != null, Project::getApprovalAmount, req.getApproveAmountMin());
        query.le(req.getApproveAmountMax() != null, Project::getApprovalAmount, req.getApproveAmountMax());

        query.like(req.getBuildOrg() != null, Project::getBuildOrgName, req.getBuildOrg());
        return query;
    }

}
