src/main/java/com/mindskip/xzs/configuration/spring/security/SecurityConfigurer.java
@@ -85,8 +85,7 @@ "/api/admin/user/conversion", "/api/admin/examPaperGrade/updates", "/api/admin/question/download/question/import/temp", "/api/admin/question/question/import", "/api/upload/**" "/api/admin/question/question/import" ).permitAll() .antMatchers("/files/**").permitAll() // 静态资源,可匿名访问 src/main/java/com/mindskip/xzs/controller/common/UploadController.java
@@ -3,14 +3,20 @@ import com.mindskip.xzs.base.RestResponse; import com.mindskip.xzs.configuration.RuoYiConfig; import lombok.RequiredArgsConstructor; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.nio.file.Files; import java.util.HashMap; import java.util.UUID; @@ -63,4 +69,32 @@ } } /** * 下载文件(单个) */ @GetMapping("/download") public void download(@RequestParam String url, @RequestParam String fileName, HttpServletResponse response) throws Exception { // 提取文件路径 String filePath = ruoYiConfig.getUrl() + File.separator + url; File file = new File(filePath); // 检查文件是否存在 if (!file.exists()) { throw new RuntimeException("文件不存在"); } // 读取文件内容 byte[] fileContent = Files.readAllBytes(file.toPath()); // 设置响应头 response.setHeader("Content-Disposition", "attachment; filename=" + fileName); response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); // 将文件内容写入响应输出流 response.getOutputStream().write(fileContent); response.getOutputStream().flush(); } } src/main/java/com/mindskip/xzs/controller/student/SelfPracticeController.java
@@ -31,17 +31,6 @@ return selfPracticeService.page(vo); } /** * 获取所选课目下的题目数量 * * @param subjectIds * @return */ @PostMapping("/subject/questionNum") public RestResponse subjectQuestionNum(@RequestBody List<Integer> subjectIds) { return selfPracticeService.subjectQuestionNum(subjectIds); } @PostMapping("/remove") public RestResponse remove(@RequestBody @NotEmpty(message = "请选择要删除的数据") List<Integer> ids) { return selfPracticeService.remove(ids); src/main/java/com/mindskip/xzs/repository/QuestionSubjectMapper.java
@@ -32,7 +32,7 @@ List<QuestionSubject> getSubject(Integer id); /** 统计课目的题目数 */ Integer countQuestionNum(@Param("subjects") List<Integer> subjects); Integer countQuestionNum(@Param("subjects") List<Integer> subjects, @Param("questionType") Integer questionType); /** 随机题目 */ List<QuestionVO> getRandomQuestionId(@Param("subjectIds") List<Integer> subjectIds, @Param("questionType") Integer questionType, @Param("questionNum") Integer questionNum); src/main/java/com/mindskip/xzs/service/SelfPracticeService.java
@@ -46,13 +46,6 @@ */ RestResponse startPractice(Integer id); /** * 查询课目下的题目数量 * * @param subjectIds * @return */ RestResponse subjectQuestionNum(List<Integer> subjectIds); /** * 随机一道题 src/main/java/com/mindskip/xzs/service/impl/SelfPracticeServiceImpl.java
@@ -74,7 +74,7 @@ if (! CollectionUtils.isEmpty(subjectNames)) { item.setSubjectNames(subjectNames.stream().collect(Collectors.joining("、"))); } item.setTotalQuestionNum(questionSubjectMapper.countQuestionNum(subjects)); item.setTotalQuestionNum(questionSubjectMapper.countQuestionNum(subjects, PracticeQuestionTypeEnum.getDataBaseValueByValue(item.getQuestionType()))); // 查询已经做了多少 PracticeQuestionCondition practiceQuestionCondition = practiceQuestionConditionMapper.selectByPracticeId(item.getId()); if (Objects.nonNull(practiceQuestionCondition)) { @@ -151,12 +151,6 @@ return RestResponse.ok(questionVO); } return RestResponse.ok(); } @Override public RestResponse subjectQuestionNum(List<Integer> subjectIds) { Integer num = questionSubjectMapper.countQuestionNum(subjectIds); return RestResponse.ok(num); } @Override src/main/resources/application.yml
@@ -61,11 +61,10 @@ hikari: idle-timeout: 600000 #10 min max-lifetime: 180000000 #30 min mvc: servlet: multipart: max-file-size: 50MB max-request-size: 500MB servlet: multipart: max-file-size: 1024MB max-request-size: 1024MB #runningtime environment profiles: active: dev src/main/resources/mapper/QuestionSubjectMapper.xml
@@ -57,11 +57,13 @@ <select id="countQuestionNum" resultType="integer"> SELECT count(distinct id) count(distinct tqs.question_id) FROM t_question_subject t_question_subject tqs INNER JOIN t_question tq ON tq.id = tqs.question_id <if test="questionType != -99">AND tq.question_type = #{questionType}</if> WHERE subject_id IN <foreach collection="subjects" open="(" separator="," close=")" item="subjectId">#{subjectId}</foreach> tqs.subject_id IN <foreach collection="subjects" open="(" separator="," close=")" item="subjectId">#{subjectId}</foreach> </select> <select id="getRandomQuestionId" resultType="com.mindskip.xzs.domain.vo.QuestionVO"> @@ -74,7 +76,11 @@ tq.correct FROM t_question_subject tqs INNER JOIN t_question tq ON tqs.question_id = tq.id AND tq.deleted = 0 AND tqs.subject_id IN <foreach collection="subjectIds" open="(" separator="," close=")" item="subjectId">#{subjectId}</foreach> INNER JOIN t_question tq ON tqs.question_id = tq.id AND tq.deleted = 0 <if test="questionType != null and questionType != -99"> AND tq.question_type = #{questionType} </if> AND tqs.subject_id IN <foreach collection="subjectIds" open="(" separator="," close=")" item="subjectId">#{subjectId}</foreach> INNER JOIN t_text_content ttc ON tq.info_text_content_id = ttc.id ORDER BY RAND() LIMIT #{questionNum}