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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zsc.edu.gateway.modules.iot.tsl.entity.Property;
import com.zsc.edu.gateway.modules.system.entity.Dept;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Objects;

/**
 * @author zhuang
 */
@Data
public class PropertyQuery {
    /**
     * 标识
     */
    public String identifier;

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

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


    /**
     * 读写类型
     */
    public Property.IoType type;

    public LambdaQueryWrapper<Property> wrapper() {
        LambdaQueryWrapper<Property> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(this.type != null, Property::getIoType, this.type);
        queryWrapper.like(StringUtils.hasText(this.identifier), Property::getIdentifier, this.identifier);
        queryWrapper.eq(Objects.nonNull(this.productId), Property::getProductId, this.productId);
        queryWrapper.like(StringUtils.hasText(this.name), Property::getName, this.name);
        return queryWrapper;
    }
}
