Browse Source

fix: 临时提交

zhongwei
haungxing 3 months ago
parent
commit
7092f66b53
  1. 5
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java
  2. 87
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/database/service/WeaviateService.java
  3. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java
  4. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java
  5. 28
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java
  6. 2
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/obj/mapper/ObjectTemplateMapper.xml

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

@ -58,7 +58,10 @@ 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);
}
}

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

@ -6,28 +6,26 @@ import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.google.protobuf.ServiceException;
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.springblade.core.tool.utils.StringUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.*;
import java.util.stream.Collector;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
@ -43,9 +41,11 @@ 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 final String vectorUrl;
private String vectorUrl;
/**
* 对象保存向量数据库
@ -89,7 +89,10 @@ public class WeaviateService {
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;
@ -98,6 +101,63 @@ public class WeaviateService {
}
/**
* 删除向量数据库表名
* @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-实体类对象属性,多个按逗号分隔
@ -106,13 +166,22 @@ public class WeaviateService {
*/
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 null;
return result;
}
/**

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

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

Loading…
Cancel
Save