lisai17@sina.com 2020-10-21 11:11:37 +08:00
parent 8a53bdfcbf
commit 371583720b
7 changed files with 92 additions and 94 deletions

View File

@ -51,7 +51,7 @@ public class LEDThread extends Device implements Runnable {
}
};
private ReentrantLock lock = new ReentrantLock();
private ReentrantLock lock = new ReentrantLock();
private ReentrantLock connlock = new ReentrantLock();
protected Socket socket;
@ -92,85 +92,83 @@ public class LEDThread extends Device implements Runnable {
}
public void screen() {
synchronized (lock) {
lock.lock();
try {
if (this.license == null) {
lock.lock();
try {
if (this.license == null) {
return;
}
// 重连一次
if (!isConnected()) {
connect();
// 重连一次后还是连不上,就等下次连上再发送内容
if (!isConnected()) {
log.error("LED %s %s 连接失败", getId(), getIp());
return;
}
}
// 重连一次
if (!isConnected()) {
connect();
// 重连一次后还是连不上,就等下次连上再发送内容
if (!isConnected()) {
log.error("LED %s %s 连接失败", getId(), getIp());
return;
}
}
String date = sdf.get().format(new Date());
String dataStr = String.format(this.format, 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];
System.arraycopy(frameHead, 0, msg, 0, frameHead.length);
String date = sdf.get().format(new Date());
String dataStr = String.format(this.format, 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];
System.arraycopy(frameHead, 0, msg, 0, frameHead.length);
// System.out.println(HexDump.toHex(msg));
packetHead[packetHead.length - 2] = (byte) (b.length + dataLen);
System.arraycopy(packetHead, 0, msg, frameHead.length, packetHead.length);
packetHead[packetHead.length - 2] = (byte) (b.length + dataLen);
System.arraycopy(packetHead, 0, msg, frameHead.length, packetHead.length);
// System.out.println(HexDump.toHex(msg));
int areaLen = b.length - 9 + dataLen;
b[7] = (byte) areaLen;
b[32] = (byte) dataLen;
System.arraycopy(b, 0, msg, packetHead.length + frameHead.length, b.length);
int areaLen = b.length - 9 + dataLen;
b[7] = (byte) areaLen;
b[32] = (byte) dataLen;
System.arraycopy(b, 0, msg, packetHead.length + frameHead.length, b.length);
// System.out.println(HexDump.toHex(msg));
System.arraycopy(data, 0, msg, packetHead.length + frameHead.length + b.length, dataLen);
System.arraycopy(data, 0, msg, packetHead.length + frameHead.length + b.length, dataLen);
// System.out.println(HexDump.toHex(msg));
byte[] toCrc = new byte[msg.length - 8];
System.arraycopy(msg, 8, toCrc, 0, toCrc.length);
int crc = CalcCRC(toCrc, toCrc.length);
byte[] toCrc = new byte[msg.length - 8];
System.arraycopy(msg, 8, toCrc, 0, toCrc.length);
int crc = CalcCRC(toCrc, toCrc.length);
byte[] msgCrc = new byte[msg.length + 3];
System.arraycopy(msg, 0, msgCrc, 0, msg.length);
msgCrc[msgCrc.length - 2] = (byte) (crc >> 8);
msgCrc[msgCrc.length - 3] = (byte) crc;
msgCrc[msgCrc.length - 1] = frameTail;
byte[] msgCrc = new byte[msg.length + 3];
System.arraycopy(msg, 0, msgCrc, 0, msg.length);
msgCrc[msgCrc.length - 2] = (byte) (crc >> 8);
msgCrc[msgCrc.length - 3] = (byte) crc;
msgCrc[msgCrc.length - 1] = frameTail;
// System.out.println(getId() + " LED 发送数据:" + HexDump.toHex(msgCrc));
socket.getOutputStream().write(msgCrc);
socket.getOutputStream().flush();
socket.getOutputStream().write(msgCrc);
socket.getOutputStream().flush();
InputStream in = socket.getInputStream();
byte[] buf = new byte[in.available()];
in.read(buf);
// LED 返回
BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
byte[] y = new byte[128];
int read = bis.read(y);
while (!(read > 0)) {
read = bis.read(y);
}
byte[] z = new byte[read];
System.arraycopy(y, 0, z, 0, read);
InputStream in = socket.getInputStream();
byte[] buf = new byte[in.available()];
in.read(buf);
// LED 返回
BufferedInputStream bis = new BufferedInputStream(socket.getInputStream());
byte[] y = new byte[128];
int read = bis.read(y);
while (!(read > 0)) {
read = bis.read(y);
}
byte[] z = new byte[read];
System.arraycopy(y, 0, z, 0, read);
// System.out.println(getId() + " LED 返回数据:" + HexDump.toHex(z));
// socket.close();
} catch (Exception e) {
if (e.getMessage().contains("Socket is not connected")) {
log.error("LED %s %s 连接已断开", getId(), getIp());
}
if (e.getMessage().contains("Read timed out")) {
log.error("LED %s %s 连接超时", getId(), getIp());
} else {
log.error(e.getMessage(), e);
}
reconn();
} finally {
lock.unlock();
} catch (Exception e) {
if (e.getMessage().contains("Socket is not connected")) {
log.error("LED %s %s 连接已断开", getId(), getIp());
}
if (e.getMessage().contains("Read timed out")) {
log.error("LED %s %s 连接超时", getId(), getIp());
} else {
log.error(e.getMessage(), e);
}
reconn();
} finally {
lock.unlock();
}
}
@ -289,29 +287,32 @@ public class LEDThread extends Device implements Runnable {
}
public boolean reconn() {
connlock.lock();
try {
log.debug("销毁LED连接");
if (socket != null) {
socket.close();
}
try {
log.debug("销毁LED连接");
if (socket != null) {
socket.close();
}
socket = null;
} catch (Exception e) {
log.error(e.getMessage(), e);
}
try {
socket = new Socket();
socket.setSoTimeout(1000);
socket.connect(new InetSocketAddress(getIp(), getPort()), 5000);
} catch (Exception e) {
if (e.getMessage().contains("connect timed out")) {
log.error("LED %s %s 连接超时", getId(), getIp());
} else {
socket = null;
} catch (Exception e) {
log.error(e.getMessage(), e);
}
try {
socket = new Socket();
socket.setSoTimeout(1000);
socket.connect(new InetSocketAddress(getIp(), getPort()), 5000);
} catch (Exception e) {
if (e.getMessage().contains("connect timed out")) {
log.error("LED %s %s 连接超时", getId(), getIp());
} else {
log.error(e.getMessage(), e);
}
}
} finally {
lock.unlock();
connlock.unlock();
}
return isConnected();

View File

@ -92,7 +92,7 @@ public class Config extends JFinalConfig {
public static DeviceThread deviceThread = new DeviceThread();
public static SocketIOService socketio = null;
private static boolean client_run = true;
public static final String CLINET_VERSION = "20201019";
public static final String CLINET_VERSION = "20201021";
public static String getRootPath() {
return PathKit.getWebRootPath()

View File

@ -349,9 +349,13 @@ public class OrderTempSyncService {
order.setProductId(ordercluster.getProductId());
order.setProductName(ordercluster.getProductName());
BigDecimal up = null;
BigDecimal up = ordercluster.getUnitPrice(); // 集团订单是每天创建的,可以使用集团订单中确定的单价
// 客户信息
if (up == null) {
return Result.failedstr("未查到有效的单价信息");
}
// 客户信息
Customer customer = Customer.dao.findById(ordercluster.getCustomerId());
if (customer != null) {
order.setCustomerId(customer.getId());
@ -362,8 +366,6 @@ public class OrderTempSyncService {
order.setCustomerPhone(customer.getPhone());
order.setCustomerTexpayerName(customer.getTexpayerName());
order.setCustomerTexpayerNum(customer.getTexpayerNum());
up = CustomerSupermarketProductService.me.getUnitPrice(customer.getId(), transport.getSupermarketId(), ordercluster.getProductId());
} else {
// 可能是零散购砂客户,没有对应的客户信息记录,但是有客户名称之类的信息
order.setCustomerId(ordercluster.getCustomerId());
@ -374,12 +376,6 @@ public class OrderTempSyncService {
order.setCustomerPhone(ordercluster.getCustomerPhone());
order.setCustomerTexpayerName(ordercluster.getCustomerTexpayerName());
order.setCustomerTexpayerNum(ordercluster.getCustomerTexpayerNum());
up = SupermarketProductService.me.getUnitPrice(transport.getSupermarketId(), ordercluster.getProductId());
}
if (up == null) {
return Result.failedstr("未查到有效的单价信息");
}
// 支付信息
@ -677,7 +673,8 @@ public class OrderTempSyncService {
transport.setTransCoTexpayerName(ordercluster.getTransCoTexpayerName());
transport.setTransCoTexpayerNum(ordercluster.getTransCoTexpayerNum());
BigDecimal up = CustomerSupermarketProductService.me.getUnitPrice(customer.getId(), transport.getSupermarketId(), product.getId());
// BigDecimal up = CustomerSupermarketProductService.me.getUnitPrice(customer.getId(), transport.getSupermarketId(), product.getId());
BigDecimal up = ordercluster.getUnitPrice(); // 集团订单是每天创建的,可以使用集团订单中确定的单价
if (up == null) {
return Result.failedstr("未查到有效的单价信息");