| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
- package restcontroller.sale.shoppingcart;
- import beans.datacontrllog.DataContrlLog;
- import beans.itemprice.ItemPrice;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.sun.jdi.LongValue;
- import common.Controller;
- import common.YosException;
- import common.annotation.API;
- import common.annotation.CACHEING_CLEAN;
- import common.data.Row;
- import common.data.Rows;
- import common.data.RowsMap;
- import common.data.SQLFactory;
- import restcontroller.R;
- import java.io.IOException;
- import java.math.BigDecimal;
- import java.util.ArrayList;
- import java.util.HashMap;
- @API(title = "购物车管理")
- public class ShoppingCart extends Controller {
- /**
- * 构造函数
- *
- * @param content
- */
- public ShoppingCart(JSONObject content) throws YosException {
- super(content);
- }
- @API(title = "新增或更新", apiversion = R.ID20220924095102.v1.class)
- @CACHEING_CLEAN(apiversions = {R.ID20220924095302.class})
- public String insertOrUpdate() throws YosException {
- Long sa_brandid = content.getLongValue("sa_brandid");
- Long itemid = content.getLong("itemid");
- BigDecimal qty = content.getBigDecimal("qty");
- BigDecimal length = content.getBigDecimal("length");
- BigDecimal width = content.getBigDecimal("width");
- String itemno = content.getString("itemno");
- String tradefield = content.getStringValue("tradefield");
- long sa_promotionid = content.getLongValue("sa_promotionid");
- long sa_promotion_itemsid = content.getLongValue("sa_promotion_itemsid");
- SQLFactory sqlFactory = new SQLFactory(this, "购物车新增");
- Long sa_shoppingcartid = 0L;
- Rows rows = dbConnect.runSqlQuery("SELECT sa_shoppingcartid FROM sa_shoppingcart WHERE siteid = '" + siteid +
- "' AND sa_brandid = " + sa_brandid +
- " and length=" + length + " and width=" + width + " AND itemid = " + itemid +
- " AND sys_enterpriseid = " + sys_enterpriseid +
- " AND tradefield = '" + tradefield +
- "' AND itemno = '" + itemno + "' and sa_promotionid=" + sa_promotionid);
- if (rows.isNotEmpty()) {
- sa_shoppingcartid = rows.get(0).getLong("sa_shoppingcartid");
- }
- ArrayList<String> sqlList = new ArrayList<>();
- if (sa_shoppingcartid <= 0) {
- sa_shoppingcartid = createTableID("sa_shoppingcart");
- sqlList.add(DataContrlLog.createLog(this, "sa_shoppingcart", sa_shoppingcartid, "新增", "购物车新增" + sa_shoppingcartid).getSQL());
- } else {
- sqlFactory = new SQLFactory(this, "购物车更新");
- sqlList.add(DataContrlLog.createLog(this, "sa_shoppingcart", sa_shoppingcartid, "更新", "购物车更新" + sa_shoppingcartid).getSQL());
- }
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("itemid", itemid);
- sqlFactory.addParameter("username", username);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("itemno", itemno);
- sqlFactory.addParameter("length", length);
- sqlFactory.addParameter("width", width);
- sqlFactory.addParameter("sa_promotionid", sa_promotionid);
- sqlFactory.addParameter("sa_promotion_itemsid", sa_promotion_itemsid);
- sqlFactory.addParameter("tradefield", tradefield);
- sqlFactory.addParameter("sa_shoppingcartid", sa_shoppingcartid);
- sqlFactory.addParameter("sa_brandid", sa_brandid);
- sqlFactory.addParameter("qty", qty);
- sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- sqlList.add(sqlFactory.getSQL());
- dbConnect.runSqlUpdate(sqlList);
- content.put("sa_shoppingcartid", sa_shoppingcartid);
- return queryDetail();
- }
- @API(title = "(批量新增)", apiversion = R.ID20231024110003.v1.class)
- @CACHEING_CLEAN(apiversions = {R.ID20220924095302.class})
- public String insert() throws YosException {
- JSONArray items = content.getJSONArray("items");
- ArrayList<String> sqlList = new ArrayList<>();
- //System.out.println(111111);
- for (Object object : items) {
- //System.out.println(object.toString());
- JSONObject item = (JSONObject) object;
- Long sa_brandid = item.getLongValue("sa_brandid");
- Long itemid = item.getLong("itemid");
- BigDecimal qty = item.getBigDecimal("qty");
- BigDecimal length = item.getBigDecimal("length");
- BigDecimal width = item.getBigDecimal("width");
- String itemno = item.getString("itemno");
- String tradefield = item.getStringValue("tradefield");
- long sa_promotionid = item.getLongValue("sa_promotionid");
- long sa_promotion_itemsid = item.getLongValue("sa_promotion_itemsid");
- SQLFactory sqlFactory = new SQLFactory(this, "购物车新增");
- Long sa_shoppingcartid = 0L;
- Rows rows = dbConnect.runSqlQuery("SELECT sa_shoppingcartid FROM sa_shoppingcart WHERE siteid = '" + siteid +
- "' AND sa_brandid = " + sa_brandid +
- " and length=" + length + " and width=" + width + " AND itemid = " + itemid +
- " AND sys_enterpriseid = " + sys_enterpriseid +
- " AND tradefield = '" + tradefield +
- "' AND itemno = '" + itemno + "' and sa_promotionid=" + sa_promotionid);
- if (rows.isNotEmpty()) {
- sa_shoppingcartid = rows.get(0).getLong("sa_shoppingcartid");
- }
- if (sa_shoppingcartid <= 0) {
- sa_shoppingcartid = createTableID("sa_shoppingcart");
- sqlList.add(DataContrlLog.createLog(this, "sa_shoppingcart", sa_shoppingcartid, "新增", "购物车新增" + sa_shoppingcartid).getSQL());
- } else {
- sqlFactory = new SQLFactory(this, "购物车更新");
- sqlList.add(DataContrlLog.createLog(this, "sa_shoppingcart", sa_shoppingcartid, "更新", "购物车更新" + sa_shoppingcartid).getSQL());
- }
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("itemid", itemid);
- sqlFactory.addParameter("username", username);
- sqlFactory.addParameter("userid", userid);
- sqlFactory.addParameter("itemno", itemno);
- sqlFactory.addParameter("length", length);
- sqlFactory.addParameter("width", width);
- sqlFactory.addParameter("sa_promotionid", sa_promotionid);
- sqlFactory.addParameter("sa_promotion_itemsid", sa_promotion_itemsid);
- sqlFactory.addParameter("tradefield", tradefield);
- sqlFactory.addParameter("sa_shoppingcartid", sa_shoppingcartid);
- sqlFactory.addParameter("sa_brandid", sa_brandid);
- sqlFactory.addParameter("qty", qty);
- sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- //System.out.println(sqlFactory.getSQL());
- sqlList.add(sqlFactory.getSQL());
- }
- dbConnect.runSqlUpdate(sqlList);
- return getSucReturnObject().toString();
- }
- @API(title = "更新数量", apiversion = R.ID20220924104302.v1.class)
- @CACHEING_CLEAN(apiversions = {R.ID20220924095302.class})
- public String updateQty() throws YosException {
- Long sa_shoppingcartid = content.getLong("sa_shoppingcartid");
- BigDecimal qty = content.getBigDecimalValue("qty", 1);
- BigDecimal length = content.getBigDecimalValue("length");
- BigDecimal width = content.getBigDecimalValue("width");
- ArrayList<String> sqlList = new ArrayList<>();
- SQLFactory sqlFactory = new SQLFactory(this, "购物车更新数量");
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("username", username);
- sqlFactory.addParameter("sa_shoppingcartid", sa_shoppingcartid);
- sqlFactory.addParameter("qty", qty);
- sqlFactory.addParameter("length", length);
- sqlFactory.addParameter("width", width);
- sqlList.add(sqlFactory.getSQL());
- //操作记录
- sqlList.add(DataContrlLog.createLog(this, "sa_shoppingcart", sa_shoppingcartid, "更新数量", "更新数量" + qty).getSQL());
- dbConnect.runSqlUpdate(sqlList);
- content.put("sa_shoppingcartid", sa_shoppingcartid);
- return queryDetail();
- }
- @API(title = "删除", apiversion = R.ID20220924095202.v1.class)
- @CACHEING_CLEAN(apiversions = {R.ID20220924095302.class})
- public String delete() throws YosException {
- JSONArray jsonArray = content.getJSONArray("sa_shoppingcartids");
- ArrayList<String> sqlList = new ArrayList<>();
- SQLFactory sqlFactory = new SQLFactory(this, "购物车删除");
- sqlFactory.addParameter_in("sa_shoppingcartid", jsonArray.toArray());
- sqlFactory.addParameter("siteid", siteid);
- sqlList.add(sqlFactory.getSQL());
- for (Object obj : jsonArray) {
- //操作记录
- sqlList.add(DataContrlLog.createLog(this, "sa_shoppingcart", Long.valueOf(obj.toString()), "删除", "删除" + obj).getSQL());
- }
- dbConnect.runSqlUpdate(sqlFactory);
- return getSucReturnObject().toString();
- }
- @API(title = "购物车列表", apiversion = R.ID20220924095302.v1.class)
- public String queryList() throws YosException, IOException {
- 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 t2.brandname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t3.itemname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t3.model like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t3.spec like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- boolean isExport = content.getBooleanValue("isExport");
- Long istool = content.getLongValue("istool");
- SQLFactory sqlFactory = new SQLFactory(this, "购物车列表", pageSize, pageNumber, pageSorting);
- if (isExport) {
- sqlFactory = new SQLFactory(this, "购物车列表");
- }
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- sqlFactory.addParameter("sa_promotionid", content.getLongValue("sa_promotionid"));
- sqlFactory.addParameter("istool", istool);
- sqlFactory.addParameter_SQL("where", where);
- String sql = sqlFactory.getSQL();
- Rows rows = dbConnect.runSqlQuery(sql);
- ArrayList<Long> 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 promotionItemsRows = dbConnect.runSqlQuery("select * from sa_promotion_items where siteid='" + siteid + "' and sa_promotionid=" + content.getLongValue("sa_promotionid"));
- RowsMap promotionItemsRowsMap = promotionItemsRows.toRowsMap("itemid");
- 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()));
- }
- try {
- ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, row.getLong("itemid"));
- row.put("oldprice", istool == 0 ? itemPrice.getContractprice() : itemPrice.getMarketprice());
- if (content.getLongValue("sa_promotionid") > 0) {
- if (promotionItemsRowsMap.containsKey(row.getString("itemid"))) {
- if (promotionItemsRowsMap.get(row.getString("itemid")).isNotEmpty()) {
- row.put("orderminqty", promotionItemsRowsMap.get(row.getString("itemid")).get(0).getBigDecimal("orderminqty"));
- row.put("orderaddqty", promotionItemsRowsMap.get(row.getString("itemid")).get(0).getBigDecimal("orderaddqty"));
- }
- }
- if (row.getBoolean("iscustomsize") && row.getLong("pricingmetod") == 1) {
- row.put("gradeprice", itemPrice.getPromotionPrice(content.getLongValue("sa_promotionid")).multiply(row.getBigDecimal("length").multiply(row.getBigDecimal("width")).divide(new BigDecimal("1000000"), 4, BigDecimal.ROUND_HALF_UP)));
- } else {
- row.put("gradeprice", itemPrice.getPromotionPrice(content.getLongValue("sa_promotionid")));
- }
- } else {
- if (row.getBoolean("iscustomsize") && row.getLong("pricingmetod") == 1) {
- row.put("gradeprice", itemPrice.getContractprice().multiply(row.getBigDecimal("length").multiply(row.getBigDecimal("width")).divide(new BigDecimal("1000000"), 4, BigDecimal.ROUND_HALF_UP)));
- } else {
- row.put("gradeprice", itemPrice.getContractprice());
- }
- }
- // row.put("gradeprice", istool == 0 ?itemPrice.getContractprice():itemPrice.getMarketprice());
- } catch (Exception e) {
- e.printStackTrace();
- row.put("oldprice", 0);
- row.put("gradeprice", 0);
- }
- 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());
- }
- }
- }
- } 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());
- }
- }
- }
- } else {
- row.put("lengthschemedetails", new JSONArray());
- }
- //选项
- String materialschemeid = row.getString("materialschemeid");
- if (!materialschemeid.equals("0") && sizecustomizedschemesRowsMap.containsKey(materialschemeid) && sizecustomizedschemesRowsMap.get(materialschemeid).isNotEmpty()) {
- row.put("type", sizecustomizedschemesRowsMap.get(materialschemeid).get(0).getString("type"));
- row.put("min", sizecustomizedschemesRowsMap.get(materialschemeid).get(0).getBigDecimal("min"));
- row.put("max", sizecustomizedschemesRowsMap.get(materialschemeid).get(0).getBigDecimal("max"));
- row.put("decimalplaces", sizecustomizedschemesRowsMap.get(materialschemeid).get(0).getBigDecimal("decimalplaces"));
- if (sizeschemedetailsRowsMap.containsKey(materialschemeid)) {
- row.put("materialschemedetails", sizeschemedetailsRowsMap.get(materialschemeid));
- } else {
- row.put("materialschemedetails", new JSONArray());
- }
- } else {
- row.put("materialschemedetails", new JSONArray());
- }
- //颜色
- String colorschemeid = row.getString("colorschemeid");
- if (!colorschemeid.equals("0") && sizecustomizedschemesRowsMap.containsKey(colorschemeid) && sizecustomizedschemesRowsMap.get(colorschemeid).isNotEmpty()) {
- row.put("type", sizecustomizedschemesRowsMap.get(colorschemeid).get(0).getString("type"));
- row.put("min", sizecustomizedschemesRowsMap.get(colorschemeid).get(0).getBigDecimal("min"));
- row.put("max", sizecustomizedschemesRowsMap.get(colorschemeid).get(0).getBigDecimal("max"));
- row.put("decimalplaces", sizecustomizedschemesRowsMap.get(colorschemeid).get(0).getBigDecimal("decimalplaces"));
- if (sizeschemedetailsRowsMap.containsKey(colorschemeid)) {
- row.put("colorsschemedetails", sizeschemedetailsRowsMap.get(colorschemeid));
- } else {
- row.put("colorsschemedetails", new JSONArray());
- }
- } else {
- row.put("colorsschemedetails", new JSONArray());
- }
- //工艺
- String cheekschemeid = row.getString("cheekschemeid");
- if (!cheekschemeid.equals("0") && sizecustomizedschemesRowsMap.containsKey(cheekschemeid) && sizecustomizedschemesRowsMap.get(cheekschemeid).isNotEmpty()) {
- row.put("type", sizecustomizedschemesRowsMap.get(cheekschemeid).get(0).getString("type"));
- row.put("min", sizecustomizedschemesRowsMap.get(cheekschemeid).get(0).getBigDecimal("min"));
- row.put("max", sizecustomizedschemesRowsMap.get(cheekschemeid).get(0).getBigDecimal("max"));
- row.put("decimalplaces", sizecustomizedschemesRowsMap.get(cheekschemeid).get(0).getBigDecimal("decimalplaces"));
- if (sizeschemedetailsRowsMap.containsKey(cheekschemeid)) {
- row.put("cheekschemedetails", sizeschemedetailsRowsMap.get(cheekschemeid));
- } else {
- row.put("cheekschemedetails", new JSONArray());
- }
- } else {
- row.put("cheekschemedetails", new JSONArray());
- }
- row.put("isselect", true);
- }
- // if (isExport) {
- // //去除不需要导出项
- // String[] removeFieldList = {"sa_shoppingcartid", "sa_brandid", "itemid", "unitgroupname", "orderminqty", "orderaddqty", "orderminqty_auxunit", "orderaddqty_auxunit"};
- // for (String key : removeFieldList) {
- // rows.getFieldList().remove(key);
- // }
- //
- // Rows uploadRows = uploadExcelToObs("order", "订单商品明细_列表", rows, getTitleMap());
- // return getSucReturnObject().setData(uploadRows).toString();
- // }
- return getSucReturnObject().setData(rows).toString();
- }
- //返回导出的标题
- public HashMap<String, String> getTitleMap() {
- HashMap<String, String> titleMap = new HashMap<>();
- titleMap.put("qty", "数量");
- titleMap.put("itemno", "产品编号");
- titleMap.put("tradefield", "领域");
- titleMap.put("brandname", "品牌");
- titleMap.put("itemname", "产品名称");
- titleMap.put("model", "型号");
- titleMap.put("spec", "规格尺寸");
- titleMap.put("unitname", "主单位");
- titleMap.put("auxunitname", "辅助单位");
- return titleMap;
- }
- @API(title = "购物车数量", apiversion = R.ID20220927093202.v1.class)
- public String getNum() throws YosException {
- Rows rows = dbConnect.runSqlQuery("SELECT COUNT(0) num FROM sa_shoppingcart t1 WHERE t1.sys_enterpriseid=" + sys_enterpriseid + " AND t1.siteid= '" + siteid + "' and t1.sa_promotionid=" + content.getLongValue("sa_promotionid"));
- return getSucReturnObject().setData(rows.get(0)).toString();
- }
- @API(title = "详情", apiversion = R.ID20220924095402.v1.class)
- public String queryDetail() throws YosException {
- Long sa_shoppingcartid = content.getLong("sa_shoppingcartid");
- SQLFactory sqlFactory = new SQLFactory(this, "购物车详情", pageSize, pageNumber, pageSorting);
- sqlFactory.addParameter("siteid", siteid);
- sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
- sqlFactory.addParameter("sa_shoppingcartid", sa_shoppingcartid);
- Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
- ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
- //附件
- RowsMap attRowsMap = getAttachmentUrl("plm_item", ids);
- for (Row row : rows) {
- row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
- try {
- ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, row.getLong("itemid"));
- row.put("oldprice", itemPrice.getPrice());
- row.put("gradeprice", itemPrice.getGraderateprice());
- } catch (Exception e) {
- e.printStackTrace();
- row.put("oldprice", 0);
- row.put("gradeprice", 0);
- }
- }
- return getSucReturnObject().setData(rows.isNotEmpty() ? rows.get(0) : new Row()).toString();
- }
- }
|