favorites.java 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package restcontroller.sale.favorites;
  2. import beans.customscheme.CustomScheme;
  3. import beans.itemprice.ItemPrice;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import common.Controller;
  7. import common.YosException;
  8. import common.annotation.API;
  9. import common.annotation.CACHEING;
  10. import common.annotation.CACHEING_CLEAN;
  11. import common.data.Row;
  12. import common.data.Rows;
  13. import common.data.RowsMap;
  14. import common.data.SQLFactory;
  15. import org.apache.commons.lang.StringUtils;
  16. import restcontroller.R;
  17. import restcontroller.webmanage.sale.itemgroup.itemgroup;
  18. import java.math.BigDecimal;
  19. import java.util.ArrayList;
  20. public class favorites extends Controller {
  21. /**
  22. * 构造函数
  23. *
  24. * @param content
  25. */
  26. public favorites(JSONObject content) throws YosException {
  27. super(content);
  28. }
  29. /**
  30. * 商品收藏
  31. *
  32. * @return
  33. */
  34. @API(title = "商品收藏", apiversion = R.ID20231121143403.v1.class, intervaltime = 200)
  35. @CACHEING_CLEAN(apiClass = {itemgroup.class, restcontroller.sale.itemgroup.itemgroup.class, favorites.class})
  36. public String insertormodify_item() throws YosException {
  37. long itemid = content.getLongValue("itemid");
  38. boolean iscollection = content.getBooleanValue("iscollection");
  39. BigDecimal qty = content.getBigDecimalValue("qty");
  40. BigDecimal width = content.getBigDecimalValue("width");
  41. BigDecimal length = content.getBigDecimalValue("length");
  42. Rows favoritesRows = dbConnect.runSqlQuery("select * from sa_favorites where sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "' and itemid='" + itemid + "'");
  43. ArrayList<String> sqllist = new ArrayList<>();
  44. SQLFactory sqlAddFactory = new SQLFactory(this, "商品收藏记录新增");
  45. if (favoritesRows.isEmpty()) {
  46. sqlAddFactory.addParameter("itemid", itemid);
  47. sqlAddFactory.addParameter("sa_favoritesid", createTableID("sa_favorites"));
  48. sqlAddFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  49. sqlAddFactory.addParameter("iscollection", iscollection);
  50. sqlAddFactory.addParameter("siteid", siteid);
  51. sqlAddFactory.addParameter("qty", qty);
  52. sqlAddFactory.addParameter("width", width);
  53. sqlAddFactory.addParameter("length", length);
  54. } else {
  55. sqlAddFactory = new SQLFactory(this, "商品收藏记录更新");
  56. sqlAddFactory.addParameter("sa_favoritesid", favoritesRows.get(0).getLong("sa_favoritesid"));
  57. sqlAddFactory.addParameter("iscollection", iscollection);
  58. sqlAddFactory.addParameter("siteid", siteid);
  59. sqlAddFactory.addParameter("qty", qty);
  60. sqlAddFactory.addParameter("width", width);
  61. sqlAddFactory.addParameter("length", length);
  62. }
  63. sqllist.add(sqlAddFactory.getSQL());
  64. dbConnect.runSqlUpdate(sqllist);
  65. return getSucReturnObject().toString();
  66. }
  67. /**
  68. * 商品批量收藏
  69. *
  70. * @return
  71. */
  72. @API(title = "商品批量收藏", apiversion = R.ID20231122102803.v1.class, intervaltime = 200)
  73. @CACHEING_CLEAN(apiClass = {itemgroup.class, restcontroller.sale.itemgroup.itemgroup.class, favorites.class})
  74. public String items_collect() throws YosException {
  75. JSONArray itemids = content.getJSONArray("itemids");
  76. boolean iscollection = content.getBooleanValue("iscollection");
  77. ArrayList<String> sqllist = new ArrayList<>();
  78. SQLFactory sqlFactory = new SQLFactory(this, "商品收藏记录批量更新");
  79. sqlFactory.addParameter_in("itemids", itemids.toArray());
  80. sqlFactory.addParameter("iscollection", iscollection);
  81. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  82. sqlFactory.addParameter("siteid", siteid);
  83. sqllist.add(sqlFactory.getSQL());
  84. dbConnect.runSqlUpdate(sqllist);
  85. return getSucReturnObject().toString();
  86. }
  87. @API(title = "商品收藏列表", apiversion = R.ID20231121145103.v1.class)
  88. @CACHEING
  89. public String querycollectionmx() throws YosException {
  90. /*
  91. 过滤条件设置
  92. */
  93. StringBuffer where = new StringBuffer(" 1=1 ");
  94. if (content.containsKey("where")) {
  95. JSONObject whereObject = content.getJSONObject("where");
  96. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  97. where.append(" and(");
  98. where.append("t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
  99. where.append("or t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
  100. where.append(")");
  101. }
  102. }
  103. /**
  104. * 查询商品明细
  105. */
  106. SQLFactory priceSqlFactory = new SQLFactory(this, "查询收藏商品原价");
  107. priceSqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  108. priceSqlFactory.addParameter("siteid", siteid);
  109. Rows pricerows = dbConnect.runSqlQuery(priceSqlFactory);
  110. RowsMap pricerowsMap = pricerows.toRowsMap("itemid");
  111. SQLFactory sqlFactory = new SQLFactory(this, "查询收藏商品列表", pageSize, pageNumber, pageSorting);
  112. sqlFactory.addParameter_SQL("where", where);
  113. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  114. sqlFactory.addParameter("siteid", siteid);
  115. Rows itemrows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  116. //定制信息
  117. CustomScheme customScheme = new CustomScheme(this);
  118. for (Row row : itemrows) {
  119. ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, row.getLong("itemid"));
  120. row.put("oldprice", itemPrice.getPrice());
  121. if (sys_enterpriseid > 0 || (usertype == 21 || usertype == 22)) {
  122. row.put("gradeprice", itemPrice.getContractprice());
  123. } else {
  124. if (pricerowsMap.containsKey(row.getString("itemid"))) {
  125. if (pricerowsMap.get(row.getString("itemid")).isNotEmpty()) {
  126. row.put("gradeprice", pricerowsMap.get(row.getString("itemid")).get(0).getBigDecimal("price"));
  127. } else {
  128. row.put("gradeprice", 0);
  129. }
  130. } else {
  131. row.put("gradeprice", 0);
  132. }
  133. }
  134. //定制信息
  135. row = customScheme.setScheme(row, "width");
  136. row = customScheme.setScheme(row, "length");
  137. row = customScheme.setScheme(row, "material");
  138. row = customScheme.setScheme(row, "color");
  139. row = customScheme.setScheme(row, "cheek");
  140. }
  141. ArrayList<Long> ids = itemrows.toArrayList("itemid", new ArrayList<>());
  142. //默认商品图片
  143. Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
  144. // 封面cover
  145. RowsMap coverRowsMap = getAttachmentUrl("plm_item", ids, "cover");
  146. // 附件
  147. RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
  148. Rows rowsitemclass = dbConnect.runSqlQuery(
  149. " 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='"
  150. + siteid + "'");
  151. RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
  152. // 货品档案领域
  153. Rows rowstradefield = dbConnect.runSqlQuery(
  154. " select t6.itemid,t6.tradefield from plm_item_tradefield t6 where t6.siteid='" + siteid + "'");
  155. RowsMap tradefieldRowsMap = rowstradefield.toRowsMap("itemid");
  156. // 品牌
  157. Rows rowsbrand = dbConnect.runSqlQuery(
  158. " 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='"
  159. + siteid + "'");
  160. RowsMap brandRowsMap = rowsbrand.toRowsMap("itemid");
  161. for (Row row : itemrows) {
  162. Rows coverRows = coverRowsMap.get(row.getString("itemid"));
  163. if (coverRows.isEmpty()) {
  164. row.put("cover", "");
  165. } else {
  166. row.put("cover", coverRows.get(0).getString("url"));
  167. }
  168. if ((attRowsMap.getOrDefault(row.getString("itemid"), new Rows())).isEmpty()) {
  169. row.put("attinfos", defaultImageRows);
  170. } else {
  171. row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  172. }
  173. row.put("itemclass", itemclassRowsMap.get(row.getString("itemid")));
  174. Rows tradefieldRows = tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows());
  175. row.put("tradefield", tradefieldRows);
  176. row.put("tradefield_shoppingcart", StringUtils.join(tradefieldRows.toArray("tradefield"), ","));
  177. row.put("brand", brandRowsMap.get(row.getString("itemid")));
  178. }
  179. return getSucReturnObject().setData(itemrows).toString();
  180. }
  181. }