noticemag.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. package com.cnd3b.restcontroller.enterprise.noticemag;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.cnd3b.common.Controller;
  5. import com.cnd3b.common.D3bException;
  6. import com.cnd3b.common.data.Row;
  7. import com.cnd3b.common.data.Rows;
  8. import com.cnd3b.common.data.RowsMap;
  9. import com.cnd3b.common.data.SQLFactory;
  10. import com.cnd3b.common.data.db.DataPool;
  11. import p2.pao.PaoRemote;
  12. import p2.pao.PaoSetRemote;
  13. import p2.util.P2Exception;
  14. import java.util.ArrayList;
  15. import java.util.Date;
  16. import java.util.Iterator;
  17. public class noticemag extends Controller {
  18. public noticemag(JSONObject content) {
  19. super(content);
  20. }
  21. /**
  22. * 通告列表查询
  23. *
  24. * @return
  25. */
  26. public String query_noticeList() {
  27. /**
  28. *排序条件设置
  29. */
  30. String[] sortfield = {"t1.fisontop desc,t1.checkdate desc"};
  31. String sort = getSort(sortfield, "t1.fisontop desc,t1.checkdate desc");
  32. /**
  33. * 过滤条件设置
  34. */
  35. StringBuffer where = new StringBuffer(" 1=1 ");
  36. if (content.containsKey("where")) {
  37. JSONObject whereObject = content.getJSONObject("where");
  38. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  39. where.append(" and(");
  40. where.append("t1.ftitle like'%").append(whereObject.getString("condition")).append("%' ");
  41. where.append("or t1.ftype like'%").append(whereObject.getString("condition")).append("%' ");
  42. where.append("or t1.fsummary like'%").append(whereObject.getString("condition")).append("%' ");
  43. where.append(")");
  44. }
  45. if (whereObject.containsKey("ftype") && !"".equals(whereObject.getString("ftype"))) {
  46. where.append(" and t1.ftype='").append(whereObject.getString("ftype")).append("'");
  47. }
  48. }
  49. SQLFactory noticehead = new SQLFactory(this, "通告列表查询", pageSize, pageNumber, sort);
  50. noticehead.addParameter("siteid", siteid);
  51. noticehead.addParameter_SQL("where", where);
  52. Rows rows = dbConnect.runSqlQuery(noticehead.getSQL());
  53. ArrayList<String> tnoticeidlist = rows.toArrayList("tnoticeid");
  54. //通告附件数量查询
  55. RowsMap attinfocountmap = getAttachmentQty("tnotice", tnoticeidlist);
  56. //通告封面图查询
  57. RowsMap noticecovermap = getAttachmentUrl("tnotice", tnoticeidlist, "cover");
  58. for (Row row : rows) {
  59. String tnoticeid = row.getString("tnoticeid");
  60. row.put("fattachmentcount", attinfocountmap.containsKey(tnoticeid) ? attinfocountmap.get(tnoticeid).getRow(0).getInteger("fattachmentcount") : 0);
  61. row.put("attinfos", noticecovermap.get(tnoticeid));
  62. row.put("headportraiturl", getHeadPic(row.getLong("tenterprise_userid")));
  63. }
  64. return getSucReturnObject().setDataByPaging(rows, sortfield).setFinalDo(DataPool.defaultdatalife, 1);
  65. }
  66. /**
  67. * 通告主界面查询
  68. *
  69. * @return
  70. */
  71. public String query_noticeMain() {
  72. String tnoticeid = content.getString("tnoticeid");
  73. SQLFactory noticehead = new SQLFactory(this, "通告主界面查询");
  74. noticehead.addParameter("siteid", siteid);
  75. noticehead.addParameter("tnoticeid", tnoticeid);
  76. Rows rows = dbConnect.runSqlQuery(noticehead.getSQL());
  77. Rows attinfosRows = getAttachmentUrl("tnotice", tnoticeid);
  78. rows.get(0).put("attinfos", attinfosRows);
  79. rows.get(0).put("headportraiturl", getHeadPic(rows.get(0).getLong("tenterprise_userid")));
  80. return getSucReturnObject().setData(rows).toString();
  81. }
  82. /**
  83. * 通告置顶
  84. *
  85. * @return
  86. */
  87. public String noticeontop() {
  88. String tnoticeid = content.getString("tnoticeid");
  89. int fisontop = content.getInteger("fisontop");//是否置顶
  90. String status = dbConnect.runSqlUpdate("update tnotice set fisontop=" + fisontop + ", changeby='" + username + "',changedate=getdate() where siteid='" + siteid + "' and tnoticeid='" + tnoticeid + "'");
  91. if ("true".equals(status)) {
  92. return getSucReturnObject().toString();
  93. } else {
  94. return getErrReturnObject().setErrMsg(status).toString();
  95. }
  96. }
  97. /**
  98. * 通告新增、修改
  99. *
  100. * @return
  101. */
  102. public String insertOrModify() throws D3bException, P2Exception {
  103. long tnoticeid = content.getLongValue("tnoticeid"); //新增时默认传0
  104. String ftype = content.getString("ftype");//通告类型
  105. String ftitle = content.getString("ftitle", "tnotice.ftitle", "标题");//标题
  106. String fsummary = content.getString("fsummary", "tnotice.fsummary", "通告导语");//概述、导读
  107. String fcontent = content.getString("fcontent", "tnotice.fcontent", "正文");//通告内容
  108. boolean fishomepage = content.getBooleanValue("fishomepage");//门户可见
  109. boolean fischeckagent = content.getBooleanValue("fischeckagent");//认证商户可见
  110. boolean fisagentsubuser = content.getBooleanValue("fisagentsubuser");//认证商户子账号可见
  111. boolean fisspecifiedrange = content.getBooleanValue("fisspecifiedrange");//指定认证商户范围
  112. boolean fissingleagent = content.getBooleanValue("fissingleagent");//个人商户可见
  113. boolean fisontop = content.getBooleanValue("fisontop");//是否置顶
  114. Date fbegdate = content.getDate("fbegdate");//开始时间
  115. Date fenddate = content.getDate("fenddate");//结束时间
  116. PaoSetRemote tnoticeSet = getP2ServerSystemPaoSet("tnotice", "siteid='" + siteid + "' and tnoticeid='" + tnoticeid + "'");
  117. PaoRemote tnotice = null;
  118. if (tnoticeid <= 0 || tnoticeSet.isEmpty()) {
  119. tnotice = tnoticeSet.addAtEnd();
  120. tnotice.setValue("siteid", siteid, 11L);//企业ID
  121. tnotice.setValue("createby", username, 11L);//录入人
  122. tnotice.setValue("createdate", sysdate, 11L);//录入时间
  123. tnotice.setValue("tenterprise_userid", userid, 11L);//创建者id
  124. } else {
  125. tnotice = tnoticeSet.getPao(0);
  126. }
  127. tnotice.setValue("ftype", ftype, 11L);//通告类型
  128. tnotice.setValue("ftitle", ftitle, 11L);//标题
  129. tnotice.setValue("fsummary", fsummary, 11L);//概述、导读
  130. tnotice.setValue("fcontent", fcontent, 11L);//通告内容
  131. tnotice.setValue("fishomepage", fishomepage, 11L);//门户可见
  132. tnotice.setValue("fischeckagent", fischeckagent, 11L);//认证商户可见
  133. tnotice.setValue("fisagentsubuser", fisagentsubuser, 11L);//认证商户子账号可见
  134. tnotice.setValue("fisspecifiedrange", fisspecifiedrange, 11L);//指定认证商户范围
  135. tnotice.setValue("fissingleagent", fissingleagent, 11L);//个人商户可见
  136. tnotice.setValue("fisontop", fisontop, 11L);//是否置顶
  137. tnotice.setValue("fbegdate", fbegdate, 11L);//开始时间
  138. tnotice.setValue("fenddate", fenddate, 11L);//结束时间
  139. tnotice.setValue("changeby", username, 11L);//修改人
  140. tnotice.setValue("changedate", sysdate, 11L);//修改时间
  141. content.put("tnoticeid", tnotice.getUniqueIDValue());
  142. tnoticeSet.save();
  143. return query_noticeMain();
  144. }
  145. /**
  146. * 发布
  147. *
  148. * @return
  149. */
  150. public String check() {
  151. String tnoticeid = content.getString("tnoticeid");
  152. boolean fischeck = content.getBooleanValue("fischeck");//是否发布
  153. SQLFactory sqlFactory = null;
  154. if (fischeck) {
  155. sqlFactory = new SQLFactory(this, "通告发布");
  156. sqlFactory.addParameter("checkby", username);
  157. } else {
  158. sqlFactory = new SQLFactory(this, "通告取消发布");
  159. }
  160. sqlFactory.addParameter("siteid", siteid);
  161. sqlFactory.addParameter("tnoticeid", tnoticeid);
  162. String status = dbConnect.runSqlUpdate(sqlFactory.getSQL());
  163. if ("true".equalsIgnoreCase(status)) {
  164. return getSucReturnObject().toString();
  165. } else {
  166. return getErrReturnObject().setErrMsg(status).toString();
  167. }
  168. }
  169. /**
  170. * 通告删除
  171. *
  172. * @return
  173. */
  174. public String delete() {
  175. long tnoticeid = content.getLongValue("tnoticeid");
  176. if (dbConnect.runSqlQuery("select * from tnotice where siteid='" + siteid + "' and fstatus='新建' and tnoticeid=" + tnoticeid).isEmpty()) {
  177. return getErrReturnObject().setErrMsg("当前状态不可删除").toString();
  178. }
  179. SQLFactory sqlFactory = new SQLFactory(this, "通告删除");
  180. sqlFactory.addParameter("siteid", siteid);
  181. sqlFactory.addParameter("tnoticeid", tnoticeid);
  182. String result = dbConnect.runSqlUpdate(sqlFactory.getSQL());
  183. if ("true".equals(result)) {
  184. return getSucReturnObject().toString();
  185. } else {
  186. return getErrReturnObject().setErrMsg(result).toString();
  187. }
  188. }
  189. /**
  190. * 已浏览用户列表
  191. *
  192. * @return
  193. */
  194. public String havereaduserlist() {
  195. String tnoticeid = content.getString("tnoticeid");
  196. /**
  197. *排序条件设置
  198. */
  199. String[] sortfield = {"t1.tenterprise_userid"};
  200. String sort = getSort(sortfield, "t1.tenterprise_userid");
  201. SQLFactory factory = new SQLFactory(this, "浏览用户列表", pageSize, pageNumber, sort);
  202. factory.addParameter("siteid", siteid);
  203. factory.addParameter("tnoticeid", tnoticeid);
  204. Rows rows = dbConnect.runSqlQuery(factory.getSQL());
  205. return getSucReturnObject().setDataByPaging(rows).setFinalDo(DataPool.defaultdatalife, 1);
  206. }
  207. /**
  208. * 查询通告人员
  209. *
  210. * @return
  211. */
  212. public String query_noticeuserList() {
  213. String tnoticeid = content.getString("tnoticeid");
  214. /**
  215. *排序条件设置
  216. */
  217. String[] sortfield = {"t1.tnotice_usersid"};
  218. String sort = getSort(sortfield, "t1.tnotice_usersid");
  219. /**
  220. * 过滤条件设置
  221. */
  222. StringBuffer where = new StringBuffer(" 1=1 ");
  223. if (content.containsKey("where")) {
  224. JSONObject whereObject = content.getJSONObject("where");
  225. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  226. where.append(" and(");
  227. where.append("t2.fname like'%").append(whereObject.getString("condition")).append("%' ");
  228. where.append("t3.fagentname like'%").append(whereObject.getString("condition")).append("%' ");
  229. where.append("t3.fbrand like'%").append(whereObject.getString("condition")).append("%' ");
  230. where.append(")");
  231. }
  232. }
  233. SQLFactory sqlFactory = new SQLFactory(this, "查询通告人员", pageSize, pageNumber, sort);
  234. sqlFactory.addParameter("siteid", siteid);
  235. sqlFactory.addParameter("tnoticeid", tnoticeid);
  236. sqlFactory.addParameter_SQL("where", where);
  237. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  238. return getSucReturnObject().setDataByPaging(rows).setFinalDo(DataPool.defaultdatalife, 1);
  239. }
  240. /**
  241. * 添加通告人员
  242. *
  243. * @return
  244. */
  245. public String adduser() {
  246. String tnoticeid = content.getString("tnoticeid");
  247. JSONArray idarray = content.getJSONArray("tagentsid");
  248. Iterator<Object> it = idarray.iterator();
  249. ArrayList<String> list = new ArrayList<>();
  250. while (it.hasNext()) {
  251. SQLFactory sqlFactory = new SQLFactory(this, "添加通告人员");
  252. sqlFactory.addParameter("siteid", siteid);
  253. sqlFactory.addParameter("createby", username);
  254. sqlFactory.addParameter("tnoticeid", tnoticeid);
  255. sqlFactory.addParameter("tagentsid", String.valueOf(it.next()));
  256. list.add(sqlFactory.getSQL());
  257. }
  258. if (!list.isEmpty()) {
  259. String status = dbConnect.runSqlUpdate(list);
  260. if ("true".equals(status)) {
  261. return getSucReturnObject().toString();
  262. } else {
  263. return getErrReturnObject().setErrMsg(status).toString();
  264. }
  265. }
  266. return getErrReturnObject().setErrMsg("没有选择添加人员").toString();
  267. }
  268. /**
  269. * 删除提报人员
  270. *
  271. * @return
  272. */
  273. public String deleteuser() {
  274. String tnoticeid = content.getString("tnoticeid");
  275. JSONArray idarray = content.getJSONArray("tagentsid");
  276. Iterator<Object> it = idarray.iterator();
  277. ArrayList<String> list = new ArrayList<>();
  278. while (it.hasNext()) {
  279. SQLFactory sqlFactory = new SQLFactory(this, "删除通告人员");
  280. sqlFactory.addParameter("siteid", siteid);
  281. sqlFactory.addParameter("createby", username);
  282. sqlFactory.addParameter("tnoticeid", tnoticeid);
  283. sqlFactory.addParameter("tagentsid", (String) it.next());
  284. list.add(sqlFactory.getSQL());
  285. }
  286. if (!list.isEmpty()) {
  287. String status = dbConnect.runSqlUpdate(list);
  288. if ("true".equals(status)) {
  289. return getSucReturnObject().toString();
  290. } else {
  291. return getErrReturnObject().setErrMsg(status).toString();
  292. }
  293. }
  294. return getErrReturnObject().setErrMsg("没有选择删除人员").toString();
  295. }
  296. }