Browse Source

add:向量配置,月报评价

zhongwei
luyie 3 months ago
parent
commit
fe5855cbab
  1. 3
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/entity/RunMonthEntity.java
  2. 6
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/VectorParamController.java
  3. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/VectorParamService.java
  4. 119
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/VectorParamServiceImpl.java
  5. 13
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/RunMonthController.java
  6. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/RunMonthService.java
  7. 56
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java
  8. 13
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/vo/RunMonthEvaluateVO.java

3
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/report/entity/RunMonthEntity.java

@ -44,4 +44,7 @@ public class RunMonthEntity extends TenantEntity {
@ApiModelProperty("分析结果")
private String analyseResult;
@ApiModelProperty("评价")
private String evaluation;
}

6
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/VectorParamController.java

@ -107,11 +107,11 @@ public class VectorParamController {
return R.data(vectorParamService.getUrlResponseKeyList(url, bladeToken, hzinfoToken));
}
@PutMapping("/synchronization")
@PutMapping("/synchronization/{id}")
@ApiOperation(value = "同步")
@ApiOperationSupport(order = 10)
public R synchronization(@RequestHeader(name = "Blade-Auth", value = "Blade-Auth", required = false) String bladeToken,
@RequestHeader(name = "Hzinfo-Auth", value = "Hzinfo-Auth", required = false) String hzinfoToken) throws JsonProcessingException {
return R.status(vectorParamService.synchronization(bladeToken, hzinfoToken));
@RequestHeader(name = "Hzinfo-Auth", value = "Hzinfo-Auth", required = false) String hzinfoToken, @PathVariable Long id) throws JsonProcessingException {
return R.status(vectorParamService.synchronization(id, bladeToken, hzinfoToken));
}
}

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/VectorParamService.java

@ -18,5 +18,5 @@ public interface VectorParamService extends IService<VectorParamEntity> {
List<String> getUrlResponseKeyList(String url, String bladeToken, String hzinfoToken);
Boolean synchronization(String bladeToken, String hzinfoToken);
Boolean synchronization(Long id ,String bladeToken, String hzinfoToken);
}

119
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/impl/VectorParamServiceImpl.java

@ -5,6 +5,7 @@ import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
@ -16,7 +17,6 @@ import com.hnac.hzims.bigmodel.maintenance.service.VectorParamService;
import com.hnac.hzims.bigmodel.maintenance.vo.VectorUrlResponse;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
@ -49,59 +49,57 @@ public class VectorParamServiceImpl extends ServiceImpl<VectorParamMapper, Vecto
.header("Hzinfo-Auth", hzinfoToken).execute();
if (response.getStatus() == HttpServletResponse.SC_OK) {
String body = response.body();
log.info("getUrlResponse:" + body);
JSONObject jsonObject = JSON.parseObject(body);
VectorUrlResponse result = new VectorUrlResponse();
result.setOriginalData(JSONArray.parseArray(jsonObject.getString("data")).toJavaList(JSONObject.class));
// try {
// ObjectMapper mapper = new ObjectMapper();
// JsonNode rootNode = mapper.readTree(body);
// if (rootNode.isArray()) {
// return getUrlResponseByArray(rootNode);
// }
// JsonNode dataNode = rootNode.findValue("data");
// if (dataNode != null && dataNode.isArray()) {
// return getUrlResponseByArray(dataNode);
// }
// if (dataNode != null) {
// return getUrlResponseByObject(dataNode);
// }
// if (rootNode != null) {
// return getUrlResponseByObject(rootNode);
// }
// } catch (JsonProcessingException e) {
// log.error("getUrlResponse error", e);
// }
try {
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readTree(body);
if (rootNode.isArray()) {
return getUrlResponseByArray(rootNode);
}
JsonNode dataNode = rootNode.findValue("data");
if (dataNode != null && dataNode.isArray()) {
return getUrlResponseByArray(dataNode);
}
if (dataNode != null) {
return getUrlResponseByObject(dataNode);
}
if (rootNode != null) {
return getUrlResponseByObject(rootNode);
}
} catch (JsonProcessingException e) {
log.error("getUrlResponse error", e);
}
}
return null;
}
// private VectorUrlResponse getUrlResponseByArray(JsonNode rootNode) throws JsonProcessingException {
// VectorUrlResponse result = new VectorUrlResponse();
// result.setOriginalData(rootNode);
// JsonNode item = rootNode.get(0);
// if (item != null) {
// List<String> keyList = new ArrayList<>();
// Iterator<String> iterator = item.fieldNames();
// while (iterator.hasNext()) {
// keyList.add(iterator.next());
// }
// result.setKeyList(keyList);
// }
// return result;
// }
private VectorUrlResponse getUrlResponseByArray(JsonNode rootNode) throws JsonProcessingException {
VectorUrlResponse result = new VectorUrlResponse();
result.setOriginalData(JSONArray.parseArray(rootNode.toPrettyString()).toJavaList(JSONObject.class));
JsonNode item = rootNode.get(0);
if (item != null) {
List<String> keyList = new ArrayList<>();
Iterator<String> iterator = item.fieldNames();
while (iterator.hasNext()) {
keyList.add(iterator.next());
}
result.setKeyList(keyList);
}
return result;
}
// private VectorUrlResponse getUrlResponseByObject(JsonNode rootNode) throws JsonProcessingException {
// VectorUrlResponse result = new VectorUrlResponse();
// result.setOriginalData(rootNode);
// List<String> keyList = new ArrayList<>();
// Iterator<String> iterator = rootNode.fieldNames();
// while (iterator.hasNext()) {
// keyList.add(iterator.next());
// }
// result.setKeyList(keyList);
// return result;
// }
private VectorUrlResponse getUrlResponseByObject(JsonNode rootNode) throws JsonProcessingException {
VectorUrlResponse result = new VectorUrlResponse();
List<JSONObject> originalData = new ArrayList<>();
originalData.add(JSON.parseObject(rootNode.toPrettyString()));
result.setOriginalData(originalData);
List<String> keyList = new ArrayList<>();
Iterator<String> iterator = rootNode.fieldNames();
while (iterator.hasNext()) {
keyList.add(iterator.next());
}
result.setKeyList(keyList);
return result;
}
@Override
public List<String> getUrlResponseKeyList(String url, String bladeToken, String hzinfoToken) {
@ -110,12 +108,11 @@ public class VectorParamServiceImpl extends ServiceImpl<VectorParamMapper, Vecto
}
@Override
public Boolean synchronization(String bladeToken, String hzinfoToken) {
List<VectorParamEntity> list = this.list();
if (CollectionUtil.isEmpty(list)) {
public Boolean synchronization(Long id, String bladeToken, String hzinfoToken) {
VectorParamEntity entity = getById(id);
if (null == entity) {
return false;
}
for (VectorParamEntity entity : list) {
VectorUrlResponse response = getUrlResponse(entity.getUrl(), bladeToken, hzinfoToken);
if (response != null) {
ObjectMapper mapper = new ObjectMapper();
@ -131,24 +128,10 @@ public class VectorParamServiceImpl extends ServiceImpl<VectorParamMapper, Vecto
String key = iterator.next();
attrMap.put(key, rootNode.findValue(key).textValue());
}
List<Object> dataList = new ArrayList();
JsonNode dataObject = (JsonNode) response.getOriginalData();
if (dataObject.isArray()) {
Iterator<JsonNode> dataIterator = dataObject.iterator();
while (dataIterator.hasNext()) {
dataList.add(toJsonObject(dataIterator.next()));
}
} else {
dataList.add(toJsonObject(dataObject));
}
weaviateService.saveBatch(response.getOriginalData(), entity.getTableName(), attrMap);
}
this.update(Wrappers.<VectorParamEntity>lambdaUpdate().eq(VectorParamEntity::getId, id).set(VectorParamEntity::getUpdateTime, new Date()));
}
return true;
}
private JSONObject toJsonObject(JsonNode node) {
JSONObject jsonObject = JSON.parseObject(node.toString());
return jsonObject;
}
}

13
hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/controller/RunMonthController.java

@ -3,15 +3,13 @@ package com.hnac.hzims.operational.report.controller;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzims.operational.report.entity.RunMonthEntity;
import com.hnac.hzims.operational.report.service.RunMonthService;
import com.hnac.hzims.operational.report.vo.RunMonthEvaluateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
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.*;
/**
* @author ysj
@ -63,4 +61,11 @@ public class RunMonthController {
runMonthService.generateAnalyseResult(month, stationCode);
return R.success("调用成功!");
}
@PutMapping("/evaluate")
@ApiOperation(value = "站点月报评价", notes = "站点月报评价")
@ApiOperationSupport(order = 6)
public R evaluate(@RequestBody RunMonthEvaluateVO req) {
return R.data(runMonthService.evaluate(req.getId(), req.getText()));
}
}

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/RunMonthService.java

@ -24,4 +24,6 @@ public interface RunMonthService extends IService<RunMonthEntity> {
* @return 大模型调用结果
*/
Boolean generateAnalyseResult(String month,String stationCode);
Boolean evaluate(Long id, String text);
}

56
hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java

@ -108,6 +108,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 查询站点月报运行数据
*
* @param mon
* @param stationCode
* @return
@ -123,7 +124,8 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
}
RunDataShowVo data = new RunDataShowVo();
BeanUtil.copyProperties(entity, data);
List<RunDataVo> runs = JSONObject.parseObject(entity.getRunData(),new TypeReference<List<RunDataVo>>(){});
List<RunDataVo> runs = JSONObject.parseObject(entity.getRunData(), new TypeReference<List<RunDataVo>>() {
});
if (CollectionUtil.isEmpty(runs)) {
return data;
}
@ -156,9 +158,9 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
}
/**
* 导出站点月报文件
*
* @param mon
* @param stationCode
*/
@ -174,7 +176,8 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
if (ObjectUtil.isEmpty(data)) {
throw new ServiceException("站点" + mon + "月份未生成运行月报数据!");
}
List<RunDataVo> runs = JSONObject.parseObject(data.getRunData(),new TypeReference<List<RunDataVo>>(){});
List<RunDataVo> runs = JSONObject.parseObject(data.getRunData(), new TypeReference<List<RunDataVo>>() {
});
if (CollectionUtil.isNotEmpty(runs)) {
// 保留两位小数
data.setRunData(JSONObject.toJSONString(runs.stream().map(run -> {
@ -210,6 +213,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 生成站点月报
*
* @param mon
* @param stationCode
* @return
@ -297,6 +301,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 调用大模型分析月报接口
*
* @param mon 月报月份
* @param stationCode 月报站号
*/
@ -329,6 +334,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 填充大模型分析所需数据格式
*
* @param req 月报数据
* @param analyseVOList 大模型分析对象
* @param month 查询月报筛选条件
@ -385,6 +391,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 创建大模型分析所需对象
*
* @param deviceName 设备名称
* @param month 对象月份
* @param deviceOrder 设备序号
@ -443,6 +450,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 先删除原先月报数据
*
* @param mon
* @param stationCode
*/
@ -459,6 +467,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 运行数据
*
* @param devices
* @return
*/
@ -491,6 +500,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 实际发电量
*
* @param type
* @param deviceCode
* @param ride
@ -512,6 +522,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 计划发电量
*
* @param type
* @param stationCode
* @param plans
@ -536,6 +547,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 获取运行数据
*
* @param device
* @return
*/
@ -557,6 +569,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 获取时间范围内运行时长
*
* @param realId
* @param startDate
* @param endDate
@ -581,6 +594,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 获取运行时长
*
* @param result
* @return
*/
@ -614,6 +628,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 告警数据
*
* @param code
* @return
*/
@ -627,6 +642,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 查询hz3000告警
*
* @param code
*/
private List<RunAlarmVo> hz3000Alarm(String code, String start, String end) {
@ -654,6 +670,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 智能预警
*
* @param code
* @param start
* @param end
@ -685,6 +702,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 运行曲线
*
* @param devices
* @return
*/
@ -703,11 +721,10 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 获取曲线数据
*
* @param attributes
* @param deviceCode
* @return
*
*
*/
private List<EchartVo> curve(List<AttributeVo> attributes, String start, String end, String deviceCode) {
List<AnalyzeDataConditionVO> datas = dataService.periodTargetSignages(start, end, 3, 3, deviceCode, attributes.stream().map(AttributeVo::getSignage).collect(Collectors.toList()));
@ -756,6 +773,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 曲线属性获取
*
* @param attributeType
* @return
*/
@ -820,6 +838,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 检查站点是否存在设备信息
*
* @param stationCode
* @return
*/
@ -848,8 +867,14 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
return true;
}
@Override
public Boolean evaluate(Long id, String text) {
return this.update(Wrappers.<RunMonthEntity>lambdaUpdate().set(RunMonthEntity::getEvaluation, text).eq(RunMonthEntity::getId, id));
}
/**
* 手绘运行数据表格
*
* @return
*/
private Workbook drawBook(String headerName, RunMonthEntity entity) {
@ -906,6 +931,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 绘制机组曲线
*
* @param hssWB
* @param rowNumber
* @param data
@ -919,7 +945,8 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
sheet.addMergedRegion(region);
return rowNumber + 1;
}
List<CurveEchartVo> curves = JSONObject.parseObject(data,new TypeReference<List<CurveEchartVo>>(){});
List<CurveEchartVo> curves = JSONObject.parseObject(data, new TypeReference<List<CurveEchartVo>>() {
});
if (CollectionUtil.isEmpty(curves)) {
// 绘制空表格
this.emptyRow(hssWB, sheet, rowNumber);
@ -941,6 +968,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 绘制曲线
*
* @param loadCurve
* @param rowNumber
*/
@ -1000,6 +1028,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 曲线转数组对象
*
* @param curves
* @return
*/
@ -1024,6 +1053,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 运行数据分析填充
*
* @param hssWB
* @param sheet
* @param rowNumber
@ -1053,6 +1083,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 运行建议及其他填充
*
* @param hssWB
* @param sheet
* @param rowNumber
@ -1081,6 +1112,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 设置头部
*
* @param hssWB
* @param sheet
*/
@ -1098,6 +1130,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 设置标题表头
*
* @param hssWB
* @param sheet
*/
@ -1114,6 +1147,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 运行数据表头绘制
*
* @param hssWB
* @param sheet
*/
@ -1142,6 +1176,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 运行数据填充
*
* @param hssWB
* @param sheet
* @param rowNumber
@ -1156,7 +1191,8 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
sheet.addMergedRegion(region);
return rowNumber + 1;
}
List<RunDataVo> runData = JSONObject.parseObject(data,new TypeReference<List<RunDataVo>>(){});
List<RunDataVo> runData = JSONObject.parseObject(data, new TypeReference<List<RunDataVo>>() {
});
if (CollectionUtil.isEmpty(runData)) {
// 绘制空表格
this.emptyRow(hssWB, sheet, rowNumber);
@ -1227,6 +1263,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 绘制空表格
*
* @param hssWB
* @param sheet
* @param rowNumber
@ -1257,6 +1294,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 告警数据表头绘制
*
* @param hssWB
* @param sheet
*/
@ -1285,6 +1323,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
/**
* 告警数据填充
*
* @param hssWB
* @param sheet
* @param rowNumber
@ -1299,7 +1338,8 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
sheet.addMergedRegion(region);
return rowNumber + 1;
}
List<RunAlarmVo> runAlarm = JSONObject.parseObject(data,new TypeReference<List<RunAlarmVo>>(){});
List<RunAlarmVo> runAlarm = JSONObject.parseObject(data, new TypeReference<List<RunAlarmVo>>() {
});
if (CollectionUtil.isEmpty(runAlarm)) {
// 绘制空表格
this.emptyRow(hssWB, sheet, rowNumber);

13
hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/vo/RunMonthEvaluateVO.java

@ -0,0 +1,13 @@
package com.hnac.hzims.operational.report.vo;
import lombok.Data;
/**
* @Author: ypj
* @Date: 2024/9/6 14:50
*/
@Data
public class RunMonthEvaluateVO {
private String text;
private Long id;
}
Loading…
Cancel
Save