Browse Source

考试管理

eganwu 1 year ago
parent
commit
a06c7d6996

+ 9 - 0
src/custom/restcontroller/R.java

@@ -5770,6 +5770,15 @@ public class R {
         }
     }
 
+    public static class ID20240323141602 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID20240323155602 {
+        public static class v1 {
+        }
+    }
 
 }
 

+ 54 - 0
src/custom/restcontroller/webmanage/saletool/courseware/CoursewareHelper.java

@@ -1,10 +1,13 @@
 package restcontroller.webmanage.saletool.courseware;
 
 import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import common.BaseClass;
 import common.Controller;
 import common.YosException;
 import common.data.QuerySQL;
+import common.data.Row;
+import common.data.Rows;
 import common.data.SQLFactory;
 
 import java.util.ArrayList;
@@ -43,4 +46,55 @@ public class CoursewareHelper extends BaseClass {
         ArrayList<String> classnames = classQuery.query().toArrayList("classnames");
         return String.join(";", classnames);
     }
+
+
+    public static JSONArray getRemoveArray(JSONArray testquestions, JSONArray sat_courseware_testlibraryids) {
+
+        JSONArray removeArray = new JSONArray();
+        for (Object object : testquestions) {
+            JSONObject jsonObject = (JSONObject) object;
+            Long sat_courseware_testlibraryid = jsonObject.getLongValue("sat_courseware_testlibraryid");
+            for (Object object2 : sat_courseware_testlibraryids) {
+                if (Long.parseLong(object2.toString()) == sat_courseware_testlibraryid) {
+                    removeArray.add(object);
+                }
+            }
+        }
+        return removeArray;
+    }
+
+    //获取查询的考试题目
+    public static JSONArray getTestlibraryRows(Controller controller, JSONArray sat_courseware_testlibraryids) throws YosException {
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(controller, "sat_courseware_testlibrary").setTableAlias("t1");
+        querySQL.setWhere("sat_courseware_testlibraryid", sat_courseware_testlibraryids.toArray());
+        querySQL.setSiteid(controller.siteid);
+        Rows testlibraryRows = querySQL.query();
+        for (Row testlibraryRow : testlibraryRows) {
+            JSONArray jsonArray = testlibraryRow.getJSONArray("options");
+            testlibraryRow.put("options", jsonArray);
+        }
+        return testlibraryRows.toJsonArray();
+    }
+
+    //计算分数
+    public static JSONArray setTestquestionsScore(JSONArray testquestions) throws YosException {
+
+        int num = testquestions.size();
+
+        int count = 0;
+        for (Object object : testquestions) {
+            JSONObject jsonObject = (JSONObject) object;
+            if (count == testquestions.size() - 1) {
+                jsonObject.put("score", 100 / num + 100 % num);
+            } else {
+                jsonObject.put("score", 100 / num);
+            }
+            count++;
+        }
+
+        return testquestions;
+    }
+
+
 }

+ 3 - 1
src/custom/restcontroller/webmanage/saletool/courseware/coursewareclass.java

@@ -64,7 +64,9 @@ public class coursewareclass extends Controller {
 
 
         dbConnect.runSqlUpdate(sqlFactory);
-        return getSucReturnObject().toString();
+
+
+        return getSucReturnObject().setData(sat_courseware_classid).toString();
     }
 
 

+ 119 - 4
src/custom/restcontroller/webmanage/saletool/courseware/coursewaretesthead.java

@@ -8,7 +8,9 @@ import common.annotation.API;
 import common.data.*;
 import restcontroller.R;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.Collections;
 
 /**
  * 考试表头
@@ -25,12 +27,44 @@ public class coursewaretesthead extends Controller {
     public String insertOrUpdate() throws YosException {
 
         Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
-
+        int testaddmode = content.getIntValue("testaddmode", 1);
+        int num = content.getIntValue("num", 0);
         JSONArray sat_courseware_classids = new JSONArray();
         if (content.containsKey("sat_courseware_classids")) {
             sat_courseware_classids = content.getJSONArray("sat_courseware_classids");
         }
 
+        ArrayList<Long> sat_courseware_testlibraryids = new ArrayList<>();
+
+        if (testaddmode == 1) {
+            if (num <= 0) {
+                return getErrReturnObject().setErrMsg("出题方式为系统随机时题目设置数量需大于0").toString();
+            }
+            if (sat_courseware_classids.size() <= 0) {
+                return getErrReturnObject().setErrMsg("请选择分类").toString();
+            }
+            StringBuffer where = new StringBuffer("(1=2");
+            for (Object obj : sat_courseware_classids) {
+                JSONArray array = (JSONArray) obj;
+                for (Object obj2 : array) {
+                    where.append(" or (");
+                    where.append("JSON_CONTAINS(t1.sat_courseware_classids,'" + obj2 + "')");
+                    where.append(")");
+                }
+            }
+            where.append(")");
+
+            QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_courseware_testlibrary").setTableAlias("t1");
+            querySQL.setSiteid(siteid);
+            querySQL.setWhere(where.toString());
+            Rows rows = querySQL.query();
+            if (num > rows.size()) {
+                return getErrReturnObject().setErrMsg("当前分类下题目数量小于系统随机出题数").toString();
+            }
+            sat_courseware_testlibraryids = rows.toArrayList("sat_courseware_testlibraryid", new ArrayList<>());
+        }
+
+
         if (sat_courseware_testheadid <= 0) {
             sat_courseware_testheadid = createTableID(sat_courseware_testhead);
             InsertSQL insertSQL = SQLFactory.createInsertSQL(this, sat_courseware_testhead);
@@ -59,6 +93,12 @@ public class coursewaretesthead extends Controller {
             updateSQL.update();
         }
 
+        if (sat_courseware_testlibraryids.size() > 0) {
+            Collections.shuffle(sat_courseware_testlibraryids);
+            content.put("sat_courseware_testlibraryids",sat_courseware_testlibraryids.subList(0,num));
+            return addtestquestions();
+        }
+
         return detail();
     }
 
@@ -122,6 +162,77 @@ public class coursewaretesthead extends Controller {
         return getSucReturnObject().toString();
     }
 
+    @API(title = "添加考试题目", apiversion = R.ID20240323141602.v1.class)
+    public String addtestquestions() throws YosException {
+        Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
+        JSONArray sat_courseware_testlibraryids = content.getJSONArray("sat_courseware_testlibraryids");
+
+        Rows testheadRows = dbConnect.runSqlQuery("SELECT * from sat_courseware_testhead WHERE sat_courseware_testheadid=" + sat_courseware_testheadid + " and siteid='" + siteid + "'");
+        if (testheadRows.isEmpty()) {
+            return getErrReturnObject().setErrMsg("数据不存在").toString();
+        }
+        if (sat_courseware_testlibraryids.size() <= 0) {
+            return getErrReturnObject().setErrMsg("请选择题目").toString();
+        }
+        JSONArray testquestions = testheadRows.get(0).getJSONArray("testquestions");
+        //移除考试题目
+        testquestions.removeAll(CoursewareHelper.getRemoveArray(testquestions, sat_courseware_testlibraryids));
+        //添加考试题目
+        testquestions.addAll(CoursewareHelper.getTestlibraryRows(this, sat_courseware_testlibraryids));
+        //设置考试分数
+        testquestions = CoursewareHelper.setTestquestionsScore(testquestions);
+
+
+        int testaddmode = testheadRows.get(0).getInteger("testaddmode");
+
+        UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sat_courseware_testhead);
+        updateSQL.setUniqueid(sat_courseware_testheadid);
+        updateSQL.setSiteid(siteid);
+        updateSQL.setValue("testquestions", testquestions);
+        if (testaddmode == 2) {
+            updateSQL.setValue("num", testquestions.size());
+        }
+        updateSQL.update();
+        return detail();
+    }
+
+
+    @API(title = "删除考试题目", apiversion = R.ID20240323155602.v1.class)
+    public String deletetestquestions() throws YosException {
+
+        Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
+        JSONArray sat_courseware_testlibraryids = content.getJSONArray("sat_courseware_testlibraryids");
+
+
+        Rows testheadRows = dbConnect.runSqlQuery("SELECT * from sat_courseware_testhead WHERE sat_courseware_testheadid=" + sat_courseware_testheadid + " and siteid='" + siteid + "'");
+        if (testheadRows.isEmpty()) {
+            return getErrReturnObject().setErrMsg("数据不存在").toString();
+        }
+        if (sat_courseware_testlibraryids.size() <= 0) {
+            return getErrReturnObject().setErrMsg("请选择题目").toString();
+        }
+        JSONArray testquestions = testheadRows.get(0).getJSONArray("testquestions");
+        //移除考试题目
+        testquestions.removeAll(CoursewareHelper.getRemoveArray(testquestions, sat_courseware_testlibraryids));
+
+        //设置考试分数
+        testquestions = CoursewareHelper.setTestquestionsScore(testquestions);
+
+
+        int testaddmode = testheadRows.get(0).getInteger("testaddmode");
+
+        UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sat_courseware_testhead);
+        updateSQL.setUniqueid(sat_courseware_testheadid);
+        updateSQL.setSiteid(siteid);
+        updateSQL.setValue("testquestions", testquestions);
+        if (testaddmode == 2) {
+            updateSQL.setValue("num", testquestions.size());
+        }
+        updateSQL.update();
+        return detail();
+    }
+
+
     @API(title = "考试表头列表", apiversion = R.ID20240323112502.v1.class)
     public String list() throws YosException {
         StringBuffer where = new StringBuffer(" 1=1 ");
@@ -148,9 +259,13 @@ public class coursewaretesthead extends Controller {
 
                 JSONArray sat_courseware_classids = whereObject.getJSONArray("sat_courseware_classids");
                 for (Object obj : sat_courseware_classids) {
-                    where.append(" and (");
-                    where.append("JSON_CONTAINS(t1.sat_courseware_classids,'" + obj + "')");
-                    where.append(")");
+                    JSONArray array = (JSONArray) obj;
+                    for (Object obj2 : array) {
+                        where.append(" and (");
+                        where.append("JSON_CONTAINS(t1.sat_courseware_classids,'" + obj2 + "')");
+                        where.append(")");
+                    }
+
                 }
             }
             if (whereObject.containsKey("begindate_create") && !"".equals(whereObject.getString("begindate_create"))) {