dd5c9638d0be697ad306d93cbc9bce8f44a2756b.svn-base 5.2 KB
package com.espeed.service.impl;
 
import java.util.ArrayList;
import java.util.List;

import com.espeed.dao.YxyMailFolderDao;
import com.espeed.dao.YxySendMailMasterBaseDao;
import com.espeed.dao.YxyUserAddressDao;
import com.espeed.pojo.YxyMailFolder;
import com.espeed.service.YxyMailFolderService;

public class YxyMailFolderServiceImpl implements YxyMailFolderService{

	/**查询所有类别*/
	public List<YxyMailFolder> findFolderAll(String loginid, String domain)throws Exception {
		String hql="from YxyMailFolder where user_loginid='"+loginid+"' and company_domain='"+domain+"' order by create_timer desc";
		List<YxyMailFolder> typelist=yxymailfolderdao.findByHql(hql);
		//查询各类别下的地址量
		String sql="select user_addr_type_id,count(*) from yxy_user_address where user_loginid='"+loginid+"' and user_domain='"+domain+"' GROUP by user_addr_type_id";
		List<Object> list=yxyuseraddressdao.findBySqlQuery(sql);
		//遍历集合赋值
		for(int i=0;i<list.size();i++){
			Object [] obj=(Object[]) list.get(i);
			int count=Integer.parseInt(obj[1].toString());
			int typeid=Integer.parseInt(obj[0].toString());
			for(int j=0;j<typelist.size();j++){
				int id=typelist.get(j).getFolder_id();
				if(typeid==id){
					typelist.get(j).setEmailnun(count);
					break;
				}
			}
		}
		return yxymailfolderdao.findByHql(hql);
	}
	
	
	/**查询本地分类中是否含有地址*/
	public List<YxyMailFolder> findFolderAddr(String loginid, String domain) throws Exception {
		//先到分类中进行查找
		String hql="from YxyMailFolder where user_loginid='"+loginid+"' and company_domain='"+domain+"' order by create_timer desc";
		List<YxyMailFolder> mailFolders = yxymailfolderdao.findByHql(hql);
		List<YxyMailFolder> temp = new ArrayList<YxyMailFolder>();
	
		//查询各类别下的地址量
		String sql="select user_addr_type_id,count(*) from yxy_user_address where user_loginid='"+loginid+"' and user_domain='"+domain+"' GROUP by user_addr_type_id";
		List<Object> list=yxyuseraddressdao.findBySqlQuery(sql);
		//遍历集合赋值
		for(int i=0;i<list.size();i++){
			Object [] obj=(Object[]) list.get(i);
			int count=Integer.parseInt(obj[1].toString());
			int typeid=Integer.parseInt(obj[0].toString());
			for(int j=0;j<mailFolders.size();j++){
				if(mailFolders.get(j).getFolder_id() == typeid){
					if(count > 0 ){
						mailFolders.get(j).setEmailnun(count);
						temp.add(mailFolders.get(j));
					}
				}
			}
		}
		return temp;
	}
	
	
	
	
	
	
	
	/**查询类别名称是否存在*/
	public int findIsExits(String loginid, String domain, String typename)throws Exception {
		String hql="from YxyMailFolder where user_loginid='"+loginid+"' and company_domain='"+domain+"' and folder_name='"+typename+"'";
		List<YxyMailFolder> list=yxymailfolderdao.findByHql(hql);
		if(list.size()>0){
			return 0;
		}else{
			return 1;
		}
	}
	
	/**删除文件类别*/
	public void delUserFolder(int typeid,int deltype)throws Exception {
		String hql="delete YxyMailFolder where folder_id="+typeid;
		yxymailfolderdao.updateByHql(hql);
		if(deltype==1){
			//删除该类别下的地址
			String hql1="delete YxyUserAddress where user_addr_type_id="+typeid;
			yxyuseraddressdao.updateByHql(hql1);
			//类别下的邮件
			String hql2="delete YxySendMailMasterBase where has_classify="+typeid;
			yxysendmailmasterbasedao.updateByHql(hql2);
		}else{
			//修改为默认
			String hql1="update YxyUserAddress set user_addr_type_id=0 where user_addr_type_id="+typeid;
			yxyuseraddressdao.updateByHql(hql1);
			
			String hql2="update YxySendMailMasterBase set has_classify=0 where has_classify="+typeid;
			yxysendmailmasterbasedao.updateByHql(hql2);
		}
		
	}
	
	/**添加文件类别*/
	public void addUserFolder(YxyMailFolder o) throws Exception {
		yxymailfolderdao.addPojo(o);
	}
	
	/**编辑类别*/
	public void editUserFolder(int typeid,String foldername) throws Exception{
		String hql="update YxyMailFolder set folder_name='"+foldername+"' where folder_id="+typeid;
		yxymailfolderdao.updateByHql(hql);
	}
	
	/**清空类别下的数据*/
	public void delTypeData(int typeid) throws Exception {
		//删除该类别下的地址
		String hql1="delete YxyUserAddress where user_addr_type_id="+typeid;
		yxyuseraddressdao.updateByHql(hql1);
		//类别下的邮件
		String hql2="delete YxySendMailMasterBase where has_classify="+typeid;
		yxysendmailmasterbasedao.updateByHql(hql2);
	}
	
	private YxyMailFolderDao yxymailfolderdao;//文件类别dao
	private YxySendMailMasterBaseDao yxysendmailmasterbasedao;//邮件信息dao
	private YxyUserAddressDao yxyuseraddressdao;//地址dao
	
	
	public YxyMailFolderDao getYxymailfolderdao() {
		return yxymailfolderdao;
	}

	public void setYxymailfolderdao(YxyMailFolderDao yxymailfolderdao) {
		this.yxymailfolderdao = yxymailfolderdao;
	}
	public YxySendMailMasterBaseDao getYxysendmailmasterbasedao() {
		return yxysendmailmasterbasedao;
	}
	public void setYxysendmailmasterbasedao(
			YxySendMailMasterBaseDao yxysendmailmasterbasedao) {
		this.yxysendmailmasterbasedao = yxysendmailmasterbasedao;
	}
	public YxyUserAddressDao getYxyuseraddressdao() {
		return yxyuseraddressdao;
	}
	public void setYxyuseraddressdao(YxyUserAddressDao yxyuseraddressdao) {
		this.yxyuseraddressdao = yxyuseraddressdao;
	}

	
	
	
}