package cn.com.ty.lift.ud.motiontrail.controller.query;

import cn.com.ty.lift.ud.common.BasePageQuery;
import cn.com.ty.lift.ud.motiontrail.mapper.entity.MotionTrail;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 人员轨迹查询条件
 *
 * @author Xson
 * @date 2020-07-15
 */
@Data
@ApiModel(description = "查询条件")
public final class MotionTrailQuery extends BasePageQuery {

    private Integer id;

    private Long mtCompanyId;
    
    private Long userId;

    private String mobile;

    private String position;

    private Date createTime;
    
    private String createTimeStr;

    /**
     * 查询条件
     *
     * @return
     */
    @Override
    public Wrapper condition() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        QueryWrapper<MotionTrail> query = new QueryWrapper<>();
        if(userId != null) {
            query.eq("user_id", userId);
        }
        // 查询时间只精确到日期，不精确到时间
        query.eq("date(create_time)", sdf.format(createTime)).orderByAsc("create_time");

        return query;
    }

    /**
     * 分页条件
     *
     * @return
     */
    @Override
    public IPage page() {
        Page<MotionTrail> page = new Page<>(getPageNum(), getPageSize());
        return page;
    }

}
