coursewaretesthead.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. package restcontroller.webmanage.saletool.courseware;
  2. import beans.department.Department;
  3. import beans.salearea.SaleArea;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import common.Controller;
  7. import common.YosException;
  8. import common.annotation.API;
  9. import common.annotation.CACHEING;
  10. import common.data.*;
  11. import restcontroller.R;
  12. import java.io.IOException;
  13. import java.math.BigDecimal;
  14. import java.util.ArrayList;
  15. import java.util.Collections;
  16. import java.util.stream.Collectors;
  17. import java.util.stream.IntStream;
  18. /**
  19. * 考试表头
  20. */
  21. public class coursewaretesthead extends Controller {
  22. String sat_courseware_testhead = "sat_courseware_testhead";
  23. public coursewaretesthead(JSONObject content) throws YosException {
  24. super(content);
  25. }
  26. @API(title = "考试表头新增或更新", apiversion = R.ID20240323112202.v1.class)
  27. public String insertOrUpdate() throws YosException {
  28. Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
  29. int testaddmode = content.getIntValue("testaddmode", 1);
  30. int num = content.getIntValue("num", 0);
  31. JSONArray sat_courseware_classids = new JSONArray();
  32. if (content.containsKey("sat_courseware_classids")) {
  33. sat_courseware_classids = content.getJSONArray("sat_courseware_classids");
  34. }
  35. ArrayList<Long> sat_courseware_testlibraryids = new ArrayList<>();
  36. if (testaddmode == 1) {
  37. if (num <= 0) {
  38. return getErrReturnObject().setErrMsg("出题方式为系统随机时题目设置数量需大于0").toString();
  39. }
  40. if (sat_courseware_classids.size() <= 0) {
  41. return getErrReturnObject().setErrMsg("请选择分类").toString();
  42. }
  43. Rows rows = CoursewareHelper.getTestlibraryWithCoursewareClassRows(this, sat_courseware_classids);
  44. if (num > rows.size()) {
  45. return getErrReturnObject().setErrMsg("当前分类下题目数量小于系统随机出题数").toString();
  46. }
  47. sat_courseware_testlibraryids = rows.toArrayList("sat_courseware_testlibraryid", new ArrayList<>());
  48. }
  49. if (sat_courseware_testheadid <= 0) {
  50. sat_courseware_testheadid = createTableID(sat_courseware_testhead);
  51. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, sat_courseware_testhead);
  52. insertSQL.setSiteid(siteid);
  53. insertSQL.setUniqueid(sat_courseware_testheadid);
  54. insertSQL.setValue("title", content.getStringValue("title"));
  55. insertSQL.setValue("status", "新建");
  56. insertSQL.setValue("testaddmode", content.getIntValue("testaddmode", 1));
  57. insertSQL.setValue("passingscore", content.getBigDecimalValue("passingscore", 60));
  58. insertSQL.setValue("num", content.getIntValue("num", 0));
  59. insertSQL.setValue("sat_courseware_classids", sat_courseware_classids);
  60. insertSQL.insert();
  61. content.put("sat_courseware_testheadid", sat_courseware_testheadid);
  62. }
  63. if (sat_courseware_testheadid > 0) {
  64. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sat_courseware_testhead);
  65. updateSQL.setSiteid(siteid);
  66. updateSQL.setUniqueid(sat_courseware_testheadid);
  67. updateSQL.setValue("title", content.getStringValue("title"));
  68. updateSQL.setValue("testaddmode", content.getIntValue("testaddmode", 1));
  69. updateSQL.setValue("passingscore", content.getBigDecimalValue("passingscore", 60));
  70. updateSQL.setValue("num", content.getIntValue("num", 0));
  71. updateSQL.setValue("sat_courseware_classids", sat_courseware_classids);
  72. if (testaddmode == 1) {//系统随机
  73. updateSQL.setValue("testquestions", new JSONArray());
  74. }
  75. updateSQL.update();
  76. }
  77. if (testaddmode == 1) {////系统随机
  78. content.put("sat_courseware_testlibraryids", sat_courseware_testlibraryids);
  79. return addtestquestions();
  80. }
  81. return detail();
  82. }
  83. @API(title = "考试表头详情", apiversion = R.ID20240323112302.v1.class)
  84. public String detail() throws YosException {
  85. Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
  86. QuerySQL querySQL = SQLFactory.createQuerySQL(this, sat_courseware_testhead).setTableAlias("t1");
  87. querySQL.setSiteid(siteid);
  88. querySQL.setWhere("sat_courseware_testheadid", sat_courseware_testheadid);
  89. Rows rows = querySQL.query();
  90. Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
  91. JSONArray jsonArray = detailRow.getJSONArray("testquestions");
  92. detailRow.put("testquestions", jsonArray);
  93. JSONArray sat_courseware_classids = detailRow.getJSONArray("sat_courseware_classids");
  94. if (sat_courseware_classids.size() == 0) {
  95. detailRow.put("classnames", "");
  96. } else {
  97. detailRow.put("classnames", CoursewareHelper.getClassnames(this, sat_courseware_classids));
  98. }
  99. if (detailRow.getLong("testaddmode") == 1) {
  100. detailRow.put("testaddmodestr", "系统随机");
  101. }
  102. if (detailRow.getLong("testaddmode") == 2) {
  103. detailRow.put("testaddmodestr", "自选题目");
  104. }
  105. return getSucReturnObject().setData(detailRow).toString();
  106. }
  107. @API(title = "考试表头删除", apiversion = R.ID20240323112402.v1.class)
  108. public String delete() throws YosException {
  109. JSONArray sat_courseware_testheadids = content.getJSONArray("sat_courseware_testheadids");
  110. DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, sat_courseware_testhead);
  111. deleteSQL.setSiteid(siteid);
  112. deleteSQL.setWhere("sat_courseware_testheadid", sat_courseware_testheadids.toArray());
  113. deleteSQL.delete();
  114. return getSucReturnObject().toString();
  115. }
  116. @API(title = "考试表头发布", apiversion = R.ID20240323141002.v1.class)
  117. public String release() throws YosException {
  118. JSONArray sat_courseware_testheadids = content.getJSONArray("sat_courseware_testheadids");
  119. int status = content.getIntValue("status", 0);
  120. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sat_courseware_testhead);
  121. updateSQL.setSiteid(siteid);
  122. updateSQL.setValue("status", status == 0 ? "新建" : "发布");
  123. updateSQL.setValue("sendby", username);
  124. updateSQL.setValue("senddate", getDateTime_Str());
  125. updateSQL.setWhere("sat_courseware_testheadid", sat_courseware_testheadids.toArray());
  126. updateSQL.update();
  127. return getSucReturnObject().toString();
  128. }
  129. @API(title = "添加考试题目", apiversion = R.ID20240323141602.v1.class)
  130. public String addtestquestions() throws YosException {
  131. Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
  132. JSONArray sat_courseware_testlibraryids = content.getJSONArray("sat_courseware_testlibraryids");
  133. Rows testheadRows = dbConnect.runSqlQuery("SELECT * from sat_courseware_testhead WHERE sat_courseware_testheadid=" + sat_courseware_testheadid + " and siteid='" + siteid + "'");
  134. if (testheadRows.isEmpty()) {
  135. return getErrReturnObject().setErrMsg("数据不存在").toString();
  136. }
  137. if (sat_courseware_testlibraryids.size() <= 0) {
  138. return getErrReturnObject().setErrMsg("请选择题目").toString();
  139. }
  140. JSONArray testquestions = testheadRows.get(0).getJSONArray("testquestions");
  141. //移除考试题目
  142. testquestions.removeAll(CoursewareHelper.getRemoveArray(testquestions, sat_courseware_testlibraryids));
  143. //添加考试题目
  144. testquestions.addAll(CoursewareHelper.getTestlibraryRows(this, sat_courseware_testlibraryids));
  145. int testaddmode = testheadRows.get(0).getInteger("testaddmode");
  146. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sat_courseware_testhead);
  147. updateSQL.setUniqueid(sat_courseware_testheadid);
  148. updateSQL.setSiteid(siteid);
  149. updateSQL.setValue("testquestions", testquestions);
  150. if (testaddmode == 2) {
  151. updateSQL.setValue("num", testquestions.size());
  152. }
  153. updateSQL.update();
  154. return detail();
  155. }
  156. @API(title = "删除考试题目", apiversion = R.ID20240323155602.v1.class)
  157. public String deletetestquestions() throws YosException {
  158. Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
  159. JSONArray sat_courseware_testlibraryids = content.getJSONArray("sat_courseware_testlibraryids");
  160. Rows testheadRows = dbConnect.runSqlQuery("SELECT * from sat_courseware_testhead WHERE sat_courseware_testheadid=" + sat_courseware_testheadid + " and siteid='" + siteid + "'");
  161. if (testheadRows.isEmpty()) {
  162. return getErrReturnObject().setErrMsg("数据不存在").toString();
  163. }
  164. if (sat_courseware_testlibraryids.size() <= 0) {
  165. return getErrReturnObject().setErrMsg("请选择题目").toString();
  166. }
  167. JSONArray testquestions = testheadRows.get(0).getJSONArray("testquestions");
  168. //移除考试题目
  169. testquestions.removeAll(CoursewareHelper.getRemoveArray(testquestions, sat_courseware_testlibraryids));
  170. int testaddmode = testheadRows.get(0).getInteger("testaddmode");
  171. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, sat_courseware_testhead);
  172. updateSQL.setUniqueid(sat_courseware_testheadid);
  173. updateSQL.setSiteid(siteid);
  174. updateSQL.setValue("testquestions", testquestions);
  175. if (testaddmode == 2) {
  176. updateSQL.setValue("num", testquestions.size());
  177. }
  178. updateSQL.update();
  179. return detail();
  180. }
  181. @API(title = "考试表头列表", apiversion = R.ID20240323112502.v1.class)
  182. public String list() throws YosException {
  183. StringBuffer where = new StringBuffer(" 1=1 ");
  184. if (content.containsKey("where")) {
  185. JSONObject whereObject = content.getJSONObject("where");
  186. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  187. where.append(" and (");
  188. where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
  189. // where.append("or t1.notes like'%").append(whereObject.getString("condition")).append("%' ");
  190. where.append(")");
  191. }
  192. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  193. where.append(" and (");
  194. where.append("t1.status ='").append(whereObject.getString("status")).append("' ");
  195. where.append(")");
  196. }
  197. if (whereObject.containsKey("testaddmode") && !"".equals(whereObject.getString("testaddmode"))) {
  198. where.append(" and (");
  199. where.append("t1.testaddmode ='").append(whereObject.getString("testaddmode")).append("' ");
  200. where.append(")");
  201. }
  202. if (whereObject.containsKey("sat_courseware_classids") && !"".equals(whereObject.getString("sat_courseware_classids"))) {
  203. JSONArray sat_courseware_classids = whereObject.getJSONArray("sat_courseware_classids");
  204. if (sat_courseware_classids.size() > 0) {
  205. where.append(" and (1=2");
  206. for (Object obj : sat_courseware_classids) {
  207. JSONArray array = (JSONArray) obj;
  208. for (Object obj2 : array) {
  209. where.append(" or (");
  210. where.append("JSON_CONTAINS(t1.sat_courseware_classids,'" + obj2 + "')");
  211. where.append(")");
  212. }
  213. }
  214. where.append(")");
  215. }
  216. }
  217. if (whereObject.containsKey("begindate_create") && !"".equals(whereObject.getString("begindate_create"))) {
  218. where.append(" and (");
  219. where.append("t1.createdate >='").append(whereObject.getString("begindate_create")).append("' ");
  220. where.append(")");
  221. }
  222. if (whereObject.containsKey("enddate_create") && !"".equals(whereObject.getString("enddate_create"))) {
  223. where.append(" and (");
  224. where.append("t1.createdate <='").append(whereObject.getString("enddate_create")).append(" 23:59:59' ");
  225. where.append(")");
  226. }
  227. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  228. where.append(" and (");
  229. where.append("t1.senddate >='").append(whereObject.getString("begindate")).append("' ");
  230. where.append(")");
  231. }
  232. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  233. where.append(" and (");
  234. where.append("t1.senddate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
  235. where.append(")");
  236. }
  237. }
  238. QuerySQL querySQL = SQLFactory.createQuerySQL(this, sat_courseware_testhead)
  239. .setTableAlias("t1");
  240. querySQL.setSiteid(siteid);
  241. querySQL.setWhere(where.toString());
  242. querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
  243. Rows rows = querySQL.query();
  244. for (Row row : rows) {
  245. if (row.getLong("testaddmode") == 1) {
  246. row.put("testaddmodestr", "系统随机");
  247. }
  248. if (row.getLong("testaddmode") == 2) {
  249. row.put("testaddmodestr", "自选题目");
  250. }
  251. JSONArray jsonArray = row.getJSONArray("testquestions");
  252. row.put("testquestions", jsonArray);
  253. }
  254. return getSucReturnObject().setData(rows).toString();
  255. }
  256. @API(title = "添加人员和试卷", apiversion = R.ID20240325102202.v1.class)
  257. public String addTest() throws YosException {
  258. Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
  259. JSONArray userids = content.getJSONArray("userids");
  260. Rows testheadRows = dbConnect.runSqlQuery("SELECT * from sat_courseware_testhead WHERE sat_courseware_testheadid=" + sat_courseware_testheadid + " and siteid='" + siteid + "'");
  261. if (testheadRows.isEmpty()) {
  262. return getErrReturnObject().setErrMsg("考试不存在").toString();
  263. }
  264. int testaddmode = testheadRows.get(0).getInteger("testaddmode");
  265. int num = testheadRows.get(0).getInteger("num");
  266. JSONArray testquestions = testheadRows.get(0).getJSONArray("testquestions");
  267. if (testaddmode == 1) {
  268. if (num > testquestions.size()) {
  269. return getErrReturnObject().setErrMsg("无法添加,题库数量小于考试题目数量").toString();
  270. }
  271. Collections.shuffle(testquestions);
  272. testquestions = new JSONArray(
  273. IntStream.range(0, num)
  274. .mapToObj(testquestions::get)
  275. .collect(Collectors.toList())
  276. );
  277. }
  278. ArrayList<String> sqlList = CoursewareHelper.getCoursewareTestSql(this, sat_courseware_testheadid, userids, testquestions);
  279. dbConnect.runSqlUpdate(sqlList);
  280. return getSucReturnObject().toString();
  281. }
  282. @API(title = "删除人员和试卷", apiversion = R.ID20240325105502.v1.class)
  283. public String deleteTest() throws YosException {
  284. Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
  285. JSONArray userids = content.getJSONArray("userids");
  286. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_courseware_test", "sat_courseware_testid");
  287. querySQL.setSiteid(siteid);
  288. querySQL.setWhere("sat_courseware_testheadid", sat_courseware_testheadid);
  289. querySQL.setWhere("userid", userids.toArray());
  290. ArrayList ids = querySQL.query().toArrayList("sat_courseware_testid");
  291. DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sat_courseware_test");
  292. deleteSQL.setSiteid(siteid);
  293. deleteSQL.setWhere("sat_courseware_testid", ids);
  294. deleteSQL.delete();
  295. DeleteSQL deleteSQL2 = SQLFactory.createDeleteSQL(this, "sat_courseware_testitems");
  296. deleteSQL2.setSiteid(siteid);
  297. deleteSQL2.setWhere("sat_courseware_testid", ids);
  298. deleteSQL2.delete();
  299. return getSucReturnObject().toString();
  300. }
  301. @API(title = "选择员工列表", apiversion = R.ID20240325110702.v1.class)
  302. public String query_hrList() throws YosException {
  303. /*
  304. 过滤条件设置
  305. */
  306. StringBuffer where = new StringBuffer(" 1=1 ");
  307. if (content.containsKey("where")) {
  308. JSONObject whereObject = content.getJSONObject("where");
  309. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  310. where.append(" and(");
  311. where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' ");
  312. where.append("or t1.phonenumber like'%").append(whereObject.getString("condition")).append("%' ");
  313. where.append("or t1.position like'%").append(whereObject.getString("condition")).append("%' ");
  314. where.append("or t1.hrcode like'%").append(whereObject.getString("condition")).append("%' ");
  315. where.append(")");
  316. }
  317. }
  318. Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
  319. boolean containssub = content.getBoolean("containssub");
  320. JSONArray departmentidsArray = content.getJSONArray("departmentids");
  321. ArrayList<Long> departmentidsList = new ArrayList<>();
  322. for (Object o : departmentidsArray) {
  323. long departmentid = Long.parseLong(o.toString());
  324. departmentidsList.add(departmentid);
  325. if (containssub) {
  326. departmentidsList.addAll(Department.getSubDepartmentIds(this, departmentid));
  327. }
  328. }
  329. where.append(" and not exists(select 1 from sat_courseware_test where userid = t1.userid and sat_courseware_testheadid=" + sat_courseware_testheadid + " and siteid='" + siteid + "' )");
  330. SQLFactory sqlFactory = new SQLFactory(this, "员工列表查询", pageSize, pageNumber, pageSorting);
  331. sqlFactory.addParameter("siteid", siteid);
  332. sqlFactory.addParameter_in("departmentid", departmentidsList);
  333. sqlFactory.addParameter_SQL("where", where);
  334. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  335. return getSucReturnObject().setData(rows).toString();
  336. }
  337. @API(title = "选择营销区域查询经销商成员", apiversion = R.ID20240325130602.v1.class)
  338. public String query_agent() throws YosException, IOException {
  339. /*
  340. 过滤条件设置
  341. */
  342. StringBuffer where = new StringBuffer(" 1=1 ");
  343. if (content.containsKey("where")) {
  344. JSONObject whereObject = content.getJSONObject("where");
  345. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  346. where.append(" and(");
  347. where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' ");
  348. where.append("or t1.position like'%").append(whereObject.getString("condition")).append("%' ");
  349. where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
  350. where.append("or t2.province like'%").append(whereObject.getString("condition")).append("%' ");
  351. where.append("or t2.city like'%").append(whereObject.getString("condition")).append("%' ");
  352. where.append("or t2.county like'%").append(whereObject.getString("condition")).append("%' ");
  353. where.append("or t2.address like'%").append(whereObject.getString("condition")).append("%' ");
  354. where.append("or t3.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
  355. where.append(")");
  356. }
  357. }
  358. Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
  359. boolean containssub = content.getBoolean("containssub");
  360. JSONArray sa_saleareaidsArray = content.getJSONArray("sa_saleareaids");
  361. ArrayList<Long> sa_saleareaidsList = new ArrayList<>();
  362. for (Object o : sa_saleareaidsArray) {
  363. Long sa_saleareaid = Long.valueOf(o.toString());
  364. sa_saleareaidsList.add(sa_saleareaid);
  365. if (containssub) {
  366. sa_saleareaidsList.addAll(SaleArea.getSubSaleAreaIds(this, sa_saleareaid));
  367. }
  368. }
  369. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_enterprise_hr",
  370. "userid", "name", "position")
  371. .setTableAlias("t1");
  372. querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t2", "t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid",
  373. "enterprisename", "province", "city", "county", "address");
  374. querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t3", "t3.sys_enterpriseid=t1.sys_enterpriseid and t3.siteid=t1.siteid",
  375. "type", "agentnum");
  376. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise_tradefield", "t4", "t4.sys_enterpriseid=t1.sys_enterpriseid and t3.siteid=t1.siteid");
  377. querySQL.addJoinTable(JOINTYPE.left, "sa_salearea", "t5", "t5.sa_saleareaid=t4.sa_saleareaid and t5.siteid=t4.siteid",
  378. "areaname");
  379. querySQL.setWhere("t1.siteid", siteid);
  380. querySQL.setWhere("t4.sa_saleareaid", sa_saleareaidsList);
  381. querySQL.setWhere(where.toString());
  382. querySQL.setWhere("not exists(select 1 from sat_courseware_test where userid = t1.userid and sat_courseware_testheadid=" + sat_courseware_testheadid + " and siteid='" + siteid + "' )");
  383. querySQL.setOrderBy(pageSorting);
  384. querySQL.setPage(pageSize, pageNumber);
  385. Rows rows = querySQL.query();
  386. for (Row row : rows) {
  387. row.put("pcc", row.getString("province") + row.getString("city") + row.getString("county"));
  388. }
  389. return getSucReturnObject().setData(rows).toString();
  390. }
  391. @API(title = "(部门)人员列表", apiversion = R.ID20240325134302.v1.class)
  392. public String queryhrList() throws YosException {
  393. Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
  394. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_hr",
  395. "hrid", "hrcode", "name", "phonenumber", "position", "userid")
  396. .setTableAlias("t1");
  397. querySQL.addJoinTable(JOINTYPE.left, "sys_department", "t2", "t1.siteid = t2.siteid and t1.departmentid = t2.departmentid",
  398. "depname", "depfullname");
  399. querySQL.setWhere(" exists(select 1 from sat_courseware_test where userid = t1.userid and sat_courseware_testheadid=" + sat_courseware_testheadid + " and siteid='" + siteid + "' )");
  400. Rows rows = querySQL.query();
  401. return getSucReturnObject().setData(rows).toString();
  402. }
  403. @API(title = "(区域)人员列表", apiversion = R.ID20240325135402.v1.class)
  404. public String queryagent() throws YosException, IOException {
  405. Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
  406. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_enterprise_hr",
  407. "userid", "name", "position")
  408. .setTableAlias("t1");
  409. querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t2", "t1.siteid = t2.siteid and t1.sys_enterpriseid = t2.sys_enterpriseid",
  410. "enterprisename");
  411. querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t3", "t3.sys_enterpriseid=t1.sys_enterpriseid and t3.siteid=t1.siteid",
  412. "agentnum");
  413. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise_tradefield", "t4", "t4.sys_enterpriseid=t1.sys_enterpriseid and t3.siteid=t1.siteid");
  414. querySQL.addJoinTable(JOINTYPE.left, "sa_salearea", "t5", "t5.sa_saleareaid=t4.sa_saleareaid and t5.siteid=t4.siteid",
  415. "areaname");
  416. querySQL.setWhere("t1.siteid", siteid);
  417. querySQL.setWhere(" exists(select 1 from sat_courseware_test where userid = t1.userid and sat_courseware_testheadid=" + sat_courseware_testheadid + " and siteid='" + siteid + "' )");
  418. querySQL.setOrderBy(pageSorting);
  419. querySQL.setPage(pageSize, pageNumber);
  420. Rows rows = querySQL.query();
  421. return getSucReturnObject().setData(rows).toString();
  422. }
  423. @API(title = "考试概况列表", apiversion = R.ID20240325141602.v1.class)
  424. public String testlist() throws YosException {
  425. StringBuffer where = new StringBuffer(" 1=1 ");
  426. if (content.containsKey("where")) {
  427. JSONObject whereObject = content.getJSONObject("where");
  428. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  429. where.append(" and(");
  430. where.append("t1.name like'%").append(whereObject.getString("condition")).append("%' ");
  431. where.append(")");
  432. }
  433. }
  434. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_courseware_test").setTableAlias("t1");
  435. querySQL.addJoinTable(JOINTYPE.left, "sat_courseware_testhead", "t2", "t2.sat_courseware_testheadid=t1.sat_courseware_testheadid and t2.siteid=t1.siteid"
  436. , "num");
  437. querySQL.setWhere(where.toString());
  438. querySQL.setSiteid(siteid);
  439. querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
  440. Rows rows = querySQL.query();
  441. for (Row row : rows) {
  442. row.put("answercount", row.getString("answercount") + "/" + row.getString("num"));
  443. row.putIfAbsent("score", 0);
  444. row.putIfAbsent("begdate", "");
  445. row.putIfAbsent("submitdate", "");
  446. }
  447. return getSucReturnObject().setData(rows).toString();
  448. }
  449. @API(title = "考试概况列表", apiversion = R.ID20240325143202.v1.class)
  450. public String testinfo() throws YosException {
  451. Long sat_courseware_testheadid = content.getLongValue("sat_courseware_testheadid");
  452. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_courseware_test").setTableAlias("t1");
  453. querySQL.addJoinTable(JOINTYPE.left, "sat_courseware_testhead", "t2", "t2.sat_courseware_testheadid=t1.sat_courseware_testheadid and t2.siteid=t1.siteid"
  454. , "num", "passingscore");
  455. querySQL.setWhere("sat_courseware_testheadid", sat_courseware_testheadid);
  456. querySQL.setSiteid(siteid);
  457. Rows rows = querySQL.query();
  458. Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
  459. detailRow.putIfAbsent("score", 0);
  460. detailRow.putIfAbsent("begdate", "");
  461. detailRow.putIfAbsent("submitdate", "");
  462. BigDecimal passingscore = detailRow.getBigDecimal("passingscore");
  463. BigDecimal score = detailRow.getBigDecimal("score");
  464. if (score.compareTo(passingscore) >= 0) {
  465. detailRow.put("ispassingscore", "及格");
  466. } else {
  467. detailRow.put("ispassingscore", "不及格");
  468. }
  469. QuerySQL querySQL2 = SQLFactory.createQuerySQL(this, "sat_courseware_testitems").setTableAlias("t1");
  470. querySQL2.setSiteid(siteid)
  471. .setWhere("sat_courseware_testid", detailRow.getLong("sat_courseware_testid"));
  472. Rows rows2 = querySQL2.query();
  473. detailRow.put("testquestions", rows2);
  474. return getSucReturnObject().setData(detailRow).toString();
  475. }
  476. @API(title = "查询我的考试列表", apiversion = R.ID20240326133302.v1.class)
  477. public String queryUserTestList() throws YosException {
  478. StringBuffer where = new StringBuffer(" 1=1 ");
  479. if (content.containsKey("where")) {
  480. JSONObject whereObject = content.getJSONObject("where");
  481. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  482. where.append(" and(");
  483. where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
  484. where.append(")");
  485. }
  486. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  487. where.append(" and(");
  488. where.append("t2.status='").append(whereObject.getString("status")).append("' ");
  489. where.append(")");
  490. }
  491. if (whereObject.containsKey("sat_courseware_classids") && !"".equals(whereObject.getString("sat_courseware_classids"))) {
  492. JSONArray sat_courseware_classids = whereObject.getJSONArray("sat_courseware_classids");
  493. if (sat_courseware_classids.size() > 0) {
  494. where.append(" and (1=2");
  495. for (Object obj : sat_courseware_classids) {
  496. JSONArray array = (JSONArray) obj;
  497. for (Object obj2 : array) {
  498. where.append(" or (");
  499. where.append("JSON_CONTAINS(t1.sat_courseware_classids,'" + obj2 + "')");
  500. where.append(")");
  501. }
  502. }
  503. where.append(")");
  504. }
  505. }
  506. }
  507. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_courseware_testhead"
  508. , "sat_courseware_testheadid", "title", "num")
  509. .setTableAlias("t1");
  510. querySQL.addJoinTable(JOINTYPE.inner, "sat_courseware_test", "t2", "t2.sat_courseware_testheadid=t1.sat_courseware_testheadid and t2.siteid=t1.siteid"
  511. , "sat_courseware_testid", "status", "score", "answercount");
  512. querySQL.setWhere(where.toString());
  513. if (!userInfo.isSysAdministrator()) {
  514. querySQL.setWhere("t2.userid", userid);
  515. }
  516. querySQL.setSiteid(siteid);
  517. querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
  518. Rows rows = querySQL.query();
  519. for (Row row : rows) {
  520. row.put("answerinfo", row.getString("answercount") + "/" + row.getString("num"));
  521. row.putIfAbsent("score", 0.0);
  522. }
  523. return getSucReturnObject().setData(rows).toString();
  524. }
  525. }