skill模块联调

This commit is contained in:
cyc 2026-04-02 08:56:05 +08:00
parent 2aef6b8fd7
commit a31d6400e9
3 changed files with 40 additions and 5 deletions

View File

@ -105,4 +105,14 @@ public class SkillsController extends BaseController {
public AjaxResult uploadDataset(@RequestParam("file") MultipartFile files) throws Exception {
return AjaxResult.success(skillService.upload(files));
}
/**
* 下载
*
*/
@GetMapping("/download")
@ApiOperation("下载结果文件")
public GenericsAjaxResult<String> download(@RequestParam("url") String url) throws Exception {
return genericsSuccess(skillService.download(url));
}
}

View File

@ -29,4 +29,6 @@ public interface SkillService {
Skill unpraise(Long id);
Map<String, Object> upload(MultipartFile files) throws IOException;
String download(String url) throws Exception;
}

View File

@ -12,6 +12,7 @@ import com.ruoyi.platform.mapper.ApprovalInfoMapper;
import com.ruoyi.platform.mapper.SkillDao;
import com.ruoyi.platform.service.MinioService;
import com.ruoyi.platform.service.SkillService;
import com.ruoyi.platform.utils.MinioUtil;
import com.ruoyi.platform.vo.SkillVo;
import com.ruoyi.system.api.constant.Constant;
import com.ruoyi.system.api.model.LoginUser;
@ -51,6 +52,8 @@ public class SkillServiceImpl implements SkillService {
private ApprovalInfoMapper approvalInfoMapper;
@Resource
private MinioService minioService;
@Resource
private MinioUtil minioUtil;
@Override
public Page<Skill> queryByPage(Skill skill, PageRequest pageRequest) {
@ -73,6 +76,7 @@ public class SkillServiceImpl implements SkillService {
String username = SecurityUtils.getLoginUser().getUsername();
skill.setCreateBy(username);
skill.setUpdateBy(username);
skill.setPraisesCount(0);
skillDao.save(skill);
return skill;
}
@ -158,7 +162,7 @@ public class SkillServiceImpl implements SkillService {
@Override
public Skill unpraise(Long id) {
Skill skill = skillDao.getSkillById(id);
int praiseCount = skill.getPraisesCount() == null?0:skill.getPraisesCount() - 1;
int praiseCount = skill.getPraisesCount() == null ? 0 : skill.getPraisesCount() - 1;
skill.setPraisesCount(praiseCount);
skillDao.edit(skill);
return skill;
@ -177,10 +181,10 @@ public class SkillServiceImpl implements SkillService {
skill.setMdContent(IoUtil.read(file.getInputStream(), StandardCharsets.UTF_8));
} else if ("zip".equals(fileType)) {
// 解析 ZIP直接填充 metadata directoryTree contentText
parseZipAndFillMetadata(file.getInputStream(), skill);
parseZipAndFillMetadata(file.getInputStream(), skill, originalFilename.substring(0, originalFilename.length() - 4));
}
String savePath = "/mini-model-platform-data/skill_file/upload/" + "/" + cn.hutool.core.lang.UUID.fastUUID() + "/" + file.getOriginalFilename();
String savePath = "/mini-model-platform-data/skill_file/upload/" + "/" + cn.hutool.core.lang.UUID.fastUUID() + "/" + file.getOriginalFilename();
HashMap<String, Object> result = MapUtil.newHashMap();
result.put("file_name", file.getOriginalFilename());
result.put("file_path", savePath);
@ -199,16 +203,33 @@ public class SkillServiceImpl implements SkillService {
return result;
}
@Override
public String download(String url) throws Exception {
return minioUtil.downloadUrlWithResponseHeader(bucketName, url);
}
/**
* 解析 ZIP 直接填充 metadata directoryTree contentText
*/
private void parseZipAndFillMetadata(InputStream inputStream, Skill skill) throws IOException {
private void parseZipAndFillMetadata(InputStream inputStream, Skill skill, String zipFileName) throws IOException {
// 创建 ZIP 根文件夹节点
Map<String, Object> zipRootNode = new HashMap<>();
zipRootNode.put("name", zipFileName);
List<Map<String, Object>> zipRootChildren = new ArrayList<>();
zipRootNode.put("children", zipRootChildren);
// 根节点列表包含 ZIP 根文件夹
List<Map<String, Object>> rootChildren = new ArrayList<>();
rootChildren.add(zipRootNode);
Map<String, Map<String, Object>> pathToNode = new HashMap<>();
Map<String, Object> rootNode = new HashMap<>();
rootNode.put("children", rootChildren);
pathToNode.put("", rootNode);
// ZIP 根文件夹添加到路径映射中
pathToNode.put(zipFileName, zipRootNode);
StringBuilder skillMdContent = new StringBuilder();
try (ZipInputStream zis = new ZipInputStream(inputStream)) {
@ -237,7 +258,9 @@ public class SkillServiceImpl implements SkillService {
cleanName = cleanName.substring(0, cleanName.length() - 1);
}
String[] parts = StrUtil.splitToArray(cleanName, '/');
// 构建包含 ZIP 根文件夹的完整路径
String fullPathWithRoot = zipFileName + "/" + cleanName;
String[] parts = StrUtil.splitToArray(fullPathWithRoot, '/');
StringBuilder currentPath = new StringBuilder();
Map<String, Object> parentNode = pathToNode.get("");