| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- package restcontroller.webmanage.saletool.courseware;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import common.Controller;
- import common.YosException;
- import common.annotation.API;
- import common.data.*;
- import restcontroller.R;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.Collections;
- /**
- * 考试表头
- */
- public class coursewaretesthead extends Controller {
- String sat_courseware_testhead = "sat_courseware_testhead";
- public coursewaretesthead(JSONObject content) throws YosException {
- super(content);
- }
- @API(title = "考试表头新增或更新", apiversion = R.ID20240323112202.v1.class)
- 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);
- insertSQL.setSiteid(siteid);
- insertSQL.setUniqueid(sat_courseware_testheadid);
- insertSQL.setValue("title", content.getStringValue("title"));
- insertSQL.setValue("status", "新建");
- insertSQL.setValue("testaddmode", content.getIntValue("testaddmode", 1));
- insertSQL.setValue("passingscore", content.getBigDecimalValue("passingscore", 60));
- insertSQL.setValue("num", content.getIntValue("num", 0));
- insertSQL.setValue("sat_courseware_classids", sat_courseware_classids);
- insertSQL.insert();
- content.put("sat_courseware_testheadid", sat_courseware_testheadid);
- }
- if (sat_courseware_testheadid > 0) {
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sat_courseware_testhead);
- updateSQL.setSiteid(siteid);
- updateSQL.setUniqueid(sat_courseware_testheadid);
- updateSQL.setValue("title", content.getStringValue("title"));
- updateSQL.setValue("testaddmode", content.getIntValue("testaddmode", 1));
- updateSQL.setValue("passingscore", content.getBigDecimalValue("passingscore", 60));
- updateSQL.setValue("num", content.getIntValue("num", 0));
- updateSQL.setValue("sat_courseware_classids", sat_courseware_classids);
- 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();
- }
- @API(title = "考试表头详情", apiversion = R.ID20240323112302.v1.class)
- public String detail() throws YosException {
- Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, sat_courseware_testhead).setTableAlias("t1");
- querySQL.setSiteid(siteid);
- querySQL.setWhere("sat_courseware_testheadid", sat_courseware_testheadid);
- Rows rows = querySQL.query();
- Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
- JSONArray jsonArray = detailRow.getJSONArray("testquestions");
- detailRow.put("testquestions", jsonArray);
- JSONArray sat_courseware_classids = detailRow.getJSONArray("sat_courseware_classids");
- if (sat_courseware_classids.size() == 0) {
- detailRow.put("classnames", "");
- } else {
- detailRow.put("classnames", CoursewareHelper.getClassnames(this, sat_courseware_classids));
- }
- if (detailRow.getLong("testaddmode") == 1) {
- detailRow.put("testaddmodestr", "系统随机");
- }
- if (detailRow.getLong("testaddmode") == 2) {
- detailRow.put("testaddmodestr", "自选题目");
- }
- return getSucReturnObject().setData(detailRow).toString();
- }
- @API(title = "考试表头删除", apiversion = R.ID20240323112402.v1.class)
- public String delete() throws YosException {
- JSONArray sat_courseware_testheadids = content.getJSONArray("sat_courseware_testheadids");
- DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, sat_courseware_testhead);
- deleteSQL.setSiteid(siteid);
- deleteSQL.setWhere("sat_courseware_testheadid", sat_courseware_testheadids.toArray());
- deleteSQL.delete();
- return getSucReturnObject().toString();
- }
- @API(title = "考试表头发布", apiversion = R.ID20240323141002.v1.class)
- public String release() throws YosException {
- JSONArray sat_courseware_testheadids = content.getJSONArray("sat_courseware_testheadids");
- int status = content.getIntValue("status", 0);
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sat_courseware_testhead);
- updateSQL.setSiteid(siteid);
- updateSQL.setValue("status", status == 0 ? "新建" : "发布");
- updateSQL.setWhere("sat_courseware_testheadid", sat_courseware_testheadids.toArray());
- updateSQL.update();
- 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 ");
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where.append(" and (");
- where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
- // where.append("or t1.notes like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
- where.append(" and (");
- where.append("t1.status ='").append(whereObject.getString("status")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("testaddmode") && !"".equals(whereObject.getString("testaddmode"))) {
- where.append(" and (");
- where.append("t1.testaddmode ='").append(whereObject.getString("testaddmode")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("sat_courseware_classids") && !"".equals(whereObject.getString("sat_courseware_classids"))) {
- JSONArray sat_courseware_classids = whereObject.getJSONArray("sat_courseware_classids");
- for (Object obj : sat_courseware_classids) {
- 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"))) {
- where.append(" and (");
- where.append("t1.createdate >='").append(whereObject.getString("begindate_create")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("enddate_create") && !"".equals(whereObject.getString("enddate_create"))) {
- where.append(" and (");
- where.append("t1.createdate <='").append(whereObject.getString("enddate_create")).append(" 23:59:59' ");
- where.append(")");
- }
- if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
- where.append(" and (");
- where.append("t1.senddate >='").append(whereObject.getString("begindate")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
- where.append(" and (");
- where.append("t1.senddate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
- where.append(")");
- }
- }
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, sat_courseware_testhead)
- .setTableAlias("t1");
- querySQL.setSiteid(siteid);
- querySQL.setWhere(where.toString());
- querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
- Rows rows = querySQL.query();
- for (Row row : rows) {
- if (row.getLong("testaddmode") == 1) {
- row.put("testaddmodestr", "系统随机");
- }
- if (row.getLong("testaddmode") == 2) {
- row.put("testaddmodestr", "自选题目");
- }
- JSONArray jsonArray = row.getJSONArray("testquestions");
- row.put("testquestions", jsonArray);
- }
- return getSucReturnObject().setData(rows).toString();
- }
- }
|