diff --git a/app/build.gradle b/app/build.gradle index 510b40ef..f32f100a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -170,4 +170,10 @@ dependencies { //gif加载包 implementation 'com.github.bumptech.glide:glide:4.9.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0' + + //曲线 + implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' + +// //sqlite orm 框架 +// implementation 'org.greenrobot:greendao:3.2.2' } diff --git a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java index 6e5452c3..e1fffdc9 100644 --- a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java +++ b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java @@ -72,6 +72,11 @@ public class ConfigName { * Db文件路径 */ public static String dbPath = ""; + + /** + * 设备过程数据DB文件路径 + */ + public static String DeviceDataDbPath=""; //endregion //region 店铺配置 diff --git a/app/src/main/java/com/bonait/bnframework/common/db/DbBase.java b/app/src/main/java/com/bonait/bnframework/common/db/DbBase.java new file mode 100644 index 00000000..d4c16345 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/db/DbBase.java @@ -0,0 +1,138 @@ +package com.bonait.bnframework.common.db; + +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.util.Log; + +import com.bonait.bnframework.common.constant.ConfigName; +import com.bonait.bnframework.common.db.file.Feild; +import com.bonait.bnframework.common.db.file.Table; +import com.bonait.bnframework.common.db.mode.BPA_PRODUCTION_DATA; + +import java.io.File; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public class DbBase extends SQLiteOpenHelper { + + public DbBase(String path) { + super(ConfigName.getInstance().dishesCon, path, null, 4); + filePath = path; + } + + private String filePath ; + + /** + * 加锁 + */ + public static Lock lock = new ReentrantLock(); //注意这个地方 + + private List tables = new ArrayList<>(); + + public void AddTable(Class table) + { + tables.add(table); + } + + public void Init(){ + File file = new File(filePath); + if(!file.exists())//文件不存在那么创建数据库 + { + Log.i("日志","初始化数据库:文件不存在准备新建!"); + //1.复制本地文件到SD卡 +// copyFilesFassets(ConfigName.getInstance().dishesCon, ConfigName.getInstance().dbPath); + CreateTables();//2.创建数据库结构 + } + Log.i("日志","初始化数据库目录:"+filePath); + } + + @Override + public void onCreate(SQLiteDatabase sqLiteDatabase) { + createTables(sqLiteDatabase, prepareTableInfo()); + } + + @Override + public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { + + } + + private ArrayList prepareTableInfo() { + ArrayList
tables = new ArrayList
(); + Table t; + return tables; + } + + + /** + * 创建数据表 + * @param db 数据库名称 + * @param tables 所要创建的数据库表列表 + */ + private void createTables(SQLiteDatabase db, ArrayList
tables) { + db.beginTransaction(); + for (Table table : tables) { + db.execSQL(table.createSQL("")); + } + db.setTransactionSuccessful(); + db.endTransaction(); + } + + /** + * 开启外键约束 + */ + private void ForeignKeys(){ + SQLiteDatabase db =this.getWritableDatabase(); + db.beginTransaction(); + db.execSQL("PRAGMA foreign_keys = 1"); + db.setTransactionSuccessful(); + db.endTransaction(); + } + + /** + * 创建数据库表 + */ + private void CreateTables() + { + tables.forEach(item->{ + CreateTablesAll(item,null); + }); + +// CreateTablesAll(BPA_PRODUCTION_DATA.class,null);//创建过程数据表 + ForeignKeys(); + } + + /** + * 创建数据库表 + * @param c + */ + private void CreateTablesAll(Class c,String premarykey) + { + if (premarykey == null){ + premarykey=""; + } + SQLiteDatabase db =this.getWritableDatabase(); + db.beginTransaction(); + String TabName= c.getSimpleName();//表名称 + ArrayList
tables = new ArrayList
(); + Table t; + t = new Table(TabName); // 创建表名称 + for (Field field : c.getFields()){ + String name=field.getName(); + String type=field.getType().getSimpleName(); + if(type.equals("String") || type.equals("Date")) + { + type="text"; + } + t.addFeild(new Feild(name, type)); // 字段名称 + } + tables.add(t); + for (Table table : tables) { + db.execSQL(table.createSQL(premarykey)); + } + db.setTransactionSuccessful(); + db.endTransaction(); + } +} diff --git a/app/src/main/java/com/bonait/bnframework/common/db/DeviceDataDb.java b/app/src/main/java/com/bonait/bnframework/common/db/DeviceDataDb.java new file mode 100644 index 00000000..18219039 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/db/DeviceDataDb.java @@ -0,0 +1,321 @@ +package com.bonait.bnframework.common.db; + +import android.content.ContentValues; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.util.Log; + +import com.bonait.bnframework.common.constant.ConfigName; +import com.bonait.bnframework.common.db.mode.BPA_ALARM_DATA; +import com.bonait.bnframework.common.db.mode.BPA_PRODUCTION_DATA; +import com.bonait.bnframework.common.helper.SdCart; +import com.bonait.bnframework.common.helper.Tools; +import com.google.gson.Gson; + +import java.lang.reflect.Field; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.Random; + +public class DeviceDataDb extends DbBase { + + private volatile static DeviceDataDb instance; + + public synchronized static DeviceDataDb get() { + if(instance==null){ + String filePath = SdCart.getInstance().getDbPath("hblxiaochaodb","DeviceDataDb.db"); + instance = new DeviceDataDb( filePath); + } + return instance; + } + private DeviceDataDb(String path) { + super(path); + AddTable(BPA_PRODUCTION_DATA.class);//添加过程数据表 + AddTable(BPA_ALARM_DATA.class);//添加报警数据表 +// Init(); + } + + //region 过程数据 + private List Productions=new ArrayList(); + + public void ResetProduction(){ + Productions.clear(); + } + + public void AddProduction(BPA_PRODUCTION_DATA data) { + if (data == null) return; + Productions.add(data); + } + + public void SaveProduction(){ + if(Productions==null||Productions.size()==0) return; + List temp=new ArrayList(); + BPA_PRODUCTION_DATA tempData = new BPA_PRODUCTION_DATA(); + if(Productions.size()>0){ + tempData.goodName=Productions.get(0).goodName; + tempData.startTime=Productions.get(0).startTime; + } + List weight=new ArrayList<>(); + Listtemperature=new ArrayList<>(); + Productions.forEach(item->{ + weight.add(Float.parseFloat(item.weight)); + temperature.add(Float.parseFloat(item.temperature)); + }); + tempData.weight=new Gson().toJson(weight); + tempData.temperature=new Gson().toJson(temperature); + tempData.endTime=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + temp.add(tempData); + BatchAddProduction(temp); + Productions.clear(); + } + + public List ReadProduction(String startTime, String endTime,String goodName){ + return getProductionData(startTime,endTime,goodName); + } + + /** + * 批量新增 + * @param data + * @return + */ + private boolean BatchAddProduction( List data) { + lock.lock(); + boolean isSucess = false; + SQLiteDatabase db = getWritableDatabase(); + try { + ContentValues cv = new ContentValues(); + db.beginTransaction();//使用beginTransaction()方法开始事务操作。 + long result=-1; + for (int i = 0; i < data.size(); i++) { + Map map = Tools.getObjValue(data.get(i)); + for (String key : map.keySet()) { + Object value = map.get(key); + if (value instanceof String) { + cv.put(key, (String) value); + } else if (value instanceof Integer) { + cv.put(key, ((Integer) value).intValue()); + } else if (value instanceof Double) { + cv.put(key, ((Double) value).doubleValue()); + } else if (value instanceof Float) { + cv.put(key, ((Float) value).floatValue()); + } else if (value instanceof Long) { + cv.put(key, ((Long) value).longValue()); + } else if (value instanceof Boolean) { + cv.put(key, ((Boolean) value).booleanValue()); + } + } + + result = db.insertOrThrow(BPA_PRODUCTION_DATA.class.getSimpleName(), null, cv); + if (result == -1) { + throw new Exception("Failed to insert data at index " + i); + } + } + db.setTransactionSuccessful();//如果需要提交更改,则使用setTransactionSuccessful()方法标记当前事务已经成功。 + isSucess= result > 0; + } catch (Exception e) { + db.close(); + isSucess= false; + }finally { + db.endTransaction();//结束事务 + db.close();//关闭连接 + lock.unlock(); + } + db.close(); + return isSucess; + } + + /** + * 根据条件获取数据 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @param goodName 配方名称 + * @return + */ + private List getProductionData(String startTime, String endTime,String goodName){ + lock.lock(); + List res = new ArrayList<>(); + SQLiteDatabase db = getReadableDatabase(); + try { + List col = new ArrayList<>(); + for (Field field : BPA_PRODUCTION_DATA.class.getFields()) { + col.add(field.getName()); + } + String[] columns = (String[]) col.toArray(new String[col.size()]); + String orderby = "startTime";//出料顺序 + String where=""; + String[] args=new String[]{}; + if(!startTime.isEmpty()){ + where+="startTime>=?"; + args=new String[]{startTime}; + } + + if (!goodName.isEmpty()) { + where+=" and goodName=?"; + args=new String[]{startTime,endTime,goodName}; + } + + if(where.isEmpty()) return new ArrayList<>(); + if(args.length<=0) return new ArrayList<>(); + + Cursor cursor = db.query(BPA_PRODUCTION_DATA.class.getSimpleName(), columns, where, args, null,null, orderby, null); + + while (cursor.moveToNext()) { + BPA_PRODUCTION_DATA data = new BPA_PRODUCTION_DATA(); + + switch (BPA_PRODUCTION_DATA.class.getSimpleName()) { + case "BPA_PRODUCTION_DATA": + ((BPA_PRODUCTION_DATA) data).temperature = cursor.getString((int) cursor.getColumnIndex("temperature")); + ((BPA_PRODUCTION_DATA) data).weight = cursor.getString((int) cursor.getColumnIndex("weight")); + ((BPA_PRODUCTION_DATA) data).goodName = cursor.getString((int) cursor.getColumnIndex("goodName")); + ((BPA_PRODUCTION_DATA) data).startTime = cursor.getString((int) cursor.getColumnIndex("startTime")); + ((BPA_PRODUCTION_DATA) data).endTime = cursor.getString((int) cursor.getColumnIndex("endTime")); + break; + } + res.add(data); + } + cursor.close(); + db.close(); + } catch (Exception e) { + Log.d("查询异常", "查询异常: " + e.getMessage()); + db.close(); + } finally { + lock.unlock(); + } + return res; + } + //endregion + + //region 报警数据 + private List Alarms=new ArrayList(); + + public void AddAlarm(BPA_ALARM_DATA data) { + if (data == null) return; + Alarms.add(data); + } + + public void SaveAlarm(){ + if(Alarms==null||Alarms.size()==0) return; + BatchAddAlarm(Alarms); + Alarms.clear(); + } + + public List ReadAlarm(String startTime, String endTime){ + return getAlarms(startTime,endTime); + } + + + /** + * 批量新增 + * @param data + * @return + */ + private boolean BatchAddAlarm( List data) { + lock.lock(); + boolean isSucess = false; + SQLiteDatabase db = getWritableDatabase(); + try { + ContentValues cv = new ContentValues(); + db.beginTransaction();//使用beginTransaction()方法开始事务操作。 + long result=-1; + for (int i = 0; i < data.size(); i++) { + Map map = Tools.getObjValue(data.get(i)); + for (String key : map.keySet()) { + Object value = map.get(key); + if (value instanceof String) { + cv.put(key, (String) value); + } else if (value instanceof Integer) { + cv.put(key, ((Integer) value).intValue()); + } else if (value instanceof Double) { + cv.put(key, ((Double) value).doubleValue()); + } else if (value instanceof Float) { + cv.put(key, ((Float) value).floatValue()); + } else if (value instanceof Long) { + cv.put(key, ((Long) value).longValue()); + } else if (value instanceof Boolean) { + cv.put(key, ((Boolean) value).booleanValue()); + } + } + + result = db.insertOrThrow(BPA_ALARM_DATA.class.getSimpleName(), null, cv); + if (result == -1) { + throw new Exception("Failed to insert data at index " + i); + } + } + db.setTransactionSuccessful();//如果需要提交更改,则使用setTransactionSuccessful()方法标记当前事务已经成功。 + isSucess= result > 0; + } catch (Exception e) { + db.close(); + isSucess= false; + }finally { + db.endTransaction();//结束事务 + db.close();//关闭连接 + lock.unlock(); + } + db.close(); + return isSucess; + } + + /** + * 根据条件获取数据 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @return + */ + private List getAlarms(String startTime, String endTime){ + lock.lock(); + List res = new ArrayList<>(); + SQLiteDatabase db = getReadableDatabase(); + try { + List col = new ArrayList<>(); + for (Field field : BPA_ALARM_DATA.class.getFields()) { + col.add(field.getName()); + } + String[] columns = (String[]) col.toArray(new String[col.size()]); + String orderby = "startTime"; + String where=""; + String[] args=new String[]{}; + if(!startTime.isEmpty()){ + where+="startTime>=?"; + args=new String[]{startTime}; + } + + if(!endTime.isEmpty()){ + where+=" and endTime<=?"; + args=new String[]{startTime,endTime}; + } + + + if(where.isEmpty()) return new ArrayList<>(); + if(args.length<=0) return new ArrayList<>(); + + Cursor cursor = db.query(BPA_ALARM_DATA.class.getSimpleName(), columns, where, args, null,null, orderby, null); + + while (cursor.moveToNext()) { + BPA_ALARM_DATA data = new BPA_ALARM_DATA(); + + switch (BPA_PRODUCTION_DATA.class.getSimpleName()) { + case "BPA_PRODUCTION_DATA": + ((BPA_ALARM_DATA) data).grade = cursor.getString((int) cursor.getColumnIndex("grade")); + ((BPA_ALARM_DATA) data).info = cursor.getString((int) cursor.getColumnIndex("info")); + ((BPA_ALARM_DATA) data).value = cursor.getString((int) cursor.getColumnIndex("value")); + ((BPA_ALARM_DATA) data).startTime = cursor.getString((int) cursor.getColumnIndex("startTime")); + break; + } + res.add(data); + } + cursor.close(); + db.close(); + } catch (Exception e) { + Log.d("查询异常", "查询异常: " + e.getMessage()); + db.close(); + } finally { + lock.unlock(); + } + return res; + } + //endregion +} diff --git a/app/src/main/java/com/bonait/bnframework/common/db/QueryDB.java b/app/src/main/java/com/bonait/bnframework/common/db/QueryDB.java index edcf2cc0..2bbe95c2 100644 --- a/app/src/main/java/com/bonait/bnframework/common/db/QueryDB.java +++ b/app/src/main/java/com/bonait/bnframework/common/db/QueryDB.java @@ -26,6 +26,7 @@ import com.bonait.bnframework.common.db.mode.BPA_ORDERLOGDESC; import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; import com.bonait.bnframework.common.db.mode.BPA_PROCESS; import com.bonait.bnframework.common.db.mode.BPA_PROCESSModel; +import com.bonait.bnframework.common.db.mode.BPA_PRODUCTION_DATA; import com.bonait.bnframework.common.db.mode.BPA_SILOS; import com.bonait.bnframework.common.db.mode.BPA_SILOSANDMATERIAL; import com.bonait.bnframework.common.db.mode.BPA_SUBORDER; @@ -2418,7 +2419,6 @@ public class QueryDB { } //endregion - //region BPA_PLCADDRESS PLC地址管理表 /** * 新增工序模型表 @@ -2505,6 +2505,131 @@ public class QueryDB { } //endregion + //region 过程数据表 + + /** + * 批量新增 + * @param data + * @return + */ + public static boolean BatchAddProduction( List data) { + lock.lock(); + boolean isSucess = false; + SQLiteDatabase db = helper.getWritableDatabase(); + try { + ContentValues cv = new ContentValues(); + db.beginTransaction();//使用beginTransaction()方法开始事务操作。 + long result=-1; + for (int i = 0; i < data.size(); i++) { + Map map = Tools.getObjValue(data.get(i)); + for (String key : map.keySet()) { + Object value = map.get(key); + if (value instanceof String) { + cv.put(key, (String) value); + } else if (value instanceof Integer) { + cv.put(key, ((Integer) value).intValue()); + } else if (value instanceof Double) { + cv.put(key, ((Double) value).doubleValue()); + } else if (value instanceof Float) { + cv.put(key, ((Float) value).floatValue()); + } else if (value instanceof Long) { + cv.put(key, ((Long) value).longValue()); + } else if (value instanceof Boolean) { + cv.put(key, ((Boolean) value).booleanValue()); + } + } + + result = db.insertOrThrow(BPA_PRODUCTION_DATA.class.getSimpleName(), null, cv); + if (result == -1) { + throw new Exception("Failed to insert data at index " + i); + } + } + db.setTransactionSuccessful();//如果需要提交更改,则使用setTransactionSuccessful()方法标记当前事务已经成功。 + isSucess= result > 0; + } catch (Exception e) { + db.close(); + isSucess= false; + }finally { + db.endTransaction();//结束事务 + db.close();//关闭连接 + lock.unlock(); + } + db.close(); + return isSucess; + } + + public static List getProductionData(String startTime, String endTime,String goodName){ + lock.lock(); + List res = new ArrayList<>(); + SQLiteDatabase db = helper.getReadableDatabase(); + try { + List col = new ArrayList<>(); + for (Field field : BPA_PRODUCTION_DATA.class.getFields()) { + col.add(field.getName()); + } + String[] columns = (String[]) col.toArray(new String[col.size()]); + String orderby = "startTime";//出料顺序 + String where=""; + String[] args=new String[]{}; + if(!startTime.isEmpty()){ + where+="startTime>=?"; + args=new String[]{startTime}; + } + +// if (!endTime.isEmpty()) { +// where+=" and endTime<=?"; +// args=new String[]{startTime,endTime}; +// } + + if (!goodName.isEmpty()) { + where+=" and goodName=?"; + args=new String[]{startTime,endTime,goodName}; + } + + if(where.isEmpty()) return new ArrayList<>(); + if(args.length<=0) return new ArrayList<>(); + +// String where = "isDelete=? and createTime>=? and createTime<=?"; +// String[] args = new String[]{"0", sta, stp}; +// if (lx >= 0) { +// where = "isDelete=? and createTime>=? and createTime<=? and status=?"; +// args = new String[]{"0", sta, stp, String.valueOf(lx)}; +// } + + + + +// String where = "goodName!=?"; +// String[] args = new String[]{""}; + Cursor cursor = db.query(BPA_PRODUCTION_DATA.class.getSimpleName(), columns, where, args, null,null, orderby, null); + + while (cursor.moveToNext()) { + BPA_PRODUCTION_DATA data = new BPA_PRODUCTION_DATA(); + + switch (BPA_PRODUCTION_DATA.class.getSimpleName()) { + case "BPA_PRODUCTION_DATA": + ((BPA_PRODUCTION_DATA) data).temperature = cursor.getString((int) cursor.getColumnIndex("temperature")); + ((BPA_PRODUCTION_DATA) data).weight = cursor.getString((int) cursor.getColumnIndex("weight")); + ((BPA_PRODUCTION_DATA) data).goodName = cursor.getString((int) cursor.getColumnIndex("goodName")); + ((BPA_PRODUCTION_DATA) data).startTime = cursor.getString((int) cursor.getColumnIndex("startTime")); + ((BPA_PRODUCTION_DATA) data).endTime = cursor.getString((int) cursor.getColumnIndex("endTime")); + break; + } + res.add(data); + } + cursor.close(); + db.close(); + } catch (Exception e) { + Log.d("查询异常", "查询异常: " + e.getMessage()); + db.close(); + } finally { + lock.unlock(); + } + return res; + } + + //endregion + //region 私有 /** diff --git a/app/src/main/java/com/bonait/bnframework/common/db/file/DBHelper.java b/app/src/main/java/com/bonait/bnframework/common/db/file/DBHelper.java index 061ebf19..90262f38 100644 --- a/app/src/main/java/com/bonait/bnframework/common/db/file/DBHelper.java +++ b/app/src/main/java/com/bonait/bnframework/common/db/file/DBHelper.java @@ -22,6 +22,7 @@ import com.bonait.bnframework.common.db.mode.BPA_ORDERLOGDESC; import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; import com.bonait.bnframework.common.db.mode.BPA_PROCESS; import com.bonait.bnframework.common.db.mode.BPA_PROCESSModel; +import com.bonait.bnframework.common.db.mode.BPA_PRODUCTION_DATA; import com.bonait.bnframework.common.db.mode.BPA_SILOS; import com.bonait.bnframework.common.db.mode.BPA_SILOSANDMATERIAL; import com.bonait.bnframework.common.db.mode.BPA_SUBORDER; @@ -125,6 +126,8 @@ public class DBHelper extends SQLiteOpenHelper { CreateTablesAll(BPA_CLOUDDATA.class,null);//云端表 CreateTablesAll(BPA_PLCADDRESS.class,null);//工序模型表 + CreateTablesAll(BPA_PRODUCTION_DATA.class,null);//创建过程数据表 + ForeignKeys(); } /** diff --git a/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_ALARM_DATA.java b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_ALARM_DATA.java new file mode 100644 index 00000000..10af41ea --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_ALARM_DATA.java @@ -0,0 +1,46 @@ +package com.bonait.bnframework.common.db.mode; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class BPA_ALARM_DATA { + + /** + * 报警信息 + */ + public String info; + + /** + * 报警值 + */ + public String value; + + /** + * 报警级别 + */ + public String grade; + + /** + * 开始时间 + */ + public String startTime; + + + public BPA_ALARM_DATA(){ + startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + } + + public BPA_ALARM_DATA(String _info,String _value,String _grade){ + this.startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + this.info = _info; + this.value = _value; + this.grade = _grade; + } + + public BPA_ALARM_DATA(String _info,String _value){ + this.startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + this.info = _info; + this.value = _value; + this.grade = "一般报警"; + } +} diff --git a/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_PRODUCTION_DATA.java b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_PRODUCTION_DATA.java new file mode 100644 index 00000000..0dd6f86e --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/db/mode/BPA_PRODUCTION_DATA.java @@ -0,0 +1,54 @@ +package com.bonait.bnframework.common.db.mode; + +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * 生产数据 + */ +public class BPA_PRODUCTION_DATA{ + + + /** + * 温度 + */ + public String temperature; + + /** + * 重量 + */ + public String weight; + + /** + * 商品名称 + */ + public String goodName; + + /** + * 开始时间 + */ + public String startTime; + + /** + * 结束时间 + */ + public String endTime; + + public BPA_PRODUCTION_DATA(){ + startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + } + + public BPA_PRODUCTION_DATA(String _goodName,String _temperature,String _weight){ + startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + this.goodName=_goodName; + this.temperature=_temperature; + this.weight=_weight; + } + + public BPA_PRODUCTION_DATA(String _goodName,Float _temperature,Float _weight){ + startTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + this.goodName=_goodName; + this.temperature=_temperature.toString(); + this.weight=_weight.toString(); + } +} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/ProductionHelper.java b/app/src/main/java/com/bonait/bnframework/common/helper/ProductionHelper.java new file mode 100644 index 00000000..4dc4ca09 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/helper/ProductionHelper.java @@ -0,0 +1,40 @@ +package com.bonait.bnframework.common.helper; + +import android.util.Log; + +import com.bonait.bnframework.common.db.QueryDB; +import com.bonait.bnframework.common.db.mode.BPA_PRODUCTION_DATA; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class ProductionHelper { + private volatile static ProductionHelper instance = null; + public static synchronized ProductionHelper get() { + if (instance == null) { // 如果instance还未被实例化则进行实例化 + instance = new ProductionHelper(); + } + return instance; + } + + private List Productions=new ArrayList(); + + public void AddProduction(BPA_PRODUCTION_DATA data) { + if (data == null) return; + Productions.add(data); + } + + public void Save(){ + if(Productions==null||Productions.size()==0) return; + QueryDB.BatchAddProduction(Productions); + Productions.clear(); + } + + public List Read(String startTime, String endTime,String goodName){ + return QueryDB.getProductionData(startTime,endTime,goodName); + } + + + +} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/SdCart.java b/app/src/main/java/com/bonait/bnframework/common/helper/SdCart.java index a158a61f..087716e3 100644 --- a/app/src/main/java/com/bonait/bnframework/common/helper/SdCart.java +++ b/app/src/main/java/com/bonait/bnframework/common/helper/SdCart.java @@ -5,6 +5,7 @@ import android.os.Environment; import android.util.Log; import com.bonait.bnframework.common.constant.ConfigName; +import com.bonait.bnframework.common.db.DeviceDataDb; import com.bonait.bnframework.common.db.file.DBHelper; import java.io.File; @@ -28,6 +29,35 @@ public class SdCart { return mInstance; } + public String getSdCardPath(){ + File sdDir = null; + boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); + if (sdCardExist) { + sdDir = Environment.getExternalStorageDirectory(); + ConfigName.getInstance().sdCardPath = sdDir.toString(); + } + return ConfigName.getInstance().sdCardPath; + } + + public String getSdCardPath(String path){ + File sdDir = null; + boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); + if (sdCardExist) { + sdDir = Environment.getExternalStorageDirectory(); + ConfigName.getInstance().sdCardPath = sdDir.toString(); + ConfigName.getInstance().appResRoot = sdDir.toString()+"/"+path; + } + File rootFile = new File(ConfigName.getInstance().appResRoot); + //如果目录不存在就创建目录 + if (!rootFile.exists()) { + rootFile.mkdirs(); + } + return ConfigName.getInstance().appResRoot; + } + + public String getDbPath(String DirPath,String fileName){ + return getSdCardPath(DirPath)+"/"+fileName; + } //endregion /** @@ -41,7 +71,7 @@ public class SdCart { sdDir = Environment.getExternalStorageDirectory(); ConfigName.getInstance().sdCardPath = sdDir.toString(); } - + DeviceDataDb.get().Init(); ConfigName.getInstance().appResRoot = ConfigName.getInstance().sdCardPath + "/hblxiaochaodb"; ConfigName.getInstance().dbPath = ConfigName.getInstance().appResRoot + "/hbl.db"; File rootFile = new File(ConfigName.getInstance().appResRoot); diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/Singleton.java b/app/src/main/java/com/bonait/bnframework/common/helper/Singleton.java index 3f34182f..dd50c70f 100644 --- a/app/src/main/java/com/bonait/bnframework/common/helper/Singleton.java +++ b/app/src/main/java/com/bonait/bnframework/common/helper/Singleton.java @@ -1,5 +1,11 @@ package com.bonait.bnframework.common.helper; public class Singleton { -// private static readonly + private volatile T instance; + public synchronized T getInstance() { + if (instance == null) { // 如果instance还未被实例化则进行实例化 +// instance = new T(); + } + return instance; + } } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java index 419d88dc..b0eb9986 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java @@ -21,6 +21,7 @@ import com.bonait.bnframework.common.utils.NetworkUtils; import com.bonait.bnframework.modules.home.adapter.FragmentAdapter; import com.bonait.bnframework.modules.home.fragment.DingDanfragment; import com.bonait.bnframework.modules.home.fragment.GongnengFragment; +import com.bonait.bnframework.modules.home.fragment.HandControlFragment; import com.bonait.bnframework.modules.home.fragment.MakeGoodFragment; import com.bonait.bnframework.modules.home.fragment.SheZhifragment; import com.bonait.bnframework.modules.mine.fragment.MyFragment; @@ -50,7 +51,9 @@ public class BottomNavigationMainActivity extends BaseActivity { mNavigateTabBar.onRestoreInstanceState(savedInstanceState); mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.gongneng, R.mipmap.gongneng_selected, "功能")); mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.dingdan, R.mipmap.dingdan_selected, "订单")); + mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.dingdan, R.mipmap.dingdan_selected, "手动控制")); mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(0, 0, "")); + mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.dingdan, R.mipmap.dingdan_selected, "IO监控")); mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.shezhi, R.mipmap.shezhi_selected, "设置")); mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.comui_tab_person, R.mipmap.comui_tab_person_selected, "我的")); mNavigateTabBar.setTabSelectListener(mOnNavigationItemSelectedListener); @@ -76,7 +79,9 @@ public class BottomNavigationMainActivity extends BaseActivity { fragmentList = new ArrayList<>(); fragmentList.add(new GongnengFragment()); fragmentList.add(new DingDanfragment()); + fragmentList.add(new HandControlFragment()); fragmentList.add(new MakeGoodFragment()); + fragmentList.add(new HandControlFragment()); fragmentList.add(new SheZhifragment()); fragmentList.add(new MyFragment()); ConfigName.getInstance().fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragmentList); @@ -85,9 +90,9 @@ public class BottomNavigationMainActivity extends BaseActivity { //手指滑动 viewPager.addOnPageChangeListener(pageChangeListener); // 设置viewPager缓存多少个fragment - viewPager.setOffscreenPageLimit(5); + viewPager.setOffscreenPageLimit(7); // 再来一单 - viewPager.setCurrentItem(2); + viewPager.setCurrentItem(3); viewPager.setSwipeable(false);//禁用页面滑动功能 } @@ -157,7 +162,7 @@ public class BottomNavigationMainActivity extends BaseActivity { = new MainNavigateTabBar.OnTabSelectedListener() { @Override public void onTabSelected(MainNavigateTabBar.ViewHolder holder) { - int _postion = 2; + int _postion = 3; switch (holder.tag) { case "功能": _postion = 0; @@ -165,15 +170,22 @@ public class BottomNavigationMainActivity extends BaseActivity { case "订单": _postion = 1; break; - case "设置": + case "手动控制": + _postion = 2; + break; + case "": _postion = 3; break; - case "我的": + case "IO监控": _postion = 4; break; - case "": - _postion = 2; + case "设置": + _postion = 5; break; + case "我的": + _postion = 6; + break; + } viewPager.setCurrentItem(_postion); } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/ddtj_adapter.java b/app/src/main/java/com/bonait/bnframework/modules/home/adapter/ddtj_adapter.java index 00bd6167..83b685f7 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/ddtj_adapter.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/adapter/ddtj_adapter.java @@ -7,24 +7,29 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.bonait.bnframework.R; +import com.bonait.bnframework.common.db.mode.BPA_PRODUCTION_DATA; import com.bonait.bnframework.common.db.res.SuOrderTJ; +import com.bonait.bnframework.common.helper.I.IRunT; import java.util.List; -public class ddtj_adapter extends ArrayAdapter { - private List datas; +public class ddtj_adapter extends ArrayAdapter { + private List datas; private Context context; private int resource; - public ddtj_adapter(@NonNull Context context, int resource, @NonNull List objects) { + public IRunT ButtonClick; + + public ddtj_adapter(@NonNull Context context, int resource, @NonNull List objects) { super(context, resource, objects); this.context = context; this.resource=resource; @@ -34,19 +39,23 @@ public class ddtj_adapter extends ArrayAdapter { @NonNull @Override public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { - SuOrderTJ order = (SuOrderTJ) getItem(position);//得到当前项选中item实例 + BPA_PRODUCTION_DATA order = (BPA_PRODUCTION_DATA) getItem(position);//得到当前项选中item实例 //为每一个子项加载设定的布局 View view = LayoutInflater.from(getContext()).inflate(this.resource, parent, false); //分别获取 image view 和 textview 的实例 - TextView name,ddzl,ddzl_yzz,ddzl_yc; + TextView name,ddzl,ddzl_yzz; + Button ddzl_yc; name = (TextView) view.findViewById(R.id.name); ddzl = (TextView) view.findViewById(R.id.ddzl); ddzl_yzz = (TextView) view.findViewById(R.id.ddzl_yzz); - ddzl_yc = (TextView) view.findViewById(R.id.ddzl_yc); - name.setText(order.name+""); - ddzl.setText(order.Count+""); - ddzl_yzz.setText(order.Yzz_Count+""); - ddzl_yc.setText(order.Yc_Count+""); + ddzl_yc = (Button) view.findViewById(R.id.ddzl_yc); + name.setText(order.goodName+""); + ddzl.setText(order.startTime+""); + ddzl_yzz.setText(order.endTime+""); + ddzl_yc.setOnClickListener((v)->{ + if(ButtonClick!=null)ButtonClick.Run(order); + }); +// ddzl_yc.setText(order.Yc_Count+""); return view; } private Activity findActivity(@NonNull Context context) { diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/DingDanfragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/DingDanfragment.java index a9b05edc..b645baad 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/DingDanfragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/DingDanfragment.java @@ -1,32 +1,98 @@ package com.bonait.bnframework.modules.home.fragment; +import static com.bonait.bnframework.MainApplication.getContext; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import android.content.Context; +import android.graphics.Color; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ListView; +import android.widget.TextView; +import com.bigkoo.pickerview.TimePickerView; import com.bonait.bnframework.R; import com.bonait.bnframework.common.base.BaseFragment; +import com.bonait.bnframework.common.db.DeviceDataDb; +import com.bonait.bnframework.common.db.mode.BPA_PRODUCTION_DATA; +import com.bonait.bnframework.common.helper.DateUtils; +import com.bonait.bnframework.common.helper.ProductionHelper; +import com.bonait.bnframework.common.utils.ToastUtils; +import com.bonait.bnframework.modules.home.adapter.ddtj_adapter; import com.bonait.bnframework.modules.home.fragment.from.OrderListActivity; import com.bonait.bnframework.modules.home.fragment.from.SalesStatisticsActivity; import com.orhanobut.logger.Logger; import com.qmuiteam.qmui.widget.QMUITopBarLayout; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; public class DingDanfragment extends BaseFragment { - @BindView(R.id.topbar) QMUITopBarLayout mTopBar;//顶部标题 + + /** + * 输入框 + */ + @BindView(R.id.edittext) + TextView edittext; + /** + * 查询按钮 + */ + @BindView(R.id.button) + Button button; + + /** + * 表格显示 + */ + @BindView(R.id.datatab) + ListView datatab; + + /** + * 子订单数据 + */ + List subOrders = new ArrayList<>(); + + /** + * 订单管理控制器 + */ + ddtj_adapter adapter; + + /** + * 日期选择器 + */ + TimePickerView pvTime; + + /** + * 开始时间-结束时间 + */ + @BindView(R.id.starttime) + EditText starttime; + + @BindView(R.id.stoptime) + EditText stoptime; + private Context context; + private ViewGroup view; + + public static BPA_PRODUCTION_DATA getProductionData; + public DingDanfragment() { } @@ -34,6 +100,10 @@ public class DingDanfragment extends BaseFragment { protected View onCreateView() { View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_ding_dan, null); ButterKnife.bind(this, root); +// view=(ViewGroup)getWindow().getDecorView(); + view=(ViewGroup)getView(); + context = getContext(); + Init(); return root; } @@ -48,23 +118,110 @@ public class DingDanfragment extends BaseFragment { * 初始化TopBar */ private void initTopBar() { - // mTopBar.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.app_color_theme_4)); - mTopBar.setTitle("订单管理"); + mTopBar.setTitle("过程数据"); } - @OnClick({R.id.ddgl,R.id.xltj}) - public void onViewClicked(View view) { - switch (view.getId()) { - case R.id.ddgl:// + /** + * 初始化 + */ + private void Init(){ + starttime.setText(new SimpleDateFormat("yyyy-MM-dd 00:00:00").format(new Date())); + stoptime.setText(new SimpleDateFormat("yyyy-MM-dd 23:59:59").format(new Date())); + starttime.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (pvTime != null) { + pvTime.show(starttime); + } + } + }); + stoptime.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (pvTime != null) { + pvTime.show(stoptime); + } + } + }); + CalendarTime(); +// Initdata(); + } + /** + * CalendarTime + * 时间选择器 + */ + public void CalendarTime() { + //控制时间范围(如果不设置范围,则使用默认时间1900-2100年,此段代码可注释) + //因为系统Calendar的月份是从0-11的,所以如果是调用Calendar的set方法来设置时间,月份的范围也要是从0-11 + Calendar selectedDate = Calendar.getInstance(); + Calendar startDate = Calendar.getInstance(); + startDate.set(2023, 0, 23); + Calendar endDate = Calendar.getInstance(); + endDate.set(2099, 11, 28); + //时间选择器 + pvTime = new TimePickerView.Builder(context, new TimePickerView.OnTimeSelectListener() { + @Override + public void onTimeSelect(Date date, View v) {//选中事件回调 + // 这里回调过来的v,就是show()方法里面所添加的 View 参数,如果show的时候没有添加参数,v则为null + TextView btn = (TextView) v; + btn.setTextSize(25); + btn.setText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)); + } + }) + //年月日时分秒 的显示与否,不设置则默认全部显示 + .setType(new boolean[]{true, true, true, true, true, false}) + .setLabel("年", "月", "日", "时", "分", "秒") + .isCenterLabel(true) + .setDividerColor(Color.DKGRAY) + .setContentSize(16)//字号 + .setDate(selectedDate) + .setRangDate(startDate, endDate) + .setDecorView(view) + .build(); + } + + /** + * 查询数据 + */ + public void QueryData() { + try { + subOrders.clear(); + String str= starttime.getText().toString(); + String stop= stoptime.getText().toString(); + if(DateUtils.compareDate(stop,str)) + { + ToastUtils.warning("开始时间不能大于结束时间!!!"); + return; + } + +// subOrders= ProductionHelper.get().Read(str,stop,edittext.getText().toString()); + subOrders= DeviceDataDb.get().ReadProduction(str,stop,edittext.getText().toString()); + + if(subOrders.size()<=0){ + ToastUtils.warning("未找到匹配的数据!"); + return; + } + + adapter = new ddtj_adapter(context,R.layout.ddtj_item,subOrders); + adapter.ButtonClick=(p)->{ + getProductionData=p; skipToActivity(OrderListActivity.class); - break; - case R.id.xltj:// - skipToActivity(SalesStatisticsActivity.class); - break; + }; + datatab.setAdapter(adapter); + + } catch (Exception e) { + } } + + @OnClick({R.id.button}) + public void onViewClicked(View view) { + QueryData(); + } + + @Override public void onDestroy() { super.onDestroy(); diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HandControlFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HandControlFragment.java new file mode 100644 index 00000000..55c59488 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/HandControlFragment.java @@ -0,0 +1,788 @@ +package com.bonait.bnframework.modules.home.fragment; + +import android.app.Activity; +import android.content.Context; +import android.graphics.Color; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.RadioButton; +import android.widget.RelativeLayout; +import android.widget.Spinner; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; +import androidx.recyclerview.widget.StaggeredGridLayoutManager; + +import com.bonait.bnframework.R; +import com.bonait.bnframework.business.ConfigData; +import com.bonait.bnframework.business.ExecuteTheRecipe; +import com.bonait.bnframework.common.base.BaseFragment; +import com.bonait.bnframework.common.constant.ConfigName; +import com.bonait.bnframework.common.constant.DataBus; +import com.bonait.bnframework.common.db.DeviceDataDb; +import com.bonait.bnframework.common.db.QueryDB; +import com.bonait.bnframework.common.db.mode.BPA_GOODS; +import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; +import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; +import com.bonait.bnframework.common.db.mode.BPA_PRODUCTION_DATA; +import com.bonait.bnframework.common.db.res.StatusMode; +import com.bonait.bnframework.common.helper.AlertDialogButton; +import com.bonait.bnframework.common.helper.Convert; +import com.bonait.bnframework.common.helper.CountDownTimerExt; +import com.bonait.bnframework.common.helper.I.IRun; +import com.bonait.bnframework.common.helper.I.IThread; +import com.bonait.bnframework.common.helper.I.MyClickListener; +import com.bonait.bnframework.common.helper.MessageLog; +import com.bonait.bnframework.common.helper.ThreadManager; +import com.bonait.bnframework.common.image.MyBitmapUtils; +import com.bonait.bnframework.common.modbus.s7.CommHelper; +import com.bonait.bnframework.common.utils.AlertDialogUtils; +import com.bonait.bnframework.common.utils.ToastUtils; +import com.bonait.bnframework.modules.home.adapter.devicestatus_adapter; +import com.bumptech.glide.Glide; +import com.litao.slider.NiftySlider; +import com.qmuiteam.qmui.widget.QMUITopBarLayout; +import com.suke.widget.SwitchButton; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; + +public class HandControlFragment extends BaseFragment { + //region 变量 +// @BindView(R.id.topbar) +// QMUITopBarLayout mTopBar;//顶部标题 + +// @BindView(R.id.main_weight) +// TextView main_weight; + + @BindView(R.id.IgnitionStatus) + TextView IgnitionStatus; + + private Context context; + + public Activity activity; + //endregion + + //region 界面 + public HandControlFragment() { + } + + @Override + protected View onCreateView() { + View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_hand_control, null); + ButterKnife.bind(this, root); + return root; + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + activity = getActivity(); + context = getContext(); + ExecuteTheRecipe.mainContext=context; + ExecuteTheRecipe.mainActivity=activity; + AlertDialogUtils.getContext=context; + NotifyProp(); + Init_弹窗(); + StatusOrMakeGoodThread(); + } + + /** + * 更新按钮背景和文本 + * @param id + * @param value + * @param trueText + * @param falseText + */ + private synchronized void RefreshButton(int id,boolean value,String trueText,String falseText){ + activity.runOnUiThread(()->{ + Button button = activity.findViewById(id); + if(!value){ + button.setText(trueText); + button.setBackgroundResource(R.drawable.bg_btn_false_color); + }else{ + button.setText(falseText); + button.setBackgroundResource(R.drawable.bg_btn_login_selected); + } + }); + } + + /** + * 通知属性初始化 + */ + private void NotifyProp(){ + + //系统启停状态更新 + ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + RefreshButton(R.id.switch_系统启停,s,"启动","停止"); + switch_系统启停.setEnabled(true); + MessageLog.ShowInfo("更新开关状态:"+(s?"true":"false")); + });}; + + //超温停气状态更新 + ExecuteTheRecipe.getDeviceData.OverTemperatureShutdownNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + RefreshButton(R.id.switch_超温停气,s,"启用","禁用"); + switch_超温停气.setEnabled(true); + });}; + + //点火模式状态更新 + ExecuteTheRecipe.getDeviceData.IgnideModeNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + RB_Hand.setChecked(s?true:false); + if(!s) RB_Auto.setChecked(true); + });}; + + //小火比例阀开度更新 + ExecuteTheRecipe.getDeviceData.SmallFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + slider_小火.setValue( s,false); + });}; + + //中火比例阀开度更新 + ExecuteTheRecipe.getDeviceData.MediumFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + slider_中火.setValue( s,false); + });}; + + //大火比例阀开度更新 + ExecuteTheRecipe.getDeviceData.HighFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + slider_大火.setValue( s,false); + });}; + + //强火比例阀开度更新 + ExecuteTheRecipe.getDeviceData.StrongFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + slider_强火.setValue( s,false); + });}; + + //搅拌速度更新 + ExecuteTheRecipe.getDeviceData.StirSpeedNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + slider_搅拌频率.setValue( s,false); + });}; + + //小火控制状态更新 + ExecuteTheRecipe.getDeviceData.SmallFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + RefreshButton(R.id.switch_小火,s,"打开","关闭"); + switch_小火.setEnabled(true); + });}; + + //中火控制状态更新 + ExecuteTheRecipe.getDeviceData.MediumFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + RefreshButton(R.id.switch_中火,s,"打开","关闭"); + switch_中火.setEnabled(true); + });}; + + //大火控制状态更新 + ExecuteTheRecipe.getDeviceData.HighFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + RefreshButton(R.id.switch_大火,s,"打开","关闭"); + switch_大火.setEnabled(true); + });}; + + //强火控制状态更新 + ExecuteTheRecipe.getDeviceData.StrongFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + RefreshButton(R.id.switch_强火,s,"打开","关闭"); + switch_强火.setEnabled(true); + });}; + + //点火控制状态更新 + ExecuteTheRecipe.getDeviceData.IgnitionStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + RefreshButton(R.id.switch_点火控制,s,"点火","关火"); + switch_点火控制.setEnabled(true); + });}; + + //温度修正值更新 + ExecuteTheRecipe.getDeviceData.TemperatureCorrectionValueNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + edit_温度修正.setText(s.toString()); + });}; + + //炒锅温度上限设置值更新 + ExecuteTheRecipe.getDeviceData.UpperTemperatureLimitNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + edit_温度上限.setText(s.toString()); + });}; + + //搅拌控制状态更新 + ExecuteTheRecipe.getDeviceData.StirControlStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + RefreshButton(R.id.switch_搅拌控制,s,"启动搅拌","停止搅拌"); + switch_搅拌控制.setEnabled(true); + });}; + + //抽油启停状态更新 + ExecuteTheRecipe.getDeviceData.OilPumpingStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + RefreshButton(R.id.switch_抽油启停,s,"启动抽油","停止抽油"); + switch_抽油启停.setEnabled(true); + });}; + + //备用气缸起停状态更新 + ExecuteTheRecipe.getDeviceData.StandbyCylinderStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + RefreshButton(R.id.switch_备用气缸,s,"启动","停止"); + switch_备用气缸.setEnabled(true); + });}; + + //设定重量状态更新 + ExecuteTheRecipe.getDeviceData.SetWeightNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + edit_设定重量.setText(s.toString()); + });}; + + //提前量状态更新 + ExecuteTheRecipe.getDeviceData.LeadNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + edit_提前量.setText(s.toString()); + });}; + + //急停故障 +// ExecuteTheRecipe.getDeviceData.EstopFaultNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// MessageLog.ShowError(s?"急停故障触发":"急停故障复位"); +// });}; + + //油泵故障 +// ExecuteTheRecipe.getDeviceData.OilPumpFault.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// MessageLog.ShowError(s?"油泵故障触发":"油泵故障复位"); +// });}; + + //搅拌故障 +// ExecuteTheRecipe.getDeviceData.MixingFailure.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// MessageLog.ShowError(s?"搅拌故障触发":"搅拌故障复位"); +// });}; + + //点火异常故障 + ExecuteTheRecipe.getDeviceData.IgnitionMalfunction.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + MessageLog.ShowError(s?"点火故障触发":"点火故障复位"); + IgnitionStatus.setText(s?"点火失败":"点火正常"); + });}; + + //高温报警故障 +// ExecuteTheRecipe.getDeviceData.HighTemperatureAlarm.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// if(s) ExecuteTheRecipe.SetForcedEnd(); +// MessageLog.ShowError(s?"高温故障触发":"高温故障复位"); +// });}; + + //备用故障1 +// ExecuteTheRecipe.getDeviceData.StandbyFailure.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// MessageLog.ShowError(s?"备用故障1触发":"备用故障1复位"); +// });}; + + } + //endregion + + //region 点击事件处理 + + + /** + * 点击事件 + * + * @param view + */ + @OnClick({R.id.button_写入参数, R.id.button_出料 , R.id.button_点火复位,R.id.button_重量清零 }) + public void onViewClicked(View view) { + CommHelper.get().siemens. CancelWrite=true; + switch (view.getId()) { + case R.id.button_出料: + if (!ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.getValue()) { + AlertDialogUtils.showDialog(context, "提示", "系统未启动,请启动后重试!"); + return ; + } + Convert.TryToFloat(edit_设定重量.getText()).OnSource((s)-> + { + ExecuteTheRecipe.showlog("手动设定出料重量:"+s.Content); + Convert.TryToFloat(edit_提前量.getText()).OnSource((t)-> + { + ExecuteTheRecipe.showlog("手动设定提前量:"+t.Content); + ExecuteTheRecipe.DischargeControlAsync(s.Content,t.Content); + }).OnFailed(p->{ + AlertDialogUtils.showDialog(context, "提示", "输入的数据格式不匹配,请重试!"); + edit_提前量.setText("0.0"); + }); + + }).OnFailed(f->{ + AlertDialogUtils.showDialog(context, "提示", "输入的数据格式不匹配,请重试!"); + edit_设定重量.setText("0.0"); + }); + break; + case R.id.button_点火复位: + ExecuteTheRecipe.showlog("手动操作点火复位开关"); + ExecuteTheRecipe.BottomClickAsync("点火复位开关"); + break; + case R.id.button_写入参数: + Convert.TryToFloat(edit_温度修正.getText()).OnSource((s)-> + { + ExecuteTheRecipe.showlog("手动设置温度修正值:"+s.Content); + ExecuteTheRecipe.WriteAsync("炒锅温度修正",s.Content); + }).OnFailed(f->{ + AlertDialogUtils.showDialog(context, "提示", "输入的数据格式不匹配,请重试!"); + edit_温度修正.setText("0.0"); + }); + Convert.TryToFloat(edit_温度上限.getText()).OnSource((s)-> + { + ExecuteTheRecipe.showlog("手动设置温度上限值:"+s.Content); + ExecuteTheRecipe.WriteAsync("炒锅温度上限设置",s.Content); + }).OnFailed(p->{ + AlertDialogUtils.showDialog(context, "提示", "输入的数据格式不匹配,请重试!"); + edit_温度上限.setText("0.0"); + }); + break; + case R.id.button_重量清零: + ExecuteTheRecipe.showlog("手动重量清零"); + ExecuteTheRecipe.BottomClickAsync("重量清零"); + break; + } + } + + public void InchingControl(View view,Boolean IsChick) + { + CommHelper.get().siemens. CancelWrite=true; + switch (view.getId()) { + case R.id.button_搅拌点动: + ExecuteTheRecipe.showlog("手动操作-搅拌点动开关,值:"+IsChick); + ExecuteTheRecipe.WriteAsync("搅拌点动开关", IsChick); + break; + case R.id.button_搅拌上升: + ExecuteTheRecipe.showlog("手动操作-搅拌上升开关,值:"+IsChick); + ExecuteTheRecipe.WriteAsync("搅拌上升", IsChick); + break; + case R.id.button_搅拌下降: + ExecuteTheRecipe.showlog("手动操作-搅拌下降开关,值:"+IsChick); + ExecuteTheRecipe.WriteAsync("搅拌下降", IsChick); + break; + case R.id.button_锅前倾: + ExecuteTheRecipe.showlog("手动操作-锅口向前开关,值:"+IsChick); + ExecuteTheRecipe.WriteAsync("锅口向前", IsChick); + break; + case R.id.button_锅后仰: + ExecuteTheRecipe.showlog("手动操作-锅口向后开关,值:"+IsChick); + ExecuteTheRecipe.WriteAsync("锅口向后", IsChick); + break; + } + } + + public View.OnTouchListener touchListener = new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + + if(!ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.getValue()){ + if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){ + AlertDialogUtils.showDialog("系统未启动,请启动后重试!", AlertDialogButton.OK,(s)->{}); + } + return false; + } + + boolean IsChick = false; + if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { + InchingControl(view,true); + MessageLog.ShowInfo("手指按下"); + } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { + InchingControl(view,false); + MessageLog.ShowInfo("手指松开"); + } + else if (motionEvent.getAction() == MotionEvent.ACTION_OUTSIDE){ + MessageLog.ShowInfo("手指离开"); + InchingControl(view,false); + } + return false; + } + }; + //endregion + + private CountDownTimerExt countDownTimer = null;//计时器 + + + //region 私有 + + + /** + * 设置显示变量 + * + * @param image + * @param val + */ + public void SetImageViewUrl(ImageView image, boolean val, int index) { + activity.runOnUiThread(()->{ + if (index == 1) { + image.setBackgroundResource( val ? R.drawable.circular_green : R.drawable.circular_gray); + } else { + image.setImageResource(!val ? R.drawable.circular_green : R.drawable.circular_gray); + } + }); + } + //endregion + + //region 设备监控状态 + /** + * 设备状态 + */ + public List sbzt = new ArrayList<>(); + public devicestatus_adapter adapter_sbzt = null; + /** + * 故障状态 + */ + public List gzzt = new ArrayList<>(); + public devicestatus_adapter adapter_gzzt = null; + + + /** + * 刷新数据 + */ + public void ReshData() { + adapter_sbzt.refresh(); + adapter_gzzt.refresh(); + } + //endregion + + //region 公共函数 + + + //endregion + + //region 状态显示或商品制作线程 + + + /** + * 线程 + */ + public void StatusOrMakeGoodThread() { + ExecuteTheRecipe.context = getContext(); + + ThreadManager.Get().StartLong("UI刷新任务", true, new IThread() { + @Override + public void Run() throws InterruptedException { + + activity.runOnUiThread(()->{ + PanWeight.setText(String.format("%.2f",ExecuteTheRecipe.getDeviceData.CurrentWeight) + " KG");//锅体重量 + CurrentTemp.setText(String.format("%.2f",ExecuteTheRecipe.getDeviceData.CurrentTemperature) + " ℃");//锅体温度 + }); + + SetImageViewUrl(image_搅拌上升, ExecuteTheRecipe.getDeviceData.MixingUpperLimit, 1); + SetImageViewUrl(image_搅拌下降, ExecuteTheRecipe.getDeviceData.MixingLowerLimit, 1); + SetImageViewUrl(image_锅后仰, ExecuteTheRecipe.getDeviceData.PostPotLimit, 1); + SetImageViewUrl(image_锅前倾,ExecuteTheRecipe.getDeviceData.PostPotLimit, 0); + + Thread.sleep(1000); + } + + @Override + public void RunComplete() throws InterruptedException { + + } + }); + + } + //endregion + + //region 弹窗处理 + @BindView(R.id.switch_系统启停) + Button switch_系统启停; + + @BindView(R.id.switch_超温停气) + Button switch_超温停气; + + @BindView(R.id.switch_搅拌控制) + Button switch_搅拌控制; + + @BindView(R.id.switch_抽油启停) + Button switch_抽油启停; + + @BindView(R.id.switch_备用气缸) + Button switch_备用气缸; + +// @BindView(R.id.editsp_物料) +// Spinner editsp_物料; + +// @BindView(R.id.editsp_点火模式) +// Spinner editsp_点火模式; + + //点火模式:手动 + @BindView(R.id.RB_Hand) + RadioButton RB_Hand; + + //点火模式:自动 + @BindView(R.id.RB_Auto) + RadioButton RB_Auto; + + @BindView(R.id.switch_点火控制) + Button switch_点火控制; + + + @BindView(R.id.button_搅拌点动) + Button button_搅拌点动;//button_搅拌点动 + + @BindView(R.id.button_搅拌上升) + Button button_搅拌上升;// + + @BindView(R.id.button_搅拌下降) + Button button_搅拌下降;// + + @BindView(R.id.button_锅前倾) + Button button_锅前倾;// + + @BindView(R.id.button_锅后仰) + Button button_锅后仰;// + + @BindView(R.id.image_搅拌上升) + ImageView image_搅拌上升; + + @BindView(R.id.image_搅拌下降) + ImageView image_搅拌下降; + + @BindView(R.id.image_锅前倾) + ImageView image_锅前倾; + + @BindView(R.id.image_锅后仰) + ImageView image_锅后仰; + + /** + * 初始化弹窗 + */ + public void Init_弹窗() { + Init_弹窗_事件(); + Init_弹窗_物料(); + Init_火力(); + } + + + private void DeviceControl(boolean isChecked,String name){ + if(isChecked&&!ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.getValue()){ + AlertDialogUtils.showDialog("系统未启动,请启动后重试!", AlertDialogButton.OK,null); + } + ExecuteTheRecipe.showlog("手动操作-"+name+",值:"+isChecked); + ExecuteTheRecipe.WriteAsync(name,isChecked); + } + + @OnClick({R.id.switch_系统启停, R.id.switch_超温停气 + , R.id.switch_搅拌控制 + , R.id.switch_抽油启停 + ,R.id.switch_备用气缸 + , R.id.switch_点火控制 + , R.id.switch_小火,R.id.switch_中火 + , R.id.switch_大火,R.id.switch_强火 + }) + public void onButtonClicked(View view) { + switch (view.getId()) { + case R.id.switch_系统启停: + ExecuteTheRecipe.showlog("手动操作-系统启停开关,值:"+!ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.getValue()); + ExecuteTheRecipe.WriteAsync("系统启停开关", !ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.getValue()); + break; + case R.id.switch_超温停气: + DeviceControl(!ExecuteTheRecipe.getDeviceData.OverTemperatureShutdownNotify.getValue(),"超温停气开关"); + break; + case R.id.switch_搅拌控制: + boolean temp=!ExecuteTheRecipe.getDeviceData.StirControlStatusNotify.getValue(); + if (temp) { + if(!ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.getValue()){ + AlertDialogUtils.showDialog("系统未启动,请启动后重试!", AlertDialogButton.OK,null); + } + ExecuteTheRecipe.showlog("手动启动搅拌"); + ExecuteTheRecipe.BottomClickAsync("搅拌启动开关"); + } else { + ExecuteTheRecipe.showlog("手动停止搅拌"); + ExecuteTheRecipe.BottomClickAsync("搅拌停止开关"); + } + break; + case R.id.switch_抽油启停: + DeviceControl(!ExecuteTheRecipe.getDeviceData.OilPumpingStatusNotify.getValue(),"料仓1出料"); + break; + case R.id.switch_备用气缸: + DeviceControl(!ExecuteTheRecipe.getDeviceData.StandbyCylinderStatusNotify.getValue(),"料仓2出料"); + break; + case R.id.switch_点火控制: + DeviceControl(!ExecuteTheRecipe.getDeviceData.IgnitionStatusNotify.getValue(),"点火启动开关"); + break; + case R.id.switch_小火: + DeviceControl(!ExecuteTheRecipe.getDeviceData.SmallFireStatusNotify.getValue(),"小火开关(一圈)"); + break; + case R.id.switch_中火: + DeviceControl(!ExecuteTheRecipe.getDeviceData.MediumFireStatusNotify.getValue(),"中火开关(二圈)"); + break; + case R.id.switch_大火: + DeviceControl(!ExecuteTheRecipe.getDeviceData.HighFireStatusNotify.getValue(),"大火开关(三圈)"); + break; + case R.id.switch_强火: + DeviceControl(!ExecuteTheRecipe.getDeviceData.StrongFireStatusNotify.getValue(),"强火开关(四圈)"); + break; + } + } + + + + + /** + * 初始化弹框中的事件 + */ + public void Init_弹窗_事件() { + + RB_Hand.setOnClickListener((s)->{ + ExecuteTheRecipe.showlog("手动切换为 手动点火"); + ExecuteTheRecipe.WriteAsync("点火手自动切换开关", true); + });//手动点火模式 + + RB_Auto.setOnClickListener((s)->{ + ExecuteTheRecipe.showlog("手动切换为 自动点火"); + ExecuteTheRecipe.WriteAsync("点火手自动切换开关", false); + });//自动点火模式 + + button_搅拌点动.setOnTouchListener(touchListener); + button_搅拌上升.setOnTouchListener(touchListener); + button_搅拌下降.setOnTouchListener(touchListener); + button_锅前倾.setOnTouchListener(touchListener); + button_锅后仰.setOnTouchListener(touchListener); + + } + + + @BindView(R.id.PanWeight) + TextView PanWeight;//锅体的重量 + + @BindView(R.id.CurrentTemp) + TextView CurrentTemp; + + @BindView(R.id.edit_设定重量) + EditText edit_设定重量;//设定重量 + + @BindView(R.id.edit_提前量) + EditText edit_提前量;//提前量 + public ArrayList materials = new ArrayList<>(); + public List names = new ArrayList<>(); + + /** + * 初始化物料 + */ + public void Init_弹窗_物料() { + materials.clear(); + names.clear(); + List bpa_materials = QueryDB.GetMaterialALL(); + for (BPA_MATERIAL item : bpa_materials) { + materials.add(item); + names.add(item.name); + } + } + + + @BindView(R.id.edit_温度修正) + EditText edit_温度修正;//edit_温度修正 + + @BindView(R.id.edit_温度上限) + EditText edit_温度上限;//edit_温度上限 + + @BindView(R.id.slider_小火) + NiftySlider slider_小火; + + @BindView(R.id.slider_中火) + NiftySlider slider_中火; + + @BindView(R.id.slider_大火) + NiftySlider slider_大火; + + @BindView(R.id.slider_强火) + NiftySlider slider_强火; + + @BindView(R.id.slider_搅拌频率) + NiftySlider slider_搅拌频率; + + @BindView(R.id.switch_小火) + Button switch_小火; + + @BindView(R.id.switch_中火) + Button switch_中火; + + @BindView(R.id.switch_大火) + Button switch_大火; + + @BindView(R.id.switch_强火) + Button switch_强火; + + /** + * 初始化火力 + */ + public void Init_火力() { + + slider_小火.setOnValueChangeListener((n,v,b)->{slider_小火.setThumbText((int) v + "");}); + slider_中火.setOnValueChangeListener((n,v,b)->{slider_中火.setThumbText((int) v + "");}); + slider_大火.setOnValueChangeListener((n,v,b)->{slider_大火.setThumbText((int) v + "");}); + slider_强火.setOnValueChangeListener((n,v,b)->{slider_强火.setThumbText((int) v + "");}); + slider_搅拌频率.setOnValueChangeListener((n,v,b)->{slider_搅拌频率.setThumbText((int) v + "");}); + + slider_小火.setOnSliderTouchListener(new NiftySlider.OnSliderTouchListener() { + @Override + public void onStartTrackingTouch(@NonNull NiftySlider niftySlider) { + + } + + @Override + public void onStopTrackingTouch(@NonNull NiftySlider niftySlider) { + int temp = (int) slider_小火.getValue(); + ExecuteTheRecipe.showlog("手动设置-小火比例值:"+temp); + ExecuteTheRecipe.WriteAsync("小火比例阀开度", temp); + ToastUtils.info("小火比例阀开度:" + temp); + } + }); + + slider_中火.setOnSliderTouchListener(new NiftySlider.OnSliderTouchListener() { + @Override + public void onStartTrackingTouch(@NonNull NiftySlider niftySlider) { + + } + + @Override + public void onStopTrackingTouch(@NonNull NiftySlider niftySlider) { + int temp = (int) slider_中火.getValue(); + ExecuteTheRecipe.showlog("手动设置-中火比例值:"+temp); + ExecuteTheRecipe.WriteAsync("中火比例阀开度", temp); + ToastUtils.info("中火比例阀开度:" + temp); + } + }); + + slider_大火.setOnSliderTouchListener(new NiftySlider.OnSliderTouchListener() { + @Override + public void onStartTrackingTouch(@NonNull NiftySlider niftySlider) { + + } + + @Override + public void onStopTrackingTouch(@NonNull NiftySlider niftySlider) { + int temp = (int) slider_大火.getValue(); + ExecuteTheRecipe.showlog("手动设置-大火比例值:"+temp); + ExecuteTheRecipe.WriteAsync("大火比例阀开度", temp); + ToastUtils.info("大火比例阀开度:" + temp); + } + }); + + slider_强火.setOnSliderTouchListener(new NiftySlider.OnSliderTouchListener() { + @Override + public void onStartTrackingTouch(@NonNull NiftySlider niftySlider) { + + } + + @Override + public void onStopTrackingTouch(@NonNull NiftySlider niftySlider) { + int temp = (int) slider_强火.getValue(); + ExecuteTheRecipe.showlog("手动设置-强火比例值:"+temp); + ExecuteTheRecipe.WriteAsync("强火比例阀开度", temp); + ToastUtils.info("强火比例阀开度:" + temp); + } + }); + + slider_搅拌频率.setOnSliderTouchListener(new NiftySlider.OnSliderTouchListener() { + @Override + public void onStartTrackingTouch(@NonNull NiftySlider niftySlider) { + + } + + @Override + public void onStopTrackingTouch(@NonNull NiftySlider niftySlider) { + int temp = (int) slider_搅拌频率.getValue(); + ExecuteTheRecipe.showlog("手动设置-搅拌速度:"+temp); + ExecuteTheRecipe.WriteAsync("搅拌速度", temp); + ToastUtils.info("搅拌速度:" + temp); + } + }); + } + //endregion +} \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java index d85a7955..73c7dba7 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java @@ -13,6 +13,7 @@ import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -31,10 +32,12 @@ import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.DataBus; +import com.bonait.bnframework.common.db.DeviceDataDb; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; +import com.bonait.bnframework.common.db.mode.BPA_PRODUCTION_DATA; import com.bonait.bnframework.common.db.res.StatusMode; import com.bonait.bnframework.common.helper.AlertDialogButton; import com.bonait.bnframework.common.helper.CountDownTimerExt; @@ -55,14 +58,18 @@ import com.bonait.bnframework.modules.home.adapter.devicestatus_adapter; import com.bonait.bnframework.modules.home.fragment.from.CpxzActivity; import com.bumptech.glide.Glide; import com.capton.colorfulprogressbar.ColorfulProgressbar; +import com.google.gson.Gson; import com.litao.slider.NiftySlider; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; import com.suke.widget.SwitchButton; +import java.text.DecimalFormat; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; +import java.util.Random; import java.util.stream.Stream; import butterknife.BindView; @@ -127,18 +134,6 @@ public class MakeGoodFragment extends BaseFragment { @BindView(R.id.IgnitionStatus) TextView IgnitionStatus; -// @BindView(R.id.btn_xtkz) -// Button button_xtkz; - -// @BindView(R.id.btn_hlkz) -// Button button_hlkz; - -// @BindView(R.id.btn_sjkz) -// Button button_sjkz; - -// @BindView(R.id.btn_jykz) -// Button button_jykz; - /** * 当前制作商品信息 */ @@ -183,122 +178,142 @@ public class MakeGoodFragment extends BaseFragment { Init_弹窗(); } + + private synchronized void RefreshButton(int id,boolean value,String trueText,String falseText){ + Button button = activity.findViewById(id); + if(!value){ + button.setText(trueText); + }else{ + button.setText(falseText); + } + } + /** * 通知属性初始化 */ private void NotifyProp(){ //系统启停状态更新 - ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - switch_系统启停.setChecked(s); - switch_系统启停.setEnabled(true); - MessageLog.ShowInfo("更新开关状态:"+(s?"true":"false")); - });}; +// ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +//// switch_系统启停.setText(s); +// RefreshButton(R.id.switch_系统启停,s,"启动","停止"); +// switch_系统启停.setEnabled(true); +// MessageLog.ShowInfo("更新开关状态:"+(s?"true":"false")); +// });}; //超温停气状态更新 - ExecuteTheRecipe.getDeviceData.OverTemperatureShutdownNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - switch_超温停气.setChecked(s); - switch_超温停气.setEnabled(true); - });}; +// ExecuteTheRecipe.getDeviceData.OverTemperatureShutdownNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +//// switch_超温停气.setChecked(s); +// RefreshButton(R.id.switch_超温停气,s,"启用","禁用"); +// switch_超温停气.setEnabled(true); +// });}; //点火模式状态更新 - ExecuteTheRecipe.getDeviceData.IgnideModeNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - RB_Hand.setChecked(s?true:false); - if(!s) RB_Auto.setChecked(true); - });}; +// ExecuteTheRecipe.getDeviceData.IgnideModeNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// RB_Hand.setChecked(s?true:false); +// if(!s) RB_Auto.setChecked(true); +// });}; //小火比例阀开度更新 - ExecuteTheRecipe.getDeviceData.SmallFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - slider_小火.setValue( s,false); - });}; +// ExecuteTheRecipe.getDeviceData.SmallFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// slider_小火.setValue( s,false); +// });}; //中火比例阀开度更新 - ExecuteTheRecipe.getDeviceData.MediumFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - slider_中火.setValue( s,false); - });}; +// ExecuteTheRecipe.getDeviceData.MediumFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// slider_中火.setValue( s,false); +// });}; //大火比例阀开度更新 - ExecuteTheRecipe.getDeviceData.HighFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - slider_大火.setValue( s,false); - });}; +// ExecuteTheRecipe.getDeviceData.HighFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// slider_大火.setValue( s,false); +// });}; //强火比例阀开度更新 - ExecuteTheRecipe.getDeviceData.StrongFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - slider_强火.setValue( s,false); - });}; +// ExecuteTheRecipe.getDeviceData.StrongFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// slider_强火.setValue( s,false); +// });}; //搅拌速度更新 - ExecuteTheRecipe.getDeviceData.StirSpeedNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - slider_搅拌频率.setValue( s,false); - });}; +// ExecuteTheRecipe.getDeviceData.StirSpeedNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// slider_搅拌频率.setValue( s,false); +// });}; //小火控制状态更新 - ExecuteTheRecipe.getDeviceData.SmallFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - switch_小火.setChecked(s); - switch_小火.setEnabled(true); - });}; +// ExecuteTheRecipe.getDeviceData.SmallFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +//// switch_小火.setChecked(s); +// RefreshButton(R.id.switch_小火,s,"打开","关闭"); +// switch_小火.setEnabled(true); +// });}; //中火控制状态更新 - ExecuteTheRecipe.getDeviceData.MediumFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - switch_中火.setChecked(s); - switch_中火.setEnabled(true); - });}; +// ExecuteTheRecipe.getDeviceData.MediumFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +//// switch_中火.setChecked(s); +// RefreshButton(R.id.switch_中火,s,"打开","关闭"); +// switch_中火.setEnabled(true); +// });}; //大火控制状态更新 - ExecuteTheRecipe.getDeviceData.HighFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - switch_大火.setChecked(s); - switch_大火.setEnabled(true); - });}; +// ExecuteTheRecipe.getDeviceData.HighFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +//// switch_大火.setChecked(s); +// RefreshButton(R.id.switch_大火,s,"打开","关闭"); +// switch_大火.setEnabled(true); +// });}; //强火控制状态更新 - ExecuteTheRecipe.getDeviceData.StrongFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - switch_强火.setChecked(s); - switch_强火.setEnabled(true); - });}; +// ExecuteTheRecipe.getDeviceData.StrongFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +//// switch_强火.setChecked(s); +// RefreshButton(R.id.switch_强火,s,"打开","关闭"); +// switch_强火.setEnabled(true); +// });}; //点火控制状态更新 - ExecuteTheRecipe.getDeviceData.IgnitionStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - switch_点火控制.setChecked(s); - switch_点火控制.setEnabled(true); - });}; +// ExecuteTheRecipe.getDeviceData.IgnitionStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +//// switch_点火控制.setChecked(s); +// RefreshButton(R.id.switch_点火控制,s,"点火","关火"); +// switch_点火控制.setEnabled(true); +// });}; //温度修正值更新 - ExecuteTheRecipe.getDeviceData.TemperatureCorrectionValueNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - edit_温度修正.setText(s.toString()); - });}; +// ExecuteTheRecipe.getDeviceData.TemperatureCorrectionValueNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// edit_温度修正.setText(s.toString()); +// });}; //炒锅温度上限设置值更新 - ExecuteTheRecipe.getDeviceData.UpperTemperatureLimitNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - edit_温度上限.setText(s.toString()); - });}; +// ExecuteTheRecipe.getDeviceData.UpperTemperatureLimitNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// edit_温度上限.setText(s.toString()); +// });}; //搅拌控制状态更新 - ExecuteTheRecipe.getDeviceData.StirControlStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - switch_搅拌控制.setChecked(s); - switch_搅拌控制.setEnabled(true); - });}; +// ExecuteTheRecipe.getDeviceData.StirControlStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +//// switch_搅拌控制.setChecked(s); +// RefreshButton(R.id.switch_搅拌控制,s,"启动搅拌","停止搅拌"); +// switch_搅拌控制.setEnabled(true); +// });}; //抽油启停状态更新 - ExecuteTheRecipe.getDeviceData.OilPumpingStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - switch_抽油启停.setChecked(s); - switch_抽油启停.setEnabled(true); - });}; +// ExecuteTheRecipe.getDeviceData.OilPumpingStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +//// switch_抽油启停.setChecked(s); +// RefreshButton(R.id.switch_抽油启停,s,"启动抽油","停止抽油"); +// switch_抽油启停.setEnabled(true); +// });}; //备用气缸起停状态更新 - ExecuteTheRecipe.getDeviceData.StandbyCylinderStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - switch_备用气缸.setChecked(s); - switch_备用气缸.setEnabled(true); - });}; +// ExecuteTheRecipe.getDeviceData.StandbyCylinderStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +//// switch_备用气缸.setChecked(s); +// RefreshButton(R.id.switch_备用气缸,s,"启动","停止"); +// switch_备用气缸.setEnabled(true); +// });}; //设定重量状态更新 - ExecuteTheRecipe.getDeviceData.SetWeightNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - edit_设定重量.setText(s.toString()); - });}; +// ExecuteTheRecipe.getDeviceData.SetWeightNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// edit_设定重量.setText(s.toString()); +// });}; //提前量状态更新 - ExecuteTheRecipe.getDeviceData.LeadNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - edit_提前量.setText(s.toString()); - });}; +// ExecuteTheRecipe.getDeviceData.LeadNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// edit_提前量.setText(s.toString()); +// });}; //急停故障 ExecuteTheRecipe.getDeviceData.EstopFaultNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ @@ -316,10 +331,10 @@ public class MakeGoodFragment extends BaseFragment { });}; //点火异常故障 - ExecuteTheRecipe.getDeviceData.IgnitionMalfunction.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ - MessageLog.ShowError(s?"点火故障触发":"点火故障复位"); - IgnitionStatus.setText(s?"点火失败":"点火正常"); - });}; +// ExecuteTheRecipe.getDeviceData.IgnitionMalfunction.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ +// MessageLog.ShowError(s?"点火故障触发":"点火故障复位"); +// IgnitionStatus.setText(s?"点火失败":"点火正常"); +// });}; //高温报警故障 ExecuteTheRecipe.getDeviceData.HighTemperatureAlarm.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ @@ -377,7 +392,7 @@ public class MakeGoodFragment extends BaseFragment { * @param view */ @OnClick({R.id.xzcp, R.id.startbutton - , R.id.btn_xtkz +// , R.id.btn_xtkz // , R.id.btn_hlkz // , R.id.btn_sjkz, R.id.btn_jykz , R.id.close_xtkz @@ -392,7 +407,6 @@ public class MakeGoodFragment extends BaseFragment { switch (view.getId()) { case R.id.xzcp://选择菜谱按钮点击 skipToActivity(CpxzActivity.class); -// ToastUtils.info("打开菜谱选择界面"); break; case R.id.btn_xtkz: SetVisibility(1); @@ -431,6 +445,7 @@ public class MakeGoodFragment extends BaseFragment { } }); } + break; case R.id.button_出料: @@ -493,64 +508,64 @@ public class MakeGoodFragment extends BaseFragment { /** * 开关事件处理 */ - public SwitchButton.OnTouchListener TouchListener = new SwitchButton.OnTouchListener() { - @Override - public boolean onTouch(View view, MotionEvent motionEvent) { - if (motionEvent.getAction() == MotionEvent.ACTION_UP) { - CommHelper.get().siemens. CancelWrite=true; -// Delay(300); - switch (view.getId()) { - case R.id.switch_系统启停: - ExecuteTheRecipe.showlog("手动操作-系统启停开关,值:"+!switch_系统启停.isChecked()); -// ExecuteTheRecipe.WriteAsync("系统启停开关", !switch_系统启停.isChecked()); - ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.setValue(!switch_系统启停.isChecked()); - break; - case R.id.switch_超温停气: - ExecuteTheRecipe.showlog("手动操作-超温停气开关,值:"+!switch_超温停气.isChecked()); - ExecuteTheRecipe.WriteAsync("超温停气开关",!switch_超温停气.isChecked()); - break; - case R.id.switch_搅拌控制: - if (!switch_搅拌控制.isChecked()) { - ExecuteTheRecipe.showlog("手动启动搅拌"); - ExecuteTheRecipe.BottomClickAsync("搅拌启动开关"); - } else { - ExecuteTheRecipe.showlog("手动停止搅拌"); - ExecuteTheRecipe.BottomClickAsync("搅拌停止开关"); - } - break; - case R.id.switch_抽油启停: - ExecuteTheRecipe.showlog("手动操作-抽油启停开关,值:"+!switch_抽油启停.isChecked()); - ExecuteTheRecipe.WriteAsync("料仓1出料",!switch_抽油启停.isChecked()); - break; - case R.id.switch_备用气缸: - ExecuteTheRecipe.showlog("手动操作-备用气缸开关,值:"+!switch_备用气缸.isChecked()); - ExecuteTheRecipe.WriteAsync("料仓2出料",!switch_备用气缸.isChecked()); - break; - case R.id.switch_点火控制: - ExecuteTheRecipe.showlog("手动操作-点火启动开关,值:"+!switch_点火控制.isChecked()); - ExecuteTheRecipe.WriteAsync("点火启动开关",!switch_点火控制.isChecked()); - break; - case R.id.switch_小火: - ExecuteTheRecipe.showlog("手动操作-小火开关,值:"+!switch_小火.isChecked()); - ExecuteTheRecipe.WriteAsync("小火开关(一圈)", !switch_小火.isChecked()); - break; - case R.id.switch_中火: - ExecuteTheRecipe.showlog("手动操作-中火开关,值:"+!switch_中火.isChecked()); - ExecuteTheRecipe.WriteAsync("中火开关(二圈)", !switch_中火.isChecked()); - break; - case R.id.switch_大火: - ExecuteTheRecipe.showlog("手动操作-大火开关,值:"+!switch_大火.isChecked()); - ExecuteTheRecipe.WriteAsync("大火开关(三圈)", !switch_大火.isChecked()); - break; - case R.id.switch_强火: - ExecuteTheRecipe.showlog("手动操作-强火开关,值:"+!switch_强火.isChecked()); - ExecuteTheRecipe.WriteAsync("强火开关(四圈)", !switch_强火.isChecked()); - break; - } - } - return false; - } - }; +// public SwitchButton.OnTouchListener TouchListener = new SwitchButton.OnTouchListener() { +// @Override +// public boolean onTouch(View view, MotionEvent motionEvent) { +// if (motionEvent.getAction() == MotionEvent.ACTION_UP) { +// CommHelper.get().siemens. CancelWrite=true; +//// Delay(300); +// switch (view.getId()) { +// case R.id.switch_系统启停: +// ExecuteTheRecipe.showlog("手动操作-系统启停开关,值:"+!switch_系统启停.isChecked()); +//// ExecuteTheRecipe.WriteAsync("系统启停开关", !switch_系统启停.isChecked()); +// ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.setValue(!switch_系统启停.isChecked()); +// break; +// case R.id.switch_超温停气: +// ExecuteTheRecipe.showlog("手动操作-超温停气开关,值:"+!switch_超温停气.isChecked()); +// ExecuteTheRecipe.WriteAsync("超温停气开关",!switch_超温停气.isChecked()); +// break; +// case R.id.switch_搅拌控制: +// if (!switch_搅拌控制.isChecked()) { +// ExecuteTheRecipe.showlog("手动启动搅拌"); +// ExecuteTheRecipe.BottomClickAsync("搅拌启动开关"); +// } else { +// ExecuteTheRecipe.showlog("手动停止搅拌"); +// ExecuteTheRecipe.BottomClickAsync("搅拌停止开关"); +// } +// break; +// case R.id.switch_抽油启停: +// ExecuteTheRecipe.showlog("手动操作-抽油启停开关,值:"+!switch_抽油启停.isChecked()); +// ExecuteTheRecipe.WriteAsync("料仓1出料",!switch_抽油启停.isChecked()); +// break; +// case R.id.switch_备用气缸: +// ExecuteTheRecipe.showlog("手动操作-备用气缸开关,值:"+!switch_备用气缸.isChecked()); +// ExecuteTheRecipe.WriteAsync("料仓2出料",!switch_备用气缸.isChecked()); +// break; +// case R.id.switch_点火控制: +// ExecuteTheRecipe.showlog("手动操作-点火启动开关,值:"+!switch_点火控制.isChecked()); +// ExecuteTheRecipe.WriteAsync("点火启动开关",!switch_点火控制.isChecked()); +// break; +// case R.id.switch_小火: +// ExecuteTheRecipe.showlog("手动操作-小火开关,值:"+!switch_小火.isChecked()); +// ExecuteTheRecipe.WriteAsync("小火开关(一圈)", !switch_小火.isChecked()); +// break; +// case R.id.switch_中火: +// ExecuteTheRecipe.showlog("手动操作-中火开关,值:"+!switch_中火.isChecked()); +// ExecuteTheRecipe.WriteAsync("中火开关(二圈)", !switch_中火.isChecked()); +// break; +// case R.id.switch_大火: +// ExecuteTheRecipe.showlog("手动操作-大火开关,值:"+!switch_大火.isChecked()); +// ExecuteTheRecipe.WriteAsync("大火开关(三圈)", !switch_大火.isChecked()); +// break; +// case R.id.switch_强火: +// ExecuteTheRecipe.showlog("手动操作-强火开关,值:"+!switch_强火.isChecked()); +// ExecuteTheRecipe.WriteAsync("强火开关(四圈)", !switch_强火.isChecked()); +// break; +// } +// } +// return false; +// } +// }; public void InchingControl(View view,Boolean IsChick) { @@ -638,10 +653,30 @@ public class MakeGoodFragment extends BaseFragment { } countDownTimer.start(); ExecuteTheRecipe.IsStart.setValue(true); + ProcessDataSave(); } }); } + private void ProcessDataSave(){ + new Thread(()->{ + while ( ExecuteTheRecipe.IsStart.getValue()&&good!=null){ + try { + DeviceDataDb.get().AddProduction(new BPA_PRODUCTION_DATA(good.name,ExecuteTheRecipe.getDeviceData.CurrentTemperature,ExecuteTheRecipe.getDeviceData.CurrentWeight)); + Thread.sleep(1000); + }catch (InterruptedException ex) { + } + } + if(!ExecuteTheRecipe.IsForcedEnd){ + DeviceDataDb.get().SaveProduction(); + }else{ + DeviceDataDb.get().ResetProduction(); + } + + }).start(); + + } + /** * 停止 */ @@ -1088,19 +1123,19 @@ public class MakeGoodFragment extends BaseFragment { //region 弹窗处理 @BindView(R.id.switch_系统启停) - SwitchButton switch_系统启停; + Button switch_系统启停; @BindView(R.id.switch_超温停气) - SwitchButton switch_超温停气; + Button switch_超温停气; @BindView(R.id.switch_搅拌控制) - SwitchButton switch_搅拌控制; + Button switch_搅拌控制; @BindView(R.id.switch_抽油启停) - SwitchButton switch_抽油启停; + Button switch_抽油启停; @BindView(R.id.switch_备用气缸) - SwitchButton switch_备用气缸; + Button switch_备用气缸; // @BindView(R.id.editsp_物料) // Spinner editsp_物料; @@ -1117,7 +1152,7 @@ public class MakeGoodFragment extends BaseFragment { RadioButton RB_Auto; @BindView(R.id.switch_点火控制) - SwitchButton switch_点火控制; + Button switch_点火控制; @BindView(R.id.button_搅拌点动) @@ -1221,21 +1256,89 @@ public class MakeGoodFragment extends BaseFragment { } }; + + private void DeviceControl(boolean isChecked,String name){ + if(isChecked&&!ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.getValue()){ + AlertDialogUtils.showDialog("系统未启动,请启动后重试!", AlertDialogButton.OK,null); + } + ExecuteTheRecipe.showlog("手动操作-"+name+",值:"+isChecked); + ExecuteTheRecipe.WriteAsync(name,isChecked); + } + + @OnClick({R.id.switch_系统启停, R.id.switch_超温停气 + , R.id.switch_搅拌控制 + , R.id.switch_抽油启停 + ,R.id.switch_备用气缸 + , R.id.switch_点火控制 + , R.id.switch_小火,R.id.switch_中火 + , R.id.switch_大火,R.id.switch_强火 + }) + public void onButtonClicked(View view) { + switch (view.getId()) { + case R.id.switch_系统启停: + ExecuteTheRecipe.showlog("手动操作-系统启停开关,值:"+!ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.getValue()); + ExecuteTheRecipe.WriteAsync("系统启停开关", !ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.getValue()); + break; + case R.id.switch_超温停气: + DeviceControl(!ExecuteTheRecipe.getDeviceData.OverTemperatureShutdownNotify.getValue(),"超温停气开关"); + break; + case R.id.switch_搅拌控制: + boolean temp=!ExecuteTheRecipe.getDeviceData.StirControlStatusNotify.getValue(); + if (temp) { + if(!ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.getValue()){ + AlertDialogUtils.showDialog("系统未启动,请启动后重试!", AlertDialogButton.OK,null); + } + ExecuteTheRecipe.showlog("手动启动搅拌"); + ExecuteTheRecipe.BottomClickAsync("搅拌启动开关"); + } else { + ExecuteTheRecipe.showlog("手动停止搅拌"); + ExecuteTheRecipe.BottomClickAsync("搅拌停止开关"); + } + break; + case R.id.switch_抽油启停: + DeviceControl(!ExecuteTheRecipe.getDeviceData.OilPumpingStatusNotify.getValue(),"料仓1出料"); + break; + case R.id.switch_备用气缸: + DeviceControl(!ExecuteTheRecipe.getDeviceData.StandbyCylinderStatusNotify.getValue(),"料仓2出料"); + break; + case R.id.switch_点火控制: + DeviceControl(!ExecuteTheRecipe.getDeviceData.IgnitionStatusNotify.getValue(),"点火启动开关"); + break; + case R.id.switch_小火: + DeviceControl(!ExecuteTheRecipe.getDeviceData.SmallFireStatusNotify.getValue(),"小火开关(一圈)"); + break; + case R.id.switch_中火: + DeviceControl(!ExecuteTheRecipe.getDeviceData.MediumFireStatusNotify.getValue(),"中火开关(二圈)"); + break; + case R.id.switch_大火: + DeviceControl(!ExecuteTheRecipe.getDeviceData.HighFireStatusNotify.getValue(),"大火开关(三圈)"); + break; + case R.id.switch_强火: + DeviceControl(!ExecuteTheRecipe.getDeviceData.StrongFireStatusNotify.getValue(),"强火开关(四圈)"); + break; + } + } + + + + /** * 初始化弹框中的事件 */ public void Init_弹窗_事件() { - switch_系统启停.setOnCheckedChangeListener(SeitchChanged); - switch_超温停气.setOnCheckedChangeListener(SeitchChanged); - switch_搅拌控制.setOnCheckedChangeListener(SeitchChanged); - switch_抽油启停.setOnCheckedChangeListener(SeitchChanged); - switch_备用气缸.setOnCheckedChangeListener(SeitchChanged); - switch_点火控制.setOnCheckedChangeListener(SeitchChanged); - switch_小火.setOnCheckedChangeListener(SeitchChanged); - switch_中火.setOnCheckedChangeListener(SeitchChanged); - switch_大火.setOnCheckedChangeListener(SeitchChanged); - switch_强火.setOnCheckedChangeListener(SeitchChanged); +// switch_系统启停.setOnCheckedChangeListener(SeitchChanged); +// switch_超温停气.setOnCheckedChangeListener(SeitchChanged); +// switch_搅拌控制.setOnCheckedChangeListener(SeitchChanged); +// switch_抽油启停.setOnCheckedChangeListener(SeitchChanged); +// switch_备用气缸.setOnCheckedChangeListener(SeitchChanged); +// switch_点火控制.setOnCheckedChangeListener(SeitchChanged); +// switch_小火.setOnCheckedChangeListener(SeitchChanged); +// switch_中火.setOnCheckedChangeListener(SeitchChanged); +// switch_大火.setOnCheckedChangeListener(SeitchChanged); +// switch_强火.setOnCheckedChangeListener(SeitchChanged); + + // switch_系统启停.setOnTouchListener(TouchListener); @@ -1314,16 +1417,16 @@ public class MakeGoodFragment extends BaseFragment { NiftySlider slider_搅拌频率; @BindView(R.id.switch_小火) - SwitchButton switch_小火; + Button switch_小火; @BindView(R.id.switch_中火) - SwitchButton switch_中火; + Button switch_中火; @BindView(R.id.switch_大火) - SwitchButton switch_大火; + Button switch_大火; @BindView(R.id.switch_强火) - SwitchButton switch_强火; + Button switch_强火; /** * 初始化火力 diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyActivity.java index aba44877..e471e8ae 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyActivity.java @@ -74,7 +74,7 @@ public class DiyActivity extends BaseActivity { ImageView cpfm;//菜谱封面 @BindView(R.id.zzsc) EditText zzsc;//制作时长 - @BindView(R.id.check) +// @BindView(R.id.check) CheckBox check;//默认收藏 List Banner_list = new ArrayList<>(); diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/OrderListActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/OrderListActivity.java index 84cbfbdd..1cd8b8b0 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/OrderListActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/OrderListActivity.java @@ -20,17 +20,36 @@ import com.bigkoo.pickerview.TimePickerView; import com.bonait.bnframework.R; import com.bonait.bnframework.common.base.BaseActivity; import com.bonait.bnframework.common.db.QueryDB; +import com.bonait.bnframework.common.db.mode.BPA_GOODS; +import com.bonait.bnframework.common.db.mode.BPA_PRODUCTION_DATA; import com.bonait.bnframework.common.db.res.ResSubOrder; +import com.bonait.bnframework.common.db.res.SuOrderTJ; import com.bonait.bnframework.common.helper.DateUtils; +import com.bonait.bnframework.common.helper.I.IRunT; +import com.bonait.bnframework.common.helper.ProductionHelper; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.modules.home.adapter.ddgl_adapter; +import com.bonait.bnframework.modules.home.adapter.ddtj_adapter; +import com.bonait.bnframework.modules.home.fragment.DingDanfragment; +import com.github.mikephil.charting.charts.LineChart; +import com.github.mikephil.charting.components.Legend; +import com.github.mikephil.charting.components.XAxis; +import com.github.mikephil.charting.components.YAxis; +import com.github.mikephil.charting.data.Entry; +import com.github.mikephil.charting.data.LineData; +import com.github.mikephil.charting.data.LineDataSet; +import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; +import com.github.mikephil.charting.utils.EntryXComparator; +import com.google.gson.Gson; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; import java.util.Date; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import butterknife.BindView; @@ -39,72 +58,26 @@ import butterknife.OnClick; public class OrderListActivity extends BaseActivity { - @BindView(R.id.topbar) QMUITopBarLayout mTopBar; - //region 操作变量 - /** - * 输入框 - */ - @BindView(R.id.edittext) - TextView edittext; - /** - * 查询按钮 - */ - @BindView(R.id.button) - Button button; - /** - * 表格显示 - */ - @BindView(R.id.datatab) - ListView datatab; - /** - * 子订单数据 - */ - ArrayList subOrders = new ArrayList<>(); - /** - * 订单管理控制器 - */ - ddgl_adapter adapter; - /** - * 日期选择器 - */ - TimePickerView pvTime; - /** - * 开始时间-结束时间 - */ - @BindView(R.id.starttime) - EditText starttime; - @BindView(R.id.stoptime) - EditText stoptime; + @BindView(R.id.chart1) + LineChart chart; + + private Context context; - @BindView(R.id.count) - TextView count; - /** - * 日志类型 - */ - @BindView(R.id.rzlx) - Spinner rzlx; - Map lx_map = new LinkedHashMap<>(); - //endregion - private Context context;private ViewGroup view; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_order_list); - ButterKnife.bind(this); - view=(ViewGroup)getWindow().getDecorView(); - context = getContext(); initTopBar(); - initFragment(); - Init(); + ChartInit(); } private void initTopBar() { - mTopBar.setTitle("订单列表"); + mTopBar.setTitle(DingDanfragment.getProductionData.goodName+"--趋势图"); mTopBar.addLeftImageButton(R.mipmap.fanhui,R.id.topbar).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -113,116 +86,116 @@ public class OrderListActivity extends BaseActivity { }); } - /** - * 初始化 - */ - private void Init(){ - //通过Activity.getIntent()获取当前页面接收到的Intent。 getXxxExtra方法获取Intent传递过来的数据 - lx_map.put("全部",-1); - lx_map.put("未开始",0); - lx_map.put("制作中",1); - lx_map.put("已制作",2); - lx_map.put("已超时",3); - ArrayAdapter adapter2 = new ArrayAdapter<>(context, R.layout.spinner_text_item, new ArrayList<>(lx_map.keySet())); - adapter2.setDropDownViewResource(R.layout.spinner_dropdown_item); - rzlx.setAdapter(adapter2); - - starttime.setText(new SimpleDateFormat("yyyy-MM-dd 00:00:00").format(new Date())); - stoptime.setText(new SimpleDateFormat("yyyy-MM-dd 23:59:59").format(new Date())); - starttime.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (pvTime != null) { - pvTime.show(starttime); - } - } - }); - stoptime.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (pvTime != null) { - pvTime.show(stoptime); - } - } - }); - CalendarTime(); - Initdata(); - } - /** - * CalendarTime - * 时间选择器 - */ - public void CalendarTime() { - //控制时间范围(如果不设置范围,则使用默认时间1900-2100年,此段代码可注释) - //因为系统Calendar的月份是从0-11的,所以如果是调用Calendar的set方法来设置时间,月份的范围也要是从0-11 - Calendar selectedDate = Calendar.getInstance(); - Calendar startDate = Calendar.getInstance(); - startDate.set(2023, 0, 23); - Calendar endDate = Calendar.getInstance(); - endDate.set(2099, 11, 28); - //时间选择器 - pvTime = new TimePickerView.Builder(context, new TimePickerView.OnTimeSelectListener() { - @Override - public void onTimeSelect(Date date, View v) {//选中事件回调 - // 这里回调过来的v,就是show()方法里面所添加的 View 参数,如果show的时候没有添加参数,v则为null - TextView btn = (TextView) v; - btn.setText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date)); - } - }) - //年月日时分秒 的显示与否,不设置则默认全部显示 - .setType(new boolean[]{true, true, true, true, true, false}) - .setLabel("年", "月", "日", "时", "分", "秒") - .isCenterLabel(true) - .setDividerColor(Color.DKGRAY) - .setContentSize(16)//字号 - .setDate(selectedDate) - .setRangDate(startDate, endDate) - .setDecorView(view) - .build(); - } + private void setData() { - /** - * 初始化数据加载 - */ - public void Initdata() { - try { - String str= starttime.getText().toString(); - String stop= stoptime.getText().toString(); - if(DateUtils.compareDate(stop,str)) - { - ToastUtils.warning("开始时间不能大于结束时间!!!"); - return; - } - String lx= rzlx.getSelectedItem().toString(); - String text= edittext.getText().toString(); - subOrders= QueryDB.GetSubOrders(str,stop, lx_map.get(lx),text); - count.setText(subOrders.size()+""); - adapter = new ddgl_adapter(context,R.layout.ddgl_item,subOrders); - datatab.setAdapter(adapter); - } catch (Exception e) { + BPA_PRODUCTION_DATA pd = DingDanfragment.getProductionData; - } - } - //endregion + Float[] weight = new Gson().fromJson(pd.weight,Float[].class); + Float[] temperature = new Gson().fromJson(pd.temperature,Float[].class); - //region 点击事件 + if(weight.length==temperature.length&&temperature.length>0) { + List temperatures = new ArrayList<>(); + List weights = new ArrayList<>(); + for (int i = 0; i < temperature.length; i++) { + temperatures.add(new Entry(i,temperature[i])); + weights.add(new Entry(i,weight[i])); + } - @OnClick({R.id.button}) - public void onViewClicked(View view) { - switch (view.getId()) { - case R.id.button://查询按钮 - Initdata(); - break; + //温度曲线设置 + LineDataSet temperatureSet = new LineDataSet(temperatures, "温度"); + temperatureSet.setAxisDependency(YAxis.AxisDependency.LEFT); + temperatureSet.setColor(Color.argb(255,89, 194, 172)); + temperatureSet.setDrawCircles(false);//是否绘制圆点 + temperatureSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER); + temperatureSet.setValueTextSize(20); +// Collections.sort(temperatureSet, new EntryXComparator());//通过x坐标值排序 + + //重量曲线设置 + LineDataSet weightSet = new LineDataSet(weights, "重量"); + weightSet.setAxisDependency(YAxis.AxisDependency.LEFT); + weightSet.setDrawCircles(false); + weightSet.setColor(Color.argb(255,159, 203, 2)); + weightSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER); + weightSet.setValueTextSize(20); + + //将所有曲线添加到集合 + List dataSets = new ArrayList<>(); + dataSets.add(temperatureSet); + dataSets.add(weightSet); + + LineData lineData = new LineData(dataSets); + chart.setData(lineData); + chart.invalidate(); //刷新绘图 } } - //endregion + /** - * viewPager里添加fragment + * 折线图初始化 */ - private void initFragment() { + private void ChartInit(){ + + chart.clear(); + + //chart.setOnChartValueSelectedListener(this); //点击监听 + chart.setDrawGridBackground(false);//绘制网格线 + chart.getDescription().setEnabled(false); //描述文本 + chart.setTouchEnabled(true);//是否可以触摸 + //启用缩放和拖动 + chart.setDragEnabled(true); + chart.setScaleEnabled(true); + + chart.setPinchZoom(true);// 如果禁用,可以分别在x轴和y轴上进行缩放 + chart.setExtraOffsets(0,10,10,20);//设置要附加到自动计算的偏移的额外偏移(围绕图表视图)。 + chart.setBackgroundColor(Color.argb(255,250, 250, 250)); //设置背景色 +// chart.setBackgroundColor(Color.argb(255,23, 23, 39)); + + //创建自定义MarkerView(扩展MarkerView)并指定布局 + //MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view); + //mv.setChartView(chart); // For bounds control + //chart.setMarker(mv); // Set the marker to the chart + + //图例设置 + Legend legend=chart.getLegend(); + legend.setOrientation(Legend.LegendOrientation.HORIZONTAL);//设置图例的方向 + legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);//设置图例的水平对齐方式 + legend.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);//设置图例的垂直对齐方式 + legend.setTextSize(20); + + //配置x坐标数据 + XAxis xl = chart.getXAxis(); + xl.setAvoidFirstLastClipping(true); + xl.setAxisMinimum(0f); + xl.setTextSize(20); + xl.setDrawAxisLine(true);//绘制X轴旁边的线 + xl.setDrawGridLines(false);//将此设置为true可启用绘制此轴的轴线。 + xl.setPosition(XAxis.XAxisPosition.BOTTOM);//设置X轴标签在底部显示 + + //配置y坐标左边数据 + YAxis leftAxis = chart.getAxisLeft(); + leftAxis.setInverted(false); + leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true) + leftAxis.setTextSize(20); + leftAxis.setDrawGridLines(false);//将此设置为true可启用绘制此轴的轴线。 + + + //关闭y坐标右边数据 + YAxis rightAxis = chart.getAxisRight(); + rightAxis.setEnabled(false); + + //抑制最大比例因子 + // chart.setScaleMinima(3f, 3f); + + //将视图居中到图表中的特定位置 + // chart.centerViewPort(10, 50); + + //图例 + Legend l = chart.getLegend(); + //修改图例 + l.setForm(Legend.LegendForm.LINE); + + setData(); } - //-------------------------配置viewPager与fragment关联----------------------------// @Override public void onDestroy() { diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SalesStatisticsActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SalesStatisticsActivity.java index 70e5384d..0130334e 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SalesStatisticsActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SalesStatisticsActivity.java @@ -200,7 +200,7 @@ public class SalesStatisticsActivity extends BaseActivity { } - adapter = new ddtj_adapter(context,R.layout.ddtj_item,subOrdersStatic); +// adapter = new ddtj_adapter(context,R.layout.ddtj_item,subOrdersStatic); datatab.setAdapter(adapter); } catch (Exception e) { diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java index a1d84a91..81fb6ff4 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java @@ -42,7 +42,7 @@ public class SystemParameterActivity extends BaseActivity { EditText edittext3; @BindView(R.id.edittext4) EditText edittext4; - @BindView(R.id.environment) +// @BindView(R.id.environment) Spinner environment; @BindView(R.id.versionselection) diff --git a/app/src/main/res/drawable/bg_btn_false_color.xml b/app/src/main/res/drawable/bg_btn_false_color.xml new file mode 100644 index 00000000..b8225b20 --- /dev/null +++ b/app/src/main/res/drawable/bg_btn_false_color.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/silosbj.xml b/app/src/main/res/drawable/silosbj.xml index fc09f223..c7f50df9 100644 --- a/app/src/main/res/drawable/silosbj.xml +++ b/app/src/main/res/drawable/silosbj.xml @@ -8,7 +8,7 @@ diff --git a/app/src/main/res/layout/activity_bottom_navigation_main.xml b/app/src/main/res/layout/activity_bottom_navigation_main.xml index 160655a2..ed91ff18 100644 --- a/app/src/main/res/layout/activity_bottom_navigation_main.xml +++ b/app/src/main/res/layout/activity_bottom_navigation_main.xml @@ -27,8 +27,9 @@ android:layout_alignParentBottom="true" android:background="@android:color/white" app:containerId="@+id/viewpager" - app:navigateTabSelectedTextColor="@color/comui_tab_text_color" - app:navigateTabTextColor="@color/comui_tab_text_color" /> + app:navigateTabSelectedTextColor="@color/black" + app:navigateTabTextSize="20sp" + app:navigateTabTextColor="@color/black" /> - + android:textSize="20dp" + android:textStyle="bold" /> + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_diy.xml b/app/src/main/res/layout/activity_diy.xml index 7bd68de9..8cd06625 100644 --- a/app/src/main/res/layout/activity_diy.xml +++ b/app/src/main/res/layout/activity_diy.xml @@ -56,7 +56,8 @@ @@ -76,7 +77,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" tools:ignore="TouchTargetSizeCheck" - android:text="菜谱名称:" /> + android:textSize="@dimen/textSize" + android:text="配方名称:" /> + android:textSize="@dimen/textSize" /> + - - - + android:textSize="@dimen/textSize" /> - + android:layout_height="wrap_content" + android:layout_marginLeft="5dp" + android:textSize="@dimen/textSize" + android:text="秒" /> + + + + + + + + + + + + + + + @@ -164,28 +177,29 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" tools:ignore="TouchTargetSizeCheck" + android:textSize="@dimen/textSize" android:text="步骤:" />