liujie
2026-03-10 5171fcf8ccf77a670632e54d2c88642377bfc2ae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.ruoyi.web.controller.api;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.model.TBanner;
import com.ruoyi.system.model.TGuide;
import com.ruoyi.system.model.TNotice;
import com.ruoyi.system.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
import java.util.Objects;
 
/**
 * 首页相关接口
 */
@Slf4j
@RestController
@RequestMapping("/index")
@Api(tags = "首页相关接口")
@Validated
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class IndexController {
 
    private final TBannerService tBannerService;
    private final TGuideService tGuideService;
    private final TNoticeService tNoticeService;
 
 
 
    @ApiOperation(value = "首页模块--轮播图",response = TBanner.class)
    @GetMapping(value = "/getBannerList")
    public R<List<TBanner>> getBannerList() {
        List<TBanner> tBannerList = tBannerService.list();
        return R.ok(tBannerList);
    }
 
    @ApiOperation(value = "首页模块--轮播图详情",response = TBanner.class)
    @GetMapping(value = "/getBannerDetail/{id}")
    public R<TBanner> getBannerDetail(@PathVariable String id) {
        TBanner tBanner = tBannerService.getById(id);
        //增加阅读量
        tBanner.setReadCount(tBanner.getReadCount() + 1);
        tBannerService.updateById(tBanner);
        return R.ok(tBanner);
    }
 
    @ApiOperation(value = "首页模块--攻略列表",response = TGuide.class)
    @GetMapping(value = "/getGuideList")
    public R<List<TGuide>> getGuideList(String title) {
        LambdaQueryWrapper<TGuide> tGuideLambdaQueryWrapper = new LambdaQueryWrapper<>();
        tGuideLambdaQueryWrapper.like(Objects.nonNull( title),TGuide::getTitle, title);
        tGuideLambdaQueryWrapper.orderByDesc(TGuide::getSort);
        List<TGuide> list = tGuideService.list(tGuideLambdaQueryWrapper);
        return R.ok(list);
    }
 
    @ApiOperation(value = "首页模块--轮播图详情",response = TBanner.class)
    @GetMapping(value = "/getGuideDetail/{id}")
    public R<TGuide> getGuideDetail(@PathVariable String id) {
        TGuide guide = tGuideService.getById(id);
        //增加阅读量
        guide.setLookNum(guide.getLookNum() + 1);
        tGuideService.updateById(guide);
        return R.ok(guide);
    }
 
 
    @ApiOperation(value = "首页模块--公告列表",response = TNotice.class)
    @GetMapping(value = "/getNoticeList")
    public R<List<TNotice>> getNoticeList(String title) {
        LambdaQueryWrapper<TNotice> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TNotice::getShowOnHome, true);
        wrapper.like(Objects.nonNull( title),TNotice::getTitle, title);
        wrapper.orderByDesc(TNotice::getSort);
        List<TNotice> list = tNoticeService.list(wrapper);
        return R.ok(list);
    }
 
 
    @ApiOperation(value = "首页模块--轮播图详情",response = TBanner.class)
    @GetMapping(value = "/getNoticeDetail/{id}")
    public R<TNotice> getNoticeDetail(@PathVariable String id) {
        TNotice notice = tNoticeService.getById(id);
        //增加阅读量
        notice.setLookNum(notice.getLookNum() + 1);
        tNoticeService.updateById(notice);
        return R.ok(notice);
    }
 
}