Explorar o código

在sys_repo与sys_repo_history两个表中添加filename字段

李英俊ya hai 1 mes
pai
achega
21dced5bc5

+ 55 - 3
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRepoController.java

@@ -4,12 +4,13 @@ import java.io.IOException;
 import java.util.List;
 import java.util.Set;
 
+import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.file.FileUploadUtils;
 import com.ruoyi.system.domain.SysRepoHistory;
 import com.ruoyi.common.utils.OfficeCompareUtils;
 import com.ruoyi.system.service.ISysRepoHistoryService;
-import org.apache.tomcat.util.http.fileupload.FileUpload;
-import org.apache.tomcat.util.http.fileupload.FileUtils;
+import com.ruoyi.common.utils.file.FileUtils;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -21,6 +22,11 @@ import com.ruoyi.system.domain.SysRepo;
 import com.ruoyi.system.service.ISysRepoService;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import static com.ruoyi.common.config.RuoYiConfig.getProfile;
+
 /**
  * 仓库管理Controller
  * 
@@ -48,7 +54,6 @@ public class SysRepoController extends BaseController
         return AjaxResult.success(getDataTable(list));
     }
 
-
     /**
      * 获取仓库详细信息
      */
@@ -67,6 +72,10 @@ public class SysRepoController extends BaseController
     @PostMapping
     public AjaxResult add(@RequestBody SysRepo sysRepo)
     {
+        sysRepo.setCreateBy(getUsername());
+        sysRepo.setUpdateBy(getUsername());
+        String filename = StringUtils.substringAfterLast(sysRepo.getUrl(), "\\");
+        sysRepo.setFileName(filename);
         return toAjax(sysRepoService.insertSysRepo(sysRepo));
     }
 
@@ -113,6 +122,49 @@ public class SysRepoController extends BaseController
         return success(getDataTable(sysRepoHistoryService.selectSysRepoHistoryList(sysRepoHistory)));
     }
 
+    /**
+     * 回滚文件版本
+     */
+    @PreAuthorize("@ss.hasPermi('system:repo:backFile')")
+    @Log(title = "回滚文件版本", businessType = BusinessType.UPDATE)
+    @PostMapping(value = "/back_file")
+    public AjaxResult upload_file(@RequestBody SysRepoHistory sysRepoHistory)
+    {
+        Long repoId = sysRepoHistory.getRepoId();
+        SysRepo sysRepo = sysRepoService.selectSysRepoByRepoId(repoId);
+        SysRepoHistory sysRepoHistory1 = sysRepoHistoryService.selectSysRepoHistoryByHId(sysRepoHistory.gethId());
+        sysRepoHistory1.sethId(null);
+        if(sysRepoHistoryService.insertSysRepoHistory(sysRepoHistory1)<1){
+            return AjaxResult.error("文件插入失败");
+        }
+        sysRepo.setUpdateBy(getUsername());
+        sysRepo.setUrl(sysRepoHistory.getUrl());
+        if(sysRepoService.updateSysRepo(sysRepo)<1){
+            return AjaxResult.error("文件插入失败");
+        }
+        return AjaxResult.success();
+    }
+
+    /**
+     * 文件下载
+     */
+    @GetMapping("/download/{resource}")
+    public void resourceDownload(@PathVariable("resource") String resource, HttpServletRequest request, HttpServletResponse response)
+            throws Exception
+    {
+//        // 本地资源路径
+//        String localPath = getProfile();
+//        // 数据库资源地址
+//        String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX);
+        String downloadPath = "C:\\Users\\admin\\Desktop\\1.docx";
+        // 下载名称
+        String downloadName = StringUtils.substringAfterLast(downloadPath, "\\");
+        response.setCharacterEncoding("utf-8");
+        response.setContentType("multipart/form-data");
+        response.setHeader("Content-Disposition",
+                "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, downloadName));
+        FileUtils.writeBytes(downloadPath, response.getOutputStream());
+    }
 
     /**
      * 修改仓库

+ 8 - 8
ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRepo.java

@@ -35,9 +35,9 @@ public class SysRepo extends BaseEntity
     @Excel(name = "状态", readConverterExp = "私密、公开")
     private String repoStatus;
 
-    /** 父级 */
-    @Excel(name = "父级")
-    private Long parentId;
+    /** 文件名 */
+    @Excel(name = "文件名")
+    private String fileName;
 
     /** 等级(一级只能是目录类型) */
     private Long groupId;
@@ -90,14 +90,14 @@ public class SysRepo extends BaseEntity
         return repoStatus;
     }
 
-    public void setParentId(Long parentId) 
+    public void setFileName(String fileName)
     {
-        this.parentId = parentId;
+        this.fileName = fileName;
     }
 
-    public Long getParentId() 
+    public String getFileName()
     {
-        return parentId;
+        return fileName;
     }
 
     public void setGroupId(Long groupId)
@@ -149,7 +149,7 @@ public class SysRepo extends BaseEntity
             .append("repoStatus", getRepoStatus())
             .append("createTime", getCreateTime())
             .append("updateTime", getUpdateTime())
-            .append("parentId", getParentId())
+            .append("fileName", getFileName())
             .append("groupId", getGroupId())
             .append("version", getVersion())
             .append("isDelete", getIsDelete())

+ 12 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRepoHistory.java

@@ -30,6 +30,9 @@ public class SysRepoHistory extends BaseEntity
     /** url */
     private String url;
 
+    /** 文件名 **/
+    private String fileName;
+
     public void sethId(Long hId) 
     {
         this.hId = hId;
@@ -80,6 +83,14 @@ public class SysRepoHistory extends BaseEntity
         return url;
     }
 
+    public void setFileName(String fileName) {
+		this.fileName = fileName;
+	}
+
+    public String getFileName() {
+		return fileName;
+	}
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@@ -88,6 +99,7 @@ public class SysRepoHistory extends BaseEntity
             .append("uploadBy", getUploadBy())
             .append("fileVersion", getFileVersion())
             .append("url", getUrl())
+            .append("fileName", getFileName())
             .toString();
     }
 }

+ 6 - 1
ruoyi-system/src/main/resources/mapper/system/SysRepoHistoryMapper.xml

@@ -10,10 +10,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="uploadBy"    column="upload_by"    />
         <result property="fileVersion"    column="file_version"    />
         <result property="url"    column="url"    />
+        <result property="fileName"    column="file_name"    />
     </resultMap>
 
     <sql id="selectSysRepoHistoryVo">
-        select h_id, repo_id, upload_by, file_version, url from sys_repo_history
+        select h_id, repo_id, upload_by, file_version, url, file_name from sys_repo_history
     </sql>
 
     <select id="selectSysRepoHistoryList" parameterType="SysRepoHistory" resultMap="SysRepoHistoryResult">
@@ -23,6 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="uploadBy != null  and uploadBy != ''"> and upload_by = #{uploadBy}</if>
             <if test="fileVersion != null  and fileVersion != ''"> and file_version = #{fileVersion}</if>
             <if test="url != null  and url != ''"> and url = #{url}</if>
+            <if test="fileName != null  and fileName != ''"> and file_name = #{fileName}</if>
         </where>
     </select>
     
@@ -38,12 +40,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="uploadBy != null and uploadBy != ''">upload_by,</if>
             <if test="fileVersion != null and fileVersion != ''">file_version,</if>
             <if test="url != null and url != ''">url,</if>
+            <if test="fileName != null  and fileName != ''">file_name,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="repoId != null">#{repoId},</if>
             <if test="uploadBy != null and uploadBy != ''">#{uploadBy},</if>
             <if test="fileVersion != null and fileVersion != ''">#{fileVersion},</if>
             <if test="url != null and url != ''">#{url},</if>
+            <if test="fileName != null  and fileName != ''">#{fileName},</if>
          </trim>
     </insert>
 
@@ -54,6 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="uploadBy != null and uploadBy != ''">upload_by = #{uploadBy},</if>
             <if test="fileVersion != null and fileVersion != ''">file_version = #{fileVersion},</if>
             <if test="url != null and url != ''">url = #{url},</if>
+            <if test="fileName != null  and fileName != ''">file_name = #{fileName},</if>
         </trim>
         where h_id = #{hId}
     </update>

+ 10 - 10
ruoyi-system/src/main/resources/mapper/system/SysRepoMapper.xml

@@ -13,7 +13,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="repoStatus"    column="repo_status"    />
         <result property="createTime"    column="create_Time"    />
         <result property="updateTime"    column="update_Time"    />
-        <result property="parentId"    column="parent_id"    />
+        <result property="fileName"    column="file_name"    />
         <result property="groupId"    column="group_id"    />
         <result property="version"    column="version"    />
         <result property="isDelete"    column="is_delete"    />
@@ -21,7 +21,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectSysRepoVo">
-        select repo_Id, repo_name, create_by, update_by, repo_type, repo_status, create_Time, update_Time, parent_id, group_id, version, is_delete, url from sys_repo
+        select repo_Id, repo_name, create_by, update_by, repo_type, repo_status, create_Time, update_Time, file_name, group_id, version, is_delete, url from sys_repo
     </sql>
 
     <select id="selectSysRepoList" parameterType="SysRepo" resultMap="SysRepoResult">
@@ -32,11 +32,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="repoStatus != null  and repoStatus != ''"> and repo_status = #{repoStatus}</if>
             <if test="createTime != null "> and create_Time = #{createTime}</if>
             <if test="updateTime != null "> and update_Time = #{updateTime}</if>
-            <if test="parentId != null "> and parent_id = #{parentId}</if>
+            <if test="fileName != null and fileName != '' "> and file_name = #{fileName}</if>
             <if test="groupId != null "> and group_id = #{groupId}</if>
             <if test="version != null  and version != ''"> and version = #{version}</if>
             <if test="isDelete != null "> and is_delete = #{isDelete}</if>
-            <if test="url != null "> and url = #{isDelete}</if>
+            <if test="url != null and url != ''"> and url = #{url}</if>
         </where>
     </select>
     
@@ -55,11 +55,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="repoStatus != null and repoStatus != ''">repo_status,</if>
             <if test="createTime != null">create_Time,</if>
             <if test="updateTime != null">update_Time,</if>
-            <if test="parentId != null">parent_id,</if>
+            <if test="fileName != null and fileName != ''">file_name,</if>
             <if test="groupId != null">group_id,</if>
             <if test="version != null">version,</if>
             <if test="isDelete != null">is_delete,</if>
-            <if test="url != null">url,</if>
+            <if test="url != null and url != ''">url,</if>
          </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="repoName != null and repoName != ''">#{repoName},</if>
@@ -69,11 +69,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="repoStatus != null and repoStatus != ''">#{repoStatus},</if>
             <if test="createTime != null">#{createTime},</if>
             <if test="updateTime != null">#{updateTime},</if>
-            <if test="parentId != null">#{parentId},</if>
+            <if test="fileName != null and fileName != ''">#{fileName},</if>
             <if test="groupId != null">#{groupId},</if>
             <if test="version != null">#{version},</if>
             <if test="isDelete != null">#{isDelete},</if>
-            <if test="url != null">#{url},</if>
+            <if test="url != null and url != ''">#{url},</if>
          </trim>
     </insert>
 
@@ -87,11 +87,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="repoStatus != null and repoStatus != ''">repo_status = #{repoStatus},</if>
             <if test="createTime != null">create_Time = #{createTime},</if>
             <if test="updateTime != null">update_Time = #{updateTime},</if>
-            <if test="parentId != null">parent_id = #{parentId},</if>
+            <if test="fileName != null and fileName != ''">file_name = #{fileName},</if>
             <if test="groupId != null">group_id = #{groupId},</if>
             <if test="version != null">version = #{version},</if>
             <if test="isDelete != null">is_delete = #{isDelete},</if>
-            <if test="url != null">url = #{url},</if>
+            <if test="url != null and url != ''">url = #{url},</if>
         </trim>
         where repo_Id = #{repoId}
     </update>

+ 7 - 7
sql/sys_repo.sql

@@ -11,7 +11,7 @@
  Target Server Version : 50741
  File Encoding         : 65001
 
- Date: 19/05/2025 15:18:45
+ Date: 20/05/2025 10:08:28
 */
 
 SET NAMES utf8mb4;
@@ -24,18 +24,18 @@ DROP TABLE IF EXISTS `sys_repo`;
 CREATE TABLE `sys_repo`  (
   `repo_Id` bigint(20) NOT NULL AUTO_INCREMENT,
   `repo_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '名称',
-  `create_by` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '创建人',
+  `create_by` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人',
   `update_by` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '更新人',
-  `repo_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '文件类型(docx、xls等)',
-  `repo_status` enum('Private','Public') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '状态(私密、公开)',
+  `repo_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件类型(docx、xls等)',
+  `repo_status` enum('Private','Public') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '状态(私密、公开)',
   `create_Time` datetime(0) DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
   `update_Time` datetime(0) DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '更改时间',
-  `parent_id` bigint(20) DEFAULT NULL COMMENT '父级',
-  `group_id` bigint(20) NOT NULL COMMENT '文件组别',
+  `file_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件名',
+  `group_id` bigint(20) DEFAULT NULL COMMENT '文件组别',
   `version` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件版本',
   `is_delete` tinyint(4) DEFAULT 0 COMMENT '是否删除',
   `url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件地址',
   PRIMARY KEY (`repo_Id`) USING BTREE
-) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
+) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '仓库文件表' ROW_FORMAT = Dynamic;
 
 SET FOREIGN_KEY_CHECKS = 1;

+ 34 - 0
sql/sys_repo_history.sql

@@ -0,0 +1,34 @@
+/*
+ Navicat MySQL Data Transfer
+
+ Source Server         : bishe
+ Source Server Type    : MySQL
+ Source Server Version : 50741
+ Source Host           : localhost:3306
+ Source Schema         : ry-vue
+
+ Target Server Type    : MySQL
+ Target Server Version : 50741
+ File Encoding         : 65001
+
+ Date: 20/05/2025 10:08:37
+*/
+
+SET NAMES utf8mb4;
+SET FOREIGN_KEY_CHECKS = 0;
+
+-- ----------------------------
+-- Table structure for sys_repo_history
+-- ----------------------------
+DROP TABLE IF EXISTS `sys_repo_history`;
+CREATE TABLE `sys_repo_history`  (
+  `h_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '历史记录ID',
+  `repo_id` int(11) NOT NULL COMMENT '所属仓库文件ID',
+  `upload_by` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '上传人',
+  `file_version` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '文件版本',
+  `url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '路径地址',
+  `file_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '文件名',
+  PRIMARY KEY (`h_id`) USING BTREE
+) ENGINE = InnoDB AUTO_INCREMENT = 12 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '文件历史表' ROW_FORMAT = Dynamic;
+
+SET FOREIGN_KEY_CHECKS = 1;