|
@@ -4,6 +4,7 @@ import android.content.Context;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.tofly.latte_core.base.LattePresenterImpl;
|
|
|
+import com.tofly.latte_core.config.Constants;
|
|
|
import com.tofly.latte_core.net.LatteNetWorkApi;
|
|
|
import com.tofly.latte_core.net.bean.BaseResponse;
|
|
|
import com.tofly.latte_core.net.helper.RxHelper;
|
|
@@ -12,13 +13,10 @@ import com.tofly.yxpc.base.Api;
|
|
|
import com.tofly.yxpc.utils.RequestBodyUtils;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
-import io.reactivex.Observable;
|
|
|
-import okhttp3.MultipartBody;
|
|
|
import okhttp3.RequestBody;
|
|
|
|
|
|
public class UpLoadImpl extends LattePresenterImpl {
|
|
@@ -26,55 +24,47 @@ public class UpLoadImpl extends LattePresenterImpl {
|
|
|
@Override
|
|
|
public void getResultOne(Context context, Map<String, Object> map) {
|
|
|
super.getResultOne(context, map);
|
|
|
- List<MultipartBody.Part> parts1 = new ArrayList<>();
|
|
|
+ Map<String, RequestBody> params = new HashMap<>();
|
|
|
List<File> list1 = (List<File>) map.get("file");
|
|
|
if (list1 != null && !list1.isEmpty()) {
|
|
|
- for (int i = 0; i < list1.size(); i++) {
|
|
|
- MultipartBody.Part part = RequestBodyUtils.toMultiPartBodyFile("file", list1.get(i), context);
|
|
|
- parts1.add(part);
|
|
|
+ for (File file : list1) {
|
|
|
+ params.put("file\";filename=\"" + file.getName(), RequestBodyUtils.toRequestBodyFile(file, context));
|
|
|
}
|
|
|
map.remove("file");
|
|
|
- map.remove("fileList");
|
|
|
}
|
|
|
- List<MultipartBody.Part> parts2 = new ArrayList<>();
|
|
|
List<File> list2 = (List<File>) map.get("bpFileList");
|
|
|
if (list2 != null && !list2.isEmpty()) {
|
|
|
- parts2 = new ArrayList<>();
|
|
|
- for (int i = 0; i < list2.size(); i++) {
|
|
|
- MultipartBody.Part part = RequestBodyUtils.toMultiPartBodyFile("bpfilelist", list2.get(i), context);
|
|
|
- parts2.add(part);
|
|
|
+ for (File file : list2) {
|
|
|
+ params.put("bpFileList\";filename=\"" + file.getName(), RequestBodyUtils.toRequestBodyFile(file, context));
|
|
|
}
|
|
|
map.remove("bpFileList");
|
|
|
}
|
|
|
- Map<String, RequestBody> params = new HashMap<>();
|
|
|
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
|
String key = entry.getKey();
|
|
|
Object value = entry.getValue();
|
|
|
params.put(key, RequestBodyUtils.toRequestBodyString(value == null ? "" : value.toString()));
|
|
|
}
|
|
|
- Api api = LatteNetWorkApi.getApiService(Api.class);
|
|
|
- Observable<BaseResponse> observable;
|
|
|
- if (list2 == null || list2.isEmpty()) {
|
|
|
- observable = api.uploadWaterNotInspect(parts1, params);
|
|
|
- } else {
|
|
|
- observable = api.uploadWaterNotInspect(parts1, parts2, params);
|
|
|
- }
|
|
|
- observable.compose(RxHelper.observableIO2Main(context))
|
|
|
+ LatteNetWorkApi.getApiService(Api.class)
|
|
|
+ .uploadWaterNotInspect(params)
|
|
|
+ .compose(RxHelper.observableIO2Main(context))
|
|
|
.subscribe(new MyObserver<BaseResponse>(context) {
|
|
|
@Override
|
|
|
public void onSuccess(BaseResponse demo) {
|
|
|
if (isViewAttached()) {
|
|
|
- getView().getResultOne(demo);
|
|
|
+ if (Constants.SUCCESS.equals(demo.getCode())) {
|
|
|
+ getView().getResultOne(demo);
|
|
|
+ } else {
|
|
|
+ getView().onMessage(demo.getMessage());
|
|
|
+ getView().getResultOne(null);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onFailure(Throwable e, String errorMsg) {
|
|
|
if (isViewAttached()) {
|
|
|
- BaseResponse baseResponse = new BaseResponse();
|
|
|
- baseResponse.setCode(null);
|
|
|
- baseResponse.setMessage(errorMsg);
|
|
|
- getView().getResultThree(baseResponse);
|
|
|
+ getView().onMessage(errorMsg);
|
|
|
+ getView().getResultOne(null);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -83,40 +73,39 @@ public class UpLoadImpl extends LattePresenterImpl {
|
|
|
@Override
|
|
|
public void getResultTwo(Context context, Map<String, Object> map) {
|
|
|
super.getResultTwo(context, map);
|
|
|
-
|
|
|
- List<MultipartBody.Part> parts1 = new ArrayList<>();
|
|
|
+ Map<String, RequestBody> params = new HashMap<>();
|
|
|
List<File> list1 = (List<File>) map.get("mapfilelist");
|
|
|
if (list1 != null && !list1.isEmpty()) {
|
|
|
- for (int i = 0; i < list1.size(); i++) {
|
|
|
- MultipartBody.Part part = RequestBodyUtils.toMultiPartBodyFile("mapfilelist", list1.get(i), context);
|
|
|
- parts1.add(part);
|
|
|
+ for (File file : list1) {
|
|
|
+ params.put("mapfilelist\";filename=\"" + file.getName(), RequestBodyUtils.toRequestBodyFile(file, context));
|
|
|
}
|
|
|
map.remove("mapfilelist");
|
|
|
}
|
|
|
-
|
|
|
- List<MultipartBody.Part> parts2 = new ArrayList<>();
|
|
|
List<File> list2 = (List<File>) map.get("file");
|
|
|
if (list2 != null && !list2.isEmpty()) {
|
|
|
- for (int i = 0; i < list2.size(); i++) {
|
|
|
- MultipartBody.Part part = RequestBodyUtils.toMultiPartBodyFile("file", list2.get(i), context);
|
|
|
- parts2.add(part);
|
|
|
+ for (File file : list2) {
|
|
|
+ params.put("file\";filename=\"" + file.getName(), RequestBodyUtils.toRequestBodyFile(file, context));
|
|
|
}
|
|
|
map.remove("file");
|
|
|
}
|
|
|
- Map<String, RequestBody> params = new HashMap<>();
|
|
|
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
|
String key = entry.getKey();
|
|
|
Object value = entry.getValue();
|
|
|
params.put(key, RequestBodyUtils.toRequestBodyString(value.toString()));
|
|
|
}
|
|
|
LatteNetWorkApi.getApiService(Api.class)
|
|
|
- .uploadWaterTwNavigation(params, parts1, parts2)
|
|
|
+ .uploadWaterTwNavigation(params)
|
|
|
.compose(RxHelper.observableIO2Main(context))
|
|
|
.subscribe(new MyObserver<BaseResponse>(context) {
|
|
|
@Override
|
|
|
public void onSuccess(BaseResponse demo) {
|
|
|
if (isViewAttached()) {
|
|
|
- getView().getResultTwo(demo);
|
|
|
+ if (Constants.SUCCESS.equals(demo.getCode())) {
|
|
|
+ getView().getResultTwo(demo);
|
|
|
+ } else {
|
|
|
+ getView().onMessage(demo.getMessage());
|
|
|
+ getView().getResultTwo(null);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -124,6 +113,7 @@ public class UpLoadImpl extends LattePresenterImpl {
|
|
|
public void onFailure(Throwable e, String errorMsg) {
|
|
|
if (isViewAttached()) {
|
|
|
getView().onMessage(errorMsg);
|
|
|
+ getView().getResultTwo(null);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -132,38 +122,30 @@ public class UpLoadImpl extends LattePresenterImpl {
|
|
|
@Override
|
|
|
public void getResultThree(Context context, Map<String, Object> map) {
|
|
|
super.getResultThree(context, map);
|
|
|
-
|
|
|
- List<MultipartBody.Part> parts1 = new ArrayList<>();
|
|
|
+ Map<String, RequestBody> params = new HashMap<>();
|
|
|
List<File> list1 = (List<File>) map.get("bpFileList");
|
|
|
if (list1 != null && !list1.isEmpty()) {
|
|
|
- for (int i = 0; i < list1.size(); i++) {
|
|
|
- MultipartBody.Part part = RequestBodyUtils.toMultiPartBodyFile("bpFileList", list1.get(i), context);
|
|
|
- parts1.add(part);
|
|
|
+ for (File file : list1) {
|
|
|
+ params.put("bpFileList\";filename=\"" + file.getName(), RequestBodyUtils.toRequestBodyFile(file, context));
|
|
|
}
|
|
|
map.remove("bpFileList");
|
|
|
}
|
|
|
|
|
|
- List<MultipartBody.Part> parts2 = new ArrayList<>();
|
|
|
List<File> list2 = (List<File>) map.get("exceptionFileList");
|
|
|
if (list2 != null && !list2.isEmpty()) {
|
|
|
- for (int i = 0; i < list2.size(); i++) {
|
|
|
- MultipartBody.Part part = RequestBodyUtils.toMultiPartBodyFile("exceptionFileList", list2.get(i), context);
|
|
|
- parts2.add(part);
|
|
|
+ for (File file : list2) {
|
|
|
+ params.put("exceptionFileList\";filename=\"" + file.getName(), RequestBodyUtils.toRequestBodyFile(file, context));
|
|
|
}
|
|
|
map.remove("exceptionFileList");
|
|
|
}
|
|
|
-
|
|
|
- List<MultipartBody.Part> parts3 = new ArrayList<>();
|
|
|
List<File> list3 = (List<File>) map.get("wfbdFileList");
|
|
|
if (list3 != null && !list3.isEmpty()) {
|
|
|
- for (int i = 0; i < list3.size(); i++) {
|
|
|
- MultipartBody.Part part = RequestBodyUtils.toMultiPartBodyFile("wfbdFileList", list3.get(i), context);
|
|
|
- parts3.add(part);
|
|
|
+ for (File file : list3) {
|
|
|
+ params.put("wfbdFileList\";filename=\"" + file.getName(), RequestBodyUtils.toRequestBodyFile(file, context));
|
|
|
}
|
|
|
map.remove("wfbdFileList");
|
|
|
}
|
|
|
|
|
|
- Map<String, RequestBody> params = new HashMap<>();
|
|
|
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
|
String key = entry.getKey();
|
|
|
if (key.equals("kbdDescribes") || key.equals("wfDescribes")) {
|
|
@@ -192,23 +174,104 @@ public class UpLoadImpl extends LattePresenterImpl {
|
|
|
}
|
|
|
}
|
|
|
LatteNetWorkApi.getApiService(Api.class)
|
|
|
- .updateBatchByCus(params, parts1, parts2, parts3)
|
|
|
+ .updateBatchByCus(params)
|
|
|
.compose(RxHelper.observableIO2Main(context))
|
|
|
.subscribe(new MyObserver<BaseResponse>(context) {
|
|
|
@Override
|
|
|
public void onSuccess(BaseResponse demo) {
|
|
|
if (isViewAttached()) {
|
|
|
- getView().getResultThree(demo);
|
|
|
+ if (Constants.SUCCESS.equals(demo.getCode())) {
|
|
|
+ getView().getResultThree(demo);
|
|
|
+ } else {
|
|
|
+ getView().onMessage(demo.getMessage());
|
|
|
+ getView().getResultThree(null);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onFailure(Throwable e, String errorMsg) {
|
|
|
if (isViewAttached()) {
|
|
|
- BaseResponse baseResponse = new BaseResponse();
|
|
|
- baseResponse.setCode(null);
|
|
|
- baseResponse.setMessage(errorMsg);
|
|
|
- getView().getResultThree(baseResponse);
|
|
|
+ getView().onMessage(errorMsg);
|
|
|
+ getView().getResultThree(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getResultFour(Context context, Map<String, Object> map) {
|
|
|
+ super.getResultFour(context, map);
|
|
|
+ LatteNetWorkApi.getApiService(Api.class)
|
|
|
+ .deleteUnRegister(map)
|
|
|
+ .compose(RxHelper.observableIO2Main(context))
|
|
|
+ .subscribe(new MyObserver<BaseResponse>(context) {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(BaseResponse demo) {
|
|
|
+ if (isViewAttached()) {
|
|
|
+ if (Constants.SUCCESS.equals(demo.getCode())) {
|
|
|
+ getView().getResultFour(demo);
|
|
|
+ } else {
|
|
|
+ getView().onMessage(demo.getMessage());
|
|
|
+ getView().getResultFour(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(Throwable e, String errorMsg) {
|
|
|
+ if (isViewAttached()) {
|
|
|
+ getView().onMessage(errorMsg);
|
|
|
+ getView().getResultFour(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getResultFive(Context context, Map<String, Object> map) {
|
|
|
+ super.getResultFive(context, map);
|
|
|
+ Map<String, RequestBody> params = new HashMap<>();
|
|
|
+ List<File> list1 = (List<File>) map.get("file");
|
|
|
+ if (list1 != null && !list1.isEmpty()) {
|
|
|
+ for (File file : list1) {
|
|
|
+ params.put("file\";filename=\"" + file.getName(), RequestBodyUtils.toRequestBodyFile(file, context));
|
|
|
+ }
|
|
|
+ map.remove("file");
|
|
|
+ }
|
|
|
+ List<File> list2 = (List<File>) map.get("bpFileList");
|
|
|
+ if (list2 != null && !list2.isEmpty()) {
|
|
|
+ for (File file : list2) {
|
|
|
+ params.put("bpFileList\";filename=\"" + file.getName(), RequestBodyUtils.toRequestBodyFile(file, context));
|
|
|
+ }
|
|
|
+ map.remove("bpFileList");
|
|
|
+ }
|
|
|
+ for (Map.Entry<String, Object> entry : map.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ Object value = entry.getValue();
|
|
|
+ params.put(key, RequestBodyUtils.toRequestBodyString(value == null ? "" : value.toString()));
|
|
|
+ }
|
|
|
+ LatteNetWorkApi.getApiService(Api.class)
|
|
|
+ .UpdateWaterNotInspect(params)
|
|
|
+ .compose(RxHelper.observableIO2Main(context))
|
|
|
+ .subscribe(new MyObserver<BaseResponse>(context) {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(BaseResponse demo) {
|
|
|
+ if (isViewAttached()) {
|
|
|
+ if (Constants.SUCCESS.equals(demo.getCode())) {
|
|
|
+ getView().getResultFive(demo);
|
|
|
+ } else {
|
|
|
+ getView().onMessage(demo.getMessage());
|
|
|
+ getView().getResultFive(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(Throwable e, String errorMsg) {
|
|
|
+ if (isViewAttached()) {
|
|
|
+ getView().onMessage(errorMsg);
|
|
|
+ getView().getResultFive(null);
|
|
|
}
|
|
|
}
|
|
|
});
|