package com.xxl.job.executor.material.entity;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.xxl.job.executor.common.entity.CtopOauthToken;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * 头条图片素材
 * @author jeecg-boot
 * @date   2020-08-01
 * @version V1.0
 */
@Data
@TableName("ctop_bytedance_image_info")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class BytedanceImageInfo {

	/**id*/
	@TableId
	private String id;
	/**头条平台账号id*/
	private Long accountId;
	/**advertiserId*/
	private Long materialId;
	/**图片大小*/
	private Long size;
	/**图片宽度*/
	private Long width;
	/**图片高度*/
	private Long height;
	/**预览地址*/
	private String url;
	private String imageUrl;
	/**图片格式*/
	private String format;
	/**图片Md5*/
	private String signature;
	private String imageCreateTime;
	private String fileName;
	/**createTime*/
	private Date createTime;
	/**updateTime*/
	private Date updateTime;
    private Integer type;

	public BytedanceImageInfo(JSONObject dataObject, CtopOauthToken token) {
		String id = dataObject.getString("id");
		if(null!=id&&id.contains("web")){
			this.imageUrl = "https://sf6-ttcdn-tos.pstatp.com/obj/"+id;
		}else{
			this.imageUrl = "https://sf6-ttcdn-tos.pstatp.com/obj/mosaic-legacy/"+id;
		}
		this.id = dataObject.getString("id");
		this.accountId = token.getAccountId();
		this.materialId = dataObject.getLong("material_id");
		this.size = dataObject.getLong("size");
		this.width = dataObject.getLong("width");
		this.height = dataObject.getLong("height");
		this.url = dataObject.getString("url");
		this.format = dataObject.getString("format");
		this.signature = dataObject.getString("signature");
		this.imageCreateTime = dataObject.getString("create_time");
		this.fileName = dataObject.getString("filename");
		this.createTime = new Date();
		this.updateTime = new Date();
	}

	public BytedanceImageInfo() {
	}
}
