package me.zhengjie;

import com.alibaba.fastjson.JSONObject;
import me.zhengjie.modules.dmuser.repository.DmUserRepository;
import me.zhengjie.modules.dmuser.service.impl.DmUserServiceImpl;
import me.zhengjie.modules.security.service.UserDetailsServiceImpl;
import me.zhengjie.ykt.domain.DmPlateNumber;
import me.zhengjie.ykt.repository.DmPlateNumberRepository;
import me.zhengjie.ykt.service.DmPlateNumberService;
import me.zhengjie.ykt.service.dto.DmPlateNumberDto;
import me.zhengjie.ykt.service.impl.DmPlateNumberServiceImpl;
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 javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class LoginCacheTest {

    @Resource(name = "userDetailsService")
    private UserDetailsServiceImpl userDetailsService;

    //这里直接使用上面封装的发送消息util类
//    @Autowired
//    private ProducerUtil producer;
    @Resource
    private DmPlateNumberRepository dmPlateNumberRepository;
    @Resource
    private DmPlateNumberServiceImpl dmPlateNumberService;
    @Resource
    private DmUserRepository dmUserRepository;

    @Test
    public void testCache() {
        long start1 = System.currentTimeMillis();
        int size = 10000;
        for (int i = 0; i < size; i++) {
            userDetailsService.loadUserByUsername("admin");
        }
        long end1 = System.currentTimeMillis();
        //关闭缓存
        userDetailsService.setEnableCache(false);
        long start2 = System.currentTimeMillis();
        for (int i = 0; i < size; i++) {
            userDetailsService.loadUserByUsername("admin");
        }
        long end2 = System.currentTimeMillis();
        System.out.print("使用缓存：" + (end1 - start1) + "毫秒\n 不使用缓存：" + (end2 - start2) + "毫秒");
    }



    @Test
    public  void  testPhone(){

         List<DmPlateNumber> dmPlateNumbers = dmPlateNumberRepository.queryDmPlateNumberAll();
        dmPlateNumbers.forEach(item->{
             int i = dmPlateNumberRepository.updateAll(item.getUserNumber().getUserNumber(), item.getUserNumber().getName(), item.getUserNumber().getContacts(), item.getId());
            System.out.println(i);
        });
    }

@Test
    public void testBigDecil(){
    BigDecimal divide = BigDecimal.valueOf(90).divide(BigDecimal.valueOf(84),2, BigDecimal.ROUND_HALF_UP);
    System.out.println(divide);
}
}



