package cn.cecep.talroad.vo.query;

import cn.cecep.talroad.common.core.domain.query.PageQuery;
import cn.cecep.talroad.common.core.utils.DateUtils;
import cn.cecep.talroad.domain.MonElecReal;
import cn.cecep.talroad.vo.AmProblemFiVo;
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 org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;

import java.util.List;


/**
 * 分表计电设备-点位对应 设备与点位为多对多的关系对象 mon_elec_real
 *
 * @author szhpt
 * @date 2023-01-10*/
@ApiModel(value = "分表计电设备-点位对应 设备与点位为多对多的关系")
@EqualsAndHashCode(callSuper = false)
@Data
public class MonElecRealQuery extends PageQuery
{

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

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

    @ApiModelProperty(value = "点位ID")
    private String deviceSiteId;

    @ApiModelProperty(value = "点位ID列表")
    private List<String> deviceSiteIds;

    @ApiModelProperty(value = "时间类型 枚举。总为“实时”")
    private String timeType;

    @ApiModelProperty(value = "数据时间开始")
    private String dataTimeStart;

    @ApiModelProperty(value = "数据时间结束")
    private String dataTimeEnd;

    @ApiModelProperty(value = "时间排序 正序:asc, 倒序:desc")
    private String timeSortType;

    @ApiModelProperty(value = "曲线图返回指定的参数")
    private List<AmProblemFiVo.PollutantVo> pollutantVos;

    /**
     *
     * @Title: getQueryWrapper
     * @Description: 查询参数组装
     * @param: @return
     * @return: QueryWrapper<BasIndustry>
     * @throws
     */
    public static QueryWrapper<MonElecReal> createLambdaQueryWrapper(MonElecRealQuery query) {
        QueryWrapper<MonElecReal> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(query.getDataTimeStart())) {
            wrapper.ge("data_time", DateUtils.parseDate(query.getDataTimeStart()));
        }
        if (StringUtils.isNotEmpty(query.getDataTimeEnd())) {
            wrapper.le("data_time", DateUtils.parseDate(query.getDataTimeEnd()));
        }

        wrapper.eq(StringUtils.isNotEmpty(query.getDeviceSiteId()), "device_site_id", query.getDeviceSiteId());
        wrapper.in(!CollectionUtils.isEmpty(query.getDeviceSiteIds()), "device_site_id", query.getDeviceSiteIds());

        if ("asc".equals(query.getTimeSortType())) {
            wrapper.orderByAsc("data_time");
        } else {
            wrapper.orderByDesc("data_time");
        }
        return wrapper;
    }
}
