feat: 控制教学班实训任务发布

main
chenyuan 4 weeks ago
parent 5dfb1a269a
commit 3c4db9849b

@ -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<TaskPublication> selectTaskPublicationByClassId(@RequestParam String classId) {
TaskPublication publication = new TaskPublication();
TaskAllocationExample example = new TaskAllocationExample();
example.createCriteria().andClassIdEqualTo(classId);
example.setOrderByClause("sort asc");
List<TaskAllocation> rows = taskAllocationMapper.selectByExample(example);
Set<String> 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<String> 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, "修改成功");

@ -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;
}
}
}

@ -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<String> taskKeys = new ArrayList<>();
public boolean isConfigured() {
return configured;
}
public void setConfigured(boolean configured) {
this.configured = configured;
}
public List<String> getTaskKeys() {
return taskKeys;
}
public void setTaskKeys(List<String> taskKeys) {
this.taskKeys = taskKeys == null ? new ArrayList<>() : taskKeys;
}
}

@ -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<String> 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<TrainingTaskClassConfig> classTasks = ensureClassTasksInitialized(teachingClassId, defaults, null);
return filterEnabled(toTasks(classTasks), enabledOnly);
List<TrainingTask> tasks = filterEnabled(toTasks(classTasks), enabledOnly);
Set<String> 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<String> getPublishedTaskKeys(String teachingClassId) {
if (taskAllocationMapper == null || StringUtils.isBlank(teachingClassId)) {
return null;
}
TaskAllocationExample example = new TaskAllocationExample();
example.createCriteria().andClassIdEqualTo(teachingClassId);
List<TaskAllocation> rows = taskAllocationMapper.selectByExample(example);
boolean configured = false;
Set<String> 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) {

Loading…
Cancel
Save