|
@@ -1,42 +1,41 @@
|
|
|
#include "hblastrecorddao.h"
|
|
|
|
|
|
-HBlastRecordDao::HBlastRecordDao(QSqlDatabase db) : database(db)
|
|
|
-{
|
|
|
-}
|
|
|
+HBlastRecordDao::HBlastRecordDao(QSqlDatabase db) : database(db) {}
|
|
|
|
|
|
-PaginatedHBlastRecordResult HBlastRecordDao::getAllHRecords(int page, int pageSize)
|
|
|
-{
|
|
|
+PaginatedHBlastRecordResult HBlastRecordDao::getAllHRecords(int page, int pageSize) {
|
|
|
QList<QSharedPointer<HBlastRecord>> BlastRecords;
|
|
|
QSqlQuery query(database);
|
|
|
int offset = (page - 1) * pageSize;
|
|
|
- query.prepare("SELECT * FROM h_blast_record ORDER BY created_at LIMIT :pageSize OFFSET :offset");
|
|
|
+ query.prepare(
|
|
|
+ "SELECT * FROM h_blast_record ORDER BY created_at desc LIMIT :pageSize OFFSET :offset");
|
|
|
query.bindValue(":pageSize", pageSize);
|
|
|
query.bindValue(":offset", offset);
|
|
|
- if (query.exec())
|
|
|
- {
|
|
|
- while (query.next())
|
|
|
- {
|
|
|
+ if (query.exec()) {
|
|
|
+ while (query.next()) {
|
|
|
BlastRecords.append(recordToBlastRecord(query.record()));
|
|
|
}
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
qWarning() << "Query execution failed: " << query.lastError().text();
|
|
|
}
|
|
|
|
|
|
query.prepare("SELECT COUNT(*) FROM h_blast_record");
|
|
|
int totalCount = 0;
|
|
|
- if (query.exec() && query.next())
|
|
|
- {
|
|
|
+ if (query.exec() && query.next()) {
|
|
|
totalCount = query.value(0).toInt();
|
|
|
}
|
|
|
return {BlastRecords, totalCount};
|
|
|
}
|
|
|
-bool HBlastRecordDao::addHBlastRecord(const HBlastRecord &record)
|
|
|
-{
|
|
|
+bool HBlastRecordDao::addHBlastRecord(const HBlastRecord &record) {
|
|
|
QSqlQuery query;
|
|
|
- query.prepare("INSERT INTO h_blast_record (uuid, project_name, project_htid, project_xmbh, operator_name, phone, operator_identity, equipment_sn, company_code, app_version, longitude, latitude, equipment_count, reg_det_count, error_det_count, blast_at, created_at, updated_at, deleted_at, create_by, update_by) "
|
|
|
- "VALUES (:uuid, :project_name, :project_htid, :project_xmbh, :operator_name, :phone, :operator_identity, :equipment_sn, :company_code, :app_version, :longitude, :latitude, :equipment_count, :reg_det_count, :error_det_count, :blast_at, :created_at, :updated_at, :deleted_at, :create_by, :update_by)");
|
|
|
+ query.prepare(
|
|
|
+ "INSERT INTO h_blast_record (uuid, project_name, project_htid, project_xmbh, "
|
|
|
+ "operator_name, phone, operator_identity, equipment_sn, company_code, app_version, "
|
|
|
+ "longitude, latitude, equipment_count, reg_det_count, error_det_count, blast_at, "
|
|
|
+ "created_at, updated_at, deleted_at, create_by, update_by, is_offline_blast) "
|
|
|
+ "VALUES (:uuid, :project_name, :project_htid, :project_xmbh, :operator_name, :phone, "
|
|
|
+ ":operator_identity, :equipment_sn, :company_code, :app_version, :longitude, :latitude, "
|
|
|
+ ":equipment_count, :reg_det_count, :error_det_count, :blast_at, :created_at, :updated_at, "
|
|
|
+ ":deleted_at, :create_by, :update_by, :is_offline_blast)");
|
|
|
query.bindValue(":uuid", record.getUuid());
|
|
|
query.bindValue(":project_name", record.getProjectName());
|
|
|
query.bindValue(":project_htid", record.getProjectHtid());
|
|
@@ -52,16 +51,13 @@ bool HBlastRecordDao::addHBlastRecord(const HBlastRecord &record)
|
|
|
query.bindValue(":equipment_count", record.getEquipmentCount());
|
|
|
query.bindValue(":reg_det_count", record.getRegDetCount());
|
|
|
query.bindValue(":error_det_count", record.getErrorDetCount());
|
|
|
+ query.bindValue(":is_offline_blast", record.getIsOfflineBlast());
|
|
|
query.bindValue(":blast_at", record.getBlastAt().toString(Qt::ISODateWithMs));
|
|
|
query.bindValue(":created_at", record.getCreatedAt().toString(Qt::ISODateWithMs));
|
|
|
query.bindValue(":create_by", record.getCreateBy());
|
|
|
- qDebug() << "created_at:" << record.getCreatedAt() << "blast_at" << record.getBlastAt();
|
|
|
- if (query.exec())
|
|
|
- {
|
|
|
+ if (query.exec()) {
|
|
|
return true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
qDebug() << "Failed to insert blast record:" << query.lastError().text();
|
|
|
return false;
|
|
|
}
|
|
@@ -106,32 +102,31 @@ bool HBlastRecordDao::addHBlastRecord(const HBlastRecord &record)
|
|
|
// return record;
|
|
|
// }
|
|
|
|
|
|
-bool HBlastRecordDao::updateHBlastRecord(const HBlastRecord &record)
|
|
|
-{
|
|
|
-
|
|
|
+bool HBlastRecordDao::updateHBlastRecord(const HBlastRecord &record) {
|
|
|
QSqlQuery query;
|
|
|
- query.prepare("UPDATE h_blast_record SET uuid = :uuid,"
|
|
|
- " project_name = :project_name, "
|
|
|
- "project_htid = :project_htid,"
|
|
|
- "project_xmbh = :project_xmbh,"
|
|
|
- "operator_name = :operator_name,"
|
|
|
- "phone = :phone,"
|
|
|
- "operator_identity = :operator_identity,"
|
|
|
- "equipment_sn = :equipment_sn,"
|
|
|
- "company_code = :company_code,"
|
|
|
- " app_version = :app_version,"
|
|
|
- "longitude = :longitude,"
|
|
|
- "latitude = :latitude,"
|
|
|
- "equipment_count = :equipment_count,"
|
|
|
- "reg_det_count = :reg_det_count,"
|
|
|
- "error_det_count = :error_det_count,"
|
|
|
- "blast_at = :blast_at,"
|
|
|
- "created_at = :created_at,"
|
|
|
- "updated_at = :updated_at,"
|
|
|
- "deleted_at = :deleted_at,"
|
|
|
- "create_by = :create_by,"
|
|
|
- "update_by = :update_by"
|
|
|
- "WHERE id = :id");
|
|
|
+ query.prepare(
|
|
|
+ "UPDATE h_blast_record SET uuid = :uuid,"
|
|
|
+ " project_name = :project_name, "
|
|
|
+ "project_htid = :project_htid,"
|
|
|
+ "project_xmbh = :project_xmbh,"
|
|
|
+ "operator_name = :operator_name,"
|
|
|
+ "phone = :phone,"
|
|
|
+ "operator_identity = :operator_identity,"
|
|
|
+ "equipment_sn = :equipment_sn,"
|
|
|
+ "company_code = :company_code,"
|
|
|
+ " app_version = :app_version,"
|
|
|
+ "longitude = :longitude,"
|
|
|
+ "latitude = :latitude,"
|
|
|
+ "equipment_count = :equipment_count,"
|
|
|
+ "reg_det_count = :reg_det_count,"
|
|
|
+ "error_det_count = :error_det_count,"
|
|
|
+ "blast_at = :blast_at,"
|
|
|
+ "created_at = :created_at,"
|
|
|
+ "updated_at = :updated_at,"
|
|
|
+ "deleted_at = :deleted_at,"
|
|
|
+ "create_by = :create_by,"
|
|
|
+ "update_by = :update_by"
|
|
|
+ "WHERE id = :id");
|
|
|
query.bindValue(":id", record.getId());
|
|
|
query.bindValue(":uuid", record.getUuid());
|
|
|
query.bindValue(":project_name", record.getProjectName());
|
|
@@ -155,40 +150,33 @@ bool HBlastRecordDao::updateHBlastRecord(const HBlastRecord &record)
|
|
|
query.bindValue(":create_by", record.getCreateBy());
|
|
|
query.bindValue(":update_by", record.getUpdateBy());
|
|
|
|
|
|
- if (query.exec())
|
|
|
- {
|
|
|
+ if (query.exec()) {
|
|
|
return true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
qDebug() << "Failed to update record:" << query.lastError().text();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-bool HBlastRecordDao::deleteHBlastRecord(const HBlastRecord &record)
|
|
|
-{
|
|
|
+bool HBlastRecordDao::deleteHBlastRecord(const HBlastRecord &record) {
|
|
|
QSqlQuery query;
|
|
|
query.prepare("DELETE FROM h_blast_record WHERE id = :id");
|
|
|
query.bindValue(":id", record.getId());
|
|
|
|
|
|
- if (query.exec())
|
|
|
- {
|
|
|
+ if (query.exec()) {
|
|
|
return true;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
qDebug() << "Failed to delete record:" << query.lastError().text();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-QSharedPointer<HBlastRecord> HBlastRecordDao::recordToBlastRecord(const QSqlRecord &record)
|
|
|
-{
|
|
|
+QSharedPointer<HBlastRecord> HBlastRecordDao::recordToBlastRecord(const QSqlRecord &record) {
|
|
|
QSharedPointer<HBlastRecord> blastRecord = QSharedPointer<HBlastRecord>::create();
|
|
|
blastRecord->setId(record.value("id").toLongLong());
|
|
|
blastRecord->setUuid(record.value("uuid").toString());
|
|
|
blastRecord->setProjectName(record.value("project_name").toString());
|
|
|
+ blastRecord->setIsOfflineBlast(record.value("is_offline_blast").toBool());
|
|
|
blastRecord->setProjectHtid(record.value("project_htid").toString());
|
|
|
blastRecord->setProjectXmbh(record.value("project_xmbh").toString());
|
|
|
blastRecord->setOperatorName(record.value("operator_name").toString());
|
|
@@ -202,10 +190,14 @@ QSharedPointer<HBlastRecord> HBlastRecordDao::recordToBlastRecord(const QSqlReco
|
|
|
blastRecord->setEquipmentCount(record.value("equipment_count").toInt());
|
|
|
blastRecord->setRegDetCount(record.value("reg_det_count").toInt());
|
|
|
blastRecord->setErrorDetCount(record.value("error_det_count").toInt());
|
|
|
- blastRecord->setBlastAt(QDateTime::fromString(record.value("blast_at").toString(), Qt::ISODateWithMs));
|
|
|
- blastRecord->setCreatedAt(QDateTime::fromString(record.value("created_at").toString(), Qt::ISODateWithMs));
|
|
|
- blastRecord->setUpdatedAt(QDateTime::fromString(record.value("updated_at").toString(), Qt::ISODateWithMs));
|
|
|
- blastRecord->setDeletedAt(QDateTime::fromString(record.value("deleted_at").toString(), Qt::ISODateWithMs));
|
|
|
+ blastRecord->setBlastAt(
|
|
|
+ QDateTime::fromString(record.value("blast_at").toString(), Qt::ISODateWithMs));
|
|
|
+ blastRecord->setCreatedAt(
|
|
|
+ QDateTime::fromString(record.value("created_at").toString(), Qt::ISODateWithMs));
|
|
|
+ blastRecord->setUpdatedAt(
|
|
|
+ QDateTime::fromString(record.value("updated_at").toString(), Qt::ISODateWithMs));
|
|
|
+ blastRecord->setDeletedAt(
|
|
|
+ QDateTime::fromString(record.value("deleted_at").toString(), Qt::ISODateWithMs));
|
|
|
blastRecord->setCreateBy(record.value("create_by").toLongLong());
|
|
|
blastRecord->setUpdateBy(record.value("update_by").toLongLong());
|
|
|
return blastRecord;
|