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 6cf995b..ffbe4f4 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,11 +4,15 @@ 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; import com.cowr.model.OrderclusterTruck; import com.cowr.model.Sysuser; +import com.cowr.model.Transport; +import com.cowr.ssjygl.order.ordercluster.truck.OrderclusterTruckService; +import com.cowr.ssjygl.transprice.TransPriceService; import com.jfinal.kit.StrKit; import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Page; @@ -577,6 +581,60 @@ public class OrderclusterService extends BaseService { return Db.paginate(pp.getPage(), pp.getSize(), "select * ", fromsql, salePara.toArray()); } + public BigDecimal getTotalPriceByLicense(int supermarket_id, String truck_license, double weight) { + Transport transport = Transport.dao.findFirst("select * from transport t \n" + + " where t.state < ? \n" + + " and t.supermarket_id = ? \n" + + " and t.truck_license = ? \n" + + " and t.out_time like ? ", + OrderStateEnum.RECEIVED.getStateid(), + supermarket_id, + truck_license, + DateTimeUtil.sdf.get().format(new Date()) + "%" + ); + + if (transport == null) { + return null; + } + + if (transport.getFirstWeight() == null || transport.getSecondWeight() == null) { + return null; + } + + OrderclusterTruck ot = OrderclusterTruckService.me.checkValidLicense(transport.getSupermarketId(), transport.getTruckLicense()); + + if (ot == null) { + return null; + } + + Ordercluster ordercluster = Ordercluster.dao.findById(ot.getOrderclusterId()); + + if (ordercluster == null) { + return null; + } + + BigDecimal up = ordercluster.getUnitPrice(); // 集团订单是每天创建的,可以使用集团订单中确定的单价 + + if (up == null) { + return null; + } + + BigDecimal net_weight = transport.getSecondWeight().subtract(transport.getFirstWeight()).abs(); + + BigDecimal total_price = TransPriceService.me.caleTotalPrice(up, net_weight); + + if(total_price == null){ + return null; + } + + // 零散购砂总价四舍五入 + if(ordercluster.getCustomerId() == null){ + total_price = total_price.setScale(0, BigDecimal.ROUND_HALF_UP); + } + + return total_price; + } + /** * 获取集团订单剩余成量 * @@ -604,6 +662,7 @@ public class OrderclusterService extends BaseService { /** * 按客户查询未完成的配额量 + * * @param customer_id * @return */ diff --git a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/devicectrl/controllers/OutController.java b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/devicectrl/controllers/OutController.java index 4cd8796..b77f314 100644 --- a/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/devicectrl/controllers/OutController.java +++ b/ssjygl-xsx-local/src/main/java/com/cowr/local/ssjygl/devicectrl/controllers/OutController.java @@ -4,9 +4,11 @@ import com.cowr.local.ssjygl.devicectrl.device.*; import com.cowr.local.ssjygl.devicectrl.utils.LicenseJPGPair; import com.cowr.local.ssjygl.main.CliCacheData; import com.cowr.model.PostLicenseResult; +import com.cowr.ssjygl.order.ordercluster.OrderclusterService; import com.jfinal.log.Log; import java.io.IOException; +import java.math.BigDecimal; public class OutController extends Controller implements Runnable { private static Log log = Log.getLog(InController.class); @@ -209,6 +211,10 @@ public class OutController extends Controller implements Runnable { log.debug("%s 【%s】上磅后,控制LED显示称重结果【%s】", getWhich(), pair.license, weight); try { + BigDecimal total_price = OrderclusterService.me.getTotalPriceByLicense(CliCacheData.SUP.getId(), pair.license, weight); + + log.debug("%s 【%s】总价 %s 元", getWhich(), pair.license, total_price); + String weightStr; if (weight >= 100) { weightStr = String.format("%.1f", weight); @@ -216,7 +222,12 @@ public class OutController extends Controller implements Runnable { weightStr = String.format("%.2f", weight); } - getLed().setWeightInfo(pair.license, weightStr); + if (total_price == null) { + getLed().setWeightInfo(pair.license, weightStr); + } else { + // 显示总价 + getLed().setPriceInfo(pair.license, weightStr, String.format("%.2f", total_price)); + } } catch (Exception e) { log.error(e.getMessage(), e); log.debug("%s 【%s】控制LED显示称重结果失败【%s】", getWhich(), pair.license, weight); 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 e3bdf4c..9a17cd9 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 @@ -15,12 +15,14 @@ import java.util.Date; import java.util.concurrent.locks.ReentrantLock; public class LEDThread extends Device implements Runnable { - private static Log log = Log.getLog(LED.class); + private static Log log = Log.getLog(LEDThread.class); + 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"; private String license = ""; private String text = "系统启动"; + private String price = ""; private String format = LEDInfoFormat; private Thread thread; private boolean running = true; @@ -37,14 +39,23 @@ public class LEDThread extends Device implements Runnable { screen(); // 更新属性后,马上刷新显示内容 } - public void setWeightInfo(String license, String text) { + public void setWeightInfo(String license, String weight) { this.license = license; - this.text = text; + this.text = weight; this.format = LEDWeightFormat; screen(); // 更新属性后,马上刷新显示内容 } + public void setPriceInfo(String license, String weight, String price) { + this.license = license; + this.text = weight; + this.price = price; + this.format = LEDPriceFormat; + + screen(); // 更新属性后,马上刷新显示内容 + } + private static final ThreadLocal sdf = new ThreadLocal() { protected SimpleDateFormat initialValue() { return new SimpleDateFormat("MM-dd HH:mm"); @@ -109,8 +120,14 @@ public class LEDThread extends Device implements Runnable { } } - String date = sdf.get().format(new Date()); - String dataStr = String.format(this.format, date, this.license, this.text); + String dataStr = null; + + if (this.format.equals(LEDPriceFormat)) { + dataStr = String.format(this.format, this.license, this.text, this.price); + } else { + dataStr = String.format(this.format, sdf.get().format(new Date()), this.license, this.text); + } + byte[] data = dataStr.getBytes(Charset.forName("gb2312")); int dataLen = data.length; byte[] msg = new byte[frameHead.length + packetHead.length + b.length + dataLen]; 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 2b83fb5..af1368c 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 @@ -40,7 +40,7 @@ public class TransportQueryService { return Result.failed("未找到有效的出入场记录"); } - if (transport.getFirstWeight() == null && transport.getSecondWeight() == null) { + if (transport.getFirstWeight() == null || transport.getSecondWeight() == null) { return Result.failed("重量数据不完整"); }