jimu-decompiled/sources/com/ubt/jimu/transport3/UnityFileOperator.java
2025-05-13 19:24:51 +02:00

324 lines
14 KiB
Java

package com.ubt.jimu.transport3;
import android.text.TextUtils;
import com.ubt.jimu.base.cache.Cache;
import com.ubt.jimu.base.db.diy.DiyDBModel;
import com.ubt.jimu.base.db.robot.RobotDbHandler;
import com.ubt.jimu.base.entities.Robot;
import com.ubt.jimu.transport.dao.TransportFileDbHandler;
import com.ubt.jimu.transport.model.TransportFile;
import com.ubt.jimu.transport3.DiyTransportServiceImpl;
import com.ubt.jimu.transport3.bean.request.UploadModelFileBean;
import com.ubt.jimu.transport3.dao.DiyDBModelDBHandler;
import com.ubt.jimu.transport3.dao.DiyModelActionDBHandler;
import com.ubt.jimu.transport3.dao.TransportFileDbHandler2;
import com.ubt.jimu.transport3.model.DiyModelAction;
import com.ubt.jimu.upload.SimpleUploadCallback;
import com.ubt.jimu.upload.UploadRequest;
import com.ubt.jimu.upload.UploadResponse;
import com.ubt.jimu.utils.LogUtils;
import com.ubt.jimu.utils.SystemUtils;
import com.ubtech.utils.FileHelper;
import com.ubtrobot.log.ALog;
import java.io.File;
import java.util.ArrayList;
/* loaded from: classes2.dex */
public class UnityFileOperator {
public static final String TAG = "unity";
public static final int TYPE_DEL_FILE = 3;
public static final int TYPE_NEW_FILE = 1;
public static final int TYPE_UPDATE_FILE = 2;
private String absoluteFilePath;
private String customModelId;
private String fileName;
private String filePath;
private String fileType;
private int modelId;
private int modelType;
private int oType;
private String userId;
public UnityFileOperator(int i, String str, int i2, String str2, int i3) {
this.modelId = i;
LogUtils.c("UnityFileOperator:" + i + " customModelId:" + str + " modelId:" + i);
this.customModelId = str;
this.modelType = i2 + 1;
this.absoluteFilePath = str2;
this.oType = i3;
this.userId = Cache.getInstance().getUserId();
this.fileType = TransportFileDbHandler2.modelFileType(str, str2);
this.filePath = TransportFileDbHandler.getFilePath(new File(str2));
this.fileName = FileHelper.a(str2);
}
private synchronized void modelActionOperator() {
LogUtils.c("开始动作同步逻辑1");
DiyDBModel selectUnique = DiyDBModelDBHandler.getInstance().selectUnique(this.userId, this.customModelId);
if (selectUnique != null && selectUnique.getStep3state().intValue() != 1) {
selectUnique.setStep3state(1);
DiyDBModelDBHandler.getInstance().update(selectUnique);
}
if (this.oType == 1) {
DiyModelAction diyModelAction = new DiyModelAction(this.userId, this.modelType, this.modelId, this.customModelId, this.fileName);
long insert = DiyModelActionDBHandler.getInstance().insert(diyModelAction);
if (this.modelId <= 0) {
return;
}
if ("local".equals(Cache.getInstance().getUserId())) {
return;
}
diyModelAction.setCustomActionId(Long.valueOf(insert));
DiyTransportServiceImpl.getInstance().uploadAction(diyModelAction, new TransportFile(this.userId, this.modelId, this.customModelId, String.valueOf(this.modelType), this.fileType, this.filePath, this.fileName));
} else if (this.oType == 2) {
DiyModelAction unique = DiyModelActionDBHandler.getInstance().unique(this.userId, this.modelType, this.customModelId, this.fileName);
if (unique == null) {
return;
}
long a = SystemUtils.a();
unique.setModifyTime(a);
unique.setLastUploadTime(a);
unique.setUploaded(false);
unique.setModify(true);
DiyModelActionDBHandler.getInstance().update(unique);
LogUtils.c("modelId:" + this.modelId);
if (this.modelId <= 0) {
return;
}
if ("local".equals(Cache.getInstance().getUserId())) {
return;
}
DiyTransportServiceImpl.getInstance().uploadAction(unique, new TransportFile(this.userId, this.modelId, this.customModelId, String.valueOf(this.modelType), this.fileType, this.filePath, this.fileName));
} else if (this.oType == 3) {
File file = new File(this.absoluteFilePath);
if (file.exists()) {
file.delete();
}
DiyModelAction unique2 = DiyModelActionDBHandler.getInstance().unique(this.userId, this.modelType, this.customModelId, this.fileName);
if (unique2 == null) {
return;
}
if (unique2.getServerId() == 0) {
DiyModelActionDBHandler.getInstance().delete(unique2);
return;
}
long a2 = SystemUtils.a();
unique2.setLastUploadTime(a2);
unique2.setModifyTime(a2);
unique2.setIsDeleted(1);
unique2.setModify(true);
DiyModelActionDBHandler.getInstance().update(unique2);
DiyTransportServiceImpl.getInstance().deleteAction(unique2);
}
}
private synchronized void modelFileOperator() {
DiyDBModel selectUnique = DiyDBModelDBHandler.getInstance().selectUnique(this.userId, this.customModelId);
if (selectUnique == null) {
return;
}
if (this.oType != 1) {
TransportFile transportModelFile = TransportFileDbHandler2.getInstance().getTransportModelFile(this.userId, this.customModelId, new File(this.absoluteFilePath));
if (transportModelFile == null) {
return;
}
long a = SystemUtils.a();
transportModelFile.setModifyTime(a);
transportModelFile.setLastUploadTime(a);
transportModelFile.setUploaded(false);
transportModelFile.setIsModify(true);
TransportFileDbHandler2.getInstance().update(transportModelFile);
if ("local".equals(Cache.getInstance().getUserId())) {
return;
}
if (selectUnique.getModelId() != null && selectUnique.getModelId().intValue() > 0) {
DiyTransportServiceImpl.getInstance().uploadModelFile(selectUnique, transportModelFile, null);
}
return;
}
LogUtils.c("modelFileOperator:filePath=" + this.filePath);
TransportFile transportFile = new TransportFile(this.userId, (long) selectUnique.getModelId().intValue(), this.customModelId, String.valueOf(this.modelType), this.fileType, this.filePath, this.fileName);
TransportFile selectUnique2 = TransportFileDbHandler2.getInstance().selectUnique(transportFile);
if (selectUnique2 != null) {
long a2 = SystemUtils.a();
selectUnique2.setModifyTime(a2);
selectUnique2.setLastUploadTime(a2);
selectUnique2.setUploaded(false);
selectUnique2.setIsModify(true);
TransportFileDbHandler2.getInstance().update(selectUnique2);
transportFile = selectUnique2;
} else {
transportFile.setCustomFileId(Long.valueOf(TransportFileDbHandler2.getInstance().insert(transportFile)));
}
if ("local".equals(Cache.getInstance().getUserId())) {
return;
}
if (selectUnique.getModelId() != null && selectUnique.getModelId().intValue() > 0) {
DiyTransportServiceImpl.getInstance().uploadModelFile(selectUnique, transportFile, null);
}
}
private synchronized void modifyModelBg() {
DiyDBModel selectUnique = DiyDBModelDBHandler.getInstance().selectUnique(this.userId, this.customModelId);
if (selectUnique == null) {
return;
}
TransportFile modelFile = TransportFileDbHandler2.getInstance().getModelFile(this.userId, this.customModelId, this.fileType);
if (modelFile == null) {
return;
}
long a = SystemUtils.a();
modelFile.setLastUploadTime(a);
modelFile.setModifyTime(a);
modelFile.setUploaded(false);
modelFile.setIsModify(true);
TransportFileDbHandler2.getInstance().update(modelFile);
selectUnique.setLastUploadTime(a);
selectUnique.setModifyTime(a);
selectUnique.setModify(true);
DiyDBModelDBHandler.getInstance().update(selectUnique);
if ("local".equals(Cache.getInstance().getUserId())) {
return;
}
if (selectUnique.getModelId() != null && selectUnique.getModelId().intValue() > 0) {
DiyTransportServiceImpl.getInstance().saveOrUpdateModel(selectUnique, modelFile, new DiyTransportServiceImpl.UploadStateListener() { // from class: com.ubt.jimu.transport3.UnityFileOperator.1
@Override // com.ubt.jimu.transport3.DiyTransportServiceImpl.UploadStateListener
public void onUploadComplete() {
}
@Override // com.ubt.jimu.transport3.DiyTransportServiceImpl.UploadStateListener
public void onUploadFailure() {
ALog.a(UnityFileOperator.TAG).d("修改模型logo失败");
}
@Override // com.ubt.jimu.transport3.DiyTransportServiceImpl.UploadStateListener
public void onUploadSucceed() {
ALog.a(UnityFileOperator.TAG).d("修改模型logo成功");
}
});
}
}
public synchronized void officialModelFileOperator() {
final String userId = Cache.getInstance().getUserId();
Robot robotByModelName = RobotDbHandler.getRobotByModelName(this.customModelId);
if (robotByModelName == null) {
return;
}
final long modelId = robotByModelName.getModelId();
if (modelId <= 0) {
return;
}
TransportFile transportFile = new TransportFile(userId, modelId, this.customModelId, "1", this.fileType, this.filePath, this.fileName);
TransportFile selectUnique = TransportFileDbHandler2.getInstance().selectUnique(transportFile);
if (selectUnique != null) {
long a = SystemUtils.a();
selectUnique.setModifyTime(a);
selectUnique.setLastUploadTime(a);
selectUnique.setFilePath(this.filePath);
selectUnique.setModelType("1");
selectUnique.setUploaded(false);
selectUnique.setIsModify(true);
TransportFileDbHandler2.getInstance().update(selectUnique);
transportFile = selectUnique;
} else {
transportFile.setCustomFileId(Long.valueOf(TransportFileDbHandler2.getInstance().insert(transportFile)));
}
if (!TextUtils.isEmpty(userId) && !"local".equals(userId)) {
final TransportFile transportFile2 = transportFile;
DiyTransportServiceImpl.getInstance().uploadFile(transportFile, new SimpleUploadCallback() { // from class: com.ubt.jimu.transport3.UnityFileOperator.2
@Override // com.ubt.jimu.upload.IUploadCallback
public void uploadFaulted(UploadRequest uploadRequest, Exception exc) {
}
@Override // com.ubt.jimu.upload.IUploadCallback
public void uploadSucceed(UploadResponse uploadResponse) {
transportFile2.setFileUrl(uploadResponse.c());
transportFile2.setModelType("1");
transportFile2.setUploaded(true);
if (transportFile2.getModelId() <= 0) {
transportFile2.setModelId(modelId);
}
TransportFileDbHandler2.getInstance().update(transportFile2);
ArrayList arrayList = new ArrayList();
arrayList.add(transportFile2);
UploadModelFileBean uploadModelFileBean = new UploadModelFileBean(userId, Cache.getInstance().getUserToken(), (int) modelId, UnityFileOperator.this.customModelId);
if (transportFile2.getId() >= 1) {
uploadModelFileBean.setUpdateFiles(arrayList);
} else {
uploadModelFileBean.setAddFiles(arrayList);
}
DiyTransportServiceImpl.getInstance().syncOfficialModelFileToService(uploadModelFileBean, transportFile2);
}
});
}
}
/* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
public void operateFile() {
char c;
LogUtils.c("fileType:" + this.fileType + " opType:" + this.oType + " " + this.filePath + " customModelId:" + this.customModelId + " modelId:" + this.modelId);
String str = this.fileType;
switch (str.hashCode()) {
case -1422950858:
if (str.equals("action")) {
c = 5;
break;
}
c = 65535;
break;
case 3141:
if (str.equals("bg")) {
c = 0;
break;
}
c = 65535;
break;
case 3059500:
if (str.equals("conn")) {
c = 1;
break;
}
c = 65535;
break;
case 3079825:
if (str.equals("desc")) {
c = 2;
break;
}
c = 65535;
break;
case 637428636:
if (str.equals(TransportFile.TYPE_CONTROLLER)) {
c = 3;
break;
}
c = 65535;
break;
case 644351654:
if (str.equals("widgetConfig")) {
c = 4;
break;
}
c = 65535;
break;
default:
c = 65535;
break;
}
if (c == 0) {
modifyModelBg();
return;
}
if (c == 1 || c == 2 || c == 3 || c == 4) {
modelFileOperator();
} else {
if (c != 5) {
return;
}
modelActionOperator();
LogUtils.c("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1111");
}
}
}