DataConnectorMapper.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. package com.dao;
  2. import com.model.po.DataConnector;
  3. import com.model.po.DataConnectorList;
  4. import com.model.po.Databases;
  5. import com.model.vo.configVo.DatabasesInfo;
  6. import com.model.vo.configVo.GroupInfo;
  7. import org.apache.ibatis.annotations.*;
  8. import org.springframework.stereotype.Repository;
  9. import java.util.List;
  10. import java.util.Map;
  11. @Mapper
  12. @Repository
  13. public interface DataConnectorMapper {
  14. /*
  15. 查询数据源创建人ID
  16. */
  17. @Select("select c.create_id from bi_data_connectors c,bi_charts cs where cs.id = #{id} and cs.bd_data_id = c.id")
  18. int getCreateId(int id);
  19. /*
  20. 查询数据源ID
  21. */
  22. @Select("select c.id from bi_data_connectors c,bi_charts cs where cs.id = #{id} and cs.bd_data_id = c.id")
  23. int getBaseId(int id);
  24. /*
  25. 查询单个数据源
  26. */
  27. @Select("select ID as dataId, DATA_NAME as dataName, DATA_NOTE as note, DATA_TAG as dataTag, COLUMNS_CONFIG as columnConfig, LOAD_OBJECT as loadObject," +
  28. "CREATE_BY as createBy, create_id as createId, USED_NUMBER as userNumber, CREATE_DATE as createDate,DB_CONFIG as dbConfig, BD_group as connectorGroup," +
  29. "CON_TYPE as type from bi_data_connectors where id = #{id}")
  30. DataConnector getOneData(int id);
  31. /*
  32. 查询自己创建的,权限分配的数据源列表,已经启用
  33. */
  34. @Select("select id as dataId, con_type as type, data_name as dataName, data_tag as dataTag, data_note as note, " +
  35. "bc.create_by as createBy, bc.create_date as createDate," +
  36. "used_number as usedNumber, db_config as dbConfig ,BD_group as connectorGroup, " +
  37. "create_id as createId from bi_data_connectors bc where CREATE_ID = #{id} or ( id in ( select distinct bs_db_id from BI_DB_STRATEGYS where bs_id in (" +
  38. " select bo_st_id from bi_db_object where " +
  39. " (BO_TYPE='1' and bo_ob_id = #{id} ) or " +
  40. " ( bo_type='0' and bo_ob_id in " +
  41. " ( select br_user_group from bi_user_rel_groups where br_user_id = #{id} ) " +
  42. " )" +
  43. "))) and is_open = '1'")
  44. List<DataConnectorList> getDataConnectorList(int id);
  45. /*
  46. 转交数据源
  47. */
  48. @Update("update bi_data_connectors set create_by = #{name}, create_id = #{createId} where id = #{baseId}")
  49. void updataOrder(@Param("name") String name, @Param("createId") int userId, @Param("baseId") int baseId);
  50. /*
  51. 插入数据源配置
  52. */
  53. @Insert("INSERT INTO bi_data_connectors(id,data_name,data_note,data_tag,con_type,LOAD_OBJECT,DB_CONFIG,columns_config,used_number,create_by,create_date, table_name, BD_GROUP, create_id) " +
  54. "VALUES (#{dataId},#{dataName}, #{note}, #{dataTag}, #{type}, #{loadObject}, #{dbConfig},#{columnConfig}, #{usedNumber},#{createBy}, to_date(#{createDate},'YYYY-MM-DD hh24:mi:ss'), #{tableName}, #{connectorGroup},#{createId})")
  55. @SelectKey(before=true,keyProperty="dataId",resultType=int.class,statement="SELECT BI_DASHBOARDS_squence.nextval from dual",keyColumn = "id")
  56. void insertDataConnector(DataConnector dataConnector);
  57. /*
  58. 更新数据源配置
  59. */
  60. @Update("<script>" +
  61. "UPDATE bi_data_connectors set " +
  62. "data_name = #{dataName}" +
  63. "<if test=\"dataTag != null\"> , data_tag = #{dataTag} </if>" +
  64. "<if test=\"loadObject != null\"> , LOAD_OBJECT = #{loadObject} </if>" +
  65. "<if test=\"columnConfig != null\"> , columns_config = #{columnConfig} </if>" +
  66. "<if test=\"dbConfig != null\"> , DB_CONFIG = #{dbConfig} </if>" +
  67. "<if test=\"usedNumber != null\"> , used_number = #{usedNumber} </if>" +
  68. "<if test=\"createBy != null\"> , create_by = #{createBy} </if>" +
  69. "<if test=\"type != null\"> , con_TYPE = #{type} </if>" +
  70. "<if test=\"note != null\"> , DATA_NOTE = #{note} </if>" +
  71. "<if test=\"tableName != null\"> , table_name = #{tableName} </if>" +
  72. "<if test=\"connectorGroup != null\"> , BD_GROUP = #{connectorGroup} </if>"+
  73. "where id = #{dataId}" +
  74. "</script>")
  75. void updateData(DataConnector dataConnector);
  76. /*
  77. 更新数据源配置的分组
  78. */
  79. @Update("update bi_data_connectors set BD_GROUP = #{connectGroup} where id = #{dataId}")
  80. void updateConfigGroup(@Param("dataId") int dataId, @Param("connectGroup") int connectGroup);
  81. /*
  82. 删除数据源
  83. */
  84. @Delete("<script>" +
  85. "delete from bi_data_connectors where id in " +
  86. "("+
  87. "<foreach collection=\"list\" index=\"index\" item=\"item\" separator=\",\">" +
  88. "#{item, jdbcType = NUMERIC}"+
  89. "</foreach>" +
  90. ")"+
  91. "</script>")
  92. void deleteData(List<Integer> idList);
  93. /*
  94. 保存数据库连接
  95. */
  96. @Insert("insert into BI_DATABASES(id,ADDRASS, CREATE_DATE, DATABASE_TYPE, DATA_NAME, bases_NAME, PASS_WORD, PORT, USER_NAME, note)" +
  97. "values(#{id},#{addrass}, to_date(#{createDate},'YYYY-MM-DD hh24:mi:ss'), #{databaseType}, #{dataName}, #{name}, #{passWord}, #{port}, #{userName}, #{note})")
  98. @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT bi_databases_squence.nextval from dual",keyColumn = "id")
  99. void inputDataBases(Databases databases);
  100. /*
  101. 查询单个数据库连接密码
  102. */
  103. @Select("select pass_word from BI_DATABASES where id= #{id}")
  104. String getBasesById(int id);
  105. /*
  106. 查询单个数据库连接
  107. */
  108. @Select("select id, bases_name as name, note, addrass, data_name as dataName, DATABASE_TYPE as databaseType," +
  109. " PASS_WORD as passWord, USER_NAME as userName, PORT, CREATE_DATE as createDate from bi_databases where id = #{id}")
  110. DatabasesInfo getDatabases(int id);
  111. /*
  112. 查询数据库配置列表
  113. */
  114. @Select("select id, bases_name as name, note, addrass, data_name as dataName, DATABASE_TYPE as databaseType," +
  115. " PASS_WORD as passWord, USER_NAME as userName, PORT, CREATE_DATE as createDate from bi_databases")
  116. List<Databases> getDatabasesList();
  117. /*
  118. 修改数据库配置列表
  119. */
  120. @Update("<script>"+
  121. "UPDATE BI_DATABASES set " +
  122. "BASES_NAME = #{name}" +
  123. "<if test=\"addrass != null\"> , ADDRASS = #{addrass} </if>" +
  124. "<if test=\"port != null\"> , PORT = #{port} </if>" +
  125. "<if test=\"databaseType != null\"> , DATABASE_TYPE = #{databaseType} </if>" +
  126. "<if test=\"dataName != null\"> , DATA_NAME = #{dataName} </if>" +
  127. "<if test=\"userName != null\"> , USER_NAME = #{userName} </if>" +
  128. "<if test=\"passWord != null\"> , PASS_WORD = #{passWord} </if>" +
  129. "<if test=\"note != null\"> , NOTE = #{note} </if>" +
  130. "where id = #{id}" +
  131. "</script>")
  132. void updatabases(Databases databases);
  133. /*
  134. 删除数据库配置
  135. */
  136. @Delete("<script>" +
  137. "delete from bi_databases where id in " +
  138. "("+
  139. "<foreach collection=\"list\" index=\"index\" item=\"item\" separator=\",\">" +
  140. "#{item, jdbcType = NUMERIC}"+
  141. "</foreach>" +
  142. ")"+
  143. "</script>")
  144. void deleteDatabases(List<Integer> idList);
  145. /*
  146. 查询数据源列数据
  147. */
  148. @Select("select columns_Config as columnConfig from bi_data_connectors " +
  149. " where id =#{id}")
  150. DataConnector getColumnData(int id);
  151. /*
  152. 查询数据库配置
  153. */
  154. @Select("select db_config from bi_data_connectors where id = #{id}")
  155. String getDbConfig(int id);
  156. /*
  157. 创建数据源分组
  158. */
  159. @Insert("insert into bi_base_group_by(bb_id, bb_group_name, bb_index, bb_father_id, create_date)" +
  160. "values(#{id}, #{groupName}, #{groupIndex}, #{fatherId}, to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'YYYY-MM-DD hh24:mi:ss'))")
  161. @SelectKey(before=true,keyProperty="id",resultType=int.class,statement="SELECT bi_base_group_by_squence.nextval from dual",keyColumn = "bb_id")
  162. void setConnectorGroup(GroupInfo group);
  163. /*
  164. 更新数据源分组
  165. */
  166. @Update("<script>"+
  167. "UPDATE bi_base_group_by set "+
  168. "bb_group_name = #{groupName}" +
  169. "<if test=\"groupIndex != null\"> , bb_index = #{groupIndex} </if>" +
  170. "<if test=\"fatherId != null\"> , bb_father_id = #{fatherId} </if>" +
  171. "<if test=\"createBy != null\"> , create_by = #{createBy} ,</if>" +
  172. "updata_date = to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'YYYY-MM-DD hh24:mi:ss') "+
  173. " where bb_id = #{id}" +
  174. "</script>")
  175. void updataConnectorGroup(GroupInfo groupInfo);
  176. /*
  177. 删除分组
  178. */
  179. @Delete("<script>" +
  180. "delete from bi_base_group_by where bb_id in" +
  181. "(" +
  182. "<foreach collection=\"list\" index=\"index\" item=\"item\" separator=\",\">" +
  183. "#{item, jdbcType = NUMERIC}" +
  184. " </foreach>" +
  185. ")" +
  186. "</script>")
  187. void delConnectorGroup(List<Integer> isList);
  188. /*
  189. 查询分组是否有子分组
  190. */
  191. @Select("select BB_GROUP_NAME from bi_base_group_by where bb_father_id = #{id}")
  192. List<String> getFatherId(int id);
  193. /*
  194. 查询是否有数据源正在使用
  195. */
  196. @Select("select data_name from bi_data_connectors where bd_group = #{id}")
  197. List<String> getConName(int id);
  198. /*
  199. 查询分组
  200. */
  201. @Select("select bb_id as id, bb_group_name as groupName, bb_index as groupIndex, bb_father_id as fatherId, create_by as createBy," +
  202. "create_date as createDate from bi_base_group_by")
  203. List<GroupInfo> getConnectorGroup();
  204. /*
  205. 查询数据源是否关联图表
  206. */
  207. @Select("select chart_name from bi_charts where bd_data_ID = #{id}")
  208. List<String> getChartsName(int id);
  209. /*
  210. 查询数据源创建人ID
  211. */
  212. @Select("select create_id from bi_data_connectors where id = #{id}")
  213. int getCreateIdById(@Param("id") int id);
  214. /*
  215. 获取数据(根据权限)
  216. */
  217. @Select("${sql}")
  218. List<Map<String, Object>> getValues(@Param("sql") String sql);
  219. /*
  220. 通过数据源ID取sql
  221. */
  222. @Select("select table_name from bi_data_connectors where id = #{id}")
  223. String getSqlByid(int id);
  224. }