diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/order/ordercluster/OrderclusterService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/order/ordercluster/OrderclusterService.java index 7f85929..e5df76a 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/order/ordercluster/OrderclusterService.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/order/ordercluster/OrderclusterService.java @@ -4,7 +4,6 @@ import com.cowr.common.Const; import com.cowr.common.base.BaseService; import com.cowr.common.enums.OrderStateEnum; import com.cowr.common.enums.UserTypeEnum; -import com.cowr.common.utils.DateTimeUtil; import com.cowr.common.view.PageParam; import com.cowr.common.view.Result; import com.cowr.model.Ordercluster; @@ -21,7 +20,10 @@ import com.jfinal.plugin.activerecord.Page; import com.jfinal.plugin.activerecord.Record; import java.math.BigDecimal; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * Generated by COWR Fri Apr 17 16:59:39 CST 2020 @@ -637,7 +639,7 @@ public class OrderclusterService extends BaseService { } /** - * 获取集团订单剩余成量 + * 获取单个集团订单剩余成量 * * @param ordercluster_id * @return @@ -696,7 +698,6 @@ public class OrderclusterService extends BaseService { } - /** * 按客户查询未完成的配额量 * @@ -730,4 +731,40 @@ public class OrderclusterService extends BaseService { return out == null ? new BigDecimal(0) : out; } + + /** + * 客户未完成的配额中,未执行完成的总金额 + * + * @param customer_id + * @return + */ + public BigDecimal undoPrice(int customer_id) { + String sql = "select(\n" + + " select sum(t.`total_weight` * t.`unit_price`) `total_price`\n" + + " from `ordercluster` t\n" + + " where t.`customer_id`= ?\n" + + " and t.state < ? ) - (\n" + + " select sum(t.`weight` * t.`unit_price`) total_price\n" + + " from order_temp t\n" + + " where exists(\n" + + " select 1 from `ordercluster` o\n" + + " where o.`customer_id`= ?\n" + + " and o.id= t.`ordercluster_id`\n" + + " and o.`state`< ?" + + " )\n" + + " and t.`customer_id`= ?\n" + + " and t.`state`= ?)"; + + BigDecimal out = Db.queryBigDecimal( + sql, + customer_id, + OrderStateEnum.RECEIVED.getStateid(), + customer_id, + OrderStateEnum.RECEIVED.getStateid(), + customer_id, + OrderStateEnum.RECEIVED.getStateid() + ); + + return out == null ? new BigDecimal("0") : out; + } } diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterSyncService.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterSyncService.java index 5bf06e1..e0a7e26 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterSyncService.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterSyncService.java @@ -9,6 +9,7 @@ import com.cowr.common.utils.DateTimeUtil; import com.cowr.common.view.Result; import com.cowr.model.*; import com.cowr.service.ssjygl.base.BaseSyncService; +import com.cowr.service.ssjygl.main.Config; import com.cowr.service.ssjygl.main.SvrCacheData; import com.cowr.service.ssjygl.sms.log.SmsService; import com.cowr.service.ssjygl.synctask.SyncTaskService; @@ -120,36 +121,20 @@ public class OrderclusterSyncService extends BaseSyncService { return Result.failed("未配置商品单价"); } - // 按客户查询未完成的订单量 - List undonlist = OrderclusterService.me.undonlist(supermarket_id, customer_id); - - if (undonlist != null && !undonlist.isEmpty()) { - BigDecimal plan_total_price = new BigDecimal(total_weight).multiply(unitprice); // 本次配额总价格 - - for (Record record : undonlist) { - Date record_cutoff_time = record.getDate("cutoff_time"); - - // 判断日期不是已经存在 - if (record_cutoff_time.getTime() == cutoff_time.getTime()) { - return Result.failedstr("客户[%s][%s]在砂站[%s]还有未完成的配额", customerObj.getName(), DateTimeUtil.sdfymd.get().format(cutoff_time), SvrCacheData.SUP_CACHE.get(supermarket_id).getName()); - } else { - // 累加总价 - plan_total_price = plan_total_price.add(record.getBigDecimal("total_weight").multiply(record.getBigDecimal("unit_price"))); - } - } - - // 按客户统计已完成量 - BigDecimal overTotalPrice = OrderclusterService.me.getOverTotalPriceByCustomer(customer_id); // 按客户找集团订单已完成量 - - if (plan_total_price.subtract(overTotalPrice).compareTo(prepayCustomer.getSurplus()) > 0) { - return Result.failedstr("剩余总配额 %.2f元,客户余额(%.2f元)不足", plan_total_price.subtract(overTotalPrice), prepayCustomer.getSurplus()); - } - } - + // 本次配额总价不能超过余额 if (unitprice.multiply(new BigDecimal(total_weight)).compareTo(prepayCustomer.getSurplus()) > 0) { return Result.failedstr("余额 %.2f 不足以购买 %.2f 吨", prepayCustomer.getSurplus(), total_weight); } + // 客户在所有砂站的未完成的配额中,未执行完成的总金额 + BigDecimal undo_price = OrderclusterService.me.undoPrice(customer_id); + BigDecimal plan_total_price = new BigDecimal(total_weight).multiply(unitprice).add(undo_price); // 本次配额总价格 + + // 本次计划总额加上未完成的量,不能超过余额 + if (plan_total_price.compareTo(prepayCustomer.getSurplus()) > 0) { + return Result.failedstr("共计总配额达 %.2f元,客户余额(%.2f元)不足", plan_total_price, prepayCustomer.getSurplus()); + } + Ordercluster model = new Ordercluster(); model.setCustomerId(customerObj.getId()); model.setCustomerAddress(customerObj.getAddress()); @@ -224,7 +209,7 @@ public class OrderclusterSyncService extends BaseSyncService { }); // 保存成功后,发送配额提醒短信 - if (ret) { + if (ret && !Config.isDev()) { for (Ordercluster cluster : newlist) { SmsService.me.sendPeiE(cluster); } @@ -721,36 +706,6 @@ public class OrderclusterSyncService extends BaseSyncService { return Result.failed(false, "订单已完成,不能修改"); } - if (oldobj.getCustomerId() != null) { - PrepayCustomer prepayCustomer = PrepayCustomerService.me.getPrepayCustomer(oldobj.getCustomerId()); - if (prepayCustomer == null) { - return Result.failed("不是预付费用户"); - } - - // 按客户查询未完成的订单量 - List undonlist = OrderclusterService.me.undonlist(oldobj.getCustomerId()); - - if (undonlist != null && !undonlist.isEmpty()) { - BigDecimal plan_total_price = model.getTotalWeight().multiply(oldobj.getUnitPrice()); - - for (Record record : undonlist) { - if (model.getId().equals(record.getInt("id"))) { - continue; // 当前修改的记录已经做为初始值了,不再累计 - } - - // 累加总价 - plan_total_price = plan_total_price.add(record.getBigDecimal("total_weight").multiply(record.getBigDecimal("unit_price"))); - } - - // 按客户统计已完成量 - BigDecimal overTotalPrice = OrderclusterService.me.getOverTotalPriceByCustomer(oldobj.getCustomerId()); // 按客户找集团订单已完成量 - - if (plan_total_price.subtract(overTotalPrice).compareTo(prepayCustomer.getSurplus()) > 0) { - return Result.failedstr("剩余总配额 %.2f元,客户余额(%.2f元)不足", plan_total_price.subtract(overTotalPrice), prepayCustomer.getSurplus()); - } - } - } - BigDecimal overweight = OrderclusterService.me.getOverWeight(model.getId()); // 集团订单已完成量 if (model.getTotalWeight().compareTo(overweight) < 0) { @@ -759,6 +714,21 @@ public class OrderclusterSyncService extends BaseSyncService { oldobj.setTotalWeight(model.getTotalWeight()); } + if (oldobj.getCustomerId() != null) { + PrepayCustomer prepayCustomer = PrepayCustomerService.me.getPrepayCustomer(oldobj.getCustomerId()); + if (prepayCustomer == null) { + return Result.failed("不是预付费用户"); + } + + // 客户在所有砂站的未完成的配额中,未执行完成的总金额 + BigDecimal undo_price = OrderclusterService.me.undoPrice(oldobj.getCustomerId()); + BigDecimal plan_total_price = model.getTotalWeight().subtract(overweight).multiply(oldobj.getUnitPrice()).add(undo_price); // 修改重量时,减去已完成量 + + if (plan_total_price.compareTo(prepayCustomer.getSurplus()) > 0) { + return Result.failedstr("共计总配额达 %.2f元,客户余额(%.2f元)不足", plan_total_price, prepayCustomer.getSurplus()); + } + } + if (model.getTimeInterval() != null) { oldobj.setTimeInterval(model.getTimeInterval()); } @@ -954,29 +924,6 @@ public class OrderclusterSyncService extends BaseSyncService { return Result.failed("不是预付费用户"); } - // 按客户查询未完成的订单量 - List undonlist = OrderclusterService.me.undonlist(oldobj.getCustomerId()); - - if (undonlist != null && !undonlist.isEmpty()) { - BigDecimal plan_total_price = total_weight.multiply(oldobj.getUnitPrice()); - - for (Record record : undonlist) { - if (oldobj.getId().equals(record.getInt("id"))) { - continue; // 当前修改的记录已经做为初始值了,不再累计 - } - - // 累加总价 - plan_total_price = plan_total_price.add(record.getBigDecimal("total_weight").multiply(record.getBigDecimal("unit_price"))); - } - - // 按客户统计已完成量 - BigDecimal overTotalPrice = OrderclusterService.me.getOverTotalPriceByCustomer(oldobj.getCustomerId()); // 按客户找集团订单已完成量 - - if (plan_total_price.subtract(overTotalPrice).compareTo(prepayCustomer.getSurplus()) > 0) { - return Result.failedstr("剩余总配额 %.2f元,客户余额(%.2f元)不足", plan_total_price.subtract(overTotalPrice), prepayCustomer.getSurplus()); - } - } - // 按客户统计已完成量 BigDecimal over_weight = OrderclusterService.me.getOverWeight(oldobj.getId()); // 按客户找集团订单已完成量 BigDecimal surplus_weight = oldobj.getTotalWeight().subtract(over_weight); // 剩余未完成量 @@ -992,12 +939,20 @@ public class OrderclusterSyncService extends BaseSyncService { oldobj.setTotalWeight(over_weight.add(surplus_weight.subtract(total_weight))); // 结转不完的,要留下 } + // 客户在所有砂站的未完成的配额中,未执行完成的总金额 + BigDecimal undo_price = OrderclusterService.me.undoPrice(oldobj.getCustomerId()); + BigDecimal plan_total_price = total_weight.subtract(over_weight).multiply(oldobj.getUnitPrice()).add(undo_price); // 本次转结的量,减去已完成量 + + if (plan_total_price.compareTo(prepayCustomer.getSurplus()) > 0) { + return Result.failedstr("共计总配额达 %.2f元,客户余额(%.2f元)不足", plan_total_price, prepayCustomer.getSurplus()); + } + List octs = OrderclusterTruck.dao.find("select * from ordercluster_truck t where t.ordercluster_id = ?", ordercluster_id); if (!octs.isEmpty()) { // 已有车辆的,在结转前,需要将已经分配其他集团订单的车辆去掉 - List ts = new ArrayList<>(); - List tsql = new ArrayList<>(); + List ts = new ArrayList<>(); + List tsql = new ArrayList<>(); Map delmap = new HashMap<>(); // 检查提交上来的车辆字符串是否用重复的 @@ -1122,7 +1077,7 @@ public class OrderclusterSyncService extends BaseSyncService { if (ret) { SyncTaskService.me.send(synctask); - if (forwardoldobj[0] != null && !isAuto) { + if (forwardoldobj[0] != null && !isAuto && !Config.isDev()) { SmsService.me.sendPeiE(forwardoldobj[0]); } }