Просмотр исходного кода

试卷-获取当前登录人员的参与状态

honorfire 6 месяцев назад
Родитель
Сommit
44e2feb51d

+ 29 - 0
snowy-plugin/snowy-plugin-exam/snowy-plugin-exam-func/src/main/java/vip/xiaonuo/exam/controller/student/ExamPaperAnswerController.java

@@ -2,10 +2,12 @@ package vip.xiaonuo.exam.controller.student;
 
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.web.bind.annotation.*;
 import vip.xiaonuo.auth.core.pojo.SaBaseLoginUser;
+import vip.xiaonuo.auth.core.util.StpLoginUserUtil;
 import vip.xiaonuo.common.pojo.CommonResult;
 import vip.xiaonuo.exam.base.BaseApiController;
 import vip.xiaonuo.exam.domain.ExamPaperAnswer;
@@ -25,8 +27,11 @@ import vip.xiaonuo.exam.viewmodel.student.exam.ExamPaperReadVM;
 import vip.xiaonuo.exam.viewmodel.student.exam.ExamPaperSubmitVM;
 import vip.xiaonuo.exam.viewmodel.student.exampaper.ExamPaperAnswerPageVM;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.validation.Valid;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 @RestController("StudentExamPaperAnswerController")
 @RequestMapping(value = "/api/student/exampaper/answer")
@@ -119,5 +124,29 @@ public class ExamPaperAnswerController extends BaseApiController {
         return CommonResult.data(vm);
     }
 
+    /**
+     * 获取该试卷的完成状态
+     * */
+    @RequestMapping(value = "/getStatus", method = RequestMethod.GET)
+    public CommonResult<Map<String,Object>> getStatus(HttpServletRequest req) {
+        Map param=new HashMap<>();
+        Map result=new HashMap();
+        if(StringUtils.isEmpty(req.getParameter("examPaperId")))CommonResult.error("试卷id不能为空");
+        param.put("examPaperId", req.getParameter("examPaperId"));
+        param.put("userId", StpLoginUserUtil.getLoginUser().getId());
+        Map<String,Object> statusResult = examPaperAnswerService.getStatus(param);
+        //是否完成,0否1是
+        String isFinish="0";
+        String answerId="";
+        if(ObjectUtil.isNotEmpty(statusResult))
+        {
+            isFinish="1";
+            answerId= String.valueOf(statusResult.get("answerId"));
+        }
+        result.put("isFinish",isFinish);
+        result.put("answerId",answerId);
+        return CommonResult.data(result);
+    }
+
 
 }

+ 6 - 0
snowy-plugin/snowy-plugin-exam/snowy-plugin-exam-func/src/main/java/vip/xiaonuo/exam/mapper/ExamPaperAnswerMapper.java

@@ -10,6 +10,7 @@ import org.apache.ibatis.annotations.Param;
 
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 @Mapper
 public interface ExamPaperAnswerMapper extends BaseMapper<ExamPaperAnswer> {
@@ -23,4 +24,9 @@ public interface ExamPaperAnswerMapper extends BaseMapper<ExamPaperAnswer> {
     ExamPaperAnswer getByPidUid(@Param("pid") Integer paperId, @Param("uid") String uid);
 
     Page<ExamPaperAnswer> adminPage(@Param("bo") ExamPaperAnswerPageRequestVM requestVM,@Param("page") Page<ExamPaperAnswer> page);
+
+    /**
+     * 获取该试卷的完成状态
+     * */
+    Map<String,Object> getStatus(Map param);
 }

+ 15 - 0
snowy-plugin/snowy-plugin-exam/snowy-plugin-exam-func/src/main/java/vip/xiaonuo/exam/mapper/mapping/ExamPaperAnswerMapper.xml

@@ -263,5 +263,20 @@
       </if>
     </where>
   </select>
+  <select id="getStatus" resultType="java.util.Map">
+    SELECT
+      IFNULL(tepa."id",'') AS answerId,
+      IFNULL(tepa."exam_paper_id",'') AS paperId
+    FROM "t_exam_paper_answer" tepa
+    WHERE 1=1
+    <if test="userId !=null and userId != ''">
+      and tepa."create_user"=#{userId}
+    </if>
+    <if test="examPaperId !=null and examPaperId != ''">
+      and tepa."exam_paper_id"=#{examPaperId}
+    </if>
+    order by tepa."create_time" desc
+    LIMIT 1
+  </select>
 
 </mapper>

+ 6 - 0
snowy-plugin/snowy-plugin-exam/snowy-plugin-exam-func/src/main/java/vip/xiaonuo/exam/service/ExamPaperAnswerService.java

@@ -10,6 +10,7 @@ import vip.xiaonuo.exam.viewmodel.student.exam.ExamPaperSubmitVM;
 import vip.xiaonuo.exam.viewmodel.student.exampaper.ExamPaperAnswerPageVM;
 
 import java.util.List;
+import java.util.Map;
 
 public interface ExamPaperAnswerService extends BaseService<ExamPaperAnswer> {
 
@@ -52,4 +53,9 @@ public interface ExamPaperAnswerService extends BaseService<ExamPaperAnswer> {
     List<Integer> selectMothCount();
 
     Page<ExamPaperAnswer> adminPage(ExamPaperAnswerPageRequestVM requestVM);
+
+    /**
+     * 获取该试卷的完成状态
+     * */
+    Map<String,Object> getStatus(Map param);
 }

+ 10 - 0
snowy-plugin/snowy-plugin-exam/snowy-plugin-exam-func/src/main/java/vip/xiaonuo/exam/service/impl/ExamPaperAnswerServiceImpl.java

@@ -34,6 +34,7 @@ import vip.xiaonuo.exam.viewmodel.student.exampaper.ExamPaperAnswerPageVM;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 import static vip.xiaonuo.exam.domain.enums.ExamPaperTypeEnum.Task;
@@ -314,4 +315,13 @@ public class ExamPaperAnswerServiceImpl extends BaseServiceImpl<ExamPaperAnswer>
         page.setSearchCount(true); // 设置计算总记录数
         return examPaperAnswerMapper.adminPage(requestVM,page);
     }
+
+    /**
+     * 获取该试卷的完成状态
+     * */
+    @Override
+    public Map<String,Object> getStatus(Map param)
+    {
+        return examPaperAnswerMapper.getStatus(param);
+    }
 }