From a45e5619ac39ce8656d218b0eaebcdfad28bd3cd Mon Sep 17 00:00:00 2001 From: xiaoCJ <406612557@qq.com> Date: Tue, 13 Aug 2024 17:24:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=A1=88=E4=BE=8B=E9=A2=98?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CaseController.java | 32 +++ .../controller/TopicController.java | 59 ++++- .../controller/TrainingController.java | 18 ++ .../entity/dto/ObjectiveQuestionDto.java | 13 ++ .../money_management/entity/dto/TopicDto.java | 24 ++ .../mapper/ObjectiveQuestionMapper.java | 15 +- .../service/ObjectiveQuestionService.java | 27 +++ .../impl/ObjectiveQuestionServiceImpl.java | 210 ++++++++++++++++++ .../mapper/ObjectiveQuestionMapper.xml | 61 ++++- 9 files changed, 439 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/sztzjy/money_management/controller/TrainingController.java create mode 100644 src/main/java/com/sztzjy/money_management/entity/dto/ObjectiveQuestionDto.java create mode 100644 src/main/java/com/sztzjy/money_management/entity/dto/TopicDto.java create mode 100644 src/main/java/com/sztzjy/money_management/service/ObjectiveQuestionService.java create mode 100644 src/main/java/com/sztzjy/money_management/service/impl/ObjectiveQuestionServiceImpl.java diff --git a/src/main/java/com/sztzjy/money_management/controller/CaseController.java b/src/main/java/com/sztzjy/money_management/controller/CaseController.java index 968c5d4..e47ab8d 100644 --- a/src/main/java/com/sztzjy/money_management/controller/CaseController.java +++ b/src/main/java/com/sztzjy/money_management/controller/CaseController.java @@ -4,9 +4,11 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.sztzjy.money_management.annotation.AnonymousAccess; import com.sztzjy.money_management.entity.CaseInfo; +import com.sztzjy.money_management.entity.Chapter; import com.sztzjy.money_management.entity.ComCase; import com.sztzjy.money_management.entity.ComCaseExample; import com.sztzjy.money_management.mapper.CaseInfoMapper; +import com.sztzjy.money_management.mapper.ChapterMapper; import com.sztzjy.money_management.mapper.ComCaseMapper; import com.sztzjy.money_management.service.CaseService; import com.sztzjy.money_management.util.ResultEntity; @@ -35,6 +37,8 @@ public class CaseController { private CaseInfoMapper caseInfoMapper; @Autowired private ComCaseMapper comCaseMapper; + @Autowired + ChapterMapper chapterMapper; @PostMapping("/insertCase") @ApiOperation("新增案例,老师和管理员新增根据caseinfo中的publish区分") @@ -108,4 +112,32 @@ public class CaseController { PageInfo pageInfo = new PageInfo(caseInfoList); return new ResultEntity<PageInfo<CaseInfo>>(pageInfo); } + + @PostMapping("/insertKnowledge") + @ApiOperation("知识点新增") + @AnonymousAccess + private ResultEntity<HttpStatus> insertKnowledge(@ApiParam("请求头可能装不下,放对象,传ID和knowledge")@RequestBody Chapter chapter) { + Chapter newChapter = chapterMapper.selectByPrimaryKey(chapter.getChapterId()); + if (newChapter == null) { + return new ResultEntity<HttpStatus>(HttpStatus.INTERNAL_SERVER_ERROR, "服务器异常,请联系管理员!"); + } + newChapter.setKnowledge(chapter.getKnowledge()); + int i = chapterMapper.updateByPrimaryKeySelective(newChapter); + if (i <= 0) { + return new ResultEntity<HttpStatus>(HttpStatus.INTERNAL_SERVER_ERROR, "服务器异常,请联系管理员!"); + } + return new ResultEntity<HttpStatus>(HttpStatus.OK, "新增成功!"); + } + + + @PostMapping("/getKnowledge") + @ApiOperation("知识点展示") + @AnonymousAccess + private ResultEntity<String> getKnowledge(@RequestParam String chapterID) { + Chapter chapter = chapterMapper.selectByPrimaryKey(chapterID); + if (chapter == null) { + return null; + } + return new ResultEntity<>(chapter.getKnowledge()); + } } diff --git a/src/main/java/com/sztzjy/money_management/controller/TopicController.java b/src/main/java/com/sztzjy/money_management/controller/TopicController.java index 4783093..8d7e45c 100644 --- a/src/main/java/com/sztzjy/money_management/controller/TopicController.java +++ b/src/main/java/com/sztzjy/money_management/controller/TopicController.java @@ -5,7 +5,10 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.sztzjy.money_management.annotation.AnonymousAccess; import com.sztzjy.money_management.entity.ObjectiveQuestionWithBLOBs; +import com.sztzjy.money_management.entity.dto.ObjectiveQuestionDto; +import com.sztzjy.money_management.entity.dto.TopicDto; import com.sztzjy.money_management.mapper.ObjectiveQuestionMapper; +import com.sztzjy.money_management.service.ObjectiveQuestionService; import com.sztzjy.money_management.util.ResultEntity; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -14,8 +17,8 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; -import java.util.HashMap; import java.util.List; /** @@ -29,6 +32,9 @@ import java.util.List; public class TopicController { @Autowired private ObjectiveQuestionMapper objectiveQuestionMapper; + @Autowired + private ObjectiveQuestionService objectiveQuestionService; + @PostMapping("/insertSingleTopic") @ApiOperation("新增单个客观题") @@ -68,6 +74,23 @@ public class TopicController { return new ResultEntity<HttpStatus>(HttpStatus.OK, "新增成功!"); } + + @AnonymousAccess + @ApiOperation("本地excel导入试题") + @PostMapping("importTopicByLocal") + private ResultEntity<HttpStatus> importTopicByLocal(@RequestParam MultipartFile file, + @ApiParam("学校ID/999999999") @RequestParam String source, + @RequestParam(required = false) String chapterID, + @RequestParam(required = false) String chapterName, + @ApiParam("普通题库/金融智能/银行从业") @RequestParam String outLine, + @RequestParam(required = false) String subClass) throws Exception { + if (file == null) { + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "导入文件不能为空"); + } + return objectiveQuestionService.insertObjectiveByExcel(file, source, chapterID, chapterName, outLine, subClass); + } + + @PostMapping("/updateTopicById") @ApiOperation("编辑客观题") private ResultEntity<HttpStatus> updateTopicById(@RequestBody ObjectiveQuestionWithBLOBs objectiveQuestionWithBLOBs) { @@ -80,11 +103,11 @@ public class TopicController { } - @PostMapping("/deleteObjectiveBYId") - @ApiOperation("客观题单个删除") + @PostMapping("/deleteObjectiveBYList") + @ApiOperation("客观题删除") @AnonymousAccess - private ResultEntity<HttpStatus> deleteObjectiveBYId(@RequestParam String objectiveQuestionId) { - int i = objectiveQuestionMapper.deleteByPrimaryKey(objectiveQuestionId); + private ResultEntity<HttpStatus> deleteObjectiveBYList(@RequestBody List<String> objectiveQuestionId) { + int i = objectiveQuestionMapper.batchDelete(objectiveQuestionId); if (i > 0) { return new ResultEntity<HttpStatus>(HttpStatus.OK, "删除成功!"); } @@ -100,12 +123,11 @@ public class TopicController { } @PostMapping("/getObjectiveCountByChapterId") - @ApiOperation("根据章节查看题目类型数量") + @ApiOperation("根据章节查看题目类型数量/模拟认证题库通用") @AnonymousAccess - private ResultEntity<List<HashMap<Integer,Integer>>> getObjectiveCountByChapterId(@ApiParam("普通题库/金融智能/银行从业") @RequestParam String outLine, - @ApiParam("理论知识/专业能力公共基础/个人理财/风险管理/公司信贷/个人贷款") @RequestParam(required = false) String subClass, - @RequestParam String chapterId) { - return new ResultEntity<>(objectiveQuestionMapper.getObjectiveCountByChapterId(outLine, subClass, chapterId)); + private ResultEntity<List<TopicDto>> getObjectiveCountByChapterId(@ApiParam("普通题库/金融智能/银行从业") @RequestParam String outLine, + @RequestParam(required = false) String chapterId) { + return new ResultEntity<>(objectiveQuestionMapper.getObjectiveCountByChapterId(outLine, chapterId)); } @@ -123,4 +145,21 @@ public class TopicController { PageInfo pageInfo = new PageInfo(list); return new ResultEntity<PageInfo<ObjectiveQuestionWithBLOBs>>(pageInfo); } + + @PostMapping("/commitObjectiveAnswer") + @ApiOperation("学习测评/提交") + @AnonymousAccess + private void commitObjectiveAnswer(@RequestParam List<ObjectiveQuestionDto> dtoList, + @RequestParam String userId, + @RequestParam String chapterId) { + objectiveQuestionService.commitObjectiveAnswer(dtoList, userId, chapterId); + } + + @PostMapping("/getObjectiveRecord") + @ApiOperation("学习测评/随机10条展示/回显") + @AnonymousAccess + private ResultEntity<List<ObjectiveQuestionDto>> getObjectiveRecord(@RequestParam String chapterId,@RequestParam String trainingId) { + List<ObjectiveQuestionDto> list =objectiveQuestionService.getObjectiveRecord(chapterId,trainingId); + return new ResultEntity<List<ObjectiveQuestionDto>>(list); + } } diff --git a/src/main/java/com/sztzjy/money_management/controller/TrainingController.java b/src/main/java/com/sztzjy/money_management/controller/TrainingController.java new file mode 100644 index 0000000..0b8dd49 --- /dev/null +++ b/src/main/java/com/sztzjy/money_management/controller/TrainingController.java @@ -0,0 +1,18 @@ +package com.sztzjy.money_management.controller; + +import com.sztzjy.money_management.mapper.ObjectiveQuestionMapper; +import io.swagger.annotations.Api; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Author xcj + * @Date 2024/8/13 + */ +@RestController +@Api(tags = "实训相关接口") +@RequestMapping("api/training") +public class TrainingController { + +} diff --git a/src/main/java/com/sztzjy/money_management/entity/dto/ObjectiveQuestionDto.java b/src/main/java/com/sztzjy/money_management/entity/dto/ObjectiveQuestionDto.java new file mode 100644 index 0000000..ccb7bd1 --- /dev/null +++ b/src/main/java/com/sztzjy/money_management/entity/dto/ObjectiveQuestionDto.java @@ -0,0 +1,13 @@ +package com.sztzjy.money_management.entity.dto; + +import com.sztzjy.money_management.entity.ObjectiveQuestionWithBLOBs; +import lombok.Data; + +/** + * @Author xcj + * @Date 2024/8/13 + */ +@Data +public class ObjectiveQuestionDto extends ObjectiveQuestionWithBLOBs { + private String userAnswer; +} diff --git a/src/main/java/com/sztzjy/money_management/entity/dto/TopicDto.java b/src/main/java/com/sztzjy/money_management/entity/dto/TopicDto.java new file mode 100644 index 0000000..4edfe79 --- /dev/null +++ b/src/main/java/com/sztzjy/money_management/entity/dto/TopicDto.java @@ -0,0 +1,24 @@ +package com.sztzjy.money_management.entity.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @Author xcj + * @Date 2024/8/13 + */ +@Data +public class TopicDto { + @ApiModelProperty("所属大纲(普通题库/金融智能/银行从业)") + private String outline; + + @ApiModelProperty("大纲子类(理论知识/专业能力公共基础/个人理财/风险管理/公司信贷/个人贷款)") + private String subclass; + + @ApiModelProperty("题目类型(0单选,1多选,2判断)") + private Integer type; + + @ApiModelProperty("题型数量") + private String count; + +} diff --git a/src/main/java/com/sztzjy/money_management/mapper/ObjectiveQuestionMapper.java b/src/main/java/com/sztzjy/money_management/mapper/ObjectiveQuestionMapper.java index 0a3d9f6..ff529b4 100644 --- a/src/main/java/com/sztzjy/money_management/mapper/ObjectiveQuestionMapper.java +++ b/src/main/java/com/sztzjy/money_management/mapper/ObjectiveQuestionMapper.java @@ -3,11 +3,11 @@ package com.sztzjy.money_management.mapper; import com.sztzjy.money_management.entity.ObjectiveQuestion; import com.sztzjy.money_management.entity.ObjectiveQuestionExample; import com.sztzjy.money_management.entity.ObjectiveQuestionWithBLOBs; +import com.sztzjy.money_management.entity.dto.ObjectiveQuestionDto; +import com.sztzjy.money_management.entity.dto.TopicDto; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; -import java.util.HashMap; import java.util.List; @Mapper @@ -40,13 +40,18 @@ public interface ObjectiveQuestionMapper { int updateByPrimaryKey(ObjectiveQuestion record); - List<HashMap<Integer, Integer>> getObjectiveCountByChapterId(@Param("outLine") String outLine, - @Param("subClass") String subClass, - @Param("chapterId") String chapterId); + List<TopicDto> getObjectiveCountByChapterId(@Param("outLine") String outLine, + @Param("chapterId") String chapterId); List<ObjectiveQuestionWithBLOBs> getObjectiveByType(@Param("type") int type, @Param("outLine") String outLine, @Param("subClass") String subClass, @Param("content") String content); + + int batchDelete(@Param("list") List<String> objectiveQuestionId); + + int insertBatch(@Param("list") List<ObjectiveQuestionWithBLOBs> objectiveQuestionList); + + List<ObjectiveQuestionDto> getObjectiveCount10(@Param("chapterId") String chapterId); } \ No newline at end of file diff --git a/src/main/java/com/sztzjy/money_management/service/ObjectiveQuestionService.java b/src/main/java/com/sztzjy/money_management/service/ObjectiveQuestionService.java new file mode 100644 index 0000000..c8d7d24 --- /dev/null +++ b/src/main/java/com/sztzjy/money_management/service/ObjectiveQuestionService.java @@ -0,0 +1,27 @@ +package com.sztzjy.money_management.service; + +import com.sztzjy.money_management.entity.ObjectiveQuestionWithBLOBs; +import com.sztzjy.money_management.entity.dto.ObjectiveQuestionDto; +import com.sztzjy.money_management.util.ResultEntity; +import org.springframework.http.HttpStatus; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.List; + +/** + * @Author xcj + * @Date 2024/8/13 + */ +public interface ObjectiveQuestionService { + ResultEntity<HttpStatus> insertObjectiveByExcel(MultipartFile file, + String source, + String chapterID, + String chapterName, + String outLine, + String subClass) throws Exception; + + void commitObjectiveAnswer(List<ObjectiveQuestionDto> dtoList, String userId, String chapterId); + + List<ObjectiveQuestionDto> getObjectiveRecord(String chapterId,String trainingId); +} diff --git a/src/main/java/com/sztzjy/money_management/service/impl/ObjectiveQuestionServiceImpl.java b/src/main/java/com/sztzjy/money_management/service/impl/ObjectiveQuestionServiceImpl.java new file mode 100644 index 0000000..d4fee45 --- /dev/null +++ b/src/main/java/com/sztzjy/money_management/service/impl/ObjectiveQuestionServiceImpl.java @@ -0,0 +1,210 @@ +package com.sztzjy.money_management.service.impl; + +import cn.hutool.core.util.IdUtil; +import com.sztzjy.money_management.entity.ObjectiveQuestionExample; +import com.sztzjy.money_management.entity.ObjectiveQuestionWithBLOBs; +import com.sztzjy.money_management.entity.StuTrainingExample; +import com.sztzjy.money_management.entity.StuTrainingWithBLOBs; +import com.sztzjy.money_management.entity.dto.ObjectiveQuestionDto; +import com.sztzjy.money_management.mapper.ObjectiveQuestionMapper; +import com.sztzjy.money_management.mapper.StuTrainingMapper; +import com.sztzjy.money_management.service.ObjectiveQuestionService; +import com.sztzjy.money_management.util.ResultEntity; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.ss.usermodel.*; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.*; + +/** + * @Author xcj + * @Date 2024/8/13 + */ +@Service +public class ObjectiveQuestionServiceImpl implements ObjectiveQuestionService { + @Autowired + private ObjectiveQuestionMapper objectiveQuestionMapper; + @Autowired + private StuTrainingMapper stuTrainingMapper; + + + @Override + public ResultEntity<HttpStatus> insertObjectiveByExcel(MultipartFile file, String source, String chapterID, String chapterName, String outLine, String subClass) throws Exception { + List<ObjectiveQuestionWithBLOBs> objectiveQuestionList = new ArrayList<>(); + Workbook workbook = WorkbookFactory.create(file.getInputStream()); + Sheet sheet = workbook.getSheetAt(0); + + // 迭代每一行 + Iterator<Row> iterator = sheet.iterator(); + iterator.next(); + while (iterator.hasNext()) { + Row row = iterator.next(); + + /*解析列,下标从0开始*/ + Cell cell0 = row.getCell(0); + Cell cell1 = row.getCell(1); + Cell cell2 = row.getCell(2); + Cell cell3 = row.getCell(3); + Cell cell4 = row.getCell(4); + Cell cell5 = row.getCell(5); + Cell cell6 = row.getCell(6); + Cell cell7 = row.getCell(7); + Cell cell8 = row.getCell(8); + Cell cell9 = row.getCell(9); + Cell cell10 = row.getCell(10); + + //判断题的BCDE选项和解析可能为空 + if (cell0 == null || cell1 == null || cell2 == null || cell6 == null || cell7 == null || cell9 == null) { + return new ResultEntity<>(HttpStatus.BAD_REQUEST, "必填项不能为空"); + } + + String content = this.getCellValue(cell0);//题干 + String a = this.getCellValue(cell1); //选项A + String b = this.getCellValue(cell2);//选项B + String type = this.getCellValue(cell6);//题型 + String answer = this.getCellValue(cell7);//答案 + String score = this.getCellValue(cell9);//分值 + String c = cell3 != null ? this.getCellValue(cell3) : null; + String d = cell4 != null ? this.getCellValue(cell4) : null; + String e = cell5 != null ? this.getCellValue(cell5) : null; + String analyze = cell8 != null ? this.getCellValue(cell8) : null; + + + ObjectiveQuestionWithBLOBs obj = new ObjectiveQuestionWithBLOBs(); + String topicId = IdUtil.randomUUID(); + obj.setObjectiveId(topicId); + obj.setContent(content); + obj.setType(Integer.valueOf(type)); + obj.setSource(source); + obj.setQuestionA(a); + obj.setQuestionB(b); + obj.setQuestionC(c); + obj.setQuestionD(d); + obj.setQuestionE(e); + obj.setAnswer(answer); + obj.setAnalysis(analyze); + obj.setScore(BigDecimal.valueOf(Integer.parseInt(score))); + if (StringUtils.isNotBlank(chapterID)) { + obj.setChapterId(chapterID); + } + if (StringUtils.isNotBlank(chapterName)) { + obj.setChapterName(chapterName); + } + if (StringUtils.isNotBlank(subClass)) { + obj.setSubclass(subClass); + } + objectiveQuestionList.add(obj); + } + int result = objectiveQuestionMapper.insertBatch(objectiveQuestionList); + if (result > 0) { + return new ResultEntity<>(HttpStatus.OK, "批量导入成功!"); + } else { + return new ResultEntity<>(HttpStatus.INTERNAL_SERVER_ERROR, "批量导入失败,请联系管理员!"); + } + } + + public String getCellValue(Cell cell) { + if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { + return String.valueOf(cell.getBooleanCellValue()); + } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { + Double d = cell.getNumericCellValue(); + return String.valueOf(d.intValue()); + } + return String.valueOf(cell.getStringCellValue()); + } + + @Override + public void commitObjectiveAnswer(List<ObjectiveQuestionDto> dtoList, String userId, String chapterId) { + StuTrainingExample stuTrainingExample = new StuTrainingExample(); + stuTrainingExample.createCriteria().andUserIdEqualTo(userId).andChapterIdEqualTo(chapterId); + List<StuTrainingWithBLOBs> stuTrainingWithBLOBs = stuTrainingMapper.selectByExampleWithBLOBs(stuTrainingExample); + + BigDecimal score = new BigDecimal(BigInteger.ZERO); + List<String> ids = new ArrayList<>(); + List<String> answerList = new ArrayList<>(); + int count = 0; + for (ObjectiveQuestionDto objectiveQuestionDto : dtoList) { + String dtoObjectiveId = objectiveQuestionDto.getObjectiveId(); + ObjectiveQuestionWithBLOBs dataObjectiveQuestion = objectiveQuestionMapper.selectByPrimaryKey(dtoObjectiveId); + String rightAnswer = dataObjectiveQuestion.getAnswer(); + String stuAnswer = objectiveQuestionDto.getUserAnswer(); + if (rightAnswer.equals(stuAnswer)) { + score = score.add(dataObjectiveQuestion.getScore()); + } else { + count += 1; + } + ids.add(dtoObjectiveId); + answerList.add(stuAnswer); + } + + if (stuTrainingWithBLOBs != null && !stuTrainingWithBLOBs.isEmpty()) { + StuTrainingWithBLOBs dataTraining = stuTrainingWithBLOBs.get(0); + //两个参数都为空说明第一次提交,进行算分 + if (StringUtils.isBlank(dataTraining.getLearningEvalIdList()) + && StringUtils.isBlank(dataTraining.getLearningEvalAnswer())) { + + dataTraining.setLearningEvalAnswer(String.valueOf(answerList)); + dataTraining.setLearningEvalIdList(String.valueOf(ids)); + dataTraining.setExpTrainingScore(score); +// dataTraining.setLearningEvalCompleteStatus(count); + + stuTrainingMapper.updateByPrimaryKeySelective(dataTraining); + } + } + } + + @Override + public List<ObjectiveQuestionDto> getObjectiveRecord(String chapterId, String trainingId) { + StuTrainingWithBLOBs stuTrainingWithBLOBs = stuTrainingMapper.selectByPrimaryKey(trainingId); + + //沒提交过的展示十条随机 + if (stuTrainingWithBLOBs == null + || StringUtils.isBlank(stuTrainingWithBLOBs.getLearningEvalAnswer()) + || StringUtils.isBlank(stuTrainingWithBLOBs.getLearningEvalIdList())) { + return objectiveQuestionMapper.getObjectiveCount10(chapterId); + } + + //提交过 回显答题数据 + String learningEvalIdList = stuTrainingWithBLOBs.getLearningEvalIdList(); //学生作答题目ID + String learningEvalAnswer = stuTrainingWithBLOBs.getLearningEvalAnswer(); //学生提交答案 + + List<String> idList = Arrays.asList(learningEvalIdList.split(",")); + List<String> stuAnswerList = Arrays.asList(learningEvalAnswer.split(",")); + + // 确保 idList 和 stuAnswerList 大小相同且顺序匹配 + if (idList.size() != stuAnswerList.size()) { + throw new IllegalArgumentException("ID 和答案数量不匹配"); + } + + // 创建题目 ID 到答案的映射 + Map<String, String> answerMap = new HashMap<>(); + for (int i = 0; i < idList.size(); i++) { + answerMap.put(idList.get(i), stuAnswerList.get(i)); + } + + + ObjectiveQuestionExample example = new ObjectiveQuestionExample(); + example.createCriteria().andObjectiveIdIn(idList); + List<ObjectiveQuestionWithBLOBs> list = objectiveQuestionMapper.selectByExampleWithBLOBs(example); + + List<ObjectiveQuestionDto> resultList = new ArrayList<>(); + for (ObjectiveQuestionWithBLOBs objectiveQuestionWithBLOBs : list) { + ObjectiveQuestionDto objectiveQuestionDto = new ObjectiveQuestionDto(); + BeanUtils.copyProperties(objectiveQuestionWithBLOBs, objectiveQuestionDto); + + // 获取对应题目的答案并设置 + String userAnswer = answerMap.get(objectiveQuestionWithBLOBs.getObjectiveId()); + objectiveQuestionDto.setUserAnswer(userAnswer); + list.add(objectiveQuestionDto); + } + return resultList; + } + + +} diff --git a/src/main/resources/mapper/ObjectiveQuestionMapper.xml b/src/main/resources/mapper/ObjectiveQuestionMapper.xml index ab19f92..b1b7357 100644 --- a/src/main/resources/mapper/ObjectiveQuestionMapper.xml +++ b/src/main/resources/mapper/ObjectiveQuestionMapper.xml @@ -454,6 +454,14 @@ where objective_id = #{objectiveId,jdbcType=VARCHAR} </update> + + <resultMap id="dtoMap" type="com.sztzjy.money_management.entity.dto.TopicDto"> + <result column="count" jdbcType="VARCHAR" property="count"/> + <result column="type" jdbcType="INTEGER" property="type"/> + <result column="outline" jdbcType="VARCHAR" property="outline"/> + <result column="subclass" jdbcType="VARCHAR" property="subclass"/> + </resultMap> + <!--下面为自己新增--> <select id="getObjectiveByType" resultMap="ResultMapWithBLOBs"> select * from objective_question @@ -473,8 +481,11 @@ </where> </select> - <select id="getObjectiveCountByChapterId" resultType="java.util.HashMap"> - SELECT type, count(*) AS count + <select id="getObjectiveCountByChapterId" resultMap="dtoMap"> + SELECT type, + MAX(outline) AS outline, + MAX(subclass) AS subclass, + count(*) AS count FROM objective_question <where> <if test="chapterId !=null"> @@ -483,11 +494,51 @@ <if test="outLine !=null and outLine !=''"> and outline = #{outLine} </if> - <if test="subClass !=null and subClass !=''"> - and subClass = #{subClass} - </if> </where> GROUP BY type </select> + <delete id="batchDelete" parameterType="java.util.List"> + delete from objective_question + where objective_id in + <foreach collection="list" separator="," open="(" close=")" item="id"> + #{id} + </foreach> + </delete> + + + <insert id="insertBatch" parameterType="java.util.List"> + insert into objective_question (objective_id, chapter_id, chapter_name, + source, type, score, + question_a, question_b, question_c, + question_d, question_e, answer, + outline, subclass, content, + analysis) VALUES + <foreach collection="objectiveQuestionList" item="item" index="index" separator=","> + ( + (#{objectiveId}, #{chapterId}, #{chapterName}, + #{source}, #{type}, #{score}, + #{questionA}, #{questionB}, #{questionC}, + #{questionD}, #{questionE}, #{answer}, + #{outline}, #{subclass}, #{content}, + #{analysis}) + ) + </foreach> + </insert> + + + <select id="getObjectiveCount10" resultMap="ResultMapWithBLOBs"> + select objective_id, chapter_id, chapter_name, source, type, score, question_a, question_b, + question_c, question_d, question_e, outline, subclass,content + from objective_question + <where> + <if test="chapterId !=null"> + chapter_id = #{chapterId} + </if> + and outline = '普通题库' + and source = '999999999' + </where> + ORDER BY RAND() + LIMIT 10; + </select> </mapper> \ No newline at end of file