From a336b91765728b8b8fb31791cf02e9e70066e00d Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期二, 30 一月 2024 16:40:22 +0800 Subject: [PATCH] 2024年01月30日16:40:11 --- app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java | 26 ++++++------ app/src/main/java/com/hdl/photovoltaic/other/HdlLogLogic.java | 35 ++++++++--------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java b/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java index 24b8088..d1ddd99 100644 --- a/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java +++ b/app/src/main/java/com/hdl/photovoltaic/internet/HttpClient.java @@ -47,6 +47,8 @@ private static volatile HttpClient sHttpClient; + private static final boolean isAddToMemory=false; + public static synchronized HttpClient getInstance() { if (sHttpClient == null) { synchronized (HttpClient.class) { @@ -70,15 +72,14 @@ */ private Disposable requestPost(String api, String body, CloudCallBeak<String> callBack) { String requestUrl = HDLCloudUserApi.getRequestUrl(api); - Gson gson = new Gson(); - System.out.println("http->鍙戦��->" + requestUrl + "\r\n" + body); + HdlLogLogic.print("http->鍙戦��->" + requestUrl + "\r\n" + body, isAddToMemory); return HxHttp.builder().url(requestUrl).raw(body).build().post().subscribeWith(new HDLResponse<String>() { @Override public void onResponse(String str) { if (callBack != null) { callBack.onSuccess(str); // System.out.println("http->鍥炲->" + requestUrl + "\r\n" + gson.fromJson(str, JsonObject.class).toString()); - System.out.println("http->鍥炲->" + requestUrl + "\r\n" + str); + HdlLogLogic.print("http->鍥炲->" + requestUrl + "\r\n" + str, isAddToMemory); } } @@ -87,7 +88,7 @@ HDLExceptionSubmitUtils.submit(requestUrl, body, e); if (callBack != null) { callBack.onFailure(e); - System.out.println("http->鍥炲->" + requestUrl + "\r\n" + "\"{code=\"" + e.getCode() + "," + "\"message=\"" + e.getMsg() + "}"); + HdlLogLogic.print("http->鍥炲->" + requestUrl + "\r\n" + "\"{code=\"" + e.getCode() + "," + "\"message=\"" + e.getMsg() + "}", isAddToMemory); } } }); @@ -107,15 +108,14 @@ String requestUrl = HDLCloudUserApi.getRequestUrl(api); - Gson gson = new Gson(); - System.out.println("http->鍙戦��->" + requestUrl + "\r\n" + body); + HdlLogLogic.print("http->鍙戦��->" + requestUrl + "\r\n" + body, isAddToMemory); return HxHttp.builder().url(requestUrl).file(body).build().post().subscribeWith(new HDLResponse<String>() { @Override public void onResponse(String str) { if (callBack != null) { callBack.onSuccess(str); // System.out.println("http->鍥炲->" + requestUrl + "\r\n" + gson.fromJson(str, JsonObject.class).toString()); - HdlLogLogic.print("http->鍥炲->" + requestUrl + "\r\n" + str, true); + HdlLogLogic.print("http->鍥炲->" + requestUrl + "\r\n" + str, isAddToMemory); } } @@ -124,7 +124,7 @@ HDLExceptionSubmitUtils.submit(requestUrl, body, e); if (callBack != null) { callBack.onFailure(e); - HdlLogLogic.print("http->鍥炲->" + requestUrl + "\r\n" + "\"{code=\"" + e.getCode() + "," + "\"message=\"" + e.getMsg() + "}", true); + HdlLogLogic.print("http->鍥炲->" + requestUrl + "\r\n" + "\"{code=\"" + e.getCode() + "," + "\"message=\"" + e.getMsg() + "}", isAddToMemory); } } }); @@ -241,7 +241,7 @@ @Override public void run() { try { - HdlLogLogic.print("http->鍙戦��->" + fullUrl + "\r\n" + json, false); + HdlLogLogic.print("http->鍙戦��->" + fullUrl + "\r\n" + json, isAddToMemory); OkHttpClient okHttpClient = new OkHttpClient(); RequestBody requestBody = FormBody.create(MediaType.parse("application/json; charset=utf-8"), getJson(json)); final Request request = new Request.Builder().url(fullUrl)//璇锋眰鐨剈rl @@ -251,7 +251,7 @@ if (response.isSuccessful()) { String s = Objects.requireNonNull(response.body()).string(); HttpResponsePack httpResponsePack = new Gson().fromJson(s, HttpResponsePack.class); - HdlLogLogic.print("http->鍥炲->" + response.request().url() + "\r\n" + s, false); + HdlLogLogic.print("http->鍥炲->" + response.request().url() + "\r\n" + s, isAddToMemory); baseSuccessCallBeak.onSuccess(httpResponsePack); } else { @@ -264,7 +264,7 @@ call.enqueue(new Callback() {//寮傛 @Override public void onFailure(@NonNull Call call, @NonNull IOException e) { - HdlLogLogic.print("http->鍥炲->" + "\r\n" + e.getMessage(), false); + HdlLogLogic.print("http->鍥炲->" + "\r\n" + e.getMessage(), isAddToMemory); } @Override @@ -274,7 +274,7 @@ String s = Objects.requireNonNull(response.body()).string(); HttpResponsePack httpResponsePack = new Gson().fromJson(s, HttpResponsePack.class); baseSuccessCallBeak.onSuccess(httpResponsePack); - HdlLogLogic.print("http->鍥炲->" + "\r\n" + s, false); + HdlLogLogic.print("http->鍥炲->" + "\r\n" + s, isAddToMemory); } else { baseSuccessCallBeak.onFailure(new HDLException(response.code(), response.message())); } @@ -283,7 +283,7 @@ } } catch (Exception e) { baseSuccessCallBeak.onFailure(new HDLException(-100, e.getMessage())); - HdlLogLogic.print("http->鍥炲->" + "\r\n" + e.getMessage(), false); + HdlLogLogic.print("http->鍥炲->" + "\r\n" + e.getMessage(), isAddToMemory); } } diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlLogLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlLogLogic.java index 410f0dd..e6a0a88 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlLogLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlLogLogic.java @@ -17,43 +17,42 @@ /** * java鎵撳嵃 * - * @param content 鑷畾涔変俊鎭弿杩� - * 榛樿涓嶅姞鍏ユ湰鍦版棩蹇� + * @param customizeContentFormat 鑷畾涔夊唴瀹规牸寮� */ - public static void print(String content) { - printBase(content, "0", false); + public static void print(String customizeContentFormat) { + printBase(customizeContentFormat, "0", false); } /** * java鎵撳嵃 * - * @param content 鑷畾涔変俊鎭弿杩� - * @param isBoolean 鏄惁鍔犲叆鍐呭瓨(鏈湴鏃ュ織鐢ㄥ埌) + * @param customizeContentFormat 鑷畾涔夊唴瀹规牸寮� + * @param isAddToMemory 鏄惁鍔犲叆鍐呭瓨(鏈湴鏃ュ織鐢ㄥ埌) */ - public static void print(String content, boolean isBoolean) { - printBase(content, "0", isBoolean); + public static void print(String customizeContentFormat, boolean isAddToMemory) { + printBase(customizeContentFormat, "0", isAddToMemory); } /** * java鎵撳嵃 * - * @param msg 鑷畾涔変俊鎭弿杩� - * @param code 鐘舵�佺爜 - * @param isBoolean 鏄惁鍔犲叆鍐呭瓨(鏈湴鏃ュ織鐢ㄥ埌) + * @param msg 鑷畾涔夊唴瀹规牸寮� + * @param code 鐘舵�佺爜 + * @param isAddToMemory 鏄惁鍔犲叆鍐呭瓨(鏈湴鏃ュ織鐢ㄥ埌) */ - public static void print(String msg, int code, boolean isBoolean) { - printBase(msg, code + "", isBoolean); + public static void print(String msg, int code, boolean isAddToMemory) { + printBase(msg, code + "", isAddToMemory); } /** * java鎵撳嵃鍜屽瓨鍌ㄦ棩蹇� * - * @param msg 淇℃伅鎻忚堪 - * @param code 鐘舵�� - * @param isBoolean 鏄惁鍔犲叆鍐呭瓨(鏈湴鏃ュ織鐢ㄥ埌) + * @param msg 淇℃伅鎻忚堪 + * @param code 鐘舵�� + * @param isAddToMemory 鏄惁鍔犲叆鍐呭瓨(鏈湴鏃ュ織鐢ㄥ埌) */ - private static void printBase(String msg, String code, boolean isBoolean) { + private static void printBase(String msg, String code, boolean isAddToMemory) { if (isPrintLogcat) { return; } @@ -63,7 +62,7 @@ String json = title; json += customLogObject.getJointMessage(); System.out.println(json); - if (isBoolean) { + if (isAddToMemory) { writeLog(customLogObject.getJointMessage()); } } -- Gitblit v1.8.0