|
|
|
@ -36,12 +36,31 @@ public class CountServiceImpl implements CountService{ |
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
@Override |
|
|
|
|
public List<Count> countWithDate(String startTime, String endTime, final Class c) { |
|
|
|
|
public List<Count> countWithDate(final String startTime, final String endTime, final Class c) { |
|
|
|
|
return (List<Count>) hibernateTemplate.execute(new HibernateCallback() { |
|
|
|
|
@Override |
|
|
|
|
public Object doInHibernate(Session session) throws HibernateException, SQLException { |
|
|
|
|
Query query=session.createSQLQuery( |
|
|
|
|
"select substring(created,1,10) as date,count(*) as count from "+c.getSimpleName()+" group by substring(created,1,10)"); |
|
|
|
|
StringBuffer sql=new StringBuffer(); |
|
|
|
|
sql.append("select date, count\n") |
|
|
|
|
.append("from (\n") |
|
|
|
|
.append(" select substring(created, 1, 10) as date, count(*) as count\n") |
|
|
|
|
.append(" from users\n") |
|
|
|
|
.append(" group by substring(created, 1, 10)\n") |
|
|
|
|
.append(" union all\n") |
|
|
|
|
.append(" SELECT CONVERT(VARCHAR(10), dateadd(d, number, DATENAME(year, GETDATE()) + '-01-01'), 23) AS date, 0 as count\n") |
|
|
|
|
.append(" FROM master..spt_values\n") |
|
|
|
|
.append(" WHERE type = 'p'\n") |
|
|
|
|
.append(" AND number between 0 and datediff(day, DATENAME(year, GETDATE()) + '-01-01', getdate())\n") |
|
|
|
|
.append(" and CONVERT(VARCHAR(10), dateadd(d, number, DATENAME(year, GETDATE()) + '-01-01'), 23) not in\n") |
|
|
|
|
.append(" (select substring(created, 1, 10) as date from users group by substring(created, 1, 10))) b\n") |
|
|
|
|
.append("where date between\n") |
|
|
|
|
.append(" '") |
|
|
|
|
.append(startTime, 0, 8) |
|
|
|
|
.append("' and '") |
|
|
|
|
.append(endTime, 0, 8) |
|
|
|
|
.append("'\n") |
|
|
|
|
.append("order by date"); |
|
|
|
|
Query query=session.createSQLQuery(sql.toString()); |
|
|
|
|
return query.setResultTransformer(Transformers.aliasToBean(Count.class)).list(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|