首页>代码>java lucene实现近实时搜索及高亮显示的代码例子下载>/message5_1/src/org/itat/message/dao/AttachmentDao.java
package org.itat.message.dao;


import java.io.File;
import java.util.List;

import javax.annotation.Resource;

import org.itat.message.idao.IAttachmentDao;
import org.itat.message.iservice.IIndexService;
import org.itat.message.util.IndexUtil;
import org.itat.message.util.SystemContext;
import org.itat.message.vo.Attachment;
import org.springframework.stereotype.Repository;

@Repository("attachmentDao")
public class AttachmentDao extends BaseDao<Attachment> implements
		IAttachmentDao{
	
	private IIndexService indexService;
	
	public IIndexService getIndexService() {
		return indexService;
	}
	@Resource
	public void setIndexService(IIndexService indexService) {
		this.indexService = indexService;
	}

	public void deletbyMsg(int msgId) {
		deleteFile(msgId);
		super.updateByHql("delete a from Attachment a where a.message=?",msgId);
	}
	
	/**
	 * 删除附件的文件
	 */
	@SuppressWarnings("unchecked")
	private void deleteFile(int msgId) {
		List<Object[]> files = this.getSession()
			.createQuery("select id,newName,message.id from Attachment where message.id=?")
			.setParameter(0, msgId).list();
		String realPath = SystemContext.getRealPath()+"/upload/";
		for(Object[] fn:files) {
			File f = new File(realPath+fn[1]);
			String id = fn[2]+"_"+fn[0];
			indexService.deleteIndex(id,IndexUtil.ATTACHMENT_TYPE);
			f.delete();
		}
								
	}

	@Override
	public void deletebyId(int id) {
		Attachment attachment = load(id);
		delete(attachment);
	}

	@Override
	public boolean delByObj(Attachment t) {
		String realPath = SystemContext.getRealPath()+"/upload/";
		File f = new File(realPath+t.getNewName());
		boolean b = f.delete();
		if(b) delete(t);
		return b;
	}
	@Override
	public List<Attachment> listByMessage(int msgId) {
		return this.list("select a from Attachment a left join fetch a.message m where m.id=?",msgId);
	}
}
最近下载更多
813405250  LV5 2021年1月2日
Sillage  LV3 2020年6月1日
全国12345  LV3 2020年5月17日
cbl234  LV1 2020年4月10日
shenshenya  LV2 2019年5月26日
执笔写下青春  LV12 2018年6月19日
mahuig  LV10 2018年4月18日
lindawhn  LV6 2018年4月12日
fengzf  LV16 2018年1月12日
ypf8312  LV22 2017年9月7日
最近浏览更多
zjut_ywf 2023年11月13日
暂无贡献等级
jy1218  LV12 2023年2月16日
cfdymyj 2022年10月8日
暂无贡献等级
BestClever  LV32 2022年6月15日
dongzhan  LV12 2021年12月16日
dongzhan  LV12 2021年12月16日
lirui9900  LV1 2021年11月16日
西凉河的葛三叔  LV3 2021年8月28日
shion994  LV6 2021年5月18日
lodddy  LV6 2021年5月4日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友