diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/scheduled/DeviceLedgerScheduledTask.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/scheduled/DeviceLedgerScheduledTask.java index 7b827cb..5410a52 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/scheduled/DeviceLedgerScheduledTask.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/scheduled/DeviceLedgerScheduledTask.java @@ -10,6 +10,7 @@ import com.hnac.hzims.equipment.service.IEmInfoService; import com.hnac.hzims.equipment.vo.DeviceLedgerVO; import com.hnac.hzims.fdp.constants.ScheduledConstant; import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.context.XxlJobHelper; import com.xxl.job.core.handler.annotation.XxlJob; import lombok.AllArgsConstructor; import org.springblade.core.tool.api.R; @@ -38,7 +39,9 @@ public class DeviceLedgerScheduledTask { @XxlJob(ScheduledConstant.DEVICE_LEDGER_DATA_GENERATE) public ReturnT execute(String param) throws Exception { - JSONObject paramJson = JSONObject.parseObject(param); + String jobParam = XxlJobHelper.getJobParam(); + XxlJobHelper.log("传参为:" + jobParam); + JSONObject paramJson = JSONObject.parseObject(jobParam); String emCode = Optional.ofNullable(paramJson).map(json -> json.getString("emCode")).orElse(""); String date = Optional.ofNullable(paramJson).map(json -> json.getString("date")).orElse(LocalDate.now().minusDays(1).format(DateUtil.DATE_FORMATTER)); List deviceLedgerList = emInfoService.getDeviceLedgerList(emCode, date); @@ -46,7 +49,7 @@ public class DeviceLedgerScheduledTask { WeaviateQueryDTO query = new WeaviateQueryDTO(); Map queryMap = new HashMap<>(); if(Func.isNotEmpty(emCode)) { - queryMap.put("emCode",emCode); + queryMap.put("deviceCode",emCode); } queryMap.put("date",date); query.setQuery(queryMap); diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/database/service/WeaviateService.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/database/service/WeaviateService.java index 2ba6d18..cecd4a4 100644 --- a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/database/service/WeaviateService.java +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/database/service/WeaviateService.java @@ -178,7 +178,7 @@ public class WeaviateService { if(Func.isEmpty(ids) && Func.isNotEmpty(className)) { // 删除className Map deleteTableParams = new HashMap<>(1); - deleteTableParams.put("table_name",className); + deleteTableParams.put("table_name",className.replace("Hzn_lm_","")); RequestClientUtil.postCall(gglmUrl + invokeApi.getDeleteTable(),deleteTableParams); } else { // 删除记录 @@ -333,32 +333,25 @@ public class WeaviateService { fields.add(additionalId); get.withFields(fields.toArray(new Field[fields.size()])); if(Func.isNotEmpty(query)) { + // waeviate 多个filter查询结果 List whereFilters = query.entrySet().stream().map(e -> WhereFilter.builder() .path(e.getKey()) .operator(Operator.Equal) .valueString(e.getValue()) .build()).collect(Collectors.toList()); - whereFilters.forEach(where -> get.withWhere(where)); + WhereFilter combinedFilter = WhereFilter.builder() + .operator(Operator.And) + .operands(whereFilters.toArray(new WhereFilter[whereFilters.size()])) + .build(); + get.withWhere(combinedFilter); + } + try { + // 执行查询并返回结果 + return get.run().getResult().getData(); + } catch (Exception e) { + // 异常处理 + System.err.println("Error occurred during query execution: " + e.getMessage()); + throw new RuntimeException("Query failed.", e); } - return get.run().getResult().getData(); } - -// public static void main(String[] args) throws AuthException { -// Config config = new Config("http", "192.168.60.16:9992"); -// WeaviateClient client = WeaviateAuthClient.apiKey(config, "123"); -// Field itemName = Field.builder().name("item_name").build(); -// Field itemId = Field.builder().name("item_id").build(); -// Field additionalId = Field.builder().name("_additional { id }").build(); -// WhereFilter where = WhereFilter.builder() -// .path(new String[]{ "item_name" }) -// .operator(Operator.Equal) -// .valueString("湖北宜昌泵站") -// .build(); -// Result result = client.graphQL().get() -// .withClassName("Hzn_lm_form_station") -// .withFields(itemName,itemId,additionalId) -// .withWhere(where) -// .run(); -// System.out.println(JSON.toJSONString(result.getResult().getData())); -// } } diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/factory/AnswerResolveFactory.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/factory/AnswerResolveFactory.java index 4f25f78..4a7f757 100644 --- a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/factory/AnswerResolveFactory.java +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/factory/AnswerResolveFactory.java @@ -51,7 +51,7 @@ public class AnswerResolveFactory { return null; } } - throw new HzServiceException(ResultCode.DEFAULT_NULL_MESSAGE,"service解析失败!"); + return null; } } diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/constants/DataOperateType.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/constants/DataOperateType.java new file mode 100644 index 0000000..6abaf17 --- /dev/null +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/constants/DataOperateType.java @@ -0,0 +1,32 @@ +package com.hnac.gglm.bigmodel.maintenance.constants; + +import lombok.Getter; + +/** + * @Author: ypj + * @Date: 2024/9/23 14:18 + */ +@Getter +public enum DataOperateType { + CREATE("CREATE", "新增"), + UPDATE("UPDATE", "更新"), + RESET("RESET", "重置"), + DELETE("DELETE", "删除"), + SYNCHRONIZATION("SYNCHRONIZATION", "同步"); + private final String code; + private final String msg; + + DataOperateType(String code, String msg) { + this.code = code; + this.msg = msg; + } + + public static DataOperateType getInstance(String code) { + for (DataOperateType dataOperateType : DataOperateType.values()) { + if (dataOperateType.getCode().equals(code)) { + return dataOperateType; + } + } + return null; + } +} diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/VectorParamController.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/VectorParamController.java index 1f6d690..6deaddd 100644 --- a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/VectorParamController.java +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/VectorParamController.java @@ -3,7 +3,10 @@ package com.hnac.gglm.bigmodel.maintenance.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.fasterxml.jackson.core.JsonProcessingException; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.gglm.bigmodel.maintenance.constants.DataOperateType; import com.hnac.gglm.bigmodel.maintenance.entity.VectorParamEntity; +import com.hnac.gglm.bigmodel.maintenance.entity.VectorParamLogEntity; +import com.hnac.gglm.bigmodel.maintenance.service.VectorParamLogService; import com.hnac.gglm.bigmodel.maintenance.service.VectorParamService; import com.hnac.gglm.bigmodel.maintenance.vo.IdsRequest; import com.hnac.hzinfo.api.annotation.ApiInterface; @@ -33,6 +36,7 @@ import java.util.Map; @Slf4j public class VectorParamController { private final VectorParamService vectorParamService; + private final VectorParamLogService vectorParamLogService; @GetMapping("/listPage") @ApiOperation(value = "分页查询") @@ -52,21 +56,37 @@ public class VectorParamController { @ApiOperation(value = "保存向量参数配置") @ApiOperationSupport(order = 3) public R save(@RequestBody VectorParamEntity req) { - return R.status(vectorParamService.save(req)); + Boolean result = vectorParamService.save(req); + if (result) { + vectorParamLogService.create(VectorParamLogEntity.builder() + .vectorParamId(req.getId()) + .type(DataOperateType.CREATE.getCode()).build()); + } + return R.status(result); } @DeleteMapping("/remove") @ApiOperation(value = "删除向量参数配置") @ApiOperationSupport(order = 4) public R remove(@RequestParam @ApiParam("主键ID,按逗号分隔") String ids) { - return R.status(vectorParamService.removeByIds(Func.toLongList(",", ids))); + Boolean result = vectorParamService.removeByIds(Func.toLongList(",", ids)); + if (result) { + vectorParamLogService.delete(Func.toLongList(",", ids)); + } + return R.status(result); } @PutMapping("/update") @ApiOperation(value = "编辑向量参数配置") @ApiOperationSupport(order = 5) public R update(@RequestBody VectorParamEntity req) { - return R.status(vectorParamService.updateById(req)); + Boolean result = vectorParamService.updateById(req); + if (result) { + vectorParamLogService.edit(VectorParamLogEntity.builder() + .vectorParamId(req.getId()) + .type(DataOperateType.UPDATE.getCode()).build()); + } + return R.status(result); } @GetMapping("/getAuthorization") diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/VectorParamLogController.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/VectorParamLogController.java new file mode 100644 index 0000000..5e46a8a --- /dev/null +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/VectorParamLogController.java @@ -0,0 +1,99 @@ +package com.hnac.gglm.bigmodel.maintenance.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.gglm.bigmodel.maintenance.entity.VectorParamLogEntity; +import com.hnac.gglm.bigmodel.maintenance.service.VectorParamLogService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.support.Condition; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.Func; +import org.springframework.web.bind.annotation.*; + +/** + * @Author: ypj + * @Date: 2024/9/23 13:50 + */ +@RestController +@RequestMapping("/vector/log") +@Api(value = "向量参数配置日志", tags = "向量参数配置日志") +@AllArgsConstructor +@Slf4j +public class VectorParamLogController { + private final VectorParamLogService vectorParamLogService; + + @GetMapping("/listPage") + @ApiOperation(value = "分页查询") + @ApiOperationSupport(order = 1) + public R> listPage(Query query, VectorParamLogEntity req) { + return R.data(vectorParamLogService.page(Condition.getPage(query), Condition.getQueryWrapper(new VectorParamLogEntity(), req))); + } + + @GetMapping("/detail") + @ApiOperation(value = "查看详情") + @ApiOperationSupport(order = 2) + public R detail(@RequestParam @ApiParam("主键ID") Long id) { + return R.data(vectorParamLogService.getById(id)); + } + + @GetMapping("/save") + @ApiOperation(value = "保存向量参数配置日志") + @ApiOperationSupport(order = 3) + public R save(@RequestBody VectorParamLogEntity req) { + return R.status(vectorParamLogService.save(req)); + } + + @GetMapping("/remove") + @ApiOperation(value = "删除向量参数配置日志") + @ApiOperationSupport(order = 4) + public R remove(@RequestParam @ApiParam("主键ID,按逗号分隔") String ids) { + return R.status(vectorParamLogService.removeByIds(Func.toLongList(",", ids))); + } + + @PutMapping("/update") + @ApiOperation(value = "编辑向量参数配置日志") + @ApiOperationSupport(order = 5) + public R update(@RequestBody VectorParamLogEntity req) { + return R.status(vectorParamLogService.updateById(req)); + } + + @PostMapping("/create") + @ApiOperation(value = "创建向量参数配置操作记录") + @ApiOperationSupport(order = 6) + public R create(@RequestBody VectorParamLogEntity req) { + return R.status(vectorParamLogService.create(req)); + } + + @PostMapping("/edit") + @ApiOperation(value = "编辑向量参数配置操作记录") + @ApiOperationSupport(order = 7) + public R edit(@RequestBody VectorParamLogEntity req) { + return R.status(vectorParamLogService.edit(req)); + } + + @PostMapping("/reset") + @ApiOperation(value = "重置向量参数配置操作记录") + @ApiOperationSupport(order = 8) + public R reset(@RequestBody VectorParamLogEntity req) { + return R.status(vectorParamLogService.reset(req)); + } + + @PostMapping("/delete") + @ApiOperation(value = "删除向量参数配置操作记录") + @ApiOperationSupport(order = 9) + public R delete(@RequestParam @ApiParam("主键ID,按逗号分隔") String ids) { + return R.status(vectorParamLogService.delete(Func.toLongList(",", ids))); + } + + @PostMapping("/synchronization") + @ApiOperation(value = "同步向量参数配置操作记录") + @ApiOperationSupport(order = 10) + public R synchronization(@RequestBody VectorParamLogEntity req) { + return R.status(vectorParamLogService.synchronization(req)); + } +} diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/entity/VectorParamLogEntity.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/entity/VectorParamLogEntity.java new file mode 100644 index 0000000..4975205 --- /dev/null +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/entity/VectorParamLogEntity.java @@ -0,0 +1,44 @@ +package com.hnac.gglm.bigmodel.maintenance.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springblade.core.mp.support.QueryField; +import org.springblade.core.mp.support.SqlCondition; +import org.springblade.core.tenant.mp.TenantEntity; + +import java.io.Serializable; + +/** + * @Author: ypj + * @Date: 2024/9/23 12:07 + */ +@ApiModel("向量参数配置日志") +@TableName("gglm_vector_param_log") +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class VectorParamLogEntity extends TenantEntity implements Serializable { + private static final long serialVersionUID = 1L; + + @ApiModelProperty("参数id") + @TableField("VECTOR_PARAM_ID") + @QueryField(condition = SqlCondition.EQUAL) + private Long vectorParamId; + + @ApiModelProperty("日志内容") + @TableField("CONTENT") + @QueryField(condition = SqlCondition.LIKE) + private String content; + + @ApiModelProperty("日志类型,新增CREATE,更新UPDATE,重置RESET") + @TableField("TYPE") + @QueryField(condition = SqlCondition.EQUAL) + private String type; +} diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/mapper/VectorParamLogMapper.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/mapper/VectorParamLogMapper.java new file mode 100644 index 0000000..ed1188b --- /dev/null +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/mapper/VectorParamLogMapper.java @@ -0,0 +1,13 @@ +package com.hnac.gglm.bigmodel.maintenance.mapper; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.gglm.bigmodel.maintenance.entity.VectorParamLogEntity; + +/** + * @Author: ypj + * @Date: 2024/9/23 13:59 + */ +@DS("hznlm") +public interface VectorParamLogMapper extends BaseMapper { +} diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/mapper/VectorParamMapper.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/mapper/VectorParamMapper.java index 6dc3e63..9fbfb79 100644 --- a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/mapper/VectorParamMapper.java +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/mapper/VectorParamMapper.java @@ -1,5 +1,6 @@ package com.hnac.gglm.bigmodel.maintenance.mapper; +import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.hnac.gglm.bigmodel.maintenance.entity.VectorParamEntity; @@ -7,5 +8,7 @@ import com.hnac.gglm.bigmodel.maintenance.entity.VectorParamEntity; * @Author: ypj * @Date: 2024/09/02 15:12 */ + +@DS("hznlm") public interface VectorParamMapper extends BaseMapper { } diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/VectorParamLogService.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/VectorParamLogService.java new file mode 100644 index 0000000..9cf5a1e --- /dev/null +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/VectorParamLogService.java @@ -0,0 +1,22 @@ +package com.hnac.gglm.bigmodel.maintenance.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.hnac.gglm.bigmodel.maintenance.entity.VectorParamLogEntity; + +import java.util.List; + +/** + * @Author: ypj + * @Date: 2024/9/23 13:56 + */ +public interface VectorParamLogService extends IService { + Boolean create(VectorParamLogEntity req); + + Boolean edit(VectorParamLogEntity req); + + Boolean reset(VectorParamLogEntity req); + + Boolean delete(List ids); + + Boolean synchronization(VectorParamLogEntity req); +} diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/VectorParamService.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/VectorParamService.java index 8553964..760447c 100644 --- a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/VectorParamService.java +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/VectorParamService.java @@ -19,4 +19,6 @@ public interface VectorParamService extends IService { List getUrlResponseKeyList(String url, String bladeToken, String hzinfoToken); Boolean synchronization(List id ,String bladeToken, String hzinfoToken); + + Boolean synchronization(Long id, String bladeToken, String hzinfoToken); } diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/VectorParamLogServiceImpl.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/VectorParamLogServiceImpl.java new file mode 100644 index 0000000..d0e5660 --- /dev/null +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/VectorParamLogServiceImpl.java @@ -0,0 +1,76 @@ +package com.hnac.gglm.bigmodel.maintenance.service.impl; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.hnac.gglm.bigmodel.maintenance.constants.DataOperateType; +import com.hnac.gglm.bigmodel.maintenance.entity.VectorParamLogEntity; +import com.hnac.gglm.bigmodel.maintenance.mapper.VectorParamLogMapper; +import com.hnac.gglm.bigmodel.maintenance.service.VectorParamLogService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * @Author: ypj + * @Date: 2024/9/23 13:57 + */ +@Service +@Slf4j +@AllArgsConstructor +@DS("hznlm") +public class VectorParamLogServiceImpl extends ServiceImpl implements VectorParamLogService { + @Override + public Boolean create(VectorParamLogEntity req) { + if (ObjectUtil.isEmpty(req.getVectorParamId())) { + return false; + } + req.setType(DataOperateType.CREATE.getCode()); + return save(req); + } + + @Override + public Boolean edit(VectorParamLogEntity req) { + if (ObjectUtil.isEmpty(req.getVectorParamId())) { + return false; + } + req.setType(DataOperateType.UPDATE.getCode()); + return save(req); + } + + @Override + public Boolean reset(VectorParamLogEntity req) { + if (ObjectUtil.isEmpty(req.getVectorParamId())) { + return false; + } + req.setType(DataOperateType.RESET.getCode()); + return save(req); + } + + @Override + public Boolean delete(List ids) { + ThreadPoolExecutor executor = new ThreadPoolExecutor(5, ids.size() > 5 ? ids.size() : 5, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue()); + ids.forEach(id -> { + executor.execute(() -> { + save(VectorParamLogEntity.builder() + .vectorParamId(id) + .type(DataOperateType.DELETE.getCode()).build()); + }); + }); + return Boolean.TRUE; + } + + @Override + public Boolean synchronization(VectorParamLogEntity req) { + if (ObjectUtil.isEmpty(req.getVectorParamId())) { + return false; + } + req.setType(DataOperateType.SYNCHRONIZATION.getCode()); + return save(req); + } +} diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/VectorParamServiceImpl.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/VectorParamServiceImpl.java index 86e4921..b69e884 100644 --- a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/VectorParamServiceImpl.java +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/VectorParamServiceImpl.java @@ -12,10 +12,13 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.hnac.gglm.bigmodel.database.service.WeaviateService; -import com.hnac.gglm.bigmodel.maintenance.vo.VectorUrlResponse; +import com.hnac.gglm.bigmodel.maintenance.constants.DataOperateType; import com.hnac.gglm.bigmodel.maintenance.entity.VectorParamEntity; +import com.hnac.gglm.bigmodel.maintenance.entity.VectorParamLogEntity; import com.hnac.gglm.bigmodel.maintenance.mapper.VectorParamMapper; +import com.hnac.gglm.bigmodel.maintenance.service.VectorParamLogService; import com.hnac.gglm.bigmodel.maintenance.service.VectorParamService; +import com.hnac.gglm.bigmodel.maintenance.vo.VectorUrlResponse; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -23,6 +26,9 @@ import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletResponse; import java.nio.charset.StandardCharsets; import java.util.*; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; /** * @Author: ypj @@ -37,6 +43,7 @@ public class VectorParamServiceImpl extends ServiceImpl 5 ? ids.size() : 5, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue()); + ids.forEach(id -> { + executor.execute(() -> { + if (synchronization(id, bladeToken, hzinfoToken)) { + log.info("synchronization vector param id:{} success", id); + } else { + log.error("synchronization vector param id:{} fail", id); } - Map attrMap = new HashMap<>(); - Iterator iterator = rootNode.fieldNames(); - while (iterator.hasNext()) { - String key = iterator.next(); - attrMap.put(key, rootNode.findValue(key).textValue()); - } - String tableName = entity.getTableName().replace(entity.getProjectPrefix() + "_",""); - weaviateService.saveBatch(response.getOriginalData(), tableName, attrMap); - this.update(Wrappers.lambdaUpdate().eq(VectorParamEntity::getId, id).set(VectorParamEntity::getUpdateTime, new Date())); + }); + }); + executor.shutdown(); + return true; + } + + + @Override + public Boolean synchronization(Long id, String bladeToken, String hzinfoToken) { + VectorParamEntity entity = baseMapper.selectById(id); + if (null == entity) { + return false; + } + log.info("synchronization vector param id:{}", id); + VectorUrlResponse response = getUrlResponse(entity.getUrl(), bladeToken, hzinfoToken); + if (response != null) { + ObjectMapper mapper = new ObjectMapper(); + JsonNode rootNode = null; + try { + rootNode = mapper.readTree(entity.getAttributeMap()); + } catch (JsonProcessingException e) { + log.error("getUrlResponseKeyList error", e); + } + Map attrMap = new HashMap<>(); + Iterator iterator = rootNode.fieldNames(); + while (iterator.hasNext()) { + String key = iterator.next(); + attrMap.put(key, rootNode.findValue(key).textValue()); + } + String tableName = entity.getTableName().replace(entity.getProjectPrefix() + "_", ""); + weaviateService.saveBatch(response.getOriginalData(), tableName, attrMap); + if (this.update(Wrappers.lambdaUpdate().eq(VectorParamEntity::getId, id).set(VectorParamEntity::getUpdateTime, new Date()))) { + return vectorParamLogService.synchronization(VectorParamLogEntity.builder() + .vectorParamId(id) + .type(DataOperateType.SYNCHRONIZATION.getCode()).build()); + } else { + return false; } } return true; } - } diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/schedule/FrontEndInteractiveSchedule.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/schedule/FrontEndInteractiveSchedule.java index 7747c10..515abba 100644 --- a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/schedule/FrontEndInteractiveSchedule.java +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/schedule/FrontEndInteractiveSchedule.java @@ -70,7 +70,7 @@ public class FrontEndInteractiveSchedule { answerVO.setExtras(resolveExtras); } catch(Exception e) { log.error("An error occurred",e); - AnswerVO.error(answerVO.getChatId(), answerVO.getUserId(), answerVO.getQuery()); + answerVO = AnswerVO.error(answerVO.getChatId(), answerVO.getUserId(), answerVO.getQuery()); } } TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO));