fix: 邮箱与手机号占位时符合该资源格式,将定时任务的配置可配置化 (#131)

This commit is contained in:
二丫讲梵 2022-12-05 21:04:12 +08:00 committed by GitHub
parent f28a3909fd
commit 25073126aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 38 deletions

View File

@ -114,8 +114,6 @@
## 💎 优秀软件推荐
- [🦄 ConsulManager高效易用的Consul Web运维平台](https://github.com/starsliao/ConsulManager)
- [🦚 Yearning — MYSQL 开源SQL语句审核平台](https://github.com/cookieY/Yearning)
- [🦅 Spug - 开源轻量自动化运维平台](https://github.com/openspug/spug)
## 🤝 贡献者

View File

@ -109,6 +109,8 @@ dingtalk:
app-secret: "xxxxxxxxxxxxxxxxxxxxxxxxxxxx" # 应用的secret
agent-id: "12121212" # 目前agent-id未使用到可忽略
enable-sync: false # 是否开启定时同步钉钉的任务
dept-sync-time: "0 30 2 * * *" # 部门同步任务的时间点 * * * * * * 秒 分 时 日 月 周, 请把时间设置在凌晨 1 ~ 5 点
user-sync-time: "0 30 3 * * *" # 用户同步任务的时间点 * * * * * * 秒 分 时 日 月 周, 请把时间设置在凌晨 1 ~ 5 点,注意请把用户同步的任务滞后于部门同步时间,比如部门为2点,则用户为3点
wecom:
# 配置获取详细文档参考http://ldapdoc.eryajf.net/pages/cf1698/
flag: "wecom" # 作为微信在平台的标识
@ -116,9 +118,13 @@ wecom:
agent-id: 1000003 # 企业微信中创建的应用ID
corp-secret: "xxxxx" # 企业微信中创建的应用secret
enable-sync: false # 是否开启定时同步企业微信的任务
dept-sync-time: "0 30 2 * * *" # 部门同步任务的时间点 * * * * * * 秒 分 时 日 月 周, 请把时间设置在凌晨 1 ~ 5 点
user-sync-time: "0 30 3 * * *" # 用户同步任务的时间点 * * * * * * 秒 分 时 日 月 周, 请把时间设置在凌晨 1 ~ 5 点,注意请把用户同步的任务滞后于部门同步时间,比如部门为2点,则用户为3点
feishu:
# 配置获取详细文档参考http://ldapdoc.eryajf.net/pages/83c90b/
flag: "feishu" # 作为飞书在平台的标识
app-id: "xxxxxxx" # 飞书的app-id
app-secret: "xxxxxxxxxxx" # 飞书的app-secret
enable-sync: false # 是否开启定时同步飞书的任务
dept-sync-time: "0 30 2 * * *" # 部门同步任务的时间点 * * * * * * 秒 分 时 日 月 周, 请把时间设置在凌晨 1 ~ 5 点
user-sync-time: "0 30 3 * * *" # 用户同步任务的时间点 * * * * * * 秒 分 时 日 月 周, 请把时间设置在凌晨 1 ~ 5 点,注意请把用户同步的任务滞后于部门同步时间,比如部门为2点,则用户为3点

View File

@ -153,25 +153,31 @@ type EmailConfig struct {
}
type DingTalkConfig struct {
AppKey string `mapstructure:"app-key" json:"appKey"`
AppSecret string `mapstructure:"app-secret" json:"appSecret"`
AgentId string `mapstructure:"agent-id" json:"agentId"`
RootOuName string `mapstructure:"root-ou-name" json:"rootOuName"`
Flag string `mapstructure:"flag" json:"flag"`
EnableSync bool `mapstructure:"enable-sync" json:"enableSync"`
AppKey string `mapstructure:"app-key" json:"appKey"`
AppSecret string `mapstructure:"app-secret" json:"appSecret"`
AgentId string `mapstructure:"agent-id" json:"agentId"`
RootOuName string `mapstructure:"root-ou-name" json:"rootOuName"`
Flag string `mapstructure:"flag" json:"flag"`
EnableSync bool `mapstructure:"enable-sync" json:"enableSync"`
DeptSyncTime string `mapstructure:"dept-sync-time" json:"deptSyncTime"`
UserSyncTime string `mapstructure:"user-sync-time" json:"userSyncTime"`
}
type WeComConfig struct {
Flag string `mapstructure:"flag" json:"flag"`
CorpID string `mapstructure:"corp-id" json:"corpId"`
AgentID int `mapstructure:"agent-id" json:"agentId"`
CorpSecret string `mapstructure:"corp-secret" json:"corpSecret"`
EnableSync bool `mapstructure:"enable-sync" json:"enableSync"`
Flag string `mapstructure:"flag" json:"flag"`
CorpID string `mapstructure:"corp-id" json:"corpId"`
AgentID int `mapstructure:"agent-id" json:"agentId"`
CorpSecret string `mapstructure:"corp-secret" json:"corpSecret"`
EnableSync bool `mapstructure:"enable-sync" json:"enableSync"`
DeptSyncTime string `mapstructure:"dept-sync-time" json:"deptSyncTime"`
UserSyncTime string `mapstructure:"user-sync-time" json:"userSyncTime"`
}
type FeiShuConfig struct {
Flag string `mapstructure:"flag" json:"flag"`
AppID string `mapstructure:"app-id" json:"appId"`
AppSecret string `mapstructure:"app-secret" json:"appSecret"`
EnableSync bool `mapstructure:"enable-sync" json:"enableSync"`
Flag string `mapstructure:"flag" json:"flag"`
AppID string `mapstructure:"app-id" json:"appId"`
AppSecret string `mapstructure:"app-secret" json:"appSecret"`
EnableSync bool `mapstructure:"enable-sync" json:"enableSync"`
DeptSyncTime string `mapstructure:"dept-sync-time" json:"deptSyncTime"`
UserSyncTime string `mapstructure:"user-sync-time" json:"userSyncTime"`
}

View File

@ -76,7 +76,7 @@ services:
WAIT_HOSTS: mysql:3306, openldap:389
ports:
- 8888:8888
# volumes: # 可按需打开此配置,将配置文件挂载到本地 可在服务运行之后,执行 docker cp go-ldap-admin-server:/app/config.yml ./config 然后再取消行注释
# volumes: # 可按需打开此配置,将配置文件挂载到本地 可在服务运行之后,执行 docker cp go-ldap-admin-server:/app/config.yml ./config 然后再取消行注释
# - ./config/config.yml:/app/config.yml
depends_on:
- mysql

View File

@ -93,22 +93,22 @@ func CommonAddUser(user *model.User, groups []*model.Group) error {
user.Introduction = user.Nickname
}
if user.Mail == "" {
user.Mail = "该用户邮箱为空"
user.Mail = "noone@eryajf.net"
}
if user.JobNumber == "" {
user.JobNumber = "该用户工号为空"
user.JobNumber = "0000"
}
if user.Departments == "" {
user.Departments = "默认:研发中心"
}
if user.Position == "" {
user.Position = "默认:技术"
user.Position = "默认:打工人"
}
if user.PostalAddress == "" {
user.PostalAddress = "默认:地球"
}
if user.Mobile == "" {
user.Mobile = "emptyMobile"
user.Mobile = "18888888888"
}
// 先将用户添加到MySQL
@ -320,16 +320,14 @@ func InitCron() {
if config.Conf.DingTalk.EnableSync {
//启动定时任务
_, err := c.AddFunc("0 1 5 * * *", func() {
common.Log.Info("每天凌晨5点1分0秒执行一次同步钉钉部门信息到ldap")
_, err := c.AddFunc(config.Conf.DingTalk.DeptSyncTime, func() {
DingTalk.SyncDingTalkDepts(nil, nil)
})
if err != nil {
common.Log.Errorf("启动同步部门的定时任务失败: %v", err)
}
//每天凌晨1点执行一次
_, err = c.AddFunc("0 30 5 * * *", func() {
common.Log.Info("每天凌晨5点30分执行一次同步钉钉用户信息到ldap")
_, err = c.AddFunc(config.Conf.DingTalk.UserSyncTime, func() {
DingTalk.SyncDingTalkUsers(nil, nil)
})
if err != nil {
@ -337,16 +335,14 @@ func InitCron() {
}
}
if config.Conf.WeCom.EnableSync {
_, err := c.AddFunc("0 1 5 * * *", func() {
common.Log.Info("每天凌晨5点1分0秒执行一次同步企业微信部门信息到ldap")
_, err := c.AddFunc(config.Conf.WeCom.DeptSyncTime, func() {
WeCom.SyncWeComDepts(nil, nil)
})
if err != nil {
common.Log.Errorf("启动同步部门的定时任务失败: %v", err)
}
//每天凌晨1点执行一次
_, err = c.AddFunc("0 30 5 * * *", func() {
common.Log.Info("每天凌晨5点30分执行一次同步企业微信用户信息到ldap")
_, err = c.AddFunc(config.Conf.WeCom.UserSyncTime, func() {
WeCom.SyncWeComUsers(nil, nil)
})
if err != nil {
@ -354,16 +350,14 @@ func InitCron() {
}
}
if config.Conf.FeiShu.EnableSync {
_, err := c.AddFunc("0 1 5 * * *", func() {
common.Log.Info("每天凌晨5点1分0秒执行一次同步飞书部门信息到ldap")
_, err := c.AddFunc(config.Conf.FeiShu.DeptSyncTime, func() {
FeiShu.SyncFeiShuDepts(nil, nil)
})
if err != nil {
common.Log.Errorf("启动同步部门的定时任务失败: %v", err)
}
//每天凌晨1点执行一次
_, err = c.AddFunc("0 30 5 * * *", func() {
common.Log.Info("每天凌晨5点30分执行一次同步飞书用户信息到ldap")
_, err = c.AddFunc(config.Conf.FeiShu.UserSyncTime, func() {
FeiShu.SyncFeiShuUsers(nil, nil)
})
if err != nil {

View File

@ -235,9 +235,9 @@ func InitData() {
JobNumber: "0000",
Mobile: "18888888888",
Avatar: "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
PostalAddress: "中国河南省南阳市",
Departments: "运维部",
Position: "系统管理员",
PostalAddress: "地球",
Departments: "研发中心",
Position: "打工人",
Introduction: "最强后台的管理员",
Status: 1,
Creator: "系统",