package com.lottery.shop.service.impl;

import com.lottery.shop.entity.TaShop;
import com.lottery.shop.mapper.TaShopMapper;
import com.lottery.shop.service.TaShopService;
import com.lottery.shop.param.TaShopPageParam;
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.apache.commons.lang3.StringUtils;
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 TaShopServiceImpl extends BaseServiceImpl<TaShopMapper, TaShop> implements TaShopService {

    @Autowired
    private TaShopMapper taShopMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveTaShop(TaShop taShop) throws Exception {
        return super.save(taShop);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateTaShop(TaShop taShop) throws Exception {
        return super.updateById(taShop);
    }

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

    @Override
    public Paging<TaShop> getTaShopPageList(TaShopPageParam taShopPageParam) throws Exception {
        Page<TaShop> page = new PageInfo<>(taShopPageParam, OrderItem.desc(getLambdaColumn(TaShop::getCreateDate)));
        LambdaQueryWrapper<TaShop> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(taShopPageParam.getName()),TaShop::getName,taShopPageParam.getName());
        wrapper.eq(null != taShopPageParam.getStatus(),TaShop::getStatus,taShopPageParam.getStatus());
        IPage<TaShop> iPage = taShopMapper.selectPage(page, wrapper);
        return new Paging<TaShop>(iPage);
    }

}
