10 changed files with 464 additions and 0 deletions
@ -0,0 +1,24 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|||
<parent> |
|||
<artifactId>yudao</artifactId> |
|||
<groupId>cn.iocoder.boot</groupId> |
|||
<version>${revision}</version> <!-- 1. 修改 version 为 ${revision} --> |
|||
</parent> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
|
|||
<artifactId>yudao-module-alert</artifactId> |
|||
<packaging>pom</packaging> <!-- 2. 新增 packaging 为 pom --> |
|||
|
|||
<name>${project.artifactId}</name> <!-- 3. 新增 name 为 ${project.artifactId} --> |
|||
<description> <!-- 4. 新增 description 为该模块的描述 --> |
|||
alert模块,主要实现预警诊断功能。 |
|||
</description> |
|||
<modules> |
|||
<module>yudao-moudle-alert-api</module> |
|||
<module>yudao-module-alert-biz</module> |
|||
</modules> |
|||
|
|||
</project> |
@ -0,0 +1,64 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|||
<parent> |
|||
<artifactId>yudao-module-alert</artifactId> |
|||
<groupId>cn.iocoder.boot</groupId> |
|||
<version>${revision}</version> <!-- 1. 修改 version 为 ${revision} --> |
|||
</parent> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
<packaging>jar</packaging> <!-- 2. 新增 packaging 为 jar --> |
|||
|
|||
<artifactId>yudao-module-alert-biz</artifactId> |
|||
|
|||
<name>${project.artifactId}</name> <!-- 3. 新增 name 为 ${project.artifactId} --> |
|||
<description> <!-- 4. 新增 description 为该模块的描述 --> |
|||
alert 模块,主要实现 XXX、YYY、ZZZ 等功能。 |
|||
</description> |
|||
|
|||
<dependencies> <!-- 5. 新增依赖,这里引入的都是比较常用的业务组件、技术组件 --> |
|||
<dependency> |
|||
<groupId>cn.iocoder.boot</groupId> |
|||
<artifactId>yudao-module-alert-api</artifactId> |
|||
<version>${revision}</version> |
|||
</dependency> |
|||
|
|||
<!-- Web 相关 --> |
|||
<dependency> |
|||
<groupId>cn.iocoder.boot</groupId> |
|||
<artifactId>yudao-spring-boot-starter-web</artifactId> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>cn.iocoder.boot</groupId> |
|||
<artifactId>yudao-spring-boot-starter-security</artifactId> |
|||
</dependency> |
|||
|
|||
<dependency> |
|||
<groupId>org.apache.httpcomponents</groupId> |
|||
<artifactId>fluent-hc</artifactId> |
|||
<version>4.5.2</version> |
|||
</dependency> |
|||
|
|||
|
|||
|
|||
<dependency> |
|||
<groupId>com.google.code.gson</groupId> |
|||
<artifactId>gson</artifactId> |
|||
<version>2.8.9</version> |
|||
</dependency> |
|||
<!-- DB 相关 --> |
|||
<dependency> |
|||
<groupId>cn.iocoder.boot</groupId> |
|||
<artifactId>yudao-spring-boot-starter-mybatis</artifactId> |
|||
</dependency> |
|||
|
|||
<!-- Test 测试相关 --> |
|||
<!-- <dependency>--> |
|||
<!-- <groupId>cn.iocoder.boot</groupId>--> |
|||
<!-- <artifactId>yudao-spring-boot-starter-test</artifactId>--> |
|||
<!-- </dependency>--> |
|||
</dependencies> |
|||
|
|||
</project> |
@ -0,0 +1,54 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.exa; |
|||
|
|||
|
|||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
|||
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
|||
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.EXAHttp; |
|||
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.EXAPageReqVO; |
|||
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.EXAVO; |
|||
import cn.iocoder.yudao.module.alert.service.exa.EXAService; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.Parameter; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import jakarta.annotation.Resource; |
|||
import jakarta.validation.Valid; |
|||
import org.springframework.security.access.prepost.PreAuthorize; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.io.IOException; |
|||
import java.net.URISyntaxException; |
|||
import java.util.List; |
|||
|
|||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
|||
|
|||
@Tag(name = "预警诊断系统 - EXA测点管理") |
|||
@RestController |
|||
@RequestMapping("/alert/exa") |
|||
@Validated |
|||
public class EXAController { |
|||
|
|||
@Resource |
|||
private EXAService exaService; |
|||
|
|||
|
|||
@GetMapping("/page") |
|||
@Operation(summary = "获取测点分页列表") |
|||
@PreAuthorize("@ss.hasPermission('system:dept:query')") |
|||
public CommonResult<PageResult<EXAHttp>> getEXAList(EXAPageReqVO reqVO) throws IOException, URISyntaxException { |
|||
PageResult<EXAHttp> pageResult = exaService.getEXAPage(reqVO); |
|||
return success(BeanUtils.toBean(pageResult, EXAHttp.class)); |
|||
} |
|||
|
|||
@GetMapping("/now") |
|||
@Operation(summary = "获取带EXA测点实时值的列表") |
|||
@PreAuthorize("@ss.hasPermission('system:dept:query')") |
|||
public CommonResult<List<EXAHttp>> getNowData(List<EXAHttp> list) throws IOException, URISyntaxException { |
|||
List<EXAHttp> nowList=exaService.getEXAListNow(list); |
|||
return success(nowList); |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,29 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.exa.vo; |
|||
|
|||
import com.google.gson.annotations.Expose; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class EXAHttp { |
|||
|
|||
private String ItemName; |
|||
|
|||
private Long SerialNumber; |
|||
|
|||
private String GroupName; |
|||
private Integer ItemType; |
|||
|
|||
private String Descriptor; |
|||
@Expose(serialize = false,deserialize = false) |
|||
private String EngUnits; |
|||
private String Source; |
|||
private Boolean AutoSave; |
|||
private String UpperBound; |
|||
private String LowerBound; |
|||
private String UpperLimit; |
|||
private String LowerLimit; |
|||
private String UpperUpperLimit; |
|||
private String LowerLowerLimit; |
|||
private String Value; |
|||
} |
@ -0,0 +1,14 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.exa.vo; |
|||
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageParam; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
@Schema(description = "预警诊断系统 - EXA测点分页 Request VO") |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
public class EXAPageReqVO extends PageParam { |
|||
@Schema(description = "测点名称或描述,模糊匹配", example = "芋道") |
|||
private String condition; |
|||
} |
@ -0,0 +1,34 @@ |
|||
package cn.iocoder.yudao.module.alert.controller.admin.exa.vo; |
|||
|
|||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
|||
import cn.iocoder.yudao.framework.common.validation.InEnum; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import jakarta.validation.constraints.Email; |
|||
import jakarta.validation.constraints.NotBlank; |
|||
import jakarta.validation.constraints.NotNull; |
|||
import jakarta.validation.constraints.Size; |
|||
|
|||
public class EXAVO { |
|||
@Schema(description = "编号", example = "1024") |
|||
private Long id; |
|||
|
|||
@Schema(description = "测点编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") |
|||
@NotBlank(message = "测点编码不能为空") |
|||
@Size(max = 30, message = "测点编码长度不能超过 30 个字符") |
|||
private String ItemName; |
|||
|
|||
@Schema(description = "测点名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") |
|||
@NotBlank(message = "测点名称不能为空") |
|||
@Size(max = 30, message = "测点名称长度不能超过 30 个字符") |
|||
private String Descriptor; |
|||
|
|||
@Schema(description = "实时值", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") |
|||
@NotBlank(message = "实时值不能为空") |
|||
private Double Value; |
|||
|
|||
@Schema(description = "单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道") |
|||
@NotBlank(message = "单位不能为空") |
|||
@Size(max = 10, message = "单位长度不能超过 10 个字符") |
|||
private String EngUnits; |
|||
|
|||
} |
@ -0,0 +1,28 @@ |
|||
package cn.iocoder.yudao.module.alert.service.exa; |
|||
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
|||
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.EXAHttp; |
|||
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.EXAPageReqVO; |
|||
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.EXAVO; |
|||
|
|||
import java.io.IOException; |
|||
import java.net.URISyntaxException; |
|||
import java.util.*; |
|||
|
|||
public interface EXAService { |
|||
/** |
|||
* 筛选部门列表 |
|||
* |
|||
* @param reqVO 筛选条件请求 VO |
|||
* @return 部门列表 |
|||
*/ |
|||
// List<EXAVO> getEXAList(EXAVO reqVO);
|
|||
|
|||
PageResult<EXAHttp> getEXAPage(EXAPageReqVO reqVO) throws IOException, URISyntaxException; |
|||
|
|||
|
|||
List<EXAHttp> getEXAListNow(List<EXAHttp> list) throws URISyntaxException, IOException; |
|||
|
|||
|
|||
} |
@ -0,0 +1,64 @@ |
|||
package cn.iocoder.yudao.module.alert.service.exa; |
|||
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|||
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.EXAHttp; |
|||
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.EXAPageReqVO; |
|||
|
|||
import cn.iocoder.yudao.module.alert.utils.EXAUtils; |
|||
import com.google.gson.Gson; |
|||
import com.google.gson.GsonBuilder; |
|||
import com.google.gson.reflect.TypeToken; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
|
|||
import org.apache.http.HttpEntity; |
|||
import org.apache.http.client.methods.CloseableHttpResponse; |
|||
import org.apache.http.client.methods.HttpGet; |
|||
import org.apache.http.client.utils.URIBuilder; |
|||
import org.apache.http.impl.client.CloseableHttpClient; |
|||
import org.apache.http.impl.client.HttpClients; |
|||
import org.apache.http.util.EntityUtils; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.validation.annotation.Validated; |
|||
|
|||
import java.io.IOException; |
|||
import java.lang.reflect.Type; |
|||
import java.net.URISyntaxException; |
|||
import java.util.*; |
|||
|
|||
import static cn.iocoder.yudao.module.alert.utils.PageUtils.getPartList; |
|||
|
|||
@Service |
|||
@Validated |
|||
@Slf4j |
|||
public class EXAServiceImpl implements EXAService { |
|||
|
|||
EXAUtils exaUtils = new EXAUtils(); |
|||
|
|||
@Override |
|||
public PageResult<EXAHttp> getEXAPage(EXAPageReqVO reqVO) throws IOException, URISyntaxException { |
|||
List<EXAHttp> exaListAll = exaUtils.getPointInfo(reqVO); |
|||
Long total = Long.valueOf(exaListAll.size()); |
|||
|
|||
List<EXAHttp> exaList = getPartList(exaListAll, reqVO.getPageNo(), reqVO.getPageSize()); |
|||
|
|||
PageResult<EXAHttp> result = new PageResult<>(getEXAListNow(exaList), total); |
|||
return result; |
|||
} |
|||
|
|||
@Override |
|||
public List<EXAHttp> getEXAListNow(List<EXAHttp> list) throws URISyntaxException, IOException { |
|||
|
|||
list.forEach(entity -> { |
|||
try { |
|||
entity.setValue(exaUtils.getNowData(entity.getItemName()).get(0)); |
|||
} catch (URISyntaxException e) { |
|||
throw new RuntimeException(e); |
|||
} catch (IOException e) { |
|||
throw new RuntimeException(e); |
|||
} |
|||
}); |
|||
|
|||
return list; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,131 @@ |
|||
package cn.iocoder.yudao.module.alert.utils; |
|||
|
|||
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
|||
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.EXAHttp; |
|||
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.EXAPageReqVO; |
|||
import com.google.gson.Gson; |
|||
import com.google.gson.GsonBuilder; |
|||
import com.google.gson.reflect.TypeToken; |
|||
import org.apache.http.HttpEntity; |
|||
import org.apache.http.client.methods.CloseableHttpResponse; |
|||
import org.apache.http.client.methods.HttpGet; |
|||
import org.apache.http.client.utils.URIBuilder; |
|||
import org.apache.http.impl.client.CloseableHttpClient; |
|||
import org.apache.http.impl.client.HttpClients; |
|||
import org.apache.http.util.EntityUtils; |
|||
|
|||
import java.io.IOException; |
|||
import java.lang.reflect.Type; |
|||
import java.net.URISyntaxException; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
import static cn.iocoder.yudao.module.alert.utils.PageUtils.getPartList; |
|||
|
|||
public class EXAUtils { |
|||
/** |
|||
* 根据分页条件和测点名称测点描述模糊查询 |
|||
* |
|||
* @param reqVO 传入对象,页数、页数量、查询条件 |
|||
* |
|||
* @return exa列表 |
|||
*/ |
|||
public List<EXAHttp> getPointInfo(EXAPageReqVO reqVO) throws URISyntaxException, IOException { |
|||
// PageResult<EXAHttp> result = new PageResult<>();
|
|||
List<EXAHttp> exaListAll = new ArrayList<EXAHttp>(); |
|||
try { |
|||
// 目标 RPC 服务的 URL
|
|||
String url = "http://47.98.32.148:9000/exawebapi/exaitem/getitems"; |
|||
//创建HttpClient对象
|
|||
CloseableHttpClient httpClient = HttpClients.createDefault(); |
|||
/* |
|||
* 由于GET请求的参数都是拼装在URL地址后方,所以我们要构建一个URL,带参数 |
|||
*/ |
|||
URIBuilder uriBuilder = new URIBuilder(url); |
|||
|
|||
/** 添加参数 */ |
|||
uriBuilder.addParameter("WhereClause", "ItemName like '%" + reqVO.getCondition() + "%' or Descriptor like '%" + reqVO.getCondition() + "%'"); |
|||
|
|||
//创建请求对象
|
|||
HttpGet httpGet = new HttpGet(uriBuilder.build()); |
|||
// 传输的类型
|
|||
httpGet.addHeader("Content-Type", "application/json;charset=utf-8"); |
|||
//发送请求,请求响应结果
|
|||
CloseableHttpResponse response = httpClient.execute(httpGet); |
|||
//获取服务器返回的状态码
|
|||
int statusCode = response.getStatusLine().getStatusCode(); |
|||
System.out.println("服务端返回成功的状态码为:" + statusCode); |
|||
HttpEntity entity = response.getEntity(); |
|||
String body = EntityUtils.toString(entity).replaceAll("\\\\", ""); |
|||
System.out.println("服务端返回的数据为:" + body); |
|||
// 步骤1:检查字符串是否为空
|
|||
// if (body == null || body.isEmpty()) {
|
|||
// return body; // 如果字符串为空或为null,直接返回
|
|||
// }
|
|||
// 步骤2:检查首尾是否是双引号
|
|||
if (body.startsWith("\"") && body.endsWith("\"")) { |
|||
// 步骤3:去掉双引号
|
|||
body = body.substring(1, body.length() - 1); // 去掉首尾的双引号
|
|||
} |
|||
|
|||
Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create(); |
|||
Type listType = new TypeToken<List<EXAHttp>>() { |
|||
}.getType(); |
|||
exaListAll = gson.fromJson(body, listType); |
|||
|
|||
|
|||
//关闭资源
|
|||
response.close(); |
|||
httpClient.close(); |
|||
} catch (Exception e) { |
|||
|
|||
} |
|||
return exaListAll; |
|||
} |
|||
|
|||
public List<String> getNowData(String itemNames) throws URISyntaxException, IOException { |
|||
List<String> result = new ArrayList<>(); |
|||
try { |
|||
// 目标 RPC 服务的 URL
|
|||
String url = "http://47.98.32.148:9000/exawebapi/exanow/getfloatvaluebatch"; |
|||
//创建HttpClient对象
|
|||
CloseableHttpClient httpClient = HttpClients.createDefault(); |
|||
/* |
|||
* 由于GET请求的参数都是拼装在URL地址后方,所以我们要构建一个URL,带参数 |
|||
*/ |
|||
URIBuilder uriBuilder = new URIBuilder(url); |
|||
|
|||
/** 添加参数 */ |
|||
uriBuilder.addParameter("ItemNames", itemNames); |
|||
|
|||
//创建请求对象
|
|||
HttpGet httpGet = new HttpGet(uriBuilder.build()); |
|||
|
|||
// 传输的类型
|
|||
httpGet.addHeader("Content-Type", "application/json"); |
|||
//发送请求,请求响应结果
|
|||
CloseableHttpResponse response = httpClient.execute(httpGet); |
|||
//获取服务器返回的状态码
|
|||
int statusCode = response.getStatusLine().getStatusCode(); |
|||
System.out.println("服务端返回成功的状态码为:" + statusCode); |
|||
HttpEntity entity = response.getEntity(); |
|||
String body = EntityUtils.toString(entity).replaceAll("\\\\", ""); |
|||
System.out.println("服务端返回的数据为:" + body); |
|||
|
|||
|
|||
Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create(); |
|||
Type listType = new TypeToken<List<String>>() { |
|||
}.getType(); |
|||
result = gson.fromJson(body, listType); |
|||
|
|||
//关闭资源
|
|||
response.close(); |
|||
httpClient.close(); |
|||
} catch (Exception e) { |
|||
|
|||
} |
|||
return result; |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,22 @@ |
|||
package cn.iocoder.yudao.module.alert.utils; |
|||
|
|||
import java.util.List; |
|||
|
|||
public class PageUtils { |
|||
/** |
|||
* 按分页方式截取inLs的一部分 |
|||
* |
|||
* @param inLs 传入列表 |
|||
* @param page 页码 |
|||
* @param limit 页容量 |
|||
* @param <T> 元素类型 |
|||
* @return 指定页的元素列表 |
|||
*/ |
|||
public static <T> List<T> getPartList(List<T> inLs, int page, int limit) { |
|||
page = (page <= 0) ? 1 : page; |
|||
limit = (limit <= 0) ? 10 : limit; |
|||
int total = inLs.size(); |
|||
|
|||
return inLs.subList(Math.min((page - 1) * limit, total), Math.min(page * limit, total)); |
|||
} |
|||
} |
Loading…
Reference in new issue