123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- package restcontroller.webmanage.saletool.sharematerial;
- import beans.attachment.Attachment;
- import beans.time.Time;
- 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 LongPicText extends Controller {
- /**
- * 构造函数
- *
- * @param content
- */
- public LongPicText(JSONObject content) throws YosException {
- super(content);
- }
- @API(title = "长图文新增或更新", apiversion = R.ID20240329131402.v1.class)
- public String insertOrUpdate() throws YosException {
- Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
- Rows rows = dbConnect.runSqlQuery("SELECT * from sat_sharematerial WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
- JSONObject jsonObject = new JSONObject();
- if (rows.isNotEmpty()) {
- jsonObject = rows.get(0).getJSONObject("sharepagecontrol");
- }
- jsonObject.put("style_bottom", content.getStringValue("style_bottom"));
- jsonObject.put("style_signup", content.getStringValue("style_signup"));
- if (sat_sharematerialid <= 0) {
- jsonObject.put("pics", new JSONArray());
- sat_sharematerialid = createTableID("sat_sharematerial");
- InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sat_sharematerial");
- insertSQL.setSiteid(siteid);
- insertSQL.setUniqueid(sat_sharematerialid);
- insertSQL.setValue("classid", "2");
- insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);
- insertSQL.setValue("type", content.getIntValue("type"));
- insertSQL.setValue("title", content.getStringValue("title"));
- insertSQL.setValue("sharepagecontrol", jsonObject);
- insertSQL.setValue("content", content.getStringValue("contentstr"));
- insertSQL.insert();
- content.put("sat_sharematerialid", sat_sharematerialid);
- }
- if (sat_sharematerialid > 0) {
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_sharematerial");
- updateSQL.setSiteid(siteid);
- updateSQL.setUniqueid(sat_sharematerialid);
- updateSQL.setValue("sys_enterpriseid", sys_enterpriseid);
- updateSQL.setValue("type", content.getIntValue("type"));
- updateSQL.setValue("title", content.getStringValue("title"));
- updateSQL.setValue("sharepagecontrol", jsonObject);
- updateSQL.setValue("content", content.getStringValue("contentstr"));
- updateSQL.update();
- }
- return detail();
- }
- @API(title = "长图文详情", apiversion = R.ID20240329131502.v1.class)
- public String detail() throws YosException {
- Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
- QuerySQL querySQ = SQLFactory.createQuerySQL(this, "sat_sharematerial")
- .setTableAlias("t1");
- querySQ.setSiteid(siteid);
- querySQ.setWhere("sat_sharematerialid", sat_sharematerialid);
- Rows rows = querySQ.query();
- Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
- //1:图片;2:视频;3:图文
- if (detailRow.getInteger("type") == 1) {
- detailRow.put("typestr", "图片");
- }
- if (detailRow.getInteger("type") == 2) {
- detailRow.put("typestr", "视频");
- }
- if (detailRow.getInteger("type") == 3) {
- detailRow.put("typestr", "图文");
- }
- Rows attRows = getAttachmentUrl("sat_sharematerial", sat_sharematerialid);
- detailRow.put("attinfos", attRows);
- detailRow.put("shareurl", "/pages/product/ctw/share?id=" + sat_sharematerialid);
- detailRow.put("noshareurl", "/pages/product/ctw/noshare?id=" + sat_sharematerialid);
- return getSucReturnObject().setData(detailRow).toString();
- }
- @API(title = "长图文上下架", apiversion = R.ID20240329131702.v1.class)
- public String updateStatus() throws YosException {
- JSONArray sat_sharematerialids = content.getJSONArray("sat_sharematerialids");
- int status = content.getIntValue("status");
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_sharematerial");
- updateSQL.setSiteid(siteid);
- updateSQL.setWhere("sat_sharematerialid", sat_sharematerialids);
- updateSQL.setValue("status", status == 0 ? "新建" : "发布");
- updateSQL.setValue("checkdate", status == 0 ? "null" : Time.getDateTime_Str());
- updateSQL.setValue("checkby", status == 0 ? "null" : username);
- updateSQL.update();
- return getSucReturnObject().toString();
- }
- @API(title = "长图文列表", apiversion = R.ID20240329131802.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("status") && !"".equals(whereObject.getString("status"))) {
- where.append(" and (");
- where.append("t1.status ='").append(whereObject.getString("status")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
- where.append(" and (");
- where.append("t1.type ='").append(whereObject.getString("type")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("begindate_create") && !"".equals(whereObject.getString("begindate_create"))) {
- where.append(" and (");
- where.append("t1.createdate >='").append(whereObject.getString("begindate_create")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("enddate_create") && !"".equals(whereObject.getString("enddate_create"))) {
- where.append(" and (");
- where.append("t1.createdate <='").append(whereObject.getString("enddate_create")).append(" 23:59:59' ");
- where.append(")");
- }
- if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
- where.append(" and (");
- where.append("t1.checkdate >='").append(whereObject.getString("begindate")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
- where.append(" and (");
- where.append("t1.checkdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
- where.append(")");
- }
- }
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_sharematerial"
- , "sat_sharematerialid", "title", "sharepagecontrol", "content", "notes", "type", "status", "createdate", "checkdate")
- .setTableAlias("t1");
- querySQL.setWhere("classid", 2);
- querySQL.setSiteid(siteid);
- querySQL.setWhere(where.toString());
- querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
- Rows rows = querySQL.query();
- for (Row row : rows) {
- row.putIfAbsent("checkdate", "");
- if (row.getInteger("type") == 1) {
- row.put("typestr", "图片");
- }
- if (row.getInteger("type") == 2) {
- row.put("typestr", "视频");
- }
- if (row.getInteger("type") == 3) {
- row.put("typestr", "图文");
- }
- Rows attRows = getAttachmentUrl("sat_sharematerial", row.getLong("sat_sharematerialid"));
- row.put("attinfos", attRows);
- row.put("shareurl", "/pages/product/ctw/share?id=" + row.getLong("sat_sharematerialid"));
- row.put("noshareurl", "/pages/product/ctw/noshare?id=" + row.getLong("sat_sharematerialid"));
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "小程序长图文详情", apiversion = R.ID20240408131902.v1.class)
- public String miniAppDetail() throws YosException {
- String ownertable = "sat_sharematerial";
- Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
- QuerySQL querySQ = SQLFactory.createQuerySQL(this, "sat_sharematerial"
- ,"sat_sharematerialid","sharepagecontrol","type","title")
- .setTableAlias("t1");
- querySQ.setSiteid(siteid);
- querySQ.setWhere("sat_sharematerialid", sat_sharematerialid);
- Rows rows = querySQ.query();
- Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
- Rows attRows = getAttachmentUrl("sat_sharematerial", sat_sharematerialid);
- detailRow.put("attinfos", attRows);
- QuerySQL attachmentQuery = SQLFactory.createQuerySQL(this, "sys_attachment_links").setTableAlias("t1");
- attachmentQuery.setSiteid(siteid);
- attachmentQuery.setWhere("ownertable", ownertable);
- attachmentQuery.setWhere("ownerid", sat_sharematerialid);
- attachmentQuery.setWhere("usetype", ownertable);
- Rows attachmentRows = attachmentQuery.query();
- ArrayList<Long> ids = attachmentRows.toArrayList("attachmentid", new ArrayList<>());
- RowsMap attRowsMap = Attachment.get(this, ids).toRowsMap("attachmentid");
- for (Row row : attachmentRows) {
- Rows attPicRows = new Rows();
- Rows tempAttRows = attRowsMap.getOrDefault(row.getString("attachmentid"), new Rows());
- for (Row tempAttRow : tempAttRows) {
- if (tempAttRow.getString("ownertable").equals(ownertable)) {
- attPicRows.add(tempAttRow);
- }
- }
- row.put("attinfos", attPicRows);
- }
- detailRow.put("attinfos_pic", attachmentRows);
- return getSucReturnObject().setData(detailRow).toString();
- }
- // @API(title = "长图文图片列表", apiversion = R.ID20240329145502.v1.class)
- // public String piclist() throws YosException {
- //
- // Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
- // Rows rows = dbConnect.runSqlQuery("SELECT * from sat_sharematerial WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
- // JSONObject jsonObject = new JSONObject();
- // JSONArray jsonArray = new JSONArray();
- // if (rows.isNotEmpty()) {
- // jsonObject = rows.get(0).getJSONObject("sharepagecontrol");
- // if (jsonObject.containsKey("pics")) {
- // jsonArray = jsonObject.getJSONArray("pics");
- // } else {
- // jsonArray = new JSONArray();
- // }
- // }
- //
- // ArrayList<Long> ids = new ArrayList<>();
- // for (Object o : jsonArray) {
- // JSONObject jsonObject1 = (JSONObject) o;
- // ids.add(jsonObject1.getLongValue("attachmentid"));
- // }
- //
- // RowsMap attRowsMap = Attachment.get(this, ids).toRowsMap("attachmentid");
- // for (Object object : jsonArray) {
- // JSONObject jsonObject1 = (JSONObject) object;
- // jsonObject1.put("attinfos", attRowsMap.getOrDefault(jsonObject1.getString("attachmentid"), new Rows()));
- // }
- //
- //
- // return getSucReturnObject().setData(jsonArray).toString();
- // }
- //
- //
- // @API(title = "长图文绑定图片信息", apiversion = R.ID20240329131902.v1.class)
- // public String updatePicInfo() throws YosException {
- //
- // Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
- // Long attachmentid = content.getLongValue("attachmentid");
- //
- // Rows rows = dbConnect.runSqlQuery("SELECT * from sat_sharematerial WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
- // JSONObject jsonObject = new JSONObject();
- // JSONArray jsonArray = new JSONArray();
- // if (rows.isNotEmpty()) {
- // jsonObject = rows.get(0).getJSONObject("sharepagecontrol");
- // if (jsonObject.containsKey("pics")) {
- // jsonArray = jsonObject.getJSONArray("pics");
- // } else {
- // jsonArray = new JSONArray();
- // }
- // }
- // JSONArray newjsonArray = getTempJSONArray(jsonArray, String.valueOf(attachmentid));
- //
- // JSONObject object = new JSONObject();
- // object.put("attachmentid", attachmentid);
- // object.put("url", content.getStringValue("url"));
- // object.put("sequence", content.getIntValue("sequence"));
- // newjsonArray.add(object);
- // jsonObject.put("pics", newjsonArray);
- //
- // UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_sharematerial");
- // updateSQL.setSiteid(siteid);
- // updateSQL.setUniqueid(sat_sharematerialid);
- //
- // updateSQL.setValue("sharepagecontrol", jsonObject);
- // System.err.println(updateSQL.getSQL());
- // updateSQL.update();
- //
- //
- // object.put("attinfos", Attachment.get(this, attachmentid));
- //
- //
- // return getSucReturnObject().setData(object).toString();
- // }
- //
- // @API(title = "长图文解绑图片信息", apiversion = R.ID20240329132002.v1.class)
- // public String deletePicInfo() throws YosException {
- //
- // Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
- // Long attachmentid = content.getLongValue("attachmentid");
- //
- // Rows rows = dbConnect.runSqlQuery("SELECT * from sat_sharematerial WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
- // JSONObject jsonObject = new JSONObject();
- // JSONArray jsonArray = new JSONArray();
- // if (rows.isNotEmpty()) {
- // jsonObject = rows.get(0).getJSONObject("sharepagecontrol");
- // if (jsonObject.containsKey("pics")) {
- // jsonArray = jsonObject.getJSONArray("pics");
- // } else {
- // jsonArray = new JSONArray();
- // }
- // }
- // jsonObject.put("pics", getTempJSONArray(jsonArray, String.valueOf(attachmentid)));
- //
- //
- // UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_sharematerial");
- // updateSQL.setSiteid(siteid);
- // updateSQL.setUniqueid(sat_sharematerialid);
- //
- // updateSQL.setValue("sharepagecontrol", jsonObject);
- // System.err.println(updateSQL.getSQL());
- // updateSQL.update();
- //
- // return detail();
- // }
- // public JSONArray getTempJSONArray(JSONArray jsonArray, String attachmentid) throws YosException {
- // JSONArray temp = new JSONArray();
- // for (Object object : jsonArray) {
- // JSONObject temp_object = (JSONObject) object;
- // if (!temp_object.getString("attachmentid").equals(attachmentid)) {
- // temp.add(object);
- // }
- // }
- //
- // return temp;
- // }
- }
|