Commit 7eb29a76 by pye52

修复日志上报的问题

1、服务器下发的时间格式将解析到秒
2、日志临时目录创建到external storage中
parent 3adb7c35
......@@ -8,7 +8,6 @@ import com.bgycc.smartcanteen.entity.CommandResponse;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.PathUtils;
import com.blankj.utilcode.util.Utils;
import com.blankj.utilcode.util.ZipUtils;
import com.google.gson.Gson;
......@@ -37,11 +36,12 @@ import static com.bgycc.smartcanteen.utils.SmartCanteenUtils.TAG;
public class LogCommandHandler extends CommandHandler {
private static final String BOOT_LOG = "system";
private static final String ZIP_FILE = "log.zip";
private static final String UPLOAD_DIR = File.separator + "upload_log";
private static final String UPLOAD_DIR = "upload_log";
private static final long DEFAULT_DELAY = 1000;
private volatile boolean start = false;
private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
private SimpleDateFormat parseFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
private SimpleDateFormat nameFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
private String deviceSN;
private CommandLog commandLog;
......@@ -83,12 +83,12 @@ public class LogCommandHandler extends CommandHandler {
startTime = null;
endTime = null;
try {
startTime = format.parse(data.getStartTime());
startTime = parseFormat.parse(data.getStartTime());
} catch (ParseException e) {
LogUtils.w(TAG, "日志上传,起始时间解析失败: " + data.toString(), e);
}
try {
endTime = format.parse(data.getEndTime());
endTime = parseFormat.parse(data.getEndTime());
} catch (ParseException e) {
LogUtils.w(TAG, "日志上传,结束时间解析失败: " + data.toString(), e);
}
......@@ -117,7 +117,7 @@ public class LogCommandHandler extends CommandHandler {
}
Thread.sleep(DEFAULT_DELAY);
File zip = new File(Utils.getApp().getCacheDir() + File.separator + ZIP_FILE);
File zip = new File(PathUtils.getExternalStoragePath() + File.separator + ZIP_FILE);
try {
wait("开始压缩", 40);
ZipUtils.zipFile(uploadDir, zip);
......@@ -143,7 +143,7 @@ public class LogCommandHandler extends CommandHandler {
}
private File tempDirInit() {
File dir = new File(Utils.getApp().getCacheDir() + UPLOAD_DIR);
File dir = new File(PathUtils.getExternalStoragePath() + File.separator + UPLOAD_DIR);
if (dir.exists()) {
// 清空临时文件夹
FileUtils.delete(dir);
......@@ -183,8 +183,8 @@ public class LogCommandHandler extends CommandHandler {
SCApi api = SCRetrofit.createApi(client);
CommandLog.CommandLogData data = commandLog.getData();
String fileNameForServer = data.getLogType()
+ format.format(startTime)
+ format.format(endTime)
+ nameFormat.format(startTime)
+ nameFormat.format(endTime)
+ deviceSN + ".zip";
fileNameForServer = fileNameForServer.replace(" ", "_");
LogUtils.d(TAG, "开始上传日志: " + fileNameForServer);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment