package com.ssm.manage.service.impl;

import com.ssm.core.service.impl.BaseServiceImpl;
import com.ssm.core.utils.SnowflakeUtil;
import com.ssm.manage.dao.BaseDao;
import com.ssm.manage.dao.SsmRechargeTypeStoreDao;
import com.ssm.manage.entity.PromotionStore;
import com.ssm.manage.entity.RechargeType;
import com.ssm.manage.entity.RechargeTypeStore;
import com.ssm.manage.service.SsmRechargeTypeStoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Service
@Slf4j
public class SsmRechargeTypeStoreImp extends BaseServiceImpl<RechargeTypeStore> implements SsmRechargeTypeStoreService {
     @Autowired
     SsmRechargeTypeStoreDao dao;

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


    /*@Override
    public int insert(List<RechargeTypeStore> rechargeTypeStoreList) {
        int i=0;
        for(RechargeTypeStore rechargeTypeStore:rechargeTypeStoreList){
            i=dao.insert(rechargeTypeStore);
        }
        return i;
    }*/

    @Override
    public int insert(List<PromotionStore> promotionStoreList,RechargeType recharge) {
        int i=0;
        for(PromotionStore promotionStore:promotionStoreList){
            RechargeTypeStore rechargeTypeStore=new RechargeTypeStore();
            rechargeTypeStore.setId(new SnowflakeUtil(new Random().nextInt(1023)).nextId());
            rechargeTypeStore.setStoreId(promotionStore.getStoreId());
            rechargeTypeStore.setStoreName(promotionStore.getStoreName());
            rechargeTypeStore.setRechargeNum(promotionStore.getStoreNum());
            rechargeTypeStore.setRechargeId(recharge.getId());
            rechargeTypeStore.setRechargeName(recharge.getRechargeTypeName());
            rechargeTypeStore.setRechargeNum(recharge.getRechargeTypeNum());
            i=dao.insert(rechargeTypeStore);
        }
        return i;
    }

    @Override
    public List<RechargeTypeStore> selectStore(RechargeType rechargeType) {
        Example example = new Example(RechargeTypeStore.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("rechargeNum",rechargeType.getRechargeTypeNum());
        criteria.andEqualTo("rechargeId",rechargeType.getId());
        List<RechargeTypeStore> list=dao.selectByExample(example);
        return list;
    }
}
