| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- package restcontroller.sale.promotion;
- 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(")");
- }
- }
- 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);
- Rows sizecustomizedschemes=dbConnect.runSqlQuery("select * from sa_sizecustomizedscheme where siteid='"+siteid+"' ");
- RowsMap sizecustomizedschemesRowsMap=sizecustomizedschemes.toRowsMap("sa_sizecustomizedschemeid");
- Rows sizeschemedetails=dbConnect.runSqlQuery("select * from sa_sizeschemedetail where siteid='"+siteid+"' ");
- RowsMap sizeschemedetailsRowsMap=sizeschemedetails.toRowsMap("sa_sizecustomizedschemeid");
- 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()));
- if(row.getLong("widthschemeid")!=0){
- if(sizecustomizedschemesRowsMap.containsKey(row.getString("widthschemeid"))){
- if(sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).isNotEmpty()){
- row.put("widthtype",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getString("type"));
- row.put("widthmin",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getBigDecimal("min"));
- row.put("widthmax",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getBigDecimal("max"));
- row.put("widthdecimalplaces",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getBigDecimal("decimalplaces"));
- if(sizeschemedetailsRowsMap.containsKey(row.getString("widthschemeid"))){
- row.put("widthschemedetails",sizeschemedetailsRowsMap.get(row.getString("widthschemeid")));
- }else{
- row.put("widthschemedetails",new JSONArray());
- }
- }
- }
- }
- if(row.getLong("lengthschemeid")!=0){
- if(sizecustomizedschemesRowsMap.containsKey(row.getString("lengthschemeid"))){
- if(sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).isNotEmpty()){
- row.put("lengthtype",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getString("type"));
- row.put("lengthmin",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getBigDecimal("min"));
- row.put("lengthmax",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getBigDecimal("max"));
- row.put("lengthdecimalplaces",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getBigDecimal("decimalplaces"));
- if(sizeschemedetailsRowsMap.containsKey(row.getString("lengthschemeid"))){
- row.put("lengthschemedetails",sizeschemedetailsRowsMap.get(row.getString("lengthschemeid")));
- }else{
- row.put("lengthschemedetails",new JSONArray());
- }
- }
- }
- }
- }
- return getSucReturnObject().setData(rows).toString();
- }
- }
|