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

.

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