Browse Source

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

zhongwei
yang_shj 1 month ago
parent
commit
953a64c307
  1. 6
      hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/fdp/vo/FdpFaultMatchVO.java
  2. 16
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/database/service/WeaviateService.java
  3. 27
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/constants/CommentType.java
  4. 8
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/DataInstructController.java
  5. 7
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/DataRecordController.java
  6. 8
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/dto/DeviceAttrDTO.java
  7. 8
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/dto/DeviceFuncDTO.java
  8. 78
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/DataInstructService.java
  9. 62
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/DataRecordService.java
  10. 2
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/KnowledgeFileInfoService.java
  11. 1
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/KnowledgeFileInfoServiceImpl.java
  12. 12
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/QuestionAnswerCommentServiceImpl.java
  13. 3
      hzims-service/gglm-big-model/src/main/resources/template/template.yml

6
hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/fdp/vo/FdpFaultMatchVO.java

@ -45,7 +45,11 @@ public class FdpFaultMatchVO implements Serializable {
private String deviceFaultName;
public void setItemName() {
this.itemName = String.format("%s %s", this.deviceName, this.faultName);
if(Func.isNotEmpty(this.ord)) {
this.itemName = String.format("%s %s %s", this.stationName, this.ord, this.faultName);
} else {
this.itemName = String.format("%s %s %s", this.stationName, this.deviceName, this.faultName);
}
}
public void setDeviceFaultName() {

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

@ -442,4 +442,20 @@ public class WeaviateService {
throw new RuntimeException("Query failed.", e);
}
}
/**
* 获取查询结果列表
* @param data 调用weaviate返回数据
* @param tableName 表名
* @return 返回列表结果
*/
public List<JSONObject> getResultList(Object data, String tableName) {
String queryJson = JSON.toJSONString(data);
// 获取到数据的ID
return Optional.ofNullable(queryJson).map(JSONObject::parseObject)
.map(object -> object.getJSONObject("Get"))
.map(object -> object.getJSONArray(weaviateProperties.getDatabase() + "_" + tableName))
.map(array -> array.toJavaList(JSONObject.class))
.orElse(Lists.newArrayList());
}
}

27
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/constants/CommentType.java

@ -0,0 +1,27 @@
package com.hnac.gglm.bigmodel.maintenance.constants;
import lombok.Getter;
/**
* @Author: ypj
* @Date: 2024/10/10 10:21
*/
@Getter
public enum CommentType {
CRITICAL(0, "差评"),
PRAISE(1, "好评");
private final int code;
private final String msg;
CommentType(int code, String msg) {
this.code = code;
this.msg = msg;
}
public static CommentType getInstance(int code) {
for (CommentType item : CommentType.values()) {
if (item.getCode() == code) {
return item;
}
}
return null;
}
}

8
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/DataInstructController.java

@ -78,4 +78,12 @@ public class DataInstructController {
return R.data(dataInstructService.getDataInstructList());
}
@GetMapping("/syncData")
@ApiOperation("同步数据至向量数据库")
@ApiOperationSupport(order = 211)
public R syncData(@RequestParam("ids") String ids) {
return R.data(dataInstructService.syncDataToVectorDb(ids));
}
}

7
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/DataRecordController.java

@ -67,4 +67,11 @@ public class DataRecordController {
return R.data(dataRecordService.getDataRecordList());
}
// 数据同步向量数据库
@GetMapping("/syncData")
@ApiOperation("同步数据至向量数据库")
@ApiOperationSupport(order = 211)
public R syncData(@RequestParam("ids") String ids) {
return R.data(dataRecordService.syncDataToVectorDb(ids));
}
}

8
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/dto/DeviceAttrDTO.java

@ -1,5 +1,6 @@
package com.hnac.gglm.bigmodel.maintenance.dto;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -10,30 +11,37 @@ public class DeviceAttrDTO {
@ApiModelProperty("item")
@JsonProperty("item_id")
@JSONField(name = "item_id")
private String itemId;
@ApiModelProperty("itemName")
@JsonProperty("item_name")
@JSONField(name = "item_name")
private String itemName;
@ApiModelProperty("站点名称")
@JsonProperty("station_name")
@JSONField(name = "station_name")
private String stationName;
@ApiModelProperty("站点ID")
@JsonProperty("station_id")
@JSONField(name = "station_id")
private String stationId;
@ApiModelProperty("遥控的设备名称")
@JsonProperty("device_name")
@JSONField(name = "device_name")
private String deviceName;
@ApiModelProperty("遥控的设备ID")
@JsonProperty("device_id")
@JSONField(name = "device_id")
private String deviceId;
@ApiModelProperty("记录名称")
@JsonProperty("record_name")
@JSONField(name = "record_name")
private String recordName;
@ApiModelProperty("取数规则")

8
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/dto/DeviceFuncDTO.java

@ -1,5 +1,6 @@
package com.hnac.gglm.bigmodel.maintenance.dto;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -10,30 +11,37 @@ public class DeviceFuncDTO {
@ApiModelProperty("item")
@JsonProperty("item_id")
@JSONField(name = "item_id")
private String itemId;
@ApiModelProperty("itemName")
@JsonProperty("item_name")
@JSONField(name = "item_name")
private String itemName;
@ApiModelProperty("站点名称")
@JsonProperty("station_name")
@JSONField(name = "station_name")
private String stationName;
@ApiModelProperty("站点ID")
@JsonProperty("station_id")
@JSONField(name = "station_id")
private String stationId;
@ApiModelProperty("遥控的设备名称")
@JsonProperty("device_name")
@JSONField(name = "device_name")
private String deviceName;
@ApiModelProperty("遥控的设备ID")
@JsonProperty("device_id")
@JSONField(name = "device_id")
private String deviceId;
@ApiModelProperty("遥控名称")
@JsonProperty("yk_name")
@JSONField(name = "yk_name")
private String ykName;
@ApiModelProperty("遥控名称")

78
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/DataInstructService.java

@ -1,32 +1,45 @@
package com.hnac.gglm.bigmodel.maintenance.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.hnac.gglm.bigmodel.business.service.VectorDataService;
import com.hnac.gglm.bigmodel.configuration.WeaviateProperties;
import com.hnac.gglm.bigmodel.database.service.WeaviateService;
import com.hnac.gglm.bigmodel.maintenance.dto.DeviceFuncDTO;
import com.hnac.gglm.bigmodel.maintenance.entity.DataInstructEntity;
import com.hnac.gglm.bigmodel.maintenance.mapper.DataInstructMapper;
import com.hnac.hzims.fdp.constants.ScheduledConstant;
import com.hnac.hzinfo.exception.HzServiceException;
import com.hnac.hzinfo.sdk.v5.device.dto.DeviceFuncInfoDTO;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
@Service
@Slf4j
@AllArgsConstructor
@RequiredArgsConstructor
@DS("hznlm")
public class DataInstructService extends BaseServiceImpl<DataInstructMapper, DataInstructEntity> {
private final VectorDataService vectorDataService;
private final WeaviateService weaviateService;
private final WeaviateProperties weaviateProperties;
@Value("${weaviate.tableName.instruct}")
private String instructTableName;
public boolean save(DataInstructEntity entity) {
//对遥控名称判重
@ -82,4 +95,63 @@ public class DataInstructService extends BaseServiceImpl<DataInstructMapper, Dat
}
return deviceFuncDTOS;
}
/**
* 同步数据至向量数据库
* @param ids 控制指令ID 按逗号分隔
* @return 同步结果
*/
public Boolean syncDataToVectorDb(String ids) {
// 根据ID获取控制指令
List<DataInstructEntity> dataInstructList = this.listByIds(Func.toLongList(",", ids));
if(Func.isEmpty(dataInstructList)) {
throw new HzServiceException("根据所传ID未查询到相关数据!");
}
// 根据ItemName获取向量数据库内待同步的数据
dataInstructList.forEach(this::syncDataToVectorDb);
return true;
}
/**
* 同步数据至向量数据库
* @param dataInstructEntity 控制指令
* @return 同步结果
*/
public Boolean syncDataToVectorDb(DataInstructEntity dataInstructEntity) {
Map<String,String> query = new HashMap<>(1);
query.put("item_name", dataInstructEntity.getItemName());
Object data = weaviateService.query(null, instructTableName, query);
List<JSONObject> resultList = weaviateService.getResultList(data, instructTableName);
if(Func.isNotEmpty(resultList)) {
// 若数据条数 > 1 说明有重复数据
if(resultList.size() > 1) {
throw new HzServiceException("数据同步失败,存在重复数据!指令名称为:" + dataInstructEntity.getYkName());
}
// 删除数据后新增
String id = Optional.ofNullable(resultList.get(0))
.map(object -> object.getJSONObject("_additional"))
.map(additional -> additional.getString("id"))
.orElse(null);
if(Func.isNotEmpty(id)) {
log.info("删除id:" + id);
weaviateService.delete(id, instructTableName);
}
}
// 新增数据
Map<String,String> attrsMap = new HashMap<>(2);
attrsMap.put("item_name", "item_name");
attrsMap.put("device_yk_name", "device_name,yk_name");
weaviateService.save(JSONObject.parseObject(JSON.toJSONString(this.convert(dataInstructEntity))), instructTableName, attrsMap);
return true;
}
/**
* 封装数据
* @return 结果
*/
private DeviceFuncDTO convert(DataInstructEntity dataInstructEntity) {
DeviceFuncDTO result = BeanUtil.copyProperties(dataInstructEntity, DeviceFuncDTO.class);
result.setType("数据中心");
return result;
}
}

62
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/DataRecordService.java

@ -1,19 +1,25 @@
package com.hnac.gglm.bigmodel.maintenance.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.hnac.gglm.bigmodel.business.service.VectorDataService;
import com.hnac.gglm.bigmodel.database.service.WeaviateService;
import com.hnac.gglm.bigmodel.maintenance.dto.DeviceAttrDTO;
import com.hnac.gglm.bigmodel.maintenance.dto.DeviceFuncDTO;
import com.hnac.gglm.bigmodel.maintenance.entity.DataInstructEntity;
import com.hnac.gglm.bigmodel.maintenance.entity.DataRecordEntity;
import com.hnac.gglm.bigmodel.maintenance.entity.TableInfoEntity;
import com.hnac.gglm.bigmodel.maintenance.mapper.DataRecordMapper;
import com.hnac.gglm.bigmodel.maintenance.vo.DataRecordVO;
import com.hnac.hzinfo.exception.HzServiceException;
import com.hnac.hzinfo.sdk.v5.device.dto.DeviceAttrInfoDTO;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.mp.base.BaseServiceImpl;
@ -21,15 +27,18 @@ import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
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.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
@Slf4j
@AllArgsConstructor
@RequiredArgsConstructor
@DS("hznlm")
public class DataRecordService extends BaseServiceImpl<DataRecordMapper, DataRecordEntity> {
@ -37,6 +46,11 @@ public class DataRecordService extends BaseServiceImpl<DataRecordMapper, DataRec
private final TableInfoService tableInfoService;
private final WeaviateService weaviateService;
@Value("${weaviate.tableName.record}")
private String recordTableName;
public boolean save(DataRecordEntity entity) {
splicing(entity);
return super.save(entity);
@ -109,4 +123,50 @@ public class DataRecordService extends BaseServiceImpl<DataRecordMapper, DataRec
}
return result;
}
public Boolean syncDataToVectorDb(String ids) {
// 根据ID获取控制指令
List<DataRecordEntity> recordEntities = this.listByIds(Func.toLongList(",", ids));
if(Func.isEmpty(recordEntities)) {
throw new HzServiceException("根据所传ID未查询到相关数据!");
}
// 根据ItemName获取向量数据库内待同步的数据
recordEntities.forEach(this::syncDataToVectorDb);
return true;
}
public Boolean syncDataToVectorDb(DataRecordEntity dataRecord) {
Map<String,String> query = new HashMap<>(1);
query.put("item_name", dataRecord.getItemName());
Object data = weaviateService.query(null, recordTableName, query);
List<JSONObject> resultList = weaviateService.getResultList(data, recordTableName);
if(Func.isNotEmpty(resultList)) {
// 若数据条数 > 1 说明有重复数据
if(resultList.size() > 1) {
throw new HzServiceException("数据同步失败,存在重复数据!指令名称为:" + dataRecord.getRecordName());
}
// 删除数据后新增
String id = Optional.ofNullable(resultList.get(0))
.map(object -> object.getJSONObject("_additional"))
.map(additional -> additional.getString("id"))
.orElse(null);
if(Func.isNotEmpty(id)) {
log.info("删除id:" + id);
weaviateService.delete(id, recordTableName);
}
}
// 新增数据
Map<String,String> attrsMap = new HashMap<>(2);
attrsMap.put("item_name", "item_name");
attrsMap.put("record_name", "record_name");
attrsMap.put("device_record_name", "device_name,record_name");
weaviateService.save(JSONObject.parseObject(JSON.toJSONString(this.convert(dataRecord))), recordTableName, attrsMap);
return true;
}
private DeviceAttrDTO convert(DataRecordEntity dataRecord) {
DeviceAttrDTO result = BeanUtil.copyProperties(dataRecord, DeviceAttrDTO.class);
result.setType("业务");
return result;
}
}

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

@ -17,7 +17,7 @@ import java.util.List;
*/
public interface KnowledgeFileInfoService extends IService<KnowledgeFileInfo> {
String SEGMENT_URL = "/kn/doc_segment";
String VECTOR_DATABASE_NAME = "Hzims_knowledge_data";
String VECTOR_DATABASE_NAME = "knowledge_data";
Boolean store(IdRequest req);

1
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/KnowledgeFileInfoServiceImpl.java

@ -76,6 +76,7 @@ public class KnowledgeFileInfoServiceImpl extends ServiceImpl<KnowledgeFileInfoM
.body(getParamsJson(knowledgeFileInfo, tenantId, createUser, createDept), "application/json")
.execute();
if (!response.isOk()) {
log.error("文件分段失败,原因:{}", response.body());
return false;
}
return Boolean.TRUE;

12
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/QuestionAnswerCommentServiceImpl.java

@ -4,8 +4,10 @@ import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.gglm.bigmodel.maintenance.entity.AgentLogEntity;
import com.hnac.gglm.bigmodel.maintenance.entity.QuestionAnswerCommentEntity;
import com.hnac.gglm.bigmodel.maintenance.mapper.QuestionAnswerCommentMapper;
import com.hnac.gglm.bigmodel.maintenance.service.AgentLogService;
import com.hnac.gglm.bigmodel.maintenance.service.QuestionAnswerCommentService;
import com.hnac.gglm.bigmodel.maintenance.vo.AnswerCommentRequest;
import com.hnac.gglm.bigmodel.maintenance.vo.AnswerPraiseRequest;
@ -29,6 +31,7 @@ import java.util.List;
@DS("hznlm")
public class QuestionAnswerCommentServiceImpl extends ServiceImpl<QuestionAnswerCommentMapper, QuestionAnswerCommentEntity> implements QuestionAnswerCommentService {
private final IUserClient userClient;
private final AgentLogService agentLogService;
@Override
public QuestionAnswerCommentEntity getComment(String userId, String questionId) {
@ -54,13 +57,18 @@ public class QuestionAnswerCommentServiceImpl extends ServiceImpl<QuestionAnswer
public Boolean praise(AnswerPraiseRequest req) {
QuestionAnswerCommentEntity entity = getComment(req.getUserId(),
req.getQuestionId());
Boolean result;
if (ObjectUtil.isNotEmpty(entity)) {
entity.setPraise(req.getPraise());
return this.updateById(entity);
result = this.updateById(entity);
} else {
entity = req.toEntity();
return this.save(entity);
result = this.save(entity);
}
if (ObjectUtil.isNotEmpty(req.getPraise()) && ObjectUtil.isNotEmpty(req.getQuestionId())) {
agentLogService.update(Wrappers.<AgentLogEntity>lambdaUpdate().set(AgentLogEntity::getUserConclusion, req.getPraise()).eq(AgentLogEntity::getQId, req.getQuestionId()));
}
return result;
}
@Override

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

@ -99,3 +99,6 @@ weaviate:
host: 192.168.60.16
port: 9992
apiKey: 123
tableName:
instruct: yk
record: record
Loading…
Cancel
Save