diff --git a/src/main/kotlin/com/pomelotea/hoperun/sign/api/HoperunDakaController.kt b/src/main/kotlin/com/pomelotea/hoperun/sign/api/HoperunDakaController.kt index dc27c27..ca45d34 100644 --- a/src/main/kotlin/com/pomelotea/hoperun/sign/api/HoperunDakaController.kt +++ b/src/main/kotlin/com/pomelotea/hoperun/sign/api/HoperunDakaController.kt @@ -12,6 +12,7 @@ import com.pomelotea.hoperun.sign.config.HoperunUserConfig.getUserConfig import com.pomelotea.hoperun.sign.config.HoperunUserConfig.userConfigMap import com.pomelotea.hoperun.sign.config.UserConfig import com.pomelotea.hoperun.sign.scheduler.AutoDakaScheduler +import com.pomelotea.hoperun.sign.scheduler.AutoDakaScheduler.Companion.dakaQueue import okhttp3.FormBody import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.Request @@ -143,6 +144,12 @@ class HoperunSignController { queryMonthAttData(employeeNo, jsessionId, getLastDateyyyy_MM() + "-01") val lastMonthAttLogs = lastMonthAttList.sortedByDescending { it.yearmonth }.filter { it.dateType == "1" } monthAttResult.addAll(lastMonthAttLogs) + val monthAttLog = monthAttResult.find { it.yearmonth == getNowDateyyyy_MM_dd() } + val autoDaka = dakaQueue.filter { it.dakaDate == getNowDateyyyy_MM_dd() }.findLast { it.employeeNo == employeeNo } + if (autoDaka != null && monthAttLog != null) { + monthAttLog.autoDakaBeginTime = autoDaka.beginTime + monthAttLog.autoDakaEndTime = autoDaka.endTime + } return monthAttResult } @@ -278,7 +285,9 @@ data class MonthAttLog( var project_id: String? = null, var projectcode: String? = null, var staff_code: String? = null, - var yearmonth: String? = null + var yearmonth: String? = null, + var autoDakaBeginTime: String? = null, + var autoDakaEndTime: String? = null, ) data class HoperunDakaRequest( diff --git a/src/main/kotlin/com/pomelotea/hoperun/sign/scheduler/AutoDakaScheduler.kt b/src/main/kotlin/com/pomelotea/hoperun/sign/scheduler/AutoDakaScheduler.kt index 27fa584..7c67335 100644 --- a/src/main/kotlin/com/pomelotea/hoperun/sign/scheduler/AutoDakaScheduler.kt +++ b/src/main/kotlin/com/pomelotea/hoperun/sign/scheduler/AutoDakaScheduler.kt @@ -25,6 +25,10 @@ class AutoDakaScheduler { val outFile = File("./daka.log") val bw: BufferedWriter = BufferedWriter(OutputStreamWriter(outFile.outputStream())) + val logFile = File("./scheduler.log") + val logBw: BufferedWriter = BufferedWriter(OutputStreamWriter(logFile.outputStream())) + + val timeThreadPool: ScheduledExecutorService = Executors.newScheduledThreadPool(1) val schedulerThreadPool: ScheduledExecutorService = Executors.newScheduledThreadPool(10) @@ -39,18 +43,16 @@ class AutoDakaScheduler { fun addAutoDakaScheduled(dakaDate: String = getNowDateyyyy_MM_dd()) { // 调休的工作日 if (isNeedDaka(dakaDate)) { - bw.use { - HoperunUserConfig.userConfigMap.forEach { (k, v) -> - if (v.autoDaka) { - // 没有当日的打卡信息才插入 - var daka = dakaQueue.find { it.dakaDate == dakaDate && it.employeeNo == v.employeeNo } - if (daka == null) { - daka = generateDakaInfo(v, dakaDate) - dakaQueue.add(daka) - } - bw.write("${v.username},${daka.toCsv()}") - bw.newLine() + HoperunUserConfig.userConfigMap.forEach { (_, v) -> + if (v.autoDaka) { + // 没有当日的打卡信息才插入 + var daka = dakaQueue.find { it.dakaDate == dakaDate && it.employeeNo == v.employeeNo } + if (daka == null) { + daka = generateDakaInfo(v, dakaDate) + dakaQueue.add(daka) } + bw.write("${v.username},${daka.toCsv()}") + bw.newLine() } } } @@ -75,11 +77,13 @@ class AutoDakaScheduler { private fun beginDaka(daka: Daka) { // println("begin:${daka.toCsv()}") + logBw.write("execute begin sign: ${daka.toCsv()}") beginTime(employeeNo = daka.employeeNo, date = daka.dakaDate, time = daka.beginTime) } private fun endDaka(daka: Daka) { // println("end:${daka.toCsv()}") + logBw.write("execute end sign: ${daka.toCsv()}") endTime(employeeNo = daka.employeeNo, date = daka.dakaDate, time = daka.beginTime) } diff --git a/src/main/resources/static/script.js b/src/main/resources/static/script.js index c4665f6..b15c1b4 100644 --- a/src/main/resources/static/script.js +++ b/src/main/resources/static/script.js @@ -28,6 +28,7 @@ if ($('#login-span').css('display') !== 'none') { let jsessonIdInput = document.querySelector('#jsessionId'); let autoDaka = document.querySelector("#toggle--switch") +autoDaka.checked = window.localStorage.getItem("autodaka") document.querySelector('#login').addEventListener("click", () => { window.localStorage.setItem("employeeNo", employeeNumberInput.value); @@ -77,7 +78,7 @@ function loginAndLoadRecord() { cocoMessage.error("登陆失败!" + result.message, 3000); } }, - error: function (e) { + error: function () { cocoMessage.error("请求失败!", 3000); } }) @@ -109,6 +110,8 @@ function loadDakaList() { '
' + (index <= 3 ? '