|
@@ -1,6 +1,7 @@
|
|
|
package com.example.opc_da.controller;
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.example.opc_common.entity.Collector;
|
|
@@ -10,12 +11,16 @@ import com.example.opc_common.util.ClientUtil;
|
|
|
import com.example.opc_common.util.Result;
|
|
|
import com.example.opc_da.service.CollectorService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+@Slf4j
|
|
|
@RestController
|
|
|
@RequestMapping("collector")
|
|
|
@RequiredArgsConstructor
|
|
@@ -208,4 +213,55 @@ public class CollectorController {
|
|
|
}
|
|
|
return collectorService.getClientNameByItemGroupId(itemGroupId);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据数据组刷新采集器
|
|
|
+ * @param itemGroupId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ @GetMapping("refreshConfigByItemGroupId")
|
|
|
+ public Result refreshConfigByItemGroupId(Integer itemGroupId){
|
|
|
+ Result clientNameByItemGroupIdResult = collectorService.getClientNameByItemGroupId(itemGroupId);
|
|
|
+ List<Map<String, Object>> clientNameList = (List<Map<String, Object>>)clientNameByItemGroupIdResult.getData();
|
|
|
+ List<Map<String, Object>> errorClientNameList = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> successClientNameList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < clientNameList.size(); i++) {
|
|
|
+ Map<String, Object> clientNameMap = clientNameList.get(i);
|
|
|
+ try {
|
|
|
+ String ip = Convert.toStr(clientNameMap.get("ipAddr"), "");
|
|
|
+ Integer id = Convert.toInt(clientNameMap.get("id"), 0);
|
|
|
+ String clientName = Convert.toStr(clientNameMap.get("clientName"), "");
|
|
|
+ if(StrUtil.isEmpty(ip)){
|
|
|
+ log.warn("采集器【" + clientName + "】IP为空");
|
|
|
+ errorClientNameList.add(clientNameMap);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String body = ClientUtil.http(ip, clientPort, ClientUtil.Client.STATUS_API).execute().body();
|
|
|
+ JSONObject obj = JSONUtil.parseObj(body);
|
|
|
+ obj = obj.getJSONObject("data");
|
|
|
+ Integer runStatus = Convert.toInt(obj.get("status"), 0);
|
|
|
+ if(runStatus.equals(0)){
|
|
|
+ log.warn("采集器【" + clientName + "】未运行");
|
|
|
+ errorClientNameList.add(clientNameMap);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ // 刷新采集器
|
|
|
+ Result result = collectorService.refreshConfig(id);
|
|
|
+ if(!result.getCode().equals(ResultEnum.SUCCESS.getRespCode())){
|
|
|
+ log.warn("采集器【" + clientName + "】刷新失败:" + result.getMsg());
|
|
|
+ errorClientNameList.add(clientNameMap);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ successClientNameList.add(clientNameMap);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("实时数据刷新采集器失败", e);
|
|
|
+ errorClientNameList.add(clientNameMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String,Object> resultMap = new HashMap<>();
|
|
|
+ resultMap.put("successClientNameList", successClientNameList);
|
|
|
+ resultMap.put("errorClientNameList", errorClientNameList);
|
|
|
+ return Result.ok(resultMap);
|
|
|
+ }
|
|
|
}
|