From 8458e64aab474c0fc2f49ae4ff22fb11ce5cf6e2 Mon Sep 17 00:00:00 2001
From: “djh” <“3298565835@qq.com”>
Date: 星期一, 11 十一月 2024 16:55:28 +0800
Subject: [PATCH] 批次新增学员查询条件,新增题目导入接口
---
exam-system/src/main/java/com/gkhy/exam/system/mapper/ExQuestionMapper.java | 2
exam-system/src/main/resources/mapper/system/ExStudentMapper.xml | 3
exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExQuestionServiceImpl.java | 164 ++++++++++++++++++++++++++++++++
exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExStudentServiceImpl.java | 25 +++++
exam-system/src/main/resources/mapper/system/ExQuestionMapper.xml | 12 ++
exam-admin/src/main/java/com/gkhy/exam/admin/controller/web/ExQuestionController.java | 12 ++
exam-system/src/main/java/com/gkhy/exam/system/service/ExStudentService.java | 2
exam-admin/src/main/java/com/gkhy/exam/admin/controller/web/ExStudentController.java | 14 ++
exam-admin/src/main/resources/application-guotai.yml | 4
exam-system/src/main/java/com/gkhy/exam/system/service/ExQuestionService.java | 5 +
10 files changed, 236 insertions(+), 7 deletions(-)
diff --git a/exam-admin/src/main/java/com/gkhy/exam/admin/controller/web/ExQuestionController.java b/exam-admin/src/main/java/com/gkhy/exam/admin/controller/web/ExQuestionController.java
index 9f70d58..139db25 100644
--- a/exam-admin/src/main/java/com/gkhy/exam/admin/controller/web/ExQuestionController.java
+++ b/exam-admin/src/main/java/com/gkhy/exam/admin/controller/web/ExQuestionController.java
@@ -14,6 +14,9 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
/**
* <p>
@@ -74,5 +77,14 @@
}
+ @RepeatSubmit
+ @Log(title = "题目管理", businessType = BusinessType.DELETE)
+ @ApiOperation(value = "导入题目")
+ @PostMapping("/upload")
+ public CommonResult uploadQuestion(@RequestParam("file")MultipartFile file) throws IOException {
+ return questionService.uploadQuestion(file);
+ }
+
+
}
diff --git a/exam-admin/src/main/java/com/gkhy/exam/admin/controller/web/ExStudentController.java b/exam-admin/src/main/java/com/gkhy/exam/admin/controller/web/ExStudentController.java
index cdab661..86dfd2a 100644
--- a/exam-admin/src/main/java/com/gkhy/exam/admin/controller/web/ExStudentController.java
+++ b/exam-admin/src/main/java/com/gkhy/exam/admin/controller/web/ExStudentController.java
@@ -37,13 +37,25 @@
@ApiOperation(value = "学员列表(分页)")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name = "pageNum", dataType = "int", required = false, value = "当前页,默认1"),
- @ApiImplicitParam(paramType = "query", name = "pageSize", dataType = "int", required = false, value = "每页数目,默认10")
+ @ApiImplicitParam(paramType = "query", name = "pageSize", dataType = "int", required = false, value = "每页数目,默认10"),
+ @ApiImplicitParam(paramType = "query", name = "duty", dataType = "String", required = false, value = "职务"),
+ @ApiImplicitParam(paramType = "query", name = "name", dataType = "String", required = false, value = "姓名")
})
@GetMapping("/list")
public CommonResult list(ExStudent student){
return CommonResult.success(studentService.selectStudentList(student));
}
+ @ApiOperation(value = "学员列表全选")
+ @ApiImplicitParams({
+ @ApiImplicitParam(paramType = "query", name = "duty", dataType = "String", required = false, value = "职务"),
+ @ApiImplicitParam(paramType = "query", name = "name", dataType = "String", required = false, value = "姓名")
+ })
+ @GetMapping("/list/checkAll")
+ public CommonResult checkAll(ExStudent student){
+ return CommonResult.success(studentService.selectStudentCheckAll(student));
+ }
+
@ApiOperation(value = "根据id获取学员信息")
@GetMapping(value = { "/{studentId}" })
public CommonResult getStudentInfo(@PathVariable(value = "studentId", required = true) Long studentId)
diff --git a/exam-admin/src/main/resources/application-guotai.yml b/exam-admin/src/main/resources/application-guotai.yml
index dabc604..184e13d 100644
--- a/exam-admin/src/main/resources/application-guotai.yml
+++ b/exam-admin/src/main/resources/application-guotai.yml
@@ -5,9 +5,9 @@
druid:
# 主库数据源
master:
- url: jdbc:mysql://127.0.0.1:6361/train_exam?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true&allowMultiQueries=true
+ url: jdbc:mysql://127.0.0.1:7006/train_exam?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true&allowMultiQueries=true
username: root
- password: G7r@5nQw*X2p%kZm
+ password: 2farwL3yPXfbH2AP
# 从库数据源
slave:
enabled: false
diff --git a/exam-system/src/main/java/com/gkhy/exam/system/mapper/ExQuestionMapper.java b/exam-system/src/main/java/com/gkhy/exam/system/mapper/ExQuestionMapper.java
index ec5d335..503a25b 100644
--- a/exam-system/src/main/java/com/gkhy/exam/system/mapper/ExQuestionMapper.java
+++ b/exam-system/src/main/java/com/gkhy/exam/system/mapper/ExQuestionMapper.java
@@ -121,4 +121,6 @@
* @return
*/
List<ExQuestion> selectQuestionByPaperId(Long paperId);
+
+ int saveBatch(List<ExQuestion> exQuestions);
}
diff --git a/exam-system/src/main/java/com/gkhy/exam/system/service/ExQuestionService.java b/exam-system/src/main/java/com/gkhy/exam/system/service/ExQuestionService.java
index d4105f9..257631c 100644
--- a/exam-system/src/main/java/com/gkhy/exam/system/service/ExQuestionService.java
+++ b/exam-system/src/main/java/com/gkhy/exam/system/service/ExQuestionService.java
@@ -2,8 +2,11 @@
import com.baomidou.mybatisplus.extension.service.IService;
import com.gkhy.exam.common.api.CommonPage;
+import com.gkhy.exam.common.api.CommonResult;
import com.gkhy.exam.system.domain.ExQuestion;
+import org.springframework.web.multipart.MultipartFile;
+import java.io.IOException;
import java.util.List;
import java.util.Map;
@@ -114,4 +117,6 @@
* @return
*/
List<ExQuestion> selectQuestionByPaperId(Long paperId);
+
+ CommonResult uploadQuestion(MultipartFile file) throws IOException;
}
diff --git a/exam-system/src/main/java/com/gkhy/exam/system/service/ExStudentService.java b/exam-system/src/main/java/com/gkhy/exam/system/service/ExStudentService.java
index 0ae0d21..57a6535 100644
--- a/exam-system/src/main/java/com/gkhy/exam/system/service/ExStudentService.java
+++ b/exam-system/src/main/java/com/gkhy/exam/system/service/ExStudentService.java
@@ -108,4 +108,6 @@
* @return
*/
List<TrainRecordVO> trainRecord(Long studentId);
+
+ List<ExStudent> selectStudentCheckAll(ExStudent student);
}
diff --git a/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExQuestionServiceImpl.java b/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExQuestionServiceImpl.java
index f083a6e..52bd136 100644
--- a/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExQuestionServiceImpl.java
+++ b/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExQuestionServiceImpl.java
@@ -5,7 +5,9 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.exam.common.api.CommonPage;
+import com.gkhy.exam.common.api.CommonResult;
import com.gkhy.exam.common.domain.entity.SysUser;
+import com.gkhy.exam.common.domain.model.LoginUserDetails;
import com.gkhy.exam.common.enums.PaperStudentStateEnum;
import com.gkhy.exam.common.enums.PrivatizeEnum;
import com.gkhy.exam.common.enums.QuestionTypeEnum;
@@ -23,15 +25,16 @@
import com.gkhy.exam.system.mapper.ExQuestionBankMapper;
import com.gkhy.exam.system.mapper.ExQuestionMapper;
import com.gkhy.exam.system.service.ExQuestionService;
+import org.apache.poi.ss.usermodel.*;
+import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
/**
* <p>
@@ -276,4 +279,157 @@
public List<ExQuestion> selectQuestionByPaperId(Long paperId) {
return baseMapper.selectQuestionByPaperId(paperId);
}
+
+ @Override
+ public CommonResult uploadQuestion(@NotNull MultipartFile file) throws IOException {
+ Workbook workbook = WorkbookFactory.create(file.getInputStream());
+ Sheet sheetAt = workbook.getSheetAt(0);
+ List<ExQuestion> exQuestions = new ArrayList<>();
+ LoginUserDetails loginUser = SecurityUtils.getLoginUser();
+ for (int i = 0; i <sheetAt.getLastRowNum(); i++) {
+ Row row = sheetAt.getRow(i + 1);
+ ExQuestion exQuestion = new ExQuestion();
+ if (row!=null){
+ exQuestion.setQuestionType((int)row.getCell(0).getNumericCellValue());
+ exQuestion.setBankId((long)row.getCell(1).getNumericCellValue());
+ exQuestion.setAnswer(row.getCell(2).getStringCellValue());
+ exQuestion.setTitle(row.getCell(3).getStringCellValue());
+ NhoooRootBean nhoooRootBean = new NhoooRootBean();
+ List<Items> items1 = new ArrayList<>();
+ String cellValue4 = getCellValue(row.getCell(4));
+ if (cellValue4!=null){
+ Items items = new Items();
+ items.setPrefix("A");
+ items.setContent(cellValue4);
+ items1.add(items);
+ }
+ String cellValue5 = getCellValue(row.getCell(5));
+ if (cellValue5!=null){
+ Items items = new Items();
+ items.setPrefix("B");
+ items.setContent(cellValue5);
+ items1.add(items);
+ }
+ String cellValue6 = getCellValue(row.getCell(6));
+ if (cellValue6!=null){
+ Items items = new Items();
+ items.setPrefix("C");
+ items.setContent(cellValue6);
+ items1.add(items);
+ }
+ String cellValue7 = getCellValue(row.getCell(7));
+ if (cellValue7!=null){
+ Items items = new Items();
+ items.setPrefix("D");
+ items.setContent(cellValue7);
+ items1.add(items);
+ }
+ String cellValue8 = getCellValue(row.getCell(8));
+ if (cellValue8!=null){
+ Items items = new Items();
+ items.setPrefix("E");
+ items.setContent(cellValue8);
+ items1.add(items);
+ }
+ String cellValue9 = getCellValue(row.getCell(8));
+ if (cellValue9!=null){
+ Items items = new Items();
+ items.setPrefix("F");
+ items.setContent(cellValue9);
+ items1.add(items);
+ }
+ String cellValue10 = getCellValue(row.getCell(10));
+ if (cellValue10!=null){
+ Items items = new Items();
+ items.setPrefix("G");
+ items.setContent(cellValue10);
+ items1.add(items);
+ }
+ String cellValue11 = getCellValue(row.getCell(11));
+ if (cellValue11!=null){
+ Items items = new Items();
+ items.setPrefix("H");
+ items.setContent(cellValue11);
+ items1.add(items);
+ }
+ nhoooRootBean.setAnalyze("");
+ nhoooRootBean.setItems(items1);
+ exQuestion.setContent(JSONObject.toJSONString(nhoooRootBean));
+ exQuestion.setPrivatize(0);
+ exQuestion.setCreateBy(loginUser.getUsername());
+ exQuestion.setCreateTime(LocalDateTime.now());
+ exQuestion.setUpdateBy(loginUser.getUsername());
+ exQuestion.setUpdateTime(LocalDateTime.now());
+ exQuestion.setCompanyId(loginUser.getUser().getCompanyId());
+ exQuestion.setStatus(0);
+ exQuestions.add(exQuestion);
+ }
+ }
+ int i = baseMapper.saveBatch(exQuestions);
+ if (i<1){
+ throw new ApiException("导入题目失败");
+ }
+ workbook.close();
+ return CommonResult.success();
+ }
+
+
+ private String getCellValue(Cell cell) {
+ if (cell == null) {
+ return null;
+ }
+ switch (cell.getCellType()) {
+ case STRING:
+ return cell.getStringCellValue();
+ case NUMERIC:
+ return String.valueOf(cell.getNumericCellValue());
+ case BOOLEAN:
+ return String.valueOf(cell.getBooleanCellValue());
+ case FORMULA:
+ return cell.getCellFormula();
+ default:
+ return null;
+ }
+ }
+
+ public class NhoooRootBean {
+
+ private String analyze;
+ private List<Items> itemsList;
+ public void setAnalyze(String analyze) {
+ this.analyze = analyze;
+ }
+ public String getAnalyze() {
+ return analyze;
+ }
+
+ public void setItems(List<Items> items) {
+ this.itemsList = items;
+ }
+ public List getItems() {
+ return itemsList;
+ }
+
+ }
+
+ public class Items {
+
+ private String prefix;
+ private String content;
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+ public String getContent() {
+ return content;
+ }
+
+ }
+
}
diff --git a/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExStudentServiceImpl.java b/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExStudentServiceImpl.java
index 15d920a..ff0174e 100644
--- a/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExStudentServiceImpl.java
+++ b/exam-system/src/main/java/com/gkhy/exam/system/service/impl/ExStudentServiceImpl.java
@@ -290,6 +290,31 @@
return trainRecordVOList;
}
+ @Override
+ public List<ExStudent> selectStudentCheckAll(ExStudent student) {
+ SysUser currentUser= SecurityUtils.getLoginUser().getUser();
+ if(!currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){
+ student.setCompanyId(currentUser.getCompanyId());
+ Map<String,Object> paramsMap=new HashMap<>();
+ if(currentUser.getUserType().equals(UserTypeEnum.DEPART_USER.getCode())) {//部门级用户
+ List<Long> workshopUserIds=userMapper.selectWorkshopUserIds(currentUser.getId());
+ if(workshopUserIds==null){
+ workshopUserIds=new ArrayList<>();
+ }
+ workshopUserIds.add(currentUser.getId());
+ paramsMap.put("createIds",workshopUserIds);
+ student.setParams(paramsMap);
+ }else if(currentUser.getUserType().equals(UserTypeEnum.WORKSHOP_USER.getCode())){//车间级用户
+ List<Long> workshopUserIds=new ArrayList<>();
+ workshopUserIds.add(currentUser.getId());
+ workshopUserIds.add(currentUser.getParentId());
+ paramsMap.put("createIds",workshopUserIds);
+ student.setParams(paramsMap);
+ }
+ }
+ return baseMapper.selectStudentList(student);
+ }
+
public ExStudent checkUserDataScope(Long studentId) {
if(studentId==null){
throw new ApiException("学员id为空!");
diff --git a/exam-system/src/main/resources/mapper/system/ExQuestionMapper.xml b/exam-system/src/main/resources/mapper/system/ExQuestionMapper.xml
index 86c2181..132c1fd 100644
--- a/exam-system/src/main/resources/mapper/system/ExQuestionMapper.xml
+++ b/exam-system/src/main/resources/mapper/system/ExQuestionMapper.xml
@@ -45,6 +45,18 @@
select id, question_type, bank_id, status, company_id,answer,title,privatize,content,version, create_by, create_time, update_by, update_time, remark
from ex_course
</sql>
+ <insert id="saveBatch">
+ INSERT INTO
+ `train_exam`.`ex_question`
+ ( `question_type`, `bank_id`, `company_id`, `status`, `answer`, `title`, `content`, `privatize`, `create_time`,
+ `create_by`, `update_time`, `update_by`, `remark`, `version`)
+ VALUES
+ <foreach collection="exQuestions" item="question" separator=",">
+ (#{question.questionType}, #{question.bankId}, #{question.companyId}, #{question.status}, #{question.answer},
+ #{question.title}, #{question.content}, #{question.privatize}, #{question.createTime}, #{question.createBy},
+ #{question.updateTime}, #{question.updateBy}, #{question.remark}, #{question.version})
+ </foreach>
+ </insert>
<select id="selectCountByBankId" resultType="integer">
diff --git a/exam-system/src/main/resources/mapper/system/ExStudentMapper.xml b/exam-system/src/main/resources/mapper/system/ExStudentMapper.xml
index ff0e4f1..2cb0b2b 100644
--- a/exam-system/src/main/resources/mapper/system/ExStudentMapper.xml
+++ b/exam-system/src/main/resources/mapper/system/ExStudentMapper.xml
@@ -72,6 +72,9 @@
<if test="createId != null">
AND s.create_id =#{createId}
</if>
+ <if test="duty != null">
+ AND s.duty =#{duty}
+ </if>
<if test="params.createIds != null and params.createIds != ''">
AND s.create_id in
<foreach collection="params.createIds" item="createId" open="(" separator="," close=")">
--
Gitblit v1.9.2