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

View File

@ -159,6 +159,8 @@ type DingTalkConfig struct {
RootOuName string `mapstructure:"root-ou-name" json:"rootOuName"` RootOuName string `mapstructure:"root-ou-name" json:"rootOuName"`
Flag string `mapstructure:"flag" json:"flag"` Flag string `mapstructure:"flag" json:"flag"`
EnableSync bool `mapstructure:"enable-sync" json:"enableSync"` 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 { type WeComConfig struct {
@ -167,6 +169,8 @@ type WeComConfig struct {
AgentID int `mapstructure:"agent-id" json:"agentId"` AgentID int `mapstructure:"agent-id" json:"agentId"`
CorpSecret string `mapstructure:"corp-secret" json:"corpSecret"` CorpSecret string `mapstructure:"corp-secret" json:"corpSecret"`
EnableSync bool `mapstructure:"enable-sync" json:"enableSync"` 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 { type FeiShuConfig struct {
@ -174,4 +178,6 @@ type FeiShuConfig struct {
AppID string `mapstructure:"app-id" json:"appId"` AppID string `mapstructure:"app-id" json:"appId"`
AppSecret string `mapstructure:"app-secret" json:"appSecret"` AppSecret string `mapstructure:"app-secret" json:"appSecret"`
EnableSync bool `mapstructure:"enable-sync" json:"enableSync"` 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 WAIT_HOSTS: mysql:3306, openldap:389
ports: ports:
- 8888:8888 - 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 # - ./config/config.yml:/app/config.yml
depends_on: depends_on:
- mysql - mysql

View File

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

View File

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