sharematerialClass.java 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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.annotation.CACHEING;
  9. import common.annotation.CACHEING_CLEAN;
  10. import common.annotation.cm;
  11. import common.data.*;
  12. import restcontroller.R;
  13. import restcontroller.webmanage.saletool.courseware.courseware;
  14. import restcontroller.webmanage.saletool.courseware.coursewareclass;
  15. import java.util.ArrayList;
  16. @API(title = "推广素材管理-分类")
  17. public class sharematerialClass extends Controller {
  18. public sharematerialClass(JSONObject content) throws YosException {
  19. super(content);
  20. }
  21. @API(title = "新增", apiversion = R.ID20240403132302.v1.class)
  22. public String insertOrUpdate() throws YosException {
  23. Long sat_sharematerial_classid = content.getLongValue("sat_sharematerial_classid");
  24. Long parentid = content.getLongValue("parentid");
  25. long level = 1;
  26. if (parentid > 0) {
  27. //查询level
  28. String sqlLevel = "SELECT IFNULL(level,0) level FROM sat_sharematerial_class WHERE sat_sharematerial_classid = '" + parentid + "'";
  29. Rows rows = dbConnect.runSqlQuery(sqlLevel);
  30. if (rows.isNotEmpty()) {
  31. level = rows.get(0).getLong("level") + 1;
  32. }
  33. }
  34. if (sat_sharematerial_classid <= 0) {
  35. sat_sharematerial_classid = createTableID("sat_sharematerial_class");
  36. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sat_sharematerial_class");
  37. insertSQL.setUniqueid(sat_sharematerial_classid);
  38. insertSQL.setSiteid(siteid);
  39. insertSQL.setValue("classname", content.getStringValue("classname"));
  40. insertSQL.setValue("isenable", content.getBooleanValue("isenable"));
  41. insertSQL.setValue("sequence", content.getLongValue("sequence"));
  42. insertSQL.setValue("remarks", content.getStringValue("remarks"));
  43. insertSQL.setValue("level", level);
  44. insertSQL.setValue("parentid", parentid);
  45. insertSQL.insert();
  46. content.put("sat_sharematerial_classid", sat_sharematerial_classid);
  47. }else{
  48. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_sharematerial_class");
  49. updateSQL.setUniqueid(sat_sharematerial_classid);
  50. updateSQL.setSiteid(siteid);
  51. updateSQL.setValue("classname", content.getStringValue("classname"));
  52. updateSQL.setValue("isenable", content.getBooleanValue("isenable"));
  53. updateSQL.setValue("sequence", content.getLongValue("sequence"));
  54. updateSQL.setValue("remarks", content.getStringValue("remarks"));
  55. updateSQL.setValue("level", level);
  56. updateSQL.update();
  57. }
  58. Rows rows = dbConnect.runSqlQuery("SELECT * from sat_sharematerial_class WHERE sat_sharematerial_classid=" + sat_sharematerial_classid + " and siteid='" + siteid + "'");
  59. return getSucReturnObject().setData(rows.get(0)).toString();
  60. }
  61. @API(title = "删除", apiversion = R.ID20221102143502.v1.class)
  62. public String delete() throws YosException {
  63. JSONArray sat_sharematerial_classids = content.getJSONArray("sat_sharematerial_classids");
  64. StringBuffer where = new StringBuffer(" 1=1 ");
  65. if (sat_sharematerial_classids.size() > 0) {
  66. where.append(" and (1=2");
  67. for (Object obj : sat_sharematerial_classids) {
  68. where.append(" or (");
  69. where.append("JSON_CONTAINS(sat_sharematerial_classids,'" + obj + "')");
  70. where.append(")");
  71. }
  72. where.append(")");
  73. }
  74. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_sharematerial");
  75. querySQL.setSiteid(siteid);
  76. querySQL.setWhere(where.toString());
  77. Rows rows = querySQL.query();
  78. if (rows.isNotEmpty()) {
  79. return getErrReturnObject().setErrMsg("当前分类已使用,无法删除").toString();
  80. }
  81. querySQL = SQLFactory.createQuerySQL(this, "sat_sharematerial_class");
  82. querySQL.setSiteid(siteid);
  83. querySQL.setWhere("parentid", sat_sharematerial_classids);
  84. rows = querySQL.query();
  85. if (rows.isNotEmpty()) {
  86. return getErrReturnObject().setErrMsg("当前分类存在下级分类,无法删除").toString();
  87. }
  88. DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sat_sharematerial_class");
  89. deleteSQL.setSiteid(siteid);
  90. deleteSQL.setWhere("sat_sharematerial_classid", sat_sharematerial_classids);
  91. deleteSQL.delete();
  92. return getSucReturnObject().toString();
  93. }
  94. @API(title = "推广素材分类列表", apiversion = R.ID20221102143202.v1.class)
  95. public String select() throws YosException {
  96. /*
  97. 过滤条件设置
  98. */
  99. StringBuffer where = new StringBuffer(" 1=1 ");
  100. if (content.containsKey("where")) {
  101. JSONObject whereObject = content.getJSONObject("where");
  102. if (whereObject.containsKey("isenable") && !"".equals(whereObject.getString("isenable"))) {
  103. where.append(" and (");
  104. where.append("isenable="+whereObject.getBoolean("isenable"));
  105. where.append(")");
  106. }
  107. }
  108. Long parentid = content.getLong("parentid");
  109. Rows rows = getClassRows(parentid, where);
  110. for (Row row : rows) {
  111. Rows attRows = Attachment.get(this, "sat_sharematerial_class", row.getLong("sat_sharematerial_classid"));
  112. row.put("attinfos", attRows);
  113. Rows secondRows = getClassRows(row.getLong("sat_sharematerial_classid"), where);
  114. row.put("children", secondRows);
  115. for (Row secondRow : secondRows) {
  116. Rows threeRows = getClassRows(secondRow.getLong("sat_sharematerial_classid"), where);
  117. secondRow.put("children", threeRows);
  118. }
  119. }
  120. return getSucReturnObject().setData(rows).toString();
  121. }
  122. public Rows getClassRows(Long parentid, StringBuffer where) throws YosException {
  123. SQLFactory sqlFactory = new SQLFactory(this, "素材分类-查询");
  124. sqlFactory.addParameter("parentid", parentid);
  125. sqlFactory.addParameter("siteid", siteid);
  126. sqlFactory.addParameter_SQL("where", where);
  127. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  128. return rows;
  129. }
  130. @API(title = "启用", apiversion = R.ID20240403153602.v1.class)
  131. public String isenadle() throws YosException {
  132. JSONArray sat_sharematerial_classids = content.getJSONArray("sat_sharematerial_classids");
  133. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_sharematerial_class");
  134. updateSQL.setSiteid(siteid);
  135. updateSQL.setValue("isenable", content.getBooleanValue("isenable"));
  136. updateSQL.setWhere("sat_sharematerial_classid ", sat_sharematerial_classids.toArray());
  137. updateSQL.update();
  138. return getSucReturnObject().toString();
  139. }
  140. }