fix: 修改充电桩数据重复上传的问题
This commit is contained in:
parent
c925268911
commit
258893dc10
@ -9,8 +9,8 @@ android {
|
||||
applicationId "com.navinfo.outdoor"
|
||||
minSdkVersion 24
|
||||
targetSdkVersion 30
|
||||
versionCode 23
|
||||
versionName "8.220617"
|
||||
versionCode 24
|
||||
versionName "8.220728"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
lintOptions {
|
||||
|
@ -198,7 +198,7 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
private static int BRIGHTNESS=40, FRAMENESS=30;
|
||||
private Button btnSetting;
|
||||
private Switch locationSwitch;
|
||||
private boolean locationEnable;
|
||||
private boolean locationEnable=true;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
@ -419,11 +419,11 @@ public class AutoTakePictureActivity extends BaseActivity implements View.OnClic
|
||||
System.out.println("收到拍照按钮jieguo:"+result.getSize().toString());
|
||||
// 道路拍照必须为横向拍照
|
||||
// TODO 测试时先解除竖向拍摄检查
|
||||
// if (Objects.requireNonNull(camera.getPictureSize()).getWidth() < camera.getPictureSize().getHeight()) {
|
||||
// ToastUtils.Message(AutoTakePictureActivity.this, "不允许竖向拍摄...");
|
||||
// systemTTS.playText("不允许竖向拍摄");
|
||||
// return;
|
||||
// }
|
||||
if (Objects.requireNonNull(camera.getPictureSize()).getWidth() < camera.getPictureSize().getHeight()) {
|
||||
ToastUtils.Message(AutoTakePictureActivity.this, "不允许竖向拍摄...");
|
||||
systemTTS.playText("不允许竖向拍摄");
|
||||
return;
|
||||
}
|
||||
|
||||
File tmpPicFolder = new File(tmpPicFoldPath);
|
||||
if (!tmpPicFolder.exists()) {
|
||||
|
@ -13,6 +13,8 @@ import com.tencent.tencentmap.mapsdk.maps.model.LatLng;
|
||||
import com.umeng.umcrash.UMCrash;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 常量
|
||||
@ -240,4 +242,7 @@ public class Constant {
|
||||
}
|
||||
return "无信号"; // 默认为无信号
|
||||
}
|
||||
|
||||
public static Set<String> submitIdSet = new HashSet<>();
|
||||
public static final String SUBMIT_TOAST_MSG= "当前POI已经在提交列表中,无需重复提交!";
|
||||
}
|
||||
|
@ -99,7 +99,16 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.ObservableSource;
|
||||
import io.reactivex.Scheduler;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.functions.Function;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
@ -879,8 +888,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
|
||||
if (currentChargingPileList != null && !currentChargingPileList.isEmpty()) {
|
||||
for (int i = 0; i < currentChargingPileList.size(); i++) {
|
||||
if (currentChargingPileList.get(i).getPileId() == chargingPileEntity.getPileId()) {
|
||||
currentChargingPileList.add(i, chargingPileEntity);
|
||||
currentChargingPileList.remove(i + 1);
|
||||
currentChargingPileList.set(i, chargingPileEntity);
|
||||
break m;
|
||||
}
|
||||
}
|
||||
@ -1163,7 +1171,85 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用RxJava提交充电站数据,附带提交充电桩数据
|
||||
* */
|
||||
private Observable submitChargingStation(PoiEntity poiEntity) {
|
||||
return Observable.just(poiEntity).subscribeOn(Schedulers.io()).observeOn(Schedulers.io())
|
||||
.doOnEach(poiEntityNotification -> {
|
||||
HttpParams httpParams = new HttpParams();
|
||||
httpParams.put("taskId", poiEntity.getTaskId());
|
||||
httpParams.put("sptype", poiEntity.getStation_type());
|
||||
httpParams.put("existence", poiEntity.getExistence());
|
||||
httpParams.put("name", poiEntity.getName());
|
||||
httpParams.put("address", poiEntity.getAddress());
|
||||
httpParams.put("telephone", poiEntity.getTelPhone());
|
||||
httpParams.put("memo", poiEntity.getMemo());
|
||||
httpParams.put("geo", poiEntity.getGeoWkt());
|
||||
OkGoBuilder okGoBuilder = OkGoBuilder.getInstance()
|
||||
.time(30)
|
||||
.Builder(getActivity())
|
||||
.url(HttpInterface.SUBMIT_CTASK)
|
||||
.cls(ChargingStationBean.class)
|
||||
.params(httpParams)
|
||||
.token(Constant.ACCESS_TOKEN);
|
||||
Response response = okGoBuilder.getSynchronization();
|
||||
Gson gson = new Gson();
|
||||
ChargingStationBean chargingStationBean = gson.fromJson(response.body().string(), ChargingStationBean.class);
|
||||
if (chargingStationBean.getCode() == 200) {
|
||||
Integer bodyId = chargingStationBean.getBody();
|
||||
if (bodyId != null && bodyId != 0) {
|
||||
poiEntity.setBodyId(bodyId);
|
||||
poiEntity.setTaskStatus(3);
|
||||
|
||||
InsertAndUpdateUtils.getInstance().insertOrUpdate(getContext(), poiEntity);
|
||||
// 实时禁用当前的保存按钮,防止用户再次点击保存,重新生成新的POI数据
|
||||
Message obtain1 = Message.obtain();
|
||||
obtain1.what = Constant.CHARGING_STATION_DISABLE;
|
||||
EventBus.getDefault().post(obtain1);
|
||||
} else {
|
||||
Message obtain1 = Message.obtain();
|
||||
obtain1.what = Constant.NEST_WORD_REGISTER;
|
||||
obtain1.obj = "充电站:" + poiEntity.getName() + " 保存本地失败";
|
||||
EventBus.getDefault().post(obtain1);
|
||||
}
|
||||
} else if (chargingStationBean.getCode() == 230) {
|
||||
FlushTokenUtil.flushToken(getActivity());
|
||||
} else {
|
||||
Message obtain1 = Message.obtain();
|
||||
obtain1.what = Constant.NEST_WORD_REGISTER;
|
||||
obtain1.obj = "充电站:" + poiEntity.getName() + " 保存本地失败";
|
||||
EventBus.getDefault().post(obtain1);
|
||||
}
|
||||
})
|
||||
.concatMap(new Function<PoiEntity, ObservableSource<ChargingPileEntity>>() {
|
||||
@Override
|
||||
public ObservableSource<ChargingPileEntity> apply(PoiEntity chargingStationPoiEntity) throws Exception {
|
||||
if (chargingStationPoiEntity != null) {
|
||||
List<ChargingPileEntity> chargingPileEntityList = PoiDatabase.getInstance(getActivity()).getChargingPileDao().getChargingPileByStationId(chargingStationPoiEntity.getId());
|
||||
PoiEntity poiEntity = PoiDatabase.getInstance(getActivity()).getPoiDao().getPoiEntity(chargingStationPoiEntity.getId());
|
||||
if (chargingPileEntityList != null && !chargingPileEntityList.isEmpty()) {
|
||||
chargingPileEntityList = chargingPileEntityList.stream().filter(chargingPileEntity -> chargingPileEntity.getBodyId()==0).collect(Collectors.toList());
|
||||
return getSaveChargingObservable(chargingPileEntityList, poiEntity.getBodyId());
|
||||
}
|
||||
}
|
||||
return Observable.never();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Observable<ChargingPileEntity> getSaveChargingObservable(List<ChargingPileEntity> chargingPileEntityList, int bodyId) {
|
||||
return Observable.fromIterable(chargingPileEntityList).subscribeOn(Schedulers.io()).observeOn(Schedulers.io())
|
||||
.doOnEach(chargingPileEntityNotification -> {
|
||||
saveChargingPileByWork(chargingPileEntityNotification.getValue(), bodyId);
|
||||
});
|
||||
}
|
||||
|
||||
private void chargingStationSaveWork(PoiEntity poiEntity) {
|
||||
if (Constant.submitIdSet.contains(poiEntity.getId())) {
|
||||
ToastUtils.Message(getActivity(), Constant.SUBMIT_TOAST_MSG);
|
||||
return;
|
||||
}
|
||||
HttpParams httpParams = new HttpParams();
|
||||
httpParams.put("taskId", poiEntity.getTaskId());
|
||||
httpParams.put("sptype", poiEntity.getStation_type());
|
||||
@ -1280,6 +1366,10 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
|
||||
|
||||
/*保存充电站数据到服务器*/
|
||||
private void chargingStationSaveByWork(PoiEntity poiEntity) {
|
||||
if (Constant.submitIdSet.contains(poiEntity.getId())) {
|
||||
ToastUtils.Message(getActivity(), Constant.SUBMIT_TOAST_MSG);
|
||||
return;
|
||||
}
|
||||
HttpParams httpParams = new HttpParams();
|
||||
httpParams.put("taskId", poiEntity.getTaskId());
|
||||
httpParams.put("sptype", poiEntity.getStation_type());
|
||||
@ -1297,10 +1387,10 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
|
||||
.cls(ChargingStationBean.class)
|
||||
.params(httpParams)
|
||||
.token(Constant.ACCESS_TOKEN);
|
||||
Constant.submitIdSet.add(poiEntity.getId());
|
||||
okGoBuilder.getRequest(new Callback<ChargingStationBean>() {
|
||||
@Override
|
||||
public void onSuccess(ChargingStationBean chargingStationBean, int id) {
|
||||
dismissLoadingDialog();
|
||||
if (chargingStationBean.getCode() == 200) {
|
||||
Integer bodyId = chargingStationBean.getBody();
|
||||
if (bodyId != null && bodyId != 0) {
|
||||
@ -1317,6 +1407,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
|
||||
|
||||
// 充电站数据已经保存在服务上,批量保存充电桩数据
|
||||
saveChargingPileByChargingStation(poiEntity);
|
||||
Constant.submitIdSet.remove(poiEntity.getId());
|
||||
if (getActivity() != null) {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
@ -1331,12 +1422,16 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
|
||||
}).start();
|
||||
} else {
|
||||
ToastUtils.Message(getActivity(), chargingStationBean.getMessage());
|
||||
Constant.submitIdSet.remove(poiEntity.getId());
|
||||
}
|
||||
} else if (chargingStationBean.getCode() == 230) {
|
||||
FlushTokenUtil.flushToken(getActivity());
|
||||
Constant.submitIdSet.remove(poiEntity.getId());
|
||||
} else {
|
||||
ToastUtils.Message(getActivity(), chargingStationBean.getMessage());
|
||||
Constant.submitIdSet.remove(poiEntity.getId());
|
||||
}
|
||||
dismissLoadingDialog();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1350,6 +1445,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
|
||||
ToastUtils.Message(getActivity(), message);
|
||||
}
|
||||
Log.d("TAG", "onError: " + e.getMessage());
|
||||
Constant.submitIdSet.remove(poiEntity.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1544,7 +1640,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
|
||||
/**
|
||||
* 保存充电桩数据到服务端
|
||||
*/
|
||||
private void saveChargingPileByWork(ChargingPileEntity chargingPileEntity, int bodyId) {
|
||||
private ChargingPileEntity saveChargingPileByWork(ChargingPileEntity chargingPileEntity, int bodyId) {
|
||||
HttpParams httpParams = new HttpParams();
|
||||
httpParams.put("taskId", chargingPileEntity.getTaskId());
|
||||
httpParams.put("name", chargingPileEntity.getName());
|
||||
@ -1582,6 +1678,7 @@ public class ChargingStationFragment extends BaseDrawerFragment implements View.
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return chargingPileEntity;
|
||||
}
|
||||
|
||||
private void initList() {
|
||||
|
@ -138,6 +138,10 @@ public class PoiEntity implements Serializable {
|
||||
|
||||
public void setTaskStatus(int taskStatus) {
|
||||
this.taskStatus = taskStatus;
|
||||
if (this.taskStatus==100) { // 当数据上传成功后,重置其bodyId和taskId
|
||||
setBodyId(0);
|
||||
setTaskId(0);
|
||||
}
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
@ -69,9 +69,13 @@ public class PoiSaveUtils {
|
||||
for (int i = 0; i < poiEntityList.size(); i++) {
|
||||
PoiEntity poiEntity = poiEntityList.get(i);
|
||||
Log.d("PoiSaveUtils", "poiEntity.getType():"+poiEntity.getType());
|
||||
if (Constant.submitIdSet.contains(poiEntity.getId())) {
|
||||
continue;
|
||||
}
|
||||
if (poiEntity.getType() == 2) { // 如果是充电站数据,首先检查子充电桩的状态
|
||||
if (savePoiNet(poiEntity) == 200) { // 网络保存成功
|
||||
if (saveChargingPileByChargingStation(poiEntity)) {
|
||||
Constant.submitIdSet.add(poiEntity.getId()); // 记录全局的正在提交的数据
|
||||
if (savePoiNet(poiEntity) == 200&&saveChargingPileByChargingStation(poiEntity)) { // 网络保存成功
|
||||
Constant.submitIdSet.remove(poiEntity.getId());
|
||||
if (savePoiNet(poiEntity) == 200) { // 网络保存-冗余操作
|
||||
// 开始上传流程
|
||||
if (saveChargingPileUploadChargingStation(poiEntity)) {
|
||||
@ -86,11 +90,11 @@ public class PoiSaveUtils {
|
||||
poiEntity.setWork_type(0);
|
||||
PoiDatabase.getInstance(mContext).getPoiDao().updatePoiEntity(poiEntity);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
poiEntity.setChecked(false);
|
||||
poiEntity.setWork_type(0);
|
||||
PoiDatabase.getInstance(mContext).getPoiDao().updatePoiEntity(poiEntity);
|
||||
Constant.submitIdSet.remove(poiEntity.getId());
|
||||
}
|
||||
} else {//其他类型
|
||||
if (savePoiNet(poiEntity) == 200) { // 网络保存成功
|
||||
|
@ -283,6 +283,7 @@ public class PreserveUtils {
|
||||
|
||||
// 充电站数据已经保存在服务上,批量保存充电桩数据
|
||||
saveChargingPileByChargingStation(mContext, poiEntity);
|
||||
Constant.submitIdSet.remove(poiEntity.getId());
|
||||
mContext.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -299,14 +300,17 @@ public class PreserveUtils {
|
||||
obtain1.what = Constant.NEST_WORD_REGISTER;
|
||||
obtain1.obj = "充电站:" + poiEntity.getName() + " 保存本地失败";
|
||||
EventBus.getDefault().post(obtain1);
|
||||
Constant.submitIdSet.remove(poiEntity.getId());
|
||||
}
|
||||
} else if (chargingStationBean.getCode() == 230) {
|
||||
FlushTokenUtil.flushToken(mContext);
|
||||
Constant.submitIdSet.remove(poiEntity.getId());
|
||||
} else {
|
||||
Message obtain1 = Message.obtain();
|
||||
obtain1.what = Constant.NEST_WORD_REGISTER;
|
||||
obtain1.obj = "充电站:" + poiEntity.getName() + " 保存本地失败";
|
||||
EventBus.getDefault().post(obtain1);
|
||||
Constant.submitIdSet.remove(poiEntity.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@ -316,6 +320,7 @@ public class PreserveUtils {
|
||||
obtain1.what = Constant.NEST_WORD_REGISTER;
|
||||
obtain1.obj = "充电站:" + poiEntity.getName() + " 保存本地失败";
|
||||
EventBus.getDefault().post(obtain1);
|
||||
Constant.submitIdSet.remove(poiEntity.getId());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user