From bec171e49451323527bc0262ab2ed9f35e861873 Mon Sep 17 00:00:00 2001 From: zer0Black <694429613@qq.com> Date: Sat, 9 Apr 2022 13:39:05 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90fix=E3=80=91=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=B7=A5=E5=85=B7=E4=B8=8D=E8=83=BD=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=AF=BC=E5=85=A5=E5=BC=82=E5=B8=B8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jero/common/constant/CommonConstant.java | 2 + .../system/controller/CommonController.java | 61 +++++++++++++++++++ .../system/controller/SysUserController.java | 3 +- 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/constant/CommonConstant.java b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/constant/CommonConstant.java index 46c84f25..4843191d 100644 --- a/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/constant/CommonConstant.java +++ b/jero-boot/jero-boot-base/jero-boot-base-core/src/main/java/com/jero/common/constant/CommonConstant.java @@ -223,6 +223,8 @@ public interface CommonConstant { public static final Integer USER_IDENTITY_1 = 1; public static final Integer USER_IDENTITY_2 = 2; + /** sys_user 表 username 唯一键索引 */ + public static final String SQL_INDEX_INDEX_USER_NAME = "index_user_name"; /** sys_user 表 username 唯一键索引 */ public static final String SQL_INDEX_UNIQ_SYS_USER_USERNAME = "uniq_sys_user_username"; /** sys_user 表 work_no 唯一键索引 */ diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/CommonController.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/CommonController.java index cf756a01..09175955 100644 --- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/CommonController.java +++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/CommonController.java @@ -275,4 +275,65 @@ public class CommonController { } } + /** + * 预览图片&下载文件 + * 请求地址:http://localhost:8080/common/static/{user/20190119/e1fe9925bc315c60addea1b98eb1cb1349547719_1547866868179.jpg} + * + * @param request + * @param response + */ + @GetMapping(value = "/static/**") + public void view(HttpServletRequest request, HttpServletResponse response) { + // ISO-8859-1 ==> UTF-8 进行编码转换 + String imgPath = extractPathFromPattern(request); + if(oConvertUtils.isEmpty(imgPath) || imgPath=="null"){ + return; + } + // 其余处理略 + InputStream inputStream = null; + OutputStream outputStream = null; + try { + imgPath = imgPath.replace("..", "").replace("../",""); + if (imgPath.endsWith(",")) { + imgPath = imgPath.substring(0, imgPath.length() - 1); + } + String filePath = uploadpath + File.separator + imgPath; + File file = new File(filePath); + if(!file.exists()){ + response.setStatus(404); + throw new RuntimeException("文件["+imgPath+"]不存在.."); + } + response.setContentType("application/force-download");// 设置强制下载不打开 + response.addHeader("Content-Disposition", "attachment;fileName=" + new String(file.getName().getBytes("UTF-8"),"iso-8859-1")); + inputStream = new BufferedInputStream(new FileInputStream(filePath)); + outputStream = response.getOutputStream(); + byte[] buf = new byte[1024]; + int len; + while ((len = inputStream.read(buf)) > 0) { + outputStream.write(buf, 0, len); + } + response.flushBuffer(); + } catch (IOException e) { + log.error("预览文件失败" + e.getMessage()); + response.setStatus(404); + e.printStackTrace(); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } + } + + } + } diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysUserController.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysUserController.java index 0d29f24c..da27e978 100644 --- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysUserController.java +++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/system/controller/SysUserController.java @@ -516,7 +516,8 @@ public class SysUserController { String message = e.getMessage().toLowerCase(); int lineNumber = i + 1; // 通过索引名判断出错信息 - if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_USER_USERNAME)) { + if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_USER_USERNAME) + || message.contains(CommonConstant.SQL_INDEX_INDEX_USER_NAME)) { errorMessage.add("第 " + lineNumber + " 行:用户名已经存在,忽略导入。"); } else if (message.contains(CommonConstant.SQL_INDEX_UNIQ_SYS_USER_WORK_NO)) { errorMessage.add("第 " + lineNumber + " 行:工号已经存在,忽略导入。");