|
@@ -0,0 +1,167 @@
|
|
|
+package restcontroller.webmanage.saletool.fad;
|
|
|
+
|
|
|
+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;
|
|
|
+
|
|
|
+public class FadClass extends Controller {
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ */
|
|
|
+ public FadClass(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "单品新增或编辑", apiversion = R.ID20240418111802.v1.class)
|
|
|
+ public String insertOrUpdate() throws YosException {
|
|
|
+ Long sa_fadclassid = content.getLongValue("sa_fadclassid");
|
|
|
+ Long parentid = content.getLongValue("parentid");
|
|
|
+ long level = 1;
|
|
|
+ if (parentid > 0) {
|
|
|
+ //查询level
|
|
|
+ String sqlLevel = "SELECT IFNULL(level,0) level FROM sa_fadclass WHERE sa_fadclassid = '" + parentid + "'";
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlLevel);
|
|
|
+ if (rows.isNotEmpty()) {
|
|
|
+ level = rows.get(0).getLong("level") + 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (sa_fadclassid <= 0) {
|
|
|
+ sa_fadclassid = createTableID("sa_fadclass");
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_fadclass");
|
|
|
+ insertSQL.setUniqueid(sa_fadclassid);
|
|
|
+ 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("sa_fadclassid", sa_fadclassid);
|
|
|
+ } else {
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_fadclass");
|
|
|
+ updateSQL.setUniqueid(sa_fadclassid);
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT * from sa_fadclass WHERE sa_fadclassid=" + sa_fadclassid + " and siteid='" + siteid + "'");
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows.get(0)).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @API(title = "单品删除", apiversion = R.ID20240418111902.v1.class)
|
|
|
+ public String delete() throws YosException {
|
|
|
+
|
|
|
+ JSONArray sa_fadclassids = content.getJSONArray("sa_fadclassids");
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
+ if (sa_fadclassids.size() > 0) {
|
|
|
+ where.append(" and (1=2");
|
|
|
+ for (Object obj : sa_fadclassids) {
|
|
|
+ where.append(" or (");
|
|
|
+ where.append("JSON_CONTAINS(sa_fadclassids,'" + obj + "')");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_fad");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere(where.toString());
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ if (rows.isNotEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("当前分类已使用,无法删除").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ querySQL = SQLFactory.createQuerySQL(this, "sa_fadclass");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere("parentid", sa_fadclassids);
|
|
|
+ rows = querySQL.query();
|
|
|
+ if (rows.isNotEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("当前分类存在下级分类,无法删除").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_fadclass");
|
|
|
+ deleteSQL.setSiteid(siteid);
|
|
|
+ deleteSQL.setWhere("sa_fadclassid", sa_fadclassids);
|
|
|
+ deleteSQL.delete();
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "单品分类列表", apiversion = R.ID20240418112002.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, "sa_fadclass", row.getLong("sa_fadclassid"));
|
|
|
+ row.put("attinfos", attRows);
|
|
|
+ Rows secondRows = getClassRows(row.getLong("sa_fadclassid"), where);
|
|
|
+ row.put("children", secondRows);
|
|
|
+ for (Row secondRow : secondRows) {
|
|
|
+ Rows threeRows = getClassRows(secondRow.getLong("sa_fadclassid"), where);
|
|
|
+ secondRow.put("children", threeRows);
|
|
|
+ for (Row threeRow : threeRows) {
|
|
|
+ Rows fourRows = getClassRows(threeRow.getLong("sa_fadclassid"), where);
|
|
|
+ threeRow.put("children", fourRows);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Rows getClassRows(Long parentid, StringBuffer where) throws YosException {
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_fadclass").setTableAlias("t1");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere("parentid", parentid);
|
|
|
+ querySQL.setWhere(where.toString());
|
|
|
+ querySQL.setOrderBy("sequence DESC,createdate DESC");
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ return rows;
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "单品启用", apiversion = R.ID20240418112102.v1.class)
|
|
|
+ public String isenadle() throws YosException {
|
|
|
+ JSONArray sa_fadclassids = content.getJSONArray("sa_fadclassids");
|
|
|
+
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_fadclass");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setValue("isenable", content.getBooleanValue("isenable"));
|
|
|
+ updateSQL.setWhere("sa_fadclassid ", sa_fadclassids.toArray());
|
|
|
+ updateSQL.update();
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|