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 7a2d678..6cf995b 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 @@ -15,10 +15,7 @@ import com.jfinal.plugin.activerecord.Page; import com.jfinal.plugin.activerecord.Record; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Generated by COWR Fri Apr 17 16:59:39 CST 2020 @@ -300,6 +297,17 @@ public class OrderclusterService extends BaseService { return Ordercluster.dao.find(sql, OrderStateEnum.RECEIVED.getStateid(), supermarket_id, customer_id, date + "%"); } + public List undonlist(Integer customer_id) { + String sql = "select * from ordercluster t \n" + + " where t.state < ? \n" + + " and t.customer_id = ? \n"; + List paraList = new ArrayList<>(); + paraList.add(OrderStateEnum.RECEIVED.getStateid()); + paraList.add(customer_id); + + return Db.find(sql, paraList.toArray()); + } + /** * 指定砂站未执行完成的集团订单 * @@ -593,4 +601,37 @@ public class OrderclusterService extends BaseService { return out == null ? new BigDecimal(0) : out; } + + /** + * 按客户查询未完成的配额量 + * @param customer_id + * @return + */ + public BigDecimal getOverWeightByCustomer(int customer_id) { + String sql = "select sum(a.weight) weight from ( \n" + + " select t.ordercluster_id, sum(t.weight) weight from order_sale t \n" + + " left join ordercluster o on o.id = t.ordercluster_id\n" + + " where t.state = ? \n" + + " and o.state < ? \n" + + " and o.customer_id = ? \n" + + " group by t.ordercluster_id \n" + + " \n" + + " union \n" + + " select t.ordercluster_id, sum(t.weight) weight from order_temp t \n" + + " left join ordercluster o on o.id = t.ordercluster_id\n" + + " where t.state = ? \n" + + " and o.state < ? \n" + + " and o.customer_id = ? \n" + + " group by t.ordercluster_id \n" + + ") a \n" + + "group by a.ordercluster_id "; + + BigDecimal out = Db.queryBigDecimal( + sql, + OrderStateEnum.RECEIVED.getStateid(), OrderStateEnum.RECEIVED.getStateid(), customer_id, + OrderStateEnum.RECEIVED.getStateid(), OrderStateEnum.RECEIVED.getStateid(), customer_id + ); + + return out == null ? new BigDecimal(0) : out; + } } diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/order/ordercluster/truck/OrderclusterTruckService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/order/ordercluster/truck/OrderclusterTruckService.java index 4c4045d..7bf64e9 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/order/ordercluster/truck/OrderclusterTruckService.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/order/ordercluster/truck/OrderclusterTruckService.java @@ -52,6 +52,12 @@ public class OrderclusterTruckService extends BaseService { return OrderclusterTruck.dao.find("select * from ordercluster_truck"); } + /** + * 验证车牌号是不是再当天有运输任务 + * @param supermarket_id + * @param truck_license + * @return + */ public OrderclusterTruck checkValidLicense(int supermarket_id, String truck_license) { if (StrKit.isBlank(truck_license)) { return null; diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/order/ordertemp/OrderTempService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/order/ordertemp/OrderTempService.java index 23e482e..ebf5bd1 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/order/ordertemp/OrderTempService.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/order/ordertemp/OrderTempService.java @@ -59,11 +59,13 @@ public class OrderTempService extends BaseService { ", p.first_pic, p.first_weight_which, p.second_weight_which, p.second_pic \n" + ", p.arrive_time, p.type, p.memo transport_memo \n" + ", s.name supermarket_name \n" + - ", v.state invoice_invalid_verify_state \n" + + ", v.state invoice_invalid_verify_state " + + ", ov.state order_invalid_verify_state \n" + " from order_temp t \n" + " left join transport p on p.order_sn = t.sn \n" + " left join supermarket s on s.id = t.supermarket_id \n" + " left join invoice_invalid_verify v on v.order_sn = t.sn and v.state = 1 \n" + + " left join order_invalid_verify ov on ov.order_sn = t.sn and ov.state = 1 \n" + " where t.sn = ?", sn); } @@ -88,11 +90,13 @@ public class OrderTempService extends BaseService { ", p.first_weight, p.second_weight, p.first_weigh_mode, p.second_weight_mode \n" + ", p.first_pic, p.first_weight_which, p.second_weight_which, p.second_pic \n" + ", p.arrive_time, p.type, p.memo transport_memo, s.name supermarket_name \n" + - ", v.state invoice_invalid_verify_state \n"; + ", v.state invoice_invalid_verify_state \n" + + ", ov.state order_invalid_verify_state \n"; String fromsql = "from order_temp t \n" + " left join transport p on p.order_sn = t.sn \n" + " left join supermarket s on s.id = t.supermarket_id \n" + " left join invoice_invalid_verify v on v.order_sn = t.sn and v.state = 1 \n" + + " left join order_invalid_verify ov on ov.order_sn = t.sn and ov.state = 1 \n" + " where 1=1 "; List paraList = new ArrayList<>(); diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/EditClusterValidator.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/EditClusterValidator.java new file mode 100644 index 0000000..911d83e --- /dev/null +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/EditClusterValidator.java @@ -0,0 +1,28 @@ +package com.cowr.service.ssjygl.order.ordercluster; + +import com.cowr.common.validator.CrudParamValidator; +import com.cowr.common.view.Result; +import com.jfinal.core.Controller; +import com.jfinal.kit.StrKit; + +public class EditClusterValidator extends CrudParamValidator { + @Override + protected void validate(Controller c) { + validateRequired("id", "id", "id 必填"); + validateInteger("id", 1, 2147483647, "id", "id 范围 1~2147483647"); + validateBigDecimal("total_weight", new java.math.BigDecimal("0.01"), new java.math.BigDecimal(9.9999999999E10), "total_weight", "total_weight 范围 0.01~9.9999999999E10"); + + if (StrKit.notBlank(c.get("time_interval"))) { + validateInteger("time_interval", 1, 3, "time_interval", "time_interval 范围 1~3"); + } + + if (StrKit.notBlank(c.get("mini_truck"))) { + validateInteger("mini_truck", 1, 2147483647, "mini_truck", "mini_truck 范围 1~2147483647"); + } + } + + @Override + protected void handleError(Controller c) { + c.renderJson(Result.failed(getErrmsg())); + } +} diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterController.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterController.java index 934ea8c..036f968 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterController.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordercluster/OrderclusterController.java @@ -81,7 +81,7 @@ public class OrderclusterController extends BaseController { /** * 修改 ordercluster 订单簇 - 集团客户订单 */ - @Before(OrderclusterEditValidator.class) + @Before(EditClusterValidator.class) public void edit() { Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token")); 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 a59bcd5..f67c937 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 @@ -24,6 +24,7 @@ import com.jfinal.log.Log; import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.IAtom; import com.jfinal.plugin.activerecord.Record; +import org.apache.poi.ss.usermodel.DateUtil; import java.math.BigDecimal; import java.sql.SQLException; @@ -115,19 +116,35 @@ public class OrderclusterSyncService extends BaseSyncService { continue; } - List undonlist = OrderclusterService.me.undonlist(supermarket_id, customer_id); - - if (undonlist != null && !undonlist.isEmpty()) { - return Result.failedstr("客户[%s]在砂站[%s]还有未完成的配额", customerObj.getName(), SvrCacheData.SUP_CACHE.get(supermarket_id).getName()); - } - BigDecimal unitprice = CustomerSupermarketProductService.me.getUnitPrice(customer_id, supermarket_id, product.getId()); if (unitprice == null) { return Result.failed("未配置商品单价"); } + List undonlist = OrderclusterService.me.undonlist(customer_id); + + if (undonlist != null && !undonlist.isEmpty()) { + BigDecimal plan_total_weight = new BigDecimal(total_weight); // 本次配额重量 + + 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_weight = plan_total_weight.add(record.getBigDecimal("total_weight")); + } + } + + BigDecimal overweight = OrderclusterService.me.getOverWeightByCustomer(customer_id); // 按客户找集团订单已完成量 + + if(plan_total_weight.subtract(overweight).multiply(unitprice).compareTo(prepayCustomer.getSurplus()) > 0 ){ + return Result.failedstr("剩余总配额 %.2f,客户余额(%.2f)不足", plan_total_weight.subtract(overweight), prepayCustomer.getSurplus()); + } + } + if (unitprice.multiply(new BigDecimal(total_weight)).compareTo(prepayCustomer.getSurplus()) > 0) { - return Result.failedstr("余额 %.2f 不足以购买 %.2f 吨 %s", prepayCustomer.getSurplus(), total_weight, product.getName()); + return Result.failedstr("余额 %.2f 不足以购买 %.2f 吨", prepayCustomer.getSurplus(), total_weight); } Ordercluster model = new Ordercluster(); @@ -500,89 +517,52 @@ public class OrderclusterSyncService extends BaseSyncService { return Result.failed(false, "订单已完成,不能修改"); } - if (oldobj.getState() > OrderStateEnum.INITIAL.getStateid() && !oldobj.getCutoffTime().equals(model.getCutoffTime())) { - return Result.failed(false, "已经开始执行的订单不能修改完成时间"); - } else if (model.getCutoffTime() != null) { - oldobj.setCutoffTime(model.getCutoffTime()); - } + String sql = "select t.ordercluster_id, sum(t.weight) weight from order_sale t \n" + + " where t.state = ? \n" + + " and t.ordercluster_id = ? \n" + + " group by t.ordercluster_id \n" + + " union \n" + + " select t.ordercluster_id, sum(t.weight) weight from order_temp t \n" + + " where t.state = ? \n" + + " and t.ordercluster_id = ? \n" + + " group by t.ordercluster_id "; - if (model.getAvgWeight() != null) { - oldobj.setAvgWeight(model.getAvgWeight()); - } + Record record = Db.findFirst(sql, OrderStateEnum.RECEIVED.getStateid(), model.getId(), OrderStateEnum.RECEIVED.getStateid(), model.getId()); - if (model.getTotalWeight() != null) { - String sql = "select t.ordercluster_id, sum(t.weight) weight from order_sale t \n" + - " where t.state = ? \n" + - " and t.ordercluster_id = ? \n" + - " group by t.ordercluster_id \n" + - " union \n" + - " select t.ordercluster_id, sum(t.weight) weight from order_temp t \n" + - " where t.state = ? \n" + - " and t.ordercluster_id = ? \n" + - " group by t.ordercluster_id "; - - Record record = Db.findFirst(sql, OrderStateEnum.RECEIVED.getStateid(), model.getId(), OrderStateEnum.RECEIVED.getStateid(), model.getId()); - - if (record != null) { - if (model.getTotalWeight().compareTo(record.getBigDecimal("weight")) < 0) { - return Result.failedstr("总量不能低于已运输量(%.2f)", record.getBigDecimal("weight")); - } else { - oldobj.setTotalWeight(model.getTotalWeight()); - } + if (record != null) { + if (model.getTotalWeight().compareTo(record.getBigDecimal("weight")) < 0) { + return Result.failedstr("总量不能低于已运输量(%.2f)", record.getBigDecimal("weight")); } else { oldobj.setTotalWeight(model.getTotalWeight()); } + } else { + oldobj.setTotalWeight(model.getTotalWeight()); } - if (model.getTimeInterval() != null) { + if(model.getTimeInterval() != null){ oldobj.setTimeInterval(model.getTimeInterval()); } - if (model.getMiniTruck() != null) { + if(model.getMiniTruck() != null){ oldobj.setMiniTruck(model.getMiniTruck()); } - if (model.getTransDistance() != null) { - oldobj.setTransDistance(model.getTransDistance()); - } - - if (model.getReqReceipt() != null) { - oldobj.setReqReceipt(model.getReqReceipt()); - } - - if (model.getCustomerTexpayerName() != null) { - oldobj.setCustomerTexpayerName(model.getCustomerTexpayerName()); - } - - if (model.getCustomerTexpayerNum() != null) { - oldobj.setCustomerTexpayerNum(model.getCustomerTexpayerNum()); - } - - // 设定了物流公司,并且和以前的不一样 - if (model.getTransCoId() != null && !model.getTransCoId().equals(oldobj.getTransCoId())) { - TransportCompany transCoObj = TransportCompany.dao.findById(model.getTransCoId()); - - if (transCoObj == null) { - return Result.failed("新增失败, 物流公司信息获取失败"); - } - - oldobj.setTransCoId(transCoObj.getId()); - oldobj.setTransCoName(transCoObj.getName()); - oldobj.setTransCoAddress(transCoObj.getAddress()); - oldobj.setTransCoBankName(transCoObj.getBankName()); - oldobj.setTransCoBankAccount(transCoObj.getBankAccount()); - oldobj.setTransCoPhone(transCoObj.getPhone()); - oldobj.setTransCoTexpayerName(transCoObj.getTexpayerName()); - oldobj.setTransCoTexpayerNum(transCoObj.getTexpayerNum()); - } + SyncTask synctask = new SyncTask(); try { boolean ret = Db.tx(new IAtom() { @Override public boolean run() throws SQLException { try { - return oldobj.update() - && SyncTaskService.me.save(new SyncTask().addUpdateData(oldobj), oldobj.getSupermarketId()) + boolean ret = oldobj.update(); + + if (!ret) { + return false; + } + + synctask.addUpdateData(oldobj); + + return SyncTaskService.me.save(synctask, oldobj.getSupermarketId()) && ModifyLogService.me.save(model, null, Enums.DataOpType.UPDATE.getId(), sysuser); } catch (Exception e) { log.error(e.getMessage(), e); @@ -592,7 +572,7 @@ public class OrderclusterSyncService extends BaseSyncService { } }); - return ret ? Result.success(model) : Result.failed("修改失败"); + return ret ? Result.success(oldobj) : Result.failed("修改失败"); } catch (Exception e) { log.error(e.getMessage(), e); return Result.failed("修改失败");