数据统计

master
pan 5 years ago
parent cbc1b9adfd
commit e9f81f3d7b
  1. 252
      WebRoot/admin/report.jsp
  2. 98328
      WebRoot/static/echarts.js
  3. 22
      WebRoot/static/echarts.min.js
  4. 1
      WebRoot/static/jquery.datetimepicker.full.min.js
  5. 1
      WebRoot/static/jquery.datetimepicker.min.css
  6. 86
      src/com/app/action/ApplyAction.java
  7. 23
      src/com/app/bean/Count.java
  8. 29
      src/com/app/bean/CountSplit.java
  9. 12
      src/com/app/service/CountService.java
  10. 48
      src/com/app/service/CountServiceImpl.java
  11. 3
      src/com/app/service/HouseServiceImpl.java
  12. 18
      src/com/app/service/UsersService.java
  13. 5
      src/com/app/service/UsersServiceImpl.java
  14. 2
      src/com/app/utils/Constants.java
  15. 5
      src/test/SpringTest.java

@ -1,151 +1,149 @@
<%@ page language="java" pageEncoding="UTF-8"%> <%@ page language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s"%> <%@ taglib uri="/struts-tags" prefix="s" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<% <%
String path = request.getContextPath(); String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
String usertype = session.getAttribute("userType")+""; String usertype = session.getAttribute("userType") + "";
%> %>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <c:import url="../head.jsp"/>
<title>公共租赁住房租赁管理系统</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="<%=basePath %>static/toastr-master/toastr.min.css" rel="stylesheet" type="text/css" />
<script src="<%=basePath %>static/toastr-master/toastr.min.js"></script>
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <script src="<%=basePath %>static/echarts.min.js"></script>
<script src="<%=basePath %>static/jquery.datetimepicker.full.min.js"></script>
<!-- App favicon --> <link href="<%=basePath %>static/jquery.datetimepicker.min.css" rel="stylesheet" type="text/css"/>
<link rel="shortcut icon" href="<%=basePath %>static/assets/images/favicon.ico"> <link>
<style>
#count,#count_group{
width: 1000px;
height: 500px;
}
</style>
<script>
<!-- plugins -->
<link href="<%=basePath %>static/assets/libs/flatpickr/flatpickr.min.css" rel="stylesheet" type="text/css" />
<!-- App css --> $(function () {
<link href="<%=basePath %>static/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> $("form").removeAttr("style")
<link href="<%=basePath %>static/assets/css/icons.min.css" rel="stylesheet" type="text/css" />
<link href="<%=basePath %>static/assets/css/app.min.css" rel="stylesheet" type="text/css" /> $.datetimepicker.setLocale('zh');
const format={
</head> format:'Y-m-d H:i:s'
}
let start=$('input[name=startTime]')
let end=$('input[name=endTime]')
$(start,end).datetimepicker(format);
start.val('${startTime}')
end.val('${endTime}')
<c:if test="${!empty state }">
toastr.${state}('${message}', '提示');
</c:if>
$(".bz").click(function(){
var txt = $(this).attr("txt");
toastr.success(txt, '提示');
});
let chart=echarts.init(count)
let publicOption={
title: {
text:'数据统计',
subtext: '统计时间从'+start.val()+'到'+end.val(),
left: 'center'
},
yAxis: {
name:'个数'
}
}
// 指定图表的配置项和数据
let option = {...publicOption,...{
xAxis: {
data: ["用户","房源","申请","举报"]
},
series: [{
type: 'bar',
data: [${userCount}, ${houseCount}, ${applyCount}, ${reportCount}]
}]
}}
// 使用刚指定的配置项和数据显示图表。
chart.setOption(option);
let groupChart=echarts.init(count_group)
let groupOption={...publicOption,...{
xAxis: {
type: 'category',
data: [<c:forEach items="${userList.dateList}" var="item">
'${item}',
</c:forEach>]
},
legend:['用户','房源'],
dataZoom: [
{
show: true,
realtime: true,
start: 65,
end: 85
},
],
series: [{
name:'用户',
type:'line',
data:${userList.countList}
},{
name:'房源',
type:'line',
data:${userList.countList}
}]
}
}
<body class="container_12"> groupChart.setOption(groupOption)
<div class="box round first" style="margin:15px;"> })
<div class="block"> </script>
</head>
<div id="container"></div>
<body class="container_12">
<div class="box round first" style="margin:15px;">
</div>
<div class="block">
<form action="${pageContext.request.contextPath}/admin/apply/report.do" method="post">
<div class="input-group col-5 ml-auto mr-auto">
<div class="input-group-append">
<span class="input-group-text">开始时间</span>
</div>
<input class="form-control" name="startTime">
<div class="input-group-append">
<span class="input-group-text">结束时间</span>
</div>
<input class="form-control" name="endTime">
</div> </div>
<button type="submit" class="mt-3 btn-block btn-info ml-auto mr-auto col-3">统计</button>
</form>
<!-- Vendor js --> <div id="count" class="ml-auto mr-auto mt-3"></div>
<script src="<%=basePath %>static/assets/js/vendor.min.js"></script>
<div id="count_group d-none" class="ml-auto mr-auto mt-3"></div>
<!-- optional plugins -->
<script src="<%=basePath %>static/assets/libs/moment/moment.min.js"></script> </div>
<script src="<%=basePath %>static/assets/libs/apexcharts/apexcharts.min.js"></script>
<script src="<%=basePath %>static/assets/libs/flatpickr/flatpickr.min.js"></script>
</div>
<!-- page js -->
<script src="<%=basePath %>static/assets/js/pages/dashboard.init.js"></script>
<!-- App js -->
<script src="<%=basePath %>static/assets/js/app.min.js"></script>
<script src="<%=basePath %>static/js.js"></script>
<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>
<c:if test="${!empty state }">
toastr.${state}('${message}', '提示');
setTimeout(function(){
window.location.href = "<%=basePath%>${url}";
},1500)
</c:if>
</script>
<script>
$(document).ready(function(){
$(".bz").click(function(){
var txt = $(this).attr("txt");
toastr.success(txt, '提示');
});
})
</script>
<script src="http://cdn.hcharts.cn/highcharts/highcharts.js"></script>
<script src="http://cdn.hcharts.cn/highcharts/modules/exporting.js"></script>
<script type="text/javascript">
$(function () {
Highcharts.chart('container', {
chart: {
type: 'column'
},
title: {
text: '统计'
},
subtitle: {
text: '--'
},
xAxis: {
categories: [
"用户","栏目","资料","房源","申请","举报"
],
crosshair: true
},
yAxis: {
min: 0,
title: {
text: '数据'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y}</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: '数据',
data: [${n1},${n2},${n3},${n4},${n5},${n6}]
}]
});
});
</script>
</html>
</body> </body>
</html> </html>

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -12,6 +12,11 @@ import org.springframework.stereotype.Controller;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List; import java.util.List;
@Controller @Controller
@ -25,9 +30,17 @@ public class ApplyAction {
private HouseService houseService; private HouseService houseService;
@Autowired @Autowired
private MaterialService materialService; private MaterialService materialService;
@Autowired
private CountService countService;
private String action; private String action;
private String startTime;
private String endTime;
private final SimpleDateFormat s=new SimpleDateFormat(Constants.DATETIME_FORMAT);
@Autowired @Autowired
private RefuseApplyService refuseApplyService; private RefuseApplyService refuseApplyService;
@ -205,18 +218,63 @@ public class ApplyAction {
act.put(Constants.USERS_MAP,ConstantsService.usersMap); act.put(Constants.USERS_MAP,ConstantsService.usersMap);
return "success"; return "success";
} }
private CountSplit splitCount(List<Count> counts){
List<String> dateList=new ArrayList<>();
List<Integer> countList=new ArrayList<>();
for(Count count:counts){
dateList.add(count.getDate());
countList.add(count.getCount());
}
return new CountSplit(dateList,countList);
}
@Resource @Resource
NewsService newsService; NewsService newsService;
@Resource @Resource
CatesService catesService; CatesService catesService;
public String report() { public String report() {
ActionContext act = ActionContext.getContext(); ActionContext act = ActionContext.getContext();
act.put("n1", usersService.list().size()); try {
act.put("n2", catesService.list().size()); if(startTime==null&&endTime==null){
act.put("n3", newsService.list().size()); Calendar defaultStart=Calendar.getInstance();
act.put("n4", houseService.list().size()); defaultStart.set(Calendar.MONTH,0);
act.put("n5", applyService.list().size()); defaultStart.set(Calendar.DAY_OF_MONTH,1);
act.put("n6", reportService.list().size()); defaultStart.set(Calendar.HOUR_OF_DAY,0);
defaultStart.set(Calendar.MINUTE,0);
defaultStart.set(Calendar.SECOND,0);
startTime=s.format(defaultStart.getTime());
endTime=s.format(new Date());
}else {
s.parse(startTime);
s.parse(endTime);
}
int userCount=countService.count(startTime,endTime,Users.class);
int houseCount=countService.count(startTime,endTime,House.class);
int applyCount=countService.count(startTime,endTime,Apply.class);
int reportCount=countService.count(startTime,endTime,Report.class);
act.put("userCount",userCount);
act.put("houseCount",houseCount);
act.put("applyCount",applyCount);
act.put("reportCount",reportCount);
List<Count> userList=countService.countWithDate(startTime,endTime,Users.class);
CountSplit splitUser=splitCount(userList);
act.put("userList",splitUser);
List<Count> houseList=countService.countWithDate(startTime,endTime,House.class);
CountSplit splitHouse=splitCount(houseList);
act.put("splitHouse",splitHouse);
act.put("startTime",startTime);
act.put("endTime",endTime);
} catch (ParseException e) {
e.printStackTrace();
}
return "success"; return "success";
} }
@ -335,4 +393,20 @@ public class ApplyAction {
public void setMessage(String message) { public void setMessage(String message) {
this.message = message; this.message = message;
} }
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
} }

@ -0,0 +1,23 @@
package com.app.bean;
public class Count {
private String date;
private Integer count;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
}

@ -0,0 +1,29 @@
package com.app.bean;
import java.util.List;
public class CountSplit {
List<String> dateList;
List<Integer> countList;
public CountSplit(List<String> dateList, List<Integer> countList) {
this.dateList = dateList;
this.countList = countList;
}
public List<String> getDateList() {
return dateList;
}
public void setDateList(List<String> dateList) {
this.dateList = dateList;
}
public List<Integer> getCountList() {
return countList;
}
public void setCountList(List<Integer> countList) {
this.countList = countList;
}
}

@ -0,0 +1,12 @@
package com.app.service;
import com.app.bean.Count;
import java.util.List;
public interface CountService {
//统计时间段
int count(String startTime, String endTime,Class c);
//统计时间段并按日期分组
List<Count> countWithDate(String startTime, String endTime, Class c);
}

@ -0,0 +1,48 @@
package com.app.service;
import com.app.bean.Count;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Service;
import java.sql.SQLException;
import java.util.List;
@Service
public class CountServiceImpl implements CountService{
@Autowired
private HibernateTemplate hibernateTemplate;
@Override
public int count(String startTime, String endTime,Class c) {
List list= hibernateTemplate.findByCriteria(DetachedCriteria.forClass(c).
add(Restrictions.ge("created",startTime))
.add(Restrictions.le("created",endTime))
.setProjection(Projections.rowCount()));
if(list.isEmpty()){
return 0;
}else{
return (Integer) list.get(0);
}
}
@SuppressWarnings("unchecked")
@Override
public List<Count> countWithDate(String startTime, 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)");
return query.list();
}
});
}
}

@ -4,6 +4,7 @@ import com.app.bean.House;
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.transform.Transformers; import org.hibernate.transform.Transformers;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -16,6 +17,8 @@ public class HouseServiceImpl implements HouseService {
@Resource @Resource
SessionFactory factory; SessionFactory factory;
private HibernateTemplate hibernateTemplate;
public void save(House model) { public void save(House model) {
factory.getCurrentSession().save(model); factory.getCurrentSession().save(model);
} }

@ -4,20 +4,20 @@ import com.app.bean.Users;
import java.util.List; import java.util.List;
public interface UsersService { public interface UsersService{
public void save(Users model); void save(Users model);
public void update(Users model); void update(Users model);
public Users findById(int id); Users findById(int id);
public void delete(int id); void delete(int id);
public List<Users> list(); List<Users> list();
public List<Users> list(String where); List<Users> list(String where);
public List<Users> list(String where, String[] param); List<Users> list(String where, String[] param);
public Users login(String username,String password); Users login(String username, String password);
} }

@ -3,6 +3,8 @@ package com.app.service;
import com.app.bean.Users; import com.app.bean.Users;
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -16,6 +18,9 @@ public class UsersServiceImpl implements UsersService {
@Resource @Resource
SessionFactory factory; SessionFactory factory;
@Autowired
private HibernateTemplate hibernateTemplate;
public void save(Users model) { public void save(Users model) {
factory.getCurrentSession().save(model); factory.getCurrentSession().save(model);
} }

@ -27,4 +27,6 @@ public class Constants {
public static final String MODEL = "model"; public static final String MODEL = "model";
public static final String USERS_MAP = "USERS_MAP"; public static final String USERS_MAP = "USERS_MAP";
public static String REGION_MAP="RegionMap"; public static String REGION_MAP="RegionMap";
public static final String DATETIME_FORMAT="yyyy-MM-dd HH:mm:ss";
} }

@ -0,0 +1,5 @@
public class SpringTest {
}
Loading…
Cancel
Save