From 1de86a2f461fbcc430fef510dca83db495c97bd7 Mon Sep 17 00:00:00 2001 From: jimleerx Date: Tue, 4 Nov 2025 15:29:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B6=88=E6=81=AF=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hoperun/sign/api/model/ScNotifyRequest.kt | 4 +- .../sign/notify/ServerChan3NotifyHelper.kt | 32 +++++ .../sign/scheduler/AutoDakaScheduler.kt | 113 ++++++------------ src/main/resources/config/application.yml | 4 + 4 files changed, 77 insertions(+), 76 deletions(-) create mode 100644 src/main/kotlin/com/pomelotea/hoperun/sign/notify/ServerChan3NotifyHelper.kt diff --git a/src/main/kotlin/com/pomelotea/hoperun/sign/api/model/ScNotifyRequest.kt b/src/main/kotlin/com/pomelotea/hoperun/sign/api/model/ScNotifyRequest.kt index d216337..e3b1140 100644 --- a/src/main/kotlin/com/pomelotea/hoperun/sign/api/model/ScNotifyRequest.kt +++ b/src/main/kotlin/com/pomelotea/hoperun/sign/api/model/ScNotifyRequest.kt @@ -3,8 +3,8 @@ package com.pomelotea.hoperun.sign.api.model data class ScNotifyRequest( val title: String, val desp: String?, - val tags: String?, - val short: String? + val tags: String? = null, + val short: String? = null ) data class ScNotifyResponse( diff --git a/src/main/kotlin/com/pomelotea/hoperun/sign/notify/ServerChan3NotifyHelper.kt b/src/main/kotlin/com/pomelotea/hoperun/sign/notify/ServerChan3NotifyHelper.kt new file mode 100644 index 0000000..b4cde94 --- /dev/null +++ b/src/main/kotlin/com/pomelotea/hoperun/sign/notify/ServerChan3NotifyHelper.kt @@ -0,0 +1,32 @@ +package com.pomelotea.hoperun.sign.notify + +import com.alibaba.fastjson.JSON +import com.alibaba.fastjson.JSONObject +import com.pomelotea.hoperun.sign.api.model.ScNotifyRequest +import com.pomelotea.hoperun.sign.api.model.ScNotifyResponse +import com.pomelotea.hoperun.sign.common.client +import com.pomelotea.hoperun.sign.scheduler.AutoDakaScheduler.Companion.logger +import okhttp3.MediaType.Companion.toMediaTypeOrNull +import okhttp3.Request +import okhttp3.RequestBody.Companion.toRequestBody +import org.springframework.beans.factory.annotation.Value +import org.springframework.stereotype.Service + +@Service +open class ServerChan3NotifyHelper( + @field:Value("\${sc3.uid}") private val uid: String, + @field:Value("\${sc3.sendKey}") private val sendKey: String, +) { + + fun push(req: ScNotifyRequest): ScNotifyResponse { + val notifyRequest = Request.Builder() + .url("https://${uid}.push.ft07.com/send/${sendKey}.send") + .post( + JSON.toJSONString(req) + .toRequestBody("application/json;charset=utf-8".toMediaTypeOrNull()) + ) + .build() + val result: String? = client.newCall(notifyRequest).execute().body?.string() + return JSONObject.parseObject(result, ScNotifyResponse::class.java) + } +} \ No newline at end of file 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 4b57070..24ab6ff 100644 --- a/src/main/kotlin/com/pomelotea/hoperun/sign/scheduler/AutoDakaScheduler.kt +++ b/src/main/kotlin/com/pomelotea/hoperun/sign/scheduler/AutoDakaScheduler.kt @@ -3,15 +3,18 @@ package com.pomelotea.hoperun.sign.scheduler import com.alibaba.fastjson.JSON import com.alibaba.fastjson.JSONObject import com.pomelotea.hoperun.sign.api.DakaResponse +import com.pomelotea.hoperun.sign.api.model.ScNotifyRequest import com.pomelotea.hoperun.sign.api.model.ScNotifyResponse import com.pomelotea.hoperun.sign.common.* import com.pomelotea.hoperun.sign.config.HoperunUserConfig import com.pomelotea.hoperun.sign.config.UserConfig +import com.pomelotea.hoperun.sign.notify.ServerChan3NotifyHelper import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.Request import okhttp3.RequestBody.Companion.toRequestBody import org.slf4j.Logger import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service import java.time.LocalDateTime import java.time.format.DateTimeFormatter import java.util.* @@ -27,7 +30,10 @@ import java.util.concurrent.TimeUnit * date 2023-03-22 14:50 * 自动打卡定时任务 **/ -class AutoDakaScheduler { +@Service +open class AutoDakaScheduler( + private val serverChan3NotifyHelper: ServerChan3NotifyHelper +) { val timeThreadPool: ScheduledExecutorService = Executors.newScheduledThreadPool(1) val schedulerThreadPool: ScheduledExecutorService = Executors.newScheduledThreadPool(10) @@ -51,33 +57,20 @@ class AutoDakaScheduler { if (daka == null) { daka = generateDakaInfo(v, dakaDate) dakaQueue.add(daka) - val notifyRequest = Request.Builder() - .url("https://7248.push.ft07.com/send/sctp7248ta-yehg0lpo6cr9xl6ikqwbpn4l.send") - .post( - JSON.toJSONString( - mapOf( - "title" to "添加打卡任务:${v.username}, $daka", - "desp" to "添加打卡任务:${v.username}, $daka" - ) - ).toRequestBody("application/json;charset=utf-8".toMediaTypeOrNull()) + val scNotifyResponse = serverChan3NotifyHelper.push( + ScNotifyRequest( + title = "添加打卡任务:${v.username}, $daka", + desp = "添加打卡任务:${v.username}, $daka" ) - .build() - val result: String? = client.newCall(notifyRequest).execute().body?.string() - val resp = JSONObject.parseObject(result, ScNotifyResponse::class.java) - if (resp.code != 0) { - val notifyRequest = Request.Builder() - .url("https://7248.push.ft07.com/send/sctp7248ta-yehg0lpo6cr9xl6ikqwbpn4l.send") - .post( - JSON.toJSONString( - mapOf( - "title" to "添加打卡任务失败:${v.username}, $daka", - "desp" to "添加打卡任务失败:${v.username}, $daka" - ) - ).toRequestBody("application/json;charset=utf-8".toMediaTypeOrNull()) + ) + + if (scNotifyResponse.code != 0) { + serverChan3NotifyHelper.push( + ScNotifyRequest( + title = "添加打卡任务失败:${v.username}, $daka", + desp = "添加打卡任务失败:${v.username}, $daka" ) - .build() - val result: String? = client.newCall(notifyRequest).execute().body?.string() - logger.info(result) + ) } logger.info("添加打卡任务: ${v.username}, $daka") } @@ -130,33 +123,19 @@ class AutoDakaScheduler { beginTime(employeeNo = daka.employeeNo, date = daka.dakaDate, time = daka.beginTime) if (resp.result != "success") { logger.error("打上班卡失败") - val notifyRequest = Request.Builder() - .url("https://7248.push.ft07.com/send/sctp7248ta-yehg0lpo6cr9xl6ikqwbpn4l.send") - .post( - JSON.toJSONString( - mapOf( - "title" to "打上班卡失败:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}", - "desp" to "打上班卡失败:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}" - ) - ).toRequestBody("application/json;charset=utf-8".toMediaTypeOrNull()) + serverChan3NotifyHelper.push( + ScNotifyRequest( + title = "打上班卡失败:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}", + desp = "打上班卡失败:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}" ) - .build() - val result: String? = client.newCall(notifyRequest).execute().body?.string() - logger.info(result) + ) } else { - val notifyRequest = Request.Builder() - .url("https://7248.push.ft07.com/send/sctp7248ta-yehg0lpo6cr9xl6ikqwbpn4l.send") - .post( - JSON.toJSONString( - mapOf( - "title" to "打上班卡成功:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}", - "desp" to "打上班卡成功:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}" - ) - ).toRequestBody("application/json;charset=utf-8".toMediaTypeOrNull()) + serverChan3NotifyHelper.push( + ScNotifyRequest( + title = "打上班卡成功:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}", + desp = "打上班卡成功:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}" ) - .build() - val result: String? = client.newCall(notifyRequest).execute().body?.string() - logger.info(result) + ) logger.info("打上班卡成功") } } catch (e: Exception) { @@ -176,33 +155,19 @@ class AutoDakaScheduler { val resp: DakaResponse = endTime(employeeNo = daka.employeeNo, date = daka.dakaDate, time = daka.endTime) if (resp.result != "success") { logger.error("打下班卡失败") - val notifyRequest = Request.Builder() - .url("https://7248.push.ft07.com/send/sctp7248ta-yehg0lpo6cr9xl6ikqwbpn4l.send") - .post( - JSON.toJSONString( - mapOf( - "title" to "打下班卡失败:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}", - "desp" to "打下班卡失败:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}" - ) - ).toRequestBody("application/json;charset=utf-8".toMediaTypeOrNull()) + serverChan3NotifyHelper.push( + ScNotifyRequest( + title = "打下班卡失败:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.endTime}", + desp = "打下班卡失败:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.endTime}" ) - .build() - val result: String? = client.newCall(notifyRequest).execute().body?.string() - logger.info(result) + ) } else { - val notifyRequest = Request.Builder() - .url("https://7248.push.ft07.com/send/sctp7248ta-yehg0lpo6cr9xl6ikqwbpn4l.send") - .post( - JSON.toJSONString( - mapOf( - "title" to "打下班卡成功:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}", - "desp" to "打下班卡成功:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}" - ) - ).toRequestBody("application/json;charset=utf-8".toMediaTypeOrNull()) + serverChan3NotifyHelper.push( + ScNotifyRequest( + title = "打下班卡成功:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.endTime}", + desp = "打下班卡成功:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.endTime}" ) - .build() - val result: String? = client.newCall(notifyRequest).execute().body?.string() - logger.info(result) + ) logger.info("打下班卡成功") } } catch (e: Exception) { diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index 677f0b8..6ef1551 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -37,3 +37,7 @@ hoperun: "projectcode": "U2103S000112" "projectname": "JRKF-浙江网商-技术服务外包" "device": "Android 12;Redmi;M2007J3SC;deviceId:OAIDe7fa6084205e9a22d8f6f71bc91893ff;deviceName:Android" + +sc3: + uid: 7248 + sendKey: sctp7248ta-yehg0lpo6cr9xl6ikqwbpn4l \ No newline at end of file