added: 定时同步LDAP

This commit is contained in:
xxx 2023-11-14 13:50:33 +08:00
parent 3c9b354aea
commit be6264dcd3
2 changed files with 63 additions and 0 deletions

View File

@ -20,6 +20,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import xyz.playedu.common.config.UniqueNameGeneratorConfig;
@ -27,6 +28,7 @@ import xyz.playedu.common.config.UniqueNameGeneratorConfig;
@SpringBootApplication
@EnableAsync
@EnableTransactionManagement
@EnableScheduling
@ComponentScan(
basePackages = {"xyz.playedu"},
nameGenerator = UniqueNameGeneratorConfig.class)

View File

@ -0,0 +1,61 @@
/*
* Copyright (C) 2023 杭州白书科技有限公司
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package xyz.playedu.api.schedule;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import xyz.playedu.common.bus.LDAPBus;
@Component
@Slf4j
public class LDAPSchedule {
@Autowired private LDAPBus ldapBus;
private int times;
@Scheduled(fixedRate = 3600000)
public void sync() {
if (!ldapBus.enabledLDAP()) {
log.info("未配置LDAP服务");
return;
}
// 系统刚启动不执行
if (times == 0) {
times++;
return;
}
try {
ldapBus.departmentSync();
} catch (Exception e) {
log.error("LDAP-部门同步失败", e);
}
try {
ldapBus.userSync();
} catch (Exception e) {
log.error("LDAP-学员同步失败", e);
}
log.info("LDAP同步成功");
}
}