From 4f9ad0b84dec1e6ad65ddc8c18ec298ddaa0827a Mon Sep 17 00:00:00 2001 From: whyclj <1525436766@qq.com> Date: 星期三, 20 十一月 2019 15:30:32 +0800 Subject: [PATCH] 修改1111 --- platforms/android/app/src/main/java/com/socket/FBS9600S_DeviceService.java | 141 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 139 insertions(+), 2 deletions(-) diff --git a/platforms/android/app/src/main/java/com/socket/FBS9600S_DeviceService.java b/platforms/android/app/src/main/java/com/socket/FBS9600S_DeviceService.java index 98b9b81..cf2745c 100644 --- a/platforms/android/app/src/main/java/com/socket/FBS9600S_DeviceService.java +++ b/platforms/android/app/src/main/java/com/socket/FBS9600S_DeviceService.java @@ -1,5 +1,8 @@ package com.socket; +import android.database.Cursor; +import android.database.SQLException; +import android.database.sqlite.SQLiteDatabase; import android.drm.DrmStore; import android.webkit.JavascriptInterface; import android.webkit.WebView; @@ -7,8 +10,12 @@ import com.fgkj.action.ServiceModel; import com.fgkj.dao.ActionUtil; import com.fgkj.dao.DBHelper; +import com.fgkj.dto.Battinf; +import com.fgkj.impl.BattinfImpl; +import com.util.Com; import java.util.ArrayList; +import java.util.Date; import java.util.List; public class FBS9600S_DeviceService { @@ -28,14 +35,20 @@ thread.start(); } allBattDatt.get(0).isInstall = true; + + List<Battinf> list = queryAllBattInf(dbHelper); //鏌ヨ鏁版嵁搴撲腑鐨勬墍鏈夌數姹犵粍淇℃伅 + + List<Battinf> temps = initBattInfo(allBattDatt,list); + + insertBattinf(dbHelper,temps); } //璇诲彇绯荤粺鐘舵�� @JavascriptInterface public void readSystemState(String index){ int battindex = Integer.parseInt(index); - if(battindex>0 && battindex <= MAXCONCENTRATORCOUNT){ - allBattDatt.get(battindex-1).readSystemState("readSystemState"); + if(battindex > 0 && battindex <= MAXCONCENTRATORCOUNT){ + allBattDatt.get(battindex - 1).readSystemState("readSystemState"); } } @@ -95,4 +108,128 @@ allBattDatt.get(battindex-1).reStartSystem("reStartSystem"); } } + + + /** + * 鍖归厤鐢垫睜淇℃伅閰嶇疆涓殑淇℃伅 + * @param battDatas + * @param list + */ + public List<Battinf> initBattInfo(List<BattDataThread> battDatas,List<Battinf> list){ + List<Battinf> battinfs = new ArrayList<>(); + for(int i = 0;i<battDatas.size();i++){ + BattDataThread battData = battDatas.get(i); + Battinf battinf = null; + for(int k = 0;k<list.size();k++){ + if(list.get(k).getBattGroupId() == battData.battIndex){ + battinf = list.get(i); + } + } + if(battinf != null){ + battinfs.add(battinf); + battData.isInstall = battinf.getStation_install() == 1; //鏄惁鏄凡瀹夎 + battData.state.monCount = battinf.getMonCount(); //褰撳墠鍗曚綋鏁扮洰 + }else{ + Battinf temp = new Battinf(); + temp.setStation_install(battData.isInstall?1:0); + temp.setBattGroupId(i+1); + temp.setBattFloatCurrent(3); + temp.setBattGroupName1("鐢垫睜缁�"); + temp.setBattGroupName("鐢垫睜缁�"+(i+1)); + temp.setBattInUseDate(new Date()); + temp.setBattProducer(""); + temp.setMonCapStd(100); + temp.setMonCount(24); + temp.setMonVolStd(2); + temp.setMonResStd(0.2); + temp.setMonSerStd(5000); + temp.setMonTmpStd(24); + battinfs.add(temp); + } + } + return battinfs; + } + + /** + * 鏌ヨ鏁版嵁搴撲腑鐨勬墍鏈夌數姹犵粍淇℃伅 + * @param dbHelper + * @return + */ + public List<Battinf> queryAllBattInf(DBHelper dbHelper){ + List<Battinf> battinfs = new ArrayList<>(); + String sql_str = "SELECT * FROM tb_battinf ORDER BY BattGroupId ASC"; + SQLiteDatabase db = dbHelper.getWritableDatabase(); + Cursor rs = null; + try { + rs = db.rawQuery(sql_str,null); + while(rs.moveToNext()){ + Battinf battinf = new Battinf(); + battinf.setNum(rs.getInt(rs.getColumnIndex("num"))); + battinf.setMonVolStd(rs.getDouble(rs.getColumnIndex("MonVolStd"))); + battinf.setStation_install(rs.getInt(rs.getColumnIndex("station_install"))); + battinf.setMonTmpStd(rs.getDouble(rs.getColumnIndex("MonTmpStd"))); + battinf.setMonSerStd(rs.getDouble(rs.getColumnIndex("MonSerStd"))); + battinf.setMonResStd(rs.getDouble(rs.getColumnIndex("MonResStd"))); + battinf.setMonCount(rs.getInt(rs.getColumnIndex("MonCount"))); + battinf.setMonCapStd(rs.getDouble(rs.getColumnIndex("MonCapStd"))); + battinf.setBattProducer(rs.getString(rs.getColumnIndex("BattProducer"))); + Date date= ActionUtil.sdfwithOut.parse( rs.getString(rs.getColumnIndex("BattInUseDate"))); + battinf.setBattInUseDate(date); + battinf.setBattGroupName1(rs.getString(rs.getColumnIndex("BattGroupName1"))); + battinf.setBattGroupName(rs.getString(rs.getColumnIndex("BattGroupName"))); + battinf.setBattFloatCurrent(rs.getDouble(rs.getColumnIndex("BattFloatCurrent"))); + battinf.setBattGroupId(rs.getInt(rs.getColumnIndex("BattGroupId"))); + battinfs.add(battinf); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if(rs != null){ + rs.close(); + } + if(db != null){ + db.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + return battinfs; + } + + /** + * 鎻掑叆鐢垫睜缁勪俊鎭� + * @param dbHelper + * @param list + */ + public void insertBattinf(DBHelper dbHelper,List<Battinf> list){ + boolean start = true; + String sql_str_start = " INSERT INTO tb_battinf(BattGroupId,BattGroupName,BattGroupName1,BattFloatCurrent,MonCount,MonCapStd,MonVolStd,MonResStd,MonSerStd,MonTmpStd,BattProducer,BattInUseDate,station_install) VALUES "; + for(int i = 0;i<list.size();i++){ + if(list.get(i).getNum() == 0){ + Battinf temp = list.get(i); + //闇�瑕佸綍鍏ョ殑鐢垫睜缁� + if(start){ + start = false; + }else{ + sql_str_start += ","; + } + sql_str_start += "("+temp.getBattGroupId()+",'"+temp.getBattGroupName()+"','"+temp.getBattGroupName1()+"',"+temp.getBattFloatCurrent()+","+temp.getMonCount()+","+temp.getMonCapStd()+","+temp.getMonVolStd()+","+temp.getMonResStd()+","+temp.getMonSerStd()+","+temp.getMonTmpStd()+",'"+temp.getBattProducer()+"','"+ Com.getDateTimeFormat(temp.getBattInUseDate(),Com.DTF_YMDhms)+"',"+temp.getStation_install()+")"; + } + } + if(!start){ + SQLiteDatabase db = null; + try { + db = dbHelper.getWritableDatabase(); + db.execSQL(sql_str_start); + } catch (SQLException e) { + e.printStackTrace(); + } finally{ + if(db != null){ + db.close(); + } + } + } + } } -- Gitblit v1.9.1