commit 06/10/2025

This commit is contained in:
2025-10-06 08:30:09 +07:00
parent 20dbc12b02
commit cf69c72f3c
9 changed files with 97 additions and 81 deletions

View File

@@ -6,11 +6,13 @@ import content.Category
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import max_channel
import org.apache.poi.xssf.usermodel.XSSFWorkbook
import org.tinylog.Logger
import java.sql.Connection
import java.sql.DriverManager
import java.util.function.Consumer
import kotlin.math.max
/**
* A class to manage a connection to a MariaDB database.
@@ -1464,7 +1466,7 @@ class MariaDB(
val countResult = statement?.executeQuery("SELECT COUNT(*) AS count FROM ${super.dbName}")
if (countResult?.next() == true) {
val count = countResult.getInt("count")
if (count == 0) {
if (count < max_channel) {
Logger.info("SoundChannel table is empty, populating with default channels" as Any)
Clear()
}
@@ -1578,9 +1580,9 @@ class MariaDB(
statement?.executeUpdate("TRUNCATE TABLE ${super.dbName}")
Logger.info("${super.dbName} table cleared" as Any)
List.clear()
// create new rows from 1 to 64 with description "Channel 01" to "Channel 64" and empty ip
for (i in 1..64) {
val channel = String.format("Channel %02d", i)
// create new rows from 1 to 64 with description "Channel 1" to "Channel 64" and empty ip
for (i in 1..max_channel) {
val channel = String.format("Channel %d", i)
val insertStatement =
connection.prepareStatement("INSERT INTO ${super.dbName} (channel, ip) VALUES (?, ?)")
insertStatement?.setString(1, channel)
@@ -1728,13 +1730,13 @@ class MariaDB(
statement?.setString(4, data.description)
val rowsAffected = statement?.executeUpdate()
if (rowsAffected != null && rowsAffected > 0) {
Logger.info("Log added: [$data.datenya $data.timenya] [$data.machine] $data.description" as Any)
Logger.info{"Log added : $data"}
return true
} else {
Logger.warn("No log entry added for: [$data.datenya $data.timenya] [$data.machine] $data.description" as Any)
Logger.warn{"Failed to add log entry : $data"}
}
} catch (e: Exception) {
Logger.error("Error adding log entry: ${e.message}" as Any)
Logger.error{"Error adding log entry: ${e.message}"}
}
return false
}