增加多群通知

This commit is contained in:
dengqichen 2025-05-28 10:44:31 +08:00
parent d165f2b043
commit 7cc6dc6ba5
6 changed files with 105 additions and 98 deletions

View File

@ -30,12 +30,25 @@
### 2. 配置企业微信Webhook
`src/main/resources/application.yml` 中配置您的企业微信Webhook地址
`src/main/resources/application.yml` 中配置您的群组信息
```yaml
wechat:
webhook:
url: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOUR_WEBHOOK_KEY
task:
reminder:
groups:
- id: "your-team"
name: "您的团队名称"
webhook:
url: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOUR_WEBHOOK_KEY"
task-system: "zentao" # 或 smartsheet, jira 等
schedules:
morning:
time: "0 0 9 * * MON-FRI"
message: "早上提醒消息"
evening:
time: "0 30 17 * * MON-FRI"
message: "晚上提醒消息"
enabled: true
```
### 3. 编译和运行
@ -66,39 +79,81 @@ java -jar target/task-reminder-1.0.0.jar
# 健康检查
curl http://localhost:8080/api/reminder/health
# 获取系统信息
curl http://localhost:8080/api/reminder/info
# 查看所有群组配置
curl http://localhost:8080/api/reminder/groups
# 发送测试消息
curl -X POST http://localhost:8080/api/reminder/test
# 手动触发早上提醒
# 手动触发所有群组早上提醒
curl -X POST http://localhost:8080/api/reminder/morning
# 手动触发晚上提醒
# 手动触发所有群组晚上提醒
curl -X POST http://localhost:8080/api/reminder/evening
# 获取提醒信息
curl http://localhost:8080/api/reminder/info
# 手动触发指定群组的提醒
curl -X POST http://localhost:8080/api/reminder/groups/{groupId}/{scheduleType}
# 重新加载配置
curl -X POST http://localhost:8080/api/reminder/reload
```
## 配置说明
### 时间配置
### 多群组配置
`application.yml` 中可以自定义提醒时间
系统支持配置多个群组,每个群组可以有不同的设置
```yaml
task:
reminder:
morning:
time: "0 0 9 * * MON-FRI" # Cron表达式工作日早上9点
message: "早上好!请及时更新您的任务状态,开始新的一天工作!"
evening:
time: "0 30 17 * * MON-FRI" # Cron表达式工作日下午5:30
message: "下班前提醒:请更新今日任务完成状态,为明天做好准备!"
groups:
# 禅道团队
- id: "zentao-team"
name: "禅道开发团队"
webhook:
url: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOUR_KEY_1"
task-system: "zentao"
schedules:
morning:
time: "0 0 9 * * MON-FRI" # 早上9点
message: "请及时登录禅道系统刷新任务状态"
evening:
time: "0 30 17 * * MON-FRI" # 下午5:30
message: "请更新今日任务完成状态"
enabled: true
# 智能表格团队
- id: "smartsheet-team"
name: "智能表格团队"
webhook:
url: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=YOUR_KEY_2"
task-system: "smartsheet"
schedules:
morning:
time: "0 50 8 * * MON-FRI" # 早上8:50
message: "请及时更新智能表格中的任务状态"
evening:
time: "0 20 17 * * MON-FRI" # 下午5:20
message: "请在智能表格中更新今日工作完成情况"
enabled: true
```
### 支持的任务管理系统
- `zentao` - 禅道
- `smartsheet` - 智能表格
- `jira` - Jira
- `trello` - Trello
- `asana` - Asana
- `notion` - Notion
### 节假日配置
系统内置了2024年和2025年的法定节假日可以在 `HolidayUtil.java` 中修改或添加自定义节假日。
系统内置了2025年的法定节假日可以在 `HolidayUtil.java` 中修改或添加自定义节假日。
## API文档

View File

@ -10,8 +10,8 @@
<version>1.0.0</version>
<packaging>jar</packaging>
<name>Zeodao Task Reminder</name>
<description>企业微信任务提醒系统</description>
<name>Multi-Group Task Reminder</name>
<description>多群企业微信任务提醒系统</description>
<parent>
<groupId>org.springframework.boot</groupId>

View File

@ -5,20 +5,20 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* Zeodao任务提醒系统主启动类
*
* 多群任务提醒系统主启动类
*
* @author Zeodao
* @version 1.0.0
* @version 2.0.0
*/
@SpringBootApplication
@EnableScheduling
public class ZeodaoTaskReminderApplication {
public class TaskReminderApplication {
public static void main(String[] args) {
SpringApplication.run(ZeodaoTaskReminderApplication.class, args);
SpringApplication.run(TaskReminderApplication.class, args);
System.out.println("=================================");
System.out.println("Zeodao任务提醒系统启动成功!");
System.out.println("系统将在工作日早上9:00和下午17:30发送任务提醒");
System.out.println("多群任务提醒系统启动成功!");
System.out.println("系统支持多个群组和多种任务管理系统");
System.out.println("=================================");
}
}

View File

@ -192,14 +192,11 @@ public class WechatWebhookService {
String systemIcon = getTaskSystemIcon(group.getTaskSystem());
message.append("## ").append(systemIcon).append(" ").append(systemName).append("任务状态提醒\n\n");
message.append("**⏰ 时间:** ").append(timestamp).append(" (").append(dayOfWeek).append(")\n");
message.append("**📝 提醒类型:** ").append(timeType).append("\n\n");
message.append("### 📢 重要提醒\n");
message.append(baseMessage).append("\n\n");
message.append("### 🔗 操作指引\n");
message.append("⏰ **时间:** ").append(timestamp).append(" (").append(dayOfWeek).append(")\n\n");
message.append("📢 ").append(baseMessage).append("\n\n");
message.append("🔗 **操作指引:**\n");
message.append(getTaskSystemInstructions(group.getTaskSystem()));
message.append("---\n");
message.append("💡 **温馨提示:** 及时更新任务状态有助于团队协作和项目管理");
message.append("💡 及时更新任务状态有助于团队协作和项目管理");
return message.toString();
}

View File

@ -13,7 +13,7 @@ import java.util.Set;
/**
* 节假日工具类
* 用于判断是否为节假日或周末
*
*
* @author Zeodao
* @version 1.0.0
*/
@ -22,54 +22,15 @@ public class HolidayUtil {
private static final Logger logger = LoggerFactory.getLogger(HolidayUtil.class);
// 2024年法定节假日可根据实际情况调整
private static final Set<LocalDate> HOLIDAYS_2024 = new HashSet<>();
// 2025年法定节假日可根据实际情况调整
private static final Set<LocalDate> HOLIDAYS_2025 = new HashSet<>();
static {
// 初始化2024年节假日
initHolidays2024();
// 初始化2025年节假日
initHolidays2025();
}
/**
* 初始化2024年节假日
*/
private static void initHolidays2024() {
// 元旦1月1日
HOLIDAYS_2024.add(LocalDate.of(2024, Month.JANUARY, 1));
// 春节2月10日-17日
for (int day = 10; day <= 17; day++) {
HOLIDAYS_2024.add(LocalDate.of(2024, Month.FEBRUARY, day));
}
// 清明节4月4日-6日
for (int day = 4; day <= 6; day++) {
HOLIDAYS_2024.add(LocalDate.of(2024, Month.APRIL, day));
}
// 劳动节5月1日-5日
for (int day = 1; day <= 5; day++) {
HOLIDAYS_2024.add(LocalDate.of(2024, Month.MAY, day));
}
// 端午节6月10日
HOLIDAYS_2024.add(LocalDate.of(2024, Month.JUNE, 10));
// 中秋节9月15日-17日
for (int day = 15; day <= 17; day++) {
HOLIDAYS_2024.add(LocalDate.of(2024, Month.SEPTEMBER, day));
}
// 国庆节10月1日-7日
for (int day = 1; day <= 7; day++) {
HOLIDAYS_2024.add(LocalDate.of(2024, Month.OCTOBER, day));
}
}
/**
* 初始化2025年节假日
@ -77,7 +38,7 @@ public class HolidayUtil {
private static void initHolidays2025() {
// 元旦1月1日
HOLIDAYS_2025.add(LocalDate.of(2025, Month.JANUARY, 1));
// 春节1月28日-2月3日预估实际以国务院公布为准
HOLIDAYS_2025.add(LocalDate.of(2025, Month.JANUARY, 28));
HOLIDAYS_2025.add(LocalDate.of(2025, Month.JANUARY, 29));
@ -86,25 +47,25 @@ public class HolidayUtil {
HOLIDAYS_2025.add(LocalDate.of(2025, Month.FEBRUARY, 1));
HOLIDAYS_2025.add(LocalDate.of(2025, Month.FEBRUARY, 2));
HOLIDAYS_2025.add(LocalDate.of(2025, Month.FEBRUARY, 3));
// 清明节4月5日-7日预估
for (int day = 5; day <= 7; day++) {
HOLIDAYS_2025.add(LocalDate.of(2025, Month.APRIL, day));
}
// 劳动节5月1日-5日预估
for (int day = 1; day <= 5; day++) {
HOLIDAYS_2025.add(LocalDate.of(2025, Month.MAY, day));
}
// 端午节5月31日-6月2日预估
HOLIDAYS_2025.add(LocalDate.of(2025, Month.MAY, 31));
HOLIDAYS_2025.add(LocalDate.of(2025, Month.JUNE, 1));
HOLIDAYS_2025.add(LocalDate.of(2025, Month.JUNE, 2));
// 中秋节10月6日预估
HOLIDAYS_2025.add(LocalDate.of(2025, Month.OCTOBER, 6));
// 国庆节10月1日-7日
for (int day = 1; day <= 7; day++) {
HOLIDAYS_2025.add(LocalDate.of(2025, Month.OCTOBER, day));
@ -113,35 +74,32 @@ public class HolidayUtil {
/**
* 判断指定日期是否为周末
*
*
* @param date 日期
* @return 是否为周末
*/
public boolean isWeekend(LocalDate date) {
DayOfWeek dayOfWeek = date.getDayOfWeek();
boolean isWeekend = dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY;
if (isWeekend) {
logger.debug("日期 {} 是周末", date);
}
return isWeekend;
}
/**
* 判断指定日期是否为法定节假日
*
*
* @param date 日期
* @return 是否为节假日
*/
public boolean isHoliday(LocalDate date) {
boolean isHoliday = false;
int year = date.getYear();
switch (year) {
case 2024:
isHoliday = HOLIDAYS_2024.contains(date);
break;
case 2025:
isHoliday = HOLIDAYS_2025.contains(date);
break;
@ -150,17 +108,17 @@ public class HolidayUtil {
logger.warn("未配置年份 {} 的节假日信息,默认不是节假日", year);
break;
}
if (isHoliday) {
logger.debug("日期 {} 是法定节假日", date);
}
return isHoliday;
}
/**
* 判断指定日期是否为工作日
*
*
* @param date 日期
* @return 是否为工作日
*/
@ -170,7 +128,7 @@ public class HolidayUtil {
/**
* 获取下一个工作日
*
*
* @param date 起始日期
* @return 下一个工作日
*/
@ -184,15 +142,12 @@ public class HolidayUtil {
/**
* 添加自定义节假日
*
*
* @param date 节假日日期
*/
public void addCustomHoliday(LocalDate date) {
int year = date.getYear();
switch (year) {
case 2024:
HOLIDAYS_2024.add(date);
break;
case 2025:
HOLIDAYS_2025.add(date);
break;

View File

@ -37,10 +37,10 @@ task:
task-system: "smartsheet"
schedules:
morning:
time: "0 0 8 * * MON-FRI" # 工作日早上8点
time: "0 50 8 * * MON-FRI" # 工作日早上8点50分
message: "早上好!请大家及时更新智能表格中的任务状态,确保项目进度信息准确无误。"
evening:
time: "0 0 18 * * MON-FRI" # 工作日下午6点
time: "0 20 17 * * MON-FRI" # 工作日下午5点20分
message: "下班前提醒:请在智能表格中更新今日工作完成情况,为明天做好准备!"
enabled: true