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

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

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