|
|
@@ -58,7 +58,11 @@ public class OrderItems extends Controller {
|
|
|
public String insertOrUpdate() throws YosException {
|
|
|
Long sa_orderid = content.getLong("sa_orderid");
|
|
|
Long sys_enterpriseid = content.getLong("sys_enterpriseid");
|
|
|
-// Long sa_contractid = content.getLongValue("sa_contractid");
|
|
|
+ JSONArray items = content.getJSONArray("items");
|
|
|
+ //辅助类
|
|
|
+ OrderItemsHelper orderItemsHelper = new OrderItemsHelper(this);
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+
|
|
|
Rows orderRows = getOrderRows(this, sa_orderid);
|
|
|
if (orderRows.isEmpty()) {
|
|
|
return getErrReturnObject().setErrMsg("数据不存在,无法添加").toString();
|
|
|
@@ -68,28 +72,16 @@ public class OrderItems extends Controller {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// sa_contractid = orderRows.get(0).getLong("sa_contractid");
|
|
|
+ //更新表头
|
|
|
+ sqlList.add(orderItemsHelper.getUpdateSql().getSQL());
|
|
|
|
|
|
String type = orderRows.get(0).getString("type");
|
|
|
- JSONArray items = content.getJSONArray("items");
|
|
|
Long sa_promotionid = orderRows.get(0).getLong("sa_promotionid");
|
|
|
+ //查询活动
|
|
|
+ Rows promotionitems = dbConnect.runSqlQuery("select * from sa_promotion_items where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid);
|
|
|
+ //批量查询商品信息
|
|
|
+ RowsMap itemRowsMap = orderItemsHelper.getItemRowsMap(items);
|
|
|
|
|
|
-
|
|
|
- ArrayList<String> sqlList = new ArrayList<>();
|
|
|
- //查询erp库存
|
|
|
-// Invbal.selectErpInvbal(this, items);
|
|
|
-
|
|
|
- ArrayList<Long> itemids = new ArrayList<>();
|
|
|
- for (Object obj : items) {
|
|
|
- JSONObject item = (JSONObject) obj;
|
|
|
- itemids.add(item.getLong("itemid"));
|
|
|
- }
|
|
|
-
|
|
|
- String sql = "select t1.*,t2.material from plm_item t1 left join plm_itemextend t2 ON t2.itemid = t1.itemid AND t2.siteid = t1.siteid where t1.siteid='" + siteid + "' and t1.itemid in " + itemids;
|
|
|
- sql = sql.replace("[", "(").replace("]", ")");
|
|
|
- Rows itemRows = dbConnect.runSqlQuery(sql);
|
|
|
-
|
|
|
- RowsMap itemRowsMap = itemRows.toRowsMap("itemid");
|
|
|
BigDecimal sumqty = BigDecimal.ZERO;
|
|
|
for (Object obj : items) {
|
|
|
JSONObject item = (JSONObject) obj;
|
|
|
@@ -97,84 +89,20 @@ public class OrderItems extends Controller {
|
|
|
Long sa_orderitemsid = item.getLong("sa_orderitemsid");
|
|
|
BigDecimal qty = item.getBigDecimalValue("qty");
|
|
|
sumqty = sumqty.add(qty);
|
|
|
- if (!type.equals("促销订单")) {
|
|
|
- if (itemRowsMap.containsKey(item.getString("itemid"))) {
|
|
|
- if (itemRowsMap.get(item.getString("itemid")).isNotEmpty()) {
|
|
|
- BigDecimal orderaddqty = itemRowsMap.get(item.getString("itemid")).get(0).getBigDecimal("orderaddqty");
|
|
|
- BigDecimal orderminqty = itemRowsMap.get(item.getString("itemid")).get(0).getBigDecimal("orderminqty");
|
|
|
- if (((qty.subtract(orderminqty)).remainder(orderaddqty)).compareTo(BigDecimal.ZERO) != 0) {
|
|
|
- return getErrReturnObject().setErrMsg("品号为" + itemRowsMap.get(item.getString("itemid")).get(0).getString("itemno") + "的商品数量不符合该商品的起订量和增量").toString();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
//商品信息
|
|
|
Row itemRow = getItemRow(itemid);
|
|
|
- Rows promotionitems = dbConnect.runSqlQuery("select * from sa_promotion_items where siteid='" + siteid + "' and sa_promotionid=" + sa_promotionid);
|
|
|
- RowsMap promotionitemsRowsMap = promotionitems.toRowsMap("itemid");
|
|
|
- if (type.equals("促销订单")) {
|
|
|
- if (promotionitemsRowsMap.containsKey(item.getString("itemid"))) {
|
|
|
- if (promotionitemsRowsMap.get(item.getString("itemid")).isNotEmpty()) {
|
|
|
- BigDecimal saledqty = promotionitemsRowsMap.get(item.getString("itemid")).get(0).getBigDecimal("saledqty");
|
|
|
- BigDecimal groupqty = promotionitemsRowsMap.get(item.getString("itemid")).get(0).getBigDecimal("groupqty");
|
|
|
- BigDecimal orderaddqty = promotionitemsRowsMap.get(item.getString("itemid")).get(0).getBigDecimal("orderaddqty");
|
|
|
- BigDecimal orderminqty = promotionitemsRowsMap.get(item.getString("itemid")).get(0).getBigDecimal("orderminqty");
|
|
|
- boolean islimit = promotionitemsRowsMap.get(item.getString("itemid")).get(0).getBoolean("islimit");
|
|
|
- if (((qty.subtract(orderminqty)).remainder(orderaddqty)).compareTo(BigDecimal.ZERO) != 0) {
|
|
|
- return getErrReturnObject().setErrMsg("品号为" + itemRowsMap.get(item.getString("itemid")).get(0).getString("itemno") + "的商品数量不符合该商品的起订量和增量").toString();
|
|
|
- }
|
|
|
- if (islimit) {
|
|
|
- if (groupqty.compareTo(saledqty.add(qty)) < 0) {
|
|
|
- return getErrReturnObject().setErrMsg(itemRow.getString("itemno") + "商品数量已超过促销活动的限定数量【" + groupqty.subtract(saledqty) + "】,无法新建").toString();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ //是否符合商品起订量和增量判断
|
|
|
+ orderItemsHelper.compareQty(type, itemRowsMap, item, itemRow, promotionitems);
|
|
|
|
|
|
BigDecimal price1 = new BigDecimal(0);
|
|
|
- SQLFactory sqlFactory = new SQLFactory(this, "订单商品明细_新增");
|
|
|
+// SQLFactory sqlFactory = new SQLFactory(this, "订单商品明细_新增");
|
|
|
+ Boolean isInsert = true;
|
|
|
JSONArray customproperties = new JSONArray();
|
|
|
if (sa_orderitemsid <= 0) {
|
|
|
- Rows rows = dbConnect.runSqlQuery("SELECT sa_orderitemsid,price from sa_orderitems WHERE siteid='" + siteid + "' and itemid=" + itemid + " and sa_orderid=" + sa_orderid);
|
|
|
-
|
|
|
- Rows customschemeRows = dbConnect.runSqlQuery("select * from sa_customscheme_items where siteid='" + siteid + "'");
|
|
|
- RowsMap customschemeRowsMap = customschemeRows.toRowsMap("sa_customschemeid");
|
|
|
-
|
|
|
- if (itemRowsMap.containsKey(item.getString("itemid"))) {
|
|
|
- if (itemRowsMap.get(item.getString("itemid")).isNotEmpty()) {
|
|
|
- if (itemRowsMap.get(item.getString("itemid")).get(0).getLong("sa_customschemeid") > 0 && !itemRowsMap.get(item.getString("itemid")).get(0).getBoolean("iscustomsize")) {
|
|
|
- System.out.println(0000);
|
|
|
- if (customschemeRowsMap.containsKey(itemRowsMap.get(item.getString("itemid")).get(0).getString("sa_customschemeid"))) {
|
|
|
- System.out.println(111111);
|
|
|
- for (Row customschemeItem : (customschemeRowsMap.get(itemRowsMap.get(item.getString("itemid")).get(0).getString("sa_customschemeid")))) {
|
|
|
- System.out.println(customschemeItem.getString("description"));
|
|
|
- System.out.println(2222);
|
|
|
- customproperties.add(customschemeItem.getString("description") + ":" + itemRowsMap.get(item.getString("itemid")).get(0).getString(customschemeItem.getString("value")));
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (itemRowsMap.get(item.getString("itemid")).get(0).getBoolean("iscustomsize")) {
|
|
|
- System.out.println(3333);
|
|
|
- if (customschemeRowsMap.containsKey(itemRowsMap.get(item.getString("itemid")).get(0).getString("sa_customschemeid"))) {
|
|
|
- System.out.println(4444);
|
|
|
- for (Row customschemeItem : (customschemeRowsMap.get(itemRowsMap.get(item.getString("itemid")).get(0).getString("sa_customschemeid")))) {
|
|
|
- System.out.println(5555);
|
|
|
- System.out.println((customschemeRowsMap.get(itemRowsMap.get(item.getString("itemid")).get(0).getString("sa_customschemeid"))).size());
|
|
|
- if (!customschemeItem.getString("value").equals("spec")) {
|
|
|
- customproperties.add(customschemeItem.getString("description") + ":" + itemRowsMap.get(item.getString("itemid")).get(0).getString(customschemeItem.getString("value")));
|
|
|
- } else {
|
|
|
- customproperties.add("尺寸:" + item.getString("length") + "*" + item.getString("width"));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- } else {
|
|
|
- customproperties.add("尺寸:" + item.getString("length") + "*" + item.getString("width"));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ //获取定制属性
|
|
|
+ customproperties = orderItemsHelper.getCustomProperties(itemRowsMap, item);
|
|
|
|
|
|
- }
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT sa_orderitemsid,price from sa_orderitems WHERE siteid='" + siteid + "' and itemid=" + itemid + " and sa_orderid=" + sa_orderid);
|
|
|
|
|
|
if (rows.isEmpty()) {
|
|
|
sa_orderitemsid = createTableID("sa_orderitems");
|
|
|
@@ -182,135 +110,40 @@ public class OrderItems extends Controller {
|
|
|
System.out.println(beans.order.Order.getDefaultIsRepeatValue(siteid, type));
|
|
|
if (beans.order.Order.getDefaultIsRepeatValue(siteid, type)) {
|
|
|
sa_orderitemsid = createTableID("sa_orderitems");
|
|
|
- sqlFactory = new SQLFactory(this, "订单商品明细_新增");
|
|
|
+ isInsert = true;
|
|
|
} else {
|
|
|
price1 = rows.get(0).getBigDecimal("price");
|
|
|
sa_orderitemsid = rows.get(0).getLong("sa_orderitemsid");
|
|
|
- sqlFactory = new SQLFactory(this, "订单商品明细_更新");
|
|
|
+ isInsert = false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} else {
|
|
|
- sqlFactory = new SQLFactory(this, "订单商品明细_更新");
|
|
|
+ isInsert = false;
|
|
|
}
|
|
|
- sqlFactory.addParameter("customproperties", customproperties.toJSONString().replace("[", "").replace("]", "").replace("\"", ""));
|
|
|
- sqlFactory.addParameter("siteid", siteid);
|
|
|
- sqlFactory.addParameter("userid", userid);
|
|
|
- sqlFactory.addParameter("username", username);
|
|
|
- sqlFactory.addParameter("sa_orderitemsid", sa_orderitemsid);
|
|
|
- sqlFactory.addParameter("sa_orderid", sa_orderid);
|
|
|
- sqlFactory.addParameter("rowno", 1);
|
|
|
- sqlFactory.addParameter("itemid", itemid);
|
|
|
- sqlFactory.addParameter("remarks", item.getStringValue("remarks"));
|
|
|
-
|
|
|
- BigDecimal conversionrate = itemRow.getBigDecimal("conversionrate");
|
|
|
- if (conversionrate.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
- conversionrate = BigDecimal.valueOf(1);
|
|
|
- }
|
|
|
- sqlFactory.addParameter("itemno", itemRow.getString("itemno"));
|
|
|
- sqlFactory.addParameter("itemname", itemRow.getString("itemname"));
|
|
|
- sqlFactory.addParameter("model", itemRow.getString("model"));
|
|
|
- sqlFactory.addParameter("unit", itemRow.getString("unit"));
|
|
|
- sqlFactory.addParameter("auxunit", itemRow.getString("auxunit"));
|
|
|
- sqlFactory.addParameter("batchcontrol", itemRow.getLong("batchcontrol"));
|
|
|
- sqlFactory.addParameter("delivery", itemRow.getLong("delivery"));
|
|
|
-
|
|
|
- sqlFactory.addParameter("stockno", item.getOrDefault("stockno", "null"));
|
|
|
- sqlFactory.addParameter("position", item.getOrDefault("position", "null"));
|
|
|
- sqlFactory.addParameter("batchno", item.getOrDefault("batchno", "null"));
|
|
|
-
|
|
|
- String deliverydate = item.getStringValue("deliverydate");
|
|
|
- Rows rows = dbConnect.runSqlQuery("SELECT deliverydate,defaultprice from sa_orderitems WHERE sa_orderitemsid =" + sa_orderitemsid);
|
|
|
- if (deliverydate.isEmpty()) {
|
|
|
- if (rows.isNotEmpty()) {
|
|
|
- deliverydate = rows.get(0).getString("deliverydate");
|
|
|
- } else {
|
|
|
- deliverydate = "null";
|
|
|
- }
|
|
|
- }
|
|
|
- String needdate = item.getStringValue("needdate");
|
|
|
- sqlFactory.addParameter("needdate", needdate.equals("") ? "null" : needdate);
|
|
|
- sqlFactory.addParameter("deliverydate", deliverydate.equals("") ? "null" : deliverydate);
|
|
|
- sqlFactory.addParameter("conversionrate", conversionrate);
|
|
|
- //订购数量
|
|
|
- sqlFactory.addParameter("qty", qty);
|
|
|
- //辅助单位数量
|
|
|
- sqlFactory.addParameter("auxqty", qty.divide(conversionrate));
|
|
|
+
|
|
|
BigDecimal defaultprice;
|
|
|
BigDecimal price;
|
|
|
//价格
|
|
|
ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, itemid);
|
|
|
if (!item.containsKey("defaultprice")) {
|
|
|
- switch (type) {
|
|
|
-// case "项目订单":
|
|
|
-// defaultprice = itemPrice.getContractprice(sa_contractid);
|
|
|
-// break;
|
|
|
-// case "工具订单":
|
|
|
-// defaultprice = itemPrice.getMarketprice();
|
|
|
-// break;
|
|
|
- case "促销订单":
|
|
|
- defaultprice = itemPrice.getGraderateprice();
|
|
|
- price = itemPrice.getPromotionPrice(sa_promotionid);
|
|
|
- break;
|
|
|
- default:
|
|
|
- defaultprice = itemPrice.getGraderateprice();
|
|
|
- price = itemPrice.getGraderateprice();
|
|
|
- if (itemRowsMap.containsKey(item.getString("itemid"))) {
|
|
|
- if (itemRowsMap.get(item.getString("itemid")).isNotEmpty()) {
|
|
|
- if (itemRowsMap.get(item.getString("itemid")).get(0).getBoolean("iscustomsize")) {
|
|
|
- System.out.println(price);
|
|
|
- price = price.multiply(item.getBigDecimal("length").multiply(item.getBigDecimal("width")).divide(new BigDecimal("1000000"), 4, BigDecimal.ROUND_HALF_UP));
|
|
|
- System.out.println(price);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+ defaultprice = orderItemsHelper.getDefaultprice(itemPrice);
|
|
|
+ price = orderItemsHelper.getPrice(orderRows.get(0), itemPrice, item, itemRowsMap);
|
|
|
} else {
|
|
|
+ defaultprice = item.getBigDecimalValue("defaultprice");
|
|
|
price = item.getBigDecimalValue("price");
|
|
|
if (price.compareTo(price1) != 0) {
|
|
|
sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "订单商品【" + itemRow.getString("itemname") + "】由单价:" + price1 + "修改为单价:" + price, "订单修改单价").getSQL());
|
|
|
}
|
|
|
- defaultprice = item.getBigDecimalValue("defaultprice");
|
|
|
-// if (!type.equals("特殊订单") && defaultprice.compareTo(rows.get(0).getBigDecimal("defaultprice")) != 0 && defaultprice.compareTo(itemPrice.getContractprice()) < 0) {
|
|
|
-// return getErrReturnObject().setErrMsg("调整价格不可小于协议价").toString();
|
|
|
-// }
|
|
|
}
|
|
|
- if (type.equals("特殊订单")) {
|
|
|
- if (item.containsKey("defaultprice")) {
|
|
|
- if (item.getBigDecimalValue("price").compareTo(BigDecimal.ZERO) > 0 && item.getBigDecimalValue("amount").compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
- sqlFactory.addParameter("price", item.getBigDecimalValue("price"));
|
|
|
- //折前金额(元)
|
|
|
- sqlFactory.addParameter("amount", price.multiply(qty));
|
|
|
- } else if (item.getBigDecimalValue("price").compareTo(BigDecimal.ZERO) <= 0 && item.getBigDecimalValue("amount").compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- sqlFactory.addParameter("price", item.getBigDecimalValue("amount").divide(qty, 6, BigDecimal.ROUND_HALF_UP));
|
|
|
- //折前金额(元)
|
|
|
- sqlFactory.addParameter("amount", item.getBigDecimalValue("amount"));
|
|
|
- } else {
|
|
|
- sqlFactory.addParameter("price", price);
|
|
|
- //折前金额(元)
|
|
|
- sqlFactory.addParameter("amount", price.multiply(qty));
|
|
|
- }
|
|
|
- } else {
|
|
|
- sqlFactory.addParameter("price", price);
|
|
|
- //折前金额(元)
|
|
|
- sqlFactory.addParameter("amount", price.multiply(qty));
|
|
|
- }
|
|
|
+
|
|
|
+ if (isInsert) {
|
|
|
+ sqlList.add(orderItemsHelper.getInsertSQL(customproperties, sa_orderitemsid, item, itemRow, type, defaultprice, price, itemPrice.getMarketprice()).getSQL());
|
|
|
} else {
|
|
|
- sqlFactory.addParameter("price", price);
|
|
|
- //折前金额(元)
|
|
|
- sqlFactory.addParameter("amount", price.multiply(qty));
|
|
|
+ sqlList.add(orderItemsHelper.getUpdateSQL(sa_orderitemsid, item, itemRow, type, defaultprice, price).getSQL());
|
|
|
}
|
|
|
- //单价,折后价(元),取合同价
|
|
|
- sqlFactory.addParameter("defaultprice", defaultprice);
|
|
|
- //金额,折后金额(元)
|
|
|
- sqlFactory.addParameter("defaultamount", defaultprice.multiply(qty));
|
|
|
- //牌价、市场价(元),标准订单牌价取商品价格,项目订单取合同里的牌价
|
|
|
- sqlFactory.addParameter("marketprice", itemPrice.getMarketprice());
|
|
|
|
|
|
|
|
|
- sqlList.add(sqlFactory.getSQL());
|
|
|
}
|
|
|
|
|
|
if (type.equals("促销订单")) {
|
|
|
@@ -715,7 +548,7 @@ public class OrderItems extends Controller {
|
|
|
object.put("method", "getMsg");
|
|
|
|
|
|
JSONObject content = new JSONObject();
|
|
|
- content.put("fitemnos", rows.toJsonArray("itemno"));
|
|
|
+ content.put("fitemnos", rows.toJsonArray("itemno"));
|
|
|
object.put("content", content);
|
|
|
|
|
|
WebRequest request = new WebRequest();
|