wangmiaomiao 11 luni în urmă
părinte
comite
ee40a2848b

+ 7 - 0
slibra-admin/pom.xml

@@ -88,6 +88,13 @@
             <version>0.7.5</version>
         </dependency>
 
+        <!-- SQL Server Driver -->
+        <dependency>
+            <groupId>com.microsoft.sqlserver</groupId>
+            <artifactId>mssql-jdbc</artifactId>
+            <scope>runtime</scope>
+        </dependency>
+
 
 
 

+ 2 - 2
slibra-admin/src/main/resources/application-local.yml

@@ -12,9 +12,9 @@ spring:
             # 从库数据源
             slave:
                 # 从数据源开关/默认关闭
-                enabled: false
+                enabled: true
                 driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
-                url: jdbc:sqlserver://10.0.3.53:1433;SelectMethod=Cursor;DatabaseName=信义;
+                url: jdbc:sqlserver://10.0.3.53:1433;SelectMethod=Cursor;DatabaseName=信义
                 username: hongshan
                 password: hongshan
             # 初始连接数

+ 29 - 0
slibra-admin/src/test/java/com/slibra/MyTest.java

@@ -3,12 +3,18 @@ package com.slibra;
 import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.github.pagehelper.PageHelper;
+import com.slibra.business.domain.TXinyiRobot;
+import com.slibra.business.mapper.TXinyiRobotMapper;
 import com.slibra.common.config.ApplicationProperties;
 import com.slibra.common.core.domain.entity.SysDept;
+import com.slibra.common.core.domain.entity.SysUser;
+import com.slibra.common.enums.DataSourceType;
 import com.slibra.common.utils.third.AliSMSUtil;
 import com.slibra.common.utils.third.NumUtil;
 import com.slibra.common.utils.third.StringUtil;
+import com.slibra.framework.datasource.DynamicDataSourceContextHolder;
 import com.slibra.system.mapper.SysDeptMapper;
+import com.slibra.system.mapper.SysUserMapper;
 import com.wechat.pay.java.service.payments.nativepay.NativePayService;
 import com.wechat.pay.java.service.payments.nativepay.model.Amount;
 import com.wechat.pay.java.service.payments.nativepay.model.PrepayRequest;
@@ -40,6 +46,12 @@ public class MyTest {
     @Resource
     private NativePayService nativePayService;
 
+    @Autowired
+    private SysUserMapper userMapper;
+
+    @Autowired
+    private TXinyiRobotMapper xinyiRobotMapper;
+
     @Test
     void contextLoads() {
     }
@@ -105,4 +117,21 @@ public class MyTest {
     }
 
 
+    @Test
+    public void testMultilyDataTwo(){
+        //从
+        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE.name());
+        List<TXinyiRobot> tXinyiRobots = xinyiRobotMapper.selectTXinyiRobotList(null);
+        DynamicDataSourceContextHolder.clearDataSourceType();
+        System.out.println(JSON.toJSONString(tXinyiRobots.get(0)));
+        System.out.println("-------------");
+        //主
+        SysUser sysUser = new SysUser();
+        sysUser.setUserId(31L);
+        List<SysUser>  userList = userMapper.selectUserList(sysUser);
+        DynamicDataSourceContextHolder.clearDataSourceType();
+        System.out.println(JSON.toJSONString(userList));
+    }
+
+
 }