添加后台模拟请求接口
This commit is contained in:
parent
5b04427505
commit
1f0297cafb
2
pom.xml
2
pom.xml
|
@ -9,7 +9,7 @@
|
|||
<relativePath/>
|
||||
</parent>
|
||||
<groupId>com.fc</groupId>
|
||||
<artifactId>v2</artifactId>
|
||||
<artifactId>goview_v2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>goview_v2</name>
|
||||
<packaging>war</packaging>
|
||||
|
|
|
@ -18,5 +18,15 @@ public class ApiController {
|
|||
return map;
|
||||
|
||||
}
|
||||
@GetMapping("/test2")
|
||||
public Object test2(String str) {
|
||||
System.out.println(str);
|
||||
Map<String, String> map=new HashMap<String, String>();
|
||||
map.put("a", "1");
|
||||
map.put("b", "2");
|
||||
map.put("c", "3");
|
||||
return map;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@ public class GoViewController {
|
|||
Map<String, Object> map=new HashMap<String, Object>();
|
||||
map.put("token",StpUtil.getTokenInfo());
|
||||
map.put("userinfo", SaTokenUtil.getUser());
|
||||
|
||||
return AjaxResult.success().put("data",map);
|
||||
} else {
|
||||
return AjaxResult.error(500, "未知账户");
|
||||
|
@ -165,6 +166,7 @@ public class GoViewController {
|
|||
buffer.append(""+request.getContextPath());
|
||||
}
|
||||
buffer.append("/oss/object/"+template.getOssProperties().getBucketName());
|
||||
|
||||
ossinfo.put("bucketURL",buffer.toString());
|
||||
ossinfo.put("BucketName",template.getOssProperties().getBucketName());
|
||||
return AjaxResult.successData(200, ossinfo).put("msg", "返回成功");
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.fc.v2.model.auto.GoviewProject;
|
|||
import com.fc.v2.model.auto.GoviewProjectData;
|
||||
import com.fc.v2.model.auto.GoviewProjectDataExample;
|
||||
import com.fc.v2.model.custom.GoviewProjectVo;
|
||||
import com.fc.v2.model.custom.MagicHttp;
|
||||
import com.fc.v2.model.custom.Tablepar;
|
||||
import com.fc.v2.service.GoviewProjectDataService;
|
||||
import com.fc.v2.service.GoviewProjectService;
|
||||
|
@ -15,7 +16,16 @@ import com.github.pagehelper.PageInfo;
|
|||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
|
@ -31,7 +41,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
@Controller
|
||||
@RequestMapping("/api/goview/project")
|
||||
public class GoviewProjectAPi extends BaseController{
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(GoviewProjectAPi.class);
|
||||
|
||||
@Autowired
|
||||
private GoviewProjectService goviewProjectService;
|
||||
|
@ -199,8 +209,48 @@ public class GoviewProjectAPi extends BaseController{
|
|||
}
|
||||
return AjaxResult.error("获取保存失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 模拟请求
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "模拟请求", notes = "模拟请求")
|
||||
@PostMapping("/magicHttp")
|
||||
@ResponseBody
|
||||
public AjaxResult magicHttp(@RequestBody MagicHttp magicHttp){
|
||||
if(magicHttp!=null){
|
||||
logger.info("后台接收前端模拟提交数据:"+JSONUtil.toJsonStr(magicHttp));
|
||||
if(magicHttp.getRequestType().toUpperCase().equals("GET")){
|
||||
HttpRequest httpRequest=HttpUtil.createGet(magicHttp.getUrl());
|
||||
if(magicHttp.getHead()!=null&&magicHttp.getHead().size()>0){
|
||||
httpRequest.addHeaders(magicHttp.getHead());
|
||||
}
|
||||
if(StrUtil.isNotBlank(magicHttp.getCookie())){
|
||||
httpRequest.cookie(magicHttp.getCookie());
|
||||
}
|
||||
httpRequest.timeout(magicHttp.getTimeout());
|
||||
String body= httpRequest.setFollowRedirects(true).execute().body();
|
||||
return AjaxResult.successData(200,body);
|
||||
}
|
||||
if(magicHttp.getRequestType().toUpperCase().equals("POST")){
|
||||
|
||||
|
||||
HttpRequest httpRequest=HttpUtil.createPost(magicHttp.getUrl());
|
||||
if(magicHttp.getHead()!=null&&magicHttp.getHead().size()>0){
|
||||
httpRequest.addHeaders(magicHttp.getHead());
|
||||
}
|
||||
if(StrUtil.isNotBlank(magicHttp.getCookie())){
|
||||
httpRequest.cookie(magicHttp.getCookie());
|
||||
}
|
||||
httpRequest.timeout(magicHttp.getTimeout());
|
||||
if(magicHttp.getForm()!=null&&magicHttp.getForm().size()>0){
|
||||
httpRequest.form(magicHttp.getForm());
|
||||
}
|
||||
String body=httpRequest.setFollowRedirects(true).execute().body();
|
||||
return AjaxResult.successData(200,body);
|
||||
}
|
||||
}
|
||||
return AjaxResult.error();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
package com.fc.v2.model.custom;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
public class MagicHttp {
|
||||
/**
|
||||
* 请求url
|
||||
*/
|
||||
@ApiModelProperty(value = "请求url")
|
||||
private String url;
|
||||
/**
|
||||
* 请求类型 get post
|
||||
*/
|
||||
@ApiModelProperty(value = "请求类型 get or post")
|
||||
private String requestType;
|
||||
|
||||
@ApiModelProperty(value = "head参数")
|
||||
private Map<String, String> head;
|
||||
|
||||
@ApiModelProperty(value = "body 内容")
|
||||
private String body;
|
||||
|
||||
@ApiModelProperty(value = "超时时间为0 不超时")
|
||||
private Integer timeout;
|
||||
|
||||
@ApiModelProperty(value = "form表单")
|
||||
private Map<String, Object> form;
|
||||
|
||||
@ApiModelProperty(value = "cookie")
|
||||
private String cookie;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getRequestType() {
|
||||
return requestType;
|
||||
}
|
||||
|
||||
public void setRequestType(String requestType) {
|
||||
this.requestType = requestType;
|
||||
}
|
||||
|
||||
public Map<String, String> getHead() {
|
||||
return head;
|
||||
}
|
||||
|
||||
public void setHead(Map<String, String> head) {
|
||||
this.head = head;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public String getCookie() {
|
||||
return cookie;
|
||||
}
|
||||
|
||||
public void setCookie(String cookie) {
|
||||
this.cookie = cookie;
|
||||
}
|
||||
|
||||
public Integer getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(Integer timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public Map<String, Object> getForm() {
|
||||
return form;
|
||||
}
|
||||
|
||||
public void setForm(Map<String, Object> form) {
|
||||
this.form = form;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.fc.v2.satoken;
|
||||
|
||||
import com.fc.v2.model.auto.TsysUser;
|
||||
import com.fc.v2.util.BeanUtils;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
|
||||
|
@ -15,7 +16,13 @@ public class SaTokenUtil {
|
|||
* 获取登录用户model
|
||||
*/
|
||||
public static TsysUser getUser() {
|
||||
return (TsysUser)StpUtil.getSession().get("user");
|
||||
Object object=StpUtil.getSession().get("user");
|
||||
if(object!=null){
|
||||
TsysUser tsysUser=new TsysUser();
|
||||
BeanUtils.copyBeanProp(tsysUser, object);
|
||||
return tsysUser;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue