notice.java 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package restcontroller.saletool.notice;
  2. import com.alibaba.fastjson.JSONObject;
  3. import common.Controller;
  4. import common.YosException;
  5. import common.annotation.API;
  6. import common.annotation.CACHEING;
  7. import common.data.Row;
  8. import common.data.Rows;
  9. import common.data.RowsMap;
  10. import common.data.SQLFactory;
  11. import restcontroller.R;
  12. import java.util.ArrayList;
  13. @API(title = "通告")
  14. public class notice extends Controller {
  15. public notice(JSONObject content) throws YosException {
  16. super(content);
  17. }
  18. @API(title = "通告列表", apiversion = R.ID20221111090904.v1.class)
  19. @CACHEING
  20. public String queryNoticeList() throws YosException {
  21. /*
  22. 排序条件设置
  23. */
  24. String sort = "t1.createdate desc";
  25. /*
  26. 过滤条件设置
  27. */
  28. String where = " 1=1 ";
  29. if (content.containsKey("where")) {
  30. JSONObject whereObject = content.getJSONObject("where");
  31. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  32. where = where + " and t1.title like'%" + whereObject.getString("condition") + "%'";
  33. }
  34. if (whereObject.containsKey("sat_notice_classid") && !"".equals(whereObject.getString("sat_notice_classid"))) {
  35. where = where + " and t1.sat_notice_classid = " + whereObject.getString("sat_notice_classid");
  36. }
  37. }
  38. SQLFactory sqlFactory = new SQLFactory(this, "通告列表查询", pageSize, pageNumber, pageSorting);
  39. sqlFactory.addParameter_SQL("where", where);
  40. sqlFactory.addParameter("siteid", siteid);
  41. sqlFactory.addParameter_in("departmentid", departmentid);
  42. sqlFactory.addParameter_in("hrid", hrid);
  43. sqlFactory.addParameter_in("sa_agentsid", userInfo.getAgentsId());
  44. sqlFactory.addParameter_in("sa_saleareaid", userInfo.getSaleAreaIds());
  45. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  46. ArrayList<Long> ids = rows.toArrayList("sat_noticeid", new ArrayList<Long>());
  47. // 封面cover
  48. RowsMap coverRowsMap = getAttachmentUrl("sat_notice", ids, "cover");
  49. // 附件
  50. RowsMap RowsMap = getAttachmentUrl("sat_notice", ids);
  51. for (Row row : rows) {
  52. Rows Rows = RowsMap.get(row.getString("sat_noticeid"));
  53. if (Rows.isEmpty()) {
  54. row.put("attinfos", new Rows());
  55. } else {
  56. row.put("attinfos", Rows);
  57. }
  58. }
  59. for (Row row : rows) {
  60. Rows coverRows = coverRowsMap.get(row.getString("sat_noticeid"));
  61. if (coverRows.isEmpty()) {
  62. row.put("cover", "");
  63. } else {
  64. row.put("cover", coverRows.get(0).getString("url"));
  65. }
  66. }
  67. SQLFactory sqlFactorycount = new SQLFactory(this, "通告列表总数量查询");
  68. sqlFactorycount.addParameter("siteid", siteid);
  69. sqlFactorycount.addParameter_in("departmentid", departmentid);
  70. sqlFactorycount.addParameter_in("userid", userid);
  71. sqlFactorycount.addParameter_in("hrid", hrid);
  72. sqlFactorycount.addParameter_in("sa_agentsid", userInfo.getAgentsId());
  73. sqlFactorycount.addParameter_in("sa_saleareaid", userInfo.getSaleAreaIds());
  74. Row readrow = dbConnect.runSqlQuery(0, sqlFactorycount);
  75. JSONObject object = new JSONObject();
  76. object.put("readNum", readrow.getLong("num"));
  77. return getSucReturnObject().setData(rows).setTips(object).toString();
  78. }
  79. @API(title = "通告详情")
  80. public String queryNoticeMain() throws YosException {
  81. Long sat_noticeid = content.getLong("sat_noticeid");
  82. // 新增记录
  83. addReadRecord(sat_noticeid);
  84. SQLFactory sqlFactory = new SQLFactory(this, "通告详情查询");
  85. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  86. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  87. // 附件
  88. ArrayList<Long> ids = rows.toArrayList("sat_noticeid", new ArrayList<Long>());
  89. RowsMap attRowsMap = getAttachmentUrl("sat_notice", ids);
  90. for (Row row : rows) {
  91. Rows Rows = attRowsMap.get(row.getString("sat_noticeid"));
  92. if (Rows.isEmpty()) {
  93. row.put("attinfos", new Rows());
  94. } else {
  95. row.put("attinfos", Rows);
  96. }
  97. }
  98. return getSucReturnObject().setData(rows.get(0)).toString();
  99. }
  100. /**
  101. * 查询阅读记录(通告留言和打分)
  102. *
  103. * @return
  104. */
  105. @API(title = "查询阅读记录")
  106. public String queryReadRecord() throws YosException {
  107. Long sat_noticeid = content.getLong("sat_noticeid");
  108. Rows rows = dbConnect
  109. .runSqlQuery("select t2.usertype,t3.position,t1.createdate,t1.createby,t1.leavemessage,t1.score,(SELECT count(*) FROM sat_notice_read WHERE siteid ='" + siteid + "' AND sat_noticeid = '" + sat_noticeid + "' and score>0) evaluatecount FROM sat_notice_read t1\n" +
  110. " left join sys_usersite t2 on t1.createuserid=t2.userid and t1.siteid=t2.siteid\n" +
  111. " left join sys_enterprise_hr t3 on t1.createuserid=t3.userid and t1.siteid=t3.siteid\n" +
  112. " WHERE t1.siteid = '" + siteid + "' AND t1.sat_noticeid ='" + sat_noticeid + "' AND t1.createuserid = '" + userid + "'");
  113. if (rows.isEmpty()) {
  114. return getErrReturnObject().setErrMsg("阅读记录不存在").toString();
  115. }
  116. return getSucReturnObject().setData(rows).toString();
  117. }
  118. /**
  119. * 更新阅读记录(通告留言和打分)
  120. *
  121. * @return
  122. */
  123. @API(title = "更新阅读记录")
  124. public String updateReadRecord() throws YosException {
  125. Long sat_noticeid = content.getLong("sat_noticeid");
  126. int score = content.getInteger("score");
  127. String leavemessage = content.getString("leavemessage");
  128. Rows rows = dbConnect.runSqlQuery("select sat_notice_readid FROM sat_notice_read WHERE siteid = '" + siteid
  129. + "' AND sat_noticeid = '" + sat_noticeid + "' AND createuserid = '" + userid + "'");
  130. if (rows.isEmpty()) {
  131. return getErrReturnObject().setErrMsg("阅读记录不存在,无法更新").toString();
  132. }
  133. SQLFactory sqlFactory = new SQLFactory(this, "阅读记录更新");
  134. sqlFactory.addParameter("leavemessage", leavemessage);
  135. sqlFactory.addParameter("score", score);
  136. sqlFactory.addParameter("siteid", siteid);
  137. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  138. sqlFactory.addParameter("userid", userid);
  139. sqlFactory.addParameter("hrid", hrid);
  140. sqlFactory.addParameter("sa_agentsid", userInfo.getAgentsId());
  141. dbConnect.runSqlUpdate(sqlFactory);
  142. return getSucReturnObject().toString();
  143. }
  144. @API(title = "更新下载附件记录")
  145. public String updateDownloadRecord() throws YosException {
  146. Long sat_noticeid = content.getLong("sat_noticeid");
  147. dbConnect.runSqlUpdate("UPDATE sat_notice_read SET isdownloadfile=1 WHERE siteid = '" + siteid
  148. + "' AND sat_noticeid = '" + sat_noticeid + "' AND createuserid = '" + userid + "'");
  149. return getSucReturnObject().toString();
  150. }
  151. // 添加阅读记录
  152. public void addReadRecord(Long sat_noticeid) throws YosException {
  153. // 新增浏览次数
  154. dbConnect.runSqlUpdate("UPDATE sat_notice SET readcount=readcount+1 WHERE sat_noticeid='" + sat_noticeid + "'");
  155. // 查询当前用户的阅读记录是否存在
  156. String sql = "SELECT sat_notice_readid FROM sat_notice_read WHERE siteid = '" + siteid
  157. + "' AND sat_noticeid = '" + sat_noticeid + "' AND createuserid = '" + userid + "'";
  158. Rows rows = dbConnect.runSqlQuery(sql);
  159. String result = "false";
  160. if (rows.isEmpty()) {
  161. SQLFactory sqlFactory = new SQLFactory(this, "阅读记录新增");
  162. sqlFactory.addParameter("siteid", siteid);
  163. sqlFactory.addParameter("sat_notice_readid", createTableID("sat_notice_read"));
  164. sqlFactory.addParameter("createby", username);
  165. sqlFactory.addParameter("changeby", username);
  166. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  167. sqlFactory.addParameter("createuserid", userid);
  168. sqlFactory.addParameter("hrid", hrid);
  169. sqlFactory.addParameter("sa_agentsid", userInfo.getAgentsId());
  170. dbConnect.runSqlUpdate(sqlFactory);
  171. } else {
  172. SQLFactory sqlFactory = new SQLFactory(this, "阅读记录次数更新");
  173. sqlFactory.addParameter("siteid", siteid);
  174. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  175. sqlFactory.addParameter("userid", userid);
  176. sqlFactory.addParameter("hrid", hrid);
  177. sqlFactory.addParameter("sa_agentsid", userInfo.getAgentsId());
  178. dbConnect.runSqlUpdate(sqlFactory);
  179. }
  180. }
  181. }