From b43fec7153e8874afab91302a4a42d25a4b71bcb Mon Sep 17 00:00:00 2001 From: liriming <1343021927@qq.com> Date: 星期二, 18 三月 2025 16:24:18 +0800 Subject: [PATCH] 预测数据接口 --- ansteel-biz/src/main/java/com/iailab/module/ansteel/common/constant/CommonConstant.java | 72 ++++++ ansteel-biz/src/main/java/com/iailab/module/ansteel/common/enums/PreLineTypeEnum.java | 33 ++ ansteel-api/src/main/java/com/iailab/module/enums/ApiConstants.java | 7 ansteel-biz/src/main/java/com/iailab/module/ansteel/util/ApiSecurityUtils.java | 82 ++++++ pom.xml | 2 /dev/null | 1 ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/ApiPointValueDTO.java | 22 + ansteel-biz/src/main/java/com/iailab/module/ansteel/api/McsServiceImpl.java | 131 ++++++++++ ansteel-api/src/main/java/com/iailab/module/api/package-info.java | 1 ansteel-api/src/main/java/com/iailab/module/enums/package-info.java | 1 ansteel-api/pom.xml | 7 ansteel-biz/src/main/java/com/iailab/module/ansteel/api/vo/ItemVO.java | 41 +++ ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/McsController.java | 34 ++ ansteel-api/src/main/java/com/iailab/module/api/mcs/AnSteelApi.java | 36 +++ ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/PowerRunStateDTO.java | 2 ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/PreDataChartRespVO.java | 40 +++ ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/AlarmMessageRespDTO.java | 70 +++++ ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/PreDataViewDTO.java | 116 +++++++++ ansteel-biz/pom.xml | 6 19 files changed, 678 insertions(+), 26 deletions(-) diff --git a/ansteel-api/pom.xml b/ansteel-api/pom.xml index 04f95b8..5edf0db 100644 --- a/ansteel-api/pom.xml +++ b/ansteel-api/pom.xml @@ -42,6 +42,13 @@ <artifactId>spring-cloud-starter-openfeign</artifactId> <optional>true</optional> </dependency> + <dependency> + <groupId>com.iailab</groupId> + <artifactId>iailab-module-model-api</artifactId> + <version>1.0.0</version> + <scope>compile</scope> + </dependency> + </dependencies> diff --git a/ansteel-api/src/main/java/com/iailab/module/api/mcs/AnSteelApi.java b/ansteel-api/src/main/java/com/iailab/module/api/mcs/AnSteelApi.java new file mode 100644 index 0000000..9a35b3b --- /dev/null +++ b/ansteel-api/src/main/java/com/iailab/module/api/mcs/AnSteelApi.java @@ -0,0 +1,36 @@ +package com.iailab.module.api.mcs; + +import com.iailab.module.api.mcs.dto.PowerRunStateDTO; +import com.iailab.module.api.mcs.dto.PreDataChartRespVO; +import com.iailab.module.enums.ApiConstants; +import com.iailab.module.model.api.mcs.dto.PreDataSingleChartReqVO; +import com.iailab.module.model.api.mcs.dto.PreDataSingleChartRespVO; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.List; + +/** + * @author lirm + * @Description + * @createTime 2025年03月17日 + */ +@FeignClient(name = ApiConstants.NAME) +@Tag(name = "RPC 服务 - 信息接口") +public interface AnSteelApi { + + String PREFIX = ApiConstants.PREFIX + "/api/mcs"; + + @GetMapping(PREFIX + "/power-run-state/list") + @Operation(summary = "发电厂机组运行情况") + List<PowerRunStateDTO> getPowerRunState(); + + @PostMapping(PREFIX + "/predict-data/charts") + @Operation(summary = "预测数据图表T+30/60/120") + PreDataChartRespVO getPreDataChart(@RequestBody PreDataSingleChartReqVO reqVO); + +} \ No newline at end of file diff --git a/ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/AlarmMessageRespDTO.java b/ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/AlarmMessageRespDTO.java new file mode 100644 index 0000000..c5a5fca --- /dev/null +++ b/ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/AlarmMessageRespDTO.java @@ -0,0 +1,70 @@ +package com.iailab.module.api.mcs.dto; + +/** + * @author PanZhibao + * @Description + * @createTime 2024年08月29日 + */ + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; + +/** + * @author PanZhibao + * @Description + * @createTime 2024年08月29日 + */ +@Schema(description = "RPC 模型 - 预警消息 DTO") +@Data +public class AlarmMessageRespDTO implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "ID") + private String id; + + @Schema(description = "配置ID") + private String configId; + + @Schema(description = "消息标题") + private String title; + + @Schema(description = "消息内容") + private String content; + + @Schema(description = "监控对象") + private String alarmObj; + + @Schema(description = "监控点位ID") + private String pointId; + + @Schema(description = "预测项ID") + private String itemId; + + @Schema(description = "当前值") + private BigDecimal currentValue; + + @Schema(description = "超出时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date outTime; + + @Schema(description = "超出值") + private BigDecimal outValue; + + @Schema(description = "预警类型") + private String alarmType; + + @Schema(description = "预警时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date alarmTime; + + @Schema(description = "创建时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createTime; + +} \ No newline at end of file diff --git a/ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/ApiPointValueDTO.java b/ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/ApiPointValueDTO.java new file mode 100644 index 0000000..fdcbe4b --- /dev/null +++ b/ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/ApiPointValueDTO.java @@ -0,0 +1,22 @@ +package com.iailab.module.api.mcs.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * @author PanZhibao + * @Description + * @createTime 2024年08月19日 + */ +@Data +public class ApiPointValueDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date t; + + private double v; +} \ No newline at end of file diff --git a/ansteel-api/src/main/java/com/iailab/module/sms/api/dto/PowerRunStateDTO.java b/ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/PowerRunStateDTO.java similarity index 92% rename from ansteel-api/src/main/java/com/iailab/module/sms/api/dto/PowerRunStateDTO.java rename to ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/PowerRunStateDTO.java index 4fbe762..88c5309 100644 --- a/ansteel-api/src/main/java/com/iailab/module/sms/api/dto/PowerRunStateDTO.java +++ b/ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/PowerRunStateDTO.java @@ -1,4 +1,4 @@ -package com.iailab.module.sms.api.dto; +package com.iailab.module.api.mcs.dto; import lombok.Data; diff --git a/ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/PreDataChartRespVO.java b/ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/PreDataChartRespVO.java new file mode 100644 index 0000000..318d4a8 --- /dev/null +++ b/ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/PreDataChartRespVO.java @@ -0,0 +1,40 @@ +package com.iailab.module.api.mcs.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * @author PanZhibao + * @Description + * @createTime 2024年11月18日 + */ +@Data +public class PreDataChartRespVO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "预测时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date predictTime; + + @Schema(description = "开始时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date startTime; + + @Schema(description = "结束时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date endTime; + + @Schema(description = "图例") + private List<String> legend; + + @Schema(description = "X轴数据") + private List<String> categories; + + private PreDataViewDTO dataView; + +} \ No newline at end of file diff --git a/ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/PreDataViewDTO.java b/ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/PreDataViewDTO.java new file mode 100644 index 0000000..621f060 --- /dev/null +++ b/ansteel-api/src/main/java/com/iailab/module/api/mcs/dto/PreDataViewDTO.java @@ -0,0 +1,116 @@ +package com.iailab.module.api.mcs.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.iailab.module.model.api.mcs.dto.AlarmMessageRespDTO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +/** + * @author PanZhibao + * @Description + * @createTime 2024年08月26日 + */ +@Schema(description = "RPC 模型 - 预测数据 DTO") +@Data +public class PreDataViewDTO implements Serializable { + private static final long serialVersionUID = 1L; + + @Schema(description = "预测项ID") + private String itemId; + + @Schema(description = "预测项名称") + private String itemName; + + @Schema(description = "输出ID") + private String outId; + + @Schema(description = "输出结果") + private String resultstr; + + @Schema(description = "输出结果") + private String resultName; + + @Schema(description = "预测时间") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date predictTime; + + @Schema(description = "量程上限") + private BigDecimal rangeH; + + @Schema(description = "量程下限") + private BigDecimal rangeL; + + @Schema(description = "柜位上限") + private BigDecimal deadLineH; + + @Schema(description = "柜位下限") + private BigDecimal deadLineL; + + @Schema(description = "运行上限") + private BigDecimal limitH; + + @Schema(description = "运行下限") + private BigDecimal limitL; + + @Schema(description = "动态上限") + private List<ApiPointValueDTO> trendsDataH; + + @Schema(description = "动态下限") + private List<ApiPointValueDTO> trendsDataL; + + @Schema(description = "当前") + private BigDecimal currValue; + + @Schema(description = "最大值") + private BigDecimal maxValue; + + @Schema(description = "最小值") + private BigDecimal minValue; + + @Schema(description = "历史最大值") + private BigDecimal hisMax; + + @Schema(description = "历史最小值") + private BigDecimal hisMin; + + @Schema(description = "历史最大值") + private BigDecimal hisCumulant; + + @Schema(description = "预测最大值") + private BigDecimal preMax; + + @Schema(description = "预测最小值") + private BigDecimal preMin; + + @Schema(description = "预测最后一个值") + private BigDecimal preLast; + + @Schema(description = "预测累计值") + private BigDecimal preCumulant; + + @Schema(description = "真实值") + private List<Object[]> realData; + + @Schema(description = "T+L/N预测值") + private List<Object[]> preData; + + @Schema(description = "预警信息") + private List<AlarmMessageRespDTO> alarmList; + + @Schema(description = "预警信息") + private String alarmMessage; + + @Schema(description = "展示线类型") + private String lineType; + + @Schema(description = "累计真实值") + private List<Object[]> cumulantRealData; + + @Schema(description = "累计预测值") + private List<Object[]> cumulantPreData; +} \ No newline at end of file diff --git a/ansteel-api/src/main/java/com/iailab/module/api/package-info.java b/ansteel-api/src/main/java/com/iailab/module/api/package-info.java new file mode 100644 index 0000000..7f2ef16 --- /dev/null +++ b/ansteel-api/src/main/java/com/iailab/module/api/package-info.java @@ -0,0 +1 @@ +package com.iailab.module.api; \ No newline at end of file diff --git a/ansteel-api/src/main/java/com/iailab/module/sms/enums/ApiConstants.java b/ansteel-api/src/main/java/com/iailab/module/enums/ApiConstants.java similarity index 68% rename from ansteel-api/src/main/java/com/iailab/module/sms/enums/ApiConstants.java rename to ansteel-api/src/main/java/com/iailab/module/enums/ApiConstants.java index 9945287..6ad39b7 100644 --- a/ansteel-api/src/main/java/com/iailab/module/sms/enums/ApiConstants.java +++ b/ansteel-api/src/main/java/com/iailab/module/enums/ApiConstants.java @@ -1,4 +1,4 @@ -package com.iailab.module.sms.enums; +package com.iailab.module.enums; import com.iailab.framework.common.enums.RpcConstants; @@ -13,9 +13,8 @@ * * 注意,需要保证和 spring.application.name 保持一致 */ - public static final String NAME = "model-server"; + public static final String NAME = "ansteel-server"; - public static final String PREFIX = RpcConstants.RPC_API_PREFIX + "/model"; + public static final String PREFIX = RpcConstants.RPC_API_PREFIX + "/ansteel"; - public static final String VERSION = "1.0.0"; } \ No newline at end of file diff --git a/ansteel-api/src/main/java/com/iailab/module/enums/package-info.java b/ansteel-api/src/main/java/com/iailab/module/enums/package-info.java new file mode 100644 index 0000000..59fc466 --- /dev/null +++ b/ansteel-api/src/main/java/com/iailab/module/enums/package-info.java @@ -0,0 +1 @@ +package com.iailab.module.enums; \ No newline at end of file diff --git a/ansteel-api/src/main/java/com/iailab/module/sms/api/AnSteelApi.java b/ansteel-api/src/main/java/com/iailab/module/sms/api/AnSteelApi.java deleted file mode 100644 index 81d5dbc..0000000 --- a/ansteel-api/src/main/java/com/iailab/module/sms/api/AnSteelApi.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.iailab.module.model.api.mcs; - -import com.iailab.module.sms.api.dto.PowerRunStateDTO; -import com.iailab.module.sms.enums.ApiConstants; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.GetMapping; - -import java.util.List; - -/** - * @author lirm - * @Description - * @createTime 2025年03月17日 - */ -@FeignClient(name = ApiConstants.NAME) -@Tag(name = "RPC 服务 - 信息接口") -public interface AnSteelApi { - - String PREFIX = ApiConstants.PREFIX + "/mcs"; - - @GetMapping(PREFIX + "/power-run-state/list") - @Operation(summary = "发电厂机组运行情况") - List<PowerRunStateDTO> getPowerRunState(); - -} \ No newline at end of file diff --git a/ansteel-api/src/main/java/com/iailab/module/sms/api/package-info.java b/ansteel-api/src/main/java/com/iailab/module/sms/api/package-info.java deleted file mode 100644 index 78b9dea..0000000 --- a/ansteel-api/src/main/java/com/iailab/module/sms/api/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.iailab.module.ansteel.api; \ No newline at end of file diff --git a/ansteel-api/src/main/java/com/iailab/module/sms/enums/package-info.java b/ansteel-api/src/main/java/com/iailab/module/sms/enums/package-info.java deleted file mode 100644 index 8f422d0..0000000 --- a/ansteel-api/src/main/java/com/iailab/module/sms/enums/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.iailab.module.ansteel.enums; \ No newline at end of file diff --git a/ansteel-biz/pom.xml b/ansteel-biz/pom.xml index 95b3e65..c172627 100644 --- a/ansteel-biz/pom.xml +++ b/ansteel-biz/pom.xml @@ -21,11 +21,6 @@ <!-- 依赖服务 --> <dependency> <groupId>com.iailab</groupId> - <artifactId>ansteel-api</artifactId> - <version>${revision}</version> - </dependency> - <dependency> - <groupId>com.iailab</groupId> <artifactId>iailab-module-infra-api</artifactId> <version>${revision}</version> </dependency> @@ -129,7 +124,6 @@ <groupId>com.iailab</groupId> <artifactId>ansteel-api</artifactId> <version>1.0.0</version> - <scope>compile</scope> </dependency> </dependencies> diff --git a/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/McsServiceImpl.java b/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/McsServiceImpl.java index 1311665..8cb1be3 100644 --- a/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/McsServiceImpl.java +++ b/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/McsServiceImpl.java @@ -1,21 +1,32 @@ package com.iailab.module.ansteel.api; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.iailab.framework.common.util.date.DateUtils; import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.module.ansteel.api.dao.PowerRunStateDao; +import com.iailab.module.ansteel.common.constant.CommonConstant; +import com.iailab.module.ansteel.common.enums.PreLineTypeEnum; +import com.iailab.module.api.mcs.AnSteelApi; +import com.iailab.module.api.mcs.dto.ApiPointValueDTO; +import com.iailab.module.api.mcs.dto.PowerRunStateDTO; +import com.iailab.module.api.mcs.dto.PreDataChartRespVO; +import com.iailab.module.api.mcs.dto.PreDataViewDTO; import com.iailab.module.data.api.point.DataPointApi; -import com.iailab.module.model.api.mcs.AnSteelApi; -import com.iailab.module.sms.api.dto.PowerRunStateDTO; +import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; +import com.iailab.module.model.api.mcs.McsApi; +import com.iailab.module.model.api.mcs.dto.ChartParamDTO; +import com.iailab.module.model.api.mcs.dto.MmItemOutputDTO; +import com.iailab.module.model.api.mcs.dto.PreDataSingleChartReqVO; +import com.iailab.module.model.api.mcs.dto.PredictItemVO; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import java.math.BigDecimal; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @Slf4j @@ -24,6 +35,9 @@ @Autowired private DataPointApi dataPointApi; + + @Autowired + private McsApi mcsApi; @Autowired private PowerRunStateDao powerRunStateDao; @@ -65,4 +79,111 @@ } return list; } + + @Override + public PreDataChartRespVO getPreDataChart(PreDataSingleChartReqVO reqVO) { + Map<String, String> tMap = new HashMap<>(); + List<ChartParamDTO> list = mcsApi.getChartParamList(reqVO.getChartCode()); + if (CollectionUtils.isEmpty(list)) { + return null; + } + list.forEach(item -> { + tMap.put(item.getParamCode(), item.getParamValue()); + }); + String itemCode = tMap.get(CommonConstant.ITEM_CODE); + if (itemCode == null) { + return null; + } + String resultStr = tMap.get(CommonConstant.RESULT_STR); + if (resultStr == null) { + return null; + } + String resultIndex = tMap.get(CommonConstant.RESULT_INDEX); + if (resultIndex == null) { + return null; + } + PredictItemVO predictItem = mcsApi.getPredictItemByItemNo(itemCode); + if (predictItem == null || predictItem.getLastTime() == null) { + return null; + } + String timeFormat = StringUtils.isBlank(reqVO.getTimeFormat()) ? DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND : reqVO.getTimeFormat(); + PreLineTypeEnum lineType = tMap.get(CommonConstant.LINE_TYPE) == null ? PreLineTypeEnum.TN : PreLineTypeEnum.getEumByCode(tMap.get(CommonConstant.LINE_TYPE)); + int lengthLeft = tMap.get(CommonConstant.LENGTH_LEFT) == null ? predictItem.getPredictLength() : new BigDecimal(tMap.get(CommonConstant.LENGTH_LEFT)).intValue(); + int lengthRight = tMap.get(CommonConstant.LENGTH_RIGHT) == null ? predictItem.getPredictLength() : new BigDecimal(tMap.get(CommonConstant.LENGTH_RIGHT)).intValue(); + String trendsDataH = tMap.get(CommonConstant.TRENDSDATA_H) == null ? null : tMap.get(CommonConstant.TRENDSDATA_H); + String trendsDataL = tMap.get(CommonConstant.TRENDSDATA_L) == null ? null : tMap.get(CommonConstant.TRENDSDATA_L); + + Date[] timeArray = calResultTime(predictItem, reqVO.getStartTime(), reqVO.getEndTime(), lengthLeft, lengthRight); + Date predictTime = timeArray[0]; + Date startTime = timeArray[1]; + Date endTime = timeArray[2]; + + PreDataChartRespVO result = ConvertUtils.sourceToTarget(mcsApi.getPreDataSingleChart(reqVO), PreDataChartRespVO.class); + PreDataViewDTO dataView = result.getDataView(); + if(trendsDataH != null) { + ApiPointValueQueryDTO pointValueQueryDTO = new ApiPointValueQueryDTO(); + pointValueQueryDTO.setPointNo(trendsDataH); + List<ApiPointValueDTO> trendsDataHList = ConvertUtils.sourceToTarget(dataPointApi.queryPointHistoryValue(pointValueQueryDTO), ApiPointValueDTO.class); + dataView.setTrendsDataH(trendsDataHList); + } + if(trendsDataL != null) { + ApiPointValueQueryDTO pointValueQueryDTO = new ApiPointValueQueryDTO(); + pointValueQueryDTO.setPointNo(trendsDataL); + List<ApiPointValueDTO> trendsDataLList = ConvertUtils.sourceToTarget(dataPointApi.queryPointHistoryValue(pointValueQueryDTO), ApiPointValueDTO.class); + dataView.setTrendsDataL(trendsDataLList); + } + MmItemOutputDTO outputDTO = mcsApi.getItemOutputByItemid(predictItem.getId(), resultStr, resultIndex); + switch (lineType) { + case TN: + if(reqVO.getChartCode().equals(CommonConstant.LDG_CHARRCODE)){ + dataView.setPreData(mcsApi.getItemResult(outputDTO.getId(), predictTime, endTime, timeFormat)); + }else{ + dataView.setPreData(mcsApi.getItemResult(outputDTO.getId(), startTime, endTime, timeFormat)); + } + + break; + case TL: + if(reqVO.getChartCode().equals(CommonConstant.LDG_CHARRCODE)){ + dataView.setPreData(mcsApi.getItemResultLastPoint(outputDTO.getId(), predictTime, endTime, timeFormat)); + }else{ + dataView.setPreData(mcsApi.getItemResultLastPoint(outputDTO.getId(), startTime, endTime, timeFormat)); + } + break; + default: + break; + } + result.setDataView(dataView); + return result; + } + + private Date[] calResultTime(PredictItemVO predictItem, Date startTimeReq, Date endTimeReq, int lengthLeft, int lengthRight) { + Date[] result = new Date[3]; + Date predictTime = predictItem.getLastTime(); + Integer granularity = predictItem.getGranularity(); + Date startTime = startTimeReq; + if (startTime == null) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(predictItem.getLastTime()); + calendar.add(Calendar.SECOND, -1 * lengthLeft * granularity); + startTime = calendar.getTime(); + } + Date endTime = endTimeReq; + if (endTime == null) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(predictItem.getLastTime()); + calendar.add(Calendar.SECOND, lengthRight * granularity); + endTime = calendar.getTime(); + } + if (endTime.getTime() <= startTime.getTime()) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(startTime); + calendar.add(Calendar.SECOND, lengthRight * granularity); + endTime = calendar.getTime(); + } + result[0] = predictTime; + result[1] = startTime; + result[2] = endTime; + return result; + } + } \ No newline at end of file diff --git a/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/McsController.java b/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/McsController.java index f281cf1..e0ac3af 100644 --- a/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/McsController.java +++ b/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/controller/McsController.java @@ -1,15 +1,21 @@ package com.iailab.module.ansteel.api.controller; import com.iailab.framework.common.pojo.CommonResult; -import com.iailab.module.model.api.mcs.AnSteelApi; -import com.iailab.module.sms.api.dto.PowerRunStateDTO; +import com.iailab.module.ansteel.util.ApiSecurityUtils; +import com.iailab.module.api.mcs.AnSteelApi; +import com.iailab.module.api.mcs.dto.PowerRunStateDTO; +import com.iailab.module.api.mcs.dto.PreDataChartRespVO; +import com.iailab.module.model.api.mcs.dto.PreDataItemChartReqVO; +import com.iailab.module.model.api.mcs.dto.PreDataItemChartRespVO; +import com.iailab.module.model.api.mcs.dto.PreDataSingleChartReqVO; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Map; @@ -21,16 +27,28 @@ **/ @Tag(name = "发电厂机组运行情况") @RestController -@RequestMapping("/mcs/power-run-state") +@RequestMapping("/ansteel/api/mcs") public class McsController { @Autowired private AnSteelApi anSteelApi; - @GetMapping("list") + @Resource + private ApiSecurityUtils apiSecurityUtils; + + @GetMapping("/power-run-state/list") public CommonResult<List<PowerRunStateDTO>> list(@RequestParam Map<String, Object> params) { List<PowerRunStateDTO> list = anSteelApi.getPowerRunState(); return success(list); } + @PostMapping("/predict-data/charts") + @Operation(summary = "预测数据图表") + public CommonResult<PreDataChartRespVO> getPreDataChart(HttpServletResponse response, HttpServletRequest + request, @RequestBody PreDataSingleChartReqVO reqVO) throws Exception { + apiSecurityUtils.validate(request); + PreDataChartRespVO respVO = anSteelApi.getPreDataChart(reqVO); + return CommonResult.success(respVO); + } + } \ No newline at end of file diff --git a/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/vo/ItemVO.java b/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/vo/ItemVO.java new file mode 100644 index 0000000..4362d09 --- /dev/null +++ b/ansteel-biz/src/main/java/com/iailab/module/ansteel/api/vo/ItemVO.java @@ -0,0 +1,41 @@ +package com.iailab.module.ansteel.api.vo; + +import lombok.Data; + +import java.util.Date; + +/** + * @author PanZhibao + * @Description + * @createTime 2024年09月01日 + */ +@Data +public class ItemVO { + private String id; + private String itemNo; + private String itemName; + private String itemType; + private Integer predictLength; + private Integer granularity; + private Integer status; + private Integer isFuse; + private Integer predictPhase; + private Integer workChecked; + private Integer isDisplay; + private Integer unitTransFactor; + + /** + * 保留的预测点位 (T+2 则n=2, T+30则n=30, T+n则表示从最后点位开始,n=预测长度;n由系统配置得出) + */ + private String saveIndex; + + /** + * 项目id + */ + private String mpkProjectId; + + /** + * 最后运行时间 + */ + private Date lastTime; +} \ No newline at end of file diff --git a/ansteel-biz/src/main/java/com/iailab/module/ansteel/common/constant/CommonConstant.java b/ansteel-biz/src/main/java/com/iailab/module/ansteel/common/constant/CommonConstant.java new file mode 100644 index 0000000..0f06e14 --- /dev/null +++ b/ansteel-biz/src/main/java/com/iailab/module/ansteel/common/constant/CommonConstant.java @@ -0,0 +1,72 @@ +package com.iailab.module.ansteel.common.constant; + + +import java.math.BigDecimal; + +/** + * @Description: 通用常量 + */ +public interface CommonConstant { + + int IS_ENABLE = 1; + + BigDecimal BAD_VALUE = new BigDecimal("-2"); + + BigDecimal ZERO_VALUE = new BigDecimal("0"); + + String MDK_SUFFIX = ".miail"; + + String MDK_RESULT = "result"; + + String MDK_STATUS_CODE = "status_code"; + + String MDK_STATUS_100 = "100"; + + String MDK_STATUS_500 = "500 "; + + String RANGE_H = "RANGE_H"; + + String RANGE_L = "RANGE_L"; + + String LIMIT_H = "LIMIT_H"; + + String LIMIT_L = "LIMIT_L"; + + String TRENDSDATA_H = "TRENDSDATA_H"; + + String TRENDSDATA_L = "TRENDSDATA_L"; + + String ITEM_CODE = "ITEM_CODE"; + + String ALARM_OBJ = "ALARM_OBJ"; + + String PLAN_ITEM_LIST = "PLAN_ITEM_LIST"; + + String RESULT_STR = "RESULT_STR"; + + String RESULT_INDEX = "RESULT_INDEX"; + + String LENGTH_LEFT = "LENGTH_LEFT"; + + String LENGTH_RIGHT = "LENGTH_RIGHT"; + + String ADJ_VALUE_POINT = "ADJ_VALUE_POINT"; + + String ADJ_VALUE_ARR_POINT = "ADJ_VALUE_ARR_POINT"; + + // 趋势预测曲线类型,0:展示T+N,1:展示T+L, + String LINE_TYPE = "LINE_TYPE"; + + // 模型输出预测值 + String OUT_PREDICT_VALUES = "predictValues"; + + // 模型输出优化值 + String OUT_OPT_VALUES = "optValues"; + + // 模型输出调整值 + String OUT_ADJUST_VALUES = "adjustValues"; + + String BFG_CHARRCODE = "BFG_PRED01"; + String COG_CHARRCODE = "COG_PRED01"; + String LDG_CHARRCODE = "LDG_PRED01"; +} diff --git a/ansteel-biz/src/main/java/com/iailab/module/ansteel/common/enums/PreLineTypeEnum.java b/ansteel-biz/src/main/java/com/iailab/module/ansteel/common/enums/PreLineTypeEnum.java new file mode 100644 index 0000000..e1fd219 --- /dev/null +++ b/ansteel-biz/src/main/java/com/iailab/module/ansteel/common/enums/PreLineTypeEnum.java @@ -0,0 +1,33 @@ +package com.iailab.module.ansteel.common.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @author PanZhibao + * @Description + * @createTime 2024年11月18日 + */ +@Getter +@AllArgsConstructor +public enum PreLineTypeEnum { + TN("0", "T+N"), + TL("1", "T+L"), + CD("2", "curData"); + + private String code; + private String desc; + + public static PreLineTypeEnum getEumByCode(String code) { + if (code == null) { + return null; + } + + for (PreLineTypeEnum statusEnum : PreLineTypeEnum.values()) { + if (statusEnum.getCode().equals(code)) { + return statusEnum; + } + } + return null; + } +} \ No newline at end of file diff --git a/ansteel-biz/src/main/java/com/iailab/module/ansteel/util/ApiSecurityUtils.java b/ansteel-biz/src/main/java/com/iailab/module/ansteel/util/ApiSecurityUtils.java new file mode 100644 index 0000000..b1bf747 --- /dev/null +++ b/ansteel-biz/src/main/java/com/iailab/module/ansteel/util/ApiSecurityUtils.java @@ -0,0 +1,82 @@ +package com.iailab.module.ansteel.util; + + +import com.iailab.framework.common.constant.Constant; +import com.iailab.framework.tenant.core.context.TenantContextHolder; +import com.iailab.module.system.api.user.AdminUserApi; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.regex.Pattern; + +/** + * @author PanZhibao + * @Description + * @createTime 2023年12月06日 15:55:00 + */ +@Component +public class ApiSecurityUtils { + + /*@Resource + private ApiAppService apiAppService;*/ + + @Resource + private AdminUserApi adminUserApi; + + private Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$"); + + private String getRequestToken(HttpServletRequest httpRequest) { + //从header中获取token + String token = httpRequest.getHeader(Constant.TOKEN_HEADER); + + //如果header中不存在token,则从参数中获取token + if (StringUtils.isBlank(token)) { + token = httpRequest.getParameter(Constant.TOKEN_HEADER); + } + + return token; + } + + private void setTenantId(HttpServletRequest httpRequest) { + String tenantId = httpRequest.getHeader(Constant.HEAD_TENANT_ID); + + if (StringUtils.isNotBlank(tenantId)) { + TenantContextHolder.setTenantId(Long.parseLong(tenantId)); + } + } + + + public void validate(HttpServletRequest httpRequest) throws Exception { + setTenantId(httpRequest); + /*String token = getRequestToken(httpRequest); + if (StringUtils.isBlank(token)) { + throw new Exception("token 不能为空!"); + } + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); + if (ObjectUtils.isEmpty(loginUser)) { + throw new RuntimeException("用户不能为空"); + } + CommonResult<AdminUserRespDTO> user = adminUserApi.getUser(loginUser.getId()); + if(ObjectUtils.isEmpty(user)) { + throw new RuntimeException("用户不存在"); + } + AdminUserRespDTO userData = user.getData(); + String username = userData.getUsername();*/ + /*ApiAppEntity appInfo = apiAppService.getInfoByAppKey(username); + if (appInfo == null) { + throw new RuntimeException("应用未授权"); + }*/ + //TODO 验证签名 +// if(!com.iailab.common.utils.JwtUtils.verify(token, appInfo.getAppSecret())){ +// throw new RuntimeException("签名错误"); +// } + } + + private boolean isInteger(String str) { + return pattern.matcher(str).matches(); + } + + +} diff --git a/pom.xml b/pom.xml index f58865e..31d413a 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ 快速开发框架,默认基础system,data,model </description> <modules> -<!-- <module>ansteel-api</module>--> + <module>ansteel-api</module> <module>ansteel-biz</module> </modules> -- Gitblit v1.9.3