diff --git a/hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/DateUtil.java b/hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/DateUtil.java index 4309a29..500ecf7 100644 --- a/hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/DateUtil.java +++ b/hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/DateUtil.java @@ -101,6 +101,26 @@ public class DateUtil extends org.springblade.core.tool.utils.DateUtil { } /** + * 获取月份第一天时刻 + * @param yearAndMonth 月份 + * @return + */ + public static LocalDateTime getFirstDateTime(String yearAndMonth) { + YearMonth yearMonth = YearMonth.parse(yearAndMonth); + return yearMonth.atDay(1).atStartOfDay(); + } + + /** + * 获取月份最后一天时刻 + * @param yearAndMonth 月份 + * @return + */ + public static LocalDateTime getLastDateTime(String yearAndMonth) { + YearMonth yearMonth = YearMonth.parse(yearAndMonth); + return LocalDateTime.of(yearMonth.atDay(1).plusMonths(1).minusDays(1),LocalTime.MAX); + } + + /** * 获取月份最后一天 * @param yearAndMonth * @return diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/constants/MqttTopicConstants.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/constants/MqttTopicConstants.java index 0c31edb..183b2d6 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/constants/MqttTopicConstants.java +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/constants/MqttTopicConstants.java @@ -16,5 +16,10 @@ public interface MqttTopicConstants { */ String TOPIC_VIDEO_DELETE = "topic_video_delete"; + /** + * 月报分析结果 + */ + String RUN_REPORT_ANALYSE_RESULT = "topic_run_report_analyse_result"; + } diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IDataAnalyseClient.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IDataAnalyseClient.java new file mode 100644 index 0000000..7ced115 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IDataAnalyseClient.java @@ -0,0 +1,31 @@ +package com.hnac.hzims.bigmodel.api.feign; + +import com.hnac.hzims.bigmodel.BigModelConstants; +import com.hnac.hzims.bigmodel.business.dto.RunReportAnalyseRequest; +import com.hnac.hzims.bigmodel.business.dto.RunReportDataAnalyseDTO; +import org.springblade.core.tool.api.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/08/14 19:16 + */ +@FeignClient(name = BigModelConstants.APP_NAME) +public interface IDataAnalyseClient { + + String PREFIX_API = "/feign/dataAnalyse"; + String SMART_REPORT_GENERATE_POWER = PREFIX_API + "/smartReportGeneratePower"; + + /** + * 发起机组发电量智能报表分析问答 + * @param req 分析数据 + * @return 分析结果 + */ + @PostMapping(SMART_REPORT_GENERATE_POWER) + R smartReportGeneratePower(@RequestBody RunReportAnalyseRequest req); + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/PowerDataDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/PowerDataDTO.java new file mode 100644 index 0000000..f146a12 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/PowerDataDTO.java @@ -0,0 +1,31 @@ +package com.hnac.hzims.bigmodel.business.dto; + +import com.alibaba.fastjson.annotation.JSONField; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/08/13 20:07 + */ +@Data +@ApiModel("发电量 - 数据分析") +public class PowerDataDTO implements Serializable { + + @ApiModelProperty("查询日期") + private String date; + + @ApiModelProperty("发电量") + private Double value; + + @JSONField(name = "run_time") + @ApiModelProperty("运行时长") + private Double runTime; + + @ApiModelProperty("发电单位") + private String unit = "万kWh"; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/RunReportAnalyseRequest.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/RunReportAnalyseRequest.java new file mode 100644 index 0000000..be52daa --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/RunReportAnalyseRequest.java @@ -0,0 +1,32 @@ +package com.hnac.hzims.bigmodel.business.dto; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/08/15 08:41 + */ +@Data +@EqualsAndHashCode +public class RunReportAnalyseRequest implements Serializable { + + /** + * 站点编号 + */ + private String stationCode; + + /** + * 查询月份 + */ + private String month; + + /** + * 分析内容 + */ + private List analyseDTOS; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/RunReportDataAnalyseDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/RunReportDataAnalyseDTO.java new file mode 100644 index 0000000..6a9b4da --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/RunReportDataAnalyseDTO.java @@ -0,0 +1,40 @@ +package com.hnac.hzims.bigmodel.business.dto; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/08/13 20:16 + * @describe: 运行月报数据分析 + */ +@Data +@EqualsAndHashCode +public class RunReportDataAnalyseDTO implements Serializable { + + /** + * 设备编号 + */ + private String emCode; + + /** + * 设备名称 + */ + @JSONField(name = "name") + private String emName; + + /** + * 发电量数据 + */ + private List power; + + /** + * 告警数据 + */ + private List soe; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/RunTimeDataDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/RunTimeDataDTO.java new file mode 100644 index 0000000..d3cc184 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/RunTimeDataDTO.java @@ -0,0 +1,26 @@ +package com.hnac.hzims.bigmodel.business.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/08/13 20:10 + */ +@Data +@ApiModel("运行时长 - 数据分析") +public class RunTimeDataDTO implements Serializable { + + @ApiModelProperty("日期") + private String date; + + @ApiModelProperty("运行时长") + private Double value; + + @ApiModelProperty("单位") + private String unit = "h"; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/SoeDataDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/SoeDataDTO.java new file mode 100644 index 0000000..f9f7460 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/SoeDataDTO.java @@ -0,0 +1,26 @@ +package com.hnac.hzims.bigmodel.business.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/08/13 20:13 + */ +@Data +@ApiModel("告警数据 - 数据分析") +public class SoeDataDTO implements Serializable { + + @ApiModelProperty("日期") + private String date; + + @ApiModelProperty("告警内容") + private String name; + + @ApiModelProperty("告警次数") + private Integer times; + +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/entity/RunMonthEntity.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/entity/RunMonthEntity.java index a88c68b..6694a16 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/entity/RunMonthEntity.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/entity/RunMonthEntity.java @@ -41,4 +41,7 @@ public class RunMonthEntity extends TenantEntity { @ApiModelProperty("运行建议") private String runPropose; + @ApiModelProperty("分析结果") + private String analyseResult; + } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/RunAlarmVo.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/RunAlarmVo.java index be44671..6ab7085 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/RunAlarmVo.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/RunAlarmVo.java @@ -11,7 +11,6 @@ import lombok.Data; @ApiModel("运行告警对象") public class RunAlarmVo { - @ApiModelProperty("设备名称") private String deviceName; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/DataAnalyseClient.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/DataAnalyseClient.java new file mode 100644 index 0000000..cf41b72 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/DataAnalyseClient.java @@ -0,0 +1,27 @@ +package com.hnac.hzims.bigmodel.api.feign; + +import com.hnac.hzims.bigmodel.business.dto.RunReportAnalyseRequest; +import com.hnac.hzims.bigmodel.business.dto.RunReportDataAnalyseDTO; +import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/08/14 19:15 + */ +@RestController +@AllArgsConstructor +public class DataAnalyseClient implements IDataAnalyseClient { + + private final IHznlmInvokeService invokeService; + + @Override + public R smartReportGeneratePower(RunReportAnalyseRequest req) { + invokeService.smartReportGeneratePower(req); + return R.success("发起问答成功"); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeApi.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeApi.java index a61d254..79b679e 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeApi.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeApi.java @@ -46,4 +46,9 @@ public class BigModelInvokeApi { private String insertVideo; private String insertYk; + + /** + * 发起机组发电量智能报表分析问答 + */ + private String smartReportGeneratePower; } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java index 69f319c..f1ee2e3 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java @@ -1,8 +1,9 @@ package com.hnac.hzims.bigmodel.interactive.service; +import com.hnac.hzims.bigmodel.business.dto.RunReportAnalyseRequest; +import com.hnac.hzims.bigmodel.business.dto.RunReportDataAnalyseDTO; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; import com.hnac.hzims.bigmodel.question.dto.QuestionDTO; -import org.springblade.core.tool.api.R; import java.util.List; import java.util.Map; @@ -74,4 +75,10 @@ public interface IHznlmInvokeService { */ void askAbort(String sessionId); + /** + * 发起机组发电量智能报表分析问答 + * @param req 待分析的数据 + */ + void smartReportGeneratePower(RunReportAnalyseRequest req); + } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java index 49dd834..0546da9 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java @@ -1,26 +1,34 @@ package com.hnac.hzims.bigmodel.interactive.service.impl; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.google.common.collect.Lists; +import com.hnac.hzims.bigmodel.business.dto.RunReportAnalyseRequest; import com.hnac.hzims.bigmodel.business.feign.IAuthClient; +import com.hnac.hzims.bigmodel.business.dto.RunReportDataAnalyseDTO; import com.hnac.hzims.bigmodel.configuration.BigModelInvokeApi; import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; import com.hnac.hzims.bigmodel.manager.SessionRedisManager; import com.hnac.hzims.bigmodel.question.dto.QuestionDTO; import com.hnac.hzims.bigmodel.utils.RequestClientUtil; +import com.hnac.hzims.bigmodel.websocket.constants.RedisKeyConstants; import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; +import com.hnac.hzims.common.constant.CommonConstant; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; /** * @Author: huangxing @@ -35,6 +43,7 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService { private final BigModelInvokeApi bigModelInvokeApi; private final SessionRedisManager sessionRedisManager; private final IAuthClient authClient; + private final RedisTemplate redisTemplate; @Value("${gglm.url}") private String gglmUrl; @@ -112,6 +121,24 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService { } @Override + public void smartReportGeneratePower(RunReportAnalyseRequest req) { + Map params = new HashMap<>(); + String sessionId = IdWorker.get32UUID(); + params.put("chat_id",sessionId); + params.put("user_id", CommonConstant.SYSTEM_USER.toString()); + params.put("data", req.getAnalyseDTOS()); + params.put("query", ""); + RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getSmartReportGeneratePower(), params); + // 将sessionId存入redis,拿到数据之后输入月报中 + JSONObject report = new JSONObject(); + report.put("stationCode",req.getStationCode()); + report.put("month",req.getMonth()); + report.put("sessionId",sessionId); + redisTemplate.opsForList().leftPush(RedisKeyConstants.RUN_REPORT_SESSION_ID,JSON.toJSONString(report)); + redisTemplate.expire(RedisKeyConstants.RUN_REPORT_SESSION_ID,5, TimeUnit.MINUTES); + } + + @Override public List hotQuestions() { try { return RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getHotQuestion(), null, new TypeReference>(){}); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/RunReportAnalyseSchedule.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/RunReportAnalyseSchedule.java new file mode 100644 index 0000000..dac9cf4 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/RunReportAnalyseSchedule.java @@ -0,0 +1,62 @@ +package com.hnac.hzims.bigmodel.schedule; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.api.constants.MqttTopicConstants; +import com.hnac.hzims.bigmodel.interactive.service.IHznlmInteractiveService; +import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.websocket.constants.RedisKeyConstants; +import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.handler.annotation.XxlJob; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.utils.Func; +import org.springblade.mqtt.producer.IMqttSender; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.Collection; +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/08/15 08:57 + */ +@Component +@AllArgsConstructor +@Slf4j +public class RunReportAnalyseSchedule { + + private final RedisTemplate redisTemplate; + private final IHznlmInvokeService invokeService; + private final IMqttSender mqttSender; + + @XxlJob(XxlJobHandlerConstant.GET_RUN_REPORT_RESULT) + public ReturnT getRunReportResult(String params) { + List analyses = (List) redisTemplate.opsForList().range(RedisKeyConstants.RUN_REPORT_SESSION_ID,0,-1); + if(Func.isEmpty(analyses)) { + return ReturnT.SUCCESS; + } + analyses.stream().forEach(analyse -> { + JSONObject analyseObject = JSONObject.parseObject(analyse); + String sessionId = analyseObject.getString("sessionId"); + List answerVOS = invokeService.getAnswerBySessionIds(sessionId); + if(Func.isNotEmpty(answerVOS)) { + AnswerVO answerVO = answerVOS.get(0); + if(answerVO.getRunning() == 0) { + log.info("运行月报分析结果为:" + answerVO.getAnswer()); + JSONObject message = new JSONObject(); + message.put("stationCode", analyseObject.getString("stationCode")); + message.put("month", analyseObject.getString("month")); + message.put("result", answerVO.getAnswer()); + // 获取到问答答案,存入消息中 + mqttSender.sendToMqtt(MqttTopicConstants.RUN_REPORT_ANALYSE_RESULT,JSON.toJSONString(message)); + redisTemplate.opsForList().remove(RedisKeyConstants.RUN_REPORT_SESSION_ID,1,analyse); + } + } + }); + return ReturnT.SUCCESS; + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java index 0f210b7..c83961f 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java @@ -11,6 +11,9 @@ public interface XxlJobHandlerConstant { /**获取问答结果**/ String GET_INTERACTIVE_RESULT = "getInteractiveResult"; + /**获取运行月报分析结果**/ + String GET_RUN_REPORT_RESULT = "getRunReportResult"; + String SYNCHRONOUS_FAULT_INSTRUCT = "synchronousFaultInstruct"; /**同步视频指令**/ diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/constants/RedisKeyConstants.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/constants/RedisKeyConstants.java index 3cd0e30..40a64fd 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/constants/RedisKeyConstants.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/constants/RedisKeyConstants.java @@ -10,4 +10,6 @@ public interface RedisKeyConstants { String SESSION_CONTENT_KEY = CommonConstant.TENANT_ID + ":hzims:bigModel:session:content"; + String RUN_REPORT_SESSION_ID = CommonConstant.TENANT_ID + ":hzims:bigModel:session:report"; + } diff --git a/hzims-service/hzims-big-model/src/main/resources/template/template.yml b/hzims-service/hzims-big-model/src/main/resources/template/template.yml index 11b3744..a41a804 100644 --- a/hzims-service/hzims-big-model/src/main/resources/template/template.yml +++ b/hzims-service/hzims-big-model/src/main/resources/template/template.yml @@ -59,6 +59,7 @@ gglm: assistantSpecialAsk: "/qa/assistant_special_ask" assistantKnowledgeAsk: "/qa/assistant_knowledge_ask" hotQuestion: "/qa/question_recommand" + smartReportGeneratePower: "/custom/smart_report_generate_power" swagger: base-packages: com.hnac.hzims.bigmodel diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/controller/RobotTaskController.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/controller/RobotTaskController.java index 4c43fbc..7198688 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/controller/RobotTaskController.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/controller/RobotTaskController.java @@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.hnac.hzinfo.inspect.ai.vo.RobotTaskVO; import com.hnac.hzinfo.inspect.ai.vo.robot.RobotTaskTransParam; +import com.hnac.hzinfo.inspect.utils.FileUtil; +import com.hnac.hzinfo.inspect.utils.HiKUtil; import io.swagger.annotations.*; import lombok.AllArgsConstructor; import javax.validation.Valid; @@ -19,6 +21,7 @@ import org.springblade.core.tool.utils.Func; import org.springblade.mqtt.producer.IMqttSender; import org.springblade.resource.feign.IOssClient; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.core.metadata.IPage; import org.springframework.web.multipart.MultipartFile; @@ -187,4 +190,15 @@ public class RobotTaskController extends BladeController { return R.success("操作成功"); } +// @GetMapping("/test") +// public R test(@RequestParam("pointCode") String pointCode) { +// String url = HiKUtil.manualCapture(pointCode); +// if(Func.isNotEmpty(url)) { +// MockMultipartFile file = FileUtil.urlToMultipartFile(url, "test.jpg"); +// R result = ossTemplate.putFile(file); +// return result; +// } +// return R.fail("失败"); +// } + } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/consume/RunReportAnalyseConsumer.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/consume/RunReportAnalyseConsumer.java new file mode 100644 index 0000000..e330c3a --- /dev/null +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/consume/RunReportAnalyseConsumer.java @@ -0,0 +1,44 @@ +package com.hnac.hzims.operational.report.consume; + +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.bigmodel.api.constants.MqttTopicConstants; +import com.hnac.hzims.operational.report.entity.RunMonthEntity; +import com.hnac.hzims.operational.report.service.RunMonthReportService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.utils.Func; +import org.springblade.mqtt.customer.IMqttReceive; +import org.springblade.mqtt.customer.annotation.MqttReceive; +import org.springframework.stereotype.Service; + +/** + * @Author: huangxing + * @Date: 2024/08/15 09:46 + */ +@MqttReceive(topicName = MqttTopicConstants.RUN_REPORT_ANALYSE_RESULT) +@Service +@Slf4j +@AllArgsConstructor +public class RunReportAnalyseConsumer implements IMqttReceive { + + private final RunMonthReportService runMonthReportService; + + @Override + public void handlerMessage(String message) { + log.info("运行月报接收到分析结果:{}",message); + JSONObject jsonObject = JSONObject.parseObject(message); + String stationCode = jsonObject.getString("stationCode"); + String month = jsonObject.getString("month"); + String result = jsonObject.getString("result"); + if(Func.isEmpty(stationCode) || Func.isEmpty(month)) { + log.error("运行月报数据分析格式有误,解析失败!分析数据为:{}",message); + } + LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate() + .set(RunMonthEntity::getAnalyseResult, result) + .eq(RunMonthEntity::getMonth, month) + .eq(RunMonthEntity::getStationCode, stationCode); + runMonthReportService.update(updateWrapper); + } +} diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java index 88c4c0d..803c856 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java @@ -1,12 +1,16 @@ package com.hnac.hzims.operational.report.service.impl; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.google.common.collect.Lists; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.hnac.hzims.alarm.config.constants.AlarmConstants; import com.hnac.hzims.alarm.config.constants.AlarmHandleConstant; +import com.hnac.hzims.bigmodel.api.feign.IDataAnalyseClient; +import com.hnac.hzims.bigmodel.business.dto.*; import com.hnac.hzims.common.logs.utils.StringUtils; import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.entity.PlanGenerationEntity; @@ -40,6 +44,7 @@ import com.hnac.hzinfo.sdk.v5.soe.dto.StbAnalysisDTO; import com.hnac.hzinfo.sdk.v5.soe.vo.StbAnalysisVO; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.*; @@ -61,6 +66,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.net.URLEncoder; import java.time.LocalDateTime; +import java.time.YearMonth; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; @@ -93,6 +99,8 @@ public class RunMonthServiceImpl extends ServiceImpl(256), new ThreadFactoryBuilder().setNameFormat("generate-run-report-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy()); @@ -145,6 +153,8 @@ public class RunMonthServiceImpl extends ServiceImpl analyseVOList = Lists.newArrayList(); + YearMonth yearMonth = YearMonth.parse(mon); + List months = Lists.newArrayList(yearMonth, yearMonth.minusMonths(1), yearMonth.minusYears(1)); + months.stream().map(YearMonth::toString).map(m ->{ + try { + return this.data(m,stationCode); + } catch(Exception e) { + return null; + } + }).filter(Func::isNotEmpty).forEach(d -> this.fillAnalyseData(d,analyseVOList,mon)); + // 过滤掉发电量为空的数据 + analyseVOList.forEach(analyseVO -> { + List power = analyseVO.getPower(); + analyseVO.setPower(power.stream().filter(p -> Func.isNotEmpty(p.getValue())).collect(Collectors.toList())); + }); + RunReportAnalyseRequest analyseRequest = new RunReportAnalyseRequest(); + analyseRequest.setMonth(mon); + analyseRequest.setStationCode(stationCode); + analyseRequest.setAnalyseDTOS(analyseVOList); + dataAnalyseClient.smartReportGeneratePower(analyseRequest); + } + + /** + * 填充大模型分析所需数据格式 + * @param req 月报数据 + * @param analyseVOList 大模型分析对象 + * @param month 查询月报筛选条件 + */ + private void fillAnalyseData(RunMonthEntity req, List analyseVOList, String month) { + if(Func.isNotEmpty(req)) { + // 解析运行月报数据 - 运行数据、告警数据 + List rundatas = JSONArray.parseArray(req.getRunData(), RunDataVo.class); + List alarms = JSONArray.parseArray(req.getAlarmData(),RunAlarmVo.class); + // 取运行、告警设备设备并集 + List runDatas = rundatas.stream().map(RunDataVo::getDeviceName).distinct().collect(Collectors.toList()); + List alarmDatas = alarms.stream().map(RunAlarmVo::getDeviceName).distinct().collect(Collectors.toList()); + Collection unionDeviceNames = CollectionUtils.union(runDatas, alarmDatas); + unionDeviceNames.forEach(deviceName -> { + Optional exist = analyseVOList.stream().filter(vo -> deviceName.equals(vo.getEmName())).findFirst(); + if(!exist.isPresent()) { + // 若该设备未新增接受数据对象,则新增之后填充数据 + RunReportDataAnalyseDTO analyseVO = this.createDeviceAnalyse(deviceName, month); + analyseVOList.add(analyseVO); + } + this.fillDeviceAnalyse(deviceName,req.getMonth(),rundatas,alarms,analyseVOList); + }); + } + } + + /** + * 创建大模型分析所需对象 + * @param deviceName 设备名称 + * @param month 对象月份 + * @return 大模型分析所需对象 + */ + private RunReportDataAnalyseDTO createDeviceAnalyse(String deviceName, String month) { + RunReportDataAnalyseDTO analyseVO = new RunReportDataAnalyseDTO(); + analyseVO.setEmName(deviceName); + YearMonth yearMonth = YearMonth.parse(month); + List powerDataDTOS = Lists.newArrayList(); + List runTimeDataDTOS = Lists.newArrayList(); + List soeDataDTOS = Lists.newArrayList(); + List months = Lists.newArrayList(yearMonth, yearMonth.minusMonths(1), yearMonth.minusYears(1)); + months.stream().map(YearMonth::toString).forEach(m -> { + PowerDataDTO powerDataDTO = new PowerDataDTO(); + powerDataDTO.setDate(m); + powerDataDTOS.add(powerDataDTO); + }); + analyseVO.setPower(powerDataDTOS); + analyseVO.setSoe(soeDataDTOS); + return analyseVO; + } + + /** + * 填充大模型分析所需参数 + * @param deviceName 设备名称 + * @param month 月报数据月份 + * @param rundatas 月报运行数据 + * @param alarms 月报告警报表数据 + * @param analyseVOList 待填充的设备分析传参对象 + */ + private void fillDeviceAnalyse(String deviceName,String month,List rundatas,List alarms,List analyseVOList) { + Optional runDataVo = rundatas.stream().filter(d -> deviceName.equals(d.getDeviceName())).findFirst(); + List soeDataDTOS = alarms.stream().filter(a -> deviceName.equals(a.getDeviceName())).map(alarm -> { + SoeDataDTO soeDataDTO = new SoeDataDTO(); + soeDataDTO.setDate(month); + soeDataDTO.setName(alarm.getContent()); + soeDataDTO.setTimes(alarm.getCount()); + return soeDataDTO; + }).collect(Collectors.toList()); + RunReportDataAnalyseDTO analyseVO = analyseVOList.stream().filter(vo -> deviceName.equals(vo.getEmName())).findFirst().get(); + if(runDataVo.isPresent()) { + // 补充发电量、运行时长 + Optional powerData = analyseVO.getPower().stream().filter(p -> month.equals(p.getDate())).findFirst(); + if(powerData.isPresent()) { + powerData.get().setValue(runDataVo.get().getGenerate()); + powerData.get().setRunTime(runDataVo.get().getRunHours()); + } + } + if(Func.isNotEmpty(soeDataDTOS)) { + // 补充告警 + analyseVO.getSoe().addAll(soeDataDTOS); + } } /** diff --git a/hzims-service/operational/src/main/resources/db/3.0.2.sql b/hzims-service/operational/src/main/resources/db/3.0.2.sql new file mode 100644 index 0000000..57cf564 --- /dev/null +++ b/hzims-service/operational/src/main/resources/db/3.0.2.sql @@ -0,0 +1,2 @@ +-- 运行月报添加分析结果字段 +alter table `hzims_run_month_report` add COLUMN `analyse_result` TEXT comment '分析结果'; \ No newline at end of file