task-reminder/src/main/java/com/zeodao/reminder/config/TaskReminderConfig.java
2025-05-30 13:06:45 +08:00

258 lines
5.6 KiB
Java

package com.zeodao.reminder.config;
import com.zeodao.reminder.enums.TaskSystemType;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 多群任务提醒配置类
*
* @author Zeodao
* @version 2.0.0
*/
@Configuration
@ConfigurationProperties(prefix = "task.reminder")
public class TaskReminderConfig {
private Global global = new Global();
private List<Group> groups = new ArrayList<>();
public Global getGlobal() {
return global;
}
public void setGlobal(Global global) {
this.global = global;
}
public List<Group> getGroups() {
return groups;
}
public void setGroups(List<Group> groups) {
this.groups = groups;
}
/**
* 根据群组ID获取群组配置
*/
public Group getGroupById(String groupId) {
return groups.stream()
.filter(group -> group.getId().equals(groupId))
.findFirst()
.orElse(null);
}
public static class Global {
private int timeout = 5000;
public int getTimeout() {
return timeout;
}
public void setTimeout(int timeout) {
this.timeout = timeout;
}
}
public static class Group {
private String id;
private String name;
private Webhook webhook = new Webhook();
private TaskSystemType taskSystem;
private Map<String, Schedule> schedules = new HashMap<>();
private Zentao zentao = new Zentao();
private Map<String, String> userMapping = new HashMap<>();
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Webhook getWebhook() {
return webhook;
}
public void setWebhook(Webhook webhook) {
this.webhook = webhook;
}
public TaskSystemType getTaskSystem() {
return taskSystem;
}
public void setTaskSystem(TaskSystemType taskSystem) {
this.taskSystem = taskSystem;
}
/**
* 设置任务系统类型(字符串版本,用于配置文件兼容)
*/
public void setTaskSystem(String taskSystemCode) {
this.taskSystem = TaskSystemType.fromCode(taskSystemCode);
}
/**
* 获取任务系统代码(字符串版本,用于向后兼容)
*/
public String getTaskSystemCode() {
return taskSystem != null ? taskSystem.getCode() : null;
}
public Map<String, Schedule> getSchedules() {
return schedules;
}
public void setSchedules(Map<String, Schedule> schedules) {
this.schedules = schedules;
}
public Zentao getZentao() {
return zentao;
}
public void setZentao(Zentao zentao) {
this.zentao = zentao;
}
public Map<String, String> getUserMapping() {
return userMapping;
}
public void setUserMapping(Map<String, String> userMapping) {
this.userMapping = userMapping;
}
}
public static class Webhook {
private String url;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
public static class Schedule {
private String time;
private String message;
private boolean enabled = true; // 默认启用
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}
public static class Zentao {
private String apiUrl;
private String token;
private String username;
private String password;
private Integer projectId;
private Integer kanbanId;
public String getApiUrl() {
return apiUrl;
}
public void setApiUrl(String apiUrl) {
this.apiUrl = apiUrl;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Integer getProjectId() {
return projectId;
}
public void setProjectId(Integer projectId) {
this.projectId = projectId;
}
public Integer getKanbanId() {
return kanbanId;
}
public void setKanbanId(Integer kanbanId) {
this.kanbanId = kanbanId;
}
}
}