Просмотр исходного кода

fix:实现课件先按类型排序、再按上传时间排序

chillqi 3 лет назад
Родитель
Сommit
f0d8271b6c

+ 1 - 5
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/service/CourseWareService.java

@@ -26,11 +26,7 @@ public interface CourseWareService {
 
     CourseWareVO getCourseWareById(Long id);
 
-    String downloadCourseWare(HttpServletRequest req, HttpServletResponse res, Long id) throws IOException;
-
-    String getSlideUrl(Long slideId);
-
-    CourseWareVO getSlideInfo(Long slideId);
+//    String downloadCourseWare(HttpServletRequest req, HttpServletResponse res, Long id) throws IOException;
 
     String changeCourseWareName(Long id, String name);
 

+ 38 - 52
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/serviceImpl/CourseWareServiceImpl.java

@@ -73,7 +73,7 @@ public class CourseWareServiceImpl implements CourseWareService {
     public List<CourseWareDTO> getCourseWaresByCourseId(Long courseId) {
         System.out.println("get");
         List<CourseWareDTO> result = courseWareRepository.findCourseWaresByCourseIdAndStateNot(courseId, ObjectState.DELETED).stream()
-                .sorted(Comparator.comparing(CourseWare::getCreatedTime))
+                .sorted(Comparator.comparing(CourseWare::getUseMethod).thenComparing(CourseWare::getCreatedTime))
                 .map(courseWare -> new CourseWareDTO(courseWareMapper.toCourseWareVO(courseWare)))
                 .collect(Collectors.toList());
         return result;
@@ -98,57 +98,43 @@ public class CourseWareServiceImpl implements CourseWareService {
         }
     }
 
-    @Override
-    public String downloadCourseWare(HttpServletRequest req, HttpServletResponse res, Long id) throws IOException {
-        System.out.println("download");
-        CourseWare courseWare = courseWareRepository.findCourseWareById(id);
-        String fileName = courseWare.getName();
-        String filePath = courseWare.getFileUrl();
-
-        OutputStream os = null;
-        InputStream is = null;
-        try{
-            res.reset();
-            res.setCharacterEncoding("utf-8");
-            res.setContentType("application/octet-stream");
-            res.setHeader("Content-Disposition", "attachment;" + new String(fileName.getBytes("gb2312"), "ISO8859-1"));
-            File f = new File(filePath);
-            is = new FileInputStream(f);
-            ServletOutputStream sout = res.getOutputStream();
-            BufferedInputStream bis = null;
-            BufferedOutputStream bos = null;
-            bis = new BufferedInputStream(is);
-            bos = new BufferedOutputStream(sout);
-            byte[] buff = new byte[2048];
-            int bytesRead;
-            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
-                bos.write(buff, 0, bytesRead);
-            }
-            bos.flush();
-            bos.close();
-            bis.close();
-            is.close();
-            os.close();
-        }catch (Exception e){
-
-        }
-
-        return fileName;
-    }
-
-    @Override
-    public String getSlideUrl(Long slideId) {
-        System.out.println("geturl");
-        CourseWare courseWare = courseWareRepository.findCourseWareById(slideId);
-        return courseWare.getFileUrl();
-    }
-
-    @Override
-    public CourseWareVO getSlideInfo(Long slideId) {
-        System.out.println("getinfo");
-        CourseWare courseWare = courseWareRepository.findCourseWareById(slideId);
-        return courseWareMapper.toCourseWareVO(courseWare);
-    }
+//    @Override
+//    public String downloadCourseWare(HttpServletRequest req, HttpServletResponse res, Long id) throws IOException {
+//        System.out.println("download");
+//        CourseWare courseWare = courseWareRepository.findCourseWareById(id);
+//        String fileName = courseWare.getName();
+//        String filePath = courseWare.getFileUrl();
+//
+//        OutputStream os = null;
+//        InputStream is = null;
+//        try{
+//            res.reset();
+//            res.setCharacterEncoding("utf-8");
+//            res.setContentType("application/octet-stream");
+//            res.setHeader("Content-Disposition", "attachment;" + new String(fileName.getBytes("gb2312"), "ISO8859-1"));
+//            File f = new File(filePath);
+//            is = new FileInputStream(f);
+//            ServletOutputStream sout = res.getOutputStream();
+//            BufferedInputStream bis = null;
+//            BufferedOutputStream bos = null;
+//            bis = new BufferedInputStream(is);
+//            bos = new BufferedOutputStream(sout);
+//            byte[] buff = new byte[2048];
+//            int bytesRead;
+//            while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
+//                bos.write(buff, 0, bytesRead);
+//            }
+//            bos.flush();
+//            bos.close();
+//            bis.close();
+//            is.close();
+//            os.close();
+//        }catch (Exception e){
+//
+//        }
+//
+//        return fileName;
+//    }
 
     @Override
     public String changeCourseWareName(Long id, String newName) {

+ 4 - 14
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/web/rest/CourseWareController.java

@@ -56,20 +56,10 @@ public class CourseWareController {
         return OkResponse.of(courseWareService.getCourseWareById(id));
     }
 
-    @GetMapping("/download")
-    public OkResponse<String> downloadCourseWare(HttpServletRequest req, HttpServletResponse res, @RequestParam Long id) throws IOException {
-        return OkResponse.of(courseWareService.downloadCourseWare(req, res, id));
-    }
-
-    @GetMapping("/getSlideUrl")
-    public OkResponse<String> getSlideUrl(@RequestParam Long slideId) {
-        return OkResponse.of(courseWareService.getSlideUrl(slideId));
-    }
-
-    @GetMapping("/getSlideInfo")
-    public OkResponse<CourseWareVO> getSlideInfo(@RequestParam Long slideId) {
-        return OkResponse.of(courseWareService.getSlideInfo(slideId));
-    }
+//    @GetMapping("/download")
+//    public OkResponse<String> downloadCourseWare(HttpServletRequest req, HttpServletResponse res, @RequestParam Long id) throws IOException {
+//        return OkResponse.of(courseWareService.downloadCourseWare(req, res, id));
+//    }
 
     @PostMapping("/changeCourseWareName")
     public OkResponse<String> changeCourseWareName(@RequestParam Long id, @RequestParam String newName) {

+ 1 - 1
seecoder-portal-server/src/main/resources/application-dev.yml

@@ -9,7 +9,7 @@ spring:
   datasource:
     url: jdbc:postgresql://localhost:5432/portal
     username: postgres
-    password: 123456
+    password: postgres
 #    username: postgres
 #    password: postgres