DailySign.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. package restcontroller.webmanage.saletool.sharematerial;
  2. import beans.attachment.Attachment;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import common.Controller;
  6. import common.YosException;
  7. import common.annotation.API;
  8. import common.data.*;
  9. import restcontroller.R;
  10. import java.util.ArrayList;
  11. /**
  12. * 每日一签
  13. */
  14. public class DailySign extends Controller {
  15. /**
  16. * 构造函数
  17. *
  18. * @param content
  19. */
  20. public DailySign(JSONObject content) throws YosException {
  21. super(content);
  22. }
  23. String sat_sharematerial = "sat_sharematerial";
  24. @API(title = "每日一签-新增或更新", apiversion = R.ID20240319103802.v1.class)
  25. public String insertOrUpdate() throws YosException {
  26. Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  27. String ondate = content.getStringValueForDate("ondate", "yyyy-MM-dd", "null");
  28. if (!ondate.equals("null") && dbConnect.runSqlQuery("SELECT 1 from sat_sharematerial WHERE ondate='" + ondate + "' and siteid='" + siteid + "' and sat_sharematerialid != " + sat_sharematerialid).isNotEmpty()) {
  29. return getErrReturnObject().setErrMsg("上档日期已存在").toString();
  30. }
  31. if (sat_sharematerialid <= 0) {
  32. sat_sharematerialid = createTableID(sat_sharematerial);
  33. InsertSQL sqlFactory = SQLFactory.createInsertSQL(this, sat_sharematerial);
  34. sqlFactory.setSiteid(siteid);
  35. sqlFactory.setUniqueid(sat_sharematerialid);
  36. sqlFactory.setValue("classid", 1);
  37. sqlFactory.setValue("sys_enterpriseid", sys_enterpriseid);
  38. sqlFactory.setValue("ondate", ondate);
  39. sqlFactory.setValue("isqrcode", content.getBooleanValue("isqrcode"));
  40. sqlFactory.setValue("qrcodecontent", content.getStringValue("qrcodecontent", true));
  41. sqlFactory.setValue("notes", content.getStringValue("notes"));
  42. // sqlFactory.setValue("type", content.getStringValue("type"));
  43. sqlFactory.insert();
  44. content.put("sat_sharematerialid", sat_sharematerialid);
  45. }
  46. if (sat_sharematerialid > 0) {
  47. UpdateSQL sqlFactory = SQLFactory.createUpdateSQL(this, sat_sharematerial);
  48. sqlFactory.setUniqueid(sat_sharematerialid);
  49. sqlFactory.setSiteid(siteid);
  50. sqlFactory.setValue("ondate", ondate);
  51. sqlFactory.setValue("isqrcode", content.getBooleanValue("isqrcode"));
  52. sqlFactory.setValue("qrcodecontent", content.getStringValue("qrcodecontent", true));
  53. sqlFactory.setValue("notes", content.getStringValue("notes"));
  54. // sqlFactory.setValue("type", content.getStringValue("type"));
  55. sqlFactory.update();
  56. }
  57. return detail();
  58. }
  59. @API(title = "每日一签-详情", apiversion = R.ID20240319103902.v1.class)
  60. public String detail() throws YosException {
  61. Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  62. QuerySQL sqlFactory = SQLFactory.createQuerySQL(this, sat_sharematerial,
  63. "sat_sharematerialid", "type", "notes", "isqrcode", "qrcodecontent", "ondate");
  64. sqlFactory.setUniqueid(sat_sharematerialid);
  65. sqlFactory.setSiteid(siteid);
  66. Rows rows = sqlFactory.query();
  67. Row detailRow = new Row();
  68. if (rows.isNotEmpty()) {
  69. detailRow = rows.get(0);
  70. Rows attRows = getAttachmentUrl("sat_sharematerial", sat_sharematerialid);
  71. detailRow.put("attinfos", attRows);
  72. }
  73. return getSucReturnObject().setData(detailRow).toString();
  74. }
  75. @API(title = "每日一签-删除", apiversion = R.ID20240319104002.v1.class)
  76. public String delete() throws YosException {
  77. JSONArray sat_sharematerialids = content.getJSONArray("sat_sharematerialids");
  78. if (sat_sharematerialids.size() == 0) {
  79. return getErrReturnObject().setErrMsg("请选择要删除的数据").toString();
  80. }
  81. DeleteSQL sqlFactory = SQLFactory.createDeleteSQL(this, sat_sharematerial);
  82. sqlFactory.setSiteid(siteid);
  83. sqlFactory.setWhere("sat_sharematerialid", sat_sharematerialids.toArray());
  84. sqlFactory.delete();
  85. return getSucReturnObject().toString();
  86. }
  87. @API(title = "每日一签-列表", apiversion = R.ID20240319104102.v1.class)
  88. public String list() throws YosException {
  89. /*
  90. 过滤条件设置
  91. */
  92. StringBuffer where = new StringBuffer(" 1=1 ");
  93. if (content.containsKey("where")) {
  94. JSONObject whereObject = content.getJSONObject("where");
  95. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  96. where.append(" and (");
  97. where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
  98. where.append("or t1.notes like'%").append(whereObject.getString("condition")).append("%' ");
  99. where.append(")");
  100. }
  101. if (whereObject.containsKey("year") && !"".equals(whereObject.getString("year"))) {
  102. where.append(" and (");
  103. where.append("YEAR(t1.createdate)='").append(whereObject.getString("year")).append("' ");
  104. where.append(")");
  105. }
  106. if (whereObject.containsKey("month") && !"".equals(whereObject.getString("month"))) {
  107. where.append(" and (");
  108. where.append("MONTH(t1.createdate)='").append(whereObject.getString("month")).append("' ");
  109. where.append(")");
  110. }
  111. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  112. where.append(" and (");
  113. where.append("t1.createdate >='").append(whereObject.getString("begindate")).append(" 00:00:00' ");
  114. where.append(")");
  115. }
  116. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  117. where.append(" and (");
  118. where.append("t1.createdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
  119. where.append(")");
  120. }
  121. if (whereObject.containsKey("week") && !"".equals(whereObject.getString("week"))) {
  122. int week = whereObject.getIntValue("week");
  123. if (week == 0) {
  124. where.append(" and (WEEK(t1.ondate)=WEEK(CURRENT_DATE))");
  125. }
  126. if (week > 0) {
  127. where.append(" and (WEEK(t1.ondate)=WEEK(CURRENT_DATE)+" + week + ")");
  128. }
  129. if (week < 0) {
  130. where.append(" and (WEEK(t1.ondate)=WEEK(CURRENT_DATE)-" + Math.abs(week) + ")");
  131. }
  132. }
  133. }
  134. QuerySQL sqlFactory = SQLFactory.createQuerySQL(this, sat_sharematerial,
  135. "sat_sharematerialid", "type", "notes", "isqrcode", "qrcodecontent", "ondate", "readcount", "downloadcount", "createdate")
  136. .setTableAlias("t1");
  137. sqlFactory.setSiteid(siteid);
  138. sqlFactory.setWhere("classid", 1);
  139. sqlFactory.setWhere(where.toString());
  140. sqlFactory.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
  141. System.err.println(sqlFactory.getSQL());
  142. Rows rows = sqlFactory.query();
  143. ArrayList<Long> ids = rows.toArrayList("sat_sharematerialid", new ArrayList<>());
  144. // 附件
  145. RowsMap RowsMap = getAttachmentUrl(sat_sharematerial, ids);
  146. for (Row row : rows) {
  147. Rows Rows = RowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows());
  148. row.put("attinfos", Rows);
  149. }
  150. return getSucReturnObject().setData(rows).toString();
  151. }
  152. @API(title = "每日一签-下载浏览列表", apiversion = R.ID20240319104202.v1.class)
  153. public String downloadOrReadlist() throws YosException {
  154. StringBuffer where = new StringBuffer(" 1=1 ");
  155. if (content.containsKey("where")) {
  156. JSONObject whereObject = content.getJSONObject("where");
  157. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  158. where.append(" and (");
  159. where.append("t2.name like'%").append(whereObject.getString("condition")).append("%' ");
  160. // where.append("or t1.notes like'%").append(whereObject.getString("condition")).append("%' ");
  161. where.append(")");
  162. }
  163. }
  164. int type = content.getIntValue("type");
  165. Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  166. QuerySQL sqlFactory = SQLFactory.createQuerySQL(this, "sat_sharematerial_read")
  167. .setTableAlias("t1");
  168. sqlFactory.addJoinTable(JOINTYPE.left, "sys_users", "t2", "t2.userid=t1.createuserid", "name");
  169. sqlFactory.addQueryFields("address", "''");
  170. sqlFactory.setSiteid(siteid);
  171. sqlFactory.setWhere(where.toString());
  172. sqlFactory.setWhere("type", type);
  173. sqlFactory.setWhere("sat_sharematerialid", sat_sharematerialid);
  174. sqlFactory.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
  175. Rows rows = sqlFactory.query();
  176. for (Row row : rows) {
  177. row.put("headpic", getHeadPic(row.getLong("createuserid")));
  178. }
  179. return getSucReturnObject().setData(rows).toString();
  180. }
  181. // @API(title = "每日一签-下载列表", apiversion = R.ID20240319104302.v1.class)
  182. // public String downloadlist() {
  183. // return getSucReturnObject().toString();
  184. // }
  185. @API(title = "更新下载浏览记录", apiversion = R.ID20240319142702.v1.class)
  186. public String updateReadAndDownload() throws YosException {
  187. Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
  188. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sat_sharematerial_read");
  189. insertSQL.setUniqueid(createTableID("sat_sharematerial_read"));
  190. insertSQL.setSiteid(siteid);
  191. insertSQL.setValue("sat_sharematerialid", sat_sharematerialid);
  192. insertSQL.setValue("type", content.getIntValue("type"));
  193. insertSQL.insert();
  194. if (content.getIntValue("type") == 0) {
  195. dbConnect.runSqlUpdate("UPDATE sat_sharematerial SET downloadcount=downloadcount+1 WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
  196. }
  197. if (content.getIntValue("type") == 1) {
  198. dbConnect.runSqlUpdate("UPDATE sat_sharematerial SET readcount=readcount+1 WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
  199. }
  200. if (content.getIntValue("type") == 2) {
  201. dbConnect.runSqlUpdate("UPDATE sat_sharematerial SET mailcount=mailcount+1 WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
  202. }
  203. return getSucReturnObject().toString();
  204. }
  205. }