称重指令

dev
lisai17@sina.com 2020-10-26 13:17:34 +08:00
parent 8db40b5b69
commit 664a677020
7 changed files with 78 additions and 29 deletions

View File

@ -237,12 +237,22 @@ public class DeviceThread extends Thread {
});
}
public double scale(String scaleId) throws IOException {
public Double scale(String scaleId) throws IOException {
if (!this.scaleMap.containsKey(scaleId)) {
throw new IllegalArgumentException(scaleId + " does not exist");
}
return this.scaleMap.get(scaleId).weigh15();
AbsScale scale = this.scaleMap.get(scaleId);
if(scale == null){
return null;
}
if(!scale.isConnected()){
scale.connect();
}
return scale.weigh15();
}
public void print(String printerId, File file) throws IOException {

View File

@ -58,7 +58,7 @@ public class XiShuiScale extends AbsScale {
int errCount = 0;
while (run.get() && list.size() < 15) {
long st = System.currentTimeMillis();
// long st = System.currentTimeMillis();
byte[] buf = new byte[18];
int read = inputStream.read(buf);

View File

@ -562,12 +562,12 @@ public class LocalOrderService {
try {
Config.deviceThread.print(printerId, getPrintFile(printdata));
cmd.set("print", true);
cmd.set("status", true);
ActionCmdLogSyncService.me.save(cmd.toJson(), sysuser);
} catch (Exception e) {
log.error(e.getMessage(), e);
cmd.set("print", false);
cmd.set("status", false);
ActionCmdLogSyncService.me.save(cmd.toJson(), sysuser);
return Result.failed("打印指令失败");

View File

@ -969,12 +969,12 @@ public class OrderTempSyncService {
try {
Config.deviceThread.print(printerId, LocalOrderService.me.getPrintFile(printdata));
cmd.set("print", true);
cmd.set("status", true);
ActionCmdLogSyncService.me.save(cmd.toJson(), sysuser);
} catch (Exception e) {
log.error(e.getMessage(), e);
cmd.set("print", false);
cmd.set("status", false);
ActionCmdLogSyncService.me.save(cmd.toJson(), sysuser);
return Result.failed("打印指令失败");

View File

@ -286,6 +286,7 @@ public class TransportController extends BaseController {
renderJson(result ? Result.success(true) : Result.failed("抬闸失败"));
}
@Before(TransportIdValidator.class)
public void cmdScale() {
Sysuser tokenuser = SysuserSyncService.me.getSysuserByToken(get("token"));
@ -294,15 +295,15 @@ public class TransportController extends BaseController {
return;
}
String which = getUpperCaseVal("which");// Enums.WhichEnum R01 入场流程 C01 出场流程
String transport_id = get("transport_id");
String which = getUpperCaseVal("which");// Enums.WhichEnum R01 入场流程 C01 出场流程
if (!Enums.CtrlFlowEnum.isValid(which)) {
renderJson(Result.failed("which 参数错误"));
return;
}
double result = TransportDeviceService.me.cmdScale(which, tokenuser);
renderJson(Result.success(result));
renderJson(TransportDeviceService.me.cmdScale(transport_id, which, tokenuser));
}
@Before(TransportIdValidator.class)

View File

@ -1,14 +1,19 @@
package com.cowr.local.ssjygl.transport;
import com.cowr.common.enums.Enums;
import com.cowr.common.enums.OrderStateEnum;
import com.cowr.common.view.Result;
import com.cowr.local.ssjygl.actioncmdlog.ActionCmdLogSyncService;
import com.cowr.local.ssjygl.devicectrl.controllers.Controller;
import com.cowr.local.ssjygl.main.CliCacheData;
import com.cowr.local.ssjygl.main.Config;
import com.cowr.model.SyncTask;
import com.cowr.model.Sysuser;
import com.cowr.model.Transport;
import com.jfinal.kit.HttpKit;
import com.jfinal.kit.StrKit;
import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import java.text.SimpleDateFormat;
@ -258,18 +263,47 @@ public class TransportDeviceService {
return ret;
}
public double cmdScale(String which, Sysuser sysuser) {
Record cmdlog = new Record();
cmdlog.set("cmd", "scale");
cmdlog.set("which", which);
public Result cmdScale(String transport_id, String which, Sysuser sysuser) {
try {
Record cmdlog = new Record();
cmdlog.set("cmd", "scale");
cmdlog.set("which", which);
cmdlog.set("transport_id", transport_id);
cmdlog.set("status", false);
Transport transport = Transport.dao.findById(transport_id);
if (transport == null) {
ActionCmdLogSyncService.me.save(cmdlog.toJson(), sysuser);
return Result.failed("未找到出入场记录");
}
if (transport.getState() >= OrderStateEnum.RECEIVED.getStateid()) {
ActionCmdLogSyncService.me.save(cmdlog.toJson(), sysuser);
return Result.failed("记录已完成或者已取消");
}
Double weight = Config.deviceThread.scale(which);
// 称重失败,在称一次
if (weight == null || weight == 0) {
weight = Config.deviceThread.scale(which);
}
if (weight == null || weight == 0) {
ActionCmdLogSyncService.me.save(cmdlog.toJson(), sysuser);
return Result.failed("称重失败");
}
boolean ret = TransportSyncService.me.postWeigh(transport, weight, which);
cmdlog.set("status", ret);
ActionCmdLogSyncService.me.save(cmdlog.toJson(), sysuser);
return Config.deviceThread.scale(which);
return ret ? Result.success() : Result.failed("称重失败");
} catch (Exception e) {
log.error(e.getMessage(), e);
return 0.0;
return Result.failed("称重失败");
}
}

View File

@ -160,23 +160,27 @@ public class TransportSyncService {
* @return
*/
public boolean postWeigh(int supermarket_id, String truck_license, Double weight, String which) {
Transport transport = TransportService.me.undoneTransport(supermarket_id, truck_license);
if (transport == null) {
log.error("车辆【%s】未找到入场记录", truck_license);
//TODO: 通知 web 端。弄一个不一样的颜色显示到出场识别队列里面?
return false;
} else if (transport.getState() >= OrderStateEnum.RECEIVED.getStateid()) {
log.error("车辆【%s】出入场记录已完结、或者已取消不能修改", truck_license);
//TODO: 通知 web 端。弄一个不一样的颜色显示到出场识别队列里面?
return false;
}
return postWeigh(transport, weight, which);
}
public boolean postWeigh(Transport transport, Double weight, String which) {
try {
if (!Enums.CtrlFlowEnum.isValid(which)) {
return false;
}
Transport transport = TransportService.me.undoneTransport(supermarket_id, truck_license);
if (transport == null) {
log.error("车辆【%s】未找到入场记录", truck_license);
//TODO: 通知 web 端。弄一个不一样的颜色显示到出场识别队列里面?
return false;
} else if (transport.getState() >= OrderStateEnum.RECEIVED.getStateid()) {
log.error("车辆【%s】出入场记录已完结、或者已取消不能修改", truck_license);
//TODO: 通知 web 端。弄一个不一样的颜色显示到出场识别队列里面?
return false;
}
boolean ret = false;
if (which.startsWith(Enums.CtrlFlowEnum.R.name())) {