Explorar o código

Merge branch 'feature-refactor' of ssh://10.10.100.21/source/platform-bi-server into feature-refactor

zhuth %!s(int64=7) %!d(string=hai) anos
pai
achega
9308315b35

+ 1 - 1
bi-server/src/main/java/com/usoftchina/bi/server/Application.java

@@ -4,7 +4,6 @@ import com.usoftchina.bi.core.jdbc.DynamicDataSourceRegister;
 import com.usoftchina.bi.core.utils.ContextUtil;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.test.autoconfigure.core.AutoConfigureCache;
 import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.ComponentScan;
@@ -19,6 +18,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
 @EnableScheduling
 @ComponentScan("com.usoftchina.bi")
 public class Application {
+
     public static void main(String[] args) {
         ApplicationContext app = SpringApplication.run(Application.class, args);
         ContextUtil.setApplicationContext(app);

+ 11 - 0
bi-server/src/main/java/com/usoftchina/bi/server/SpringbootStartApplication.java

@@ -1,7 +1,11 @@
 package com.usoftchina.bi.server;
 
+import com.usoftchina.bi.core.utils.ContextUtil;
+import org.springframework.boot.SpringApplication;
 import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.web.context.WebApplicationContext;
 
 /**
  * @Author chenwei
@@ -14,4 +18,11 @@ public class SpringbootStartApplication extends SpringBootServletInitializer {
         return applicationBuilder.sources(Application.class);
     }
 
+    @Override
+    protected WebApplicationContext run(SpringApplication application) {
+        ConfigurableApplicationContext app =  application.run();
+        ContextUtil.setApplicationContext(app);
+        return (WebApplicationContext) app;
+    }
+
 }

+ 2 - 2
bi-server/src/main/java/com/usoftchina/bi/server/controller/dashboard/DashboardMenuController.java

@@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.*;
  * @Date 2019-04-19
  */
 @RestController
-@RequestMapping("/dashBoard/menu")
+@RequestMapping("/dashboard/menu")
 @Api(description = "看板目录相关接口")
 public class DashboardMenuController {
 
@@ -62,7 +62,7 @@ public class DashboardMenuController {
         return new RepEntity(RepCode.success);
     }
 
-    @GetMapping("/list/dashBoard/{menuId}")
+    @GetMapping("/list/{menuId}")
     @CheckToken
     @ApiOperation(value = "获得目录下的所有报表", notes = "通过MenuId获得目录下的所有报表", response = RepEntity.class)
     public RepEntity getDashBoardByMenuId(@RequestHeader String token, @PathVariable("menuId") int menuId){

+ 8 - 0
bi-server/src/main/java/com/usoftchina/bi/server/dao/dataSource/DataConnectorMapper.java

@@ -140,6 +140,14 @@ public interface DataConnectorMapper {
     @Select("SELECT COUNT(*) FROM BI_CHARTS WHERE BD_DATA_ID = #{id}")
     int countChartsById(Long id);
 
+    /**
+     * 是否存在数据连接
+     * @param databases
+     * @return
+     */
+    @Select("SELECT COUNT(*) FROM BI_DATABASES WHERE ADDRASS = #{addrass,jdbcType=VARCHAR} AND PORT = #{port,jdbcType=VARCHAR} AND USER_NAME = #{userName,jdbcType=VARCHAR}")
+    int countDataBases(Databases databases);
+
     /*
     删除数据源
      */

+ 5 - 5
bi-server/src/main/java/com/usoftchina/bi/server/model/vo/configVo/DashboardsInfo.java

@@ -12,14 +12,14 @@ public class DashboardsInfo {
     private String filters;
     private String chartIds;
     private String bdCode;
-    private int menu;
+    private int menuId;
 
-    public int getMenu() {
-        return menu;
+    public int getMenuId() {
+        return menuId;
     }
 
-    public void setMenu(int menu) {
-        this.menu = menu;
+    public void setMenuId(int menuId) {
+        this.menuId = menuId;
     }
 
     public String getBdCode() {

+ 19 - 0
bi-server/src/main/java/com/usoftchina/bi/server/service/dataSource/DataBasesService.java

@@ -52,8 +52,11 @@ public class DataBasesService {
         }
         Databases databases = new Databases();
         BeanUtils.copyProperties(databasesInfo, databases);
+        //校验此数据连接是否已存在
+        validExists(databases);
         //校验此连接是否可用
         implementSqlService.connectTest(databases);
+
         String note = databases.getNote();
         if (note == null || "".equals(note)){
             note = "";
@@ -64,9 +67,21 @@ public class DataBasesService {
         databasesInfo.setId(id);
         //添加数据源可切换
         addDataSource(databasesInfo);
+
         return new RepEntity(RepCode.success,id);
     }
 
+    /**
+     * 校验此数据连接是否已存在
+     * @param databases
+     */
+    private void validExists(Databases databases){
+        int count = dataConnectorMapper.countDataBases(databases);
+        if (count > 0) {
+            throw new MyException("已存在用户名为 " + databases.getUserName() + " 的数据连接!");
+        }
+    }
+
     /*
    查看数据库配置列表
     */
@@ -206,12 +221,16 @@ public class DataBasesService {
         }
         if (!target.containsKey(String.valueOf(databasesInfo.getId()))) {
             target.put(databasesInfo.getId(), dataSourceRegister.buildDataSource(dsMap));
+
             DynamicDataSource datasource = (DynamicDataSource) ContextUtil.getBean("dataSource");
+
             datasource.setTargetDataSources(target);
             datasource.afterPropertiesSet();
 
             Set<String> dataSourceIds = DynamicDataSourceContextHolder.getDataSourceIds();
+
             dataSourceIds.add(String.valueOf(databasesInfo.getId()));
+
             DynamicDataSourceContextHolder.setDataSourceIds(dataSourceIds);
         }
     }

+ 1 - 0
bi-server/src/main/java/com/usoftchina/bi/server/service/dataSource/ImplementSqlService.java

@@ -135,6 +135,7 @@ public class ImplementSqlService {
         String username = databases.getUserName();
         Connection con = null;
         try {
+            DriverManager.setLoginTimeout(6);
             con = DriverManager.getConnection(url, username, password);
             con.close();
         } catch (SQLException se) {