package com.malk.ruisi.controller;

import com.alibaba.fastjson.JSONObject;
import com.malk.ruisi.service.QysApiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/***
 * 测试契约锁
 */
@RestController
@Slf4j
@RequestMapping("/qys/")
public class QysApiTestController {
    @Autowired
    private QysApiService qysApiService;

    @PostMapping("test")
    public JSONObject testJSon(@RequestBody() JSONObject param){
        log.info("JSON格式请求参数：{}",param);
        try {
            Map data=(Map) param.get("data");
            String url=String.valueOf(param.get("url"));
            boolean isPost=(Boolean) param.get("isPost");
            if(isPost){
                return qysApiService.sendPost(data,url);
            }else {
                return qysApiService.sendGet(data,url,false);
            }
        } catch (Exception apiException) {
            return new JSONObject().fluentPut("msg","失败");
        }
    }
}
