123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- 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.annotation.CACHEING;
- import common.annotation.CACHEING_CLEAN;
- import common.annotation.cm;
- import common.data.*;
- import restcontroller.R;
- import restcontroller.webmanage.saletool.courseware.courseware;
- import restcontroller.webmanage.saletool.courseware.coursewareclass;
- import java.util.ArrayList;
- @API(title = "推广素材管理-分类")
- public class sharematerialClass extends Controller {
- public sharematerialClass(JSONObject content) throws YosException {
- super(content);
- }
- @API(title = "新增", apiversion = R.ID20240403132302.v1.class)
- public String insertOrUpdate() throws YosException {
- Long sat_sharematerial_classid = content.getLongValue("sat_sharematerial_classid");
- Long parentid = content.getLongValue("parentid");
- long level = 1;
- if (parentid > 0) {
- //查询level
- String sqlLevel = "SELECT IFNULL(level,0) level FROM sat_sharematerial_class WHERE sat_sharematerial_classid = '" + parentid + "'";
- Rows rows = dbConnect.runSqlQuery(sqlLevel);
- if (rows.isNotEmpty()) {
- level = rows.get(0).getLong("level") + 1;
- }
- }
- if (sat_sharematerial_classid <= 0) {
- sat_sharematerial_classid = createTableID("sat_sharematerial_class");
- InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sat_sharematerial_class");
- insertSQL.setUniqueid(sat_sharematerial_classid);
- insertSQL.setSiteid(siteid);
- insertSQL.setValue("classname", content.getStringValue("classname"));
- insertSQL.setValue("isenable", content.getBooleanValue("isenable"));
- insertSQL.setValue("sequence", content.getLongValue("sequence"));
- insertSQL.setValue("remarks", content.getStringValue("remarks"));
- insertSQL.setValue("level", level);
- insertSQL.setValue("parentid", parentid);
- insertSQL.insert();
- content.put("sat_sharematerial_classid", sat_sharematerial_classid);
- }else{
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_sharematerial_class");
- updateSQL.setUniqueid(sat_sharematerial_classid);
- updateSQL.setSiteid(siteid);
- updateSQL.setValue("classname", content.getStringValue("classname"));
- updateSQL.setValue("isenable", content.getBooleanValue("isenable"));
- updateSQL.setValue("sequence", content.getLongValue("sequence"));
- updateSQL.setValue("remarks", content.getStringValue("remarks"));
- updateSQL.setValue("level", level);
- updateSQL.update();
- }
- Rows rows = dbConnect.runSqlQuery("SELECT * from sat_sharematerial_class WHERE sat_sharematerial_classid=" + sat_sharematerial_classid + " and siteid='" + siteid + "'");
- return getSucReturnObject().setData(rows.get(0)).toString();
- }
- @API(title = "删除", apiversion = R.ID20221102143502.v1.class)
- public String delete() throws YosException {
- JSONArray sat_sharematerial_classids = content.getJSONArray("sat_sharematerial_classids");
- StringBuffer where = new StringBuffer(" 1=1 ");
- if (sat_sharematerial_classids.size() > 0) {
- where.append(" and (1=2");
- for (Object obj : sat_sharematerial_classids) {
- where.append(" or (");
- where.append("JSON_CONTAINS(sat_sharematerial_classids,'" + obj + "')");
- where.append(")");
- }
- where.append(")");
- }
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_sharematerial");
- querySQL.setSiteid(siteid);
- querySQL.setWhere(where.toString());
- Rows rows = querySQL.query();
- if (rows.isNotEmpty()) {
- return getErrReturnObject().setErrMsg("当前分类已使用,无法删除").toString();
- }
- querySQL = SQLFactory.createQuerySQL(this, "sat_sharematerial_class");
- querySQL.setSiteid(siteid);
- querySQL.setWhere("parentid", sat_sharematerial_classids);
- rows = querySQL.query();
- if (rows.isNotEmpty()) {
- return getErrReturnObject().setErrMsg("当前分类存在下级分类,无法删除").toString();
- }
- DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sat_sharematerial_class");
- deleteSQL.setSiteid(siteid);
- deleteSQL.setWhere("sat_sharematerial_classid", sat_sharematerial_classids);
- deleteSQL.delete();
- return getSucReturnObject().toString();
- }
- @API(title = "推广素材分类列表", apiversion = R.ID20221102143202.v1.class)
- public String select() throws YosException {
- /*
- 过滤条件设置
- */
- StringBuffer where = new StringBuffer(" 1=1 ");
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("isenable") && !"".equals(whereObject.getString("isenable"))) {
- where.append(" and (");
- where.append("isenable="+whereObject.getBoolean("isenable"));
- where.append(")");
- }
- }
- Long parentid = content.getLong("parentid");
- Rows rows = getClassRows(parentid, where);
- for (Row row : rows) {
- Rows attRows = Attachment.get(this, "sat_sharematerial_class", row.getLong("sat_sharematerial_classid"));
- row.put("attinfos", attRows);
- Rows secondRows = getClassRows(row.getLong("sat_sharematerial_classid"), where);
- row.put("children", secondRows);
- for (Row secondRow : secondRows) {
- Rows threeRows = getClassRows(secondRow.getLong("sat_sharematerial_classid"), where);
- secondRow.put("children", threeRows);
- }
- }
- return getSucReturnObject().setData(rows).toString();
- }
- public Rows getClassRows(Long parentid, StringBuffer where) throws YosException {
- SQLFactory sqlFactory = new SQLFactory(this, "素材分类-查询");
- sqlFactory.addParameter("parentid", parentid);
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter_SQL("where", where);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- return rows;
- }
- @API(title = "启用", apiversion = R.ID20240403153602.v1.class)
- public String isenadle() throws YosException {
- JSONArray sat_sharematerial_classids = content.getJSONArray("sat_sharematerial_classids");
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sat_sharematerial_class");
- updateSQL.setSiteid(siteid);
- updateSQL.setValue("isenable", content.getBooleanValue("isenable"));
- updateSQL.setWhere("sat_sharematerial_classid ", sat_sharematerial_classids.toArray());
- updateSQL.update();
- return getSucReturnObject().toString();
- }
- }
|