package com.zsc.edu.gateway.modules.iot.tsl.query;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zsc.edu.gateway.modules.iot.product.entity.Product;
import com.zsc.edu.gateway.modules.iot.tsl.entity.Event;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Objects;

/**
 * @author zhuang
 */
@Data
public class EventQuery {

    /**
     * 标识
     */
    public String identifier;

    /**
     * 名称
     */
    public String name;


    /**
     * 1异常上报
     * 0普通上报
     * 事件级别
     */
    public String level;

    /**
     * 名称
     */
    public Long productId;

    public LambdaQueryWrapper<Event> wrapper() {
        LambdaQueryWrapper<Event> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.hasText(this.name), Event::getName, this.name);
        queryWrapper.like(StringUtils.hasText(this.identifier), Event::getIdentifier, this.identifier);
        queryWrapper.eq(StringUtils.hasText(this.level), Event::getType, this.level);
        queryWrapper.eq(Objects.nonNull(this.productId), Event::getProductId, this.productId);
        return queryWrapper;
    }

}
