创建标签添加日志

This commit is contained in:
670788339
2025-10-30 14:34:41 +08:00
parent 9c529a061e
commit 2527e081d9
2 changed files with 41 additions and 6 deletions

View File

@@ -283,9 +283,9 @@ public class CourseManageApi extends ApiBaseController{
//填充必要的信息 //填充必要的信息
try { try {
log.info("-------- 标签相关开始 -------"); log.info("-------- 标签相关开始 ------- 课程ID = {} " , dto.getCourse().getId());
CurrentUser userInfo = getCurrent(); CurrentUser userInfo = getCurrent();
Course oldCourse = StringUtils.isBlank(dto.getCourse().getId()) ? courseService.get(dto.getCourse().getId()) : null; Course oldCourse = StringUtils.isBlank(dto.getCourse().getId()) ? null : courseService.get(dto.getCourse().getId());
tagService.updateTags(oldCourse,dto.getCourse(),userInfo); tagService.updateTags(oldCourse,dto.getCourse(),userInfo);
log.info("-------- 标签相关结束 -------"); log.info("-------- 标签相关结束 -------");

View File

@@ -375,14 +375,15 @@ public class CourseTagServiceImpl implements ICourseTagService {
@Override @Override
public void updateTags(Course oldCourse, Course newCourse, CurrentUser userInfo) { public void updateTags(Course oldCourse, Course newCourse, CurrentUser userInfo) {
log.info(" --- 标签修改 --- 在线课参数 oldCourse = " + oldCourse); log.info(" --- 标签修改 --- 在线课参数 oldCourse = {} " , oldCourse);
log.info(" --- 标签修改 --- 在线课参数 newCourse = " + newCourse); log.info(" --- 标签修改 --- 在线课参数 newCourse = {} " , newCourse);
log.info(" --- 标签修改 --- 用户信息 userInfo = " + userInfo); log.info(" --- 标签修改 --- 用户信息 userInfo = {} " , userInfo);
// 获取新旧课程的标签ID列表 // 获取新旧课程的标签ID列表
List<String> oldTagIds = getTagIdsFromCourse(oldCourse); List<String> oldTagIds = getTagIdsFromCourse(oldCourse);
List<String> newTagIds = getTagIdsFromCourse(newCourse); List<String> newTagIds = getTagIdsFromCourse(newCourse);
log.info(" --- 旧标签 oldTagIds = {} " , oldTagIds);
log.info(" --- 新修改 newTagIds = {} " , newTagIds);
if (oldCourse == null) { if (oldCourse == null) {
// 新增课程 - 处理所有新标签 // 新增课程 - 处理所有新标签
handleNewCourseTags(newCourse, newTagIds, userInfo); handleNewCourseTags(newCourse, newTagIds, userInfo);
@@ -390,6 +391,7 @@ public class CourseTagServiceImpl implements ICourseTagService {
// 编辑课程 - 比较差异并处理 // 编辑课程 - 比较差异并处理
handleEditCourseTags(oldCourse, newCourse, oldTagIds, newTagIds, userInfo); handleEditCourseTags(oldCourse, newCourse, oldTagIds, newTagIds, userInfo);
} }
log.info("完成课程标签更新: courseId={}", newCourse != null ? newCourse.getId() : "null");
} }
/** /**
@@ -417,6 +419,7 @@ public class CourseTagServiceImpl implements ICourseTagService {
* 处理新增课程的标签逻辑 * 处理新增课程的标签逻辑
*/ */
private void handleNewCourseTags(Course newCourse, List<String> newTagIds, CurrentUser userInfo) { private void handleNewCourseTags(Course newCourse, List<String> newTagIds, CurrentUser userInfo) {
log.info("处理新增课程的标签逻辑: courseId={}, tagCount={}", newCourse != null ? newCourse.getId() : "null", newTagIds.size());
String courseId = newCourse.getId(); String courseId = newCourse.getId();
for (String tagId : newTagIds) { for (String tagId : newTagIds) {
@@ -440,6 +443,7 @@ public class CourseTagServiceImpl implements ICourseTagService {
// 更新标签使用计数并检查是否设置为公共标签 // 更新标签使用计数并检查是否设置为公共标签
updateTagUseCountAndPublicStatus(tag, userInfo); updateTagUseCountAndPublicStatus(tag, userInfo);
} }
log.info("完成新增课程标签处理: courseId={}", newCourse != null ? newCourse.getId() : "null");
} }
/** /**
@@ -447,6 +451,12 @@ public class CourseTagServiceImpl implements ICourseTagService {
*/ */
private void handleEditCourseTags(Course oldCourse, Course newCourse, private void handleEditCourseTags(Course oldCourse, Course newCourse,
List<String> oldTagIds, List<String> newTagIds, CurrentUser userInfo) { List<String> oldTagIds, List<String> newTagIds, CurrentUser userInfo) {
log.info("处理编辑课程的标签逻辑: courseId={}, oldTagCount={}, newTagCount={}, toRemove={}, toAdd={}",
newCourse != null ? newCourse.getId() : "null",
oldTagIds.size(), newTagIds.size(),
oldTagIds.stream().filter(tagId -> !newTagIds.contains(tagId)).count(),
newTagIds.stream().filter(tagId -> !oldTagIds.contains(tagId)).count());
String courseId = newCourse.getId(); String courseId = newCourse.getId();
// 找出需要删除的标签(存在于旧课程但不在新课程中) // 找出需要删除的标签(存在于旧课程但不在新课程中)
@@ -486,12 +496,16 @@ public class CourseTagServiceImpl implements ICourseTagService {
if (hasCourseTypeChanged(oldCourse, newCourse)) { if (hasCourseTypeChanged(oldCourse, newCourse)) {
updateCourseTypeTagRelations(oldCourse, newCourse, newTagIds, userInfo); updateCourseTypeTagRelations(oldCourse, newCourse, newTagIds, userInfo);
} }
log.info("完成编辑课程标签处理: courseId={}", newCourse != null ? newCourse.getId() : "null");
} }
/** /**
* 创建课程-标签关联关系 * 创建课程-标签关联关系
*/ */
private void createCourseTagRelation(String courseId, CourseTag tag, CurrentUser userInfo) { private void createCourseTagRelation(String courseId, CourseTag tag, CurrentUser userInfo) {
log.debug("创建课程-标签关联关系: courseId={}, tagId={}, tagName={}",
courseId, tag != null ? tag.getId() : "null", tag != null ? tag.getTagName() : "null");
// 检查是否已存在关联关系 // 检查是否已存在关联关系
QueryBuilder query = QueryBuilder.from(CourseTagRelation.class); QueryBuilder query = QueryBuilder.from(CourseTagRelation.class);
List<IFieldFilter> filters = new ArrayList<>(); List<IFieldFilter> filters = new ArrayList<>();
@@ -532,12 +546,21 @@ public class CourseTagServiceImpl implements ICourseTagService {
courseTagRelationDao.saveOrUpdate(relation); courseTagRelationDao.saveOrUpdate(relation);
} }
} }
log.debug("完成课程-标签关联关系创建: courseId={}, tagId={}", courseId, tag != null ? tag.getId() : "null");
} }
/** /**
* 创建分类-标签关联关系 * 创建分类-标签关联关系
*/ */
private void createCourseTypeTagRelations(Course course, CourseTag tag, CurrentUser userInfo) { private void createCourseTypeTagRelations(Course course, CourseTag tag, CurrentUser userInfo) {
log.debug("创建分类-标签关联关系: courseId={}, tagId={}, sysType1={}, sysType2={}, sysType3={}",
course != null ? course.getId() : "null",
tag != null ? tag.getId() : "null",
course != null ? course.getSysType1() : "null",
course != null ? course.getSysType2() : "null",
course != null ? course.getSysType3() : "null");
String sysType1 = course.getSysType1(); String sysType1 = course.getSysType1();
String sysType2 = course.getSysType2(); String sysType2 = course.getSysType2();
String sysType3 = course.getSysType3(); String sysType3 = course.getSysType3();
@@ -607,6 +630,7 @@ public class CourseTagServiceImpl implements ICourseTagService {
* 移除课程-标签关联关系 * 移除课程-标签关联关系
*/ */
private void removeCourseTagRelation(String courseId, String tagId, CurrentUser userInfo) { private void removeCourseTagRelation(String courseId, String tagId, CurrentUser userInfo) {
log.debug("移除课程-标签关联关系: courseId={}, tagId={}", courseId, tagId);
// 查找关联关系 // 查找关联关系
QueryBuilder query = QueryBuilder.from(CourseTagRelation.class); QueryBuilder query = QueryBuilder.from(CourseTagRelation.class);
List<IFieldFilter> filters = new ArrayList<>(); List<IFieldFilter> filters = new ArrayList<>();
@@ -641,6 +665,7 @@ public class CourseTagServiceImpl implements ICourseTagService {
// 检查是否需要删除分类-标签关联关系 // 检查是否需要删除分类-标签关联关系
checkAndRemoveCourseTypeTagRelation(tagId, userInfo); checkAndRemoveCourseTypeTagRelation(tagId, userInfo);
} }
log.debug("完成课程-标签关联关系移除: courseId={}, tagId={}", courseId, tagId);
} }
/** /**
@@ -681,6 +706,11 @@ public class CourseTagServiceImpl implements ICourseTagService {
* 更新标签使用计数并检查公共标签状态 * 更新标签使用计数并检查公共标签状态
*/ */
private void updateTagUseCountAndPublicStatus(CourseTag tag, CurrentUser userInfo) { private void updateTagUseCountAndPublicStatus(CourseTag tag, CurrentUser userInfo) {
log.debug("更新标签使用计数和公共状态: tagId={}, tagName={}, beforeUseCount={}",
tag != null ? tag.getId() : "null",
tag != null ? tag.getTagName() : "null",
tag != null ? tag.getUseCount() : "null");
// 统计当前活跃的关联关系数量 // 统计当前活跃的关联关系数量
QueryBuilder query = QueryBuilder.from(CourseTagRelation.class); QueryBuilder query = QueryBuilder.from(CourseTagRelation.class);
List<IFieldFilter> filters = new ArrayList<>(); List<IFieldFilter> filters = new ArrayList<>();
@@ -707,6 +737,11 @@ public class CourseTagServiceImpl implements ICourseTagService {
tag.setSysUpdateTime(now); tag.setSysUpdateTime(now);
courseTagDao.update(tag); courseTagDao.update(tag);
log.debug("完成标签使用计数和公共状态更新: tagId={}, tagName={}, afterUseCount={}, isPublic={}",
tag != null ? tag.getId() : "null",
tag != null ? tag.getTagName() : "null",
tag != null ? tag.getUseCount() : "null",
tag != null ? tag.getIsPublic() : "null");
} }
/** /**