|
@@ -0,0 +1,227 @@
|
|
|
+package restcontroller.webmanage.saletool.sharematerial;
|
|
|
+
|
|
|
+import beans.attachment.Attachment;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import common.Controller;
|
|
|
+import common.YosException;
|
|
|
+import common.annotation.API;
|
|
|
+import common.data.*;
|
|
|
+import restcontroller.R;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 每日一签
|
|
|
+ */
|
|
|
+public class DailySign extends Controller {
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ */
|
|
|
+ public DailySign(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ String sat_sharematerial = "sat_sharematerial";
|
|
|
+
|
|
|
+ @API(title = "每日一签-新增或更新", apiversion = R.ID20240319103802.v1.class)
|
|
|
+ public String insertOrUpdate() throws YosException {
|
|
|
+
|
|
|
+ Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
|
|
|
+
|
|
|
+ if (sat_sharematerialid <= 0) {
|
|
|
+ sat_sharematerialid = createTableID(sat_sharematerial);
|
|
|
+ InsertSQL sqlFactory = SQLFactory.createInsertSQL(this, sat_sharematerial);
|
|
|
+ sqlFactory.setSiteid(siteid);
|
|
|
+ sqlFactory.setUniqueid(sat_sharematerialid);
|
|
|
+ sqlFactory.setValue("sys_enterpriseid", sys_enterpriseid);
|
|
|
+ sqlFactory.setValue("ondate", content.getStringValueForDate("ondate", "yyyy-MM-dd", "null"));
|
|
|
+ sqlFactory.setValue("isqrcode", content.getBooleanValue("isqrcode"));
|
|
|
+ sqlFactory.setValue("qrcodecontent", content.getStringValue("qrcodecontent", true));
|
|
|
+ sqlFactory.setValue("notes", content.getStringValue("notes"));
|
|
|
+ sqlFactory.setValue("type", content.getStringValue("type"));
|
|
|
+ sqlFactory.insert();
|
|
|
+ content.put("sat_sharematerialid", sat_sharematerialid);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (sat_sharematerialid > 0) {
|
|
|
+ UpdateSQL sqlFactory = SQLFactory.createUpdateSQL(this, sat_sharematerial);
|
|
|
+ sqlFactory.setUniqueid(sat_sharematerialid);
|
|
|
+ sqlFactory.setSiteid(siteid);
|
|
|
+ sqlFactory.setValue("ondate", content.getStringValueForDate("ondate", "yyyy-MM-dd", "null"));
|
|
|
+ sqlFactory.setValue("isqrcode", content.getBooleanValue("isqrcode"));
|
|
|
+ sqlFactory.setValue("qrcodecontent", content.getStringValue("qrcodecontent", true));
|
|
|
+ sqlFactory.setValue("notes", content.getStringValue("notes"));
|
|
|
+ sqlFactory.setValue("type", content.getStringValue("type"));
|
|
|
+ sqlFactory.update();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return detail();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "每日一签-详情", apiversion = R.ID20240319103902.v1.class)
|
|
|
+ public String detail() throws YosException {
|
|
|
+ Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
|
|
|
+
|
|
|
+ QuerySQL sqlFactory = SQLFactory.createQuerySQL(this, sat_sharematerial,
|
|
|
+ "sat_sharematerialid", "type", "notes", "isqrcode", "qrcodecontent", "ondate");
|
|
|
+ sqlFactory.setUniqueid(sat_sharematerialid);
|
|
|
+ sqlFactory.setSiteid(siteid);
|
|
|
+ Rows rows = sqlFactory.query();
|
|
|
+
|
|
|
+ Row detailRow = new Row();
|
|
|
+ if (rows.isNotEmpty()) {
|
|
|
+ detailRow = rows.get(0);
|
|
|
+ Rows attRows = getAttachmentUrl("sat_sharematerial", sat_sharematerialid);
|
|
|
+ detailRow.put("attinfos", attRows);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(detailRow).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "每日一签-删除", apiversion = R.ID20240319104002.v1.class)
|
|
|
+ public String delete() throws YosException {
|
|
|
+
|
|
|
+ JSONArray sat_sharematerialids = content.getJSONArray("sat_sharematerialids");
|
|
|
+ if (sat_sharematerialids.size() == 0) {
|
|
|
+ return getErrReturnObject().setErrMsg("请选择要删除的数据").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ DeleteSQL sqlFactory = SQLFactory.createDeleteSQL(this, sat_sharematerial);
|
|
|
+ sqlFactory.setSiteid(siteid);
|
|
|
+ sqlFactory.setWhere("sat_sharematerialid", sat_sharematerialids.toArray());
|
|
|
+ sqlFactory.delete();
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "每日一签-列表", apiversion = R.ID20240319104102.v1.class)
|
|
|
+ public String list() throws YosException {
|
|
|
+
|
|
|
+ /*
|
|
|
+ 过滤条件设置
|
|
|
+ */
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
+ if (content.containsKey("where")) {
|
|
|
+ JSONObject whereObject = content.getJSONObject("where");
|
|
|
+ if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t1.title like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.notes like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (whereObject.containsKey("year") && !"".equals(whereObject.getString("year"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("YEAR(t1.createdate)='").append(whereObject.getString("year")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("month") && !"".equals(whereObject.getString("month"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("MONTH(t1.createdate)='").append(whereObject.getString("month")).append("' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t1.createdate >='").append(whereObject.getString("begindate")).append(" 00:00:00' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t1.createdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ QuerySQL sqlFactory = SQLFactory.createQuerySQL(this, sat_sharematerial,
|
|
|
+ "sat_sharematerialid", "type", "notes", "isqrcode", "qrcodecontent", "ondate", "readcount", "downloadcount", "createdate")
|
|
|
+ .setTableAlias("t1");
|
|
|
+ sqlFactory.setSiteid(siteid);
|
|
|
+ sqlFactory.setWhere(where.toString());
|
|
|
+ sqlFactory.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
|
|
|
+ Rows rows = sqlFactory.query();
|
|
|
+
|
|
|
+ ArrayList<Long> ids = rows.toArrayList("sat_sharematerialid", new ArrayList<>());
|
|
|
+ // 附件
|
|
|
+ RowsMap RowsMap = getAttachmentUrl(sat_sharematerial, ids);
|
|
|
+ for (Row row : rows) {
|
|
|
+ Rows Rows = RowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows());
|
|
|
+ row.put("attinfos", Rows);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "每日一签-下载浏览列表", apiversion = R.ID20240319104202.v1.class)
|
|
|
+ public String downloadOrReadlist() throws YosException {
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
+ if (content.containsKey("where")) {
|
|
|
+ JSONObject whereObject = content.getJSONObject("where");
|
|
|
+ if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
|
|
|
+ where.append(" and (");
|
|
|
+ where.append("t2.name like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+// where.append("or t1.notes like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean isdownload=content.getBooleanValue("isdownload");
|
|
|
+ Long sat_sharematerialid=content.getLongValue("sat_sharematerialid");
|
|
|
+
|
|
|
+ QuerySQL sqlFactory = SQLFactory.createQuerySQL(this, "sat_sharematerial_read")
|
|
|
+ .setTableAlias("t1");
|
|
|
+ sqlFactory.addJoinTable(JOINTYPE.left,"sys_users","t2","t2.userid=t1.createuserid","name");
|
|
|
+ sqlFactory.addQueryFields("address","''");
|
|
|
+ sqlFactory.setSiteid(siteid);
|
|
|
+ sqlFactory.setWhere(where.toString());
|
|
|
+ sqlFactory.setWhere("isdownload",isdownload);
|
|
|
+ sqlFactory.setWhere("sat_sharematerialid",sat_sharematerialid);
|
|
|
+ sqlFactory.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
|
|
|
+ Rows rows = sqlFactory.query();
|
|
|
+
|
|
|
+ ArrayList<Long> ids = rows.toArrayList("createuserid", new ArrayList<>());
|
|
|
+ // 附件
|
|
|
+ RowsMap RowsMap = Attachment.get(this,"sys_users",ids);
|
|
|
+ for (Row row : rows) {
|
|
|
+ Rows Rows = RowsMap.getOrDefault(row.getString("createuserid"), new Rows());
|
|
|
+ row.put("attinfos", Rows);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+// @API(title = "每日一签-下载列表", apiversion = R.ID20240319104302.v1.class)
|
|
|
+// public String downloadlist() {
|
|
|
+// return getSucReturnObject().toString();
|
|
|
+// }
|
|
|
+
|
|
|
+ @API(title = "更新下载浏览记录", apiversion = R.ID20240319142702.v1.class)
|
|
|
+ public String updateReadAndDownload() throws YosException {
|
|
|
+
|
|
|
+ Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
|
|
|
+
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sat_sharematerial_read");
|
|
|
+ insertSQL.setUniqueid(createTableID("sat_sharematerial_read"));
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("sat_sharematerialid", sat_sharematerialid);
|
|
|
+ insertSQL.setValue("isdownload", content.getBooleanValue("isdownload"));
|
|
|
+ insertSQL.insert();
|
|
|
+
|
|
|
+ if (content.getBooleanValue("isdownload")) {
|
|
|
+ dbConnect.runSqlUpdate("UPDATE sat_sharematerial SET downloadcount=downloadcount+1 WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
|
|
|
+ } else {
|
|
|
+ dbConnect.runSqlUpdate("UPDATE sat_sharematerial SET readcount=readcount+1 WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
|
|
|
+ }
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|