package init;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kiisoo.ic.app.IcApplication;
import com.kiisoo.ic.common.utils.RedisUtil;
import com.kiisoo.ic.customer.entity.OpCustomer;
import com.kiisoo.ic.customer.entity.OpSellerCustomerRelation;
import com.kiisoo.ic.customer.mapper.OpCustomerDOMapper;
import com.kiisoo.ic.customer.mapper.OpSellerCustomerRelationDOMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = IcApplication.class)
public class RedisKeyInit {

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private OpCustomerDOMapper opCustomerDOMapper;

    @Autowired
    private OpSellerCustomerRelationDOMapper opSellerCustomerRelationDOMapper;

    @Test
    public void initKey(){
        System.out.println("写入redis OpCustomer 判断是否有这个客户 start");
        List<OpCustomer> list = opCustomerDOMapper.selectCustomerListAll();
        redisUtil.batchAddExternalUserIdKey(list);
//        for (OpCustomer item : list) {
//            redisUtil.setCustomerId(item.getCpUserId(), item.getId());
//        }
        System.out.println("写入redis OpCustomer 判断是否有这个客户 end");
    }

    @Test
    public void initKey2(){
        System.out.println("写入redis OpSellerCustomerRelation start");
        List<OpSellerCustomerRelation> list = opSellerCustomerRelationDOMapper.selectList(null);
        redisUtil.batchAddVailKey2(list);
//        for (int i = 0; i < list.size(); i++) {
//            OpSellerCustomerRelation item = list.get(i);
//            redisUtil.setCustomerId(item.getId() , item.getUserId(), item.getStoreId(), item.getId());
//        }
        System.out.println("写入redis OpSellerCustomerRelation end");
    }

    @Test
    public void initKey3(){
        System.out.println("写入redis OpSellerCustomerRelation 判断是否有效 start");
        OpSellerCustomerRelation entity = new OpSellerCustomerRelation();
        entity.setType(1);
        List<OpSellerCustomerRelation> list = opSellerCustomerRelationDOMapper.selectList(new QueryWrapper<>(entity));
        redisUtil.batchAddVailKey(list);
//        for (int i = 0; i < list.size(); i++) {
//            OpSellerCustomerRelation item = list.get(i);
//            redisUtil.addVailKey(item.getId());
//        }
        System.out.println("写入redis OpSellerCustomerRelation 判断是否有效 end");
    }
}
