wlzboy
2025-10-26 2c86a8bd60deed0dd0e044bad6fb83f75d19a332
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package com.ruoyi.quartz.task;
 
import com.ruoyi.system.domain.DepartmentSyncDTO;
import com.ruoyi.system.domain.OrderClassDTO;
import com.ruoyi.system.service.IDepartmentSyncDataService;
import com.ruoyi.system.service.IOrderClassDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.service.IDepartmentSyncService;
 
import java.util.List;
 
/**
 * 部门同步定时任务
 * 
 * @author ruoyi
 * @date 2025-10-18
 */
@Component("departmentSyncTask")
public class DepartmentSyncTask
{
    private static final Logger log = LoggerFactory.getLogger(DepartmentSyncTask.class);
 
    @Autowired
    private IDepartmentSyncDataService departmentSyncDataService;
 
    @Autowired
    private IDepartmentSyncService departmentSyncService;
 
    private List<DepartmentSyncDTO> getDepartment(){
        return departmentSyncDataService.getBranchDepartments();
    }
 
    private List<DepartmentSyncDTO> getTransportDept(){
        return departmentSyncDataService.getTransportDepartments();
    }
    @Autowired
    private IOrderClassDataService orderClassDataService;
private List<OrderClassDTO> getServiceOrdCode() {
    return orderClassDataService.getServiceOrderClass();
}
private List<OrderClassDTO> getDispatchOrdCode() {
    return orderClassDataService.getDispatchOrderClass();
}
 
    /**
     * 同步分公司和部门数据
     * 
     * 使用示例:
     * - 任务名称:分公司同步
     * - 调用目标:departmentSyncTask.syncDepartments
     * - cron表达式:0 0 2 * * ?(每天凌晨2点执行)
     */
    public void syncDepartments()
    {
        try
        {
            log.info("==========开始执行部门同步定时任务==========");
            
            AjaxResult result = departmentSyncService.syncBranchDepartments(this.getDepartment(), this.getServiceOrdCode(),this.getDispatchOrdCode());
 
            departmentSyncService.syncTransportDepartments(this.getTransportDept());
            
            if (result.get("code").equals(200))
            {
                log.info("部门同步成功: {}", result.get("msg"));
            }
            else
            {
                log.error("部门同步失败: {}", result.get("msg"));
            }
            
            log.info("==========部门同步定时任务执行完成==========");
        }
        catch (Exception e)
        {
            log.error("部门同步定时任务执行异常", e);
        }
    }
 
    /**
     * 同步分公司和部门数据(带参数)
     * 
     * @param params 参数(预留,暂未使用)
     */
    public void syncDepartments(String params)
    {
        log.info("部门同步任务参数: {}", params);
        syncDepartments();
    }
}