添加获取邮箱邮件数据
This commit is contained in:
parent
a1935a6284
commit
8560c50162
|
|
@ -14,4 +14,6 @@ public class HttpClientHostProperties {
|
|||
*/
|
||||
private String oceanHost;
|
||||
|
||||
private String armdHost;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,410 @@
|
|||
package org.jeecg.sysEmail.controller;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.client.utils.URIBuilder;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.properties.HttpClientHostProperties;
|
||||
import org.jeecg.sysEmail.entity.SysEmail;
|
||||
import org.jeecg.utils.HttpClientUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLEncoder;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/sysEmail")
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class SysEmailController {
|
||||
|
||||
private final HttpClientHostProperties hostProperties;
|
||||
|
||||
|
||||
@Operation(summary = "获取邮箱列表")
|
||||
@GetMapping("/getEmailList")
|
||||
public Result<List<SysEmail>> getEmailList() throws IOException {
|
||||
String url = hostProperties.getArmdHost();
|
||||
String apiUrl = url + "sysEmail/sourceList";
|
||||
Map<String, String> getHeaders = Map.of("Authorization", "");
|
||||
|
||||
String apiResult= HttpClientUtil.doGet(apiUrl, getHeaders, true); // 启用 SSL
|
||||
//region
|
||||
String getResult = "{\n" +
|
||||
" \"success\": true,\n" +
|
||||
" \"message\": \"\",\n" +
|
||||
" \"code\": 200,\n" +
|
||||
" \"result\": [\n" +
|
||||
" {\n" +
|
||||
" \"sourceId\": \"1002\",\n" +
|
||||
" \"sourceName\": \"15210169137\",\n" +
|
||||
" \"hostId\": null,\n" +
|
||||
" \"cpuUsedItemId\": null,\n" +
|
||||
" \"enabled\": 1\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"sourceId\": \"1001\",\n" +
|
||||
" \"sourceName\": \"15210169137@139.com\",\n" +
|
||||
" \"hostId\": null,\n" +
|
||||
" \"cpuUsedItemId\": null,\n" +
|
||||
" \"enabled\": 1\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"sourceId\": \"1999017699534446594\",\n" +
|
||||
" \"sourceName\": \"test0002\",\n" +
|
||||
" \"hostId\": null,\n" +
|
||||
" \"cpuUsedItemId\": null,\n" +
|
||||
" \"enabled\": 1\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"timestamp\": 1765456465367\n" +
|
||||
"}";
|
||||
//endregion
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Result<List<SysEmail>> result = objectMapper.readValue(getResult, new TypeReference<>() {
|
||||
});
|
||||
if (result.getCode() == 200) {
|
||||
return result;
|
||||
} else {
|
||||
return Result.error("API 请求失败, 错误码: " + result.getCode() + ", 消息: " + result.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("获取邮箱服务器列表失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最近的邮箱数据信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取昨天和今天的邮件信息")
|
||||
@GetMapping("/getRecentAlarms")
|
||||
public Result<Map<String, Object>> getRecentAlarms() throws IOException {
|
||||
String url = hostProperties.getArmdHost();
|
||||
String apiUrl = url + "sysEmailLog/getRecentAlarms";
|
||||
Map<String, String> getHeaders = Map.of("Authorization", "");
|
||||
String apiResult= HttpClientUtil.doGet(apiUrl, getHeaders, true); // 启用 SSL
|
||||
//region
|
||||
String toDayResult = " {\n" +
|
||||
" \"success\": true,\n" +
|
||||
" \"message\": \"\",\n" +
|
||||
" \"code\": 200,\n" +
|
||||
" \"result\": {\n" +
|
||||
" \"categories\": [\n" +
|
||||
" \"00:00\",\n" +
|
||||
" \"01:00\",\n" +
|
||||
" \"02:00\",\n" +
|
||||
" \"03:00\",\n" +
|
||||
" \"04:00\",\n" +
|
||||
" \"05:00\",\n" +
|
||||
" \"06:00\",\n" +
|
||||
" \"07:00\",\n" +
|
||||
" \"08:00\",\n" +
|
||||
" \"09:00\",\n" +
|
||||
" \"10:00\",\n" +
|
||||
" \"11:00\",\n" +
|
||||
" \"12:00\",\n" +
|
||||
" \"13:00\",\n" +
|
||||
" \"14:00\",\n" +
|
||||
" \"15:00\",\n" +
|
||||
" \"16:00\",\n" +
|
||||
" \"17:00\",\n" +
|
||||
" \"18:00\",\n" +
|
||||
" \"19:00\",\n" +
|
||||
" \"20:00\",\n" +
|
||||
" \"21:00\",\n" +
|
||||
" \"22:00\",\n" +
|
||||
" \"23:00\"\n" +
|
||||
" ],\n" +
|
||||
" \"series\": {\n" +
|
||||
" \"todayAlarm\": [\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0\n" +
|
||||
" ],\n" +
|
||||
" \"todayProcess\": [\n" +
|
||||
" 54,\n" +
|
||||
" 41,\n" +
|
||||
" 46,\n" +
|
||||
" 40,\n" +
|
||||
" 48,\n" +
|
||||
" 48,\n" +
|
||||
" 66,\n" +
|
||||
" 49,\n" +
|
||||
" 47,\n" +
|
||||
" 44,\n" +
|
||||
" 47,\n" +
|
||||
" 39,\n" +
|
||||
" 50,\n" +
|
||||
" 43,\n" +
|
||||
" 45,\n" +
|
||||
" 40,\n" +
|
||||
" 21,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0\n" +
|
||||
" ],\n" +
|
||||
" \"yesterdayAlarm\": [\n" +
|
||||
" 3,\n" +
|
||||
" 4,\n" +
|
||||
" 4,\n" +
|
||||
" 4,\n" +
|
||||
" 4,\n" +
|
||||
" 3,\n" +
|
||||
" 4,\n" +
|
||||
" 4,\n" +
|
||||
" 4,\n" +
|
||||
" 3,\n" +
|
||||
" 4,\n" +
|
||||
" 4,\n" +
|
||||
" 4,\n" +
|
||||
" 3,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0\n" +
|
||||
" ],\n" +
|
||||
" \"yesterdayProcess\": [\n" +
|
||||
" 49,\n" +
|
||||
" 52,\n" +
|
||||
" 52,\n" +
|
||||
" 56,\n" +
|
||||
" 58,\n" +
|
||||
" 50,\n" +
|
||||
" 80,\n" +
|
||||
" 38,\n" +
|
||||
" 69,\n" +
|
||||
" 39,\n" +
|
||||
" 66,\n" +
|
||||
" 31,\n" +
|
||||
" 50,\n" +
|
||||
" 60,\n" +
|
||||
" 51,\n" +
|
||||
" 37,\n" +
|
||||
" 60,\n" +
|
||||
" 40,\n" +
|
||||
" 55,\n" +
|
||||
" 41,\n" +
|
||||
" 50,\n" +
|
||||
" 42,\n" +
|
||||
" 52,\n" +
|
||||
" 34\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"timestamp\": 1765528894649\n" +
|
||||
"}";
|
||||
|
||||
|
||||
//endregion
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Result<Map<String, Object>> result = objectMapper.readValue(toDayResult, new TypeReference<>() {
|
||||
});
|
||||
if (result.getCode() == 200) {
|
||||
return result;
|
||||
} else {
|
||||
return Result.error("API 请求失败, 错误码: " + result.getCode() + ", 消息: " + result.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("获取邮箱服务器列表失败: " + e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/getMonthly")
|
||||
@Operation(summary = "获取一月的邮件信息")
|
||||
public Result<Map<String, Object>> getMonthly(@RequestParam("emailId") String emailId,
|
||||
@RequestParam("startDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
|
||||
@RequestParam("endDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) throws URISyntaxException, IOException {
|
||||
String url = hostProperties.getArmdHost();
|
||||
String apiUrl = url + "sysEmailLog/getYesterdayAndToday";
|
||||
Map<String, String> getHeaders = Map.of("Authorization", "");
|
||||
|
||||
String fullUrl = apiUrl + "?emailId=" + URLEncoder.encode(emailId, "UTF-8")
|
||||
+ "&startDate=" + startDate.toString() // LocalDate的toString()默认就是yyyy-MM-dd格式
|
||||
+ "&endDate=" + endDate.toString();
|
||||
String apiResult = HttpClientUtil.doGet(fullUrl, getHeaders, true);
|
||||
//region
|
||||
String DataResult = " {\n" +
|
||||
" \"success\": true,\n" +
|
||||
" \"message\": \"\",\n" +
|
||||
" \"code\": 200,\n" +
|
||||
" \"result\": {\n" +
|
||||
" \"categories\": [\n" +
|
||||
" \"11-12\",\n" +
|
||||
" \"11-13\",\n" +
|
||||
" \"11-14\",\n" +
|
||||
" \"11-15\",\n" +
|
||||
" \"11-16\",\n" +
|
||||
" \"11-17\",\n" +
|
||||
" \"11-18\",\n" +
|
||||
" \"11-19\",\n" +
|
||||
" \"11-20\",\n" +
|
||||
" \"11-21\",\n" +
|
||||
" \"11-22\",\n" +
|
||||
" \"11-23\",\n" +
|
||||
" \"11-24\",\n" +
|
||||
" \"11-25\",\n" +
|
||||
" \"11-26\",\n" +
|
||||
" \"11-27\",\n" +
|
||||
" \"11-28\",\n" +
|
||||
" \"11-29\",\n" +
|
||||
" \"11-30\",\n" +
|
||||
" \"12-01\",\n" +
|
||||
" \"12-02\",\n" +
|
||||
" \"12-03\",\n" +
|
||||
" \"12-04\",\n" +
|
||||
" \"12-05\",\n" +
|
||||
" \"12-06\",\n" +
|
||||
" \"12-07\",\n" +
|
||||
" \"12-08\",\n" +
|
||||
" \"12-09\",\n" +
|
||||
" \"12-10\",\n" +
|
||||
" \"12-11\",\n" +
|
||||
" \"12-12\"\n" +
|
||||
" ],\n" +
|
||||
" \"series\": {\n" +
|
||||
" \"alarm\": [\n" +
|
||||
" 52,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 0,\n" +
|
||||
" 1,\n" +
|
||||
" 32,\n" +
|
||||
" 52,\n" +
|
||||
" 0\n" +
|
||||
" ],\n" +
|
||||
" \"process\": [\n" +
|
||||
" 2900,\n" +
|
||||
" 1673,\n" +
|
||||
" 1060,\n" +
|
||||
" 2030,\n" +
|
||||
" 2364,\n" +
|
||||
" 2060,\n" +
|
||||
" 2325,\n" +
|
||||
" 1438,\n" +
|
||||
" 1116,\n" +
|
||||
" 1138,\n" +
|
||||
" 1173,\n" +
|
||||
" 1134,\n" +
|
||||
" 1123,\n" +
|
||||
" 1158,\n" +
|
||||
" 1097,\n" +
|
||||
" 1102,\n" +
|
||||
" 1203,\n" +
|
||||
" 1124,\n" +
|
||||
" 1137,\n" +
|
||||
" 1201,\n" +
|
||||
" 1125,\n" +
|
||||
" 1138,\n" +
|
||||
" 1200,\n" +
|
||||
" 1275,\n" +
|
||||
" 1133,\n" +
|
||||
" 1255,\n" +
|
||||
" 1288,\n" +
|
||||
" 1083,\n" +
|
||||
" 1167,\n" +
|
||||
" 1212,\n" +
|
||||
" 768\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
" },\n" +
|
||||
" \"timestamp\": 1765531641598\n" +
|
||||
"}";//HttpClientUtil.doGet(getUrl, getHeaders, true); // 启用 SSL
|
||||
|
||||
|
||||
//endregion
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Result<Map<String, Object>> result = objectMapper.readValue(DataResult, new TypeReference<>() {
|
||||
});
|
||||
|
||||
if (result.getCode() == 200) {
|
||||
return result;
|
||||
} else {
|
||||
return Result.error("API 请求失败, 错误码: " + result.getCode() + ", 消息: " + result.getMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("获取邮箱服务器列表失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package org.jeecg.sysEmail.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SysEmail implements Serializable {
|
||||
private String sourceId;
|
||||
|
||||
private String sourceName;
|
||||
|
||||
private String hostId;
|
||||
|
||||
private String cpuUsedItemId;
|
||||
|
||||
/**
|
||||
* 是否启用邮箱(0-不启用,1-启用)
|
||||
*/
|
||||
private Integer enabled;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user