package cn.flightfeather.supervision.bgtask.sysnotice
|
|
import cn.flightfeather.supervision.domain.entity.NoticeTemplate
|
import cn.flightfeather.supervision.domain.entity.Userinfo
|
import cn.flightfeather.supervision.domain.enumeration.DistrictType
|
import cn.flightfeather.supervision.domain.enumeration.SceneType
|
import cn.flightfeather.supervision.domain.mapper.NoticeTemplateMapper
|
import cn.flightfeather.supervision.lightshare.service.NotificationService
|
import cn.flightfeather.supervision.lightshare.vo.NotificationVo
|
import org.springframework.stereotype.Component
|
import java.util.*
|
|
/**
|
* 系统通知管理
|
*/
|
@Component
|
class SysNoticeManager(
|
private val noticeTemplateMapper: NoticeTemplateMapper,
|
private val notificationService:NotificationService
|
) {
|
|
data class Receiver(
|
val receiverType: String = "-1",
|
val receiverId: String? = null,
|
val district: String = "-1",
|
)
|
|
private val userId = "sys"
|
private val regex = "#{param}"
|
private val templates = mutableMapOf<Int, NoticeTemplate?>()
|
|
/**
|
* 发送通知
|
* @param code
|
* @see [SysNoticeTemplate],[LedgerNoticeTemplate],[SelfPatrolNoticeTemplate],
|
* [EmergencySelfPatrolNoticeTemplate],[AssessmentNoticeTemplate],[CommitmentNoticeTemplate]
|
*/
|
private fun send(code: Int, receiver: Receiver, params: List<String> = emptyList()) {
|
val p = mutableListOf<String>().apply { addAll(params) }
|
val t = if (templates.containsKey(code)) {
|
templates[code]
|
} else {
|
val temp = noticeTemplateMapper.selectByPrimaryKey(code)
|
templates[code] = temp
|
temp
|
}
|
var template = t?.ntNoticeTemplate
|
while (p.isNotEmpty() && template?.contains(regex) == true) {
|
template = template.replace(regex, p.first())
|
p.removeFirst()
|
}
|
|
notificationService.releaseNotice(userId, NotificationVo(
|
authorId = userId,
|
authorName = userId,
|
typeId = t?.ntNoticeType?.toString(),
|
typeName = t?.ntNoticeTypeName,
|
subTypeId = t?.ntNoticeSubType?.toString(),
|
subTypeName = t?.ntNoticeSubTypeName,
|
title = t?.ntNoticeTitle,
|
content = t?.ntNoticeTemplate,
|
updateTime = Date(),
|
receiverType = receiver.receiverType,
|
receiverId = receiver.receiverId,
|
district = receiver.district
|
))
|
}
|
|
/**
|
* 发送给特定用户
|
*/
|
private fun sendToUser(code: Int, users: List<Userinfo?>, params: List<String> = emptyList()) {
|
if (users.isNotEmpty()) {
|
val idList = users.map { it?.guid }.joinToString(";") + ";"
|
send(code, Receiver(receiverId = idList), params)
|
}
|
}
|
|
/**
|
* 发送给一片区域内的所有用户
|
*/
|
private fun sendToArea(
|
code: Int,
|
sceneTypes: List<SceneType>,
|
districts: List<DistrictType>,
|
params: List<String> = emptyList(),
|
) {
|
val receiverType = if (sceneTypes.isEmpty()) {
|
"0;"
|
} else {
|
sceneTypes.map { it.value }.joinToString(";") + ";"
|
}
|
val district = if (districts.isEmpty()) {
|
"0"
|
} else {
|
districts.joinToString(";") + ";"
|
}
|
send(code, Receiver(receiverType = receiverType, district = district), params)
|
}
|
|
/**
|
* 系统提醒/通知
|
*/
|
fun send(t: SysNoticeTemplate, users: List<Userinfo?>, params: List<String> = emptyList()) =
|
sendToUser(t.value, users, params)
|
|
fun send(
|
t: SysNoticeTemplate,
|
sceneTypes: List<SceneType>,
|
districts: List<DistrictType>,
|
params: List<String> = emptyList(),
|
) = sendToArea(t.value, sceneTypes, districts, params)
|
|
/**
|
* 环保台账提醒/通知
|
*/
|
fun send(t: LedgerNoticeTemplate, users: List<Userinfo?>, params: List<String> = emptyList()) =
|
sendToUser(t.value, users, params)
|
|
fun send(
|
t: LedgerNoticeTemplate,
|
sceneTypes: List<SceneType>,
|
districts: List<DistrictType>,
|
params: List<String> = emptyList(),
|
) = sendToArea(t.value, sceneTypes, districts, params)
|
|
/**
|
* 自巡查提醒/通知
|
*/
|
fun send(t: SelfPatrolNoticeTemplate, users: List<Userinfo?>, params: List<String> = emptyList()) =
|
sendToUser(t.value, users, params)
|
|
fun send(
|
t: SelfPatrolNoticeTemplate,
|
sceneTypes: List<SceneType>,
|
districts: List<DistrictType>,
|
params: List<String> = emptyList(),
|
) = sendToArea(t.value, sceneTypes, districts, params)
|
|
/**
|
* 应急自巡查提醒/通知
|
*/
|
fun send(t: EmergencySelfPatrolNoticeTemplate, users: List<Userinfo?>, params: List<String> = emptyList()) =
|
sendToUser(t.value, users, params)
|
|
fun send(
|
t: EmergencySelfPatrolNoticeTemplate,
|
sceneTypes: List<SceneType>,
|
districts: List<DistrictType>,
|
params: List<String> = emptyList(),
|
) = sendToArea(t.value, sceneTypes, districts, params)
|
|
/**
|
* 自测智评提醒/通知
|
*/
|
fun send(t: AssessmentNoticeTemplate, users: List<Userinfo?>, params: List<String> = emptyList()) =
|
sendToUser(t.value, users, params)
|
|
fun send(
|
t: AssessmentNoticeTemplate,
|
sceneTypes: List<SceneType>,
|
districts: List<DistrictType>,
|
params: List<String> = emptyList(),
|
) = sendToArea(t.value, sceneTypes, districts, params)
|
|
/**
|
* 守法承诺提醒/通知
|
*/
|
fun send(t: CommitmentNoticeTemplate, users: List<Userinfo?>, params: List<String> = emptyList()) =
|
sendToUser(t.value, users, params)
|
|
fun send(
|
t: CommitmentNoticeTemplate,
|
sceneTypes: List<SceneType>,
|
districts: List<DistrictType>,
|
params: List<String> = emptyList(),
|
) = sendToArea(t.value, sceneTypes, districts, params)
|
}
|