promotion.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. package restcontroller.sale.promotion;
  2. import beans.customscheme.CustomScheme;
  3. import beans.salearea.SaleArea;
  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.data.Row;
  11. import common.data.Rows;
  12. import common.data.RowsMap;
  13. import common.data.SQLFactory;
  14. import org.apache.commons.lang.StringUtils;
  15. import restcontroller.R;
  16. import java.math.BigDecimal;
  17. import java.util.ArrayList;
  18. import java.util.ListIterator;
  19. public class promotion extends Controller {
  20. public promotion(JSONObject arg0) throws YosException {
  21. super(arg0);
  22. // TODO Auto-generated constructor stub
  23. }
  24. @API(title = "查询促销方案列表", apiversion = R.ID20220103140003.v1.class)
  25. @CACHEING
  26. public String querypromotionList() throws YosException {
  27. StringBuffer where = new StringBuffer(" 1=1 ");
  28. if (content.containsKey("where")) {
  29. JSONObject whereObject = content.getJSONObject("where");
  30. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  31. where.append(" and(");
  32. where.append("t.promnum like'%").append(whereObject.getString("condition")).append("%' ");
  33. where.append("or t.promname like'%").append(whereObject.getString("condition")).append("%' ");
  34. where.append("or t.remarks like'%").append(whereObject.getString("condition")).append("%' ");
  35. where.append(")");
  36. }
  37. }
  38. SQLFactory sqlFactory = new SQLFactory(this, "促销方案列表查询", pageSize, pageNumber, pageSorting);
  39. sqlFactory.addParameter("siteid", siteid);
  40. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  41. sqlFactory.addParameter_SQL("where", where);
  42. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  43. //默认商品图片
  44. Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
  45. //附件
  46. ArrayList<Long> ids = rows.toArrayList("sa_promotionid", new ArrayList<>());
  47. RowsMap attRowsMap = getAttachmentUrl("sa_promotion", ids);
  48. SQLFactory sqlFactory1 = new SQLFactory(this, "促销订单金额合计查询");
  49. sqlFactory1.addParameter("siteid", siteid);
  50. sqlFactory1.addParameter("sys_enterpriseid", sys_enterpriseid);
  51. Rows sumAmountRows = dbConnect.runSqlQuery(sqlFactory1.getSQL());
  52. RowsMap sumAmountRowsMap = sumAmountRows.toRowsMap("sa_promotionid");
  53. SQLFactory sqlFactory2 = new SQLFactory(this, "促销方案列表查询(触发的促销方案)");
  54. sqlFactory2.addParameter("siteid", siteid);
  55. sqlFactory2.addParameter("sys_enterpriseid", sys_enterpriseid);
  56. Rows openPromotionsRows = dbConnect.runSqlQuery(sqlFactory2.getSQL());
  57. RowsMap openPromotionsRowsMap = openPromotionsRows.toRowsMap("sa_promotionid");
  58. ListIterator<Row> iterator = rows.listIterator();
  59. while (iterator.hasNext()) {
  60. Row row = iterator.next();
  61. if (row.getLong("sa_openpromotionid") != 0) {
  62. if (sumAmountRowsMap.containsKey(row.getString("sa_promotionid"))) {
  63. BigDecimal sumamount = sumAmountRowsMap.get(row.getString("sa_promotionid")).get(0).getBigDecimal("sumamount");
  64. if (sumamount.compareTo(row.getBigDecimal("openamount")) >= 0) {
  65. if (openPromotionsRowsMap.containsKey(row.getString("sa_openpromotionid"))) {
  66. iterator.add(openPromotionsRowsMap.get(row.getString("sa_openpromotionid")).get(0));
  67. }
  68. }
  69. }
  70. }
  71. }
  72. Rows promotionAuthRows = dbConnect.runSqlQuery("select t1.sa_promotionid,ifnull(t1.limitamount,0)-ifnull(t1.saledamount,0) canuseamount from sa_promotion_auth t1 inner join sa_promotion t2 on t1.sa_promotionid=t2.sa_promotionid and t1.siteid=t2.siteid where t1.sys_enterpriseid=" + sys_enterpriseid);
  73. RowsMap promotionAuthRowsMap = promotionAuthRows.toRowsMap("sa_promotionid");
  74. for (Row row : rows) {
  75. if ((attRowsMap.getOrDefault(row.getString("sa_promotionid"), new Rows())).isEmpty()) {
  76. row.put("attinfos", defaultImageRows);
  77. } else {
  78. row.put("attinfos", attRowsMap.getOrDefault(row.getString("sa_promotionid"), new Rows()));
  79. }
  80. if (!StringUtils.isBlank(row.getString("tradefield"))) {
  81. row.put("tradefield", JSONArray.parseArray(row.getString("tradefield")));
  82. } else {
  83. row.put("tradefield", new JSONArray());
  84. }
  85. if (row.getString("type").equals("返利促销")) {
  86. if (promotionAuthRowsMap.containsKey(row.getString("sa_promotionid"))) {
  87. row.put("canuseamount", promotionAuthRowsMap.get(row.getString("sa_promotionid")).get(0).getBigDecimal("canuseamount"));
  88. } else {
  89. row.put("canuseamount", 0);
  90. }
  91. } else {
  92. row.put("canuseamount", 0);
  93. }
  94. // if(row.getLong("sa_openpromotionid")!=0){
  95. // if(sumAmountRowsMap.containsKey(row.getString("sa_promotionid"))){
  96. // BigDecimal sumamount = sumAmountRowsMap.get(row.getString("sa_promotionid")).get(0).getBigDecimal("sumamount");
  97. // if(sumamount.compareTo(row.getBigDecimal("openamount"))>=0){
  98. // if(openPromotionsRowsMap.containsKey(row.getString("sa_openpromotionid"))){
  99. // rows.add(openPromotionsRowsMap.get(row.getString("sa_openpromotionid")).get(0));
  100. // }
  101. // }
  102. // }
  103. // }
  104. }
  105. return getSucReturnObject().setData(rows).toString();
  106. }
  107. @API(title = "促销方案商品列表(业务端)", apiversion = R.ID20230116094803.v1.class)
  108. @CACHEING
  109. public String queryPromotionItemsList() throws YosException {
  110. /*
  111. * 过滤条件设置
  112. */
  113. StringBuffer where = new StringBuffer(" 1=1 ");
  114. if (content.containsKey("where")) {
  115. JSONObject whereObject = content.getJSONObject("where");
  116. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  117. where.append(" and(");
  118. where.append("t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
  119. where.append("or t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
  120. where.append("or t2.model like'%").append(whereObject.getString("condition")).append("%' ");
  121. where.append("or t2.standards like'%").append(whereObject.getString("condition")).append("%' ");
  122. where.append("or t2.spec like'%").append(whereObject.getString("condition")).append("%' ");
  123. where.append(")");
  124. }
  125. if (whereObject.containsKey("packagetypemx") && !"".equals(whereObject.getString("packagetypemx"))) {
  126. where.append(" and(");
  127. where.append("t1.packagetypemx ='").append(whereObject.getString("packagetypemx")).append("' ");
  128. where.append(")");
  129. }
  130. }
  131. Long sa_promotionid = content.getLong("sa_promotionid");
  132. // Long sa_promotion_itemgroupid = content.getLong("sa_promotion_itemgroupid");
  133. SQLFactory sqlFactory = new SQLFactory(this, "促销方案商品查询", pageSize, pageNumber, pageSorting);
  134. sqlFactory.addParameter_SQL("where", where);
  135. sqlFactory.addParameter("sa_promotionid", sa_promotionid);
  136. // sqlFactory.addParameter("sa_promotion_itemgroupid", sa_promotion_itemgroupid);
  137. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  138. sqlFactory.addParameter("siteid", siteid);
  139. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  140. ArrayList ids = rows.toArrayList("itemid", new ArrayList<>());
  141. //默认商品图片
  142. Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
  143. // 附件
  144. RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
  145. //商品领域
  146. RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
  147. //定制信息
  148. CustomScheme customScheme = new CustomScheme(this);
  149. for (Row row : rows) {
  150. if ((attRowsMap.getOrDefault(row.getString("itemid"), new Rows())).isEmpty()) {
  151. row.put("attinfos", defaultImageRows);
  152. } else {
  153. row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  154. }
  155. row.put("tradefield", tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  156. //定制信息
  157. row = customScheme.setScheme(row, "width");
  158. row = customScheme.setScheme(row, "length");
  159. row = customScheme.setScheme(row, "material");
  160. row = customScheme.setScheme(row, "color");
  161. row = customScheme.setScheme(row, "cheek");
  162. if (row.getLong("width") == 0) {
  163. row.replace("width", null);
  164. }
  165. if (row.getLong("length") == 0) {
  166. row.replace("length", null);
  167. }
  168. row.putIfAbsent("saledqty", 0);
  169. row.putIfAbsent("islimit", 0);
  170. row.putIfAbsent("groupqty", 1);
  171. }
  172. return getSucReturnObject().setData(rows).toString();
  173. }
  174. @API(title = "查询促销方案列表(区域经理)", apiversion = R.ID20231025144003.v1.class)
  175. @CACHEING
  176. public String querypromotionList_regionalManager() throws YosException {
  177. StringBuffer where = new StringBuffer(" 1=1 ");
  178. if (content.containsKey("where")) {
  179. JSONObject whereObject = content.getJSONObject("where");
  180. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  181. where.append(" and(");
  182. where.append("t.promnum like'%").append(whereObject.getString("condition")).append("%' ");
  183. where.append("or t.promname like'%").append(whereObject.getString("condition")).append("%' ");
  184. where.append("or t.remarks like'%").append(whereObject.getString("condition")).append("%' ");
  185. where.append(")");
  186. }
  187. }
  188. SQLFactory areasqlFactory = new SQLFactory(this, "区域经理查询下属营销区域");
  189. areasqlFactory.addParameter("siteid", siteid);
  190. areasqlFactory.addParameter("hrid", hrid);
  191. Rows arearows = dbConnect.runSqlQuery(areasqlFactory);
  192. ArrayList<Long> arrayList = arearows.toArrayList("sa_saleareaid", new ArrayList<Long>());
  193. arrayList.addAll(SaleArea.getSubSaleAreaIds(this, arrayList));
  194. SQLFactory sqlFactory = new SQLFactory(this, "促销方案列表查询(区域经理)", pageSize, pageNumber, pageSorting);
  195. sqlFactory.addParameter("siteid", siteid);
  196. sqlFactory.addParameter_in("sa_saleareaids", arrayList);
  197. sqlFactory.addParameter_SQL("where", where);
  198. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  199. //默认商品图片
  200. Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
  201. //附件
  202. ArrayList<Long> ids = rows.toArrayList("sa_promotionid", new ArrayList<>());
  203. RowsMap attRowsMap = getAttachmentUrl("sa_promotion", ids);
  204. // SQLFactory sqlFactory1 = new SQLFactory(this, "促销订单金额合计查询");
  205. // sqlFactory1.addParameter("siteid", siteid);
  206. // sqlFactory1.addParameter("sys_enterpriseid", sys_enterpriseid);
  207. // Rows sumAmountRows = dbConnect.runSqlQuery(sqlFactory1.getSQL());
  208. // RowsMap sumAmountRowsMap = sumAmountRows.toRowsMap("sa_promotionid");
  209. //
  210. // SQLFactory sqlFactory2 = new SQLFactory(this, "促销方案列表查询(触发的促销方案)");
  211. // sqlFactory2.addParameter("siteid", siteid);
  212. // sqlFactory2.addParameter("sys_enterpriseid", sys_enterpriseid);
  213. // Rows openPromotionsRows = dbConnect.runSqlQuery(sqlFactory2.getSQL());
  214. // RowsMap openPromotionsRowsMap = openPromotionsRows.toRowsMap("sa_promotionid");
  215. //
  216. // ListIterator<Row> iterator = rows.listIterator();
  217. // while (iterator.hasNext()) {
  218. // Row row = iterator.next();
  219. // if(row.getLong("sa_openpromotionid")!=0){
  220. // if(sumAmountRowsMap.containsKey(row.getString("sa_promotionid"))){
  221. // BigDecimal sumamount = sumAmountRowsMap.get(row.getString("sa_promotionid")).get(0).getBigDecimal("sumamount");
  222. // if(sumamount.compareTo(row.getBigDecimal("openamount"))>=0){
  223. // if(openPromotionsRowsMap.containsKey(row.getString("sa_openpromotionid"))){
  224. // iterator.add(openPromotionsRowsMap.get(row.getString("sa_openpromotionid")).get(0));
  225. // }
  226. // }
  227. // }
  228. // }
  229. // }
  230. //Rows promotionAuthRows = dbConnect.runSqlQuery("select t1.sa_promotionid,ifnull(t1.limitamount,0)-ifnull(t1.saledamount,0) canuseamount from sa_promotion_auth t1 inner join sa_promotion t2 on t1.sa_promotionid=t2.sa_promotionid and t1.siteid=t2.siteid where t1.sys_enterpriseid="+sys_enterpriseid);
  231. // RowsMap promotionAuthRowsMap = promotionAuthRows.toRowsMap("sa_promotionid");
  232. for (Row row : rows) {
  233. if ((attRowsMap.getOrDefault(row.getString("sa_promotionid"), new Rows())).isEmpty()) {
  234. row.put("attinfos", defaultImageRows);
  235. } else {
  236. row.put("attinfos", attRowsMap.getOrDefault(row.getString("sa_promotionid"), new Rows()));
  237. }
  238. if (!StringUtils.isBlank(row.getString("tradefield"))) {
  239. row.put("tradefield", JSONArray.parseArray(row.getString("tradefield")));
  240. } else {
  241. row.put("tradefield", new JSONArray());
  242. }
  243. // if(row.getString("type").equals("返利促销")){
  244. // if(promotionAuthRowsMap.containsKey(row.getString("sa_promotionid"))){
  245. // row.put("canuseamount", promotionAuthRowsMap.get(row.getString("sa_promotionid")).get(0).getBigDecimal("canuseamount"));
  246. // }else {
  247. // row.put("canuseamount", 0);
  248. // }
  249. //
  250. // }else{
  251. // row.put("canuseamount", 0);
  252. // }
  253. }
  254. return getSucReturnObject().setData(rows).toString();
  255. }
  256. @API(title = "促销方案商品列表(区域经理)", apiversion = R.ID20231025144103.v1.class)
  257. @CACHEING
  258. public String queryPromotionItemsList_regionalManager() throws YosException {
  259. /*
  260. * 过滤条件设置
  261. */
  262. StringBuffer where = new StringBuffer(" 1=1 ");
  263. if (content.containsKey("where")) {
  264. JSONObject whereObject = content.getJSONObject("where");
  265. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  266. where.append(" and(");
  267. where.append("t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
  268. where.append("or t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
  269. where.append("or t2.model like'%").append(whereObject.getString("condition")).append("%' ");
  270. where.append(")");
  271. }
  272. }
  273. Long sa_promotionid = content.getLong("sa_promotionid");
  274. // Long sa_promotion_itemgroupid = content.getLong("sa_promotion_itemgroupid");
  275. SQLFactory sqlFactory = new SQLFactory(this, "促销方案商品查询(区域经理)", pageSize, pageNumber, pageSorting);
  276. sqlFactory.addParameter_SQL("where", where);
  277. sqlFactory.addParameter("sa_promotionid", sa_promotionid);
  278. // sqlFactory.addParameter("sa_promotion_itemgroupid", sa_promotion_itemgroupid);
  279. sqlFactory.addParameter("siteid", siteid);
  280. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  281. ArrayList ids = rows.toArrayList("itemid", new ArrayList<>());
  282. //默认商品图片
  283. Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
  284. // 附件
  285. RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
  286. //商品领域
  287. RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
  288. //定制信息
  289. CustomScheme customScheme = new CustomScheme(this);
  290. for (Row row : rows) {
  291. if ((attRowsMap.getOrDefault(row.getString("itemid"), new Rows())).isEmpty()) {
  292. row.put("attinfos", defaultImageRows);
  293. } else {
  294. row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  295. }
  296. row.put("tradefield", tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
  297. //定制信息
  298. row = customScheme.setScheme(row, "width");
  299. row = customScheme.setScheme(row, "length");
  300. row = customScheme.setScheme(row, "material");
  301. row = customScheme.setScheme(row, "color");
  302. row = customScheme.setScheme(row, "cheek");
  303. if (row.getLong("width") == 0) {
  304. row.replace("width", null);
  305. }
  306. if (row.getLong("length") == 0) {
  307. row.replace("length", null);
  308. }
  309. }
  310. return getSucReturnObject().setData(rows).toString();
  311. }
  312. }