fix: 修改某些情况下照片损坏的问题,修改线任务照片不存在时阻止用户上传

This commit is contained in:
xiaoyan 2023-03-28 10:57:38 +08:00
parent a66647d735
commit 61c1c53696
3 changed files with 95 additions and 84 deletions

View File

@ -174,6 +174,7 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
import io.reactivex.BackpressureStrategy;
import io.reactivex.Emitter;
import io.reactivex.Flowable;
import io.reactivex.FlowableEmitter;
import io.reactivex.FlowableOnSubscribe;
@ -241,6 +242,9 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
private Logger logger;
private ImageView imgLocationType;
private PicturesSpeedCheck speedCheck;
// 任务结束对应的控制对象
private Disposable finishDisposable;
private Emitter<RoadMatchEntity> finishEmitter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -638,6 +642,82 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
// 清空缓存数据
spf.edit().remove("match-data");
spf.edit().commit();
// 启动数据完成的Rx流当有数据需要完成时会在捕捉流程中由上游发送数据
finishDisposable = Observable.create(new ObservableOnSubscribe<RoadMatchEntity>() {
@Override
public void subscribe(ObservableEmitter<RoadMatchEntity> emitter) throws Exception {
finishEmitter =emitter;
}
})
.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);
}
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);
}
})
.observeOn(AndroidSchedulers.mainThread())
.onErrorResumeNext(Observable.empty())
.subscribe(new Consumer<PoiEntity>() {
@Override
public void accept(PoiEntity poiEntity) {
// 重新绘制网络任务和本地任务
initRoadLine2Map();
finishTaskCount--;
if (finishTaskCount == 0&&wantBack) {
showExitDialog(false);
}
}
}, 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&&wantBack) {
showExitDialog(true);
}
}
}, new Action() {
@Override
public void run() throws Exception {
}
});
}
/**
@ -1333,84 +1413,12 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
private boolean wantBack = false; // 用户是否想要退出当前界面如果当前有正在处理的图片转移任务会阻挡用户退出此时该值状态置为true当照片处理完后可以对话框提示用户退出
private void finishRoadTask(Map<Integer, RoadMatchEntity> finishEntityMap) {
if (finishEntityMap!=null&&!finishEntityMap.isEmpty()) {
finishTaskCount++;
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);
}
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);*/
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>() {
@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);
}
}
});
for (Map.Entry<Integer, RoadMatchEntity> entry: finishEntityMap.entrySet()) {
if (finishEmitter!=null) {
finishTaskCount++;
finishEmitter.onNext(entry.getValue());
}
}
}
}
@ -1741,6 +1749,9 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
// 退出后切换主定位模式为腾讯定位
LocationLifeCycle.getInstance().setMainLocationFrom(LocationLifeCycle.LOCATION_FROM.TENCENT);
LocationLifeCycle.getInstance().stopGPSLocation();
if (finishDisposable!=null&&!finishDisposable.isDisposed()) {
finishDisposable.dispose();
}
}
@Override

View File

@ -2,9 +2,9 @@ package com.navinfo.outdoor.http;
public class HttpInterface {
// public static final String IP = "http://172.23.138.133:9999/m4";//测试接口-IP
public static final String IP0 = "http://dtxbmaps.navinfo.com/dtxb/dev/m4";//开发接口-外网
public static final String IP = "http://dtxbmaps.navinfo.com/dtxb/dev/m4";//开发接口-外网
public static final String IP1 = "http://dtxbmaps.navinfo.com/dtxb/test/m4";//测试接口-外网
public static final String IP = "http://dtxbmaps.navinfo.com/dtxb/m4";//正式接口
public static final String IP2 = "http://dtxbmaps.navinfo.com/dtxb/m4";//正式接口
public static final String USER_PATH = "/user/";//我的
public static final String MSG_LIST_PATH = "/msgList/";//发现
public static final String USER_LOGIN_PATH = "/userlogin/";//登录

View File

@ -174,7 +174,7 @@ public class PoiSaveUtils {
@Override
public ObservableSource<?> apply(PoiEntity poiEntity) throws Exception {
List<File> photoFileList = AWMp4ParserHelper.getInstance().getFileListByUUID(poiEntity.getId());
if (photoFileList == null||photoFileList.isEmpty()) {
if (photoFileList == null||photoFileList.size()<2/*如果文件压缩包内小于2个文件说明拍摄的照片丢失了*/) {
bInt++;
return Observable.empty();
}
@ -431,7 +431,7 @@ public class PoiSaveUtils {
initList(HttpInterface.C_TASK_UP_LOAD_PIC, photoFile, poiEntity);
} else if (poiEntity.getType() == 3) {
List<File> videoFileList = AWMp4ParserHelper.getInstance().getFileListByUUID(poiEntity.getId());
if (videoFileList != null && !videoFileList.isEmpty()) {
if (videoFileList != null && videoFileList.size()<2) {
boolean existsPic = PoiSaveUtils.getInstance(mContext).checkPicExists(videoFileList);
if (!existsPic) {
bInt++;
@ -475,7 +475,7 @@ public class PoiSaveUtils {
// }
} else if (poiEntity.getType() == 4) {
List<File> videoFileList = AWMp4ParserHelper.getInstance().getFileListByUUID(poiEntity.getId());
if (videoFileList != null && !videoFileList.isEmpty()) {
if (videoFileList != null && videoFileList.size()<2) {
boolean existsPic = PoiSaveUtils.getInstance(mContext).checkPicExists(videoFileList);
if (!existsPic) {
bInt++;
@ -762,7 +762,7 @@ public class PoiSaveUtils {
public boolean checkPicExists(List<File> fileList) {
boolean isExistsPic = false; // 是否记录的照片全部不存在
for (File picFile: fileList) {
if (picFile!=null&&picFile.exists()) {
if (picFile!=null&&picFile.exists()&&!picFile.getName().endsWith(".txt")/*至少包含1张照片*/) {
isExistsPic = true;
break;
}