package com.ubt.jimu.base.db.robot; import com.ubt.jimu.base.db.AbstractDaoHandler; import com.ubt.jimu.base.db.DatabaseUtils; import com.ubt.jimu.base.entities.Robot; import com.ubt.jimu.gen.RobotDao; import java.util.Iterator; import java.util.List; import org.greenrobot.greendao.AbstractDao; import org.greenrobot.greendao.query.QueryBuilder; import org.greenrobot.greendao.query.WhereCondition; /* loaded from: classes.dex */ public class RobotDbHandler extends AbstractDaoHandler { private static RobotDbHandler instance; public RobotDbHandler(AbstractDao abstractDao) { super(abstractDao); } public static synchronized RobotDbHandler getInstance() { RobotDbHandler robotDbHandler; synchronized (RobotDbHandler.class) { if (instance == null) { instance = new RobotDbHandler(DatabaseUtils.getDaoSession(true).s()); } robotDbHandler = instance; } return robotDbHandler; } public static Robot getRobotById(long j) { QueryBuilder k = DatabaseUtils.getDaoSession(true).s().k(); k.a(RobotDao.Properties.ModelId.a(Long.valueOf(j)), new WhereCondition[0]); return k.c(); } public static Robot getRobotByModelName(String str) { QueryBuilder k = DatabaseUtils.getDaoSession(true).s().k(); k.a(RobotDao.Properties.ModelName.a((Object) str), new WhereCondition[0]); return k.c(); } public static List getRobotList(long j) { try { return DatabaseUtils.getDaoSession(true).q().h(Long.valueOf(j)).getRobotList(); } catch (Exception e) { e.printStackTrace(); return null; } } public static void saveOrUpdate(List list) { try { RobotDao s = DatabaseUtils.getDaoSession(true).s(); List j = s.j(); if (j == null || j.size() == 0) { s.c((Iterable) list); } for (Robot robot : list) { Iterator it = j.iterator(); while (true) { if (it.hasNext()) { Robot next = it.next(); if (robot.getModelId() == next.getModelId()) { robot.setDownload(next.getDownload() && robot.getModelUpdateTime() == next.getModelUpdateTime()); } } } } s.c((Iterable) list); } catch (Exception e) { e.printStackTrace(); } } public static void setRobotDownloadState(Robot robot) { RobotDao s = DatabaseUtils.getDaoSession(true).s(); QueryBuilder k = s.k(); k.a(RobotDao.Properties.ModelName.a((Object) robot.getModelName()), new WhereCondition[0]); List b = k.b(); if (b == null || b.size() <= 0) { return; } Iterator it = b.iterator(); while (it.hasNext()) { it.next().setDownload(robot.getDownload()); } s.d((Iterable) b); } @Override // com.ubt.jimu.base.db.AbstractDaoHandler, com.ubt.jimu.base.db.IDaoHandler public Robot selectUnique(Robot robot) { QueryBuilder k = this.dao.k(); k.a(RobotDao.Properties.ModelId.a(Long.valueOf(robot.getModelId())), new WhereCondition[0]); return (Robot) k.c(); } }