|
|
@@ -1,5 +1,6 @@
|
|
|
package com.cec.plugins.controller;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.cec.plugins.domain.DtoPolicy;
|
|
|
import com.cec.plugins.domain.ResultData;
|
|
|
@@ -10,10 +11,9 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* @author zhanghaijun
|
|
|
@@ -45,9 +45,27 @@ public class CollectController {
|
|
|
reported(policy);
|
|
|
// 开始上报采集数据
|
|
|
taskCollectService.startReported(policy);
|
|
|
+ // 保存采集策略
|
|
|
+ taskCollectService.policyWritFile(policy);
|
|
|
return ResultData.success();
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("/getPolicy")
|
|
|
+ public ResultData getPolicy() {
|
|
|
+ return ResultData.success(StrUtil.blankToDefault(taskCollectService.policyReadFileToStr(),""));
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/reportedPolicy")
|
|
|
+ public ResultData reportedPolicy() {
|
|
|
+ DtoPolicy policy = taskCollectService.policyReadFile();
|
|
|
+ if (Optional.ofNullable(policy).map(DtoPolicy::getPolicy).isPresent()) {
|
|
|
+ taskCollectService.reportPolicy(policy);
|
|
|
+ return ResultData.success("上报采集数据成功");
|
|
|
+ }
|
|
|
+ return ResultData.fail("未发现上报策略");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Async
|
|
|
public void reported(DtoPolicy policy) {
|
|
|
ReportedData data = new ReportedData();
|