Initial commit
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
package com.ubt.jimu.controller.syn;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.ubt.jimu.base.cache.Cache;
|
||||
import com.ubt.jimu.base.db.robot.RobotDbHandler;
|
||||
import com.ubt.jimu.base.entities.Robot;
|
||||
import com.ubt.jimu.base.entities.RobotLite;
|
||||
import com.ubt.jimu.base.http.ApiResponse;
|
||||
import com.ubt.jimu.transport.model.TransportFile;
|
||||
import com.ubt.jimu.transport3.api.DiyTransportServiceProxy;
|
||||
import com.ubt.jimu.transport3.dao.DiyModelActionDBHandler;
|
||||
import com.ubt.jimu.transport3.dao.TransportFileDbHandler2;
|
||||
import com.ubt.jimu.transport3.download.TransportFileDownloader;
|
||||
import com.ubt.jimu.transport3.model.DiyModelAction;
|
||||
import com.ubt.jimu.utils.LogUtils;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class OfficialActionFileSyncTask implements Callable<Boolean> {
|
||||
private RobotLite a;
|
||||
private DiyTransportServiceProxy b;
|
||||
private BlockingQueue<Boolean> d = new LinkedBlockingQueue();
|
||||
private DiyModelActionDBHandler c = DiyModelActionDBHandler.getInstance();
|
||||
|
||||
public OfficialActionFileSyncTask(RobotLite robotLite, DiyTransportServiceProxy diyTransportServiceProxy) {
|
||||
this.a = robotLite;
|
||||
this.b = diyTransportServiceProxy;
|
||||
}
|
||||
|
||||
private List<DiyModelAction> a(String str) {
|
||||
Robot robotByModelName;
|
||||
int modelId;
|
||||
if (!this.a.isOfficial() || (robotByModelName = RobotDbHandler.getRobotByModelName(this.a.getModelId())) == null || (modelId = (int) robotByModelName.getModelId()) <= 0) {
|
||||
return null;
|
||||
}
|
||||
final ArrayList arrayList = new ArrayList();
|
||||
this.b.actions(modelId, str).subscribe(new Consumer<ApiResponse<List<DiyModelAction>>>() { // from class: com.ubt.jimu.controller.syn.OfficialActionFileSyncTask.1
|
||||
@Override // io.reactivex.functions.Consumer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void accept(ApiResponse<List<DiyModelAction>> apiResponse) throws Exception {
|
||||
List<DiyModelAction> models;
|
||||
if (apiResponse == null || (models = apiResponse.getModels()) == null || models.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (DiyModelAction diyModelAction : models) {
|
||||
if (diyModelAction != null) {
|
||||
diyModelAction.setServerId(1L);
|
||||
diyModelAction.setUserId(Cache.getInstance().getUserId());
|
||||
if (diyModelAction.getIsDeleted() == 1) {
|
||||
OfficialActionFileSyncTask.this.c.deleteModelAction(diyModelAction);
|
||||
} else {
|
||||
DiyModelAction selectUnique = OfficialActionFileSyncTask.this.c.selectUnique(diyModelAction);
|
||||
if (selectUnique == null || selectUnique.getLastUploadTime() < diyModelAction.getLastUploadTime()) {
|
||||
arrayList.add(diyModelAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LogUtils.c("查询用户动作成功——》需要更新的数据:" + arrayList.size());
|
||||
}
|
||||
});
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
/* JADX WARN: Can't rename method to resolve collision */
|
||||
@Override // java.util.concurrent.Callable
|
||||
public Boolean call() throws Exception {
|
||||
List<DiyModelAction> a;
|
||||
String userId = Cache.getInstance().getUserId();
|
||||
String userToken = Cache.getInstance().getUserToken();
|
||||
if (!TextUtils.isEmpty(userId) && !TextUtils.isEmpty(userToken) && !userId.equals("local") && (a = a(userToken)) != null && a.size() != 0) {
|
||||
a(a);
|
||||
try {
|
||||
this.d.poll(15000L, TimeUnit.MILLISECONDS);
|
||||
return false;
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void a(final List<DiyModelAction> list) {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
Iterator<DiyModelAction> it = list.iterator();
|
||||
while (it.hasNext()) {
|
||||
arrayList.add(TransportFileDbHandler2.newActionFile(it.next()));
|
||||
}
|
||||
new TransportFileDownloader().downloadFileSyn(arrayList, new Consumer<HashMap<String, TransportFile>>() { // from class: com.ubt.jimu.controller.syn.OfficialActionFileSyncTask.2
|
||||
@Override // io.reactivex.functions.Consumer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void accept(HashMap<String, TransportFile> hashMap) throws Exception {
|
||||
if (hashMap == null || hashMap.size() == 0) {
|
||||
return;
|
||||
}
|
||||
LogUtils.c("下载动作文件成功:" + hashMap.size());
|
||||
for (String str : hashMap.keySet()) {
|
||||
if (!TextUtils.isEmpty(str)) {
|
||||
Iterator it2 = list.iterator();
|
||||
while (true) {
|
||||
if (it2.hasNext()) {
|
||||
DiyModelAction diyModelAction = (DiyModelAction) it2.next();
|
||||
if (str.equals(diyModelAction.getFileUrl())) {
|
||||
diyModelAction.setServerId(1L);
|
||||
diyModelAction.setUploaded(true);
|
||||
diyModelAction.setModify(false);
|
||||
OfficialActionFileSyncTask.this.c.insertOrUpdateActionDB(diyModelAction);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
OfficialActionFileSyncTask.this.d.offer(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,132 @@
|
||||
package com.ubt.jimu.controller.syn;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.ubt.jimu.base.cache.Cache;
|
||||
import com.ubt.jimu.base.db.robot.RobotDbHandler;
|
||||
import com.ubt.jimu.base.entities.Robot;
|
||||
import com.ubt.jimu.base.entities.RobotLite;
|
||||
import com.ubt.jimu.base.http.ApiResponse;
|
||||
import com.ubt.jimu.transport.model.TransportFile;
|
||||
import com.ubt.jimu.transport3.api.DiyTransportServiceProxy;
|
||||
import com.ubt.jimu.transport3.bean.response.TransportFileBean;
|
||||
import com.ubt.jimu.transport3.dao.TransportFileDbHandler2;
|
||||
import com.ubt.jimu.transport3.download.TransportFileDownloader;
|
||||
import com.ubt.jimu.utils.LogUtils;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class OfficialModelFileSynTask implements Callable<Boolean> {
|
||||
private RobotLite a;
|
||||
private DiyTransportServiceProxy b;
|
||||
private BlockingQueue<Boolean> c = new LinkedBlockingQueue();
|
||||
|
||||
public OfficialModelFileSynTask(RobotLite robotLite, DiyTransportServiceProxy diyTransportServiceProxy) {
|
||||
this.a = robotLite;
|
||||
this.b = diyTransportServiceProxy;
|
||||
}
|
||||
|
||||
private List<TransportFile> a(final String str) {
|
||||
Robot robotByModelName = RobotDbHandler.getRobotByModelName(this.a.getModelId());
|
||||
if (robotByModelName == null) {
|
||||
return null;
|
||||
}
|
||||
final ArrayList arrayList = new ArrayList();
|
||||
LogUtils.c("token:" + Cache.getInstance().getUserToken());
|
||||
this.b.getModelFiles(str, (int) robotByModelName.getModelId(), Cache.getInstance().getUserToken()).subscribe(new Consumer<ApiResponse<List<TransportFileBean>>>(this) { // from class: com.ubt.jimu.controller.syn.OfficialModelFileSynTask.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 {
|
||||
List<TransportFileBean> models;
|
||||
LogUtils.c("listApiResponse:" + apiResponse + " 线程:" + Thread.currentThread().getName());
|
||||
if (!apiResponse.isStatus() || (models = apiResponse.getModels()) == null || models.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < models.size(); i++) {
|
||||
TransportFileBean transportFileBean = models.get(i);
|
||||
if (transportFileBean.getIsDeleted() != 1) {
|
||||
long lastUploadTime = transportFileBean.getLastUploadTime();
|
||||
TransportFile modelFile = TransportFileDbHandler2.getInstance().getModelFile(str, transportFileBean.getCustomModelId(), transportFileBean.getFileType());
|
||||
if (modelFile == null) {
|
||||
arrayList.add(TransportFileBean.toTransportFile(str, transportFileBean));
|
||||
} else if (lastUploadTime > modelFile.getLastUploadTime()) {
|
||||
arrayList.add(TransportFileBean.toTransportFile(str, transportFileBean));
|
||||
}
|
||||
}
|
||||
}
|
||||
LogUtils.c("文件查询完毕");
|
||||
}
|
||||
});
|
||||
return arrayList;
|
||||
}
|
||||
|
||||
/* JADX WARN: Can't rename method to resolve collision */
|
||||
@Override // java.util.concurrent.Callable
|
||||
public Boolean call() throws Exception {
|
||||
LogUtils.c("开始获取模型文件");
|
||||
if (!this.a.isOfficial()) {
|
||||
return false;
|
||||
}
|
||||
String userId = Cache.getInstance().getUserId();
|
||||
if (TextUtils.isEmpty(userId) || "local".equals(userId)) {
|
||||
return false;
|
||||
}
|
||||
LogUtils.c("查询需要下载的文件");
|
||||
List<TransportFile> a = a(userId);
|
||||
if (a == null || a.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
LogUtils.c("开始下载数据");
|
||||
a(a);
|
||||
try {
|
||||
this.c.poll(5000L, TimeUnit.MILLISECONDS);
|
||||
LogUtils.c("流程结束");
|
||||
return false;
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void a(List<TransportFile> list) {
|
||||
new TransportFileDownloader().downloadFileSyn(list, new Consumer<HashMap<String, TransportFile>>() { // from class: com.ubt.jimu.controller.syn.OfficialModelFileSynTask.2
|
||||
@Override // io.reactivex.functions.Consumer
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void accept(HashMap<String, TransportFile> hashMap) throws Exception {
|
||||
LogUtils.c("官方模型用户文件下载成功");
|
||||
if (hashMap != null && hashMap.size() > 0) {
|
||||
Iterator<String> it = hashMap.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
TransportFile transportFile = hashMap.get(it.next());
|
||||
LogUtils.b("woo file download success: " + transportFile.getFullPath());
|
||||
transportFile.setUploaded(true);
|
||||
transportFile.setIsModify(false);
|
||||
transportFile.setIsDeleted(false);
|
||||
transportFile.setId(1L);
|
||||
TransportFile selectUnique = TransportFileDbHandler2.getInstance().selectUnique(transportFile);
|
||||
if (selectUnique == null) {
|
||||
TransportFileDbHandler2.getInstance().insert(transportFile);
|
||||
} else {
|
||||
selectUnique.setId(transportFile.getId());
|
||||
selectUnique.setUploaded(true);
|
||||
selectUnique.setIsModify(false);
|
||||
selectUnique.setModifyTime(transportFile.getModifyTime());
|
||||
selectUnique.setLastUploadTime(transportFile.getLastUploadTime());
|
||||
TransportFileDbHandler2.getInstance().update(selectUnique);
|
||||
}
|
||||
}
|
||||
LogUtils.c("文件下载完成");
|
||||
}
|
||||
OfficialModelFileSynTask.this.c.offer(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@@ -0,0 +1,56 @@
|
||||
package com.ubt.jimu.controller.syn;
|
||||
|
||||
import com.ubt.jimu.base.entities.RobotLite;
|
||||
import com.ubt.jimu.transport3.api.DiyTransportServiceProxy;
|
||||
import com.ubt.jimu.utils.LogUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class OfficialSyncExecutor implements Runnable {
|
||||
private RobotLite a;
|
||||
private DiyTransportServiceProxy b = new DiyTransportServiceProxy();
|
||||
private SyncCompletedListener c;
|
||||
|
||||
public interface SyncCompletedListener {
|
||||
void a();
|
||||
}
|
||||
|
||||
public OfficialSyncExecutor(RobotLite robotLite) {
|
||||
this.a = robotLite;
|
||||
}
|
||||
|
||||
public void a(SyncCompletedListener syncCompletedListener) {
|
||||
this.c = syncCompletedListener;
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
ArrayList arrayList = new ArrayList();
|
||||
arrayList.add(new OfficialActionFileSyncTask(this.a, this.b));
|
||||
arrayList.add(new OfficialModelFileSynTask(this.a, this.b));
|
||||
try {
|
||||
try {
|
||||
Executors.newSingleThreadExecutor().invokeAll(arrayList, 20000L, TimeUnit.MILLISECONDS);
|
||||
if (this.c == null) {
|
||||
return;
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
Thread.currentThread().interrupt();
|
||||
if (this.c == null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
LogUtils.c("数据同步完成");
|
||||
this.c.a();
|
||||
} catch (Throwable th) {
|
||||
if (this.c != null) {
|
||||
LogUtils.c("数据同步完成");
|
||||
this.c.a();
|
||||
}
|
||||
throw th;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user