All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.javaclub.base.domain.query.BaseQuery Maven / Gradle / Ivy

package com.github.javaclub.base.domain.query;

import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.javaclub.sword.core.Collections;
import com.github.javaclub.sword.core.Entry;
import com.github.javaclub.sword.core.Numbers;
import com.github.javaclub.sword.core.Strings;
import com.github.javaclub.sword.domain.DomainEntityQuery;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * BaseQuery
 *
 * @version $Id: BaseQuery.java 2023-09-06 16:43:22 Exp $
 */
@Data
public class BaseQuery extends DomainEntityQuery {

	private static final long serialVersionUID = 1L;
	
	@ApiModelProperty(value = "匹配主键ID", example = "1")
	private Long id;
	
	@ApiModelProperty(value = "主键ID IN(ids)", hidden = true)
	private List ids;
	
	@ApiModelProperty(value = "主键ID NOT IN(ids)", hidden = true)
	private List notInIds; 
	
	@ApiModelProperty(value = "主键ID大于等于minId", example = "1", hidden = true)
	private Long minId;
	
	@ApiModelProperty(value = "主键ID小于等于maxId", example = "999999", hidden = true)
	private Long maxId;
	
	public  QueryWrapper buildBaseQuery() {
		QueryWrapper queryWrapper = new QueryWrapper();
		
		queryWrapper.eq(Numbers.isPositiveNumber(getId()), "id", getId())
					.ge(null != getMinId(), "id", getMinId())
					.le(null != getMaxId(), "id", getMaxId());
		if (Collections.isNotEmpty(ids)) {
			queryWrapper.in("id", ids);
		}
		if (Collections.isNotEmpty(notInIds)) {
			queryWrapper.notIn("id", notInIds);
		}
		if (null != getGmtCreateRange()) {
			Date startTime = getGmtCreateRange().getStart();
			Date endTime = getGmtCreateRange().getEnd();
			queryWrapper.ge(null != startTime, GMT_CREATE_COLUMN, startTime);
			queryWrapper.le(null != endTime, GMT_CREATE_COLUMN, endTime);
		}
		if (null != getGmtModifyRange()) {
			Date startTime = getGmtModifyRange().getStart();
			Date endTime = getGmtModifyRange().getEnd();
			queryWrapper.ge(null != startTime, GMT_CREATE_COLUMN, startTime);
			queryWrapper.le(null != endTime, GMT_CREATE_COLUMN, endTime);
		}
		
		if (Collections.isNotEmpty(getOrderByList())) {
			for (Entry order : getOrderByList()) {
				queryWrapper.orderBy(true, Strings.equalsIgnoreCase("ASC", order.getValue()), order.getKey());
			}
		} else {
			queryWrapper.orderByDesc(GMT_CREATE_COLUMN);
		}
		return queryWrapper;
	}
	
	static final String GMT_CREATE_COLUMN = "created_time";
	static final String GMT_MODIFY_COLUMN = "modified_time";

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy