Browse Source

add:历史数据查询

zhongwei
haungxing 6 months ago
parent
commit
c414f10227
  1. 12
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DateEnum.java
  2. 20
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java
  3. 5
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java

12
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DateEnum.java

@ -11,12 +11,12 @@ import java.util.Arrays;
*/ */
@AllArgsConstructor @AllArgsConstructor
public enum DateEnum { public enum DateEnum {
YEAR("year","年","按年",5,6), YEAR("year","年","按年",5,6),
MONTH("month","月","按月",4,5), MONTH("month","月","按月",4,5),
DAY("day","日","按日",3,3), DAY("day","每天","按天",3,3),
HOUR("hour","时","按时",2,2), HOUR("hour","每小时","按时",2,2),
MINUTE("minute","分","按分",1,1), MINUTE("minute","","按分",1,1),
SECOND("second","秒","按秒",0,0), SECOND("second","秒","按秒",0,0),
; ;
@Getter @Getter
private String code; private String code;

20
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java

@ -1,5 +1,6 @@
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.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.hnac.hzims.bigmodel.interactive.constants.DataMethodEnum; import com.hnac.hzims.bigmodel.interactive.constants.DataMethodEnum;
@ -17,8 +18,10 @@ import com.hnac.hzinfo.sdk.v5.device.dto.ReductionDataDTO;
import com.hnac.hzinfo.sdk.v5.device.vo.ReductionDataVO; import com.hnac.hzinfo.sdk.v5.device.vo.ReductionDataVO;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -40,11 +43,13 @@ import java.util.stream.Collectors;
public class AnalyseDataServiceImpl implements IAnalyseDataService { public class AnalyseDataServiceImpl implements IAnalyseDataService {
private final DeviceDataClient deviceDataClient; private final DeviceDataClient deviceDataClient;
private final BladeLogger logger;
public static final int DATA_COUNT_MAX = 8000; public static final int DATA_COUNT_MAX = 8000;
@Override @Override
public ExtraVO getHistoryData(HistoryDataSearchVO searchVO) { public ExtraVO getHistoryData(HistoryDataSearchVO searchVO) {
if(DataMethodEnum.USUAL.getMethod().equals(searchVO.getMethod())) { if(Func.isEmpty(searchVO.getDataType()) || StringUtil.isBlank(searchVO.getDataType())
|| DataMethodEnum.USUAL.getMethod().equals(searchVO.getMethod())) {
searchVO.setDataType(DateEnum.SECOND.getDateType()); searchVO.setDataType(DateEnum.SECOND.getDateType());
} }
// 聚合数据方式处理 // 聚合数据方式处理
@ -52,12 +57,11 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService {
searchVO.setDataType(dateEnum.getDateType()); searchVO.setDataType(dateEnum.getDateType());
// 获取最适配时间段 // 获取最适配时间段
DateEnum adapterDate = this.getDateEnumByDuration(searchVO.getStartTime(), searchVO.getEndTime(), dateEnum); DateEnum adapterDate = this.getDateEnumByDuration(searchVO.getStartTime(), searchVO.getEndTime(), dateEnum);
String note = adapterDate.getDateType().equals(searchVO.getDataType()) ? "" : "(由于数据量过大,只能帮您" + adapterDate.getDateType() + "查询)";
searchVO.setDataType(adapterDate.getDateType()); searchVO.setDataType(adapterDate.getDateType());
String label = "根据数据量匹配到的取数规则为:" + adapterDate.getDateType() + "查询,查询结果如下:";
ExtraVO extraVO = new ExtraVO(); ExtraVO extraVO = new ExtraVO();
extraVO.setType(FuncRouteEnum.HISTORY_DATA.getType().getType()); extraVO.setType(FuncRouteEnum.HISTORY_DATA.getType().getType());
extraVO.setFuncCode(FuncRouteEnum.HISTORY_DATA.getFuncCode()); extraVO.setFuncCode(FuncRouteEnum.HISTORY_DATA.getFuncCode());
extraVO.setLabel(label);
Map<String,Object> params = new HashMap<>(1); Map<String,Object> params = new HashMap<>(1);
ReductionDataVO dataVO = this.getPolymerizationData(searchVO); ReductionDataVO dataVO = this.getPolymerizationData(searchVO);
List<Map> datalist = dataVO.getDataList().stream().map(m -> { List<Map> datalist = dataVO.getDataList().stream().map(m -> {
@ -65,6 +69,15 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService {
m.remove(searchVO.getSignage()); m.remove(searchVO.getSignage());
return m; return m;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
DataMethodEnum enumByMethod = DataMethodEnum.getEnumByMethod(searchVO.getMethod());
String label = searchVO.getStationName() + "_"
+ searchVO.getDeviceName() + "_"
+ dataVO.getFieldMap().get(searchVO.getSignage()) + "_"
+ adapterDate.getName()
+ enumByMethod.getMethod()
+ note
+ ":";
extraVO.setLabel(label);
params.put("data",datalist); params.put("data",datalist);
params.put("deviceName",searchVO.getDeviceName()); params.put("deviceName",searchVO.getDeviceName());
params.put("attrName",dataVO.getFieldMap().get(searchVO.getSignage())); params.put("attrName",dataVO.getFieldMap().get(searchVO.getSignage()));
@ -92,6 +105,7 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService {
dataDTO.setSaveTimeType(dateEnum.getSaveTimeType()); dataDTO.setSaveTimeType(dateEnum.getSaveTimeType());
dataDTO.setTimeInterval(1); dataDTO.setTimeInterval(1);
dataDTO.setDtos(Lists.newArrayList(reductionAttrData)); dataDTO.setDtos(Lists.newArrayList(reductionAttrData));
logger.info("interactive:getPolymerizationData","config传参为:" + JSON.toJSONString(dataDTO));
Result<ReductionDataVO> dataVO = deviceDataClient.pageDeviceCodeAndSignages(dataDTO); Result<ReductionDataVO> dataVO = deviceDataClient.pageDeviceCodeAndSignages(dataDTO);
Assert.isTrue(dataVO.isSuccess(),() -> { Assert.isTrue(dataVO.isSuccess(),() -> {
throw new ServiceException("聚合历史数据查询失败!"); throw new ServiceException("聚合历史数据查询失败!");

5
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java

@ -50,6 +50,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -229,12 +230,14 @@ public class InteractiveServiceImpl implements IInteractiveService {
params.put("ids",Func.toStrList(",",sessionIds).toArray()); params.put("ids",Func.toStrList(",",sessionIds).toArray());
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus()) HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus())
.body(JSON.toJSONString(params)).execute(); .body(JSON.toJSONString(params)).execute();
logger.info("interactive:getAnswerBySessionIds","获取答案:" + response.body());
Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> {
throw new ServiceException("远程调用大模型【获取问题答案】接口失败!"); throw new ServiceException("远程调用大模型【获取问题答案】接口失败!");
}); });
XxlJobLogger.log("接收到答案:"+JSON.toJSONString(response.body())); XxlJobLogger.log("接收到答案:"+JSON.toJSONString(response.body()));
List<AnswerVO> result = JSONArray.parseArray(response.body(), AnswerVO.class); List<AnswerVO> result = JSONArray.parseArray(response.body(), AnswerVO.class);
if(CollectionUtil.isNotEmpty(result)) {
logger.info("interactive:getAnswerBySessionIds","获取答案:" + response.body());
}
result.stream().filter(answerVO -> answerVO.getRunning() == 0).forEach(answerVO -> { result.stream().filter(answerVO -> answerVO.getRunning() == 0).forEach(answerVO -> {
Object[] extras = answerVO.getExtras(); Object[] extras = answerVO.getExtras();
if(ObjectUtil.isEmpty(answerVO.getExtras()) || extras.length == 0){ if(ObjectUtil.isEmpty(answerVO.getExtras()) || extras.length == 0){

Loading…
Cancel
Save