|
楼主 |
发表于 2016-11-12 09:43:32
|
显示全部楼层
在baas中随机抽取题库的试题函数如下:
- public static JSONObject creatTest(JSONObject params, ActionContext context) throws SQLException, NamingException{
- Table table = null;
- String querysql;
-
- String fJudgeNum = "50";
- String fSingleNum = "30";
- String fMultiNum = "20";
- Object columns = params.get("columns");
- Connection conn = context.getConnection("YGS");
- /*
- * List<Object> sqlParams = new ArrayList<Object>();
- * sqlParams.add(fExamBankID);
- */
- try {
-
- querysql = "(SELECT uuid() as fID,fIndex,fType,fQuestion,fQuestionPic,fCorrect,fPoints,fOptionA,fOptionB,fOptionC,fOptionD,0 as version FROM YG_examBank where fType='判断题' ORDER BY RAND() LIMIT " + fJudgeNum + ") ";
- querysql = querysql
- + "union (SELECT uuid() as fID,fIndex,fType,fQuestion,fQuestionPic,fCorrect,fPoints,fOptionA,fOptionB,fOptionC,fOptionD,0 as version FROM YG_examBank where fType='单选题' ORDER BY RAND() LIMIT " + fSingleNum + ") ";
- querysql = querysql
- + "union (SELECT uuid() as fID,fIndex,fType,fQuestion,fQuestionPic,fCorrect,fPoints,fOptionA,fOptionB,fOptionC,fOptionD,0 as version FROM YG_examBank where fType='多选题' ORDER BY RAND() LIMIT " + fMultiNum + ") ";
- table = DataUtils.queryData(conn, querysql, null, columns, null, null);
- return Transform.tableToJson(table);
- } finally {
- conn.close();
- }
- }
复制代码 |
|