⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eventdaoimpl.java

📁 基于Sturts+Spring+Hibernate的一个高级销售管理系统。内容丰富
💻 JAVA
字号:
package com.yuanchung.sales.dao.taskEvent.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.yuanchung.sales.dao.taskEvent.EventDAO;
import com.yuanchung.sales.exception.ApplicationException;
import com.yuanchung.sales.exception.SystemException;
import com.yuanchung.sales.model.taskEvent.Event;
import com.yuanchung.sales.model.user.User;
@SuppressWarnings("unchecked")
public class EventDAOImpl extends HibernateDaoSupport implements EventDAO {

	/**
	 * @author 福建圆创软件;
	 * @function 添加日历事件;
	 * @param 保存event参数的实例
	 * @return 返回是否保存成功;
	 */
	public boolean addEvent(Event event) throws DataAccessException {
		this.getHibernateTemplate().save(event);
		return true;

	}

	/**
	 * 更新事件
	 * 
	 * @param classCode类编码
	 * @param recordId记录ID
	 * @param flag旗标
	 * @throws DataAccessException
	 */
	public void updateEvents(int modifyManId, String modifyTime,
			String classCode, int recordId, int flag)
			throws DataAccessException {
		getHibernateTemplate()
				.bulkUpdate(
						"update Event as e set e.flag=?, e.modifyManId=?, e.lastModifyTime=? where e.functionId=? and e.recordId=?",
						new Object[] { flag, modifyManId, modifyTime,
								classCode, recordId });

	}

	// 根据联系人更新事件
	public void updateEventsByContactId(int modifyManId, String modifyTime,
			int contactId, int flag) throws DataAccessException {

		this
				.getHibernateTemplate()
				.bulkUpdate(
						"update Event as e set e.flag=?, e.modifyManId=?, e.lastModifyTime=? where e.customerContact.id=? ",
						new Object[] { flag, modifyManId, modifyTime, contactId });

	}

	// 根据ID更新事件
	public void updateEventById(int modifyManId, String modifyTime,
			int eventId, int flag) throws DataAccessException {
		try {
			this
					.getHibernateTemplate()
					.bulkUpdate(
							"update Event as e set e.flag=?, e.modifyManId=?, e.lastModifyTime=? where e.id=? ",
							new Object[] { flag, modifyManId, modifyTime,
									eventId });
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("update event exception");
			throw new SystemException("update event exception");
		}
	}

	// 查找所有已删除的事件
	public List getEventByDelete(User user, int flag)
			throws DataAccessException {
		try {
			return getHibernateTemplate()
					.find(
							"from Event as e where e.user=? and e.flag=? order by e.lastModifyTime desc",
							new Object[] { user, flag });
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("get event data exception");
			throw new SystemException("get event data exception");
		}
	}

	// 根据subject模糊查找事件
	public List getEventsBySujectLike(User user, int flag, String subject)
			throws DataAccessException {
		try {
			return getHibernateTemplate().find(
					"from Event as e where e.user=? and e.flag=? and e.subject like '%"
							+ subject + "%' order by e.lastModifyTime desc",
					new Object[] { user, flag });
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("get event data exception");
			throw new SystemException("get event data exception");
		}
	}

	/**
	 * @author 福建圆创软件;
	 * @function 根据某天搜索事件;
	 * @param DayOfMonth
	 *            日期;
	 * @return 返回事件列表;
	 */
	public List getEventByDay(String dayOfMonth, int flag, User user)
			throws DataAccessException {
		return this.getHibernateTemplate().find(
				"from Event e where e.flag=" + flag
						+ " and e.startDate='" + dayOfMonth
						+ "' and e.endDate='" + dayOfMonth + "'"
						+ " and e.user=?", user);
	}

	/**
	 * @author 福建圆创软件;
	 * @function 根据某年某月搜索事件;
	 * @param date
	 *            日期;
	 * @param flag
	 *            是否激活状态;
	 * @return 返回事件列表;
	 */
	public List getEventsByMonth(int flag, int year, int month, User user)
			throws DataAccessException {
		return this.getHibernateTemplate().find(
				"from Event e where e.flag=" + flag
						+ " and e.currentYear=" + year + " and e.monthOfYear="
						+ month + " and e.user=?", user);
	}

	/**
	 * @author 福建圆创软件;
	 * @function 根据id号搜索事件;
	 * @param id
	 * @return 该id号的事件;
	 * @throws ApplicationException
	 */
	public Event getEventById(Integer id) throws DataAccessException {
		return (Event) this.getHibernateTemplate().get(Event.class, id);
	}

	/**
	 * @author 陆文邦;
	 * @function 根据某年某周搜索事件;
	 * @param flag
	 *            是否激活状态;
	 * @return 返回事件列表;
	 */
	public List getEventsByWeek(int weekOfYearInt, int year, int flag, User user)
			throws DataAccessException {
		return this.getHibernateTemplate().find(
				" from Event e where e.flag=" + flag
						+ " and e.currentYear=" + year + " and e.weekOfYear="
						+ weekOfYearInt + " and e.user=?", user);
	}

	/**
	 * @author 陆文邦;
	 * @function 根据id号搜索事件;
	 * @param id
	 * @return 该id号的事件;
	 * @throws ApplicationException
	 */
	public List getEventsByDate(int year, int dayOfYear, int flag, User user)
			throws DataAccessException {
		return this.getHibernateTemplate().find(
				"from Event e where e.flag=" + flag
						+ " and e.currentYear=" + year + " and e.dayOfYear="
						+ dayOfYear + " and e.user=?", user);
	}

	/**
	 * @author 陆文邦
	 * @date 2008-12-18
	 * @function 查找相关的数据;
	 * @param user
	 * @param flag
	 * @return
	 * @throws ApplicationException
	 */
	public List getTaskEvent(final User user, final int flag)
			throws DataAccessException {
		return this.getHibernateTemplate().executeFind(new HibernateCallback() {

			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				Query query = session
						.createSQLQuery("(select a.id, a.Subject,a.beFirst as istype from activity_task a) union all (select b.id as cc ,b.Subject,b.createTime from event b);");
				List list = query.list();
				return list;
			}
		});
	}

	/**
	 * 函数功能 修改事件; 创建时间 2008-12-23; 程序员 陆文邦;
	 * 
	 * @param event
	 * @throws ApplicationException
	 */
	public void modifyEvent(Event event) throws DataAccessException {
		this.getHibernateTemplate().merge(event);
	}

	/**
	 * 函数功能: 删除事件,不是物理删除; 参数说明: id 事件id,针对该id的事件修改; flag 旗标,标识该事件是否可用; 程序作者:
	 * 陆文邦; 创建时间: 2008-12-24
	 * 
	 * @throws ApplicationException
	 */
	public void mergeEventFlag(final Integer id, final int flag)
			throws DataAccessException {
		this.getHibernateTemplate().execute(new HibernateCallback() {

			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				Query query = session.createQuery("update Event e set e.flag="
						+ flag + " where e.id=" + id);
				query.executeUpdate();
				return null;
			}

		});
	}

	/**
	 * 函数功能: 获取系列事件列表; 参数说明:
	 * 
	 * @param flag
	 *            标识该事件是否可用;
	 * @param seq
	 *            事件序列号; 程序作者: 陆文邦; 创建时间: 2008-12-29;
	 * @throws DataAccessException
	 */
	public List getSeqEvents(int flag, String seq) throws DataAccessException {
		return this.getHibernateTemplate().find(
				" from Event e where e.flag=" + flag
						+ " and e.eventSeq=" + seq);
	}

	/**
	 * 函数功能: 删除事件; 参数说明:
	 * 
	 * @param event
	 *            事件对象; 程序作者: 陆文邦; 创建时间: 2008-12-29;
	 * @throws DataAccessException
	 */
	public void deleteEvent(Event event) throws DataAccessException {
		this.getHibernateTemplate().delete(event);
	}

	/**
	 * 函数功能: 获取系列事件列表的最后一件; 参数说明:
	 * 
	 * @param flag
	 *            标识该事件是否可用;
	 * @param seq
	 *            事件序列号; 程序作者: 陆文邦; 创建时间: 2008-12-29;
	 * @throws DataAccessException
	 */
	public Event getLastEventBySeq(int flag, String seq)
			throws DataAccessException {
		return (Event) this.getHibernateTemplate().find(
				"from Event e where e.flag=" + flag
						+ " and e.eventSeq=" + seq + " order by e.id desc")
				.get(0);
	}
}

⌨️ 快捷键说明

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