123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- package restcontroller.webmanage.saletool.sharematerial;
- import beans.attachment.Attachment;
- import beans.datacontrllog.DataContrlLog;
- import beans.parameter.Parameter;
- import beans.remind.Remind;
- 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 utility.email.EmailContent;
- 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.setValue("ispicture", content.getBooleanValue("ispicture"));
- sqlFactory.insert();
- content.put("sat_sharematerialid", sat_sharematerialid);
- DataContrlLog.createLog(this, "sat_sharematerial", sat_sharematerialid, "新建", "新建资料 " + content.getStringValue("title")).insert();
- } else {
- 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.setValue("ispicture", content.getBooleanValue("ispicture"));
- sqlFactory.update();
- DataContrlLog.createLog(this, "sat_sharematerial", sat_sharematerialid, "编辑", "编辑资料 " + content.getStringValue("title")).insert();
- }
- return detail();
- }
- @API(title = "装备资源库详情", apiversion = R.ID20240407094602.v1.class)
- public String detail() throws YosException {
- String ownertable = "sat_sharematerial";
- 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", "ispicture")
- .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);
- attRows.sortby("sequence", "linksid");
- 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);
- }
- QuerySQL attachmentQuery = SQLFactory.createQuerySQL(this, "sys_attachment_links").setTableAlias("t1");
- attachmentQuery.setSiteid(siteid);
- attachmentQuery.setWhere("ownertable", ownertable);
- attachmentQuery.setWhere("ownerid", sat_sharematerialid);
- attachmentQuery.setWhere("usetype", ownertable);
- attachmentQuery.setOrderBy("t1.sequence,t1.linksid");
- Rows attachmentRows = attachmentQuery.query();
- ArrayList<Long> ids = attachmentRows.toArrayList("attachmentid", new ArrayList<>());
- RowsMap attRowsMap = Attachment.get(this, ids).toRowsMap("attachmentid");
- for (Row row : attachmentRows) {
- Rows attPicRows = new Rows();
- Rows tempAttRows = attRowsMap.getOrDefault(row.getString("attachmentid"), new Rows());
- for (Row tempAttRow : tempAttRows) {
- // if (tempAttRow.getString("usetype").equals(ownertable)) {
- attPicRows.add(tempAttRow);
- // }
- }
- row.put("attinfos", attPicRows);
- }
- detailRow.put("attinfos_pic", attachmentRows);
- SharematerialHelper.updateReadLog(this, sat_sharematerialid, 0);
- 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;
- if (array.size() > 0) {
- where.append(" or (");
- where.append("JSON_CONTAINS(t1.sat_sharematerial_classids,'" + array.get(array.size() - 1) + "')");
- where.append(")");
- }
- }
- where.append(")");
- }
- }
- }
- boolean isDataAuth = content.getBooleanValue("isDataAuth");
- QuerySQL sqlFactory = SQLFactory.createQuerySQL(this, sat_sharematerial,
- "sat_sharematerialid", "title", "type", "status", "mailcount",
- "readcount", "downloadcount", "createdate", "checkdate",
- "sat_sharematerial_classids", "ispicture")
- .setTableAlias("t1");
- sqlFactory.setSiteid(siteid);
- sqlFactory.setWhere("classid", 3);
- sqlFactory.setWhere(where.toString());
- sqlFactory.setOrderBy(pageSorting).setPage(pageSize, pageNumber);
- if (isDataAuth) {
- sqlFactory.setDataAuth(true);
- }
- Rows rows = sqlFactory.query();
- ArrayList<Long> ids = rows.toArrayList("sat_sharematerialid", new ArrayList<>());
- // 附件
- RowsMap RowsMap = getAttachmentUrl(sat_sharematerial, ids);
- for (Row row : rows) {
- Rows attRows = RowsMap.getOrDefault(row.getString("sat_sharematerialid"), new Rows());
- attRows.sortby("sequence", "linksid");
- row.put("attinfos", attRows);
- 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");
- String title = "";
- String classStr = "";
- String typeStr = "";
- if (ownertable.equals("sat_sharematerial")) {
- Row row = dbConnect.runSqlQuery(0, "SELECT * from sat_sharematerial WHERE siteid='" + siteid + "' and sat_sharematerialid=" + ownerid);
- title = row.getString("title");
- int classid = row.getInteger("classid");
- if (classid == 2) {
- classStr = "长图文";
- }
- if (classid == 3) {
- classStr = "资料";
- }
- if (classid == 4) {
- classStr = "效果图";
- }
- if (classid == 5) {
- classStr = "设计实景";
- typeStr = "视频图";
- }
- int type = row.getInteger("type");
- if (type == 1) {
- typeStr = "图片";
- }
- if (type == 2) {
- typeStr = "视频";
- }
- }
- if (ownertable.equals("sa_fad")) {
- Row row = dbConnect.runSqlQuery(0, "SELECT * from sa_fad WHERE siteid='" + siteid + "' and sa_fadid=" + ownerid);
- title = row.getString("name");
- int classid = row.getInteger("classid");
- if (classid == 1) {
- classStr = "单品";
- typeStr = "";
- }
- if (classid == 2) {
- classStr = "商品";
- typeStr = "图片";
- }
- }
- 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();
- DataContrlLog.createLog(this, ownertable, ownerid, "新建", "新建" + typeStr + "于" + classStr + " " + title).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.setValue("attachmentid", content.getLongValue("attachmentid"));
- updateSQL.update();
- DataContrlLog.createLog(this, ownertable, ownerid, "编辑", "编辑" + typeStr + "于" + classStr + " " + title).insert();
- }
- 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.ID20240425102102.v1.class)
- public String attachmentInserts() throws YosException {
- String ownertable = content.getStringValue("ownertable");
- Long ownerid = content.getLongValue("ownerid");
- JSONArray jsonArray = content.getJSONArray("items");
- ArrayList<String> listSql = new ArrayList<>();
- for (Object obj : jsonArray) {
- if (obj instanceof JSONObject) {
- JSONObject jsonObject = (JSONObject) obj;
- InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_attachment_links");
- insertSQL.setSiteid(siteid);
- insertSQL.setUniqueid(createTableID("sys_attachment_links"));
- insertSQL.setValue("usetype", ownertable);
- insertSQL.setValue("attachmentid", jsonObject.getLongValue("attachmentid"));
- insertSQL.setValue("jumpurl", jsonObject.getStringValue("jumpurl", true));
- insertSQL.setValue("sequence", jsonObject.getLongValue("sequence"));
- insertSQL.setValue("ownertable", ownertable);
- insertSQL.setValue("ownerid", ownerid);
- listSql.add(insertSQL.getSQL());
- }
- }
- dbConnect.runSqlUpdate(listSql);
- return getSucReturnObject().toString();
- }
- @API(title = "图片删除", apiversion = R.ID20240407135902.v1.class)
- public String attachmentDelete() throws YosException {
- JSONArray linksids = content.getJSONArray("linksids");
- for (Object object : linksids) {
- Row row = dbConnect.runSqlQuery(0, "select * from sys_attachment_links where linksid=" + object);
- String ownertable = row.getString("ownertable");
- Long ownerid = row.getLong("ownerid");
- String classStr = "";
- String typeStr = "";
- if (ownertable.equals("sat_sharematerial")) {
- row = dbConnect.runSqlQuery(0, "SELECT * from sat_sharematerial WHERE siteid='" + siteid + "' and sat_sharematerialid=" + ownerid);
- int classid = row.getInteger("classid");
- if (classid == 2) {
- classStr = "长图文";
- }
- if (classid == 3) {
- classStr = "资料";
- }
- if (classid == 4) {
- classStr = "效果图";
- }
- if (classid == 5) {
- classStr = "设计实景";
- typeStr = "视频图";
- }
- int type = row.getInteger("type");
- if (type == 1) {
- typeStr = "图片";
- }
- if (type == 2) {
- typeStr = "视频";
- }
- DataContrlLog.createLog(this, ownertable, ownerid, "删除", "删除" + typeStr + "于" + classStr + " " + row.getString("name")).insert();
- }
- if (ownertable.equals("sa_fad")) {
- row = dbConnect.runSqlQuery(0, "SELECT * from sa_fad WHERE siteid='" + siteid + "' and sa_fadid=" + ownerid);
- int classid = row.getInteger("classid");
- if (classid == 1) {
- classStr = "单品";
- typeStr = "";
- }
- if (classid == 2) {
- classStr = "商品";
- typeStr = "图片";
- }
- }
- DataContrlLog.createLog(this, ownertable, ownerid, "删除", "删除" + typeStr + "于" + classStr + " " + row.getString("name")).insert();
- }
- 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) {
- Rows attRows = new Rows();
- Rows tempAttRows = attRowsMap.getOrDefault(row.getString("attachmentid"), new Rows());
- for (Row tempAttRow : tempAttRows) {
- // if (tempAttRow.getString("usetype").equals(ownertable)) {
- attRows.add(tempAttRow);
- // }
- }
- row.put("attinfos", attRows);
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "发送邮件", apiversion = R.ID20240408154702.v1.class)
- public String sendMail() throws Exception {
- Long sat_sharematerialid = content.getLongValue("sat_sharematerialid");
- String email = content.getStringValue("email");
- if (!Parameter.get(siteid, "remind_mail").equalsIgnoreCase("1")) {
- return getErrReturnObject().setErrMsg("邮件功能未开启").toString();
- }
- Rows rows = dbConnect.runSqlQuery("SELECT * from sat_sharematerial where sat_sharematerialid=" + sat_sharematerialid);
- if (rows.isEmpty()) {
- return getErrReturnObject().setErrMsg("数据不存在").toString();
- }
- Rows rowsAtt = Attachment.get(this, "sat_sharematerial", sat_sharematerialid, "sat_sharematerial");
- EmailContent emailContent = new EmailContent();
- emailContent.addText(rows.get(0).getString("content"));
- for (Row rowAtt : rowsAtt) {
- emailContent.addFile(rowAtt.getString("url"));
- }
- Remind remind = new Remind(siteid);
- remind.setTitle(rows.get(0).getString("title"));
- remind.setToemail(email);
- remind.setContent(emailContent);
- remind.sendByMail();
- SharematerialHelper.updateReadLog(this, sat_sharematerialid, 2);
- return getSucReturnObject().toString();
- }
- }
|