Browse Source

add: 运行月报智能分析

zhongwei
haungxing 3 months ago
parent
commit
23c9fe191d
  1. 20
      hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/DateUtil.java
  2. 5
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/constants/MqttTopicConstants.java
  3. 31
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IDataAnalyseClient.java
  4. 31
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/PowerDataDTO.java
  5. 32
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/RunReportAnalyseRequest.java
  6. 40
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/RunReportDataAnalyseDTO.java
  7. 26
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/RunTimeDataDTO.java
  8. 26
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/SoeDataDTO.java
  9. 3
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/entity/RunMonthEntity.java
  10. 1
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/vo/RunAlarmVo.java
  11. 27
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/DataAnalyseClient.java
  12. 5
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeApi.java
  13. 9
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java
  14. 27
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java
  15. 62
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/RunReportAnalyseSchedule.java
  16. 3
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java
  17. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/constants/RedisKeyConstants.java
  18. 1
      hzims-service/hzims-big-model/src/main/resources/template/template.yml
  19. 14
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/controller/RobotTaskController.java
  20. 44
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/consume/RunReportAnalyseConsumer.java
  21. 126
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java
  22. 2
      hzims-service/operational/src/main/resources/db/3.0.2.sql

20
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 * @param yearAndMonth
* @return * @return

5
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 TOPIC_VIDEO_DELETE = "topic_video_delete";
/**
* 月报分析结果
*/
String RUN_REPORT_ANALYSE_RESULT = "topic_run_report_analyse_result";
} }

31
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);
}

31
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";
}

32
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<RunReportDataAnalyseDTO> analyseDTOS;
}

40
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<PowerDataDTO> power;
/**
* 告警数据
*/
private List<SoeDataDTO> soe;
}

26
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";
}

26
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;
}

3
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("运行建议") @ApiModelProperty("运行建议")
private String runPropose; private String runPropose;
@ApiModelProperty("分析结果")
private String analyseResult;
} }

1
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("运行告警对象") @ApiModel("运行告警对象")
public class RunAlarmVo { public class RunAlarmVo {
@ApiModelProperty("设备名称") @ApiModelProperty("设备名称")
private String deviceName; private String deviceName;

27
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("发起问答成功");
}
}

5
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 insertVideo;
private String insertYk; private String insertYk;
/**
* 发起机组发电量智能报表分析问答
*/
private String smartReportGeneratePower;
} }

9
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; 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.interactive.vo.AnswerVO;
import com.hnac.hzims.bigmodel.question.dto.QuestionDTO; import com.hnac.hzims.bigmodel.question.dto.QuestionDTO;
import org.springblade.core.tool.api.R;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -74,4 +75,10 @@ public interface IHznlmInvokeService {
*/ */
void askAbort(String sessionId); void askAbort(String sessionId);
/**
* 发起机组发电量智能报表分析问答
* @param req 待分析的数据
*/
void smartReportGeneratePower(RunReportAnalyseRequest req);
} }

27
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; package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.google.common.collect.Lists; 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.feign.IAuthClient;
import com.hnac.hzims.bigmodel.business.dto.RunReportDataAnalyseDTO;
import com.hnac.hzims.bigmodel.configuration.BigModelInvokeApi; import com.hnac.hzims.bigmodel.configuration.BigModelInvokeApi;
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService;
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO;
import com.hnac.hzims.bigmodel.manager.SessionRedisManager; import com.hnac.hzims.bigmodel.manager.SessionRedisManager;
import com.hnac.hzims.bigmodel.question.dto.QuestionDTO; import com.hnac.hzims.bigmodel.question.dto.QuestionDTO;
import com.hnac.hzims.bigmodel.utils.RequestClientUtil; 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.bigmodel.websocket.sessionManager.InteractiveSessionManager;
import com.hnac.hzims.common.constant.CommonConstant;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit;
/** /**
* @Author: huangxing * @Author: huangxing
@ -35,6 +43,7 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
private final BigModelInvokeApi bigModelInvokeApi; private final BigModelInvokeApi bigModelInvokeApi;
private final SessionRedisManager sessionRedisManager; private final SessionRedisManager sessionRedisManager;
private final IAuthClient authClient; private final IAuthClient authClient;
private final RedisTemplate redisTemplate;
@Value("${gglm.url}") @Value("${gglm.url}")
private String gglmUrl; private String gglmUrl;
@ -112,6 +121,24 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
} }
@Override @Override
public void smartReportGeneratePower(RunReportAnalyseRequest req) {
Map<String,Object> 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() { public List hotQuestions() {
try { try {
return RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getHotQuestion(), null, new TypeReference<List<String>>(){}); return RequestClientUtil.postCall(gglmUrl + bigModelInvokeApi.getHotQuestion(), null, new TypeReference<List<String>>(){});

62
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<String> getRunReportResult(String params) {
List<String> analyses = (List<String>) 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<AnswerVO> 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;
}
}

3
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_INTERACTIVE_RESULT = "getInteractiveResult";
/**获取运行月报分析结果**/
String GET_RUN_REPORT_RESULT = "getRunReportResult";
String SYNCHRONOUS_FAULT_INSTRUCT = "synchronousFaultInstruct"; String SYNCHRONOUS_FAULT_INSTRUCT = "synchronousFaultInstruct";
/**同步视频指令**/ /**同步视频指令**/

2
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 SESSION_CONTENT_KEY = CommonConstant.TENANT_ID + ":hzims:bigModel:session:content";
String RUN_REPORT_SESSION_ID = CommonConstant.TENANT_ID + ":hzims:bigModel:session:report";
} }

1
hzims-service/hzims-big-model/src/main/resources/template/template.yml

@ -59,6 +59,7 @@ gglm:
assistantSpecialAsk: "/qa/assistant_special_ask" assistantSpecialAsk: "/qa/assistant_special_ask"
assistantKnowledgeAsk: "/qa/assistant_knowledge_ask" assistantKnowledgeAsk: "/qa/assistant_knowledge_ask"
hotQuestion: "/qa/question_recommand" hotQuestion: "/qa/question_recommand"
smartReportGeneratePower: "/custom/smart_report_generate_power"
swagger: swagger:
base-packages: com.hnac.hzims.bigmodel base-packages: com.hnac.hzims.bigmodel

14
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.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzinfo.inspect.ai.vo.RobotTaskVO; import com.hnac.hzinfo.inspect.ai.vo.RobotTaskVO;
import com.hnac.hzinfo.inspect.ai.vo.robot.RobotTaskTransParam; 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 io.swagger.annotations.*;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import javax.validation.Valid; import javax.validation.Valid;
@ -19,6 +21,7 @@ import org.springblade.core.tool.utils.Func;
import org.springblade.mqtt.producer.IMqttSender; import org.springblade.mqtt.producer.IMqttSender;
import org.springblade.resource.feign.IOssClient; import org.springblade.resource.feign.IOssClient;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -187,4 +190,15 @@ public class RobotTaskController extends BladeController {
return R.success("操作成功"); 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<BladeFile> result = ossTemplate.putFile(file);
// return result;
// }
// return R.fail("失败");
// }
} }

44
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<RunMonthEntity> updateWrapper = Wrappers.<RunMonthEntity>lambdaUpdate()
.set(RunMonthEntity::getAnalyseResult, result)
.eq(RunMonthEntity::getMonth, month)
.eq(RunMonthEntity::getStationCode, stationCode);
runMonthReportService.update(updateWrapper);
}
}

126
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; package com.hnac.hzims.operational.report.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.hnac.hzims.alarm.config.constants.AlarmConstants; import com.hnac.hzims.alarm.config.constants.AlarmConstants;
import com.hnac.hzims.alarm.config.constants.AlarmHandleConstant; 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.common.logs.utils.StringUtils;
import com.hnac.hzims.equipment.entity.EmInfoEntity; import com.hnac.hzims.equipment.entity.EmInfoEntity;
import com.hnac.hzims.equipment.entity.PlanGenerationEntity; 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 com.hnac.hzinfo.sdk.v5.soe.vo.StbAnalysisVO;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
@ -61,6 +66,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.YearMonth;
import java.util.*; import java.util.*;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
@ -93,6 +99,8 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
private final IHistoryDataSearchClient historyDataSearchClient; private final IHistoryDataSearchClient historyDataSearchClient;
private final IDataAnalyseClient dataAnalyseClient;
// 创建线程池 // 创建线程池
private static final ExecutorService pool = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(256), new ThreadFactoryBuilder().setNameFormat("generate-run-report-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy()); private static final ExecutorService pool = new ThreadPoolExecutor(5, 5, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(256), new ThreadFactoryBuilder().setNameFormat("generate-run-report-pool-%d").build() , new ThreadPoolExecutor.CallerRunsPolicy());
@ -145,6 +153,8 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
return data; return data;
} }
/** /**
* 导出站点月报文件 * 导出站点月报文件
* @param mon * @param mon
@ -273,7 +283,121 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
// 先删除原先月报数据 // 先删除原先月报数据
this.deleteRunReport(mon,stationCode); this.deleteRunReport(mon,stationCode);
// 保存生成月报数据 // 保存生成月报数据
return runMonthReportService.save(run); boolean save = runMonthReportService.save(run);
// 调用大模型分析月报接口 结果通过mqtt获取
this.smartReportGeneratePower(mon,stationCode);
return save;
}
/**
* 调用大模型分析月报接口
* @param mon 月报月份
* @param stationCode 月报站号
*/
private void smartReportGeneratePower(String mon,String stationCode) {
List<RunReportDataAnalyseDTO> analyseVOList = Lists.newArrayList();
YearMonth yearMonth = YearMonth.parse(mon);
List<YearMonth> 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<PowerDataDTO> 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<RunReportDataAnalyseDTO> analyseVOList, String month) {
if(Func.isNotEmpty(req)) {
// 解析运行月报数据 - 运行数据、告警数据
List<RunDataVo> rundatas = JSONArray.parseArray(req.getRunData(), RunDataVo.class);
List<RunAlarmVo> alarms = JSONArray.parseArray(req.getAlarmData(),RunAlarmVo.class);
// 取运行、告警设备设备并集
List<String> runDatas = rundatas.stream().map(RunDataVo::getDeviceName).distinct().collect(Collectors.toList());
List<String> alarmDatas = alarms.stream().map(RunAlarmVo::getDeviceName).distinct().collect(Collectors.toList());
Collection<String> unionDeviceNames = CollectionUtils.union(runDatas, alarmDatas);
unionDeviceNames.forEach(deviceName -> {
Optional<RunReportDataAnalyseDTO> 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<PowerDataDTO> powerDataDTOS = Lists.newArrayList();
List<RunTimeDataDTO> runTimeDataDTOS = Lists.newArrayList();
List<SoeDataDTO> soeDataDTOS = Lists.newArrayList();
List<YearMonth> 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<RunDataVo> rundatas,List<RunAlarmVo> alarms,List<RunReportDataAnalyseDTO> analyseVOList) {
Optional<RunDataVo> runDataVo = rundatas.stream().filter(d -> deviceName.equals(d.getDeviceName())).findFirst();
List<SoeDataDTO> 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<PowerDataDTO> 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);
}
} }
/** /**

2
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 '分析结果';
Loading…
Cancel
Save