| | |
| | | package org.springblade.mdm.program.controller; |
| | | |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.tenant.annotation.NonDS; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.mdm.program.entity.NcProgram; |
| | | import org.springblade.mdm.program.service.NcProgramService; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | private final NcProgramService ncProgramService; |
| | | |
| | | @PostMapping("/upload") |
| | | @Operation(summary = "上传", description = "上传程序/附件文件") |
| | | public R<Boolean> upload(@RequestParam MultipartFile file,Long nodeId, |
| | | @RequestParam String category) { |
| | | ncProgramService.uploadNcFile(file,nodeId,category); |
| | | @Operation(summary = "上传文件", description = "上传程序/附件文件") |
| | | public R<Boolean> upload(@Parameter(description="文件") @RequestPart("file") MultipartFile file, @Parameter(description="所属节点ID")@RequestParam Long nodeId, |
| | | @Parameter(description="文件分类,使用字典(node_file_type)") @RequestParam String category) { |
| | | ncProgramService.uploadProgramFile(file,nodeId,category); |
| | | return R.<Boolean>status(true); |
| | | } |
| | | |
| | | @PostMapping("/remove") |
| | | @Operation(summary = "删除程序文件", description = "") |
| | | public R<Boolean> removeFile(Long id) { |
| | | try { |
| | | ncProgramService.removeProgram(id); |
| | | return R.success(); |
| | | }catch(Exception e) { |
| | | log.error("删除文件失败",e); |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @GetMapping("/content") |
| | | @Operation(summary = "获取文件内容", description = "仅限文本格式的内容,二进制文件将返回空串") |
| | | public R<String> fileContent(Long id) { |
| | | try { |
| | | return R.data(ncProgramService.getFileContent(id)); |
| | | }catch(Exception e) { |
| | | log.error("删除文件失败",e); |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | } |
| | | } |