12 changed files with 1022 additions and 22 deletions
@ -0,0 +1,242 @@ |
|||
package com.boge.common.utils; |
|||
|
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
@Configuration |
|||
@ConfigurationProperties( |
|||
prefix = "file" |
|||
) |
|||
public class FileProperties { |
|||
private Long maxSize; |
|||
private Long avatarMaxSize; |
|||
private ElPath mac; |
|||
private ElPath linux; |
|||
private ElPath windows; |
|||
|
|||
public ElPath getPath() { |
|||
String os = System.getProperty("os.name"); |
|||
if (os.toLowerCase().startsWith("win")) { |
|||
return this.windows; |
|||
} else { |
|||
return os.toLowerCase().startsWith("mac") ? this.mac : this.linux; |
|||
} |
|||
} |
|||
|
|||
public FileProperties() { |
|||
} |
|||
|
|||
public Long getMaxSize() { |
|||
return this.maxSize; |
|||
} |
|||
|
|||
public Long getAvatarMaxSize() { |
|||
return this.avatarMaxSize; |
|||
} |
|||
|
|||
public ElPath getMac() { |
|||
return this.mac; |
|||
} |
|||
|
|||
public ElPath getLinux() { |
|||
return this.linux; |
|||
} |
|||
|
|||
public ElPath getWindows() { |
|||
return this.windows; |
|||
} |
|||
|
|||
public void setMaxSize(final Long maxSize) { |
|||
this.maxSize = maxSize; |
|||
} |
|||
|
|||
public void setAvatarMaxSize(final Long avatarMaxSize) { |
|||
this.avatarMaxSize = avatarMaxSize; |
|||
} |
|||
|
|||
public void setMac(final ElPath mac) { |
|||
this.mac = mac; |
|||
} |
|||
|
|||
public void setLinux(final ElPath linux) { |
|||
this.linux = linux; |
|||
} |
|||
|
|||
public void setWindows(final ElPath windows) { |
|||
this.windows = windows; |
|||
} |
|||
|
|||
public boolean equals(final Object o) { |
|||
if (o == this) { |
|||
return true; |
|||
} else if (!(o instanceof FileProperties)) { |
|||
return false; |
|||
} else { |
|||
FileProperties other = (FileProperties)o; |
|||
if (!other.canEqual(this)) { |
|||
return false; |
|||
} else { |
|||
label71: { |
|||
Object this$maxSize = this.getMaxSize(); |
|||
Object other$maxSize = other.getMaxSize(); |
|||
if (this$maxSize == null) { |
|||
if (other$maxSize == null) { |
|||
break label71; |
|||
} |
|||
} else if (this$maxSize.equals(other$maxSize)) { |
|||
break label71; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
Object this$avatarMaxSize = this.getAvatarMaxSize(); |
|||
Object other$avatarMaxSize = other.getAvatarMaxSize(); |
|||
if (this$avatarMaxSize == null) { |
|||
if (other$avatarMaxSize != null) { |
|||
return false; |
|||
} |
|||
} else if (!this$avatarMaxSize.equals(other$avatarMaxSize)) { |
|||
return false; |
|||
} |
|||
|
|||
label57: { |
|||
Object this$mac = this.getMac(); |
|||
Object other$mac = other.getMac(); |
|||
if (this$mac == null) { |
|||
if (other$mac == null) { |
|||
break label57; |
|||
} |
|||
} else if (this$mac.equals(other$mac)) { |
|||
break label57; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
Object this$linux = this.getLinux(); |
|||
Object other$linux = other.getLinux(); |
|||
if (this$linux == null) { |
|||
if (other$linux != null) { |
|||
return false; |
|||
} |
|||
} else if (!this$linux.equals(other$linux)) { |
|||
return false; |
|||
} |
|||
|
|||
Object this$windows = this.getWindows(); |
|||
Object other$windows = other.getWindows(); |
|||
if (this$windows == null) { |
|||
if (other$windows == null) { |
|||
return true; |
|||
} |
|||
} else if (this$windows.equals(other$windows)) { |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
} |
|||
} |
|||
|
|||
protected boolean canEqual(final Object other) { |
|||
return other instanceof FileProperties; |
|||
} |
|||
|
|||
public int hashCode() { |
|||
boolean PRIME = true; |
|||
int result = 1; |
|||
Object $maxSize = this.getMaxSize(); |
|||
result = result * 59 + ($maxSize == null ? 43 : $maxSize.hashCode()); |
|||
Object $avatarMaxSize = this.getAvatarMaxSize(); |
|||
result = result * 59 + ($avatarMaxSize == null ? 43 : $avatarMaxSize.hashCode()); |
|||
Object $mac = this.getMac(); |
|||
result = result * 59 + ($mac == null ? 43 : $mac.hashCode()); |
|||
Object $linux = this.getLinux(); |
|||
result = result * 59 + ($linux == null ? 43 : $linux.hashCode()); |
|||
Object $windows = this.getWindows(); |
|||
result = result * 59 + ($windows == null ? 43 : $windows.hashCode()); |
|||
return result; |
|||
} |
|||
|
|||
public String toString() { |
|||
return "FileProperties(maxSize=" + this.getMaxSize() + ", avatarMaxSize=" + this.getAvatarMaxSize() + ", mac=" + this.getMac() + ", linux=" + this.getLinux() + ", windows=" + this.getWindows() + ")"; |
|||
} |
|||
|
|||
public static class ElPath { |
|||
private String path; |
|||
private String avatar; |
|||
|
|||
public ElPath() { |
|||
} |
|||
|
|||
public String getPath() { |
|||
return this.path; |
|||
} |
|||
|
|||
public String getAvatar() { |
|||
return this.avatar; |
|||
} |
|||
|
|||
public void setPath(final String path) { |
|||
this.path = path; |
|||
} |
|||
|
|||
public void setAvatar(final String avatar) { |
|||
this.avatar = avatar; |
|||
} |
|||
|
|||
public boolean equals(final Object o) { |
|||
if (o == this) { |
|||
return true; |
|||
} else if (!(o instanceof ElPath)) { |
|||
return false; |
|||
} else { |
|||
ElPath other = (ElPath)o; |
|||
if (!other.canEqual(this)) { |
|||
return false; |
|||
} else { |
|||
Object this$path = this.getPath(); |
|||
Object other$path = other.getPath(); |
|||
if (this$path == null) { |
|||
if (other$path != null) { |
|||
return false; |
|||
} |
|||
} else if (!this$path.equals(other$path)) { |
|||
return false; |
|||
} |
|||
|
|||
Object this$avatar = this.getAvatar(); |
|||
Object other$avatar = other.getAvatar(); |
|||
if (this$avatar == null) { |
|||
if (other$avatar != null) { |
|||
return false; |
|||
} |
|||
} else if (!this$avatar.equals(other$avatar)) { |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
|
|||
protected boolean canEqual(final Object other) { |
|||
return other instanceof ElPath; |
|||
} |
|||
|
|||
public int hashCode() { |
|||
boolean PRIME = true; |
|||
int result = 1; |
|||
Object $path = this.getPath(); |
|||
result = result * 59 + ($path == null ? 43 : $path.hashCode()); |
|||
Object $avatar = this.getAvatar(); |
|||
result = result * 59 + ($avatar == null ? 43 : $avatar.hashCode()); |
|||
return result; |
|||
} |
|||
|
|||
public String toString() { |
|||
return "FileProperties.ElPath(path=" + this.getPath() + ", avatar=" + this.getAvatar() + ")"; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,281 @@ |
|||
package com.boge.common.utils; |
|||
|
|||
import java.text.DecimalFormat; |
|||
|
|||
import cn.hutool.core.io.IoUtil; |
|||
import cn.hutool.core.util.IdUtil; |
|||
import cn.hutool.poi.excel.BigExcelWriter; |
|||
import cn.hutool.poi.excel.ExcelUtil; |
|||
import java.io.File; |
|||
import java.io.FileInputStream; |
|||
import java.io.FileNotFoundException; |
|||
import java.io.FileOutputStream; |
|||
import java.io.IOException; |
|||
import java.io.InputStream; |
|||
import java.io.OutputStream; |
|||
import java.security.MessageDigest; |
|||
import java.text.DecimalFormat; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import javax.servlet.ServletOutputStream; |
|||
import javax.servlet.http.HttpServletRequest; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
|
|||
import com.boge.common.exception.RRException; |
|||
import org.apache.poi.util.IOUtils; |
|||
import org.apache.poi.xssf.streaming.SXSSFSheet; |
|||
|
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
public class FileUtil extends cn.hutool.core.io.FileUtil { |
|||
private static final Logger log = LoggerFactory.getLogger(FileUtil.class); |
|||
public static final String SYS_TEM_DIR; |
|||
private static final int GB = 1073741824; |
|||
private static final int MB = 1048576; |
|||
private static final int KB = 1024; |
|||
private static final DecimalFormat DF; |
|||
public static final String IMAGE = "图片"; |
|||
public static final String TXT = "文档"; |
|||
public static final String MUSIC = "音乐"; |
|||
public static final String VIDEO = "视频"; |
|||
public static final String OTHER = "其他"; |
|||
|
|||
public FileUtil() { |
|||
} |
|||
|
|||
public static File toFile(MultipartFile multipartFile) { |
|||
String fileName = multipartFile.getOriginalFilename(); |
|||
String prefix = "." + getExtensionName(fileName); |
|||
File file = null; |
|||
|
|||
try { |
|||
file = new File(SYS_TEM_DIR + IdUtil.simpleUUID() + prefix); |
|||
multipartFile.transferTo(file); |
|||
} catch (IOException var5) { |
|||
IOException e = var5; |
|||
log.error(e.getMessage(), e); |
|||
} |
|||
|
|||
return file; |
|||
} |
|||
|
|||
public static String getExtensionName(String filename) { |
|||
if (filename != null && filename.length() > 0) { |
|||
int dot = filename.lastIndexOf(46); |
|||
if (dot > -1 && dot < filename.length() - 1) { |
|||
return filename.substring(dot + 1); |
|||
} |
|||
} |
|||
|
|||
return filename; |
|||
} |
|||
|
|||
public static String getFileNameNoEx(String filename) { |
|||
if (filename != null && filename.length() > 0) { |
|||
int dot = filename.lastIndexOf(46); |
|||
if (dot > -1 && dot < filename.length()) { |
|||
return filename.substring(0, dot); |
|||
} |
|||
} |
|||
|
|||
return filename; |
|||
} |
|||
|
|||
public static String getSize(long size) { |
|||
String resultSize; |
|||
if (size / 1073741824L >= 1L) { |
|||
resultSize = DF.format((double)((float)size / 1.07374182E9F)) + "GB "; |
|||
} else if (size / 1048576L >= 1L) { |
|||
resultSize = DF.format((double)((float)size / 1048576.0F)) + "MB "; |
|||
} else if (size / 1024L >= 1L) { |
|||
resultSize = DF.format((double)((float)size / 1024.0F)) + "KB "; |
|||
} else { |
|||
resultSize = size + "B "; |
|||
} |
|||
|
|||
return resultSize; |
|||
} |
|||
|
|||
static File inputStreamToFile(InputStream ins, String name) throws Exception { |
|||
File file = new File(SYS_TEM_DIR + name); |
|||
if (file.exists()) { |
|||
return file; |
|||
} else { |
|||
OutputStream os = new FileOutputStream(file); |
|||
int len = 8192; |
|||
byte[] buffer = new byte[len]; |
|||
|
|||
int bytesRead; |
|||
while((bytesRead = ins.read(buffer, 0, len)) != -1) { |
|||
os.write(buffer, 0, bytesRead); |
|||
} |
|||
|
|||
os.close(); |
|||
ins.close(); |
|||
return file; |
|||
} |
|||
} |
|||
|
|||
public static File upload(MultipartFile file, String filePath) { |
|||
Date date = new Date(); |
|||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS"); |
|||
String name = getFileNameNoEx(file.getOriginalFilename()); |
|||
String suffix = getExtensionName(file.getOriginalFilename()); |
|||
String nowStr = "-" + format.format(date); |
|||
|
|||
try { |
|||
String fileName = name + nowStr + "." + suffix; |
|||
String path = filePath + fileName; |
|||
File dest = (new File(path)).getCanonicalFile(); |
|||
if (!dest.getParentFile().exists() && !dest.getParentFile().mkdirs()) { |
|||
System.out.println("was not successful."); |
|||
} |
|||
|
|||
file.transferTo(dest); |
|||
return dest; |
|||
} catch (Exception var10) { |
|||
Exception e = var10; |
|||
log.error(e.getMessage(), e); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
public static void downloadExcel(List<Map<String, Object>> list, HttpServletResponse response) throws IOException { |
|||
String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx"; |
|||
File file = new File(tempPath); |
|||
BigExcelWriter writer = ExcelUtil.getBigWriter(file); |
|||
writer.write(list, true); |
|||
SXSSFSheet sheet = (SXSSFSheet)writer.getSheet(); |
|||
sheet.trackAllColumnsForAutoSizing(); |
|||
writer.autoSizeColumnAll(); |
|||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); |
|||
response.setHeader("Content-Disposition", "attachment;filename=file.xlsx"); |
|||
ServletOutputStream out = response.getOutputStream(); |
|||
file.deleteOnExit(); |
|||
writer.flush(out, true); |
|||
IoUtil.close(out); |
|||
} |
|||
|
|||
public static String getFileType(String type) { |
|||
String documents = "txt doc pdf ppt pps xlsx xls docx"; |
|||
String music = "mp3 wav wma mpa ram ra aac aif m4a"; |
|||
String video = "avi mpg mpe mpeg asf wmv mov qt rm mp4 flv m4v webm ogv ogg"; |
|||
String image = "bmp dib pcp dif wmf gif jpg tif eps psd cdr iff tga pcd mpt png jpeg svg"; |
|||
if (image.contains(type)) { |
|||
return "图片"; |
|||
} else if (documents.contains(type)) { |
|||
return "文档"; |
|||
} else if (music.contains(type)) { |
|||
return "音乐"; |
|||
} else { |
|||
return video.contains(type) ? "视频" : "其他"; |
|||
} |
|||
} |
|||
|
|||
public static void checkSize(long maxSize, long size) { |
|||
int len = 1048576; |
|||
if (size > maxSize * (long)len) { |
|||
throw new RRException("文件超出规定大小"); |
|||
} |
|||
} |
|||
|
|||
public static boolean check(File file1, File file2) { |
|||
String img1Md5 = getMd5(file1); |
|||
String img2Md5 = getMd5(file2); |
|||
return img1Md5.equals(img2Md5); |
|||
} |
|||
|
|||
public static boolean check(String file1Md5, String file2Md5) { |
|||
return file1Md5.equals(file2Md5); |
|||
} |
|||
|
|||
private static byte[] getByte(File file) { |
|||
byte[] b = new byte[(int)file.length()]; |
|||
|
|||
try { |
|||
InputStream in = new FileInputStream(file); |
|||
|
|||
try { |
|||
System.out.println(in.read(b)); |
|||
} catch (IOException var4) { |
|||
IOException e = var4; |
|||
log.error(e.getMessage(), e); |
|||
} |
|||
|
|||
return b; |
|||
} catch (FileNotFoundException var5) { |
|||
FileNotFoundException e = var5; |
|||
log.error(e.getMessage(), e); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
private static String getMd5(byte[] bytes) { |
|||
char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; |
|||
|
|||
try { |
|||
MessageDigest mdTemp = MessageDigest.getInstance("MD5"); |
|||
mdTemp.update(bytes); |
|||
byte[] md = mdTemp.digest(); |
|||
int j = md.length; |
|||
char[] str = new char[j * 2]; |
|||
int k = 0; |
|||
byte[] var7 = md; |
|||
int var8 = md.length; |
|||
|
|||
for(int var9 = 0; var9 < var8; ++var9) { |
|||
byte byte0 = var7[var9]; |
|||
str[k++] = hexDigits[byte0 >>> 4 & 15]; |
|||
str[k++] = hexDigits[byte0 & 15]; |
|||
} |
|||
|
|||
return new String(str); |
|||
} catch (Exception var11) { |
|||
Exception e = var11; |
|||
log.error(e.getMessage(), e); |
|||
return null; |
|||
} |
|||
} |
|||
|
|||
public static void downloadFile(HttpServletRequest request, HttpServletResponse response, File file, boolean deleteOnExit) { |
|||
response.setCharacterEncoding(request.getCharacterEncoding()); |
|||
response.setContentType("application/octet-stream"); |
|||
FileInputStream fis = null; |
|||
|
|||
try { |
|||
fis = new FileInputStream(file); |
|||
response.setHeader("Content-Disposition", "attachment; filename=" + file.getName()); |
|||
IOUtils.copy(fis, response.getOutputStream()); |
|||
response.flushBuffer(); |
|||
} catch (Exception var14) { |
|||
Exception e = var14; |
|||
log.error(e.getMessage(), e); |
|||
} finally { |
|||
if (fis != null) { |
|||
try { |
|||
fis.close(); |
|||
if (deleteOnExit) { |
|||
file.deleteOnExit(); |
|||
} |
|||
} catch (IOException var13) { |
|||
IOException e = var13; |
|||
log.error(e.getMessage(), e); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
public static String getMd5(File file) { |
|||
return getMd5(getByte(file)); |
|||
} |
|||
|
|||
static { |
|||
SYS_TEM_DIR = System.getProperty("java.io.tmpdir") + File.separator; |
|||
DF = new DecimalFormat("0.00"); |
|||
} |
|||
} |
@ -0,0 +1,81 @@ |
|||
//
|
|||
// Source code recreated from a .class file by IntelliJ IDEA
|
|||
// (powered by FernFlower decompiler)
|
|||
//
|
|||
package com.boge.modules.tickets.controller; |
|||
import com.boge.common.exception.RRException; |
|||
import com.boge.common.utils.FileUtil; |
|||
import com.boge.modules.tickets.entity.LocalStorage; |
|||
import com.boge.modules.tickets.service.LocalStorageService; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import java.io.IOException; |
|||
import java.util.Map; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
|
|||
import org.springframework.http.HttpStatus; |
|||
import org.springframework.http.ResponseEntity; |
|||
import org.springframework.validation.annotation.Validated; |
|||
import org.springframework.web.bind.annotation.DeleteMapping; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.PutMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
@RestController |
|||
@Api( |
|||
tags = {"工具:本地存储管理"} |
|||
) |
|||
@RequestMapping({"/api/localStorage"}) |
|||
public class LocalStorageController { |
|||
private final LocalStorageService localStorageService; |
|||
|
|||
@ApiOperation("查询文件") |
|||
@GetMapping |
|||
public ResponseEntity<Object> query() { |
|||
return new ResponseEntity(this.localStorageService.queryAll(), HttpStatus.OK); |
|||
} |
|||
|
|||
@ApiOperation("导出数据") |
|||
@GetMapping({"/download"}) |
|||
public void download(HttpServletResponse response) throws IOException { |
|||
|
|||
this.localStorageService.download(this.localStorageService.queryAll(), response); |
|||
} |
|||
|
|||
@ApiOperation("上传文件") |
|||
@PostMapping |
|||
public ResponseEntity<Object> create(@RequestParam String name, @RequestParam("file") MultipartFile file) { |
|||
LocalStorage localStorage = this.localStorageService.create(name, file); |
|||
return new ResponseEntity(localStorage, HttpStatus.CREATED); |
|||
} |
|||
|
|||
@PostMapping({"/pictures"}) |
|||
@ApiOperation("上传图片") |
|||
public ResponseEntity<Object> upload(@RequestParam MultipartFile file) { |
|||
String suffix = FileUtil.getExtensionName(file.getOriginalFilename()); |
|||
if (!"图片".equals(FileUtil.getFileType(suffix))) { |
|||
throw new RRException("只能上传图片"); |
|||
} else { |
|||
LocalStorage localStorage = this.localStorageService.create((String)null, file); |
|||
return new ResponseEntity(localStorage, HttpStatus.OK); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
@DeleteMapping |
|||
@ApiOperation("多选删除") |
|||
public ResponseEntity<Object> delete(@RequestBody Long[] ids) { |
|||
this.localStorageService.deleteAll(ids); |
|||
return new ResponseEntity(HttpStatus.OK); |
|||
} |
|||
|
|||
public LocalStorageController(final LocalStorageService localStorageService) { |
|||
this.localStorageService = localStorageService; |
|||
} |
|||
} |
@ -0,0 +1,10 @@ |
|||
package com.boge.modules.tickets.dao; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.boge.modules.tickets.entity.LocalStorage; |
|||
import com.boge.modules.tickets.entity.TicketsEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
@Mapper |
|||
public interface LocalStorageMapper extends BaseMapper<LocalStorage> { |
|||
} |
@ -0,0 +1,15 @@ |
|||
package com.boge.modules.tickets.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
@Data |
|||
public class LocalStorageDto implements Serializable { |
|||
private Long id; |
|||
private String realName; |
|||
private String name; |
|||
private String suffix; |
|||
private String type; |
|||
private String size; |
|||
|
|||
} |
@ -0,0 +1,95 @@ |
|||
package com.boge.modules.tickets.entity; |
|||
|
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
import org.hibernate.annotations.CreationTimestamp; |
|||
import org.hibernate.annotations.UpdateTimestamp; |
|||
import org.springframework.data.annotation.CreatedBy; |
|||
import org.springframework.data.annotation.LastModifiedBy; |
|||
|
|||
import javax.persistence.*; |
|||
import java.io.Serializable; |
|||
import java.sql.Timestamp; |
|||
|
|||
@Entity |
|||
@Data |
|||
@Table( |
|||
name = "tool_local_storage" |
|||
) |
|||
public class LocalStorage implements Serializable { |
|||
|
|||
@Id |
|||
@Column( |
|||
name = "storage_id" |
|||
) |
|||
@ApiModelProperty( |
|||
value = "ID", |
|||
hidden = true |
|||
) |
|||
@GeneratedValue( |
|||
strategy = GenerationType.IDENTITY |
|||
) |
|||
private Long id; |
|||
@ApiModelProperty("真实文件名") |
|||
private String realName; |
|||
@ApiModelProperty("文件名") |
|||
private String name; |
|||
@ApiModelProperty("后缀") |
|||
private String suffix; |
|||
@ApiModelProperty("路径") |
|||
private String path; |
|||
@ApiModelProperty("类型") |
|||
private String type; |
|||
@ApiModelProperty("大小") |
|||
private String size; |
|||
@CreatedBy |
|||
@Column( |
|||
name = "create_by", |
|||
updatable = false |
|||
) |
|||
@ApiModelProperty( |
|||
value = "创建人", |
|||
hidden = true |
|||
) |
|||
private String createBy; |
|||
@LastModifiedBy |
|||
@Column( |
|||
name = "update_by" |
|||
) |
|||
@ApiModelProperty( |
|||
value = "更新人", |
|||
hidden = true |
|||
) |
|||
private String updatedBy; |
|||
@CreationTimestamp |
|||
@Column( |
|||
name = "create_time", |
|||
updatable = false |
|||
) |
|||
@ApiModelProperty( |
|||
value = "创建时间", |
|||
hidden = true |
|||
) |
|||
private Timestamp createTime; |
|||
@UpdateTimestamp |
|||
@Column( |
|||
name = "update_time" |
|||
) |
|||
@ApiModelProperty( |
|||
value = "更新时间", |
|||
hidden = true |
|||
) |
|||
private Timestamp updateTime; |
|||
|
|||
public LocalStorage(String realName, String name, String suffix, String path, String type, String size) { |
|||
this.realName = realName; |
|||
this.name = name; |
|||
this.suffix = suffix; |
|||
this.path = path; |
|||
this.type = type; |
|||
this.size = size; |
|||
} |
|||
|
|||
public LocalStorage() { |
|||
} |
|||
} |
@ -0,0 +1,83 @@ |
|||
package com.boge.modules.tickets.entity; |
|||
|
|||
import java.sql.Timestamp; |
|||
import java.util.List; |
|||
|
|||
public class LocalStorageQueryCriteria { |
|||
|
|||
private String blurry; |
|||
|
|||
private List<Timestamp> createTime; |
|||
|
|||
public LocalStorageQueryCriteria() { |
|||
} |
|||
|
|||
public String getBlurry() { |
|||
return this.blurry; |
|||
} |
|||
|
|||
public List<Timestamp> getCreateTime() { |
|||
return this.createTime; |
|||
} |
|||
|
|||
public void setBlurry(final String blurry) { |
|||
this.blurry = blurry; |
|||
} |
|||
|
|||
public void setCreateTime(final List<Timestamp> createTime) { |
|||
this.createTime = createTime; |
|||
} |
|||
|
|||
public boolean equals(final Object o) { |
|||
if (o == this) { |
|||
return true; |
|||
} else if (!(o instanceof LocalStorageQueryCriteria)) { |
|||
return false; |
|||
} else { |
|||
LocalStorageQueryCriteria other = (LocalStorageQueryCriteria)o; |
|||
if (!other.canEqual(this)) { |
|||
return false; |
|||
} else { |
|||
Object this$blurry = this.getBlurry(); |
|||
Object other$blurry = other.getBlurry(); |
|||
if (this$blurry == null) { |
|||
if (other$blurry != null) { |
|||
return false; |
|||
} |
|||
} else if (!this$blurry.equals(other$blurry)) { |
|||
return false; |
|||
} |
|||
|
|||
Object this$createTime = this.getCreateTime(); |
|||
Object other$createTime = other.getCreateTime(); |
|||
if (this$createTime == null) { |
|||
if (other$createTime != null) { |
|||
return false; |
|||
} |
|||
} else if (!this$createTime.equals(other$createTime)) { |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
|
|||
protected boolean canEqual(final Object other) { |
|||
return other instanceof LocalStorageQueryCriteria; |
|||
} |
|||
|
|||
public int hashCode() { |
|||
boolean PRIME = true; |
|||
int result = 1; |
|||
Object $blurry = this.getBlurry(); |
|||
result = result * 59 + ($blurry == null ? 43 : $blurry.hashCode()); |
|||
Object $createTime = this.getCreateTime(); |
|||
result = result * 59 + ($createTime == null ? 43 : $createTime.hashCode()); |
|||
return result; |
|||
} |
|||
|
|||
public String toString() { |
|||
return "LocalStorageQueryCriteria(blurry=" + this.getBlurry() + ", createTime=" + this.getCreateTime() + ")"; |
|||
} |
|||
} |
@ -0,0 +1,31 @@ |
|||
/* |
|||
* Copyright 2019-2020 Zheng Jie |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package com.boge.modules.tickets.enums; |
|||
|
|||
/** |
|||
* @author ZhangHouYing |
|||
* @date 2019-08-10 9:56 |
|||
*/ |
|||
public enum MsgType { |
|||
/** 连接 */ |
|||
CONNECT, |
|||
/** 关闭 */ |
|||
CLOSE, |
|||
/** 信息 */ |
|||
INFO, |
|||
/** 错误 */ |
|||
ERROR |
|||
} |
@ -0,0 +1,8 @@ |
|||
package com.boge.modules.tickets.repository; |
|||
|
|||
import com.boge.modules.tickets.entity.LocalStorage; |
|||
import org.springframework.data.jpa.repository.JpaRepository; |
|||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
|||
|
|||
public interface LocalStorageRepository extends JpaRepository<LocalStorage, Long>, JpaSpecificationExecutor<LocalStorage> { |
|||
} |
@ -0,0 +1,22 @@ |
|||
package com.boge.modules.tickets.service; |
|||
|
|||
import com.boge.modules.tickets.dto.LocalStorageDto; |
|||
import com.boge.modules.tickets.entity.LocalStorage; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
|
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.io.IOException; |
|||
import java.util.List; |
|||
|
|||
public interface LocalStorageService { |
|||
|
|||
List<LocalStorage> queryAll(); |
|||
|
|||
|
|||
LocalStorage create(String name, MultipartFile file); |
|||
|
|||
|
|||
void deleteAll(Long[] ids); |
|||
|
|||
void download(List<LocalStorage> localStorageDtos, HttpServletResponse response) throws IOException; |
|||
} |
@ -0,0 +1,105 @@ |
|||
package com.boge.modules.tickets.service.impl; |
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import cn.hutool.core.util.StrUtil; |
|||
import java.io.File; |
|||
import java.io.IOException; |
|||
import java.util.ArrayList; |
|||
import java.util.Iterator; |
|||
import java.util.LinkedHashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.boge.common.exception.RRException; |
|||
import com.boge.common.utils.FileProperties; |
|||
import com.boge.common.utils.FileUtil; |
|||
import com.boge.modules.tickets.dao.LocalStorageMapper; |
|||
import com.boge.modules.tickets.entity.LocalStorage; |
|||
import com.boge.modules.tickets.entity.LocalStorageQueryCriteria; |
|||
import com.boge.modules.tickets.repository.LocalStorageRepository; |
|||
import com.boge.modules.tickets.service.LocalStorageService; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.web.multipart.MultipartFile; |
|||
@Service |
|||
public class LocalStorageServiceImpl extends ServiceImpl<LocalStorageMapper, LocalStorage> implements LocalStorageService { |
|||
private final LocalStorageRepository localStorageRepository; |
|||
private final LocalStorageMapper localStorageMapper; |
|||
private final FileProperties properties; |
|||
|
|||
public List<LocalStorage> queryAll() { |
|||
return localStorageMapper.selectList(new QueryWrapper<LocalStorage>()); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
@Transactional( |
|||
rollbackFor = {Exception.class} |
|||
) |
|||
public LocalStorage create(String name, MultipartFile multipartFile) { |
|||
FileUtil.checkSize(this.properties.getMaxSize(), multipartFile.getSize()); |
|||
String suffix = FileUtil.getExtensionName(multipartFile.getOriginalFilename()); |
|||
String type = FileUtil.getFileType(suffix); |
|||
File file = FileUtil.upload(multipartFile, this.properties.getPath().getPath() + type + File.separator); |
|||
if (ObjectUtil.isNull(file)) { |
|||
throw new RRException("上传失败"); |
|||
} else { |
|||
try { |
|||
name = StrUtil.isEmpty(name) ? FileUtil.getFileNameNoEx(multipartFile.getOriginalFilename()) : name; |
|||
LocalStorage localStorage = new LocalStorage(file.getName(), name, suffix, file.getPath(), type, FileUtil.getSize(multipartFile.getSize())); |
|||
return (LocalStorage)this.localStorageRepository.save(localStorage); |
|||
} catch (Exception var7) { |
|||
Exception e = var7; |
|||
FileUtil.del(file); |
|||
throw new RRException(e.toString()); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
@Transactional( |
|||
rollbackFor = {Exception.class} |
|||
) |
|||
public void deleteAll(Long[] ids) { |
|||
Long[] var2 = ids; |
|||
int var3 = ids.length; |
|||
|
|||
for(int var4 = 0; var4 < var3; ++var4) { |
|||
Long id = var2[var4]; |
|||
LocalStorage storage = (LocalStorage)this.localStorageRepository.findById(id).orElseGet(LocalStorage::new); |
|||
FileUtil.del(storage.getPath()); |
|||
this.localStorageRepository.delete(storage); |
|||
} |
|||
|
|||
} |
|||
|
|||
public void download(List<LocalStorage> queryAll, HttpServletResponse response) throws IOException { |
|||
List<Map<String, Object>> list = new ArrayList(); |
|||
Iterator var4 = queryAll.iterator(); |
|||
|
|||
while(var4.hasNext()) { |
|||
LocalStorage localStorageDTO = (LocalStorage)var4.next(); |
|||
Map<String, Object> map = new LinkedHashMap(); |
|||
map.put("文件名", localStorageDTO.getRealName()); |
|||
map.put("备注名", localStorageDTO.getName()); |
|||
map.put("文件类型", localStorageDTO.getType()); |
|||
map.put("文件大小", localStorageDTO.getSize()); |
|||
map.put("创建者", localStorageDTO.getCreateBy()); |
|||
map.put("创建日期", localStorageDTO.getCreateTime()); |
|||
list.add(map); |
|||
} |
|||
|
|||
FileUtil.downloadExcel(list, response); |
|||
} |
|||
|
|||
public LocalStorageServiceImpl(final LocalStorageRepository localStorageRepository, final LocalStorageMapper localStorageMapper, final FileProperties properties) { |
|||
this.localStorageRepository = localStorageRepository; |
|||
this.localStorageMapper = localStorageMapper; |
|||
this.properties = properties; |
|||
} |
|||
} |
Loading…
Reference in new issue