|
|
@@ -19,6 +19,7 @@ import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -52,32 +53,24 @@ public class ExamController extends BaseController {
|
|
|
Sort sortByStatus = new Sort(Sort.Direction.ASC, "status");
|
|
|
Sort sortById = new Sort(Sort.Direction.DESC, "id");
|
|
|
User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
|
|
|
+
|
|
|
if (queryBy.equals("organizer")) {
|
|
|
return examLogic.getExamList(user.getId(), type, status, keyword, new PageRequest(activePage - 1, rowsOnPage, sortById));
|
|
|
- } else if(queryBy.equals("participant")) {
|
|
|
+ } else if (queryBy.equals("participant")) {
|
|
|
return examLogic.getParticipantExamList(user.getId(), type, status, keyword, new PageRequest(activePage - 1, rowsOnPage, sortByStatus));
|
|
|
- } else{
|
|
|
+ } else if(queryBy.equals("assistManager")){
|
|
|
return examLogic.getAssistManagerExamList(user.getId(), type, status, keyword, new PageRequest(activePage - 1, rowsOnPage, sortByStatus));
|
|
|
+ } else{
|
|
|
+ return examLogic.getContestMentorExamList(user.getId(), type, status, keyword, new PageRequest(activePage - 1, rowsOnPage, sortByStatus));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @RequiresPermissions("tasks:view")
|
|
|
- @RequestMapping(value = "/api/test/exams", method = RequestMethod.GET)
|
|
|
- public List<ExamVO> getExams() {
|
|
|
- if (!SecurityUtils.getSubject().isPermitted("tasks:view")) {
|
|
|
- throw new UnauthorizedException("unauthorized");
|
|
|
- }
|
|
|
- String username = (String) SecurityUtils.getSubject().getPrincipals().getPrimaryPrincipal();
|
|
|
- return examLogic.getExamList(username);
|
|
|
- }
|
|
|
-
|
|
|
@RequiresPermissions("task:view")
|
|
|
@RequestMapping(value = "api/exam/{examId}", method = RequestMethod.GET)
|
|
|
public ExamVO getExamById(@PathVariable Long examId) {
|
|
|
User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
|
|
|
String permissionStr = user.getId().toString() + ":task:view:" + examId.toString();
|
|
|
boolean isOwner = SecurityUtils.getSubject().isPermitted(new TaskPermission(permissionStr));
|
|
|
-
|
|
|
if (isOwner) {
|
|
|
return examLogic.getExamById(examId);
|
|
|
} else {
|
|
|
@@ -105,6 +98,17 @@ public class ExamController extends BaseController {
|
|
|
}
|
|
|
|
|
|
@RequiresPermissions("task:update")
|
|
|
+ @RequestMapping(value = "api/exam2paper/{examId}/{paperId}", method = RequestMethod.DELETE)
|
|
|
+ public Boolean deleteExam2Paper(@PathVariable Long examId, @PathVariable Long paperId) {
|
|
|
+ User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
|
|
|
+ String examPermissionStr = user.getId().toString() + ":task:update:" + examId.toString();
|
|
|
+ if (!SecurityUtils.getSubject().isPermitted(new TaskPermission(examPermissionStr))) {
|
|
|
+ throw new UnauthorizedException("unauthorized");
|
|
|
+ }
|
|
|
+ return examLogic.deleteExam2Paper(examId, paperId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresPermissions("task:update")
|
|
|
@RequestMapping(value = "api/exam/{examId}", method = RequestMethod.PUT)
|
|
|
public ExamVO update(@PathVariable Long examId, @RequestBody ExamVO examVO) {
|
|
|
User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
|
|
|
@@ -123,6 +127,7 @@ public class ExamController extends BaseController {
|
|
|
public Page<AssignedTaskVO> getAssignedTaskByExamId(@RequestParam(name = "examId", required = false) Long examId,
|
|
|
@RequestParam(name = "sortOrder", required = false, defaultValue = "desc") String sortOrder,
|
|
|
@RequestParam(name = "sortBy", required = false, defaultValue = "score") String sortBy,
|
|
|
+ @RequestParam(name = "keyword", required = false, defaultValue = "") String keyword,
|
|
|
HttpServletRequest request) throws Exception {
|
|
|
User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
|
|
|
String examPermissionStr = user.getId().toString() + ":task:view:" + examId.toString();
|
|
|
@@ -134,7 +139,7 @@ public class ExamController extends BaseController {
|
|
|
|
|
|
boolean hasScorePermission = SecurityUtils.getSubject().isPermitted(new TaskPermission(user.getId().toString() + ":task:score:" + examId.toString()));
|
|
|
boolean needFilter = !hasScorePermission;
|
|
|
- return examLogic.getAssignedTasks(examId, needFilter, pageable);
|
|
|
+ return examLogic.getAssignedTasks(examId,keyword, needFilter, pageable);
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = UrlConstants.API + "exam/user", method = RequestMethod.GET)
|
|
|
@@ -157,25 +162,26 @@ public class ExamController extends BaseController {
|
|
|
return examLogic.getUsers(examId,needFilter,email,keyword,pageable);
|
|
|
}
|
|
|
|
|
|
- private Pageable getPageInfo(String sortOrder, String sortBy,HttpServletRequest request){
|
|
|
+ private Pageable getPageInfo(String sortOrder, String sortBy,HttpServletRequest request) {
|
|
|
String activePage = request.getHeader("activePage");
|
|
|
String rowsOnPage = request.getHeader("rowsOnPage");
|
|
|
if (activePage == null || rowsOnPage == null) {
|
|
|
throw new IllegalArgumentException("缺少分页信息");
|
|
|
}
|
|
|
Sort sort;
|
|
|
- if(sortOrder.equals("desc"))
|
|
|
- sort = new Sort(Sort.Direction.DESC,sortBy);
|
|
|
+ if (sortOrder.equals("desc"))
|
|
|
+ sort = new Sort(Sort.Direction.DESC, sortBy);
|
|
|
else
|
|
|
- sort = new Sort(Sort.Direction.ASC,sortBy);
|
|
|
+ sort = new Sort(Sort.Direction.ASC, sortBy);
|
|
|
|
|
|
return new PageRequest(Integer.parseInt(activePage) - 1, Integer.parseInt(rowsOnPage), sort);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@RequestMapping(value = UrlConstants.API + "score", method = RequestMethod.GET)
|
|
|
public ScoreVO getScoreByExamIdAndWorkerId(@RequestParam(name = "examId") Long examId) throws Exception {
|
|
|
User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
|
|
|
- examLogic.getExamByIdAndParticipantIdIfPermited(examId,user.getId());
|
|
|
+ examLogic.getExamByIdAndParticipantIdIfPermited(examId, user.getId());
|
|
|
return examLogic.getScoreBy(examId, user.getId());
|
|
|
}
|
|
|
|
|
|
@@ -208,4 +214,20 @@ public class ExamController extends BaseController {
|
|
|
return examLogic.updateStatutsForAllTask();
|
|
|
}
|
|
|
|
|
|
+ @RequestMapping(value = UrlConstants.API + "scoreExcel/{examId}", method = RequestMethod.GET)
|
|
|
+ public void getExamScoresOfExcel(@PathVariable("examId") Long examId,
|
|
|
+ HttpServletResponse response) throws Exception {
|
|
|
+ User user = (User) SecurityUtils.getSubject().getSession().getAttribute("User");
|
|
|
+
|
|
|
+ String permissionStrForOwner = user.getId().toString() + ":task:*:" + examId.toString();
|
|
|
+ String permissionStrForContestMentor = user.getId().toString() + ":task:view:" + examId.toString();
|
|
|
+
|
|
|
+ if (SecurityUtils.getSubject().isPermitted(new TaskPermission(permissionStrForOwner))) {
|
|
|
+ examLogic.exportExcelByOwner(response, examId);
|
|
|
+ } else if (SecurityUtils.getSubject().isPermitted(new TaskPermission(permissionStrForContestMentor))) {
|
|
|
+ examLogic.exportExcelByContestMentor(response, examId, user);
|
|
|
+ } else {
|
|
|
+ throw new UnauthorizedException("unthorized");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|