新增定时获取组织修改的 job 调度
This commit is contained in:
@@ -0,0 +1,40 @@
|
|||||||
|
package com.zt.plat.module.system.job.sync;
|
||||||
|
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import com.zt.plat.framework.tenant.core.job.TenantJob;
|
||||||
|
import com.zt.plat.module.system.service.sync.SyncIWorkOrgChangeService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于定时同步 iWork 当日变更的组织数据
|
||||||
|
* 同步时间:每日23:00
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class SyncIWorkOrgChangeJob {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SyncIWorkOrgChangeService syncIWorkOrgChangeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行定时任务
|
||||||
|
* 配置执行频率:每日23:00时执行一次
|
||||||
|
* cron表达式:0 0 23 * * ?
|
||||||
|
*/
|
||||||
|
@XxlJob("syncIWorkOrgChangeJob")
|
||||||
|
@TenantJob
|
||||||
|
public void execute() {
|
||||||
|
log.info("[syncIWorkOrgChangeJob][开始执行同步 iWork 当日变更组织任务]");
|
||||||
|
try {
|
||||||
|
int processedCount = syncIWorkOrgChangeService.process();
|
||||||
|
if (processedCount > 0) {
|
||||||
|
log.info("[syncIWorkOrgChangeJob][同步任务执行完成,处理了 {} 条记录]", processedCount);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("[syncIWorkOrgChangeJob][同步任务执行失败]", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.zt.plat.module.system.service.sync;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时同步 iWork 组织变更服务
|
||||||
|
*/
|
||||||
|
public interface SyncIWorkOrgChangeService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 执行同步
|
||||||
|
* @return 拉取记录数量
|
||||||
|
*/
|
||||||
|
int process();
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.zt.plat.module.system.service.sync;
|
||||||
|
|
||||||
|
import com.zt.plat.module.system.controller.admin.integration.iwork.vo.IWorkFullSyncReqVO;
|
||||||
|
import com.zt.plat.module.system.controller.admin.integration.iwork.vo.IWorkFullSyncRespVO;
|
||||||
|
import com.zt.plat.module.system.service.integration.iwork.IWorkSyncService;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SyncIWorkOrgChangeServiceImpl implements SyncIWorkOrgChangeService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IWorkSyncService iWorkSyncService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int process() {
|
||||||
|
IWorkFullSyncReqVO reqVO = new IWorkFullSyncReqVO();
|
||||||
|
reqVO.setPageSize(10);
|
||||||
|
ZoneId zone = ZoneId.of("Asia/Shanghai");
|
||||||
|
String startOfToday = LocalDate.now(zone)
|
||||||
|
.atStartOfDay(zone)
|
||||||
|
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||||
|
reqVO.setModified(startOfToday);
|
||||||
|
IWorkFullSyncRespVO subcompanyResp = iWorkSyncService.fullSyncSubcompanies(reqVO);
|
||||||
|
IWorkFullSyncRespVO departmentResp = iWorkSyncService.fullSyncDepartments(reqVO);
|
||||||
|
return countPulled(subcompanyResp) + countPulled(departmentResp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int countPulled(IWorkFullSyncRespVO respVO) {
|
||||||
|
if (respVO == null || respVO.getBatches() == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return respVO.getBatches().stream()
|
||||||
|
.mapToInt(batch -> batch.getPulled() == null ? 0 : batch.getPulled())
|
||||||
|
.sum();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user