登录登出添加统计分析
This commit is contained in:
@@ -62,7 +62,6 @@ public class CountDemo {
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static Map<String, Object> barOrLine(String startDate, String endDate, List<JSONObject> list) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
@@ -28,4 +28,5 @@ public class SysUserLoginInOut extends BaseEntity {
|
||||
private transient String inoutTypeName;
|
||||
private transient String startDate;
|
||||
private transient String endDate;
|
||||
private transient int count;
|
||||
}
|
||||
|
||||
@@ -14,4 +14,6 @@ import java.util.Map;
|
||||
*/
|
||||
public interface SysUserLoginInOutMapper extends BaseMapper<SysUserLoginInOut> {
|
||||
List<SysUserLoginInOut> findByInoutType(Map<String, Object> map);
|
||||
|
||||
List<SysUserLoginInOut> countByType(Map<String, Object> map);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.xwbing.service.sys;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.xwbing.constant.CommonEnum;
|
||||
import com.xwbing.domain.entity.sys.SysUserLoginInOut;
|
||||
import com.xwbing.domain.mapper.sys.SysUserLoginInOutMapper;
|
||||
import com.xwbing.util.DateUtil2;
|
||||
import com.xwbing.util.Pagination;
|
||||
import com.xwbing.util.RestMessage;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
@@ -16,6 +19,7 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 项目名称: boot-module-demo
|
||||
@@ -75,4 +79,97 @@ public class SysUserLoginInOutService {
|
||||
return page.result(page, pageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录登出饼图
|
||||
*
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @return
|
||||
*/
|
||||
public JSONArray pie(String startDate, String endDate) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (StringUtils.isNotEmpty(startDate)) {
|
||||
map.put("startDate", startDate + " 00:00:00");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(endDate)) {
|
||||
map.put("endDate", endDate + " 23:59:59");
|
||||
}
|
||||
List<SysUserLoginInOut> list = loginInOutMapper.countByType(map);
|
||||
int in = 0;
|
||||
int out = 0;
|
||||
for (SysUserLoginInOut inOut : list) {
|
||||
if (inOut.getInoutType() == 1) {
|
||||
in = inOut.getCount();
|
||||
} else {
|
||||
out = inOut.getCount();
|
||||
}
|
||||
}
|
||||
JSONArray result = new JSONArray();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("name", "in");
|
||||
obj.put("value", in);
|
||||
result.add(obj);
|
||||
obj = new JSONObject();
|
||||
obj.put("name", out);
|
||||
obj.put("value", out);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录登出柱状图
|
||||
*
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> bar(String startDate, String endDate) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
//统计时间
|
||||
List<String> days = DateUtil2.listDate(startDate, endDate);
|
||||
result.put("xAxis", days);
|
||||
//统计数据
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (StringUtils.isNotEmpty(startDate)) {
|
||||
map.put("startDate", startDate + " 00:00:00");
|
||||
}
|
||||
if (StringUtils.isNotEmpty(endDate)) {
|
||||
map.put("endDate", endDate + " 23:59:59");
|
||||
}
|
||||
List<SysUserLoginInOut> list = loginInOutMapper.findByInoutType(map);
|
||||
JSONArray in = new JSONArray();
|
||||
JSONArray out = new JSONArray();
|
||||
if (CollectionUtils.isNotEmpty(list)) {
|
||||
Map<String, List<SysUserLoginInOut>> collect = list.stream().peek(obj -> obj.setRecordTime(obj.getRecordTime().substring(0, 10))).collect(Collectors.groupingBy(SysUserLoginInOut::getRecordTime));
|
||||
days.forEach(day -> {
|
||||
List<SysUserLoginInOut> sample = collect.get(day);
|
||||
if (CollectionUtils.isNotEmpty(sample)) {
|
||||
int sumIn = sample.stream().filter(obj -> obj.getInoutType() == 1).mapToInt(SysUserLoginInOut::getCount).sum();
|
||||
int sumOut = sample.stream().filter(obj -> obj.getInoutType() == 2).mapToInt(SysUserLoginInOut::getCount).sum();
|
||||
in.add(sumIn);
|
||||
out.add(sumOut);
|
||||
} else {
|
||||
in.add(0);
|
||||
out.add(0);
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
days.forEach(day -> {
|
||||
in.add(0);
|
||||
out.add(0);
|
||||
});
|
||||
}
|
||||
JSONArray series = new JSONArray();
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("name", "in");
|
||||
obj.put("data", in);
|
||||
series.add(obj);
|
||||
obj = new JSONObject();
|
||||
obj.put("name", "out");
|
||||
obj.put("data", out);
|
||||
series.add(obj);
|
||||
result.put("series", series);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -65,5 +65,19 @@
|
||||
</where>
|
||||
ORDER BY a.create_time DESC
|
||||
</select>
|
||||
<select id="countByType" resultMap="resultMap">
|
||||
SELECT count(1) count,inout_type
|
||||
from
|
||||
<include refid="table"/>
|
||||
<where>
|
||||
<if test="startDate!=null">
|
||||
and a.create_time>=#{startDate}
|
||||
</if>
|
||||
<if test="endDate!=null">
|
||||
and a.create_time <![CDATA[ <= ]]> #{endDate}
|
||||
</if>
|
||||
</where>
|
||||
group by inout_type
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.xwbing.controller.sys;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xwbing.annotation.LogInfo;
|
||||
import com.xwbing.domain.entity.vo.PageSysUserLoginInOutVo;
|
||||
@@ -17,6 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 项目名称: boot-module-demo
|
||||
@@ -42,4 +44,18 @@ public class SysUserLoginInOutControl {
|
||||
Pagination pagination = inOutService.page(inout, startDate, endDate, page);
|
||||
return JsonResult.toJSONObj(pagination, "获取列表成功");
|
||||
}
|
||||
|
||||
@LogInfo("获取饼图数据")
|
||||
@GetMapping("pie")
|
||||
public JSONObject pie(@RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate) {
|
||||
JSONArray pie = inOutService.pie(startDate, endDate);
|
||||
return JsonResult.toJSONObj(pie, "");
|
||||
}
|
||||
|
||||
@LogInfo("获取柱状图数据")
|
||||
@GetMapping("bar")
|
||||
public JSONObject bar(@RequestParam(required = false) String startDate, @RequestParam(required = false) String endDate) {
|
||||
Map<String, Object> bar = inOutService.bar(startDate, endDate);
|
||||
return JsonResult.toJSONObj(bar, "");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user