提交 61baa2a3 authored 作者: 张航's avatar 张航

添加了默认下载基础地图以及地图的发布,并且修复了进度条的bug,项目目前可以稳定运行

上级 f9255149
...@@ -23,7 +23,7 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter { ...@@ -23,7 +23,7 @@ public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**") registry.addResourceHandler("/img/**")
.addResourceLocations("file:/"+ mapImgPath +"/"); .addResourceLocations("file:/"+ mapImgPath +"/");
super.addResourceHandlers(registry); super.addResourceHandlers(registry);
} }
......
...@@ -30,7 +30,6 @@ public class DownMapLv3 { ...@@ -30,7 +30,6 @@ public class DownMapLv3 {
//高德地图(6:影像,7:矢量,8:影像路网) //高德地图(6:影像,7:矢量,8:影像路网)
String imgUrl = CLStringUtil.getImgUrl(z, x, y); String imgUrl = CLStringUtil.getImgUrl(z, x, y);
File file = CLStringUtil.getFullFileNotExist(z, x, y); File file = CLStringUtil.getFullFileNotExist(z, x, y);
System.out.println(imgUrl);
// 开始下载地图 // 开始下载地图
if (file != null) { if (file != null) {
try { try {
...@@ -38,7 +37,9 @@ public class DownMapLv3 { ...@@ -38,7 +37,9 @@ public class DownMapLv3 {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return;
} }
System.out.println(imgUrl+" 基础地图加载");
} }
} }
}).start(); }).start();
......
...@@ -30,7 +30,6 @@ public class DownMapLv4 { ...@@ -30,7 +30,6 @@ public class DownMapLv4 {
//高德地图(6:影像,7:矢量,8:影像路网) //高德地图(6:影像,7:矢量,8:影像路网)
String imgUrl = CLStringUtil.getImgUrl(z, x, y); String imgUrl = CLStringUtil.getImgUrl(z, x, y);
File file = CLStringUtil.getFullFileNotExist(z, x, y); File file = CLStringUtil.getFullFileNotExist(z, x, y);
System.out.println(imgUrl);
// 开始下载地图 // 开始下载地图
if (file != null) { if (file != null) {
...@@ -39,7 +38,10 @@ public class DownMapLv4 { ...@@ -39,7 +38,10 @@ public class DownMapLv4 {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return;
} }
System.out.println(imgUrl+" 基础地图加载");
} }
} }
}).start(); }).start();
......
...@@ -39,7 +39,9 @@ public class DownMapLv5 { ...@@ -39,7 +39,9 @@ public class DownMapLv5 {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return;
} }
System.out.println(imgUrl+" 基础地图加载");
} }
} }
}).start(); }).start();
......
...@@ -30,8 +30,6 @@ public class DownMapLv6 { ...@@ -30,8 +30,6 @@ public class DownMapLv6 {
//高德地图(6:影像,7:矢量,8:影像路网) //高德地图(6:影像,7:矢量,8:影像路网)
String imgUrl = CLStringUtil.getImgUrl(z, x, y); String imgUrl = CLStringUtil.getImgUrl(z, x, y);
File file = CLStringUtil.getFullFileNotExist(z, x, y); File file = CLStringUtil.getFullFileNotExist(z, x, y);
System.out.println(imgUrl);
// 开始下载地图 // 开始下载地图
if (file != null) { if (file != null) {
try { try {
...@@ -39,7 +37,9 @@ public class DownMapLv6 { ...@@ -39,7 +37,9 @@ public class DownMapLv6 {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return;
} }
System.out.println(imgUrl+" 基础地图加载");
} }
} }
}).start(); }).start();
......
...@@ -31,7 +31,6 @@ public class DownMapLv6Runner implements ApplicationRunner { ...@@ -31,7 +31,6 @@ public class DownMapLv6Runner implements ApplicationRunner {
if (!flag){ if (!flag){
return; return;
} }
DownMapLv3.downLoad(); DownMapLv3.downLoad();
DownMapLv4.downLoad(); DownMapLv4.downLoad();
DownMapLv5.downLoad(); DownMapLv5.downLoad();
......
...@@ -139,17 +139,16 @@ public class DownMapService { ...@@ -139,17 +139,16 @@ public class DownMapService {
for (Future<String> future : futures) { for (Future<String> future : futures) {
if (DownMapService.stoped || !session.isOpen()) { if (DownMapService.stoped || !session.isOpen()) {
DownMapService.finished = true; DownMapService.finished = true;
// 如果发布了取消任务,则取消任务
stopDownLoad(futures); stopDownLoad(futures);
break; break;
} }
completionService.take();
Future<String> take = completionService.take(); Future<String> take = completionService.take();
String result = take.get(); String result = take.get();
speed++; // 累计到下载进度上 speed++; // 累计到下载进度上
countSuccessFile++; countSuccessFile++;
System.out.println(result); System.out.println(result);
} }
// 如果发布了取消任务,则取消任务
// 结束定时器 // 结束定时器
speedTimer.cancel(); speedTimer.cancel();
long end = System.currentTimeMillis(); long end = System.currentTimeMillis();
...@@ -162,6 +161,9 @@ public class DownMapService { ...@@ -162,6 +161,9 @@ public class DownMapService {
resBody.put("totalSize", CLStringUtil.getDownTotalSize()); resBody.put("totalSize", CLStringUtil.getDownTotalSize());
// 完成标志 // 完成标志
this.finished = true; this.finished = true;
log.info("falidNum > "+errResults.size());
log.info("totalTime > "+(end - start) / 1000 + " s");
log.info("totalSize > "+CLStringUtil.getDownTotalSize());
return resBody; return resBody;
} }
...@@ -233,7 +235,7 @@ public class DownMapService { ...@@ -233,7 +235,7 @@ public class DownMapService {
try { try {
if (DownMapService.stoped) { // 停止下载的命令 if (DownMapService.stoped) { // 停止下载的命令
DownMapService.finished = true; DownMapService.finished = true;
return null; return imgUrl + " Loaded";
} }
//高德地图(6:影像,7:矢量,8:影像路网) //高德地图(6:影像,7:矢量,8:影像路网)
imgUrl = CLStringUtil.getImgUrl(z, x, y); imgUrl = CLStringUtil.getImgUrl(z, x, y);
......
...@@ -23,7 +23,7 @@ import java.util.TimerTask; ...@@ -23,7 +23,7 @@ import java.util.TimerTask;
/** /**
* @ClassName WebSocket * @ClassName WebSocket
* @Description: WebSocket服务类,统一功能: 0: 代表请求下载文件校验信息,1代表 * @Description: WebSocket服务类, 统一功能: 0: 代表请求下载文件校验信息,1代表
* @Author zhanghang * @Author zhanghang
* @Date 2020/3/31 * @Date 2020/3/31
* @Version V1.0 * @Version V1.0
...@@ -111,21 +111,23 @@ public class DownLoadMapWebSocket { ...@@ -111,21 +111,23 @@ public class DownLoadMapWebSocket {
SocketResultData socketData = JSONUtil.toBean(message, SocketResultData.class); SocketResultData socketData = JSONUtil.toBean(message, SocketResultData.class);
// 校验下载信息(操作类型为0) // 校验下载信息(操作类型为0)
if (socketData.getType() == OperationTypeEnum.DOWNLOAD_READY.getType()) { if (socketData.getType() == OperationTypeEnum.DOWNLOAD_READY.getType()) {
if (DownMapService.isBusy){ if (DownMapService.isBusy) {
// 线程未执行完成 // 线程未执行完成
return; return;
} }
AppointSending(JSONUtil.toJsonStr(new SocketResultData(OperationTypeEnum.SYS_SUCCESS,"准备下载",null))); AppointSending(JSONUtil.toJsonStr(new SocketResultData(OperationTypeEnum.SYS_SUCCESS, "准备下载", null)));
//initDownLoad();
DownMapService.readyCountFile = 0;
Map<String, Object> body = downMapService.readyDownLoad(socketData.getBody()); Map<String, Object> body = downMapService.readyDownLoad(socketData.getBody());
// 校验信息结果 // 校验信息结果
SocketResultData resultData = new SocketResultData(OperationTypeEnum.DOWNLOAD_READY,body); SocketResultData resultData = new SocketResultData(OperationTypeEnum.DOWNLOAD_READY, body);
// 返回结果 // 返回结果
AppointSending(JSONUtil.toJsonStr(resultData)); AppointSending(JSONUtil.toJsonStr(resultData));
} }
// 停止下载(5) // 停止下载(5)
if (socketData.getType() == OperationTypeEnum.DOWNLOAD_STOP.getType()) { if (socketData.getType() == OperationTypeEnum.DOWNLOAD_STOP.getType()) {
if (!DownMapService.isBusy){ if (!DownMapService.isBusy) {
// 线程未执行完成 // 线程未执行完成
AppointSending(JSONUtil.toJsonStr(new SocketResultData(OperationTypeEnum.SYS_SUCCESS, "暂无下载任务", null))); AppointSending(JSONUtil.toJsonStr(new SocketResultData(OperationTypeEnum.SYS_SUCCESS, "暂无下载任务", null)));
return; return;
...@@ -139,25 +141,25 @@ public class DownLoadMapWebSocket { ...@@ -139,25 +141,25 @@ public class DownLoadMapWebSocket {
} }
// 操作类型为1,开始下载 // 操作类型为1,开始下载
if (socketData.getType() == OperationTypeEnum.DOWNLOAD_MAP.getType()){ if (socketData.getType() == OperationTypeEnum.DOWNLOAD_MAP.getType()) {
if (DownMapService.isBusy){ if (DownMapService.isBusy) {
// 线程未执行完成 // 线程未执行完成
return; return;
} }
initDownLoad(); initDownLoad(); // 初始化下载信息
// 下载和发送地图(由于是单机,只有一个session,所以需要开启一个线程执行,否则执行期间服务器接收不到其他命令) // 下载和发送地图(由于是单机,只有一个session,所以需要开启一个线程执行,否则执行期间服务器接收不到其他命令)
thread = new Thread(() -> { thread = new Thread(() -> {
try { try {
downLoadMap(socketData,session); downLoadMap(socketData, session);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
AppointSending(JSONUtil.toJsonStr(new SocketResultData(OperationTypeEnum.SYS_ERROR,"系统异常!!",null))); AppointSending(JSONUtil.toJsonStr(new SocketResultData(OperationTypeEnum.SYS_ERROR, "系统异常!!", null)));
} }
}); });
thread.start(); thread.start();
} }
} catch (Exception e) { } catch (Exception e) {
AppointSending(JSONUtil.toJsonStr(new SocketResultData(OperationTypeEnum.SYS_ERROR,"系统异常!!",null))); AppointSending(JSONUtil.toJsonStr(new SocketResultData(OperationTypeEnum.SYS_ERROR, "系统异常!!", null)));
e.printStackTrace(); e.printStackTrace();
} }
} }
...@@ -170,15 +172,15 @@ public class DownLoadMapWebSocket { ...@@ -170,15 +172,15 @@ public class DownLoadMapWebSocket {
@Override @Override
public void run() { public void run() {
// 发送了停止命令或者已经完成 // 发送了停止命令或者已经完成
if (DownMapService.stoped || DownMapService.finished){ if (DownMapService.stoped || DownMapService.finished) {
speedTimer.cancel(); speedTimer.cancel();
return; }else {
}
// 发送速度 // 发送速度
SocketResultData speed = new SocketResultData(OperationTypeEnum.SYS_SUCCESS, "下载速度"+DownMapService.speed + "张/s", null); SocketResultData speed = new SocketResultData(OperationTypeEnum.SYS_SUCCESS, "下载速度" + DownMapService.speed + "张/s", null);
AppointSending(JSONUtil.toJsonStr(speed)); AppointSending(JSONUtil.toJsonStr(speed));
} }
},1000,1000); }
}, 1000, 1000);
// 创建定时任务向前端发送进度 // 创建定时任务向前端发送进度
Timer scheduleTimer = new Timer(); Timer scheduleTimer = new Timer();
// 每隔0.2秒汇报一次 // 每隔0.2秒汇报一次
...@@ -186,23 +188,23 @@ public class DownLoadMapWebSocket { ...@@ -186,23 +188,23 @@ public class DownLoadMapWebSocket {
@Override @Override
public void run() { public void run() {
// 发送了停止命令或者已经完成 // 发送了停止命令或者已经完成
if (DownMapService.stoped || DownMapService.finished){ if (DownMapService.stoped || DownMapService.finished) {
DownMapService.isBusy = false; DownMapService.isBusy = false;
SocketResultData schedule = new SocketResultData(OperationTypeEnum.DOWNLOAD_SCHEDULE, 100+"", null); SocketResultData schedule = new SocketResultData(OperationTypeEnum.DOWNLOAD_SCHEDULE, 100 + "", null);
AppointSending(JSONUtil.toJsonStr(schedule)); AppointSending(JSONUtil.toJsonStr(schedule));
scheduleTimer.cancel(); scheduleTimer.cancel();
return; } else {
}
// 发送进度 // 发送进度
SocketResultData schedule = new SocketResultData(OperationTypeEnum.DOWNLOAD_SCHEDULE, DownMapService.schedule+"", null); SocketResultData schedule = new SocketResultData(OperationTypeEnum.DOWNLOAD_SCHEDULE, DownMapService.schedule + "", null);
AppointSending(JSONUtil.toJsonStr(schedule)); AppointSending(JSONUtil.toJsonStr(schedule));
} }
},200,200); }
}, 200, 200);
// 发送执行结果(这里是异步阻塞的,会等待downLoad执行完成) // 发送执行结果(这里是异步阻塞的,会等待downLoad执行完成)
Map<String, Object> resBody = downMapService.downLoad(socketData.getBody(),session); Map<String, Object> resBody = downMapService.downLoad(socketData.getBody(), session);
String msg = "下载完成,总用时"+resBody.get("totalTime")+",总大小"+ resBody.get("totalSize")+ String msg = "下载完成,总用时" + resBody.get("totalTime") + ",总大小" + resBody.get("totalSize") +
",总用时"+resBody.get("totalTime")+",失败个数"+resBody.get("falidNum")+"(可选择非覆盖重新下载!)"; ",总用时" + resBody.get("totalTime") + ",失败个数" + resBody.get("falidNum") + "(可选择非覆盖重新下载!)";
SocketResultData resultData = new SocketResultData(OperationTypeEnum.SYS_SUCCESS, msg, null); SocketResultData resultData = new SocketResultData(OperationTypeEnum.SYS_SUCCESS, msg, null);
AppointSending(JSONUtil.toJsonStr(resultData)); AppointSending(JSONUtil.toJsonStr(resultData));
// 通知下载完成 // 通知下载完成
...@@ -211,8 +213,8 @@ public class DownLoadMapWebSocket { ...@@ -211,8 +213,8 @@ public class DownLoadMapWebSocket {
private static void initDownLoad() { private static void initDownLoad() {
HttpUtil.totalSize = 0; HttpUtil.totalSize = 0;
DownMapService.finished =false; DownMapService.finished = false;
DownMapService.stoped =false; DownMapService.stoped = false;
DownMapService.speed = 0; DownMapService.speed = 0;
DownMapService.schedule = 0; DownMapService.schedule = 0;
DownMapService.countSuccessFile = 0; DownMapService.countSuccessFile = 0;
......
...@@ -142,7 +142,6 @@ ...@@ -142,7 +142,6 @@
var schedule = result.message; var schedule = result.message;
if (schedule > 100){ if (schedule > 100){
schedule = 100; schedule = 100;
socketMsgEle.innerHTML = '<p style="color: green">下载完成,请等待。。。</p>';
} }
console.log(schedule); console.log(schedule);
$("#progressBar").width(schedule + "%"); $("#progressBar").width(schedule + "%");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论