package com.ssm.manage.service.impl;

import com.github.pagehelper.PageInfo;
import com.ssm.core.service.impl.BaseServiceImpl;
import com.ssm.manage.dao.BaseDao;
import com.ssm.manage.dao.SsmTopUpPromotionDao;
import com.ssm.manage.dao.SsmUploadFilesDao;
import com.ssm.manage.entity.PromotionUnit;
import com.ssm.manage.entity.SysUser;
import com.ssm.manage.entity.TopUpPromotion;
import com.ssm.manage.query.TopUpPromotionRequest;
import com.ssm.manage.query.UserRequest;
import com.ssm.manage.service.SsmSysUserService;
import com.ssm.manage.service.SsmTopUpPromotionService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SsmTopUpPromotionServiceImpl  extends BaseServiceImpl<TopUpPromotion> implements SsmTopUpPromotionService {

    @Autowired
    private SsmTopUpPromotionDao dao;

    @Override
    public BaseDao<TopUpPromotion> getDao() {
        return dao;
    }

    @Override
    public PageInfo<TopUpPromotion> selectByPage(TopUpPromotionRequest topUpPromotionRequest) {
        return dao.selectByPage(topUpPromotionRequest);
    }

    @Override
    @Transactional(rollbackFor=Exception.class)
    public int insert(TopUpPromotionRequest topUpPromotionRequest) {
        TopUpPromotion topUpPromotion = new TopUpPromotion();
        TopUpPromotion topUpPromotion1 = new TopUpPromotion();
        topUpPromotion1.setPromotionNum(topUpPromotionRequest.getPromotionNum());
        TopUpPromotion topUpPromotion2 = dao.selectOne(topUpPromotion1);
        if(topUpPromotion2==null){
            throw new RuntimeException("编码已经存在");
        }
        BeanUtils.copyProperties(topUpPromotionRequest, topUpPromotion);
        return dao.insert(topUpPromotion);
    }
}
