From 3c4db9849b2a7be8929d21e5c7bdbe43e4ad6c64 Mon Sep 17 00:00:00 2001 From: chenyuan Date: Fri, 31 Jul 2026 10:52:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8E=A7=E5=88=B6=E6=95=99=E5=AD=A6?= =?UTF-8?q?=E7=8F=AD=E5=AE=9E=E8=AE=AD=E4=BB=BB=E5=8A=A1=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stu/TaskAllocationController.java | 64 ++++++++++++++++++- .../linkCommerce/entity/TaskAllocation.java | 7 +- .../entity/dto/TaskPublication.java | 26 ++++++++ .../service/impl/TrainingTaskServiceImpl.java | 46 ++++++++++++- 4 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/sztzjy/linkCommerce/entity/dto/TaskPublication.java diff --git a/src/main/java/com/sztzjy/linkCommerce/controller/stu/TaskAllocationController.java b/src/main/java/com/sztzjy/linkCommerce/controller/stu/TaskAllocationController.java index 8b99181..82658d7 100644 --- a/src/main/java/com/sztzjy/linkCommerce/controller/stu/TaskAllocationController.java +++ b/src/main/java/com/sztzjy/linkCommerce/controller/stu/TaskAllocationController.java @@ -7,11 +7,13 @@ import com.sztzjy.linkCommerce.entity.SchoolClass; import com.sztzjy.linkCommerce.entity.TaskAllocation; import com.sztzjy.linkCommerce.entity.TaskAllocationExample; import com.sztzjy.linkCommerce.entity.TeachingClassStudent; +import com.sztzjy.linkCommerce.entity.dto.TaskPublication; import com.sztzjy.linkCommerce.mapper.SchoolClassMapper; import com.sztzjy.linkCommerce.mapper.TaskAllocationMapper; import com.sztzjy.linkCommerce.mapper.TeachingClassStudentMapper; import com.sztzjy.linkCommerce.service.SchoolDefaultTaskService; import com.sztzjy.linkCommerce.service.StudentTeachingClassResolver; +import com.sztzjy.linkCommerce.service.TrainingTaskService; import com.sztzjy.linkCommerce.util.ResultEntity; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -23,7 +25,10 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.Collections; +import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import java.util.UUID; @Api(tags = "任务分配相关") @@ -40,6 +45,31 @@ public class TaskAllocationController { SchoolDefaultTaskService schoolDefaultTaskService; @Autowired(required = false) StudentTeachingClassResolver studentTeachingClassResolver; + @Autowired(required = false) + TrainingTaskService trainingTaskService; + + @PostMapping("/selectTaskPublicationByClassId") + @ApiOperation("查询教学班实训任务发布配置") + @AnonymousAccess + public ResultEntity selectTaskPublicationByClassId(@RequestParam String classId) { + TaskPublication publication = new TaskPublication(); + TaskAllocationExample example = new TaskAllocationExample(); + example.createCriteria().andClassIdEqualTo(classId); + example.setOrderByClause("sort asc"); + List rows = taskAllocationMapper.selectByExample(example); + Set taskKeys = new LinkedHashSet<>(); + if (rows != null) { + for (TaskAllocation row : rows) { + if (TaskAllocation.PUBLICATION_MARKER.equals(row.getModule())) { + publication.setConfigured(true); + } else if (row.getDisabledStatus() == null || row.getDisabledStatus() == 0) { + taskKeys.add(row.getModule()); + } + } + } + publication.setTaskKeys(new ArrayList<>(taskKeys)); + return new ResultEntity<>(HttpStatus.OK, "查询成功", publication); + } @PostMapping("/selectTaskAllocationByClassId") @ApiOperation("根据班级ID查询任务分配") @@ -106,15 +136,43 @@ public class TaskAllocationController { || !userId.equals(schoolClass.getCreatedBy())) { return new ResultEntity<>(HttpStatus.BAD_REQUEST, "只能分配自己创建教学班的任务"); } + if (taskAllocationList == null) { + taskAllocationList = Collections.emptyList(); + } + Set taskKeys = new LinkedHashSet<>(); + for (TaskAllocation allocation : taskAllocationList) { + if (allocation == null || TaskAllocation.PUBLICATION_MARKER.equals(allocation.getModule())) { + continue; + } + String taskKey = allocation.getModule() == null ? null : allocation.getModule().trim(); + if (taskKey != null && !taskKey.isEmpty() + && (trainingTaskService == null || trainingTaskService.getByTaskKey(taskKey) != null)) { + taskKeys.add(taskKey); + } + } + TaskAllocationExample taskAllocationExample = new TaskAllocationExample(); taskAllocationExample.createCriteria().andClassIdEqualTo(classId); taskAllocationMapper.deleteByExample(taskAllocationExample); - for (int i = 0; i < taskAllocationList.size(); i++) { - TaskAllocation taskAllocation = taskAllocationList.get(i); + TaskAllocation marker = new TaskAllocation(); + marker.setId(UUID.randomUUID().toString()); + marker.setClassId(classId); + marker.setSchoolId(schoolClass.getSchoolId()); + marker.setModule(TaskAllocation.PUBLICATION_MARKER); + marker.setDisabledStatus((byte) 1); + marker.setSort(0); + taskAllocationMapper.insert(marker); + + int sort = 1; + for (String taskKey : taskKeys) { + TaskAllocation taskAllocation = new TaskAllocation(); taskAllocation.setId(UUID.randomUUID().toString()); taskAllocation.setClassId(classId); - taskAllocation.setSchoolId(schoolId); + taskAllocation.setSchoolId(schoolClass.getSchoolId()); + taskAllocation.setModule(taskKey); + taskAllocation.setDisabledStatus((byte) 0); + taskAllocation.setSort(sort++); taskAllocationMapper.insert(taskAllocation); } return new ResultEntity<>(HttpStatus.OK, "修改成功"); diff --git a/src/main/java/com/sztzjy/linkCommerce/entity/TaskAllocation.java b/src/main/java/com/sztzjy/linkCommerce/entity/TaskAllocation.java index 2fa575c..1cb932e 100644 --- a/src/main/java/com/sztzjy/linkCommerce/entity/TaskAllocation.java +++ b/src/main/java/com/sztzjy/linkCommerce/entity/TaskAllocation.java @@ -7,6 +7,11 @@ import io.swagger.annotations.ApiModelProperty; * task_allocation */ public class TaskAllocation { + /** + * A marker persisted with a teaching-class publication setting. Its presence means the + * class has been explicitly configured, even when no actual task is selected. + */ + public static final String PUBLICATION_MARKER = "__TEACHING_CLASS_TASK_PUBLICATION__"; @ApiModelProperty(notes = "主键ID") private String id; @@ -72,4 +77,4 @@ public class TaskAllocation { public void setSort(Integer sort) { this.sort = sort; } -} \ No newline at end of file +} diff --git a/src/main/java/com/sztzjy/linkCommerce/entity/dto/TaskPublication.java b/src/main/java/com/sztzjy/linkCommerce/entity/dto/TaskPublication.java new file mode 100644 index 0000000..72935b9 --- /dev/null +++ b/src/main/java/com/sztzjy/linkCommerce/entity/dto/TaskPublication.java @@ -0,0 +1,26 @@ +package com.sztzjy.linkCommerce.entity.dto; + +import java.util.ArrayList; +import java.util.List; + +/** Teaching-class task publication state. */ +public class TaskPublication { + private boolean configured; + private List taskKeys = new ArrayList<>(); + + public boolean isConfigured() { + return configured; + } + + public void setConfigured(boolean configured) { + this.configured = configured; + } + + public List getTaskKeys() { + return taskKeys; + } + + public void setTaskKeys(List taskKeys) { + this.taskKeys = taskKeys == null ? new ArrayList<>() : taskKeys; + } +} diff --git a/src/main/java/com/sztzjy/linkCommerce/service/impl/TrainingTaskServiceImpl.java b/src/main/java/com/sztzjy/linkCommerce/service/impl/TrainingTaskServiceImpl.java index 9d79d25..e25023b 100644 --- a/src/main/java/com/sztzjy/linkCommerce/service/impl/TrainingTaskServiceImpl.java +++ b/src/main/java/com/sztzjy/linkCommerce/service/impl/TrainingTaskServiceImpl.java @@ -4,11 +4,14 @@ import com.alibaba.fastjson.JSON; import com.sztzjy.linkCommerce.config.security.JwtUser; import com.sztzjy.linkCommerce.entity.SchoolClass; import com.sztzjy.linkCommerce.entity.SchoolClassExample; +import com.sztzjy.linkCommerce.entity.TaskAllocation; +import com.sztzjy.linkCommerce.entity.TaskAllocationExample; import com.sztzjy.linkCommerce.entity.TeachingClassStudent; import com.sztzjy.linkCommerce.entity.TrainingTask; import com.sztzjy.linkCommerce.entity.TrainingTaskClassConfig; import com.sztzjy.linkCommerce.entity.importDto.TrainingTaskImportDTO; import com.sztzjy.linkCommerce.mapper.SchoolClassMapper; +import com.sztzjy.linkCommerce.mapper.TaskAllocationMapper; import com.sztzjy.linkCommerce.mapper.TeachingClassStudentMapper; import com.sztzjy.linkCommerce.mapper.TrainingTaskClassConfigMapper; import com.sztzjy.linkCommerce.mapper.TrainingTaskMapper; @@ -26,8 +29,10 @@ import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.UUID; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -48,6 +53,9 @@ public class TrainingTaskServiceImpl implements TrainingTaskService { @Autowired public TeachingClassStudentMapper teachingClassStudentMapper; + @Autowired(required = false) + public TaskAllocationMapper taskAllocationMapper; + @Autowired(required = false) public StudentTeachingClassResolver studentTeachingClassResolver; @@ -284,6 +292,10 @@ public class TrainingTaskServiceImpl implements TrainingTaskService { String normalizedTaskKey = StringUtils.trimToEmpty(taskKey); TrainingTask defaultTask = trainingTaskMapper.selectByTaskKey(normalizedTaskKey); if (StringUtils.isNotBlank(teachingClassId)) { + Set publishedTaskKeys = getPublishedTaskKeys(teachingClassId); + if (publishedTaskKeys != null && !publishedTaskKeys.contains(normalizedTaskKey)) { + return null; + } ensureClassTasksInitialized(teachingClassId, trainingTaskMapper.selectList(null, null, null), null); TrainingTaskClassConfig classTask = trainingTaskClassConfigMapper.selectByTeachingClassAndTaskKey(teachingClassId, normalizedTaskKey); if (classTask != null) { @@ -310,7 +322,39 @@ public class TrainingTaskServiceImpl implements TrainingTaskService { return filterEnabled(sortTasks(defaults), enabledOnly); } List classTasks = ensureClassTasksInitialized(teachingClassId, defaults, null); - return filterEnabled(toTasks(classTasks), enabledOnly); + List tasks = filterEnabled(toTasks(classTasks), enabledOnly); + Set publishedTaskKeys = getPublishedTaskKeys(teachingClassId); + if (publishedTaskKeys == null) { + return tasks; + } + return tasks.stream() + .filter(task -> publishedTaskKeys.contains(task.getTaskKey())) + .collect(Collectors.toList()); + } + + /** + * @return null when this teaching class has never been configured (default: all tasks), + * otherwise the explicitly published task keys, which may be empty. + */ + private Set getPublishedTaskKeys(String teachingClassId) { + if (taskAllocationMapper == null || StringUtils.isBlank(teachingClassId)) { + return null; + } + TaskAllocationExample example = new TaskAllocationExample(); + example.createCriteria().andClassIdEqualTo(teachingClassId); + List rows = taskAllocationMapper.selectByExample(example); + boolean configured = false; + Set taskKeys = new LinkedHashSet<>(); + if (rows != null) { + for (TaskAllocation row : rows) { + if (TaskAllocation.PUBLICATION_MARKER.equals(row.getModule())) { + configured = true; + } else if (row.getDisabledStatus() == null || row.getDisabledStatus() == 0) { + taskKeys.add(row.getModule()); + } + } + } + return configured ? taskKeys : null; } private String requireStudentTeachingClass(JwtUser student) {