relationmanagedaoimpl.java

来自「基于Sturts+Spring+Hibernate的一个高级销售管理系统。内容丰」· Java 代码 · 共 135 行

JAVA
135
字号
package com.yuanchung.sales.dao;

import java.util.Date;
import java.util.List;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.yuanchung.sales.config.ClassCodeMgr;
import com.yuanchung.sales.exception.ApplicationException;
import com.yuanchung.sales.exception.SystemException;
import com.yuanchung.sales.model.user.User;
import com.yuanchung.sales.util.Constants;
import com.yuanchung.sales.util.DateTimeTool;

public class RelationManageDAOImpl extends HibernateDaoSupport implements RelationManageDAO {

	/**
	 * 根据相关项的ID和记录查找任务
	 */
	public List getActivityRasksByRelation(String relationId, int recordId, int executeState) throws SystemException {
		try{
			//任务已完成
			StringBuffer hql = new StringBuffer();
			hql.append("from "+ClassCodeMgr.ACTIVITYRASK);
			hql.append(" where flag=1 and functionId=?");
			hql.append(" and recordId=?");
			//若任务未完成
			if(executeState != Constants.RASKEXECUTEED) {				
				hql.append(" and executeState!=?");
			}else{
				hql.append(" and executeState=?");
			}
			hql.append("order by beFirst");//按优先级的升序排列
			return getHibernateTemplate().find(hql.toString(), new Object[]{relationId, recordId, Constants.RASKEXECUTEED});	
		}catch(Exception e){
			e.printStackTrace();
			logger.error(Constants.DATABASEFINDDATAEXCEPTION);
			throw new SystemException(Constants.DATABASEFINDDATAEXCEPTION);
		}	
	}

	/**
	 * 根据两个参数搜索该参数对象两个表;
	 */
	public List getEventByRelation(String relationId, int recordId, boolean isNotOverdue)
			throws SystemException {
		try{			
			StringBuffer hql = new StringBuffer();
			hql.append("from "+ClassCodeMgr.EVENT);
			hql.append(" where flag=1 and functionId=?");
			hql.append(" and recordId=?");		
			
			if(isNotOverdue) {//若事件不过期	
				hql.append("and endTime >= '"+DateTimeTool.dateToStrFormat("", new Date())+"'");
			}else{
				hql.append("and endTime < '"+DateTimeTool.dateToStrFormat("", new Date())+"'");
			}
			hql.append("order by endTime");//按结束时间的升序排列
			return getHibernateTemplate().find(hql.toString(), new Object[]{relationId, recordId});	
		}catch(Exception e){
			e.printStackTrace();
			logger.error(Constants.DATABASEFINDDATAEXCEPTION);
			throw new SystemException(Constants.DATABASEFINDDATAEXCEPTION);
		}
	}
	/**
	 * 活动--->任务	根据联系人ID和执行状态查找任务
	 * @param contactId联系人ID
	 * @param executeState执行状态
	 * @return
	 * @throws ApplicationException
	 */
	public List getActivityRasks(int contactId, int executeState) throws SystemException {
		try{
			//任务已完成
			StringBuffer hql = new StringBuffer();
			hql.append("from "+ClassCodeMgr.ACTIVITYRASK);
			hql.append(" where flag=1 and customerContact.id=?");			
			//若任务未完成
			if(executeState != Constants.RASKEXECUTEED) {				
				hql.append(" and executeState!=?");
			}else{
				hql.append(" and executeState=?");
			}
			return getHibernateTemplate().find(hql.toString(), new Object[]{contactId, Constants.RASKEXECUTEED});	
		}catch(Exception e){
			e.printStackTrace();
			logger.error(Constants.DATABASEFINDDATAEXCEPTION);
			throw new SystemException(Constants.DATABASEFINDDATAEXCEPTION);
		}
	}
	/**
	 * 查找是否过期的事件
	 * @param contactId
	 * @param isNotOverdue
	 * @return
	 * @throws SystemException
	 */
	public List getEvents(int contactId, boolean isNotOverdue) throws SystemException {
		try{
			StringBuffer hql = new StringBuffer();
			hql.append("from "+ClassCodeMgr.EVENT);
			hql.append(" where flag=1 and customerContact.id=?");				
			
			if(isNotOverdue) {//若事件不过期	
				hql.append("and endTime >= '"+DateTimeTool.dateToStrFormat("", new Date())+"'");
			}else{
				hql.append("and endTime < '"+DateTimeTool.dateToStrFormat("", new Date())+"'");
			}
			hql.append("order by endTime");//按结束时间的升序排列
			return getHibernateTemplate().find(hql.toString(), contactId);	
		}catch(Exception e) {
			e.printStackTrace();
			logger.error(Constants.DATABASEFINDDATAEXCEPTION);
			throw new SystemException(Constants.DATABASEFINDDATAEXCEPTION);
		}
	}
	/**
	 * 根据修改人的ID查找用户
	 * @param modifyManId
	 * @return
	 * @throws SystemException
	 */
	public User getUserByModifyManId(int modifyManId) throws SystemException {
		try{
			return (User)getHibernateTemplate().get(User.class, modifyManId);	
		}catch(Exception e){
			e.printStackTrace();
			logger.error(Constants.DATABASEFINDDATAEXCEPTION);
			throw new SystemException(Constants.DATABASEFINDDATAEXCEPTION);
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?