|
@@ -0,0 +1,156 @@
|
|
|
+package restcontroller.sale.favorites;
|
|
|
+
|
|
|
+import beans.itemprice.ItemPrice;
|
|
|
+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.data.Row;
|
|
|
+import common.data.Rows;
|
|
|
+import common.data.RowsMap;
|
|
|
+import common.data.SQLFactory;
|
|
|
+
|
|
|
+import restcontroller.R;
|
|
|
+import restcontroller.webmanage.sale.itemgroup.itemgroup;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
+public class favorites extends Controller {
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ */
|
|
|
+ public favorites(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增修改商品组
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @API(title = "商品收藏", apiversion = R.ID20231121143403.v1.class,intervaltime = 200)
|
|
|
+ @CACHEING_CLEAN(apiClass = {itemgroup.class, restcontroller.sale.itemgroup.itemgroup.class,favorites.class})
|
|
|
+ public String insertormodify_item() throws YosException {
|
|
|
+ long itemid = content.getLongValue("itemid");
|
|
|
+ boolean iscollection=content.getBooleanValue("iscollection");
|
|
|
+ Rows favoritesRows = dbConnect.runSqlQuery("select * from sa_favorites where sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "' and itemid='"+itemid+"'");
|
|
|
+ ArrayList<String> sqllist = new ArrayList<>();
|
|
|
+ SQLFactory sqlAddFactory = new SQLFactory(this, "商品收藏记录新增");
|
|
|
+ if(favoritesRows.isEmpty()){
|
|
|
+ sqlAddFactory.addParameter("itemid", itemid);
|
|
|
+ sqlAddFactory.addParameter("sa_favoritesid", createTableID("sa_favorites"));
|
|
|
+ sqlAddFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
|
|
|
+ sqlAddFactory.addParameter("iscollection", iscollection);
|
|
|
+ sqlAddFactory.addParameter("siteid", siteid);
|
|
|
+ }else{
|
|
|
+ sqlAddFactory = new SQLFactory(this, "商品收藏记录更新");
|
|
|
+ sqlAddFactory.addParameter("sa_favoritesid", favoritesRows.get(0).getLong("sa_favoritesid"));
|
|
|
+ sqlAddFactory.addParameter("iscollection", iscollection);
|
|
|
+ sqlAddFactory.addParameter("siteid", siteid);
|
|
|
+ }
|
|
|
+ sqllist.add(sqlAddFactory.getSQL());
|
|
|
+ dbConnect.runSqlUpdate(sqllist);
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "商品收藏列表", apiversion = R.ID20231121145103.v1.class)
|
|
|
+ @CACHEING
|
|
|
+ public String querycollectionmx() 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("t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询商品明细
|
|
|
+ */
|
|
|
+ SQLFactory priceSqlFactory = new SQLFactory(this, "查询收藏商品原价");
|
|
|
+ priceSqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
|
|
|
+ priceSqlFactory.addParameter("siteid", siteid);
|
|
|
+ Rows pricerows = dbConnect.runSqlQuery(priceSqlFactory);
|
|
|
+ RowsMap pricerowsMap = pricerows.toRowsMap("itemid");
|
|
|
+
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "查询收藏商品列表", pageSize, pageNumber, pageSorting);
|
|
|
+ sqlFactory.addParameter_SQL("where",where);
|
|
|
+ sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ Rows itemrows = dbConnect.runSqlQuery(sqlFactory.getSQL());
|
|
|
+ for (Row row : itemrows) {
|
|
|
+ ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, row.getLong("itemid"));
|
|
|
+ row.put("oldprice", itemPrice.getPrice());
|
|
|
+ if (sys_enterpriseid > 0 || (usertype == 21 || usertype == 22)) {
|
|
|
+ row.put("gradeprice", itemPrice.getContractprice());
|
|
|
+ } else {
|
|
|
+ if(pricerowsMap.containsKey(row.getString("itemid"))){
|
|
|
+ if(pricerowsMap.get(row.getString("itemid")).isNotEmpty()){
|
|
|
+ row.put("gradeprice", pricerowsMap.get(row.getString("itemid")).get(0).getBigDecimal("price"));
|
|
|
+ }else{
|
|
|
+ row.put("gradeprice",0);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ row.put("gradeprice", 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ArrayList<Long> ids = itemrows.toArrayList("itemid", new ArrayList<>());
|
|
|
+
|
|
|
+ //默认商品图片
|
|
|
+ Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
|
|
|
+ // 封面cover
|
|
|
+ RowsMap coverRowsMap = getAttachmentUrl("plm_item", ids, "cover");
|
|
|
+ // 附件
|
|
|
+ RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
|
|
|
+ Rows rowsitemclass = dbConnect.runSqlQuery(
|
|
|
+ " select t7.itemclassname,t6.itemid,t8.brandname from sa_itemsaleclass t6 inner JOIN plm_itemclass t7 ON t7.itemclassid = t6.itemclassid AND t7.siteid = t6.siteid LEFT JOIN sa_brand t8 ON t8.sa_brandid = t7.sa_brandid AND t8.siteid = t7.siteid where t6.siteid='"
|
|
|
+ + siteid + "'");
|
|
|
+ RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
|
|
|
+
|
|
|
+ // 货品档案领域
|
|
|
+ Rows rowstradefield = dbConnect.runSqlQuery(
|
|
|
+ " select t6.itemid,t6.tradefield from plm_item_tradefield t6 where t6.siteid='" + siteid + "'");
|
|
|
+ RowsMap tradefieldRowsMap = rowstradefield.toRowsMap("itemid");
|
|
|
+
|
|
|
+ // 品牌
|
|
|
+ Rows rowsbrand = dbConnect.runSqlQuery(
|
|
|
+ " select distinct t8.sa_brandid,t6.itemid,t8.brandname from sa_itemsaleclass t6 inner JOIN plm_itemclass t7 ON t7.itemclassid = t6.itemclassid AND t7.siteid = t6.siteid LEFT JOIN sa_brand t8 ON t8.sa_brandid = t7.sa_brandid AND t8.siteid = t7.siteid where t6.siteid='"
|
|
|
+ + siteid + "'");
|
|
|
+ RowsMap brandRowsMap = rowsbrand.toRowsMap("itemid");
|
|
|
+ for (Row row : itemrows) {
|
|
|
+ Rows coverRows = coverRowsMap.get(row.getString("itemid"));
|
|
|
+ if (coverRows.isEmpty()) {
|
|
|
+ row.put("cover", "");
|
|
|
+ } else {
|
|
|
+ row.put("cover", coverRows.get(0).getString("url"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if ((attRowsMap.getOrDefault(row.getString("itemid"), new Rows())).isEmpty()) {
|
|
|
+ row.put("attinfos", defaultImageRows);
|
|
|
+ } else {
|
|
|
+ row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
|
|
|
+ }
|
|
|
+ row.put("itemclass", itemclassRowsMap.get(row.getString("itemid")));
|
|
|
+ row.put("tradefield", tradefieldRowsMap.get(row.getString("itemid")));
|
|
|
+ row.put("brand", brandRowsMap.get(row.getString("itemid")));
|
|
|
+ }
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(itemrows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|