package com.sztzjy.linkCommerce.controller.stu; import com.sztzjy.linkCommerce.annotation.AnonymousAccess; import com.sztzjy.linkCommerce.entity.TaskAllocation; import com.sztzjy.linkCommerce.entity.TaskAllocationExample; import com.sztzjy.linkCommerce.mapper.TaskAllocationMapper; import com.sztzjy.linkCommerce.util.ResultEntity; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.UUID; @Api(tags = "任务分配相关") @RequestMapping("api/taskAllocation") @RestController public class TaskAllocationController { @Autowired TaskAllocationMapper taskAllocationMapper; @PostMapping("/selectTaskAllocationByClassId") @ApiOperation("根据班级ID查询任务分配") @AnonymousAccess public ResultEntity> selectTaskAllocationByClassId(@RequestParam String classId) { TaskAllocationExample taskAllocationExample = new TaskAllocationExample(); taskAllocationExample.createCriteria().andClassIdEqualTo(classId); taskAllocationExample.setOrderByClause("sort asc"); List taskAllocations = taskAllocationMapper.selectByExample(taskAllocationExample); if (taskAllocations == null || taskAllocations.isEmpty()) { TaskAllocationExample taskAllocationExampleAdmin = new TaskAllocationExample(); taskAllocationExample.createCriteria().andClassIdEqualTo("999999999"); taskAllocationExampleAdmin.setOrderByClause("sort asc"); taskAllocations = taskAllocationMapper.selectByExample(taskAllocationExampleAdmin); } return new ResultEntity<>(HttpStatus.OK, "查询成功", taskAllocations); } @PostMapping("/updateTaskAllocationByClassId") @ApiOperation("根据班级ID查询任务分配") @AnonymousAccess public ResultEntity updateTaskAllocationByClassId(@RequestBody List taskAllocationList, @RequestParam String classId, @RequestParam String schoolId) { if ("999999999".equals(schoolId) || "999999999".equals(classId)) { return new ResultEntity<>(HttpStatus.BAD_REQUEST, "超管数据无法修改"); } 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.setId(UUID.randomUUID().toString()); taskAllocation.setClassId(classId); taskAllocation.setSchoolId(schoolId); taskAllocationMapper.insert(taskAllocation); } return new ResultEntity<>(HttpStatus.OK, "修改成功"); } }