diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/invoice/receive/InvoiceReceiveService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/invoice/receive/InvoiceReceiveService.java index 89394de..53099f6 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/invoice/receive/InvoiceReceiveService.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/invoice/receive/InvoiceReceiveService.java @@ -35,7 +35,7 @@ public class InvoiceReceiveService extends BaseService { * @param invoice_code * @return */ - public InvoiceReceive checkReceive(int supermarket_id, String invoice_number, String invoice_code) { + public InvoiceReceive checkSurplusReceive(int supermarket_id, String invoice_number, String invoice_code) { if (!StrKit.notBlank(invoice_number, invoice_code)) { return null; } @@ -54,6 +54,30 @@ public class InvoiceReceiveService extends BaseService { return receive; } + /** + * 有领用记录,可以是已经被使用完的 + * @param supermarket_id + * @param invoice_number + * @param invoice_code + * @return + */ + public InvoiceReceive checkReceive(int supermarket_id, String invoice_number, String invoice_code) { + if (!StrKit.notBlank(invoice_number, invoice_code)) { + return null; + } + + Integer code = Integer.parseInt(invoice_code); + String sql = "select * from invoice_receive t\n" + + " where t.supermarket_id = ? \n" + + " and t.invoice_number = ? \n" + + " and cast(t.start_code as unsigned integer) <= ? \n" + + " and cast(t.end_code as unsigned integer) >= ? \n" + + " limit 1"; + + InvoiceReceive receive = InvoiceReceive.dao.findFirst(sql, supermarket_id, invoice_number, code, code); + + return receive; + } public String nextInvoiceCode(InvoiceReceive receive) { if (receive == null) { // 前面判断过了,应该不会再这里出现 null diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java index 134a79e..13d9669 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/stat/sale/OrderStatService.java @@ -577,7 +577,7 @@ public class OrderStatService { total.set("weight", total.getDouble("weight") + record.getDouble("weight")); } - total.set("weight", String.format("%.2f", total.getDouble("weight"))); + total.set("weight", Double.parseDouble(String.format("%.2f", total.getDouble("weight")))); dblist.add(total); @@ -620,7 +620,7 @@ public class OrderStatService { total.set("weight", total.getDouble("weight") + record.getDouble("weight")); } - total.set("weight", String.format("%.2f", total.getDouble("weight"))); + total.set("weight", Double.parseDouble(String.format("%.2f", total.getDouble("weight")))); dblist.add(total); diff --git a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/transport/TransportService.java b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/transport/TransportService.java index 19ab7fc..ad553b8 100644 --- a/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/transport/TransportService.java +++ b/ssjygl-xsx-common/src/main/java/com/cowr/ssjygl/transport/TransportService.java @@ -3,22 +3,14 @@ package com.cowr.ssjygl.transport; import com.cowr.common.Const; import com.cowr.common.base.BaseService; import com.cowr.common.enums.OrderStateEnum; -import com.cowr.common.enums.OrderTypeEnum; import com.cowr.common.view.PageParam; -import com.cowr.common.view.Result; -import com.cowr.model.Supermarket; -import com.cowr.model.Transport; -import com.cowr.model.TransportCompany; -import com.cowr.model.Truck; -import com.cowr.ssjygl.prepay.PrepayService; +import com.cowr.model.*; import com.jfinal.kit.StrKit; import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Page; import com.jfinal.plugin.activerecord.Record; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; +import java.util.*; /** * Generated by COWR Sun Apr 12 21:56:13 CST 2020 diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/devicectrl/device/LEDThread.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/devicectrl/device/LEDThread.java index 9a17cd9..2a2c378 100644 --- a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/devicectrl/device/LEDThread.java +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/devicectrl/device/LEDThread.java @@ -16,7 +16,7 @@ import java.util.concurrent.locks.ReentrantLock; public class LEDThread extends Device implements Runnable { private static Log log = Log.getLog(LEDThread.class); - private static final String LEDPriceFormat = " %s \\n重: %s吨\\n %s元"; + private static final String LEDPriceFormat = "%s\\n%s吨\\n%s元"; private static final String LEDWeightFormat = "%s\\n %s \\n重: %s吨"; private static final String LEDInfoFormat = "%s\\n %s \\n%s"; diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/invoice/invalidverify/InvoiceInvalidVerifySyncService.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/invoice/invalidverify/InvoiceInvalidVerifySyncService.java index 8d812f4..bd198a7 100644 --- a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/invoice/invalidverify/InvoiceInvalidVerifySyncService.java +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/invoice/invalidverify/InvoiceInvalidVerifySyncService.java @@ -12,7 +12,6 @@ import com.jfinal.log.Log; import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.IAtom; -import java.sql.SQLException; import java.util.Date; public class InvoiceInvalidVerifySyncService { diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/ordertemp/OrderTempSyncService.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/ordertemp/OrderTempSyncService.java index fb86e84..36da5c1 100644 --- a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/ordertemp/OrderTempSyncService.java +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/order/ordertemp/OrderTempSyncService.java @@ -11,7 +11,6 @@ import com.cowr.local.ssjygl.main.CliCacheData; import com.cowr.local.ssjygl.main.Config; import com.cowr.local.ssjygl.order.LocalOrderService; import com.cowr.local.ssjygl.order.orderseq.OrderSeqService; -import com.cowr.ssjygl.customer.supermarketproduct.CustomerSupermarketProductService; import com.cowr.ssjygl.invoice.log.InvoiceLogService; import com.cowr.ssjygl.invoice.receive.InvoiceReceiveService; import com.cowr.ssjygl.order.ordercluster.OrderclusterService; @@ -56,7 +55,7 @@ public class OrderTempSyncService { return Result.failed("进出场记录已完结或者已作废,不能使用"); } - InvoiceReceive receive = InvoiceReceiveService.me.checkReceive(transport.getSupermarketId(), invoice_number, invoice_code); + InvoiceReceive receive = InvoiceReceiveService.me.checkSurplusReceive(transport.getSupermarketId(), invoice_number, invoice_code); if (receive == null) { return Result.failed("没有有效的发票领用记录,或者发票已经被使用"); } @@ -316,7 +315,7 @@ public class OrderTempSyncService { // 零散客户需要开具发票的,需要检查是否有有效的领用记录 if (ordercluster.getReqReceipt() == 1) { - receive = InvoiceReceiveService.me.checkReceive(transport.getSupermarketId(), invoice_number, invoice_code); + receive = InvoiceReceiveService.me.checkSurplusReceive(transport.getSupermarketId(), invoice_number, invoice_code); if (receive == null) { return Result.failed("没有有效的发票领用记录,或者发票已经被使用"); @@ -638,7 +637,7 @@ public class OrderTempSyncService { order.setInvoiceType(2); // 需要专票的,在结算开了专票之后,再修改 invoice_site 字段 } else { - receive = InvoiceReceiveService.me.checkReceive(transport.getSupermarketId(), invoice_number, invoice_code); + receive = InvoiceReceiveService.me.checkSurplusReceive(transport.getSupermarketId(), invoice_number, invoice_code); if (receive == null) { return Result.failed("没有有效的发票领用记录,或者发票已经被使用"); } @@ -887,7 +886,7 @@ public class OrderTempSyncService { return Result.failedstr("请先将已开具的发票[%s]取消", order.getInvoiceCode()); } - InvoiceReceive receive = InvoiceReceiveService.me.checkReceive(order.getSupermarketId(), invoice_number, invoice_code); + InvoiceReceive receive = InvoiceReceiveService.me.checkSurplusReceive(order.getSupermarketId(), invoice_number, invoice_code); if (receive == null) { return Result.failed("没有有效的发票领用记录,或者发票已经被使用"); } @@ -986,7 +985,7 @@ public class OrderTempSyncService { cmd.set("status", false); ActionCmdLogSyncService.me.save(cmd.toJson(), sysuser); - return Result.failed("打印指令失败"); + return Result.success("开票成功,打印指令失败"); } return Result.success("开票成功,打印指令已发送"); diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/transport/TransportQueryService.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/transport/TransportQueryService.java index af1368c..3cfd29f 100644 --- a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/transport/TransportQueryService.java +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/transport/TransportQueryService.java @@ -10,6 +10,7 @@ import com.cowr.local.ssjygl.main.Config; import com.cowr.ssjygl.customer.supermarketproduct.CustomerSupermarketProductService; import com.cowr.ssjygl.invoice.receive.InvoiceReceiveService; import com.cowr.ssjygl.order.OrderService; +import com.cowr.ssjygl.order.ordercluster.OrderclusterService; import com.cowr.ssjygl.order.ordercluster.truck.OrderclusterTruckService; import com.cowr.ssjygl.supermarket.product.SupermarketProductService; import com.cowr.model.*; @@ -66,7 +67,12 @@ public class TransportQueryService { transobj.set("prepay_truck", false); } + BigDecimal overweight = OrderclusterService.me.getOverWeight(ordercluster.getId()); // 集团订单已完成量 + transobj.set("ordercluster", ordercluster); + transobj.set("ordercluster_over_weight", overweight); + transobj.set("ordercluster_surplus_weight", ordercluster.getTotalWeight().subtract(overweight)); + transobj.set("ordercluster_surplus_threshold", Config.configprop.getInt("surplus.threshold", 30)); transobj.set("weight", net_weight); transobj.set("net_weight", net_weight); diff --git a/ssjygl-xsx-local/src/main/resources/dev/config.properties b/ssjygl-xsx-local/src/main/resources/dev/config.properties index 769618d..68d95e1 100644 --- a/ssjygl-xsx-local/src/main/resources/dev/config.properties +++ b/ssjygl-xsx-local/src/main/resources/dev/config.properties @@ -21,7 +21,10 @@ default_scale_wait_time=8000 #最大毛重不超过 49 吨,超过 49 吨不能上高速 #2020-10-16 盐港都是小磅,最大只能40 -weigh.max=40 +weigh.max=49 + +#集团订单剩余量在结算时的剩余量预警值 +surplus.threshold=30 #打印用到的配置信息 print.vendor=浠水县长投环保有限公司 diff --git a/ssjygl-xsx-local/src/main/resources/prod/config.properties b/ssjygl-xsx-local/src/main/resources/prod/config.properties index 77a0b6a..2ae1f69 100644 --- a/ssjygl-xsx-local/src/main/resources/prod/config.properties +++ b/ssjygl-xsx-local/src/main/resources/prod/config.properties @@ -22,6 +22,9 @@ default_scale_wait_time=8000 #2020-10-16 盐港都是小磅,最大只能40 weigh.max=49 +#集团订单剩余量在结算时的剩余量预警值 +surplus.threshold=30 + #打印用到的配置信息 print.vendor=浠水县长投环保有限公司 print.vendorTaxId=91421125MA49GYYK2B diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/invoice/log/InvoiceLogSyncService.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/invoice/log/InvoiceLogSyncService.java index b1d595e..47e990d 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/invoice/log/InvoiceLogSyncService.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/invoice/log/InvoiceLogSyncService.java @@ -17,7 +17,6 @@ import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.IAtom; import com.jfinal.plugin.activerecord.Record; -import java.sql.SQLException; import java.util.*; public class InvoiceLogSyncService extends BaseSyncService { diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/jobs/SyncJob.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/jobs/SyncJob.java index deb36c4..3132ac3 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/jobs/SyncJob.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/jobs/SyncJob.java @@ -1,5 +1,7 @@ package com.cowr.service.ssjygl.jobs; +import com.cowr.model.Supermarket; +import com.cowr.service.ssjygl.main.SvrCacheData; import com.cowr.service.ssjygl.smslog.SmsService; import com.cowr.service.ssjygl.synctask.SyncTaskService; import com.jfinal.log.Log; @@ -7,13 +9,17 @@ import org.quartz.Job; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; +import java.util.Map; + public class SyncJob implements Job { private static Log log = Log.getLog(SyncJob.class); @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { try { - SyncTaskService.me.task(); + for(Map.Entry entry : SvrCacheData.SUP_CACHE.entrySet()){ + SyncTaskService.me.task(entry.getKey()); + } } catch (Exception e) { log.error(e.getMessage(), e); } 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 64b3d65..fa0984c 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 @@ -127,13 +127,13 @@ public class OrderclusterSyncService extends BaseSyncService { if (undonlist != null && !undonlist.isEmpty()) { BigDecimal plan_total_weight = new BigDecimal(total_weight); // 本次配额重量 - for(Record record : undonlist){ + for (Record record : undonlist) { Date record_cutoff_time = record.getDate("cutoff_time"); // 判断日期不是已经存在 - if(record_cutoff_time.getTime() == cutoff_time.getTime()){ + 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{ + } else { // 累加总量 plan_total_weight = plan_total_weight.add(record.getBigDecimal("total_weight")); } @@ -142,7 +142,7 @@ public class OrderclusterSyncService extends BaseSyncService { // 按客户统计已完成量 BigDecimal overweight = OrderclusterService.me.getOverWeightByCustomer(customer_id); // 按客户找集团订单已完成量 - if(plan_total_weight.subtract(overweight).multiply(unitprice).compareTo(prepayCustomer.getSurplus()) > 0 ){ + if (plan_total_weight.subtract(overweight).multiply(unitprice).compareTo(prepayCustomer.getSurplus()) > 0) { return Result.failedstr("剩余总配额 %.2f,客户余额(%.2f)不足", plan_total_weight.subtract(overweight), prepayCustomer.getSurplus()); } } @@ -521,33 +521,49 @@ public class OrderclusterSyncService extends BaseSyncService { return Result.failed(false, "订单已完成,不能修改"); } - 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 (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_weight = model.getTotalWeight(); + + for (Record record : undonlist) { + if (model.getId().equals(record.getInt("id"))) { + continue; // 当前修改的记录已经做为初始值了,不再累计 + } + + // 累加总量 + plan_total_weight = plan_total_weight.add(record.getBigDecimal("total_weight")); + } + + // 按客户统计已完成量 + BigDecimal overweight = OrderclusterService.me.getOverWeightByCustomer(oldobj.getCustomerId()); // 按客户找集团订单已完成量 + + if (plan_total_weight.subtract(overweight).multiply(oldobj.getUnitPrice()).compareTo(prepayCustomer.getSurplus()) > 0) { + return Result.failedstr("剩余总配额 %.2f,客户余额(%.2f)不足", plan_total_weight.subtract(overweight), prepayCustomer.getSurplus()); + } + } + } + + BigDecimal overweight = OrderclusterService.me.getOverWeight(model.getId()); // 集团订单已完成量 + + if (model.getTotalWeight().compareTo(overweight) < 0) { + return Result.failedstr("总量不能低于已运输量(%.2f)", overweight); } 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()); } diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordertemp/OrderTempSyncService.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordertemp/OrderTempSyncService.java index 7f08368..9400d71 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordertemp/OrderTempSyncService.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/order/ordertemp/OrderTempSyncService.java @@ -130,7 +130,7 @@ public class OrderTempSyncService { } // 是预付费订单 - if (order.getIsprepaid() == 1) { + if (order.getIsprepaid() == 1 && order.getCustomerId() != null) { Customer customer = Customer.dao.findById(order.getCustomerId()); if (customer == null) { diff --git a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/synctask/SyncTaskService.java b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/synctask/SyncTaskService.java index a0e3fca..99803de 100644 --- a/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/synctask/SyncTaskService.java +++ b/ssjygl-xsx-service/src/main/java/com/cowr/service/ssjygl/synctask/SyncTaskService.java @@ -89,14 +89,6 @@ public class SyncTaskService { } } }); - - // 2020-10-10 创建的任务不能立马就发出,要事务完成后发出,避免事务回滚 -// if (ret) { -// for (SyncTask obj : list) { -// send(obj); -// } -// } - return ret; // 有插入的,还是需要返回插入状态 } } @@ -167,15 +159,19 @@ public class SyncTaskService { } } - public void task() { + /** + * 按砂站ID去找未完成的,避免一个砂站有过多的未完成堆积,导致其他的不能下发 + * @param supermarket_id + */ + public void task(int supermarket_id) { if (!isEnable()) { return; } - List list = unsynclist(); + List list = unsynclist(supermarket_id); if (!list.isEmpty()) { - log.debug("开始下发未同步完成的数据 " + list.size()); + log.debug("开始下发未同步完成的数据 supermarket_id: %s, len: %s", supermarket_id, list.size()); } for (SyncTask obj : list) { @@ -183,8 +179,8 @@ public class SyncTaskService { } } - public List unsynclist() { - return SyncTask.dao.find("select * from sync_task t where t.state = 0 order by t.create_time limit 0, 500"); + public List unsynclist(int supermarket_id) { + return SyncTask.dao.find("select * from sync_task t where t.state = 0 and t.supermarket_id = ? order by t.create_time limit 0, 500", supermarket_id); } /**