package com.yiqi.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yiqi.app.domain.AppBanner;
import com.yiqi.app.service.IAppBannerService;
import com.yiqi.common.constant.UrlConstants;
import com.yiqi.common.core.domain.R;
import com.yiqi.common.enums.AppBannerType;
import com.yiqi.common.enums.StatusType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xiaohei
 * @date 2023/10/4
 */
@Api(tags = "轮播图、启动页广告、首页广告")
@RestController
@RequestMapping(value = UrlConstants.wxappApi + "/banner")
public class WeAppBannerController {

    @Autowired
    private IAppBannerService appBannerService;

    @ApiOperation("获取轮播图列表")
    @GetMapping(value = "list")
    public R<List<AppBanner>> list(@RequestParam @ApiParam("0:轮播，3：金刚位 4：腰线") String bannerType) throws Exception {
        return R.ok(appBannerService.selectAppBannerListByType(bannerType));
    }

    @ApiOperation("获取广告")
    @GetMapping(value = "getAdver")
    public R<AppBanner> getAdver(@RequestParam @ApiParam("1:启动页广告，2：首页广告") String bannerType) throws Exception {
        return R.ok(appBannerService.getOne(new QueryWrapper<AppBanner>().lambda()
                .eq(AppBanner::getStatus, StatusType.OK.getCode())
                .eq(AppBanner::getBannerType, bannerType), false));
    }

}
