PromotionOrder.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package restcontroller.webmanage.sale.order;
  2. import beans.brand.Brand;
  3. import beans.itemprice.ItemPrice;
  4. import com.alibaba.fastjson.JSONObject;
  5. import common.Controller;
  6. import common.YosException;
  7. import common.annotation.API;
  8. import common.data.Row;
  9. import common.data.Rows;
  10. import common.data.RowsMap;
  11. import common.data.SQLFactory;
  12. import restcontroller.R;
  13. import java.util.ArrayList;
  14. import static beans.order.Order.getOrderRows;
  15. /**
  16. * 促销订单相关接口
  17. */
  18. public class PromotionOrder extends Controller {
  19. /**
  20. * 构造函数
  21. *
  22. * @param content
  23. */
  24. public PromotionOrder(JSONObject content) throws YosException {
  25. super(content);
  26. }
  27. /**
  28. * 查询订货企业授权的促销方案列表
  29. *
  30. * @return
  31. */
  32. @API(title = "查询促销方案列表", apiversion = R.ID20230107182102.v1.class)
  33. public String selectPromotionList() throws YosException {
  34. StringBuffer where = new StringBuffer(" 1=1 ");
  35. if (content.containsKey("where")) {
  36. JSONObject whereObject = content.getJSONObject("where");
  37. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  38. where.append(" and(");
  39. where.append("t.promnum like'%").append(whereObject.getString("condition")).append("%' ");
  40. where.append("or t.promname like'%").append(whereObject.getString("condition")).append("%' ");
  41. where.append("or t.remarks like'%").append(whereObject.getString("condition")).append("%' ");
  42. where.append(")");
  43. }
  44. }
  45. if (content.containsKey("sys_enterpriseid")) {
  46. sys_enterpriseid = content.getLongValue("sys_enterpriseid");
  47. }
  48. SQLFactory sqlFactory = new SQLFactory(this, "促销方案列表查询", pageSize, pageNumber, pageSorting);
  49. sqlFactory.addParameter("siteid", siteid);
  50. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  51. sqlFactory.addParameter_SQL("where", where);
  52. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  53. return getSucReturnObject().setData(rows).toString();
  54. }
  55. @API(title = "查询促销方案中的商品列表", apiversion = R.ID20230107182302.v1.class)
  56. public String selectPromotionItemsList() throws YosException {
  57. StringBuffer where = new StringBuffer(" 1=1 ");
  58. if (content.containsKey("where")) {
  59. JSONObject whereObject = content.getJSONObject("where");
  60. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  61. where.append(" and(");
  62. where.append("t1.itemno like'%").append(whereObject.getString("condition")).append("%' ");
  63. where.append("or t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
  64. where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
  65. where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
  66. where.append(")");
  67. }
  68. }
  69. Long sa_orderid = content.getLong("sa_orderid");
  70. Rows orderRows = getOrderRows(this,sa_orderid);
  71. Long sa_promotionid = -1L;
  72. if (orderRows.isNotEmpty()) {
  73. sa_promotionid = orderRows.get(0).getLong("sa_promotionid");
  74. sys_enterpriseid = orderRows.get(0).getLong("sys_enterpriseid");
  75. }
  76. // ArrayList<Long> itemids = getOrderItemsList(sa_orderid, sa_promotionid);
  77. // itemids.add(-1L);
  78. SQLFactory sqlFactory = new SQLFactory(this, "促销方案商品列表", pageSize, pageNumber, pageSorting);
  79. sqlFactory.addParameter("siteid", siteid);
  80. // sqlFactory.addParameter_in("itemid", itemids);
  81. sqlFactory.addParameter("sa_promotionid", sa_promotionid);
  82. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  83. sqlFactory.addParameter_SQL("where", where);
  84. String sql = sqlFactory.getSQL();
  85. Rows rows = dbConnect.runSqlQuery(sql);
  86. ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
  87. //查询附件
  88. RowsMap attinfoRowsMap = getAttachmentUrl("plm_item", ids);
  89. //商品领域
  90. RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
  91. //品牌
  92. RowsMap brandRowsMap = Brand.getBrandRowsMap(this, ids);
  93. for (Row row : rows) {
  94. row.put("attinfos", attinfoRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  95. row.put("tradefield", tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  96. row.put("brand", brandRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  97. }
  98. return getSucReturnObject().setData(rows).toString();
  99. }
  100. // public ArrayList<Long> getOrderItemsList(Long sa_orderid, Long sa_promotionid) throws YosException {
  101. // String sql = "SELECT distinct itemid from sa_promotion_itemprice WHERE sa_promotionid = '" + sa_promotionid + "' and siteid = '" + siteid + "' and itemid not in (SELECT itemid from sa_orderitems WHERE sa_orderid = " + sa_orderid + " and siteid = '" + siteid + "')";
  102. // Rows rows = dbConnect.runSqlQuery(sql);
  103. // return rows.toArrayList("itemid", new ArrayList<>());
  104. // }
  105. }