128 lines
6.0 KiB
Java
128 lines
6.0 KiB
Java
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);
|
|
}
|
|
});
|
|
}
|
|
}
|