eganwu 1 anno fa
parent
commit
f3ea1a9417
1 ha cambiato i file con 138 aggiunte e 6 eliminazioni
  1. 138 6
      src/custom/restcontroller/webmanage/saletool/fad/Fad.java

+ 138 - 6
src/custom/restcontroller/webmanage/saletool/fad/Fad.java

@@ -1,6 +1,8 @@
 package restcontroller.webmanage.saletool.fad;
 
 import beans.attachment.Attachment;
+import beans.brand.Brand;
+import beans.itemclass.ItemClass;
 import beans.time.Time;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -290,22 +292,152 @@ public class Fad extends Controller {
     }
 
     @API(title = "选择商品列表", apiversion = R.ID20240418141402.v1.class)
-    public String chooseItemlist() {
-        return getSucReturnObject().toString();
+    public String chooseItemlist() 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.itemno like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.color like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+
+        Long sa_fadid=content.getLongValue("sa_fadid");
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item"
+                ,"itemid","itemname","itemno","model","spec","color","marketprice","standards");
+        querySQL.setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_itemclass", "t2", "t2.itemclassid = t1.marketingcategory AND t2.siteid = t1.siteid",
+                "itemclassname");
+        querySQL.setWhere("t1.siteid", siteid);
+        querySQL.setWhere(where.toString());
+        querySQL.setWhere("not exists(select 1 from  sa_fad_link where sa_fadid=" + sa_fadid + " and itemid=t1.itemid and siteid='" + siteid + "'  )");
+        querySQL.setOrderBy(pageSorting);
+        querySQL.setPage(pageSize, pageNumber);
+
+        Rows rows = querySQL.query();
+        // 默认商品图片
+        Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
+        // 附件
+        ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
+        RowsMap attRowsMapCover = getAttachmentUrl("plm_item", ids, "cover");
+        RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
+        // 商品领域
+        RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
+
+        RowsMap itemclassRowsMap = ItemClass.getAllItemClassRowsMap(this, ids);
+        for (Row row : rows) {
+            if (attRowsMapCover.getOrDefault(row.getString("itemid"), new Rows()).isNotEmpty()) {
+                row.put("attinfos", attRowsMapCover.getOrDefault(row.getString("itemid"), new Rows()));
+            } else if (attRowsMap.getOrDefault(row.getString("itemid"), new Rows()).isNotEmpty()) {
+                row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
+            } else {
+                row.put("attinfos", defaultImageRows);
+            }
+            String[] tradefield = tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()).toArray("tradefield");
+            row.put("tradefield", StringUtils.join(tradefield, ","));
+
+            String[] itemclass = itemclassRowsMap.getOrDefault(row.getString("itemid"), new Rows()).toArray("itemclassname");
+            row.put("itemclass", StringUtils.join(itemclass, ","));
+        }
+
+
+        return getSucReturnObject().setData(rows).toString();
     }
 
     @API(title = "关联商品列表", apiversion = R.ID20240418141502.v1.class)
-    public String relateItemlist() {
-        return getSucReturnObject().toString();
+    public String relateItemlist() 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.itemno like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.color like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+
+        Long sa_fadid=content.getLongValue("sa_fadid");
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item"
+                ,"itemid","itemname","itemno","model","spec","color","marketprice","standards");
+        querySQL.setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_itemclass", "t2", "t2.itemclassid = t1.marketingcategory AND t2.siteid = t1.siteid",
+                "itemclassname");
+        querySQL.setWhere("t1.siteid", siteid);
+        querySQL.setWhere(where.toString());
+        querySQL.setWhere("exists(select 1 from  sa_fad_link where sa_fadid=" + sa_fadid + " and itemid=t1.itemid and siteid='" + siteid + "'  )");
+        querySQL.setOrderBy(pageSorting);
+        querySQL.setPage(pageSize, pageNumber);
+
+        Rows rows = querySQL.query();
+        // 默认商品图片
+        Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
+        // 附件
+        ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
+        RowsMap attRowsMapCover = getAttachmentUrl("plm_item", ids, "cover");
+        RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
+        // 商品领域
+        RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
+
+        RowsMap itemclassRowsMap = ItemClass.getAllItemClassRowsMap(this, ids);
+        for (Row row : rows) {
+            if (attRowsMapCover.getOrDefault(row.getString("itemid"), new Rows()).isNotEmpty()) {
+                row.put("attinfos", attRowsMapCover.getOrDefault(row.getString("itemid"), new Rows()));
+            } else if (attRowsMap.getOrDefault(row.getString("itemid"), new Rows()).isNotEmpty()) {
+                row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
+            } else {
+                row.put("attinfos", defaultImageRows);
+            }
+            String[] tradefield = tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()).toArray("tradefield");
+            row.put("tradefield", StringUtils.join(tradefield, ","));
+
+            String[] itemclass = itemclassRowsMap.getOrDefault(row.getString("itemid"), new Rows()).toArray("itemclassname");
+            row.put("itemclass", StringUtils.join(itemclass, ","));
+        }
+
+
+        return getSucReturnObject().setData(rows).toString();
     }
 
     @API(title = "关联商品", apiversion = R.ID20240418141602.v1.class)
-    public String relateItem() {
+    public String relateItem() throws YosException {
+        Long sa_fadid = content.getLongValue("sa_fadid");
+        JSONArray itemids = content.getJSONArray("itemids");
+
+        ArrayList<String> sqlList = new ArrayList<>();
+
+        for (Object obj : itemids) {
+            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_fad_link");
+            insertSQL.setSiteid(siteid);
+            insertSQL.setUniqueid(createTableID("sa_fad_link"));
+            insertSQL.setValue("itemid", obj);
+            insertSQL.setValue("sa_fadid", sa_fadid);
+            sqlList.add(insertSQL.getSQL());
+        }
+
+
+        dbConnect.runSqlUpdate(sqlList);
         return getSucReturnObject().toString();
     }
 
     @API(title = "删除商品", apiversion = R.ID20240418141702.v1.class)
-    public String deleteItem() {
+    public String deleteItem() throws YosException {
+        JSONArray sa_fad_linkids = content.getJSONArray("sa_fad_linkids");
+
+        DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_fad_link");
+        deleteSQL.setSiteid(siteid);
+        deleteSQL.setWhere("sa_fad_linkid", sa_fad_linkids);
+        deleteSQL.delete();
         return getSucReturnObject().toString();
     }