|
@@ -15,6 +15,7 @@ import org.springframework.http.HttpEntity;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpMethod;
|
|
import org.springframework.http.HttpMethod;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.MediaType;
|
|
|
|
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
@@ -28,8 +29,8 @@ import java.util.Map;
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
public class WebAccessService {
|
|
public class WebAccessService {
|
|
- @Autowired
|
|
|
|
- private RestTemplate restTemplate;
|
|
|
|
|
|
+// @Autowired
|
|
|
|
+// private RestTemplate restTemplate;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private ISysDictItemService sysDictItemService;
|
|
private ISysDictItemService sysDictItemService;
|
|
@@ -263,6 +264,14 @@ public class WebAccessService {
|
|
headers.setContentType(type);
|
|
headers.setContentType(type);
|
|
headers.add("Authorization", "Basic " + base64Creds);
|
|
headers.add("Authorization", "Basic " + base64Creds);
|
|
HttpEntity<String> formEntity;
|
|
HttpEntity<String> formEntity;
|
|
|
|
+
|
|
|
|
+ // 配置http请求的连接超时时间和读取超时时间,原来的注入的方法,容易超时
|
|
|
|
+ HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory ();
|
|
|
|
+ factory.setConnectTimeout(60 * 1000);
|
|
|
|
+ factory.setReadTimeout(5 * 60 * 1000);
|
|
|
|
+ factory.setConnectionRequestTimeout(5 * 60 * 1000);
|
|
|
|
+ RestTemplate restTemplate = new RestTemplate(factory);
|
|
|
|
+
|
|
JSONObject result;
|
|
JSONObject result;
|
|
if (jsonObject == null) {
|
|
if (jsonObject == null) {
|
|
formEntity = new HttpEntity<String>(null, headers);
|
|
formEntity = new HttpEntity<String>(null, headers);
|
|
@@ -318,9 +327,7 @@ public class WebAccessService {
|
|
|
|
|
|
return rtn;
|
|
return rtn;
|
|
}
|
|
}
|
|
- //endregion
|
|
|
|
|
|
|
|
- //region <<获取历史记录>>
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
* 生成获取历史记录的参数
|
|
* 生成获取历史记录的参数
|
|
@@ -340,37 +347,30 @@ public class WebAccessService {
|
|
* @param Interval 每笔数据之间隔时间,以 IntervalType 为单位。
|
|
* @param Interval 每笔数据之间隔时间,以 IntervalType 为单位。
|
|
* @param Records 欲查询之每个点的数据笔数。
|
|
* @param Records 欲查询之每个点的数据笔数。
|
|
* @param DataType 数据型态,0 - Last,1-Min,2 - Max,3 - Avg。
|
|
* @param DataType 数据型态,0 - Last,1-Min,2 - Max,3 - Avg。
|
|
|
|
+ * @param TagName 点位名。
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public JSONObject generateDataLogObject(String StartTime, String IntervalType, Integer Interval, Integer Records, String DataType) {
|
|
|
|
|
|
+ public JSONObject generateDataLogObject(String StartTime, String IntervalType, Integer Interval,
|
|
|
|
+ Integer Records, String DataType, String TagName) {
|
|
JSONArray list = new JSONArray();
|
|
JSONArray list = new JSONArray();
|
|
JSONObject rtn = new JSONObject();
|
|
JSONObject rtn = new JSONObject();
|
|
|
|
|
|
- // 获取大屏参数设置
|
|
|
|
- GuanDashboardParam paramat = new GuanDashboardParam();
|
|
|
|
- paramat.setStatus("1"); // 状态为启用
|
|
|
|
- paramat.setIflog("Y"); // 需要获取历史记录
|
|
|
|
- List<GuanDashboardParam> dashboardParamList = dashboardParamMapper.selectAllDashboardParam(paramat);
|
|
|
|
-
|
|
|
|
rtn.put("StartTime", StartTime);
|
|
rtn.put("StartTime", StartTime);
|
|
rtn.put("IntervalType", IntervalType);
|
|
rtn.put("IntervalType", IntervalType);
|
|
rtn.put("Interval", Interval);
|
|
rtn.put("Interval", Interval);
|
|
rtn.put("Records", Records);
|
|
rtn.put("Records", Records);
|
|
- if (dashboardParamList != null && dashboardParamList.size() > 0) {
|
|
|
|
- for (GuanDashboardParam param : dashboardParamList) {
|
|
|
|
- JSONObject sub = new JSONObject();
|
|
|
|
- sub.put("Name", param.getTagName());
|
|
|
|
- sub.put("DataType", DataType);
|
|
|
|
- list.add(sub);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- rtn.put("Tags", list);
|
|
|
|
|
|
|
|
|
|
+ JSONObject sub = new JSONObject();
|
|
|
|
+ sub.put("Name", TagName);
|
|
|
|
+ sub.put("DataType", DataType);
|
|
|
|
+
|
|
|
|
+ list.add(sub);
|
|
|
|
+ rtn.put("Tags", list);
|
|
return rtn;
|
|
return rtn;
|
|
}
|
|
}
|
|
//endregion
|
|
//endregion
|
|
|
|
|
|
- //region <<根据大屏参数设置,获取点位实时值>>
|
|
|
|
|
|
+ //region <<根据大屏参数设置,获取点位值>>
|
|
/**
|
|
/**
|
|
* 取得测点(Tag)的量测值
|
|
* 取得测点(Tag)的量测值
|
|
*
|
|
*
|
|
@@ -400,5 +400,46 @@ public class WebAccessService {
|
|
JSONObject jsonObject = getTagNameValuesNoAnalysis(waparams);
|
|
JSONObject jsonObject = getTagNameValuesNoAnalysis(waparams);
|
|
return jsonObject;
|
|
return jsonObject;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 取得历史记录
|
|
|
|
+ *
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public JSONObject getDashboardDataLog() {
|
|
|
|
+ // 获取大屏参数设置
|
|
|
|
+ GuanDashboardParam paramat = new GuanDashboardParam();
|
|
|
|
+ paramat.setStatus("1"); // 状态为启用
|
|
|
|
+ paramat.setIflog("Y"); // 需要获取历史记录
|
|
|
|
+ List<GuanDashboardParam> dashboardParamList = dashboardParamMapper.selectAllDashboardParam(paramat);
|
|
|
|
+
|
|
|
|
+ // 组合参数信息
|
|
|
|
+ JSONArray list = new JSONArray();
|
|
|
|
+ if (dashboardParamList != null && dashboardParamList.size() > 0) {
|
|
|
|
+ for (GuanDashboardParam param : dashboardParamList) {
|
|
|
|
+ if (param.getTagName() != null && !"".equals(param.getTagName())) {
|
|
|
|
+ JSONObject jo = generateDataLogObject("2023-12-26 21:00:00",
|
|
|
|
+ param.getIntervaltype() == null || "".equals(param.getIntervaltype()) ? "M" : param.getIntervaltype(),
|
|
|
|
+ param.getIntervals() == null ? 1 : param.getIntervals(),
|
|
|
|
+ param.getRecords() == null ? 1000 : param.getRecords(),
|
|
|
|
+ param.getDatatype() == null || "".equals(param.getDatatype()) ? "0" : param.getDatatype(),
|
|
|
|
+ param.getTagName());
|
|
|
|
+
|
|
|
|
+ // 获取信息
|
|
|
|
+ JSONObject dataLog = GetDataLog(jo);
|
|
|
|
+ JSONObject logObj = new JSONObject();
|
|
|
|
+ logObj.put("Name", param.getParamName());
|
|
|
|
+ logObj.put("Values", dataLog.getJSONArray("DataLog").getJSONObject(0).getJSONArray("Values"));
|
|
|
|
+ list.add(logObj);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ JSONObject rtn = new JSONObject();
|
|
|
|
+ rtn.put("历史记录", list);
|
|
|
|
+ return rtn;
|
|
|
|
+ }
|
|
//endregion
|
|
//endregion
|
|
}
|
|
}
|