diff --git a/README.md b/README.md index 0ef60cd..e1cf807 100644 --- a/README.md +++ b/README.md @@ -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) ## 🤝 贡献者 diff --git a/config.yml b/config.yml index c1e5ca6..0a73930 100644 --- a/config.yml +++ b/config.yml @@ -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 # 是否开启定时同步飞书的任务 \ No newline at end of file + enable-sync: false # 是否开启定时同步飞书的任务 + dept-sync-time: "0 30 2 * * *" # 部门同步任务的时间点 * * * * * * 秒 分 时 日 月 周, 请把时间设置在凌晨 1 ~ 5 点 + user-sync-time: "0 30 3 * * *" # 用户同步任务的时间点 * * * * * * 秒 分 时 日 月 周, 请把时间设置在凌晨 1 ~ 5 点,注意请把用户同步的任务滞后于部门同步时间,比如部门为2点,则用户为3点 \ No newline at end of file diff --git a/config/config.go b/config/config.go index bbe7c91..8ac3eb7 100644 --- a/config/config.go +++ b/config/config.go @@ -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"` } diff --git a/docs/docker-compose/docker-compose.yaml b/docs/docker-compose/docker-compose.yaml index dd57f3a..ef401f2 100644 --- a/docs/docker-compose/docker-compose.yaml +++ b/docs/docker-compose/docker-compose.yaml @@ -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 diff --git a/logic/a_logic.go b/logic/a_logic.go index 8b4e155..c222a99 100644 --- a/logic/a_logic.go +++ b/logic/a_logic.go @@ -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 { diff --git a/public/common/init_mysql_data.go b/public/common/init_mysql_data.go index d1b1b5a..a6f587e 100644 --- a/public/common/init_mysql_data.go +++ b/public/common/init_mysql_data.go @@ -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: "系统",