mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-07-24 18:29:33 +08:00
后台新增学员的最近一个月的学习统计api
This commit is contained in:
parent
3e36fcd1f0
commit
b34c744da9
9
pom.xml
9
pom.xml
@ -127,12 +127,17 @@
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-json</artifactId>
|
||||
<version>5.8.15</version>
|
||||
<version>5.8.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-http</artifactId>
|
||||
<version>5.8.15</version>
|
||||
<version>5.8.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-core</artifactId>
|
||||
<version>5.8.16</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -40,8 +40,7 @@ import java.util.Map;
|
||||
@Slf4j
|
||||
public class SystemController {
|
||||
|
||||
@Autowired
|
||||
private ImageCaptchaService imageCaptchaService;
|
||||
@Autowired private ImageCaptchaService imageCaptchaService;
|
||||
|
||||
@GetMapping("/image-captcha")
|
||||
public JsonResponse imageCaptcha() throws IOException {
|
||||
|
@ -15,6 +15,9 @@
|
||||
*/
|
||||
package xyz.playedu.api.controller.backend;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@ -49,6 +52,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
* @create 2023/2/23 09:48
|
||||
*/
|
||||
@RestController
|
||||
@ -56,29 +60,23 @@ import java.util.stream.Collectors;
|
||||
@RequestMapping("/backend/v1/user")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private UserDepartmentService userDepartmentService;
|
||||
@Autowired private UserDepartmentService userDepartmentService;
|
||||
|
||||
@Autowired
|
||||
private DepartmentService departmentService;
|
||||
@Autowired private DepartmentService departmentService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
@Autowired private ApplicationContext context;
|
||||
|
||||
@Autowired
|
||||
private UserCourseHourRecordService userCourseHourRecordService;
|
||||
@Autowired private UserCourseHourRecordService userCourseHourRecordService;
|
||||
|
||||
@Autowired
|
||||
private UserCourseRecordService userCourseRecordService;
|
||||
@Autowired private UserCourseRecordService userCourseRecordService;
|
||||
|
||||
@Autowired
|
||||
private CourseHourService courseHourService;
|
||||
@Autowired private CourseHourService courseHourService;
|
||||
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
@Autowired private CourseService courseService;
|
||||
|
||||
@Autowired private UserLearnDurationStatsService userLearnDurationStatsService;
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.USER_INDEX)
|
||||
@GetMapping("/index")
|
||||
@ -441,12 +439,47 @@ public class UserController {
|
||||
@GetMapping("/{id}/learn-stats")
|
||||
@SneakyThrows
|
||||
public JsonResponse learn(@PathVariable(name = "id") Integer id) {
|
||||
User user = userService.findOrFail(id);
|
||||
|
||||
// 学习时长统计
|
||||
// 今天、昨天、本周、本月
|
||||
// 最近一个月的每天学习时长
|
||||
String todayStr = DateTime.now().toDateStr();
|
||||
String startDateStr = DateTime.of(DateTime.now().getTime() - 86400000L * 30).toDateStr();
|
||||
long startTime = new DateTime(startDateStr).getTime();
|
||||
long endTime = new DateTime(todayStr).getTime();
|
||||
|
||||
return JsonResponse.data(null);
|
||||
List<UserLearnDurationStats> monthRecords =
|
||||
userLearnDurationStatsService.dateBetween(id, startDateStr, todayStr);
|
||||
Map<Date, Long> date2duration =
|
||||
monthRecords.stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
UserLearnDurationStats::getCreatedDate,
|
||||
UserLearnDurationStats::getDuration));
|
||||
|
||||
@Data
|
||||
class StatsItem {
|
||||
private String key;
|
||||
private Long value;
|
||||
}
|
||||
|
||||
List<StatsItem> data = new ArrayList<>();
|
||||
|
||||
while (startTime <= endTime) {
|
||||
String dateKey = DateTime.of(startTime).toDateStr();
|
||||
Date tmpDate = new Date(startTime);
|
||||
|
||||
Long duration = 0L;
|
||||
if (date2duration.get(tmpDate) != null) {
|
||||
duration = date2duration.get(tmpDate);
|
||||
}
|
||||
|
||||
StatsItem tmpItem = new StatsItem();
|
||||
tmpItem.setKey(dateKey);
|
||||
tmpItem.setValue(duration);
|
||||
|
||||
data.add(tmpItem);
|
||||
|
||||
startTime += 86400000;
|
||||
}
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
}
|
||||
|
@ -38,4 +38,6 @@ public interface UserLearnDurationStatsService extends IService<UserLearnDuratio
|
||||
Long todayUserDuration(Integer userId);
|
||||
|
||||
Long userDuration(Integer userId);
|
||||
|
||||
List<UserLearnDurationStats> dateBetween(Integer userId, String startAt, String endAt);
|
||||
}
|
||||
|
@ -109,4 +109,10 @@ public class UserLearnDurationStatsServiceImpl
|
||||
Long totalDuration = getBaseMapper().getUserDuration(userId);
|
||||
return totalDuration == null ? 0L : totalDuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserLearnDurationStats> dateBetween(Integer userId, String startAt, String endAt) {
|
||||
return list(
|
||||
query().getWrapper().eq("user_id", userId).between("created_date", startAt, endAt));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user