提交 2d22ae6e authored 作者: yangli's avatar yangli

.

上级 7bcf29de
...@@ -53,9 +53,19 @@ public class ProgramController { ...@@ -53,9 +53,19 @@ public class ProgramController {
@Value(value = "${apq.url.upgrade}") @Value(value = "${apq.url.upgrade}")
private String upgradeUrl; private String upgradeUrl;
@Value(value = "apq.url.install-status-upissue")
private String installStatusUpIssueUrl;
@Value(value = "apq.url.upgrade-status-upissue")
private String upgradeStatusUpIssueUrl;
@Value(value = "${apq.url.add-program}") @Value(value = "${apq.url.add-program}")
private String addProgramUrl; private String addProgramUrl;
@Resource @Resource
private InstalledProgramCache installedProgramCache; private InstalledProgramCache installedProgramCache;
...@@ -102,12 +112,13 @@ public class ProgramController { ...@@ -102,12 +112,13 @@ public class ProgramController {
return R.success(page.setRecords(list)); return R.success(page.setRecords(list));
} }
private static final Set<Long> SET = new ConcurrentHashSet<>(); private static final Set<String> SET = new ConcurrentHashSet<>();
private static final Map<Long, Thread> MAP = new ConcurrentHashMap<>(); private static final Map<String, Thread> MAP = new ConcurrentHashMap<>();
@GetMapping(value = "download_and_install") @GetMapping(value = "{type}/download_and_install")
public void downloadAndInstall(@RequestParam @NotNull Long id, public void downloadAndInstall(@PathVariable @Pattern(regexp = "install|upgrade") String type,
@RequestParam @NotNull Long id,
@RequestParam @NotBlank String url, @RequestParam @NotBlank String url,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
File dir = new File(SysConfigUtil.getProperty("download.path", File dir = new File(SysConfigUtil.getProperty("download.path",
...@@ -116,11 +127,12 @@ public class ProgramController { ...@@ -116,11 +127,12 @@ public class ProgramController {
HttpResponse rsp = HttpUtil.createGet(url).execute(true); HttpResponse rsp = HttpUtil.createGet(url).execute(true);
double length = rsp.contentLength(); double length = rsp.contentLength();
DecimalFormat decimalFormat = new DecimalFormat("0.#####"); DecimalFormat decimalFormat = new DecimalFormat("0.#####");
String key = type + "-" + id;
File file = rsp.writeBodyForFile(dir, new StreamProgress() { File file = rsp.writeBodyForFile(dir, new StreamProgress() {
@SneakyThrows @SneakyThrows
@Override @Override
public void start() { public void start() {
SET.add(id); SET.add(key);
response.getWriter().write("0\n"); response.getWriter().write("0\n");
} }
...@@ -134,23 +146,29 @@ public class ProgramController { ...@@ -134,23 +146,29 @@ public class ProgramController {
@Override @Override
public void finish() { public void finish() {
response.getWriter().close(); response.getWriter().close();
SET.remove(id); SET.remove(key);
} }
}); });
MAP.put(id, new Thread(() -> { MAP.put(key, new Thread(() -> {
int exitVal = -1;
try { try {
Runtime.getRuntime().exec("cmd /c " + file.getPath()).waitFor(); exitVal = Runtime.getRuntime().exec("cmd /c \"" + file.getPath() +"\"").waitFor();
} catch (Exception e) { } catch (Exception e) {
log.error("执行安装文件 {} 失败", file.getPath(), e); log.error("执行安装文件 {} 失败", file.getPath(), e);
} }
MAP.remove(id); MAP.remove(key);
if (exitVal == 0) {
HttpUtil.post(StrUtil.format(type.equals("install") ? installStatusUpIssueUrl : upgradeStatusUpIssueUrl,
MacAddrUtil.get(), id), (String) null);
}
})); }));
MAP.get(id).start(); MAP.get(key).start();
} }
@GetMapping(value = "is_installing") @GetMapping(value = "{type}/is_installing")
public R<Boolean> isInstalling(@RequestParam @NotNull Long id) { public R<Boolean> isInstalling(@PathVariable @Pattern(regexp = "install|upgrade") String type,
return R.success(MAP.containsKey(id)); @RequestParam @NotNull Long id) {
return R.success(MAP.containsKey(type + "-" + id));
} }
@GetMapping(value = "get_version") @GetMapping(value = "get_version")
......
...@@ -44,9 +44,12 @@ apq: ...@@ -44,9 +44,12 @@ apq:
device_info: /facility/facility/getByMacAddress?macAddress={} device_info: /facility/facility/getByMacAddress?macAddress={}
install: /ops/install/getClientList?macAddress={}&pageNum={}&pageSize={} install: /ops/install/getClientList?macAddress={}&pageNum={}&pageSize={}
upgrade: /ops/upgrade/getClientList?macAddress={}&pageNum={}&pageSize={} upgrade: /ops/upgrade/getClientList?macAddress={}&pageNum={}&pageSize={}
install-status-upissue: /ops/install/upIssueStatus/{}/{}
upgrade-status-upissue: /ops/upgrade/upIssueStatus/{}/{}
add-program: /ops/program/addFacProgram add-program: /ops/program/addFacProgram
send-control-req: /facility/facility/remoteRequest send-control-req: /facility/facility/remoteRequest
# VNC中继服务器 # VNC中继服务器
vnc-repeater: 120.24.236.245:5500 vnc-repeater: 120.24.236.245:5500
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论