|
@@ -1,8 +1,10 @@
|
|
package cn.iselab.mooctest.site.web.ctrl;
|
|
package cn.iselab.mooctest.site.web.ctrl;
|
|
|
|
|
|
import cn.iselab.mooctest.site.common.constant.UrlConstants;
|
|
import cn.iselab.mooctest.site.common.constant.UrlConstants;
|
|
|
|
+import cn.iselab.mooctest.site.models.CaseExtends;
|
|
import cn.iselab.mooctest.site.models.UserStarCase;
|
|
import cn.iselab.mooctest.site.models.UserStarCase;
|
|
import cn.iselab.mooctest.site.models.instancePermission.ExamPermission;
|
|
import cn.iselab.mooctest.site.models.instancePermission.ExamPermission;
|
|
|
|
+import cn.iselab.mooctest.site.service.Exam2CaseService;
|
|
import cn.iselab.mooctest.site.service.UserStarCaseService;
|
|
import cn.iselab.mooctest.site.service.UserStarCaseService;
|
|
import cn.iselab.mooctest.site.service.fromKibug.CaseTakeService;
|
|
import cn.iselab.mooctest.site.service.fromKibug.CaseTakeService;
|
|
import cn.iselab.mooctest.site.web.data.SearchConditionVO;
|
|
import cn.iselab.mooctest.site.web.data.SearchConditionVO;
|
|
@@ -34,6 +36,7 @@ import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.validation.constraints.NotNull;
|
|
import javax.validation.constraints.NotNull;
|
|
import java.util.Comparator;
|
|
import java.util.Comparator;
|
|
@@ -48,6 +51,9 @@ import java.util.Map;
|
|
public class CaseController extends BaseSearchController {
|
|
public class CaseController extends BaseSearchController {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ private Exam2CaseService exam2CaseService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
private CaseLogic caseLogic;
|
|
private CaseLogic caseLogic;
|
|
@Autowired
|
|
@Autowired
|
|
private ExamService examService;
|
|
private ExamService examService;
|
|
@@ -69,13 +75,12 @@ public class CaseController extends BaseSearchController {
|
|
Long userId;
|
|
Long userId;
|
|
if (isPublic == null || isPublic) {
|
|
if (isPublic == null || isPublic) {
|
|
userId = null;
|
|
userId = null;
|
|
- }
|
|
|
|
- else {
|
|
|
|
|
|
+ } else {
|
|
userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
}
|
|
}
|
|
Sort sortById = new Sort(Sort.Direction.DESC, "id");
|
|
Sort sortById = new Sort(Sort.Direction.DESC, "id");
|
|
Pageable pageable = PageRequest.of(Integer.parseInt(activePage) - 1, Integer.parseInt(rowsOnPage), sortById);
|
|
Pageable pageable = PageRequest.of(Integer.parseInt(activePage) - 1, Integer.parseInt(rowsOnPage), sortById);
|
|
- return caseLogic.searchCases(isPublic, userId, null, null,keyword, pageable);
|
|
|
|
|
|
+ return caseLogic.searchCases(isPublic, userId, null, null, keyword, pageable);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -93,7 +98,7 @@ public class CaseController extends BaseSearchController {
|
|
if (isPublic == null || isPublic) {
|
|
if (isPublic == null || isPublic) {
|
|
userId = null;
|
|
userId = null;
|
|
}
|
|
}
|
|
- return caseLogic.searchCases(isPublic, userId,extraCondition,excludeCondition, keyword,
|
|
|
|
|
|
+ return caseLogic.searchCases(isPublic, userId, extraCondition, excludeCondition, keyword,
|
|
pageable);
|
|
pageable);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -113,9 +118,9 @@ public class CaseController extends BaseSearchController {
|
|
if (!SecurityUtils.getSubject().isPermitted(new CasePermission(permissionStr))) {
|
|
if (!SecurityUtils.getSubject().isPermitted(new CasePermission(permissionStr))) {
|
|
throw new UnauthenticatedException("forbidden");
|
|
throw new UnauthenticatedException("forbidden");
|
|
}
|
|
}
|
|
- CaseGraphDTO caseGraph = caseLogic.saveGraph(caseGraphDTO);
|
|
|
|
|
|
+ CaseGraphDTO caseGraph = caseLogic.saveGraph(caseGraphDTO);
|
|
//修改caseGraph后执行缓存失效
|
|
//修改caseGraph后执行缓存失效
|
|
- if(caseGraph != null){
|
|
|
|
|
|
+ if (caseGraph != null) {
|
|
generalCalculateScoreLogic.expireMetaNode(caseGraph.getCaseId());
|
|
generalCalculateScoreLogic.expireMetaNode(caseGraph.getCaseId());
|
|
}
|
|
}
|
|
return caseGraph;
|
|
return caseGraph;
|
|
@@ -130,12 +135,12 @@ public class CaseController extends BaseSearchController {
|
|
|
|
|
|
@RequestMapping(value = UrlConstants.API + "support/caseGraph", method = RequestMethod.GET)
|
|
@RequestMapping(value = UrlConstants.API + "support/caseGraph", method = RequestMethod.GET)
|
|
public CaseGraphDTO getSupportCaseGraph(@RequestParam(name = "caseId") Long caseId,
|
|
public CaseGraphDTO getSupportCaseGraph(@RequestParam(name = "caseId") Long caseId,
|
|
- @RequestParam(name = "examId", required = false) Long examId, @RequestParam(name =
|
|
|
|
|
|
+ @RequestParam(name = "examId", required = false) Long examId, @RequestParam(name =
|
|
"token") String token) throws Exception {
|
|
"token") String token) throws Exception {
|
|
String tmp = "123hsiawi456";
|
|
String tmp = "123hsiawi456";
|
|
- if(tmp.equals(token)){
|
|
|
|
|
|
+ if (tmp.equals(token)) {
|
|
return caseLogic.getGraph(caseId, examId);
|
|
return caseLogic.getGraph(caseId, examId);
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -148,7 +153,7 @@ public class CaseController extends BaseSearchController {
|
|
|
|
|
|
@RequiresPermissions("case:update")
|
|
@RequiresPermissions("case:update")
|
|
@RequestMapping(value = UrlConstants.API + "case/{caseId}", method = RequestMethod.PUT)
|
|
@RequestMapping(value = UrlConstants.API + "case/{caseId}", method = RequestMethod.PUT)
|
|
- public void updateCase(@RequestBody CaseExtendsVO caseExtendsVO,@PathVariable("caseId") Long caseId){
|
|
|
|
|
|
+ public void updateCase(@RequestBody CaseExtendsVO caseExtendsVO, @PathVariable("caseId") Long caseId) {
|
|
Long userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
Long userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
String permissionStr = userId.toString() + ":case:update:" + caseId.toString();
|
|
String permissionStr = userId.toString() + ":case:update:" + caseId.toString();
|
|
if (!SecurityUtils.getSubject().isPermitted(new CasePermission(permissionStr))) {
|
|
if (!SecurityUtils.getSubject().isPermitted(new CasePermission(permissionStr))) {
|
|
@@ -157,14 +162,40 @@ public class CaseController extends BaseSearchController {
|
|
caseLogic.update(caseExtendsVO, caseId);
|
|
caseLogic.update(caseExtendsVO, caseId);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
+ 管理员配置webIde开关接口
|
|
|
|
+ */
|
|
|
|
+ @RequiresRoles("admin")
|
|
|
|
+ @RequestMapping(value = UrlConstants.API + "exam/paper/case", method = RequestMethod.PUT)
|
|
|
|
+ public void configureCaseToWebIde(boolean isopen, long examId, long paperId, long caseId) throws Exception {
|
|
|
|
+ CaseExtendsVO caseExtends = caseLogic.getCaseExtends(caseId);
|
|
|
|
+ //判断题目类型 如果不是开发者或者tdd就报错
|
|
|
|
+ boolean is_develop = false;
|
|
|
|
+ boolean is_tdd = false;
|
|
|
|
+ if (caseExtends.getSubjectId() != null) {
|
|
|
|
+ if (caseExtends.getSubjectId() == 60) {
|
|
|
|
+ is_develop = true;
|
|
|
|
+ }
|
|
|
|
+ if (caseExtends.getSubjectId() == 51 || caseExtends.getSubjectId() == 78) {
|
|
|
|
+ is_tdd = true;
|
|
|
|
+ }
|
|
|
|
+ if (!(is_develop && is_tdd)) {
|
|
|
|
+ throw new IllegalArgumentException("题目类型有误");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ caseLogic.openOrCloseToWebIde(isopen, examId, paperId, caseId);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 管理员影藏公开的case
|
|
* 管理员影藏公开的case
|
|
|
|
+ *
|
|
* @param caseId
|
|
* @param caseId
|
|
*/
|
|
*/
|
|
@RequiresRoles(value = "admin")
|
|
@RequiresRoles(value = "admin")
|
|
@RequiresPermissions("case:update")
|
|
@RequiresPermissions("case:update")
|
|
@RequestMapping(value = UrlConstants.API + "case/hide/{caseId}", method = RequestMethod.PUT)
|
|
@RequestMapping(value = UrlConstants.API + "case/hide/{caseId}", method = RequestMethod.PUT)
|
|
- public CaseExtendsVO hideCase(@PathVariable("caseId") Long caseId){
|
|
|
|
|
|
+ public CaseExtendsVO hideCase(@PathVariable("caseId") Long caseId) {
|
|
Long userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
Long userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
String permissionStr = userId.toString() + ":case:update:" + caseId.toString();
|
|
String permissionStr = userId.toString() + ":case:update:" + caseId.toString();
|
|
if (!SecurityUtils.getSubject().isPermitted(new CasePermission(permissionStr))) {
|
|
if (!SecurityUtils.getSubject().isPermitted(new CasePermission(permissionStr))) {
|
|
@@ -272,19 +303,19 @@ public class CaseController extends BaseSearchController {
|
|
return caseLogic.getPythonCommunityExerciseCases(examId);
|
|
return caseLogic.getPythonCommunityExerciseCases(examId);
|
|
}
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = UrlConstants.API + "/pythonCommunity/exercise/case2exercise/{caseId}",method = RequestMethod.GET)
|
|
|
|
- public UserStarCaseVO getLatestCaseTake(@PathVariable("caseId")long caseId) throws Exception {
|
|
|
|
- Long userId = (Long)SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
|
|
|
|
+ @RequestMapping(value = UrlConstants.API + "/pythonCommunity/exercise/case2exercise/{caseId}", method = RequestMethod.GET)
|
|
|
|
+ public UserStarCaseVO getLatestCaseTake(@PathVariable("caseId") long caseId) throws Exception {
|
|
|
|
+ Long userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
if (userId == null) {
|
|
if (userId == null) {
|
|
throw new HttpBadRequestException("no user found, login first");
|
|
throw new HttpBadRequestException("no user found, login first");
|
|
}
|
|
}
|
|
- Map<Long,Long> examIdMap = userStarCaseService.getSubmitExams(userId,caseId);
|
|
|
|
|
|
+ Map<Long, Long> examIdMap = userStarCaseService.getSubmitExams(userId, caseId);
|
|
UserStarCaseVO userStarCaseVO = new UserStarCaseVO();
|
|
UserStarCaseVO userStarCaseVO = new UserStarCaseVO();
|
|
- if(examIdMap == null || examIdMap.size() == 0) {
|
|
|
|
- UserStarCase userStarCase = userStarCaseService.getUserStarCase(userId,caseId);
|
|
|
|
|
|
+ if (examIdMap == null || examIdMap.size() == 0) {
|
|
|
|
+ UserStarCase userStarCase = userStarCaseService.getUserStarCase(userId, caseId);
|
|
userStarCaseVO.setCaseId(caseId);
|
|
userStarCaseVO.setCaseId(caseId);
|
|
userStarCaseVO.setExamId(userStarCase.getExamId());
|
|
userStarCaseVO.setExamId(userStarCase.getExamId());
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
//收藏的题有提交记录,找最晚一次提交
|
|
//收藏的题有提交记录,找最晚一次提交
|
|
Long examId = examIdMap.entrySet().stream()
|
|
Long examId = examIdMap.entrySet().stream()
|
|
.max(Comparator.comparingLong(Map.Entry::getKey))
|
|
.max(Comparator.comparingLong(Map.Entry::getKey))
|