mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-28 16:22:45 +08:00
added: 定时同步LDAP
This commit is contained in:
parent
3c9b354aea
commit
be6264dcd3
@ -20,6 +20,7 @@ import org.springframework.boot.SpringApplication;
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
import xyz.playedu.common.config.UniqueNameGeneratorConfig;
|
import xyz.playedu.common.config.UniqueNameGeneratorConfig;
|
||||||
@ -27,6 +28,7 @@ import xyz.playedu.common.config.UniqueNameGeneratorConfig;
|
|||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableAsync
|
@EnableAsync
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
|
@EnableScheduling
|
||||||
@ComponentScan(
|
@ComponentScan(
|
||||||
basePackages = {"xyz.playedu"},
|
basePackages = {"xyz.playedu"},
|
||||||
nameGenerator = UniqueNameGeneratorConfig.class)
|
nameGenerator = UniqueNameGeneratorConfig.class)
|
||||||
|
@ -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同步成功");
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user