Skip to content

Commit 7e3f228

Browse files
committed
新增 **通知渠道**,新增「SecRandom+ClassIsland」选项
1 parent 8f5f804 commit 7e3f228

3 files changed

Lines changed: 56 additions & 20 deletions

File tree

CHANGELOG/v2.2.0/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ v2.0 - Koharu(小鸟游星野) release 3
33

44
## 🚀 主要更新
55

6-
-
6+
- 新增 **通知渠道**,新增「SecRandom+ClassIsland」选项
77

88
## 💡 功能优化
99

app/Language/modules/notification_settings.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,12 @@
9898
},
9999
"notification_service_type": {
100100
"name": "通知服务类型",
101-
"description": "选择通知服务类型,内置服务或ClassIsland",
102-
"combo_items": ["内置通知服务", "ClassIsland通知服务"],
101+
"description": "选择通知服务类型,SecRandom或ClassIsland",
102+
"combo_items": [
103+
"SecRandom",
104+
"ClassIsland",
105+
"SecRandom+ClassIsland",
106+
],
103107
},
104108
"notification_display_duration": {
105109
"name": "通知显示时长",
@@ -183,8 +187,9 @@
183187
"name": "Notification service type",
184188
"description": "Select notification service type, SecRandom or ClassIsland",
185189
"combo_items": [
186-
"SecRandom Notification Service",
187-
"ClassIsland Notification Service",
190+
"SecRandom",
191+
"ClassIsland",
192+
"SecRandom + ClassIsland",
188193
],
189194
},
190195
"notification_display_duration": {
@@ -259,8 +264,8 @@
259264
},
260265
"notification_service_type": {
261266
"name": "通知服务类型",
262-
"description": "选择通知服务类型,内置服务或ClassIsland",
263-
"combo_items": ["内置通知服务", "ClassIsland通知服务"],
267+
"description": "选择通知服务类型,SecRandom或ClassIsland",
268+
"combo_items": ["SecRandom", "ClassIsland", "SecRandom+ClassIsland"],
264269
},
265270
"notification_display_duration": {
266271
"name": "通知显示时长",
@@ -327,8 +332,9 @@
327332
"name": "Notification service type",
328333
"description": "Select notification service type, SecRandom or ClassIsland",
329334
"combo_items": [
330-
"SecRandom Notification Service",
331-
"ClassIsland Notification Service",
335+
"SecRandom",
336+
"ClassIsland",
337+
"SecRandom + ClassIsland",
332338
],
333339
},
334340
"notification_display_duration": {
@@ -413,8 +419,12 @@
413419
},
414420
"notification_service_type": {
415421
"name": "通知服务类型",
416-
"description": "选择通知服务类型,内置服务或ClassIsland",
417-
"combo_items": ["内置通知服务", "ClassIsland通知服务"],
422+
"description": "选择通知服务类型,SecRandom或ClassIsland",
423+
"combo_items": [
424+
"SecRandom",
425+
"ClassIsland",
426+
"SecRandom+ClassIsland",
427+
],
418428
},
419429
"notification_display_duration": {
420430
"name": "通知显示时长",
@@ -493,8 +503,9 @@
493503
"name": "Notification service type",
494504
"description": "Select notification service type, SecRandom or ClassIsland",
495505
"combo_items": [
496-
"SecRandom Notification Service",
497-
"ClassIsland Notification Service",
506+
"SecRandom",
507+
"ClassIsland",
508+
"SecRandom + ClassIsland",
498509
],
499510
},
500511
"notification_display_duration": {

app/common/notification/notification_service.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ def send_to_classisland(
946946
draw_count=1,
947947
settings=None,
948948
settings_group=None,
949+
fallback_on_error=True,
949950
):
950951
"""发送通知到ClassIsland
951952
@@ -955,6 +956,7 @@ def send_to_classisland(
955956
draw_count: 抽取的学生数量
956957
settings: 通知设置参数
957958
settings_group: 设置组名称
959+
fallback_on_error: 是否在错误时回退到内置通知
958960
"""
959961

960962
try:
@@ -965,17 +967,27 @@ def send_to_classisland(
965967
if status:
966968
logger.info("成功发送通知到ClassIsland,结果未知")
967969
else:
970+
if fallback_on_error:
971+
logger.info("因错误回退到SecRandom通知服务")
972+
self._show_secrandom_notification(
973+
class_name,
974+
selected_students,
975+
draw_count,
976+
settings,
977+
settings_group,
978+
)
979+
else:
980+
logger.warning("发送通知到ClassIsland失败")
981+
except Exception as e:
982+
logger.exception("发送通知到ClassIsland时出错: {}", e)
983+
# 如果发生异常,回退到SecRandom通知服务
984+
if fallback_on_error:
968985
logger.info("因错误回退到SecRandom通知服务")
969986
self._show_secrandom_notification(
970987
class_name, selected_students, draw_count, settings, settings_group
971988
)
972-
except Exception as e:
973-
logger.exception("发送通知到ClassIsland时出错: {}", e)
974-
# 如果发生异常,回退到SecRandom通知服务
975-
logger.info("因错误回退到SecRandom通知服务")
976-
self._show_secrandom_notification(
977-
class_name, selected_students, draw_count, settings, settings_group
978-
)
989+
else:
990+
logger.warning("发送通知到ClassIsland时出错,但不回退")
979991

980992
def _show_secrandom_notification(
981993
self,
@@ -1101,6 +1113,19 @@ def show_roll_call_result(
11011113
)
11021114
return
11031115

1116+
# 如果选择了内置+ClassIsland通知服务,则同时发送到两个服务
1117+
if notification_service_type == 2: # 2 表示 内置+ClassIsland 通知服务
1118+
# 先发送到ClassIsland,不回退(因为会继续显示内置通知)
1119+
self.send_to_classisland(
1120+
class_name,
1121+
selected_students,
1122+
draw_count,
1123+
settings,
1124+
settings_group,
1125+
fallback_on_error=False,
1126+
)
1127+
# 继续执行下面的内置通知逻辑,不return
1128+
11041129
# 否则使用SecRandom浮窗通知
11051130
# 获取设置
11061131
if settings:

0 commit comments

Comments
 (0)