package com.hzs.system.config.provider;/**
 * @Description:
 * @Author: yuhui
 * @Time: 2023/5/15 10:14
 * @Classname: AdvertBannerServiceProvider
 * @PackageName: com.hzs.system.config.provider
 */

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.IAccountServiceApi;
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.List;
import java.util.stream.Collectors;

/**
 *@BelongsProject: hzs_cloud
 *@BelongsPackage: com.hzs.system.config.provider
 *@Author: yh
 *@CreateTime: 2023-05-15  10:14
 *@Description: TODO
 *@Version: 1.0
 */
@DubboService
public class AdvertBannerServiceProvider implements AdvertBannerServiceApi {
    @Autowired
    private IBdAdvertBannerService advertBannerService;

    /**
     * 查询全部banner
     * @return
     */
    @Override
    public R<List<AdvertBannerDTO>> findAll() {
        QueryWrapper<BdAdvertBanner> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("SORT");
        List<BdAdvertBanner> bannerList = advertBannerService.list(queryWrapper);
        List<AdvertBannerDTO> bannerDTOList = bannerList.stream().map(advertBanner -> {
            AdvertBannerDTO ab = BeanUtil.copyProperties(advertBanner, AdvertBannerDTO.class);
            return ab;
        }).collect(Collectors.toList());
        return R.ok(bannerDTOList);
    }
}
