From dca36f1f90975a720b6d2eb0f8e258dfabc6739a Mon Sep 17 00:00:00 2001 From: zhaoqiaobo <583671871@qq.com> Date: Tue, 25 Jun 2024 10:01:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(all):=20=E8=A7=A3=E5=86=B3=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1 同一毫秒值上传多个文件,文件被覆盖造成文件丢失 --- .../common/utils/FileLogsUtil.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/blade-biz-common/src/main/java/org/springblade/common/utils/FileLogsUtil.java b/blade-biz-common/src/main/java/org/springblade/common/utils/FileLogsUtil.java index 36511603c..2478cda41 100644 --- a/blade-biz-common/src/main/java/org/springblade/common/utils/FileLogsUtil.java +++ b/blade-biz-common/src/main/java/org/springblade/common/utils/FileLogsUtil.java @@ -1,11 +1,17 @@ package org.springblade.common.utils; +import cn.hutool.core.lang.UUID; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springblade.common.constant.CommonConstant; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Writer; import java.net.HttpURLConnection; import java.net.URL; import java.util.Calendar; @@ -29,16 +35,17 @@ public class FileLogsUtil { String imgPath = CommonConstant.SYSTEMFILEPATH + "logs/"; - //根据当前时间 按照 年/月/日 创建一个文件 + // 根据当前时间 按照 年/月/日 创建一个文件 imgPath = imgPath + dataString; - // 判断文件夹是否存在 + // 判断文件夹是否存在 File imgPathFile = new File(imgPath); if (!imgPathFile.exists()) { imgPathFile.mkdirs(); } // 按照年-月-日 创建一个字符串 - String fileName = System.currentTimeMillis() + ".log"; + // 使用 uuid 作为文件名 确保文件唯一 + String fileName = UUID.randomUUID().toString() + ".log"; Writer writer = null; try { @@ -67,7 +74,7 @@ public class FileLogsUtil { public static String loadFileContent(String urlString) { try { - log.info(">>>> 开始下载 {}",urlString); + log.info(">>>> 开始下载 {}", urlString); URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); @@ -78,7 +85,7 @@ public class FileLogsUtil { content.append(inputLine); } in.close(); - log.info(">>>> 结束下载 {}",urlString); + log.info(">>>> 结束下载 {}", urlString); return content.toString(); } catch (Exception e) { e.printStackTrace(); @@ -90,12 +97,12 @@ public class FileLogsUtil { StringBuilder stringBuffer = new StringBuilder(); Calendar calendar = Calendar.getInstance(); - calendar.setTime(date); //放入Date类型数据 - //获取年份 + calendar.setTime(date); // 放入Date类型数据 + // 获取年份 stringBuffer.append(calendar.get(Calendar.YEAR)).append("/"); - //获取月份 + // 获取月份 stringBuffer.append(calendar.get(Calendar.MONTH) + 1).append("/"); - //获取日份 + // 获取日份 stringBuffer.append(calendar.get(Calendar.DATE)).append("/"); return stringBuffer.toString(); From e0d8fd0261ebe01453bfde27ca550c03050afc45 Mon Sep 17 00:00:00 2001 From: zhaoqiaobo <583671871@qq.com> Date: Tue, 25 Jun 2024 10:02:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat(all):=20=E5=A2=9E=E5=8A=A0=E5=BF=97?= =?UTF-8?q?=E9=82=A6=E6=8E=A5=E6=94=B6=E8=AE=A2=E5=8D=95=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=9A=84=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logpm/factorydata/zbom/feign/FactoryDataZbomClient.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/feign/FactoryDataZbomClient.java b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/feign/FactoryDataZbomClient.java index b621af8f4..4b37814e5 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/feign/FactoryDataZbomClient.java +++ b/blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/feign/FactoryDataZbomClient.java @@ -4,6 +4,7 @@ import cn.hutool.json.JSONUtil; import com.logpm.factorydata.zbom.service.FactoryLogService; import com.logpm.factorydata.zbom.vo.ZBReceiptDTO; import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.api.R; import org.springframework.web.bind.annotation.RestController; @@ -13,12 +14,14 @@ import org.springframework.web.bind.annotation.RestController; */ @RestController @AllArgsConstructor +@Slf4j public class FactoryDataZbomClient implements IFactoryDataZbomClient { private final FactoryLogService factoryLogService; @Override public R order(String data) { + log.info("接收工厂订单:{}", data); factoryLogService.orderData(JSONUtil.toBean(data, ZBReceiptDTO.class)); return R.success("成功"); }