|
@@ -0,0 +1,173 @@
|
|
|
|
|
+package restcontroller.prsx.devstage;
|
|
|
|
|
+
|
|
|
|
|
+import beans.datacontrllog.DataContrlLog;
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import common.Controller;
|
|
|
|
|
+import common.YosException;
|
|
|
|
|
+import common.annotation.API;
|
|
|
|
|
+import common.data.*;
|
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
|
|
+import restcontroller.R;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+
|
|
|
|
|
+public class devstage extends Controller {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 构造函数
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param content
|
|
|
|
|
+ */
|
|
|
|
|
+ public devstage(JSONObject content) throws YosException {
|
|
|
|
|
+ super(content);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @API(title = "新建或编辑", apiversion = R.ID2025100916233702.v1.class)
|
|
|
|
|
+ public String insertOrUpdate() throws YosException {
|
|
|
|
|
+
|
|
|
|
|
+ Long sa_devstageid = content.getLongValue("sa_devstageid");
|
|
|
|
|
+ String stagename = content.getStringValue("stagename");
|
|
|
|
|
+ Long sequence = content.getLongValue("sequence");
|
|
|
|
|
+ String remarks = content.getStringValue("remarks");
|
|
|
|
|
+ JSONArray itemclassids = content.getJSONArray("itemclassid");
|
|
|
|
|
+ JSONArray sa_brandids = new JSONArray();
|
|
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ if (sa_devstageid <= 0) {
|
|
|
|
|
+ sa_devstageid = createTableID("sa_devstage");
|
|
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_devstage");
|
|
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
|
|
+ insertSQL.setUniqueid(sa_devstageid);
|
|
|
|
|
+ insertSQL.setValue("stagename", stagename);
|
|
|
|
|
+ insertSQL.setValue("sequence", sequence);
|
|
|
|
|
+ insertSQL.setValue("remarks", remarks);
|
|
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sa_devstage", sa_devstageid, "新建", stagename).getSQL());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_devstage");
|
|
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
|
|
+ updateSQL.setUniqueid(sa_devstageid);
|
|
|
|
|
+ updateSQL.setValue("stagename", stagename);
|
|
|
|
|
+ updateSQL.setValue("sequence", sequence);
|
|
|
|
|
+ updateSQL.setValue("remarks", remarks);
|
|
|
|
|
+ sqlList.add(updateSQL.getSQL());
|
|
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sa_devstage", sa_devstageid, "编辑", stagename).getSQL());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (content.containsKey("sa_brandids")) {
|
|
|
|
|
+ sa_brandids = content.getJSONArray("sa_brandids");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (sa_brandids.size() > 0) {
|
|
|
|
|
+ String sql = " SELECT DISTINCT itemclassid from plm_itemclass WHERE classtype = '营销' and siteid = '" + siteid + "' and sa_brandid in " + sa_brandids;
|
|
|
|
|
+ sql = sql.replace("[", "(").replace("]", ")");
|
|
|
|
|
+ itemclassids.addAll(dbConnect.runSqlQuery(sql).toJsonArray("itemclassid"));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (itemclassids.size() > 0) {
|
|
|
|
|
+ String sql = "with recursive itemclass as (select itemclassid from plm_itemclass where siteid = '" + siteid + "' and itemclassid in " + itemclassids + " union all select t2.itemclassid from itemclass t1 inner join plm_itemclass t2 on t1.itemclassid = t2.parentid and t2.siteid = '" + siteid + "') select itemclassid from itemclass";
|
|
|
|
|
+ sql = sql.replace("[", "(").replace("]", ")");
|
|
|
|
|
+ itemclassids.addAll(dbConnect.runSqlQuery(sql).toJsonArray("itemclassid"));
|
|
|
|
|
+ }
|
|
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_itemclass", "itemclassfullname", "itemclassid");
|
|
|
|
|
+ querySQL.setTableAlias("t1");
|
|
|
|
|
+ querySQL.addJoinTable(JOINTYPE.inner, "sa_brand", "t2", "t1.siteid=t2.siteid and t1.sa_brandid=t2.sa_brandid", "brandname", "sa_brandid");
|
|
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
|
|
+ querySQL.setWhere("itemclassid", itemclassids.toArray());
|
|
|
|
|
+ Rows rows = querySQL.query();
|
|
|
|
|
+ if (rows.isNotEmpty()) {
|
|
|
|
|
+ DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_devstage_itemclass");
|
|
|
|
|
+ deleteSQL.setSiteid(siteid);
|
|
|
|
|
+ deleteSQL.setWhere("sa_devstageid", sa_devstageid);
|
|
|
|
|
+ sqlList.add(deleteSQL.getSQL());
|
|
|
|
|
+ }
|
|
|
|
|
+ for (Row row : rows) {
|
|
|
|
|
+ long itemclassid = row.getLong("itemclassid");
|
|
|
|
|
+ long sa_brandid = row.getLong("sa_brandid");
|
|
|
|
|
+ String itemclassfullname = row.getString("itemclassfullname");
|
|
|
|
|
+ String brandname = row.getString("brandname");
|
|
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_devstage_itemclass");
|
|
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
|
|
+ insertSQL.setUniqueid(createTableID("sa_devstage_itemclass"));
|
|
|
|
|
+ insertSQL.setValue("sa_devstageid", sa_devstageid);
|
|
|
|
|
+ insertSQL.setValue("itemclassid", itemclassid);
|
|
|
|
|
+ insertSQL.setValue("sa_brandid", sa_brandid);
|
|
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sa_devstage", sa_devstageid, "新建营销类别", "营销类别:" + itemclassfullname + ",品牌:" + brandname).getSQL());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return getSucReturnObject().toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @API(title = "删除", apiversion = R.ID2025100916243002.v1.class)
|
|
|
|
|
+ public String delete() throws YosException {
|
|
|
|
|
+ Long sa_devstageid = content.getLongValue("sa_devstageid");
|
|
|
|
|
+ DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_devstage");
|
|
|
|
|
+ deleteSQL.setSiteid(siteid);
|
|
|
|
|
+ deleteSQL.setWhere("sa_devstageid", sa_devstageid);
|
|
|
|
|
+ deleteSQL.delete();
|
|
|
|
|
+
|
|
|
|
|
+ deleteSQL = SQLFactory.createDeleteSQL(this, "sa_devstage_itemclass");
|
|
|
|
|
+ deleteSQL.setSiteid(siteid);
|
|
|
|
|
+ deleteSQL.setWhere("sa_devstageid", sa_devstageid);
|
|
|
|
|
+ deleteSQL.delete();
|
|
|
|
|
+
|
|
|
|
|
+ DataContrlLog.createLog(this, "sa_devstage", sa_devstageid, "删除", "删除成功").insert();
|
|
|
|
|
+ return getSucReturnObject().toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @API(title = "列表", apiversion = R.ID2025100916245502.v1.class)
|
|
|
|
|
+ public String list() throws YosException {
|
|
|
|
|
+
|
|
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_devstage", "*").setTableAlias("t1");
|
|
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
|
|
+ querySQL.setPage(pageSize, pageNumber).setOrderBy("sequence");
|
|
|
|
|
+ querySQL.setCondition("stagename", "remarks");
|
|
|
|
|
+ Rows rows = querySQL.query();
|
|
|
|
|
+
|
|
|
|
|
+ querySQL = SQLFactory.createQuerySQL(this, "sa_devstage_itemclass", "*").setTableAlias("t1");
|
|
|
|
|
+ querySQL.addJoinTable(JOINTYPE.inner, "plm_itemclass", "t2", "t1.siteid=t2.siteid and t1.itemclassid=t2.itemclassid", "itemclassfullname", "itemclassname");
|
|
|
|
|
+ querySQL.addJoinTable(JOINTYPE.inner, "sa_brand", "t3", "t1.siteid=t3.siteid and t1.sa_brandid=t3.sa_brandid", "brandname");
|
|
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
|
|
+ querySQL.setWhere("sa_devstageid", rows.toArrayList("sa_devstageid"));
|
|
|
|
|
+ RowsMap rowsMap = querySQL.query().toRowsMap("sa_devstageid");
|
|
|
|
|
+
|
|
|
|
|
+ for (Row row :rows) {
|
|
|
|
|
+ if(rowsMap.containsKey(row.getString("sa_devstageid"))){
|
|
|
|
|
+ row.put("itemclassnames", StringUtils.join(rowsMap.get(row.getString("sa_devstageid")).toArrayList("itemclassname"),","));
|
|
|
|
|
+ }
|
|
|
|
|
+ row.putIfAbsent("itemclassnames", "");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @API(title = "关联查询营销类别", apiversion = R.ID2025100916251802.v1.class)
|
|
|
|
|
+ public String itemclassList() throws YosException {
|
|
|
|
|
+ Long sa_devstageid = content.getLongValue("sa_devstageid");
|
|
|
|
|
+
|
|
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_devstage_itemclass", "*").setTableAlias("t1");
|
|
|
|
|
+ querySQL.addJoinTable(JOINTYPE.inner, "plm_itemclass", "t2", "t1.siteid=t2.siteid and t1.itemclassid=t2.itemclassid", "itemclassfullname", "itemclassname");
|
|
|
|
|
+ querySQL.addJoinTable(JOINTYPE.inner, "sa_brand", "t3", "t1.siteid=t3.siteid and t1.sa_brandid=t3.sa_brandid", "brandname");
|
|
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
|
|
+ querySQL.setWhere("sa_devstageid", sa_devstageid);
|
|
|
|
|
+ Rows rows = querySQL.query();
|
|
|
|
|
+
|
|
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @API(title = "开发阶段授权营销类别删除", apiversion = R.ID2025101011145102.v1.class)
|
|
|
|
|
+ public String deleteitemclass() throws YosException {
|
|
|
|
|
+ Long sa_devstage_itemclassid = content.getLongValue("sa_devstage_itemclassid");
|
|
|
|
|
+ DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_devstage_itemclass");
|
|
|
|
|
+ deleteSQL.setSiteid(siteid);
|
|
|
|
|
+ deleteSQL.setWhere("sa_devstage_itemclassid", sa_devstage_itemclassid);
|
|
|
|
|
+ deleteSQL.delete();
|
|
|
|
|
+ return getSucReturnObject().toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+}
|