wlzboy
2025-10-18 b46065a201c09ce69f111806f2bda4a5f476bc4e
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
package com.ruoyi.web.controller.system;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.DepartmentSyncDTO;
import com.ruoyi.system.domain.UserSyncDTO;
import com.ruoyi.system.service.IDepartmentSyncService;
import com.ruoyi.system.service.IUserSyncService;
 
import java.util.List;
 
/**
 * 部门和用户同步Controller
 * 
 * @author ruoyi
 * @date 2025-10-18
 */
@RestController
@RequestMapping("/system/dept/sync")
public class DepartmentSyncController extends BaseController
{
    @Autowired
    private IDepartmentSyncService departmentSyncService;
 
    @Autowired
    private IUserSyncService userSyncService;
 
 
    
    /**
     * 同步分公司和部门数据(使用外部传入的数据源)
     * 
     * 适用场景:
     * 1. 已从其他来源获取了部门数据
     * 2. 需要对数据进行预处理后再同步
     * 3. 批量同步多个数据源
     * 
     * @param branchDepts 分公司数据列表
     * @return 同步结果
     */
    @PreAuthorize("@ss.hasPermi('system:dept:sync')")
    @PostMapping("/branch/data")
    public AjaxResult syncBranchDepartmentsWithData(@RequestBody List<DepartmentSyncDTO> branchDepts)
    {
        return departmentSyncService.syncBranchDepartments(branchDepts);
    }
    
    /**
     * 同步转运部和子部门数据(使用外部传入的数据源)
     * 
     * 同步逻辑:
     * 1. 确保总公司(ID=101)下存在"转运部"
     * 2. 创建转运部的子部门
     * 
     * @param transportDepts 转运部子部门数据列表
     * @return 同步结果
     */
    @PreAuthorize("@ss.hasPermi('system:dept:sync')")
    @PostMapping("/transport/data")
    public AjaxResult syncTransportDepartmentsWithData(@RequestBody List<DepartmentSyncDTO> transportDepts)
    {
        return departmentSyncService.syncTransportDepartments(transportDepts);
    }
 
 
    
    /**
     * 同步OA用户数据(使用外部传入的数据源)
     * 
     * 适用场景:
     * 1. 已从其他来源获取了用户数据
     * 2. 需要对数据进行预处理后再同步
     * 3. 批量同步多个数据源
     * 
     * @param oaUsers OA用户数据列表
     * @return 同步结果
     */
    @PreAuthorize("@ss.hasPermi('system:user:sync')")
    @PostMapping("/user/data")
    public AjaxResult syncOaUsersWithData(@RequestBody List<UserSyncDTO> oaUsers)
    {
        return userSyncService.syncOaUsers(oaUsers);
    }
}