|
|
@@ -1,53 +1,48 @@
|
|
|
package cn.reghao.tnb.search.app.controller;
|
|
|
|
|
|
-import cn.reghao.tnb.search.app.es.EsSearch;
|
|
|
+import cn.reghao.jutil.jdk.db.PageList;
|
|
|
+import cn.reghao.jutil.web.WebResult;
|
|
|
+import cn.reghao.tnb.search.app.es.WenshuSearch;
|
|
|
import cn.reghao.tnb.search.app.model.po.Wenshu;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.ui.ModelMap;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
+ * 裁判文书搜索接口
|
|
|
+ *
|
|
|
* @author reghao
|
|
|
* @date 2025-05-02 16:44:46
|
|
|
*/
|
|
|
-@Controller
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/search1/wenshu")
|
|
|
public class SearchController {
|
|
|
- private EsSearch esSearch;
|
|
|
+ private final WenshuSearch wenshuSearch;
|
|
|
|
|
|
- // 裁判文书搜索页面
|
|
|
- @GetMapping("/wenshu")
|
|
|
- public String wenshuSearchPage(@RequestParam(value = "search", required = false) String search,
|
|
|
- @RequestParam(value = "searchType", required = false) String searchType,
|
|
|
- ModelMap model) {
|
|
|
- Pageable pageable = PageRequest.of(0, 10, Sort.by(Sort.Direction.ASC, "createTime"));
|
|
|
- Page<Wenshu> page;
|
|
|
- if (search == null) {
|
|
|
- page = Page.empty();
|
|
|
- } else {
|
|
|
- page = esSearch.search(search, pageable);
|
|
|
- }
|
|
|
+ public SearchController(WenshuSearch wenshuSearch) {
|
|
|
+ this.wenshuSearch = wenshuSearch;
|
|
|
+ }
|
|
|
|
|
|
- if (searchType == null) {
|
|
|
- searchType = "";
|
|
|
- }
|
|
|
+ @GetMapping("/query")
|
|
|
+ public String searchWenshu(@RequestParam(value = "search") String keyword) {
|
|
|
+ Pageable pageable = PageRequest.of(0, 10, Sort.by(Sort.Direction.ASC, "createTime"));
|
|
|
+ Page<Wenshu> page = wenshuSearch.search(keyword, pageable);
|
|
|
|
|
|
- model.put("page", page);
|
|
|
- model.put("search", search);
|
|
|
- model.put("searchType", searchType);
|
|
|
- return "/classic/wenshu/wenshu_search";
|
|
|
+ int pageNumber = page.getNumber();
|
|
|
+ int pageSize = page.getSize();
|
|
|
+ int total = (int) page.getTotalElements();
|
|
|
+ List<Wenshu> list = page.getContent();
|
|
|
+ PageList<Wenshu> pageList = PageList.pageList(pageNumber, pageSize, total, list);
|
|
|
+ return WebResult.success(pageList);
|
|
|
}
|
|
|
|
|
|
- // 裁判文书详情页面
|
|
|
- @GetMapping("/wenshu/{id}")
|
|
|
- public String wenshuPage(@PathVariable("id") String id, ModelMap model) {
|
|
|
- Wenshu wenshuResult = esSearch.getById(id);
|
|
|
- model.put("wenshu", wenshuResult);
|
|
|
- return "/classic/wenshu/wenshu";
|
|
|
+ @GetMapping("/detail/{id}")
|
|
|
+ public String getWenshuDetail(@PathVariable("id") String id) {
|
|
|
+ Wenshu wenshuResult = wenshuSearch.getById(id);
|
|
|
+ return WebResult.success(wenshuResult);
|
|
|
}
|
|
|
}
|