|
|
@@ -2,41 +2,75 @@ package com.ffii.fpsms.m18.service |
|
|
|
|
|
|
|
import com.ffii.core.utils.JwtTokenUtil |
|
|
|
import com.ffii.fpsms.m18.web.models.M18CommonRequest |
|
|
|
//import jakarta.annotation.PostConstruct |
|
|
|
import com.ffii.fpsms.modules.common.SettingNames |
|
|
|
import com.ffii.fpsms.modules.settings.service.SettingsService |
|
|
|
import jakarta.annotation.PostConstruct |
|
|
|
import org.slf4j.Logger |
|
|
|
import org.slf4j.LoggerFactory |
|
|
|
import org.springframework.scheduling.TaskScheduler |
|
|
|
//import org.springframework.scheduling.annotation.Async |
|
|
|
import org.springframework.scheduling.annotation.Scheduled |
|
|
|
import org.springframework.scheduling.support.CronTrigger |
|
|
|
import org.springframework.stereotype.Service |
|
|
|
import java.time.LocalDateTime |
|
|
|
import java.time.format.DateTimeFormatter |
|
|
|
//import java.util.concurrent.ScheduledFuture |
|
|
|
//import kotlin.concurrent.Volatile |
|
|
|
import java.util.concurrent.ScheduledFuture |
|
|
|
import kotlin.concurrent.Volatile |
|
|
|
import kotlin.jvm.optionals.getOrNull |
|
|
|
|
|
|
|
@Service |
|
|
|
open class M18SchedulerService( |
|
|
|
val m18PurchaseOrderService: M18PurchaseOrderService, |
|
|
|
val m18DeliveryOrderService: M18DeliveryOrderService, |
|
|
|
val m18MasterDataService: M18MasterDataService, |
|
|
|
val settingsService: SettingsService, |
|
|
|
val taskScheduler: TaskScheduler, |
|
|
|
) { |
|
|
|
var logger: Logger = LoggerFactory.getLogger(JwtTokenUtil::class.java) |
|
|
|
val dataStringFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd") |
|
|
|
|
|
|
|
// @Volatile |
|
|
|
// var scheduledM18Po: ScheduledFuture<*>? = null |
|
|
|
// |
|
|
|
// @PostConstruct |
|
|
|
// fun init() { |
|
|
|
// |
|
|
|
// } |
|
|
|
// |
|
|
|
// fun scheduleM18PoTask() { |
|
|
|
// scheduledM18Po?.cancel(false) |
|
|
|
// } |
|
|
|
@Volatile |
|
|
|
var scheduledM18Po: ScheduledFuture<*>? = null |
|
|
|
|
|
|
|
fun isValidCronExpression(cronExpression: String): Boolean { |
|
|
|
return try { |
|
|
|
CronTrigger(cronExpression) |
|
|
|
true |
|
|
|
} catch (e: IllegalArgumentException) { |
|
|
|
false |
|
|
|
} |
|
|
|
} |
|
|
|
@PostConstruct |
|
|
|
fun init() { |
|
|
|
scheduleM18PoTask() |
|
|
|
} |
|
|
|
|
|
|
|
fun scheduleM18PoTask() { |
|
|
|
val defaultCronExpression = "0 0 2 * * *"; |
|
|
|
scheduledM18Po?.cancel(false) |
|
|
|
|
|
|
|
var cron = settingsService.findByName(SettingNames.SCHEDULE_M18_PO).getOrNull()?.value ?: defaultCronExpression; |
|
|
|
|
|
|
|
if (!isValidCronExpression(cron)) { |
|
|
|
cron = defaultCronExpression |
|
|
|
} |
|
|
|
scheduledM18Po = taskScheduler.schedule( |
|
|
|
{ |
|
|
|
// testTask(); |
|
|
|
getM18Pos() |
|
|
|
}, |
|
|
|
CronTrigger(cron) |
|
|
|
) |
|
|
|
println("Cron: $cron") |
|
|
|
} |
|
|
|
|
|
|
|
fun testTask() { |
|
|
|
println("Test: ${LocalDateTime.now()}") |
|
|
|
} |
|
|
|
|
|
|
|
// @Async |
|
|
|
// @Scheduled(cron = "0 0 2 * * *") // (SS/MM/HH/DD/MM/YY) |
|
|
|
@Scheduled(cron = "0 0 2 * * *") // (SS/MM/HH/DD/MM/YY) |
|
|
|
// @Scheduled(cron = "0 0 2 * * *") // (SS/MM/HH/DD/MM/YY) |
|
|
|
open fun getM18Pos() { |
|
|
|
val currentTime = LocalDateTime.now() |
|
|
|
val today = currentTime.toLocalDate().atStartOfDay() |
|
|
|