Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
public class FieldInfo implements Serializable {
@Schema(description = "字段名称")
private String fieldName;
@Schema(description = "数据库字段名称")
private String tableFieldName;
@Schema(description = "是否主键 true是 false否")
private Boolean isPrimary = false;
@Schema(description = "JAVA字段类型")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public List<CodeVo> getCode(ReqCode reqCode) {
Optional<SearchInfo> searchInfo = codeInfo.getSearchList().stream().filter((search) ->
search.getFieldInfo().getFieldName().equals(finalFieldName) && search.getComponent() != null && search.getComponent().size() == 2)
.findFirst();
fieldInfo.setTableFieldName(fieldName);
fieldInfo.setFieldName(StringUtils.toCamelCase(fieldName));
FieldExpand fieldExpand = new FieldExpand().setFieldInfo(fieldInfo);
//设置字典组件列表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.security.KeyStore;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -61,8 +60,8 @@ public static Result<String> get(String url, Map<String, String> headers) throws
* <p>
* 此方法构造一个带有参数的URL并执行GET请求如果参数为空,则执行不带参数的GET请求
*
* @param url 请求的URL
* @param params 请求的参数,格式为键值对
* @param url 请求的URL
* @param params 请求的参数,格式为键值对
* @param headers 请求的头信息,格式为键值对
* @param timeOut 请求的超时时间
* @return 返回请求的结果
Expand Down Expand Up @@ -92,11 +91,11 @@ public static Result<String> get(String url, Map<String, String> headers, TimeOu
return buildResult(okHttpClient, request);
}

public static Result<String> postForm(String url, String params) throws IOException {
public static <T> Result<String> postForm(String url, T params) throws IOException {
return postForm(url, params, null);
}

public static Result<String> postForm(String url, String params, Map<String, String> headers) throws IOException {
public static <T> Result<String> postForm(String url, T params, Map<String, String> headers) throws IOException {
return postForm(url, params, headers, null);
}

Expand All @@ -106,22 +105,22 @@ public static Result<String> postForm(String url, String params, Map<String, Str
* 本方法专注于处理Form类型的POST请求,通过提供的URL、请求参数、自定义请求头和超时设置,
* 来执行网络请求,并返回请求的结果。使用较低级别的HTTP API来实现自定义请求的需求。
*
* @param url 请求的URL,指定了资源的位置
* @param params 请求参数,以字符串形式提交,通常为键值对的形式
* @param url 请求的URL,指定了资源的位置
* @param params 请求参数,以字符串形式提交,通常为键值对的形式
* @param headers 请求头信息,包含HTTP请求头部字段和对应的值,可为空
* @param timeOut 请求的超时设置,决定了请求各阶段的最大等待时间
* @return 返回请求的结果,包括状态码、响应头和响应体等信息
* @throws IOException 如果请求过程中发生I/O错误,如网络中断等
*/
public static Result<String> postForm(String url, String params, Map<String, String> headers, TimeOut timeOut) throws IOException {
public static <T> Result<String> postForm(String url, T params, Map<String, String> headers, TimeOut timeOut) throws IOException {
return post(url, params, headers, timeOut, Form_TYPE);
}

public static Result<String> postJson(String url, String params) throws IOException {
public static <T> Result<String> postJson(String url, T params) throws IOException {
return postJson(url, params, null);
}

public static Result<String> postJson(String url, String params, Map<String, String> headers) throws IOException {
public static <T> Result<String> postJson(String url, T params, Map<String, String> headers) throws IOException {
return postJson(url, params, headers, null);
}

Expand All @@ -130,13 +129,13 @@ public static Result<String> postJson(String url, String params, Map<String, Str
* 此方法用于发送带有JSON数据的HTTP POST请求到指定的URL
* 它允许自定义请求头和超时设置,以满足不同的网络请求需求
*
* @param url 请求的URL地址,指定资源位置
* @param params 请求的JSON参数,以字符串形式表示
* @param url 请求的URL地址,指定资源位置
* @param params 请求的JSON参数,以字符串形式表示
* @param headers 请求头信息,包含请求的附加信息,如认证信息、接受类型等
* @param timeOut 连接和读取超时设置,用于控制网络请求的响应时间
* @return 返回包含响应结果的Result对象,响应体以字符串形式存储
*/
public static Result<String> postJson(String url, String params, Map<String, String> headers, TimeOut timeOut) throws IOException {
public static <T> Result<String> postJson(String url, T params, Map<String, String> headers, TimeOut timeOut) throws IOException {
return post(url, params, headers, timeOut, JSON_TYPE);
}

Expand All @@ -145,17 +144,23 @@ public static Result<String> postJson(String url, String params, Map<String, Str
* 该方法负责发起HTTP POST请求,根据提供的参数构建请求并发送
* 主要用于需要向服务器提交数据的场景
*
* @param url 请求的URL,表示服务器的地址
* @param params 请求的参数,通常为JSON字符串或其他格式的数据
* @param headers 请求头部,包含一些附加信息如认证信息、内容类型等
* @param timeOut 请求的超时时间设置
* @param url 请求的URL,表示服务器的地址
* @param params 请求的参数,通常为JSON字符串或其他格式的数据
* @param headers 请求头部,包含一些附加信息如认证信息、内容类型等
* @param timeOut 请求的超时时间设置
* @param mediaType 请求体的媒体类型,通常指明发送的数据格式(如"application/json")
* @return 返回请求的结果,包含响应的所有信息
* @throws IOException 如果请求过程中发生错误,可能会抛出此异常
*/
public static Result<String> post(String url, String params, Map<String, String> headers, TimeOut timeOut, MediaType mediaType) throws IOException {
public static <T> Result<String> post(String url, T params, Map<String, String> headers, TimeOut timeOut, MediaType mediaType) throws IOException {
log.info("请求url:{},请求入参:{},请求头部:{}", url, params, headers);
RequestBody requestBody = RequestBody.create(params, mediaType);
RequestBody requestBody;
// 判断请求参数类型
if (params instanceof String) {
requestBody = RequestBody.create((String) params, mediaType);
} else {
requestBody = RequestBody.create(JSON.toJSONString(params), mediaType);
}
Request request = buildRequest(url, headers, requestBody, RequestMethod.POST);
OkHttpClient okHttpClient = buildOkHttpClient(url, timeOut);
return buildResult(okHttpClient, request);
Expand Down Expand Up @@ -192,8 +197,8 @@ public static Result<String> upload(String url, File file, Map<String, String> h
/**
* 文件上传接口
*
* @param url 文件上传的URL,指定文件将被上传到的服务器地址
* @param file 待上传的文件,通过File对象指定
* @param url 文件上传的URL,指定文件将被上传到的服务器地址
* @param file 待上传的文件,通过File对象指定
* @param headers 请求头信息,用于设置HTTP请求的头字段
* @param timeOut 超时设置,控制请求的读写超时时间
* @return 返回一个Result对象,包含上传结果和一个字符串消息
Expand All @@ -213,7 +218,7 @@ public static Result<String> upload(String url, File file, Map<String, String> h
* 构建httpClient
* 根据给定的URL和超时设置构建一个OkHttpClient实例,支持HTTPS连接和自定义超时设置
*
* @param url 要请求的URL,用于确定使用HTTP还是HTTPS
* @param url 要请求的URL,用于确定使用HTTP还是HTTPS
* @param timeOut 超时设置,用于设置连接、读取和写入的超时时间
* @return 构建好的OkHttpClient实例
*/
Expand All @@ -234,10 +239,10 @@ private static OkHttpClient buildOkHttpClient(String url, TimeOut timeOut) {
/**
* 构建请求
*
* @param url 请求的URL地址
* @param headers 请求头信息,为键值对形式的Map
* @param url 请求的URL地址
* @param headers 请求头信息,为键值对形式的Map
* @param requestBody 请求体内容,根据不同请求方法包含不同的数据
* @param method 请求方法,包括GET、POST、PUT、PATCH、DELETE等
* @param method 请求方法,包括GET、POST、PUT、PATCH、DELETE等
* @return 返回构建完成的Request对象
*/
private static Request buildRequest(String url, Map<String, String> headers, RequestBody requestBody, RequestMethod method) {
Expand Down Expand Up @@ -277,15 +282,14 @@ private static Request buildRequest(String url, Map<String, String> headers, Req
*/
private static Result<String> buildResult(OkHttpClient okHttpClient, Request request) throws IOException {
try (Response response = okHttpClient.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new MyRuntimeException(MessageFormat.format("错误:OkHttp请求异常。请求:{0} 结果:{1}"
, request.body(), response.body()));
log.info("请求执行完成,响应状态码:{},响应信息:{}", response.code(), response.message());
if (response.body() != null) {
return Result.buildResult(response.body().string(), response.code(), response.message());
}
assert response.body() != null;
return Result.buildResult(response.body().string(), response.code(), response.message());
return Result.buildResult(null, response.code(), response.message());
} catch (IOException e) {
log.error("错误:OkHttp请求异常", e);
throw e;
throw new MyRuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
HttpServletResponse response = (HttpServletResponse) servletResponse;
response.setContentType(ContentType.APPLICATION_JSON.toString());
response.setStatus(HttpStatus.UNAUTHORIZED.value());
response.getWriter().println(result);
response.getWriter().print(result);
}

protected Result<?> isAccessAllowed(ServletRequest request) {
Expand Down