wechatapplet.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package com.cnd3b.restcontroller.customer.wechatapplet;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.cnd3b.common.Controller;
  4. import com.cnd3b.common.data.Row;
  5. import com.cnd3b.common.data.Rows;
  6. import com.cnd3b.common.data.RowsMap;
  7. import com.cnd3b.common.data.SQLFactory;
  8. import com.cnd3b.common.parameter.parameter;
  9. import com.cnd3b.utility.WebRequest;
  10. import com.cnd3b.utility.wechatdock.WechatDock_Enterprise;
  11. import org.apache.commons.codec.digest.DigestUtils;
  12. import p2.pao.PaoRemote;
  13. import p2.pao.PaoSetRemote;
  14. import p2.util.P2Exception;
  15. import java.text.SimpleDateFormat;
  16. import java.util.Calendar;
  17. public class wechatapplet extends Controller {
  18. /**
  19. * 构造函数
  20. *
  21. * @param content
  22. */
  23. public wechatapplet(JSONObject content) {
  24. super(content);
  25. }
  26. /**
  27. * 获取培训学习列表
  28. *
  29. * @return
  30. */
  31. public String getCoursewareList() throws P2Exception {
  32. String ttypedetailid = content.getString("ttypedetailid");
  33. String keywords = "";
  34. if (content.containsKey("keywords")) {
  35. keywords = content.getString("keywords");
  36. }
  37. SQLFactory sqlFactory = new SQLFactory(this, "查询课件列表", pageSize, pageNumber, " t1.createdate desc");
  38. sqlFactory.addParameter("ttypedetailid", ttypedetailid);
  39. sqlFactory.addParameter("keywords", "%" + keywords + "%");
  40. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  41. // RowsMap rowsMap = getAttachmentUrl("tarchives_sc", rows.toArrayList("tarchives_scid"), "video");
  42. //查询封面
  43. RowsMap rowsMapCover = getAttachmentUrl("tarchives_sc", rows.toArrayList("tarchives_scid"), "cover");
  44. for (Row row : rows) {
  45. // row.put("attinfos", rowsMap.get(row.getString("tarchives_scid")));
  46. Rows coverRows = rowsMapCover.get(row.getString("tarchives_scid"));
  47. if (!coverRows.isEmpty()) {
  48. row.put("cover", coverRows.get(0).getString("fobsurl"));
  49. } else {
  50. row.put("cover", "");
  51. }
  52. }
  53. createRequestLog();
  54. return getSucReturnObject().setDataByPaging(rows).preloading(1).toString();
  55. }
  56. /**
  57. * 获取课件详情
  58. *
  59. * @return
  60. */
  61. public String getCoursewareDetail() throws P2Exception {
  62. String tarchives_scid = content.getString("tarchives_scid");
  63. //已学习人数加一
  64. String sql = "UPDATE tarchives_sc SET fvisitors= CASE WHEN fvisitors IS NULL THEN 1 else fvisitors + 1 END where tarchives_scid='" + tarchives_scid + "'";
  65. dbConnect.runSqlUpdate(sql);
  66. SQLFactory sqlFactory = new SQLFactory(this, "查询课件详细");
  67. sqlFactory.addParameter("tarchives_scid", tarchives_scid);
  68. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  69. RowsMap rowsMap = getAttachmentUrl("tarchives_sc", rows.toArrayList("tarchives_scid"), "video");
  70. //查询封面
  71. RowsMap rowsMapCover = getAttachmentUrl("tarchives_sc", rows.toArrayList("tarchives_scid"), "cover");
  72. for (Row row : rows) {
  73. row.put("attinfos", rowsMap.get(row.getString("tarchives_scid")));
  74. Rows coverRows = rowsMapCover.get(row.getString("tarchives_scid"));
  75. if (!coverRows.isEmpty()) {
  76. row.put("cover", coverRows.get(0).getString("fobsurl"));
  77. }
  78. }
  79. if (rows.isEmpty()) {
  80. return getErrReturnObject().setErrMsg("未找到当前课件").toString();
  81. }
  82. createRequestLog();
  83. return getSucReturnObject().setData(rows.get(0)).toString();
  84. }
  85. /**
  86. * 获取分类
  87. *
  88. * @return
  89. * @throws P2Exception
  90. */
  91. public String getTypeList() throws P2Exception {
  92. String fusertype = content.getString("fusertype");
  93. String where = "";
  94. //1表示业务员
  95. if (fusertype.equals("1")) {
  96. where = "t1.fissaler ='1'";
  97. } else {
  98. where = "t1.fisagent ='1'";
  99. }
  100. String fparentid = content.getString("fparentid");
  101. SQLFactory sqlFactory = new SQLFactory(this, "分类");
  102. sqlFactory.addParameter_SQL("fparentid", fparentid);
  103. sqlFactory.addParameter_SQL("where", where);
  104. String sql = sqlFactory.getSQL();
  105. Rows rows = dbConnect.runSqlQuery(sql);
  106. createRequestLog();
  107. return getSucReturnObject().setData(rows).toString();
  108. }
  109. /**
  110. * 新增日志
  111. */
  112. private void createRequestLog() {
  113. new Thread() {
  114. @Override
  115. public void run() {
  116. String sql = "SELECT*FROM tuserrequestlog WHERE fdate='" + getDate_Str() + "' AND tuserid='" + parameter.tuserid + "'";
  117. Rows rows = dbConnect.runSqlQuery(sql);
  118. if (rows.isEmpty()) {
  119. SQLFactory sqlFactory = new SQLFactory(this, "新增日志");
  120. sqlFactory.addParameter("tuserrequestlogid", createTableID("tuserrequestlog", "tuserrequestlogid"));
  121. sqlFactory.addParameter("siteid", parameter.defaultsiteid);
  122. sqlFactory.addParameter("fdate", getDate_Str());
  123. sqlFactory.addParameter("flastrequestdate", getDateTime_Str());
  124. sqlFactory.addParameter("tuserid", parameter.tuserid);
  125. dbConnect.runSqlUpdate(sqlFactory.getSQL());
  126. } else {
  127. String id = rows.get(0).getString("tuserrequestlogid");
  128. String sqlUpdate = "UPDATE tuserrequestlog SET frequesttimes=frequesttimes+1,flastrequestdate = '" + getDateTime_Str() + "' WHERE tuserrequestlogid = '" + id + "'";
  129. dbConnect.runSqlUpdate(sqlUpdate);
  130. }
  131. }
  132. }.start();
  133. }
  134. }