LongPicText.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. package restcontroller.webmanage.saletool.sharematerial;
  2. import beans.attachment.Attachment;
  3. import beans.time.Time;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import common.Controller;
  7. import common.YosException;
  8. import common.annotation.API;
  9. import common.data.*;
  10. import restcontroller.R;
  11. import java.util.ArrayList;
  12. public class LongPicText extends Controller {
  13. /**
  14. * 构造函数
  15. *
  16. * @param content
  17. */
  18. public LongPicText(JSONObject content) throws YosException {
  19. super(content);
  20. }
  21. @API(title = "长图文新增或更新", apiversion = R.ID20240329131402.v1.class)
  22. public String insertOrUpdate() throws YosException {
  23. Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  24. Rows rows = dbConnect.runSqlQuery("SELECT * from sat_sharematerial WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
  25. JSONObject jsonObject = new JSONObject();
  26. if (rows.isNotEmpty()) {
  27. jsonObject = rows.get(0).getJSONObject("sharepagecontrol");
  28. }
  29. jsonObject.put("style_bottom", content.getStringValue("style_bottom"));
  30. jsonObject.put("style_signup", content.getStringValue("style_signup"));
  31. if (sat_sharematerialid <= 0) {
  32. jsonObject.put("pics", new JSONArray());
  33. sat_sharematerialid = createTableID("sat_sharematerial");
  34. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sat_sharematerial");
  35. insertSQL.setSiteid(siteid);
  36. insertSQL.setUniqueid(sat_sharematerialid);
  37. insertSQL.setValue("classid", "2");
  38. insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);
  39. insertSQL.setValue("type", content.getIntValue("type"));
  40. insertSQL.setValue("title", content.getStringValue("title"));
  41. insertSQL.setValue("sharepagecontrol", jsonObject);
  42. insertSQL.setValue("content", content.getStringValue("contentstr"));
  43. insertSQL.insert();
  44. content.put("sat_sharematerialid", sat_sharematerialid);
  45. }else {
  46. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_sharematerial");
  47. updateSQL.setSiteid(siteid);
  48. updateSQL.setUniqueid(sat_sharematerialid);
  49. updateSQL.setValue("sys_enterpriseid", sys_enterpriseid);
  50. updateSQL.setValue("type", content.getIntValue("type"));
  51. updateSQL.setValue("title", content.getStringValue("title"));
  52. updateSQL.setValue("sharepagecontrol", jsonObject);
  53. updateSQL.setValue("content", content.getStringValue("contentstr"));
  54. updateSQL.update();
  55. }
  56. return detail();
  57. }
  58. @API(title = "长图文详情", apiversion = R.ID20240329131502.v1.class)
  59. public String detail() throws YosException {
  60. Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  61. QuerySQL querySQ = SQLFactory.createQuerySQL(this, "sat_sharematerial")
  62. .setTableAlias("t1");
  63. querySQ.setSiteid(siteid);
  64. querySQ.setWhere("sat_sharematerialid", sat_sharematerialid);
  65. Rows rows = querySQ.query();
  66. Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
  67. //1:图片;2:视频;3:图文
  68. if (detailRow.getInteger("type") == 1) {
  69. detailRow.put("typestr", "图片");
  70. }
  71. if (detailRow.getInteger("type") == 2) {
  72. detailRow.put("typestr", "视频");
  73. }
  74. if (detailRow.getInteger("type") == 3) {
  75. detailRow.put("typestr", "图文");
  76. }
  77. Rows attRows = getAttachmentUrl("sat_sharematerial", sat_sharematerialid);
  78. detailRow.put("attinfos", attRows);
  79. detailRow.put("shareurl", "/pages/product/ctw/share?id=" + sat_sharematerialid);
  80. detailRow.put("noshareurl", "/pages/product/ctw/noshare?id=" + sat_sharematerialid);
  81. return getSucReturnObject().setData(detailRow).toString();
  82. }
  83. @API(title = "长图文上下架", apiversion = R.ID20240329131702.v1.class)
  84. public String updateStatus() throws YosException {
  85. JSONArray sat_sharematerialids = content.getJSONArray("sat_sharematerialids");
  86. int status = content.getIntValue("status");
  87. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_sharematerial");
  88. updateSQL.setSiteid(siteid);
  89. updateSQL.setWhere("sat_sharematerialid", sat_sharematerialids);
  90. updateSQL.setValue("status", status == 0 ? "新建" : "发布");
  91. updateSQL.setValue("checkdate", status == 0 ? "null" : Time.getDateTime_Str());
  92. updateSQL.setValue("checkby", status == 0 ? "null" : username);
  93. updateSQL.update();
  94. return getSucReturnObject().toString();
  95. }
  96. @API(title = "长图文列表", apiversion = R.ID20240329131802.v1.class)
  97. public String list() throws YosException {
  98. StringBuffer where = new StringBuffer(" 1=1 ");
  99. if (content.containsKey("where")) {
  100. JSONObject whereObject = content.getJSONObject("where");
  101. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  102. where.append(" and (");
  103. where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
  104. where.append(")");
  105. }
  106. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  107. where.append(" and (");
  108. where.append("t1.status ='").append(whereObject.getString("status")).append("' ");
  109. where.append(")");
  110. }
  111. if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
  112. where.append(" and (");
  113. where.append("t1.type ='").append(whereObject.getString("type")).append("' ");
  114. where.append(")");
  115. }
  116. if (whereObject.containsKey("begindate_create") && !"".equals(whereObject.getString("begindate_create"))) {
  117. where.append(" and (");
  118. where.append("t1.createdate >='").append(whereObject.getString("begindate_create")).append("' ");
  119. where.append(")");
  120. }
  121. if (whereObject.containsKey("enddate_create") && !"".equals(whereObject.getString("enddate_create"))) {
  122. where.append(" and (");
  123. where.append("t1.createdate <='").append(whereObject.getString("enddate_create")).append(" 23:59:59' ");
  124. where.append(")");
  125. }
  126. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  127. where.append(" and (");
  128. where.append("t1.checkdate >='").append(whereObject.getString("begindate")).append("' ");
  129. where.append(")");
  130. }
  131. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  132. where.append(" and (");
  133. where.append("t1.checkdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
  134. where.append(")");
  135. }
  136. }
  137. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_sharematerial"
  138. , "sat_sharematerialid", "title", "sharepagecontrol", "content", "notes", "type", "status", "createdate", "checkdate")
  139. .setTableAlias("t1");
  140. querySQL.setWhere("classid", 2);
  141. querySQL.setSiteid(siteid);
  142. querySQL.setWhere(where.toString());
  143. querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
  144. Rows rows = querySQL.query();
  145. for (Row row : rows) {
  146. row.putIfAbsent("checkdate", "");
  147. if (row.getInteger("type") == 1) {
  148. row.put("typestr", "图片");
  149. }
  150. if (row.getInteger("type") == 2) {
  151. row.put("typestr", "视频");
  152. }
  153. if (row.getInteger("type") == 3) {
  154. row.put("typestr", "图文");
  155. }
  156. Rows attRows = getAttachmentUrl("sat_sharematerial", row.getLong("sat_sharematerialid"));
  157. row.put("attinfos", attRows);
  158. row.put("shareurl", "/pages/product/ctw/share?id=" + row.getLong("sat_sharematerialid"));
  159. row.put("noshareurl", "/pages/product/ctw/noshare?id=" + row.getLong("sat_sharematerialid"));
  160. }
  161. return getSucReturnObject().setData(rows).toString();
  162. }
  163. @API(title = "小程序长图文详情", apiversion = R.ID20240408131902.v1.class,accesstoken = false)
  164. public String miniAppDetail() throws YosException {
  165. String ownertable = "sat_sharematerial";
  166. Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  167. QuerySQL querySQ = SQLFactory.createQuerySQL(this, "sat_sharematerial"
  168. ,"sat_sharematerialid","sharepagecontrol","type","title","siteid")
  169. .setTableAlias("t1");
  170. querySQ.setWhere("sat_sharematerialid", sat_sharematerialid);
  171. Rows rows = querySQ.query();
  172. Row detailRow = rows.isNotEmpty() ? rows.get(0) : new Row();
  173. Rows attRows = getAttachmentUrl("sat_sharematerial", sat_sharematerialid);
  174. detailRow.put("attinfos", attRows);
  175. QuerySQL attachmentQuery = SQLFactory.createQuerySQL(this, "sys_attachment_links").setTableAlias("t1");
  176. attachmentQuery.setSiteid(detailRow.getString("siteid"));
  177. attachmentQuery.setWhere("ownertable", ownertable);
  178. attachmentQuery.setWhere("ownerid", sat_sharematerialid);
  179. attachmentQuery.setWhere("usetype", ownertable);
  180. attachmentQuery.setOrderBy("t1.sequence");
  181. Rows attachmentRows = attachmentQuery.query();
  182. ArrayList<Long> ids = attachmentRows.toArrayList("attachmentid", new ArrayList<>());
  183. RowsMap attRowsMap = Attachment.get(this, ids).toRowsMap("attachmentid");
  184. for (Row row : attachmentRows) {
  185. Rows attPicRows = new Rows();
  186. Rows tempAttRows = attRowsMap.getOrDefault(row.getString("attachmentid"), new Rows());
  187. for (Row tempAttRow : tempAttRows) {
  188. if (tempAttRow.getString("usetype").equals(ownertable)) {
  189. attPicRows.add(tempAttRow);
  190. }
  191. }
  192. row.put("attinfos", attPicRows);
  193. }
  194. detailRow.put("attinfos_pic", attachmentRows);
  195. return getSucReturnObject().setData(detailRow).toString();
  196. }
  197. // @API(title = "长图文图片列表", apiversion = R.ID20240329145502.v1.class)
  198. // public String piclist() throws YosException {
  199. //
  200. // Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  201. // Rows rows = dbConnect.runSqlQuery("SELECT * from sat_sharematerial WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
  202. // JSONObject jsonObject = new JSONObject();
  203. // JSONArray jsonArray = new JSONArray();
  204. // if (rows.isNotEmpty()) {
  205. // jsonObject = rows.get(0).getJSONObject("sharepagecontrol");
  206. // if (jsonObject.containsKey("pics")) {
  207. // jsonArray = jsonObject.getJSONArray("pics");
  208. // } else {
  209. // jsonArray = new JSONArray();
  210. // }
  211. // }
  212. //
  213. // ArrayList<Long> ids = new ArrayList<>();
  214. // for (Object o : jsonArray) {
  215. // JSONObject jsonObject1 = (JSONObject) o;
  216. // ids.add(jsonObject1.getLongValue("attachmentid"));
  217. // }
  218. //
  219. // RowsMap attRowsMap = Attachment.get(this, ids).toRowsMap("attachmentid");
  220. // for (Object object : jsonArray) {
  221. // JSONObject jsonObject1 = (JSONObject) object;
  222. // jsonObject1.put("attinfos", attRowsMap.getOrDefault(jsonObject1.getString("attachmentid"), new Rows()));
  223. // }
  224. //
  225. //
  226. // return getSucReturnObject().setData(jsonArray).toString();
  227. // }
  228. //
  229. //
  230. // @API(title = "长图文绑定图片信息", apiversion = R.ID20240329131902.v1.class)
  231. // public String updatePicInfo() throws YosException {
  232. //
  233. // Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  234. // Long attachmentid = content.getLongValue("attachmentid");
  235. //
  236. // Rows rows = dbConnect.runSqlQuery("SELECT * from sat_sharematerial WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
  237. // JSONObject jsonObject = new JSONObject();
  238. // JSONArray jsonArray = new JSONArray();
  239. // if (rows.isNotEmpty()) {
  240. // jsonObject = rows.get(0).getJSONObject("sharepagecontrol");
  241. // if (jsonObject.containsKey("pics")) {
  242. // jsonArray = jsonObject.getJSONArray("pics");
  243. // } else {
  244. // jsonArray = new JSONArray();
  245. // }
  246. // }
  247. // JSONArray newjsonArray = getTempJSONArray(jsonArray, String.valueOf(attachmentid));
  248. //
  249. // JSONObject object = new JSONObject();
  250. // object.put("attachmentid", attachmentid);
  251. // object.put("url", content.getStringValue("url"));
  252. // object.put("sequence", content.getIntValue("sequence"));
  253. // newjsonArray.add(object);
  254. // jsonObject.put("pics", newjsonArray);
  255. //
  256. // UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_sharematerial");
  257. // updateSQL.setSiteid(siteid);
  258. // updateSQL.setUniqueid(sat_sharematerialid);
  259. //
  260. // updateSQL.setValue("sharepagecontrol", jsonObject);
  261. // System.err.println(updateSQL.getSQL());
  262. // updateSQL.update();
  263. //
  264. //
  265. // object.put("attinfos", Attachment.get(this, attachmentid));
  266. //
  267. //
  268. // return getSucReturnObject().setData(object).toString();
  269. // }
  270. //
  271. // @API(title = "长图文解绑图片信息", apiversion = R.ID20240329132002.v1.class)
  272. // public String deletePicInfo() throws YosException {
  273. //
  274. // Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  275. // Long attachmentid = content.getLongValue("attachmentid");
  276. //
  277. // Rows rows = dbConnect.runSqlQuery("SELECT * from sat_sharematerial WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
  278. // JSONObject jsonObject = new JSONObject();
  279. // JSONArray jsonArray = new JSONArray();
  280. // if (rows.isNotEmpty()) {
  281. // jsonObject = rows.get(0).getJSONObject("sharepagecontrol");
  282. // if (jsonObject.containsKey("pics")) {
  283. // jsonArray = jsonObject.getJSONArray("pics");
  284. // } else {
  285. // jsonArray = new JSONArray();
  286. // }
  287. // }
  288. // jsonObject.put("pics", getTempJSONArray(jsonArray, String.valueOf(attachmentid)));
  289. //
  290. //
  291. // UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_sharematerial");
  292. // updateSQL.setSiteid(siteid);
  293. // updateSQL.setUniqueid(sat_sharematerialid);
  294. //
  295. // updateSQL.setValue("sharepagecontrol", jsonObject);
  296. // System.err.println(updateSQL.getSQL());
  297. // updateSQL.update();
  298. //
  299. // return detail();
  300. // }
  301. // public JSONArray getTempJSONArray(JSONArray jsonArray, String attachmentid) throws YosException {
  302. // JSONArray temp = new JSONArray();
  303. // for (Object object : jsonArray) {
  304. // JSONObject temp_object = (JSONObject) object;
  305. // if (!temp_object.getString("attachmentid").equals(attachmentid)) {
  306. // temp.add(object);
  307. // }
  308. // }
  309. //
  310. // return temp;
  311. // }
  312. }