diff --git a/app/src/main/java/com/iflytop/profilometer/api/auth/AuthApi.java b/app/src/main/java/com/iflytop/profilometer/api/auth/AuthApi.java index 1e7e4ac..d3f232d 100644 --- a/app/src/main/java/com/iflytop/profilometer/api/auth/AuthApi.java +++ b/app/src/main/java/com/iflytop/profilometer/api/auth/AuthApi.java @@ -3,10 +3,8 @@ package com.iflytop.profilometer.api.auth; import android.content.Context; import com.iflytop.profilometer.common.result.Result; -import com.iflytop.profilometer.common.utils.GsonUtil; -import com.iflytop.profilometer.core.websocket.WebSocketManager; import com.iflytop.profilometer.dao.UserDao; -import com.iflytop.profilometer.model.entiy.AppUser; +import com.iflytop.profilometer.model.entity.AppUser; /** * 权限验证接口 diff --git a/app/src/main/java/com/iflytop/profilometer/api/measure/MeasureApi.java b/app/src/main/java/com/iflytop/profilometer/api/measure/MeasureApi.java index 16d6b88..b44a7b9 100644 --- a/app/src/main/java/com/iflytop/profilometer/api/measure/MeasureApi.java +++ b/app/src/main/java/com/iflytop/profilometer/api/measure/MeasureApi.java @@ -2,12 +2,6 @@ package com.iflytop.profilometer.api.measure; import android.content.Context; -import com.iflytop.profilometer.common.result.Result; -import com.iflytop.profilometer.common.utils.GsonUtil; -import com.iflytop.profilometer.core.websocket.WebSocketManager; -import com.iflytop.profilometer.dao.UserDao; -import com.iflytop.profilometer.model.entiy.AppUser; - /** * 测量接口 */ diff --git a/app/src/main/java/com/iflytop/profilometer/api/record/RecordApi.java b/app/src/main/java/com/iflytop/profilometer/api/record/RecordApi.java index 75be80e..77a617c 100644 --- a/app/src/main/java/com/iflytop/profilometer/api/record/RecordApi.java +++ b/app/src/main/java/com/iflytop/profilometer/api/record/RecordApi.java @@ -6,7 +6,7 @@ import com.iflytop.profilometer.common.result.Result; import com.iflytop.profilometer.common.utils.GsonUtil; import com.iflytop.profilometer.core.websocket.WebSocketManager; import com.iflytop.profilometer.dao.UserDao; -import com.iflytop.profilometer.model.entiy.AppUser; +import com.iflytop.profilometer.model.entity.AppUser; /** * 权限验证接口 diff --git a/app/src/main/java/com/iflytop/profilometer/api/system/SystemApi.java b/app/src/main/java/com/iflytop/profilometer/api/system/SystemApi.java index 715cc9d..c42c752 100644 --- a/app/src/main/java/com/iflytop/profilometer/api/system/SystemApi.java +++ b/app/src/main/java/com/iflytop/profilometer/api/system/SystemApi.java @@ -2,12 +2,6 @@ package com.iflytop.profilometer.api.system; import android.content.Context; -import com.iflytop.profilometer.common.result.Result; -import com.iflytop.profilometer.common.utils.GsonUtil; -import com.iflytop.profilometer.core.websocket.WebSocketManager; -import com.iflytop.profilometer.dao.UserDao; -import com.iflytop.profilometer.model.entiy.AppUser; - /** * 系统相关接口 */ diff --git a/app/src/main/java/com/iflytop/profilometer/core/db/helper/MyDatabaseHelper.java b/app/src/main/java/com/iflytop/profilometer/core/db/helper/MyDatabaseHelper.java index 8dda200..b43d400 100644 --- a/app/src/main/java/com/iflytop/profilometer/core/db/helper/MyDatabaseHelper.java +++ b/app/src/main/java/com/iflytop/profilometer/core/db/helper/MyDatabaseHelper.java @@ -7,48 +7,75 @@ import android.database.sqlite.SQLiteOpenHelper; public class MyDatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "app.db"; - private static final int DATABASE_VERSION = 1; + private static final int DATABASE_VERSION = 4; // 数据库版本升级 // 表名 public static final String TABLE_APP_USER = "app_user"; - public static final String TABLE_DEFAULT_BLUETOOTH = "default_bluetooth"; public static final String TABLE_PROFILE_RECORD = "profile_record_description"; + public static final String TABLE_PROFILE_RECORD_POINT_SET = "profile_record_point_set"; + public static final String TABLE_BASE_PROFILE_RECORD_POINT_SET = "base_profile_record_point_set"; + public static final String TABLE_SYSTEM_CONFIG = "system_config"; // 用户表建表语句 - private static final String CREATE_TABLE_APP_USER = "CREATE TABLE IF NOT EXISTS " + TABLE_APP_USER + " (" - + "id INTEGER PRIMARY KEY AUTOINCREMENT, " - + "create_time TEXT, " - + "update_time TEXT, " - + "account TEXT NOT NULL, " - + "nickname TEXT NOT NULL, " - + "password TEXT NOT NULL, " - + "usr_role TEXT, " // 存储枚举为字符串 - + "is_built_in_user INTEGER DEFAULT 0" - + ");"; - - // 默认蓝牙设备表建表语句 - private static final String CREATE_TABLE_DEFAULT_BLUETOOTH = "CREATE TABLE IF NOT EXISTS " + TABLE_DEFAULT_BLUETOOTH + " (" - + "id INTEGER PRIMARY KEY AUTOINCREMENT, " - + "create_time TEXT, " - + "update_time TEXT, " - + "bluetooth_id TEXT, " - + "bluetooth_name TEXT" - + ");"; + private static final String CREATE_TABLE_APP_USER = + "CREATE TABLE IF NOT EXISTS " + TABLE_APP_USER + " (" + + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + + "create_time TEXT, " + + "update_time TEXT, " + + "account TEXT NOT NULL, " + + "nickname TEXT NOT NULL, " + + "password TEXT NOT NULL, " + + "usr_role TEXT, " // 存储枚举为字符串 + + "is_built_in_user INTEGER DEFAULT 0" + + ");"; // 测量记录表建表语句 - private static final String CREATE_TABLE_PROFILE_RECORD = "CREATE TABLE IF NOT EXISTS " + TABLE_PROFILE_RECORD + " (" - + "id INTEGER PRIMARY KEY AUTOINCREMENT, " - + "create_time TEXT, " - + "update_time TEXT, " - + "uuid TEXT, " - + "operator_name TEXT, " - + "track_shape_code TEXT, " - + "verification_method_code TEXT, " - + "name TEXT NOT NULL, " - + "line_name TEXT, " - + "location TEXT, " - + "direction TEXT" - + ");"; + private static final String CREATE_TABLE_PROFILE_RECORD = + "CREATE TABLE IF NOT EXISTS " + TABLE_PROFILE_RECORD + " (" + + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + + "create_time TEXT, " + + "update_time TEXT, " + + "uuid TEXT, " + + "operator_name TEXT, " + + "track_shape_code TEXT, " + + "verification_method_code TEXT, " + + "name TEXT NOT NULL, " + + "line_name TEXT, " + + "location TEXT, " + + "direction TEXT" + + ");"; + + // 测量点集表建表语句 + private static final String CREATE_TABLE_PROFILE_RECORD_POINT_SET = + "CREATE TABLE IF NOT EXISTS " + TABLE_PROFILE_RECORD_POINT_SET + " (" + + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + + "profile_record_uuid TEXT, " + + "points TEXT, " + + "create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, " + + "update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP" + + ");"; + + // 基础测量点集表建表语句 + private static final String CREATE_TABLE_BASE_PROFILE_RECORD_POINT_SET = + "CREATE TABLE IF NOT EXISTS " + TABLE_BASE_PROFILE_RECORD_POINT_SET + " (" + + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + + "name TEXT, " + + "code TEXT, " + + "points TEXT, " + + "cal_points TEXT, " + + "create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, " + + "update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP" + + ");"; + + // 系统配置表(KV形式)建表语句 + private static final String CREATE_TABLE_SYSTEM_CONFIG = + "CREATE TABLE IF NOT EXISTS " + TABLE_SYSTEM_CONFIG + " (" + + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + + "config_key TEXT NOT NULL, " // 键,不能为空 + + "config_value TEXT, " // 值 + + "create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, " + + "update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP" + + ");"; public MyDatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); @@ -57,16 +84,20 @@ public class MyDatabaseHelper extends SQLiteOpenHelper { @Override public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_TABLE_APP_USER); - db.execSQL(CREATE_TABLE_DEFAULT_BLUETOOTH); db.execSQL(CREATE_TABLE_PROFILE_RECORD); + db.execSQL(CREATE_TABLE_PROFILE_RECORD_POINT_SET); + db.execSQL(CREATE_TABLE_BASE_PROFILE_RECORD_POINT_SET); + db.execSQL(CREATE_TABLE_SYSTEM_CONFIG); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - // 注意:实际生产中请做好数据迁移 + // 注意:实际生产中请做好数据迁移处理 db.execSQL("DROP TABLE IF EXISTS " + TABLE_APP_USER); - db.execSQL("DROP TABLE IF EXISTS " + TABLE_DEFAULT_BLUETOOTH); db.execSQL("DROP TABLE IF EXISTS " + TABLE_PROFILE_RECORD); + db.execSQL("DROP TABLE IF EXISTS " + TABLE_PROFILE_RECORD_POINT_SET); + db.execSQL("DROP TABLE IF EXISTS " + TABLE_BASE_PROFILE_RECORD_POINT_SET); + db.execSQL("DROP TABLE IF EXISTS " + TABLE_SYSTEM_CONFIG); onCreate(db); } } diff --git a/app/src/main/java/com/iflytop/profilometer/dao/BaseProfileRecordPointSetDao.java b/app/src/main/java/com/iflytop/profilometer/dao/BaseProfileRecordPointSetDao.java new file mode 100644 index 0000000..b12cb7c --- /dev/null +++ b/app/src/main/java/com/iflytop/profilometer/dao/BaseProfileRecordPointSetDao.java @@ -0,0 +1,112 @@ +package com.iflytop.profilometer.dao; + +import android.annotation.SuppressLint; +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; + +import com.iflytop.profilometer.core.db.helper.MyDatabaseHelper; +import com.iflytop.profilometer.model.entity.BaseProfileRecordPointSet; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +public class BaseProfileRecordPointSetDao { + private final MyDatabaseHelper dbHelper; + + public BaseProfileRecordPointSetDao(Context context) { + dbHelper = new MyDatabaseHelper(context); + } + + // 插入基础测量点集记录 + public long insertBaseProfileRecordPointSet(BaseProfileRecordPointSet entity) { + SQLiteDatabase db = dbHelper.getWritableDatabase(); + ContentValues values = new ContentValues(); + String currentTime = getCurrentTime(); + values.put("create_time", currentTime); + values.put("update_time", currentTime); + values.put("name", entity.getName()); + values.put("code", entity.getCode()); + values.put("points", entity.getPoints()); + values.put("cal_points", entity.getCalPoints()); + long id = db.insert(MyDatabaseHelper.TABLE_BASE_PROFILE_RECORD_POINT_SET, null, values); + db.close(); + return id; + } + + // 更新基础测量点集记录 + public int updateBaseProfileRecordPointSet(BaseProfileRecordPointSet entity) { + SQLiteDatabase db = dbHelper.getWritableDatabase(); + ContentValues values = new ContentValues(); + values.put("update_time", getCurrentTime()); + values.put("name", entity.getName()); + values.put("code", entity.getCode()); + values.put("points", entity.getPoints()); + values.put("cal_points", entity.getCalPoints()); + int rows = db.update(MyDatabaseHelper.TABLE_BASE_PROFILE_RECORD_POINT_SET, values, "id = ?", new String[]{String.valueOf(entity.getId())}); + db.close(); + return rows; + } + + // 删除基础测量点集记录 + public int deleteBaseProfileRecordPointSet(long id) { + SQLiteDatabase db = dbHelper.getWritableDatabase(); + int rows = db.delete(MyDatabaseHelper.TABLE_BASE_PROFILE_RECORD_POINT_SET, "id = ?", new String[]{String.valueOf(id)}); + db.close(); + return rows; + } + + // 查询所有基础测量点集记录 + @SuppressLint("Range") + public List getAllBaseProfileRecordPointSets() { + List list = new ArrayList<>(); + SQLiteDatabase db = dbHelper.getReadableDatabase(); + Cursor cursor = db.query(MyDatabaseHelper.TABLE_BASE_PROFILE_RECORD_POINT_SET, null, null, null, null, null, "id DESC"); + if (cursor.moveToFirst()) { + do { + BaseProfileRecordPointSet entity = new BaseProfileRecordPointSet(); + entity.setId(cursor.getLong(cursor.getColumnIndex("id"))); + entity.setName(cursor.getString(cursor.getColumnIndex("name"))); + entity.setCode(cursor.getString(cursor.getColumnIndex("code"))); + entity.setPoints(cursor.getString(cursor.getColumnIndex("points"))); + entity.setCalPoints(cursor.getString(cursor.getColumnIndex("cal_points"))); + entity.setCreateTime(cursor.getString(cursor.getColumnIndex("create_time"))); + entity.setUpdateTime(cursor.getString(cursor.getColumnIndex("update_time"))); + list.add(entity); + } while (cursor.moveToNext()); + cursor.close(); + } + db.close(); + return list; + } + + // 根据 id 查询基础测量点集记录 + @SuppressLint("Range") + public BaseProfileRecordPointSet getBaseProfileRecordPointSetById(long id) { + SQLiteDatabase db = dbHelper.getReadableDatabase(); + Cursor cursor = db.query(MyDatabaseHelper.TABLE_BASE_PROFILE_RECORD_POINT_SET, null, "id = ?", new String[]{String.valueOf(id)}, null, null, null); + BaseProfileRecordPointSet entity = null; + if (cursor.moveToFirst()) { + entity = new BaseProfileRecordPointSet(); + entity.setId(cursor.getLong(cursor.getColumnIndex("id"))); + entity.setName(cursor.getString(cursor.getColumnIndex("name"))); + entity.setCode(cursor.getString(cursor.getColumnIndex("code"))); + entity.setPoints(cursor.getString(cursor.getColumnIndex("points"))); + entity.setCalPoints(cursor.getString(cursor.getColumnIndex("cal_points"))); + entity.setCreateTime(cursor.getString(cursor.getColumnIndex("create_time"))); + entity.setUpdateTime(cursor.getString(cursor.getColumnIndex("update_time"))); + cursor.close(); + } + db.close(); + return entity; + } + + private String getCurrentTime() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); + return sdf.format(new Date()); + } +} diff --git a/app/src/main/java/com/iflytop/profilometer/dao/BluetoothDao.java b/app/src/main/java/com/iflytop/profilometer/dao/BluetoothDao.java deleted file mode 100644 index 2525950..0000000 --- a/app/src/main/java/com/iflytop/profilometer/dao/BluetoothDao.java +++ /dev/null @@ -1,58 +0,0 @@ -//package com.iflytop.profilometer.dao; -// -//import android.annotation.SuppressLint; -//import android.content.ContentValues; -//import android.content.Context; -//import android.database.Cursor; -//import android.database.sqlite.SQLiteDatabase; -// -//import com.iflytop.profilometer.core.db.helper.MyDatabaseHelper; -//import com.iflytop.profilometer.model.entiy.DefaultBluetooth; -// -//import java.text.SimpleDateFormat; -//import java.util.Date; -//import java.util.Locale; -// -//public class BluetoothDao { -// private final MyDatabaseHelper dbHelper; -// -// public BluetoothDao(Context context) { -// dbHelper = new MyDatabaseHelper(context); -// } -// -// // 插入默认蓝牙设备数据 -// public long insertBluetooth(DefaultBluetooth bt) { -// SQLiteDatabase db = dbHelper.getWritableDatabase(); -// ContentValues values = new ContentValues(); -// String currentTime = getCurrentTime(); -// values.put("create_time", currentTime); -// values.put("update_time", currentTime); -// values.put("bluetooth_id", bt.getBluetoothId()); -// values.put("bluetooth_name", bt.getBluetoothName()); -// long id = db.insert(MyDatabaseHelper.TABLE_DEFAULT_BLUETOOTH, null, values); -// db.close(); -// return id; -// } -// -// // 查询最近设置的默认蓝牙设备 -// @SuppressLint("Range") -// public DefaultBluetooth getDefaultBluetooth() { -// DefaultBluetooth bt = null; -// SQLiteDatabase db = dbHelper.getReadableDatabase(); -// Cursor cursor = db.query(MyDatabaseHelper.TABLE_DEFAULT_BLUETOOTH, null, null, null, null, null, "id DESC", "1"); -// if(cursor.moveToFirst()){ -// bt = new DefaultBluetooth(); -// bt.setId(cursor.getLong(cursor.getColumnIndex("id"))); -// bt.setBluetoothId(cursor.getString(cursor.getColumnIndex("bluetooth_id"))); -// bt.setBluetoothName(cursor.getString(cursor.getColumnIndex("bluetooth_name"))); -// cursor.close(); -// } -// db.close(); -// return bt; -// } -// -// private String getCurrentTime() { -// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); -// return sdf.format(new Date()); -// } -//} diff --git a/app/src/main/java/com/iflytop/profilometer/dao/ProfileRecordDao.java b/app/src/main/java/com/iflytop/profilometer/dao/ProfileRecordDao.java index 1e2344f..18ca985 100644 --- a/app/src/main/java/com/iflytop/profilometer/dao/ProfileRecordDao.java +++ b/app/src/main/java/com/iflytop/profilometer/dao/ProfileRecordDao.java @@ -1,112 +1,128 @@ -//package com.iflytop.profilometer.dao; -// -//import android.annotation.SuppressLint; -//import android.content.ContentValues; -//import android.content.Context; -//import android.database.Cursor; -//import android.database.sqlite.SQLiteDatabase; -// -//import com.iflytop.profilometer.core.db.helper.MyDatabaseHelper; -//import com.iflytop.profilometer.model.entiy.ProfileRecordDescription; -// -//import java.text.SimpleDateFormat; -//import java.util.ArrayList; -//import java.util.Date; -//import java.util.List; -//import java.util.Locale; -// -//public class ProfileRecordDao { -// private final MyDatabaseHelper dbHelper; -// -// public ProfileRecordDao(Context context) { -// dbHelper = new MyDatabaseHelper(context); -// } -// -// // 插入测量记录 -// public long insertProfileRecord(ProfileRecordDescription record) { -// SQLiteDatabase db = dbHelper.getWritableDatabase(); -// ContentValues values = new ContentValues(); -// String currentTime = getCurrentTime(); -// values.put("create_time", currentTime); -// values.put("update_time", currentTime); -// values.put("uuid", record.getUuid()); -// values.put("operator_name", record.getOperatorName()); -// values.put("track_shape_code", record.getTrackShapeCode()); -// values.put("verification_method_code", record.getVerificationMethodCode()); -// values.put("name", record.getName()); -// values.put("line_name", record.getLineName()); -// values.put("location", record.getLocation()); -// values.put("direction", record.getDirection()); -// long id = db.insert(MyDatabaseHelper.TABLE_PROFILE_RECORD, null, values); -// db.close(); -// return id; -// } -// -// // 查询所有测量记录 -// @SuppressLint("Range") -// public List getAllProfileRecords() { -// List records = new ArrayList<>(); -// SQLiteDatabase db = dbHelper.getReadableDatabase(); -// Cursor cursor = db.query(MyDatabaseHelper.TABLE_PROFILE_RECORD, null, null, null, null, null, "id DESC"); -// if(cursor.moveToFirst()){ -// do{ -// ProfileRecordDescription record = new ProfileRecordDescription(); -// record.setId(cursor.getLong(cursor.getColumnIndex("id"))); -// record.setUuid(cursor.getString(cursor.getColumnIndex("uuid"))); -// record.setOperatorName(cursor.getString(cursor.getColumnIndex("operator_name"))); -// record.setTrackShapeCode(cursor.getString(cursor.getColumnIndex("track_shape_code"))); -// record.setVerificationMethodCode(cursor.getString(cursor.getColumnIndex("verification_method_code"))); -// record.setName(cursor.getString(cursor.getColumnIndex("name"))); -// record.setLineName(cursor.getString(cursor.getColumnIndex("line_name"))); -// record.setLocation(cursor.getString(cursor.getColumnIndex("location"))); -// record.setDirection(cursor.getString(cursor.getColumnIndex("direction"))); -// records.add(record); -// } while(cursor.moveToNext()); -// cursor.close(); -// } -// db.close(); -// return records; -// } -// -// @SuppressLint("Range") -// public List getProfileRecords(int page, int pageSize) { -// List records = new ArrayList<>(); -// SQLiteDatabase db = dbHelper.getReadableDatabase(); -// // 计算偏移量 -// int offset = (page - 1) * pageSize; -// // 使用 LIMIT 与 OFFSET 分页查询 -// String limitClause = offset + ", " + pageSize; -// Cursor cursor = db.query( -// MyDatabaseHelper.TABLE_PROFILE_RECORD, // 表名 -// null, // 查询所有列 -// null, null, // selection 及 selectionArgs -// null, null, // groupBy 和 having -// "id DESC", // orderBy -// limitClause // limit 子句:offset, pageSize -// ); -// if (cursor.moveToFirst()) { -// do { -// ProfileRecordDescription record = new ProfileRecordDescription(); -// record.setId(cursor.getLong(cursor.getColumnIndex("id"))); -// record.setUuid(cursor.getString(cursor.getColumnIndex("uuid"))); -// record.setOperatorName(cursor.getString(cursor.getColumnIndex("operator_name"))); -// record.setTrackShapeCode(cursor.getString(cursor.getColumnIndex("track_shape_code"))); -// record.setVerificationMethodCode(cursor.getString(cursor.getColumnIndex("verification_method_code"))); -// record.setName(cursor.getString(cursor.getColumnIndex("name"))); -// record.setLineName(cursor.getString(cursor.getColumnIndex("line_name"))); -// record.setLocation(cursor.getString(cursor.getColumnIndex("location"))); -// record.setDirection(cursor.getString(cursor.getColumnIndex("direction"))); -// records.add(record); -// } while (cursor.moveToNext()); -// cursor.close(); -// } -// db.close(); -// return records; -// } -// -// -// private String getCurrentTime() { -// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); -// return sdf.format(new Date()); -// } -//} +package com.iflytop.profilometer.dao; + +import android.annotation.SuppressLint; +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; + +import com.iflytop.profilometer.core.db.helper.MyDatabaseHelper; +import com.iflytop.profilometer.model.entity.ProfileRecordDescription; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +public class ProfileRecordDao { + private final MyDatabaseHelper dbHelper; + + public ProfileRecordDao(Context context) { + dbHelper = new MyDatabaseHelper(context); + } + + // 插入测量记录 + public long insertProfileRecord(ProfileRecordDescription record) { + SQLiteDatabase db = dbHelper.getWritableDatabase(); + ContentValues values = new ContentValues(); + String currentTime = getCurrentTime(); + values.put("create_time", currentTime); + values.put("update_time", currentTime); + values.put("uuid", record.getUuid()); + values.put("operator_name", record.getOperatorName()); + values.put("track_shape_code", record.getTrackShapeCode()); + values.put("verification_method_code", record.getVerificationMethodCode()); + values.put("name", record.getName()); + values.put("line_name", record.getLineName()); + values.put("location", record.getLocation()); + values.put("direction", record.getDirection()); + long id = db.insert(MyDatabaseHelper.TABLE_PROFILE_RECORD, null, values); + db.close(); + return id; + } + + // 更新测量记录 + public int updateProfileRecord(ProfileRecordDescription record) { + SQLiteDatabase db = dbHelper.getWritableDatabase(); + ContentValues values = new ContentValues(); + values.put("update_time", getCurrentTime()); + values.put("uuid", record.getUuid()); + values.put("operator_name", record.getOperatorName()); + values.put("track_shape_code", record.getTrackShapeCode()); + values.put("verification_method_code", record.getVerificationMethodCode()); + values.put("name", record.getName()); + values.put("line_name", record.getLineName()); + values.put("location", record.getLocation()); + values.put("direction", record.getDirection()); + int rows = db.update(MyDatabaseHelper.TABLE_PROFILE_RECORD, values, "id = ?", new String[]{String.valueOf(record.getId())}); + db.close(); + return rows; + } + + // 删除测量记录 + public int deleteProfileRecord(long id) { + SQLiteDatabase db = dbHelper.getWritableDatabase(); + int rows = db.delete(MyDatabaseHelper.TABLE_PROFILE_RECORD, "id = ?", new String[]{String.valueOf(id)}); + db.close(); + return rows; + } + + // 查询所有测量记录 + @SuppressLint("Range") + public List getAllProfileRecords() { + List records = new ArrayList<>(); + SQLiteDatabase db = dbHelper.getReadableDatabase(); + Cursor cursor = db.query(MyDatabaseHelper.TABLE_PROFILE_RECORD, null, null, null, null, null, "id DESC"); + if (cursor.moveToFirst()) { + do { + ProfileRecordDescription record = new ProfileRecordDescription(); + record.setId(cursor.getLong(cursor.getColumnIndex("id"))); + record.setUuid(cursor.getString(cursor.getColumnIndex("uuid"))); + record.setOperatorName(cursor.getString(cursor.getColumnIndex("operator_name"))); + record.setTrackShapeCode(cursor.getString(cursor.getColumnIndex("track_shape_code"))); + record.setVerificationMethodCode(cursor.getString(cursor.getColumnIndex("verification_method_code"))); + record.setName(cursor.getString(cursor.getColumnIndex("name"))); + record.setLineName(cursor.getString(cursor.getColumnIndex("line_name"))); + record.setLocation(cursor.getString(cursor.getColumnIndex("location"))); + record.setDirection(cursor.getString(cursor.getColumnIndex("direction"))); + record.setCreateTime(cursor.getString(cursor.getColumnIndex("create_time"))); + record.setUpdateTime(cursor.getString(cursor.getColumnIndex("update_time"))); + records.add(record); + } while (cursor.moveToNext()); + cursor.close(); + } + db.close(); + return records; + } + + // 根据 id 查询测量记录 + @SuppressLint("Range") + public ProfileRecordDescription getProfileRecordById(long id) { + SQLiteDatabase db = dbHelper.getReadableDatabase(); + Cursor cursor = db.query(MyDatabaseHelper.TABLE_PROFILE_RECORD, null, "id = ?", new String[]{String.valueOf(id)}, null, null, null); + ProfileRecordDescription record = null; + if (cursor.moveToFirst()) { + record = new ProfileRecordDescription(); + record.setId(cursor.getLong(cursor.getColumnIndex("id"))); + record.setUuid(cursor.getString(cursor.getColumnIndex("uuid"))); + record.setOperatorName(cursor.getString(cursor.getColumnIndex("operator_name"))); + record.setTrackShapeCode(cursor.getString(cursor.getColumnIndex("track_shape_code"))); + record.setVerificationMethodCode(cursor.getString(cursor.getColumnIndex("verification_method_code"))); + record.setName(cursor.getString(cursor.getColumnIndex("name"))); + record.setLineName(cursor.getString(cursor.getColumnIndex("line_name"))); + record.setLocation(cursor.getString(cursor.getColumnIndex("location"))); + record.setDirection(cursor.getString(cursor.getColumnIndex("direction"))); + record.setCreateTime(cursor.getString(cursor.getColumnIndex("create_time"))); + record.setUpdateTime(cursor.getString(cursor.getColumnIndex("update_time"))); + cursor.close(); + } + db.close(); + return record; + } + + private String getCurrentTime() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); + return sdf.format(new Date()); + } +} diff --git a/app/src/main/java/com/iflytop/profilometer/dao/ProfileRecordPointSetDao.java b/app/src/main/java/com/iflytop/profilometer/dao/ProfileRecordPointSetDao.java new file mode 100644 index 0000000..a8da6ae --- /dev/null +++ b/app/src/main/java/com/iflytop/profilometer/dao/ProfileRecordPointSetDao.java @@ -0,0 +1,104 @@ +package com.iflytop.profilometer.dao; + +import android.annotation.SuppressLint; +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; + +import com.iflytop.profilometer.core.db.helper.MyDatabaseHelper; +import com.iflytop.profilometer.model.entity.ProfileRecordPointSet; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +public class ProfileRecordPointSetDao { + private final MyDatabaseHelper dbHelper; + + public ProfileRecordPointSetDao(Context context) { + dbHelper = new MyDatabaseHelper(context); + } + + // 插入测量点集记录 + public long insertProfileRecordPointSet(ProfileRecordPointSet pointSet) { + SQLiteDatabase db = dbHelper.getWritableDatabase(); + ContentValues values = new ContentValues(); + String currentTime = getCurrentTime(); + values.put("create_time", currentTime); + values.put("update_time", currentTime); + values.put("profile_record_uuid", pointSet.getProfileRecordUuid()); + values.put("points", pointSet.getPoints()); + long id = db.insert(MyDatabaseHelper.TABLE_PROFILE_RECORD_POINT_SET, null, values); + db.close(); + return id; + } + + // 更新测量点集记录 + public int updateProfileRecordPointSet(ProfileRecordPointSet pointSet) { + SQLiteDatabase db = dbHelper.getWritableDatabase(); + ContentValues values = new ContentValues(); + values.put("update_time", getCurrentTime()); + values.put("profile_record_uuid", pointSet.getProfileRecordUuid()); + values.put("points", pointSet.getPoints()); + int rows = db.update(MyDatabaseHelper.TABLE_PROFILE_RECORD_POINT_SET, values, "id = ?", new String[]{String.valueOf(pointSet.getId())}); + db.close(); + return rows; + } + + // 删除测量点集记录 + public int deleteProfileRecordPointSet(long id) { + SQLiteDatabase db = dbHelper.getWritableDatabase(); + int rows = db.delete(MyDatabaseHelper.TABLE_PROFILE_RECORD_POINT_SET, "id = ?", new String[]{String.valueOf(id)}); + db.close(); + return rows; + } + + // 查询所有测量点集记录 + @SuppressLint("Range") + public List getAllProfileRecordPointSets() { + List list = new ArrayList<>(); + SQLiteDatabase db = dbHelper.getReadableDatabase(); + Cursor cursor = db.query(MyDatabaseHelper.TABLE_PROFILE_RECORD_POINT_SET, null, null, null, null, null, "id DESC"); + if (cursor.moveToFirst()) { + do { + ProfileRecordPointSet pointSet = new ProfileRecordPointSet(); + pointSet.setId(cursor.getLong(cursor.getColumnIndex("id"))); + pointSet.setProfileRecordUuid(cursor.getString(cursor.getColumnIndex("profile_record_uuid"))); + pointSet.setPoints(cursor.getString(cursor.getColumnIndex("points"))); + pointSet.setCreateTime(cursor.getString(cursor.getColumnIndex("create_time"))); + pointSet.setUpdateTime(cursor.getString(cursor.getColumnIndex("update_time"))); + list.add(pointSet); + } while (cursor.moveToNext()); + cursor.close(); + } + db.close(); + return list; + } + + // 根据 id 查询测量点集记录 + @SuppressLint("Range") + public ProfileRecordPointSet getProfileRecordPointSetById(long id) { + SQLiteDatabase db = dbHelper.getReadableDatabase(); + Cursor cursor = db.query(MyDatabaseHelper.TABLE_PROFILE_RECORD_POINT_SET, null, "id = ?", new String[]{String.valueOf(id)}, null, null, null); + ProfileRecordPointSet pointSet = null; + if (cursor.moveToFirst()) { + pointSet = new ProfileRecordPointSet(); + pointSet.setId(cursor.getLong(cursor.getColumnIndex("id"))); + pointSet.setProfileRecordUuid(cursor.getString(cursor.getColumnIndex("profile_record_uuid"))); + pointSet.setPoints(cursor.getString(cursor.getColumnIndex("points"))); + pointSet.setCreateTime(cursor.getString(cursor.getColumnIndex("create_time"))); + pointSet.setUpdateTime(cursor.getString(cursor.getColumnIndex("update_time"))); + cursor.close(); + } + db.close(); + return pointSet; + } + + private String getCurrentTime() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); + return sdf.format(new Date()); + } +} diff --git a/app/src/main/java/com/iflytop/profilometer/dao/SystemConfigDao.java b/app/src/main/java/com/iflytop/profilometer/dao/SystemConfigDao.java new file mode 100644 index 0000000..b55bc1f --- /dev/null +++ b/app/src/main/java/com/iflytop/profilometer/dao/SystemConfigDao.java @@ -0,0 +1,123 @@ +package com.iflytop.profilometer.dao; + +import android.annotation.SuppressLint; +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; + +import com.iflytop.profilometer.core.db.helper.MyDatabaseHelper; +import com.iflytop.profilometer.model.entity.SystemConfig; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +public class SystemConfigDao { + private final MyDatabaseHelper dbHelper; + + public SystemConfigDao(Context context) { + dbHelper = new MyDatabaseHelper(context); + } + + // 插入系统配置 + public long insertSystemConfig(SystemConfig config) { + SQLiteDatabase db = dbHelper.getWritableDatabase(); + ContentValues values = new ContentValues(); + String currentTime = getCurrentTime(); + values.put("create_time", currentTime); + values.put("update_time", currentTime); + values.put("config_key", config.getConfigKey()); + values.put("config_value", config.getConfigValue()); + long id = db.insert(MyDatabaseHelper.TABLE_SYSTEM_CONFIG, null, values); + db.close(); + return id; + } + + // 更新系统配置 + public int updateSystemConfig(SystemConfig config) { + SQLiteDatabase db = dbHelper.getWritableDatabase(); + ContentValues values = new ContentValues(); + values.put("update_time", getCurrentTime()); + values.put("config_key", config.getConfigKey()); + values.put("config_value", config.getConfigValue()); + int rows = db.update(MyDatabaseHelper.TABLE_SYSTEM_CONFIG, values, "id = ?", new String[]{String.valueOf(config.getId())}); + db.close(); + return rows; + } + + // 删除系统配置 + public int deleteSystemConfig(long id) { + SQLiteDatabase db = dbHelper.getWritableDatabase(); + int rows = db.delete(MyDatabaseHelper.TABLE_SYSTEM_CONFIG, "id = ?", new String[]{String.valueOf(id)}); + db.close(); + return rows; + } + + // 查询所有系统配置 + @SuppressLint("Range") + public List getAllSystemConfigs() { + List list = new ArrayList<>(); + SQLiteDatabase db = dbHelper.getReadableDatabase(); + Cursor cursor = db.query(MyDatabaseHelper.TABLE_SYSTEM_CONFIG, null, null, null, null, null, "id DESC"); + if (cursor.moveToFirst()) { + do { + SystemConfig config = new SystemConfig(); + config.setId(cursor.getLong(cursor.getColumnIndex("id"))); + config.setConfigKey(cursor.getString(cursor.getColumnIndex("config_key"))); + config.setConfigValue(cursor.getString(cursor.getColumnIndex("config_value"))); + config.setCreateTime(cursor.getString(cursor.getColumnIndex("create_time"))); + config.setUpdateTime(cursor.getString(cursor.getColumnIndex("update_time"))); + list.add(config); + } while (cursor.moveToNext()); + cursor.close(); + } + db.close(); + return list; + } + + // 根据 id 查询系统配置 + @SuppressLint("Range") + public SystemConfig getSystemConfigById(long id) { + SQLiteDatabase db = dbHelper.getReadableDatabase(); + Cursor cursor = db.query(MyDatabaseHelper.TABLE_SYSTEM_CONFIG, null, "id = ?", new String[]{String.valueOf(id)}, null, null, null); + SystemConfig config = null; + if (cursor.moveToFirst()) { + config = new SystemConfig(); + config.setId(cursor.getLong(cursor.getColumnIndex("id"))); + config.setConfigKey(cursor.getString(cursor.getColumnIndex("config_key"))); + config.setConfigValue(cursor.getString(cursor.getColumnIndex("config_value"))); + config.setCreateTime(cursor.getString(cursor.getColumnIndex("create_time"))); + config.setUpdateTime(cursor.getString(cursor.getColumnIndex("update_time"))); + cursor.close(); + } + db.close(); + return config; + } + + //根据 key 查询系统配置 + @SuppressLint("Range") + public SystemConfig getSystemConfigByKey(String key) { + SQLiteDatabase db = dbHelper.getReadableDatabase(); + Cursor cursor = db.query(MyDatabaseHelper.TABLE_SYSTEM_CONFIG, null, "config_key = ?", new String[]{key}, null, null, null); + SystemConfig config = null; + if (cursor.moveToFirst()) { + config = new SystemConfig(); + config.setId(cursor.getLong(cursor.getColumnIndex("id"))); + config.setConfigKey(cursor.getString(cursor.getColumnIndex("config_key"))); + config.setConfigValue(cursor.getString(cursor.getColumnIndex("config_value"))); + config.setCreateTime(cursor.getString(cursor.getColumnIndex("create_time"))); + config.setUpdateTime(cursor.getString(cursor.getColumnIndex("update_time"))); + cursor.close(); + } + db.close(); + return config; + } + + private String getCurrentTime() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); + return sdf.format(new Date()); + } +} diff --git a/app/src/main/java/com/iflytop/profilometer/dao/UserDao.java b/app/src/main/java/com/iflytop/profilometer/dao/UserDao.java index b553138..5b99b4a 100644 --- a/app/src/main/java/com/iflytop/profilometer/dao/UserDao.java +++ b/app/src/main/java/com/iflytop/profilometer/dao/UserDao.java @@ -7,7 +7,7 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import com.iflytop.profilometer.core.db.helper.MyDatabaseHelper; -import com.iflytop.profilometer.model.entiy.AppUser; +import com.iflytop.profilometer.model.entity.AppUser; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -40,6 +40,29 @@ public class UserDao { return id; } + // 更新 AppUser + public int updateAppUser(AppUser user) { + SQLiteDatabase db = dbHelper.getWritableDatabase(); + ContentValues values = new ContentValues(); + values.put("update_time", getCurrentTime()); + values.put("account", user.getAccount()); + values.put("nickname", user.getNickname()); + values.put("password", user.getPassword()); + values.put("usr_role", user.getUsrRole().name()); + values.put("is_built_in_user", user.getBuiltInUser() ? 1 : 0); + int rows = db.update(MyDatabaseHelper.TABLE_APP_USER, values, "id = ?", new String[]{String.valueOf(user.getId())}); + db.close(); + return rows; + } + + // 删除 AppUser + public int deleteAppUser(long id) { + SQLiteDatabase db = dbHelper.getWritableDatabase(); + int rows = db.delete(MyDatabaseHelper.TABLE_APP_USER, "id = ?", new String[]{String.valueOf(id)}); + db.close(); + return rows; + } + // 查询所有用户 @SuppressLint("Range") public List getAllUsers() { diff --git a/app/src/main/java/com/iflytop/profilometer/model/entiy/AppUser.java b/app/src/main/java/com/iflytop/profilometer/model/entity/AppUser.java similarity index 93% rename from app/src/main/java/com/iflytop/profilometer/model/entiy/AppUser.java rename to app/src/main/java/com/iflytop/profilometer/model/entity/AppUser.java index a0da620..68bd892 100644 --- a/app/src/main/java/com/iflytop/profilometer/model/entiy/AppUser.java +++ b/app/src/main/java/com/iflytop/profilometer/model/entity/AppUser.java @@ -1,9 +1,7 @@ -package com.iflytop.profilometer.model.entiy; +package com.iflytop.profilometer.model.entity; import com.iflytop.profilometer.common.base.BaseEntity; -import java.io.Serializable; - public class AppUser extends BaseEntity { public enum UsrRole { User, Admin, Dev; diff --git a/app/src/main/java/com/iflytop/profilometer/model/entity/BaseProfileRecordPointSet.java b/app/src/main/java/com/iflytop/profilometer/model/entity/BaseProfileRecordPointSet.java new file mode 100644 index 0000000..08646ae --- /dev/null +++ b/app/src/main/java/com/iflytop/profilometer/model/entity/BaseProfileRecordPointSet.java @@ -0,0 +1,42 @@ +package com.iflytop.profilometer.model.entity; + +import com.iflytop.profilometer.common.base.BaseEntity; + +public class BaseProfileRecordPointSet extends BaseEntity { + private String name; + private String code; + private String points; + private String calPoints; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getPoints() { + return points; + } + + public void setPoints(String points) { + this.points = points; + } + + public String getCalPoints() { + return calPoints; + } + + public void setCalPoints(String calPoints) { + this.calPoints = calPoints; + } +} diff --git a/app/src/main/java/com/iflytop/profilometer/model/entiy/ProfileRecordDescription.java b/app/src/main/java/com/iflytop/profilometer/model/entity/ProfileRecordDescription.java similarity index 97% rename from app/src/main/java/com/iflytop/profilometer/model/entiy/ProfileRecordDescription.java rename to app/src/main/java/com/iflytop/profilometer/model/entity/ProfileRecordDescription.java index 6d00bb4..535a567 100644 --- a/app/src/main/java/com/iflytop/profilometer/model/entiy/ProfileRecordDescription.java +++ b/app/src/main/java/com/iflytop/profilometer/model/entity/ProfileRecordDescription.java @@ -1,4 +1,4 @@ -package com.iflytop.profilometer.model.entiy; +package com.iflytop.profilometer.model.entity; import com.iflytop.profilometer.common.base.BaseEntity; diff --git a/app/src/main/java/com/iflytop/profilometer/model/entity/ProfileRecordPointSet.java b/app/src/main/java/com/iflytop/profilometer/model/entity/ProfileRecordPointSet.java new file mode 100644 index 0000000..985d4c1 --- /dev/null +++ b/app/src/main/java/com/iflytop/profilometer/model/entity/ProfileRecordPointSet.java @@ -0,0 +1,24 @@ +package com.iflytop.profilometer.model.entity; + +import com.iflytop.profilometer.common.base.BaseEntity; + +public class ProfileRecordPointSet extends BaseEntity { + private String profileRecordUuid; + private String points; + + public String getProfileRecordUuid() { + return profileRecordUuid; + } + + public void setProfileRecordUuid(String profileRecordUuid) { + this.profileRecordUuid = profileRecordUuid; + } + + public String getPoints() { + return points; + } + + public void setPoints(String points) { + this.points = points; + } +} diff --git a/app/src/main/java/com/iflytop/profilometer/model/entity/SystemConfig.java b/app/src/main/java/com/iflytop/profilometer/model/entity/SystemConfig.java new file mode 100644 index 0000000..1adc34d --- /dev/null +++ b/app/src/main/java/com/iflytop/profilometer/model/entity/SystemConfig.java @@ -0,0 +1,21 @@ +package com.iflytop.profilometer.model.entity; + +import com.iflytop.profilometer.common.base.BaseEntity; + +public class SystemConfig extends BaseEntity { + private String configKey; // 配置项键 + private String configValue; // 配置项值 + + public String getConfigKey() { + return configKey; + } + public void setConfigKey(String configKey) { + this.configKey = configKey; + } + public String getConfigValue() { + return configValue; + } + public void setConfigValue(String configValue) { + this.configValue = configValue; + } +} diff --git a/app/src/main/java/com/iflytop/profilometer/model/entiy/DefaultBluetooth.java b/app/src/main/java/com/iflytop/profilometer/model/entiy/DefaultBluetooth.java deleted file mode 100644 index 395c968..0000000 --- a/app/src/main/java/com/iflytop/profilometer/model/entiy/DefaultBluetooth.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.iflytop.profilometer.model.entiy; - -import com.iflytop.profilometer.common.base.BaseEntity; - -public class DefaultBluetooth extends BaseEntity { - - private String bluetoothId; - private String bluetoothName; - - - public String getBluetoothId() { - return bluetoothId; - } - - public void setBluetoothId(String bluetoothId) { - this.bluetoothId = bluetoothId; - } - - public String getBluetoothName() { - return bluetoothName; - } - - public void setBluetoothName(String bluetoothName) { - this.bluetoothName = bluetoothName; - } -} \ No newline at end of file