notice.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. package restcontroller.saletool.notice;
  2. import beans.attachment.Attachment;
  3. import beans.parameter.Parameter;
  4. import beans.remind.Remind;
  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 utility.email.EmailContent;
  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. public String queryNoticeList() throws YosException {
  20. String where = " 1=1 ";
  21. if (content.containsKey("where")) {
  22. JSONObject whereObject = content.getJSONObject("where");
  23. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  24. where = where + " and t1.title like'%" + whereObject.getString("condition") + "%'";
  25. }
  26. if (whereObject.containsKey("sat_notice_classid") && !"".equals(whereObject.getString("sat_notice_classid"))) {
  27. where = where + " and t1.sat_notice_classid = " + whereObject.getString("sat_notice_classid");
  28. }
  29. if (whereObject.containsKey("isread") && !"".equals(whereObject.getString("isread"))) {
  30. //已读
  31. if (whereObject.getLongValue("isread") == 0) {
  32. where = where + " and t3.confirmed =0";
  33. }
  34. //已知
  35. if (whereObject.getLongValue("isread") == 1) {
  36. where = where + " and t3.confirmed =1";
  37. }
  38. //未读
  39. if (whereObject.getLongValue("isread") == 2) {
  40. where = where + " and t3.confirmed is null";
  41. }
  42. }
  43. }
  44. if (pageSorting.equals("''")) {
  45. pageSorting = "t1.checkdate desc";
  46. }
  47. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_notice"
  48. , "sat_noticeid", "title", "checkdate", "status")
  49. .setTableAlias("t1");
  50. querySQL.addJoinTable(JOINTYPE.left, "sat_notice_class", "t2", "t1.sat_notice_classid = t2.sat_notice_classid and t2.siteid = t1.siteid",
  51. "classname");
  52. querySQL.addJoinTable(JOINTYPE.left, "sat_notice_read", "t3", "t3.siteid = t1.siteid AND t3.sat_noticeid = t1.sat_noticeid and t3.createuserid =" + userid);
  53. querySQL.addQueryFields("confirmed", "(CASE WHEN (t3.confirmed is null) THEN 2 ELSE t3.confirmed END)");
  54. querySQL.setWhere("status","发布");
  55. querySQL.setSiteid(siteid);
  56. querySQL.setWhere(where);
  57. querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting).setDataAuth(true);
  58. Rows rows = querySQL.query();
  59. // ArrayList<Long> ids = rows.toArrayList("sat_noticeid", new ArrayList<Long>());
  60. // // 封面cover
  61. // RowsMap coverRowsMap = getAttachmentUrl("sat_notice", ids, "cover");
  62. // // 附件
  63. // RowsMap RowsMap = getAttachmentUrl("sat_notice", ids);
  64. for (Row row : rows) {
  65. // Rows Rows = RowsMap.get(row.getString("sat_noticeid"));
  66. // if (Rows.isEmpty()) {
  67. // row.put("attinfos", new Rows());
  68. // } else {
  69. // row.put("attinfos", Rows);
  70. // }
  71. // Rows coverRows = coverRowsMap.get(row.getString("sat_noticeid"));
  72. // if (coverRows.isEmpty()) {
  73. // row.put("cover", "");
  74. // } else {
  75. // row.put("cover", coverRows.get(0).getString("url"));
  76. // }
  77. if (row.getLong("confirmed") == 0) {
  78. row.putIfAbsent("readstatus", "已读");
  79. }
  80. if (row.getLong("confirmed") == 1) {
  81. row.putIfAbsent("readstatus", "已知");
  82. }
  83. if (row.getLong("confirmed") == 2) {
  84. row.putIfAbsent("readstatus", "未读");
  85. }
  86. }
  87. JSONObject object = new JSONObject();
  88. object.put("readNum", rows.getTotalRows());
  89. return getSucReturnObject().setData(rows).setTips(object).toString();
  90. }
  91. @API(title = "确认已知", apiversion = R.ID20240320152902.v1.class)
  92. public String confirmed() throws YosException {
  93. Long sat_noticeid = content.getLong("sat_noticeid");
  94. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_notice_read");
  95. updateSQL.setSiteid(siteid);
  96. updateSQL.setValue("confirmed", 1);
  97. updateSQL.setWhere("sat_noticeid", sat_noticeid);
  98. updateSQL.setWhere("createuserid", userid);
  99. updateSQL.update();
  100. return getSucReturnObject().toString();
  101. }
  102. @API(title = "发送邮件", apiversion = R.ID20240320153302.v1.class)
  103. public String sendMail() throws Exception {
  104. Long sat_noticeid = content.getLong("sat_noticeid");
  105. String email = content.getStringValue("email");
  106. if (!Parameter.get(siteid, "remind_mail").equalsIgnoreCase("1")) {
  107. return getErrReturnObject().setErrMsg("邮件功能未开启").toString();
  108. }
  109. Rows rows = dbConnect.runSqlQuery("SELECT * from sat_notice where sat_noticeid=" + sat_noticeid);
  110. if (rows.isEmpty()) {
  111. return getErrReturnObject().setErrMsg("数据不存在").toString();
  112. }
  113. Rows rowsAtt = Attachment.get(this, "sat_notice", sat_noticeid);
  114. EmailContent emailContent = new EmailContent();
  115. emailContent.addText(rows.get(0).getString("content"));
  116. for (Row rowAtt : rowsAtt) {
  117. emailContent.addFile(rowAtt.getString("url"));
  118. }
  119. Remind remind = new Remind(siteid);
  120. remind.setTitle(rows.get(0).getString("title"));
  121. remind.setToemail(email);
  122. remind.setContent(emailContent);
  123. remind.sendByMail();
  124. return getSucReturnObject().toString();
  125. }
  126. @API(title = "通告详情")
  127. public String queryNoticeMain() throws YosException {
  128. Long sat_noticeid = content.getLong("sat_noticeid");
  129. // 新增记录
  130. addReadRecord(sat_noticeid);
  131. SQLFactory sqlFactory = new SQLFactory(this, "通告详情查询");
  132. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  133. sqlFactory.addParameter("userid", userid);
  134. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  135. // 附件
  136. ArrayList<Long> ids = rows.toArrayList("sat_noticeid", new ArrayList<Long>());
  137. RowsMap attRowsMap = getAttachmentUrl("sat_notice", ids);
  138. for (Row row : rows) {
  139. Rows Rows = attRowsMap.get(row.getString("sat_noticeid"));
  140. if (Rows.isEmpty()) {
  141. row.put("attinfos", new Rows());
  142. } else {
  143. row.put("attinfos", Rows);
  144. }
  145. }
  146. return getSucReturnObject().setData(rows.get(0)).toString();
  147. }
  148. /**
  149. * 查询阅读记录(通告留言和打分)
  150. *
  151. * @return
  152. */
  153. @API(title = "查询阅读记录")
  154. public String queryReadRecord() throws YosException {
  155. Long sat_noticeid = content.getLong("sat_noticeid");
  156. Rows rows = dbConnect
  157. .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" +
  158. " left join sys_usersite t2 on t1.createuserid=t2.userid and t1.siteid=t2.siteid\n" +
  159. " left join sys_enterprise_hr t3 on t1.createuserid=t3.userid and t1.siteid=t3.siteid\n" +
  160. " WHERE t1.siteid = '" + siteid + "' AND t1.sat_noticeid ='" + sat_noticeid + "' AND t1.createuserid = '" + userid + "'");
  161. if (rows.isEmpty()) {
  162. return getErrReturnObject().setErrMsg("阅读记录不存在").toString();
  163. }
  164. return getSucReturnObject().setData(rows).toString();
  165. }
  166. /**
  167. * 更新阅读记录(通告留言和打分)
  168. *
  169. * @return
  170. */
  171. @API(title = "更新阅读记录")
  172. public String updateReadRecord() throws YosException {
  173. Long sat_noticeid = content.getLong("sat_noticeid");
  174. int score = content.getInteger("score");
  175. String leavemessage = content.getString("leavemessage");
  176. Rows rows = dbConnect.runSqlQuery("select sat_notice_readid FROM sat_notice_read WHERE siteid = '" + siteid
  177. + "' AND sat_noticeid = '" + sat_noticeid + "' AND createuserid = '" + userid + "'");
  178. if (rows.isEmpty()) {
  179. return getErrReturnObject().setErrMsg("阅读记录不存在,无法更新").toString();
  180. }
  181. SQLFactory sqlFactory = new SQLFactory(this, "阅读记录更新");
  182. sqlFactory.addParameter("leavemessage", leavemessage);
  183. sqlFactory.addParameter("score", score);
  184. sqlFactory.addParameter("siteid", siteid);
  185. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  186. sqlFactory.addParameter("userid", userid);
  187. sqlFactory.addParameter("hrid", hrid);
  188. sqlFactory.addParameter("sa_agentsid", userInfo.getAgentID());
  189. dbConnect.runSqlUpdate(sqlFactory);
  190. return getSucReturnObject().toString();
  191. }
  192. @API(title = "更新下载附件记录")
  193. public String updateDownloadRecord() throws YosException {
  194. Long sat_noticeid = content.getLong("sat_noticeid");
  195. dbConnect.runSqlUpdate("UPDATE sat_notice_read SET isdownloadfile=1 WHERE siteid = '" + siteid
  196. + "' AND sat_noticeid = '" + sat_noticeid + "' AND createuserid = '" + userid + "'");
  197. return getSucReturnObject().toString();
  198. }
  199. // 添加阅读记录
  200. public void addReadRecord(Long sat_noticeid) throws YosException {
  201. // 新增浏览次数
  202. dbConnect.runSqlUpdate("UPDATE sat_notice SET readcount=readcount+1 WHERE sat_noticeid='" + sat_noticeid + "'");
  203. // 查询当前用户的阅读记录是否存在
  204. String sql = "SELECT sat_notice_readid FROM sat_notice_read WHERE siteid = '" + siteid
  205. + "' AND sat_noticeid = '" + sat_noticeid + "' AND createuserid = '" + userid + "'";
  206. Rows rows = dbConnect.runSqlQuery(sql);
  207. String result = "false";
  208. if (rows.isEmpty()) {
  209. SQLFactory sqlFactory = new SQLFactory(this, "阅读记录新增");
  210. sqlFactory.addParameter("siteid", siteid);
  211. sqlFactory.addParameter("sat_notice_readid", createTableID("sat_notice_read"));
  212. sqlFactory.addParameter("createby", username);
  213. sqlFactory.addParameter("changeby", username);
  214. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  215. sqlFactory.addParameter("createuserid", userid);
  216. sqlFactory.addParameter("hrid", hrid);
  217. sqlFactory.addParameter("sa_agentsid", userInfo.getAgentID());
  218. dbConnect.runSqlUpdate(sqlFactory);
  219. } else {
  220. SQLFactory sqlFactory = new SQLFactory(this, "阅读记录次数更新");
  221. sqlFactory.addParameter("siteid", siteid);
  222. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  223. sqlFactory.addParameter("userid", userid);
  224. sqlFactory.addParameter("hrid", hrid);
  225. sqlFactory.addParameter("sa_agentsid", userInfo.getAgentID());
  226. dbConnect.runSqlUpdate(sqlFactory);
  227. }
  228. }
  229. }