代码实现
获取当前周信息,并获取每天的登录次数,因为是走势图调用,所以返回数组,可根据个人需要进行更改
/*
* @Description TODO 登录统计
* @Author dengewi
* @Date 2019/11/2
* @Param
* @return
**/
@GetMapping("loginCount")
public Map<String, Object> loginCount(
HttpServletRequest request, HttpServletResponse response
) throws Exception{
SysUser sysUser = (SysUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
//获取当前周时间
Calendar calendar = Calendar.getInstance();
while (calendar.get(Calendar.DAY_OF_WEEK)!=Calendar.MONDAY){
calendar.add(Calendar.DAY_OF_WEEK, -1);
}
String weekDays[] = {"周一","周二","周三","周四","周五","周六","周日",};
Integer value[] = new Integer[7]; //统计数量
for(int i=0;i<7;i++){
LogSysExample example = new LogSysExample();
LogSysExample.Criteria criteria = example.createCriteria();
//获取开始结束时间
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
Date startdate = calendar.getTime();
//获取结束时间
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
Date enddate = calendar.getTime();
//条件
criteria.andCreatetimeBetween(startdate, enddate);
criteria.andActionEqualTo("登录");
criteria.andUseridEqualTo(sysUser.getId());
List<LogSys> loglist = logSysService.selectAll(example);
value[i] = loglist.size();
calendar.add(Calendar.DATE,1);
}
LoginCount loginCount = new LoginCount();
loginCount.setWeeks(weekDays);
loginCount.setCount(value);
return restHelper.toJsonMap(RestHelper.SUCCESS,"获取走势图数据",loginCount);
}
接口返回
{
"msg" : "获取走势图数据",
"data" : {
"weeks" : [ "周一", "周二", "周三", "周四", "周五", "周六", "周日" ],
"count" : [ 0, 0, 1, 0, 0, 0, 0 ]
},
"code" : 200
}
返回对象
/*
* @Description TODO 首页接口返回
* @Author dengewi
* @Date 2019/11/2 13:30
* @Param
* @return
**/
public class LoginCount {
private String[] weeks;
private Integer[] count;
public String[] getWeeks() {
return weeks;
}
public void setWeeks(String[] weeks) {
this.weeks = weeks;
}
public Integer[] getCount() {
return count;
}
public void setCount(Integer[] count) {
this.count = count;
}
}
版权声明:本文为weixin_35242653原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。