学习进度统计
This commit is contained in:
@@ -179,5 +179,16 @@ public class LearningTaskController {
|
||||
public ResultDomain<Map<String, Object>> getTaskStatisticsRankings(@PathVariable("taskID") String taskID) {
|
||||
return learningTaskService.getTaskStatisticsRankings(taskID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 首页任务学习进度统计,
|
||||
* @param
|
||||
* @author yslg
|
||||
* @since 2025-11-17
|
||||
*/
|
||||
@GetMapping("/statistics")
|
||||
public ResultDomain<Map<String, Object>> getStatistics(@RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {
|
||||
return learningTaskService.getMyTotalStatistics(startTime, endTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.common.core.page.PageParam;
|
||||
import org.xyzh.common.dto.study.TbLearningRecord;
|
||||
import org.xyzh.common.dto.study.TbLearningTask;
|
||||
import org.xyzh.common.vo.UserDeptRoleVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.xyzh.common.vo.UserDeptRoleVO;
|
||||
import org.xyzh.common.vo.TaskItemVO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @description LearningTaskMapper.java文件描述 学习任务数据访问层
|
||||
@@ -182,4 +183,17 @@ public interface LearningTaskMapper extends BaseMapper<TbLearningTask> {
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
long countLearningTasks(@Param("filter") TbLearningTask filter, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
/**
|
||||
* @description 获取任务统计(按标签分组,统计指定时间范围内当前用户任务的完成进度)
|
||||
* @param filter 过滤条件(包含开始、结束时间)
|
||||
* @param userDeptRoles 用户部门角色列表
|
||||
* @param userId 当前用户ID
|
||||
* @return List<Map<String, Object>> 任务统计列表
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<Map<String, Object>> getTaskStaticByTag(@Param("filter") TbLearningTask filter,
|
||||
@Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles,
|
||||
@Param("userId") String userId);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.xyzh.study.service.impl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -13,6 +14,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.core.enums.TaskItemType;
|
||||
import org.xyzh.common.dto.study.TbLearningRecord;
|
||||
import org.xyzh.common.dto.study.TbLearningTask;
|
||||
import org.xyzh.common.dto.study.TbTaskItem;
|
||||
import org.xyzh.common.dto.study.TbTaskUser;
|
||||
import org.xyzh.common.dto.user.TbSysUser;
|
||||
@@ -241,21 +243,19 @@ public class SCLearningRecordServiceImpl implements LearningRecordService {
|
||||
int completedRequired = 0;
|
||||
|
||||
for (TaskItemVO item : allTaskItems) {
|
||||
if (item.getRequired() != null && item.getRequired()) {
|
||||
// if (item.getRequired() != null && item.getRequired()) {
|
||||
totalRequired++;
|
||||
if (item.getStatus() != null && item.getStatus() == 2) {
|
||||
completedRequired++;
|
||||
} else {
|
||||
allCompleted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!allCompleted) {
|
||||
return;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
// 计算总进度
|
||||
BigDecimal progressPercent = BigDecimal.valueOf(100);
|
||||
BigDecimal progressPercent = BigDecimal.valueOf(completedRequired/(totalRequired * 1.0) * 100);
|
||||
|
||||
// 更新 task_user 状态
|
||||
TbTaskUser taskUser = new TbTaskUser();
|
||||
@@ -265,7 +265,7 @@ public class SCLearningRecordServiceImpl implements LearningRecordService {
|
||||
taskUser.setUpdater(userId);
|
||||
|
||||
// 全部完成
|
||||
taskUser.setStatus(2);
|
||||
taskUser.setStatus(totalRequired == completedRequired? 2:1);
|
||||
taskUser.setCompleteTime(new Date());
|
||||
taskUserMapper.updateTaskUser(taskUser);
|
||||
logger.info("更新任务用户状态成功 - taskId: {}, userId: {}, status: {}, progress: {}",
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.xyzh.study.service.impl;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@@ -827,4 +829,39 @@ public class SCLearningTaskServiceImpl implements LearningTaskService {
|
||||
}
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Map<String, Object>> getMyTotalStatistics(String startTime, String endTime) {
|
||||
ResultDomain<Map<String, Object>> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
TbSysUser currentUser = LoginUtil.getCurrentUser();
|
||||
if (currentUser == null) {
|
||||
resultDomain.fail("请先登录");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
Map<String, Object> statisticsData = new HashMap<>();
|
||||
|
||||
// 获取当前用户的部门角色信息
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
|
||||
// 解析时间范围
|
||||
TbLearningTask filter = new TbLearningTask();
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
filter.setStartTime(df.parse(startTime));
|
||||
filter.setEndTime(df.parse(endTime));
|
||||
|
||||
// 按标签统计当前用户在时间范围内任务的平均完成进度
|
||||
List<Map<String, Object>> tagProgressList = learningTaskMapper.getTaskStaticByTag(filter, userDeptRoles,
|
||||
currentUser.getID());
|
||||
|
||||
statisticsData.put("tagProgressList", tagProgressList);
|
||||
|
||||
resultDomain.success("获取学习记录统计数据成功", statisticsData);
|
||||
} catch (Exception e) {
|
||||
logger.error("获取学习记录统计数据失败", e);
|
||||
resultDomain.fail("获取学习记录统计数据失败:" + e.getMessage());
|
||||
}
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,4 +357,9 @@
|
||||
LIMIT 10
|
||||
</select>
|
||||
|
||||
<!-- getTaskStaticByTag -->
|
||||
|
||||
<select id="getTaskStaticByTag">
|
||||
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -352,4 +352,22 @@
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- getTaskStaticByTag:按标签统计当前用户在时间范围内任务的平均完成进度 -->
|
||||
|
||||
<select id="getTaskStaticByTag" resultType="java.util.Map">
|
||||
SELECT
|
||||
tt.name AS tagName,
|
||||
AVG(tu.progress) AS avgProgress
|
||||
FROM tb_learning_task t
|
||||
LEFT JOIN tb_task_user tu ON t.task_id = tu.task_id
|
||||
LEFT JOIN tb_learning_task_tag tlt ON t.task_id = tlt.task_id
|
||||
LEFT JOIN tb_tag tt ON tlt.tag_id = tt.tag_id
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE t.deleted = 0
|
||||
AND tu.deleted = 0
|
||||
AND tu.user_id = #{userId}
|
||||
AND tu.progress IS NOT NULL
|
||||
AND t.create_time BETWEEN #{filter.startTime} AND #{filter.endTime}
|
||||
GROUP BY tt.tag_id, tt.name
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user