EquipmentResourceLibrary.java 18 KB

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