From 843b514c5b0f1ed58e82c84d80558e30a4de3765 Mon Sep 17 00:00:00 2001 From: ls <1793460677@qq.com> Date: Mon, 17 Mar 2025 09:44:06 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E4=B8=8A=E4=BC=A0=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base-fast/pom.xml | 71 +++-- .../com/boge/common/utils/FileProperties.java | 242 +++++++++++++++ .../java/com/boge/common/utils/FileUtil.java | 281 ++++++++++++++++++ .../controller/LocalStorageController.java | 81 +++++ .../tickets/dao/LocalStorageMapper.java | 10 + .../modules/tickets/dto/LocalStorageDto.java | 15 + .../modules/tickets/entity/LocalStorage.java | 95 ++++++ .../entity/LocalStorageQueryCriteria.java | 83 ++++++ .../boge/modules/tickets/enums/MsgType.java | 31 ++ .../repository/LocalStorageRepository.java | 8 + .../tickets/service/LocalStorageService.java | 22 ++ .../service/impl/LocalStorageServiceImpl.java | 105 +++++++ 12 files changed, 1022 insertions(+), 22 deletions(-) create mode 100644 base-fast/src/main/java/com/boge/common/utils/FileProperties.java create mode 100644 base-fast/src/main/java/com/boge/common/utils/FileUtil.java create mode 100644 base-fast/src/main/java/com/boge/modules/tickets/controller/LocalStorageController.java create mode 100644 base-fast/src/main/java/com/boge/modules/tickets/dao/LocalStorageMapper.java create mode 100644 base-fast/src/main/java/com/boge/modules/tickets/dto/LocalStorageDto.java create mode 100644 base-fast/src/main/java/com/boge/modules/tickets/entity/LocalStorage.java create mode 100644 base-fast/src/main/java/com/boge/modules/tickets/entity/LocalStorageQueryCriteria.java create mode 100644 base-fast/src/main/java/com/boge/modules/tickets/enums/MsgType.java create mode 100644 base-fast/src/main/java/com/boge/modules/tickets/repository/LocalStorageRepository.java create mode 100644 base-fast/src/main/java/com/boge/modules/tickets/service/LocalStorageService.java create mode 100644 base-fast/src/main/java/com/boge/modules/tickets/service/impl/LocalStorageServiceImpl.java diff --git a/base-fast/pom.xml b/base-fast/pom.xml index 2312c27..4966be5 100644 --- a/base-fast/pom.xml +++ b/base-fast/pom.xml @@ -1,6 +1,6 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 io.base base-fast @@ -14,6 +14,9 @@ 2.4.12 + + + UTF-8 UTF-8 @@ -54,7 +57,16 @@ org.springframework.boot spring-boot-starter-web - + + com.jcraft + jsch + 0.1.55 + + + ch.ethz.ganymed + ganymed-ssh2 + build210 + org.springframework.boot spring-boot-starter-aop @@ -72,10 +84,25 @@ spring-boot-configuration-processor true + + javax.persistence + javax.persistence-api + 2.2 + + + org.hibernate + hibernate-core + 5.4.21.Final + + + org.springframework.boot + spring-boot-starter-data-jpa + + - - - + + + com.baomidou @@ -120,23 +147,23 @@ poi-ooxml 4.1.2 - - - + + + com.alibaba druid-spring-boot-starter diff --git a/base-fast/src/main/java/com/boge/common/utils/FileProperties.java b/base-fast/src/main/java/com/boge/common/utils/FileProperties.java new file mode 100644 index 0000000..f4a7ebf --- /dev/null +++ b/base-fast/src/main/java/com/boge/common/utils/FileProperties.java @@ -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() + ")"; + } + } +} diff --git a/base-fast/src/main/java/com/boge/common/utils/FileUtil.java b/base-fast/src/main/java/com/boge/common/utils/FileUtil.java new file mode 100644 index 0000000..1bed65e --- /dev/null +++ b/base-fast/src/main/java/com/boge/common/utils/FileUtil.java @@ -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> 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"); + } +} diff --git a/base-fast/src/main/java/com/boge/modules/tickets/controller/LocalStorageController.java b/base-fast/src/main/java/com/boge/modules/tickets/controller/LocalStorageController.java new file mode 100644 index 0000000..c5b9051 --- /dev/null +++ b/base-fast/src/main/java/com/boge/modules/tickets/controller/LocalStorageController.java @@ -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 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 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 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 delete(@RequestBody Long[] ids) { + this.localStorageService.deleteAll(ids); + return new ResponseEntity(HttpStatus.OK); + } + + public LocalStorageController(final LocalStorageService localStorageService) { + this.localStorageService = localStorageService; + } +} diff --git a/base-fast/src/main/java/com/boge/modules/tickets/dao/LocalStorageMapper.java b/base-fast/src/main/java/com/boge/modules/tickets/dao/LocalStorageMapper.java new file mode 100644 index 0000000..fb8f290 --- /dev/null +++ b/base-fast/src/main/java/com/boge/modules/tickets/dao/LocalStorageMapper.java @@ -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 { +} diff --git a/base-fast/src/main/java/com/boge/modules/tickets/dto/LocalStorageDto.java b/base-fast/src/main/java/com/boge/modules/tickets/dto/LocalStorageDto.java new file mode 100644 index 0000000..c4706e0 --- /dev/null +++ b/base-fast/src/main/java/com/boge/modules/tickets/dto/LocalStorageDto.java @@ -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; + +} diff --git a/base-fast/src/main/java/com/boge/modules/tickets/entity/LocalStorage.java b/base-fast/src/main/java/com/boge/modules/tickets/entity/LocalStorage.java new file mode 100644 index 0000000..3af2983 --- /dev/null +++ b/base-fast/src/main/java/com/boge/modules/tickets/entity/LocalStorage.java @@ -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() { + } +} diff --git a/base-fast/src/main/java/com/boge/modules/tickets/entity/LocalStorageQueryCriteria.java b/base-fast/src/main/java/com/boge/modules/tickets/entity/LocalStorageQueryCriteria.java new file mode 100644 index 0000000..6a7f995 --- /dev/null +++ b/base-fast/src/main/java/com/boge/modules/tickets/entity/LocalStorageQueryCriteria.java @@ -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 createTime; + + public LocalStorageQueryCriteria() { + } + + public String getBlurry() { + return this.blurry; + } + + public List getCreateTime() { + return this.createTime; + } + + public void setBlurry(final String blurry) { + this.blurry = blurry; + } + + public void setCreateTime(final List 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() + ")"; + } +} diff --git a/base-fast/src/main/java/com/boge/modules/tickets/enums/MsgType.java b/base-fast/src/main/java/com/boge/modules/tickets/enums/MsgType.java new file mode 100644 index 0000000..33bd1d5 --- /dev/null +++ b/base-fast/src/main/java/com/boge/modules/tickets/enums/MsgType.java @@ -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 +} diff --git a/base-fast/src/main/java/com/boge/modules/tickets/repository/LocalStorageRepository.java b/base-fast/src/main/java/com/boge/modules/tickets/repository/LocalStorageRepository.java new file mode 100644 index 0000000..a4afe38 --- /dev/null +++ b/base-fast/src/main/java/com/boge/modules/tickets/repository/LocalStorageRepository.java @@ -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, JpaSpecificationExecutor { +} diff --git a/base-fast/src/main/java/com/boge/modules/tickets/service/LocalStorageService.java b/base-fast/src/main/java/com/boge/modules/tickets/service/LocalStorageService.java new file mode 100644 index 0000000..d7038fb --- /dev/null +++ b/base-fast/src/main/java/com/boge/modules/tickets/service/LocalStorageService.java @@ -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 queryAll(); + + + LocalStorage create(String name, MultipartFile file); + + + void deleteAll(Long[] ids); + + void download(List localStorageDtos, HttpServletResponse response) throws IOException; +} diff --git a/base-fast/src/main/java/com/boge/modules/tickets/service/impl/LocalStorageServiceImpl.java b/base-fast/src/main/java/com/boge/modules/tickets/service/impl/LocalStorageServiceImpl.java new file mode 100644 index 0000000..92a5bc2 --- /dev/null +++ b/base-fast/src/main/java/com/boge/modules/tickets/service/impl/LocalStorageServiceImpl.java @@ -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 implements LocalStorageService { + private final LocalStorageRepository localStorageRepository; + private final LocalStorageMapper localStorageMapper; + private final FileProperties properties; + + public List queryAll() { + return localStorageMapper.selectList(new QueryWrapper()); + } + + + + + + @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 queryAll, HttpServletResponse response) throws IOException { + List> list = new ArrayList(); + Iterator var4 = queryAll.iterator(); + + while(var4.hasNext()) { + LocalStorage localStorageDTO = (LocalStorage)var4.next(); + Map 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; + } +}