教培功能

dev
zhangyanli 2024-03-22 09:38:57 +08:00
parent 7f8b9402ce
commit 70002e33a7
4 changed files with 919 additions and 0 deletions

View File

@ -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<PageData> datalistPage(Page page);
/**
* ()
*
* @param pd
* @throws Exception
*/
List<PageData> 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<PageData> findByIds(PageData pd);
/**
* (ids)
*
* @param pd
* @throws Exception
*/
void deleteByCoursewareIds(PageData pd);
/**
* ()
*
* @param pd CURRICULUMID ID
* @throws Exception
*/
List<PageData> listByCourseware(PageData pd);
/**
* ()
*
* @param pd CURRICULUMID ID
* @throws Exception
*/
List<PageData> 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<PageData> listAllByType(PageData pd);
Integer hasQuestionNumber(PageData pd);
/**
* 使
*
* @param pd
* @return
* @throws Exception
*/
Integer maxQuestionNumber(PageData pd);
/**
*
*
*
*
*
*
* @param pd
* @return
*/
List<PageData> getCountByQuestionType(PageData pd);
/**
*
*
* @param pd
* @return
*/
String getScoreByPaper(PageData pd);
/**
*
*
* @param pd
* @throws Exception
*/
void deleteByPaper(PageData pd);
List<PageData> getPaperQuestionInfo(PageData pd);
}

View File

@ -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<PageData> datalistPage(Page page);
/**
* ()
*
* @param pd
* @throws Exception
*/
List<PageData> 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<PageData> preData);
}

View File

@ -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<PageData> list(Page page) throws Exception {
return paperQuestionCacheMapper.datalistPage(page);
}
/**
* ()
*
* @param pd
* @throws Exception
*/
public List<PageData> 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<PageData> 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<PageData> listByCourseware(PageData pd) throws Exception {
return paperQuestionCacheMapper.listByCourseware(pd);
}
/**
*
*
* @param pd CURRICULUMID ID
* @return
*/
@Override
public List<PageData> findForStageByQuestionNum(PageData pd) {
int QUESTIONNUM = Integer.parseInt(pd.getString("QUESTIONNUM"));
pd.put("COURSEWARE_IDS", pd.getString("COURSEWARES").split(","));
List<PageData> qlist = paperQuestionCacheMapper.findForStageByQuestionNum(pd); //根据阶段考试所选课件获取习题数据
List<Integer> tempList = new ArrayList<Integer>();
List<PageData> questions = new ArrayList<PageData>();
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<PageData> 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<PageData> 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<PageData> getPaperQuestionInfo(PageData pd) throws Exception {
return paperQuestionCacheMapper.getPaperQuestionInfo(pd);
}
}

View File

@ -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<PageData> list(Page page) throws Exception {
return stageexampaperCacheMapper.datalistPage(page);
}
/**
* ()
*
* @param pd
* @throws Exception
*/
public List<PageData> 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<PageData> getSaveStage(PageData pd) throws Exception {
List<PageData> 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<PageData> questionAllList = questionService.listAllByType(questionPd); // 获取该类型的习题数据
Integer danxuanNmber = Integer.parseInt(pd.getString(xitiType)); //选择该类型数据的个数
if (danxuanNmber > questionAllList.size()) {
System.out.println("课程习题总数少于考试试题数,无法生成试卷试题");
return null;
}
List<Integer> tempList = new ArrayList<Integer>(); //索引
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<PageData> preData, Map<String, String> labelTypeeMap) {
// 获取题号
AtomicReference<BigDecimal> 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<PageData> listPd = (List) ObjectExcelRead.readExcel(filePath, fileName, 1, 0, i);
if (listPd.size() > 0) {
ArrayList<String> sheet0 = new ArrayList<String>() {{
add("单选题目");
add("单选选项A");
add("单选选项B");
add("单选选项C");
add("单选选项D");
add("单选答案");
if (hasScore) {
add("分值");
}
add("答案解析");
add("标签类型");
add("关联课件名称");
}};
ArrayList<String> sheet1 = new ArrayList<String>() {{
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<Integer, String> CHOICE_COLUMN = new HashMap<Integer, String>();
HashMap<Integer, ArrayList<String>> hMap = new HashMap<>();
hMap.put(0, sheet0);
hMap.put(1, sheet1);
PageData data = listPd.get(0);
ArrayList<String> 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<PageData> preData, Map<String, String> labelTypeeMap) {
AtomicReference<BigDecimal> sum = new AtomicReference<>(new BigDecimal(0));
for (int i = 2; i < 3; i++) {
// 校验表头
List<PageData> 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<Integer, String> BLANKS_COLUMN = new HashMap<Integer, String>();
ArrayList<String> sheet2 = new ArrayList<String>() {{
add("判断题目");
add("判断答案");
if (hasScore) {
add("分值");
}
add("答案解析");
add("标签类型");
add("关联课件名称");
}};
HashMap<Integer, ArrayList<String>> hMap = new HashMap<>();
hMap.put(2, sheet2);
PageData data = listPd.get(0);
ArrayList<String> 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<PageData> preData) {
stageexampaperCacheMapper.saveTestPaper(preData);
}
}