10 changed files with 178 additions and 8 deletions
@ -0,0 +1,64 @@ |
|||||||
|
package com.mh.user.dto; |
||||||
|
|
||||||
|
import java.util.StringJoiner; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project mh_esi |
||||||
|
* @description 推送给王工AI数据 |
||||||
|
* @date 2026-04-02 09:38:05 |
||||||
|
*/ |
||||||
|
public class PushAiDTO { |
||||||
|
|
||||||
|
private String curDate; |
||||||
|
|
||||||
|
private Double cl; |
||||||
|
|
||||||
|
private String projectId; |
||||||
|
|
||||||
|
private String projectName; |
||||||
|
|
||||||
|
public String getCurDate() { |
||||||
|
return curDate; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCurDate(String curDate) { |
||||||
|
this.curDate = curDate; |
||||||
|
} |
||||||
|
|
||||||
|
public Double getCl() { |
||||||
|
return cl; |
||||||
|
} |
||||||
|
|
||||||
|
public void setCl(Double cl) { |
||||||
|
this.cl = cl; |
||||||
|
} |
||||||
|
|
||||||
|
public String getProjectId() { |
||||||
|
return projectId; |
||||||
|
} |
||||||
|
|
||||||
|
public void setProjectId(String projectId) { |
||||||
|
this.projectId = projectId; |
||||||
|
} |
||||||
|
|
||||||
|
public String getProjectName() { |
||||||
|
return projectName; |
||||||
|
} |
||||||
|
|
||||||
|
public void setProjectName(String projectName) { |
||||||
|
this.projectName = projectName; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return new StringJoiner(", ", PushAiDTO.class.getSimpleName() + "[", "]") |
||||||
|
.add("curDate='" + curDate + "'") |
||||||
|
.add("cl=" + cl) |
||||||
|
.add("projectId='" + projectId + "'") |
||||||
|
.add("projectName='" + projectName + "'") |
||||||
|
.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,65 @@ |
|||||||
|
package com.mh.user.job; |
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil; |
||||||
|
import com.mh.user.dto.PushAiDTO; |
||||||
|
import com.mh.user.service.EnergyDataService; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.apache.commons.lang3.time.DateUtils; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.http.HttpEntity; |
||||||
|
import org.springframework.http.HttpHeaders; |
||||||
|
import org.springframework.http.MediaType; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.scheduling.annotation.Scheduled; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
import org.springframework.web.client.RestClientException; |
||||||
|
import org.springframework.web.client.RestTemplate; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author LJF |
||||||
|
* @version 1.0 |
||||||
|
* @project mh_esi |
||||||
|
* @description 推送数据给王工AI进行数据分析 |
||||||
|
* @date 2026-04-02 08:54:43 |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@Component |
||||||
|
public class PushDataToAIJob { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private EnergyDataService energyDataService; |
||||||
|
|
||||||
|
// @Scheduled(cron = " 0 10 0/1 * * ? ")
|
||||||
|
public void pushDataToAIJob(){ |
||||||
|
log.info("推送数据给王工 AI 进行数据分析"); |
||||||
|
// 获取最近时间一个小时数据
|
||||||
|
// 获取前两小时前的时间
|
||||||
|
Date date = new Date(); |
||||||
|
Date date1 = DateUtils.addHours(date, -3); |
||||||
|
String dateStr = DateUtil.format(date1, "yyyy-MM-dd HH"); |
||||||
|
List<PushAiDTO> list = energyDataService.queryPushAI(dateStr,"14"); |
||||||
|
// http 方式请求接口发送
|
||||||
|
String url = "http://192.168.1.222:8766/AIDataPush"; |
||||||
|
RestTemplate restTemplate = new RestTemplate(); |
||||||
|
HttpHeaders headers = new HttpHeaders(); |
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON); |
||||||
|
postData(url, restTemplate, headers, list); |
||||||
|
List<PushAiDTO> list2 = energyDataService.queryPushAI(dateStr,"15"); |
||||||
|
postData(url, restTemplate, headers, list2); |
||||||
|
} |
||||||
|
|
||||||
|
private void postData(String url, RestTemplate restTemplate, HttpHeaders headers, List<PushAiDTO> list2) { |
||||||
|
HttpEntity<List<PushAiDTO>> request2 = new HttpEntity<>(list2, headers); |
||||||
|
ResponseEntity<String> response2 = null; |
||||||
|
try { |
||||||
|
response2 = restTemplate.postForEntity(url, request2, String.class); |
||||||
|
} catch (RestClientException e) { |
||||||
|
log.info("推送结果:{}", e.getMessage()); |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
log.info("推送结果:{}", response2.getBody()); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue