public Page doSave(WebForm form, Module module) {
Integer fillBox_num = Integer
.parseInt((String) form.get("FillBox_num"));
Integer singleChoice_num = Integer.parseInt((String) form
.get("SingleChoice_num"));
Integer mulitiChoice_num = Integer.parseInt((String) form
.get("MulitiChoice_num"));
Integer estimate_num = Integer.parseInt((String) form
.get("Estimate_num"));
Integer other_num = Integer.parseInt((String) form.get("Other_num"));
int fillBox_totalNum = 0;
int singleChoice_totalNum = 0;
int mulitiChoice_totalNum = 0;
int estimate_totalNum = 0;
int other_totalNum = 0;
List<Question> fillBox_totalList = new java.util.ArrayList<Question>();
List<Question> singleChoice_totalList = new java.util.ArrayList<Question>();
List<Question> mulitiChoice_totalList = new java.util.ArrayList<Question>();
List<Question> estimate_totalList = new java.util.ArrayList<Question>();
List<Question> other_totalList = new java.util.ArrayList<Question>();
Random random = new Random();
TestPaperCommand cmd = new TestPaperCommand();
TestPaper testPaper = new TestPaper();
List<TestPaperItem> items = new java.util.ArrayList<TestPaperItem>();
form.toPo(cmd);
errors = cmd.vaild();
if (errors != null && errors.size() > 0) {
form.addResult("errors", errors);
return module.findPage("edit");
}
java.util.Iterator it = form.getTextElement().keySet().iterator();
List<String> typeList = new ArrayList<String>();
List<String> scoreList = new ArrayList<String>();
int inputTotalScore = CommUtil.null2Int(form.get("totalScore"));
int singleScore = 0;
int totalScore = 0;
while (it.hasNext()) {
String name = (String) it.next();
System.out.println(name);
if (name.indexOf("_num") > 0) {
typeList.add(name.substring(0, name.length() - 4));
}
if (name.indexOf("_score") > 0) {
scoreList.add(name);
}
}
for (String s : typeList) {
int score = 0;
int num = 0;
score = CommUtil.null2Int(form.get(s + "_score"));
num = CommUtil.null2Int(form.get(s + "_num"));
singleScore = score * num;
System.out.println(s + "类型的分数是" + singleScore);
totalScore = totalScore + singleScore;
}
if (totalScore != inputTotalScore) {
form.addResult("msg", "请检查总分和题型分数累加是否相等!");
return this.doAdd(form, module);
}
CourseInfo courseInfo = new CourseInfo();
courseInfo.setCourse(cmd.getCourse());
courseInfo.setChapter(cmd.getCourseChapter());
courseInfo.setWare(cmd.getCourseWare());
testPaper.setCourseInfo(courseInfo);
// 自动生成填空题
QuestionQueryObject fqqo = new QuestionQueryObject();
fqqo.addQuery("obj.ttype", QuestionType.FillBox, "=");
fqqo.addQuery("obj.courseInfo.course", courseInfo.getCourse(), "=");
fqqo.addQuery("obj.courseInfo.chapter", courseInfo.getChapter(), "=");
fqqo.addQuery("obj.courseInfo.ware", courseInfo.getWare(), "=");
if (fillBox_num != 0) {
if (this.questionService.getQuestionBy(fqqo).getResult() != null) {
System.out.println("开始生成填空题...");
fillBox_totalList = this.questionService.getQuestionBy(fqqo)
.getResult();
fillBox_totalNum = fillBox_totalList.size();
if (fillBox_num > fillBox_totalNum) {
form.addResult("msg", "对不起,您选择的课程中没有足够的填空题!");
return this.doAdd(form, module);
} else {
int f = 0;
while (f < fillBox_num) {
TestPaperItem item = new TestPaperItem();
int count = random.nextInt(fillBox_totalList.size());
item.setQuestion(fillBox_totalList.get(count));
int fill_score = CommUtil.null2Int(form
.get("FillBox_score"));
item.setScore(fill_score);
item.setPaper(testPaper);
items.add(item);
System.out.println(items.size());
fillBox_totalList.remove(count);
f++;
}
}
} else {
form.addResult("msg", "对不起,您选择的课程中没有填空题!");
return this.doAdd(form, module);
}
}
// 自动生成判断题
QuestionQueryObject eqqo = new QuestionQueryObject();
eqqo.addQuery("obj.ttype", QuestionType.Estimate, "=");
eqqo.addQuery("obj.courseInfo.course", courseInfo.getCourse(), "=");
eqqo.addQuery("obj.courseInfo.chapter", courseInfo.getChapter(), "=");
eqqo.addQuery("obj.courseInfo.ware", courseInfo.getWare(), "=");
if (estimate_num != 0) {
if (this.questionService.getQuestionBy(eqqo).getResult() != null) {
estimate_totalList = this.questionService.getQuestionBy(eqqo)
.getResult();
estimate_totalNum = estimate_totalList.size();
if (estimate_num > estimate_totalNum) {
form.addResult("msg", "对不起,您选择的课程中没有足够的判断题!");
return this.doAdd(form, module);
} else {
int e = 0;
while (e < estimate_num) {
TestPaperItem item = new TestPaperItem();
int count = random.nextInt(estimate_totalList.size());
item.setQuestion(estimate_totalList.get(count));
int estimate_score = CommUtil.null2Int(form
.get("Estimate_score"));
item.setScore(estimate_score);
items.add(item);
estimate_totalList.remove(count);
e++;
}
}
} else {
form.addResult("msg", "对不起,您选择的课程中没有判断题!");
return this.doAdd(form, module);
}
}
// 自动生成单选题
QuestionQueryObject sqqo = new QuestionQueryObject();
sqqo.addQuery("obj.ttype", QuestionType.SingleChoice, "=");
sqqo.addQuery("obj.courseInfo.course", courseInfo.getCourse(), "=");
sqqo.addQuery("obj.courseInfo.chapter", courseInfo.getChapter(), "=");
sqqo.addQuery("obj.courseInfo.ware", courseInfo.getWare(), "=");
if (singleChoice_num != 0) {
if (this.questionService.getQuestionBy(sqqo).getResult() != null) {
singleChoice_totalList = this.questionService.getQuestionBy(
sqqo).getResult();
singleChoice_totalNum = singleChoice_totalList.size();
if (singleChoice_num > singleChoice_totalNum) {
form.addResult("msg", "对不起,您选择的课程中没有足够的单选题!");
return this.doAdd(form, module);
} else {
int s = 0;
while (s < singleChoice_num) {
TestPaperItem item = new TestPaperItem();
int count = random.nextInt(singleChoice_totalList
.size());
item.setQuestion(singleChoice_totalList.get(count));
int singleChoice_score = CommUtil
.null2Int("SingleChoice_score");
item.setScore(singleChoice_score);
items.add(item);
singleChoice_totalList.remove(count);
s++;
}
}
} else {
form.addResult("msg", "对不起,您选择的课程中没有单选题!");
return this.doAdd(form, module);
}
}
// 自动生成多选题
QuestionQueryObject mqqo = new QuestionQueryObject();
mqqo.addQuery("obj.ttype", QuestionType.MulitiChoice, "=");
mqqo.addQuery("obj.courseInfo.course", courseInfo.getCourse(), "=");
mqqo.addQuery("obj.courseInfo.chapter", courseInfo.getChapter(), "=");
mqqo.addQuery("obj.courseInfo.ware", courseInfo.getWare(), "=");
if (mulitiChoice_num != 0) {
if (this.questionService.getQuestionBy(mqqo).getResult() != null) {
mulitiChoice_totalList = this.questionService.getQuestionBy(
mqqo).getResult();
mulitiChoice_totalNum = mulitiChoice_totalList.size();
if (mulitiChoice_num > mulitiChoice_totalNum) {
form.addResult("msg", "对不起,您选择的课程中没有足够的多选题!");
return this.doAdd(form, module);
} else {
int m = 0;
while (m < mulitiChoice_num) {
TestPaperItem item = new TestPaperItem();
int count = random.nextInt(mulitiChoice_totalList
.size());
item.setQuestion(mulitiChoice_totalList.get(count));
int mulitiChoice_score = CommUtil.null2Int(form
.get("MulitiChoice_score"));
item.setScore(mulitiChoice_score);
items.add(item);
mulitiChoice_totalList.remove(count);
m++;
}
}
} else {
form.addResult("msg", "对不起,您选择的课程中没有多选题!");
return this.doAdd(form, module);
}
}
// 自动生成其他题
QuestionQueryObject oqqo = new QuestionQueryObject();
oqqo.addQuery("obj.ttype", QuestionType.Other, "=");
oqqo.addQuery("obj.courseInfo.course", courseInfo.getCourse(), "=");
oqqo.addQuery("obj.courseInfo.chapter", courseInfo.getChapter(), "=");
oqqo.addQuery("obj.courseInfo.ware", courseInfo.getWare(), "=");
if (other_num != 0) {
if (this.questionService.getQuestionBy(oqqo).getResult() != null) {
other_totalList = this.questionService.getQuestionBy(oqqo)
.getResult();
other_totalNum = other_totalList.size();
if (other_num > other_totalNum) {
form.addResult("msg", "对不起,您选择的课程中没有足够的其他题!");
return this.doAdd(form, module);
} else {
int m = 0;
while (m < mulitiChoice_num) {
TestPaperItem item = new TestPaperItem();
int count = random.nextInt(other_totalList.size());
item.setQuestion(other_totalList.get(count));
int other_score = CommUtil.null2Int(form
.get("Other_score"));
item.setScore(other_score);
items.add(item);
other_totalList.remove(count);
m++;
}
}
} else {
form.addResult("msg", "对不起,您选择的课程中没有其他题!");
return this.doAdd(form, module);
}
}
com.easyjf.beans.BeanUtils.copyProperties(cmd, testPaper);
for (TestPaperItem testItem : items) {
System.out.println(testItem.getQuestion().getTtype()
+ testItem.getQuestion().getContent());
testPaper.addTestPaperItem(testItem);
}
Long ret = this.service.addTestPaper(testPaper);
return this.doList(form, module);
}
相关推荐
- **定义与特点**:EasyJWeb是一个让开发者能够高效且轻松地创建Java Web应用程序的框架。它采用请求转发模型的MVC(Model-View-Controller)架构,这有助于清晰地区分业务逻辑、数据管理和用户界面展示,从而提高...
EasyJWeb 2.0 是一个专门针对企业级Java Web应用设计的快速开发框架,由国内知名的开源团队EasyJF开发并维护。这个框架的独特之处在于它完全由中国开源爱好者创建,其文档和注释均采用中文,为中文开发者提供了极大...
作为一个旨在让基于Java的Web应用程序开发变得直接、快速、简易的框架,EasyJWeb提供了一个IoC容器,并对企业级应用中的一些通用业务逻辑(如分页、查询、DAO等)进行了抽象及封装,提供了一套可以直接操作、应用企业...
EasyJWeb是一个轻量级的Java Web开发框架,它的设计目标是简化Web应用程序的开发过程,提高开发效率。本教程将带你一步步了解如何创建并运行你的第一个EasyJWeb项目。 首先,我们需要理解EasyJWeb的基本概念。...
Easyjweb 1.2.2 是一个专为提高开发效率而设计的Java Web开发框架,与Struts类似,但其宣称的开发速度是Struts的多倍。这个框架在2010年1月15日发布了最新的1.2.2版本,旨在为开发者提供更为高效和便捷的开发体验。...
在IT行业中,EasyJWeb是一个轻量级的Java Web应用框架,主要用来简化Web应用程序的开发。本示例将引导我们逐步了解如何使用EasyJWeb创建一个简单的"Say Hello"应用,这通常是我们初次接触任何Web框架时都会做的经典...
EasyJWeb是一个在Java EE开发领域备受关注的轻量级框架,它的核心目标是简化企业级应用的构建过程,提高开发效率。这个框架以其小巧、灵活、易用的特点,为开发者提供了高效的工作流和强大的功能支持。 一、框架...
在Eclipse中,通过导入已有的文件和项目,选择EasyJWeb的根目录,将所有项目导入并创建一个名为EasyJWeb的Working Set。如果Eclipse显示缺失JAR包,需要在Eclipse的Java构建路径中设置`M2_REPO`变量,指向`%user_...
easyjweb-2.0 java 快速开发 easyjweb-2.0 java 快速开发 easyjweb-2.0 java 快速开发
EasyJWeb框架0.7.0是一个专为Java开发者设计的轻量级Web应用框架,旨在简化开发过程,提高开发效率。这个版本的框架在早期的版本基础上进行了优化和改进,提供了一系列的功能来支持Web应用程序的快速开发。 首先,`...
**EasyJWeb**则是一个轻量级的Java Web开发框架,它的设计目标是简化Java Web应用的开发过程,提高开发效率。EasyJWeb通过提供简单的API和约定优于配置的方式,让开发者可以快速构建Web服务。它特别适合于小型到中型...
【Easyjweb项目实例】是针对Java Web开发框架Easyjweb的一个实践教程,它提供了丰富的学习资源和源代码,帮助开发者深入理解并掌握Easyjweb的使用。Easyjweb是一款基于Java的轻量级Web应用框架,设计目标是简化开发...
EasyJWeb是一个基于Java技术的MVC框架,专为快速构建企业级Web应用程序而设计。它的设计理念源于国内项目实践经验,并吸收了Rails、Struts、JSF、Tapestry等流行开源框架的优点。作为一款由中国开源爱好者开发的框架...
EasyJWeb支持多角色分配给一个用户,用户通过角色获取相应的权限。在系统初始化或者用户注册时,会将角色与用户进行关联,从而确定用户的权限范围。 五、权限检查机制 当用户尝试访问某一资源时,EasyJWeb会进行...
配置easyjweb项目 ,要用到的细节,免于发生不必要的错误
- **设计理念**:EasyJWeb的设计理念汲取了Rails、Struts、JSF、Tapestry等流行框架的优点,并结合了中国开发者的需求和习惯,致力于打造一个易于使用、高效且灵活的Java Web开发框架。 - **目标用户**:面向具有...