diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/oss/service/impl/OSSFileServiceImpl.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/oss/service/impl/OSSFileServiceImpl.java index 73533a058..de2744c3e 100644 --- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/oss/service/impl/OSSFileServiceImpl.java +++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/modules/oss/service/impl/OSSFileServiceImpl.java @@ -32,407 +32,403 @@ import java.util.List; @Service("ossFileService") public class OSSFileServiceImpl extends ServiceImpl implements IOSSFileService { - @Value(value = "${jero.path.upload}") - private String uploadpath; - @Value(value = "${jero.path.uploadCos}") - private String uploadCospath; + @Value(value = "${jero.path.upload}") + private String uploadpath; + @Value(value = "${jero.path.uploadCos}") + private String uploadCospath; - /** - * 文件后缀黑名单 - */ - @Value(value="${jero.fileSuffixLimits}") - private String[] fileSuffixLimits; + /** + * 文件后缀黑名单 + */ + @Value(value = "${jero.fileSuffixLimits}") + private String[] fileSuffixLimits; - // 文档拆分条款图片访问路径 - @Value(value = "${jero.splitUrl}") - private String splitUrl; + // 文档拆分条款图片访问路径 + @Value(value = "${jero.splitUrl}") + private String splitUrl; - @Override - public void upload(MultipartFile multipartFile) throws IOException { - String fileName = multipartFile.getOriginalFilename(); - fileName = CommonUtils.getFileName(fileName); - OSSFile ossFile = new OSSFile(); - ossFile.setFileName(fileName); - String url = OssBootUtil.upload(multipartFile,"upload/test"); - //update-begin--Author:scott Date:20201227 for:JT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败------------------- - // 返回阿里云原生域名前缀URL - ossFile.setUrl(OssBootUtil.getOriginalUrl(url)); - //update-end--Author:scott Date:20201227 for:JT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败------------------- - this.save(ossFile); - } - /** - * 本地文件上传 - * - * @param mf 文件 - * @param bizPath 自定义路径 - * @return - */ - @Override - public OSSFile uploadLocal(MultipartFile mf, String bizPath,String state,String cut) { + @Override + public void upload(MultipartFile multipartFile) throws IOException { + String fileName = multipartFile.getOriginalFilename(); + fileName = CommonUtils.getFileName(fileName); + OSSFile ossFile = new OSSFile(); + ossFile.setFileName(fileName); + String url = OssBootUtil.upload(multipartFile, "upload/test"); + //update-begin--Author:scott Date:20201227 for:JT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败------------------- + // 返回阿里云原生域名前缀URL + ossFile.setUrl(OssBootUtil.getOriginalUrl(url)); + //update-end--Author:scott Date:20201227 for:JT-361【文件预览】阿里云原生域名可以文件预览,自己映射域名kkfileview提示文件下载失败------------------- + this.save(ossFile); + } - //处理文件大小,大于100M抛出异常 - long fileSize = mf.getSize() / 1024 / 1024; - String originalFilename = mf.getOriginalFilename(); - if (fileSize >= 100) { - if(cut.equals(CutEnum.CN.getValue())){ - throw new JeroBootException(originalFilename + "文件大小超出100MB, 请压缩或降低文件质量!"); - }else{ - throw new JeroBootException(originalFilename + "File size out 100MB, Please compress or reduce file quality!"); - } - } + /** + * 本地文件上传 + * + * @param mf 文件 + * @param bizPath 自定义路径 + * @return + */ + @Override + public OSSFile uploadLocal(MultipartFile mf, String bizPath, String state, String cut) { - OSSFile oSSFile = new OSSFile(); - try { - String ctxPath = uploadpath; - String fileName = null; - String fileType = null; - File file = new File(ctxPath + File.separator + bizPath + File.separator); - if (!file.exists()) { - file.mkdirs();// 创建文件根目录 - } - String orgName = mf.getOriginalFilename();// 获取文件名 - orgName = CommonUtils.getFileName(orgName); - if (orgName.indexOf(".") != -1) { - fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf(".")); - } else { - fileName = orgName + "_" + System.currentTimeMillis(); - } + //处理文件大小,大于100M抛出异常 + long fileSize = mf.getSize() / 1024 / 1024; + String originalFilename = mf.getOriginalFilename(); + if (fileSize >= 100) { + if (cut.equals(CutEnum.CN.getValue())) { + throw new JeroBootException(originalFilename + "文件大小超出100MB, 请压缩或降低文件质量!"); + } else { + throw new JeroBootException(originalFilename + "File size out 100MB, Please compress or reduce file quality!"); + } + } - fileType = orgName.substring(orgName.lastIndexOf(".")); - String fileTypeStr = ".doc,.DOC,.docx,.DOCX,.xls, .XLS,.xlsx,.XLSX,.pdf,.PDF"; - //判断文件类型 - if("1".equals(state)){ - //固定文件 - if(!fileTypeStr.contains(fileType)){ - if(cut.equals(CutEnum.CN.getValue())){ - throw new JeroBootException("只能够上传pdf,word,excel类型的文件。请重新选择文件!"); - }else{ - throw new JeroBootException("Only upload pdf,word,excel type of file Please select the file again!"); - } - } - }else{ - if (CommonUtils.limitFileSuffix(orgName, fileSuffixLimits)) { - if(cut.equals(CutEnum.CN.getValue())){ - throw new JeroBootException("不能上传"+StringUtils.join(fileSuffixLimits, ",")+"类型的文件。请重新选择文件!"); - }else{ - throw new JeroBootException("Can't upload"+StringUtils.join(fileSuffixLimits, ",")+"type of file Please select the file again!"); - } - } - } + OSSFile oSSFile = new OSSFile(); + try { + String ctxPath = uploadpath; + String fileName = null; + String fileType = null; + File file = new File(ctxPath + File.separator + bizPath + File.separator); + if (!file.exists()) { + file.mkdirs();// 创建文件根目录 + } + String orgName = mf.getOriginalFilename();// 获取文件名 + orgName = CommonUtils.getFileName(orgName); + if (orgName.indexOf(".") != -1) { + fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf(".")); + } else { + fileName = orgName + "_" + System.currentTimeMillis(); + } - if (StringUtils.isNotEmpty(fileType)) { - String[] fileTypeArr = {".doc",".DOC",".txt",".TXT", ".docx",".DOCX", - ".xls", ".XLS",".xlsx",".XLSX", ".pdf",".PDF", ".png",".PNG", - ".jfif",".JFIF", ".pjpeg",".PJPEG", ".jpeg",".JPEG", ".pjp",".PJP", - ".jpg",".JPG", ".swf",".SWF", ".bmp",".BMP",".rar",".RAR",".zip",".ZIP",".ppt",".PPT",".pptx",".PPTX",".csv",".CSV"}; - boolean flag = true; - for (String fileTypeTemp : fileTypeArr) { - if (fileTypeTemp.equalsIgnoreCase(fileType)) { - flag = false; - } - } - if (flag) { - if(cut.equals(CutEnum.CN.getValue())){ - throw new JeroBootException("只能够上传pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!"); - }else{ - throw new JeroBootException("Only upload pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!"); - } - } - } + fileType = orgName.substring(orgName.lastIndexOf(".")); + String fileTypeStr = ".doc,.DOC,.docx,.DOCX,.xls, .XLS,.xlsx,.XLSX,.pdf,.PDF"; + //判断文件类型 + if ("1".equals(state)) { + //固定文件 + if (!fileTypeStr.contains(fileType)) { + if (cut.equals(CutEnum.CN.getValue())) { + throw new JeroBootException("只能够上传pdf,word,excel类型的文件。请重新选择文件!"); + } else { + throw new JeroBootException("Only upload pdf,word,excel type of file Please select the file again!"); + } + } + } else { + if (CommonUtils.limitFileSuffix(orgName, fileSuffixLimits)) { + if (cut.equals(CutEnum.CN.getValue())) { + throw new JeroBootException("不能上传" + StringUtils.join(fileSuffixLimits, ",") + "类型的文件。请重新选择文件!"); + } else { + throw new JeroBootException("Can't upload" + StringUtils.join(fileSuffixLimits, ",") + "type of file Please select the file again!"); + } + } + } - String savePath = file.getPath() + File.separator + fileName; - File savefile = new File(savePath); - FileCopyUtils.copy(mf.getBytes(), savefile); - String dbpath = null; - if (oConvertUtils.isNotEmpty(bizPath)) { - dbpath = bizPath + File.separator + fileName; - } else { - dbpath = fileName; - } - if (dbpath.contains("\\")) { - dbpath = dbpath.replace("\\", "/"); - } + if (StringUtils.isNotEmpty(fileType)) { + String[] fileTypeArr = {".doc", ".DOC", ".txt", ".TXT", ".docx", ".DOCX", + ".xls", ".XLS", ".xlsx", ".XLSX", ".pdf", ".PDF", ".png", ".PNG", + ".jfif", ".JFIF", ".pjpeg", ".PJPEG", ".jpeg", ".JPEG", ".pjp", ".PJP", + ".jpg", ".JPG", ".swf", ".SWF", ".bmp", ".BMP", ".rar", ".RAR", ".zip", ".ZIP", ".ppt", ".PPT", ".pptx", ".PPTX", ".csv", ".CSV"}; + boolean flag = true; + for (String fileTypeTemp : fileTypeArr) { + if (fileTypeTemp.equalsIgnoreCase(fileType)) { + flag = false; + } + } + if (flag) { + if (cut.equals(CutEnum.CN.getValue())) { + throw new JeroBootException("只能够上传pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!"); + } else { + throw new JeroBootException("Only upload pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!"); + } + } + } - LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); - //存入文件表 - oSSFile.setFileName(orgName); - oSSFile.setId(UuidUtils.getUUID()); - oSSFile.setUrl(savePath); - oSSFile.setCreateBy(loginUser.getUsername()); - oSSFile.setCreateTime(new Date()); - this.save(oSSFile); - oSSFile.setUrl(null); - return oSSFile; - } catch (IOException e) { - log.error(e.getMessage(), e); - } - return oSSFile; - } + String savePath = file.getPath() + File.separator + fileName; + File savefile = new File(savePath); + FileCopyUtils.copy(mf.getBytes(), savefile); + String dbpath = null; + if (oConvertUtils.isNotEmpty(bizPath)) { + dbpath = bizPath + File.separator + fileName; + } else { + dbpath = fileName; + } + if (dbpath.contains("\\")) { + dbpath = dbpath.replace("\\", "/"); + } - /** - * 本地文件上传 cos - * - * @param mf 文件 - * @param bizPath 自定义路径 - * @return - */ - @Override - public OSSFile uploadLocalOfCos(MultipartFile mf, String bizPath,String state,String cut) { + LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + //存入文件表 + oSSFile.setFileName(orgName); + oSSFile.setId(UuidUtils.getUUID()); + oSSFile.setUrl(savePath); + oSSFile.setCreateBy(loginUser.getUsername()); + oSSFile.setCreateTime(new Date()); + this.save(oSSFile); + oSSFile.setUrl(null); + return oSSFile; + } catch (IOException e) { + log.error(e.getMessage(), e); + } + return oSSFile; + } - //处理文件大小,大于100M抛出异常 - long fileSize = mf.getSize() / 1024 / 1024; - String originalFilename = mf.getOriginalFilename(); - if (fileSize >= 100) { - if(cut.equals(CutEnum.CN.getValue())){ - throw new JeroBootException(originalFilename + "文件大小超出100MB, 请压缩或降低文件质量!"); - }else{ - throw new JeroBootException(originalFilename + "File size out 100MB, Please compress or reduce file quality!"); - } - } + /** + * 本地文件上传 cos + * + * @param mf 文件 + * @param bizPath 自定义路径 + * @return + */ + @Override + public OSSFile uploadLocalOfCos(MultipartFile mf, String bizPath, String state, String cut) { - OSSFile oSSFile = new OSSFile(); - try { - String ctxPath = uploadCospath; - String fileName = null; - String fileType = null; + //处理文件大小,大于100M抛出异常 + long fileSize = mf.getSize() / 1024 / 1024; + String originalFilename = mf.getOriginalFilename(); + if (fileSize >= 100) { + if (cut.equals(CutEnum.CN.getValue())) { + throw new JeroBootException(originalFilename + "文件大小超出100MB, 请压缩或降低文件质量!"); + } else { + throw new JeroBootException(originalFilename + "File size out 100MB, Please compress or reduce file quality!"); + } + } - String orgName = mf.getOriginalFilename();// 获取文件名 - orgName = CommonUtils.getFileName(orgName); - if (orgName.indexOf(".") != -1) { - fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf(".")); - } else { - fileName = orgName + "_" + System.currentTimeMillis(); - } + OSSFile oSSFile = new OSSFile(); + String ctxPath = uploadCospath; + String fileName = null; + String fileType = null; - String filePath = ctxPath + "/" + fileName; - fileType = orgName.substring(orgName.lastIndexOf(".")); - String fileTypeStr = ".doc,.DOC,.docx,.DOCX,.xls, .XLS,.xlsx,.XLSX,.pdf,.PDF"; - //判断文件类型 - if("1".equals(state)){ - //固定文件 - if(!fileTypeStr.contains(fileType)){ - if(cut.equals(CutEnum.CN.getValue())){ - throw new JeroBootException("只能够上传pdf,word,excel类型的文件。请重新选择文件!"); - }else{ - throw new JeroBootException("Only upload pdf,word,excel type of file Please select the file again!"); - } - } - }else{ - if (CommonUtils.limitFileSuffix(orgName, fileSuffixLimits)) { - if(cut.equals(CutEnum.CN.getValue())){ - throw new JeroBootException("不能上传"+StringUtils.join(fileSuffixLimits, ",")+"类型的文件。请重新选择文件!"); - }else{ - throw new JeroBootException("Can't upload"+StringUtils.join(fileSuffixLimits, ",")+"type of file Please select the file again!"); - } - } - } + String orgName = mf.getOriginalFilename();// 获取文件名 + orgName = CommonUtils.getFileName(orgName); + if (orgName.indexOf(".") != -1) { + fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf(".")); + } else { + fileName = orgName + "_" + System.currentTimeMillis(); + } - if (StringUtils.isNotEmpty(fileType)) { - String[] fileTypeArr = {".doc",".DOC",".txt",".TXT", ".docx",".DOCX", - ".xls", ".XLS",".xlsx",".XLSX", ".pdf",".PDF", ".png",".PNG", - ".jfif",".JFIF", ".pjpeg",".PJPEG", ".jpeg",".JPEG", ".pjp",".PJP", - ".jpg",".JPG", ".swf",".SWF", ".bmp",".BMP",".rar",".RAR",".zip",".ZIP",".ppt",".PPT",".pptx",".PPTX",".csv",".CSV"}; - boolean flag = true; - for (String fileTypeTemp : fileTypeArr) { - if (fileTypeTemp.equalsIgnoreCase(fileType)) { - flag = false; - } - } - if (flag) { - if(cut.equals(CutEnum.CN.getValue())){ - throw new JeroBootException("只能够上传pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!"); - }else{ - throw new JeroBootException("Only upload pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!"); - } - } - } + String filePath = ctxPath + "/" + fileName; + fileType = orgName.substring(orgName.lastIndexOf(".")); + String fileTypeStr = ".doc,.DOC,.docx,.DOCX,.xls, .XLS,.xlsx,.XLSX,.pdf,.PDF"; + //判断文件类型 + if ("1".equals(state)) { + //固定文件 + if (!fileTypeStr.contains(fileType)) { + if (cut.equals(CutEnum.CN.getValue())) { + throw new JeroBootException("只能够上传pdf,word,excel类型的文件。请重新选择文件!"); + } else { + throw new JeroBootException("Only upload pdf,word,excel type of file Please select the file again!"); + } + } + } else { + if (CommonUtils.limitFileSuffix(orgName, fileSuffixLimits)) { + if (cut.equals(CutEnum.CN.getValue())) { + throw new JeroBootException("不能上传" + StringUtils.join(fileSuffixLimits, ",") + "类型的文件。请重新选择文件!"); + } else { + throw new JeroBootException("Can't upload" + StringUtils.join(fileSuffixLimits, ",") + "type of file Please select the file again!"); + } + } + } - // 将文件上传至腾讯云 cos - CosBootUtil.upload(mf, filePath); + if (StringUtils.isNotEmpty(fileType)) { + String[] fileTypeArr = {".doc", ".DOC", ".txt", ".TXT", ".docx", ".DOCX", + ".xls", ".XLS", ".xlsx", ".XLSX", ".pdf", ".PDF", ".png", ".PNG", + ".jfif", ".JFIF", ".pjpeg", ".PJPEG", ".jpeg", ".JPEG", ".pjp", ".PJP", + ".jpg", ".JPG", ".swf", ".SWF", ".bmp", ".BMP", ".rar", ".RAR", ".zip", ".ZIP", ".ppt", ".PPT", ".pptx", ".PPTX", ".csv", ".CSV"}; + boolean flag = true; + for (String fileTypeTemp : fileTypeArr) { + if (fileTypeTemp.equalsIgnoreCase(fileType)) { + flag = false; + } + } + if (flag) { + if (cut.equals(CutEnum.CN.getValue())) { + throw new JeroBootException("只能够上传pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!"); + } else { + throw new JeroBootException("Only upload pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!"); + } + } + } - LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); - //存入文件表 - oSSFile.setFileName(orgName); - oSSFile.setId(UuidUtils.getUUID()); - oSSFile.setUrl(filePath); - oSSFile.setCreateBy(loginUser.getUsername()); - oSSFile.setCreateTime(new Date()); - this.save(oSSFile); - oSSFile.setUrl(null); - return oSSFile; - } catch (Exception e) { - log.error(e.getMessage(), e); - } - return oSSFile; - } + // 将文件上传至腾讯云 cos + CosBootUtil.upload(mf, filePath); - /** - * 本地文件上传-文档拆分专用 - * - * @param mf 文件 - * @param bizPath 自定义路径 - * @return - */ - @Override - public OSSFile uploadLocalForSplit(MultipartFile mf, String bizPath,String state,String cut) { + LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + //存入文件表 + oSSFile.setFileName(orgName); + oSSFile.setId(UuidUtils.getUUID()); + oSSFile.setUrl(filePath); + oSSFile.setCreateBy(loginUser.getUsername()); + oSSFile.setCreateTime(new Date()); + this.save(oSSFile); + oSSFile.setUrl(null); + return oSSFile; + } - //处理文件大小,大于100M抛出异常 - long fileSize = mf.getSize() / 1024 / 1024; - String originalFilename = mf.getOriginalFilename(); - if (fileSize >= 100) { - if(cut.equals(CutEnum.CN.getValue())){ - throw new JeroBootException(originalFilename + "文件大小超出100MB, 请压缩或降低文件质量!"); - }else{ - throw new JeroBootException(originalFilename + "File size out 100MB, Please compress or reduce file quality!"); - } - } + /** + * 本地文件上传-文档拆分专用 + * + * @param mf 文件 + * @param bizPath 自定义路径 + * @return + */ + @Override + public OSSFile uploadLocalForSplit(MultipartFile mf, String bizPath, String state, String cut) { - OSSFile oSSFile = new OSSFile(); - try { - String ctxPath = uploadCospath; - String fileName = null; - String fileType = null; + //处理文件大小,大于100M抛出异常 + long fileSize = mf.getSize() / 1024 / 1024; + String originalFilename = mf.getOriginalFilename(); + if (fileSize >= 100) { + if (cut.equals(CutEnum.CN.getValue())) { + throw new JeroBootException(originalFilename + "文件大小超出100MB, 请压缩或降低文件质量!"); + } else { + throw new JeroBootException(originalFilename + "File size out 100MB, Please compress or reduce file quality!"); + } + } - String orgName = mf.getOriginalFilename();// 获取文件名 - orgName = CommonUtils.getFileName(orgName); - if (orgName.indexOf(".") != -1) { - fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf(".")); - } else { - fileName = orgName + "_" + System.currentTimeMillis(); - } + OSSFile oSSFile = new OSSFile(); + try { + String ctxPath = uploadCospath; + String fileName = null; + String fileType = null; - String filePath = ctxPath + "/" + fileName; - fileType = orgName.substring(orgName.lastIndexOf(".")); - String fileTypeStr = ".doc,.DOC,.docx,.DOCX,.xls, .XLS,.xlsx,.XLSX,.pdf,.PDF"; - //判断文件类型 - if("1".equals(state)){ - //固定文件 - if(!fileTypeStr.contains(fileType)){ - if(cut.equals(CutEnum.CN.getValue())){ - throw new JeroBootException("只能够上传pdf,word,excel类型的文件。请重新选择文件!"); - }else{ - throw new JeroBootException("Only upload pdf,word,excel type of file Please select the file again!"); - } - } - }else{ - if (CommonUtils.limitFileSuffix(orgName, fileSuffixLimits)) { - if(cut.equals(CutEnum.CN.getValue())){ - throw new JeroBootException("不能上传"+StringUtils.join(fileSuffixLimits, ",")+"类型的文件。请重新选择文件!"); - }else{ - throw new JeroBootException("Can't upload"+StringUtils.join(fileSuffixLimits, ",")+"type of file Please select the file again!"); - } - } - } + String orgName = mf.getOriginalFilename();// 获取文件名 + orgName = CommonUtils.getFileName(orgName); + if (orgName.indexOf(".") != -1) { + fileName = orgName.substring(0, orgName.lastIndexOf(".")) + "_" + System.currentTimeMillis() + orgName.substring(orgName.lastIndexOf(".")); + } else { + fileName = orgName + "_" + System.currentTimeMillis(); + } - if (StringUtils.isNotEmpty(fileType)) { - String[] fileTypeArr = {".doc",".DOC",".txt",".TXT", ".docx",".DOCX", - ".xls", ".XLS",".xlsx",".XLSX", ".pdf",".PDF", ".png",".PNG", - ".jfif",".JFIF", ".pjpeg",".PJPEG", ".jpeg",".JPEG", ".pjp",".PJP", - ".jpg",".JPG", ".swf",".SWF", ".bmp",".BMP",".rar",".RAR",".zip",".ZIP",".ppt",".PPT",".pptx",".PPTX",".csv",".CSV"}; - boolean flag = true; - for (String fileTypeTemp : fileTypeArr) { - if (fileTypeTemp.equalsIgnoreCase(fileType)) { - flag = false; - } - } - if (flag) { - if(cut.equals(CutEnum.CN.getValue())){ - throw new JeroBootException("只能够上传pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!"); - }else{ - throw new JeroBootException("Only upload pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!"); - } - } - } + String filePath = ctxPath + "/" + fileName; + fileType = orgName.substring(orgName.lastIndexOf(".")); + String fileTypeStr = ".doc,.DOC,.docx,.DOCX,.xls, .XLS,.xlsx,.XLSX,.pdf,.PDF"; + //判断文件类型 + if ("1".equals(state)) { + //固定文件 + if (!fileTypeStr.contains(fileType)) { + if (cut.equals(CutEnum.CN.getValue())) { + throw new JeroBootException("只能够上传pdf,word,excel类型的文件。请重新选择文件!"); + } else { + throw new JeroBootException("Only upload pdf,word,excel type of file Please select the file again!"); + } + } + } else { + if (CommonUtils.limitFileSuffix(orgName, fileSuffixLimits)) { + if (cut.equals(CutEnum.CN.getValue())) { + throw new JeroBootException("不能上传" + StringUtils.join(fileSuffixLimits, ",") + "类型的文件。请重新选择文件!"); + } else { + throw new JeroBootException("Can't upload" + StringUtils.join(fileSuffixLimits, ",") + "type of file Please select the file again!"); + } + } + } - // 将文件上传至腾讯云 cos - CosBootUtil.upload(mf, filePath); + if (StringUtils.isNotEmpty(fileType)) { + String[] fileTypeArr = {".doc", ".DOC", ".txt", ".TXT", ".docx", ".DOCX", + ".xls", ".XLS", ".xlsx", ".XLSX", ".pdf", ".PDF", ".png", ".PNG", + ".jfif", ".JFIF", ".pjpeg", ".PJPEG", ".jpeg", ".JPEG", ".pjp", ".PJP", + ".jpg", ".JPG", ".swf", ".SWF", ".bmp", ".BMP", ".rar", ".RAR", ".zip", ".ZIP", ".ppt", ".PPT", ".pptx", ".PPTX", ".csv", ".CSV"}; + boolean flag = true; + for (String fileTypeTemp : fileTypeArr) { + if (fileTypeTemp.equalsIgnoreCase(fileType)) { + flag = false; + } + } + if (flag) { + if (cut.equals(CutEnum.CN.getValue())) { + throw new JeroBootException("只能够上传pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!"); + } else { + throw new JeroBootException("Only upload pdf/word/excel/csv/ppt/txt/zip/rar/静态图片类型的文件。请重新选择文件!"); + } + } + } - LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); - //存入文件表 - oSSFile.setFileName(orgName); - oSSFile.setId(UuidUtils.getUUID()); - oSSFile.setUrl(filePath); - oSSFile.setCreateBy(loginUser.getUsername()); - oSSFile.setCreateTime(new Date()); - this.save(oSSFile); - // 文件路径做特殊处理 - BASE64Encoder base64Encoder = new BASE64Encoder(); - String encode = base64Encoder.encode(filePath.getBytes(StandardCharsets.UTF_8)); - String imgUrl = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + encode; - oSSFile.setUrl(imgUrl); - return oSSFile; - } catch (Exception e) { - log.error(e.getMessage(), e); - } - return oSSFile; - } + // 将文件上传至腾讯云 cos + CosBootUtil.upload(mf, filePath); - @Override - public List getFileInfos(String id) { - if(com.jero.modules.system.util.StringUtils.isEmpty(id)){ - return new ArrayList<>(); - } - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.in(OSSFile::getId,id.split(",")); - List list = this.list(wrapper); - if(list.size() == 0){ - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.in(OSSFile::getConnectId,id.split(",")); - list = this.list(lambdaQueryWrapper); - } - return list; - } - @Override - public List getFileInfoAll(String id) { - if (com.jero.modules.system.util.StringUtils.isEmpty(id)) { - return new ArrayList<>(); - } - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - wrapper.in(OSSFile::getId, id.split(",")); - List list = this.list(wrapper); - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.in(OSSFile::getConnectId, id.split(",")); - list.addAll(this.list(lambdaQueryWrapper)); - return list; - } + LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + //存入文件表 + oSSFile.setFileName(orgName); + oSSFile.setId(UuidUtils.getUUID()); + oSSFile.setUrl(filePath); + oSSFile.setCreateBy(loginUser.getUsername()); + oSSFile.setCreateTime(new Date()); + this.save(oSSFile); + // 文件路径做特殊处理 + BASE64Encoder base64Encoder = new BASE64Encoder(); + String encode = base64Encoder.encode(filePath.getBytes(StandardCharsets.UTF_8)); + String imgUrl = splitUrl + "/jero-boot/sys/split/file/getImage?fileUrl=" + encode; + oSSFile.setUrl(imgUrl); + return oSSFile; + } catch (Exception e) { + log.error(e.getMessage(), e); + } + return oSSFile; + } - @Override - public List getFileInfosByConnectId(String connectId) { - LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); - if(connectId.contains(",")){ - wrapper.in(OSSFile::getConnectId, Arrays.asList(connectId.split(","))); - }else{ - wrapper.eq(OSSFile::getConnectId,connectId); - } + @Override + public List getFileInfos(String id) { + if (com.jero.modules.system.util.StringUtils.isEmpty(id)) { + return new ArrayList<>(); + } + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.in(OSSFile::getId, id.split(",")); + List list = this.list(wrapper); + if (list.size() == 0) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.in(OSSFile::getConnectId, id.split(",")); + list = this.list(lambdaQueryWrapper); + } + return list; + } - List list = this.list(wrapper); - return list; - } + @Override + public List getFileInfoAll(String id) { + if (com.jero.modules.system.util.StringUtils.isEmpty(id)) { + return new ArrayList<>(); + } + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.in(OSSFile::getId, id.split(",")); + List list = this.list(wrapper); + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.in(OSSFile::getConnectId, id.split(",")); + list.addAll(this.list(lambdaQueryWrapper)); + return list; + } - @Override - public boolean delete(OSSFile ossFile) { - try { - this.removeById(ossFile.getId()); - OssBootUtil.deleteUrl(ossFile.getUrl()); - } - catch (Exception ex) { - return false; - } - return true; - } + @Override + public List getFileInfosByConnectId(String connectId) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + if (connectId.contains(",")) { + wrapper.in(OSSFile::getConnectId, Arrays.asList(connectId.split(","))); + } else { + wrapper.eq(OSSFile::getConnectId, connectId); + } - @Override - public void updateFileInfo(List ossFileList) { - this.updateBatchById(ossFileList); - } + List list = this.list(wrapper); + return list; + } - @Override - public void deleteByConnectIdList(List connectIdList) { - if(connectIdList.size() != 0){ - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.in(OSSFile::getConnectId,connectIdList); - this.remove(lambdaQueryWrapper); - } - } + @Override + public boolean delete(OSSFile ossFile) { + try { + this.removeById(ossFile.getId()); + OssBootUtil.deleteUrl(ossFile.getUrl()); + } catch (Exception ex) { + return false; + } + return true; + } + + @Override + public void updateFileInfo(List ossFileList) { + this.updateBatchById(ossFileList); + } + + @Override + public void deleteByConnectIdList(List connectIdList) { + if (connectIdList.size() != 0) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.in(OSSFile::getConnectId, connectIdList); + this.remove(lambdaQueryWrapper); + } + } }