fix: 修改自动采集图片损坏的问题

This commit is contained in:
xiaoyan 2023-01-09 14:39:51 +08:00
parent 8c81509ccb
commit b1a89e1f05
2 changed files with 99 additions and 66 deletions

View File

@ -12,8 +12,8 @@ android {
applicationId "com.navinfo.outdoor"
minSdkVersion 23
targetSdkVersion 30
versionCode 40
versionName "8.221219"
versionCode 41
versionName "8.230109"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {

View File

@ -154,12 +154,14 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TimeZone;
import java.util.Timer;
import java.util.TimerTask;
@ -1309,83 +1311,113 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
/**
* 结束采集对照片归档
* */
private boolean hasFinishTask = false; // 当前是否包含已完成任务未处理完
private int finishTaskCount = 0;
private boolean wantBack = false; // 用户是否想要退出当前界面如果当前有正在处理的图片转移任务会阻挡用户退出此时该值状态置为true当照片处理完后可以对话框提示用户退出
private void finishRoadTask(Map<Integer, RoadMatchEntity> finishEntityMap) {
hasFinishTask = true;
Observable.fromIterable(finishEntityMap.values())
.subscribeOn(Schedulers.io()).observeOn(Schedulers.computation())
.filter(roadMatchEntity -> roadMatchEntity!=null)
.map(roadMatchEntity -> {
// 判断是否已领取未领取则调用领取数据接口
PoiEntity poiEntity = poiDao.getTaskIdPoiEntity(roadMatchEntity.getId());
if (poiEntity == null) {
// 数据库中不存在尝试再次领取
InsertAndUpdateUtils.getInstance().insertOrUpdate(AutoTakePictureActivity.this, translateRoadMatchEntity(roadMatchEntity));
// 调用网络领取任务
receiverRoadTask(roadMatchEntity).subscribe(receiveObserver);
}
if (finishEntityMap!=null&&!finishEntityMap.isEmpty()) {
finishTaskCount++;
List<LocationRecorder> recorderList = recorderDao.getLocationRecorderByTime(roadMatchEntity.getStartMatchTime(), roadMatchEntity.getEndMathchTime());
File recorderFolder = new File(Constant.PICTURE_FOLDER+"/"+poiEntity.getId());
if (!recorderFolder.exists()) {
recorderFolder.mkdirs();
}
// 编辑paper.txt
// 复制图片文件
File paperFile = new File(recorderFolder.getAbsolutePath(), "paper.txt");
for (int i = 0; i < recorderList.size(); i++) {
File originImg = new File(recorderList.get(i).getImgFileName());
File destFile = new File(recorderFolder.getAbsolutePath()+"/"+i+".jpg");
if (!destFile.exists()) {
FileUtils.copyFile(originImg.getAbsolutePath(), destFile.getAbsolutePath());
Observable.fromIterable(finishEntityMap.values())
.subscribeOn(Schedulers.io()).observeOn(Schedulers.computation())
.filter(roadMatchEntity -> roadMatchEntity!=null)
.map(roadMatchEntity -> {
// 判断是否已领取未领取则调用领取数据接口
PoiEntity poiEntity = poiDao.getTaskIdPoiEntity(roadMatchEntity.getId());
if (poiEntity == null) {
// 数据库中不存在尝试再次领取
InsertAndUpdateUtils.getInstance().insertOrUpdate(AutoTakePictureActivity.this, translateRoadMatchEntity(roadMatchEntity));
// 调用网络领取任务
receiverRoadTask(roadMatchEntity).subscribe(receiveObserver);
}
FileUtils.writeFile(paperFile.getAbsolutePath(), recorderList.get(i).toString(picFormatter ,i), true);
}
return poiEntity;
})
.doOnNext(poiEntity -> {
// 网络提交数据
if (poiEntity!=null) {
// 提交数据更新状态
roadSaveWork(poiEntity);
List<LocationRecorder> recorderList = recorderDao.getLocationRecorderByTime(roadMatchEntity.getStartMatchTime(), roadMatchEntity.getEndMathchTime());
File recorderFolder = new File(Constant.PICTURE_FOLDER+"/"+poiEntity.getId());
if (!recorderFolder.exists()) {
recorderFolder.mkdirs();
}
// 编辑paper.txt
// 复制图片文件
File paperFile = new File(recorderFolder.getAbsolutePath(), "paper.txt");
for (int i = 0; i < recorderList.size(); i++) {
File originImg = new File(recorderList.get(i).getImgFileName());
File destFile = new File(recorderFolder.getAbsolutePath()+"/"+i+".jpg");
if (!destFile.exists()) {
FileUtils.copyFile(originImg.getAbsolutePath(), destFile.getAbsolutePath());
}
FileUtils.writeFile(paperFile.getAbsolutePath(), recorderList.get(i).toString(picFormatter ,i), true);
}
return poiEntity;
})
.doOnNext(poiEntity -> {
// 网络提交数据
if (poiEntity!=null) {
// 提交数据更新状态
roadSaveWork(poiEntity);
/*poiEntity.setTaskStatus(3);
InsertAndUpdateUtils.getInstance().insertOrUpdate(AutoTakePictureActivity.this, poiEntity);*/
}
})
.observeOn(AndroidSchedulers.mainThread())
.onErrorResumeNext(new Function<Throwable, ObservableSource<? extends PoiEntity>>() {
@Override
public ObservableSource<? extends PoiEntity> apply(Throwable throwable) throws Exception {
return null;
}
})
.subscribe(new Consumer<PoiEntity>() {
@Override
public void accept(PoiEntity poiEntity) {
finishEntityMap.remove(poiEntity.getTaskId());
}
})
.observeOn(AndroidSchedulers.mainThread())
.onErrorResumeNext(Observable.empty())
.subscribe(new Consumer<PoiEntity>() {
@Override
public void accept(PoiEntity poiEntity) {
// // 已经处理过该任务将其从finish列表中移除
// if (poiEntity!=null) {
// finishEntityMap.remove(poiEntity.getTaskId());
// }
}
}, new Consumer<Throwable>() {
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) {
// 此处异常可能是服务返回的数据无法解析但http正常返回了因此可能为程序问题不再重复尝试上报
systemTTS.playText("注意,领取任务失败!");
XLog.e("完成失败:"+throwable.getMessage());
ToastUtils.Message(AutoTakePictureActivity.this, throwable.getMessage());
finishTaskCount--;
if (finishTaskCount == 0) {
showExitDialog(true);
}
}
}, new Action() {
@Override
public void run() throws Exception {
// 重新绘制网络任务和本地任务
initRoadLine2Map();
finishTaskCount--;
if (finishTaskCount == 0) {
showExitDialog(false);
}
}
});
}
}
private void showExitDialog(boolean hasError) {
StringBuilder dialogMessage = new StringBuilder("任务数据处理完成,是否退出当前界面");
if (hasError) {
dialogMessage.append("(注意,其中有部分任务处理失败)");
}
MessageDialog.show(AutoTakePictureActivity.this, "退出当前界面", dialogMessage)
.setOkButton("确定", new OnDialogButtonClickListener() {
@Override
public void accept(Throwable throwable) {
// 此处异常可能是服务返回的数据无法解析但http正常返回了因此可能为程序问题不再重复尝试上报
systemTTS.playText("注意,领取任务失败!");
XLog.e("完成失败:"+throwable.getMessage());
ToastUtils.Message(AutoTakePictureActivity.this, throwable.getMessage());
hasFinishTask = false;
public boolean onClick(BaseDialog baseDialog, View v) {
AutoTakePictureActivity.this.finish();
return false;
}
}, new Action() {
})
.setCancelButton("取消", new OnDialogButtonClickListener() {
@Override
public void run() throws Exception {
// 重新绘制网络任务和本地任务
initRoadLine2Map();
// finishEntityMap.clear();
hasFinishTask = false;
public boolean onClick(BaseDialog baseDialog, View v) {
baseDialog.doDismiss();
wantBack = false;
return false;
}
});
})
.show();
}
private void roadSaveWork(PoiEntity poiEntity) throws IOException {
@ -1692,8 +1724,9 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
@Override
public void onBackPressed() {
DialogSettings.style = DialogSettings.STYLE.STYLE_IOS;
if (hasFinishTask) {
if (finishTaskCount>0) {
MessageDialog.show(this, "提示", "后台正在处理已拍摄完成的任务,请稍后再退出当前界面");
wantBack = true;
return;
}
MessageDialog.show(this, "提示", "退出自动采集模式?", "", "").setOnOkButtonClickListener(new OnDialogButtonClickListener() {