wanfa99 3 лет назад
Родитель
Сommit
a0ae26f94e

+ 34 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/controller/TestController.java

@@ -0,0 +1,34 @@
+package org.jeecg.modules.openApi.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import org.jeecg.modules.openApi.service.ISenYuDataSourceOne;
+import org.jeecg.modules.system.util.JsonChangeUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+import java.util.Map;
+
+/***
+ * 测试取数类
+ */
+@RestController
+@RequestMapping("/openApi/test")
+public class TestController {
+    //数据源one
+    @Autowired
+    private ISenYuDataSourceOne senYuDataSourceOne;
+
+    @GetMapping(value = "/Query")
+    public JSONObject save(HttpServletRequest request, HttpServletResponse response) {
+        JSONObject result = new JSONObject();
+        String sql="select  * from Inventory where cInvCode='0101000001'";
+        List<Map<String, Object>> list=senYuDataSourceOne.queryForList(sql);
+        List<JSONObject> listJSONObject= JsonChangeUtils.toListJson(list);
+        return  listJSONObject.get(0);
+    }
+}

+ 16 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/service/ISenYuDataSourceOne.java

@@ -0,0 +1,16 @@
+package org.jeecg.modules.openApi.service;
+
+import java.util.List;
+import java.util.Map;
+
+/***
+ * 数据源1
+ *
+ */
+public interface ISenYuDataSourceOne {
+
+    public List<Map<String, Object>> queryForList(String sql);//查询
+
+    public boolean update(String sql);//执行更新或删除语句
+
+}

+ 35 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/service/impl/SenYuDataSourceOneServiceImpl.java

@@ -0,0 +1,35 @@
+package org.jeecg.modules.openApi.service.impl;
+
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import org.jeecg.modules.openApi.service.ISenYuDataSourceOne;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+@Service
+@DS("multi-one")
+public class SenYuDataSourceOneServiceImpl implements ISenYuDataSourceOne {
+
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+
+    @Override
+    public List<Map<String, Object>> queryForList(String sql) {
+        return jdbcTemplate.queryForList(sql);
+    }
+
+    @Override
+    public boolean update(String sql) {
+        boolean flag = false;
+        int i=jdbcTemplate.update(sql);
+        if (i > 0) {
+            flag = true;
+        }
+        return flag;
+    }
+
+}

+ 2 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/util/JsonChangeUtils.java

@@ -19,11 +19,11 @@ public class JsonChangeUtils{
      * @param result
      * @return
      */
-    public static List<JSONObject> toListJson(List<Map<String, String>> result) {
+    public static List<JSONObject> toListJson(List<Map<String, Object>> result) {
         List<JSONObject> pljf = new ArrayList<JSONObject>();// 表数据json集合
         JSONObject jf = new JSONObject();
         for (int i = 0; i < result.size(); i++) {
-            Map<String, String> map = result.get(i);
+            Map<String, Object> map = result.get(i);
             Set<String> keys = map.keySet();
             jf = new JSONObject();
             for (String key : keys) {

+ 7 - 7
jeecg-boot-module-system/src/main/resources/application-dev.yml

@@ -131,16 +131,16 @@ spring:
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
       datasource:
         master:
-          url: jdbc:mysql://127.0.0.1:3306/sen_yu_dz_new?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
+          url: jdbc:mysql://106.15.206.14:3306/sen_yu_dz_dev?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
           username: root
           password: CuiDian1234
           driver-class-name: com.mysql.cj.jdbc.Driver
-          # 多数据源配置
-#        multi-datasource1:
-#          url: jdbc:mysql://localhost:3306/sen_yu?useUnicode=true&characterEncoding=utf8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
-#          username: root
-#          password: root
-#          driver-class-name: com.mysql.cj.jdbc.Driver
+        #多数据源配置
+        multi-one:
+          url: jdbc:sqlserver://106.15.32.1:1433;SelectMethod=cursor;DatabaseName=UFDATA
+          username: cuidian
+          password: cuidianUFdata
+          driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
   #redis 配置
   redis:
     database: 0

+ 1 - 1
jeecg-boot-module-system/src/main/resources/application.yml

@@ -2,4 +2,4 @@ spring:
   application:
     name: jeecg-system
   profiles:
-    active: @profile.name@
+    active: dev