EquipmentResourceLibrary.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. package restcontroller.webmanage.saletool.sharematerial;
  2. import beans.attachment.Attachment;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import common.Controller;
  6. import common.YosException;
  7. import common.annotation.API;
  8. import common.data.*;
  9. import restcontroller.R;
  10. import java.util.ArrayList;
  11. /**
  12. * 装备资源库
  13. */
  14. public class EquipmentResourceLibrary extends Controller {
  15. /**
  16. * 构造函数
  17. *
  18. * @param content
  19. */
  20. public EquipmentResourceLibrary(JSONObject content) throws YosException {
  21. super(content);
  22. }
  23. String sat_sharematerial = "sat_sharematerial";
  24. @API(title = "装备资源库新增或编辑", apiversion = R.ID20240407094502.v1.class)
  25. public String insertOrUpdate() throws YosException {
  26. Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  27. JSONArray sat_sharematerial_classids = new JSONArray();
  28. if (content.containsKey("sat_sharematerial_classids")) {
  29. sat_sharematerial_classids = content.getJSONArray("sat_sharematerial_classids");
  30. for (Object obj : sat_sharematerial_classids) {
  31. if (!(obj instanceof JSONArray)) {
  32. return getErrReturnObject().setErrMsg("格式不正确,正确的为[[1,2,3]]").toString();
  33. }
  34. }
  35. }
  36. if (sat_sharematerialid <= 0) {
  37. sat_sharematerialid = createTableID(sat_sharematerial);
  38. InsertSQL sqlFactory = SQLFactory.createInsertSQL(this, sat_sharematerial);
  39. sqlFactory.setUniqueid(sat_sharematerialid);
  40. sqlFactory.setSiteid(siteid);
  41. sqlFactory.setValue("sys_enterpriseid", sys_enterpriseid);
  42. sqlFactory.setValue("classid", 3);
  43. sqlFactory.setValue("title", content.getStringValue("title"));
  44. sqlFactory.setValue("sat_sharematerial_classids", sat_sharematerial_classids);
  45. sqlFactory.setValue("type", content.getIntValue("type"));
  46. sqlFactory.setValue("sequence", content.getLongValue("sequence"));
  47. sqlFactory.setValue("isqrcode", content.getBooleanValue("isqrcode"));
  48. sqlFactory.setValue("qrcodecontent", content.getStringValue("qrcodecontent", true));
  49. sqlFactory.setValue("canshared_c", content.getBooleanValue("canshared_c"));
  50. sqlFactory.setValue("candownload", content.getBooleanValue("candownload"));
  51. sqlFactory.setValue("candownload_c", content.getBooleanValue("candownload_c"));
  52. sqlFactory.insert();
  53. content.put("sat_sharematerialid", sat_sharematerialid);
  54. }
  55. if (sat_sharematerialid > 0) {
  56. UpdateSQL sqlFactory = SQLFactory.createUpdateSQL(this, sat_sharematerial);
  57. sqlFactory.setUniqueid(sat_sharematerialid);
  58. sqlFactory.setSiteid(siteid);
  59. sqlFactory.setValue("sys_enterpriseid", sys_enterpriseid);
  60. sqlFactory.setValue("title", content.getStringValue("title"));
  61. sqlFactory.setValue("sat_sharematerial_classids", sat_sharematerial_classids);
  62. sqlFactory.setValue("type", content.getIntValue("type"));
  63. sqlFactory.setValue("sequence", content.getLongValue("sequence"));
  64. sqlFactory.setValue("isqrcode", content.getBooleanValue("isqrcode"));
  65. sqlFactory.setValue("qrcodecontent", content.getStringValue("qrcodecontent", true));
  66. sqlFactory.setValue("canshared_c", content.getBooleanValue("canshared_c"));
  67. sqlFactory.setValue("candownload", content.getBooleanValue("candownload"));
  68. sqlFactory.setValue("candownload_c", content.getBooleanValue("candownload_c"));
  69. sqlFactory.update();
  70. }
  71. return detail();
  72. }
  73. @API(title = "装备资源库详情", apiversion = R.ID20240407094602.v1.class)
  74. public String detail() throws YosException {
  75. Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  76. QuerySQL sqlFactory = SQLFactory.createQuerySQL(this, sat_sharematerial
  77. , "sat_sharematerialid", "type", "status", "sequence", "title", "canshared_c", "candownload_c", "candownload"
  78. , "sat_sharematerial_classids", "mailcount", "canshared", "downloadcount", "isqrcode", "qrcodecontent", "sharecount", "readcount"
  79. , "createby", "createdate", "checkby", "checkdate", "changeby", "changedate")
  80. .setTableAlias("t1");
  81. sqlFactory.setUniqueid(sat_sharematerialid);
  82. sqlFactory.setSiteid(siteid);
  83. Rows rows = sqlFactory.query();
  84. QuerySQL dataauth = SQLFactory.createQuerySQL(this, "sys_dataauth").setTableAlias("t1");
  85. dataauth.setWhere("siteid", siteid);
  86. dataauth.setWhere("ownertable", "sat_sharematerial");
  87. dataauth.setWhere("ownerid", sat_sharematerialid);
  88. Rows dataauthRows = dataauth.query();
  89. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_dataauths",
  90. "roleid");
  91. querySQL.addJoinTable(JOINTYPE.inner, "sys_role", "t2", "t1.roleid=t2.roleid and t1.siteid=t2.siteid",
  92. "rolename");
  93. querySQL.setTableAlias("t1");
  94. querySQL.setWhere("t1.siteid", siteid);
  95. querySQL.setWhere("t1.ownertable", "sat_sharematerial");
  96. querySQL.setWhere("t1.ownerid", sat_sharematerialid);
  97. Rows roleRows = querySQL.query();
  98. Row detailRow = new Row();
  99. if (rows.isNotEmpty()) {
  100. detailRow = rows.get(0);
  101. Rows attRows = getAttachmentUrl("sat_sharematerial", sat_sharematerialid);
  102. detailRow.put("attinfos", attRows);
  103. detailRow.putIfAbsent("checkdate", "");
  104. if (detailRow.getInteger("type") == 1) {
  105. detailRow.put("typestr", "图片");
  106. }
  107. if (detailRow.getInteger("type") == 2) {
  108. detailRow.put("typestr", "视频");
  109. }
  110. if (detailRow.getInteger("type") == 3) {
  111. detailRow.put("typestr", "图文");
  112. }
  113. detailRow.put("role", roleRows.toArrayList("roleid", new ArrayList<Long>()));
  114. detailRow.put("dataauth", dataauthRows);
  115. }
  116. return getSucReturnObject().setData(detailRow).toString();
  117. }
  118. @API(title = "装备资源库列表", apiversion = R.ID20240407094702.v1.class)
  119. public String list() throws YosException {
  120. /*
  121. 过滤条件设置
  122. */
  123. StringBuffer where = new StringBuffer(" 1=1 ");
  124. if (content.containsKey("where")) {
  125. JSONObject whereObject = content.getJSONObject("where");
  126. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  127. where.append(" and (");
  128. where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
  129. where.append(")");
  130. }
  131. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  132. where.append(" and (");
  133. where.append("t1.status ='").append(whereObject.getString("status")).append("' ");
  134. where.append(")");
  135. }
  136. if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
  137. where.append(" and (");
  138. where.append("t1.type ='").append(whereObject.getString("type")).append("' ");
  139. where.append(")");
  140. }
  141. if (whereObject.containsKey("begindate_create") && !"".equals(whereObject.getString("begindate_create"))) {
  142. where.append(" and (");
  143. where.append("t1.createdate >='").append(whereObject.getString("begindate_create")).append("' ");
  144. where.append(")");
  145. }
  146. if (whereObject.containsKey("enddate_create") && !"".equals(whereObject.getString("enddate_create"))) {
  147. where.append(" and (");
  148. where.append("t1.createdate <='").append(whereObject.getString("enddate_create")).append(" 23:59:59' ");
  149. where.append(")");
  150. }
  151. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  152. where.append(" and (");
  153. where.append("t1.checkdate >='").append(whereObject.getString("begindate")).append("' ");
  154. where.append(")");
  155. }
  156. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  157. where.append(" and (");
  158. where.append("t1.checkdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
  159. where.append(")");
  160. }
  161. if (whereObject.containsKey("sat_sharematerial_classids") && !"".equals(whereObject.getString("sat_sharematerial_classids"))) {
  162. JSONArray sat_courseware_classids = whereObject.getJSONArray("sat_sharematerial_classids");
  163. if (sat_courseware_classids.size() > 0) {
  164. where.append(" and (1=2");
  165. for (Object obj : sat_courseware_classids) {
  166. JSONArray array = (JSONArray) obj;
  167. for (Object obj2 : array) {
  168. where.append(" or (");
  169. where.append("JSON_CONTAINS(t1.sat_sharematerial_classids,'" + obj2 + "')");
  170. where.append(")");
  171. }
  172. }
  173. where.append(")");
  174. }
  175. }
  176. }
  177. QuerySQL sqlFactory = SQLFactory.createQuerySQL(this, sat_sharematerial,
  178. "sat_sharematerialid", "title", "type", "status", "mailcount", "readcount", "downloadcount", "createdate", "checkdate", "sat_sharematerial_classids")
  179. .setTableAlias("t1");
  180. sqlFactory.setSiteid(siteid);
  181. sqlFactory.setWhere("classid", 3);
  182. sqlFactory.setWhere(where.toString());
  183. sqlFactory.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
  184. System.err.println(sqlFactory.getSQL());
  185. Rows rows = sqlFactory.query();
  186. ArrayList<Long> ids = rows.toArrayList("sat_sharematerialid", new ArrayList<>());
  187. // 附件
  188. RowsMap RowsMap = getAttachmentUrl(sat_sharematerial, ids);
  189. for (Row row : rows) {
  190. Rows Rows = RowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows());
  191. row.put("attinfos", Rows);
  192. row.putIfAbsent("checkdate", "");
  193. if (row.getInteger("type") == 1) {
  194. row.put("typestr", "图片");
  195. }
  196. if (row.getInteger("type") == 2) {
  197. row.put("typestr", "视频");
  198. }
  199. if (row.getInteger("type") == 3) {
  200. row.put("typestr", "图文");
  201. }
  202. }
  203. return getSucReturnObject().setData(rows).toString();
  204. }
  205. @API(title = "图片新增或编辑", apiversion = R.ID20240407135802.v1.class)
  206. public String attachmentInsertOrUpdate() throws YosException {
  207. Long linksid = content.getLongValue("linksid");
  208. String ownertable = content.getStringValue("ownertable");
  209. Long ownerid = content.getLongValue("ownerid");
  210. if (linksid <= 0) {
  211. linksid = createTableID("sys_attachment_links");
  212. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_attachment_links");
  213. insertSQL.setSiteid(siteid);
  214. insertSQL.setUniqueid(linksid);
  215. insertSQL.setValue("usetype", ownertable);
  216. insertSQL.setValue("attachmentid", content.getLongValue("attachmentid"));
  217. insertSQL.setValue("jumpurl", content.getStringValue("jumpurl", true));
  218. insertSQL.setValue("sequence", content.getLongValue("sequence"));
  219. insertSQL.setValue("ownertable", ownertable);
  220. insertSQL.setValue("ownerid", ownerid);
  221. insertSQL.insert();
  222. }
  223. if (linksid > 0) {
  224. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_attachment_links");
  225. updateSQL.setSiteid(siteid);
  226. updateSQL.setUniqueid(linksid);
  227. updateSQL.setValue("jumpurl", content.getStringValue("jumpurl", true));
  228. updateSQL.setValue("sequence", content.getLongValue("sequence"));
  229. updateSQL.update();
  230. }
  231. String sql = "SELECT * from sys_attachment_links WHERE linksid=" + linksid + " and siteid='" + siteid + "'";
  232. Rows rows = dbConnect.runSqlQuery(sql);
  233. return getSucReturnObject().setData(rows.isNotEmpty() ? rows.get(0) : new Row()).toString();
  234. }
  235. @API(title = "图片删除", apiversion = R.ID20240407135902.v1.class)
  236. public String attachmentDelete() throws YosException {
  237. JSONArray linksids = content.getJSONArray("linksids");
  238. DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sys_attachment_links");
  239. deleteSQL.setSiteid(siteid);
  240. deleteSQL.setWhere("linksid", linksids);
  241. deleteSQL.delete();
  242. return getSucReturnObject().toString();
  243. }
  244. @API(title = "图片列表", apiversion = R.ID20240407140002.v1.class)
  245. public String attachmentList() throws YosException {
  246. StringBuffer where = new StringBuffer(" 1=1 ");
  247. if (content.containsKey("where")) {
  248. JSONObject whereObject = content.getJSONObject("where");
  249. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  250. where.append(" and (");
  251. where.append("t1.attachmentid like'%").append(whereObject.getString("condition")).append("%' ");
  252. where.append(")");
  253. }
  254. }
  255. String ownertable = content.getStringValue("ownertable");
  256. Long ownerid = content.getLongValue("ownerid");
  257. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_attachment_links").setTableAlias("t1");
  258. querySQL.setSiteid(siteid);
  259. querySQL.setWhere(where.toString());
  260. querySQL.setWhere("ownertable", ownertable);
  261. querySQL.setWhere("ownerid", ownerid);
  262. querySQL.setWhere("usetype", ownertable);
  263. querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
  264. Rows rows = querySQL.query();
  265. ArrayList<Long> ids = rows.toArrayList("attachmentid", new ArrayList<>());
  266. RowsMap attRowsMap = Attachment.get(this, ids).toRowsMap("attachmentid");
  267. for (Row row : rows) {
  268. row.put("attinfos", attRowsMap.getOrDefault(row.getString("attachmentid"), new Rows()));
  269. }
  270. return getSucReturnObject().setData(rows).toString();
  271. }
  272. }