package cn.cecep.talroad.vo.query;


import cn.cecep.talroad.common.core.annotation.Excel;
import cn.cecep.talroad.common.core.domain.query.PageQuery;
import cn.cecep.talroad.common.core.web.domain.BaseEntity;
import cn.cecep.talroad.domain.BasDevice;
import cn.cecep.talroad.domain.BasDeviceSite;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.sf.jsqlparser.statement.select.Wait;

import java.util.List;


@ApiModel(value = "设备点位表")
@Data
@EqualsAndHashCode(callSuper = false)
public class BasDeviceSiteQuery extends PageQuery {

    private String id;

    @ApiModelProperty(value = "设备ID")
    private String deviceId;

    @ApiModelProperty(value = "点位名称")
    private String name;

    @ApiModelProperty(value = "点位经度")
    private String pointLng;

    @ApiModelProperty(value = "点位纬度")
    private String pointLat;

    @ApiModelProperty(value = "分表计电-状态: 正常,停运,掉线")
    private String status;

    @ApiModelProperty(value = "点位类型: 生产监测点位...")
    private String type;

    @ApiModelProperty(value = "对应装备名称")
    private String equipName;

    @ApiModelProperty(value = "所属企业")
    private String factoryId;

    @ApiModelProperty(value = "额定功率")
    private String normalValue;

    @ApiModelProperty(value = "最小功率")
    private String minValue;

    @ApiModelProperty(value = "是否统计")
    private String isStat;

    @ApiModelProperty(value = "对应设施名称")
    @Excel(name = "对应设施名称")
    private String deviceName;

    @ApiModelProperty(value = "设施类型")
    @Excel(name = "设施类型")
    private String deviceType;
    @ApiModelProperty("操作时间，只有日志查询使用")
    private String startTime;

    @ApiModelProperty("操作时间，只有日志查询使用")
    private String endTime;

    @ApiModelProperty(value = "设备IDs")
    private List<String> deviceIds;

    @ApiModelProperty("是否启用")
    private String isStatus;

    /**
     * @throws
     * @Title: getQueryWrapper
     * @Description: 查询参数组装
     * @param: @return
     * @return: QueryWrapper<BasDeviceSite>
     */
    public static QueryWrapper<BasDeviceSite> createLambdaQueryWrapper(BasDeviceSiteQuery query) {
        QueryWrapper<BasDeviceSite> wrapper = new QueryWrapper<>();
        wrapper.eq(ObjectUtil.isNotNull(query.getId()), "mam.id", query.getId());
        wrapper.eq(ObjectUtil.isNotNull(query.getDeviceId()), "mam.device_id", query.getDeviceId());
        wrapper.like(StrUtil.isNotBlank(query.getName()), "mam.name", query.getName());
        wrapper.eq(ObjectUtil.isNotNull(query.getPointLat()), "mam.point_lat", query.getPointLat());
        wrapper.eq(ObjectUtil.isNotNull(query.getPointLng()), "mam.point_lng", query.getPointLng());
        wrapper.eq(ObjectUtil.isNotNull(query.getStatus()), "mam.status", query.getStatus());
        wrapper.eq(ObjectUtil.isNotNull(query.getType()), "mam.type", query.getType());
        wrapper.eq(ObjectUtil.isNotNull(query.getEquipName()), "mam.equip_name", query.getEquipName());
        wrapper.eq(ObjectUtil.isNotNull(query.getFactoryId()), "mam.factory_id", query.getFactoryId());
        wrapper.eq(ObjectUtil.isNotNull(query.getIsStat()), "mam.is_stat", query.getIsStat());
        wrapper.eq(ObjectUtil.isNotNull(query.getNormalValue()), "mam.normal_value", query.getNormalValue());
        wrapper.eq(ObjectUtil.isNotNull(query.getMinValue()), "mam.min_value", query.getMinValue());
        wrapper.eq(ObjectUtil.isNotNull(query.getMinValue()), "mam.is_status", query.getIsStatus());


        wrapper.like(StrUtil.isNotBlank(query.getDeviceName()), "poc.name", query.getDeviceName());
        wrapper.like(StrUtil.isNotBlank(query.getDeviceType()), "poc.type", query.getDeviceType());
        wrapper.orderByAsc("mam.name", "mam.id");
        return wrapper;
    }
    /**
     * @throws
     * @Title: getQueryWrapper
     * @Description: 查询参数组装
     * @param: @return
     * @return: QueryWrapper<BasDeviceSite>
     */
    public static QueryWrapper<BasDeviceSite> createSingLambdaQueryWrapper(BasDeviceSiteQuery query) {
        QueryWrapper<BasDeviceSite> wrapper = new QueryWrapper<>();
        wrapper.eq(ObjectUtil.isNotNull(query.getId()), "id", query.getId());
        wrapper.eq(ObjectUtil.isNotNull(query.getDeviceId()), "device_id", query.getDeviceId());
        wrapper.like(StrUtil.isNotBlank(query.getName()), "name", query.getName());
        wrapper.eq(ObjectUtil.isNotNull(query.getPointLat()), "point_lat", query.getPointLat());
        wrapper.eq(ObjectUtil.isNotNull(query.getPointLng()), "point_lng", query.getPointLng());
        wrapper.eq(ObjectUtil.isNotNull(query.getStatus()), "status", query.getStatus());
        wrapper.eq(StrUtil.isNotBlank(query.getType()), "type", query.getType());
        wrapper.eq(ObjectUtil.isNotNull(query.getEquipName()), "equip_name", query.getEquipName());
        wrapper.eq(ObjectUtil.isNotNull(query.getFactoryId()), "factory_id", query.getFactoryId());
        wrapper.eq(ObjectUtil.isNotNull(query.getIsStat()), "is_stat", query.getIsStat());
        wrapper.eq(ObjectUtil.isNotNull(query.getNormalValue()), "normal_value", query.getNormalValue());
        wrapper.eq(ObjectUtil.isNotNull(query.getMinValue()), "min_value", query.getMinValue());
        wrapper.eq(ObjectUtil.isNotNull(query.getMinValue()), "mam.is_status", query.getIsStatus());
//        wrapper.like(StrUtil.isNotBlank(query.getDeviceName()), "name", query.getDeviceName());
        wrapper.like(StrUtil.isNotBlank(query.getDeviceType()), "type", query.getDeviceType());
        wrapper.in(CollectionUtil.isNotEmpty(query.getDeviceIds()),"device_id",query.getDeviceIds());
        wrapper.orderByAsc("name", "id");
        return wrapper;
    }

    public static QueryWrapper<BasDeviceSite> createSingLambdaQueryWrapperQiye(BasDeviceSiteQuery query) {
        QueryWrapper<BasDeviceSite> wrapper = new QueryWrapper<>();
        wrapper.eq(ObjectUtil.isNotNull(query.getId()), "id", query.getId());
        wrapper.eq(ObjectUtil.isNotNull(query.getDeviceId()), "device_id", query.getDeviceId());
        wrapper.like(StrUtil.isNotBlank(query.getName()), "name", query.getName());
        wrapper.eq(ObjectUtil.isNotNull(query.getPointLat()), "point_lat", query.getPointLat());
        wrapper.eq(ObjectUtil.isNotNull(query.getPointLng()), "point_lng", query.getPointLng());
        wrapper.eq(ObjectUtil.isNotNull(query.getStatus()), "status", query.getStatus());
        wrapper.eq(ObjectUtil.isNotNull(query.getType()), "type", query.getType());
        wrapper.eq(ObjectUtil.isNotNull(query.getEquipName()), "equip_name", query.getEquipName());
        wrapper.eq(ObjectUtil.isNotNull(query.getFactoryId()), "mam.factory_id", query.getFactoryId());
        wrapper.eq(ObjectUtil.isNotNull(query.getIsStat()), "is_stat", query.getIsStat());
        wrapper.eq(ObjectUtil.isNotNull(query.getNormalValue()), "normal_value", query.getNormalValue());
        wrapper.eq(ObjectUtil.isNotNull(query.getMinValue()), "min_value", query.getMinValue());
        wrapper.eq(ObjectUtil.isNotNull(query.getMinValue()), "mam.is_status", query.getIsStatus());
        wrapper.like(StrUtil.isNotBlank(query.getDeviceName()), "poc.name", query.getDeviceName());
        wrapper.like(StrUtil.isNotBlank(query.getDeviceType()), "poc.type", query.getDeviceType());
        wrapper.orderByAsc("name", "id");
        return wrapper;
    }
}
