package com.iformall.service.impl;

import java.util.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iformall.domain.po.WxCouponSpread;
import com.iformall.mapper.WxCouponSpreadMapper;
import com.iformall.service.WxCouponSpreadService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.iformall.common.IdWorker;

@Service
public class WxCouponSpreadServiceImpl implements WxCouponSpreadService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
    WxCouponSpreadMapper wxCouponSpreadMapper;


    @Override
    public PageInfo<WxCouponSpread> listAsPage(WxCouponSpread record, Integer pageIndex, Integer pageSize) {
        return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponSpreadMapper.findList(record));
    }

    @Override
    public WxCouponSpread getById(Long id) {
        return wxCouponSpreadMapper.selectByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(WxCouponSpread record) {
        if (record.getId() == null) {
            //record.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            final IdWorker idWorker = IdWorker.get();
            record.setId(idWorker.nextId());
            wxCouponSpreadMapper.insertSelective(record);
        } else {
            wxCouponSpreadMapper.updateByPrimaryKeySelective(record);
        }
    }

    @Override
    public void deleteById(Long id) {
        wxCouponSpreadMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<WxCouponSpread> findList(WxCouponSpread record) {
        return wxCouponSpreadMapper.findList(record);

    }


}
