Parcourir la source

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

wangggziwen il y a 7 mois
Parent
commit
029b87cb11

+ 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();