177 lines
7.7 KiB
Java
177 lines
7.7 KiB
Java
package com.ubt.jimu.transport3.dao;
|
|
|
|
import android.text.TextUtils;
|
|
import com.ubt.jimu.base.cache.Cache;
|
|
import com.ubt.jimu.base.db.AbstractDaoHandler;
|
|
import com.ubt.jimu.base.db.DatabaseUtils;
|
|
import com.ubt.jimu.blockly.networkSync.utils.QiNiuUtils;
|
|
import com.ubt.jimu.gen.DiyModelActionDao;
|
|
import com.ubt.jimu.transport3.model.DiyModelAction;
|
|
import com.ubt.jimu.utils.LogUtils;
|
|
import java.io.File;
|
|
import java.util.List;
|
|
import org.greenrobot.greendao.AbstractDao;
|
|
import org.greenrobot.greendao.query.QueryBuilder;
|
|
import org.greenrobot.greendao.query.WhereCondition;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class DiyModelActionDBHandler extends AbstractDaoHandler<DiyModelAction> {
|
|
private static final String TAG = "DiyModelActionDBHandler";
|
|
private static DiyModelActionDBHandler diyModelActionDBHandler;
|
|
|
|
public DiyModelActionDBHandler(AbstractDao<DiyModelAction, Long> abstractDao) {
|
|
super(abstractDao);
|
|
}
|
|
|
|
public static synchronized DiyModelActionDBHandler getInstance() {
|
|
DiyModelActionDBHandler diyModelActionDBHandler2;
|
|
synchronized (DiyModelActionDBHandler.class) {
|
|
if (diyModelActionDBHandler == null) {
|
|
diyModelActionDBHandler = new DiyModelActionDBHandler(DatabaseUtils.getDaoSession(true).f());
|
|
}
|
|
diyModelActionDBHandler2 = diyModelActionDBHandler;
|
|
}
|
|
return diyModelActionDBHandler2;
|
|
}
|
|
|
|
public void deleteAction(List<DiyModelAction> list) {
|
|
if (list == null || list.size() == 0) {
|
|
return;
|
|
}
|
|
for (DiyModelAction diyModelAction : list) {
|
|
if (diyModelAction != null) {
|
|
deleteModelAction(diyModelAction);
|
|
}
|
|
}
|
|
}
|
|
|
|
public boolean deleteModelAction(DiyModelAction diyModelAction) {
|
|
DiyModelAction selectUnique;
|
|
if (diyModelAction == null || (selectUnique = selectUnique(diyModelAction)) == null) {
|
|
return false;
|
|
}
|
|
delete(selectUnique);
|
|
String str = QiNiuUtils.getAndroidSystemRootPath() + QiNiuUtils.getDiyActionLoaclPath(selectUnique);
|
|
LogUtils.c("删除动作:" + str);
|
|
File file = new File(str);
|
|
if (!file.exists()) {
|
|
return true;
|
|
}
|
|
file.delete();
|
|
return true;
|
|
}
|
|
|
|
public void deleteModelActions(String str, int i, String str2) {
|
|
List<DiyModelAction> modelActions = getModelActions(str, i, str2);
|
|
if (modelActions == null || modelActions.size() == 0) {
|
|
return;
|
|
}
|
|
deleteAction(modelActions);
|
|
}
|
|
|
|
public List<DiyModelAction> getAllOfflineUpdateBean() {
|
|
String userId = Cache.getInstance().getUserId();
|
|
if (TextUtils.isEmpty(userId)) {
|
|
userId = "local";
|
|
}
|
|
QueryBuilder k = this.dao.k();
|
|
k.a(DiyModelActionDao.Properties.UserId.a((Object) userId), DiyModelActionDao.Properties.ModelId.b(0), DiyModelActionDao.Properties.ServerId.a((Object) 1), DiyModelActionDao.Properties.Modify.a((Object) 1));
|
|
return query(k);
|
|
}
|
|
|
|
public List<DiyModelAction> getModelActions(String str, int i, String str2) {
|
|
QueryBuilder k = this.dao.k();
|
|
k.a(DiyModelActionDao.Properties.UserId.a((Object) str), DiyModelActionDao.Properties.ModelType.a(Integer.valueOf(i)), DiyModelActionDao.Properties.CustomModelId.a((Object) str2));
|
|
return query(k);
|
|
}
|
|
|
|
public List<DiyModelAction> getQiNiuActionDB() {
|
|
String userId = Cache.getInstance().getUserId();
|
|
if (TextUtils.isEmpty(userId)) {
|
|
userId = "local";
|
|
}
|
|
QueryBuilder k = this.dao.k();
|
|
k.a(DiyModelActionDao.Properties.UserId.a((Object) userId), DiyModelActionDao.Properties.ModelId.b(0), DiyModelActionDao.Properties.ServerId.a((Object) 0), DiyModelActionDao.Properties.Uploaded.a((Object) 0), DiyModelActionDao.Properties.Modify.a((Object) 1));
|
|
return query(k);
|
|
}
|
|
|
|
public List<DiyModelAction> getSyncServiceActionDB() {
|
|
String userId = Cache.getInstance().getUserId();
|
|
if (TextUtils.isEmpty(userId)) {
|
|
userId = "local";
|
|
}
|
|
QueryBuilder k = this.dao.k();
|
|
k.a(DiyModelActionDao.Properties.UserId.a((Object) userId), DiyModelActionDao.Properties.ModelId.b(0), DiyModelActionDao.Properties.Uploaded.a((Object) 1), DiyModelActionDao.Properties.ServerId.a((Object) 0), DiyModelActionDao.Properties.Modify.a((Object) 1));
|
|
return query(k);
|
|
}
|
|
|
|
public List<DiyModelAction> getUserActions(String str) {
|
|
QueryBuilder k = this.dao.k();
|
|
k.a(DiyModelActionDao.Properties.UserId.a((Object) str), new WhereCondition[0]);
|
|
return query(k);
|
|
}
|
|
|
|
public void insertOrUpdateActionDB(DiyModelAction diyModelAction) {
|
|
LogUtils.c("查询数据库 userId:" + diyModelAction.getUserId() + " CustomModelId:" + diyModelAction.getCustomModelId() + " FileName:" + diyModelAction.getFileName() + " ModelType:" + diyModelAction.getModelType());
|
|
DiyModelAction selectUnique = selectUnique(diyModelAction);
|
|
if (selectUnique == null) {
|
|
insert(diyModelAction);
|
|
return;
|
|
}
|
|
selectUnique.setId(diyModelAction.getId());
|
|
selectUnique.setServerId(1L);
|
|
selectUnique.setModelId(diyModelAction.getModelId());
|
|
selectUnique.setFileUrl(diyModelAction.getFileUrl());
|
|
selectUnique.setCreateTime(diyModelAction.getCreateTime());
|
|
selectUnique.setModifyTime(diyModelAction.getModifyTime());
|
|
selectUnique.setLastUploadTime(diyModelAction.getLastUploadTime());
|
|
selectUnique.setModify(diyModelAction.getModify());
|
|
selectUnique.setUploaded(diyModelAction.getUploaded());
|
|
update(selectUnique);
|
|
}
|
|
|
|
public DiyModelAction unique(String str, int i, String str2, String str3) {
|
|
QueryBuilder k = this.dao.k();
|
|
k.a(DiyModelActionDao.Properties.UserId.a((Object) str), DiyModelActionDao.Properties.ModelType.a(Integer.valueOf(i)), DiyModelActionDao.Properties.CustomModelId.a((Object) str2), DiyModelActionDao.Properties.FileName.a((Object) str3));
|
|
return unique(k);
|
|
}
|
|
|
|
public boolean updateQiNiuState(DiyModelAction diyModelAction) {
|
|
if (diyModelAction == null) {
|
|
return false;
|
|
}
|
|
String userId = Cache.getInstance().getUserId();
|
|
QueryBuilder k = this.dao.k();
|
|
k.a(DiyModelActionDao.Properties.UserId.a((Object) userId), DiyModelActionDao.Properties.CustomModelId.a((Object) diyModelAction.getCustomModelId()), DiyModelActionDao.Properties.FileName.a((Object) diyModelAction.getFileName()));
|
|
DiyModelAction unique = unique(k);
|
|
if (unique == null) {
|
|
return false;
|
|
}
|
|
update(unique);
|
|
return true;
|
|
}
|
|
|
|
public void uploadUserIdAndModelId(String str, int i) {
|
|
String userId = Cache.getInstance().getUserId();
|
|
if (i <= 0) {
|
|
return;
|
|
}
|
|
QueryBuilder k = this.dao.k();
|
|
k.a(DiyModelActionDao.Properties.CustomModelId.a((Object) str), DiyModelActionDao.Properties.Uploaded.a((Object) 0), DiyModelActionDao.Properties.Modify.a((Object) 1));
|
|
List<DiyModelAction> query = query(k);
|
|
if (query == null || query.size() == 0) {
|
|
return;
|
|
}
|
|
for (DiyModelAction diyModelAction : query) {
|
|
diyModelAction.setUserId(userId);
|
|
diyModelAction.setModelId(i);
|
|
insertOrUpdate(diyModelAction);
|
|
}
|
|
}
|
|
|
|
@Override // com.ubt.jimu.base.db.AbstractDaoHandler, com.ubt.jimu.base.db.IDaoHandler
|
|
public DiyModelAction selectUnique(DiyModelAction diyModelAction) {
|
|
return unique(diyModelAction.getUserId(), diyModelAction.getModelType(), diyModelAction.getCustomModelId(), diyModelAction.getFileName());
|
|
}
|
|
}
|