|
@@ -0,0 +1,157 @@
|
|
|
+package restcontroller.webmanage.adspace;
|
|
|
+
|
|
|
+import beans.attachment.Attachment;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import common.Controller;
|
|
|
+import common.YosException;
|
|
|
+import common.annotation.API;
|
|
|
+import common.data.*;
|
|
|
+import restcontroller.R;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
+public class ad extends Controller {
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ */
|
|
|
+ public ad(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "广告新增或更新", apiversion = R.ID20240328160002.v1.class)
|
|
|
+ public String insertOrUpdate() throws YosException {
|
|
|
+
|
|
|
+ Long sys_adid = content.getLongValue("sys_adid");
|
|
|
+ Long sys_adspaceid = content.getLongValue("sys_adspaceid");
|
|
|
+
|
|
|
+ if (sys_adid <= 0) {
|
|
|
+ sys_adid = createTableID("sys_ad");
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_ad");
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setUniqueid(sys_adid);
|
|
|
+ insertSQL.setValue("sys_adspaceid", sys_adspaceid);
|
|
|
+ insertSQL.setValue("sequence", content.getIntValue("sequence"));
|
|
|
+ insertSQL.setValue("title", content.getStringValue("title"));
|
|
|
+ insertSQL.setValue("hyperlink", content.getStringValue("hyperlink"));
|
|
|
+ insertSQL.setValue("sequence", content.getIntValue("sequence"));
|
|
|
+ insertSQL.setValue("isused", content.getBooleanValue("isused"));
|
|
|
+ insertSQL.insert();
|
|
|
+ content.put("sys_adid", sys_adid);
|
|
|
+ }
|
|
|
+ if (sys_adid > 0) {
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_ad");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setUniqueid(sys_adid);
|
|
|
+ updateSQL.setValue("sequence", content.getIntValue("sequence"));
|
|
|
+ updateSQL.setValue("title", content.getStringValue("title"));
|
|
|
+ updateSQL.setValue("hyperlink", content.getStringValue("hyperlink"));
|
|
|
+ updateSQL.setValue("sequence", content.getIntValue("sequence"));
|
|
|
+ updateSQL.setValue("isused", content.getBooleanValue("isused"));
|
|
|
+ updateSQL.update();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return detail();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "广告详情", apiversion = R.ID20240328160102.v1.class)
|
|
|
+ public String detail() throws YosException {
|
|
|
+
|
|
|
+ Long sys_adid = content.getLongValue("sys_adid");
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_ad").setTableAlias("t1");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere("sys_adid", sys_adid);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
|
|
|
+
|
|
|
+ Rows attinfos = Attachment.get(this, "sys_ad", sys_adid);
|
|
|
+ detailRow.put("attinfos", attinfos);
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(detailRow).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "广告删除", apiversion = R.ID20240328160202.v1.class)
|
|
|
+ public String delete() throws YosException {
|
|
|
+
|
|
|
+ JSONArray sys_adids = content.getJSONArray("sys_adids");
|
|
|
+
|
|
|
+ DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sys_ad");
|
|
|
+ deleteSQL.setSiteid(siteid);
|
|
|
+ deleteSQL.setWhere("sys_adid", sys_adids.toArray());
|
|
|
+ deleteSQL.delete();
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "广告上下架", apiversion = R.ID20240328160302.v1.class)
|
|
|
+ public String isused() throws YosException {
|
|
|
+ JSONArray sys_adids = content.getJSONArray("sys_adids");
|
|
|
+ int isused = content.getIntValue("isused", 0);
|
|
|
+
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_ad");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setValue("isused", isused);
|
|
|
+ updateSQL.setWhere("sys_adid", sys_adids.toArray());
|
|
|
+ updateSQL.update();
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "广告列表", apiversion = R.ID20240328160402.v1.class)
|
|
|
+ public String list() throws YosException {
|
|
|
+
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
+ if (content.containsKey("where")) {
|
|
|
+ JSONObject whereObject = content.getJSONObject("where");
|
|
|
+ if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t1.createdate >='").append(whereObject.getString("begindate")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t1.createdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Long sys_adspaceid = content.getLongValue("sys_adspaceid");
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_ad")
|
|
|
+ .setTableAlias("t1");
|
|
|
+
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere("sys_adspaceid", sys_adspaceid);
|
|
|
+ querySQL.setWhere(where.toString());
|
|
|
+ querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ RowsMap attinfosRowsMap = Attachment.get(this, "sys_ad", rows.toArrayList("sys_adid", new ArrayList<>()));
|
|
|
+
|
|
|
+ for (Row row : rows) {
|
|
|
+ row.put("attinfos", attinfosRowsMap.getOrDefault(row.getString("sys_adid"), new Rows()));
|
|
|
+ if (row.getBoolean("isused")) {
|
|
|
+ row.put("status", "上架");
|
|
|
+ } else {
|
|
|
+ row.put("status", "下架");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|