IntelligentRecognition/ah-jjsp-service/.svn/pristine/91/919307432eaf3f920885dc4cb69...

58 lines
1.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.sercurityControl.decision.controller;
import com.securityControl.common.core.web.domain.AjaxResult;
import com.sercurityControl.decision.domain.Attachment;
import com.sercurityControl.decision.service.FileService;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
/**
* 文件操作
*/
@RestController
@RequestMapping("/file")
public class FileController {
@Resource
private FileService fileService;
/**
* 图片下载
* @param attachment 文件对象只传md5
*/
@PostMapping("/queryPicId")
public AjaxResult queryPicId(@RequestBody Attachment attachment) {
String base64 = fileService.queryPicId(attachment.getMd5());
if (StringUtils.hasLength(base64)) {
return AjaxResult.success("图片查询成功!",base64);
}
return AjaxResult.error("图片查询失败!");
}
/**
* 文件上传
* @param file 文件
*/
@PostMapping("/upload")
public AjaxResult upload(@RequestParam MultipartFile file) throws Exception {
Attachment upload = fileService.upload(file);
if (ObjectUtils.isEmpty(upload)) {
return AjaxResult.error("文件上传失败!");
}
return AjaxResult.success(upload);
}
/**
* 文件下载
* @param md5 文件md5拼在链接后面
*/
@GetMapping("/getFile/{md5}")
public void getFile(@PathVariable("md5") String md5, HttpServletResponse response) {
fileService.getFile(md5,response);
}
}