package com.ubt.jimu.transport3.upgrade; 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.blockly.bean.BlocklyProject; import com.ubt.jimu.blockly.bean.JimuMotion; import com.ubt.jimu.blockly.bean.JimuSound; import com.ubt.jimu.blockly.dao.BlocklyProjectDbHandler; import com.ubt.jimu.blockly.dao.JimuMotionDbHandler; import com.ubt.jimu.blockly.dao.JimuSoundDbHandler; import com.ubt.jimu.gen.TransportFileDao; import com.ubt.jimu.transport.dao.ConfigItemDbHandler; import com.ubt.jimu.transport.model.TransportFile; import com.ubt.jimu.transport3.dao.DiyDBModelDBHandler; import com.ubt.jimu.transport3.dao.TransportFileDbHandler2; import com.ubt.jimu.utils.SystemUtils; import com.ubtech.utils.StringUtils; import com.ubtrobot.log.ALog; import java.util.HashMap; import java.util.List; import org.greenrobot.greendao.query.QueryBuilder; import org.greenrobot.greendao.query.WhereCondition; /* loaded from: classes2.dex */ public class BlocklyUpgrade { private final String TAG = "upgrade"; private BlocklyProjectDbHandler programDbHandler = BlocklyProjectDbHandler.getInstance(); private DiyDBModelDBHandler modelDBHandler = DiyDBModelDBHandler.getInstance(); private ConfigItemDbHandler itemDbHandler = ConfigItemDbHandler.getInstance(); private TransportFileDbHandler2 fileDbHandler = TransportFileDbHandler2.getInstance(); private JimuSoundDbHandler soundDbHandler = JimuSoundDbHandler.getInstance(); private JimuMotionDbHandler motionDbHandler = JimuMotionDbHandler.getInstance(); private static class Model { public String customModelId; public long modelId; public Model(String str, long j) { this.customModelId = str; this.modelId = j; } } private void tableBlockly() { try { List selectAll = this.programDbHandler.selectAll(); if (selectAll != null && selectAll.size() != 0) { List selectAll2 = this.modelDBHandler.selectAll(); HashMap hashMap = new HashMap(); if (selectAll2 != null && selectAll2.size() > 0) { for (DiyDBModel diyDBModel : selectAll2) { hashMap.put(diyDBModel.getCustomModelId(), diyDBModel); } } long a = SystemUtils.a(); for (BlocklyProject blocklyProject : selectAll) { long j = 0; if (StringUtils.f(blocklyProject.getCustomModelId())) { DiyDBModel diyDBModel2 = (DiyDBModel) hashMap.get(blocklyProject.getCustomModelId()); if (diyDBModel2.getModelId() != null) { j = diyDBModel2.getModelId().intValue(); } } else { QueryBuilder queryBuilder = this.fileDbHandler.getQueryBuilder(); queryBuilder.a(TransportFileDao.Properties.FileName.a((Object) (blocklyProject.getXmlId() + ".xml")), new WhereCondition[0]); List query = this.fileDbHandler.query(queryBuilder); if (query != null && query.size() > 0) { j = query.get(0).getModelId(); } } blocklyProject.setModelId(j); blocklyProject.setLastUploadTime(a); blocklyProject.setIsModify(true); blocklyProject.setIsUploadQiNiu(false); blocklyProject.setIsUploadService(false); blocklyProject.setIsFirst(0); } this.programDbHandler.updateInTx(selectAll); ALog.a("upgrade").d("编程案例升级:" + selectAll.size()); return; } ALog.a("upgrade").d("编程案例升级:0"); } catch (Exception e) { e.printStackTrace(); } } private void tableJimuMotion() { try { List selectAll = this.motionDbHandler.selectAll(); if (selectAll != null && selectAll.size() != 0) { List selectAll2 = RobotDbHandler.getInstance().selectAll(); List selectAll3 = DiyDBModelDBHandler.getInstance().selectAll(); HashMap hashMap = new HashMap(); if (selectAll2 != null && selectAll2.size() > 0) { for (Robot robot : selectAll2) { hashMap.put(robot.getModelName(), new Model(robot.getModelName(), robot.getModelId())); } } if (selectAll3 != null && selectAll3.size() > 0) { for (DiyDBModel diyDBModel : selectAll3) { hashMap.put(diyDBModel.getCustomModelId(), new Model(diyDBModel.getCustomModelId(), diyDBModel.getModelId().intValue())); } } long a = SystemUtils.a(); for (JimuMotion jimuMotion : selectAll) { jimuMotion.setLastUploadTime(a); jimuMotion.setIsFirst(0); jimuMotion.setIsUploadService(false); ALog.a("upgrade").d("JimuMotion: " + jimuMotion.getActionName() + " " + jimuMotion.getActionID()); Model model = (Model) hashMap.get(jimuMotion.getCustomModelId()); if (model != null) { jimuMotion.setModelId((int) model.modelId); } } this.motionDbHandler.updateInTx(selectAll); return; } ALog.a("upgrade").d("动作帧升级:0"); } catch (Exception e) { e.printStackTrace(); } } private void tableJimuSound() { try { List selectAll = this.soundDbHandler.selectAll(); if (selectAll != null && selectAll.size() != 0) { long a = SystemUtils.a(); for (JimuSound jimuSound : selectAll) { jimuSound.setLastUploadTime(a); jimuSound.setUploadQiNiu(false); jimuSound.setSyncUbtService(false); jimuSound.setIsFirst(0); jimuSound.setAudioId(jimuSound.getKey()); ALog.a("upgrade").d("JimuSound:" + jimuSound.getDescription() + " " + jimuSound.getKey()); } this.soundDbHandler.updateInTx(selectAll); ALog.a("upgrade").d("录音升级:" + selectAll.size()); return; } ALog.a("upgrade").d("录音升级:0"); } catch (Exception e) { e.printStackTrace(); } } public void upgrade() { tableBlockly(); tableJimuSound(); tableJimuMotion(); } }