|
楼主 |
发表于 2014-12-4 19:58:11
|
显示全部楼层
在后台使用java写随机生成考试题的action
public static Table queryExamList(){
//在题库中随机抽取30道公共判断题,10道公共单选题,10到公共多选题,20道区域判断题,10道区域单选题,10道区域单选题,10道定向题组成试卷(带题目序号)
//这条语句用于MYSQL
StringBuffer sbSql = new StringBuffer();
sbSql.append("SELECT @rownum:=@rownum+1 AS fRowNo, a.* from (");
sbSql.append("(SELECT * FROM MY_ExamBasic where fExamType='公共科目判断题' ORDER BY RAND() LIMIT 30) ");
sbSql.append("union (SELECT * FROM MY_ExamBasic where fExamType='公共科目单选题' ORDER BY RAND() LIMIT 10)");
sbSql.append("union (SELECT * FROM MY_ExamBasic where fExamType='公共科目多选题' ORDER BY RAND() LIMIT 10) ");
sbSql.append("union (SELECT * FROM MY_ExamBasic where fExamType='区域科目判断题' ORDER BY RAND() LIMIT 20) ");
sbSql.append("union (SELECT * FROM MY_ExamBasic where fExamType='区域科目单选题' ORDER BY RAND() LIMIT 10)");
sbSql.append("union (SELECT * FROM MY_ExamBasic where fExamType='区域科目多选题' ORDER BY RAND() LIMIT 10) ");
sbSql.append("union (SELECT * FROM MY_ExamBasic where fExamType='区域科目定向题' ORDER BY RAND() LIMIT 10) ");
sbSql.append(") a,(select @rownum :=0) b ");
//这条语句用于SQLSERVER
StringBuffer sbSql1 = new StringBuffer();
//sbSql1.append("SELECT fRowNo=row_number(), a.* from (");
sbSql1.append("select row_number() over (order by fExamType) as fRowNo ,* from (select top 30 * from MY_ExamBasic where fExamType='公共科目判断题' order by NewID()) a ");
sbSql1.append(" union all select row_number() over (order by fExamType) as fRowNo ,* from (select top 10 * from MY_ExamBasic where fExamType='公共科目单选题' order by NewID()) b ");
sbSql1.append("union all select row_number() over (order by fExamType) as fRowNo ,* from (select top 10 * from MY_ExamBasic where fExamType='公共科目多选题' order by NewID()) c ");
sbSql1.append("union all select row_number() over (order by fExamType) as fRowNo ,* from (select top 20 * from MY_ExamBasic where fExamType='区域科目判断题' order by NewID()) c ");
sbSql1.append("union all select row_number() over (order by fExamType) as fRowNo ,* from (select top 10 * from MY_ExamBasic where fExamType='区域科目单选题' order by NewID()) c ");
sbSql1.append("union all select row_number() over (order by fExamType) as fRowNo ,* from (select top 10 * from MY_ExamBasic where fExamType='区域科目多选题' order by NewID()) c ");
sbSql1.append("union all select row_number() over (order by fExamType) as fRowNo ,* from (select top 10 * from MY_ExamBasic where fExamType='区域科目定向题' order by NewID()) d ");
HashMap<String, String> sqlMap = new HashMap<String, String>();
sqlMap.put(SQL.DEFAULT_DB_NAME, sbSql1.toString());
sqlMap.put(DatabaseProduct.MSSQL.name(), sbSql1.toString());
sqlMap.put(DatabaseProduct.SYBASE.name(), sbSql1.toString());
Table table = SQL.select(sqlMap, null, "/MyProject/TaxiManage/data");
table.getProperties().put(Table.PROP_NAME_ROWID, "fID");
return table;
}
|
|