package com.hwrj.cloud.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.hwrj.cloud.admin.dao.UmsRollBuyDao;
import com.hwrj.cloud.admin.mapper.UmsRollBuyMapper;
import com.hwrj.cloud.admin.model.UmsRollBuy;
import com.hwrj.cloud.admin.model.UmsRollBuyExample;
import com.hwrj.cloud.admin.service.UmsRollBuyService;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class UmsRollBuyServiceImpl implements UmsRollBuyService {

    @Autowired
    private UmsRollBuyMapper umsRollBuyMapper;
    @Override
    public int add(UmsRollBuy buy) {
        if (buy != null){
            int i = umsRollBuyMapper.insertSelective(buy);
            return i;
        }
        return 0;
    }

    @Override
    public int update(UmsRollBuy buy) {
        if (buy != null&&buy.getId() !=null){
            int i = umsRollBuyMapper.updateByPrimaryKeySelective(buy);
            return i;
        }
        return 0;
    }

    @Override
    public int delete(Long id) {
        if (id != null){
            int i = umsRollBuyMapper.deleteByPrimaryKey(id);
            return i;
        }
        return 0;
    }

    @Override
    public List<UmsRollBuy> page(String keyword, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        UmsRollBuyExample example = new UmsRollBuyExample();
        UmsRollBuyExample.Criteria criteria = example.createCriteria();
        if (!StringUtils.isEmpty(keyword)){
            criteria.andMemberNameLike("%"+keyword+"%");
        }
        return umsRollBuyMapper.selectByExample(example);
    }

    @Override
    public UmsRollBuy info(Long id) {
        if (id != null){
            return umsRollBuyMapper.selectByPrimaryKey(id);
        }
        return null;
    }
    @Autowired
    private UmsRollBuyDao umsRollBuyDao;
    @Override
    public int importExcel(List<UmsRollBuy> list) {
        if (list != null &&list.size()>0){
            return umsRollBuyDao.insertList(list);
        }
        return 0;
    }
}
