소스 검색

软件搜索&软件Top10

yonghuifan 1 년 전
부모
커밋
f98ca96f89

+ 23 - 4
src/main/java/com/dragon/tj/portal/controller/FileManageController.java

@@ -1,12 +1,11 @@
 package com.dragon.tj.portal.controller;
 
 import com.dragon.tj.portal.common.base.R;
+import com.dragon.tj.portal.entity.FileInfo;
+import com.dragon.tj.portal.entity.PageParam;
 import com.dragon.tj.portal.service.FileManageService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 
@@ -17,10 +16,30 @@ public class FileManageController {
     @Autowired
     private FileManageService fileManageService;
 
+    /*
+    * 文件上传
+    * */
     @PostMapping("/upload/{type}")
     public R upload(MultipartFile file, @PathVariable("type")Integer type){
 
         return R.ok().setData(fileManageService.upload(file,type));
     }
 
+    /*
+     *   文件软件搜索
+     * */
+    @PostMapping("search")
+    public R search(@RequestBody PageParam<FileInfo> appInfoPage) {
+
+        return R.ok(fileManageService.search(appInfoPage));
+    }
+
+    /*
+     *   获取Top 数量
+     * */
+    @GetMapping("top/{type}/{num}")
+    public R search(@PathVariable("type")String type,@PathVariable("num")Integer num) {
+        return R.ok(fileManageService.top(type,num));
+    }
+
 }

+ 13 - 0
src/main/java/com/dragon/tj/portal/mapper/FileManageMapper.java

@@ -3,6 +3,10 @@ package com.dragon.tj.portal.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.dragon.tj.portal.entity.FileInfo;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
 
 /**
  * 应用程序
@@ -10,4 +14,13 @@ import org.apache.ibatis.annotations.Mapper;
 @Mapper
 public interface FileManageMapper extends BaseMapper<FileInfo> {
 
+    @Select("<script>"
+            +"select * from file_info where type in "
+            + "<foreach item='item' index='index' collection='types'      open='(' separator=',' close=')'>"
+            + "#{item}"
+            + "</foreach>"
+            + "order by downloads desc  limit #{num}"
+            + "</script>")
+    List<FileInfo> getTop(@Param("types") List<String> ids,@Param("num")Integer limit);
+
 }

+ 8 - 0
src/main/java/com/dragon/tj/portal/service/FileManageService.java

@@ -1,8 +1,16 @@
 package com.dragon.tj.portal.service;
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.dragon.tj.portal.entity.FileInfo;
+import com.dragon.tj.portal.entity.PageParam;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.util.List;
+
 public interface FileManageService {
     FileInfo upload(MultipartFile file,Integer type);
+
+    Page<FileInfo> search(PageParam<FileInfo> pageParam);
+
+    List<FileInfo> top(String type, Integer num);
 }

+ 36 - 2
src/main/java/com/dragon/tj/portal/service/impl/FileManageServiceImpl.java

@@ -1,11 +1,15 @@
 package com.dragon.tj.portal.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.dragon.tj.portal.auth.model.LoginUser;
 import com.dragon.tj.portal.auth.util.SecurityUtils;
 import com.dragon.tj.portal.common.util.UploadUtils;
 import com.dragon.tj.portal.entity.FileInfo;
+import com.dragon.tj.portal.entity.PageParam;
 import com.dragon.tj.portal.mapper.FileManageMapper;
 import com.dragon.tj.portal.service.FileManageService;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.ApplicationContext;
@@ -16,8 +20,7 @@ import java.io.File;
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 
 @Service
 public class FileManageServiceImpl implements FileManageService {
@@ -77,4 +80,35 @@ public class FileManageServiceImpl implements FileManageService {
 
         return fileInfo;
     }
+
+    @Override
+    public Page<FileInfo> search(PageParam<FileInfo> pageParam) {
+        FileInfo fileParam = pageParam.getParams();
+        Page<FileInfo> rowPage = new Page(pageParam.getPage(), pageParam.getSize());
+
+        LambdaQueryWrapper<FileInfo> queryWrapper = new LambdaQueryWrapper<>();
+
+        //文件分类category(办公常用、系统工具)
+        queryWrapper.eq(fileParam.getType() != null,FileInfo::getType, fileParam.getType());
+        queryWrapper.eq(FileInfo::getDelFlag, 0);
+
+        //文件名称
+        queryWrapper.like(StringUtils.isNotEmpty(fileParam.getFileName()), FileInfo::getFileName, fileParam.getFileName());
+        //文件拓展名
+        queryWrapper.like(StringUtils.isNotEmpty(fileParam.getExtension()), FileInfo::getExtension, fileParam.getExtension());
+        //ContentType
+        queryWrapper.like(StringUtils.isNotEmpty(fileParam.getContentType()), FileInfo::getContentType, fileParam.getContentType());
+
+
+        //下载量排序
+        queryWrapper.orderByDesc(FileInfo::getDownloads);
+
+        return fileManageMapper.selectPage(rowPage, queryWrapper);
+    }
+
+    @Override
+    public List<FileInfo> top(String type, Integer num) {
+        List<String> list = Arrays.asList(type.split(","));
+        return fileManageMapper.getTop(list,num);
+    }
 }