88 lines
2.8 KiB
Java
88 lines
2.8 KiB
Java
package com.yunhai.notice.controller.api;
|
|
|
|
import com.yunhai.notice.config.Config;
|
|
import com.yunhai.notice.model.notice.UpFileResultVo;
|
|
import com.yunhai.notice.model.notice.UpFileVo;
|
|
import com.yunhai.notice.service.IFileService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 附件域接口(file/)。
|
|
* <p>路径前缀:{@code Config.API_PATH + "/file/"}(原 base/ 前缀已修正为独立文件域)。
|
|
* 方法名统一 PascalCase;写操作一律 POST。
|
|
* 返回裸对象,由 ApiResponseAdvice 自动包装为 {code, msg, data}。</p>
|
|
*/
|
|
@RestController
|
|
@RequestMapping(value = Config.API_PATH + "/file/")
|
|
public class FileController {
|
|
|
|
@Autowired
|
|
private IFileService fileService;
|
|
|
|
/**
|
|
* 附件上传(单文件)。
|
|
* 前端: POST file/Upload (form-data)
|
|
* 返回: { fileid, host, fileurl, name, type, size }
|
|
*/
|
|
@PostMapping("Upload")
|
|
public UpFileResultVo upload(@RequestParam("file") MultipartFile file) {
|
|
return fileService.uploadToResult(file, "notice");
|
|
}
|
|
|
|
/**
|
|
* 图片上传(多文件,返回数组)。
|
|
* 前端: POST file/UploadImage (form-data, accept=image/*)
|
|
*/
|
|
@PostMapping("UploadImage")
|
|
public List<UpFileVo> uploadImage(@RequestParam("file") MultipartFile[] files) {
|
|
return fileService.uploadImages(files, "notice");
|
|
}
|
|
/**
|
|
* 文件下载(浏览器直接 location.href 跳转)。
|
|
*/
|
|
@GetMapping("Down")
|
|
public void down(@RequestParam("id") Integer id, HttpServletResponse response) {
|
|
fileService.download(id, response);
|
|
}
|
|
|
|
/**
|
|
* 文件在线预览(inline 输出,前端取 Blob 交给 open-file-viewer 渲染)。
|
|
*/
|
|
@GetMapping("Preview")
|
|
public void preview(@RequestParam("id") Integer id,
|
|
@RequestParam(value = "type", required = false) Integer type,
|
|
HttpServletResponse response) {
|
|
fileService.preview(id, response);
|
|
}
|
|
|
|
/**
|
|
* 删除文件。
|
|
*/
|
|
@PostMapping("Delete")
|
|
public void delete(@RequestParam("fileId") Integer fileId) {
|
|
fileService.delete(fileId);
|
|
}
|
|
|
|
/**
|
|
* 查询某通知下的附件列表。
|
|
*/
|
|
@GetMapping("List")
|
|
public List<UpFileVo> list(@RequestParam("topicId") Integer topicId) {
|
|
return fileService.listByTopic("notice", topicId);
|
|
}
|
|
|
|
/**
|
|
* 批量绑定附件到通知。
|
|
*/
|
|
@PostMapping("Bind")
|
|
public void bind(@RequestParam("fileIds") List<Integer> fileIds,
|
|
@RequestParam("topicId") Integer topicId) {
|
|
fileService.bindToTopic(fileIds, topicId);
|
|
}
|
|
|
|
} |