package cn.fateverse.query.entity.dto;

import cn.fateverse.common.core.utils.ObjectUtils;
import cn.fateverse.common.decrypt.annotation.EncryptField;
import cn.fateverse.query.entity.UniColumn;
import cn.fateverse.query.entity.UniCon;
import com.alibaba.fastjson2.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @author Clay
 * @date 2023-08-09
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SqlDto {

    //查询id
    @EncryptField
    @NotBlank(message = "查询id不为空")
    private String queryId;

    //查询语句
    @NotBlank(message = "sql语句不为空")
    private String uniSql;

    private Long menuId;

    //查询条件
    private List<UniCon> uniCons;

    //查询列信息
    private List<UniColumn> uniColumns;

    @JsonIgnore
    @JSONField(serialize = false)
    public Long getLongQueryId() {
        return ObjectUtils.isEmpty(queryId) ? null : Long.valueOf(queryId);
    }
}
