Browse Source

fix: 修复向量数据库批量新增会重置数据bug

add:设备助手缺陷数据同步
zhongwei
haungxing 2 months ago
parent
commit
c099b250b2
  1. 30
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/feign/IDefectStatisticClient.java
  2. 15
      hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java
  3. 18
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/database/service/WeaviateService.java
  4. 6
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/service/impl/ControlAnswerResolveServiceImpl.java
  5. 12
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/controller/CreateTaskController.java
  6. 54
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/feign/DefectStatisticClient.java

30
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/defect/feign/IDefectStatisticClient.java

@ -0,0 +1,30 @@
package com.hnac.hzims.operational.defect.feign;
import com.hnac.hzims.operational.OperationalConstants;
import org.springblade.core.tool.api.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/**
* @Author: huangxing
* @Date: 2024/09/21 16:32
*/
@FeignClient(OperationalConstants.APP_NAME)
public interface IDefectStatisticClient {
String PREFIX_API = "/feign/defect_statistic";
String GET_DEFECT_OVERVIEW = PREFIX_API + "/getDefectOverview";
/**
* 获取缺陷概览
* @param date 日期
* @param emCode 设备编码
* @return 缺陷概览
*/
@GetMapping(GET_DEFECT_OVERVIEW)
R<List<String>> getDefectOverview(@RequestParam("date") String date, @RequestParam("emCode") String emCode);
}

15
hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/service/impl/EmInfoServiceImpl.java

@ -21,6 +21,7 @@ import com.hnac.hzims.fdp.service.IFdpQuestionService;
import com.hnac.hzims.operational.access.feign.IAccessMaterialClient;
import com.hnac.hzims.operational.access.feign.IOperAccessTaskClient;
import com.hnac.hzims.operational.access.vo.MaterialConsumeVO;
import com.hnac.hzims.operational.defect.feign.IDefectStatisticClient;
import com.hnac.hzims.operational.main.constant.HomePageConstant;
import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.feign.IStationClient;
@ -133,6 +134,9 @@ public class EmInfoServiceImpl extends ServiceImpl<EmInfoMapper, EmInfoEntity> i
@Autowired
private ITicketInfoClient ticketInfoClient;
@Autowired
private IDefectStatisticClient defectStatisticClient;
@Value("${hzims.equipment.emInfo.code}")
public String deviceCodePath;
@ -1074,7 +1078,6 @@ public class EmInfoServiceImpl extends ServiceImpl<EmInfoMapper, EmInfoEntity> i
deviceLedgerVO.setStationCode(stationOptional.get().getCode());
deviceLedgerVO.setStationName(stationOptional.get().getName());
deviceLedgerVO.setDate(date);
// TODO 获取设备两票、检修、缺陷等数据填入 dataSummary
R<List<String>> accessTaskOverview = accessTaskClient.getAccessTaskOverview(date, emInfo.getNumber());
if(!accessTaskOverview.isSuccess()) {
throw new HzServiceException("获取设备台账失败!");
@ -1098,6 +1101,16 @@ public class EmInfoServiceImpl extends ServiceImpl<EmInfoMapper, EmInfoEntity> i
}).collect(Collectors.toList());
result.addAll(deviceLedgerVOList);
}
R<List<String>> defectOverview = defectStatisticClient.getDefectOverview(date, emInfo.getNumber());
if(Func.isNotEmpty(defectOverview.getData())) {
List<DeviceLedgerVO> deviceLedgerVOList = defectOverview.getData().stream().map(overview -> {
DeviceLedgerVO deviceLedger = BeanUtil.copy(deviceLedgerVO, DeviceLedgerVO.class);
deviceLedger.setDataSummary(overview);
deviceLedger.setType("缺陷");
return deviceLedger;
}).collect(Collectors.toList());
result.addAll(deviceLedgerVOList);
}
return result;
}

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

@ -118,6 +118,9 @@ public class WeaviateService {
// }
public Boolean saveBatch(List entities,String className, Map<String,String> attrsMap) {
// 查询Weaviate 4.7.0表是否存在 若不存则新建表
Result<Boolean> existResult = weaviateClient.schema().exists().withClassName("Hzn_lm_" + className).run();
if(existResult.hasErrors() || !existResult.getResult()) {
Map<java.lang.String,Object> createTableParams = new HashMap<>(2);
Map<String,String> deleteTableParams = new HashMap<>(1);
deleteTableParams.put("table_name",className);
@ -127,6 +130,7 @@ public class WeaviateService {
createTableParams.put("vector_names",vectorStr.toArray(new String[vectorStr.size()]));
RequestClientUtil.postCall(gglmUrl + invokeApi.getDeleteTable(),deleteTableParams);
RequestClientUtil.postCall(gglmUrl + invokeApi.getCreateTable(),createTableParams);
}
Map<String,Object> params = new HashMap<>(2);
params.put("table_name", className);
List<Map<String, Object>> data = new ArrayList<>();
@ -171,20 +175,22 @@ public class WeaviateService {
* @return 删除结果
*/
public Boolean delete(String ids,String className) {
if(Func.isEmpty(ids) && Func.isNotEmpty(className)) {
// 删除className
Map<String,String> deleteTableParams = new HashMap<>(1);
deleteTableParams.put("table_name",className);
RequestClientUtil.postCall(gglmUrl + invokeApi.getDeleteTable(),deleteTableParams);
} else {
// 删除记录
ObjectDeleter deleter = weaviateClient.data().deleter();
deleter.withClassName(className);
if(Func.isEmpty(ids)) {
Result<List<WeaviateObject>> allObject = weaviateClient.data().objectsGetter().withClassName(className).withLimit(10000).run();
if(!allObject.hasErrors()) {
ids = allObject.getResult().stream().map(WeaviateObject::getId).collect(Collectors.joining(","));
}
}
Func.toStrList(",",ids).forEach(id -> {
Result<Boolean> result = deleter.withID(id).run();
if(result.hasErrors()) {
throw new HzServiceException(ResultCode.FAILURE,id + "记录删除失败!");
}
});
}
return true;
}

6
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/service/impl/ControlAnswerResolveServiceImpl.java

@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
import com.hnac.gglm.bigmodel.interactive.constants.ParamKeyConstants;
import java.util.HashMap;
import java.util.Map;
/**
* @Author: huangxing
@ -56,6 +57,11 @@ public class ControlAnswerResolveServiceImpl implements IAnswerResolveService {
log.info("机器人巡检传参为:{}", JSON.toJSONString(param));
String body = HttpRequest.post("http://192.168.60.29:8080/api/hzinfo-inspect/plan/initiateRobotPlan").body(JSON.toJSONString(param)).execute().body();
log.info("结果为:{}",body);
ExtraVO result = originExtra.toJavaObject(ExtraVO.class);
result.setType(FunctionConstants.TypeEnum.PARAMS.getType());
Map<String,Object> extraParams = new HashMap<>();
extraParams.put("name","查看巡检任务");
result.setParams(extraParams);
}
}
ExtraVO result = originExtra.toJavaObject(ExtraVO.class);

12
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/controller/CreateTaskController.java

@ -3,15 +3,13 @@ package com.hnac.hzinfo.inspect.task.controller;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzinfo.inspect.request.GenerateTaskVO;
import com.hnac.hzinfo.inspect.task.service.ICreateTaskService;
import com.hnac.hzinfo.inspect.task.service.impl.FileUploaderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
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;
import org.springframework.web.bind.annotation.*;
/**
* @ClassName CreateTaskController
@ -27,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
public class CreateTaskController extends BladeController {
private final ICreateTaskService createTaskService;
private final FileUploaderService uploaderService;
@PostMapping("/createShowTask")
@ApiOperation("生成演示数据")
@ -36,4 +35,9 @@ public class CreateTaskController extends BladeController {
return R.success("成功!");
}
@GetMapping("/test")
public R test(@RequestParam String url, @RequestParam String fileName) {
return R.data(uploaderService.upload(url,fileName));
}
}

54
hzims-service/operational/src/main/java/com/hnac/hzims/operational/defect/feign/DefectStatisticClient.java

@ -0,0 +1,54 @@
package com.hnac.hzims.operational.defect.feign;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.hnac.hzims.operational.defect.entity.OperDefectStatisticsEntity;
import com.hnac.hzims.operational.defect.service.IOperDefectStatisticsService;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author: huangxing
* @Date: 2024/09/21 16:38
*/
@RestController
@AllArgsConstructor
public class DefectStatisticClient implements IDefectStatisticClient {
private final IOperDefectStatisticsService defectStatisticsService;
@Override
@GetMapping(GET_DEFECT_OVERVIEW)
public R<List<String>> getDefectOverview(@RequestParam("date") String date, @RequestParam("emCode") String emCode) {
// 查询缺陷列表
LambdaQueryWrapper<OperDefectStatisticsEntity> queryWrapper = Wrappers.<OperDefectStatisticsEntity>lambdaQuery()
.eq(OperDefectStatisticsEntity::getEmCode, emCode)
.like(OperDefectStatisticsEntity::getFindTime, date)
.eq(OperDefectStatisticsEntity::getIsDefect, 1)
.isNotNull(OperDefectStatisticsEntity::getConclusion);
List<OperDefectStatisticsEntity> defectStatisticsEntities = defectStatisticsService.list(queryWrapper);
String overviewTemplate = "%s于%s在%s设备上发现一例%s缺陷,经过详细的分析与测试,最终定论结果为%s";
if(Func.isNotEmpty(defectStatisticsEntities)) {
List<String> overviewList = defectStatisticsEntities.stream().map(defect -> {
String finderName = defect.getFinderName();
String findTime = DateUtil.formatDateTime(defect.getFindTime());
String emName = defect.getName();
String defectName = defect.getFaultName();
String conclusion = defect.getConclusion();
return String.format(overviewTemplate, finderName, findTime, emName, defectName, conclusion);
}).collect(Collectors.toList());
return R.data(overviewList);
}
return R.data(Lists.newArrayList());
}
}
Loading…
Cancel
Save