diff --git a/src/main/java/com/zcloud/mapper/dsno3/eduStudy/PaperQuestionCacheMapper.java b/src/main/java/com/zcloud/mapper/dsno3/eduStudy/PaperQuestionCacheMapper.java new file mode 100644 index 0000000..2360c98 --- /dev/null +++ b/src/main/java/com/zcloud/mapper/dsno3/eduStudy/PaperQuestionCacheMapper.java @@ -0,0 +1,169 @@ +package com.zcloud.mapper.dsno3.eduStudy; + +import com.zcloud.entity.Page; +import com.zcloud.entity.PageData; + +import java.util.List; + +/** + * 说明:习题管理暂存 + * 作者:zhangyanli + * 时间:2023-04-26 + * 官网:www.zcloudchina.com + */ +public interface PaperQuestionCacheMapper { + + /** + * 新增 + * + * @param pd + * @throws Exception + */ + void save(PageData pd); + + /** + * 删除 + * + * @param pd + * @throws Exception + */ + void delete(PageData pd); + + /** + * 修改 + * + * @param pd + * @throws Exception + */ + void edit(PageData pd); + + /** + * 列表 + * + * @param page + * @throws Exception + */ + List datalistPage(Page page); + + /** + * 列表(全部) + * + * @param pd + * @throws Exception + */ + List listAll(PageData pd); + + /** + * 通过id获取数据 + * + * @param pd + * @throws Exception + */ + PageData findById(PageData pd); + + /** + * 批量删除 + * + * @param pd + * @throws Exception + */ + void deleteAll(PageData pd); + + /** + * 列表(根据所选ID获取数据) + * + * @param pd + * @throws Exception + */ + List findByIds(PageData pd); + + /** + * 批量删除(根据所选课件ids删除习题) + * + * @param pd + * @throws Exception + */ + void deleteByCoursewareIds(PageData pd); + + /** + * 列表(根据课程所选课件获取习题数据) + * + * @param pd CURRICULUMID 课件ID + * @throws Exception + */ + List listByCourseware(PageData pd); + + /** + * 列表(根据阶段考试所选课件获取习题数据) + * + * @param pd CURRICULUMID 课件ID + * @throws Exception + */ + List findForStageByQuestionNum(PageData pd); + + /** + * 列表(根据课程所选课件获取习题数据) + * + * @param pd CURRICULUMID 课件ID + * @throws Exception + */ + Integer countByCourseware(PageData pd); + + /** + * 列表(根据阶段考试所选课件范围获取习题数据) + * + * @param pd COURSEWARES 课件ID+课件分类 + * @throws Exception + */ + Integer countByStageExamCourseware(PageData pd); + + /** + * 列表(全部) 根据类型获取习题数据 -- 准备随机选题 + * + * @param pd + * @throws Exception + */ + List listAllByType(PageData pd); + + Integer hasQuestionNumber(PageData pd); + + /** + * 获取最大题号,导入时候使用 + * + * @param pd + * @return + * @throws Exception + */ + Integer maxQuestionNumber(PageData pd); + + /** + * 获取 + * 该企业下的 + * 该培训行业类型 + * 该岗位培训类型 + * 下的习题个数 + * + * @param pd + * @return + */ + List getCountByQuestionType(PageData pd); + + /** + * 查询试卷试题总分数 + * + * @param pd + * @return + */ + String getScoreByPaper(PageData pd); + + /** + * 删除试卷下习题 + * + * @param pd + * @throws Exception + */ + void deleteByPaper(PageData pd); + + List getPaperQuestionInfo(PageData pd); +} + diff --git a/src/main/java/com/zcloud/mapper/dsno3/eduStudy/StageexampaperCacheMapper.java b/src/main/java/com/zcloud/mapper/dsno3/eduStudy/StageexampaperCacheMapper.java new file mode 100644 index 0000000..e87cc55 --- /dev/null +++ b/src/main/java/com/zcloud/mapper/dsno3/eduStudy/StageexampaperCacheMapper.java @@ -0,0 +1,98 @@ +package com.zcloud.mapper.dsno3.eduStudy; + +import com.zcloud.entity.Page; +import com.zcloud.entity.PageData; + +import java.util.LinkedList; +import java.util.List; + +/** + * 说明:试卷暂存 + * 作者:wangxuan + * 官网:www.zcloudchina.com + */ +public interface StageexampaperCacheMapper { + + /** + * 新增 + * + * @param pd + * @throws Exception + */ + void save(PageData pd); + + /** + * 删除 + * + * @param pd + * @throws Exception + */ + void delete(PageData pd); + + /** + * 修改 + * + * @param pd + * @throws Exception + */ + void edit(PageData pd); + + /** + * 列表 + * + * @param page + * @throws Exception + */ + List datalistPage(Page page); + + /** + * 列表(全部) + * + * @param pd + * @throws Exception + */ + List listAll(PageData pd); + + /** + * 通过id获取数据 + * + * @param pd + * @throws Exception + */ + PageData findById(PageData pd); + + /** + * 批量删除 + * + * @param ArrayDATA_IDS + * @throws Exception + */ + void deleteAll(String[] ArrayDATA_IDS); + + /** + * 修改 状态 + * + * @param pd + * @throws Exception + */ + void editState(PageData pd); + + /** + * 修改 状态 + * + * @param pd + * @throws Exception + */ + void editIssell(PageData pd); + + /** + * 修改试卷分数 + * + * @param pd + * @throws Exception + */ + void editExamscore(PageData pd); + + + void saveTestPaper(LinkedList preData); +} diff --git a/src/main/java/com/zcloud/service/eduStudy/impl/PaperQuestionCacheServiceImpl.java b/src/main/java/com/zcloud/service/eduStudy/impl/PaperQuestionCacheServiceImpl.java new file mode 100644 index 0000000..498238d --- /dev/null +++ b/src/main/java/com/zcloud/service/eduStudy/impl/PaperQuestionCacheServiceImpl.java @@ -0,0 +1,232 @@ +package com.zcloud.service.eduStudy.impl; + +import com.zcloud.entity.Page; +import com.zcloud.entity.PageData; +import com.zcloud.mapper.dsno3.eduStudy.PaperQuestionCacheMapper; +import com.zcloud.service.eduStudy.PaperQuestionCacheService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +/** + * 说明:习题管理暂存 + * 作者:zhangyanli + * 时间:2023-04-26 + * 官网:www.zcloudchina.com + */ +@Service +@Transactional //开启事物 +public class PaperQuestionCacheServiceImpl implements PaperQuestionCacheService { + + @Autowired + private PaperQuestionCacheMapper paperQuestionCacheMapper; + + /** + * 新增 + * + * @param pd + * @throws Exception + */ + public void save(PageData pd) throws Exception { + paperQuestionCacheMapper.save(pd); + } + + /** + * 删除 + * + * @param pd + * @throws Exception + */ + public void delete(PageData pd) throws Exception { + paperQuestionCacheMapper.delete(pd); + } + + /** + * 修改 + * + * @param pd + * @throws Exception + */ + public void edit(PageData pd) throws Exception { + paperQuestionCacheMapper.edit(pd); + } + + /** + * 列表 + * + * @param page + * @throws Exception + */ + public List list(Page page) throws Exception { + return paperQuestionCacheMapper.datalistPage(page); + } + + /** + * 列表(全部) + * + * @param pd + * @throws Exception + */ + public List listAll(PageData pd) throws Exception { + return paperQuestionCacheMapper.listAll(pd); + } + + /** + * 通过id获取数据 + * + * @param pd + * @throws Exception + */ + public PageData findById(PageData pd) throws Exception { + return paperQuestionCacheMapper.findById(pd); + } + + /** + * 批量删除 + * + * @param pd + * @throws Exception + */ + public void deleteAll(PageData pd) throws Exception { + paperQuestionCacheMapper.deleteAll(pd); + } + + /** + * 列表(根据所选ID获取数据) + * + * @param pd + * @throws Exception + */ + public List findByIds(PageData pd) throws Exception { + return paperQuestionCacheMapper.findByIds(pd); + } + + /** + * 批量删除(根据所选课件ids删除习题) + * + * @param pd + * @throws Exception + */ + @Override + public void deleteByCoursewareIds(PageData pd) throws Exception { + paperQuestionCacheMapper.deleteByCoursewareIds(pd); + } + + /** + * 列表(根据课程所选课件获取习题数据) + * + * @param pd CURRICULUMID 课件ID + * @throws Exception + */ + @Override + public List listByCourseware(PageData pd) throws Exception { + return paperQuestionCacheMapper.listByCourseware(pd); + } + + /** + * 按照试卷试题数及试卷所选课件范围随机抽取试题 + * + * @param pd CURRICULUMID 课件ID + * @return + */ + @Override + public List findForStageByQuestionNum(PageData pd) { + int QUESTIONNUM = Integer.parseInt(pd.getString("QUESTIONNUM")); + pd.put("COURSEWARE_IDS", pd.getString("COURSEWARES").split(",")); + List qlist = paperQuestionCacheMapper.findForStageByQuestionNum(pd); //根据阶段考试所选课件获取习题数据 + List tempList = new ArrayList(); + List questions = new ArrayList(); + if (QUESTIONNUM > qlist.size()) { + System.out.println("课程习题总数少于考试试题数,无法生成试卷试题"); + return questions; + } + for (int i = 0; i < QUESTIONNUM; i++) { + int random = new Random().nextInt(qlist.size()); + if (!tempList.contains(random)) { + tempList.add(random); + questions.add(qlist.get(random)); + } else { + i--; + } + } + System.out.println("抽取的阶段考试试题索引值:" + tempList.toString()); + return questions; + } + + /** + * 列表(全部) 根据类型获取习题数据 -- 准备随机选题 + * + * @param pd + * @throws Exception + */ + public List listAllByType(PageData pd) throws Exception { + return paperQuestionCacheMapper.listAllByType(pd); + } + + public Integer hasQuestionNumber(PageData pd) throws Exception { + return paperQuestionCacheMapper.hasQuestionNumber(pd); + } + + /** + * 获取最大题号,导入时候使用 + * + * @param pd + * @return + * @throws Exception + */ + public Integer maxQuestionNumber(PageData pd) throws Exception { + return paperQuestionCacheMapper.maxQuestionNumber(pd); + } + + /** + * 获取 + * 该企业下的 + * 该培训行业类型 + * 该岗位培训类型 + * 下的习题个数 + * + * @param pd + * @return + */ + public List getCountByQuestionType(PageData pd) throws Exception { + return paperQuestionCacheMapper.getCountByQuestionType(pd); + } + + + /** + * 查询试卷试题总分数 + * + * @param pd + * @return + * @throws Exception + */ + public String getScoreByPaper(PageData pd) throws Exception { + return paperQuestionCacheMapper.getScoreByPaper(pd); + } + + /** + * 查询试卷试题总分数 + * + * @param pd + * @return + * @throws Exception + */ + public void deleteByPaper(PageData pd) throws Exception { + paperQuestionCacheMapper.deleteByPaper(pd); + } + + /** + * 获取草稿试题信息 + * + * @param pd + * @throws Exception + */ + public List getPaperQuestionInfo(PageData pd) throws Exception { + return paperQuestionCacheMapper.getPaperQuestionInfo(pd); + } +} + diff --git a/src/main/java/com/zcloud/service/eduStudy/impl/StageexampaperCacheServiceImpl.java b/src/main/java/com/zcloud/service/eduStudy/impl/StageexampaperCacheServiceImpl.java new file mode 100644 index 0000000..ca54337 --- /dev/null +++ b/src/main/java/com/zcloud/service/eduStudy/impl/StageexampaperCacheServiceImpl.java @@ -0,0 +1,420 @@ +package com.zcloud.service.eduStudy.impl; + +import com.zcloud.entity.Page; +import com.zcloud.entity.PageData; +import com.zcloud.mapper.dsno3.eduStudy.StageexampaperCacheMapper; +import com.zcloud.service.eduStudy.QuestionService; +import com.zcloud.service.eduStudy.StageexampaperCacheService; +import com.zcloud.util.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; + +/** + * 说明:试卷暂存 + * 作者:zhangyanli + * 时间:2023-04-26 + * 官网:www.zcloudchina.com + */ +@Service +public class StageexampaperCacheServiceImpl implements StageexampaperCacheService { + + // 填空题目 0 填空答案1 分值2 答案解析3 标签类型4 + @Autowired + private StageexampaperCacheMapper stageexampaperCacheMapper; + @Autowired + private QuestionService questionService; + + /** + * 新增 + * + * @param pd + * @throws Exception + */ + public void save(PageData pd) throws Exception { + stageexampaperCacheMapper.save(pd); // 保存试卷表 + + } + + /** + * 删除 + * + * @param pd + * @throws Exception + */ + public void delete(PageData pd) throws Exception { + stageexampaperCacheMapper.delete(pd); + } + + /** + * 修改 + * + * @param pd + * @throws Exception + */ + public void edit(PageData pd) throws Exception { + stageexampaperCacheMapper.edit(pd); + } + + /** + * 列表 + * + * @param page + * @throws Exception + */ + public List list(Page page) throws Exception { + return stageexampaperCacheMapper.datalistPage(page); + } + + /** + * 列表(全部) + * + * @param pd + * @throws Exception + */ + public List listAll(PageData pd) throws Exception { + return stageexampaperCacheMapper.listAll(pd); + } + + /** + * 通过id获取数据 + * + * @param pd + * @throws Exception + */ + public PageData findById(PageData pd) throws Exception { + return stageexampaperCacheMapper.findById(pd); + } + + /** + * 批量删除 + * + * @param ArrayDATA_IDS + * @throws Exception + */ + public void deleteAll(String[] ArrayDATA_IDS) throws Exception { + stageexampaperCacheMapper.deleteAll(ArrayDATA_IDS); + } + + public List getSaveStage(PageData pd) throws Exception { + List valList = new ArrayList<>(); + for (int i = 1; i <= 3; i++) { + String xitiType = ""; + Integer QUESTIONSCORE = 0; + if (1 == i) { + xitiType = "DANYUANTICOUNT"; + QUESTIONSCORE = Integer.parseInt(pd.getString("DANXUANTINUMBER")); + } else if (2 == i) { + xitiType = "DUOXUANTICOUNT"; + QUESTIONSCORE = Integer.parseInt(pd.getString("DUOXUANTINUMBER")); + } else if (3 == i) { + xitiType = "PANDUITICOUNT"; + QUESTIONSCORE = Integer.parseInt(pd.getString("PANDUITINUMBER")); + } + PageData questionPd = new PageData(); + questionPd.put("TRAINTYPE", pd.getString("TRAINTYPE")); // 培训行业类型 + questionPd.put("POSTTYPE", pd.getString("POSTTYPE")); // 岗位培训类型 + questionPd.put("QUESTIONTYPE", i); //试题类型(单选题、多选题、判断题) + questionPd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID()); //企业信息 + List questionAllList = questionService.listAllByType(questionPd); // 获取该类型的习题数据 + Integer danxuanNmber = Integer.parseInt(pd.getString(xitiType)); //选择该类型数据的个数 + + if (danxuanNmber > questionAllList.size()) { + System.out.println("课程习题总数少于考试试题数,无法生成试卷试题"); + return null; + } + List tempList = new ArrayList(); //索引 + for (int j = 0; j < danxuanNmber; j++) { + int random = new Random().nextInt(questionAllList.size()); + if (!tempList.contains(random)) { + tempList.add(random); + PageData quMap = questionAllList.get(random); + quMap.put("QUESTIONSCORE", QUESTIONSCORE); //添加分数 + valList.add(quMap); + } else { + j--; + } + } + } + return valList; + } + + /** + * 修改 状态 + * + * @param pd + * @throws Exception + */ + public void editState(PageData pd) throws Exception { + stageexampaperCacheMapper.editState(pd); + } + + /** + * 修改 状态 + * + * @param pd + * @throws Exception + */ + public void editIssell(PageData pd) throws Exception { + stageexampaperCacheMapper.editIssell(pd); + } + + /** + * 修改试卷分数 + * + * @param pd + * @throws Exception + */ + public void editExamscore(PageData pd) throws Exception { + stageexampaperCacheMapper.editExamscore(pd); + } + + @Override + public BigDecimal getSingleMultipleChoiceList(AtomicInteger QUESTIONNUMBER, boolean hasScore, String ID, StringBuilder errorMsg, PageData pg, String filePath, String fileName, LinkedList preData, Map labelTypeeMap) { + + // 获取题号 + + AtomicReference sum = new AtomicReference<>(new BigDecimal(0)); + for (int i = 0; i < 2; i++) { + // 单选题目 0 单选选项A 1 单选选项B 2 单选选项C 3 单选选项D 4 单选答案 5 分值 6 答案解析 7 标签类型 8 + // 多选题目 多选选项A 多选选项B 多选选项C 多选选项D 多选答案 分值 答案解析 标签类型 + // 说明有题 + List listPd = (List) ObjectExcelRead.readExcel(filePath, fileName, 1, 0, i); + if (listPd.size() > 0) { + ArrayList sheet0 = new ArrayList() {{ + add("单选题目"); + add("单选选项A"); + add("单选选项B"); + add("单选选项C"); + add("单选选项D"); + add("单选答案"); + if (hasScore) { + add("分值"); + } + add("答案解析"); + add("标签类型"); + add("关联课件名称"); + }}; + ArrayList sheet1 = new ArrayList() {{ + add("多选题目"); + add("多选选项A"); + add("多选选项B"); + add("多选选项C"); + add("多选选项D"); + add("多选答案"); + if (hasScore) { + add("分值"); + } + add("答案解析"); + add("标签类型"); + add("关联课件名称"); + }}; + String[] CHOICE; + if (hasScore) { + CHOICE = new String[]{ + "QUESTIONDRY" + , "OPTIONA" + , "OPTIONB" + , "OPTIONC" + , "OPTIOND" + , "ANSWER" + , "SCORE" + , "DESCR" + , "LABEL_TYPE" + , "COURSEWARENAME" + }; + } else { + CHOICE = new String[]{ + "QUESTIONDRY" + , "OPTIONA" + , "OPTIONB" + , "OPTIONC" + , "OPTIOND" + , "ANSWER" + , "DESCR" + , "LABEL_TYPE" + , "COURSEWARENAME" + }; + } + + + HashMap CHOICE_COLUMN = new HashMap(); + HashMap> hMap = new HashMap<>(); + hMap.put(0, sheet0); + hMap.put(1, sheet1); + PageData data = listPd.get(0); + ArrayList sheet = hMap.get(i); + if (data == null || data.size() == 0 || data.size() != sheet.size()) { + String sheetType = ""; + if (i == 0) { + sheetType = "单选题"; + } else if (i == 1) { + sheetType = "多选题"; + } + errorMsg.append("请检查" + sheetType + "导入模板表头中字段是否正确\n"); + return sum.get(); + } + for (int k = 0; k < sheet.size(); k++) { + if (!data.get("var" + k).toString().equals(sheet.get(k))) { + errorMsg.append("请检查导入模板表头中字段 " + sheet.get(k) + " 是否正确\n"); + return sum.get(); + } + CHOICE_COLUMN.put(k, sheet.get(k)); + } + listPd.remove(0); + // 替换标签类型 + int finalI = i; + listPd.forEach(x -> { + // 参数正确 + QUESTIONNUMBER.getAndIncrement(); + // 设置标签类型 LABEL_TYPE + String LABEL_TYPE_ID = labelTypeeMap.get(x.getString("var8")); + if (Tools.notEmpty(LABEL_TYPE_ID)) { + x.put("var8", LABEL_TYPE_ID); + } else { + // 让他提示 标签类型找不到 + x.put("var8", "NO_Label_Type"); + } + // 题干 + // 校验 空值 + PaperTextValid.checkValid(errorMsg, finalI, QUESTIONNUMBER.get(), x, CHOICE, CHOICE_COLUMN, true); + // 主键 + x.put(ID, UuidUtil.get32UUID()); + // 设置题型 + x.put("QUESTIONTYPE", finalI + 1); + // 设置序号 + x.put("QUESTIONNUMBER", QUESTIONNUMBER.get()); + + if (hasScore) { + if (PaperTextValid.isNumeric((String) x.get("var6"))) { + //防止分值get报错 + BigDecimal var6 = sum.get().add(new BigDecimal((String) x.get("var6"))); + sum.set(var6); + } + } + + // 基础信息 + x.putAll(pg); + preData.add(x); + }); + } + + } + return sum.get(); + } + + @Override + public BigDecimal getJudgeCompletionChoiceList(AtomicInteger QUESTIONNUMBER, boolean hasScore, String ID, StringBuilder errorMsg, PageData pg, String filePath, String fileName, LinkedList preData, Map labelTypeeMap) { + + AtomicReference sum = new AtomicReference<>(new BigDecimal(0)); + for (int i = 2; i < 3; i++) { + // 校验表头 + List listPd = (List) ObjectExcelRead.readExcel(filePath, fileName, 1, 0, i); + // 填空题目 0 填空答案1 分值2 答案解析3 标签类型4 + // 说明有题 + if (listPd.size() > 0) { + String[] BLANKS; + if (hasScore) { + BLANKS = new String[]{ + "QUESTIONDRY" + , "ANSWER" + , "SCORE" + , "DESCR" + , "LABEL_TYPE" + , "COURSEWARENAME" + }; + } else { + BLANKS = new String[]{ + "QUESTIONDRY" + , "ANSWER" + , "DESCR" + , "LABEL_TYPE" + , "COURSEWARENAME" + }; + } + + HashMap BLANKS_COLUMN = new HashMap(); + ArrayList sheet2 = new ArrayList() {{ + add("判断题目"); + add("判断答案"); + if (hasScore) { + add("分值"); + } + add("答案解析"); + add("标签类型"); + add("关联课件名称"); + }}; + HashMap> hMap = new HashMap<>(); + hMap.put(2, sheet2); + PageData data = listPd.get(0); + ArrayList sheet = hMap.get(i); + if (data == null || data.size() == 0 || data.size() != sheet.size()) { + String sheetType = ""; + if (i == 2) { + sheetType = "判断题"; + } + errorMsg.append("请检查" + sheetType + "导入模板表头中字段是否正确\n"); + return sum.get(); + } + for (int k = 0; k < sheet.size(); k++) { + if (!data.get("var" + k).toString().equals(sheet.get(k))) { + errorMsg.append("请检查导入模板表头中字段 " + sheet.get(k) + " 是否正确\n"); + return sum.get(); + } + BLANKS_COLUMN.put(k, sheet.get(k)); + } + listPd.remove(0); + // 替换标签类型 + int finalI = i; + listPd.forEach(x -> { + QUESTIONNUMBER.getAndIncrement(); + // 题干 + // 填空题目 0 填空答案1 分值2 答案解析3 标签类型4 + // 选项 abcd + x.put("OPTIONA", "对"); + x.put("OPTIONB", "错"); + // var4 + String LABEL_TYPE_ID = labelTypeeMap.get(x.getString("var4")); + if (Tools.notEmpty(LABEL_TYPE_ID)) { + x.put("var4", LABEL_TYPE_ID); + } else { + // 让他提示 标签类型找不到 + x.put("var4", "NO_Label_Type"); + } + // 校验 空 + PaperTextValid.checkValid(errorMsg, finalI, QUESTIONNUMBER.get(), x, BLANKS, BLANKS_COLUMN, false); + // 填空 + // 答案 + // 填空题目 0 填空答案1 分值2 答案解析3 标签类型4 + // 主键 + x.put(ID, UuidUtil.get32UUID()); + // 设置题型 + x.put("QUESTIONTYPE", finalI + 1); + // 设置序号 + x.put("QUESTIONNUMBER", QUESTIONNUMBER.get()); + if (hasScore) { + if (PaperTextValid.isNumeric((String) x.get("var2"))) { + //防止分值get报错 + BigDecimal var2 = sum.get().add(new BigDecimal((String) x.get("var2"))); + sum.set(var2); + } + } + // 基础信息 + x.putAll(pg); + preData.add(x); + }); + } + } + return sum.get(); + } + + @Override + public void saveTestPaper(LinkedList preData) { + stageexampaperCacheMapper.saveTestPaper(preData); + } +} +