package com.sys.bus.file.service;

import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.sys.bus.file.model.Attachment;

import java.util.List;

public class AttachmentService {
	private static final Attachment dao = new Attachment().dao();
	/**
	 * 保存附件
	 * @param attachment
	 */
	@Before(Tx.class)
	public void save(Attachment attachment) {
		attachment.save();
	}
	/**
	 * 根据id删除附件  
	 */
	@Before(Tx.class)
	public void deleteAttachmentById(String id) {
		dao.deleteById(id);
	}
	/**
	 * 根据relationId展示所有附件
	 */
	public List<Attachment> listByRelationId (String id) {
		String sql =   "select * from ct_jx_attachment where attachment_relationId = '"+id+"' order by attachment_createTime asc";
		return dao.find(sql);
	}
	
	
	public Attachment getByAttachmentId(String id){
		return dao.findById(id);
	}
}
