删除无用代码
This commit is contained in:
parent
1b8ed7f033
commit
47d7fd829d
@ -1,116 +0,0 @@
|
||||
package com.xkrs.controller;
|
||||
|
||||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.dao.FilePathDao;
|
||||
import com.xkrs.model.entity.FilePath;
|
||||
import com.xkrs.utils.FileFastDfs;
|
||||
import com.xkrs.utils.FileUtil;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||||
import static com.xkrs.utils.FileUtil.getUploadInfo;
|
||||
|
||||
@RestController
|
||||
public class FileController {
|
||||
|
||||
@Resource
|
||||
private FileFastDfs fileFastDfs;
|
||||
|
||||
@Resource
|
||||
private FilePathDao filePathDao;
|
||||
|
||||
/**
|
||||
* 上传多张图片
|
||||
*
|
||||
* @param files
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/uploadFileMore")
|
||||
public String uploadFileMore(MultipartFile[] files) throws Exception {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
if (null == files || files.length == 0) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "result or fileType is null", locale);
|
||||
}
|
||||
List list = new ArrayList();
|
||||
for (MultipartFile file : files) {
|
||||
boolean m = FileUtil.checkFileSize(file.getSize(), 100, "M");
|
||||
if (m == false) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "图片大小不能超过100M", locale);
|
||||
}
|
||||
File file1 = fileFastDfs.multipartFileToFile(file);
|
||||
String dir = "fire_point";
|
||||
String info = fileFastDfs.uploadFile(file1, dir);
|
||||
Map<String, String> map = getUploadInfo(info);
|
||||
file1.delete();
|
||||
FilePath filePath = new FilePath();
|
||||
filePath.setFilePath(map.get("path"));
|
||||
filePath.setFileName(map.get("fileName"));
|
||||
filePath.setSize(map.get("size"));
|
||||
filePath.setMtime(map.get("mtime"));
|
||||
filePath.setUrl(map.get("url"));
|
||||
filePath.setMd5(map.get("md5"));
|
||||
filePath.setScene(map.get("scene"));
|
||||
filePathDao.save(filePath);
|
||||
}
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "上传成功!", locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传单张图片
|
||||
*
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/uploadFile")
|
||||
public String uploadFile(MultipartFile file) throws Exception {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
if (null == file) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.PARAM_NULL, "result or fileType is null", locale);
|
||||
}
|
||||
boolean m = FileUtil.checkFileSize(file.getSize(), 100, "M");
|
||||
if (m == false) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "图片大小不能超过100M", locale);
|
||||
}
|
||||
File file1 = fileFastDfs.multipartFileToFile(file);
|
||||
String dir = "fire_point";
|
||||
String info = fileFastDfs.uploadFile(file1, dir);
|
||||
Map<String, String> map = getUploadInfo(info);
|
||||
file1.delete();
|
||||
FilePath filePath = new FilePath();
|
||||
filePath.setFilePath(map.get("path"));
|
||||
filePath.setFileName(map.get("fileName"));
|
||||
filePath.setSize(map.get("size"));
|
||||
filePath.setMtime(map.get("mtime"));
|
||||
filePath.setUrl(map.get("url"));
|
||||
filePath.setMd5(map.get("md5"));
|
||||
filePath.setScene(map.get("scene"));
|
||||
filePathDao.save(filePath);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "上传成功!", locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询火点图片路径
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/findPath")
|
||||
public String findPath() {
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
List<Map<String, String>> path = filePathDao.findPath();
|
||||
if (path == null || path.size() == 0) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "还未上传任何图片信息!", locale);
|
||||
}
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, path, locale);
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.xkrs.dao;
|
||||
|
||||
import com.xkrs.model.entity.FilePath;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author XinYi Song
|
||||
*/
|
||||
public interface FilePathDao extends JpaRepository<FilePath,Long> {
|
||||
|
||||
/**
|
||||
* 查询全部路径
|
||||
* @return
|
||||
*/
|
||||
@Query(value = "select file_path filepath from file_path",nativeQuery = true)
|
||||
List<Map<String,String>> findPath();
|
||||
}
|
@ -1,135 +0,0 @@
|
||||
package com.xkrs.model.entity;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
/**
|
||||
* @author XinYi Song
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "file_path")
|
||||
public class FilePath {
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "file_path_seq_gen")
|
||||
@SequenceGenerator(name = "file_path_seq_gen", sequenceName = "file_path_id_seq",allocationSize = 1)
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 图片路径
|
||||
*/
|
||||
@Column(length = 500,columnDefinition = "varchar(500)")
|
||||
private String filePath;
|
||||
|
||||
@Column(length = 88,columnDefinition = "varchar(88)")
|
||||
private String fileName;
|
||||
|
||||
@Column(length = 65,columnDefinition = "varchar(65)")
|
||||
private String size;
|
||||
|
||||
@Column(length = 85,columnDefinition = "varchar(85)")
|
||||
private String mtime;
|
||||
|
||||
@Column(length = 88,columnDefinition = "varchar(88)")
|
||||
private String url;
|
||||
|
||||
@Column(length = 85,columnDefinition = "varchar(85)")
|
||||
private String md5;
|
||||
|
||||
@Column(length = 65,columnDefinition = "varchar(65)")
|
||||
private String scene;
|
||||
|
||||
public FilePath() {
|
||||
}
|
||||
|
||||
public FilePath(Integer id, String filePath, String fileName, String size, String mtime, String url, String md5, String scene) {
|
||||
this.id = id;
|
||||
this.filePath = filePath;
|
||||
this.fileName = fileName;
|
||||
this.size = size;
|
||||
this.mtime = mtime;
|
||||
this.url = url;
|
||||
this.md5 = md5;
|
||||
this.scene = scene;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(String size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getMtime() {
|
||||
return mtime;
|
||||
}
|
||||
|
||||
public void setMtime(String mtime) {
|
||||
this.mtime = mtime;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getMd5() {
|
||||
return md5;
|
||||
}
|
||||
|
||||
public void setMd5(String md5) {
|
||||
this.md5 = md5;
|
||||
}
|
||||
|
||||
public String getScene() {
|
||||
return scene;
|
||||
}
|
||||
|
||||
public void setScene(String scene) {
|
||||
this.scene = scene;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FilePath{" +
|
||||
"id=" + id +
|
||||
", filePath='" + filePath + '\'' +
|
||||
", fileName='" + fileName + '\'' +
|
||||
", size='" + size + '\'' +
|
||||
", mtime='" + mtime + '\'' +
|
||||
", url='" + url + '\'' +
|
||||
", md5='" + md5 + '\'' +
|
||||
", scene='" + scene + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user