304 lines
8.6 KiB
Plaintext
304 lines
8.6 KiB
Plaintext
package com.bonus.question.service;
|
||
|
||
import com.bonus.question.beans.QuestionBean;
|
||
import com.bonus.question.dao.QuestionDao;
|
||
import com.bonus.sys.AjaxRes;
|
||
import com.bonus.sys.BaseServiceImp;
|
||
import com.bonus.sys.Page;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Service;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
|
||
import java.util.*;
|
||
|
||
@Service("QuestionService")
|
||
public class QuestionServiceImp extends BaseServiceImp<QuestionBean> implements QuestionService {
|
||
@Autowired
|
||
QuestionDao dao;
|
||
|
||
@Override
|
||
public Page<QuestionBean> findByPage(QuestionBean o, Page<QuestionBean> page){
|
||
page.setResults(dao.findByPage(o,page));
|
||
return page;
|
||
}
|
||
|
||
@Override
|
||
public List<QuestionBean> findExamPage(QuestionBean quest) {
|
||
// TODO Auto-generated method stub
|
||
return dao.findExamPage(quest);
|
||
}
|
||
|
||
@Override
|
||
@Transactional
|
||
public AjaxRes addQuestion(QuestionBean o) {
|
||
AjaxRes ar = getAjaxRes();
|
||
try {
|
||
int count = dao.insert(o);
|
||
if(count == 1) {
|
||
ar.setSucceedMsg("新增成功");
|
||
|
||
} else {
|
||
ar.setFailMsg("新增失败!");
|
||
}
|
||
} catch(Exception e) {
|
||
e.printStackTrace();
|
||
ar.setFailMsg("新增失败");
|
||
}
|
||
return ar;
|
||
}
|
||
|
||
@Override
|
||
public String addCaseQuestion(QuestionBean o) {
|
||
String caseId = "";
|
||
try {
|
||
dao.addCaseQuestion(o);
|
||
caseId = o.getCaseId();
|
||
} catch(Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
return caseId;
|
||
}
|
||
|
||
@Override
|
||
public AjaxRes updateQuestion(QuestionBean o) {
|
||
AjaxRes ar = getAjaxRes();
|
||
try {
|
||
int count = dao.update(o);
|
||
if(count == 1) {
|
||
ar.setSucceedMsg("修改成功");
|
||
} else {
|
||
ar.setFailMsg("修改失败!");
|
||
}
|
||
} catch(Exception e) {
|
||
e.printStackTrace();
|
||
ar.setFailMsg("修改失败");
|
||
}
|
||
return ar;
|
||
}
|
||
|
||
@Override
|
||
public AjaxRes deleteApply(QuestionBean o) {
|
||
AjaxRes ar = getAjaxRes();
|
||
Integer res = 0;
|
||
String ids = o.getIds();
|
||
List<Integer> idss = getIntList(ids);
|
||
res = dao.deleteApply(idss);
|
||
if(res == 0) {
|
||
ar.setFailMsg("删除失败!");
|
||
}else {
|
||
ar.setSucceedMsg("删除成功!");
|
||
}
|
||
return ar;
|
||
}
|
||
|
||
@Override
|
||
public QuestionBean findById(QuestionBean o) {
|
||
return dao.findById(o);
|
||
}
|
||
|
||
@Override
|
||
public Integer makeExamPage(QuestionBean quest) {
|
||
Map<String,String> questionMap = new HashMap<String,String>();
|
||
QuestionBean casequest = new QuestionBean();
|
||
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(questionType);
|
||
quest.setTeamzy(limit);
|
||
List<QuestionBean> question1 = dao.getRandomQuestion(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= dxcommongetlimit(questionType);
|
||
quest.setTeamzy(limit);
|
||
List<QuestionBean> question1 = dao.getRandomQuestion(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= pdcommongetlimit(questionType);
|
||
quest.setTeamzy(limit);
|
||
List<QuestionBean> question1 = dao.getRandomQuestion(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) {
|
||
List<QuestionBean> question1 = dao.getRandomQuestion(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) {
|
||
List<QuestionBean> question1 = dao.getRandomQuestion(quest);
|
||
for(int k = 0; k < question1.size(); k++) {
|
||
questionMap.put(question1.get(k).getQuestionId(), question1.get(k).getOperation());
|
||
}
|
||
}
|
||
}
|
||
}else {
|
||
//设置题目难度
|
||
quest.setQuestionLevel(String.valueOf(1));
|
||
List<QuestionBean> question1 = dao.getRandomQuestion(quest);
|
||
for(int k = 0; k < question1.size(); k++) {
|
||
questionMap.put(question1.get(k).getQuestionId(), question1.get(k).getOperation());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
System.out.println("questionMap:"+questionMap);
|
||
QuestionBean makeExam = new QuestionBean();
|
||
Integer res = 0;
|
||
makeExam.setExamId(quest.getExamId());
|
||
makeExam.setUser(quest.getUser());
|
||
for(Map.Entry<String, String> entry : questionMap.entrySet()) {
|
||
makeExam.setQuestionId(entry.getKey());
|
||
String oper = entry.getValue();
|
||
List<String> list = new ArrayList<String>();
|
||
String[] arr = oper.split(";");
|
||
if(arr.length == 2){
|
||
makeExam.setOperation(oper);
|
||
}else{
|
||
for(String str: arr) {
|
||
list.add(str.trim());
|
||
}
|
||
Collections.shuffle(list);
|
||
String newOperation ="";
|
||
for(String strr: list) {
|
||
newOperation += strr+";";
|
||
}
|
||
makeExam.setOperation(newOperation);
|
||
}
|
||
res = dao.inputExamPageRecord(makeExam);
|
||
}
|
||
return res;
|
||
}
|
||
|
||
private int commongetlimit(String questionType) {
|
||
Map<String, Integer> getlimitInfo = getlimitInfo();
|
||
Integer integer = getlimitInfo.get(questionType);
|
||
if(integer == null) {
|
||
integer=30;
|
||
}
|
||
return integer;
|
||
|
||
}
|
||
private int dxcommongetlimit(String questionType) {
|
||
Map<String, Integer> getlimitInfo = getdxlimitInfo();
|
||
Integer integer = getlimitInfo.get(questionType);
|
||
if(integer == null) {
|
||
integer=5;
|
||
}
|
||
return integer;
|
||
|
||
}
|
||
public static Map<String, Integer> getdxlimitInfo() {
|
||
Map<String, Integer> map = new HashMap<>();
|
||
map.put("69", 10);
|
||
return map;
|
||
}
|
||
private int pdcommongetlimit(String questionType) {
|
||
Map<String, Integer> getlimitInfo = getpdlimitInfo();
|
||
Integer integer = getlimitInfo.get(questionType);
|
||
if(integer == null) {
|
||
integer=30;
|
||
}
|
||
return integer;
|
||
|
||
}
|
||
public static Map<String, Integer> getpdlimitInfo() {
|
||
Map<String, Integer> map = new HashMap<>();
|
||
map.put("69", 25);
|
||
return map;
|
||
}
|
||
|
||
public static Map<String, Integer> getlimitInfo() {
|
||
Map<String, Integer> map = new HashMap<>();
|
||
map.put("218", 40);
|
||
map.put("67", 40);
|
||
map.put("69", 45);
|
||
map.put("152", 40);
|
||
|
||
return map;
|
||
}
|
||
|
||
@Override
|
||
public List<QuestionBean> findUserExamPage(QuestionBean quest) {
|
||
// TODO Auto-generated method stub
|
||
return dao.findUserExamPage(quest);
|
||
}
|
||
|
||
@Override
|
||
public List<QuestionBean> findCaseId(QuestionBean quest) {
|
||
// TODO Auto-generated method stub
|
||
return dao.findCaseId(quest);
|
||
}
|
||
|
||
@Override
|
||
public List<QuestionBean> findCaseQuest(QuestionBean quest) {
|
||
// TODO Auto-generated method stub
|
||
return dao.findCaseQuest(quest);
|
||
}
|
||
|
||
@Override
|
||
public List<QuestionBean> findSelfExamPage(QuestionBean quest) {
|
||
// TODO Auto-generated method stub
|
||
return dao.findSelfExamPage(quest);
|
||
}
|
||
|
||
@Override
|
||
public int findIdbyequ(QuestionBean unList) {
|
||
// TODO Auto-generated method stub
|
||
return dao.findIdbyequ(unList);
|
||
}
|
||
@Override
|
||
public int findIdbyequ1(QuestionBean unList) {
|
||
// TODO Auto-generated method stub
|
||
return dao.findIdbyequ1(unList);
|
||
}
|
||
|
||
@Override
|
||
public String findtitleby(QuestionBean questionBean) {
|
||
// TODO Auto-generated method stub
|
||
return dao.findtitleby(questionBean);
|
||
}
|
||
}
|