?? eventdaoimpl.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 + -