Browse Source

clear test

dev-lhz
fanshuai 1 year ago
parent
commit
d38638359d
2 changed files with 32 additions and 5 deletions
  1. +2
    -5
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java
  2. +30
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ConvertUtil.java

+ 2
- 5
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java View File

@@ -1,6 +1,5 @@
package com.ruoyi.platform.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.platform.constant.Constant;
@@ -12,7 +11,6 @@ import com.ruoyi.platform.service.GitService;
import com.ruoyi.platform.service.NewDatasetService;
import com.ruoyi.platform.utils.*;
import com.ruoyi.platform.vo.GitProjectVo;
import com.ruoyi.platform.vo.ModelsVo;
import com.ruoyi.platform.vo.NewDatasetVo;
import com.ruoyi.platform.vo.VersionVo;
import com.ruoyi.system.api.model.LoginUser;
@@ -188,7 +186,7 @@ public class NewDatasetServiceImpl implements NewDatasetService {

//部分信息在前面的版本里面,从那边取过来
Map<String, Object> stringObjectMap = YamlUtils.loadYamlFile(localPath + "/" + "dataset.yaml");
NewDatasetVo newDatasetVo = ConvertUtil.convertMapToObject(stringObjectMap, NewDatasetVo.class);
NewDatasetVo newDatasetVo = ConvertUtil.convertMapToObject2(stringObjectMap, NewDatasetVo.class);
//检查是否存在本地重名分支,有的话干掉
dvcUtils.deleteLocalBranch(localPath, branchName);
// 创建本地分支
@@ -326,8 +324,7 @@ public class NewDatasetServiceImpl implements NewDatasetService {
List<Map<String, Object>> fileDetailsAfterGitPull = dvcUtils.getFileDetailsAfterGitPull(localPathlocal + loginUser.getUsername() + "/datasets/" + id, repo, version, "dataset", gitLinkUsername, gitLinkPassword);
// 在localPathlocal+id+"/"+repositoryName目录下的dataset.yaml中取到元数据
Map<String, Object> stringObjectMap = YamlUtils.loadYamlFile(localPathlocal + loginUser.getUsername() + "/datasets/" + id + "/" + repo + "/" + "dataset.yaml");
String jsonString = JSON.toJSONString(stringObjectMap);
NewDatasetVo newDatasetVo = JSON.parseObject(jsonString, NewDatasetVo.class);
NewDatasetVo newDatasetVo = ConvertUtil.convertMapToObject2(stringObjectMap, NewDatasetVo.class);
List<VersionVo> versionVos = new ArrayList<VersionVo>();
if (fileDetailsAfterGitPull != null && fileDetailsAfterGitPull.size() > 0) {
for (Map<String, Object> fileDetail : fileDetailsAfterGitPull) {


+ 30
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/ConvertUtil.java View File

@@ -98,6 +98,36 @@ public class ConvertUtil {
return null;
}

public static <T> T convertMapToObject2(Map<String, Object> map, Class<T> targetClass) {
try {
T targetObject = targetClass.newInstance();
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
String camelCaseKey = toCamelCase(key);

if (hasProperty(targetClass, camelCaseKey)) {
// 获取目标属性的类型
Class<?> propertyType = PropertyUtils.getPropertyType(targetObject, camelCaseKey);

if (propertyType.isAssignableFrom(LinkedHashMap.class)) {
// 如果属性类型是 HashMap,则递归转换
Map<String, Object> mapValue = (Map<String, Object>) value;
Object convertedValue = convertMapToObject(mapValue, propertyType);
PropertyUtils.setProperty(targetObject, camelCaseKey, convertedValue);
} else if (!(value instanceof LinkedHashMap)) {
PropertyUtils.setProperty(targetObject, camelCaseKey, value);
}
}
}
return targetObject;
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
return null;
}


private static boolean hasProperty(Class<?> clazz, String propertyName) {
try {
Field field = clazz.getDeclaredField(propertyName);


Loading…
Cancel
Save