package com.hzs.system.config.controller.api;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.hzs.common.core.web.controller.BaseController;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.web.page.TableDataInfo;
import com.hzs.common.domain.system.config.BdAdvertBanner;
import com.hzs.common.security.utils.SecurityUtils;
import com.hzs.system.config.service.IBdAdvertBannerService;
import com.hzs.system.config.vo.ApiAdvertBannerVO;
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.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 广告banner 前端控制器
 *
 * @author hzs
 * @since 2022-12-08
 */
@RestController
@RequestMapping("/api/bd-advert-banner")
public class ApiBdAdvertBannerController extends BaseController {

    @Autowired
    private IBdAdvertBannerService advertBannerService;

    /**
     * @description: 查询广告banner
     * @author: zhang jing
     * @date: 2022/8/30 10:20
     * @param: [advertBanner]
     * @return: com.hzs.common.core.web.page.TableDataInfo
     **/
    @GetMapping("/list")
    public TableDataInfo list(BdAdvertBanner banner) {
        List<BdAdvertBanner> list = advertBannerService.listData(banner, SecurityUtils.getUserId());
        return getDataTable(list);
    }

    /**
     * 广告banner列表
     *
     * @return
     */
    @GetMapping("/banner-list")
    public AjaxResult bannerList() {
        // 返回结果
        List<ApiAdvertBannerVO> resultList = new ArrayList<>();

        List<BdAdvertBanner> list = advertBannerService.listData(null, SecurityUtils.getUserId());
        if (CollectionUtil.isNotEmpty(list)) {
            resultList = BeanUtil.copyToList(list, ApiAdvertBannerVO.class);
        }

        return AjaxResult.success(resultList);
    }


}
