package thyyxxk.webserver.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import thyyxxk.webserver.config.auth.PassToken;
import thyyxxk.webserver.dao.his.PublicDao;
import thyyxxk.webserver.entity.ResultVo;
import thyyxxk.webserver.utils.DateUtil;
import thyyxxk.webserver.utils.ResultVoUtil;

import java.util.Date;

@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {
    private final PublicDao dao;

    public TestController(PublicDao dao) {
        this.dao = dao;
    }

    @GetMapping("/test1")
    @PassToken
    public ResultVo<String> getTest1() throws InterruptedException {
        log.info("test1循环开始:{}", DateUtil.formatDatetime(new Date()));
        for (int j = 0; j < 100; j++) {
            Thread.sleep(100);
        }
        log.info("test1循环结束:{}", DateUtil.formatDatetime(new Date()));
        return ResultVoUtil.success("test1");
    }

    @GetMapping("test2")
    @PassToken
    public ResultVo<String> getTest2() {
        log.info("test2，Dao开始:{}", DateUtil.formatDatetime(new Date()));
        dao.getDept();
        log.info("test2，Dao开始:{}", DateUtil.formatDatetime(new Date()));
        return ResultVoUtil.success("test2");
    }


}

