package com.community.huiju.service.impl;

import com.community.commom.constant.Constant;
import com.community.commom.utils.DateUtils;
import com.community.huiju.dao.ToBannerMapper;
import com.community.huiju.dao.TpCarouselSettingMapper;
import com.community.huiju.model.ToBanner;
import com.community.huiju.service.BannerServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author weichaochao
 * @Title: BannerServiceImpl
 * @date 2018/10/22
 */
@Service("/BannerService")
public class BannerServiceImpl implements BannerServiceI {

    @Autowired
    private ToBannerMapper toBannerMapper;

    @Autowired
    private TpCarouselSettingMapper tpCarouselSettingMapper;

    @Override
    public ToBanner viewBannerImg(Integer bannerId) {
        return toBannerMapper.selectByCommunityId(bannerId);
    }

    @Override
    public List<ToBanner> viewAllBannerImg(Integer bannerPosition) {
        //查询轮播图数量
        Integer bannerNum = tpCarouselSettingMapper.selectCarouselNum(Constant.BANNER);

        String nowTime = DateUtils.getDate("yyyy-MM-dd");
        List<ToBanner> bannersList = toBannerMapper.selectAllByNum(nowTime, bannerNum, bannerPosition);
        bannersList.stream().forEach(banner -> {
            if (banner.getBannerType().equals(Constant.BANNER_TYPE_ARTICLE)){
                banner.setExternalLink("http://101.132.102.231:8011/#/bannerDetail?from=index&id="+banner.getId());
            }
        });
        return bannersList;
    }
}
