package com.qs.mp.service;

import com.qs.mp.MpApplication;
import com.qs.mp.admin.service.ITicketBoxSerialService;
import com.qs.mp.common.utils.DateUtils;
import com.qs.mp.framework.service.IWxUrlLinkService;
import com.qs.mp.quartz.task.DayStatTask;
import com.qs.mp.quartz.task.TicketBoxTask;
import com.qs.mp.quartz.task.TicketPkgDataTask;
import java.io.IOException;
import java.util.Date;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;

/**
 * @author zhongcp
 * @Date 2021/8/31
 */
@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = MpApplication.class)
@TestPropertySource(locations = "classpath:application-dev.yml")
@ActiveProfiles("dev")
public class ServiceImplTest {

  protected final Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());

  @Autowired
  private IWxUrlLinkService wxUrlLinkService;

  @Autowired
  private ITicketBoxSerialService ticketBoxSerialService;

  @Autowired
  private TicketBoxTask ticketBoxTask;

  @Autowired
  private DayStatTask dayStatTask;

  @Autowired
  private TicketPkgDataTask ticketPkgDataTask;

  @Test
  public void testGenerateQrCode() {
    System.out.println(wxUrlLinkService.generateCode("pages/index/index", "id=1", "wxc3a684f1196f6e15"));

  }

  @Test
  public void testGenerateUnlimitCode() {
    System.out.println(wxUrlLinkService.generateUnlimitCode("pages/ticketBox/detail", "boxId=1&suid=2&type=user", "wx8533800e393dbd6b"));

  }

  @Test
  public void testGenerateShortUrl() {
    System.out.println(wxUrlLinkService.generate("", "", "wxc3a684f1196f6e15"));

  }

  @Test
  public void testGenerateUrlSchema() {
    System.out.println(wxUrlLinkService.generateUrlSchema("/pages/login/invitation", "", "wxc3a684f1196f6e15"));

  }

  @Test
  public void testGenerateSerial() {
    System.out.println(ticketBoxSerialService.generateSerial(null));

  }


  @Test
  public void testCheckTicketBox() {
    ticketBoxTask.checkPrize("954112676047486977");

  }

  @Test
  public void testDayStat() {
    dayStatTask.stat(null);
  }

  @Test
  public void testPkgDataRefresh() {
    ticketPkgDataTask.refresh();
  }




  public static void main(String[] args) {
    /*int n = 500;
    Random rand = new Random();
    boolean[] bool = new boolean[n];
    int randInt = 0;
    for(int i = 0; i < 50 ; i++) {
      do {
        randInt = rand.nextInt(n);
      }while(bool[randInt]);
      bool[randInt] = true;
      System.out.println(randInt);
    }
  */
    /*String s = "z";

    int i = Character.codePointAt(s, 0);

    System.out.println(i + "");

    char[] a = Character.toChars(72);

    System.out.println(new String(a));*/
    System.out.println(DateUtils.dateTime());
    System.out.println(new Date().getTime());
  }

  }
