增加消息通知
This commit is contained in:
@@ -3,8 +3,8 @@ package com.pomelotea.hoperun.sign.api.model
|
|||||||
data class ScNotifyRequest(
|
data class ScNotifyRequest(
|
||||||
val title: String,
|
val title: String,
|
||||||
val desp: String?,
|
val desp: String?,
|
||||||
val tags: String?,
|
val tags: String? = null,
|
||||||
val short: String?
|
val short: String? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
data class ScNotifyResponse(
|
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.JSON
|
||||||
import com.alibaba.fastjson.JSONObject
|
import com.alibaba.fastjson.JSONObject
|
||||||
import com.pomelotea.hoperun.sign.api.DakaResponse
|
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.api.model.ScNotifyResponse
|
||||||
import com.pomelotea.hoperun.sign.common.*
|
import com.pomelotea.hoperun.sign.common.*
|
||||||
import com.pomelotea.hoperun.sign.config.HoperunUserConfig
|
import com.pomelotea.hoperun.sign.config.HoperunUserConfig
|
||||||
import com.pomelotea.hoperun.sign.config.UserConfig
|
import com.pomelotea.hoperun.sign.config.UserConfig
|
||||||
|
import com.pomelotea.hoperun.sign.notify.ServerChan3NotifyHelper
|
||||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.RequestBody.Companion.toRequestBody
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -27,7 +30,10 @@ import java.util.concurrent.TimeUnit
|
|||||||
* date 2023-03-22 14:50
|
* date 2023-03-22 14:50
|
||||||
* 自动打卡定时任务
|
* 自动打卡定时任务
|
||||||
**/
|
**/
|
||||||
class AutoDakaScheduler {
|
@Service
|
||||||
|
open class AutoDakaScheduler(
|
||||||
|
private val serverChan3NotifyHelper: ServerChan3NotifyHelper
|
||||||
|
) {
|
||||||
|
|
||||||
val timeThreadPool: ScheduledExecutorService = Executors.newScheduledThreadPool(1)
|
val timeThreadPool: ScheduledExecutorService = Executors.newScheduledThreadPool(1)
|
||||||
val schedulerThreadPool: ScheduledExecutorService = Executors.newScheduledThreadPool(10)
|
val schedulerThreadPool: ScheduledExecutorService = Executors.newScheduledThreadPool(10)
|
||||||
@@ -51,33 +57,20 @@ class AutoDakaScheduler {
|
|||||||
if (daka == null) {
|
if (daka == null) {
|
||||||
daka = generateDakaInfo(v, dakaDate)
|
daka = generateDakaInfo(v, dakaDate)
|
||||||
dakaQueue.add(daka)
|
dakaQueue.add(daka)
|
||||||
val notifyRequest = Request.Builder()
|
val scNotifyResponse = serverChan3NotifyHelper.push(
|
||||||
.url("https://7248.push.ft07.com/send/sctp7248ta-yehg0lpo6cr9xl6ikqwbpn4l.send")
|
ScNotifyRequest(
|
||||||
.post(
|
title = "添加打卡任务:${v.username}, $daka",
|
||||||
JSON.toJSONString(
|
desp = "添加打卡任务:${v.username}, $daka"
|
||||||
mapOf<String, String>(
|
|
||||||
"title" to "添加打卡任务:${v.username}, $daka",
|
|
||||||
"desp" to "添加打卡任务:${v.username}, $daka"
|
|
||||||
)
|
)
|
||||||
).toRequestBody("application/json;charset=utf-8".toMediaTypeOrNull())
|
|
||||||
)
|
)
|
||||||
.build()
|
|
||||||
val result: String? = client.newCall(notifyRequest).execute().body?.string()
|
if (scNotifyResponse.code != 0) {
|
||||||
val resp = JSONObject.parseObject(result, ScNotifyResponse::class.java)
|
serverChan3NotifyHelper.push(
|
||||||
if (resp.code != 0) {
|
ScNotifyRequest(
|
||||||
val notifyRequest = Request.Builder()
|
title = "添加打卡任务失败:${v.username}, $daka",
|
||||||
.url("https://7248.push.ft07.com/send/sctp7248ta-yehg0lpo6cr9xl6ikqwbpn4l.send")
|
desp = "添加打卡任务失败:${v.username}, $daka"
|
||||||
.post(
|
|
||||||
JSON.toJSONString(
|
|
||||||
mapOf<String, String>(
|
|
||||||
"title" to "添加打卡任务失败:${v.username}, $daka",
|
|
||||||
"desp" to "添加打卡任务失败:${v.username}, $daka"
|
|
||||||
)
|
)
|
||||||
).toRequestBody("application/json;charset=utf-8".toMediaTypeOrNull())
|
|
||||||
)
|
)
|
||||||
.build()
|
|
||||||
val result: String? = client.newCall(notifyRequest).execute().body?.string()
|
|
||||||
logger.info(result)
|
|
||||||
}
|
}
|
||||||
logger.info("添加打卡任务: ${v.username}, $daka")
|
logger.info("添加打卡任务: ${v.username}, $daka")
|
||||||
}
|
}
|
||||||
@@ -130,33 +123,19 @@ class AutoDakaScheduler {
|
|||||||
beginTime(employeeNo = daka.employeeNo, date = daka.dakaDate, time = daka.beginTime)
|
beginTime(employeeNo = daka.employeeNo, date = daka.dakaDate, time = daka.beginTime)
|
||||||
if (resp.result != "success") {
|
if (resp.result != "success") {
|
||||||
logger.error("打上班卡失败")
|
logger.error("打上班卡失败")
|
||||||
val notifyRequest = Request.Builder()
|
serverChan3NotifyHelper.push(
|
||||||
.url("https://7248.push.ft07.com/send/sctp7248ta-yehg0lpo6cr9xl6ikqwbpn4l.send")
|
ScNotifyRequest(
|
||||||
.post(
|
title = "打上班卡失败:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}",
|
||||||
JSON.toJSONString(
|
desp = "打上班卡失败:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}"
|
||||||
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())
|
|
||||||
)
|
)
|
||||||
.build()
|
|
||||||
val result: String? = client.newCall(notifyRequest).execute().body?.string()
|
|
||||||
logger.info(result)
|
|
||||||
} else {
|
} else {
|
||||||
val notifyRequest = Request.Builder()
|
serverChan3NotifyHelper.push(
|
||||||
.url("https://7248.push.ft07.com/send/sctp7248ta-yehg0lpo6cr9xl6ikqwbpn4l.send")
|
ScNotifyRequest(
|
||||||
.post(
|
title = "打上班卡成功:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}",
|
||||||
JSON.toJSONString(
|
desp = "打上班卡成功:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.beginTime}"
|
||||||
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())
|
|
||||||
)
|
)
|
||||||
.build()
|
|
||||||
val result: String? = client.newCall(notifyRequest).execute().body?.string()
|
|
||||||
logger.info(result)
|
|
||||||
logger.info("打上班卡成功")
|
logger.info("打上班卡成功")
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -176,33 +155,19 @@ class AutoDakaScheduler {
|
|||||||
val resp: DakaResponse = endTime(employeeNo = daka.employeeNo, date = daka.dakaDate, time = daka.endTime)
|
val resp: DakaResponse = endTime(employeeNo = daka.employeeNo, date = daka.dakaDate, time = daka.endTime)
|
||||||
if (resp.result != "success") {
|
if (resp.result != "success") {
|
||||||
logger.error("打下班卡失败")
|
logger.error("打下班卡失败")
|
||||||
val notifyRequest = Request.Builder()
|
serverChan3NotifyHelper.push(
|
||||||
.url("https://7248.push.ft07.com/send/sctp7248ta-yehg0lpo6cr9xl6ikqwbpn4l.send")
|
ScNotifyRequest(
|
||||||
.post(
|
title = "打下班卡失败:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.endTime}",
|
||||||
JSON.toJSONString(
|
desp = "打下班卡失败:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.endTime}"
|
||||||
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())
|
|
||||||
)
|
)
|
||||||
.build()
|
|
||||||
val result: String? = client.newCall(notifyRequest).execute().body?.string()
|
|
||||||
logger.info(result)
|
|
||||||
} else {
|
} else {
|
||||||
val notifyRequest = Request.Builder()
|
serverChan3NotifyHelper.push(
|
||||||
.url("https://7248.push.ft07.com/send/sctp7248ta-yehg0lpo6cr9xl6ikqwbpn4l.send")
|
ScNotifyRequest(
|
||||||
.post(
|
title = "打下班卡成功:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.endTime}",
|
||||||
JSON.toJSONString(
|
desp = "打下班卡成功:${daka.employeeNo}:DATE:${daka.dakaDate}:TIME:${daka.endTime}"
|
||||||
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())
|
|
||||||
)
|
)
|
||||||
.build()
|
|
||||||
val result: String? = client.newCall(notifyRequest).execute().body?.string()
|
|
||||||
logger.info(result)
|
|
||||||
logger.info("打下班卡成功")
|
logger.info("打下班卡成功")
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
@@ -37,3 +37,7 @@ hoperun:
|
|||||||
"projectcode": "U2103S000112"
|
"projectcode": "U2103S000112"
|
||||||
"projectname": "JRKF-浙江网商-技术服务外包"
|
"projectname": "JRKF-浙江网商-技术服务外包"
|
||||||
"device": "Android 12;Redmi;M2007J3SC;deviceId:OAIDe7fa6084205e9a22d8f6f71bc91893ff;deviceName:Android"
|
"device": "Android 12;Redmi;M2007J3SC;deviceId:OAIDe7fa6084205e9a22d8f6f71bc91893ff;deviceName:Android"
|
||||||
|
|
||||||
|
sc3:
|
||||||
|
uid: 7248
|
||||||
|
sendKey: sctp7248ta-yehg0lpo6cr9xl6ikqwbpn4l
|
||||||
Reference in New Issue
Block a user