package com.ssm.manage.service.impl;

import com.github.pagehelper.PageInfo;
import com.ssm.core.service.impl.BaseServiceImpl;
import com.ssm.manage.dao.SsmRechargeAccountDao;
import com.ssm.manage.dao.SsmRechargeDemotioneingRunDao;
import com.ssm.manage.entity.RechargeAccount;
import com.ssm.manage.entity.RechargeDemotioneingRun;
import com.ssm.manage.entity.SmsException;
import com.ssm.manage.entity.SysUser;
import com.ssm.manage.query.RechargeDemotioneingRunRequest;
import com.ssm.manage.query.UserRequest;
import com.ssm.manage.service.SsmRechargeAccountService;
import com.ssm.manage.service.SsmRechargeDemotioneingRunService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class SsmRechargeDemotioneingRunServiceImpl  extends BaseServiceImpl<RechargeDemotioneingRun> implements SsmRechargeDemotioneingRunService {
    @Autowired
    private SsmRechargeDemotioneingRunDao dao;

    @Override
    public SsmRechargeDemotioneingRunDao getDao() {
        return dao;
    }

    @Override
    public PageInfo<RechargeDemotioneingRun> selectByPage(RechargeDemotioneingRunRequest rechargeDemotioneingRunRequest) {
        return dao.selectByPage(rechargeDemotioneingRunRequest);
    }
    @Override
    public PageInfo<RechargeDemotioneingRun> selectByPages(RechargeDemotioneingRunRequest rechargeDemotioneingRunRequest) {
        return dao.selectByPages(rechargeDemotioneingRunRequest);
    }

    @Override
    public int saveRechargeDemotioneingRun(RechargeDemotioneingRun rechargeDemotioneingRun) {
        RechargeDemotioneingRunRequest rechargeDemotioneingRunRequest = new RechargeDemotioneingRunRequest();
        rechargeDemotioneingRunRequest.setRechargeTypeId(rechargeDemotioneingRun.getRechargeTypeId());
        rechargeDemotioneingRunRequest.setNewRechargeTypeId(rechargeDemotioneingRun.getNewRechargeTypeId());
        rechargeDemotioneingRunRequest.setStoreId(rechargeDemotioneingRun.getStoreId());
        List<RechargeDemotioneingRun> rechargeDemotioneingRuns = dao.selectListChongFu(rechargeDemotioneingRunRequest);
        int i ;
        if(rechargeDemotioneingRuns.size()==0){
            i = dao.saveNotNull(rechargeDemotioneingRun);
        }else{
            i=2;
        }
        return i;
    }

    @Override
    public int updateRechargeDemotioneingRun(RechargeDemotioneingRun rechargeDemotioneingRun) {
        int i = dao.updateByPrimaryKeySelective(rechargeDemotioneingRun);
        return i;
    }


}
