From fbb91ceed1165f385664abd7dfc755f621baea36 Mon Sep 17 00:00:00 2001 From: pengjie <17373303529@163.com> Date: Tue, 14 Nov 2023 17:43:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/zhgd/config/CorsConfig.java | 3 +- .../controller/admin/FileController.java | 117 ++++++++++-------- .../admin/SystemUserOpController.java | 1 + .../modules/basicdata/vo/SystemUserOpVo.java | 3 + 4 files changed, 70 insertions(+), 54 deletions(-) diff --git a/src/main/java/com/zhgd/config/CorsConfig.java b/src/main/java/com/zhgd/config/CorsConfig.java index e24c6b3..6ebfa61 100644 --- a/src/main/java/com/zhgd/config/CorsConfig.java +++ b/src/main/java/com/zhgd/config/CorsConfig.java @@ -14,7 +14,8 @@ public class CorsConfig{ public FilterRegistrationBean corsFilter() { CorsConfiguration config = new CorsConfiguration(); config.setAllowCredentials(true); - config.addAllowedOrigin("*"); +// config.addAllowedOrigin("*"); + config.addAllowedOrigin("http://10.75.253.12:6090"); config.addAllowedHeader("*"); config.addAllowedMethod("*"); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/admin/FileController.java b/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/admin/FileController.java index 66347ff..fdc701b 100644 --- a/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/admin/FileController.java +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/admin/FileController.java @@ -1,6 +1,5 @@ package com.zhgd.xmgl.modules.basicdata.controller.admin; -import cn.xuyanwu.spring.file.storage.FileInfo; import cn.xuyanwu.spring.file.storage.FileStorageService; import com.zhgd.annotation.OperLog; import com.zhgd.file.FileUtil; @@ -17,7 +16,6 @@ import org.springframework.web.multipart.MultipartFile; import springfox.documentation.annotations.ApiIgnore; import javax.servlet.http.HttpServletResponse; -import java.net.URLEncoder; import java.util.Map; /** @@ -42,23 +40,38 @@ public class FileController { /** * 上传文件到指定存储平台,成功返回文件信息 */ - @OperLog(operModul = "文件管理", operType = "文件上传", operDesc = "文件上传") - @ApiOperation(value = "文件上传", notes = "文件上传", httpMethod="POST") - @PostMapping("/upload") - public Result uploadPlatform(MultipartFile file) { - return Result.success(fileStorageService.of(file) - .setPlatform("minio-1") //使用指定的存储平台 - .upload()); - } - -// /** -// * 上传文件到本地,成功返回文件信息 -// */ // @OperLog(operModul = "文件管理", operType = "文件上传", operDesc = "文件上传") // @ApiOperation(value = "文件上传", notes = "文件上传", httpMethod="POST") // @PostMapping("/upload") -// public Result> upload(MultipartFile file) { -// return Result.success(fileDetailService.upload(file)); +// public Result uploadPlatform(MultipartFile file) { +// return Result.success(fileStorageService.of(file) +// .setPlatform("minio-1") //使用指定的存储平台 +// .upload()); +// } + + /** + * 上传文件到本地,成功返回文件信息 + */ + @OperLog(operModul = "文件管理", operType = "文件上传", operDesc = "文件上传") + @ApiOperation(value = "文件上传", notes = "文件上传", httpMethod="POST") + @PostMapping("/upload") + public Result> upload(MultipartFile file) { + return Result.success(fileDetailService.upload(file)); + } + +// /** +// * 上传BASE64文件 +// */ +// @OperLog(operModul = "文件管理", operType = "BASE64文件上传", operDesc = "BASE64文件上传") +// @ApiOperation(value = "BASE64文件上传", notes = "BASE64文件上传", httpMethod="POST") +// @ApiImplicitParam(name = "base64", value = "BASE64字符串", required = true, dataType = "String") +// @PostMapping("/uploadBase64") +// public Result uploadBase64(@ApiIgnore @RequestBody Map map) { +// String base64 = MapUtils.getString(map, "base64"); +// MultipartFile multipartFile = FileUtil.base64toMultipart(base64, "text.jpg"); +// return Result.success(fileStorageService.of(multipartFile) +// .setPlatform("minio-1") //使用指定的存储平台 +// .upload()); // } /** @@ -68,33 +81,48 @@ public class FileController { @ApiOperation(value = "BASE64文件上传", notes = "BASE64文件上传", httpMethod="POST") @ApiImplicitParam(name = "base64", value = "BASE64字符串", required = true, dataType = "String") @PostMapping("/uploadBase64") - public Result uploadBase64(@ApiIgnore @RequestBody Map map) { + public Result> uploadBase64(@ApiIgnore @RequestBody Map map) { String base64 = MapUtils.getString(map, "base64"); MultipartFile multipartFile = FileUtil.base64toMultipart(base64, "text.jpg"); - return Result.success(fileStorageService.of(multipartFile) - .setPlatform("minio-1") //使用指定的存储平台 - .upload()); + return Result.success(fileDetailService.upload(multipartFile)); } /** * 下载文件 */ - @OperLog(operModul = "文件管理", operType = "文件下载", operDesc = "文件下载") - @ApiOperation(value = "文件下载", notes = "文件下载", httpMethod="POST") - @ApiImplicitParam(name = "fileUrl", value = "文件路径", paramType = "body", dataType = "String") - @PostMapping("/download") - public void download(@ApiIgnore @RequestBody Map map, HttpServletResponse response) throws Exception { - // 获取文件信息 - String fileUrl = MapUtils.getString(map, "fileUrl"); - FileInfo fileInfo = fileStorageService.getFileInfoByUrl(fileUrl); - if (null == fileInfo) { - throw new Exception("缩略图文件下载失败,文件不存在!fileInfo:" + fileInfo); - } - response.setHeader("Content-disposition", "attachment; filename=" + fileUrl.substring(fileUrl.lastIndexOf("/") + 1)); - response.setContentType("application/octet-stream");// 定义输出类型 - fileStorageService.download(fileInfo).outputStream(response.getOutputStream()); - } +// @OperLog(operModul = "文件管理", operType = "文件下载", operDesc = "文件下载") +// @ApiOperation(value = "文件下载", notes = "文件下载", httpMethod="POST") +// @ApiImplicitParam(name = "fileUrl", value = "文件路径", paramType = "body", dataType = "String") +// @PostMapping("/download") +// public void download(@ApiIgnore @RequestBody Map map, HttpServletResponse response) throws Exception { +// // 获取文件信息 +// String fileUrl = MapUtils.getString(map, "fileUrl"); +// FileInfo fileInfo = fileStorageService.getFileInfoByUrl(fileUrl); +// if (null == fileInfo) { +// throw new Exception("缩略图文件下载失败,文件不存在!fileInfo:" + fileInfo); +// } +// response.setHeader("Content-disposition", "attachment; filename=" + fileUrl.substring(fileUrl.lastIndexOf("/") + 1)); +// response.setContentType("application/octet-stream");// 定义输出类型 +// fileStorageService.download(fileInfo).outputStream(response.getOutputStream()); +// } + + /** + * 获取预览文件流 + */ +// @OperLog(operModul = "文件管理", operType = "获取预览文件流", operDesc = "获取预览文件流") +// @ApiOperation(value = "获取预览文件流", notes = "获取预览文件流", httpMethod="POST") +// @GetMapping("/preview") +// public void download(@RequestParam(value = "fileUrl", required = true) String fileUrl, HttpServletResponse response) throws Exception { +// // 获取文件信息 +// FileInfo fileInfo = fileStorageService.getFileInfoByUrl(fileUrl); +// if (null == fileInfo) { +// throw new Exception("缩略图文件预览失败,文件不存在!fileInfo:" + fileInfo); +// } +// response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(fileInfo.getOriginalFilename(), "UTF-8")); +// response.setContentType("application/octet-stream");// 定义输出类型 +// fileStorageService.download(fileInfo).outputStream(response.getOutputStream()); +// } /** * 获取预览文件流 @@ -104,23 +132,6 @@ public class FileController { @GetMapping("/preview") public void download(@RequestParam(value = "fileUrl", required = true) String fileUrl, HttpServletResponse response) throws Exception { // 获取文件信息 - FileInfo fileInfo = fileStorageService.getFileInfoByUrl(fileUrl); - if (null == fileInfo) { - throw new Exception("缩略图文件预览失败,文件不存在!fileInfo:" + fileInfo); - } - response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(fileInfo.getOriginalFilename(), "UTF-8")); - response.setContentType("application/octet-stream");// 定义输出类型 - fileStorageService.download(fileInfo).outputStream(response.getOutputStream()); + fileDetailService.download(fileUrl, response); } - -// /** -// * 获取预览文件流 -// */ -// @OperLog(operModul = "文件管理", operType = "获取预览文件流", operDesc = "获取预览文件流") -// @ApiOperation(value = "获取预览文件流", notes = "获取预览文件流", httpMethod="POST") -// @GetMapping("/preview") -// public void download(@RequestParam(value = "fileUrl", required = true) String fileUrl, HttpServletResponse response) throws Exception { -// // 获取文件信息 -// fileDetailService.download(fileUrl, response); -// } } diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/admin/SystemUserOpController.java b/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/admin/SystemUserOpController.java index aa1b9cd..60f7326 100644 --- a/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/admin/SystemUserOpController.java +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/controller/admin/SystemUserOpController.java @@ -80,6 +80,7 @@ public class SystemUserOpController { systemUser.setIsManager(false); systemUser.setAccountType(2); systemUser.setUserTel(systemUserOpVo.getNumPhone()); + systemUser.setRealName(systemUserOpVo.getRealName()); systemUserService.save(systemUser); //新增用户角色 SystemUserRole systemUserRole = new SystemUserRole(); diff --git a/src/main/java/com/zhgd/xmgl/modules/basicdata/vo/SystemUserOpVo.java b/src/main/java/com/zhgd/xmgl/modules/basicdata/vo/SystemUserOpVo.java index 4579289..dd83633 100644 --- a/src/main/java/com/zhgd/xmgl/modules/basicdata/vo/SystemUserOpVo.java +++ b/src/main/java/com/zhgd/xmgl/modules/basicdata/vo/SystemUserOpVo.java @@ -25,4 +25,7 @@ public class SystemUserOpVo { @ApiModelProperty(value = "手机号") private String numPhone; + + @ApiModelProperty(value = "用户名") + private String realName; }