package com.lottery.type.service.impl;

import com.lottery.type.entity.TdLottery;
import com.lottery.type.mapper.TdLotteryMapper;
import com.lottery.type.service.TdLotteryService;
import com.lottery.type.param.TdLotteryPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 彩种 服务实现类
 *
 * @author fxf
 * @since 2020-09-07
 */
@Slf4j
@Service
public class TdLotteryServiceImpl extends BaseServiceImpl<TdLotteryMapper, TdLottery> implements TdLotteryService {

    @Autowired
    private TdLotteryMapper tdLotteryMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveTdLottery(TdLottery tdLottery) throws Exception {
        return super.save(tdLottery);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateTdLottery(TdLottery tdLottery) throws Exception {
        return super.updateById(tdLottery);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteTdLottery(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<TdLottery> getTdLotteryPageList(TdLotteryPageParam tdLotteryPageParam) throws Exception {
        Page<TdLottery> page = new PageInfo<>(tdLotteryPageParam, OrderItem.desc(getLambdaColumn(TdLottery::getCreateDate)));
        LambdaQueryWrapper<TdLottery> wrapper = new LambdaQueryWrapper<>();
        IPage<TdLottery> iPage = tdLotteryMapper.selectPage(page, wrapper);
        return new Paging<TdLottery>(iPage);
    }

}
