sharematerial.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. package restcontroller.webmanage.saletool.sharematerial;
  2. import beans.datatag.DataTag;
  3. import beans.remind.Remind;
  4. import beans.user.User;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alibaba.fastjson.JSONObject;
  7. import common.Controller;
  8. import common.YosException;
  9. import common.annotation.API;
  10. import common.annotation.CACHEING;
  11. import common.annotation.CACHEING_CLEAN;
  12. import common.annotation.cm;
  13. import common.data.Row;
  14. import common.data.Rows;
  15. import common.data.RowsMap;
  16. import common.data.SQLFactory;
  17. import restcontroller.R;
  18. import java.util.ArrayList;
  19. import java.util.HashMap;
  20. @API(title = "推广素材管理")
  21. public class sharematerial extends Controller {
  22. public sharematerial(JSONObject content) throws YosException {
  23. super(content);
  24. }
  25. @API(title = "新增")
  26. @CACHEING_CLEAN(cms = {@cm(clazz = sharematerial.class, method = {"select"})})
  27. public String insertOrUpdate() throws YosException {
  28. Long sat_sharematerialid = content.getLong("sat_sharematerialid");
  29. String title = content.getString("title", "sat_sharematerial");
  30. Long sat_sharematerial_classid = content.getLong("sat_sharematerial_classid");
  31. String notes = content.getString("notes", "sat_sharematerial");
  32. JSONArray tagArray = content.getJSONArray("tag");
  33. boolean canfiledownload = content.getBoolean("canfiledownload");
  34. String text = content.getString("content", true);
  35. int type = content.getIntValue("type");
  36. SQLFactory sqlFactory;
  37. if (sat_sharematerialid <= 0) {
  38. //素材id
  39. sat_sharematerialid = createTableID("sat_sharematerial");
  40. sqlFactory = new SQLFactory(this, "素材-新增");
  41. sqlFactory.addParameter("createdepid", departmentid);
  42. sqlFactory.addParameter("createuserid", userid);
  43. sqlFactory.addParameter("createby", username);
  44. sqlFactory.addParameter("authuserid", userid);
  45. sqlFactory.addParameter("authdepid", departmentid);
  46. } else {
  47. sqlFactory = new SQLFactory(this, "素材-更新");
  48. }
  49. sqlFactory.addParameter("siteid", siteid);
  50. sqlFactory.addParameter("sat_sharematerialid", sat_sharematerialid);
  51. sqlFactory.addParameter("changeuserid", userid);
  52. sqlFactory.addParameter("changeby", username);
  53. sqlFactory.addParameter("title", title);
  54. sqlFactory.addParameter("type", type);
  55. sqlFactory.addParameter("sat_sharematerial_classid", sat_sharematerial_classid);
  56. sqlFactory.addParameter("content", text);
  57. sqlFactory.addParameter("notes", notes);
  58. sqlFactory.addParameter("canfiledownload", canfiledownload);
  59. // sqlFactory.addParameter("tag", tagArray.toJSONString());
  60. sqlFactory.addParameter("sa_agentsid", userInfo.getAgentID());
  61. ArrayList<String> list = (ArrayList<String>) JSONObject.parseArray(tagArray.toJSONString(), String.class);
  62. DataTag.updateTag(this, "sat_sharematerial", sat_sharematerialid, list);
  63. dbConnect.runSqlUpdate(sqlFactory);
  64. content.put("sat_sharematerialid", sat_sharematerialid);
  65. return selectDetail();
  66. }
  67. @API(title = "删除", apiversion = R.ID20221102143602.v1.class)
  68. @CACHEING_CLEAN(cms = {@cm(clazz = sharematerial.class, method = {"select"})})
  69. public String delete() throws YosException {
  70. JSONArray array = content.getJSONArray("sat_sharematerialids");
  71. SQLFactory sqlFactory = new SQLFactory(this, "素材-删除");
  72. sqlFactory.addParameter_in("sat_sharematerialid", array.toArray());
  73. String sql = sqlFactory.getSQL();
  74. dbConnect.runSqlUpdate(sql);
  75. return getSucReturnObject().toString();
  76. }
  77. @API(title = "审核")
  78. @CACHEING_CLEAN(cms = {@cm(clazz = sharematerial.class, method = {"select"})})
  79. public String audit() throws YosException {
  80. Long sat_sharematerialid = content.getLong("sat_sharematerialid");
  81. int type = content.getIntValue("type");
  82. String status = "新建";
  83. if (type == 0) {
  84. status = "新建";
  85. } else {
  86. status = "审核";
  87. }
  88. SQLFactory sqlFactory = new SQLFactory(this, "素材-审核");
  89. sqlFactory.addParameter("sat_sharematerialid", sat_sharematerialid);
  90. sqlFactory.addParameter("checkby", username);
  91. sqlFactory.addParameter("status", status);
  92. dbConnect.runSqlUpdate(sqlFactory);
  93. //发送邮件和消息,发布时发送消息
  94. if (type != 0) {
  95. sendMsg(sat_sharematerialid);
  96. }
  97. return getSucReturnObject().toString();
  98. }
  99. /**
  100. * 发送消息:新素材发布,推广素材发布范围内的经销商/人员
  101. *
  102. * @param sat_sharematerialid
  103. * @throws YosException
  104. */
  105. public void sendMsg(Long sat_sharematerialid) throws YosException {
  106. SQLFactory sqlFactory = new SQLFactory(this, "查询范围内的账号");
  107. sqlFactory.addParameter("siteid", siteid);
  108. sqlFactory.addParameter("sat_sharematerialid", sat_sharematerialid);
  109. Rows useridRows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  110. if (useridRows.isNotEmpty()) {
  111. for (Row row : useridRows) {
  112. Long tempUserid = row.getLong("userid");
  113. if (tempUserid != 0) {
  114. Remind remind = new Remind(this);
  115. remind.setType("应用");
  116. remind.setTitle("新素材发布");
  117. remind.setContent("您有新的推广素材,请查看!");
  118. remind.setTouserid(tempUserid);
  119. remind.setObjectname("sat_sharematerial");
  120. remind.setObjectid(sat_sharematerialid);
  121. remind.sendByDialogMsg().createSys_message();
  122. //发邮件
  123. remind.setToemail(User.getUserMailAddress(this, tempUserid));
  124. remind.sendByMail();
  125. }
  126. }
  127. }
  128. }
  129. @API(title = "管理端-素材列表", apiversion = R.ID20221102143102.v1.class)
  130. @CACHEING
  131. public String select() throws YosException {
  132. /*
  133. 过滤条件设置
  134. */
  135. StringBuffer where = new StringBuffer(" 1=1 ");
  136. if (content.containsKey("where")) {
  137. JSONObject whereObject = content.getJSONObject("where");
  138. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  139. where.append(" and(");
  140. where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
  141. where.append("or t1.content like'%").append(whereObject.getString("condition")).append("%' ");
  142. where.append("or t2.classname like'%").append(whereObject.getString("condition")).append("%' ");
  143. where.append("or t1.notes like'%").append(whereObject.getString("condition")).append("%' ");
  144. where.append(")");
  145. }
  146. if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
  147. where.append(" and(");
  148. where.append("t1.type = '").append(whereObject.getString("type")).append("' ");
  149. where.append(")");
  150. }
  151. if (whereObject.containsKey("sat_sharematerial_classid") && !"".equals(whereObject.getString("sat_sharematerial_classid"))) {
  152. where.append(" and(");
  153. where.append("t1.sat_sharematerial_classid = '").append(whereObject.getString("sat_sharematerial_classid")).append("' ");
  154. where.append("or t3.sat_sharematerial_classid = '").append(whereObject.getString("sat_sharematerial_classid")).append("' ");
  155. where.append(")");
  156. }
  157. }
  158. SQLFactory sqlFactory = new SQLFactory(this, "素材-列表", pageSize, pageNumber, pageSorting);
  159. sqlFactory.addParameter_SQL("where", where);
  160. String sql = sqlFactory.getSQL();
  161. Rows rows = dbConnect.runSqlQuery(sql);
  162. ArrayList<Long> ids = rows.toArrayList("sat_sharematerialid", new ArrayList<>());
  163. HashMap<Long, ArrayList<String>> tagMap = DataTag.queryTag(this, "sat_sharematerial", ids, false);
  164. //封面cover
  165. RowsMap coverRowsMap = getAttachmentUrl("sat_sharematerial", ids, "cover");
  166. //附件
  167. RowsMap attRowsMap = getAttachmentUrl("sat_sharematerial", ids, "default");
  168. for (Row row : rows) {
  169. Rows coverRows = coverRowsMap.get(row.getString("sat_sharematerialid"));
  170. if (coverRows.isEmpty()) {
  171. row.put("cover", "");
  172. } else {
  173. row.put("cover", coverRows.get(0).getString("url"));
  174. }
  175. row.put("attinfos", attRowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows()));
  176. row.put("tag", tagMap.get(row.getString("sat_sharematerialid")));
  177. }
  178. return getSucReturnObject().setData(rows).toString();
  179. }
  180. @API(title = "详细")
  181. public String selectDetail() throws YosException {
  182. Long sat_sharematerialid = content.getLong("sat_sharematerialid");
  183. SQLFactory sqlFactory = new SQLFactory(this, "素材-详细");
  184. sqlFactory.addParameter("sat_sharematerialid", sat_sharematerialid);
  185. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  186. ArrayList<Long> ids = rows.toArrayList("sat_sharematerialid", new ArrayList<>());
  187. //封面cover
  188. RowsMap coverRowsMap = getAttachmentUrl("sat_sharematerial", ids, "cover");
  189. //附件
  190. RowsMap attRowsMap = getAttachmentUrl("sat_sharematerial", ids, "default");
  191. for (Row row : rows) {
  192. Rows coverRows = coverRowsMap.get(row.getString("sat_sharematerialid"));
  193. if (coverRows.isEmpty()) {
  194. row.put("cover", "");
  195. } else {
  196. row.put("cover", coverRows.get(0).getString("url"));
  197. }
  198. row.put("attinfos", attRowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows()));
  199. row.put("tag", DataTag.queryTag(this, "sat_sharematerial", row.getLong("sat_sharematerialid"), false));
  200. }
  201. return getSucReturnObject().setData(rows.size() > 0 ? rows.get(0) : new Row()).toString();
  202. }
  203. }