|
|
|
@@ -1,7 +1,9 @@ |
|
|
|
package com.ruoyi.platform.service.impl; |
|
|
|
|
|
|
|
import com.ruoyi.common.security.utils.SecurityUtils; |
|
|
|
import com.ruoyi.platform.annotations.CheckDuplicate; |
|
|
|
import com.ruoyi.platform.domain.AssetIcon; |
|
|
|
import com.ruoyi.platform.domain.Dataset; |
|
|
|
import com.ruoyi.platform.domain.Models; |
|
|
|
import com.ruoyi.platform.domain.ModelsVersion; |
|
|
|
import com.ruoyi.platform.mapper.ModelsDao; |
|
|
|
@@ -34,6 +36,7 @@ import javax.annotation.Resource; |
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
@@ -116,8 +119,9 @@ public class ModelsServiceImpl implements ModelsService { |
|
|
|
* @return 实例对象 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Models insert(Models models) { |
|
|
|
public Models insert(Models models) throws Exception { |
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser(); |
|
|
|
checkDeclaredName(models); |
|
|
|
models.setCreateBy(loginUser.getUsername()); |
|
|
|
models.setUpdateBy(loginUser.getUsername()); |
|
|
|
models.setUpdateTime(new Date()); |
|
|
|
@@ -173,8 +177,9 @@ public class ModelsServiceImpl implements ModelsService { |
|
|
|
if (!(StringUtils.equals(username,"admin") || StringUtils.equals(username,createdBy))){ |
|
|
|
throw new Exception("无权限删除该模型"); |
|
|
|
} |
|
|
|
if (modelsVersionService.queryByModelsId(id).size()>0){ |
|
|
|
throw new Exception("请先删除该镜像下的版本文件"); |
|
|
|
//判断是否有版本文件 |
|
|
|
if (!modelsVersionService.queryByModelsId(id).isEmpty()){ |
|
|
|
throw new Exception("请先删除该模型下的版本文件"); |
|
|
|
} |
|
|
|
models.setState(0); |
|
|
|
return this.modelsDao.update(models)>0?"删除成功":"删除失败"; |
|
|
|
@@ -427,6 +432,31 @@ public class ModelsServiceImpl implements ModelsService { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void checkDeclaredName(Models insert) throws Exception { |
|
|
|
Models existingModel = modelsDao.findByName(insert.getName()); |
|
|
|
if (existingModel != null) { |
|
|
|
// Check if the found models is not the same as the one being inserted |
|
|
|
// This is important if you are using this method for both insert and update operations |
|
|
|
// You may need an identifier check here, e.g., if 'insert' has an ID and it's the same as 'existingDataset' |
|
|
|
if (insert.getId() != null && insert.getId().equals(existingModel.getId())) { |
|
|
|
// This is the same dataset, no duplicate name issue for update operation |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
// Now we know there's another dataset with the same name |
|
|
|
Field[] fields = Models.class.getDeclaredFields(); |
|
|
|
for (Field field : fields) { |
|
|
|
field.setAccessible(true); // Make private fields accessible |
|
|
|
if ("name".equals(field.getName()) && field.isAnnotationPresent(CheckDuplicate.class)) { |
|
|
|
// If the field is 'name' and is marked with CheckDuplicate annotation |
|
|
|
CheckDuplicate annotation = field.getAnnotation(CheckDuplicate.class); |
|
|
|
throw new Exception("重复的模型名称: " + insert.getName() + ". " + annotation.message()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Map<String, String>> exportModels(String path, String uuid) throws Exception { |
|
|
|
List<Map<String, String>> results = new ArrayList<>(); |
|
|
|
|