添加能耗采集定时任务

This commit is contained in:
chy
2026-03-13 09:58:32 +08:00
parent fde5cfe3b2
commit 21fe5196be
6 changed files with 358 additions and 4 deletions

View File

@@ -17,8 +17,6 @@ import org.springframework.stereotype.Component;
@Component("SaSetdtlSyncJob")
public class SaSetdtlSyncJob implements JobHandler {
@Autowired
private ILideeYunJiService lideeYunJiService;
@Autowired
private IGrBiSaSetdtlService grBiSaSetdtlService;

View File

@@ -0,0 +1,136 @@
package com.lideeyunji.core.framework.config.job;
import cn.hutool.json.JSONObject;
import com.lideeyunji.core.framework.service.ILideeYunJiService;
import com.lideeyunji.tool.framework.common.util.http.HttpUtils;
import com.lideeyunji.tool.framework.quartz.core.handler.JobHandler;
import com.lideeyunji.tool.framework.tenant.core.aop.TenantIgnore;
import com.lideeyunji.tool.framework.yunji.component.redis.lideeYunjiRedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.ehcache.xml.model.CacheTemplate;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.sql.*;
import java.util.HashMap;
import java.util.Map;
/**
* 保存模块使用记录 能耗模块使用记录
*/
@Slf4j
@Component("anyToGrBiNh")
public class anyToGrBiNh implements JobHandler {
@Autowired
private lideeYunjiRedisUtils redisUtil;
@Autowired
private ILideeYunJiService lideeYunJiService;
@Override
@TenantIgnore
public String execute(String param) {
log.info("*********** 同步能耗数据 ************");
getToken();
String resultStr = "*********** 同步能耗数据保存成功 ************";
log.info(resultStr);
return resultStr;
}
private void getToken() {
try {
String nhtoken = redisUtil.get("nh_token", String.class);
System.out.println(nhtoken);
if(nhtoken==null){
// 2. POST 表单请求
Map<String, String> params = new HashMap<>();
params.put("fLoginname", "9287ee99ae49b47dc7ce1746eac04f8b");
params.put("fPassword", "d23d0731bcf61d824aa30372da5fae0b");
params.put("loginType", "password");
params.put("projectType", "4");
String postResult = HttpUtils.doPost("http://111.39.171.64:8090/SubstationWEBV2/user/login", params, null);
JSONObject jsonObject = new JSONObject(postResult);
jsonObject= new JSONObject(jsonObject.get("data").toString());
redisUtil.set("nh_token",jsonObject.get("token"),(Long)jsonObject.get("tokenExpireTime"));
System.out.println(jsonObject.get("token"));
getNhsj(jsonObject.get("token").toString());
}
else {
nhtoken = redisUtil.get("nh_token").toString();
getNhsj(nhtoken);
}
} catch (IOException e) {
e.printStackTrace();
}
}
private void getNhsj(String token){
try {
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", token);
String getResult = HttpUtils.doGet("http://111.39.171.64:8090/SubstationWEBV2/main/Compare/overview?fCoaccountno=1", headers);
System.out.println("GET Response:\n" + getResult);
// 3. POST JSON 请求
// String jsonBody = "{\"name\":\"Alice\",\"age\":25}";
// Map<String, String> headers = new HashMap<>();
// headers.put("Authorization", "Bearer your_token_here");
// String jsonResult = HttpUtils.doPostJson("https://api.example.com/user", jsonBody, headers);
// System.out.println("POST JSON Response:\n" + jsonResult);
} catch (IOException e) {
e.printStackTrace();
}
}
public void main(String[] args) {
getToken();
// 2. POST 表单请求
// Map<String, String> params = new HashMap<>();
// params.put("fLoginname", "2613504b593d16343ccf368879f9519c");
// params.put("fPassword", "c7d967eaeaa0963fe33c740b46316590");
// params.put("loginType", "password");
// params.put("projectType", "4");
// String postResult = HttpUtils.doPost("http://111.39.171.64:8090/SubstationWEBV2/user/login", params, null);
// System.out.println("POST Form Response:\n" + postResult);
// JSONObject jsonObject = new JSONObject(postResult);
// jsonObject= new JSONObject(jsonObject.get("data").toString());
//System.out.println(jsonObject.get("token"));
// 1. GET 请求
// String getResult = HttpUtils.doGet("https://api.example.com/data", null);
// System.out.println("GET Response:\n" + getResult);
// 3. POST JSON 请求
// String jsonBody = "{\"name\":\"Alice\",\"age\":25}";
// Map<String, String> headers = new HashMap<>();
// headers.put("Authorization", "Bearer your_token_here");
// String jsonResult = HttpUtils.doPostJson("https://api.example.com/user", jsonBody, headers);
// System.out.println("POST JSON Response:\n" + jsonResult);
}
}

View File

@@ -278,6 +278,9 @@ public class Func extends FuncBase {
return fieldValObj;
}
/*
* http post请求
* */
public static String sendPost(String url, Object body) throws Exception {
String accept = HttpRequest.post(url)
.body(Func.json2Str(body))