🆗 由于默认密码变更,已无法后台登录,改为使用jsessionID登录

🆗 兼容新的打卡
🆗 增加自动打卡开关
This commit is contained in:
jimlee
2023-03-22 19:34:53 +08:00
parent becdffe1d4
commit 8e9842b4f9
3 changed files with 36 additions and 19 deletions

View File

@@ -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.HoperunUserConfig.userConfigMap
import com.pomelotea.hoperun.sign.config.UserConfig import com.pomelotea.hoperun.sign.config.UserConfig
import com.pomelotea.hoperun.sign.scheduler.AutoDakaScheduler import com.pomelotea.hoperun.sign.scheduler.AutoDakaScheduler
import com.pomelotea.hoperun.sign.scheduler.AutoDakaScheduler.Companion.dakaQueue
import okhttp3.FormBody import okhttp3.FormBody
import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.Request import okhttp3.Request
@@ -143,6 +144,12 @@ class HoperunSignController {
queryMonthAttData(employeeNo, jsessionId, getLastDateyyyy_MM() + "-01") queryMonthAttData(employeeNo, jsessionId, getLastDateyyyy_MM() + "-01")
val lastMonthAttLogs = lastMonthAttList.sortedByDescending { it.yearmonth }.filter { it.dateType == "1" } val lastMonthAttLogs = lastMonthAttList.sortedByDescending { it.yearmonth }.filter { it.dateType == "1" }
monthAttResult.addAll(lastMonthAttLogs) 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 return monthAttResult
} }
@@ -278,7 +285,9 @@ data class MonthAttLog(
var project_id: String? = null, var project_id: String? = null,
var projectcode: String? = null, var projectcode: String? = null,
var staff_code: 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( data class HoperunDakaRequest(

View File

@@ -25,6 +25,10 @@ class AutoDakaScheduler {
val outFile = File("./daka.log") val outFile = File("./daka.log")
val bw: BufferedWriter = BufferedWriter(OutputStreamWriter(outFile.outputStream())) 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 timeThreadPool: ScheduledExecutorService = Executors.newScheduledThreadPool(1)
val schedulerThreadPool: ScheduledExecutorService = Executors.newScheduledThreadPool(10) val schedulerThreadPool: ScheduledExecutorService = Executors.newScheduledThreadPool(10)
@@ -39,8 +43,7 @@ class AutoDakaScheduler {
fun addAutoDakaScheduled(dakaDate: String = getNowDateyyyy_MM_dd()) { fun addAutoDakaScheduled(dakaDate: String = getNowDateyyyy_MM_dd()) {
// 调休的工作日 // 调休的工作日
if (isNeedDaka(dakaDate)) { if (isNeedDaka(dakaDate)) {
bw.use { HoperunUserConfig.userConfigMap.forEach { (_, v) ->
HoperunUserConfig.userConfigMap.forEach { (k, v) ->
if (v.autoDaka) { if (v.autoDaka) {
// 没有当日的打卡信息才插入 // 没有当日的打卡信息才插入
var daka = dakaQueue.find { it.dakaDate == dakaDate && it.employeeNo == v.employeeNo } var daka = dakaQueue.find { it.dakaDate == dakaDate && it.employeeNo == v.employeeNo }
@@ -53,7 +56,6 @@ class AutoDakaScheduler {
} }
} }
} }
}
dakaQueue.forEach { dakaQueue.forEach {
val beginDate = LocalDateTime.parse(it.dakaDate + "T" + it.beginTime + ":" + randowSecond(), DateTimeFormatter.ISO_LOCAL_DATE_TIME) val beginDate = LocalDateTime.parse(it.dakaDate + "T" + it.beginTime + ":" + randowSecond(), DateTimeFormatter.ISO_LOCAL_DATE_TIME)
@@ -75,11 +77,13 @@ class AutoDakaScheduler {
private fun beginDaka(daka: Daka) { private fun beginDaka(daka: Daka) {
// println("begin:${daka.toCsv()}") // println("begin:${daka.toCsv()}")
logBw.write("execute begin sign: ${daka.toCsv()}")
beginTime(employeeNo = daka.employeeNo, date = daka.dakaDate, time = daka.beginTime) beginTime(employeeNo = daka.employeeNo, date = daka.dakaDate, time = daka.beginTime)
} }
private fun endDaka(daka: Daka) { private fun endDaka(daka: Daka) {
// println("end:${daka.toCsv()}") // println("end:${daka.toCsv()}")
logBw.write("execute end sign: ${daka.toCsv()}")
endTime(employeeNo = daka.employeeNo, date = daka.dakaDate, time = daka.beginTime) endTime(employeeNo = daka.employeeNo, date = daka.dakaDate, time = daka.beginTime)
} }

View File

@@ -28,6 +28,7 @@ if ($('#login-span').css('display') !== 'none') {
let jsessonIdInput = document.querySelector('#jsessionId'); let jsessonIdInput = document.querySelector('#jsessionId');
let autoDaka = document.querySelector("#toggle--switch") let autoDaka = document.querySelector("#toggle--switch")
autoDaka.checked = window.localStorage.getItem("autodaka")
document.querySelector('#login').addEventListener("click", () => { document.querySelector('#login').addEventListener("click", () => {
window.localStorage.setItem("employeeNo", employeeNumberInput.value); window.localStorage.setItem("employeeNo", employeeNumberInput.value);
@@ -77,7 +78,7 @@ function loginAndLoadRecord() {
cocoMessage.error("登陆失败!" + result.message, 3000); cocoMessage.error("登陆失败!" + result.message, 3000);
} }
}, },
error: function (e) { error: function () {
cocoMessage.error("请求失败!", 3000); cocoMessage.error("请求失败!", 3000);
} }
}) })
@@ -109,6 +110,8 @@ function loadDakaList() {
'<div class="job-detail-buttons">' + '<div class="job-detail-buttons">' +
'<button class="search-buttons detail-button">' + (signlog.begin_time == null ? "未打卡" : signlog.begin_time.substr(11, 5)) + '</button>' + '<button class="search-buttons detail-button">' + (signlog.begin_time == null ? "未打卡" : signlog.begin_time.substr(11, 5)) + '</button>' +
'<button class="search-buttons detail-button">' + (signlog.end_time == null ? "未打卡" : signlog.end_time.substr(11, 5)) + '</button>' + '<button class="search-buttons detail-button">' + (signlog.end_time == null ? "未打卡" : signlog.end_time.substr(11, 5)) + '</button>' +
(signlog.autoDakaBeginTime == null ? "" : '<br><button class="search-buttons detail-button">定时上班卡时间: ' + signlog.autoDakaBeginTime + '</button>') +
(signlog.autoDakaEndTime == null ? "" : '<button class="search-buttons detail-button">定时下班卡时间: ' + signlog.autoDakaEndTime + '</button>') +
(signlog.end_time != null && signlog.end_time.substr(11, 5) > "20:30" ? '<button class="search-buttons detail-button">餐补</button>' : '') + (signlog.end_time != null && signlog.end_time.substr(11, 5) > "20:30" ? '<button class="search-buttons detail-button">餐补</button>' : '') +
'</div>' + '</div>' +
(index <= 3 ? '<div class="job-card-buttons">' + (index <= 3 ? '<div class="job-card-buttons">' +
@@ -130,7 +133,7 @@ function loadDakaList() {
} }
closeLoading() closeLoading()
}, },
error: function (e) { error: function () {
cocoMessage.error("请求失败!", 3000); cocoMessage.error("请求失败!", 3000);
closeLoading() closeLoading()
} }
@@ -205,7 +208,8 @@ function bindSaveDakaTime() {
function bindAutoDakaToggle() { function bindAutoDakaToggle() {
document.querySelectorAll("#toggle--switch").forEach((dakaButton) => { document.querySelectorAll("#toggle--switch").forEach((dakaButton) => {
$(dakaButton).off('change').on('change', function (e) { $(dakaButton).off('change').on('change', function () {
window.localStorage.setItem("autodaka", this.checked);
$.ajax({ $.ajax({
method: "get", method: "get",
url: "/api/daka/auto/" + window.localStorage.getItem("employeeNo") + "/" + autoDaka.checked, url: "/api/daka/auto/" + window.localStorage.getItem("employeeNo") + "/" + autoDaka.checked,
@@ -214,7 +218,7 @@ function bindAutoDakaToggle() {
cocoMessage.error("登陆失败!" + result.message, 3000); cocoMessage.error("登陆失败!" + result.message, 3000);
} }
}, },
error: function (e) { error: function () {
cocoMessage.error("请求失败!", 3000); cocoMessage.error("请求失败!", 3000);
} }
}) })
@@ -260,7 +264,7 @@ function saveDakaTime(signDate, beginTime, endTime) {
} }
} }
}, },
error: function (e) { error: function () {
cocoMessage.error("请求失败!", 3000); cocoMessage.error("请求失败!", 3000);
} }
}); });
@@ -290,7 +294,7 @@ function saveDakaTime(signDate, beginTime, endTime) {
} }
} }
}, },
error: function (e) { error: function () {
cocoMessage.error("请求失败!", 3000); cocoMessage.error("请求失败!", 3000);
} }
}); });
@@ -308,7 +312,7 @@ function randomBeginTime() {
function randomEndTime() { function randomEndTime() {
let hourArray = [18, 19, 20, 21, 22, 23, 20, 21, 22, 20, 20, 21]; let hourArray = [18, 19, 20, 21, 22, 23, 20, 21, 22, 20, 20, 21];
let randomHour = hourArray[Math.round(Math.random() * 9)]; let randomHour = hourArray[Math.round(Math.random() * 9)];
let randomMinute = 0; let randomMinute;
if (randomHour === 18) { if (randomHour === 18) {
randomMinute = Math.round(Math.random() * 30) + 29; randomMinute = Math.round(Math.random() * 30) + 29;
} else { } else {