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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.ruoyi.system.service.impl;
 
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.domain.DepartmentSyncDTO;
import com.ruoyi.system.mapper.DepartmentSyncMapper;
import com.ruoyi.system.service.IDepartmentSyncDataService;
 
import java.util.List;
 
/**
 * SQL Server 部门数据查询服务实现
 * 
 * 职责:专门负责从 SQL Server 查询部门数据
 * 
 * 数据流向:SQL Server → 返回 DTO 列表
 * 
 * @author ruoyi
 * @date 2025-10-18
 */
@Service
@DataSource(DataSourceType.SQLSERVER)
public class DepartmentSyncDataServiceImpl implements IDepartmentSyncDataService
{
    private static final Logger log = LoggerFactory.getLogger(DepartmentSyncDataServiceImpl.class);
 
    @Autowired
    private DepartmentSyncMapper departmentSyncMapper;
 
    /**
     * 从 SQL Server 查询合作单位下的所有分公司数据
     * 
     * 注意:DepartmentSyncMapper 上有 @DataSource(DataSourceType.SQLSERVER) 注解
     * 此方法会自动切换到 SQL Server 数据源执行查询
     * 
     * @return 分公司列表
     */
    @Override
    public List<DepartmentSyncDTO> getBranchDepartments()
    {
        try
        {
            log.info("开始从 SQL Server 查询分公司数据...");
            
            // 调用 Mapper 查询 SQL Server 数据
            // @DataSource 注解会自动切换数据源
            List<DepartmentSyncDTO> branchDepts = departmentSyncMapper.selectBranchDepartments();
            
            if (branchDepts == null || branchDepts.isEmpty())
            {
                log.warn("未从 SQL Server 查询到分公司数据");
                return branchDepts;
            }
            
            log.info("从 SQL Server 查询到 {} 条分公司数据", branchDepts.size());
            return branchDepts;
        }
        catch (Exception e)
        {
            log.error("从 SQL Server 查询分公司数据失败", e);
            throw new RuntimeException("查询 SQL Server 数据失败: " + e.getMessage(), e);
        }
    }
    
    /**
     * 从 SQL Server 查询转运部下的所有子部门数据
     * 
     * 注意:DepartmentSyncMapper 上有 @DataSource(DataSourceType.SQLSERVER) 注解
     * 此方法会自动切换到 SQL Server 数据源执行查询
     * 
     * @return 转运部子部门列表
     */
    @Override
    public List<DepartmentSyncDTO> getTransportDepartments()
    {
        try
        {
            log.info("开始从 SQL Server 查询转运部子部门数据...");
            
            // 调用 Mapper 查询 SQL Server 数据
            // @DataSource 注解会自动切换数据源
            List<DepartmentSyncDTO> transportDepts = departmentSyncMapper.selectTransportDepartments();
            
            if (transportDepts == null || transportDepts.isEmpty())
            {
                log.warn("未从 SQL Server 查询到转运部子部门数据");
                return transportDepts;
            }
            
            log.info("从 SQL Server 查询到 {} 条转运部子部门数据", transportDepts.size());
            return transportDepts;
        }
        catch (Exception e)
        {
            log.error("从 SQL Server 查询转运部子部门数据失败", e);
            throw new RuntimeException("查询 SQL Server 数据失败: " + e.getMessage(), e);
        }
    }
}