224 lines
9.8 KiB
Java
224 lines
9.8 KiB
Java
package com.ubt.jimu.sync;
|
|
|
|
import android.text.TextUtils;
|
|
import com.ubt.jimu.base.cache.Cache;
|
|
import com.ubt.jimu.base.http.ApiResponse;
|
|
import com.ubt.jimu.blockly.networkSync.utils.QiNiuUtils;
|
|
import com.ubt.jimu.transport.model.TransportFile;
|
|
import com.ubt.jimu.transport3.api.DiyTransportServiceProxy;
|
|
import com.ubt.jimu.transport3.bean.request.UploadModelFileBean;
|
|
import com.ubt.jimu.transport3.bean.response.TransportFileBean;
|
|
import com.ubt.jimu.transport3.dao.TransportFileDbHandler2;
|
|
import com.ubt.jimu.upload.DataUploadProxy;
|
|
import com.ubt.jimu.upload.SimpleUploadCallback;
|
|
import com.ubt.jimu.upload.UploadFilePathUtils;
|
|
import com.ubt.jimu.upload.UploadRequest;
|
|
import com.ubt.jimu.upload.UploadResponse;
|
|
import com.ubt.jimu.utils.LogUtils;
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
import io.reactivex.functions.Consumer;
|
|
import io.reactivex.schedulers.Schedulers;
|
|
import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class OfflineModelFilesUpload {
|
|
private String a;
|
|
private DiyTransportServiceProxy b;
|
|
private TransportFileDbHandler2 c;
|
|
|
|
public OfflineModelFilesUpload(DiyTransportServiceProxy diyTransportServiceProxy) {
|
|
this.b = diyTransportServiceProxy;
|
|
if (this.c == null) {
|
|
this.c = TransportFileDbHandler2.getInstance();
|
|
}
|
|
}
|
|
|
|
public void b(String str, String str2) {
|
|
a(str, str2, this.c.getOfflineController());
|
|
}
|
|
|
|
public void c(String str, String str2) {
|
|
a(str, str2, this.c.getOfflineControllerMenuList());
|
|
}
|
|
|
|
public void d(String str, String str2) {
|
|
a(str, str2, this.c.getOfflineDesc());
|
|
}
|
|
|
|
public void e(String str, String str2) {
|
|
a(str, str2, this.c.getOfflineServosFile());
|
|
}
|
|
|
|
public void f(String str, String str2) {
|
|
a(str, str2, this.c.getOfflineVideo());
|
|
}
|
|
|
|
public void g(String str, String str2) {
|
|
a(str, str2, this.c.getOfflineVideoCover());
|
|
}
|
|
|
|
private void c(final int i, final TransportFile transportFile) {
|
|
String modelFileLocal = QiNiuUtils.getModelFileLocal(transportFile);
|
|
LogUtils.c("localPath:" + modelFileLocal);
|
|
if (TextUtils.isEmpty(modelFileLocal)) {
|
|
return;
|
|
}
|
|
if (!new File(modelFileLocal).exists()) {
|
|
LogUtils.c("Diy file not exists");
|
|
return;
|
|
}
|
|
UploadRequest uploadRequest = new UploadRequest();
|
|
uploadRequest.a(UploadFilePathUtils.a(modelFileLocal));
|
|
uploadRequest.b(modelFileLocal);
|
|
DataUploadProxy.c().a(uploadRequest, new SimpleUploadCallback() { // from class: com.ubt.jimu.sync.OfflineModelFilesUpload.2
|
|
@Override // com.ubt.jimu.upload.IUploadCallback
|
|
public void uploadFaulted(UploadRequest uploadRequest2, Exception exc) {
|
|
transportFile.setUploaded(false);
|
|
try {
|
|
OfflineModelFilesUpload.this.c.insertOrUpdate2(transportFile);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.upload.IUploadCallback
|
|
public void uploadSucceed(UploadResponse uploadResponse) {
|
|
transportFile.setUploaded(true);
|
|
transportFile.setFileUrl(uploadResponse.c());
|
|
try {
|
|
OfflineModelFilesUpload.this.c.insertOrUpdate2(transportFile);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
OfflineModelFilesUpload.this.b(i, transportFile);
|
|
}
|
|
});
|
|
}
|
|
|
|
public void a(String str, String str2) {
|
|
a(str, str2, this.c.getOfflineBgFile());
|
|
}
|
|
|
|
public void b(int i, final TransportFile transportFile) {
|
|
this.a = Cache.getInstance().getUserToken();
|
|
UploadModelFileBean uploadModelFileBean = new UploadModelFileBean(transportFile.getUserId(), this.a, (int) transportFile.getModelId(), transportFile.getCustomModelId());
|
|
ArrayList arrayList = new ArrayList();
|
|
arrayList.add(transportFile);
|
|
if (i == 1) {
|
|
uploadModelFileBean.setAddFiles(arrayList);
|
|
} else if (i == 0) {
|
|
uploadModelFileBean.setUpdateFiles(arrayList);
|
|
} else if (i == -1) {
|
|
uploadModelFileBean.setDeleteFiles(arrayList);
|
|
}
|
|
this.b.uploadModelFiles(uploadModelFileBean).subscribeOn(Schedulers.b()).observeOn(AndroidSchedulers.a()).subscribe(new Consumer<ApiResponse<Object>>() { // from class: com.ubt.jimu.sync.OfflineModelFilesUpload.3
|
|
@Override // io.reactivex.functions.Consumer
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public void accept(ApiResponse<Object> apiResponse) throws Exception {
|
|
if (apiResponse == null || !apiResponse.isStatus()) {
|
|
return;
|
|
}
|
|
transportFile.setId(1L);
|
|
transportFile.setIsModify(false);
|
|
OfflineModelFilesUpload.this.c.insertOrUpdate(transportFile);
|
|
}
|
|
});
|
|
}
|
|
|
|
private void a(String str, String str2, List<TransportFile> list) {
|
|
if (list == null || list.size() == 0) {
|
|
return;
|
|
}
|
|
for (final TransportFile transportFile : list) {
|
|
long modelId = transportFile.getModelId();
|
|
if (modelId != 0) {
|
|
LogUtils.c("token:" + str2);
|
|
this.b.getModelFiles(str, (int) modelId, str2).subscribeOn(Schedulers.b()).observeOn(AndroidSchedulers.a()).subscribe(new Consumer<ApiResponse<List<TransportFileBean>>>() { // from class: com.ubt.jimu.sync.OfflineModelFilesUpload.1
|
|
@Override // io.reactivex.functions.Consumer
|
|
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
|
public void accept(ApiResponse<List<TransportFileBean>> apiResponse) throws Exception {
|
|
TransportFileBean a = OfflineModelFilesUpload.this.a(apiResponse, transportFile);
|
|
if (a == null || !a.isOutTime()) {
|
|
if ("1".equals(transportFile.getModelType())) {
|
|
if (a == null) {
|
|
OfflineModelFilesUpload.this.a(1, transportFile);
|
|
return;
|
|
} else {
|
|
if (a.isOutTime()) {
|
|
return;
|
|
}
|
|
OfflineModelFilesUpload.this.a(0, transportFile);
|
|
return;
|
|
}
|
|
}
|
|
boolean uploaded = transportFile.getUploaded();
|
|
long id = transportFile.getId();
|
|
if (uploaded) {
|
|
if (id == 0) {
|
|
OfflineModelFilesUpload.this.b(1, transportFile);
|
|
return;
|
|
} else {
|
|
OfflineModelFilesUpload.this.b(0, transportFile);
|
|
return;
|
|
}
|
|
}
|
|
if (id == 0) {
|
|
OfflineModelFilesUpload.this.a(1, transportFile);
|
|
} else {
|
|
OfflineModelFilesUpload.this.a(0, transportFile);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
public void a(int i, TransportFile transportFile) {
|
|
String userId = Cache.getInstance().getUserId();
|
|
this.a = Cache.getInstance().getUserToken();
|
|
if ("local".equals(userId) || TextUtils.isEmpty(userId)) {
|
|
return;
|
|
}
|
|
c(i, transportFile);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public TransportFileBean a(ApiResponse<List<TransportFileBean>> apiResponse, TransportFile transportFile) {
|
|
List<TransportFileBean> models;
|
|
if (apiResponse != null && apiResponse.getModels() != null && apiResponse.getModels().size() != 0 && (models = apiResponse.getModels()) != null && models.size() > 0) {
|
|
for (int i = 0; i < models.size(); i++) {
|
|
TransportFileBean transportFileBean = models.get(i);
|
|
String customModelId = transportFileBean.getCustomModelId();
|
|
String fileName = transportFileBean.getFileName();
|
|
String fileType = transportFileBean.getFileType();
|
|
long lastUploadTime = transportFileBean.getLastUploadTime();
|
|
int isDeleted = transportFileBean.getIsDeleted();
|
|
String customModelId2 = transportFile.getCustomModelId();
|
|
String fileName2 = transportFile.getFileName();
|
|
String fileType2 = transportFile.getFileType();
|
|
long lastUploadTime2 = transportFile.getLastUploadTime();
|
|
if (customModelId.equals(customModelId2) && fileName.equals(fileName2) && fileType.equals(fileType2)) {
|
|
LogUtils.c("离线数据同步:" + fileName2 + " " + fileName);
|
|
if (lastUploadTime >= lastUploadTime2) {
|
|
transportFileBean.setOutTime(true);
|
|
} else {
|
|
transportFileBean.setOutTime(false);
|
|
}
|
|
if (isDeleted == 1) {
|
|
transportFileBean.setOutTime(true);
|
|
}
|
|
return transportFileBean;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void a(String str, int i) {
|
|
this.c.uploadUserIdAndModelId(str, i);
|
|
}
|
|
}
|