123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- 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");
- String ondate = content.getStringValueForDate("ondate", "yyyy-MM-dd", "null");
- if (!ondate.equals("null") && dbConnect.runSqlQuery("SELECT 1 from sat_sharematerial WHERE ondate='" + ondate + "' and siteid='" + siteid + "' and sat_sharematerialid != " + sat_sharematerialid).isNotEmpty()) {
- return getErrReturnObject().setErrMsg("上档日期已存在").toString();
- }
- 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("classid", 1);
- sqlFactory.setValue("sys_enterpriseid", sys_enterpriseid);
- sqlFactory.setValue("ondate", ondate);
- 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", ondate);
- 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(")");
- }
- if (whereObject.containsKey("week") && !"".equals(whereObject.getString("week"))) {
- int week = whereObject.getIntValue("week");
- if (week == 0) {
- where.append(" and (WEEK(t1.ondate)=WEEK(CURRENT_DATE))");
- }
- if (week > 0) {
- where.append(" and (WEEK(t1.ondate)=WEEK(CURRENT_DATE)+" + week + ")");
- }
- if (week < 0) {
- where.append(" and (WEEK(t1.ondate)=WEEK(CURRENT_DATE)-" + Math.abs(week) + ")");
- }
- }
- }
- QuerySQL sqlFactory = SQLFactory.createQuerySQL(this, sat_sharematerial,
- "sat_sharematerialid", "type", "notes", "isqrcode", "qrcodecontent", "ondate", "readcount", "downloadcount", "createdate")
- .setTableAlias("t1");
- sqlFactory.setSiteid(siteid);
- sqlFactory.setWhere("classid", 1);
- sqlFactory.setWhere(where.toString());
- sqlFactory.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
- System.err.println(sqlFactory.getSQL());
- 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(")");
- }
- }
- int type = content.getIntValue("type");
- 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("type", type);
- sqlFactory.setWhere("sat_sharematerialid", sat_sharematerialid);
- sqlFactory.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
- Rows rows = sqlFactory.query();
- for (Row row : rows) {
- row.put("headpic", getHeadPic(row.getLong("createuserid")));
- }
- 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("type", content.getIntValue("type"));
- insertSQL.insert();
- if (content.getIntValue("type") == 0) {
- dbConnect.runSqlUpdate("UPDATE sat_sharematerial SET downloadcount=downloadcount+1 WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
- }
- if (content.getIntValue("type") == 1) {
- dbConnect.runSqlUpdate("UPDATE sat_sharematerial SET readcount=readcount+1 WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
- }
- if (content.getIntValue("type") == 2) {
- dbConnect.runSqlUpdate("UPDATE sat_sharematerial SET mailcount=mailcount+1 WHERE sat_sharematerialid=" + sat_sharematerialid + " and siteid='" + siteid + "'");
- }
- return getSucReturnObject().toString();
- }
- }
|