notice.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. package restcontroller.webmanage.saletool.notice;
  2. import beans.remind.Remind;
  3. import beans.user.User;
  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.annotation.CACHEING;
  10. import common.annotation.CACHEING_CLEAN;
  11. import common.annotation.cm;
  12. import common.data.Row;
  13. import common.data.Rows;
  14. import common.data.RowsMap;
  15. import common.data.SQLFactory;
  16. import restcontroller.R;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. @API(title = "通告")
  20. public class notice extends Controller {
  21. public notice(JSONObject content) throws YosException {
  22. super(content);
  23. }
  24. @API(title = "通告新增修改", apiversion = R.ID20221101094803.v1.class)
  25. @CACHEING_CLEAN(cms = {@cm(clazz = notice.class, method = {"queryNoticeList"})})
  26. public String insertormodify_notice() throws YosException {
  27. long sat_noticeid = content.getLong("sat_noticeid");
  28. ArrayList<String> sqllist = new ArrayList<>();
  29. String title = content.getString("title");
  30. Long sat_notice_classid = content.getLong("sat_notice_classid");
  31. String summary = content.getString("summary");
  32. String content1 = content.getString("content", true);
  33. boolean issecret = content.getBoolean("issecret");
  34. boolean isontop = content.getBoolean("isontop");
  35. String begdate = content.getStringValue("begdate");
  36. String enddate = content.getStringValue("enddate");
  37. if (sat_noticeid <= 0 || dbConnect
  38. .runSqlQuery("select sat_noticeid from sat_notice where sat_noticeid=" + sat_noticeid).isEmpty()) {
  39. sat_noticeid = createTableID("sat_notice");
  40. SQLFactory sqlFactory = new SQLFactory(this, "通告新增");
  41. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  42. sqlFactory.addParameter("siteid", siteid);
  43. sqlFactory.addParameter("createdepid", departmentid);
  44. sqlFactory.addParameter("createuserid", userid);
  45. sqlFactory.addParameter("createby", username);
  46. sqlFactory.addParameter("authuserid", userid);
  47. sqlFactory.addParameter("authdepid", departmentid);
  48. sqlFactory.addParameter("changeby", username);
  49. sqlFactory.addParameter("changeuserid", userid);
  50. sqlFactory.addParameter("title", title);
  51. sqlFactory.addParameter("sat_notice_classid", sat_notice_classid);
  52. sqlFactory.addParameter("summary", summary);
  53. sqlFactory.addParameter("content", content1);
  54. sqlFactory.addParameter("issecret", issecret);
  55. sqlFactory.addParameter("isontop", isontop);
  56. sqlFactory.addParameter("begdate", begdate.equals("") ? "null" : begdate);
  57. sqlFactory.addParameter("enddate", enddate.equals("") ? "null" : enddate);
  58. content.put("sat_noticeid", sat_noticeid);
  59. sqllist.add(sqlFactory.getSQL());
  60. if (isontop) {
  61. sqllist.add("update sat_notice set isontop=0 where isontop=1 and sat_noticeid !=" + sat_noticeid);
  62. }
  63. } else {
  64. Rows rowscount = dbConnect.runSqlQuery("select status from sat_notice where sat_noticeid=" + sat_noticeid);
  65. if (rowscount.isEmpty()) {
  66. return getErrReturnObject().setErrMsg("此通告不存在").toString();
  67. } else {
  68. if (!rowscount.get(0).getString("status").equals("新建")) {
  69. return getErrReturnObject().setErrMsg("非新建状态的通告无法更新").toString();
  70. }
  71. }
  72. SQLFactory sqlFactory = new SQLFactory(this, "通告更新");
  73. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  74. sqlFactory.addParameter("siteid", siteid);
  75. sqlFactory.addParameter("createdepid", departmentid);
  76. sqlFactory.addParameter("authuserid", userid);
  77. sqlFactory.addParameter("authdepid", departmentid);
  78. sqlFactory.addParameter("changeby", username);
  79. sqlFactory.addParameter("changeuserid", userid);
  80. sqlFactory.addParameter("title", title);
  81. sqlFactory.addParameter("isontop", isontop);
  82. sqlFactory.addParameter("sat_notice_classid", sat_notice_classid);
  83. sqlFactory.addParameter("summary", summary);
  84. sqlFactory.addParameter("content", content1);
  85. sqlFactory.addParameter("issecret", issecret);
  86. sqlFactory.addParameter("begdate", begdate.equals("") ? "null" : begdate);
  87. sqlFactory.addParameter("enddate", enddate.equals("") ? "null" : enddate);
  88. sqllist.add(sqlFactory.getSQL());
  89. if (isontop) {
  90. sqllist.add("update sat_notice set isontop=0 where isontop=1 and sat_noticeid !=" + sat_noticeid);
  91. }
  92. }
  93. dbConnect.runSqlUpdate(sqllist);
  94. return queryNoticeMain();
  95. }
  96. @API(title = "通告列表", apiversion = R.ID20221101094903.v1.class)
  97. @CACHEING
  98. public String queryNoticeList() throws YosException {
  99. /*
  100. 排序条件设置
  101. */
  102. String sort = "t1.createdate desc";
  103. /*
  104. 过滤条件设置
  105. */
  106. String where = " 1=1 ";
  107. if (content.containsKey("where")) {
  108. JSONObject whereObject = content.getJSONObject("where");
  109. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  110. where = where + " and t1.title like'%" + whereObject.getString("condition") + "%'";
  111. }
  112. if (whereObject.containsKey("sat_notice_classid") && !"".equals(whereObject.getString("sat_notice_classid"))) {
  113. where = where + " and t2.sat_notice_classid = " + whereObject.getString("sat_notice_classid");
  114. }
  115. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  116. where = where + " and t1.status ='" + whereObject.getString("status") + "' ";
  117. }
  118. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  119. where = where + " and t1.checkdate >='" + whereObject.getString("begindate") + "'";
  120. }
  121. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  122. where = where + " and t1.checkdate <='" + whereObject.getString("enddate") + "'";
  123. }
  124. }
  125. SQLFactory sqlFactory = new SQLFactory(this, "通告列表查询", pageSize, pageNumber, pageSorting);
  126. sqlFactory.addParameter_SQL("where", where);
  127. sqlFactory.addParameter("siteid", siteid);
  128. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  129. ArrayList<Long> ids = rows.toArrayList("sat_noticeid", new ArrayList<Long>());
  130. // 附件
  131. RowsMap RowsMap = getAttachmentUrl("sat_notice", ids);
  132. // 封面cover
  133. RowsMap coverRowsMap = getAttachmentUrl("sat_notice", ids, "cover");
  134. for (Row row : rows) {
  135. Rows Rows = RowsMap.get(row.getString("sat_noticeid"));
  136. if (Rows.isEmpty()) {
  137. row.put("attinfos", new Rows());
  138. } else {
  139. row.put("attinfos", Rows);
  140. }
  141. // row.put("attinfos", attRowsMap.getOrDefault(row.getString("sat_coursewareid"), new Rows()));
  142. }
  143. for (Row row : rows) {
  144. Rows coverRows = coverRowsMap.get(row.getString("sat_noticeid"));
  145. if (coverRows.isEmpty()) {
  146. row.put("cover", "");
  147. } else {
  148. row.put("cover", coverRows.get(0).getString("url"));
  149. }
  150. }
  151. return getSucReturnObject().setData(rows).toString();
  152. }
  153. @API(title = "通告详情", apiversion = R.ID20221101095003.v1.class)
  154. public String queryNoticeMain() throws YosException {
  155. Long sat_noticeid = content.getLong("sat_noticeid");
  156. // 新增记录
  157. addReadRecord(sat_noticeid);
  158. SQLFactory sqlFactory = new SQLFactory(this, "通告详情查询");
  159. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  160. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  161. ArrayList<Long> ids = rows.toArrayList("sat_noticeid", new ArrayList<Long>());
  162. // 附件
  163. RowsMap attRowsMap = getAttachmentUrl("sat_notice", ids, "default");
  164. // 封面cover
  165. RowsMap coverRowsMap = getAttachmentUrl("sat_notice", ids, "cover");
  166. for (Row row : rows) {
  167. Rows coverRows = coverRowsMap.get(row.getString("sat_noticeid"));
  168. if (coverRows.isEmpty()) {
  169. row.put("cover", "");
  170. } else {
  171. row.put("cover", coverRows.get(0).getString("url"));
  172. }
  173. row.put("attinfos", attRowsMap.getOrDefault(row.getString("sat_noticeid"), new Rows()));
  174. }
  175. return getSucReturnObject().setData(rows.size() > 0 ? rows.get(0) : new Row()).toString();
  176. }
  177. @API(title = "删除", apiversion = R.ID20221101095103.v1.class)
  178. @CACHEING_CLEAN(cms = {@cm(clazz = notice.class, method = {"queryNoticeList"})})
  179. public String delete() throws YosException {
  180. JSONArray sat_noticeids = content.getJSONArray("sat_noticeids");
  181. StringBuffer err = new StringBuffer();
  182. for (Object o : sat_noticeids) {
  183. long sat_noticeid = Long.parseLong(o.toString());
  184. Rows rowscount = dbConnect.runSqlQuery("select title,status from sat_notice where sat_noticeid=" + sat_noticeid);
  185. if (rowscount.isEmpty()) {
  186. err.append(rowscount.get(0).getString("title")).append("--").append("此通告不存在,无法删除;");
  187. continue;
  188. } else if (!rowscount.get(0).getString("status").equals("新建")) {
  189. err.append(rowscount.get(0).getString("title")).append("--").append("非新建状态的通告无法删除;");
  190. continue;
  191. }
  192. ArrayList<String> list = new ArrayList<>();
  193. String deletesql = "delete from sat_notice where sat_noticeid=" + sat_noticeid;
  194. list.add(deletesql);
  195. dbConnect.runSqlUpdate(list);
  196. }
  197. if (err.length() == 0)
  198. return getSucReturnObject().toString();
  199. else
  200. return getSucReturnObject().setData(err).toString();
  201. }
  202. /**
  203. * 通告发布
  204. *
  205. * @return
  206. */
  207. @API(title = "发布", apiversion = R.ID20221101095203.v1.class)
  208. @CACHEING_CLEAN(apiversions = {R.ID20221111090904.v1.class, R.ID20221101094903.v1.class})
  209. public String release() throws YosException {
  210. JSONArray sat_noticeids = content.getJSONArray("sat_noticeids");
  211. String[] s = {"sat_noticeids"};
  212. for (String s1 : s) {
  213. if (!content.containsKey(s1))
  214. return getErrReturnObject().setErrMsg("缺少" + s1 + "参数").toString();
  215. }
  216. List<String> list = sat_noticeids.toJavaList(String.class);
  217. String[] stringArray = list.toArray(new String[0]);
  218. SQLFactory sqlFactoryquery = new SQLFactory(this, "通告状态查询");
  219. sqlFactoryquery.addParameter("siteid", siteid);
  220. sqlFactoryquery.addParameter_in("sat_noticeids", stringArray);
  221. Rows rows = dbConnect.runSqlQuery(sqlFactoryquery);
  222. for (Row row : rows) {
  223. if (row.getString("status").equals("发布")) {
  224. return getErrReturnObject().setErrMsg("【" + row.getString("title") + "】通告已发布,无法再次发布").toString();
  225. }
  226. }
  227. SQLFactory sqlFactoryupdate = new SQLFactory(this, "通告发布");
  228. sqlFactoryupdate.addParameter("siteid", siteid);
  229. sqlFactoryupdate.addParameter_in("sat_noticeids", stringArray);
  230. sqlFactoryupdate.addParameter("checkby", username);
  231. dbConnect.runSqlUpdate(sqlFactoryupdate);
  232. //发送消息
  233. for (String id : stringArray) {
  234. //sendMsg(Long.parseLong(id));
  235. }
  236. return getSucReturnObject().toString();
  237. }
  238. /**
  239. * 发送消息:新课程发布,商学院发布范围内的经销商/人员
  240. *
  241. * @param id
  242. * @throws YosException
  243. */
  244. public void sendMsg(Long id) throws YosException {
  245. SQLFactory sqlFactory = new SQLFactory(this, "查询范围内的账号");
  246. sqlFactory.addParameter("siteid", siteid);
  247. sqlFactory.addParameter("sat_noticeid", id);
  248. Rows useridRows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  249. if (useridRows.isNotEmpty()) {
  250. for (Row row : useridRows) {
  251. Long tempUserid = row.getLong("userid");
  252. if (tempUserid != 0) {
  253. Remind remind = new Remind(this);
  254. remind.setType("应用");
  255. remind.setTitle("新通告发布");
  256. remind.setContent("您有新的通告,请查看!");
  257. remind.setTouserid(tempUserid);
  258. remind.sendByDialogMsg().createSys_message();
  259. remind.setToemail(User.getUserMailAddress(this, tempUserid));
  260. remind.sendByMail();
  261. }
  262. }
  263. }
  264. }
  265. /**
  266. * 通告下架
  267. *
  268. * @return
  269. */
  270. @API(title = "下架", apiversion = R.ID20221101095303.v1.class)
  271. @CACHEING_CLEAN(apiversions = {R.ID20221111090904.v1.class, R.ID20221101094903.v1.class})
  272. public String undercarriage() throws YosException {
  273. JSONArray sat_noticeids = content.getJSONArray("sat_noticeids");
  274. String[] s = {"sat_noticeids"};
  275. for (String s1 : s) {
  276. if (!content.containsKey(s1))
  277. return getErrReturnObject().setErrMsg("缺少" + s1 + "参数").toString();
  278. }
  279. List<String> list = sat_noticeids.toJavaList(String.class);
  280. String[] stringArray = list.toArray(new String[0]);
  281. SQLFactory sqlFactoryquery = new SQLFactory(this, "通告状态查询");
  282. sqlFactoryquery.addParameter("siteid", siteid);
  283. sqlFactoryquery.addParameter_in("sat_noticeids", stringArray);
  284. Rows rows = dbConnect.runSqlQuery(sqlFactoryquery);
  285. for (Row row : rows) {
  286. if (row.getString("status").equals("新建")) {
  287. return getErrReturnObject().setErrMsg("【" + row.getString("title") + "】通告已下架,无法再次下架").toString();
  288. }
  289. }
  290. SQLFactory sqlFactoryupdate = new SQLFactory(this, "通告下架");
  291. sqlFactoryupdate.addParameter("siteid", siteid);
  292. sqlFactoryupdate.addParameter_in("sat_noticeids", stringArray);
  293. dbConnect.runSqlUpdate(sqlFactoryupdate);
  294. //发送消息
  295. for (String id : stringArray) {
  296. if (rows.isNotEmpty()) {
  297. sendOffMsg(Long.parseLong(id), rows.get(0).getString("title"));
  298. }
  299. }
  300. return getSucReturnObject().toString();
  301. }
  302. /**
  303. * 发送消息:新课程发布,商学院发布范围内的经销商/人员
  304. *
  305. * @param id
  306. * @throws YosException
  307. */
  308. public void sendOffMsg(Long id, String title) throws YosException {
  309. SQLFactory sqlFactory = new SQLFactory(this, "查询范围内的账号");
  310. sqlFactory.addParameter("siteid", siteid);
  311. sqlFactory.addParameter("sat_noticeid", id);
  312. Rows useridRows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  313. if (useridRows.isNotEmpty()) {
  314. for (Row row : useridRows) {
  315. Long tempUserid = row.getLong("userid");
  316. if (tempUserid != 0) {
  317. Remind remind = new Remind(this);
  318. remind.setType("应用");
  319. remind.setTitle("通告取消");
  320. remind.setContent("通告【" + title + "】已取消发布,请查看!");
  321. remind.setTouserid(tempUserid);
  322. remind.sendByDialogMsg().createSys_message();
  323. remind.setToemail(User.getUserMailAddress(this, tempUserid));
  324. remind.sendByMail();
  325. }
  326. }
  327. }
  328. }
  329. /**
  330. * 通告置顶
  331. *
  332. * @return
  333. */
  334. @API(title = "置顶", apiversion = R.ID20221101095403.v1.class)
  335. @CACHEING_CLEAN(cms = {@cm(clazz = notice.class, method = {"queryNoticeList"})})
  336. public String topping() throws YosException {
  337. String[] s = {"sat_noticeid"};
  338. for (String s1 : s) {
  339. if (!content.containsKey(s1))
  340. return getErrReturnObject().setErrMsg("缺少" + s1 + "参数").toString();
  341. }
  342. String sqlName = "SELECT COUNT(*) count FROM sat_notice WHERE sat_noticeid = '"
  343. + content.getIntValue("sat_noticeid") + "' and isontop=1";
  344. Rows rowsName = dbConnect.runSqlQuery(sqlName);
  345. if (rowsName.get(0).getLong("count") > 0) {
  346. return getErrReturnObject().setErrMsg("此通告已置顶,无须再次置顶").toString();
  347. }
  348. dbConnect.runSqlUpdate("update sat_notice set isontop=0 where isontop=1 ");
  349. dbConnect.runSqlUpdate(
  350. "update sat_notice set isontop=1 where sat_noticeid=" + content.getIntValue("sat_noticeid"));
  351. return getSucReturnObject().toString();
  352. }
  353. /**
  354. * 通告取消置顶
  355. *
  356. * @return
  357. */
  358. @API(title = "取消置顶", apiversion = R.ID20221101095503.v1.class)
  359. @CACHEING_CLEAN(cms = {@cm(clazz = notice.class, method = {"queryNoticeList"})})
  360. public String cancelTopping() throws YosException {
  361. String[] s = {"sat_noticeid"};
  362. for (String s1 : s) {
  363. if (!content.containsKey(s1))
  364. return getErrReturnObject().setErrMsg("缺少" + s1 + "参数").toString();
  365. }
  366. String sqlName = "SELECT COUNT(*) count FROM sat_notice WHERE sat_noticeid = '"
  367. + content.getIntValue("sat_noticeid") + "' and isontop=0";
  368. Rows rowsName = dbConnect.runSqlQuery(sqlName);
  369. if (rowsName.get(0).getLong("count") > 0) {
  370. return getErrReturnObject().setErrMsg("此通告已取消置顶,无须再次取消").toString();
  371. }
  372. dbConnect.runSqlUpdate(
  373. "update sat_notice set isontop=0 where sat_noticeid=" + content.getIntValue("sat_noticeid"));
  374. return getSucReturnObject().toString();
  375. }
  376. /**
  377. * 更新阅读记录(通告留言和打分)
  378. *
  379. * @return
  380. */
  381. @API(title = "更新阅读记录", apiversion = R.ID20221101095603.v1.class)
  382. public String updateReadRecord() throws YosException {
  383. Long sat_noticeid = content.getLong("sat_noticeid");
  384. int score = content.getInteger("score");
  385. String leavemessage = content.getString("leavemessage");
  386. Rows rows = dbConnect.runSqlQuery("select sat_notice_readid FROM sat_notice_read WHERE siteid = '" + siteid
  387. + "' AND sat_noticeid = '" + sat_noticeid + "' AND createuserid = '" + userid + "'");
  388. if (rows.isEmpty()) {
  389. return getErrReturnObject().setErrMsg("阅读记录不存在,无法更新").toString();
  390. }
  391. SQLFactory sqlFactory = new SQLFactory(this, "阅读记录更新");
  392. sqlFactory.addParameter("leavemessage", leavemessage);
  393. sqlFactory.addParameter("score", score);
  394. sqlFactory.addParameter("siteid", siteid);
  395. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  396. sqlFactory.addParameter("userid", userid);
  397. dbConnect.runSqlUpdate(sqlFactory);
  398. return getSucReturnObject().toString();
  399. }
  400. /**
  401. * 查询阅读记录(通告留言和打分)
  402. *
  403. * @return
  404. */
  405. @API(title = "查询阅读记录", apiversion = R.ID20221101095703.v1.class)
  406. public String queryReadRecord() throws YosException {
  407. Long sat_noticeid = content.getLong("sat_noticeid");
  408. String where = " 1=1 ";
  409. if (content.containsKey("where")) {
  410. JSONObject whereObject = content.getJSONObject("where");
  411. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  412. where = where + " and (t1.leavemessage like'%" + whereObject.getString("condition")
  413. + "%' or t3.position like '%" + whereObject.getString("condition") + "%' or t1.createby like '%" + whereObject.getString("condition") + "%')";
  414. }
  415. if (whereObject.containsKey("score") && !"".equals(whereObject.getString("score"))) {
  416. where = where + " and t1.score ='" + whereObject.getString("score") + "' ";
  417. }
  418. if (whereObject.containsKey("usertype") && !"".equals(whereObject.getString("usertype"))) {
  419. where = where + " and t2.usertype ='" + whereObject.getString("usertype") + "' ";
  420. }
  421. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  422. where = where + " and t1.createdate >='" + whereObject.getString("begindate") + "'";
  423. }
  424. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  425. where = where + " and t1.createdate <='" + whereObject.getString("enddate") + "'";
  426. }
  427. }
  428. Rows rows = dbConnect
  429. .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" +
  430. " left join sys_usersite t2 on t1.createuserid=t2.userid and t1.siteid=t2.siteid\n" +
  431. " left join sys_enterprise_hr t3 on t1.createuserid=t3.userid and t1.siteid=t3.siteid\n" +
  432. " WHERE " + where + " and t1.siteid = '" + siteid + "' AND t1.sat_noticeid ='" + sat_noticeid + "' and !(isnull(t1.leavemessage) and t1.score=0)");
  433. return getSucReturnObject().setData(rows).toString();
  434. }
  435. @API(title = "更新下载附件记录")
  436. public String updateDownloadRecord() throws YosException {
  437. Long sat_noticeid = content.getLong("sat_noticeid");
  438. dbConnect.runSqlUpdate("UPDATE sat_notice_read SET isdownloadfile=1 WHERE siteid = '" + siteid
  439. + "' AND sat_noticeid = '" + sat_noticeid + "' AND createuserid = '" + userid + "'");
  440. return getSucReturnObject().toString();
  441. }
  442. @API(title = "通告阅读记录评分分析")
  443. public String scoreAnalysis() throws YosException {
  444. Long sat_noticeid = content.getLong("sat_noticeid");
  445. SQLFactory sqlFactory = new SQLFactory(this, "通告评分状况分析");
  446. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  447. sqlFactory.addParameter("siteid", siteid);
  448. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  449. return getSucReturnObject().setData(rows).toString();
  450. }
  451. /**
  452. * 通告阅读记录下载分析
  453. *
  454. * @return
  455. */
  456. @API(title = "通告阅读记录下载分析")
  457. public String fileDownloadAnalysis() throws YosException {
  458. Long sat_noticeid = content.getLong("sat_noticeid");
  459. SQLFactory sqlFactory = new SQLFactory(this, "通告附件下载状况分析");
  460. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  461. sqlFactory.addParameter("siteid", siteid);
  462. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  463. SQLFactory sqlFactory1 = new SQLFactory(this, "通告总人数统计查询");
  464. sqlFactory1.addParameter("sat_noticeid", sat_noticeid);
  465. sqlFactory1.addParameter("siteid", siteid);
  466. Rows rows1 = dbConnect.runSqlQuery(sqlFactory1);
  467. Rows rowscount = new Rows();
  468. Row row = new Row();
  469. row.put("sumcount", rows1.get(0).getLong("sumnum"));
  470. row.put("downloadcount", rows.get(0).getLong("downloadcount"));
  471. row.put("undownloadcount", rows1.get(0).getLong("sumnum") - rows.get(0).getLong("downloadcount"));
  472. rowscount.add(row);
  473. return getSucReturnObject().setData(rowscount).toString();
  474. }
  475. @API(title = "同板块间通告评分对比")
  476. public String scoreContrast() throws YosException {
  477. String where = " 1=1 ";
  478. int sat_notice_classid = content.getIntValue("sat_notice_classid");
  479. if (content.containsKey("where")) {
  480. JSONObject whereObject = content.getJSONObject("where");
  481. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  482. where = where + " and t1.checkdate >='" + whereObject.getString("begindate") + "'";
  483. }
  484. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  485. where = where + " and t1.checkdate <='" + whereObject.getString("enddate") + "'";
  486. }
  487. }
  488. SQLFactory sqlFactory = new SQLFactory(this, "同板块间通告评分对比");
  489. sqlFactory.addParameter_SQL("where", where);
  490. sqlFactory.addParameter("sat_notice_classid", sat_notice_classid);
  491. sqlFactory.addParameter("siteid", siteid);
  492. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  493. return getSucReturnObject().setData(rows).toString();
  494. }
  495. // 添加阅读记录
  496. public void addReadRecord(Long sat_noticeid) throws YosException {
  497. // 新增浏览次数
  498. dbConnect.runSqlUpdate("UPDATE sat_notice SET readcount=readcount+1 WHERE sat_noticeid='" + sat_noticeid + "'");
  499. // 查询当前用户的阅读记录是否存在
  500. String sql = "SELECT sat_notice_readid FROM sat_notice_read WHERE siteid = '" + siteid
  501. + "' AND sat_noticeid = '" + sat_noticeid + "' AND createuserid = '" + userid + "'";
  502. Rows rows = dbConnect.runSqlQuery(sql);
  503. if (rows.isEmpty()) {
  504. SQLFactory sqlFactory = new SQLFactory(this, "阅读记录新增");
  505. sqlFactory.addParameter("siteid", siteid);
  506. sqlFactory.addParameter("sat_notice_readid", createTableID("sat_notice_read"));
  507. sqlFactory.addParameter("createby", username);
  508. sqlFactory.addParameter("changeby", username);
  509. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  510. sqlFactory.addParameter("createuserid", userid);
  511. sqlFactory.addParameter("hrid", hrid);
  512. sqlFactory.addParameter("sa_agentsid", userInfo.getAgentsId());
  513. dbConnect.runSqlUpdate(sqlFactory);
  514. } else {
  515. SQLFactory sqlFactory = new SQLFactory(this, "阅读记录次数更新");
  516. sqlFactory.addParameter("siteid", siteid);
  517. sqlFactory.addParameter("sat_noticeid", sat_noticeid);
  518. sqlFactory.addParameter("userid", userid);
  519. sqlFactory.addParameter("hrid", hrid);
  520. sqlFactory.addParameter("sa_agentsid", userInfo.getAgentsId());
  521. dbConnect.runSqlUpdate(sqlFactory);
  522. }
  523. }
  524. }