From 4f5952c0082ef451dbf2c7ac4c2fb6055cb02f38 Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Wed, 18 Aug 2021 11:58:00 +0800
Subject: [PATCH] 开始考试接口调用修改

---
 src/main/java/org/springblade/modules/apply/service/ApplyService.java                      |    3 
 src/main/java/org/springblade/modules/exam/controller/ExamSubjectChoicesController.java    |   23 ++++
 src/main/java/org/springblade/modules/system/mapper/DeptMapper.xml                         |  166 ++++++++++++++++++++-------------
 src/main/java/org/springblade/modules/apply/service/impl/ApplyServiceImpl.java             |    8 +
 src/main/java/org/springblade/modules/exam/service/ExamSubjectChoicesService.java          |    8 +
 src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java          |    4 
 src/main/java/org/springblade/modules/exam/service/impl/ExamSubjectChoicesServiceImpl.java |   52 ++++++++--
 src/main/java/org/springblade/modules/apply/controller/ApplyController.java                |   14 ++
 src/main/java/org/springblade/modules/exam/vo/ExamSubjectChoicesVO.java                    |   16 +++
 9 files changed, 210 insertions(+), 84 deletions(-)

diff --git a/src/main/java/org/springblade/modules/apply/controller/ApplyController.java b/src/main/java/org/springblade/modules/apply/controller/ApplyController.java
index 851b5e6..c6f1b8b 100644
--- a/src/main/java/org/springblade/modules/apply/controller/ApplyController.java
+++ b/src/main/java/org/springblade/modules/apply/controller/ApplyController.java
@@ -24,7 +24,9 @@
 import org.springblade.modules.apply.vo.ApplyPaPerVO;
 import org.springblade.modules.apply.vo.ApplyVO;
 import org.springblade.modules.exam.entity.ExamPaper;
+import org.springblade.modules.exam.entity.ExamScore;
 import org.springblade.modules.exam.service.ExamPaperService;
+import org.springblade.modules.exam.service.ExamScoreService;
 import org.springblade.modules.system.entity.User;
 import org.springblade.modules.system.service.IUserService;
 import org.springframework.web.bind.annotation.*;
@@ -50,6 +52,8 @@
 	private final ExamPaperService examPaperService;
 
 	private final IUserService userService;
+
+	private final ExamScoreService examScoreService;
 
 	/**
 	 * 自定义分页
@@ -618,8 +622,16 @@
 	 * @return
 	 */
 	@PostMapping("/updateApplyStatus")
-	public void updateApplyStatus(@RequestBody ApplyVO apply){
+	public ExamScore updateApplyStatus(@RequestBody ApplyVO apply){
 		applyService.updateApplyStatus(apply);
+		//新增考试成绩,没有成绩数据,待提交答题后更新数据
+		ExamScore examScore = new ExamScore();
+		examScore.setExamId(apply.getExamId().toString());
+		examScore.setUserId(apply.getUserId().toString());
+		examScore.setExamTime(new Date());
+		//新增
+		examScoreService.save(examScore);
+		return examScore;
 	}
 
 
diff --git a/src/main/java/org/springblade/modules/apply/service/ApplyService.java b/src/main/java/org/springblade/modules/apply/service/ApplyService.java
index fa69a98..4ecf6bb 100644
--- a/src/main/java/org/springblade/modules/apply/service/ApplyService.java
+++ b/src/main/java/org/springblade/modules/apply/service/ApplyService.java
@@ -8,6 +8,7 @@
 import org.springblade.modules.apply.excel.ApplyInfoExcel;
 import org.springblade.modules.apply.vo.ApplyPaPerVO;
 import org.springblade.modules.apply.vo.ApplyVO;
+import org.springblade.modules.exam.entity.ExamScore;
 
 import java.util.List;
 import java.util.Map;
@@ -108,7 +109,7 @@
 	 * @param apply 报名信息,包含userId,applyid
 	 * @return
 	 */
-    void updateApplyStatus(ApplyVO apply);
+	void updateApplyStatus(ApplyVO apply);
 
 	/**
 	 * 查询报名信息,取最新的一条(即当前userId,)applyId最大的一条记录
diff --git a/src/main/java/org/springblade/modules/apply/service/impl/ApplyServiceImpl.java b/src/main/java/org/springblade/modules/apply/service/impl/ApplyServiceImpl.java
index f331ac2..3e29119 100644
--- a/src/main/java/org/springblade/modules/apply/service/impl/ApplyServiceImpl.java
+++ b/src/main/java/org/springblade/modules/apply/service/impl/ApplyServiceImpl.java
@@ -20,7 +20,9 @@
 import org.springblade.modules.apply.vo.ApplyPaPerVO;
 import org.springblade.modules.apply.vo.ApplyVO;
 import org.springblade.modules.exam.entity.ExamPaper;
+import org.springblade.modules.exam.entity.ExamScore;
 import org.springblade.modules.exam.service.ExamPaperService;
+import org.springblade.modules.exam.service.ExamScoreService;
 import org.springblade.modules.system.entity.User;
 import org.springblade.modules.system.service.IUserService;
 import org.springblade.modules.training.entity.TrainingRegistration;
@@ -407,9 +409,11 @@
 	public void updateApplyStatus(ApplyVO apply) {
 		//正式考
 		if (apply.getExamType()==1){
+			Apply apply1 = new Apply();
+			apply1.setId(apply.getId());
 			//考试中
-			apply.setIsExam(3);
-			baseMapper.updateById(apply);
+			apply1.setIsExam(3);
+			baseMapper.updateById(apply1);
 		}
 		//模拟考
 		if (apply.getExamType()==2){
diff --git a/src/main/java/org/springblade/modules/exam/controller/ExamSubjectChoicesController.java b/src/main/java/org/springblade/modules/exam/controller/ExamSubjectChoicesController.java
index 8fb9cb8..ac671ab 100644
--- a/src/main/java/org/springblade/modules/exam/controller/ExamSubjectChoicesController.java
+++ b/src/main/java/org/springblade/modules/exam/controller/ExamSubjectChoicesController.java
@@ -146,6 +146,29 @@
 	}
 
 	/**
+	 * 获取下一题的题目,并判断上一题的答案,且返回上一题答题结果
+	 *
+	 * @param examSubjectChoices 选择题信息对象
+	 */
+	@GetMapping("/getSubjectResultInfo")
+	@ApiOperation(value = "详情", notes = "传入examSubjectChoices")
+	public R<ExamSubjectChoicesVO> getSubjectResultInfo(ExamSubjectChoicesVO examSubjectChoices) {
+		//查询下一题题目详情
+		ExamSubjectChoicesVO detail = examSubjectChoicesService.selectExamSubjectChoicesInfo(examSubjectChoices);
+		//判断当前题目的答题结果
+		if (examSubjectChoices.getPreSubJectId()!=null) {
+			if (null!=examSubjectChoices.getPreResult() && examSubjectChoices.getPreResult()!="" && !examSubjectChoices.getPreResult().equals("")) {
+				detail.setResult(examSubjectChoicesService.getAnswerResult(examSubjectChoices.getPreSubJectId(), examSubjectChoices.getPreResult()));
+			}else {
+				//无
+				detail.setResult(3);
+			}
+		}
+		//返回
+		return R.data(detail);
+	}
+
+	/**
 	 * 查询试卷包含的题目
 	 */
 	@GetMapping("/getEexPaperChoices")
diff --git a/src/main/java/org/springblade/modules/exam/service/ExamSubjectChoicesService.java b/src/main/java/org/springblade/modules/exam/service/ExamSubjectChoicesService.java
index 0fe5159..a88fe35 100644
--- a/src/main/java/org/springblade/modules/exam/service/ExamSubjectChoicesService.java
+++ b/src/main/java/org/springblade/modules/exam/service/ExamSubjectChoicesService.java
@@ -54,4 +54,12 @@
 	 * @param isCovered
 	 */
 	void importSubject(List<ExamSubjectExcel> data, Boolean isCovered);
+
+	/**
+	 * 判断当前题目的答题结果
+	 * @param preSubJectId 题目Id
+	 * @param preResult 提交的结果
+	 * @return
+	 */
+    Integer getAnswerResult(Long preSubJectId, String preResult);
 }
diff --git a/src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java b/src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java
index e556b9d..8b31768 100644
--- a/src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java
+++ b/src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java
@@ -185,8 +185,8 @@
 			}else {
 				examScore.setQualified(1);
 			}
-			//保存成绩数据
-			int i = baseMapper.insert(examScore);
+			//修改成绩数据
+			int i = baseMapper.updateById(examScore);
 			//修改考试状态
 
 			if (i>0){
diff --git a/src/main/java/org/springblade/modules/exam/service/impl/ExamSubjectChoicesServiceImpl.java b/src/main/java/org/springblade/modules/exam/service/impl/ExamSubjectChoicesServiceImpl.java
index db4688d..d8be14a 100644
--- a/src/main/java/org/springblade/modules/exam/service/impl/ExamSubjectChoicesServiceImpl.java
+++ b/src/main/java/org/springblade/modules/exam/service/impl/ExamSubjectChoicesServiceImpl.java
@@ -91,12 +91,6 @@
 				});
 				return true;
 			}
-			//内网数据同步
-			try {
-//				arg.test01(arg.url+"/examSubjectChoices/saveSubjectChoicesAndOption",examSubjectChoices);
-			} catch (Exception e) {
-				e.printStackTrace();
-			}
 		}else {
 			//修改
 			ExamSubjectChoices subjectChoices = new ExamSubjectChoices();
@@ -140,12 +134,6 @@
 					examSubjectOptionService.save(examSubjectOption);
 				});
 				return true;
-			}
-			//内网数据同步
-			try {
-//				arg.test01(arg.url+"/examSubjectChoices/saveSubjectChoicesAndOption",examSubjectChoices);
-			} catch (Exception e) {
-				e.printStackTrace();
 			}
 		}
 		return status;
@@ -302,4 +290,44 @@
 		});
 
 	}
+
+
+	/**
+	 * 判断当前题目的答题结果
+	 * @param preSubJectId 题目Id
+	 * @param preResult 提交的结果
+	 * @return
+	 */
+	@Override
+	public Integer getAnswerResult(Long preSubJectId, String preResult) {
+		//查询题目信息
+		ExamSubjectChoices choices = this.getById(preSubJectId);
+		//对比答案
+		if (choices.getChoicesType() == 2 || choices.getChoicesType() == 3){
+			//判断题逻辑
+			if (preResult.equals(choices.getAnswer())) {
+				return 1;
+			}else {
+				return 2;
+			}
+		}else if(choices.getChoicesType() == 0 || choices.getChoicesType() == 1){
+			//处理多选题的答案排序
+			String[] split = preResult.split(",");
+			StringBuilder builder = new StringBuilder();
+			for (String s : split) {
+				builder.append(s);
+			}
+			char[] arrayCh = builder.toString().toCharArray();
+			//利用数组帮助类自动排序
+			Arrays.sort(arrayCh);
+			String sub0 = Arrays.toString(arrayCh);
+			String sub = sub0.substring(1,sub0.length()-1).replaceAll(" ","");
+			if (sub.equals(choices.getAnswer())) {
+				return 1;
+			}else {
+				return 2;
+			}
+		}
+		return 2;
+	}
 }
diff --git a/src/main/java/org/springblade/modules/exam/vo/ExamSubjectChoicesVO.java b/src/main/java/org/springblade/modules/exam/vo/ExamSubjectChoicesVO.java
index d8867bf..0f322cc 100644
--- a/src/main/java/org/springblade/modules/exam/vo/ExamSubjectChoicesVO.java
+++ b/src/main/java/org/springblade/modules/exam/vo/ExamSubjectChoicesVO.java
@@ -19,4 +19,20 @@
 	private List<ExamSubjectOption> examSubjectOptions;
 
 	private String tmid;
+
+	/**
+	 * 上一题的题目id
+	 */
+	private Long preSubJectId;
+
+	/**
+	 * 上一题答题提交的结果
+	 */
+	private String preResult;
+
+
+	/**
+	 * 上一题的答题结果,对,错  1:对  2:错
+	 */
+	private Integer result;
 }
diff --git a/src/main/java/org/springblade/modules/system/mapper/DeptMapper.xml b/src/main/java/org/springblade/modules/system/mapper/DeptMapper.xml
index 49f4e2a..aed1aaf 100644
--- a/src/main/java/org/springblade/modules/system/mapper/DeptMapper.xml
+++ b/src/main/java/org/springblade/modules/system/mapper/DeptMapper.xml
@@ -159,80 +159,114 @@
 
     <!--懒加载获取部门树形结构(包含用户数据)app-->
     <select id="lazyTreeUserApp" resultType="org.springblade.modules.system.vo.DeptAndUserVO" >
-        select DISTINCT  * from (
-        (SELECT
-        dept.id,
-        dept.parent_id,
-        dept.dept_name AS label,
-        dept.id AS "key",
-        dept.id AS "value",
-        1 as idCardNo,
-        (
-        SELECT
-        CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
-        FROM
-        blade_dept
-        WHERE
-        parent_id = dept.id and dept.is_deleted = 0
-        ) AS "has_children"
-        FROM
-        blade_dept dept
-        left join
-        blade_user bu
-        on
-        bu.dept_id = dept.id
-        WHERE
-        dept.is_deleted = 0
-        and bu.is_deleted = 0
-        <if test="type==1">
+        select DISTINCT
+            c.id,
+            c.parent_id,
+            c.title,
+            c.value,
+            c.key,
+            (
+            SELECT
+            CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
+            FROM
+            blade_dept
+            where
+            id = c.parent_id
             and dept_category=1
-            AND dept.parent_id = "1413470343230877697"
-        </if>
-        <if test="type==2 or type==3">
-            and dept_category=2
-            AND dept.parent_id = "1123598813738675201"
-        </if>
-        <if test="type==4 and jurisdiction!=null and jurisdiction!=''">
-            and dept_category=1
-            AND dept.parent_id = "1413470343230877697"
-            and bu.jurisdiction = #{jurisdiction}
-        </if>
-        )
+            ) AS "has_children"
+        from (
+            (SELECT
+            dept.id,
+            dept.parent_id,
+            dept.dept_name AS label,
+            dept.id AS "key",
+            dept.id AS "value",
+            1 as idCardNo,
+            (
+                SELECT
+                CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
+                FROM
+                blade_dept
+                WHERE
+                parent_id = dept.id and dept.is_deleted = 0
+                ) AS "has_children"
+                FROM
+                blade_dept dept
+                left join
+                blade_user bu
+                on
+                bu.dept_id = dept.id
+                WHERE
+                dept.is_deleted = 0
+                and bu.is_deleted = 0
+                <if test="type==1">
+                    and dept_category=1
+                    AND dept.parent_id = "1413470343230877697"
+                </if>
+                <if test="type==2 or type==3">
+                    and dept_category=2
+                    AND dept.parent_id = "1123598813738675201"
+                </if>
+                <if test="type==4 and jurisdiction!=null and jurisdiction!=''">
+                    and dept_category=1
+                    AND dept.parent_id = "1413470343230877697"
+                    and bu.jurisdiction = #{jurisdiction}
+                </if>
+            )
 
-        union all
+            union all
 
-        (select
-        bu.id,
-        bu.dept_id  parent_id,
-        bu.real_name AS label,
-        bu.id AS "key",
-        bu.id AS "value",
-        bu.cardid as idCardNo,
-        0 as "has_children"
-        from blade_user bu
-        left join
-        blade_dept bd
-        on
-        bd.id = bu.dept_id
-        where 1=1
-        and bu.is_deleted = 0
-        <if test="type==1">
-            and dept_category=1
-        </if>
-        <if test="type==2 or type==3">
-            and dept_category=2
-        </if>
-        <if test="type==4 and jurisdiction!=null and jurisdiction!=''">
-            and dept_category=1
-            and bu.jurisdiction = #{jurisdiction}
-        </if>
-        )
+            (
+                select
+                bu.id,
+                bu.dept_id  parent_id,
+                bu.real_name AS label,
+                bu.id AS "key",
+                bu.id AS "value",
+                bu.cardid as idCardNo,
+                0 as "has_children"
+                from blade_user bu
+                left join
+                blade_dept bd
+                on
+                bd.id = bu.dept_id
+                where 1=1
+                and bu.is_deleted = 0
+                <if test="type==1">
+                    and dept_category=1
+                </if>
+                <if test="type==2 or type==3">
+                    and dept_category=2
+                </if>
+                <if test="type==4 and jurisdiction!=null and jurisdiction!=''">
+                    and dept_category=1
+                    and bu.jurisdiction = #{jurisdiction}
+                </if>
+            )
         )c
     </select>
 
     <!--懒加载获取部门树形结构(包含用户数据)-->
     <select id="lazyTreeUser" resultMap="treeNodeResultMap" >
-        select DISTINCT  * from (
+        select DISTINCT
+            c.id,
+            c.parent_id,
+            c.title,
+            c.value,
+            c.key,
+            (
+            SELECT
+            CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
+            FROM
+            blade_dept
+            where
+            id = c.parent_id
+            <if test="parentId!=null and parentId!=''">
+                and dept_category=1
+                AND id = #{parentId}
+            </if>
+            ) AS "has_children"
+        from (
             (SELECT
               dept.id,
               dept.parent_id,

--
Gitblit v1.9.3