From 92b71ac07ad4e0b7282135cad0919a4be4ec1efb Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Thu, 29 Jul 2021 11:33:08 +0800
Subject: [PATCH] 考试成绩导入接口修改,查询接口修改

---
 src/main/java/org/springblade/modules/exam/entity/ExamScore.java                  |    7 -
 src/main/java/org/springblade/modules/exam/service/ExamScoreService.java          |   10 ++
 src/main/java/org/springblade/modules/exam/mapper/ExamScoreMapper.java            |    6 +
 src/main/java/org/springblade/modules/exam/excel/ExamScoreImporter.java           |   41 ++++++++++
 src/main/java/org/springblade/modules/exam/excel/ExamScoreExcel.java              |   55 +++++++++++++
 src/main/java/org/springblade/modules/exam/vo/ExamScoreVO.java                    |    5 +
 src/main/java/org/springblade/modules/exam/service/impl/ExamScoreServiceImpl.java |   31 +++++++
 src/main/java/org/springblade/modules/exam/mapper/ExamScoreMapper.xml             |   49 +++++++++---
 src/main/java/org/springblade/modules/exam/controller/ExamScoreController.java    |   34 ++++++++
 9 files changed, 216 insertions(+), 22 deletions(-)

diff --git a/src/main/java/org/springblade/modules/exam/controller/ExamScoreController.java b/src/main/java/org/springblade/modules/exam/controller/ExamScoreController.java
index 940ee48..ec5acfb 100644
--- a/src/main/java/org/springblade/modules/exam/controller/ExamScoreController.java
+++ b/src/main/java/org/springblade/modules/exam/controller/ExamScoreController.java
@@ -4,14 +4,21 @@
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import lombok.AllArgsConstructor;
+import org.springblade.core.excel.util.ExcelUtil;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.modules.exam.entity.ExamScore;
+import org.springblade.modules.exam.excel.ExamScoreExcel;
+import org.springblade.modules.exam.excel.ExamScoreImporter;
 import org.springblade.modules.exam.service.ExamScoreService;
 import org.springblade.modules.exam.vo.ExamScoreVO;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @author zhongrj
@@ -89,8 +96,8 @@
 				//不合格
 				examScore.setQualified(1);
 			}
-			int totalSocre = examScore.getLearnGrade()+examScore.getTheoryGrade();
-			examScore.setAllGrade(Math.round(totalSocre/2));
+//			int totalSocre = examScore.getLearnGrade()+examScore.getTheoryGrade();
+//			examScore.setAllGrade(Math.round(totalSocre/2));
 		}
 		return R.status(examScoreService.updateById(examScore));
 	}
@@ -125,4 +132,27 @@
 		//返回
 		return R.data(detail);
 	}
+
+	/**
+	 * 导入实操成绩
+	 * @param isCovered 1 覆盖  0不覆盖
+	 * @return
+	 */
+	@PostMapping("import-examScore")
+	@ApiOperation(value = "导入实操成绩", notes = "传入excel")
+	public R importExamScore(MultipartFile file, Integer isCovered) {
+		ExamScoreImporter examScoreImporter = new ExamScoreImporter(examScoreService, false);
+		ExcelUtil.save(file, examScoreImporter, ExamScoreExcel.class);
+		return R.success("操作成功");
+	}
+
+	/**
+	 * 导出模板
+	 */
+	@GetMapping("export-template")
+	@ApiOperation(value = "导出模板")
+	public void exportUser(HttpServletResponse response) {
+		List<ExamScoreExcel> list = new ArrayList<>();
+		ExcelUtil.export(response, "实操成绩数据模板", "实操成绩数据表", list, ExamScoreExcel.class);
+	}
 }
diff --git a/src/main/java/org/springblade/modules/exam/entity/ExamScore.java b/src/main/java/org/springblade/modules/exam/entity/ExamScore.java
index dbf54eb..ca6d66f 100644
--- a/src/main/java/org/springblade/modules/exam/entity/ExamScore.java
+++ b/src/main/java/org/springblade/modules/exam/entity/ExamScore.java
@@ -55,13 +55,6 @@
 
 
 	/**
-	 * 考试类型 0:正式考试  1: 模拟考试  2:在线联系  3:调查问卷
-	 */
-//	@TableField("exam_type")
-//	private Integer examType;
-
-
-	/**
 	 * 考试人员所属公司名称id
 	 */
 	private String company;
diff --git a/src/main/java/org/springblade/modules/exam/excel/ExamScoreExcel.java b/src/main/java/org/springblade/modules/exam/excel/ExamScoreExcel.java
new file mode 100644
index 0000000..35c7b2e
--- /dev/null
+++ b/src/main/java/org/springblade/modules/exam/excel/ExamScoreExcel.java
@@ -0,0 +1,55 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.exam.excel;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import com.alibaba.excel.annotation.write.style.ContentRowHeight;
+import com.alibaba.excel.annotation.write.style.HeadRowHeight;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * ExamPaymentExcel
+ * @author zhongrj
+ * @since 2021-07-29
+ */
+@Data
+@ColumnWidth(25)
+@HeadRowHeight(20)
+@ContentRowHeight(18)
+public class ExamScoreExcel implements Serializable {
+	private static final long serialVersionUID = 1L;
+
+
+	@ColumnWidth(20)
+	@ExcelProperty("姓名")
+	private String name;
+
+
+	@ColumnWidth(25)
+	@ExcelProperty("身份证号码")
+	private String idCardNo;
+
+
+	@ColumnWidth(15)
+	@ExcelProperty("实操得分")
+	private Integer learnGrade;
+
+
+}
diff --git a/src/main/java/org/springblade/modules/exam/excel/ExamScoreImporter.java b/src/main/java/org/springblade/modules/exam/excel/ExamScoreImporter.java
new file mode 100644
index 0000000..61b6d08
--- /dev/null
+++ b/src/main/java/org/springblade/modules/exam/excel/ExamScoreImporter.java
@@ -0,0 +1,41 @@
+/*
+ *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
+ *
+ *  Redistributions of source code must retain the above copyright notice,
+ *  this list of conditions and the following disclaimer.
+ *  Redistributions in binary form must reproduce the above copyright
+ *  notice, this list of conditions and the following disclaimer in the
+ *  documentation and/or other materials provided with the distribution.
+ *  Neither the name of the dreamlu.net developer nor the names of its
+ *  contributors may be used to endorse or promote products derived from
+ *  this software without specific prior written permission.
+ *  Author: Chill 庄骞 (smallchill@163.com)
+ */
+package org.springblade.modules.exam.excel;
+
+import lombok.RequiredArgsConstructor;
+import org.springblade.core.excel.support.ExcelImporter;
+import org.springblade.modules.exam.service.ExamScoreService;
+
+import java.util.List;
+
+/**
+ * 实操成绩导入类
+ *
+ * @author zhongrj
+ * @since 2021-07-29
+ */
+@RequiredArgsConstructor
+public class ExamScoreImporter implements ExcelImporter<ExamScoreExcel> {
+
+	private final ExamScoreService service;
+	private final Boolean isCovered;
+
+	@Override
+	public void save(List<ExamScoreExcel> data) {
+		service.importExamScore(data, isCovered);
+	}
+}
diff --git a/src/main/java/org/springblade/modules/exam/mapper/ExamScoreMapper.java b/src/main/java/org/springblade/modules/exam/mapper/ExamScoreMapper.java
index 84fe425..1875259 100644
--- a/src/main/java/org/springblade/modules/exam/mapper/ExamScoreMapper.java
+++ b/src/main/java/org/springblade/modules/exam/mapper/ExamScoreMapper.java
@@ -31,4 +31,10 @@
 	 */
 	ExamScoreVO selectExamScoreInfo(@Param("examScore") ExamScore examScore);
 
+	/**
+	 * 根据身份证号导入实操成绩
+	 * @param idCardNo 身份证号
+	 * @return
+	 */
+    ExamScore getExamScoreInfoByIdCardNo(@Param("idCardNo")String idCardNo);
 }
diff --git a/src/main/java/org/springblade/modules/exam/mapper/ExamScoreMapper.xml b/src/main/java/org/springblade/modules/exam/mapper/ExamScoreMapper.xml
index d4cec07..1beef9d 100644
--- a/src/main/java/org/springblade/modules/exam/mapper/ExamScoreMapper.xml
+++ b/src/main/java/org/springblade/modules/exam/mapper/ExamScoreMapper.xml
@@ -5,31 +5,40 @@
     <!--考试成绩分页信息-->
     <select id="selectExamScorePage" resultType="org.springblade.modules.exam.vo.ExamScoreVO">
         SELECT
-         id,candidate_no candidateNo,theory_grade theoryGrade,ifnull(learn_grade,-1) learnGrade,all_grade,
-         exam_name examName,security_name securityName,exam_type examType,company,exam_time examTime,
-         all_score allScore,exam_end_time examEndTime,qualified
+         es.id,es.theory_grade theoryGrade,ifnull(learn_grade,-1) learnGrade,
+         exam_name examName,bu.real_name securityName,company,exam_time examTime,
+         all_score allScore,exam_end_time examEndTime,qualified,
+         bd.dept_name companyName
         FROM
-            exam_score
+            exam_score es
+        left join
+            blade_user bu
+        on
+            es.user_id = bu.id
+        left join
+            blade_dept bd
+        on
+            bd.id = es.company
         WHERE
             1=1
         <if test="examScore.examName!=null and  examScore.examName!=''">
-            and exam_name like concat('%', #{examScore.examName},'%')
+            and es.exam_name like concat('%', #{examScore.examName},'%')
         </if>
-        <if test="examScore.company!=null and  examScore.company!=''">
-            and company like concat('%', #{examScore.company},'%')
+        <if test="examScore.companyName!=null and  examScore.companyName!=''">
+            and bd.dept_name like concat('%', #{examScore.companyName},'%')
         </if>
         <if test="examScore.securityName!=null and  examScore.securityName!=''">
-            and security_name like concat('%', #{examScore.securityName},'%')
+            and bu.real_name like concat('%', #{examScore.securityName},'%')
         </if>
         <if test="examScore.userId!=null and  examScore.userId!=''">
-            and user_id = #{examScore.userId}
+            and es.user_id = #{examScore.userId}
         </if>
         <if test="examScore.candidateNo!=null and  examScore.candidateNo!=''">
-            and candidate_no = #{examScore.candidateNo}
+            and es.candidate_no = #{examScore.candidateNo}
         </if>
-<!--        <if test="examScore.examType!=null">-->
-<!--            and exam_type = #{examScore.examType}-->
-<!--        </if>-->
+        <if test="examScore.qualified!=null">
+            and es.qualified = #{examScore.qualified}
+        </if>
     </select>
 
     <!--考试成绩详情信息-->
@@ -46,4 +55,18 @@
             and id = #{examScore.id}
         </if>
     </select>
+
+    <!---->
+    <select id="getExamScoreInfoByIdCardNo" resultType="org.springblade.modules.exam.entity.ExamScore">
+        select
+            es.*
+        from
+            exam_score es
+        left join
+            blade_user bu
+        on
+            bu.id = es.user_id
+        where
+            bu.cardid = #{idCardNo}
+    </select>
 </mapper>
diff --git a/src/main/java/org/springblade/modules/exam/service/ExamScoreService.java b/src/main/java/org/springblade/modules/exam/service/ExamScoreService.java
index 1f8e3e8..9888350 100644
--- a/src/main/java/org/springblade/modules/exam/service/ExamScoreService.java
+++ b/src/main/java/org/springblade/modules/exam/service/ExamScoreService.java
@@ -3,7 +3,10 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.springblade.modules.exam.entity.ExamScore;
+import org.springblade.modules.exam.excel.ExamScoreExcel;
 import org.springblade.modules.exam.vo.ExamScoreVO;
+
+import java.util.List;
 
 /**
  * 考试成绩服务类
@@ -32,4 +35,11 @@
 	 * @return
 	 */
 	Boolean saveExamScore(ExamScoreVO examScore);
+
+	/**
+	 * 导入实操成绩
+	 * @param examScoreExcelList
+	 * @param isCovered 是否覆盖
+	 */
+    void importExamScore(List<ExamScoreExcel> examScoreExcelList, Boolean isCovered);
 }
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 617bc0e..f1b71e7 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
@@ -7,6 +7,7 @@
 import org.springblade.modules.exam.entity.ExamExaminationSubject;
 import org.springblade.modules.exam.entity.ExamPaper;
 import org.springblade.modules.exam.entity.ExamScore;
+import org.springblade.modules.exam.excel.ExamScoreExcel;
 import org.springblade.modules.exam.mapper.ExamScoreMapper;
 import org.springblade.modules.exam.service.ExamPaperService;
 import org.springblade.modules.exam.service.ExamScoreService;
@@ -17,6 +18,8 @@
 
 import java.util.Arrays;
 import java.util.List;
+
+import static com.bstek.ureport.expression.model.condition.Join.and;
 
 /**
  * 考试成绩服务实现类
@@ -120,4 +123,32 @@
 		//返回结果
 		return false;
 	}
+
+	/**
+	 * 导入实操成绩
+	 * @param examScoreExcelList
+	 * @param isCovered 是否覆盖
+	 */
+	@Override
+	public void importExamScore(List<ExamScoreExcel> examScoreExcelList, Boolean isCovered) {
+		if (examScoreExcelList.size()>0){
+			examScoreExcelList.forEach(examScoreExcel -> {
+				if (null!=examScoreExcel.getLearnGrade() && null!=examScoreExcel.getIdCardNo() && examScoreExcel.getIdCardNo()!=""){
+					ExamScore examScore = baseMapper.getExamScoreInfoByIdCardNo(examScoreExcel.getIdCardNo());
+					if (null!=examScore) {
+						examScore.setLearnGrade(examScoreExcel.getLearnGrade());
+						if (examScore.getTheoryGrade() >= 60 && examScore.getLearnGrade() >= 60) {
+							//合格
+							examScore.setQualified(0);
+						} else {
+							//不合格
+							examScore.setQualified(1);
+						}
+						//更新成绩数据
+						baseMapper.updateById(examScore);
+					}
+				}
+			});
+		}
+	}
 }
diff --git a/src/main/java/org/springblade/modules/exam/vo/ExamScoreVO.java b/src/main/java/org/springblade/modules/exam/vo/ExamScoreVO.java
index 89b631d..e1189f0 100644
--- a/src/main/java/org/springblade/modules/exam/vo/ExamScoreVO.java
+++ b/src/main/java/org/springblade/modules/exam/vo/ExamScoreVO.java
@@ -16,6 +16,11 @@
 	private static final long serialVersionUID = 1L;
 
 	/**
+	 * 公司名称
+	 */
+	private String companyName;
+
+	/**
 	 * 试卷id
 	 */
 	private Long papersId;

--
Gitblit v1.9.3