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 getBranchDepartments() { try { log.info("开始从 SQL Server 查询分公司数据..."); // 调用 Mapper 查询 SQL Server 数据 // @DataSource 注解会自动切换数据源 List 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 getTransportDepartments() { try { log.info("开始从 SQL Server 查询转运部子部门数据..."); // 调用 Mapper 查询 SQL Server 数据 // @DataSource 注解会自动切换数据源 List 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); } } }