| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- 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.util.ArrayList;
- /**
- * 考试表头
- */
- 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");
- JSONArray sat_courseware_classids = new JSONArray();
- if (content.containsKey("sat_courseware_classids")) {
- sat_courseware_classids = content.getJSONArray("sat_courseware_classids");
- }
- 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();
- }
- 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.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) {
- where.append(" and (");
- where.append("JSON_CONTAINS(t1.sat_courseware_classids,'" + obj + "')");
- 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();
- }
- }
|