|
@@ -1,9 +1,13 @@
|
|
|
package com.tuoren.remote;
|
|
package com.tuoren.remote;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
|
+import java.nio.file.Path;
|
|
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.sql.Connection;
|
|
import java.sql.Connection;
|
|
|
import java.sql.ResultSet;
|
|
import java.sql.ResultSet;
|
|
|
-import java.util.Date;
|
|
|
|
|
|
|
+import java.util.HashSet;
|
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
|
|
import javax.sql.DataSource;
|
|
import javax.sql.DataSource;
|
|
|
|
|
|
|
@@ -12,7 +16,6 @@ import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
-import cn.hutool.core.util.HexUtil;
|
|
|
|
|
import cn.hutool.db.sql.SqlExecutor;
|
|
import cn.hutool.db.sql.SqlExecutor;
|
|
|
import io.netty.bootstrap.ServerBootstrap;
|
|
import io.netty.bootstrap.ServerBootstrap;
|
|
|
import io.netty.buffer.ByteBuf;
|
|
import io.netty.buffer.ByteBuf;
|
|
@@ -64,6 +67,8 @@ class MyServerInitializer extends ChannelInitializer<SocketChannel>{
|
|
|
class MyServerHandler extends ChannelInboundHandlerAdapter{
|
|
class MyServerHandler extends ChannelInboundHandlerAdapter{
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(MyServerHandler.class);
|
|
private static Logger logger = LoggerFactory.getLogger(MyServerHandler.class);
|
|
|
|
|
+ static Set<String> downFileSign = new HashSet<String>();
|
|
|
|
|
+ String filedir = System.getProperty("user.dir")+"/file/";
|
|
|
String key ="tuorenzhinenghua";
|
|
String key ="tuorenzhinenghua";
|
|
|
DataSource ds = PropertyConfig.getDs();
|
|
DataSource ds = PropertyConfig.getDs();
|
|
|
@Override
|
|
@Override
|
|
@@ -119,7 +124,7 @@ class MyServerHandler extends ChannelInboundHandlerAdapter{
|
|
|
json.put("code", 1);
|
|
json.put("code", 1);
|
|
|
|
|
|
|
|
String deviceName = jsonData.getString("device");
|
|
String deviceName = jsonData.getString("device");
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Connection conn = ds.getConnection();
|
|
Connection conn = ds.getConnection();
|
|
|
ResultSet resultSet = SqlExecutor.callQuery(conn, "select c.type,c.total_dose,c.first_dose,c.max_dose,c.append_dose,c.continue_dose"
|
|
ResultSet resultSet = SqlExecutor.callQuery(conn, "select c.type,c.total_dose,c.first_dose,c.max_dose,c.append_dose,c.continue_dose"
|
|
|
+ ",c.self_control_lock_time,c.patient_code from bus_device_configuration c "
|
|
+ ",c.self_control_lock_time,c.patient_code from bus_device_configuration c "
|
|
@@ -146,18 +151,61 @@ class MyServerHandler extends ChannelInboundHandlerAdapter{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private String handleCheck(JSONObject jsonData) throws Exception{
|
|
private String handleCheck(JSONObject jsonData) throws Exception{
|
|
|
|
|
+ String version = jsonData.getString("version");
|
|
|
|
|
+ String[] verarr = version.split("\\.");
|
|
|
|
|
+ version = verarr[0]+verarr[1];
|
|
|
JSONObject json = new JSONObject();
|
|
JSONObject json = new JSONObject();
|
|
|
- json.put("update_flag", 1); //是否可以升级
|
|
|
|
|
- json.put("update_file", "1.2.bin");
|
|
|
|
|
|
|
+ Connection conn = ds.getConnection();
|
|
|
|
|
+ int veri = Integer.parseInt(version);
|
|
|
|
|
+ veri++;
|
|
|
|
|
+ version = String.valueOf(veri);
|
|
|
|
|
+ String mainV = version.substring(0, version.length()-2);
|
|
|
|
|
+ String secV = version.substring(version.length()-2);
|
|
|
|
|
+
|
|
|
|
|
+ String version2 = mainV+"."+secV;
|
|
|
|
|
+
|
|
|
|
|
+ ResultSet resultSet = SqlExecutor.callQuery(conn, "select url from sys_version where type=7 and version_name = ? limit 1", version2);
|
|
|
|
|
+ if(resultSet.next()) {
|
|
|
|
|
+ json.put("update_flag", 1); //是否可以升级
|
|
|
|
|
+ json.put("update_file", "1.2.bin");
|
|
|
|
|
+
|
|
|
|
|
+ String url = resultSet.getString("url");
|
|
|
|
|
+
|
|
|
|
|
+ String file = version2+".bin";
|
|
|
|
|
+ Path path = Paths.get(filedir+file);
|
|
|
|
|
+ if (Files.exists(path)) {
|
|
|
|
|
+ json.put("update_flag", 1); //是否可以升级
|
|
|
|
|
+ json.put("update_file", file);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ if(downFileSign.contains(file)) {
|
|
|
|
|
+ json.put("update_flag", 0); //是否可以升级
|
|
|
|
|
+ }else {
|
|
|
|
|
+ downFileSign.add(file);
|
|
|
|
|
+ try {
|
|
|
|
|
+ DownloadFileFromURL.downloadUsingStream(url, filedir+file);
|
|
|
|
|
+ json.put("update_flag", 1); //是否可以升级
|
|
|
|
|
+ json.put("update_file", file);
|
|
|
|
|
+ }catch (Exception e) {
|
|
|
|
|
+ // TODO: handle exception
|
|
|
|
|
+ json.put("update_flag", 0); //是否可以升级
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ logger.info("download file error:"+e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ downFileSign.remove(file);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }else {
|
|
|
|
|
+ json.put("update_flag", 0); //是否可以升级
|
|
|
|
|
+ }
|
|
|
|
|
+ conn.close();
|
|
|
return json.toString();
|
|
return json.toString();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private byte[] handleUpdateFile(JSONObject jsonData) throws Exception{
|
|
private byte[] handleUpdateFile(JSONObject jsonData) throws Exception{
|
|
|
byte[] bs = null;
|
|
byte[] bs = null;
|
|
|
String file = jsonData.getString("file");
|
|
String file = jsonData.getString("file");
|
|
|
- String workdir = System.getProperty("user.dir");
|
|
|
|
|
- System.out.println(workdir);
|
|
|
|
|
- File fileF = new File(workdir+"/file/"+file);
|
|
|
|
|
|
|
+ File fileF = new File(filedir+file);
|
|
|
byte blockNum = jsonData.getByte("blockNum");
|
|
byte blockNum = jsonData.getByte("blockNum");
|
|
|
if(0==blockNum) {
|
|
if(0==blockNum) {
|
|
|
bs = YModem.fileInfo(fileF, file);
|
|
bs = YModem.fileInfo(fileF, file);
|
|
@@ -167,6 +215,7 @@ class MyServerHandler extends ChannelInboundHandlerAdapter{
|
|
|
return bs;
|
|
return bs;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|