commit 22/01/2026
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import ActiveMQ.ActiveMQClient
|
||||
import Other.Config
|
||||
import Web.WebUI
|
||||
import database.MySQLInjector
|
||||
import database.MySQLAdapter
|
||||
import org.tinylog.provider.ProviderRegistry
|
||||
import java.util.function.Consumer
|
||||
|
||||
@@ -13,7 +13,7 @@ fun main() {
|
||||
webUI.Start()
|
||||
val activeclient = ActiveMQClient()
|
||||
//activeclient.Start()
|
||||
val mysql = MySQLInjector()
|
||||
val mysql = MySQLAdapter()
|
||||
mysql.Start()
|
||||
|
||||
activeclient.MessageConsumer = Consumer{ message ->
|
||||
|
||||
110
src/database/MySQLAdapter.kt
Normal file
110
src/database/MySQLAdapter.kt
Normal file
@@ -0,0 +1,110 @@
|
||||
package database
|
||||
|
||||
import java.sql.Connection
|
||||
import java.sql.DriverManager
|
||||
import config
|
||||
import org.tinylog.Logger
|
||||
import java.util.function.BiConsumer
|
||||
|
||||
@Suppress("UNUSED")
|
||||
/**
|
||||
* MySQL Adapter for AAS
|
||||
* @param aas_id The AAS ID (1, 2, or 3)
|
||||
*/
|
||||
class MySQLAdapter(val aas_id: Int) {
|
||||
|
||||
init{
|
||||
require(aas_id in 1..3){
|
||||
"aas_id must be between 1 and 3"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to connect to MySQL Database
|
||||
* @param cb Callback function with parameters (success: Boolean, connection: Connection)
|
||||
*/
|
||||
private fun Connect(cb : BiConsumer<Boolean,Connection?>){
|
||||
try {
|
||||
val conn = when(aas_id){
|
||||
1 -> DriverManager.getConnection(config.MySQL_AAS1, config.MySQL_AAS1_Username, config.MySQL_AAS1_Password)
|
||||
2 -> DriverManager.getConnection(config.MySQL_AAS2, config.MySQL_AAS2_Username, config.MySQL_AAS2_Password)
|
||||
3 -> DriverManager.getConnection(config.MySQL_AAS3, config.MySQL_AAS3_Username, config.MySQL_AAS3_Password)
|
||||
else -> null
|
||||
}
|
||||
if (conn != null){
|
||||
cb.accept(true, conn)
|
||||
} else throw Exception("Connection is null")
|
||||
} catch (e : Exception){
|
||||
Logger.error { "Failed to connect MySQL Adapter for AAS$aas_id: ${e.message}" }
|
||||
cb.accept(false, null)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Airline Codes
|
||||
* @param cb Callback function with parameters (success: Boolean, codes: ArrayList<String>)
|
||||
*/
|
||||
fun GetAirlineCode(cb: BiConsumer<Boolean, ArrayList<String>>){
|
||||
Connect { success, connection ->
|
||||
if (success){
|
||||
try {
|
||||
connection!!.prepareStatement("SELECT DISTINCT TAG from aas.soundbank").use { statement ->
|
||||
val result = ArrayList<String>()
|
||||
statement.executeQuery().use { rs ->
|
||||
while (rs.next()){
|
||||
result.add(rs.getString("TAG"))
|
||||
}
|
||||
}
|
||||
connection.close()
|
||||
Logger.info { "GetAirlineCode succeeded, found ${result.size} codes" }
|
||||
cb.accept(true, result)
|
||||
}
|
||||
} catch (e: Exception){
|
||||
Logger.error { "GetAirlineCode failed, exception: ${e.message}" }
|
||||
cb.accept(false, arrayListOf())
|
||||
}
|
||||
|
||||
} else {
|
||||
Logger.error { "GetAirlineCode failed, no Connection" }
|
||||
cb.accept(false, arrayListOf())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert records to Queue Table
|
||||
* @param queue Vararg of QueueTableData to insert
|
||||
*/
|
||||
fun InsertToQueueTable(vararg queue: QueueTableData){
|
||||
Connect { success, connection ->
|
||||
if (success){
|
||||
var updatecount : IntArray
|
||||
try{
|
||||
connection!!.prepareStatement("INSERT INTO aas.queue_table (Date_Time, Source, Type, Message, SB_TAGS, BroadcastZones, Repeat, Language) VALUES (?,?,?,?,?,?,?,?)").use { ps ->
|
||||
queue.forEach { data ->
|
||||
ps.setString(1, data.Date_Time)
|
||||
ps.setString(2, data.Source)
|
||||
ps.setString(3, data.Tipe)
|
||||
ps.setString(4, data.Message)
|
||||
ps.setString(5, data.SB_Tags)
|
||||
ps.setString(6, data.BroadcastZones)
|
||||
ps.setInt(7, 1)
|
||||
ps.setString(8, data.Language)
|
||||
ps.addBatch()
|
||||
}
|
||||
updatecount = ps.executeBatch()
|
||||
ps.close()
|
||||
}
|
||||
|
||||
connection.close()
|
||||
Logger.info { "Inserted ${queue.size} records to AAS$aas_id Queue Table, update counts: ${updatecount.joinToString()}" }
|
||||
} catch (e : Exception){
|
||||
Logger.error { "Failed to insert MySQL Adapter for AAS$aas_id: ${e.message}" }
|
||||
}
|
||||
|
||||
} else Logger.error { "InsertToQueueTable failed , no Connection" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package database
|
||||
|
||||
@Suppress("UNUSED")
|
||||
class MySQLInjector {
|
||||
|
||||
/**
|
||||
* Start MySQL Injector
|
||||
*/
|
||||
fun Start(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop MySQL Injector
|
||||
*/
|
||||
fun Stop(){
|
||||
|
||||
}
|
||||
}
|
||||
3
src/database/QueueTableData.kt
Normal file
3
src/database/QueueTableData.kt
Normal file
@@ -0,0 +1,3 @@
|
||||
package database
|
||||
|
||||
data class QueueTableData(val Date_Time: String, val Source: String, val Tipe: String, val Message: String, val SB_Tags: String, val BroadcastZones: String, val Language: String)
|
||||
Reference in New Issue
Block a user