package com.shkj;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Sets;
import com.shkj.common.utils.StringUtils;
import com.shkj.plc.sdk.device.PLCReadAndWrite;
import com.shkj.wms.domain.SysStockDetail;
import com.shkj.wms.service.IBusinOutInPlanService;
import com.shkj.wms.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
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.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static com.shkj.common.constant.Constants.UTF8;
import static java.util.concurrent.Executors.newScheduledThreadPool;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = ShkjApplication.class)
@Slf4j
public class test {


    @Autowired
    IBusinOutInPlanService iBusinOutInPlanService;

    @Autowired
    PLCReadAndWrite plcReadAndWrite;

    ScheduledExecutorService executor = newScheduledThreadPool(4);

    @Test
    public  void test() {
        iBusinOutInPlanService.getOrderNoByContainerCode("10000171", "in");
    }




    @Test
    public  void test2(){

        executor.scheduleWithFixedDelay(new Runnable() {

            public void run() {
                System.out.println("====");
              /*  try {
                    int i = 1 / 0;
                } catch (Exception e) {
                    e.printStackTrace();
                }*/

				try {
					Thread.sleep(10000);
					System.out.println("执行完毕");
				} catch (InterruptedException e) {
					e.printStackTrace();
				}

            }
        }, 1000, 3000, TimeUnit.MILLISECONDS);
    }


    @Test
    public  void test3(){
        executor.scheduleAtFixedRate(new Runnable() {

            public void run() {
                System.out.println("====");
                try {
                    Thread.sleep(10000);//此地方可以试下把try catch去掉，任务就会停掉
                    System.out.println("执行完毕");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, 1000, 3000, TimeUnit.MILLISECONDS);
    }
}
