EquipmentResourceLibrary.java 18 KB

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