19 changed files with 278 additions and 38 deletions
@ -0,0 +1,84 @@ |
|||||||
|
package org.springblade.common.utils; |
||||||
|
|
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springblade.common.constant.CommonConstant; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.io.FileWriter; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.Writer; |
||||||
|
import java.util.Calendar; |
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
/** |
||||||
|
* 根据日志文件生成本地文件 |
||||||
|
*/ |
||||||
|
public class FileLogsUtil { |
||||||
|
private static final Logger log = LoggerFactory.getLogger(FileLogsUtil.class); |
||||||
|
|
||||||
|
|
||||||
|
// 根基传入的String 日志响应内容 保存到本地磁盘,返回本次保存的磁盘路径
|
||||||
|
public static String saveFileLogs(String logs) { |
||||||
|
|
||||||
|
Date date = new Date(); |
||||||
|
// 获取当前系统时间
|
||||||
|
Long startdate = date.getTime(); |
||||||
|
|
||||||
|
String dataString = makeDateString(date); |
||||||
|
|
||||||
|
|
||||||
|
String imgPath = CommonConstant.SYSTEMFILEPATH + "logs/"; |
||||||
|
//根据当前时间 按照 年/月/日 创建一个文件
|
||||||
|
imgPath = imgPath + dataString; |
||||||
|
|
||||||
|
// 判断文件夹是否存在
|
||||||
|
File imgPathFile = new File(imgPath); |
||||||
|
if (!imgPathFile.exists()) { |
||||||
|
imgPathFile.mkdirs(); |
||||||
|
} |
||||||
|
// 按照年-月-日 创建一个字符串
|
||||||
|
String fileName = System.currentTimeMillis() + ".log"; |
||||||
|
|
||||||
|
Writer writer = null; |
||||||
|
try { |
||||||
|
writer = new FileWriter(imgPath + fileName); |
||||||
|
writer.write(logs); |
||||||
|
writer.flush(); |
||||||
|
|
||||||
|
} catch (IOException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} finally { |
||||||
|
if (writer != null) { |
||||||
|
try { |
||||||
|
writer.close(); |
||||||
|
} catch (IOException e) { |
||||||
|
throw new RuntimeException(e); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
Long endDate = new Date().getTime(); |
||||||
|
|
||||||
|
log.info("保存消耗时间:" + (endDate - startdate) + "毫秒"); |
||||||
|
|
||||||
|
return imgPath + fileName; |
||||||
|
} |
||||||
|
|
||||||
|
private static String makeDateString(Date date) { |
||||||
|
|
||||||
|
StringBuilder stringBuffer = new StringBuilder(); |
||||||
|
Calendar calendar = Calendar.getInstance(); |
||||||
|
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(); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,16 @@ |
|||||||
|
package com.logpm.factory.oupai.vo; |
||||||
|
|
||||||
|
import com.logpm.factory.oupai.entity.OpOrderStatusLogEntity; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.EqualsAndHashCode; |
||||||
|
|
||||||
|
@Data |
||||||
|
@EqualsAndHashCode(callSuper = true) |
||||||
|
public class OpOrderStatusLogVO extends OpOrderStatusLogEntity { |
||||||
|
|
||||||
|
/** |
||||||
|
* 响应内容 |
||||||
|
*/ |
||||||
|
private String reponseBody; |
||||||
|
|
||||||
|
} |
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue