mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-22 11:52:43 +08:00
added: 首页主面板api
This commit is contained in:
parent
d621cc5937
commit
c1b3029f4b
@ -1,9 +1,13 @@
|
||||
package xyz.playedu.api.controller.backend;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import xyz.playedu.api.constant.BackendConstant;
|
||||
import xyz.playedu.api.constant.SystemConstant;
|
||||
import xyz.playedu.api.domain.UserLearnDurationStats;
|
||||
import xyz.playedu.api.service.*;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -16,11 +20,49 @@ import java.util.HashMap;
|
||||
@RequestMapping("/backend/v1/dashboard")
|
||||
public class DashboardController {
|
||||
|
||||
@Autowired
|
||||
private AdminUserService adminUserService;
|
||||
|
||||
@Autowired
|
||||
private ResourceCategoryService resourceCategoryService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
|
||||
@Autowired
|
||||
private DepartmentService departmentService;
|
||||
|
||||
@Autowired
|
||||
private ResourceService resourceService;
|
||||
|
||||
@Autowired
|
||||
private UserLearnDurationStatsService userLearnDurationStatsService;
|
||||
|
||||
@GetMapping("/index")
|
||||
public JsonResponse index() {
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("version", SystemConstant.VERSION);
|
||||
|
||||
data.put("user_total", userService.total());//总学员数量
|
||||
data.put("user_today", userService.todayCount());//今日注册学员数量
|
||||
data.put("user_yesterday", userService.yesterdayCount());//昨日注册学员数量
|
||||
|
||||
data.put("course_total", courseService.total());//线上课数量
|
||||
|
||||
data.put("department_total", departmentService.total());
|
||||
data.put("resource_category_total", resourceCategoryService.total());
|
||||
data.put("admin_user_total", adminUserService.total());
|
||||
|
||||
data.put("resource_video_total", resourceService.total(BackendConstant.RESOURCE_TYPE_VIDEO));
|
||||
data.put("resource_image_total", resourceService.total(BackendConstant.RESOURCE_TYPE_IMAGE));
|
||||
|
||||
data.put("user_learn_today", userLearnDurationStatsService.todayTotal());
|
||||
data.put("user_learn_yesterday", userLearnDurationStatsService.yesterdayTotal());
|
||||
data.put("user_learn_top10", userLearnDurationStatsService.top10());
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@ -24,11 +26,13 @@ public class UserLearnDurationRecord implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@JsonProperty("user_id")
|
||||
private Integer userId;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@JsonProperty("created_date")
|
||||
private Date createdDate;
|
||||
|
||||
/**
|
||||
@ -39,21 +43,25 @@ public class UserLearnDurationRecord implements Serializable {
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
@JsonProperty("start_at")
|
||||
private Date startAt;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
@JsonProperty("end_at")
|
||||
private Date endAt;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@JsonProperty("course_id")
|
||||
private Integer courseId;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@JsonProperty("hour_id")
|
||||
private Integer hourId;
|
||||
|
||||
@TableField(exist = false)
|
||||
|
@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@ -24,6 +26,7 @@ public class UserLearnDurationStats implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@JsonProperty("user_id")
|
||||
private Integer userId;
|
||||
|
||||
/**
|
||||
@ -34,6 +37,7 @@ public class UserLearnDurationStats implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@JsonProperty("created_date")
|
||||
private Date createdDate;
|
||||
|
||||
@TableField(exist = false)
|
||||
|
@ -42,4 +42,6 @@ public interface AdminUserService extends IService<AdminUser> {
|
||||
void passwordChange(AdminUser user, String password);
|
||||
|
||||
List<AdminUser> chunks(List<Integer> ids);
|
||||
|
||||
Long total();
|
||||
}
|
||||
|
@ -51,4 +51,6 @@ public interface CourseService extends IService<Course> {
|
||||
Map<Integer, List<Integer>> getCategoryIdsGroup(List<Integer> courseIds);
|
||||
|
||||
Map<Integer, List<Integer>> getDepIdsGroup(List<Integer> courseIds);
|
||||
|
||||
Long total();
|
||||
}
|
||||
|
@ -45,4 +45,6 @@ public interface DepartmentService extends IService<Department> {
|
||||
Map<Integer, List<Department>> groupByParent();
|
||||
|
||||
Map<Integer, String> id2name();
|
||||
|
||||
Long total();
|
||||
}
|
||||
|
@ -41,4 +41,6 @@ public interface ResourceCategoryService extends IService<ResourceCategory> {
|
||||
Map<Integer, List<ResourceCategory>> groupByParent();
|
||||
|
||||
Map<Integer, String> id2name();
|
||||
|
||||
Long total();
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package xyz.playedu.api.service;
|
||||
import xyz.playedu.api.domain.UserLearnDurationStats;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【user_learn_duration_stats】的数据库操作Service
|
||||
@ -10,4 +12,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
*/
|
||||
public interface UserLearnDurationStatsService extends IService<UserLearnDurationStats> {
|
||||
void storeOrUpdate(Integer userId, Long startTime, Long endTime);
|
||||
|
||||
Long todayTotal();
|
||||
|
||||
Long yesterdayTotal();
|
||||
|
||||
List<UserLearnDurationStats> top10();
|
||||
}
|
||||
|
@ -38,4 +38,10 @@ public interface UserService extends IService<User> {
|
||||
void passwordChange(User user, String oldPassword, String newPassword) throws ServiceException;
|
||||
|
||||
List<User> chunks(List<Integer> ids, List<String> fields);
|
||||
|
||||
Long total();
|
||||
|
||||
Long todayCount();
|
||||
|
||||
Long yesterdayCount();
|
||||
}
|
||||
|
@ -175,6 +175,11 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
|
||||
public List<AdminUser> chunks(List<Integer> ids) {
|
||||
return list(query().getWrapper().in("id", ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long total() {
|
||||
return count();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import xyz.playedu.api.domain.ResourceCourseCategory;
|
||||
@ -210,6 +209,11 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long total() {
|
||||
return count();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -223,6 +223,11 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
||||
public Map<Integer, String> id2name() {
|
||||
return all().stream().collect(Collectors.toMap(Department::getId, Department::getName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long total() {
|
||||
return count();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -209,6 +209,11 @@ public class ResourceCategoryServiceImpl extends ServiceImpl<ResourceCategoryMap
|
||||
public Map<Integer, String> id2name() {
|
||||
return all().stream().collect(Collectors.toMap(ResourceCategory::getId, ResourceCategory::getName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long total() {
|
||||
return count();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
@ -16,8 +17,7 @@ import java.util.Date;
|
||||
* @createDate 2023-03-22 13:55:29
|
||||
*/
|
||||
@Service
|
||||
public class UserLearnDurationStatsServiceImpl extends ServiceImpl<UserLearnDurationStatsMapper, UserLearnDurationStats>
|
||||
implements UserLearnDurationStatsService {
|
||||
public class UserLearnDurationStatsServiceImpl extends ServiceImpl<UserLearnDurationStatsMapper, UserLearnDurationStats> implements UserLearnDurationStatsService {
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
@ -43,6 +43,29 @@ public class UserLearnDurationStatsServiceImpl extends ServiceImpl<UserLearnDura
|
||||
newStats.setDuration((int) (stats.getDuration() + duration));
|
||||
updateById(newStats);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public Long todayTotal() {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String today = simpleDateFormat.format(new Date());
|
||||
return count(query().getWrapper().eq("created_date", today));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public Long yesterdayTotal() {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String yesterday = simpleDateFormat.format(new Date(System.currentTimeMillis() - 86399000));
|
||||
return count(query().getWrapper().eq("created_date", yesterday));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserLearnDurationStats> top10() {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String today = simpleDateFormat.format(new Date());
|
||||
return list(query().getWrapper().eq("created_date", today).orderByDesc("duration").last("limit 10"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import xyz.playedu.api.constant.SystemConstant;
|
||||
@ -16,6 +17,7 @@ import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.UserPaginateFilter;
|
||||
import xyz.playedu.api.util.HelperUtil;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ -160,6 +162,29 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
public List<User> chunks(List<Integer> ids, List<String> fields) {
|
||||
return list(query().getWrapper().in("id", ids).select(fields));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long total() {
|
||||
return count();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public Long todayCount() {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date now = new Date();
|
||||
String todayDate = simpleDateFormat.format(now);
|
||||
return count(query().getWrapper().between("created_at", simpleDateFormat.parse(todayDate), now));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public Long yesterdayCount() {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String todayDate = simpleDateFormat.format(new Date());
|
||||
String yesterdayDate = simpleDateFormat.format(new Date(System.currentTimeMillis() - 86400000));
|
||||
return count(query().getWrapper().between("created_at", simpleDateFormat.parse(yesterdayDate), simpleDateFormat.parse(todayDate)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user