ad.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package restcontroller.webmanage.adspace;
  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 restcontroller.webmanage.saletool.courseware.CoursewareHelper;
  11. import java.util.ArrayList;
  12. public class ad extends Controller {
  13. /**
  14. * 构造函数
  15. *
  16. * @param content
  17. */
  18. public ad(JSONObject content) throws YosException {
  19. super(content);
  20. }
  21. @API(title = "广告新增或更新", apiversion = R.ID20240328160002.v1.class)
  22. public String insertOrUpdate() throws YosException {
  23. Long sys_adid = content.getLongValue("sys_adid");
  24. Long sys_adspaceid = content.getLongValue("sys_adspaceid");
  25. if (sys_adid <= 0) {
  26. sys_adid = createTableID("sys_ad");
  27. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_ad");
  28. insertSQL.setSiteid(siteid);
  29. insertSQL.setUniqueid(sys_adid);
  30. insertSQL.setValue("sys_adspaceid", sys_adspaceid);
  31. insertSQL.setValue("sequence", content.getIntValue("sequence"));
  32. insertSQL.setValue("title", content.getStringValue("title"));
  33. insertSQL.setValue("hyperlink", content.getStringValue("hyperlink"));
  34. insertSQL.setValue("sequence", content.getIntValue("sequence"));
  35. insertSQL.setValue("isused", content.getBooleanValue("isused"));
  36. insertSQL.insert();
  37. content.put("sys_adid", sys_adid);
  38. }
  39. if (sys_adid > 0) {
  40. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_ad");
  41. updateSQL.setSiteid(siteid);
  42. updateSQL.setUniqueid(sys_adid);
  43. updateSQL.setValue("sequence", content.getIntValue("sequence"));
  44. updateSQL.setValue("title", content.getStringValue("title"));
  45. updateSQL.setValue("hyperlink", content.getStringValue("hyperlink"));
  46. updateSQL.setValue("sequence", content.getIntValue("sequence"));
  47. updateSQL.setValue("isused", content.getBooleanValue("isused"));
  48. updateSQL.update();
  49. }
  50. return detail();
  51. }
  52. @API(title = "广告详情", apiversion = R.ID20240328160102.v1.class)
  53. public String detail() throws YosException {
  54. Long sys_adid = content.getLongValue("sys_adid");
  55. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_ad").setTableAlias("t1");
  56. querySQL.setSiteid(siteid);
  57. querySQL.setWhere("sys_adid", sys_adid);
  58. Rows rows = querySQL.query();
  59. Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
  60. Rows attinfos = Attachment.get(this, "sys_ad", sys_adid);
  61. detailRow.put("attinfos", attinfos);
  62. QuerySQL querySQL2 = SQLFactory.createQuerySQL(this, "sys_dataauths",
  63. "roleid");
  64. querySQL2.addJoinTable(JOINTYPE.inner, "sys_role", "t2", "t1.roleid=t2.roleid and t1.siteid=t2.siteid",
  65. "rolename");
  66. querySQL2.setTableAlias("t1");
  67. querySQL2.setWhere("t1.siteid", siteid);
  68. querySQL2.setWhere("t1.ownertable", "sys_ad");
  69. querySQL2.setWhere("t1.ownerid", sys_adid);
  70. Rows roleRows = querySQL2.query();
  71. detailRow.put("role", roleRows.toArrayList("roleid", new ArrayList<Long>()));
  72. QuerySQL dataauth = SQLFactory.createQuerySQL(this, "sys_dataauth").setTableAlias("t1");
  73. dataauth.setWhere("siteid", siteid);
  74. dataauth.setWhere("ownertable", "sys_ad");
  75. dataauth.setWhere("ownerid", sys_adid);
  76. Rows dataauthRows = dataauth.query();
  77. detailRow.put("dataauth", dataauthRows);
  78. return getSucReturnObject().setData(detailRow).toString();
  79. }
  80. @API(title = "广告删除", apiversion = R.ID20240328160202.v1.class)
  81. public String delete() throws YosException {
  82. JSONArray sys_adids = content.getJSONArray("sys_adids");
  83. DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sys_ad");
  84. deleteSQL.setSiteid(siteid);
  85. deleteSQL.setWhere("sys_adid", sys_adids.toArray());
  86. deleteSQL.delete();
  87. return getSucReturnObject().toString();
  88. }
  89. @API(title = "广告上下架", apiversion = R.ID20240328160302.v1.class)
  90. public String isused() throws YosException {
  91. JSONArray sys_adids = content.getJSONArray("sys_adids");
  92. int isused = content.getIntValue("isused", 0);
  93. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_ad");
  94. updateSQL.setSiteid(siteid);
  95. updateSQL.setValue("isused", isused);
  96. updateSQL.setWhere("sys_adid", sys_adids.toArray());
  97. updateSQL.update();
  98. return getSucReturnObject().toString();
  99. }
  100. @API(title = "广告列表", apiversion = R.ID20240328160402.v1.class)
  101. public String list() throws YosException {
  102. StringBuffer where = new StringBuffer(" 1=1 ");
  103. if (content.containsKey("where")) {
  104. JSONObject whereObject = content.getJSONObject("where");
  105. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  106. where.append(" and (");
  107. where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
  108. where.append(")");
  109. }
  110. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  111. where.append(" and (");
  112. where.append("t1.createdate >='").append(whereObject.getString("begindate")).append("' ");
  113. where.append(")");
  114. }
  115. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  116. where.append(" and (");
  117. where.append("t1.createdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
  118. where.append(")");
  119. }
  120. }
  121. Long sys_adspaceid = content.getLongValue("sys_adspaceid");
  122. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_ad")
  123. .setTableAlias("t1");
  124. querySQL.setSiteid(siteid);
  125. querySQL.setWhere("sys_adspaceid", sys_adspaceid);
  126. querySQL.setWhere(where.toString());
  127. querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
  128. Rows rows = querySQL.query();
  129. RowsMap attinfosRowsMap = Attachment.get(this, "sys_ad", rows.toArrayList("sys_adid", new ArrayList<>()));
  130. for (Row row : rows) {
  131. row.put("attinfos", attinfosRowsMap.getOrDefault(row.getString("sys_adid"), new Rows()));
  132. if (row.getBoolean("isused")) {
  133. row.put("status", "上架");
  134. } else {
  135. row.put("status", "下架");
  136. }
  137. }
  138. return getSucReturnObject().setData(rows).toString();
  139. }
  140. }