Attachment

来源:互联网 发布:淘宝省市区街道联动js 编辑:程序博客网 时间:2024/05/01 10:33
/**
 * 
 */
package com.et.common.system.domain;


import static javax.persistence.GenerationType.SEQUENCE;


import java.util.Date;
import java.util.UUID;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


import org.hibernate.annotations.Type;


import com.etong.common.system.domain.base.LongIdEntity;


/**
* @version 1.0
 */
@Entity
@Table(name="SYS_ATTACHMENTS"/*, schema="UAWP"*/)
public class Attachment extends LongIdEntity {

private static final long serialVersionUID = -6427159624515315135L;

public static final String DEFAULT_CONTENT_TYPE = "application/x-msdownload";

private String objectType;//所属对象类型(63)
private String objectId;//所属对象ID(32)
private int order;//顺序号

private String name;//附件名称(127)
private String suffix;//后缀(8)
private String path;//存储路径(255)
private String contentType;//内容类型(32)   planarGraph:泵站平面图

private String creator;//创建者
private String creatorId;//创建者ID
private Date createDate;//创建时间

private boolean compressed;//是否压缩
private boolean encrypted;//是否加密

/**
* 创建一个默认的附件对象。
*/
public Attachment() {

}

/**
* 根据附件配置和文件名创建一个附件对象。
* @param config
* @param fileName
*/
public Attachment(AttachmentConfig config, String fileName) {
this.compressed = config.isCompressed();
this.encrypted = config.isEncrypted();
int dot = fileName.lastIndexOf('.');
this.name = fileName.substring(0, dot);
this.suffix = fileName.substring(dot);
this.contentType = DEFAULT_CONTENT_TYPE;
String path = config.getDirectory() + UUID.randomUUID() + suffix;
if(this.encrypted) {
path += ".enc";
} else if(this.compressed){
path += ".zip";
}
this.path = path;
}


@Id
@SequenceGenerator(name="seq_attach", sequenceName="seq_attach")
    @GeneratedValue(strategy=SEQUENCE, generator="seq_attach")
public Long getId() {
return id;
}

/**
* @return the objectType
*/
@Column(length=63)
public String getObjectType() {
return objectType;
}

/**
* @param objectType the objectType to set
*/
public void setObjectType(String objectType) {
this.objectType = objectType;
}

/**
* @return the objectId
*/
@Column(length=32)
public String getObjectId() {
return objectId;
}

/**
* @param objectId the objectId to set
*/
public void setObjectId(String objectId) {
this.objectId = objectId;
}

/**
* @return the order
*/
public int getOrder() {
return order;
}

/**
* @param order the order to set
*/
public void setOrder(int order) {
this.order = order;
}

/**
* @return the name
*/
@Column(length=127)
public String getName() {
return name;
}

/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}

/**
* @return the suffix
*/
@Column(length=8)
public String getSuffix() {
return suffix;
}

/**
* @param suffix the suffix to set
*/
public void setSuffix(String suffix) {
this.suffix = suffix;
}

/**
* @return the path
*/
@Column(length=255)
public String getPath() {
return path;
}

/**
* @param path the path to set
*/
public void setPath(String path) {
this.path = path;
}
/**
* @return the contentType
*/
@Column(length=32)
public String getContentType() {
return contentType;
}

/**
* @param contentType the contentType to set
*/
public void setContentType(String contentType) {
this.contentType = contentType;
}

/**
* @return the creator
*/
@Column(length=16)
public String getCreator() {
return creator;
}

/**
* @param creator the creator to set
*/
public void setCreator(String creator) {
this.creator = creator;
}

/**
* @return the creatorId
*/
@Column(length=32)
public String getCreatorId() {
return creatorId;
}


/**
* @param creatorId the creatorId to set
*/
public void setCreatorId(String creatorId) {
this.creatorId = creatorId;
}


/**
* @return the createDate
*/
@Temporal(TemporalType.TIMESTAMP)
public Date getCreateDate() {
return createDate;
}

/**
* @param createDate the createDate to set
*/
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}


/**
* @return the compressed
*/
@Type(type="true_false")
public boolean isCompressed() {
return compressed;
}


/**
* @param compressed the compressed to set
*/
public void setCompressed(boolean compressed) {
this.compressed = compressed;
}


/**
* @return the encrypted
*/
@Type(type="true_false")
public boolean isEncrypted() {
return encrypted;
}


/**
* @param encrypted the encrypted to set
*/
public void setEncrypted(boolean encrypted) {
this.encrypted = encrypted;
}

}
0 0
原创粉丝点击