增加消息通知
This commit is contained in:
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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<String, String>(
|
||||
"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<String, String>(
|
||||
"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<String, String>(
|
||||
"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<String, String>(
|
||||
"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<String, String>(
|
||||
"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<String, String>(
|
||||
"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) {
|
||||
|
||||
Reference in New Issue
Block a user