* @param month
* @return
*/
public static int[] statCalendarLogs(SiteBean site, SessionUserObject user, Calendar month)
{
Calendar firstDate = (Calendar)month.clone();
firstDate.set(Calendar.DATE,1);
DateUtils.resetTime(firstDate);
Calendar nextMonthFirstDate = (Calendar)firstDate.clone();
nextMonthFirstDate.add(Calendar.MONTH,1);
//����ָ���·��ж�����
Calendar tempCal = (Calendar)nextMonthFirstDate.clone();
tempCal.add(Calendar.DATE,-1);
int dateCount = tempCal.get(Calendar.DATE);
int[] logCounts = new int[dateCount+1];
//��ѯ�����µ������ռǽ���ͳ��
StringBuffer hql = new StringBuffer("SELECT j.writeTime FROM DiaryBean AS j WHERE j.writeTime>=:beginTime AND j.writeTime<:endTime AND j.status=:status AND j.site.id=:site");
if(!site.isOwner(user)){
//�ų��û�û��Ȩ���ʵķ���
hql.append(" AND (j.catalog.type<>:cat_type");
if(user != null)
hql.append(" OR (j.catalog.type=:cat_type AND j.catalog.id IN (SELECT p.key.catalog FROM CatalogPermBean AS p WHERE p.key.user=:user))");
hql.append(')');
}
Session ssn = getSession();
try{
Query q = ssn.createQuery(hql.toString()).setCacheable(true);
q.setTimestamp("beginTime", firstDate.getTime());
q.setTimestamp("endTime", nextMonthFirstDate.getTime());
q.setInteger("status", DiaryBean.STATUS_NORMAL);
q.setInteger("site", site.getId());
if(!site.isOwner(user)){
q.setInteger("cat_type", CatalogBean.TYPE_OWNER);
if(user != null)
q.setInteger("user", user.getId());
}
int total = 0;
Iterator logs = q.list().iterator();
while(logs.hasNext()){
tempCal.setTime((Date)logs.next());
int date = tempCal.get(Calendar.DATE);
logCounts[date]++;
total ++;
}
logCounts[0] = total;