数据统计

master
pan 5 years ago
parent 8e94a17a71
commit 4fb3eaadd0
  1. 85
      WebRoot/admin/report.jsp
  2. 10
      src/com/app/action/ApplyAction.java
  3. 25
      src/com/app/service/CountServiceImpl.java

@ -12,14 +12,14 @@
<head> <head>
<c:import url="../head.jsp"/> <c:import url="../head.jsp"/>
<link href="<%=basePath %>static/toastr-master/toastr.min.css" rel="stylesheet" type="text/css" /> <link href="<%=basePath %>static/toastr-master/toastr.min.css" rel="stylesheet" type="text/css"/>
<script src="<%=basePath %>static/toastr-master/toastr.min.js"></script> <script src="<%=basePath %>static/toastr-master/toastr.min.js"></script>
<script src="<%=basePath %>static/echarts.min.js"></script> <script src="<%=basePath %>static/echarts.min.js"></script>
<script src="<%=basePath %>static/jquery.datetimepicker.full.min.js"></script> <script src="<%=basePath %>static/jquery.datetimepicker.full.min.js"></script>
<link href="<%=basePath %>static/jquery.datetimepicker.min.css" rel="stylesheet" type="text/css"/> <link href="<%=basePath %>static/jquery.datetimepicker.min.css" rel="stylesheet" type="text/css"/>
<link> <link>
<style> <style>
#count,#count_group{ #count, #count_group {
width: 1000px; width: 1000px;
height: 500px; height: 500px;
} }
@ -31,61 +31,71 @@
$("form").removeAttr("style") $("form").removeAttr("style")
$.datetimepicker.setLocale('zh'); $.datetimepicker.setLocale('zh');
const format={ const format = {
format:'Y-m-d H:i:s' format: 'Y-m-d H:i:s'
} }
let start=$('input[name=startTime]') let start = $('input[name=startTime]')
let end=$('input[name=endTime]') let end = $('input[name=endTime]')
$(start,end).datetimepicker(format); $(start, end).datetimepicker(format);
start.val('${startTime}') start.val('${startTime}')
end.val('${endTime}') end.val('${endTime}')
<c:if test="${!empty state }"> <c:if test="${!empty state }">
toastr.${state}('${message}', '提示'); toastr.${state}('${message}', '提示');
</c:if> </c:if>
$(".bz").click(function(){ $(".bz").click(function () {
var txt = $(this).attr("txt"); var txt = $(this).attr("txt");
toastr.success(txt, '提示'); toastr.success(txt, '提示');
}); });
let chart=echarts.init(count) let chart = echarts.init(count)
let publicOption={ let publicOption = {
title: { title: {
text:'数据统计', text: '数据统计',
subtext: '统计时间从'+start.val()+'到'+end.val(), subtext: '统计时间从' + start.val() + '到' + end.val(),
left: 'center' left: 'center'
}, },
yAxis: { yAxis: {
name:'个数' name: '个数'
} }
} }
let group = ['用户', '房源', '申请', '举报']
// 指定图表的配置项和数据 // 指定图表的配置项和数据
let option = {...publicOption,...{ let option = {
...publicOption, ...{
xAxis: { xAxis: {
data: ["用户","房源","申请","举报"] data: group
}, },
series: [{ series: [{
type: 'bar', type: 'bar',
data: [${userCount}, ${houseCount}, ${applyCount}, ${reportCount}] data: [${userCount}, ${houseCount}, ${applyCount}, ${reportCount}],
}] label:{
}} show:true
}
}],
tooltip: {
show: true
}
}
}
// 使用刚指定的配置项和数据显示图表。 // 使用刚指定的配置项和数据显示图表。
chart.setOption(option); chart.setOption(option);
let groupChart=echarts.init(count_group) let groupChart = echarts.init(count_group)
let groupOption={...publicOption,...{
let groupOption = {
...publicOption, ...{
xAxis: { xAxis: {
type: 'category', type: 'category',
data: [<c:forEach items="${userList.dateList}" var="item"> data: [<c:forEach items="${userList.dateList}" var="item">
'${item}', '${item}',
</c:forEach>] </c:forEach>]
}, },
legend:['用户','房源'],
dataZoom: [ dataZoom: [
{ {
show: true, show: true,
@ -94,14 +104,29 @@
end: 85 end: 85
}, },
], ],
tooltip: {
trigger: 'axis'
},
legend: {
data: group,
left: 0
},
series: [{ series: [{
name:'用户', name: group[0],
type:'line', type: 'line',
data:${userList.countList}
},{
name:'房源',
type:'line',
data:${userList.countList} data:${userList.countList}
}, {
name: group[1],
type: 'line',
data:${houseList.countList}
}, {
name: group[2],
type: 'line',
data:${applyList.countList}
}, {
name: group[3],
type: 'line',
data:${reportList.countList}
}] }]
} }
} }
@ -137,7 +162,7 @@
<div id="count" class="ml-auto mr-auto mt-3"></div> <div id="count" class="ml-auto mr-auto mt-3"></div>
<div id="count_group d-none" class="ml-auto mr-auto mt-3"></div> <div id="count_group" class="ml-auto mr-auto mt-3"></div>
</div> </div>

@ -267,7 +267,15 @@ public class ApplyAction {
List<Count> houseList=countService.countWithDate(startTime,endTime,House.class); List<Count> houseList=countService.countWithDate(startTime,endTime,House.class);
CountSplit splitHouse=splitCount(houseList); CountSplit splitHouse=splitCount(houseList);
act.put("splitHouse",splitHouse); act.put("houseList",splitHouse);
List<Count> applyList=countService.countWithDate(startTime,endTime,Apply.class);
CountSplit splitApply=splitCount(applyList);
act.put("applyList",splitApply);
List<Count> reportList=countService.countWithDate(startTime,endTime,Report.class);
CountSplit splitReport=splitCount(reportList);
act.put("reportList",splitReport);
act.put("startTime",startTime); act.put("startTime",startTime);
act.put("endTime",endTime); act.put("endTime",endTime);

@ -36,12 +36,31 @@ public class CountServiceImpl implements CountService{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @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() { return (List<Count>) hibernateTemplate.execute(new HibernateCallback() {
@Override @Override
public Object doInHibernate(Session session) throws HibernateException, SQLException { public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query=session.createSQLQuery( StringBuffer sql=new StringBuffer();
"select substring(created,1,10) as date,count(*) as count from "+c.getSimpleName()+" group by substring(created,1,10)"); 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(); return query.setResultTransformer(Transformers.aliasToBean(Count.class)).list();
} }
}); });

Loading…
Cancel
Save