diff --git a/common/src/main/java/com/huoran/common/entity/ProjectManage.java b/common/src/main/java/com/huoran/common/entity/ProjectManage.java index 250988a4..8da45864 100644 --- a/common/src/main/java/com/huoran/common/entity/ProjectManage.java +++ b/common/src/main/java/com/huoran/common/entity/ProjectManage.java @@ -70,7 +70,7 @@ public class ProjectManage implements Serializable { @NotNull(message = "状态不能为空!") private Integer state; - @ApiModelProperty(value = "系统类型(0编程类 1流程类 2.AI类)") + @ApiModelProperty(value = "系统类型(0编程类 1流程类 2.AI类 3.理论类)") @TableField(exist = false) private Integer type; @@ -157,5 +157,31 @@ public class ProjectManage implements Serializable { @ApiModelProperty(value = "商品id") private Integer mallId; + //试卷id + @ApiModelProperty(value = "试卷id") + @TableField(exist = false) + private Integer paperId; + + //试卷名称 + @ApiModelProperty(value = "试卷名称") + @TableField(exist = false) + private String paperName; + + @ApiModelProperty(value = "建议用途(练习、考核、竞赛)") + @TableField(exist = false) + private Integer paperType; + + @ApiModelProperty(value = "题型") + @TableField(exist = false) + private String questionType; + + @ApiModelProperty(value = "年份") + @TableField(exist = false) + private Integer particularYear; + + @ApiModelProperty(value = "试卷总分") + @TableField(exist = false) + private Double score; + } diff --git a/exam/src/main/java/com/huoran/exam/controller/ExamPaperController.java b/exam/src/main/java/com/huoran/exam/controller/ExamPaperController.java index 6a2f254d..1b00c3e1 100644 --- a/exam/src/main/java/com/huoran/exam/controller/ExamPaperController.java +++ b/exam/src/main/java/com/huoran/exam/controller/ExamPaperController.java @@ -334,6 +334,20 @@ public class ExamPaperController { } + @NoRepeatSubmit + @ApiOperation(value = "提交试卷(练习)") + @PostMapping("/submitTheExamPaperForPractice") + public R submitTheExamPaperForPractice(@RequestBody @Valid ExamSubmitReq examSubmitReq) throws JsonProcessingException { + String accountId = TokenUtils.getAccountId(); + Integer schoolId = TokenUtils.getSchoolId(); + examSubmitReq.setAccountId(Integer.valueOf(accountId)); + examSubmitReq.setSchoolId(schoolId); + return examPaperService.submitTheExamPaperForPractice(examSubmitReq); + } + + + + @NoRepeatSubmit @ApiOperation(value = "模拟交卷") @PostMapping("/simulatedHandover") diff --git a/exam/src/main/java/com/huoran/exam/entity/req/ExamSubmitReq.java b/exam/src/main/java/com/huoran/exam/entity/req/ExamSubmitReq.java index 155e6008..f33b2b02 100644 --- a/exam/src/main/java/com/huoran/exam/entity/req/ExamSubmitReq.java +++ b/exam/src/main/java/com/huoran/exam/entity/req/ExamSubmitReq.java @@ -71,5 +71,9 @@ public class ExamSubmitReq implements Serializable { @ApiModelProperty(value = "商品id") private Integer mallId; + //课程id + @ApiModelProperty(value = "课程id") + private Integer cid; + } diff --git a/exam/src/main/java/com/huoran/exam/service/ExamPaperService.java b/exam/src/main/java/com/huoran/exam/service/ExamPaperService.java index ba57586a..4eee2b14 100644 --- a/exam/src/main/java/com/huoran/exam/service/ExamPaperService.java +++ b/exam/src/main/java/com/huoran/exam/service/ExamPaperService.java @@ -30,6 +30,8 @@ public interface ExamPaperService extends IService { R submitTheExamPaper(ExamSubmitReq examSubmitReq) throws JsonProcessingException; + R submitTheExamPaperForPractice(ExamSubmitReq examSubmitReq) throws JsonProcessingException; + void editTheTestPaperAsADraft(List paperIds); ResponseEntity word(R detailedExamScores, HttpServletResponse response) throws IOException; diff --git a/exam/src/main/java/com/huoran/exam/service/impl/ExamPaperServiceImpl.java b/exam/src/main/java/com/huoran/exam/service/impl/ExamPaperServiceImpl.java index e00678e2..45a5b4ab 100644 --- a/exam/src/main/java/com/huoran/exam/service/impl/ExamPaperServiceImpl.java +++ b/exam/src/main/java/com/huoran/exam/service/impl/ExamPaperServiceImpl.java @@ -30,6 +30,8 @@ import com.huoran.exam.service.ExamPaperService; import com.huoran.exam.service.QuestionsService; import org.apache.commons.lang3.StringUtils; import org.apache.poi.xwpf.usermodel.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ByteArrayResource; @@ -59,7 +61,7 @@ import java.util.regex.Pattern; */ @Service public class ExamPaperServiceImpl extends ServiceImpl implements ExamPaperService { - + private static Logger logger = LoggerFactory.getLogger(ExamPaperServiceImpl.class); @Autowired public ExamClassificationMapper examClassificationMapper; @@ -234,6 +236,96 @@ public class ExamPaperServiceImpl extends ServiceImpl examPaperQuestionUserAnswerList = new ArrayList<>(); + for (SubmitJudgeReq submitJudgeReq : examSubmitReq.getExamSubmitJudgeList()) { + if (submitJudgeReq == null || !isValidSubmitJudgeReq(submitJudgeReq)) { + throw new IllegalArgumentException("提交参数请求无效"); + } + + ExamPaperQuestionUserAnswer examPaperQuestionUserAnswer = new ExamPaperQuestionUserAnswer(); + if (submitJudgeReq.getAnswer().isEmpty()) { + if (submitJudgeReq.getAnswerContent().isEmpty()) { + examPaperQuestionUserAnswer.setAnsweringStatus("未作答"); + } + } else { + GradingResultResp gradingResultResp = questionsService.gradeAnswer(submitJudgeReq); + examPaperQuestionUserAnswer.setDoRight(gradingResultResp.isCorrect()); + examPaperQuestionUserAnswer.setAnsweringStatus("已作答"); + totalScoreOfTheExamPaper += gradingResultResp.getTotalScore(); + examPaperQuestionUserAnswer.setUserScore(gradingResultResp.getTotalScore()); + examPaperQuestionUserAnswer.setBackupScore(gradingResultResp.getTotalScore()); + + if (gradingResultResp.getBlankGradingInfos() != null && gradingResultResp.getBlankGradingInfos().size() > 0) { + String jsonText = JSON.toJSONString(gradingResultResp.getBlankGradingInfos()); + examPaperQuestionUserAnswer.setJsonText(jsonText); + } + } + examPaperQuestionUserAnswer.setReportId(reportId); + examPaperQuestionUserAnswer.setCreateUser(TokenUtils.getUserName()); + examPaperQuestionUserAnswer.setPaperId(examSubmitReq.getPaperId()); + examPaperQuestionUserAnswer.setQuestionVersionId(submitJudgeReq.getQuestionVersionId()); + examPaperQuestionUserAnswer.setSchoolId(examSubmitReq.getSchoolId()); + examPaperQuestionUserAnswer.setAccountId(examSubmitReq.getAccountId()); + examPaperQuestionUserAnswer.setQuestionType(submitJudgeReq.getQuestionType()); + examPaperQuestionUserAnswer.setSerialNumber(submitJudgeReq.getSerialNumber()); + examPaperQuestionUserAnswer.setUserAnswer(submitJudgeReq.getAnswer().toString()); + examPaperQuestionUserAnswer.setQuestionScore(submitJudgeReq.getSetScore()); + examPaperQuestionUserAnswer.setAttachmentUrl(submitJudgeReq.getAttachmentUrl()); + examPaperQuestionUserAnswer.setAttachmentName(submitJudgeReq.getAttachmentName()); + examPaperQuestionUserAnswer.setAnswerContent(submitJudgeReq.getAnswerContent()); + examPaperQuestionUserAnswer.setOutlineId(submitJudgeReq.getOutlineId()); + + if (examSubmitReq.getSystemId() != null) { + examPaperQuestionUserAnswer.setSystemId(examSubmitReq.getSystemId()); + } + examPaperQuestionUserAnswerList.add(examPaperQuestionUserAnswer); + } + + examPaperQuestionUserAnswerService.saveBatch(examPaperQuestionUserAnswerList); + + report.setScore(totalScoreOfTheExamPaper); + report.setReportId(reportId); + occupationlabClient.updateExperimentalReport(report); + + return R.ok(); + } catch (Exception e) { + // 记录异常日志 + logger.error("提交练习试卷错误", e); + return R.error("提交失败,请重试"); + } + } + + @Override public void editTheTestPaperAsADraft(List paperIds) { //批量把试卷状态更改为草稿 diff --git a/nakadai/src/main/java/com/huoran/nakadai/controller/CurriculumController.java b/nakadai/src/main/java/com/huoran/nakadai/controller/CurriculumController.java index b337b6f0..5c72f404 100644 --- a/nakadai/src/main/java/com/huoran/nakadai/controller/CurriculumController.java +++ b/nakadai/src/main/java/com/huoran/nakadai/controller/CurriculumController.java @@ -64,6 +64,10 @@ public class CurriculumController { return service.createCurriculum(curriculum); } + + + + /** * @Description: 编辑课程 * @auther: Rong diff --git a/nakadai/src/main/java/com/huoran/nakadai/entity/Curriculum.java b/nakadai/src/main/java/com/huoran/nakadai/entity/Curriculum.java index 64aea081..ba4f9fcf 100644 --- a/nakadai/src/main/java/com/huoran/nakadai/entity/Curriculum.java +++ b/nakadai/src/main/java/com/huoran/nakadai/entity/Curriculum.java @@ -140,4 +140,12 @@ public class Curriculum implements Serializable { @ApiModelProperty(value = "小程序图片地址") private String miniProgramPictureAddress; + + //练习是否包含理论试卷 + @ApiModelProperty(value = "练习是否包含理论试卷(0否,1是)") + private Integer practiceTheoreticalPaper; + + //练习是否包含实操项目 + @ApiModelProperty(value = "练习是否包含实操项目(0否,1是)") + private Integer practicePracticeProject; } diff --git a/nakadai/src/main/java/com/huoran/nakadai/entity/CurriculumConfigure.java b/nakadai/src/main/java/com/huoran/nakadai/entity/CurriculumConfigure.java index 61d2de97..824c936b 100644 --- a/nakadai/src/main/java/com/huoran/nakadai/entity/CurriculumConfigure.java +++ b/nakadai/src/main/java/com/huoran/nakadai/entity/CurriculumConfigure.java @@ -52,5 +52,8 @@ public class CurriculumConfigure implements Serializable { @ApiModelProperty(value = "是否删除(默认0未删 1为已删除)") private Integer isDel; + @ApiModelProperty(value = "试卷id") + private Integer paperId; + } diff --git a/nakadai/src/main/java/com/huoran/nakadai/entity/req/ConfigurationReq.java b/nakadai/src/main/java/com/huoran/nakadai/entity/req/ConfigurationReq.java index d28b7caa..d1960bac 100644 --- a/nakadai/src/main/java/com/huoran/nakadai/entity/req/ConfigurationReq.java +++ b/nakadai/src/main/java/com/huoran/nakadai/entity/req/ConfigurationReq.java @@ -32,4 +32,9 @@ public class ConfigurationReq { @ApiModelProperty(value = "是否展示") private Integer isShow; + + //试卷id + @ApiModelProperty(value = "试卷id") + private Integer paperId; + } diff --git a/nakadai/src/main/java/com/huoran/nakadai/entity/res/CurriculumDetailRes.java b/nakadai/src/main/java/com/huoran/nakadai/entity/res/CurriculumDetailRes.java index 6f1a6ffb..570d71b9 100644 --- a/nakadai/src/main/java/com/huoran/nakadai/entity/res/CurriculumDetailRes.java +++ b/nakadai/src/main/java/com/huoran/nakadai/entity/res/CurriculumDetailRes.java @@ -19,15 +19,19 @@ public class CurriculumDetailRes { @ApiModelProperty(value = "课程id") private Integer cid; - @ApiModelProperty(value = "项目名称") + @ApiModelProperty(value = "项目名称/试卷名称") private String projectName; @ApiModelProperty(value = "项目权限(0、练习 1、考核 2、竞赛)") private Integer permissions; - @ApiModelProperty(value = "应用名称") + @ApiModelProperty(value = "系统名称") private String applicationName; + //systemName + @ApiModelProperty(value = "系统名称") + private String systemName; + @ApiModelProperty(value = "排序(对项目展示进行排序)") private Integer sort; @@ -48,4 +52,8 @@ public class CurriculumDetailRes { @ApiModelProperty(value = "备注") private String remark; + + //试卷id + @ApiModelProperty(value = "试卷id") + private Integer paperId; } diff --git a/nakadai/src/main/java/com/huoran/nakadai/mapper/xml/CurriculumConfigureMapper.xml b/nakadai/src/main/java/com/huoran/nakadai/mapper/xml/CurriculumConfigureMapper.xml index 89004825..a2ce8f81 100644 --- a/nakadai/src/main/java/com/huoran/nakadai/mapper/xml/CurriculumConfigureMapper.xml +++ b/nakadai/src/main/java/com/huoran/nakadai/mapper/xml/CurriculumConfigureMapper.xml @@ -29,27 +29,47 @@ SELECT - ( SELECT project_name FROM occupationlab.ol_project_manage pm WHERE pm.project_id = r.project_id ) AS - projectName, - ( SELECT cu.curriculum_name FROM nakadai.curriculum cu WHERE cu.cid = r.curriculum_id ) AS curriculumName, - ( - SELECT - submit_time - FROM - occupationlab.ol_experimental_report e - WHERE - e.project_id = r.project_id - AND account_id = r.account_id - AND assessment_id IS NULL - ORDER BY - report_id DESC - LIMIT 0, - 1 - ) AS lastTime, + c.cid as curriculumId, + c.curriculum_name, r.project_id, - FORMAT( - ( - ( SELECT IFNULL( sum( time_sum ), 0 ) FROM occupationlab.ol_experimental_report WHERE project_id = r.project_id - AND assessment_id IS NULL AND account_id = r.account_id ) / 60 + r.paper_id, + CASE - ), - 2 - ) AS duration, - ( - SELECT - score - FROM - occupationlab.ol_experimental_report e - WHERE - project_id = r.project_id - AND e.account_id = #{pageReq.accountId} - AND assessment_id IS NULL - ORDER BY - score DESC - LIMIT 0, - 1 - ) AS hightScore, - ( - SELECT - IFNULL( count( 1 ), 0 ) - FROM - occupationlab.ol_experimental_report er - WHERE - er.project_id = r.project_id - AND account_id = #{pageReq.accountId} - AND er.assessment_id IS NULL - ) AS practiceNum, - r.curriculum_id + WHEN r.project_id IS NOT NULL + AND r.paper_id IS NOT NULL THEN + CONCAT( m.project_name, ' - ', p.NAME ) + WHEN r.project_id IS NOT NULL THEN + m.project_name + WHEN r.paper_id IS NOT NULL THEN + p.NAME ELSE NULL + END AS projectName, + MAX( r.score ) AS hightScore, + COUNT( * ) AS practiceNum, + FORMAT( SUM( r.time_sum ) / 60.0, 2 ) AS duration, + MAX( r.submit_time ) AS lastTime FROM occupationlab.ol_experimental_report r + LEFT JOIN exam.exam_paper p ON p.paper_id = r.paper_id + LEFT JOIN occupationlab.ol_project_manage m ON m.project_id = r.project_id + LEFT JOIN nakadai.curriculum c ON c.cid = r.curriculum_id WHERE r.account_id = #{pageReq.accountId} AND r.assessment_id IS NULL + and r.curriculum_id = #{pageReq.curriculumId} @@ -74,22 +45,10 @@ GROUP BY - r.project_id - ORDER BY - ( - SELECT - submit_time - FROM - occupationlab.ol_experimental_report e - WHERE - e.project_id = r.project_id - AND account_id = r.account_id - AND assessment_id IS NULL + r.project_id, + r.paper_id ORDER BY - report_id DESC - LIMIT 0, - 1 - ) DESC + lastTime DESC @@ -854,19 +789,41 @@ + + + + diff --git a/occupationlab/src/main/java/com/huoran/occupationlab/service/ExperimentalReportService.java b/occupationlab/src/main/java/com/huoran/occupationlab/service/ExperimentalReportService.java index 2c08ea97..672de6bc 100644 --- a/occupationlab/src/main/java/com/huoran/occupationlab/service/ExperimentalReportService.java +++ b/occupationlab/src/main/java/com/huoran/occupationlab/service/ExperimentalReportService.java @@ -12,6 +12,7 @@ import com.huoran.occupationlab.entity.vo.ProductClassInformationVO; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.validation.constraints.NotNull; import java.io.IOException; import java.util.List; @@ -106,7 +107,7 @@ public interface ExperimentalReportService extends IService * @auther: Rong * @date: 2021/9/30 15:35 */ - R practiceByStudentDetail(Integer curriculumId, Integer projectId, Integer accountId, Integer pageNum, Integer pageSize); + R practiceByStudentDetail(Integer curriculumId, Integer projectId, Integer accountId, Integer pageNum, Integer pageSize, Integer paperId); /** * @Description: 学生端-练习-导出实验情况 diff --git a/occupationlab/src/main/java/com/huoran/occupationlab/service/ProjectManageService.java b/occupationlab/src/main/java/com/huoran/occupationlab/service/ProjectManageService.java index e0aa4357..b04b9da2 100644 --- a/occupationlab/src/main/java/com/huoran/occupationlab/service/ProjectManageService.java +++ b/occupationlab/src/main/java/com/huoran/occupationlab/service/ProjectManageService.java @@ -95,9 +95,10 @@ public interface ProjectManageService extends IService { * 根据系统id获取系统内置项目 * * @param systemId + * @param keyword * @return */ - List getInternalProjectBySystemId(List systemId, Integer permissions); + List getInternalProjectBySystemId(List systemId, Integer permissions, String keyword); /** * 获取学校下所有系统id @@ -150,4 +151,6 @@ public interface ProjectManageService extends IService { Integer projectCreatedUnderProduct( Integer mallId, Integer permissions, Integer schoolId); R getCompetitionProjectByMiddleGround(PageAssessmentForProjectReq projectManageReq); + + R getProjectOrExamPaperByAssessment(PageAssessmentForProjectReq projectManage); } diff --git a/occupationlab/src/main/java/com/huoran/occupationlab/service/impl/ExperimentalReportServiceImpl.java b/occupationlab/src/main/java/com/huoran/occupationlab/service/impl/ExperimentalReportServiceImpl.java index ddc064db..eb393f38 100644 --- a/occupationlab/src/main/java/com/huoran/occupationlab/service/impl/ExperimentalReportServiceImpl.java +++ b/occupationlab/src/main/java/com/huoran/occupationlab/service/impl/ExperimentalReportServiceImpl.java @@ -59,6 +59,7 @@ import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.validation.constraints.NotNull; import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStream; @@ -175,7 +176,7 @@ public class ExperimentalReportServiceImpl extends ServiceImpl retList = baseMapper.exportPracticeByStudent(curriculumId, accountId); - // 告诉浏览器用什么软件可以打开此文件 - response.setHeader("content-Type", "application/vnd.ms-excel"); - // 下载文件的默认名称 - response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("学生练习实验成绩", "UTF-8") + - ".xls"); - //编码 - response.setCharacterEncoding("UTF-8"); + if (retList.size() == 0) { + //抛出 + return; + } + + + String curriculumName = retList.get(0).getCurriculumName() + "_练习实验成绩"; + String userName = TokenUtils.getUserName(); + String fileName = userName + "_" + curriculumName + ".xls"; + String encodedFileName = + URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString()).replace("+", "%20").replace("%2B", ""); + response.setHeader("Content-Disposition", encodedFileName); + + Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), ExportByStudentResp.class, retList); ExportParams exportParams = new ExportParams(null, "delivery", ExcelType.XSSF); exportParams.setStyle(ExcelStyleUtil.class); @@ -582,9 +590,10 @@ public class ExperimentalReportServiceImpl extends ServiceImpl page = new Page(pageNum, pageSize); - return R.ok().put("data", baseMapper.practiceByStudentDetail(page, curriculumId, projectId, accountId)); + return R.ok().put("data", baseMapper.practiceByStudentDetail(page, curriculumId, projectId, accountId, + paperId)); } @Override @@ -723,11 +732,11 @@ public class ExperimentalReportServiceImpl extends ServiceImpl reportIds = new ArrayList<>(); - if (req.getStageId()!= null){ + if (req.getStageId() != null) { //赛事单独处理,实验报告表没有stage_id字段,只有ol_user_score才存有 - List userScoreReportIds = userScoreMapper.userScoreReportIds(req.getStageId(),req.getCompetitionId()); + List userScoreReportIds = userScoreMapper.userScoreReportIds(req.getStageId(), + req.getCompetitionId()); reportIds.addAll(userScoreReportIds); return reportIds; } @@ -1598,10 +1608,10 @@ public class ExperimentalReportServiceImpl extends ServiceImpl map = result; reportData = (com.huoran.common.entity.ExperimentalReport) map.get("report"); - if (map.get("userScores")== null){ + if (map.get("userScores") == null) { String json = reportData.getData(); userScores = JSONArray.parseArray(json, UserScore.class); - }else { + } else { userScores = (List) map.get("userScores"); } @@ -1756,71 +1766,70 @@ public class ExperimentalReportServiceImpl extends ServiceImpl userScores = null; - com.huoran.common.entity.ExperimentalReport reportData = null; - - // 首先尝试从Redis中获取userScores的数量和reportData - if (redisTemplate.hasKey(totalScoreSetKey)) { - String userScoresSizeStr = (String) redisTemplate.opsForValue().get(totalScoreSetKey); - if (userScoresSizeStr != null) { - Integer userScoresSize = Integer.parseInt(userScoresSizeStr); - if (userScoresSize >= 30) { - // 直接从Redis中获取并解析userScores - String serializedUserScores = (String) redisTemplate.opsForValue().get(cacheKey); - userScores = JSON.parseArray(serializedUserScores, UserScore.class); - - // 同时从Redis中获取reportData - String serializedReportData = (String) redisTemplate.opsForValue().get(reportDataKey); - reportData = JSON.parseObject(serializedReportData, com.huoran.common.entity.ExperimentalReport.class); - - if (reportData != null) { - // 调用创建报告文件的方法 - return createReportFileFromDb(reportData, userScores, systemId, tempDir); + private Path generateSingleReportFileByProcessClass(Integer reportId, Path tempDir, Integer systemId) throws IOException, TemplateException { + String cacheKey = "userScores:" + reportId; + String totalScoreSetKey = "totalScoreSet:" + reportId; + String reportDataKey = "reportData:" + reportId; + List userScores = null; + com.huoran.common.entity.ExperimentalReport reportData = null; + + // 首先尝试从Redis中获取userScores的数量和reportData + if (redisTemplate.hasKey(totalScoreSetKey)) { + String userScoresSizeStr = (String) redisTemplate.opsForValue().get(totalScoreSetKey); + if (userScoresSizeStr != null) { + Integer userScoresSize = Integer.parseInt(userScoresSizeStr); + if (userScoresSize >= 30) { + // 直接从Redis中获取并解析userScores + String serializedUserScores = (String) redisTemplate.opsForValue().get(cacheKey); + userScores = JSON.parseArray(serializedUserScores, UserScore.class); + + // 同时从Redis中获取reportData + String serializedReportData = (String) redisTemplate.opsForValue().get(reportDataKey); + reportData = JSON.parseObject(serializedReportData, + com.huoran.common.entity.ExperimentalReport.class); + + if (reportData != null) { + // 调用创建报告文件的方法 + return createReportFileFromDb(reportData, userScores, systemId, tempDir); + } } } } - } - // 如果缓存中没有足够的数据,从数据库获取 - R result = reportDetail(reportId); - Integer status = (Integer) result.get("status"); - - if (status != null && status == 200) { - Map map = result; - reportData = (com.huoran.common.entity.ExperimentalReport) map.get("report"); - if (map.get("userScores")== null){ - String json = reportData.getData(); - userScores = JSONArray.parseArray(json, UserScore.class); - }else { - userScores = (List) map.get("userScores"); - } + // 如果缓存中没有足够的数据,从数据库获取 + R result = reportDetail(reportId); + Integer status = (Integer) result.get("status"); + if (status != null && status == 200) { + Map map = result; + reportData = (com.huoran.common.entity.ExperimentalReport) map.get("report"); + if (map.get("userScores") == null) { + String json = reportData.getData(); + userScores = JSONArray.parseArray(json, UserScore.class); + } else { + userScores = (List) map.get("userScores"); + } - if (reportData != null && userScores != null) { - int userScoresSize = userScores.size(); - if (userScoresSize >= 30) { - // 缓存userScores和reportData - redisTemplate.opsForValue().set(totalScoreSetKey, String.valueOf(userScoresSize)); - redisTemplate.opsForValue().set(cacheKey, JSON.toJSONString(userScores)); - redisTemplate.opsForValue().set(reportDataKey, JSON.toJSONString(reportData)); - // 调用创建报告文件的方法 - return createReportFileFromDb(reportData, userScores, systemId, tempDir); - }else { - return createReportFileFromDb(reportData, userScores, systemId, tempDir); + if (reportData != null && userScores != null) { + int userScoresSize = userScores.size(); + if (userScoresSize >= 30) { + // 缓存userScores和reportData + redisTemplate.opsForValue().set(totalScoreSetKey, String.valueOf(userScoresSize)); + redisTemplate.opsForValue().set(cacheKey, JSON.toJSONString(userScores)); + redisTemplate.opsForValue().set(reportDataKey, JSON.toJSONString(reportData)); + // 调用创建报告文件的方法 + return createReportFileFromDb(reportData, userScores, systemId, tempDir); + } else { + return createReportFileFromDb(reportData, userScores, systemId, tempDir); + } } } - } - - /* throw new IllegalStateException("报告数据不完整,无法生成文件。");*/ - System.out.println("报告数据不完整,无法生成文件。"); - return null; - } + /* throw new IllegalStateException("报告数据不完整,无法生成文件。");*/ + System.out.println("报告数据不完整,无法生成文件。"); + return null; + } // 新增方法用于使用缓存数据创建报告文件 @@ -2020,7 +2029,7 @@ public class ExperimentalReportServiceImpl extends ServiceImpl + * // * @param reportId + * // * @param tempDir * -// * @param reportId -// * @param tempDir * @return * @throws IOException * @throws TemplateException diff --git a/occupationlab/src/main/java/com/huoran/occupationlab/service/impl/ProjectManageServiceImpl.java b/occupationlab/src/main/java/com/huoran/occupationlab/service/impl/ProjectManageServiceImpl.java index da88a4f9..71a35765 100644 --- a/occupationlab/src/main/java/com/huoran/occupationlab/service/impl/ProjectManageServiceImpl.java +++ b/occupationlab/src/main/java/com/huoran/occupationlab/service/impl/ProjectManageServiceImpl.java @@ -10,16 +10,12 @@ import com.huoran.api.NakadaiClient; import com.huoran.api.UserClient; import com.huoran.common.constant.DelConstant; import com.huoran.common.constant.PlatformConstant; -import com.huoran.common.entity.BcJudgmentPoint; -import com.huoran.common.entity.LcJudgmentPoint; -import com.huoran.common.entity.ProjectJudgmentVo; -import com.huoran.common.entity.ProjectManage; +import com.huoran.common.entity.*; import com.huoran.common.entity.to.JudgmentPointDataTo; import com.huoran.common.entity.to.ProjectDataTo; import com.huoran.common.exception.CustomException; import com.huoran.common.exception.ExceptionEnum; import com.huoran.common.response.R; -import com.huoran.common.entity.ProjectJudgment; import com.huoran.occupationlab.entity.ProjectManageDisable; import com.huoran.occupationlab.entity.SchoolProjectHintOpen; import com.huoran.occupationlab.entity.req.PageAssessmentForProjectReq; @@ -118,7 +114,8 @@ public class ProjectManageServiceImpl extends ServiceImpl projectJudgmentList) { + private Integer bindProjectJudgment(Integer systemId, Integer projectId, + List projectJudgmentList) { int result = 1; // 根据系统查询判分点类型 Integer type = baseMapper.selectSystemType(systemId); @@ -212,12 +209,12 @@ public class ProjectManageServiceImpl extends ServiceImpl projectJudgmentVos = new ArrayList<>(); Map bcJudgmentPointMap = new HashMap<>(); Map lcJudgmentPointMap = new HashMap<>(); - if (type == 1){ + if (type == 1) { List lcJudgmentPoints; - if (stuAssessent != null){ + if (stuAssessent != null) { lcJudgmentPoints = judgmentPointClient.queryLcJudgmentByLcIds(judgmentIds, null); - }else { + } else { lcJudgmentPoints = judgmentPointClient.queryLcJudgmentByLcIds(judgmentIds, DelConstant.IS_OPEN); } @@ -226,13 +223,13 @@ public class ProjectManageServiceImpl extends ServiceImpl point, // value 为对应的 LcJudgmentPoint 对象 (existing, replacement) -> existing // 解决并发冲突 - )); + )); - }else { + } else { List bcJudgmentPoints; - if (stuAssessent != null){ + if (stuAssessent != null) { bcJudgmentPoints = judgmentPointClient.queryBcJudgmentByBcIds(judgmentIds, null); - }else { + } else { bcJudgmentPoints = judgmentPointClient.queryBcJudgmentByBcIds(judgmentIds, DelConstant.IS_OPEN); } @@ -241,7 +238,7 @@ public class ProjectManageServiceImpl extends ServiceImpl point, // value 为对应的 BcJudgmentPoint 对象 (existing, replacement) -> existing // 解决并发冲突 - )); + )); } @@ -311,8 +308,6 @@ public class ProjectManageServiceImpl extends ServiceImpl wrapper = new QueryWrapper().eq("project_name", projectManage.getProjectName()); + QueryWrapper wrapper = new QueryWrapper().eq("project_name", + projectManage.getProjectName()); wrapper.eq("is_del", DelConstant.NOT_DEL); wrapper.eq("zt_del", DelConstant.NOT_DEL); /*switch (projectManage.getFounder()) { @@ -420,13 +420,14 @@ public class ProjectManageServiceImpl extends ServiceImpl 100){ + if (number > 100) { // 使用方式 List scores = allocateScores(totalPoints, number); - return R.ok().put("data", scores).put("sum",scores.stream().mapToDouble(BigDecimal::doubleValue).sum()); + return R.ok().put("data", scores).put("sum", scores.stream().mapToDouble(BigDecimal::doubleValue).sum()); } List list = new ArrayList<>(); Integer score = totalPoints / number; @@ -442,13 +443,14 @@ public class ProjectManageServiceImpl extends ServiceImpl allocateScores(int totalPoints, int numberOfShares) { + // public static List allocateScores(int totalPoints, int numberOfShares) { // if (totalPoints <= 0 || numberOfShares <= 0 || numberOfShares > 1000) { -// throw new IllegalArgumentException("Invalid input. Total points must be positive, number of shares must be between 1 and 1000."); +// throw new IllegalArgumentException("Invalid input. Total points must be positive, number of shares must +// be between 1 and 1000."); // } // // BigDecimal totalScore = BigDecimal.valueOf(totalPoints); @@ -468,9 +470,11 @@ public class ProjectManageServiceImpl extends ServiceImpl 0) { -// scoresList.set(scoresList.size() - 1, scoresList.get(scoresList.size() - 1).subtract(sum.subtract(totalScore))); +// scoresList.set(scoresList.size() - 1, scoresList.get(scoresList.size() - 1).subtract(sum.subtract +// (totalScore))); // } // // // 四舍五入并保留一位小数 @@ -482,7 +486,8 @@ public class ProjectManageServiceImpl extends ServiceImpl allocateScores(int totalPoints, int numberOfShares) { if (totalPoints <= 0 || numberOfShares <= 0 || numberOfShares > 1000) { - throw new IllegalArgumentException("Invalid input. Total points must be positive, number of shares must be between 1 and 1000."); + throw new IllegalArgumentException("Invalid input. Total points must be positive, number of shares must " + + "be between 1 and 1000."); } BigDecimal totalScore = BigDecimal.valueOf(totalPoints); @@ -520,14 +525,14 @@ public class ProjectManageServiceImpl extends ServiceImpl projectManages = projectManageMapper .selectList(new QueryWrapper() - .eq("school_id", schoolId) - .eq("permissions", permissions) - .eq("zt_del", DelConstant.NOT_DEL) - .eq("is_del", DelConstant.NOT_DEL) - .eq("zt_open", 0) - .eq("is_open", 0) - .eq("mall_id", mallId).last(" AND FIND_IN_SET( system_id, '" + systemId + "' )") - ); + .eq("school_id", schoolId) + .eq("permissions", permissions) + .eq("zt_del", DelConstant.NOT_DEL) + .eq("is_del", DelConstant.NOT_DEL) + .eq("zt_open", 0) + .eq("is_open", 0) + .eq("mall_id", mallId).last(" AND FIND_IN_SET( system_id, '" + systemId + "' )") + ); //课程排序优于老师创建的项目 // List projectManageList = new ArrayList<>(); @@ -541,27 +546,35 @@ public class ProjectManageServiceImpl extends ServiceImpl projectManageList = projectManageMapper.selectSystemProject(schoolId, systemId, permissions, cId); + List projectManageList = projectManageMapper.selectSystemProject(schoolId, systemId, + permissions, cId); projectManageList.addAll(projectManages); - return R.ok().put("projects", projectManageList).put("projectSize", projectManageList.size()); + //查询当前课程绑定的练习试卷 + List practiceExamPaperList = projectManageMapper.getTestPaperByCourse( + permissions, cId); + + + return R.ok().put("projects", projectManageList).put("projectSize", projectManageList.size()).put( + "exercisePaperList", practiceExamPaperList); } @Override - public List getProjectBySystemIdRemoteCall(String systemId,Integer schoolId, Integer permissions, Integer cId, Integer mallId) { + public List getProjectBySystemIdRemoteCall(String systemId, Integer schoolId, Integer permissions, + Integer cId, Integer mallId) { List projectManages = projectManageMapper .selectList(new QueryWrapper() - .eq("school_id", schoolId) - .eq("permissions", permissions) - .eq("zt_del", DelConstant.NOT_DEL) - .eq("is_del", DelConstant.NOT_DEL) - .eq("zt_open", 0) - .eq("is_open", 0).eq("mall_id", mallId) - .last(" AND FIND_IN_SET( system_id, '" + systemId + "' )") - ); + .eq("school_id", schoolId) + .eq("permissions", permissions) + .eq("zt_del", DelConstant.NOT_DEL) + .eq("is_del", DelConstant.NOT_DEL) + .eq("zt_open", 0) + .eq("is_open", 0).eq("mall_id", mallId) + .last(" AND FIND_IN_SET( system_id, '" + systemId + "' )") + ); //课程排序优于老师创建的项目 List projectManageList = new ArrayList<>(); @@ -613,13 +626,37 @@ public class ProjectManageServiceImpl extends ServiceImpl getInternalProjectBySystemId(List systemId, Integer permissions) { + public List getInternalProjectBySystemId(List systemId, Integer permissions, + String keyword) { String id = ""; + List systemTypes = new ArrayList<>(); for (Integer sysId : systemId) { id += sysId + ","; + + int type = baseMapper.selectSystemType(sysId); + systemTypes.add(type); } String systemIds = id.substring(0, id.length() - 1); - return baseMapper.selectProjectList(systemIds, permissions); + + List projectManageList = baseMapper.selectProjectList(systemIds, permissions, keyword); + + //如果systemTypes包含了3,那么查询查询对应的理论试卷 + if (systemTypes.contains(3)) { + + projectManageList.addAll(getAllExamPaper(keyword)); + } + return projectManageList; + } + + + /** + * 获取中台发布的全部全部试卷 + * + * @return + */ + + public List getAllExamPaper(String keyword) { + return baseMapper.getAllExamPaper(0, keyword); } @Override @@ -697,7 +734,8 @@ public class ProjectManageServiceImpl extends ServiceImpl page = new Page(projectManageReq.getPageNum(), projectManageReq.getPageSize()); + Page page = new Page(projectManageReq.getPageNum(), + projectManageReq.getPageSize()); IPage iPage = null; /* @@ -719,7 +757,8 @@ public class ProjectManageServiceImpl extends ServiceImpl系统筛选 // iPage = baseMapper.selectPage(page, queryWrapper); @@ -749,7 +788,8 @@ public class ProjectManageServiceImpl extends ServiceImpl page = new Page(projectManageReq.getPageNum(), projectManageReq.getPageSize()); + Page page = new Page(projectManageReq.getPageNum(), + projectManageReq.getPageSize()); IPage iPage = null; QueryWrapper queryWrapper = new QueryWrapper<>(); @@ -763,7 +803,7 @@ public class ProjectManageServiceImpl extends ServiceImpl openQueryWrapper = new QueryWrapper<>(); openQueryWrapper.eq("school_id", projectManageReq.getSchoolId()); openQueryWrapper.eq("project_id", record.getProjectId()); - SchoolProjectHintOpen schoolProjectHintOpen = schoolProjectHintOpenMapper.selectOne(openQueryWrapper); + SchoolProjectHintOpen schoolProjectHintOpen = + schoolProjectHintOpenMapper.selectOne(openQueryWrapper); if (ObjectUtil.isNotNull(schoolProjectHintOpen)) { record.setHintOpenBySchool(schoolProjectHintOpen.getHintOpen()); } else { @@ -790,7 +831,9 @@ public class ProjectManageServiceImpl extends ServiceImpl accountIdList = userClient.getAccountIdsBySchoolId(projectManageReq.getSchoolId(), PlatformConstant.POST_STATION); + List accountIdList = + userClient.getAccountIdsBySchoolId(projectManageReq.getSchoolId(), + PlatformConstant.POST_STATION); //为满足非超管、管理员的角色情况下能看到本人及超管、管理员角色发布的项目 由此将当前用户的账号id赋值进去List accountIdList.add(projectManageReq.getAccountId()); projectManageReq.setAccountIdList(accountIdList); @@ -801,7 +844,8 @@ public class ProjectManageServiceImpl extends ServiceImpl openQueryWrapper = new QueryWrapper<>(); openQueryWrapper.eq("school_id", projectManageReq.getSchoolId()); openQueryWrapper.eq("project_id", record.getProjectId()); - SchoolProjectHintOpen schoolProjectHintOpen = schoolProjectHintOpenMapper.selectOne(openQueryWrapper); + SchoolProjectHintOpen schoolProjectHintOpen = + schoolProjectHintOpenMapper.selectOne(openQueryWrapper); if (ObjectUtil.isNotNull(schoolProjectHintOpen)) { record.setHintOpenBySchool(schoolProjectHintOpen.getHintOpen()); } else { @@ -813,7 +857,7 @@ public class ProjectManageServiceImpl extends ServiceImpl accountIdList = userClient.getAccountIdsBySchoolId(projectManageReq.getSchoolId(), PlatformConstant.POST_STATION); + List accountIdList = userClient.getAccountIdsBySchoolId(projectManageReq.getSchoolId(), + PlatformConstant.POST_STATION); //为满足非超管、管理员的角色情况下能看到本人及超管、管理员角色发布的项目 由此将当前用户的账号id赋值进去List accountIdList.add(projectManageReq.getAccountId()); projectManageReq.setAccountIdList(accountIdList); @@ -834,7 +879,8 @@ public class ProjectManageServiceImpl extends ServiceImpl openQueryWrapper = new QueryWrapper<>(); openQueryWrapper.eq("school_id", projectManageReq.getSchoolId()); openQueryWrapper.eq("project_id", record.getProjectId()); - SchoolProjectHintOpen schoolProjectHintOpen = schoolProjectHintOpenMapper.selectOne(openQueryWrapper); + SchoolProjectHintOpen schoolProjectHintOpen = + schoolProjectHintOpenMapper.selectOne(openQueryWrapper); if (ObjectUtil.isNotNull(schoolProjectHintOpen)) { record.setHintOpenBySchool(schoolProjectHintOpen.getHintOpen()); } else { @@ -865,7 +911,8 @@ public class ProjectManageServiceImpl extends ServiceImpl accountIdList = userClient.getAccountIdsBySchoolId(projectManageReq.getSchoolId(), PlatformConstant.POST_STATION); + List accountIdList = userClient.getAccountIdsBySchoolId(projectManageReq.getSchoolId(), + PlatformConstant.POST_STATION); //为满足非超管、管理员的角色情况下能看到本人及超管、管理员角色发布的项目 由此将当前用户的账号id赋值进去List accountIdList.add(projectManageReq.getAccountId()); projectManageReq.setAccountIdList(accountIdList); @@ -889,6 +936,13 @@ public class ProjectManageServiceImpl extends ServiceImpl page = new Page(req.getPageNum(), req.getPageSize()); + IPage iPage = baseMapper.getProjectOrExamPaperByAssessment(page, req); + return R.ok().put("data", iPage); + } + @Override public R getProjectAssessmentByCompetition(PageAssessmentForProjectReq req) { Page page = new Page(req.getPageNum(), req.getPageSize()); @@ -911,7 +965,7 @@ public class ProjectManageServiceImpl extends ServiceImpl judgmentIds = projectJudgmentMapper.selectBcJudgmentIdList(projectDataTo.getSet(), projectDataTo.getName()); + ArrayList judgmentIds = projectJudgmentMapper.selectBcJudgmentIdList(projectDataTo.getSet(), + projectDataTo.getName()); JudgmentPointDataTo judgmentPointDataTo = new JudgmentPointDataTo(); judgmentPointDataTo.setJudgmentIds(judgmentIds); return judgmentPointDataTo; } else { //查询流程判分点 - ArrayList judgmentIds = projectJudgmentMapper.selectLcJudgmentIdList(projectDataTo.getSet(), projectDataTo.getName()); + ArrayList judgmentIds = projectJudgmentMapper.selectLcJudgmentIdList(projectDataTo.getSet(), + projectDataTo.getName()); JudgmentPointDataTo judgmentPointDataTo = new JudgmentPointDataTo(); judgmentPointDataTo.setJudgmentIds(judgmentIds); return judgmentPointDataTo;