Browse Source

Merge remote-tracking branch 'origin/prod-5.1.3' into prod-5.1.3

zhongwei
ty 5 months ago
parent
commit
0c4047d482
  1. 5
      hzims-biz-common/src/main/java/com/hnac/hzims/common/service/UserAuthDataService.java
  2. 21
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/wrapper/BaseSyncWrapper.java
  3. 3
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/PowerDataDTO.java
  4. 23
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/database/entity/WeaviateEntity.java
  5. 2
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/ControlEntity.java
  6. 2
      hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/obj/entity/ObjectEntity.java
  7. 5
      hzims-service/hzims-big-model/pom.xml
  8. 4
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/DataAnalyseClient.java
  9. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/controller/DataSourceExecuteController.java
  10. 6
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/controller/RemoteController.java
  11. 6
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java
  12. 21
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/wrapper/CanvasSyncWrapper.java
  13. 5
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeApi.java
  14. 56
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfigure.java
  15. 32
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateProperties.java
  16. 252
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java
  17. 11
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/util/WeaviateUtil.java
  18. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java
  19. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java
  20. 28
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java
  21. 40
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/SyncPropertyEntity.java
  22. 6
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java
  23. 2
      hzims-service/hzims-big-model/src/main/resources/template/template.yml
  24. 2
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/mapper/ObjectTemplateMapper.xml
  25. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/report/service/impl/RunMonthServiceImpl.java
  26. 28
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/aspect/VideoSyncAspect.java
  27. 38
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/wrapper/VideoSyncWrapper.java
  28. 12
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainPlanServiceImpl.java
  29. 2
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java

5
hzims-biz-common/src/main/java/com/hnac/hzims/common/service/UserAuthDataService.java

@ -1,9 +1,11 @@
package com.hnac.hzims.common.service;
import com.hnac.hzims.common.constant.CommonConstant;
import com.hnac.hzims.common.logs.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.http.HttpStatus;
@ -22,6 +24,9 @@ public class UserAuthDataService {
* @return
*/
public String getUserAuthDataSQL(Long userId) {
if(CommonConstant.SYSTEM_USER.equals(userId)) {
return "";
}
R<User> r = userClient.userInfoById(userId);
String sqlScript = null;
if(r.getCode() != HttpStatus.OK.value() || r.getData() == null) {

21
hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/wrapper/BaseSyncWrapper.java

@ -0,0 +1,21 @@
package com.hnac.hzims.bigmodel.api.wrapper;
import com.hnac.hzims.bigmodel.api.dto.SyncDTO;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author: huangxing
* @Date: 2024/08/20 09:23
* @Describe 对象转换为同步对象基础类
*/
public abstract class BaseSyncWrapper<O,S extends SyncDTO> {
public abstract S convert(O obj);
public List<S> listVO(List<O> list) {
return list.stream().map(this::convert).collect(Collectors.toList());
}
}

3
hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/PowerDataDTO.java

@ -28,4 +28,7 @@ public class PowerDataDTO implements Serializable {
@ApiModelProperty("发电单位")
private String unit = "万kWh";
@ApiModelProperty("运行时长单位")
private String runtimeUnit = "h";
}

23
hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/database/entity/WeaviateEntity.java

@ -0,0 +1,23 @@
package com.hnac.hzims.bigmodel.database.entity;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
/**
* @Author: huangxing
* @Date: 2024/08/22 19:35
*/
@Data
@EqualsAndHashCode
public class WeaviateEntity implements Serializable {
@JSONField(name = "item_id")
private String itemId;
@JSONField(name = "item_name")
private String itemName;
}

2
hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/ControlEntity.java

@ -26,7 +26,7 @@ public class ControlEntity extends TenantEntity implements Serializable {
@ApiModelProperty(value = "itemId",required = true)
private String itemId;
@ApiModelProperty(value = "站点名称",required = true)
@ApiModelProperty(value = "站点名称")
@QueryField(condition = SqlCondition.LIKE)
private String stationName;

2
hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/obj/entity/ObjectEntity.java

@ -49,7 +49,7 @@ public class ObjectEntity extends TenantEntity {
* 地理位置
*/
@ApiModelProperty(value = "地理位置,长度必须为1到128")
@Size(min=1,max = 128,message ="地理位置长度必须为1到128")
// @Size(min=1,max = 128,message ="地理位置长度必须为1到128")
private String address;
/**
* 经度(东经)

5
hzims-service/hzims-big-model/pom.xml

@ -83,6 +83,11 @@
<artifactId>oapi-java-sdk</artifactId>
<version>release-V4-2.0.2</version>
</dependency>
<dependency>
<groupId>io.weaviate</groupId>
<artifactId>client</artifactId>
<version>4.7.0</version>
</dependency>
</dependencies>
<build>

4
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/DataAnalyseClient.java

@ -1,9 +1,11 @@
package com.hnac.hzims.bigmodel.api.feign;
import com.alibaba.fastjson.JSON;
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 lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.RestController;
@ -15,12 +17,14 @@ import java.util.List;
*/
@RestController
@AllArgsConstructor
@Slf4j
public class DataAnalyseClient implements IDataAnalyseClient {
private final IHznlmInvokeService invokeService;
@Override
public R smartReportGeneratePower(RunReportAnalyseRequest req) {
log.info("获取运行月报告传参详情为:{}", JSON.toJSONString(req));
invokeService.smartReportGeneratePower(req);
return R.success("发起问答成功");
}

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/DataSourceExecuteController.java → hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/controller/DataSourceExecuteController.java

@ -1,4 +1,4 @@
package com.hnac.hzims.bigmodel.business.control;
package com.hnac.hzims.bigmodel.business.controller;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzims.bigmodel.business.service.DataSourceService;

6
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/RemoteController.java → hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/controller/RemoteController.java

@ -1,7 +1,6 @@
package com.hnac.hzims.bigmodel.business.control;
package com.hnac.hzims.bigmodel.business.controller;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzims.bigmodel.BigModelConstants;
import com.hnac.hzims.bigmodel.business.service.RemoteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -9,6 +8,7 @@ import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.system.dto.ControlDTO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -27,7 +27,7 @@ public class RemoteController {
@ApiOperation("下发遥控指令")
@ApiOperationSupport(order = 1)
@PostMapping("/sendRemoteControl")
public R<Object> sendRemoteControl(ControlDTO controlDTO) {
public R<Object> sendRemoteControl(@RequestBody ControlDTO controlDTO) {
return remoteService.sendRemoteControl(controlDTO);
}

6
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java

@ -58,11 +58,15 @@ public class DataSourceService {
throw new HzServiceException(ResultCode.FAILURE,"查询语句中存在未进行鉴权的表,查询失败!");
});
if("1".equals(propertise.get(0).getAuthType())) {
String tableSubStr = "(SELECT * FROM " + tableAuthVO.getTableName() + " where" + userAuthDataSQL +") temp";
String tableSubStr = "(SELECT * FROM " + tableAuthVO.getTableName() + " where is_deleted = 0 and " + userAuthDataSQL +") temp";
sql = sql.replace(tableAuthVO.getTableName(),tableSubStr);
} else {
String tableSubStr = "(SELECT * FROM " + tableAuthVO.getTableName() + " where is_deleted = 0) temp";
sql = sql.replace(tableAuthVO.getTableName(),tableSubStr);
}
}
}
sql = sql.replaceAll("&gt;", ">").replaceAll("&lt;", "<");
log.info("执行sql:{}",sql);
return this.queryListOnSpecificDataSource(sql, sqlVO.getTableAuthVOList().get(0).getDatasourceName());
}

21
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/wrapper/CanvasSyncWrapper.java

@ -0,0 +1,21 @@
package com.hnac.hzims.bigmodel.business.wrapper;
import com.hnac.hzims.bigmodel.api.dto.CanvasSyncDTO;
import com.hnac.hzims.bigmodel.api.wrapper.BaseSyncWrapper;
import com.hnac.hzinfo.sdk.v5.scada.vo.CanvasVO;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
/**
* @Author: huangxing
* @Date: 2024/08/20 16:49
*/
@Component
@AllArgsConstructor
public class CanvasSyncWrapper extends BaseSyncWrapper<CanvasVO, CanvasSyncDTO> {
@Override
public CanvasSyncDTO convert(CanvasVO obj) {
return null;
}
}

5
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeApi.java

@ -62,4 +62,9 @@ public class BigModelInvokeApi {
*/
private String updateKnowledge;
/**
* 计算向量
*/
private String compute;
}

56
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfigure.java

@ -0,0 +1,56 @@
package com.hnac.hzims.bigmodel.configuration;
import io.weaviate.client.Config;
import io.weaviate.client.WeaviateAuthClient;
import io.weaviate.client.WeaviateClient;
import io.weaviate.client.v1.auth.exception.AuthException;
import io.weaviate.client.v1.data.api.ObjectCreator;
import io.weaviate.client.v1.data.api.ObjectDeleter;
import io.weaviate.client.v1.data.api.ObjectUpdater;
import io.weaviate.client.v1.data.api.ObjectsGetter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @Author: huangxing
* @Date: 2024/08/22 18:38
*/
@Configuration
public class WeaviateConfigure {
private final WeaviateProperties weaviateProperties;
public WeaviateConfigure(WeaviateProperties weaviateProperties) {
this.weaviateProperties = weaviateProperties;
}
@Bean
public WeaviateClient weaviateClient() throws AuthException {
Config config = new Config(this.weaviateProperties.getSchema(), this.weaviateProperties.getHost() + ":" + this.weaviateProperties.getPort());
return WeaviateAuthClient.apiKey(config,this.weaviateProperties.getApiKey());
}
@Bean
public ObjectsGetter objectsGetter() throws AuthException {
WeaviateClient weaviateClient = weaviateClient();
return weaviateClient.data().objectsGetter();
}
@Bean
public ObjectCreator objectCreator() throws AuthException {
WeaviateClient weaviateClient = weaviateClient();
return weaviateClient.data().creator();
}
@Bean
public ObjectDeleter deleter() throws AuthException {
WeaviateClient weaviateClient = weaviateClient();
return weaviateClient.data().deleter();
}
@Bean
public ObjectUpdater updater() throws AuthException {
WeaviateClient weaviateClient = weaviateClient();
return weaviateClient.data().updater();
}
}

32
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateProperties.java

@ -0,0 +1,32 @@
package com.hnac.hzims.bigmodel.configuration;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @Author: huangxing
* @Date: 2024/08/21 15:22
*/
@Data
@Component
@ConfigurationProperties(prefix = "weaviate.datasource")
public class WeaviateProperties {
private String schema;
private String host;
private String port;
/**
* 登录认证KEY
*/
private String apiKey;
/**
* 数据库表名前缀
*/
private String classNamePrefix;
}

252
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java

@ -0,0 +1,252 @@
package com.hnac.hzims.bigmodel.database.service;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.hnac.hzims.bigmodel.configuration.BigModelInvokeApi;
import com.hnac.hzinfo.exception.HzServiceException;
import io.weaviate.client.base.Result;
import io.weaviate.client.v1.data.api.ObjectCreator;
import io.weaviate.client.v1.data.api.ObjectDeleter;
import io.weaviate.client.v1.data.api.ObjectUpdater;
import io.weaviate.client.v1.data.api.ObjectsGetter;
import io.weaviate.client.v1.data.model.WeaviateObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* @Author: huangxing
* @Date: 2024/08/22 19:17
*/
@RequiredArgsConstructor
@Service
@Slf4j
public class WeaviateService {
private final ObjectCreator objectCreator;
private final ObjectUpdater objectUpdater;
private final ObjectDeleter objectDeleter;
private final ObjectsGetter objectsGetter;
private final BigModelInvokeApi invokeApi;
@Value("${gglm.vectorUrl}")
private String vectorUrl;
/**
* 对象保存向量数据库
* @param entity 保存对象
* @param className 保存表名
* @param attrs 待计算的列信息
* @return 保存操作结果
*/
public Boolean save(Object entity, String className, List<String> attrs) {
ObjectCreator creator = objectCreator.withClassName(className);
if(Func.isNotEmpty(attrs)) {
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(entity));
List<String> vectors = attrs.stream().map(attr -> jsonObject.getString(attr)).collect(Collectors.toList());
Float[] compute = this.compute(vectors);
creator.withVector(compute);
}
Result<WeaviateObject> result = creator.withProperties(BeanUtil.toMap(entity)).run();
return !result.hasErrors();
}
/**
* 对象批量保存向量数据库
* @param entities 保存对象列表
* @param className 保存表名
* @param attrsMap 待计算的列信息 key-向量名 value-实体类对象属性,多个按逗号分隔
* @return 保存操作结果
*/
public Boolean saveBatch(List entities,String className, Map<String,String> attrsMap) {
ObjectCreator creator = objectCreator.withClassName(className);
List<String> vectorStrs = Lists.newArrayList();
List<String> attrs = Lists.newArrayList();
if(Func.isNotEmpty(attrsMap)) {
// 格式化数据
attrsMap.forEach((k,v) -> attrs.add(v));
// 解析待计算的向量字段
entities.forEach(entity -> {
List<String> vectorStr = attrs.stream().map(fields -> this.getFieldValue(fields, entity)).filter(Func::isNotEmpty).collect(Collectors.toList());
vectorStrs.addAll(vectorStr);
});
}
if(Func.isNotEmpty(vectorStrs)) {
// 若解析出来的向量存在值
Float[] vectors = this.compute(vectorStrs);
List<Map<String, Float[]>> vector = this.splitVector(entities.size(), attrsMap, vectors);
for(int i = 0; i < entities.size(); i++) {
creator.withProperties(BeanUtil.toMap(entities.get(i))).withVectors(vector.get(i)).run();
}
} else {
entities.forEach(entity -> creator.withProperties(BeanUtil.toMap(entity)).run());
return true;
}
return false;
}
/**
* 删除向量数据库表名
* @param className 表名
* @return 删除结果
*/
public Boolean deleteByClassName(String className) {
Result<Boolean> result = objectDeleter.withClassName(className).run();
return !result.hasErrors();
}
/**
* 删除向量数据库ID
* @param id 向量数据库ID
* @return 删除结果
*/
public Boolean deleteById(String id) {
Result<Boolean> result = objectDeleter.withID(id).run();
return !result.hasErrors();
}
/**
* 更新数据库通过ID
* @param id 向量数据库ID
* @return 更新结果
*/
public Boolean updateById(String id, Object entity, String className, Map<String,String> attrMap) {
ObjectUpdater updater = objectUpdater.withClassName(className).withID(id).withProperties(BeanUtil.toMap(entity));
// 计算向量
Map<String, Float[]> vector = new HashMap<>();
if(Func.isNotEmpty(attrMap)) {
attrMap.forEach((k,v) -> {
String fieldValue = this.getFieldValue(v, entity);
Float[] compute = this.compute(Lists.newArrayList(fieldValue));
vector.put(k,compute);
});
}
if(Func.isNotEmpty(vector)) {
updater.withVectors(vector);
}
Result<Boolean> result = updater.run();
return !result.hasErrors();
}
public List<Map> list(String id,String className) {
if(Func.isNotEmpty(id)) {
objectsGetter.withID(id);
}
if(Func.isNotEmpty(className)) {
objectsGetter.withClassName(className);
}
Result<List<WeaviateObject>> result = objectsGetter.run();
if(result.hasErrors()) {
throw new HzServiceException("查询失败!");
}
return result.getResult().stream().map(WeaviateObject::getProperties).collect(Collectors.toList());
}
/**
* 拆解计算出来的向量Float[]
* @param entitySize 对象列表size
* @param attrsMap 待计算的列信息 key-向量名 value-实体类对象属性,多个按逗号分隔
* @param vectorTotal 计算出的向量总量
* @return 拆解结果
*/
private List<Map<String,Float[]>> splitVector(Integer entitySize,Map<String,String> attrsMap,Float[] vectorTotal) {
List<Map<String,Float[]>> result = Lists.newArrayList();
List<Float> vectorTotalList = Lists.newArrayList(vectorTotal);
// 获取待切割的下标
List<Integer> indexes = this.getSplitIndex(vectorTotal.length, entitySize);
int step = vectorTotal.length / entitySize;
indexes.forEach(index -> {
List<Float> vectors = vectorTotalList.subList(index, index + step);
Map<String,Float[]> vectorMap = new HashMap<>();
List<Integer> splitIndex = this.getSplitIndex(vectors.size(), attrsMap.size());
AtomicInteger i = new AtomicInteger();
attrsMap.forEach((k,v) -> {
List<Float> vector = vectors.subList(splitIndex.get(i.get()), splitIndex.get(i.get() + (vectors.size() / attrsMap.size())));
vectorMap.put(k, vector.toArray(new Float[vector.size()]));
i.getAndIncrement();
});
});
return result;
}
/**
* 获取将list等量分隔成若干份的列表下标
* @param size 总数
* @param splitNum 分隔数量
* @return 下标集合
*/
private List<Integer> getSplitIndex(int size,int splitNum) {
if(size % splitNum != 0) {
throw new HzServiceException("向量计算失败,无法根据同步对象进行等量分隔!");
}
return IntStream.iterate(0, index -> index + 1)
.limit(splitNum)
.mapToObj(index -> index * (size / splitNum))
.collect(Collectors.toList());
}
private String getFieldValue(String fields,Object object) {
Class clazz = object.getClass();
return Func.toStrList(",", fields).stream().map(field -> {
try {
Field declaredField = clazz.getDeclaredField(field);
declaredField.setAccessible(true);
return declaredField.get(object).toString();
} catch (NoSuchFieldException | IllegalAccessException e) {
return null;
}
}).collect(Collectors.joining(" "));
}
/**
* 计算向量值
* @param vectors 待计算的向量
* @return 向量值Float[]
*/
private Float[] compute(List<String> vectors) {
// 向量计算
String url = vectorUrl + invokeApi.getCompute();
String jsonData = JSONUtil.toJsonStr(vectors);
HttpResponse response = HttpRequest.post(url)
.header("Content-Type", "application/json; charset=utf-8")
.body(jsonData)
.execute();
byte[] bytes = response.bodyBytes();
if (bytes.length % 4 != 0) {
throw new HzServiceException("向量计算失败!响应数据长度不是4的倍数");
}
List<byte[]> chunks = new ArrayList<>();
int range = bytes.length / 4;
IntStream.range(0, range)
.forEach(index -> {
byte[] chunk = new byte[4];
int page = index * 4;
chunk[0] = bytes[page];
chunk[1] = bytes[page + 1];
chunk[2] = bytes[page + 2];
chunk[3] = bytes[page + 3];
chunks.add(chunk);
});
List<Float> floats = chunks.stream().map(b -> {
ByteBuffer buffer = ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN);
return buffer.getFloat();
}).collect(Collectors.toList());
return floats.toArray(new Float[floats.size()]);
}
}

11
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/util/WeaviateUtil.java

@ -0,0 +1,11 @@
package com.hnac.hzims.bigmodel.database.util;
/**
* @Author: huangxing
* @Date: 2024/08/23 10:09
*/
public class WeaviateUtil {
}

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java

@ -64,7 +64,7 @@ public class FontEndInteractiveController {
@ApiOperationSupport(order = 5)
@GetMapping("/interruptSession")
public R interruptSession(@RequestParam(value = "id") String sessionId) {
hznlmInvokeService.askAbort(sessionId);
hznlmInvokeService.interruptSession(sessionId);
return R.success("操作成功!");
}
}

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java

@ -81,6 +81,8 @@ public interface IHznlmInvokeService {
*/
void askAbort(String sessionId);
void interruptSession(String sessionId);
/**
* 发起机组发电量智能报表分析问答
* @param req 待分析的数据

28
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java

@ -17,6 +17,7 @@ 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 com.hnac.hzinfo.exception.HzServiceException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
@ -126,6 +127,33 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
sessionRedisManager.removeSessionId(sessionId);
}
public void interruptSession(String sessionId) {
this.askAbort(sessionId);
// 循环获取该会话ID中断状态,当状态等于-2或重连超6次则中断返回结果
int status = 999;
int attempts = 0;
while (status > 0) {
// 若重连超过10次 则抛出错误
if(attempts >= 8) {
throw new HzServiceException("中断失败!长时间未获取到中断状态");
}
List<AnswerVO> answers = this.getAnswerBySessionIds(sessionId);
if(Func.isNotEmpty(answers)) {
log.info(answers.get(0).getStatus()+"");
status = answers.get(0).getStatus();
}
// 若获取到的状态不等于2 则延时0.5秒
if(status > 0) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
attempts ++;
}
}
@Override
public void smartReportGeneratePower(RunReportAnalyseRequest req) {
Map<String,Object> params = new HashMap<>();

40
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/SyncPropertyEntity.java

@ -0,0 +1,40 @@
package com.hnac.hzims.bigmodel.maintenance.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.core.tenant.mp.TenantEntity;
import java.io.Serializable;
/**
* @Author: huangxing
* @Date: 2024/08/21 08:33
*/
@Data
@EqualsAndHashCode
@ApiModel(value = "同步向量库基础配置",description = "同步向量库基础配置")
@TableName("")
public class SyncPropertyEntity extends TenantEntity implements Serializable {
@ApiModelProperty("配置编号")
private String code;
@ApiModelProperty("数据源")
private String datasource;
@ApiModelProperty("数据源名称")
private String datasourceName;
@ApiModelProperty("数据库表名")
private String tableName;
@ApiModelProperty("向量数据库表名,由小写字母以及_组成")
private String vectorTableName;
@ApiModelProperty("表描述")
private String tableDesc;
}

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

@ -20,17 +20,17 @@ public class TableColumnService {
private final DataSourceService dataSourceService;
public List<Map<String,Object>> getDatabase(String datasource) {
String sql = "select distinct `table_schema` as tableName from `information_schema`.`tables` where `table_schema` <> 'information_schema';";
String sql = "select distinct UPPER(`table_schema`) as tableName from `information_schema`.`tables` where `table_schema` <> 'information_schema';";
return dataSourceService.queryListOnSpecificDataSource(sql,datasource);
}
public List<Map<String, Object>> getTables(String datasource,String database) {
String sql = "select distinct `table_name` as tableName from `information_schema`.`tables` where `table_schema` = '" + database + "';";
String sql = "select distinct UPPER(`table_name`) as tableName from `information_schema`.`tables` where `table_schema` = '" + database + "';";
return dataSourceService.queryListOnSpecificDataSource(sql,datasource);
}
public List<Map<String, Object>> getColumns(String datasource,String database,String tableName) {
String sql = "select distinct `column_name` as columnName,`column_comment` as columnComment from `information_schema`.`COLUMNS` where `TABLE_SCHEMA` = '" + database + "' and `TABLE_NAME` = '" + tableName + "';";
String sql = "select distinct UPPER(`column_name`) as columnName,UPPER(`column_comment`) as columnComment from `information_schema`.`COLUMNS` where `TABLE_SCHEMA` = '" + database + "' and `TABLE_NAME` = '" + tableName + "';";
return dataSourceService.queryListOnSpecificDataSource(sql,datasource);
}

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

@ -49,6 +49,7 @@ spring:
gglm:
url: "http://${gglm.host}:${gglm.port}"
vectorUrl: "http://${vector.host}:${vector.port}"
api:
assistantAsk: "/qa/assistant_ask"
assistantStatus: "/qa/assistant_status"
@ -62,6 +63,7 @@ gglm:
smartReportGeneratePower: "/custom/smart_report_generate_power"
assistantAnalyseAsk: "/qa/assistant_analyse_ask"
updateKnowledge: "/kn/update_knowledge"
compute: "compute"
swagger:
base-packages: com.hnac.hzims.bigmodel

2
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/mapper/ObjectTemplateMapper.xml

@ -3,7 +3,7 @@
<mapper namespace="com.hnac.hzinfo.inspect.obj.mapper.ObjectTemplateMapper">
<select id="getListByObjectId" resultType="com.hnac.hzinfo.inspect.obj.entity.ObjectTemplateEntity">
SELECT t.id,o.code,o.name,o.SUPPORT_AUTO_VIDEO,t.template_id,t.object_id
SELECT distinct t.id,o.code,o.name,o.SUPPORT_AUTO_VIDEO,t.template_id,t.object_id
from hz_st_re_object_template t
left JOIN hz_st_re_template o on (t.template_id=o.id)
left join hz_st_re_template_project p on o.id = p.template_id

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

@ -369,7 +369,7 @@ public class RunMonthServiceImpl extends ServiceImpl<RunMonthMapper, RunMonthEnt
// 告警信息
List<SoeDataDTO> soeDataDTOS = alarms.stream().filter(a -> deviceName.equals(a.getDeviceName())).map(alarm -> {
SoeDataDTO soeDataDTO = new SoeDataDTO();
soeDataDTO.setDate(month);
soeDataDTO.setDate(req.getMonth());
soeDataDTO.setName(alarm.getContent());
soeDataDTO.setTimes(alarm.getCount());
return soeDataDTO;

28
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/aspect/AddVideoAspect.java → hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/aspect/VideoSyncAspect.java

@ -5,24 +5,17 @@ import com.google.common.collect.Lists;
import com.hnac.hzims.bigmodel.api.constants.MqttTopicConstants;
import com.hnac.hzims.bigmodel.api.dto.VideoSyncDTO;
import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity;
import com.hnac.hzims.operational.station.feign.IStationClient;
import com.hnac.hzims.operational.station.service.IStationService;
import com.hnac.hzims.operational.station.vo.StationVO;
import com.hnac.hzims.operational.station.wrapper.VideoSyncWrapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.mqtt.producer.IMqttSender;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @Author: huangxing
@ -32,9 +25,9 @@ import java.util.stream.Collectors;
@Component
@AllArgsConstructor
@Slf4j
public class AddVideoAspect {
public class VideoSyncAspect {
private final IStationService stationService;
private final VideoSyncWrapper wrapper;
private final IMqttSender mqttSender;
@Pointcut("execution(* com.hnac.hzims.operational.station.service.IStationVideoTypeService.saveBatch(..)) " +
@ -51,26 +44,15 @@ public class AddVideoAspect {
if(args.length == 1) {
Object arg = args[0];
if(arg instanceof StationVideoTypeEntity) {
List<VideoSyncDTO> videoSyncDTOS = Lists.newArrayList(this.convert((StationVideoTypeEntity) arg));
List<VideoSyncDTO> videoSyncDTOS = Lists.newArrayList(wrapper.convert((StationVideoTypeEntity) arg));
mqttSender.sendToMqtt(MqttTopicConstants.TOPIC_VIDEO_INSERT, JSON.toJSONString(videoSyncDTOS));
}
else if(arg instanceof List) {
List<StationVideoTypeEntity> videoList = (List<StationVideoTypeEntity>) args[0];
List<VideoSyncDTO> videoSyncDTOS = videoList.stream().map(this::convert).collect(Collectors.toList());
List<VideoSyncDTO> videoSyncDTOS = wrapper.listVO(videoList);
mqttSender.sendToMqtt(MqttTopicConstants.TOPIC_VIDEO_INSERT, JSON.toJSONString(videoSyncDTOS));
}
}
}
private VideoSyncDTO convert(StationVideoTypeEntity entity) {
VideoSyncDTO videoSyncDTO = BeanUtil.copy(entity,VideoSyncDTO.class);
StationVO station = stationService.getStationByCode(entity.getStationId());
String stationName = Optional.ofNullable(station).map(StationVO::getName).orElse("");
videoSyncDTO.setId(String.valueOf(entity.getId()));
videoSyncDTO.setItemId(String.valueOf(entity.getId()));
videoSyncDTO.setStationName(stationName);
videoSyncDTO.setItemName(stationName + " " + videoSyncDTO.getName());
return videoSyncDTO;
}
}

38
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/wrapper/VideoSyncWrapper.java

@ -0,0 +1,38 @@
package com.hnac.hzims.operational.station.wrapper;
import com.hnac.hzims.bigmodel.api.dto.VideoSyncDTO;
import com.hnac.hzims.bigmodel.api.wrapper.BaseSyncWrapper;
import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity;
import com.hnac.hzims.operational.station.service.IStationService;
import com.hnac.hzims.operational.station.vo.StationVO;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.SpringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Optional;
/**
* @Author: huangxing
* @Date: 2024/08/20 11:21
*/
@Component
@AllArgsConstructor
public class VideoSyncWrapper extends BaseSyncWrapper<StationVideoTypeEntity, VideoSyncDTO> {
private final IStationService stationService;
@Override
public VideoSyncDTO convert(StationVideoTypeEntity entity) {
VideoSyncDTO videoSyncDTO = BeanUtil.copy(entity,VideoSyncDTO.class);
StationVO station = stationService.getStationByCode(entity.getStationId());
String stationName = Optional.ofNullable(station).map(StationVO::getName).orElse("");
videoSyncDTO.setId(String.valueOf(entity.getId()));
videoSyncDTO.setItemId(String.valueOf(entity.getId()));
videoSyncDTO.setStationName(stationName);
videoSyncDTO.setItemName(stationName + " " + videoSyncDTO.getName());
return videoSyncDTO;
}
}

12
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/TrainPlanServiceImpl.java

@ -20,6 +20,7 @@ import com.hnac.hzims.safeproduct.service.ITrainPlanService;
import com.hnac.hzims.safeproduct.service.ITrainRecordService;
import com.hnac.hzims.safeproduct.vo.TrainMonthVO;
import com.hnac.hzims.safeproduct.vo.TrainYearVO;
import org.apache.commons.collections4.map.HashedMap;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.utils.DateUtil;
@ -34,10 +35,7 @@ import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -105,7 +103,7 @@ public class TrainPlanServiceImpl extends ServiceImpl<TrainPlanMapper, TrainPlan
// 查询各单位全年已完成的培训计划数
List<AnalysisYearDTO> unitMonthDataList = baseMapper.selectFinishedDataByUnit(unitList, year);
// 将各单位每个月的培训计划数据写入统计列表
List<TrainYearVO> res = new ArrayList<>();
HashedMap<String, TrainYearVO> map = new HashedMap<>();
unitMonthDataList.forEach(data -> {
TrainYearVO trainYearVO = records.stream().filter(x -> x.getUnit().equals(data.getUnit()))
.collect(Collectors.toList()).get(0);
@ -161,9 +159,11 @@ public class TrainPlanServiceImpl extends ServiceImpl<TrainPlanMapper, TrainPlan
trainYearVO.setSum(sum + data.getFinishedNum());
}
if (trainYearVO.getSum() != 0) {
res.add(trainYearVO);
map.put(trainYearVO.getUnit(), trainYearVO);
}
});
List<TrainYearVO> list = new ArrayList<>(map.values());
List<TrainYearVO> res = list.stream().sorted(Comparator.comparing(TrainYearVO::getUnit)).collect(Collectors.toList());
unitPage.setRecords(res);
return unitPage;
}

2
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/utils/BaseUtil.java

@ -240,7 +240,7 @@ public class BaseUtil {
String encodeName = URLEncoder.encode(name, "UTF-8").replaceAll("\\+", "%20");
String prefixString = url.substring(0, url.lastIndexOf("/") + 1);
String encodeUrl = prefixString + encodeName;
String id = paragraph.getDocument().getPackagePart().addExternalRelationship(encodeUrl,
String id = paragraph.getDocument().getPackagePart().addExternalRelationship(url,
XWPFRelation.HYPERLINK.getRelation()).getId();
CTHyperlink cLink = paragraph.getCTP().addNewHyperlink();
cLink.setId(id);

Loading…
Cancel
Save