|
@@ -13,6 +13,7 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -24,45 +25,65 @@ public class AlgorithmExpandDomainService {
|
|
|
private AlgorithmExpandMapper algorithmExpandMapper;
|
|
|
|
|
|
public void checkIsExisted(ResponseBodyVO<String> algorithmBody) {
|
|
|
- final String algorithmListResponseJson = algorithmBody.getInfo();
|
|
|
- log.info("算法平台请求结果为:{}", algorithmListResponseJson);
|
|
|
- final String algorithmListJson = JsonUtil.getString(algorithmListResponseJson, "data.content");
|
|
|
- log.info("算法平台的算法列表JSON为:{}", algorithmListJson);
|
|
|
- final List<AlgorithmExpandAclEntity> algorithmExpandAclEntities = JsonUtil.jsonToList(algorithmListJson, AlgorithmExpandAclEntity.class);
|
|
|
- log.info("算法平台的算法列表为:{}", algorithmExpandAclEntities);
|
|
|
- if (CollectionUtil.isNotEmpty(algorithmExpandAclEntities)) {
|
|
|
- //1 获取算法平台查询到的所有算法ID
|
|
|
- final List<String> aclAlgorithmIds = algorithmExpandAclEntities.stream().map(AlgorithmExpandAclEntity::getAlgorithmId).collect(Collectors.toList());
|
|
|
- log.info("算法平台的算法ID列表为:{}", aclAlgorithmIds);
|
|
|
- List<String> infrastructureAlgorithmIds = algorithmExpandMapper.selectAlgorithmIds(AlgorithmExpandInfrastructureParam.builder().algorithmIds(aclAlgorithmIds).build());
|
|
|
- //2 不存在的数据插入数据库并设置状态为“未测试”
|
|
|
- algorithmExpandAclEntities.forEach(algorithmExpandAclEntity -> {
|
|
|
- final String algorithmId = algorithmExpandAclEntity.getAlgorithmId();
|
|
|
- if (infrastructureAlgorithmIds.contains(algorithmId)) {
|
|
|
- log.info("更新算法平台算法。");
|
|
|
- final List<AlgorithmExpandEntity> AlgorithmExpandInfrastructureEntities = algorithmExpandMapper.select(AlgorithmExpandInfrastructureParam.builder().algorithmId(algorithmId).build());
|
|
|
- final AlgorithmExpandEntity algorithmExpandEntity = AlgorithmExpandInfrastructureEntities.get(0);
|
|
|
- // status 不能被覆盖
|
|
|
-// BeanUtils.copyProperties(algorithmExpandAclEntity, algorithmExpandEntity);
|
|
|
- {
|
|
|
- algorithmExpandEntity.setId(algorithmExpandAclEntity.getId());
|
|
|
- algorithmExpandEntity.setAlgorithmId(algorithmExpandAclEntity.getAlgorithmId());
|
|
|
- algorithmExpandEntity.setAlgorithmName(algorithmExpandAclEntity.getAlgorithmName());
|
|
|
- algorithmExpandEntity.setDescription(algorithmExpandAclEntity.getDescription());
|
|
|
- algorithmExpandEntity.setAlgorithmType(algorithmExpandAclEntity.getAlgorithmType());
|
|
|
- algorithmExpandEntity.setAlgorithmVersion(algorithmExpandAclEntity.getAlgorithmVersion());
|
|
|
- algorithmExpandEntity.setTeam(algorithmExpandAclEntity.getTeam());
|
|
|
- algorithmExpandEntity.setTopic(algorithmExpandAclEntity.getTopic());
|
|
|
+ try {
|
|
|
+ final String algorithmListResponseJson = algorithmBody.getInfo();
|
|
|
+ log.info("算法平台请求结果为:{}", algorithmListResponseJson);
|
|
|
+ final String algorithmListJson = JsonUtil.getString(algorithmListResponseJson, "data.content");
|
|
|
+ log.info("算法平台的算法列表JSON为:{}", algorithmListJson);
|
|
|
+ List<AlgorithmExpandAclEntity> algorithmExpandAclEntitiesTemp = JsonUtil.jsonToList(algorithmListJson, AlgorithmExpandAclEntity.class);
|
|
|
+ List<AlgorithmExpandAclEntity> algorithmExpandAclEntities = new ArrayList<>();
|
|
|
+ for (AlgorithmExpandAclEntity algorithmExpandAclEntity : algorithmExpandAclEntitiesTemp) {
|
|
|
+ if (algorithmExpandAclEntity == null) { // v20240605 竟然有空数据
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ algorithmExpandAclEntities.add(algorithmExpandAclEntity);
|
|
|
+ }
|
|
|
+ log.info("算法平台的算法列表为:{}", algorithmExpandAclEntities);
|
|
|
+ if (CollectionUtil.isNotEmpty(algorithmExpandAclEntities)) {
|
|
|
+ //1 获取算法平台查询到的所有算法ID
|
|
|
+// final List<String> aclAlgorithmIds = algorithmExpandAclEntities.stream().map(AlgorithmExpandAclEntity::getAlgorithmId).collect(Collectors.toList());
|
|
|
+ List<String> aclAlgorithmIds = new ArrayList<>();
|
|
|
+ for (AlgorithmExpandAclEntity algorithmExpandAclEntity : algorithmExpandAclEntities) {
|
|
|
+ if (algorithmExpandAclEntity.getAlgorithmId() == null || algorithmExpandAclEntity.getAlgorithmId().isEmpty()) {
|
|
|
+ log.error("存在错误数据(algorithmId为空):{}", algorithmExpandAclEntity);
|
|
|
+ } else {
|
|
|
+ aclAlgorithmIds.add(algorithmExpandAclEntity.getAlgorithmId());
|
|
|
}
|
|
|
- algorithmExpandMapper.update(algorithmExpandEntity);
|
|
|
- } else {
|
|
|
- log.info("插入算法平台算法。");
|
|
|
- final AlgorithmExpandEntity algorithmExpandEntity = new AlgorithmExpandEntity();
|
|
|
- BeanUtils.copyProperties(algorithmExpandAclEntity, algorithmExpandEntity);
|
|
|
- algorithmExpandEntity.setStatus(DictConstants.ALGORITHM_EXPAND_STATUS_NOT_TESTED);
|
|
|
- algorithmExpandMapper.insert(algorithmExpandEntity);
|
|
|
}
|
|
|
- });
|
|
|
+ log.info("算法平台的算法ID列表为:{}", aclAlgorithmIds);
|
|
|
+ List<String> infrastructureAlgorithmIds = algorithmExpandMapper.selectAlgorithmIds(AlgorithmExpandInfrastructureParam.builder().algorithmIds(aclAlgorithmIds).build());
|
|
|
+ //2 不存在的数据插入数据库并设置状态为“未测试”
|
|
|
+ algorithmExpandAclEntities.forEach(algorithmExpandAclEntity -> {
|
|
|
+ final String algorithmId = algorithmExpandAclEntity.getAlgorithmId();
|
|
|
+ if (infrastructureAlgorithmIds.contains(algorithmId)) {
|
|
|
+ log.info("更新算法平台算法。");
|
|
|
+ final List<AlgorithmExpandEntity> AlgorithmExpandInfrastructureEntities = algorithmExpandMapper.select(AlgorithmExpandInfrastructureParam.builder().algorithmId(algorithmId).build());
|
|
|
+ final AlgorithmExpandEntity algorithmExpandEntity = AlgorithmExpandInfrastructureEntities.get(0);
|
|
|
+ // status 不能被覆盖
|
|
|
+ // BeanUtils.copyProperties(algorithmExpandAclEntity, algorithmExpandEntity);
|
|
|
+ {
|
|
|
+ algorithmExpandEntity.setId(algorithmExpandAclEntity.getId());
|
|
|
+ algorithmExpandEntity.setAlgorithmId(algorithmExpandAclEntity.getAlgorithmId());
|
|
|
+ algorithmExpandEntity.setAlgorithmName(algorithmExpandAclEntity.getAlgorithmName());
|
|
|
+ algorithmExpandEntity.setDescription(algorithmExpandAclEntity.getDescription());
|
|
|
+ algorithmExpandEntity.setAlgorithmType(algorithmExpandAclEntity.getAlgorithmType());
|
|
|
+ algorithmExpandEntity.setAlgorithmVersion(algorithmExpandAclEntity.getAlgorithmVersion());
|
|
|
+ algorithmExpandEntity.setTeam(algorithmExpandAclEntity.getTeam());
|
|
|
+ algorithmExpandEntity.setTopic(algorithmExpandAclEntity.getTopic());
|
|
|
+ }
|
|
|
+ algorithmExpandMapper.update(algorithmExpandEntity);
|
|
|
+ } else {
|
|
|
+ log.info("插入算法平台算法。");
|
|
|
+ final AlgorithmExpandEntity algorithmExpandEntity = new AlgorithmExpandEntity();
|
|
|
+ BeanUtils.copyProperties(algorithmExpandAclEntity, algorithmExpandEntity);
|
|
|
+ algorithmExpandEntity.setStatus(DictConstants.ALGORITHM_EXPAND_STATUS_NOT_TESTED);
|
|
|
+ algorithmExpandMapper.insert(algorithmExpandEntity);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("检查算法是否存在报错:", e);
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
|