| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- 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 EquipmentResourceLibrary extends Controller {
- /**
- * 构造函数
- *
- * @param content
- */
- public EquipmentResourceLibrary(JSONObject content) throws YosException {
- super(content);
- }
- String sat_sharematerial = "sat_sharematerial";
- @API(title = "装备资源库新增或编辑", apiversion = R.ID20240407094502.v1.class)
- public String insertOrUpdate() throws YosException {
- Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
- JSONArray sat_sharematerial_classids = new JSONArray();
- if (content.containsKey("sat_sharematerial_classids")) {
- sat_sharematerial_classids = content.getJSONArray("sat_sharematerial_classids");
- for (Object obj : sat_sharematerial_classids) {
- if (!(obj instanceof JSONArray)) {
- return getErrReturnObject().setErrMsg("格式不正确,正确的为[[1,2,3]]").toString();
- }
- }
- }
- if (sat_sharematerialid <= 0) {
- sat_sharematerialid = createTableID(sat_sharematerial);
- InsertSQL sqlFactory = SQLFactory.createInsertSQL(this, sat_sharematerial);
- sqlFactory.setUniqueid(sat_sharematerialid);
- sqlFactory.setSiteid(siteid);
- sqlFactory.setValue("sys_enterpriseid", sys_enterpriseid);
- sqlFactory.setValue("classid", 3);
- sqlFactory.setValue("title", content.getStringValue("title"));
- sqlFactory.setValue("sat_sharematerial_classids", sat_sharematerial_classids);
- sqlFactory.setValue("type", content.getIntValue("type"));
- sqlFactory.setValue("sequence", content.getLongValue("sequence"));
- sqlFactory.setValue("isqrcode", content.getBooleanValue("isqrcode"));
- sqlFactory.setValue("qrcodecontent", content.getStringValue("qrcodecontent", true));
- sqlFactory.setValue("canshared_c", content.getBooleanValue("canshared_c"));
- sqlFactory.setValue("candownload", content.getBooleanValue("candownload"));
- sqlFactory.setValue("candownload_c", content.getBooleanValue("candownload_c"));
- 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("sys_enterpriseid", sys_enterpriseid);
- sqlFactory.setValue("title", content.getStringValue("title"));
- sqlFactory.setValue("sat_sharematerial_classids", sat_sharematerial_classids);
- sqlFactory.setValue("type", content.getIntValue("type"));
- sqlFactory.setValue("sequence", content.getLongValue("sequence"));
- sqlFactory.setValue("isqrcode", content.getBooleanValue("isqrcode"));
- sqlFactory.setValue("qrcodecontent", content.getStringValue("qrcodecontent", true));
- sqlFactory.setValue("canshared_c", content.getBooleanValue("canshared_c"));
- sqlFactory.setValue("candownload", content.getBooleanValue("candownload"));
- sqlFactory.setValue("candownload_c", content.getBooleanValue("candownload_c"));
- sqlFactory.update();
- }
- return detail();
- }
- @API(title = "装备资源库详情", apiversion = R.ID20240407094602.v1.class)
- public String detail() throws YosException {
- Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
- QuerySQL sqlFactory = SQLFactory.createQuerySQL(this, sat_sharematerial
- , "sat_sharematerialid", "type", "status", "sequence", "title", "canshared_c", "candownload_c", "candownload"
- , "sat_sharematerial_classids", "mailcount", "canshared", "downloadcount", "isqrcode", "qrcodecontent", "sharecount", "readcount"
- , "createby", "createdate", "checkby", "checkdate", "changeby", "changedate")
- .setTableAlias("t1");
- sqlFactory.setUniqueid(sat_sharematerialid);
- sqlFactory.setSiteid(siteid);
- Rows rows = sqlFactory.query();
- QuerySQL dataauth = SQLFactory.createQuerySQL(this, "sys_dataauth").setTableAlias("t1");
- dataauth.setWhere("siteid", siteid);
- dataauth.setWhere("ownertable", "sat_sharematerial");
- dataauth.setWhere("ownerid", sat_sharematerialid);
- Rows dataauthRows = dataauth.query();
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_dataauths",
- "roleid");
- querySQL.addJoinTable(JOINTYPE.inner, "sys_role", "t2", "t1.roleid=t2.roleid and t1.siteid=t2.siteid",
- "rolename");
- querySQL.setTableAlias("t1");
- querySQL.setWhere("t1.siteid", siteid);
- querySQL.setWhere("t1.ownertable", "sat_sharematerial");
- querySQL.setWhere("t1.ownerid", sat_sharematerialid);
- Rows roleRows = querySQL.query();
- Row detailRow = new Row();
- if (rows.isNotEmpty()) {
- detailRow = rows.get(0);
- Rows attRows = getAttachmentUrl("sat_sharematerial", sat_sharematerialid);
- detailRow.put("attinfos", attRows);
- detailRow.putIfAbsent("checkdate", "");
- if (detailRow.getInteger("type") == 1) {
- detailRow.put("typestr", "图片");
- }
- if (detailRow.getInteger("type") == 2) {
- detailRow.put("typestr", "视频");
- }
- if (detailRow.getInteger("type") == 3) {
- detailRow.put("typestr", "图文");
- }
- detailRow.put("role", roleRows.toArrayList("roleid", new ArrayList<Long>()));
- detailRow.put("dataauth", dataauthRows);
- }
- return getSucReturnObject().setData(detailRow).toString();
- }
- @API(title = "装备资源库列表", apiversion = R.ID20240407094702.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(")");
- }
- if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
- where.append(" and (");
- where.append("t1.status ='").append(whereObject.getString("status")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
- where.append(" and (");
- where.append("t1.type ='").append(whereObject.getString("type")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("begindate_create") && !"".equals(whereObject.getString("begindate_create"))) {
- where.append(" and (");
- where.append("t1.createdate >='").append(whereObject.getString("begindate_create")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("enddate_create") && !"".equals(whereObject.getString("enddate_create"))) {
- where.append(" and (");
- where.append("t1.createdate <='").append(whereObject.getString("enddate_create")).append(" 23:59:59' ");
- where.append(")");
- }
- if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
- where.append(" and (");
- where.append("t1.checkdate >='").append(whereObject.getString("begindate")).append("' ");
- where.append(")");
- }
- if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
- where.append(" and (");
- where.append("t1.checkdate <='").append(whereObject.getString("enddate")).append(" 23:59:59' ");
- where.append(")");
- }
- if (whereObject.containsKey("sat_sharematerial_classids") && !"".equals(whereObject.getString("sat_sharematerial_classids"))) {
- JSONArray sat_courseware_classids = whereObject.getJSONArray("sat_sharematerial_classids");
- if (sat_courseware_classids.size() > 0) {
- where.append(" and (1=2");
- for (Object obj : sat_courseware_classids) {
- JSONArray array = (JSONArray) obj;
- for (Object obj2 : array) {
- where.append(" or (");
- where.append("JSON_CONTAINS(t1.sat_sharematerial_classids,'" + obj2 + "')");
- where.append(")");
- }
- }
- where.append(")");
- }
- }
- }
- QuerySQL sqlFactory = SQLFactory.createQuerySQL(this, sat_sharematerial,
- "sat_sharematerialid", "title", "type", "status", "mailcount", "readcount", "downloadcount", "createdate", "checkdate", "sat_sharematerial_classids")
- .setTableAlias("t1");
- sqlFactory.setSiteid(siteid);
- sqlFactory.setWhere("classid", 3);
- 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);
- row.putIfAbsent("checkdate", "");
- if (row.getInteger("type") == 1) {
- row.put("typestr", "图片");
- }
- if (row.getInteger("type") == 2) {
- row.put("typestr", "视频");
- }
- if (row.getInteger("type") == 3) {
- row.put("typestr", "图文");
- }
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "图片新增或编辑", apiversion = R.ID20240407135802.v1.class)
- public String attachmentInsertOrUpdate() throws YosException {
- Long linksid = content.getLongValue("linksid");
- String ownertable = content.getStringValue("ownertable");
- Long ownerid = content.getLongValue("ownerid");
- if (linksid <= 0) {
- linksid = createTableID("sys_attachment_links");
- InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_attachment_links");
- insertSQL.setSiteid(siteid);
- insertSQL.setUniqueid(linksid);
- insertSQL.setValue("usetype", ownertable);
- insertSQL.setValue("attachmentid", content.getLongValue("attachmentid"));
- insertSQL.setValue("jumpurl", content.getStringValue("jumpurl", true));
- insertSQL.setValue("sequence", content.getLongValue("sequence"));
- insertSQL.setValue("ownertable", ownertable);
- insertSQL.setValue("ownerid", ownerid);
- insertSQL.insert();
- }
- if (linksid > 0) {
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_attachment_links");
- updateSQL.setSiteid(siteid);
- updateSQL.setUniqueid(linksid);
- updateSQL.setValue("jumpurl", content.getStringValue("jumpurl", true));
- updateSQL.setValue("sequence", content.getLongValue("sequence"));
- updateSQL.update();
- }
- String sql = "SELECT * from sys_attachment_links WHERE linksid=" + linksid + " and siteid='" + siteid + "'";
- Rows rows = dbConnect.runSqlQuery(sql);
- return getSucReturnObject().setData(rows.isNotEmpty() ? rows.get(0) : new Row()).toString();
- }
- @API(title = "图片删除", apiversion = R.ID20240407135902.v1.class)
- public String attachmentDelete() throws YosException {
- JSONArray linksids = content.getJSONArray("linksids");
- DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sys_attachment_links");
- deleteSQL.setSiteid(siteid);
- deleteSQL.setWhere("linksid", linksids);
- deleteSQL.delete();
- return getSucReturnObject().toString();
- }
- @API(title = "图片列表", apiversion = R.ID20240407140002.v1.class)
- public String attachmentList() 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.attachmentid like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- String ownertable = content.getStringValue("ownertable");
- Long ownerid = content.getLongValue("ownerid");
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_attachment_links").setTableAlias("t1");
- querySQL.setSiteid(siteid);
- querySQL.setWhere(where.toString());
- querySQL.setWhere("ownertable", ownertable);
- querySQL.setWhere("ownerid", ownerid);
- querySQL.setWhere("usetype", ownertable);
- querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
- Rows rows = querySQL.query();
- ArrayList<Long> ids = rows.toArrayList("attachmentid", new ArrayList<>());
- RowsMap attRowsMap = Attachment.get(this, ids).toRowsMap("attachmentid");
- for (Row row : rows) {
- row.put("attinfos", attRowsMap.getOrDefault(row.getString("attachmentid"), new Rows()));
- }
- return getSucReturnObject().setData(rows).toString();
- }
- }
|