coursewaretesthead.java 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. package restcontroller.webmanage.saletool.courseware;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import common.Controller;
  5. import common.YosException;
  6. import common.annotation.API;
  7. import common.data.*;
  8. import restcontroller.R;
  9. import java.util.ArrayList;
  10. /**
  11. * 考试表头
  12. */
  13. public class coursewaretesthead extends Controller {
  14. String sat_courseware_testhead = "sat_courseware_testhead";
  15. public coursewaretesthead(JSONObject content) throws YosException {
  16. super(content);
  17. }
  18. @API(title = "考试表头新增或更新", apiversion = R.ID20240323112202.v1.class)
  19. public String insertOrUpdate() throws YosException {
  20. Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
  21. JSONArray sat_courseware_classids = new JSONArray();
  22. if (content.containsKey("sat_courseware_classids")) {
  23. sat_courseware_classids = content.getJSONArray("sat_courseware_classids");
  24. }
  25. if (sat_courseware_testheadid <= 0) {
  26. sat_courseware_testheadid = createTableID(sat_courseware_testhead);
  27. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, sat_courseware_testhead);
  28. insertSQL.setSiteid(siteid);
  29. insertSQL.setUniqueid(sat_courseware_testheadid);
  30. insertSQL.setValue("title", content.getStringValue("title"));
  31. insertSQL.setValue("status", "新建");
  32. insertSQL.setValue("testaddmode", content.getIntValue("testaddmode", 1));
  33. insertSQL.setValue("passingscore", content.getBigDecimalValue("passingscore", 60));
  34. insertSQL.setValue("num", content.getIntValue("num", 0));
  35. insertSQL.setValue("sat_courseware_classids", sat_courseware_classids);
  36. insertSQL.insert();
  37. content.put("sat_courseware_testheadid", sat_courseware_testheadid);
  38. }
  39. if (sat_courseware_testheadid > 0) {
  40. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sat_courseware_testhead);
  41. updateSQL.setSiteid(siteid);
  42. updateSQL.setUniqueid(sat_courseware_testheadid);
  43. updateSQL.setValue("title", content.getStringValue("title"));
  44. updateSQL.setValue("testaddmode", content.getIntValue("testaddmode", 1));
  45. updateSQL.setValue("passingscore", content.getBigDecimalValue("passingscore", 60));
  46. updateSQL.setValue("num", content.getIntValue("num", 0));
  47. updateSQL.setValue("sat_courseware_classids", sat_courseware_classids);
  48. updateSQL.update();
  49. }
  50. return detail();
  51. }
  52. @API(title = "考试表头详情", apiversion = R.ID20240323112302.v1.class)
  53. public String detail() throws YosException {
  54. Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
  55. QuerySQL querySQL = SQLFactory.createQuerySQL(this, sat_courseware_testhead).setTableAlias("t1");
  56. querySQL.setSiteid(siteid);
  57. querySQL.setWhere("sat_courseware_testheadid", sat_courseware_testheadid);
  58. Rows rows = querySQL.query();
  59. Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
  60. JSONArray jsonArray = detailRow.getJSONArray("testquestions");
  61. detailRow.put("testquestions", jsonArray);
  62. JSONArray sat_courseware_classids = detailRow.getJSONArray("sat_courseware_classids");
  63. if (sat_courseware_classids.size() == 0) {
  64. detailRow.put("classnames", "");
  65. } else {
  66. detailRow.put("classnames", CoursewareHelper.getClassnames(this, sat_courseware_classids));
  67. }
  68. if (detailRow.getLong("testaddmode") == 1) {
  69. detailRow.put("testaddmodestr", "系统随机");
  70. }
  71. if (detailRow.getLong("testaddmode") == 2) {
  72. detailRow.put("testaddmodestr", "自选题目");
  73. }
  74. return getSucReturnObject().setData(detailRow).toString();
  75. }
  76. @API(title = "考试表头删除", apiversion = R.ID20240323112402.v1.class)
  77. public String delete() throws YosException {
  78. JSONArray sat_courseware_testheadids = content.getJSONArray("sat_courseware_testheadids");
  79. DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, sat_courseware_testhead);
  80. deleteSQL.setSiteid(siteid);
  81. deleteSQL.setWhere("sat_courseware_testheadid", sat_courseware_testheadids.toArray());
  82. deleteSQL.delete();
  83. return getSucReturnObject().toString();
  84. }
  85. @API(title = "考试表头列表", apiversion = R.ID20240323112502.v1.class)
  86. public String list() throws YosException {
  87. StringBuffer where = new StringBuffer(" 1=1 ");
  88. if (content.containsKey("where")) {
  89. JSONObject whereObject = content.getJSONObject("where");
  90. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  91. where.append(" and (");
  92. where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
  93. // where.append("or t1.notes like'%").append(whereObject.getString("condition")).append("%' ");
  94. where.append(")");
  95. }
  96. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  97. where.append(" and (");
  98. where.append("t1.status ='").append(whereObject.getString("status")).append("' ");
  99. where.append(")");
  100. }
  101. if (whereObject.containsKey("testaddmode") && !"".equals(whereObject.getString("testaddmode"))) {
  102. where.append(" and (");
  103. where.append("t1.testaddmode ='").append(whereObject.getString("testaddmode")).append("' ");
  104. where.append(")");
  105. }
  106. if (whereObject.containsKey("sat_courseware_classids") && !"".equals(whereObject.getString("sat_courseware_classids"))) {
  107. JSONArray sat_courseware_classids = whereObject.getJSONArray("sat_courseware_classids");
  108. for (Object obj : sat_courseware_classids) {
  109. where.append(" and (");
  110. where.append("JSON_CONTAINS(t1.sat_courseware_classids,'" + obj + "')");
  111. where.append(")");
  112. }
  113. }
  114. if (whereObject.containsKey("begindate_create") && !"".equals(whereObject.getString("begindate_create"))) {
  115. where.append(" and (");
  116. where.append("t1.createdate >='").append(whereObject.getString("begindate_create")).append("' ");
  117. where.append(")");
  118. }
  119. if (whereObject.containsKey("enddate_create") && !"".equals(whereObject.getString("enddate_create"))) {
  120. where.append(" and (");
  121. where.append("t1.createdate <='").append(whereObject.getString("enddate_create")).append(" 23:59:59' ");
  122. where.append(")");
  123. }
  124. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  125. where.append(" and (");
  126. where.append("t1.senddate >='").append(whereObject.getString("begindate")).append("' ");
  127. where.append(")");
  128. }
  129. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  130. where.append(" and (");
  131. where.append("t1.senddate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
  132. where.append(")");
  133. }
  134. }
  135. QuerySQL querySQL = SQLFactory.createQuerySQL(this, sat_courseware_testhead)
  136. .setTableAlias("t1");
  137. querySQL.setSiteid(siteid);
  138. querySQL.setWhere(where.toString());
  139. querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
  140. Rows rows = querySQL.query();
  141. for (Row row : rows) {
  142. if (row.getLong("testaddmode") == 1) {
  143. row.put("testaddmodestr", "系统随机");
  144. }
  145. if (row.getLong("testaddmode") == 2) {
  146. row.put("testaddmodestr", "自选题目");
  147. }
  148. JSONArray jsonArray = row.getJSONArray("testquestions");
  149. row.put("testquestions", jsonArray);
  150. }
  151. return getSucReturnObject().setData(rows).toString();
  152. }
  153. }