浏览代码

文件上传accessPath

chenw 6 年之前
父节点
当前提交
64f2ab4aeb

+ 20 - 1
base-servers/file/file-server/src/main/java/com/usoftchina/smartschool/file/controller/FileController.java

@@ -18,6 +18,7 @@ import org.apache.commons.compress.archivers.ArchiveOutputStream;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.*;
@@ -190,7 +191,7 @@ public class FileController {
         return Result.error(ExceptionCode.FILE_NOT_EXISTS);
     }
 
-    @ApiOperation(value = "查看文件信息")
+    @ApiOperation(value = "通过ids查看文件信息")
     @GetMapping(value = "/info", params = "ids")
     public Result<FileInfoDTO> getFileInfoList(String ids) {
         if (StringUtils.isEmpty(ids)){
@@ -208,6 +209,24 @@ public class FileController {
         return Result.error(ExceptionCode.FILE_NOT_EXISTS);
     }
 
+    @ApiOperation(value = "通过accessPath查看文件信息")
+    @GetMapping(value = "/info", params = "accessPath")
+    public Result<FileInfoDTO> getFileInfoListByAccessPath(@RequestParam("accessPath") String accessPath) {
+        if (StringUtils.isEmpty(accessPath)){
+            throw new BizException(ExceptionCode.ILLEGAL_ARGUMENTS);
+        }
+        List<FileInfo> fileInfoList = new ArrayList<>();
+        String[] accessPathArray = accessPath.split(",");
+        for (int i = 0; i < accessPathArray.length; i++) {
+            FileInfo info = fileService.findByAccessPath(accessPathArray[i]);
+            fileInfoList.add(info);
+        }
+        if (!CollectionUtils.isEmpty(fileInfoList)) {
+            return Result.success(BeanMapper.mapList(fileInfoList, FileInfoDTO.class));
+        }
+        return Result.error(ExceptionCode.FILE_NOT_EXISTS);
+    }
+
     @ApiOperation(value = "查看子文件")
     @GetMapping(value = "/list")
     public Result<List<FileInfoDTO>> listFiles(@RequestParam(value = "folderId", required = false) Long folderId) {

+ 7 - 0
base-servers/file/file-server/src/main/java/com/usoftchina/smartschool/file/mapper/FileInfoMapper.java

@@ -43,4 +43,11 @@ public interface FileInfoMapper extends CommonBaseMapper<FileInfo>{
      * @return
      */
     FileInfo selectByFullPath(@Param("fullPath") String fullPath);
+
+    /**
+     * 按绝对路径查找
+     * @param accessPath
+     * @return
+     */
+    FileInfo selectByAccessPath(@Param("accessPath") String accessPath);
 }

+ 7 - 0
base-servers/file/file-server/src/main/java/com/usoftchina/smartschool/file/service/FileInfoService.java

@@ -27,4 +27,11 @@ public interface FileInfoService extends CommonBaseService<FileInfoMapper, FileI
      * @return
      */
     FileInfo findByFullPath(String fullPath);
+
+    /**
+     * 按绝对路径查找
+     * @param accessPath
+     * @return
+     */
+    FileInfo findByAccessPath(String accessPath);
 }

+ 5 - 0
base-servers/file/file-server/src/main/java/com/usoftchina/smartschool/file/service/impl/FileInfoServiceImpl.java

@@ -26,6 +26,11 @@ public class FileInfoServiceImpl extends CommonBaseServiceImpl<FileInfoMapper, F
         return getMapper().selectByFullPath(fullPath);
     }
 
+    @Override
+    public FileInfo findByAccessPath(String accessPath) {
+        return getMapper().selectByAccessPath(accessPath);
+    }
+
     /**
      * 清理回收站超过7天的文件
      */

+ 13 - 3
base-servers/file/file-server/src/main/resources/mapper/FileInfoMapper.xml

@@ -5,12 +5,12 @@
     <insert id="insert" parameterType="com.usoftchina.smartschool.file.po.FileInfo"
             useGeneratedKeys="true" keyProperty="id">
         insert into f_fileinfo(folder_id,name,full_path,mime,ext,type,size,company_id,
-        creator_id,create_time,updater_id,update_time,deleted,deleter_id,delete_time)
+        creator_id,create_time,updater_id,update_time,deleted,deleter_id,delete_time,access_path)
         values (#{folderId,jdbcType=BIGINT},#{name,jdbcType=VARCHAR},#{fullPath,jdbcType=VARCHAR},
         #{mime,jdbcType=VARCHAR},#{ext,jdbcType=VARCHAR},#{type,jdbcType=VARCHAR},#{size,jdbcType=BIGINT},
         #{companyId,jdbcType=BIGINT},#{creatorId,jdbcType=BIGINT},#{createTime,jdbcType=TIMESTAMP},
         #{updaterId,jdbcType=BIGINT},#{updateTime,jdbcType=TIMESTAMP},#{deleted,jdbcType=BOOLEAN},
-        #{deleterId,jdbcType=BIGINT},#{deleteTime,jdbcType=TIMESTAMP})
+        #{deleterId,jdbcType=BIGINT},#{deleteTime,jdbcType=TIMESTAMP},#{accessPath,jdbcType=VARCHAR})
     </insert>
     <insert id="insertSelective" parameterType="com.usoftchina.smartschool.file.po.FileInfo"
             useGeneratedKeys="true" keyProperty="id">
@@ -61,6 +61,9 @@
             <if test="deleteTime != null">
                 delete_time,
             </if>
+            <if test="accessPath != null">
+                access_path,
+            </if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="folderId != null">
@@ -108,6 +111,9 @@
             <if test="deleteTime != null">
                 #{delete_time,jdbcType=TIMESTAMP},
             </if>
+            <if test="accessPath != null">
+                #{access_path,jdbcType=VARCHAR},
+            </if>
         </trim>
     </insert>
     <update id="updateByPrimaryKey" parameterType="com.usoftchina.smartschool.file.po.FileInfo">
@@ -192,11 +198,12 @@
         <result column="deleted" jdbcType="BOOLEAN" property="deleted"/>
         <result column="deleter_id" jdbcType="BIGINT" property="deleterId"/>
         <result column="delete_time" jdbcType="TIMESTAMP" property="deleteTime"/>
+        <result column="access_path" jdbcType="VARCHAR" property="accessPath"/>
     </resultMap>
     <sql id="baseColumns">
         f_fileinfo.id,f_fileinfo.folder_id,f_fileinfo.name,f_fileinfo.full_path,f_fileinfo.mime,f_fileinfo.ext,
         f_fileinfo.type,f_fileinfo.size,f_fileinfo.company_id,f_fileinfo.creator_id,f_fileinfo.create_time,
-        f_fileinfo.updater_id,f_fileinfo.update_time,f_fileinfo.deleted,f_fileinfo.deleter_id,f_fileinfo.delete_time
+        f_fileinfo.updater_id,f_fileinfo.update_time,f_fileinfo.deleted,f_fileinfo.deleter_id,f_fileinfo.delete_time,f_fileinfo.access_path
     </sql>
 
     <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
@@ -205,6 +212,9 @@
     <select id="selectByFullPath" parameterType="java.lang.String" resultMap="BaseResultMap">
         select <include refid="baseColumns"/> from f_fileinfo where full_path=#{fullPath}
     </select>
+    <select id="selectByAccessPath" parameterType="java.lang.String" resultMap="BaseResultMap">
+      select <include refid="baseColumns"/> from f_fileinfo where access_path=#{accessPath}
+    </select>
     <select id="selectByFolderId" parameterType="java.lang.Long" resultMap="BaseResultMap">
         select <include refid="baseColumns"/> from f_fileinfo where folder_id=#{folderId} order by id
     </select>