PromotionOrder.java 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package restcontroller.webmanage.sale.order;
  2. import beans.brand.Brand;
  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.data.Row;
  10. import common.data.Rows;
  11. import common.data.RowsMap;
  12. import common.data.SQLFactory;
  13. import restcontroller.R;
  14. import java.util.ArrayList;
  15. import static beans.order.Order.getOrderRows;
  16. /**
  17. * 促销订单相关接口
  18. */
  19. public class PromotionOrder extends Controller {
  20. /**
  21. * 构造函数
  22. *
  23. * @param content
  24. */
  25. public PromotionOrder(JSONObject content) throws YosException {
  26. super(content);
  27. }
  28. /**
  29. * 查询订货企业授权的促销方案列表
  30. *
  31. * @return
  32. */
  33. @API(title = "查询促销方案列表", apiversion = R.ID20230107182102.v1.class)
  34. public String selectPromotionList() throws YosException {
  35. StringBuffer where = new StringBuffer(" 1=1 ");
  36. if (content.containsKey("where")) {
  37. JSONObject whereObject = content.getJSONObject("where");
  38. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  39. where.append(" and(");
  40. where.append("t.promnum like'%").append(whereObject.getString("condition")).append("%' ");
  41. where.append("or t.promname like'%").append(whereObject.getString("condition")).append("%' ");
  42. where.append("or t.remarks like'%").append(whereObject.getString("condition")).append("%' ");
  43. where.append(")");
  44. }
  45. }
  46. if (content.containsKey("sys_enterpriseid")) {
  47. sys_enterpriseid = content.getLongValue("sys_enterpriseid");
  48. }
  49. SQLFactory sqlFactory = new SQLFactory(this, "促销方案列表查询", pageSize, pageNumber, pageSorting);
  50. sqlFactory.addParameter("siteid", siteid);
  51. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  52. sqlFactory.addParameter_SQL("where", where);
  53. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  54. return getSucReturnObject().setData(rows).toString();
  55. }
  56. @API(title = "查询促销方案中的商品列表", apiversion = R.ID20230107182302.v1.class)
  57. public String selectPromotionItemsList() throws YosException {
  58. StringBuffer where = new StringBuffer(" 1=1 ");
  59. if (content.containsKey("where")) {
  60. JSONObject whereObject = content.getJSONObject("where");
  61. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  62. where.append(" and(");
  63. where.append("t1.itemno like'%").append(whereObject.getString("condition")).append("%' ");
  64. where.append("or t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
  65. where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
  66. where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
  67. where.append(")");
  68. }
  69. }
  70. Long sa_orderid = content.getLong("sa_orderid");
  71. Rows orderRows = getOrderRows(this,sa_orderid);
  72. Long sa_promotionid = -1L;
  73. if (orderRows.isNotEmpty()) {
  74. sa_promotionid = orderRows.get(0).getLong("sa_promotionid");
  75. sys_enterpriseid = orderRows.get(0).getLong("sys_enterpriseid");
  76. }
  77. // ArrayList<Long> itemids = getOrderItemsList(sa_orderid, sa_promotionid);
  78. // itemids.add(-1L);
  79. SQLFactory sqlFactory = new SQLFactory(this, "促销方案商品列表", pageSize, pageNumber, pageSorting);
  80. sqlFactory.addParameter("siteid", siteid);
  81. // sqlFactory.addParameter_in("itemid", itemids);
  82. sqlFactory.addParameter("sa_promotionid", sa_promotionid);
  83. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  84. sqlFactory.addParameter_SQL("where", where);
  85. String sql = sqlFactory.getSQL();
  86. Rows rows = dbConnect.runSqlQuery(sql);
  87. ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
  88. //查询附件
  89. RowsMap attinfoRowsMap = getAttachmentUrl("plm_item", ids);
  90. //商品领域
  91. RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
  92. //品牌
  93. RowsMap brandRowsMap = Brand.getBrandRowsMap(this, ids);
  94. Rows sizecustomizedschemes=dbConnect.runSqlQuery("select * from sa_sizecustomizedscheme where siteid='"+siteid+"' ");
  95. RowsMap sizecustomizedschemesRowsMap=sizecustomizedschemes.toRowsMap("sa_sizecustomizedschemeid");
  96. Rows sizeschemedetails=dbConnect.runSqlQuery("select * from sa_sizeschemedetail where siteid='"+siteid+"' ");
  97. RowsMap sizeschemedetailsRowsMap=sizeschemedetails.toRowsMap("sa_sizecustomizedschemeid");
  98. for (Row row : rows) {
  99. row.put("attinfos", attinfoRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  100. row.put("tradefield", tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  101. row.put("brand", brandRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  102. if(row.getLong("widthschemeid")!=0){
  103. if(sizecustomizedschemesRowsMap.containsKey(row.getString("widthschemeid"))){
  104. if(sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).isNotEmpty()){
  105. row.put("widthtype",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getString("type"));
  106. row.put("widthmin",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getBigDecimal("min"));
  107. row.put("widthmax",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getBigDecimal("max"));
  108. row.put("widthdecimalplaces",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getBigDecimal("decimalplaces"));
  109. if(sizeschemedetailsRowsMap.containsKey(row.getString("widthschemeid"))){
  110. row.put("widthschemedetails",sizeschemedetailsRowsMap.get(row.getString("widthschemeid")));
  111. }else{
  112. row.put("widthschemedetails",new JSONArray());
  113. }
  114. }
  115. }
  116. }
  117. if(row.getLong("lengthschemeid")!=0){
  118. if(sizecustomizedschemesRowsMap.containsKey(row.getString("lengthschemeid"))){
  119. if(sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).isNotEmpty()){
  120. row.put("lengthtype",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getString("type"));
  121. row.put("lengthmin",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getBigDecimal("min"));
  122. row.put("lengthmax",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getBigDecimal("max"));
  123. row.put("lengthdecimalplaces",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getBigDecimal("decimalplaces"));
  124. if(sizeschemedetailsRowsMap.containsKey(row.getString("lengthschemeid"))){
  125. row.put("lengthschemedetails",sizeschemedetailsRowsMap.get(row.getString("lengthschemeid")));
  126. }else{
  127. row.put("lengthschemedetails",new JSONArray());
  128. }
  129. }
  130. }
  131. }
  132. }
  133. return getSucReturnObject().setData(rows).toString();
  134. }
  135. // public ArrayList<Long> getOrderItemsList(Long sa_orderid, Long sa_promotionid) throws YosException {
  136. // 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 + "')";
  137. // Rows rows = dbConnect.runSqlQuery(sql);
  138. // return rows.toArrayList("itemid", new ArrayList<>());
  139. // }
  140. }