LongPicText.java 15 KB

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