package cn.cecep.talroad.vo.query;

import cn.cecep.talroad.common.core.domain.query.PageQuery;
import cn.cecep.talroad.common.core.utils.StringUtils;
import cn.cecep.talroad.domain.AmVideoDevFi;
import com.baomidou.mybatisplus.annotation.TableField;
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 java.util.Arrays;
import java.util.List;


/**
 * 视频监控对象 m_am_video_dev_fi
 *
 * @author szhpt
 * @date 2023-01-10*/
@ApiModel(value = "视频监控")
@EqualsAndHashCode(callSuper = false)
@Data
public class AmVideoDevFiQuery extends PageQuery
{

    @ApiModelProperty(value = "主键id")
    private String id;

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

    private String outletId;

    @ApiModelProperty("对应排污许可行业")
    private String industry;

    @ApiModelProperty("对应排污许可生产设施名称")
    private String deviceName;

    @ApiModelProperty("对应排污许可生产设施编号")
    private String deviceCode;

    @ApiModelProperty(value = "视频通道ID")
    private String channelId;

    @ApiModelProperty(value = "视频监测点位名称")
    private String devName;

    @ApiModelProperty("站房id")
    private String stationBuildingId;


    @ApiModelProperty("设备id")
    private String deviceId;

    @ApiModelProperty("设备来源 1:GB28181, 2:污染源动态管控")
    private List<String> devSource;

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

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

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

    /**
     *
     * @Title: getQueryWrapper
     * @Description: 查询参数组装
     * @param: @return
     * @return: QueryWrapper<BasIndustry>
     * @throws
     */
    public static QueryWrapper<AmVideoDevFi> createLambdaQueryWrapper(AmVideoDevFiQuery query) {
        QueryWrapper<AmVideoDevFi> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotEmpty(query.getId()), "id", query.getId());
        wrapper.eq(StringUtils.isNotEmpty(query.getFactoryId()), "factory_id", query.getFactoryId());
        wrapper.eq(StringUtils.isNotEmpty(query.getOutletId()), "outlet_id", query.getOutletId());
        wrapper.like(StringUtils.isNotEmpty(query.getDevName()), "dev_name", query.getDevName());
        wrapper.like(StringUtils.isNotEmpty(query.getDeviceName()), "deviceName", query.getDeviceName());
        wrapper.eq(StringUtils.isNotEmpty(query.getStationBuildingId()), "station_building_id", query.getStationBuildingId());

        // 若未指定则查询1和2的
        if (query.getDevSource() == null || query.getDevSource().isEmpty()) {
            wrapper.in( "dev_source", Arrays.asList("1", "2"));
        } else {
            wrapper.in( "dev_source", query.getDevSource());
        }

        wrapper.orderByAsc("status", "id");
        return wrapper;
    }

    public static QueryWrapper<AmVideoDevFi> createLambdaQueryWrapperFactory(AmVideoDevFiQuery query) {
        QueryWrapper<AmVideoDevFi> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotEmpty(query.getId()), "mam.id", query.getId());
        wrapper.eq(StringUtils.isNotEmpty(query.getFactoryId()), "mam.factory_id", query.getFactoryId());
        wrapper.like(StringUtils.isNotEmpty(query.getChannelId()), "mam.channel_id", query.getChannelId());
        wrapper.like(StringUtils.isNotEmpty(query.getDeviceCode()), "poc.pollutant_code", query.getDeviceCode());
        wrapper.like(StringUtils.isNotEmpty(query.getDeviceName()), "poc.pollutant_name", query.getDeviceName());
        wrapper.like(StringUtils.isNotEmpty(query.getDevName()), "mam.dev_name", query.getDevName());
        wrapper.eq(StringUtils.isNotEmpty(query.getStationBuildingId()), "station_building_id", query.getStationBuildingId());

        // 若未指定则查询1和2的
        if (query.getDevSource() == null || query.getDevSource().isEmpty()) {
            wrapper.in( "dev_source", Arrays.asList("1", "2"));
        } else {
            wrapper.in( "dev_source", query.getDevSource());
        }

        wrapper.orderByAsc("mam.status", "mam.id");
        return wrapper;
    }
    public static QueryWrapper<AmVideoDevFi> createLambdaQueryWrapperXK(AmVideoDevFiQuery query) {
        QueryWrapper<AmVideoDevFi> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotEmpty(query.getFactoryId()), "poc.factory_id", query.getFactoryId());
        wrapper.eq(StringUtils.isNotEmpty(query.getIndustry()), "poc.industry", query.getIndustry());
        wrapper.like(StringUtils.isNotEmpty(query.getDeviceCode()), "poc.pollutant_code", query.getDeviceCode());
        wrapper.like(StringUtils.isNotEmpty(query.getDeviceName()), "poc.pollutant_name", query.getDeviceName());
        return wrapper;
    }
}
