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);
|
}
|
|
}
|