|
@@ -1,5 +1,7 @@
|
|
|
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;
|
|
@@ -7,10 +9,9 @@ import common.annotation.API;
|
|
|
import common.annotation.CACHEING;
|
|
|
import common.annotation.CACHEING_CLEAN;
|
|
|
import common.annotation.cm;
|
|
|
-import common.data.Row;
|
|
|
-import common.data.Rows;
|
|
|
-import common.data.SQLFactory;
|
|
|
+import common.data.*;
|
|
|
import restcontroller.R;
|
|
|
+import restcontroller.webmanage.saletool.courseware.courseware;
|
|
|
import restcontroller.webmanage.saletool.courseware.coursewareclass;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
@@ -21,17 +22,12 @@ public class sharematerialClass extends Controller {
|
|
|
super(content);
|
|
|
}
|
|
|
|
|
|
- @API(title = "新增")
|
|
|
- @CACHEING_CLEAN(cms = {@cm(clazz = sharematerialClass.class, method = {"select"})})
|
|
|
+ @API(title = "新增", apiversion = R.ID20240403132302.v1.class)
|
|
|
public String insertOrUpdate() throws YosException {
|
|
|
- Long sat_sharematerial_classid = content.getLong("sat_sharematerial_classid");
|
|
|
- String classname = content.getString("classname", "sat_sharematerial_class");
|
|
|
- Long parentid = content.getLong("parentid");
|
|
|
- boolean isenable = content.getBoolean("isenable");
|
|
|
+ Long sat_sharematerial_classid = content.getLongValue("sat_sharematerial_classid");
|
|
|
+ Long parentid = content.getLongValue("parentid");
|
|
|
long level = 1;
|
|
|
- if (parentid == 0) {
|
|
|
- level = 1;
|
|
|
- } else {
|
|
|
+ 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);
|
|
@@ -39,72 +35,67 @@ public class sharematerialClass extends Controller {
|
|
|
level = rows.get(0).getLong("level") + 1;
|
|
|
}
|
|
|
}
|
|
|
- SQLFactory sqlFactory;
|
|
|
if (sat_sharematerial_classid <= 0) {
|
|
|
- sqlFactory = new SQLFactory(this, "素材分类-新增");
|
|
|
- sqlFactory.addParameter("sat_sharematerial_classid", createTableID("sat_sharematerial_class"));
|
|
|
- sqlFactory.addParameter("siteid", siteid);
|
|
|
- sqlFactory.addParameter("createuserid", userid);
|
|
|
- sqlFactory.addParameter("createby", username);
|
|
|
+ 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("level", level);
|
|
|
+ insertSQL.setValue("parentid", parentid);
|
|
|
+ insertSQL.insert();
|
|
|
+ content.put("sat_sharematerial_classid", sat_sharematerial_classid);
|
|
|
+ }
|
|
|
+ if (sat_sharematerial_classid > 0) {
|
|
|
+ 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("level", level);
|
|
|
+ updateSQL.update();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- } else {
|
|
|
- sqlFactory = new SQLFactory(this, "素材分类-更新");
|
|
|
- sqlFactory.addParameter("sat_sharematerial_classid", sat_sharematerial_classid);
|
|
|
- sqlFactory.addParameter("changeuserid", userid);
|
|
|
- sqlFactory.addParameter("changeby", username);
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT * from sat_sharematerial_class WHERE sat_sharematerial_classid=" + sat_sharematerial_classid + " and siteid='" + siteid + "'");
|
|
|
|
|
|
- }
|
|
|
- sqlFactory.addParameter("changeuserid", userid);
|
|
|
- sqlFactory.addParameter("changeby", username);
|
|
|
- sqlFactory.addParameter("classname", classname);
|
|
|
- sqlFactory.addParameter("parentid", parentid);
|
|
|
- sqlFactory.addParameter("issystem", 0);
|
|
|
- sqlFactory.addParameter("level", level);
|
|
|
- sqlFactory.addParameter("isenable", isenable);
|
|
|
-
|
|
|
- String sql = sqlFactory.getSQL();
|
|
|
- dbConnect.runSqlUpdate(sql);
|
|
|
- return getSucReturnObject().toString();
|
|
|
+ return getSucReturnObject().setData(rows.get(0)).toString();
|
|
|
}
|
|
|
|
|
|
|
|
|
@API(title = "删除", apiversion = R.ID20221102143502.v1.class)
|
|
|
- @CACHEING_CLEAN(cms = {@cm(clazz = sharematerialClass.class, method = {"select"}),@cm(clazz = sharematerial.class, method = {"select"})})
|
|
|
public String delete() throws YosException {
|
|
|
- Long sat_sharematerial_classid = content.getLong("sat_sharematerial_classid");
|
|
|
-
|
|
|
- Rows rows = dbConnect.runSqlQuery("select issystem,parentid from sat_sharematerial_class where sat_sharematerial_classid=" + sat_sharematerial_classid);
|
|
|
- if (rows.isEmpty()) {
|
|
|
- return getErrReturnObject().setErrMsg("当前分类不存在,无法删除").toString();
|
|
|
- } else {
|
|
|
- if (rows.get(0).getBoolean("issystem")) {
|
|
|
- return getErrReturnObject().setErrMsg("当前分类为系统分类,无法删除").toString();
|
|
|
- }
|
|
|
- if (rows.get(0).getLong("parentid") == 0) {
|
|
|
- Rows subRows = dbConnect.runSqlQuery("select sat_sharematerial_classid from sat_sharematerial_class WHERE parentid = " + sat_sharematerial_classid);
|
|
|
- if (subRows.isNotEmpty()) {
|
|
|
- return getErrReturnObject().setErrMsg("当前分类下包含子类,无法删除").toString();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- Rows rowssite = dbConnect.runSqlQuery("select sat_sharematerial_classid from sat_sharematerial_class where issystem=1 AND parentid !=0 and siteid='" + siteid + "'");
|
|
|
- if (rowssite.isEmpty()) {
|
|
|
- return getErrReturnObject().setErrMsg("当前分类下不存在系统板块,无法删除").toString();
|
|
|
+
|
|
|
+ JSONArray sat_sharematerial_classids = content.getJSONArray("sat_sharematerial_classids");
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sat_sharematerial");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere("sat_sharematerial_classid", sat_sharematerial_classids);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ if (rows.isNotEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("当前分类已使用,无法删除").toString();
|
|
|
}
|
|
|
- ArrayList<String> sqllist = new ArrayList<>();
|
|
|
- String deletesql = "DELETE FROM sat_sharematerial_class WHERE sat_sharematerial_classid = '" + sat_sharematerial_classid + "'";
|
|
|
- sqllist.add(deletesql);
|
|
|
- if (rows.get(0).getLong("parentid") != 0) {
|
|
|
- String updatesql = "update sat_sharematerial set sat_sharematerial_classid=" + rowssite.get(0).getLong("sat_sharematerial_classid") + " where sat_sharematerial_classid = '" + sat_sharematerial_classid + "'";
|
|
|
- sqllist.add(updatesql);
|
|
|
+
|
|
|
+ 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();
|
|
|
}
|
|
|
- dbConnect.runSqlUpdate(sqllist);
|
|
|
+
|
|
|
+
|
|
|
+ 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)
|
|
|
- @CACHEING
|
|
|
+ @API(title = "推广素材分类列表", apiversion = R.ID20221102143202.v1.class)
|
|
|
public String select() throws YosException {
|
|
|
/*
|
|
|
过滤条件设置
|
|
@@ -122,18 +113,45 @@ public class sharematerialClass extends Controller {
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
- for (Row row : rows) {
|
|
|
- SQLFactory tempFac = new SQLFactory(this, "素材分类-查询");
|
|
|
- tempFac.addParameter("parentid", row.getString("sat_sharematerial_classid"));
|
|
|
- tempFac.addParameter("siteid", siteid);
|
|
|
- tempFac.addParameter_SQL("where", where);
|
|
|
- row.put("children", dbConnect.runSqlQuery(tempFac));
|
|
|
- }
|
|
|
- return getSucReturnObject().setData(rows).toString();
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|