package cn.cecep.talroad.vo.query;

import cn.cecep.talroad.common.core.domain.query.PageQuery;
import cn.cecep.talroad.domain.BasDcsOperationLog;
import cn.cecep.talroad.domain.MAmVideoCoordinateOperationLog;
import cn.cecep.talroad.vo.MAmVideoCoordinateOperationLogQuery;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Date;

/**
 * @className: BasDcsOperationLog
 * @description: TODO 类描述
 * @author: Mr.Yanghongtao
 * @date: 2023/04/28 15:24
 * @Company: Copyright© [2023/04/28 15:24] by [Mr.Yanghongtao]
 **/

/**
 * DCS系统参数设置操作日志
 */
@ApiModel(value = "DCS系统参数设置操作日志query")
@Data
@EqualsAndHashCode(callSuper = false)
public class BasDcsOperationLogQuery extends PageQuery {

    private String logId;
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    private Date operationTime;
    private String workProcedure;
    private String deviceId;
    private String deviceName;
    private String paramName;
    private String beforeModifyParamUnit;
    private String beforeModifyNormalValue;
    private String afterModifyNormalValue;
    private String operator;
    private String operatorId;
    private String factoryId;
    private String afterModifyParamUnit;
    private String beforeModifyMinValue;
    private String afterModifyMinValue;
    private String beforeModifyMaxValue;
    private String afterModifyMaxValue;

    @ApiModelProperty(value = "开始时间")
    private Date startTime;
    @ApiModelProperty(value = "结束时间")
    private Date endTime;

    @ApiModelProperty(value = "操作日志-工序名称")
    private String workStep;
    @ApiModelProperty(value = "操作日志-设备名称")
    private String name;

    public static QueryWrapper<BasDcsOperationLog> createLambdaQueryWrapper(BasDcsOperationLogQuery query) {
        QueryWrapper<BasDcsOperationLog> wrapper = new QueryWrapper<>();

        if (StrUtil.isNotBlank(query.getName())) {
            query.setDeviceName(query.getName());
        }
        if (StrUtil.isNotBlank(query.getWorkStep())) {
            query.setWorkProcedure(query.getWorkStep());
        }

        wrapper.ge(ObjectUtil.isNotNull(query.getStartTime()), "operation_time", query.getStartTime());
        wrapper.le(ObjectUtil.isNotNull(query.getEndTime()), "operation_time", query.getEndTime());
        wrapper.eq(ObjectUtil.isNotNull(query.getDeviceId()), "device_id", query.getDeviceId());
        wrapper.like(StrUtil.isNotBlank(query.getDeviceName()), "device_name", query.getDeviceName());
        wrapper.like(StrUtil.isNotBlank(query.getParamName()), "param_name", query.getParamName());
        wrapper.like(StrUtil.isNotBlank(query.getWorkProcedure()), "work_procedure", query.getWorkProcedure());
        wrapper.orderByDesc("operation_time");
        return wrapper;
    }

}
