491 lines
13 KiB
Plaintext
491 lines
13 KiB
Plaintext
package com.bonus.grade.service;
|
||
|
||
import com.bonus.core.DateTimeHelper;
|
||
import com.bonus.grade.beans.gradeBean;
|
||
import com.bonus.grade.dao.gradeDao;
|
||
import com.bonus.question.beans.QuestionBean;
|
||
import com.bonus.question.dao.QuestionDao;
|
||
import com.bonus.score.beans.ExamQuestionBean;
|
||
import com.bonus.score.beans.ScoreBean;
|
||
import com.bonus.score.dao.ScoreDao;
|
||
import com.bonus.sys.AjaxRes;
|
||
import com.bonus.sys.BaseServiceImp;
|
||
import com.bonus.sys.Page;
|
||
import com.bonus.sys.UserShiroHelper;
|
||
import com.bonus.sys.beans.UserBean;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Service;
|
||
|
||
import java.text.DateFormat;
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.*;
|
||
|
||
@Service("gradeService")
|
||
public class gradeServiceImp extends BaseServiceImp<gradeBean> implements gradeService {
|
||
|
||
@Autowired
|
||
private gradeDao dao;
|
||
|
||
@Autowired
|
||
private QuestionDao questionDao;
|
||
|
||
@Autowired
|
||
ScoreDao scoreDao;
|
||
|
||
@Override
|
||
public gradeBean findByExamId(gradeBean o) {
|
||
return dao.findByExamId(o);
|
||
}
|
||
|
||
@Override
|
||
public gradeBean findByExamIdPlus(gradeBean o) {
|
||
return dao.findByExamIdPlus(o);
|
||
}
|
||
|
||
@Override
|
||
public gradeBean findSelfByExamId(gradeBean o) {
|
||
return dao.findSelfByExamId(o);
|
||
}
|
||
|
||
@Override
|
||
public gradeBean getinfoByid(String id) {
|
||
// TODO Auto-generated method stub
|
||
return dao.getinfoByid(id);
|
||
}
|
||
|
||
@Override
|
||
public gradeBean findExamPage(gradeBean o) {
|
||
// TODO Auto-generated method stub
|
||
return dao.findExamPage(o);
|
||
}
|
||
|
||
@Override
|
||
public void professsave(String examPerfession, String difficultId, String examid) {
|
||
// TODO Auto-generated method stub
|
||
dao.professsave(examPerfession, difficultId, examid);
|
||
}
|
||
|
||
@Override
|
||
public void updateStatus(gradeBean o) {
|
||
// TODO Auto-generated method stub
|
||
dao.updateStatus(o);
|
||
}
|
||
|
||
@Override
|
||
public void deleteProfess(gradeBean o) {
|
||
dao.deleteProfess(o);
|
||
}
|
||
|
||
@Override
|
||
public void deleteRegistration(gradeBean o) {
|
||
dao.deleteRegistration(o);
|
||
}
|
||
|
||
@Override
|
||
public List<gradeBean> getProfessById(String id) {
|
||
return dao.getProfessById(id);
|
||
}
|
||
|
||
@Override
|
||
public Page<ScoreBean> findByPageTwo(ScoreBean o, Page<ScoreBean> page) {
|
||
page.setResults(dao.findByPageTwo(o, page));
|
||
return page;
|
||
}
|
||
|
||
@Override
|
||
public List<gradeBean> findExaming() {
|
||
|
||
return dao.findExaming();
|
||
}
|
||
|
||
@Override
|
||
public AjaxRes toStartStatus(ScoreBean o) {
|
||
AjaxRes ar = getAjaxRes();
|
||
Integer res = dao.toStartStatus(o);
|
||
if (res == 1) {
|
||
ar.setSucceedMsg("成功");
|
||
} else {
|
||
ar.setFailMsg("失败");
|
||
}
|
||
return ar;
|
||
}
|
||
|
||
@Override
|
||
public gradeBean findIsActice(String id) {
|
||
// TODO Auto-generated method stub
|
||
return dao.findIsActice(id);
|
||
}
|
||
|
||
@Override
|
||
public void saveQuestionContent(ScoreBean o) {
|
||
dao.saveQuestionContent(o);
|
||
}
|
||
|
||
@Override
|
||
public void saveExamInfo(QuestionBean unList) {
|
||
dao.saveExamInfo(unList);
|
||
}
|
||
@Override
|
||
public void saveExamInfo1(QuestionBean unList) {
|
||
dao.saveExamInfo1(unList);
|
||
}
|
||
|
||
@Override
|
||
public List<ExamQuestionBean> findExamContent(ExamQuestionBean o) {
|
||
return dao.findExamContent(o);
|
||
}
|
||
|
||
@Override
|
||
public Integer stopExam(gradeBean o) {
|
||
Integer res = 0;
|
||
res = dao.stopExam(o);
|
||
return res;
|
||
}
|
||
|
||
@Override
|
||
public gradeBean findExamPersonNum(gradeBean o) {
|
||
return dao.findExamPersonNum(o);
|
||
}
|
||
|
||
@Override
|
||
public String genSelfExam(gradeBean o) {
|
||
int res = 0;
|
||
String examId = null;
|
||
try {
|
||
UserBean user = UserShiroHelper.getCurrentUser();
|
||
// exam_paper_self 插入数据
|
||
res = insertSelfPaper(o, user);
|
||
examId = o.getExamId();
|
||
// exam_profess_self 插入数据
|
||
res = insertSelfProfess(o, examId);
|
||
// exam_question_self 插入数据
|
||
res = insertSelfQuestion(o, user, examId);
|
||
// exam_person_self_record 插入数据
|
||
res = insertSelfRecord(o, user, examId);
|
||
System.out.println("res:" + res);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
return examId;
|
||
}
|
||
|
||
private int insertSelfRecord(gradeBean o, UserBean user, String examId) {
|
||
int res = 0;
|
||
try {
|
||
int processTime = 60;
|
||
String nowTime = DateTimeHelper.getNowTime();
|
||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||
Date date = df.parse(nowTime);
|
||
Date date2 = new Date(date.getTime() + processTime * 60 * 1000);
|
||
String endTime = df.format(date2);
|
||
ScoreBean score = new ScoreBean();
|
||
score.setUser(user);
|
||
score.setProfessId(o.getExamPerfession());
|
||
score.setExamId(examId);
|
||
score.setEndTime(endTime);
|
||
res = scoreDao.insertSelfRecord(score);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
return res;
|
||
}
|
||
|
||
private int insertSelfQuestion(gradeBean o, UserBean user, String examId) {
|
||
int res = 0;
|
||
String typeId = o.getTypeId();
|
||
String idCard = user.getLoginName();
|
||
try {
|
||
// exam_question_self 插入数据
|
||
|
||
QuestionBean quest = new QuestionBean();
|
||
quest.setQuestionType(o.getExamPerfession());
|
||
quest.setDifficultId(o.getDifficultId());
|
||
quest.setExamId(examId);
|
||
quest.setUser(user);
|
||
|
||
Map<String, String> questionMap = new HashMap<String, String>();
|
||
if (quest.getDifficultId().equals("1")) {
|
||
// 1:单选2:多选3:判断4:填空5:简单6:案例分析
|
||
for (int i = 1; i <= 6; i++) {
|
||
// 设置试卷题型
|
||
quest.setClassification(String.valueOf(i));
|
||
if (i == 1) {
|
||
// 1.简单;2.一般;3.困难;
|
||
for (int j = 1; j <= 1; j++) {
|
||
// 设置题目难度
|
||
quest.setQuestionLevel(String.valueOf(j));
|
||
if (j == 1) {
|
||
String questionType = quest.getQuestionType();
|
||
int limit = commongetlimit(i, questionType, typeId, idCard);
|
||
quest.setTeamzy(limit);
|
||
List<QuestionBean> question1 = questionDao.getRandomSelfQuestion(quest);
|
||
for (int k = 0; k < question1.size(); k++) {
|
||
questionMap.put(question1.get(k).getQuestionId(), question1.get(k).getOperation());
|
||
}
|
||
}
|
||
}
|
||
} else if (i == 2) {
|
||
// 1.简单;2.一般;3.困难;
|
||
for (int j = 1; j <= 1; j++) {
|
||
// 设置题目难度
|
||
quest.setQuestionLevel(String.valueOf(j));
|
||
if (j == 1) {
|
||
|
||
String questionType = quest.getQuestionType();
|
||
int limit = commongetlimit(i, questionType, typeId, idCard);
|
||
quest.setTeamzy(limit);
|
||
|
||
List<QuestionBean> question1 = questionDao.getRandomSelfQuestion(quest);
|
||
for (int k = 0; k < question1.size(); k++) {
|
||
questionMap.put(question1.get(k).getQuestionId(), question1.get(k).getOperation());
|
||
}
|
||
}
|
||
}
|
||
} else if (i == 3) {
|
||
// 1.简单;2.一般;3.困难;
|
||
for (int j = 1; j <= 1; j++) {
|
||
// 设置题目难度
|
||
quest.setQuestionLevel(String.valueOf(j));
|
||
if (j == 1) {
|
||
String questionType = quest.getQuestionType();
|
||
int limit = commongetlimit(i, questionType, typeId, idCard);
|
||
quest.setTeamzy(limit);
|
||
List<QuestionBean> question1 = questionDao.getRandomSelfQuestion(quest);
|
||
for (int k = 0; k < question1.size(); k++) {
|
||
questionMap.put(question1.get(k).getQuestionId(), question1.get(k).getOperation());
|
||
}
|
||
}
|
||
}
|
||
} else if (i == 4) {
|
||
// 1.简单;2.一般;3.困难;
|
||
for (int j = 1; j <= 1; j++) {
|
||
// 设置题目难度
|
||
quest.setQuestionLevel(String.valueOf(j));
|
||
if (j == 1) {
|
||
String questionType = quest.getQuestionType();
|
||
int limit = commongetlimit(i, questionType, typeId, idCard);
|
||
quest.setTeamzy(limit);
|
||
List<QuestionBean> question1 = questionDao.getRandomSelfQuestion(quest);
|
||
for (int k = 0; k < question1.size(); k++) {
|
||
questionMap.put(question1.get(k).getQuestionId(), question1.get(k).getOperation());
|
||
}
|
||
}
|
||
}
|
||
} else if (i == 5) {
|
||
// 1.简单;2.一般;3.困难;
|
||
for (int j = 1; j <= 1; j++) {
|
||
// 设置题目难度
|
||
quest.setQuestionLevel(String.valueOf(j));
|
||
if (j == 1) {
|
||
String questionType = quest.getQuestionType();
|
||
int limit = commongetlimit(i, questionType, typeId, idCard);
|
||
quest.setTeamzy(limit);
|
||
List<QuestionBean> question1 = questionDao.getRandomSelfQuestion(quest);
|
||
for (int k = 0; k < question1.size(); k++) {
|
||
questionMap.put(question1.get(k).getQuestionId(), question1.get(k).getOperation());
|
||
}
|
||
}
|
||
}
|
||
} else {
|
||
// 设置题目难度
|
||
|
||
quest.setTeamzy(1);
|
||
quest.setQuestionLevel(String.valueOf(1));
|
||
List<QuestionBean> question1 = questionDao.getRandomSelfQuestion(quest);
|
||
for (int k = 0; k < question1.size(); k++) {
|
||
questionMap.put(question1.get(k).getQuestionId(), question1.get(k).getOperation());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
System.out.println("questionMap:" + questionMap);
|
||
|
||
for (Map.Entry<String, String> entry : questionMap.entrySet()) {
|
||
QuestionBean makeExam = new QuestionBean();
|
||
makeExam.setExamId(quest.getExamId());
|
||
makeExam.setUser(quest.getUser());
|
||
makeExam.setQuestionId(entry.getKey());
|
||
String oper = entry.getValue();
|
||
List<String> list = new ArrayList<String>();
|
||
String[] arr = oper.split(";");
|
||
for (String str : arr) {
|
||
list.add(str.trim());
|
||
}
|
||
Collections.shuffle(list);
|
||
String newOperation = "";
|
||
for (String strr : list) {
|
||
newOperation += strr + ";";
|
||
}
|
||
makeExam.setOperation(newOperation);
|
||
QuestionBean qubean = new QuestionBean();
|
||
qubean = questionDao.findStandAnswer(makeExam);
|
||
if (qubean != null) {
|
||
makeExam.setStandAnswer(qubean.getStandAnswer());
|
||
}
|
||
res = questionDao.insertSelfQuestion(makeExam);
|
||
}
|
||
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
return res;
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取各题型数量
|
||
*
|
||
* @param i
|
||
* @param questionType
|
||
* @param typeId
|
||
* @param idCard
|
||
* @return
|
||
*/
|
||
private int commongetlimit(int i, String questionType, String typeId, String idCard) {
|
||
int num = 0;
|
||
|
||
// 查找题型配置 org_subject_type_score 如果为空则走下面的判断
|
||
QuestionBean bean = questionDao.getSetInfoById(questionType, i);
|
||
if (bean != null) {
|
||
num = bean.getTeamzy();
|
||
} else {
|
||
|
||
if ("2".equals(typeId)) {
|
||
int age = DateTimeHelper.getAgeByIDNumber(idCard);
|
||
if (age < 40) {
|
||
if (i == 1) {// 单选20
|
||
num = 20;
|
||
}
|
||
if (i == 2) {// 多选5
|
||
num = 5;
|
||
}
|
||
if (i == 3) {// 判断25
|
||
num = 25;
|
||
}
|
||
if (i == 4) {// 填空
|
||
num = 0;
|
||
}
|
||
if (i == 5) {// 简答
|
||
num = 0;
|
||
}
|
||
if (i == 6) {// 案例
|
||
num = 0;
|
||
}
|
||
} else {
|
||
if (i == 1) {// 单选25
|
||
num = 25;
|
||
}
|
||
if (i == 2) {// 多选0
|
||
num = 0;
|
||
}
|
||
if (i == 3) {// 判断25
|
||
num = 25;
|
||
}
|
||
if (i == 4) {// 填空
|
||
num = 0;
|
||
}
|
||
if (i == 5) {// 简答
|
||
num = 0;
|
||
}
|
||
if (i == 6) {// 案例
|
||
num = 0;
|
||
}
|
||
}
|
||
|
||
} else {
|
||
|
||
if (i == 1) {// 单选30
|
||
num = 30;
|
||
Map<String, Integer> getlimitInfo = getlimitInfo();
|
||
Integer integer = getlimitInfo.get(questionType);
|
||
if (integer == null) {
|
||
num = 30;
|
||
} else {
|
||
num = integer;
|
||
}
|
||
}
|
||
if (i == 2) {// 多选10
|
||
num = 10;
|
||
}
|
||
if (i == 3) {// 判断20
|
||
num = 20;
|
||
}
|
||
if (i == 4) {// 填空20
|
||
num = 5;
|
||
}
|
||
if (i == 5) {// 简单20
|
||
num = 2;
|
||
}
|
||
if (i == 6) {// 案例20
|
||
num = 1;
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
return num;
|
||
|
||
}
|
||
|
||
public static Map<String, Integer> getlimitInfo() {
|
||
Map<String, Integer> map = new HashMap<>();
|
||
map.put("218", 40);
|
||
map.put("67", 40);
|
||
map.put("69", 50);
|
||
map.put("152", 40);
|
||
return map;
|
||
}
|
||
|
||
private int insertSelfProfess(gradeBean o, String examId) {
|
||
int res = 0;
|
||
try {
|
||
// exam_profess_self 插入数据
|
||
|
||
res = dao.insertSelfProfess(o);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
return res;
|
||
}
|
||
|
||
private int insertSelfPaper(gradeBean o, UserBean user) {
|
||
int res = 0;
|
||
try {
|
||
// exam_paper_self 插入数据
|
||
int processTime = 60;
|
||
String nowTime = DateTimeHelper.getNowTime();
|
||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||
Date date = df.parse(nowTime);
|
||
Date date2 = new Date(date.getTime() + processTime * 60 * 1000);
|
||
String endTime = df.format(date2);
|
||
o.setReleaseTime(nowTime);
|
||
o.setEndTime(endTime);
|
||
o.setStartTime(nowTime);
|
||
o.setExamTime("60");
|
||
o.setExamName("自测练习");
|
||
o.setIsActive("1");
|
||
o.setViewGrade("1");
|
||
o.setFabuUserid(user.getId() + "");
|
||
res = dao.insertSelfPaper(o);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
return res;
|
||
}
|
||
|
||
@Override
|
||
public gradeBean getSelfInfoBy(String examId) {
|
||
return dao.getSelfInfoBy(examId);
|
||
}
|
||
|
||
@Override
|
||
public void saveQuestionSelfContent(ScoreBean o) {
|
||
dao.saveQuestionSelfContent(o);
|
||
}
|
||
|
||
@Override
|
||
public List<gradeBean> selectExamCount() {
|
||
return dao.selectExamCount();
|
||
}
|
||
}
|