123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- 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 restcontroller.webmanage.saletool.courseware.CoursewareHelper;
- 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);
- QuerySQL querySQL2 = SQLFactory.createQuerySQL(this, "sys_dataauths",
- "roleid");
- querySQL2.addJoinTable(JOINTYPE.inner, "sys_role", "t2", "t1.roleid=t2.roleid and t1.siteid=t2.siteid",
- "rolename");
- querySQL2.setTableAlias("t1");
- querySQL2.setWhere("t1.siteid", siteid);
- querySQL2.setWhere("t1.ownertable", "sys_ad");
- querySQL2.setWhere("t1.ownerid", sys_adid);
- Rows roleRows = querySQL2.query();
- detailRow.put("role", roleRows.toArrayList("roleid", new ArrayList<Long>()));
- QuerySQL dataauth = SQLFactory.createQuerySQL(this, "sys_dataauth").setTableAlias("t1");
- dataauth.setWhere("siteid", siteid);
- dataauth.setWhere("ownertable", "sys_ad");
- dataauth.setWhere("ownerid", sys_adid);
- Rows dataauthRows = dataauth.query();
- detailRow.put("dataauth", dataauthRows);
- 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();
- }
- }
|