/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package cn.com.liandisys.ycjt.ggcx.admin.model.cms;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.google.common.collect.Lists;

import cn.com.liandisys.ycjt.ggcx.admin.model.User;
import cn.com.liandisys.ycjt.ggcx.admin.utils.CmsUtils;

/**
 * 文章实体
 * @author jiangchao
 * @version 2016-11-29
 */
@Entity
@Table(name = "CMS_ARTICLE")
public class Article implements Serializable {

    public static final String DEFAULT_TEMPLATE = "frontViewArticle";
    public static final String DEL_FLAG_NORMAL = "1";
	
	private static final long serialVersionUID = 1L;
	private String id;// 实体编号（唯一标识）
	private Category category;// 分类编号
	private String title;	// 标题
    private String link;	// 外部链接
	private String color;	// 标题颜色（red：红色；green：绿色；blue：蓝色；yellow：黄色；orange：橙色）
	private String image;	// 文章图片
	private String keywords;// 关键字
	private String description;// 描述、摘要
	private Integer weight;	// 权重，越大越靠前
	@DateTimeFormat(pattern = "yyyy/MM/dd")
	@JsonFormat(pattern = "yyyy/MM/dd")
	private Date weightDate;// 权重期限，超过期限，将weight设置为0
	private Integer hits;	// 点击数
	private String posid;	// 推荐位，多选（1：首页焦点图；2：栏目页文章推荐；）
    private String customContentView;	// 自定义内容视图
   	private String viewConfig;	// 视图参数
	private User createBy;	// 创建者
	//@DateTimeFormat(pattern = "yyyy/MM/dd HH:mm:ss")
	//@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss")
	private Date createDate;	// 创建日期
	private User updateBy;	// 更新者
	@DateTimeFormat(pattern = "yyyy/MM/dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss")
	private Date updateDate;	// 更新日期
	private String remarks;	// 备注
	private String delFlag; 	// 删除标记（0：正常；1：删除；2：审核）
	private ArticleData articleData;	//文章副表
	
	private String appIndexView; //在APP首页模块显示(1:显示，0:不显示)
	private String appInfoView;  //在APP资讯模块显示(1:显示，0:不显示)
	private String appIndexViewYcjt; //在盐城交通APP首页模块显示(1:显示，0:不显示)
	private String appInfoViewYcjt;  //在盐城交通APP资讯模块显示(1:显示，0:不显示)
	private String publisher; // 文章中显示的发布者姓名
	private String files; // 附件存储路径
	private String publisheDate;
	



	@Id
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
    @Column(name="id")
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	@ManyToOne(fetch = FetchType.EAGER, targetEntity = Category.class)
	@JoinColumn(name = "category_id")
	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}
	
	@Column
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	@Column
	public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }
    
    @Column
    public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}
	
	@Column
	public String getImage() {
		return image;
	}

	public void setImage(String image) {
        this.image = image;
	}
	
	@Column
	public String getKeywords() {
		return keywords;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}
	
	@Column
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	@Column
	public Integer getWeight() {
		return weight;
	}

	public void setWeight(Integer weight) {
		this.weight = weight;
	}
	
	@Column
	public Date getWeightDate() {
		return weightDate;
	}

	public void setWeightDate(Date weightDate) {
		this.weightDate = weightDate;
	}
	
	@Column
	public Integer getHits() {
		return hits;
	}

	public void setHits(Integer hits) {
		this.hits = hits;
	}

	@Column
	public String getPosid() {
		return posid;
	}

	public void setPosid(String posid) {
		this.posid = posid;
	}
	
	@Column
	public String getCustomContentView() {
        return customContentView;
    }

    public void setCustomContentView(String customContentView) {
        this.customContentView = customContentView;
    }

    @Column
    public String getViewConfig() {
        return viewConfig;
    }

    public void setViewConfig(String viewConfig) {
        this.viewConfig = viewConfig;
    }
    
    @ManyToOne(fetch = FetchType.EAGER, targetEntity = User.class)
	@JoinColumn(name = "create_by")
    public User getCreateBy() {
		return createBy;
	}

	public void setCreateBy(User createBy) {
		this.createBy = createBy;
	}

	@Column
	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	@ManyToOne(fetch = FetchType.EAGER, targetEntity = User.class)
	@JoinColumn(name = "update_by")
	public User getUpdateBy() {
		return updateBy;
	}

	public void setUpdateBy(User updateBy) {
		this.updateBy = updateBy;
	}

	@Column
	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}
	
	@Column
	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	@Column
	public String getDelFlag() {
		return delFlag;
	}

	public void setDelFlag(String delFlag) {
		this.delFlag = delFlag;
	}
	
	@Column
	public String getAppIndexView() {
		return appIndexView;
	}

	public void setAppIndexView(String appIndexView) {
		this.appIndexView = appIndexView;
	}
	
	@Column
	public String getAppInfoView() {
		return appInfoView;
	}

	public void setAppInfoView(String appInfoView) {
		this.appInfoView = appInfoView;
	}
	
	@Column
	public String getAppIndexViewYcjt() {
		return appIndexViewYcjt;
	}

	public void setAppIndexViewYcjt(String appIndexViewYcjt) {
		this.appIndexViewYcjt = appIndexViewYcjt;
	}
	
	@Column
	public String getAppInfoViewYcjt() {
		return appInfoViewYcjt;
	}

	public void setAppInfoViewYcjt(String appInfoViewYcjt) {
		this.appInfoViewYcjt = appInfoViewYcjt;
	}
	
	
	@Column
	public String getPublisher() {
		return publisher;
	}

	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}
	
	@Column
	public String getFiles() {
		return files;
	}

	public void setFiles(String files) {
		this.files = files;
	}
	
	@Column
	public String getPublisheDate() {
		return publisheDate;
	}

	public void setPublisheDate(String publisheDate) {
		this.publisheDate = publisheDate;
	}
	
	@OneToOne(fetch = FetchType.EAGER, targetEntity = ArticleData.class)
	@JoinColumn(name = "data_id")
	public ArticleData getArticleData() {
		return articleData;
	}

	public void setArticleData(ArticleData articleData) {
		this.articleData = articleData;
	}

	public Article() {
		super();
		this.weight = 0;
		this.hits = 0;
		this.posid = "";
	}

	public Article(String id){
		this();
		this.id = id;
	}
	
	public Article(Category category){
		this();
		this.category = category;
	}

	@Transient
	public List<String> getPosidList() {
		List<String> list = Lists.newArrayList();
		if (posid != null){
			for (String s : StringUtils.split(posid, ",")) {
				list.add(s);
			}
		}
		return list;
	}

	public void setPosidList(List<String> list) {
		posid = ","+StringUtils.join(list, ",")+",";
	}

	@Transient
   	public String getUrl() {
        return CmsUtils.getUrlDynamic(this);
   	}

	@Transient
   	public String getImageSrc() {
        return CmsUtils.formatImageSrcToWeb(this.image);
   	}
	
}


