| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- package restcontroller.sale.favorites;
- import beans.customscheme.CustomScheme;
- import beans.itemprice.ItemPrice;
- import com.alibaba.fastjson.JSONArray;
- 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 org.apache.commons.lang.StringUtils;
- import restcontroller.R;
- import restcontroller.webmanage.sale.itemgroup.itemgroup;
- import java.math.BigDecimal;
- 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");
- BigDecimal qty = content.getBigDecimalValue("qty");
- BigDecimal width = content.getBigDecimalValue("width");
- BigDecimal length = content.getBigDecimalValue("length");
- 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);
- sqlAddFactory.addParameter("qty", qty);
- sqlAddFactory.addParameter("width", width);
- sqlAddFactory.addParameter("length", length);
- } else {
- sqlAddFactory = new SQLFactory(this, "商品收藏记录更新");
- sqlAddFactory.addParameter("sa_favoritesid", favoritesRows.get(0).getLong("sa_favoritesid"));
- sqlAddFactory.addParameter("iscollection", iscollection);
- sqlAddFactory.addParameter("siteid", siteid);
- sqlAddFactory.addParameter("qty", qty);
- sqlAddFactory.addParameter("width", width);
- sqlAddFactory.addParameter("length", length);
- }
- sqllist.add(sqlAddFactory.getSQL());
- dbConnect.runSqlUpdate(sqllist);
- return getSucReturnObject().toString();
- }
- /**
- * 商品批量收藏
- *
- * @return
- */
- @API(title = "商品批量收藏", apiversion = R.ID20231122102803.v1.class, intervaltime = 200)
- @CACHEING_CLEAN(apiClass = {itemgroup.class, restcontroller.sale.itemgroup.itemgroup.class, favorites.class})
- public String items_collect() throws YosException {
- JSONArray itemids = content.getJSONArray("itemids");
- boolean iscollection = content.getBooleanValue("iscollection");
- ArrayList<String> sqllist = new ArrayList<>();
- SQLFactory sqlFactory = new SQLFactory(this, "商品收藏记录批量更新");
- sqlFactory.addParameter_in("itemids", itemids.toArray());
- sqlFactory.addParameter("iscollection", iscollection);
- sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- sqlFactory.addParameter("siteid", siteid);
- sqllist.add(sqlFactory.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());
- //定制信息
- CustomScheme customScheme = new CustomScheme(this);
- 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);
- }
- }
- //定制信息
- row = customScheme.setScheme(row, "width");
- row = customScheme.setScheme(row, "length");
- row = customScheme.setScheme(row, "material");
- row = customScheme.setScheme(row, "color");
- row = customScheme.setScheme(row, "cheek");
- }
- 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")));
- Rows tradefieldRows = tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows());
- row.put("tradefield", tradefieldRows);
- row.put("tradefield_shoppingcart", StringUtils.join(tradefieldRows.toArray("tradefield"), ","));
- row.put("brand", brandRowsMap.get(row.getString("itemid")));
- }
- return getSucReturnObject().setData(itemrows).toString();
- }
- }
|