成就等界面接口调整

This commit is contained in:
2025-10-31 19:13:21 +08:00
parent 9ad9507a72
commit 16754b527e
61 changed files with 4748 additions and 592 deletions

View File

@@ -0,0 +1,46 @@
package org.xyzh.study.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.xyzh.common.dto.study.TbLearningTaskTag;
import org.xyzh.common.vo.TagVO;
import java.util.List;
/**
* @description 学习任务标签关联Mapper
* @filename LearningTaskTagMapper.java
* @author yslg
* @copyright xyzh
* @since 2025-10-31
*/
@Mapper
public interface LearningTaskTagMapper extends BaseMapper<TbLearningTaskTag> {
/**
* 根据任务ID查询标签VO列表包含标签详细信息
*/
List<TagVO> selectByTaskId(@Param("taskId") String taskId);
/**
* 根据标签ID查询任务关联列表
*/
List<TbLearningTaskTag> selectByTagId(@Param("tagId") String tagId);
/**
* 批量插入任务标签关联
*/
int batchInsert(@Param("list") List<TbLearningTaskTag> list);
/**
* 根据任务ID删除所有标签关联
*/
int deleteByTaskId(@Param("taskId") String taskId);
/**
* 删除指定任务的指定标签
*/
int deleteByTaskIdAndTagId(@Param("taskId") String taskId, @Param("tagId") String tagId);
}

View File

@@ -29,7 +29,10 @@ import org.xyzh.study.mapper.TaskUserMapper;
import org.xyzh.study.mapper.CourseMapper;
import org.xyzh.system.utils.LoginUtil;
import org.xyzh.study.mapper.TaskItemMapper;
import org.xyzh.study.mapper.LearningTaskTagMapper;
import org.xyzh.api.study.task.LearningTaskService;
import org.xyzh.common.dto.study.TbLearningTaskTag;
import org.xyzh.common.vo.TagVO;
import org.xyzh.common.core.enums.TaskItemType;
import org.xyzh.api.system.permission.ResourcePermissionService;
import org.xyzh.common.vo.UserDeptRoleVO;
@@ -59,6 +62,9 @@ public class SCLearningTaskServiceImpl implements LearningTaskService {
@Autowired
private TaskItemMapper taskItemMapper;
@Autowired
private LearningTaskTagMapper learningTaskTagMapper;
@Autowired
private ResourcePermissionService resourcePermissionService;
@@ -237,6 +243,22 @@ public class SCLearningTaskServiceImpl implements LearningTaskService {
int learnCount = courseMapper.incrementLearnCount(item.getItemID(), taskUsers.size());
}
// 绑定标签
List<TagVO> taskTags = taskVO.getTaskTags();
if (taskTags != null && !taskTags.isEmpty()) {
List<TbLearningTaskTag> taskTagList = new ArrayList<>();
for (TagVO tag : taskTags) {
TbLearningTaskTag taskTag = new TbLearningTaskTag();
taskTag.setID(IDUtils.generateID());
taskTag.setTaskID(taskID);
taskTag.setTagID(tag.getTagID());
taskTag.setCreator(currentUser.getID());
taskTag.setCreateTime(now);
taskTagList.add(taskTag);
}
learningTaskTagMapper.batchInsert(taskTagList);
}
// 创建任务资源权限
try {
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
@@ -423,6 +445,57 @@ public class SCLearningTaskServiceImpl implements LearningTaskService {
int learnCount = courseMapper.incrementLearnCount(taskID, usersToInsert.size());
}
// 4. 处理标签关联
List<TagVO> newTags = taskVO.getTaskTags();
if (newTags == null) {
newTags = new ArrayList<>();
}
// 获取现有的标签关联
List<TagVO> existingTags = learningTaskTagMapper.selectByTaskId(taskID);
Map<String, TagVO> existingTagMap = existingTags.stream()
.collect(Collectors.toMap(TagVO::getTagID, tag -> tag));
Set<String> newTagIDs = new HashSet<>();
List<TbLearningTaskTag> tagsToInsert = new ArrayList<>();
// 处理新的标签关联
for (TagVO tag : newTags) {
String tagID = tag.getTagID();
if (tagID == null || tagID.isEmpty()) {
continue;
}
newTagIDs.add(tagID);
// 如果不存在,则新增
if (!existingTagMap.containsKey(tagID)) {
TbLearningTaskTag taskTag = new TbLearningTaskTag();
taskTag.setID(IDUtils.generateID());
taskTag.setTaskID(taskID);
taskTag.setTagID(tagID);
taskTag.setCreator(user.getID());
taskTag.setCreateTime(now);
tagsToInsert.add(taskTag);
}
}
// 找出要删除的标签关联
List<String> tagIDsToDelete = existingTagMap.values().stream()
.filter(taskTag -> !newTagIDs.contains(taskTag.getTagID()))
.map(TagVO::getTagID)
.collect(Collectors.toList());
// 删除不再需要的标签
for (String tagID : tagIDsToDelete) {
learningTaskTagMapper.deleteByTaskIdAndTagId(taskID, tagID);
}
// 插入新标签
if (!tagsToInsert.isEmpty()) {
learningTaskTagMapper.batchInsert(tagsToInsert);
}
resultDomain.success("更新任务成功", taskVO);
return resultDomain;
}
@@ -494,11 +567,13 @@ public class SCLearningTaskServiceImpl implements LearningTaskService {
taskVO.setTaskCourses(taskCourses);
taskVO.setTaskResources(taskResources);
taskVO.setTaskUsers(taskUsers);
// 获取任务标签
List<TagVO> taskTags = learningTaskTagMapper.selectByTaskId(taskID);
taskVO.setTaskTags(taskTags);
taskVO.setTotalTaskNum(allTaskItems.size());
resultDomain.success("获取任务详情成功", taskVO);
return resultDomain;
}
@@ -556,11 +631,13 @@ public class SCLearningTaskServiceImpl implements LearningTaskService {
taskVO.setTaskCourses(taskCourses);
taskVO.setTaskResources(taskResources);
taskVO.setTaskUsers(taskUsers);
// 获取任务标签
List<TagVO> taskTags = learningTaskTagMapper.selectByTaskId(taskID);
taskVO.setTaskTags(taskTags);
taskVO.setTotalTaskNum(allTaskItems.size());
resultDomain.success("获取任务详情成功", taskVO);
return resultDomain;
}

View File

@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.xyzh.study.mapper.LearningTaskTagMapper">
<!-- 结果映射 -->
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.study.TbLearningTaskTag">
<id column="id" property="id" jdbcType="VARCHAR"/>
<result column="task_id" property="taskID" jdbcType="VARCHAR"/>
<result column="tag_id" property="tagID" jdbcType="VARCHAR"/>
<result column="creator" property="creator" jdbcType="VARCHAR"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
</resultMap>
<!-- TagVO 结果映射 -->
<resultMap id="TagVOResultMap" type="org.xyzh.common.vo.TagVO">
<id column="id" property="id" jdbcType="VARCHAR"/>
<result column="tag_id" property="tagID" jdbcType="VARCHAR"/>
<result column="tag_name" property="tagName" jdbcType="VARCHAR"/>
<result column="tag_color" property="tagColor" jdbcType="VARCHAR"/>
<result column="creator" property="creator" jdbcType="VARCHAR"/>
</resultMap>
<!-- 基础列 -->
<sql id="Base_Column_List">
id, task_id, tag_id, creator, create_time
</sql>
<!-- 根据任务ID查询标签VO列表包含标签详细信息 -->
<select id="selectByTaskId" resultMap="TagVOResultMap">
SELECT
tlt.id,
tlt.tag_id,
t.name AS tag_name,
t.color AS tag_color,
tlt.creator
FROM tb_learning_task_tag tlt
INNER JOIN tb_tag t ON tlt.tag_id = t.tag_id AND t.deleted = 0
WHERE tlt.task_id = #{taskId}
ORDER BY tlt.create_time ASC
</select>
<!-- 根据标签ID查询任务关联列表 -->
<select id="selectByTagId" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM tb_learning_task_tag
WHERE tag_id = #{tagId}
ORDER BY create_time DESC
</select>
<!-- 批量插入任务标签关联 -->
<insert id="batchInsert">
INSERT INTO tb_learning_task_tag (
id, task_id, tag_id, creator, create_time
) VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.id}, #{item.taskID}, #{item.tagID},
#{item.creator}, #{item.createTime}
)
</foreach>
</insert>
<!-- 根据任务ID删除所有标签关联 -->
<delete id="deleteByTaskId">
DELETE FROM tb_learning_task_tag
WHERE task_id = #{taskId}
</delete>
<!-- 删除指定任务的指定标签 -->
<delete id="deleteByTaskIdAndTagId">
DELETE FROM tb_learning_task_tag
WHERE task_id = #{taskId} AND tag_id = #{tagId}
</delete>
</mapper>