瀏覽代碼

资料下载

Signed-off-by: guoWenHao <2532478980@qq.com>
guoWenHao 9 月之前
父節點
當前提交
3342580179

+ 13 - 0
teacher-serve/src/main/java/com/example/controller/user/CommonController.java

@@ -2,11 +2,13 @@ package com.example.controller.user;
 
 import com.example.constant.MessageConstant;
 import com.example.result.Result;
+import com.example.service.CommonService;
 import com.example.utils.AliOssUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -27,6 +29,10 @@ public class CommonController {
     @Autowired
     private AliOssUtil aliOssUtil;
 
+
+    @Autowired
+    private CommonService commonService;
+
     /*
     文件上传
      */
@@ -49,4 +55,11 @@ public class CommonController {
         }
         return Result.error(MessageConstant.UPLOAD_FAILED);
     }
+
+    @GetMapping("/download")
+    public Result<String> getUrl(Long id,Integer status){
+        log.info("下载指定文件:id,{},status,{}",id,status);
+        String url = commonService.getUrl(id,status);
+        return Result.success(url);
+    }
 }

+ 31 - 0
teacher-serve/src/main/java/com/example/mapper/CommonMapper.java

@@ -0,0 +1,31 @@
+package com.example.mapper;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+
+@Mapper
+public interface CommonMapper {
+    /**
+     * 下载著作
+     * @param id
+     * @return
+     */
+    @Select("select file from teacherteam_system.work where id = #{id}")
+    String getWork(Long id);
+
+    /**
+     * 下载论文
+     * @param id
+     * @return
+     */
+    @Select("select file from teacherteam_system.thesis where id = #{id}")
+    String getThesis(Long id);
+
+    /**
+     * 下载共享资料
+     * @param id
+     * @return
+     */
+    @Select("select file from teacherteam_system.resources where id = #{id}")
+    String getResource(Long id);
+}

+ 5 - 0
teacher-serve/src/main/java/com/example/mapper/ResourceMapper.java

@@ -39,5 +39,10 @@ public interface ResourceMapper {
     @Select("select * from teacherteam_system.resources where id = #{id}")
     Resource getById(Long id);
 
+    /**
+     * 资料分页查询
+     * @param pageQueryDTO
+     * @return
+     */
     Page<Resource> getAll(PageQueryDTO pageQueryDTO);
 }

+ 5 - 0
teacher-serve/src/main/java/com/example/service/CommonService.java

@@ -0,0 +1,5 @@
+package com.example.service;
+
+public interface CommonService {
+    String getUrl(Long id, Integer status);
+}

+ 5 - 0
teacher-serve/src/main/java/com/example/service/ResourceService.java

@@ -32,5 +32,10 @@ public interface ResourceService {
      */
     ResourceVO getById(Long id);
 
+    /**
+     * 资料分页查询
+     * @param pageQueryDTO
+     * @return
+     */
     PageResult getAll(PageQueryDTO pageQueryDTO);
 }

+ 28 - 0
teacher-serve/src/main/java/com/example/service/impl/CommonServiceImpl.java

@@ -0,0 +1,28 @@
+package com.example.service.impl;
+
+import com.example.mapper.CommonMapper;
+import com.example.service.CommonService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class CommonServiceImpl implements CommonService {
+
+    @Autowired
+    private CommonMapper commonMapper;
+
+    @Override
+    public String getUrl(Long id, Integer status) {
+
+        String url = null;
+        //status,1为著作,2为论文,3为共享资料
+        if (status == 1) {
+            url = commonMapper.getWork(id);
+        } else if (status == 2) {
+            url = commonMapper.getThesis(id);
+        } else if (status == 3) {
+            url = commonMapper.getResource(id);
+        }
+        return url;
+    }
+}

+ 6 - 0
teacher-serve/src/main/java/com/example/service/impl/ResourceServiceImpl.java

@@ -71,6 +71,12 @@ public class ResourceServiceImpl implements ResourceService {
         return resourceVO;
     }
 
+    /**
+     *
+     * 资料分页查询
+     * @param pageQueryDTO
+     * @return
+     */
     @Override
     public PageResult getAll(PageQueryDTO pageQueryDTO) {
         PageHelper.startPage(pageQueryDTO.getPage(),pageQueryDTO.getPageSize());