package restcontroller.webmanage.sale.order; import beans.brand.Brand; import beans.itemprice.ItemPrice; import com.alibaba.fastjson.JSONObject; import common.Controller; import common.YosException; import common.annotation.API; import common.data.Row; import common.data.Rows; import common.data.RowsMap; import common.data.SQLFactory; import restcontroller.R; import java.util.ArrayList; import static beans.order.Order.getOrderRows; /** * 促销订单相关接口 */ public class PromotionOrder extends Controller { /** * 构造函数 * * @param content */ public PromotionOrder(JSONObject content) throws YosException { super(content); } /** * 查询订货企业授权的促销方案列表 * * @return */ @API(title = "查询促销方案列表", apiversion = R.ID20230107182102.v1.class) public String selectPromotionList() 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(")"); } } if (content.containsKey("sys_enterpriseid")) { sys_enterpriseid = content.getLongValue("sys_enterpriseid"); } 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); return getSucReturnObject().setData(rows).toString(); } @API(title = "查询促销方案中的商品列表", apiversion = R.ID20230107182302.v1.class) public String selectPromotionItemsList() 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("t1.itemno like'%").append(whereObject.getString("condition")).append("%' "); where.append("or t1.itemname like'%").append(whereObject.getString("condition")).append("%' "); where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' "); where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' "); where.append(")"); } } Long sa_orderid = content.getLong("sa_orderid"); Rows orderRows = getOrderRows(this,sa_orderid); Long sa_promotionid = -1L; if (orderRows.isNotEmpty()) { sa_promotionid = orderRows.get(0).getLong("sa_promotionid"); sys_enterpriseid = orderRows.get(0).getLong("sys_enterpriseid"); } // ArrayList itemids = getOrderItemsList(sa_orderid, sa_promotionid); // itemids.add(-1L); SQLFactory sqlFactory = new SQLFactory(this, "促销方案商品列表", pageSize, pageNumber, pageSorting); sqlFactory.addParameter("siteid", siteid); // sqlFactory.addParameter_in("itemid", itemids); sqlFactory.addParameter("sa_promotionid", sa_promotionid); sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid); sqlFactory.addParameter_SQL("where", where); String sql = sqlFactory.getSQL(); Rows rows = dbConnect.runSqlQuery(sql); ArrayList ids = rows.toArrayList("itemid", new ArrayList<>()); //查询附件 RowsMap attinfoRowsMap = getAttachmentUrl("plm_item", ids); //商品领域 RowsMap tradefieldRowsMap = beans.Item.Item.getTradefieldRowsMap(this, ids); //品牌 RowsMap brandRowsMap = Brand.getBrandRowsMap(this, ids); for (Row row : rows) { row.put("attinfos", attinfoRowsMap.getOrDefault(row.getString("itemid"), new Rows())); row.put("tradefield", tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows())); row.put("brand", brandRowsMap.getOrDefault(row.getString("itemid"), new Rows())); } return getSucReturnObject().setData(rows).toString(); } // public ArrayList getOrderItemsList(Long sa_orderid, Long sa_promotionid) throws YosException { // 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 + "')"; // Rows rows = dbConnect.runSqlQuery(sql); // return rows.toArrayList("itemid", new ArrayList<>()); // } }