commit 05/02/2026

This commit is contained in:
2026-02-05 16:51:03 +07:00
parent 4a6df6bef4
commit afd896161e
2 changed files with 25 additions and 22 deletions

View File

@@ -3,6 +3,8 @@ package database
import org.apache.poi.xssf.usermodel.XSSFWorkbook import org.apache.poi.xssf.usermodel.XSSFWorkbook
import org.tinylog.Logger import org.tinylog.Logger
import java.sql.Connection import java.sql.Connection
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.function.Consumer import java.util.function.Consumer
class Table_LogSemiAuto(connection: Connection) : dbFunctions<LogSemiauto>("logsemiauto", connection, listOf("index", "date", "time", "source", "description")) { 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>?){ fun GetLogSemiAutoForHtml(date: String, filter: String?, cbOK: Consumer<ArrayList<LogSemiauto>>?, cbFail: Consumer<String>?){
try{ try{
val valid_date : String? = when{ val valid_date : java.sql.Date? = when{
dateformat1.matches(date) -> date dateformat1.matches(date) -> {
java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("dd/MM/yyyy")))
}
dateformat2.matches(date) -> { dateformat2.matches(date) -> {
val parts = date.split("-") java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("dd-MM-yyyy")))
"${parts[0]}/${parts[1]}/${parts[2]}"
} }
dateformat3.matches(date) -> { dateformat3.matches(date) -> {
val parts = date.split("/") java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy/MM/dd")))
"${parts[2]}/${parts[1]}/${parts[0]}"
} }
dateformat4.matches(date) -> { dateformat4.matches(date) -> {
val parts = date.split("-") java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")))
"${parts[2]}/${parts[1]}/${parts[0]}"
} }
else -> null else -> null
} }
if (valid_date!=null){ if (valid_date!=null){
val statement = if (filter.isNullOrEmpty()){ 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 { } 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()){ if (!filter.isNullOrEmpty()){
statement?.setString(2, "%$filter%") statement?.setString(2, "%$filter%")
} }

View File

@@ -3,6 +3,8 @@ package database
import org.apache.poi.xssf.usermodel.XSSFWorkbook import org.apache.poi.xssf.usermodel.XSSFWorkbook
import org.tinylog.Logger import org.tinylog.Logger
import java.sql.Connection import java.sql.Connection
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.function.Consumer import java.util.function.Consumer
class Table_Logs(connection: Connection) : dbFunctions<Log> ("logs", connection,listOf("index", "datenya", "timenya", "machine", "description")) { 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>?){ fun GetLogForHtml(date: String, filter: String?, cbOK: Consumer<ArrayList<Log>>?, cbFail: Consumer<String>?){
try{ try{
val valid_date : String? = when{ val valid_date : java.sql.Date? = when{
dateformat1.matches(date) -> date dateformat1.matches(date) -> {
java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("dd/MM/yyyy")))
}
dateformat2.matches(date) -> { dateformat2.matches(date) -> {
val parts = date.split("-") java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("dd-MM-yyyy")))
"${parts[0]}/${parts[1]}/${parts[2]}"
} }
dateformat3.matches(date) -> { dateformat3.matches(date) -> {
val parts = date.split("/") java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy/MM/dd")))
"${parts[2]}/${parts[1]}/${parts[0]}"
} }
dateformat4.matches(date) -> { dateformat4.matches(date) -> {
val parts = date.split("-") java.sql.Date.valueOf(LocalDate.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd")))
"${parts[2]}/${parts[1]}/${parts[0]}"
} }
else -> null else -> null
} }
if (valid_date!=null){ if (valid_date!=null){
// use coalescing for different datenya formats
val statement = if (filter.isNullOrEmpty()){ 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 { } 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()){ if (!filter.isNullOrEmpty()){
statement?.setString(2, "%$filter%") statement?.setString(2, "%$filter%")
} }