From 7462319ff70be7b9b09e4bba29c86dcdda0c714f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=82=96=E6=99=8B=E9=A3=9E?= <378266566@qq.com> Date: Fri, 25 Apr 2025 15:22:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A2=84=E8=AD=A6=E8=AF=8A=E6=96=AD?= =?UTF-8?q?=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-module-alert/pom.xml | 24 ++++ .../yudao-module-alert-biz/pom.xml | 64 +++++++++ .../controller/admin/exa/EXAController.java | 54 ++++++++ .../controller/admin/exa/vo/EXAHttp.java | 29 ++++ .../controller/admin/exa/vo/EXAPageReqVO.java | 14 ++ .../alert/controller/admin/exa/vo/EXAVO.java | 34 +++++ .../module/alert/service/exa/EXAService.java | 28 ++++ .../alert/service/exa/EXAServiceImpl.java | 64 +++++++++ .../yudao/module/alert/utils/EXAUtils.java | 131 ++++++++++++++++++ .../yudao/module/alert/utils/PageUtils.java | 22 +++ 10 files changed, 464 insertions(+) create mode 100644 yudao-module-alert/pom.xml create mode 100644 yudao-module-alert/yudao-module-alert-biz/pom.xml create mode 100644 yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/EXAController.java create mode 100644 yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/EXAHttp.java create mode 100644 yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/EXAPageReqVO.java create mode 100644 yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/EXAVO.java create mode 100644 yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/exa/EXAService.java create mode 100644 yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/exa/EXAServiceImpl.java create mode 100644 yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/utils/EXAUtils.java create mode 100644 yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/utils/PageUtils.java diff --git a/yudao-module-alert/pom.xml b/yudao-module-alert/pom.xml new file mode 100644 index 0000000..6e35894 --- /dev/null +++ b/yudao-module-alert/pom.xml @@ -0,0 +1,24 @@ + + + + yudao + cn.iocoder.boot + ${revision} + + 4.0.0 + + yudao-module-alert + pom + + ${project.artifactId} + + alert模块,主要实现预警诊断功能。 + + + yudao-moudle-alert-api + yudao-module-alert-biz + + + diff --git a/yudao-module-alert/yudao-module-alert-biz/pom.xml b/yudao-module-alert/yudao-module-alert-biz/pom.xml new file mode 100644 index 0000000..ebed9cf --- /dev/null +++ b/yudao-module-alert/yudao-module-alert-biz/pom.xml @@ -0,0 +1,64 @@ + + + + yudao-module-alert + cn.iocoder.boot + ${revision} + + 4.0.0 + jar + + yudao-module-alert-biz + + ${project.artifactId} + + alert 模块,主要实现 XXX、YYY、ZZZ 等功能。 + + + + + cn.iocoder.boot + yudao-module-alert-api + ${revision} + + + + + cn.iocoder.boot + yudao-spring-boot-starter-web + + + + cn.iocoder.boot + yudao-spring-boot-starter-security + + + + org.apache.httpcomponents + fluent-hc + 4.5.2 + + + + + + com.google.code.gson + gson + 2.8.9 + + + + cn.iocoder.boot + yudao-spring-boot-starter-mybatis + + + + + + + + + + diff --git a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/EXAController.java b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/EXAController.java new file mode 100644 index 0000000..4cc0147 --- /dev/null +++ b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/EXAController.java @@ -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> getEXAList(EXAPageReqVO reqVO) throws IOException, URISyntaxException { + PageResult pageResult = exaService.getEXAPage(reqVO); + return success(BeanUtils.toBean(pageResult, EXAHttp.class)); + } + + @GetMapping("/now") + @Operation(summary = "获取带EXA测点实时值的列表") + @PreAuthorize("@ss.hasPermission('system:dept:query')") + public CommonResult> getNowData(List list) throws IOException, URISyntaxException { + List nowList=exaService.getEXAListNow(list); + return success(nowList); + } + + +} diff --git a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/EXAHttp.java b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/EXAHttp.java new file mode 100644 index 0000000..d3dec61 --- /dev/null +++ b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/EXAHttp.java @@ -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; +} diff --git a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/EXAPageReqVO.java b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/EXAPageReqVO.java new file mode 100644 index 0000000..02a7fb9 --- /dev/null +++ b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/EXAPageReqVO.java @@ -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; +} diff --git a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/EXAVO.java b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/EXAVO.java new file mode 100644 index 0000000..0ade4cc --- /dev/null +++ b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/controller/admin/exa/vo/EXAVO.java @@ -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; + +} diff --git a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/exa/EXAService.java b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/exa/EXAService.java new file mode 100644 index 0000000..76a4b89 --- /dev/null +++ b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/exa/EXAService.java @@ -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 getEXAList(EXAVO reqVO); + + PageResult getEXAPage(EXAPageReqVO reqVO) throws IOException, URISyntaxException; + + + List getEXAListNow(List list) throws URISyntaxException, IOException; + + +} diff --git a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/exa/EXAServiceImpl.java b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/exa/EXAServiceImpl.java new file mode 100644 index 0000000..842d8c0 --- /dev/null +++ b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/service/exa/EXAServiceImpl.java @@ -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 getEXAPage(EXAPageReqVO reqVO) throws IOException, URISyntaxException { + List exaListAll = exaUtils.getPointInfo(reqVO); + Long total = Long.valueOf(exaListAll.size()); + + List exaList = getPartList(exaListAll, reqVO.getPageNo(), reqVO.getPageSize()); + + PageResult result = new PageResult<>(getEXAListNow(exaList), total); + return result; + } + + @Override + public List getEXAListNow(List 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; + } + +} diff --git a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/utils/EXAUtils.java b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/utils/EXAUtils.java new file mode 100644 index 0000000..64e65fb --- /dev/null +++ b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/utils/EXAUtils.java @@ -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 getPointInfo(EXAPageReqVO reqVO) throws URISyntaxException, IOException { +// PageResult result = new PageResult<>(); + List exaListAll = new ArrayList(); + 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>() { + }.getType(); + exaListAll = gson.fromJson(body, listType); + + + //关闭资源 + response.close(); + httpClient.close(); + } catch (Exception e) { + + } + return exaListAll; + } + + public List getNowData(String itemNames) throws URISyntaxException, IOException { + List 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>() { + }.getType(); + result = gson.fromJson(body, listType); + + //关闭资源 + response.close(); + httpClient.close(); + } catch (Exception e) { + + } + return result; + } + + +} diff --git a/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/utils/PageUtils.java b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/utils/PageUtils.java new file mode 100644 index 0000000..6e20607 --- /dev/null +++ b/yudao-module-alert/yudao-module-alert-biz/src/main/java/cn/iocoder/yudao/module/alert/utils/PageUtils.java @@ -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 元素类型 + * @return 指定页的元素列表 + */ + public static List getPartList(List 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)); + } +} -- 2.30.2