commit 05/02/2026
This commit is contained in:
@@ -3,6 +3,8 @@ package database
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook
|
||||
import org.tinylog.Logger
|
||||
import java.sql.Connection
|
||||
import java.time.LocalDate
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.function.Consumer
|
||||
|
||||
class Table_LogSemiAuto(connection: Connection) : dbFunctions<LogSemiauto>("logsemiauto", connection, listOf("index", "date", "time", "source", "description")) {
|
||||
@@ -90,29 +92,28 @@ class Table_LogSemiAuto(connection: Connection) : dbFunctions<LogSemiauto>("logs
|
||||
|
||||
fun GetLogSemiAutoForHtml(date: String, filter: String?, cbOK: Consumer<ArrayList<LogSemiauto>>?, cbFail: Consumer<String>?){
|
||||
try{
|
||||
val valid_date : String? = when{
|
||||
dateformat1.matches(date) -> date
|
||||
val valid_date : java.sql.Date? = when{
|
||||
dateformat1.matches(date) -> {
|
||||
java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("dd/MM/yyyy")))
|
||||
}
|
||||
dateformat2.matches(date) -> {
|
||||
val parts = date.split("-")
|
||||
"${parts[0]}/${parts[1]}/${parts[2]}"
|
||||
java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("dd-MM-yyyy")))
|
||||
}
|
||||
dateformat3.matches(date) -> {
|
||||
val parts = date.split("/")
|
||||
"${parts[2]}/${parts[1]}/${parts[0]}"
|
||||
java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy/MM/dd")))
|
||||
}
|
||||
dateformat4.matches(date) -> {
|
||||
val parts = date.split("-")
|
||||
"${parts[2]}/${parts[1]}/${parts[0]}"
|
||||
java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")))
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
if (valid_date!=null){
|
||||
val statement = if (filter.isNullOrEmpty()){
|
||||
connection.prepareStatement("SELECT * FROM ${super.dbName} WHERE date = ?")
|
||||
connection.prepareStatement("SELECT * FROM ${super.dbName} WHERE COALESCE(STR_TO_DATE(date,'%d/%m/%Y'), STR_TO_DATE(date,'%d-%m-%Y'), STR_TO_DATE(date,'%Y/%m/%d'), STR_TO_DATE(date,'%Y-%m-%d')) = ?")
|
||||
} else {
|
||||
connection.prepareStatement("SELECT * FROM ${super.dbName} WHERE date = ? AND description LIKE ?")
|
||||
connection.prepareStatement("SELECT * FROM ${super.dbName} WHERE COALESCE(STR_TO_DATE(date,'%d/%m/%Y'), STR_TO_DATE(date,'%d-%m-%Y'), STR_TO_DATE(date,'%Y/%m/%d'), STR_TO_DATE(date,'%Y-%m-%d')) = ? AND description LIKE ?")
|
||||
}
|
||||
statement?.setString(1, valid_date)
|
||||
statement?.setDate(1, valid_date)
|
||||
if (!filter.isNullOrEmpty()){
|
||||
statement?.setString(2, "%$filter%")
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package database
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook
|
||||
import org.tinylog.Logger
|
||||
import java.sql.Connection
|
||||
import java.time.LocalDate
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.function.Consumer
|
||||
|
||||
class Table_Logs(connection: Connection) : dbFunctions<Log> ("logs", connection,listOf("index", "datenya", "timenya", "machine", "description")) {
|
||||
@@ -42,29 +44,29 @@ class Table_Logs(connection: Connection) : dbFunctions<Log> ("logs", connection,
|
||||
|
||||
fun GetLogForHtml(date: String, filter: String?, cbOK: Consumer<ArrayList<Log>>?, cbFail: Consumer<String>?){
|
||||
try{
|
||||
val valid_date : String? = when{
|
||||
dateformat1.matches(date) -> date
|
||||
val valid_date : java.sql.Date? = when{
|
||||
dateformat1.matches(date) -> {
|
||||
java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("dd/MM/yyyy")))
|
||||
}
|
||||
dateformat2.matches(date) -> {
|
||||
val parts = date.split("-")
|
||||
"${parts[0]}/${parts[1]}/${parts[2]}"
|
||||
java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("dd-MM-yyyy")))
|
||||
}
|
||||
dateformat3.matches(date) -> {
|
||||
val parts = date.split("/")
|
||||
"${parts[2]}/${parts[1]}/${parts[0]}"
|
||||
java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy/MM/dd")))
|
||||
}
|
||||
dateformat4.matches(date) -> {
|
||||
val parts = date.split("-")
|
||||
"${parts[2]}/${parts[1]}/${parts[0]}"
|
||||
java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")))
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
if (valid_date!=null){
|
||||
// use coalescing for different datenya formats
|
||||
val statement = if (filter.isNullOrEmpty()){
|
||||
connection.prepareStatement("SELECT * FROM ${super.dbName} WHERE datenya = ?")
|
||||
connection.prepareStatement("SELECT * FROM ${super.dbName} WHERE COALESCE(STR_TO_DATE(datenya,'%d/%m/%Y'), STR_TO_DATE(datenya,'%d-%m-%Y'), STR_TO_DATE(datenya,'%Y/%m/%d'), STR_TO_DATE(datenya,'%Y-%m-%d')) = ?")
|
||||
} else {
|
||||
connection.prepareStatement("SELECT * FROM ${super.dbName} WHERE datenya = ? AND description LIKE ?")
|
||||
connection.prepareStatement("SELECT * FROM ${super.dbName} WHERE COALESCE(STR_TO_DATE(datenya,'%d/%m/%Y'), STR_TO_DATE(datenya,'%d-%m-%Y'), STR_TO_DATE(datenya,'%Y/%m/%d'), STR_TO_DATE(datenya,'%Y-%m-%d')) = ? AND description LIKE ?")
|
||||
}
|
||||
statement?.setString(1, valid_date)
|
||||
statement?.setDate(1, valid_date)
|
||||
if (!filter.isNullOrEmpty()){
|
||||
statement?.setString(2, "%$filter%")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user