|
@@ -1,7 +1,27 @@
|
|
|
package com.ruoyi.quartz.task;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.ruoyi.common.constant.MonitoringAlarms;
|
|
|
+import com.ruoyi.common.monitoringAlarms.main.OpenApi;
|
|
|
+import com.ruoyi.common.utils.JsonUtil;
|
|
|
+import com.ruoyi.warehouse.warehouse.domain.TMonitoringAlarms;
|
|
|
+import com.ruoyi.warehouse.warehouse.service.ITMonitoringAlarmsService;
|
|
|
+import okhttp3.OkHttpClient;
|
|
|
+import okhttp3.Request;
|
|
|
+import okhttp3.RequestBody;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* 定时任务调度测试
|
|
@@ -11,6 +31,10 @@ import com.ruoyi.common.utils.StringUtils;
|
|
|
@Component("ryTask")
|
|
|
public class RyTask
|
|
|
{
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ITMonitoringAlarmsService tMonitoringAlarmsService;
|
|
|
+
|
|
|
public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
|
|
|
{
|
|
|
System.out.println(StringUtils.format("执行多参方法: 字符串类型{},布尔类型{},长整型{},浮点型{},整形{}", s, b, l, d, i));
|
|
@@ -25,4 +49,47 @@ public class RyTask
|
|
|
{
|
|
|
System.out.println("执行无参方法");
|
|
|
}
|
|
|
+
|
|
|
+ public void queryAlarmList()
|
|
|
+ {
|
|
|
+ Map<String, Object> rsp = new HashMap<>();
|
|
|
+
|
|
|
+ rsp.put("appId", "26GgM5hQYPPOa6GW");
|
|
|
+ rsp.put("appSecret", "fa6370788e207c06a9dcbfb01b46ddff9c396124");
|
|
|
+
|
|
|
+ OkHttpClient okHttpClient = new OkHttpClient();
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(MonitoringAlarms.API_PREFIX_DEV + MonitoringAlarms.GET_ACCESS_TOKEN)
|
|
|
+ .method("post", RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), JsonUtil.toJson(rsp)))
|
|
|
+ .post(RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), JsonUtil.toJson(rsp)))
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ String rest = Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
|
|
|
+ JSONObject result = JSON.parseObject(rest);
|
|
|
+ if ("OK".equals(result.get("rmsg"))){
|
|
|
+ String data = result.getString("data");
|
|
|
+ JSONObject resultData = JSON.parseObject(data);
|
|
|
+ String token = resultData.get("access_token").toString();
|
|
|
+ String retStr = OpenApi.queryAlarmList(MonitoringAlarms.API_PREFIX_DEV, token, 1, 1000);
|
|
|
+ JSONObject restList = JSON.parseObject(retStr);
|
|
|
+ System.out.println(restList.get("rmsg"));
|
|
|
+ if ("OK".equals(restList.get("rmsg"))) {
|
|
|
+// String resatList = restList.get("data").toString();
|
|
|
+// JSONObject tMonitoringAlarmsList = JSON.parseObject(resatList);
|
|
|
+ List<TMonitoringAlarms> list = JSONArray.parseArray(restList.get("data").toString(), TMonitoringAlarms.class);
|
|
|
+ for (TMonitoringAlarms tMonitoringAlarms : list) {
|
|
|
+ TMonitoringAlarms alarms = tMonitoringAlarmsService.selectTMonitoringAlarmsById(tMonitoringAlarms.getId());
|
|
|
+ if (ObjectUtils.isNotNull(alarms)) {
|
|
|
+ tMonitoringAlarmsService.updateTMonitoringAlarms(tMonitoringAlarms);
|
|
|
+ } else {
|
|
|
+ tMonitoringAlarmsService.insertTMonitoringAlarms(tMonitoringAlarms);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ System.out.println("请求反馈异常," + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|