| | |
| | | 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;
|
| | |
| | | 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 {
|
| | |
| | | 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");
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | 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();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|