package demo.helloprovider;
import demo.hellocommon.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

@RestController
public class HelloProviderController {

    @GetMapping(value = "/user/greet/{username}")
    public String greet(@PathVariable String username) {
        try{
            //TimeUnit.SECONDS.sleep(60);   //睡眠60秒
        }catch(Exception e){e.printStackTrace();}

        if(username!=null && username.equals("Monster"))
            throw new IllegalArgumentException(username);
        return "Hello," + username;
    }

    @GetMapping(value = "/user/testname")
    public Result testName(@SpringQueryMap Name name) {
        System.out.println("firstname:"+name.getFirstname()
                           +",lastname:"+name.getLastname());

        return new Result(100,"OK");
    }

    @PostMapping(value = "/user/testuser")
    public Result testUser(@RequestBody User user) {
        System.out.println("id:"+user.getId()
                +",name:"+user.getName().getFirstname()
                +" "+user.getName().getLastname());

        return new Result(100,"OK");
    }

}


/*********************************************************
 * 作者：孙卫琴                                   
 * 来源：《Spring Cloud Alibaba微服务开发零基础入门到实战》源代码  
 * 技术支持网址：www.javathinker.net/alibaba                    
 *********************************************************/
