From cc903588abf9b24cf58e3b6ff8dcb49e6ed32a8d Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Fri, 6 Sep 2024 14:54:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=90=91=E9=87=8F=E5=BA=93=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../database/controller/WeaviateController.java | 7 +++-- .../bigmodel/database/service/WeaviateService.java | 35 +++++++++++++++------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/controller/WeaviateController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/controller/WeaviateController.java index 7683887..620950d 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/controller/WeaviateController.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/controller/WeaviateController.java @@ -27,8 +27,11 @@ public class WeaviateController { } @GetMapping("/list") - public R> list(@RequestParam(value = "id",required = false) String id, @RequestParam("className") String className) { - return R.data(weaviateService.list(id,className)); + public R> list(@RequestParam(value = "id",required = false) String id, + @RequestParam("className") String className, + @RequestParam("current") Integer current, + @RequestParam("pageSize") Integer pageSize) { + return R.data(weaviateService.list(id,className,current,pageSize)); } @DeleteMapping("/removeById") diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java index 2af50cd..76d308c 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java @@ -8,27 +8,34 @@ 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.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.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 io.weaviate.client.v1.graphql.model.GraphQLResponse; +import io.weaviate.client.v1.graphql.query.Get; +import io.weaviate.client.v1.graphql.query.fields.Field; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.api.ResultCode; 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; +import java.util.stream.Stream; /** * @Author: huangxing @@ -122,16 +129,22 @@ public class WeaviateService { * @param className 表名 * @return 删除结果 */ - public Boolean delete(String id,String className) { + public Boolean delete(String ids,String className) { ObjectDeleter deleter = weaviateClient.data().deleter(); - if(Func.isNotEmpty(id)) { - deleter.withID(id); - } - if(Func.isNotEmpty(className)) { - deleter.withClassName(className); + deleter.withClassName(className); + if(Func.isEmpty(ids)) { + Result> allObject = weaviateClient.data().objectsGetter().withClassName(className).withLimit(10000).run(); + if(!allObject.hasErrors()) { + ids = allObject.getResult().stream().map(WeaviateObject::getId).collect(Collectors.joining(",")); + } } - Result result = deleter.run(); - return !result.hasErrors(); + Func.toStrList(",",ids).forEach(id -> { + Result result = deleter.withID(id).run(); + if(result.hasErrors()) { + throw new HzServiceException(ResultCode.FAILURE,id + "记录删除失败!"); + } + }); + return true; } /** @@ -157,7 +170,7 @@ public class WeaviateService { return !result.hasErrors(); } - public List list(String id,String className) { + public List list(String id,String className,Integer current,Integer pageSize) { ObjectsGetter objectsGetter = weaviateClient.data().objectsGetter(); if(Func.isNotEmpty(id)) { objectsGetter.withID(id); @@ -165,7 +178,7 @@ public class WeaviateService { if(Func.isNotEmpty(className)) { objectsGetter.withClassName(className); } - Result> result = objectsGetter.run(); + Result> result = objectsGetter.withLimit(pageSize).withOffset((current-1) * pageSize).run(); if(result.hasErrors()) { throw new HzServiceException("查询失败!"); }