package com.hzs.system.config.provider;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.hzs.common.core.domain.R;
import com.hzs.common.domain.system.config.BdAdvertBanner;
import com.hzs.system.config.AdvertBannerServiceApi;
import com.hzs.system.config.dto.AdvertBannerDTO;
import com.hzs.system.config.service.IBdAdvertBannerService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@DubboService
public class AdvertBannerServiceProvider implements AdvertBannerServiceApi {

    @Autowired
    private IBdAdvertBannerService advertBannerService;

    /**
     * 查询全部banner
     *
     * @return
     */
    @Override
    public R<List<AdvertBannerDTO>> findAll() {
        List<AdvertBannerDTO> bannerDTOList = new ArrayList<>();

        List<BdAdvertBanner> bannerList = advertBannerService.listData(null);
        if (CollectionUtil.isNotEmpty(bannerList)) {
            bannerDTOList = bannerList.stream().map(advertBanner -> BeanUtil.copyProperties(advertBanner, AdvertBannerDTO.class)).collect(Collectors.toList());
        }

        return R.ok(bannerDTOList);
    }

}
