package com.liquidnet.service.kylin.service.impl.partner;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liquidnet.service.kylin.dto.vo.BuyNoticeVo;
import com.liquidnet.service.kylin.entity.KylinBuyNotice;
import com.liquidnet.service.kylin.mapper.KylinBuyNoticeMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liquidnet.service.kylin.service.partner.IKylinBuyNoticePartnerService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 购票须知表 服务实现类
 * </p>
 *
 * @author liquidnet
 * @since 2021-05-18
 */
@Service
public class KylinBuyNoticePartnerServiceImpl extends ServiceImpl<KylinBuyNoticeMapper, KylinBuyNotice> implements IKylinBuyNoticePartnerService {

    @Autowired
    private KylinBuyNoticeMapper kylinBuyNoticeMapper;

    @Override
    public PageInfo<BuyNoticeVo> getBuyNotice() {
        PageInfo<BuyNoticeVo> pageInfoTmp = null;

        PageHelper.startPage(1, 20);
        List<KylinBuyNotice> buyNoticeList = kylinBuyNoticeMapper.selectList(new UpdateWrapper<KylinBuyNotice>().eq("status", 1).orderByDesc("sort").orderByDesc("mid"));

        List<BuyNoticeVo> buyNoticeVoList = new ArrayList<>();
        for (KylinBuyNotice item : buyNoticeList) {
            BuyNoticeVo buyNoticeVo = new BuyNoticeVo();
            BeanUtils.copyProperties(item, buyNoticeVo);
            buyNoticeVoList.add(buyNoticeVo);
        }
        pageInfoTmp = new PageInfo(buyNoticeVoList);

        return pageInfoTmp;
    }

}
