|
|
@@ -21,6 +21,21 @@ public class DeliveryDao {
|
|
|
dbHelper = new DBHelper(context);
|
|
|
}
|
|
|
|
|
|
+ // 从Cursor解析记录(复用方法)
|
|
|
+ private DeliveryRecord parseRecordFromCursor(Cursor cursor) {
|
|
|
+ DeliveryRecord record = new DeliveryRecord(
|
|
|
+ cursor.getString(cursor.getColumnIndexOrThrow("deliveryNo")),
|
|
|
+ cursor.getString(cursor.getColumnIndexOrThrow("machine")),
|
|
|
+ cursor.getString(cursor.getColumnIndexOrThrow("operator")),
|
|
|
+ cursor.getString(cursor.getColumnIndexOrThrow("operatorName")),
|
|
|
+ cursor.getInt(cursor.getColumnIndexOrThrow("isPush"))
|
|
|
+ );
|
|
|
+ record.setId(cursor.getLong(cursor.getColumnIndexOrThrow("id")));
|
|
|
+ record.setOperationTime(cursor.getString(cursor.getColumnIndexOrThrow("operationTime")));
|
|
|
+
|
|
|
+ return record;
|
|
|
+ }
|
|
|
+
|
|
|
// 添加送货记录
|
|
|
public long addDelivery(DeliveryRecord record) {
|
|
|
// 1. 先检查是否存在
|
|
|
@@ -35,6 +50,7 @@ public class DeliveryDao {
|
|
|
values.put("operator", record.getOperator());
|
|
|
values.put("operatorName", record.getOperatorName());
|
|
|
values.put("operationTime", record.getOperationTime());
|
|
|
+ values.put("isPush", record.isPush() ? 1 : 0); // 布尔转INT
|
|
|
|
|
|
try {
|
|
|
long id = db.insertOrThrow("delivery", null, values);
|
|
|
@@ -50,6 +66,7 @@ public class DeliveryDao {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 检查送货单号是否存在
|
|
|
*/
|
|
|
@@ -85,14 +102,7 @@ public class DeliveryDao {
|
|
|
|
|
|
DeliveryRecord record = null;
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
- record = new DeliveryRecord(
|
|
|
- cursor.getString(cursor.getColumnIndexOrThrow("deliveryNo")),
|
|
|
- cursor.getString(cursor.getColumnIndexOrThrow("machine")),
|
|
|
- cursor.getString(cursor.getColumnIndexOrThrow("operator")),
|
|
|
- cursor.getString(cursor.getColumnIndexOrThrow("operatorName"))
|
|
|
- );
|
|
|
- record.setId(cursor.getLong(cursor.getColumnIndexOrThrow("id")));
|
|
|
- record.setOperationTime(cursor.getString(cursor.getColumnIndexOrThrow("operationTime")));
|
|
|
+ record = parseRecordFromCursor(cursor);
|
|
|
cursor.close();
|
|
|
}
|
|
|
db.close();
|
|
|
@@ -113,14 +123,7 @@ public class DeliveryDao {
|
|
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
do {
|
|
|
- DeliveryRecord record = new DeliveryRecord(
|
|
|
- cursor.getString(cursor.getColumnIndexOrThrow("deliveryNo")),
|
|
|
- cursor.getString(cursor.getColumnIndexOrThrow("machine")),
|
|
|
- cursor.getString(cursor.getColumnIndexOrThrow("operator")),
|
|
|
- cursor.getString(cursor.getColumnIndexOrThrow("operatorName"))
|
|
|
- );
|
|
|
- record.setId(cursor.getLong(cursor.getColumnIndexOrThrow("id")));
|
|
|
- record.setOperationTime(cursor.getString(cursor.getColumnIndexOrThrow("operationTime")));
|
|
|
+ DeliveryRecord record = parseRecordFromCursor(cursor);
|
|
|
records.add(record);
|
|
|
} while (cursor.moveToNext());
|
|
|
}
|
|
|
@@ -131,6 +134,91 @@ public class DeliveryDao {
|
|
|
return records;
|
|
|
}
|
|
|
|
|
|
+ // 根据送货单号更新上传状态
|
|
|
+ public int markAsPushed(String deliveryNo) {
|
|
|
+ SQLiteDatabase db = dbHelper.getWritableDatabase();
|
|
|
+ ContentValues values = new ContentValues();
|
|
|
+ values.put("isPush", 1); // 标记为已上传
|
|
|
+
|
|
|
+ return db.update(
|
|
|
+ "delivery",
|
|
|
+ values,
|
|
|
+ "deliveryNo = ?",
|
|
|
+ new String[]{deliveryNo}
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据送货单号更新上传状态为失败
|
|
|
+ public int updateDeliveryPushFail(String deliveryNo) {
|
|
|
+ SQLiteDatabase db = dbHelper.getWritableDatabase();
|
|
|
+ ContentValues values = new ContentValues();
|
|
|
+ values.put("isPush", 0); // 标记为已上传
|
|
|
+
|
|
|
+ return db.update(
|
|
|
+ "delivery",
|
|
|
+ values,
|
|
|
+ "deliveryNo = ?",
|
|
|
+ new String[]{deliveryNo}
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量标记为已上传
|
|
|
+ public int markMultipleAsPushed(List<String> deliveryNos) {
|
|
|
+ SQLiteDatabase db = dbHelper.getWritableDatabase();
|
|
|
+ db.beginTransaction();
|
|
|
+ int successCount = 0;
|
|
|
+
|
|
|
+ try {
|
|
|
+ for (String deliveryNo : deliveryNos) {
|
|
|
+ ContentValues values = new ContentValues();
|
|
|
+ values.put("isPush", 1);
|
|
|
+
|
|
|
+ int updated = db.update(
|
|
|
+ "delivery",
|
|
|
+ values,
|
|
|
+ "deliveryNo = ? AND isPush = 0", // 只更新待上传的记录
|
|
|
+ new String[]{deliveryNo}
|
|
|
+ );
|
|
|
+
|
|
|
+ if (updated > 0) {
|
|
|
+ successCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ db.setTransactionSuccessful();
|
|
|
+ return successCount;
|
|
|
+ } finally {
|
|
|
+ db.endTransaction();
|
|
|
+ db.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询所有待上传的记录
|
|
|
+ public List<DeliveryRecord> listPendingUploadRecords() {
|
|
|
+ List<DeliveryRecord> records = new ArrayList<>();
|
|
|
+ SQLiteDatabase db = dbHelper.getReadableDatabase();
|
|
|
+
|
|
|
+ Cursor cursor = db.query(
|
|
|
+ "delivery",
|
|
|
+ null,
|
|
|
+ "isPush = 0", // 待上传状态
|
|
|
+ null, null, null,
|
|
|
+ "operationTime ASC" // 按时间升序(最早优先)
|
|
|
+ );
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (cursor != null && cursor.moveToFirst()) {
|
|
|
+ do {
|
|
|
+ DeliveryRecord record = parseRecordFromCursor(cursor);
|
|
|
+ records.add(record);
|
|
|
+ } while (cursor.moveToNext());
|
|
|
+ }
|
|
|
+ return records;
|
|
|
+ } finally {
|
|
|
+ if (cursor != null) cursor.close();
|
|
|
+ db.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 获取总记录数
|
|
|
public int getTotalRecordsCount() {
|
|
|
SQLiteDatabase db = dbHelper.getReadableDatabase();
|
|
|
@@ -162,14 +250,7 @@ public class DeliveryDao {
|
|
|
|
|
|
if (cursor != null) {
|
|
|
while (cursor.moveToNext()) {
|
|
|
- DeliveryRecord record = new DeliveryRecord(
|
|
|
- cursor.getString(cursor.getColumnIndexOrThrow("deliveryNo")),
|
|
|
- cursor.getString(cursor.getColumnIndexOrThrow("machine")),
|
|
|
- cursor.getString(cursor.getColumnIndexOrThrow("operator")),
|
|
|
- cursor.getString(cursor.getColumnIndexOrThrow("operatorName"))
|
|
|
- );
|
|
|
- record.setId(cursor.getLong(cursor.getColumnIndexOrThrow("id")));
|
|
|
- record.setOperationTime(cursor.getString(cursor.getColumnIndexOrThrow("operationTime")));
|
|
|
+ DeliveryRecord record = parseRecordFromCursor(cursor);
|
|
|
records.add(record);
|
|
|
}
|
|
|
cursor.close();
|