/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.youchain.domain;

import com.youchain.base.BaseEntity;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.io.Serializable;

/**
* @website https://eladmin.vip
* @description /
* @author baobl
* @date 2024-09-14
**/
@Entity
@Data
@Table(name="sys_excel_config")
public class ExcelConfig  extends BaseEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "`id`")
    @ApiModelProperty(value = "主键")
    private Long id;

    @Column(name = "`table_name`")
    @ApiModelProperty(value = "table表名")
    private String tableName;

    @Column(name = "`excel_column_name`")
    @ApiModelProperty(value = "Excel列名")
    private String excelColumnName;

    @Column(name = "`table_column_name`")
    @ApiModelProperty(value = "table字段名")
    private String tableColumnName;
    @Column(name = "`dict_name`")
    @ApiModelProperty(value = "关联字典")
    private String dictName;
    @OneToOne
    @JoinColumn(name = "ec_key_id")
    @ApiModelProperty(value = "关联外键")
    private ExcelConfigKey ecKey;
    @Column(name = "`table_column_type`")
    @ApiModelProperty(value = "table字段类型")
    private String tableColumnType;

    @Column(name = "`glb_type`")
    @ApiModelProperty(value = "关联表类型")
    private Integer glbType=0;
    @Column(name = "`only_flag`")
    @ApiModelProperty(value = "唯一标识")
    private Boolean onlyFlag=false;

    @Column(name = "`default_value`")
    @ApiModelProperty(value = "默认值")
    private String defaultValue;

    @Column(name = "`work_type`")
    @ApiModelProperty(value = "导入规则")
    private String workType="1";

    public void copy(ExcelConfig source){
        BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
    }
    public Object getFormat(Object value,String columnType) {
        switch (columnType){
            case "string":
                value="'"+value+"'";
                break;
            case "long":
                value=Long.valueOf(value+"");
                break;
        }
        return value;
    }
}
