package com.hzs.system.base.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.domain.system.config.BdAdvertBanner;
import com.hzs.system.config.dto.AdvertBannerDTO;
import com.hzs.system.config.service.IBdAdvertBannerService;
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.List;
import java.util.stream.Collectors;

/**
 * 首页banner
 */
@RestController
@RequestMapping("/api/banner")
public class ApiBannerController extends BaseController {

    @Autowired
    private IBdAdvertBannerService iBdAdvertBannerService;

    /**
     * banner列表
     *
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list() {
        List<BdAdvertBanner> bannerList = iBdAdvertBannerService.listData(null);
        if (CollectionUtil.isNotEmpty(bannerList)) {
            return AjaxResult.success(bannerList.stream().map(advertBanner -> BeanUtil.copyProperties(advertBanner, AdvertBannerDTO.class)).collect(Collectors.toList()));
        }
        return AjaxResult.success();
    }

}
