YxyUserInfoServiceImpl.java 9.7 KB
package com.espeed.service.impl;
     
import java.util.ArrayList;
import java.util.List;

import com.espeed.centre.pojo.YxyUserInfo;
import com.espeed.dao.CentreLoginDao;
import com.espeed.dao.XLicenceFunDao;
import com.espeed.dao.XMailAccountDao;
import com.espeed.dao.YxyCompanyWebInfoDao;
import com.espeed.dao.YxySysParamatersValueDao;
import com.espeed.dao.YxyUserInfoDao;
import com.espeed.pojo.YxyCompanyWebInfo;
import com.espeed.pojo.YxySysParamatersValue;
import com.espeed.service.YxyUserInfoService;
import com.espeed.tool.Md5Code;
import com.espeed.vo.PageBean;
import com.espeed.webmail.pojo.XLicenceFun;
import com.espeed.webmail.pojo.XMailAccount;

public class YxyUserInfoServiceImpl implements YxyUserInfoService{

	/**查询用户信息*/
	public List<YxyUserInfo> findVerificationUser(String loginid, String domain)throws Exception {
		List<YxyUserInfo> users = new ArrayList<YxyUserInfo>();
		String sql = "select company_id from centre_company where domain = '"+domain+"'";
		List<Object> objects = yxyuserinfodao.findBySqlQuery(sql);
		if(objects.size()>0){
			int company_id = Integer.parseInt(objects.get(0).toString());
			String hql="from YxyUserInfo where login_id='"+loginid+"' and company_id="+company_id; 
			return yxyuserinfodao.findByHql(hql);
		}
		return users;
	}
	
	/**查询所有用户*/
	public List<YxyUserInfo> findByUser(int company_id) throws Exception {
		String hql="from YxyUserInfo where company_id="+company_id;
		return yxyuserinfodao.findByHql(hql);
	}
	
	/**查询所有用户根据域*/
	//public List<YxyUserInfo> findDomainUser(String domain) throws Exception {
	public List<YxyUserInfo> findDomainUser(YxyUserInfo user)throws Exception{
		if(user.getUser_role()==1)//系统管理员
		{
			String hql="from YxyUserInfo where company_id="+user.getCompany_id()+" ORDER BY enrol_time desc";
			return yxyuserinfodao.findByHql(hql);
		}
		else if(user.getUser_role()==2)//部门管理员
		{
			String ids = "";
			//获取子部门
			String sql="select dept_id from centre_department where parent_dept_id = "+user.getDept_id();
			List<Object> objects = yxyuserinfodao.findBySqlQuery(sql);
			if(objects.size() > 0){
				for(Object obj : objects){
					ids += obj.toString() + ",";
				}
				ids += String.valueOf(user.getDept_id());
			}else{
				ids = String.valueOf(user.getDept_id());
			}
			String hql="from YxyUserInfo where company_id="+user.getCompany_id()+" and dept_id in("+ids+") ORDER BY enrol_time desc";
			return yxyuserinfodao.findByHql(hql);
		}
		else
		{
			return new ArrayList<YxyUserInfo>();
		}
		
		//String hql="from YxyUserInfo where companydomain='"+domain+"'";
		//return yxyuserinfodao.findByHql(hql);
	}
	
	/**查询所有用户根据域*/
	//public List<YxyUserInfo> findDomainUser(String domain, PageBean pb)throws Exception {
	public List<YxyUserInfo> findDomainUser(YxyUserInfo user,PageBean pb)throws Exception {
		if(user.getUser_role()==1)//系统管理员
		{
			String hql="from YxyUserInfo where company_id="+user.getCompany_id()+" ORDER BY enrol_time desc";
			String hqlcount="select count(*) from YxyUserInfo where company_id="+user.getCompany_id()+" ORDER BY enrol_time desc";
			return yxyuserinfodao.findByHqlPage(hql, hqlcount, pb);
		}
		else if(user.getUser_role()==2)//部门管理员
		{
			String ids = "";
			//获取子部门
			String sql="select dept_id from centre_department where parent_dept_id = "+user.getDept_id();
			List<Object> objects = yxyuserinfodao.findBySqlQuery(sql);
			if(objects.size() > 0){
				for(Object obj : objects){
					ids += obj.toString() + ",";
				}
				ids += String.valueOf(user.getDept_id());
			}else{
				ids = String.valueOf(user.getDept_id());
			}
			String hql="from YxyUserInfo where company_id="+user.getCompany_id()+" and dept_id in("+ids+") ORDER BY enrol_time desc";
			String hqlcount="select count(*) from YxyUserInfo where company_id="+user.getCompany_id()+" and dept_id in("+ids+") ORDER BY enrol_time desc";
			return yxyuserinfodao.findByHqlPage(hql, hqlcount, pb);
		}
		else
		{
			return new ArrayList<YxyUserInfo>();
		}
	}
	
	/**更新该用户登录时间*/
	public void updateUserLoginDate(String date,String loginid,String domain) throws Exception {
		//String hql="update YxyUserInfo set lastdate='"+date+"' where loginid='"+loginid+"' and companydomain='"+domain+"'"; 
		//yxyuserinfodao.updateByHql(hql);
	}
	
	/**http调用查询用户信息*/
	public YxyUserInfo findHttpInfo(String loginid, String domain, String aip)throws Exception {
		String hql="from YxyUserInfo where  loginid='"+loginid+"' and companydomain='"+domain+"' and domainaip='"+aip+"'";
		List<YxyUserInfo> o=yxyuserinfodao.findByHql(hql);
		if(o.size()>0){
			return o.get(0);
		}else{
			return null;
		}
		
	}
	
	/**实体更新*/
	public void updatePojo(YxyUserInfo o) throws Exception {
		yxyuserinfodao.updatePojo(o);
		
	}
	
	/**开通用户营销*/
	public void updateOpenYxy(String logindid,String domain,String username,
			int ismange,int deptid,int pdeptid,int new_tol_num,int new_month_num,int new_day_num)throws Exception
	{
		//添加用户基本信息
		YxyUserInfo user=new YxyUserInfo();
//		user.setCompanydomain(domain);
//		user.setLoginid(logindid);
//		user.setUsername(username);
//		user.setUserrole(ismange+"");
//		user.setDeptid(deptid);
//		user.setPdeptid(pdeptid);
		yxyuserinfodao.addPojo(user);
		//需要添加的集合
		List<YxySysParamatersValue> paramvaluelist=new ArrayList<YxySysParamatersValue>();
		//添加日发送量
		YxySysParamatersValue daypara=new YxySysParamatersValue();
		daypara.setCompany_domain(domain);
		daypara.setOwner_loginid(logindid);
		daypara.setOwner_type(4);
		daypara.setPara_id(1);
		daypara.setPara_value(new_day_num+"");
		paramvaluelist.add(daypara);
		//添加月发送量
		YxySysParamatersValue monthpara=new YxySysParamatersValue();
		monthpara.setCompany_domain(domain);
		monthpara.setOwner_loginid(logindid);
		monthpara.setOwner_type(4);
		monthpara.setPara_id(2);
		monthpara.setPara_value(new_month_num+"");
		paramvaluelist.add(monthpara);
		//添加总发送量
		YxySysParamatersValue tolpara=new YxySysParamatersValue();
		tolpara.setCompany_domain(domain);
		tolpara.setOwner_loginid(logindid);
		tolpara.setOwner_type(4);
		tolpara.setPara_id(34);
		tolpara.setPara_value(new_tol_num+"");
		paramvaluelist.add(tolpara);
		//添加参数值
		yxysysparamatersvaluedao.addPojoPi(paramvaluelist);
	}
	
	/**更改用户状态*/
	public void updateUserStatus(String loginid,int company_id,int delete_flag)throws Exception
	{
		String hql = "update YxyUserInfo set delete_flag = "+delete_flag+" where login_id = '"+loginid+"' and company_id = "+company_id;
		
		yxyuserinfodao.updateByHql(hql);
	}
	
	/**获取webmail访问路径信息*/
	public List<YxyCompanyWebInfo> findWebmailInfo(String hql)throws Exception
	{
		return yxycompanywebinfodao.findByHql(hql);
	}
	
	/**个人版登录验证*/
	public int findLoginInfo(String loginid,String domain,String password)throws Exception{
		String sql = "select credential from centre_login where identity_type = 11 and identity = '"+loginid+"###"+domain+"'";
		List<Object> objects = yxyuserinfodao.findBySqlQuery(sql);
		if(objects.size()>0){
			String credential = objects.get(0).toString();
			if(password.equals(credential)){
				return 1;//登录成功
			}else{
				return -5;//密码不正确
			}
		}else{
			return -4;//帐号不存在
		}
	}
	
	/**查询企业授权模块信息*/
	public List<XLicenceFun> getCompanyLicences(String hql)throws Exception{
		return xlicencefundao.findByHql(hql);
	}
	
	/**修改用户密码*/
	public void updateUserPassword(int user_id,String password)throws Exception{
		password = Md5Code.createMd5(password);
		String hql = "update CentreLogin set credential = '"+password+"' where identity_type = 11 and user_id = "+user_id;
		centrelogindao.updateByHql(hql);
	}
	
	/**验证用户密码*/
	public int verifyUserPassword(int user_id,String password)throws Exception{
		password = Md5Code.createMd5(password);
		String hql = "select count(*) from CentreLogin where identity_type = 11 and user_id = "+user_id+" and credential = '"+password+"'";
		int counts = centrelogindao.findByHqlCount(hql);
		if(counts > 0){//密码正确
			return 1;
		}else{//密码不正确
			return 0;
		}
	}
	
	/**查询用户邮箱*/
	public List<XMailAccount> findUserAccountByHql(String hql)throws Exception{
		return xmailaccountdao.findByHql(hql);
	}
	
	private YxyUserInfoDao yxyuserinfodao;
	private YxySysParamatersValueDao yxysysparamatersvaluedao;
	private YxyCompanyWebInfoDao yxycompanywebinfodao;
	private XLicenceFunDao xlicencefundao;
	private CentreLoginDao centrelogindao;
	private XMailAccountDao xmailaccountdao;//邮箱帐号dao
	public YxyUserInfoDao getYxyuserinfodao() {
		return yxyuserinfodao;
	}
	public void setYxyuserinfodao(YxyUserInfoDao yxyuserinfodao) {
		this.yxyuserinfodao = yxyuserinfodao;
	}
	public YxySysParamatersValueDao getYxysysparamatersvaluedao() {
		return yxysysparamatersvaluedao;
	}
	public void setYxysysparamatersvaluedao(
			YxySysParamatersValueDao yxysysparamatersvaluedao) {
		this.yxysysparamatersvaluedao = yxysysparamatersvaluedao;
	}
	public YxyCompanyWebInfoDao getYxycompanywebinfodao() {
		return yxycompanywebinfodao;
	}
	public void setYxycompanywebinfodao(YxyCompanyWebInfoDao yxycompanywebinfodao) {
		this.yxycompanywebinfodao = yxycompanywebinfodao;
	}
	public XLicenceFunDao getXlicencefundao() {
		return xlicencefundao;
	}
	public void setXlicencefundao(XLicenceFunDao xlicencefundao) {
		this.xlicencefundao = xlicencefundao;
	}
	public CentreLoginDao getCentrelogindao() {
		return centrelogindao;
	}
	public void setCentrelogindao(CentreLoginDao centrelogindao) {
		this.centrelogindao = centrelogindao;
	}
	public XMailAccountDao getXmailaccountdao() {
		return xmailaccountdao;
	}
	public void setXmailaccountdao(XMailAccountDao xmailaccountdao) {
		this.xmailaccountdao = xmailaccountdao;
	}
}