搞定
This commit is contained in:
@@ -5,14 +5,15 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.quinn.common.QuinnConstant;
|
||||
import com.quinn.pojo.*;
|
||||
import com.quinn.pojo.param.QuerySource;
|
||||
import com.quinn.service.SourceCategoryService;
|
||||
import com.quinn.service.SourceCommentService;
|
||||
import com.quinn.service.SourceService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -41,13 +42,18 @@ public class SourceController {
|
||||
|
||||
// 列表展示
|
||||
@GetMapping("/source")
|
||||
public String sourceList(@RequestParam String name,@RequestParam int category,Model model){
|
||||
public String sourceList(Model model){
|
||||
Page<Source> pageParam = new Page<>(1, 10);
|
||||
QueryWrapper<Source> sourceQuery = new QueryWrapper<>();
|
||||
sourceQuery.orderByDesc("gmt_create");
|
||||
sourceService.page(pageParam,sourceQuery);
|
||||
// 结果
|
||||
List<Source> sourceList = pageParam.getRecords();
|
||||
if (!CollectionUtils.isEmpty(sourceList)){
|
||||
sourceList.forEach(x ->{
|
||||
x.setSourceLink(QuinnConstant.GUN);
|
||||
});
|
||||
}
|
||||
model.addAttribute("sourceList",sourceList);
|
||||
model.addAttribute("pageParam",pageParam);
|
||||
|
||||
@@ -58,32 +64,70 @@ public class SourceController {
|
||||
return "source/list";
|
||||
}
|
||||
|
||||
@PostMapping("/source/page")
|
||||
public String blogListPage(QuerySource querySource, Model model){
|
||||
int page = querySource.getPageNum();
|
||||
int limit = querySource.getLimit();
|
||||
if (querySource.getPageNum() < 1){
|
||||
page = 1;
|
||||
}
|
||||
Page<Source> pageParam = new Page<>(page, limit);
|
||||
QueryWrapper<Source> sourceQuery = new QueryWrapper<>();
|
||||
addParam(sourceQuery,querySource.getName(),querySource.getCategory());
|
||||
sourceQuery.orderByDesc("gmt_create");
|
||||
sourceService.page(pageParam,sourceQuery);
|
||||
|
||||
// 结果
|
||||
List<Source> blogList = pageParam.getRecords();
|
||||
model.addAttribute("sourceList",blogList);
|
||||
model.addAttribute("pageParam",pageParam);
|
||||
return "source/list::s_table_refresh";
|
||||
}
|
||||
|
||||
// 列表展示
|
||||
@GetMapping("/hot/source")
|
||||
@GetMapping("/hotspot")
|
||||
public String sourceHotPot(Model model){
|
||||
Page<Source> pageParam = new Page<>(1, 10);
|
||||
Page<Source> pageParam = new Page<>(1, 9);
|
||||
QueryWrapper<Source> sourceQuery = new QueryWrapper<>();
|
||||
sourceQuery.orderByDesc("down_record");
|
||||
sourceService.page(pageParam,sourceQuery);
|
||||
// 结果
|
||||
List<Source> sourceList = pageParam.getRecords();
|
||||
if (!CollectionUtils.isEmpty(sourceList)){
|
||||
sourceList.forEach(x ->{
|
||||
x.setSourceLink(QuinnConstant.GUN);
|
||||
x.setSourceContent("");
|
||||
});
|
||||
}
|
||||
model.addAttribute("sourceList",sourceList);
|
||||
return "source/list";
|
||||
return "source/hotspot";
|
||||
}
|
||||
|
||||
|
||||
// 查看文件详情
|
||||
/**
|
||||
* 查看下载资源的详情
|
||||
* @param sid
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/source/view/{sid}")
|
||||
public String read(@PathVariable("sid") String sid, Model model){
|
||||
Source source = sourceService.getOne(new QueryWrapper<Source>().eq("id", sid));
|
||||
source.setSourceLink("no network link");
|
||||
if(source != null){
|
||||
source.setSourceLink(QuinnConstant.GUN);
|
||||
}
|
||||
model.addAttribute("source",source);
|
||||
List<SourceComment> commentList = sourceCommentService.list(new QueryWrapper<SourceComment>().eq("topic_id", sid).orderByDesc("gmt_create"));
|
||||
model.addAttribute("commentList",commentList);
|
||||
return "source/view";
|
||||
}
|
||||
|
||||
// 下载文件
|
||||
/**
|
||||
* 下载具体的文件
|
||||
* @param response
|
||||
* @param sid
|
||||
* @throws IOException
|
||||
*/
|
||||
@GetMapping("/source/download/{sid}")
|
||||
public void read(HttpServletResponse response, @PathVariable("sid") String sid) throws IOException {
|
||||
Source source = sourceService.getOne(new QueryWrapper<Source>().eq("id", sid));
|
||||
@@ -93,4 +137,13 @@ public class SourceController {
|
||||
this.sourceService.downloadSource(response.getOutputStream(),source);
|
||||
}
|
||||
|
||||
private void addParam(QueryWrapper<Source> sourceQuery, String name, int category) {
|
||||
if (!StringUtils.isEmpty(name)){
|
||||
sourceQuery.like("source_name",name);
|
||||
}
|
||||
if (category > 0){
|
||||
sourceQuery.eq("category_id",category);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user