package cn.com.ctop.toutiao.entity;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import cn.com.ctop.common.module.entity.CtopOauthToken;
import org.jeecgframework.poi.excel.annotation.Excel;

import java.util.Date;

/**
 * @Description: 头条图片素材信息
 * @Author: jeecg-boot
 * @Date: 2019-07-29
 * @Version: V1.0
 */
@Data
@TableName("ctop_bytedance_image_info")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "ctop_bytedance_image_info对象", description = "头条图片素材信息")
public class ByteDanceImageInfo {

    /**
     * id
     */
    @TableId
    @ApiModelProperty(value = "id")
    private String id;
    /**
     * 文件id
     */
    @Excel(name = "文件id", width = 15)
    @ApiModelProperty(value = "文件id")
    private String fileId;
    /**
     * 头条平台账号id
     */
    @Excel(name = "头条平台账号id", width = 15)
    @ApiModelProperty(value = "头条平台账号id")
    private Long accountId;
    @Excel(name = "平台账号id", width = 15)
    @ApiModelProperty(value = "平台账号id")
    private String advertiserId;

    /**
     * 图片大小
     */
    @Excel(name = "图片大小", width = 15)
    @ApiModelProperty(value = "图片大小")
    private Long size;
    /**
     * 图片宽度
     */
    @Excel(name = "图片宽度", width = 15)
    @ApiModelProperty(value = "图片宽度")
    private Integer width;
    /**
     * 图片高度
     */
    @Excel(name = "图片高度", width = 15)
    @ApiModelProperty(value = "图片高度")
    private Integer height;
    /**
     * 预览地址
     */
    @Excel(name = "预览地址", width = 15)
    @ApiModelProperty(value = "预览地址")
    private String url;
    /**
     * 图片格式
     */
    @Excel(name = "图片格式", width = 15)
    @ApiModelProperty(value = "图片格式")
    private String format;
    /**
     * 图片Md5
     */
    @Excel(name = "图片Md5", width = 15)
    @ApiModelProperty(value = "图片Md5")
    private String signature;
    /**
     * status
     */
    @Excel(name = "status", width = 15)
    @ApiModelProperty(value = "status")
    private Integer status;
    /**
     * createTime
     */
    @ApiModelProperty(value = "createTime")
    private Date createTime;
    /**
     * updateTime
     */
    @ApiModelProperty(value = "updateTime")
    private Date updateTime;

    public ByteDanceImageInfo(JSONObject data, CtopOauthToken token) {
        this.id = data.getString("id");
        this.fileId = id;
        this.accountId = token.getAccountId();
        this.advertiserId = token.getAdvertiserId();
        this.width = data.getInteger("width");
        this.height = data.getInteger("width");
        this.size = data.getLong("size");
        this.url = data.getString("url");
        this.format = data.getString("format");
        this.signature = data.getString("signature");
        this.status = 1;
        Date now = new Date();
        this.createTime = now;
        this.updateTime = now;
    }

    public ByteDanceImageInfo() {

    }
}
