3 changed files with 231 additions and 1 deletions
-
22app/src/main/java/com/iflytop/profilometer/core/db/helper/MyDatabaseHelper.java
-
140app/src/main/java/com/iflytop/profilometer/dao/SyncTaskDao.java
-
70app/src/main/java/com/iflytop/profilometer/model/entity/SyncTask.java
@ -0,0 +1,140 @@ |
|||
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.SyncTask; |
|||
|
|||
import java.text.SimpleDateFormat; |
|||
import java.util.ArrayList; |
|||
import java.util.Date; |
|||
import java.util.List; |
|||
import java.util.Locale; |
|||
|
|||
public class SyncTaskDao { |
|||
private final MyDatabaseHelper dbHelper; |
|||
|
|||
public SyncTaskDao(Context context) { |
|||
dbHelper = new MyDatabaseHelper(context); |
|||
} |
|||
|
|||
// 插入同步任务记录 |
|||
public long insertSyncTask(SyncTask task) { |
|||
SQLiteDatabase db = dbHelper.getWritableDatabase(); |
|||
ContentValues values = new ContentValues(); |
|||
String currentTime = getCurrentTime(); |
|||
values.put("create_time", currentTime); |
|||
values.put("update_time", currentTime); |
|||
values.put("uuid", task.getUuid()); |
|||
values.put("operator_name", task.getOperatorName()); |
|||
values.put("track_shape_code", task.getTrackShapeCode()); |
|||
values.put("verification_method_code", task.getVerificationMethodCode()); |
|||
values.put("name", task.getName()); |
|||
values.put("line_name", task.getLineName()); |
|||
values.put("location", task.getLocation()); |
|||
values.put("direction", task.getDirection()); |
|||
values.put("sync_status", task.getSyncStatus()); |
|||
long id = db.insert(MyDatabaseHelper.TABLE_SYNC_TASK, null, values); |
|||
db.close(); |
|||
return id; |
|||
} |
|||
|
|||
// 更新同步任务记录 |
|||
public int updateSyncTask(SyncTask task) { |
|||
SQLiteDatabase db = dbHelper.getWritableDatabase(); |
|||
ContentValues values = new ContentValues(); |
|||
values.put("update_time", getCurrentTime()); |
|||
values.put("uuid", task.getUuid()); |
|||
values.put("operator_name", task.getOperatorName()); |
|||
values.put("track_shape_code", task.getTrackShapeCode()); |
|||
values.put("verification_method_code", task.getVerificationMethodCode()); |
|||
values.put("name", task.getName()); |
|||
values.put("line_name", task.getLineName()); |
|||
values.put("location", task.getLocation()); |
|||
values.put("direction", task.getDirection()); |
|||
values.put("sync_status", task.getSyncStatus()); |
|||
int rows = db.update(MyDatabaseHelper.TABLE_SYNC_TASK, values, "id = ?", new String[]{String.valueOf(task.getId())}); |
|||
db.close(); |
|||
return rows; |
|||
} |
|||
|
|||
// 删除指定的同步任务记录 |
|||
public int deleteSyncTask(long id) { |
|||
SQLiteDatabase db = dbHelper.getWritableDatabase(); |
|||
int rows = db.delete(MyDatabaseHelper.TABLE_SYNC_TASK, "id = ?", new String[]{String.valueOf(id)}); |
|||
db.close(); |
|||
return rows; |
|||
} |
|||
|
|||
// 清空同步任务表数据 |
|||
public int clearSyncTasks() { |
|||
SQLiteDatabase db = dbHelper.getWritableDatabase(); |
|||
int rows = db.delete(MyDatabaseHelper.TABLE_SYNC_TASK, null, null); |
|||
db.close(); |
|||
return rows; |
|||
} |
|||
|
|||
// 查询所有同步任务记录 |
|||
@SuppressLint("Range") |
|||
public List<SyncTask> getAllSyncTasks() { |
|||
List<SyncTask> list = new ArrayList<>(); |
|||
SQLiteDatabase db = dbHelper.getReadableDatabase(); |
|||
Cursor cursor = db.query(MyDatabaseHelper.TABLE_SYNC_TASK, null, null, null, null, null, "id DESC"); |
|||
if (cursor.moveToFirst()) { |
|||
do { |
|||
SyncTask task = new SyncTask(); |
|||
task.setId(cursor.getLong(cursor.getColumnIndex("id"))); |
|||
task.setUuid(cursor.getString(cursor.getColumnIndex("uuid"))); |
|||
task.setOperatorName(cursor.getString(cursor.getColumnIndex("operator_name"))); |
|||
task.setTrackShapeCode(cursor.getString(cursor.getColumnIndex("track_shape_code"))); |
|||
task.setVerificationMethodCode(cursor.getString(cursor.getColumnIndex("verification_method_code"))); |
|||
task.setName(cursor.getString(cursor.getColumnIndex("name"))); |
|||
task.setLineName(cursor.getString(cursor.getColumnIndex("line_name"))); |
|||
task.setLocation(cursor.getString(cursor.getColumnIndex("location"))); |
|||
task.setDirection(cursor.getString(cursor.getColumnIndex("direction"))); |
|||
task.setSyncStatus(cursor.getString(cursor.getColumnIndex("sync_status"))); |
|||
task.setCreateTime(cursor.getString(cursor.getColumnIndex("create_time"))); |
|||
task.setUpdateTime(cursor.getString(cursor.getColumnIndex("update_time"))); |
|||
list.add(task); |
|||
} while (cursor.moveToNext()); |
|||
cursor.close(); |
|||
} |
|||
db.close(); |
|||
return list; |
|||
} |
|||
|
|||
// 根据 id 查询同步任务记录 |
|||
@SuppressLint("Range") |
|||
public SyncTask getSyncTaskById(long id) { |
|||
SQLiteDatabase db = dbHelper.getReadableDatabase(); |
|||
Cursor cursor = db.query(MyDatabaseHelper.TABLE_SYNC_TASK, null, "id = ?", new String[]{String.valueOf(id)}, null, null, null); |
|||
SyncTask task = null; |
|||
if (cursor.moveToFirst()) { |
|||
task = new SyncTask(); |
|||
task.setId(cursor.getLong(cursor.getColumnIndex("id"))); |
|||
task.setUuid(cursor.getString(cursor.getColumnIndex("uuid"))); |
|||
task.setOperatorName(cursor.getString(cursor.getColumnIndex("operator_name"))); |
|||
task.setTrackShapeCode(cursor.getString(cursor.getColumnIndex("track_shape_code"))); |
|||
task.setVerificationMethodCode(cursor.getString(cursor.getColumnIndex("verification_method_code"))); |
|||
task.setName(cursor.getString(cursor.getColumnIndex("name"))); |
|||
task.setLineName(cursor.getString(cursor.getColumnIndex("line_name"))); |
|||
task.setLocation(cursor.getString(cursor.getColumnIndex("location"))); |
|||
task.setDirection(cursor.getString(cursor.getColumnIndex("direction"))); |
|||
task.setSyncStatus(cursor.getString(cursor.getColumnIndex("sync_status"))); |
|||
task.setCreateTime(cursor.getString(cursor.getColumnIndex("create_time"))); |
|||
task.setUpdateTime(cursor.getString(cursor.getColumnIndex("update_time"))); |
|||
cursor.close(); |
|||
} |
|||
db.close(); |
|||
return task; |
|||
} |
|||
|
|||
private String getCurrentTime() { |
|||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); |
|||
return sdf.format(new Date()); |
|||
} |
|||
} |
@ -0,0 +1,70 @@ |
|||
package com.iflytop.profilometer.model.entity; |
|||
|
|||
import com.iflytop.profilometer.common.base.BaseEntity; |
|||
|
|||
public class SyncTask extends BaseEntity { |
|||
private String uuid; |
|||
private String operatorName; |
|||
private String trackShapeCode; |
|||
private String verificationMethodCode; |
|||
private String name; |
|||
private String lineName; |
|||
private String location; |
|||
private String direction; |
|||
private String syncStatus; // 同步状态字段 |
|||
|
|||
public String getUuid() { |
|||
return uuid; |
|||
} |
|||
public void setUuid(String uuid) { |
|||
this.uuid = uuid; |
|||
} |
|||
public String getOperatorName() { |
|||
return operatorName; |
|||
} |
|||
public void setOperatorName(String operatorName) { |
|||
this.operatorName = operatorName; |
|||
} |
|||
public String getTrackShapeCode() { |
|||
return trackShapeCode; |
|||
} |
|||
public void setTrackShapeCode(String trackShapeCode) { |
|||
this.trackShapeCode = trackShapeCode; |
|||
} |
|||
public String getVerificationMethodCode() { |
|||
return verificationMethodCode; |
|||
} |
|||
public void setVerificationMethodCode(String verificationMethodCode) { |
|||
this.verificationMethodCode = verificationMethodCode; |
|||
} |
|||
public String getName() { |
|||
return name; |
|||
} |
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
public String getLineName() { |
|||
return lineName; |
|||
} |
|||
public void setLineName(String lineName) { |
|||
this.lineName = lineName; |
|||
} |
|||
public String getLocation() { |
|||
return location; |
|||
} |
|||
public void setLocation(String location) { |
|||
this.location = location; |
|||
} |
|||
public String getDirection() { |
|||
return direction; |
|||
} |
|||
public void setDirection(String direction) { |
|||
this.direction = direction; |
|||
} |
|||
public String getSyncStatus() { |
|||
return syncStatus; |
|||
} |
|||
public void setSyncStatus(String syncStatus) { |
|||
this.syncStatus = syncStatus; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue