Browse Source

fix: 向量库维护临时提交

zhongwei
haungxing 3 months ago
parent
commit
5c38593cad
  1. 21
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/wrapper/BaseSyncWrapper.java
  2. 2
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/ControlEntity.java
  3. 5
      hzims-service/hzims-big-model/pom.xml
  4. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/controller/DataSourceExecuteController.java
  5. 6
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/controller/RemoteController.java
  6. 21
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/wrapper/CanvasSyncWrapper.java
  7. 20
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfig.java
  8. 40
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/SyncPropertyEntity.java
  9. 6
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java
  10. 35
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/config/ZhipuAiConfig.java
  11. 28
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/aspect/VideoSyncAspect.java
  12. 38
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/wrapper/VideoSyncWrapper.java

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

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;

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>

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

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

20
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/WeaviateConfig.java

@ -0,0 +1,20 @@
package com.hnac.hzims.bigmodel.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
/**
* @Author: huangxing
* @Date: 2024/08/21 15:22
*/
@Configuration
public class WeaviateConfig {
@Bean
public WebClient weaviateClient() {
return WebClient.create("http://192.168.60.16:9992");
}
}

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

35
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/config/ZhipuAiConfig.java

@ -1,11 +1,22 @@
package com.hnac.hzims.bigmodel.zhipuai.config;
import com.alibaba.fastjson.JSON;
import com.zhipu.oapi.ClientV4;
import io.weaviate.client.Config;
import io.weaviate.client.WeaviateAuthClient;
import io.weaviate.client.WeaviateClient;
import io.weaviate.client.base.Result;
import io.weaviate.client.v1.auth.exception.AuthException;
import io.weaviate.client.v1.data.model.WeaviateObject;
import io.weaviate.client.v1.misc.model.Meta;
import lombok.AllArgsConstructor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.List;
/**
* @Author: ypj
* @Date: 2024/8/9 17:01
@ -21,4 +32,28 @@ public class ZhipuAiConfig {
public ClientV4 clientV4() {
return new ClientV4.Builder(properties.getApiSecret()).build();
}
// public static void main(String[] args) throws AuthException {
// Config config = new Config("http", "192.168.60.16:9992");
// WeaviateClient client = WeaviateAuthClient.apiKey(config,"123");
// // 新增 HZIMS_TEST
//// Result<WeaviateObject> craeteTableTest = client.data().creator().withClassName("HZIMS_TEST").run();
//// System.out.println(JSON.toJSONString(craeteTableTest));
//// Result<List<WeaviateObject>> searchResult = client.data().objectsGetter().withClassName("HZIMS_TEST").run();
//// System.out.println(JSON.toJSONString(searchResult));
// // 新增数据
//// HashMap<String,Object> hashMap = new HashMap<String, Object>() {{
//// put("id_", "13412423423412");
//// put("name", "test");
//// }};
//// Result<WeaviateObject> hzimsTest = client.data().creator().withClassName("HZIMS_TEST").withProperties(hashMap).withVector(new Float[]{}).run();
//// System.out.println(JSON.toJSONString(hzimsTest));
//// Result<List<WeaviateObject>> searchResult = client.data().objectsGetter().withClassName("HZIMS_TEST").run();
//// System.out.println(JSON.toJSONString(searchResult));
// // 删除数据
// Result<Boolean> hzimsTest = client.data().deleter().withClassName("HZIMS_TEST").withID("14c6847d-b758-475f-968d-64b0e193e43e").run();
// System.out.println(JSON.toJSONString(hzimsTest));
// Result<List<WeaviateObject>> searchResult = client.data().objectsGetter().withClassName("HZIMS_TEST").run();
// System.out.println(JSON.toJSONString(searchResult));
// }
}

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;
}
}
Loading…
Cancel
Save