|
|
|
@ -5,6 +5,7 @@ import cn.hutool.http.HttpResponse;
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode; |
|
|
|
@ -16,7 +17,6 @@ import com.hnac.hzims.bigmodel.maintenance.service.VectorParamService;
|
|
|
|
|
import com.hnac.hzims.bigmodel.maintenance.vo.VectorUrlResponse; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
@ -49,59 +49,57 @@ public class VectorParamServiceImpl extends ServiceImpl<VectorParamMapper, Vecto
|
|
|
|
|
.header("Hzinfo-Auth", hzinfoToken).execute(); |
|
|
|
|
if (response.getStatus() == HttpServletResponse.SC_OK) { |
|
|
|
|
String body = response.body(); |
|
|
|
|
log.info("getUrlResponse:" + body); |
|
|
|
|
JSONObject jsonObject = JSON.parseObject(body); |
|
|
|
|
VectorUrlResponse result = new VectorUrlResponse(); |
|
|
|
|
result.setOriginalData(JSONArray.parseArray(jsonObject.getString("data")).toJavaList(JSONObject.class)); |
|
|
|
|
// try {
|
|
|
|
|
// ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
// JsonNode rootNode = mapper.readTree(body);
|
|
|
|
|
// if (rootNode.isArray()) {
|
|
|
|
|
// return getUrlResponseByArray(rootNode);
|
|
|
|
|
// }
|
|
|
|
|
// JsonNode dataNode = rootNode.findValue("data");
|
|
|
|
|
// if (dataNode != null && dataNode.isArray()) {
|
|
|
|
|
// return getUrlResponseByArray(dataNode);
|
|
|
|
|
// }
|
|
|
|
|
// if (dataNode != null) {
|
|
|
|
|
// return getUrlResponseByObject(dataNode);
|
|
|
|
|
// }
|
|
|
|
|
// if (rootNode != null) {
|
|
|
|
|
// return getUrlResponseByObject(rootNode);
|
|
|
|
|
// }
|
|
|
|
|
// } catch (JsonProcessingException e) {
|
|
|
|
|
// log.error("getUrlResponse error", e);
|
|
|
|
|
// }
|
|
|
|
|
try { |
|
|
|
|
ObjectMapper mapper = new ObjectMapper(); |
|
|
|
|
JsonNode rootNode = mapper.readTree(body); |
|
|
|
|
if (rootNode.isArray()) { |
|
|
|
|
return getUrlResponseByArray(rootNode); |
|
|
|
|
} |
|
|
|
|
JsonNode dataNode = rootNode.findValue("data"); |
|
|
|
|
if (dataNode != null && dataNode.isArray()) { |
|
|
|
|
return getUrlResponseByArray(dataNode); |
|
|
|
|
} |
|
|
|
|
if (dataNode != null) { |
|
|
|
|
return getUrlResponseByObject(dataNode); |
|
|
|
|
} |
|
|
|
|
if (rootNode != null) { |
|
|
|
|
return getUrlResponseByObject(rootNode); |
|
|
|
|
} |
|
|
|
|
} catch (JsonProcessingException e) { |
|
|
|
|
log.error("getUrlResponse error", e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// private VectorUrlResponse getUrlResponseByArray(JsonNode rootNode) throws JsonProcessingException {
|
|
|
|
|
// VectorUrlResponse result = new VectorUrlResponse();
|
|
|
|
|
// result.setOriginalData(rootNode);
|
|
|
|
|
// JsonNode item = rootNode.get(0);
|
|
|
|
|
// if (item != null) {
|
|
|
|
|
// List<String> keyList = new ArrayList<>();
|
|
|
|
|
// Iterator<String> iterator = item.fieldNames();
|
|
|
|
|
// while (iterator.hasNext()) {
|
|
|
|
|
// keyList.add(iterator.next());
|
|
|
|
|
// }
|
|
|
|
|
// result.setKeyList(keyList);
|
|
|
|
|
// }
|
|
|
|
|
// return result;
|
|
|
|
|
// }
|
|
|
|
|
private VectorUrlResponse getUrlResponseByArray(JsonNode rootNode) throws JsonProcessingException { |
|
|
|
|
VectorUrlResponse result = new VectorUrlResponse(); |
|
|
|
|
result.setOriginalData(JSONArray.parseArray(rootNode.toPrettyString()).toJavaList(JSONObject.class)); |
|
|
|
|
JsonNode item = rootNode.get(0); |
|
|
|
|
if (item != null) { |
|
|
|
|
List<String> keyList = new ArrayList<>(); |
|
|
|
|
Iterator<String> iterator = item.fieldNames(); |
|
|
|
|
while (iterator.hasNext()) { |
|
|
|
|
keyList.add(iterator.next()); |
|
|
|
|
} |
|
|
|
|
result.setKeyList(keyList); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// private VectorUrlResponse getUrlResponseByObject(JsonNode rootNode) throws JsonProcessingException {
|
|
|
|
|
// VectorUrlResponse result = new VectorUrlResponse();
|
|
|
|
|
// result.setOriginalData(rootNode);
|
|
|
|
|
// List<String> keyList = new ArrayList<>();
|
|
|
|
|
// Iterator<String> iterator = rootNode.fieldNames();
|
|
|
|
|
// while (iterator.hasNext()) {
|
|
|
|
|
// keyList.add(iterator.next());
|
|
|
|
|
// }
|
|
|
|
|
// result.setKeyList(keyList);
|
|
|
|
|
// return result;
|
|
|
|
|
// }
|
|
|
|
|
private VectorUrlResponse getUrlResponseByObject(JsonNode rootNode) throws JsonProcessingException { |
|
|
|
|
VectorUrlResponse result = new VectorUrlResponse(); |
|
|
|
|
List<JSONObject> originalData = new ArrayList<>(); |
|
|
|
|
originalData.add(JSON.parseObject(rootNode.toPrettyString())); |
|
|
|
|
result.setOriginalData(originalData); |
|
|
|
|
List<String> keyList = new ArrayList<>(); |
|
|
|
|
Iterator<String> iterator = rootNode.fieldNames(); |
|
|
|
|
while (iterator.hasNext()) { |
|
|
|
|
keyList.add(iterator.next()); |
|
|
|
|
} |
|
|
|
|
result.setKeyList(keyList); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<String> getUrlResponseKeyList(String url, String bladeToken, String hzinfoToken) { |
|
|
|
@ -110,45 +108,30 @@ public class VectorParamServiceImpl extends ServiceImpl<VectorParamMapper, Vecto
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Boolean synchronization(String bladeToken, String hzinfoToken) { |
|
|
|
|
List<VectorParamEntity> list = this.list(); |
|
|
|
|
if (CollectionUtil.isEmpty(list)) { |
|
|
|
|
public Boolean synchronization(Long id, String bladeToken, String hzinfoToken) { |
|
|
|
|
VectorParamEntity entity = getById(id); |
|
|
|
|
if (null == entity) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
for (VectorParamEntity entity : list) { |
|
|
|
|
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) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
Map<String, String> attrMap = new HashMap<>(); |
|
|
|
|
Iterator<String> iterator = rootNode.fieldNames(); |
|
|
|
|
while (iterator.hasNext()) { |
|
|
|
|
String key = iterator.next(); |
|
|
|
|
attrMap.put(key, rootNode.findValue(key).textValue()); |
|
|
|
|
} |
|
|
|
|
List<Object> dataList = new ArrayList(); |
|
|
|
|
JsonNode dataObject = (JsonNode) response.getOriginalData(); |
|
|
|
|
if (dataObject.isArray()) { |
|
|
|
|
Iterator<JsonNode> dataIterator = dataObject.iterator(); |
|
|
|
|
while (dataIterator.hasNext()) { |
|
|
|
|
dataList.add(toJsonObject(dataIterator.next())); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
dataList.add(toJsonObject(dataObject)); |
|
|
|
|
} |
|
|
|
|
weaviateService.saveBatch(response.getOriginalData(), entity.getTableName(), attrMap); |
|
|
|
|
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) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
Map<String, String> attrMap = new HashMap<>(); |
|
|
|
|
Iterator<String> iterator = rootNode.fieldNames(); |
|
|
|
|
while (iterator.hasNext()) { |
|
|
|
|
String key = iterator.next(); |
|
|
|
|
attrMap.put(key, rootNode.findValue(key).textValue()); |
|
|
|
|
} |
|
|
|
|
weaviateService.saveBatch(response.getOriginalData(), entity.getTableName(), attrMap); |
|
|
|
|
this.update(Wrappers.<VectorParamEntity>lambdaUpdate().eq(VectorParamEntity::getId, id).set(VectorParamEntity::getUpdateTime, new Date())); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private JSONObject toJsonObject(JsonNode node) { |
|
|
|
|
JSONObject jsonObject = JSON.parseObject(node.toString()); |
|
|
|
|
return jsonObject; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|