SearchController.java 2.89 KB
Newer Older
张辰's avatar
张辰 committed
1 2 3 4
package com.tanpu.community.controller;

import com.tanpu.common.api.CommonResp;
import com.tanpu.common.auth.UserHolder;
刘基明's avatar
刘基明 committed
5
import com.tanpu.community.api.beans.qo.FollowQo;
张辰's avatar
张辰 committed
6
import com.tanpu.community.api.beans.req.search.ThemeFullSearchReq;
刘基明's avatar
刘基明 committed
7
import com.tanpu.community.api.beans.resp.ThemeAndUserSearchResp;
张辰's avatar
张辰 committed
8
import com.tanpu.community.api.beans.resp.ThemeFullSearchResp;
刘基明's avatar
刘基明 committed
9 10
import com.tanpu.community.api.beans.resp.UserSearchResp;
import com.tanpu.community.manager.HomePageManager;
张辰's avatar
张辰 committed
11
import com.tanpu.community.manager.ThemeManager;
张辰's avatar
张辰 committed
12
import com.tanpu.community.util.PagePdfGenUtils;
张辰's avatar
张辰 committed
13 14 15
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
张辰's avatar
1  
张辰 committed
16
import org.springframework.web.bind.annotation.*;
张辰's avatar
张辰 committed
17 18

import javax.annotation.Resource;
张辰's avatar
1  
张辰 committed
19
import java.io.IOException;
张辰's avatar
张辰 committed
20 21 22 23 24 25 26 27 28 29 30 31 32
import java.util.List;

@RestController
@Slf4j
@RequestMapping(value = "/api/search")
public class SearchController {

    @Resource
    private UserHolder userHolder;

    @Autowired
    private ThemeManager themeManager;

刘基明's avatar
刘基明 committed
33 34 35
    @Autowired
    private HomePageManager homePageManager;

张辰's avatar
张辰 committed
36
    // 内容全文搜索
张辰's avatar
张辰 committed
37 38 39 40
    @ApiOperation("全文搜索主题")
    @PostMapping(value = "/themeFullText")
    @ResponseBody
    public CommonResp<ThemeFullSearchResp> themeFullText(@RequestBody ThemeFullSearchReq req) {
张辰's avatar
张辰 committed
41
        ThemeFullSearchResp resp = themeManager.themeFullSearch(req.keyword, req.page.pageNumber, req.page.pageSize, req.ident, userHolder.getUserId());
张辰's avatar
张辰 committed
42
        return CommonResp.success(resp);
张辰's avatar
张辰 committed
43 44
    }

刘基明's avatar
刘基明 committed
45
    // 用户+内容全文搜索
刘基明's avatar
刘基明 committed
46 47
    @ApiOperation("综合搜索")
    @PostMapping(value = "/muLtipuleSearch")
刘基明's avatar
刘基明 committed
48 49 50
    @ResponseBody
    public CommonResp<ThemeAndUserSearchResp> themeFullTextAndUserSearch(@RequestBody ThemeFullSearchReq req) {
        ThemeFullSearchResp themeFullSearch = themeManager.themeFullSearch(req.keyword, req.page.pageNumber, req.page.pageSize, req.ident, userHolder.getUserId());
刘基明's avatar
刘基明 committed
51
        List<FollowQo> users = homePageManager.userNameSerach(req.keyword, 1, 3, req.ident, userHolder.getUserId());
刘基明's avatar
刘基明 committed
52 53 54 55 56 57 58 59 60 61 62 63 64

        return CommonResp.success(ThemeAndUserSearchResp.builder().themes(themeFullSearch.getThemes()).users(users).build());
    }

    // 用户搜索
    @ApiOperation("用户姓名模糊查询")
    @PostMapping(value = "/userNameFuzzy")
    @ResponseBody
    public CommonResp<UserSearchResp> userNameSerach(@RequestBody ThemeFullSearchReq req) {
        List<FollowQo> users = homePageManager.userNameSerach(req.keyword, req.page.pageNumber, req.page.pageSize, req.ident, userHolder.getUserId());
        return CommonResp.success(UserSearchResp.builder().users(users).build());
    }

张辰's avatar
张辰 committed
65 66
    @GetMapping("/testGenPdf")
    public CommonResp testGenPdf(@RequestParam("url") String url) {
张辰's avatar
1  
张辰 committed
67 68 69 70 71 72
        try {
            PagePdfGenUtils.genPdf(url);
            return CommonResp.success();
        } catch (Throwable e) {
            return CommonResp.error("9999", e.getMessage());
        }
张辰's avatar
张辰 committed
73
    }
张辰's avatar
张辰 committed
74
}