提交 6832128c authored 作者: wangqiang's avatar wangqiang

Merge remote-tracking branch 'origin/master'

......@@ -49,8 +49,13 @@ public class ProgramController {
@Value(value = "${apq.url.upgrade}")
private String upgradeUrl;
@Value(value = "${apq.url.add-program}")
private String addProgramUrl;
private static List<Map<String, String>> programList;
private static final double MIN_MATCH = 0.5;
@GetMapping(value = "{type}/list")
public R<Page<Map<String, String>>> list(@PathVariable @Pattern(regexp = "install|upgrade") String type,
@RequestParam(required = false, defaultValue = "1") Integer current,
......@@ -80,7 +85,7 @@ public class ProgramController {
.entrySet()
.stream()
.max(Map.Entry.comparingByKey())
.filter(e -> e.getKey() >= 0.5)
.filter(e -> e.getKey() >= MIN_MATCH)
.ifPresent(e -> m.put("localVersion", e.getValue())))
.collect(Collectors.toList());
return R.success(page.setRecords(list));
......@@ -121,6 +126,21 @@ public class ProgramController {
}
}
@GetMapping(value = "get_version")
public R<String> getVersion(@RequestParam @NotBlank String name) throws IOException {
if (programList == null) loadProgramListJob();
return programList.stream()
.collect(Collectors.toMap(p -> StrUtil.similar(p.get("name").toLowerCase(), name.toLowerCase()),
p -> p.get("version"), (l, r) -> r))
.entrySet()
.stream()
.max(Map.Entry.comparingByKey())
.filter(e -> e.getKey() >= MIN_MATCH)
.map(Map.Entry::getValue)
.map(R::success)
.orElseGet(R::success);
}
@Scheduled(fixedDelay = 3000)
protected void loadProgramListJob() throws IOException {
......@@ -157,4 +177,18 @@ public class ProgramController {
}
return info;
}
@Scheduled(fixedDelay = 60000)
protected void addProgram2Platform() throws IOException {
if (programList == null) loadProgramListJob();
List<String> programNames = programList.stream().map(p -> p.get("name")).collect(Collectors.toList());
String sn = SysConfigUtil.getProperty("device.sn");
if (StrUtil.isBlank(sn)) {
log.warn("未配置设备SN号");
return;
}
HttpUtil.post(gateway + addProgramUrl,
JSONUtil.createObj().set("snNo", sn).set("programList", programNames).toString());
}
}
apq:
iot-gateway: 192.168.124.19:7002
url:
install: /ops/install/getList?pageNum={}&pageSize={}
upgrade: /ops/upgrade/getList?pageNum={}&pageSize={}
......@@ -35,4 +35,12 @@ core:
-
id: "http"
type: "HTTP"
extensionConfiguration: http-config.json
\ No newline at end of file
extensionConfiguration: http-config.json
apq:
iot-gateway: 192.168.124.19:7002
url:
install: /ops/install/getList?pageNum={}&pageSize={}
upgrade: /ops/upgrade/getList?pageNum={}&pageSize={}
add-program: /ops/program/addFacProgram
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论