瀏覽代碼

装置信息 - 附件上传功能不允许文件重名

wangggziwen 7 月之前
父節點
當前提交
029b87cb11
共有 1 個文件被更改,包括 18 次插入0 次删除
  1. 18 0
      rc-admin/src/main/java/com/ruoyi/web/controller/rc/TCommonfileController.java

+ 18 - 0
rc-admin/src/main/java/com/ruoyi/web/controller/rc/TCommonfileController.java

@@ -41,6 +41,24 @@ public class TCommonfileController extends BaseController
     {
         if (!file.isEmpty())
         {
+            if ("deptinfo-plane".equals(pType) || "deptinfo-welcome".equals(pType) || "deptinfo-video".equals(pType)) {
+                // 查询文件列表
+                TCommonfile commonfile = new TCommonfile();
+                commonfile.setpType(pType);
+                commonfile.setpId(Long.parseLong(pId));
+                List<TCommonfile> tCommonfiles = tCommonfileService.selectTCommonfileList(commonfile);
+                // 遍历判断是否重名
+                boolean isNameRepeat = false;
+                for (TCommonfile tCommonfile : tCommonfiles) {
+                    if (file.getOriginalFilename().equals(tCommonfile.getFileName())) {
+                        isNameRepeat = true;
+                    }
+                }
+                // 重名不上传
+                if (isNameRepeat) {
+                    return AjaxResult.error("上传失败,存在重名文件");
+                }
+            }
             String url = FileUploadUtils.upload(RuoYiConfig.getFilePath("/"+ pType), file);
             long size = file.getSize()/1024;
             TCommonfile tCommonfile = new TCommonfile();