Browse Source

删除接口参数调整,增加删除限制

chenw 7 years ago
parent
commit
f01f0d1368
17 changed files with 81 additions and 116 deletions
  1. 4 1
      bi-core/src/main/java/com/usoftchina/bi/core/base/RepCode.java
  2. 10 0
      bi-core/src/main/java/com/usoftchina/bi/core/exception/MyException.java
  3. 1 1
      bi-server/src/main/java/com/usoftchina/bi/server/controller/chart/ChartsConfigController.java
  4. 1 1
      bi-server/src/main/java/com/usoftchina/bi/server/controller/dataSource/DataBasesController.java
  5. 2 2
      bi-server/src/main/java/com/usoftchina/bi/server/controller/dataSource/DataConnectorController.java
  6. 2 2
      bi-server/src/main/java/com/usoftchina/bi/server/controller/strategy/StrategysController.java
  7. 1 1
      bi-server/src/main/java/com/usoftchina/bi/server/controller/user/UserController.java
  8. 5 9
      bi-server/src/main/java/com/usoftchina/bi/server/dao/chart/ChartsConfigMapper.java
  9. 12 27
      bi-server/src/main/java/com/usoftchina/bi/server/dao/dataSource/DataConnectorMapper.java
  10. 2 9
      bi-server/src/main/java/com/usoftchina/bi/server/dao/strategy/StrategysBdMapper.java
  11. 2 9
      bi-server/src/main/java/com/usoftchina/bi/server/dao/strategy/StrategysChartMapper.java
  12. 2 9
      bi-server/src/main/java/com/usoftchina/bi/server/dao/user/UserMapper.java
  13. 7 2
      bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ChartsConfigService.java
  14. 7 3
      bi-server/src/main/java/com/usoftchina/bi/server/service/dataSource/DataBasesService.java
  15. 15 24
      bi-server/src/main/java/com/usoftchina/bi/server/service/dataSource/DataConnectorService.java
  16. 6 14
      bi-server/src/main/java/com/usoftchina/bi/server/service/strategy/StrategysService.java
  17. 2 2
      bi-server/src/main/java/com/usoftchina/bi/server/service/user/UserService.java

+ 4 - 1
bi-core/src/main/java/com/usoftchina/bi/core/base/RepCode.java

@@ -21,7 +21,10 @@ public enum  RepCode {
     DataSourceNull(-507, "数据源切换失败"),
     ChartNonExistent(-508, "图表不存在"),
     DataNonExistent(-509, "数据源不存在"),
-    DashboardNonExistent(-510, "看板不存在");
+    DashboardNonExistent(-510, "看板不存在"),
+    DATACONNECTOR_USED_DATASOURCE(-511, "已有数据源使用了此连接,无法删除!"),
+    CHARTS_USED_DATACONNECTOR(-512, "已有图表使用了此数据源,无法删除!"),
+    DASHBOARD_USED_CHARTS(-513, "已有看板使用了此图表,无法删除!");
 
     private int code;
     private String msg;

+ 10 - 0
bi-core/src/main/java/com/usoftchina/bi/core/exception/MyException.java

@@ -1,5 +1,7 @@
 package com.usoftchina.bi.core.exception;
 
+import com.usoftchina.bi.core.base.RepCode;
+
 public class MyException extends RuntimeException{
     /**
      * 错误编码
@@ -47,6 +49,14 @@ public class MyException extends RuntimeException{
      this(code, msg, cause, true);
   }
 
+    /**
+     * 构造一个基本移仓
+     * @param repCode   异常枚举类
+     */
+    public MyException(RepCode repCode){
+        this(repCode.getCode(), repCode.getMsg(), true);
+    }
+
     /**
      * 构造一个基本异常.
      *

+ 1 - 1
bi-server/src/main/java/com/usoftchina/bi/server/controller/chart/ChartsConfigController.java

@@ -73,7 +73,7 @@ public class ChartsConfigController {
     @ApiOperation(value = "删除图表", notes = "删除图表", response = RepEntity.class)
     @CheckToken
     @PostMapping("/delChartsConfig")
-    public RepEntity delChartsConfig(@RequestHeader String token,@RequestBody List<Integer> body){
+    public RepEntity delChartsConfig(@RequestHeader String token,@RequestBody Long body){
         return chartsConfigService.delChartsConfig(body);
     }
 

+ 1 - 1
bi-server/src/main/java/com/usoftchina/bi/server/controller/dataSource/DataBasesController.java

@@ -53,7 +53,7 @@ public class DataBasesController {
     @CheckToken
     @Auth(user = "admin")
     @PostMapping("/delDatabases")
-    public RepEntity delDatabases(@RequestHeader String token,@RequestBody List<Integer> body){
+    public RepEntity delDatabases(@RequestHeader String token,@RequestBody Long body){
         return dataBasesService.delDatabases(body);
     }
 

+ 2 - 2
bi-server/src/main/java/com/usoftchina/bi/server/controller/dataSource/DataConnectorController.java

@@ -103,7 +103,7 @@ public class DataConnectorController {
     @Auth(user = "admin")
     @CheckToken
     @PostMapping("/delDataConnector")
-    public RepEntity delDataConnector(@RequestHeader String token,@RequestBody List<Integer> body){
+    public RepEntity delDataConnector(@RequestHeader String token,@RequestBody Long body){
         return dataConnectorService.delDataConnector(body);
     }
 
@@ -159,7 +159,7 @@ public class DataConnectorController {
     @Auth(user = "admin")
     @CheckToken
     @PostMapping("/delDataConnectorGroup")
-    public RepEntity delDataConnectorGroup(@RequestHeader String token,@RequestBody List<Integer> body){
+    public RepEntity delDataConnectorGroup(@RequestHeader String token,@RequestBody Long body){
         return dataConnectorService.delDataConnectorGroup(body);
     }
 

+ 2 - 2
bi-server/src/main/java/com/usoftchina/bi/server/controller/strategy/StrategysController.java

@@ -32,7 +32,7 @@ public class StrategysController {
      */
     @ApiOperation(value = "删除数据源策略", notes = "删除数据源策略", response = RepEntity.class)
     @PostMapping("/delDbStrategys")
-    public RepEntity delDbStrategys(@RequestBody List<Integer> body){
+    public RepEntity delDbStrategys(@RequestBody Long body){
         return strategysService.delDbStrategys(body);
     }
 
@@ -41,7 +41,7 @@ public class StrategysController {
      */
     @ApiOperation(value = "删除图表策略", notes = "删除图表策略", response = RepEntity.class)
     @PostMapping("/delChartStrategys")
-    public RepEntity delChartStrategys(@RequestBody List<Integer> body){
+    public RepEntity delChartStrategys(@RequestBody Long body){
         return strategysService.delChartStrategys(body);
     }
 

+ 1 - 1
bi-server/src/main/java/com/usoftchina/bi/server/controller/user/UserController.java

@@ -99,7 +99,7 @@ public class UserController {
     @ApiOperation(value = "删除用户组", notes = "删除用户组", response = RepEntity.class)
     @Auth(user = "admin")
     @PostMapping("/delUserGroup")
-    public RepEntity delUserGroup(@RequestBody List<Integer> body){
+    public RepEntity delUserGroup(@RequestBody Long body){
         return userService.delUserGroup(body);
     }
 

+ 5 - 9
bi-server/src/main/java/com/usoftchina/bi/server/dao/chart/ChartsConfigMapper.java

@@ -25,15 +25,11 @@ public interface ChartsConfigMapper {
     @SelectKey(before=true,keyProperty="chartId",resultType=Integer.class,statement="SELECT bi_charts_sequence.nextval from dual",keyColumn = "id")
     void insertCharts(ChartConfig chartConfig);
 
-    @Delete("<script>" +
-            "delete from bi_charts where id in " +
-            "("+
-            "<foreach collection=\"list\" index=\"index\" item=\"item\"  separator=\",\">" +
-            "#{item, jdbcType = NUMERIC}"+
-            "</foreach>" +
-            ")"+
-            "</script>")
-    void deleteCharts(List<Integer> idList);
+    @Select("SELECT COUNT(*) FROM BI_DASHBOARDS_CHART WHERE CHART_ID = #{id}")
+    int countDashboardsById(Long id);
+
+    @Delete("delete from bi_charts where id = #{id}")
+    void deleteCharts(Long id);
 
     @Select("select bc.id as chartId, chart_name as chartName, chart_type as chartType, bc.create_by as createBy, bc.create_date as createDate, bc_charts_group as chartsGroup " +
             ",bc.bc_filters as filters, bc.BD_DATA_ID as dataId, bc_table_name as tableName, CHART_CONFIG as chartConfig, bc.GROUP_BY as groupBy, bc_charts_option as chartOption, " +

+ 12 - 27
bi-server/src/main/java/com/usoftchina/bi/server/dao/dataSource/DataConnectorMapper.java

@@ -137,18 +137,14 @@ public interface DataConnectorMapper {
     @Update("update bi_data_connectors set BD_GROUP = #{connectGroup} where id = #{dataId}")
     void updateConfigGroup(@Param("dataId") int dataId, @Param("connectGroup") int connectGroup);
 
+    @Select("SELECT COUNT(*) FROM BI_CHARTS WHERE BD_DATA_ID = #{id}")
+    int countChartsById(Long id);
+
     /*
     删除数据源
      */
-    @Delete("<script>" +
-            "delete from bi_data_connectors where id in " +
-            "("+
-            "<foreach collection=\"list\" index=\"index\" item=\"item\"  separator=\",\">" +
-            "#{item, jdbcType = NUMERIC}"+
-            "</foreach>" +
-            ")"+
-            "</script>")
-    void deleteData(List<Integer> idList);
+    @Delete("DELETE FROM BI_DATA_CONNECTORS WHERE ID = #{id}")
+    void deleteData(Long id);
 
     /*
     保存数据库连接
@@ -195,18 +191,14 @@ public interface DataConnectorMapper {
             "</script>")
     void updatabases(Databases databases);
 
+    @Select("SELECT COUNT(*) FROM BI_DATA_CONNECTORS WHERE DB_CONFIG = #{id}")
+    int countDataConnectorById(Long id);
+
     /*
     删除数据库配置
      */
-    @Delete("<script>" +
-            "delete from bi_databases where id in " +
-            "("+
-            "<foreach collection=\"list\" index=\"index\" item=\"item\"  separator=\",\">" +
-            "#{item, jdbcType = NUMERIC}"+
-            "</foreach>" +
-            ")"+
-            "</script>")
-    void deleteDatabases(List<Integer> idList);
+    @Delete("DELETE FROM BI_DATABASES WHERE ID = #{id}")
+    void deleteDatabases(Long id);
 
     /*
     查询数据源列数据
@@ -245,15 +237,8 @@ public interface DataConnectorMapper {
     /*
     删除分组
      */
-    @Delete("<script>" +
-            "delete from bi_base_group_by where bb_id in" +
-            "(" +
-            "<foreach collection=\"list\" index=\"index\" item=\"item\"  separator=\",\">" +
-            "#{item, jdbcType = NUMERIC}" +
-            " </foreach>" +
-            ")" +
-            "</script>")
-    void delConnectorGroup(List<Integer> isList);
+    @Delete("delete from bi_base_group_by where bb_id = #{id}")
+    void delConnectorGroup(Long id);
 
     /*
     查询分组是否有子分组

+ 2 - 9
bi-server/src/main/java/com/usoftchina/bi/server/dao/strategy/StrategysBdMapper.java

@@ -39,15 +39,8 @@ public interface StrategysBdMapper {
     /*
     删除数据源策略
      */
-    @Delete("<script>" +
-            "delete from bi_db_strategys where bs_id in" +
-            "(" +
-            "<foreach collection=\"list\" index=\"index\" item=\"item\"  separator=\",\">" +
-            "#{item, jdbcType = NUMERIC}" +
-            " </foreach>" +
-            ")" +
-            "</script>")
-    void delStrategys(List<Integer> idList);
+    @Delete("delete from bi_db_strategys where bs_id = #{id}")
+    void delStrategys(Long id);
 
     /*
     查询数据源策略Id

+ 2 - 9
bi-server/src/main/java/com/usoftchina/bi/server/dao/strategy/StrategysChartMapper.java

@@ -39,15 +39,8 @@ public interface StrategysChartMapper {
     /*
     删除图表策略
      */
-    @Delete("<script>" +
-            "delete from bi_chart_strategys where bc_id in" +
-            "(" +
-            "<foreach collection=\"list\" index=\"index\" item=\"item\"  separator=\",\">" +
-            "#{item, jdbcType = NUMERIC}" +
-            " </foreach>" +
-            ")" +
-            "</script>")
-    void delStrategys(List<Integer> idList);
+    @Delete("delete from bi_chart_strategys where bc_id = #{id}")
+    void delStrategys(Long id);
 
     /*
     查询数据源策略Id

+ 2 - 9
bi-server/src/main/java/com/usoftchina/bi/server/dao/user/UserMapper.java

@@ -130,15 +130,8 @@ public interface UserMapper {
     /*
     删除用户组
      */
-    @Delete("<script>" +
-            "delete from bi_user_groups where bg_id in " +
-            "("+
-            "<foreach collection=\"list\" index=\"index\" item=\"item\"  separator=\",\">" +
-            "#{item, jdbcType = NUMERIC}"+
-            "</foreach>" +
-            ")"+
-            "</script>")
-    void delUserGroup(List<Integer> idList);
+    @Delete("delete from bi_user_groups where bg_id = #{id}")
+    void delUserGroup(Long id);
 
     /*
     添加用户到用户组

+ 7 - 2
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ChartsConfigService.java

@@ -3,6 +3,7 @@ package com.usoftchina.bi.server.service.chart;
 import com.usoftchina.bi.core.base.RepCode;
 import com.usoftchina.bi.core.base.RepEntity;
 import com.usoftchina.bi.core.base.TestPage;
+import com.usoftchina.bi.core.exception.MyException;
 import com.usoftchina.bi.core.utils.GetTokenDataUtil;
 import com.usoftchina.bi.server.dao.chart.ChartsConfigMapper;
 import com.usoftchina.bi.server.dao.user.UserMapper;
@@ -179,8 +180,12 @@ public class ChartsConfigService {
     /*
     删除图表
      */
-    public RepEntity delChartsConfig(List<Integer> idList){
-        chartsConfigMapper.deleteCharts(idList);
+    public RepEntity delChartsConfig(Long id){
+        int count = chartsConfigMapper.countDashboardsById(id);
+        if (count > 0) {
+            throw new MyException(RepCode.DASHBOARD_USED_CHARTS);
+        }
+        chartsConfigMapper.deleteCharts(id);
         return new RepEntity(RepCode.success);
     }
 

+ 7 - 3
bi-server/src/main/java/com/usoftchina/bi/server/service/dataSource/DataBasesService.java

@@ -1,7 +1,7 @@
 package com.usoftchina.bi.server.service.dataSource;
 
+import com.usoftchina.bi.core.exception.MyException;
 import com.usoftchina.bi.core.utils.ContextUtil;
-import com.usoftchina.bi.core.utils.GetTokenDataUtil;
 import com.usoftchina.bi.server.dao.dataSource.DataConnectorMapper;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.type.CollectionType;
@@ -81,8 +81,12 @@ public class DataBasesService {
     /*
     删除数据库配置
      */
-    public RepEntity delDatabases(List<Integer> idList){
-        dataConnectorMapper.deleteDatabases(idList);
+    public RepEntity delDatabases(Long id){
+        int count = dataConnectorMapper.countDataConnectorById(id);
+        if (count > 0) {
+            throw new MyException(RepCode.DATACONNECTOR_USED_DATASOURCE);
+        }
+        dataConnectorMapper.deleteDatabases(id);
         return new RepEntity(RepCode.success);
     }
 

+ 15 - 24
bi-server/src/main/java/com/usoftchina/bi/server/service/dataSource/DataConnectorService.java

@@ -225,16 +225,12 @@ public class DataConnectorService {
     删除数据源
      */
     @CacheEvict(value = "singleDataConnector")
-    public RepEntity delDataConnector(List<Integer> idList) {
-        Iterator isList = idList.iterator();
-//        while (isList.hasNext()){
-//            int id = (int) isList.next();
-//            List<String> chartName = dataConnectorMapper.getChartsName(id);
-//            if (chartName.size() != 0){
-//                return new RepEntity(RepCode.hasChartsUsing, chartName);
-//            }
-//        }
-        dataConnectorMapper.deleteData(idList);
+    public RepEntity delDataConnector(Long id) {
+        int count = dataConnectorMapper.countChartsById(id);
+        if (count > 0) {
+            throw new MyException(RepCode.CHARTS_USED_DATACONNECTOR);
+        }
+        dataConnectorMapper.deleteData(id);
         return new RepEntity(RepCode.success);
     }
 
@@ -278,21 +274,16 @@ public class DataConnectorService {
     删除数据源分组
      */
     @CacheEvict(value = "singleDataConnector")
-    public RepEntity delDataConnectorGroup(List<Integer> idList) {
-        List<Integer> integerList = idList;
-        Iterator isList = integerList.iterator();
-        while (isList.hasNext()) {
-            int id = (int) isList.next();
-            List<String> groupName = dataConnectorMapper.getFatherId(id);
-            if (groupName.size() != 0) {
-                return new RepEntity(RepCode.hasGroupUsing);
-            }
-            List<String> chartName = dataConnectorMapper.getConName(id);
-            if (chartName.size() != 0) {
-                return new RepEntity(RepCode.hasConUsing);
-            }
+    public RepEntity delDataConnectorGroup(Long id) {
+        List<String> groupName = dataConnectorMapper.getFatherId(id.intValue());
+        if (groupName.size() != 0) {
+            return new RepEntity(RepCode.hasGroupUsing);
+        }
+        List<String> chartName = dataConnectorMapper.getConName(id.intValue());
+        if (chartName.size() != 0) {
+            return new RepEntity(RepCode.hasConUsing);
         }
-        dataConnectorMapper.delConnectorGroup(idList);
+        dataConnectorMapper.delConnectorGroup(id);
         return new RepEntity(RepCode.success);
     }
 

+ 6 - 14
bi-server/src/main/java/com/usoftchina/bi/server/service/strategy/StrategysService.java

@@ -79,26 +79,18 @@ public class StrategysService {
     /*
     删除数据源策略
      */
-    public RepEntity delDbStrategys(List<Integer> idList){
-        strategysBdMapper.delStrategys(idList);
-        Iterator isList = idList.iterator();
-        while (isList.hasNext()){
-            int id = (int) isList.next();
-            strategysBdMapper.delObject(id);
-        }
+    public RepEntity delDbStrategys(Long id){
+        strategysBdMapper.delStrategys(id);
+        strategysBdMapper.delObject(id.intValue());
         return new RepEntity(RepCode.success);
     }
 
     /*
     删除图表策略
      */
-    public RepEntity delChartStrategys(List<Integer> idList){
-        strategysChartMapper.delStrategys(idList);
-        Iterator isList = idList.iterator();
-        while (isList.hasNext()){
-            int id = (int) isList.next();
-            strategysChartMapper.delObject(id);
-        }
+    public RepEntity delChartStrategys(Long id){
+        strategysChartMapper.delStrategys(id);
+        strategysChartMapper.delObject(id.intValue());
         return new RepEntity(RepCode.success);
     }
 

+ 2 - 2
bi-server/src/main/java/com/usoftchina/bi/server/service/user/UserService.java

@@ -180,8 +180,8 @@ public class UserService {
     /*
     删除用户组
      */
-    public RepEntity delUserGroup(List<Integer> idList){
-        userMapper.delUserGroup(idList);
+    public RepEntity delUserGroup(Long id){
+        userMapper.delUserGroup(id);
         return new RepEntity(RepCode.success);
     }