| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- package restcontroller.sale.promotion;
- import beans.customscheme.CustomScheme;
- import beans.salearea.SaleArea;
- 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.data.Row;
- import common.data.Rows;
- import common.data.RowsMap;
- import common.data.SQLFactory;
- import org.apache.commons.lang.StringUtils;
- import restcontroller.R;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.ListIterator;
- public class promotion extends Controller {
- public promotion(JSONObject arg0) throws YosException {
- super(arg0);
- // TODO Auto-generated constructor stub
- }
- @API(title = "查询促销方案列表", apiversion = R.ID20220103140003.v1.class)
- @CACHEING
- public String querypromotionList() 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("t.promnum like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t.promname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t.remarks like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- SQLFactory sqlFactory = new SQLFactory(this, "促销方案列表查询", pageSize, pageNumber, pageSorting);
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- sqlFactory.addParameter_SQL("where", where);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- //默认商品图片
- Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
- //附件
- ArrayList<Long> ids = rows.toArrayList("sa_promotionid", new ArrayList<>());
- RowsMap attRowsMap = getAttachmentUrl("sa_promotion", ids);
- SQLFactory sqlFactory1 = new SQLFactory(this, "促销订单金额合计查询");
- sqlFactory1.addParameter("siteid", siteid);
- sqlFactory1.addParameter("sys_enterpriseid", sys_enterpriseid);
- Rows sumAmountRows = dbConnect.runSqlQuery(sqlFactory1.getSQL());
- RowsMap sumAmountRowsMap = sumAmountRows.toRowsMap("sa_promotionid");
- SQLFactory sqlFactory2 = new SQLFactory(this, "促销方案列表查询(触发的促销方案)");
- sqlFactory2.addParameter("siteid", siteid);
- sqlFactory2.addParameter("sys_enterpriseid", sys_enterpriseid);
- Rows openPromotionsRows = dbConnect.runSqlQuery(sqlFactory2.getSQL());
- RowsMap openPromotionsRowsMap = openPromotionsRows.toRowsMap("sa_promotionid");
- ListIterator<Row> iterator = rows.listIterator();
- while (iterator.hasNext()) {
- Row row = iterator.next();
- if (row.getLong("sa_openpromotionid") != 0) {
- if (sumAmountRowsMap.containsKey(row.getString("sa_promotionid"))) {
- BigDecimal sumamount = sumAmountRowsMap.get(row.getString("sa_promotionid")).get(0).getBigDecimal("sumamount");
- if (sumamount.compareTo(row.getBigDecimal("openamount")) >= 0) {
- if (openPromotionsRowsMap.containsKey(row.getString("sa_openpromotionid"))) {
- iterator.add(openPromotionsRowsMap.get(row.getString("sa_openpromotionid")).get(0));
- }
- }
- }
- }
- }
- 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);
- RowsMap promotionAuthRowsMap = promotionAuthRows.toRowsMap("sa_promotionid");
- for (Row row : rows) {
- if ((attRowsMap.getOrDefault(row.getString("sa_promotionid"), new Rows())).isEmpty()) {
- row.put("attinfos", defaultImageRows);
- } else {
- row.put("attinfos", attRowsMap.getOrDefault(row.getString("sa_promotionid"), new Rows()));
- }
- if (!StringUtils.isBlank(row.getString("tradefield"))) {
- row.put("tradefield", JSONArray.parseArray(row.getString("tradefield")));
- } else {
- row.put("tradefield", new JSONArray());
- }
- if (row.getString("type").equals("返利促销")) {
- if (promotionAuthRowsMap.containsKey(row.getString("sa_promotionid"))) {
- row.put("canuseamount", promotionAuthRowsMap.get(row.getString("sa_promotionid")).get(0).getBigDecimal("canuseamount"));
- } else {
- row.put("canuseamount", 0);
- }
- } else {
- row.put("canuseamount", 0);
- }
- // if(row.getLong("sa_openpromotionid")!=0){
- // if(sumAmountRowsMap.containsKey(row.getString("sa_promotionid"))){
- // BigDecimal sumamount = sumAmountRowsMap.get(row.getString("sa_promotionid")).get(0).getBigDecimal("sumamount");
- // if(sumamount.compareTo(row.getBigDecimal("openamount"))>=0){
- // if(openPromotionsRowsMap.containsKey(row.getString("sa_openpromotionid"))){
- // rows.add(openPromotionsRowsMap.get(row.getString("sa_openpromotionid")).get(0));
- // }
- // }
- // }
- // }
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "促销方案商品列表(业务端)", apiversion = R.ID20230116094803.v1.class)
- @CACHEING
- public String queryPromotionItemsList() 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.itemname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.model like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.standards like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.spec like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- if (whereObject.containsKey("packagetypemx") && !"".equals(whereObject.getString("packagetypemx"))) {
- where.append(" and(");
- where.append("t1.packagetypemx ='").append(whereObject.getString("packagetypemx")).append("' ");
- where.append(")");
- }
- }
- Long sa_promotionid = content.getLong("sa_promotionid");
- // Long sa_promotion_itemgroupid = content.getLong("sa_promotion_itemgroupid");
- SQLFactory sqlFactory = new SQLFactory(this, "促销方案商品查询", pageSize, pageNumber, pageSorting);
- sqlFactory.addParameter_SQL("where", where);
- sqlFactory.addParameter("sa_promotionid", sa_promotionid);
- // sqlFactory.addParameter("sa_promotion_itemgroupid", sa_promotion_itemgroupid);
- sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- sqlFactory.addParameter("siteid", siteid);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- ArrayList ids = rows.toArrayList("itemid", new ArrayList<>());
- //默认商品图片
- Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
- // 附件
- RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
- //商品领域
- RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
- //定制信息
- CustomScheme customScheme = new CustomScheme(this);
- for (Row row : rows) {
- 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("tradefield", tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
- //定制信息
- 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");
- if (row.getLong("width") == 0) {
- row.replace("width", null);
- }
- if (row.getLong("length") == 0) {
- row.replace("length", null);
- }
- row.putIfAbsent("saledqty", 0);
- row.putIfAbsent("islimit", 0);
- row.putIfAbsent("groupqty", 1);
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "查询促销方案列表(区域经理)", apiversion = R.ID20231025144003.v1.class)
- @CACHEING
- public String querypromotionList_regionalManager() 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("t.promnum like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t.promname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t.remarks like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- SQLFactory areasqlFactory = new SQLFactory(this, "区域经理查询下属营销区域");
- areasqlFactory.addParameter("siteid", siteid);
- areasqlFactory.addParameter("hrid", hrid);
- Rows arearows = dbConnect.runSqlQuery(areasqlFactory);
- ArrayList<Long> arrayList = arearows.toArrayList("sa_saleareaid", new ArrayList<Long>());
- arrayList.addAll(SaleArea.getSubSaleAreaIds(this, arrayList));
- SQLFactory sqlFactory = new SQLFactory(this, "促销方案列表查询(区域经理)", pageSize, pageNumber, pageSorting);
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter_in("sa_saleareaids", arrayList);
- sqlFactory.addParameter_SQL("where", where);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- //默认商品图片
- Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
- //附件
- ArrayList<Long> ids = rows.toArrayList("sa_promotionid", new ArrayList<>());
- RowsMap attRowsMap = getAttachmentUrl("sa_promotion", ids);
- // SQLFactory sqlFactory1 = new SQLFactory(this, "促销订单金额合计查询");
- // sqlFactory1.addParameter("siteid", siteid);
- // sqlFactory1.addParameter("sys_enterpriseid", sys_enterpriseid);
- // Rows sumAmountRows = dbConnect.runSqlQuery(sqlFactory1.getSQL());
- // RowsMap sumAmountRowsMap = sumAmountRows.toRowsMap("sa_promotionid");
- //
- // SQLFactory sqlFactory2 = new SQLFactory(this, "促销方案列表查询(触发的促销方案)");
- // sqlFactory2.addParameter("siteid", siteid);
- // sqlFactory2.addParameter("sys_enterpriseid", sys_enterpriseid);
- // Rows openPromotionsRows = dbConnect.runSqlQuery(sqlFactory2.getSQL());
- // RowsMap openPromotionsRowsMap = openPromotionsRows.toRowsMap("sa_promotionid");
- //
- // ListIterator<Row> iterator = rows.listIterator();
- // while (iterator.hasNext()) {
- // Row row = iterator.next();
- // if(row.getLong("sa_openpromotionid")!=0){
- // if(sumAmountRowsMap.containsKey(row.getString("sa_promotionid"))){
- // BigDecimal sumamount = sumAmountRowsMap.get(row.getString("sa_promotionid")).get(0).getBigDecimal("sumamount");
- // if(sumamount.compareTo(row.getBigDecimal("openamount"))>=0){
- // if(openPromotionsRowsMap.containsKey(row.getString("sa_openpromotionid"))){
- // iterator.add(openPromotionsRowsMap.get(row.getString("sa_openpromotionid")).get(0));
- // }
- // }
- // }
- // }
- // }
- //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);
- // RowsMap promotionAuthRowsMap = promotionAuthRows.toRowsMap("sa_promotionid");
- for (Row row : rows) {
- if ((attRowsMap.getOrDefault(row.getString("sa_promotionid"), new Rows())).isEmpty()) {
- row.put("attinfos", defaultImageRows);
- } else {
- row.put("attinfos", attRowsMap.getOrDefault(row.getString("sa_promotionid"), new Rows()));
- }
- if (!StringUtils.isBlank(row.getString("tradefield"))) {
- row.put("tradefield", JSONArray.parseArray(row.getString("tradefield")));
- } else {
- row.put("tradefield", new JSONArray());
- }
- // if(row.getString("type").equals("返利促销")){
- // if(promotionAuthRowsMap.containsKey(row.getString("sa_promotionid"))){
- // row.put("canuseamount", promotionAuthRowsMap.get(row.getString("sa_promotionid")).get(0).getBigDecimal("canuseamount"));
- // }else {
- // row.put("canuseamount", 0);
- // }
- //
- // }else{
- // row.put("canuseamount", 0);
- // }
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "促销方案商品列表(区域经理)", apiversion = R.ID20231025144103.v1.class)
- @CACHEING
- public String queryPromotionItemsList_regionalManager() 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.itemname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.model like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- Long sa_promotionid = content.getLong("sa_promotionid");
- // Long sa_promotion_itemgroupid = content.getLong("sa_promotion_itemgroupid");
- SQLFactory sqlFactory = new SQLFactory(this, "促销方案商品查询(区域经理)", pageSize, pageNumber, pageSorting);
- sqlFactory.addParameter_SQL("where", where);
- sqlFactory.addParameter("sa_promotionid", sa_promotionid);
- // sqlFactory.addParameter("sa_promotion_itemgroupid", sa_promotion_itemgroupid);
- sqlFactory.addParameter("siteid", siteid);
- Rows rows = dbConnect.runSqlQuery(sqlFactory);
- ArrayList ids = rows.toArrayList("itemid", new ArrayList<>());
- //默认商品图片
- Rows defaultImageRows = getAttachmentUrl("system", (long) 1, "defaultImage");
- // 附件
- RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
- //商品领域
- RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids);
- //定制信息
- CustomScheme customScheme = new CustomScheme(this);
- for (Row row : rows) {
- 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("tradefield", tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
- //定制信息
- 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");
- if (row.getLong("width") == 0) {
- row.replace("width", null);
- }
- if (row.getLong("length") == 0) {
- row.replace("length", null);
- }
- }
- return getSucReturnObject().setData(rows).toString();
- }
- }
|