# 功能描述

实现对数据库的增删改查操作及日志记录。 支持mysql、mongdb、elasticsearch数据库。 系统支持mybatis,可配置是否开启mybatis。 系统支持表结构导出、表结构同步、表数据导出、表数据同步。

# mybatis配置一览表

提示

需在application.yml中设置mybatis-plus.enabled为true才能开启mybatis服务。

mybatis-plus:
  enabled: false  #是否开启mybatis-plus
  #全局config参数配置
  #config-location: classpath:mybatis/mybatis-config.xml
  #扫描mapper类路径配置
  mapper-scan: sei.cloud.data.mapper
  #扫描mapper的xml文件路径配置
  mapper-locations: classpath*:mybatis/mapper/**/*.xml
  #实体扫描,多个package用逗号或者分号分隔
  type-aliases-package: sei.cloud.data.entry
#  type-enums-package: com.baomidou.springboot.entity.enums
  global-config:
    #主键类型  0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
    id-type: 2
    #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
    field-strategy: 2
    #驼峰下划线转换
    db-column-underline: true
    #刷新mapper 调试神器
    refresh-mapper: true
    #数据库大写下划线转换
    #capital-mode: true
    #序列接口实现类配置,不在推荐使用此方式进行配置,请使用自定义bean注入
#    key-generator: com.baomidou.mybatisplus.incrementer.H2KeyGenerator
    #逻辑删除配置(下面3个配置)
    logic-delete-value: 0
    logic-not-delete-value: 1
    #自定义sql注入器,不在推荐使用此方式进行配置,请使用自定义bean注入
#    sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector
    #自定义填充策略接口实现,不在推荐使用此方式进行配置,请使用自定义bean注入
#    meta-object-handler: com.baomidou.springboot.MyMetaObjectHandler
    #自定义SQL注入器
    #sql-injector: com.baomidou.springboot.xxx
    # SQL 解析缓存,开启后多租户 @SqlParser 注解生效
    sql-parser-cache: true
  configuration:
    map-underscore-to-camel-case: true
    cache-enabled: false
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

# mysql配置一览表

配置文件为application-sqldb.yml

提示

需在application.yml中增加spring.profiles.active中增加datasource-sqldb才能激活配置文件

spring:
  jpa:
    open-in-view: false
    database: MYSQL # 配置 DBMS 类型
    show-sql: true  # 配置是否将执行的 SQL 输出到日志
    properties:
      hibernate:
        hbm2ddl:
          auto: update  # 配置开启自动更新表结构

  # 数据库密码加密设置方式
  # 1、找到 druid-1.1.22.jar 文件并进入该目录
  # 2、假设数据库口令为root,则执行命令: java -cp druid-1.1.22.jar com.alibaba.druid.filter.config.ConfigTools root
  # 3、将生成的 password 字符串拷贝到下面的配置文件中的 password 选项中
  # 4、将生成的 publicKey 字符串拷贝到下面的配置文件中的 publicKey 选项中并去掉注释
  # 5、重新启动服务器
  datasource:
    #druid的监控页面用户名口令设置
    druid-filters:
      user-name: admin
      user-password: xiong
      # wall: 127.0.0.1

    master: #缺省数据库
      key: seicloud
      name: 系统账套
      type: com.alibaba.druid.pool.DruidDataSource
      # 如果对数据库密码进行了加密,则设置公钥,否则不设置
      # publicKey:
      url: jdbc:mysql://127.0.0.1:3306/sei-cloud?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&noAccessToProcedureBodies=true&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
      username: root
      password: root
      driver-class-name: com.mysql.cj.jdbc.Driver
      initial-size: 10
      min-idle: 10
      max-active: 150
      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
      time-between-eviction-runs-millis: 90000
      # 配置一个连接在池中最小生存的时间,单位是毫秒
      min-evictable-idle-time-millis: 300000
      # Oracle请使用select 1 from dual
      validation-query: SELECT 1
      test-while-idle: true
      test-on-borrow: false
      test-on-return: false
      # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
      filters: stat
      log-slow-sql: false
      # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
      connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
      # 合并多个DruidDataSource的监控数据
      use-global-data-source-stat: true

#    slave:  #其它数据库
#      - key: slave1  #其它数据库1
#        。。。其它配置选项与master相同
#      - key: slave2  #其它数据库2
#        。。。其它配置选项与master相同
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

# mongodb配置一览表

配置文件为application-mongodb.yml

提示

(1) 需在application.yml中增加spring.profiles.active中增加datasource-mongodb才能激活配置文件 (2) 需设置application-mongodb.yml中的spring.data.mongodb.enabled为true才能开启mongodb服务

spring:
  data:
    mongodb:
      enabled: true #设置为true才开启mongodb服务
      host: 127.0.0.1
      port: 27017
#      authentication-database: admin
#      username:
#      password:
      database: sei-cloud-log    #指定操作的数据库
1
2
3
4
5
6
7
8
9
10

# elasticsearch配置一览表

配置文件为application-elasticsearch.yml

提示

(1) 需在application.yml中增加spring.profiles.active中增加datasource-elasticsearch才能激活配置文件 (2) 需设置application-elasticsearch.yml中的spring.elasticsearch.enabled为true才能开启elasticsearch服务

spring:
  elasticsearch:
    enabled: false #设置为true才启动elasticsearch服务
    host: 127.0.0.1:9200  #多个ip之间用逗号分隔
    user:
    password:
1
2
3
4
5
6

# mysql接口

# 第一步 引入包

<dependency>
    <groupId>sei-cloud</groupId>
    <artifactId>datasource</artifactId>
</dependency>
1
2
3
4

# 第二步 引入接口

@Resource
    DataService dataService;
1
2

# 第三步 使用接口

/**
 * SQL操作
 * @author xiong
 */
public interface DataService {

    /**
     * 获得数据源
     * @return Connection
     */
    Connection getConnection();

     /**
      * 释放数据源
      * @param con: 数据库连接
      */
     void closeConnection(@NonNull Connection con);

    /**
     * 只用于页面请求完成后的数据库关闭
     * @param con: 数据库连接
     */
    void afterPageRequestCloseConnection(@NonNull Connection con);

    /**
     * 执行sql的ddl语句(建表/导入数据等)
     * @param reader: 读取
     */
    void runSQLScript(Reader reader);

    /**
     * 判断表是否为树型结构(判断标准为表中有_pid字段)
     * @param tableName: 表名称
     * @return boolean
     * @throws SQLException 异常
     */
    boolean isTreeTable(@NonNull String tableName) throws SQLException;

    /**
     * 判断表是否为工作流表结构(判断标准为表中有_flowid字段)
     * @param tableName: 表名称
     * @return boolean
     * @throws SQLException 异常
     */
    boolean isWorkflowTable(@NonNull String tableName) throws SQLException;

    /**
     * 获得指定模块的主表名
     * @param module: 模块标识
     * @return String | null
     * @throws SQLException 异常
     */
    String getMainTableName(@NonNull String module) throws SQLException;

    /**
     * 获得指定模块的子表名
     * @param module: 模块标识
     * @return List
     * @throws SQLException 异常
     */
    List<String> getSubTableName(@NonNull String module) throws SQLException;

    /**
     * 分页函数
     * @param currPageNumber: 当前页码
     * @param pageSize: 每一页记录数
     * @param beanClass: 结果类型
     * @param sql: SQL语句
     * @param parameterValue: SQL语句中的问号参数值
     * @param <T> T
     * @return PageVo
     * @throws SQLException 异常
     */
    <T> PageVo<T> getPage(int currPageNumber, int pageSize, Class<T> beanClass, @NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 分页函数
     * @param currPageNumber: 当前页码
     * @param pageSize: 每一页记录数
     * @param sql: SQL语句
     * @param parameterValue: SQL语句中的问号参数值
     * @return PageVo
     * @throws SQLException 异常
     */
    PageVo<XJSONObject> getPage(int currPageNumber, int pageSize, @NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 获得树型结构的父级字段以斜杠/分隔的联合值
     * @param table: 树型表名称
     * @param fieldName: 树型表当前记录树字段名称
     * @param parentFieldValue: 树型表当前记录树字段值
     * @param fields: 要获得的字段列表
     * @return 与fields内字段顺序对应的结果列表
     * @throws SQLException 异常
     */
    List<String> getTreeParentJoin(@NonNull String table, @NonNull String fieldName, @Nullable Object parentFieldValue, @NonNull List<String> fields) throws SQLException;

    /**
     * 获得父ID值为fieldValue的所有子节点fieldName字段的值(多个值间分号分割)
     * @param table: 树型表名称
     * @param fieldName:  要拿的树型表字段名
     * @param isIncludeParent: 是否包含父节点值
     * @param parameterValue: 父ID值
     * @return 返回父ID值为fieldValue的所有子节点fieldName字段值(多个值间分后分割)
     * @throws SQLException 异常
     */
    List<Object> getTreeChildJoin(@NonNull String table, @NonNull String fieldName, boolean isIncludeParent, Object... parameterValue) throws SQLException;

    /**
     * 获得指定的下级表(子表)和平行表关系
     * @param tableName: 表名
     * @return List
     * @throws SQLException  异常
     */
    List<JSONObject> getTableRelation(String tableName) throws SQLException;

    /**
     * 获得平行表数据
     * @param tableName: 源表名称
     * @param keyFieldName: 源表主键字段
     * @param fields: 要获取的字段,为null则所有字段,数据库不存在的字段自动剔除
     * @param row: 源表数据
     * @param targetTableName: 设置要获得的平行表的表名,为null则为所有平行表
     * @return Map
     * @throws SQLException
     */
    Map<String, XJSONObject> getMergeParallelTableData(@NonNull String tableName, @Nullable String keyFieldName, @Nullable Collection<String> fields, @NonNull XJSONObject row, @Nullable String... targetTableName) throws SQLException;

    /**
     * 获得或融合平行表数据
     * @param tableName: 源表名称
     * @param keyFieldName: 源表主键字段
     * @param fields: 要获取的字段,为null则所有字段,数据库不存在的字段自动剔除
     * @param row: 源表数据
     * @param targetTableName: 设置只融合的表,否则获得或融合所有平行表
     * @return Map
     * @throws SQLException
     */
    Map<String, List<XJSONObject>> getMergeSubTableData(@NonNull String tableName, @Nullable String keyFieldName, @Nullable Collection<String> fields, @NonNull XJSONObject row, @Nullable String... targetTableName) throws SQLException;

    /**
     * 插入数据
     * @param sql: SQL语句
     * @param parameterValue: SQL语句中的问号参数值
     * @return int
     * @throws SQLException 异常
     */
    int insertData(@NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 插入数据并获得插入记录的自增长主键值
     * @param sql: SQL语句
     * @param returnList: 接收执行结果的返回值,用于插入时获得插入记录的自增长主键值, 为null表示不要
     * @param parameterValue: SQL语句中的问号参数值
     * @return int
     * @throws SQLException 异常
     */
    int insertDataCallBack(@NonNull String sql, @Nullable List<Object> returnList, Object... parameterValue) throws SQLException;

    /**
     * 删除数据
     * @param sql: SQL语句
     * @param parameterValue: 对应的参数值
     * @return int
     * @throws SQLException 异常
     */
    int deleteData(@NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 更新数据
     * @param sql: SQL语句
     * @param parameterValue: 对应的参数值
     * @return int
     * @throws SQLException 异常
     */
    int updateData(@NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 批量更新数据
     * @param sql: SQL语句
     * @param fieldVal: 每一个List条目对应更新的一条数据, 每条数据如果有多个字段则将多个字段值放入List或者Array中
     * @return int
     * @throws SQLException 异常
     */
    int updateDataBatch(@NonNull String sql, @NonNull List<Object> fieldVal) throws SQLException;

    /**
     * 返回查询结构的总行数
     * @param sql: SQL语句,必须包含count函数
     * @param parameterValue: 对应的参数值
     * @return long
     * @throws SQLException 异常
     */
    int selectCount(@NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 查询数据,返回一条数据指定类型的对象
     * @param sql: SQL语句
     * @param beanClass: 结果转换类型
     * @param parameterValue: 对应的参数值
     * @param <T> T
     * @return T | null
     * @throws SQLException 异常
     * @throws InstantiationException 异常
     * @throws IntrospectionException 异常
     * @throws IllegalAccessException 异常
     * @throws IllegalArgumentException 异常
     */
    <T> T selectOne(@NonNull String sql, @NonNull Class<T> beanClass, Object... parameterValue) throws SQLException, InstantiationException, IntrospectionException, IllegalAccessException, IllegalArgumentException;

    /**
     * 查询数据,返回一条数据指定类型的对象,每个字段带表名
     * @param sql: SQL语句
     * @param beanClass: 结果转换类型
     * @param parameterValue: 对应的参数值
     * @param <T> T
     * @return T | null
     * @throws SQLException 异常
     * @throws InstantiationException 异常
     * @throws IntrospectionException 异常
     * @throws IllegalAccessException 异常
     * @throws IllegalArgumentException 异常
     */
    <T> T selectOneWithTableName(@NonNull String sql, @NonNull Class<T> beanClass, Object... parameterValue) throws SQLException, InstantiationException, IntrospectionException, IllegalAccessException, IllegalArgumentException;

    /**
     * 查询数据,返回第一条数据的Map对象
     * @param sql: SQL语句
     * @param parameterValue: 对应的参数值
     * @return Map
     * @throws SQLException 异常
     */
    XJSONObject selectOne(@NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 查询数据,返回第一条数据的Map对象并缓存
     * @param cacheKey: 缓存的key
     * @param sql: SQL语句
     * @param parameterValue: 对应的参数值
     * @return XJSONObject
     * @throws SQLException 异常
     */
    XJSONObject selectOne2Cache(@NonNull String cacheKey, @NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 查询数据,返回第一条数据的第一个字段值
     * @param sql: SQL语句
     * @param parameterValue: 参数值
     * @return Object
     * @throws SQLException 异常
     */
    Object selectOneValue(@NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 查询数据,返回第一条数据的第一个字段值并缓存
     * @param cacheKey: 缓存的key
     * @param sql: SQL语句
     * @param parameterValue: 参数值
     * @return Object
     * @throws SQLException 异常
     */
    Object selectOneValue2Cache(@NonNull String cacheKey, @NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 查询数据,返回一条数据的Map对象,每个字段带表名
     * @param sql: SQL语句
     * @param parameterValue: 对应的参数值
     * @return Map | null
     * @throws SQLException 异常
     */
    XJSONObject selectOneWithTableName(@NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 查询数据,返回一条数据的Map对象,除主表字段不带表名,其它表带表名
     * @param primaryTableName: 主表名称
     * @param sql: SQL语句
     * @param parameterValue: 对应的参数值
     * @return Map | null
     * @throws SQLException 异常
     */
    XJSONObject selectOneWithPrimaryNoTableName(@NonNull String primaryTableName, @NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 查询条数据,返回多条数据列表,每条数据为指定的类型
     * @param sql: SQL语句
     * @param beanClass: 要转换的对象类
     * @param parameterValue: 对应的参数值
     * @param <T> T
     * @return List | null
     * @throws SQLException 异常
     */
    <T> List<T> selectList(@NonNull String sql, @NonNull Class<T> beanClass, Object... parameterValue) throws SQLException;

    /**
     * 查询返回多条数据列表,每条数据为指定的类型,每个字段带表名
     * @param sql: SQL语句
     * @param beanClass: 要转换的对象类
     * @param parameterValue: 对应的参数值
     * @param <T> T
     * @return List | null
     * @throws SQLException 异常
     */
    <T> List<T> selectListWithTableName(@NonNull String sql, @NonNull Class<T> beanClass, Object... parameterValue) throws SQLException;

    /**
     * 查询条数据,返回多条数据列表,每条数据为XJSONObject类型
     * @param sql: SQL语句
     * @param parameterValue: 对应的参数值
     * @return List | null
     * @throws SQLException 异常
     */
    List<XJSONObject> selectList(@NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 查询条数据并缓存结果,返回多条数据列表,每条数据为XJSONObject类型
     * @param cacheKey: 缓存的key
     * @param sql: SQL语句
     * @param parameterValue: 对应的参数值
     * @return List | null
     * @throws SQLException 异常
     */
    List<XJSONObject> selectList2Cache(@NonNull String cacheKey, @NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 返回每条记录的第一个字段的值
     * @param sql: SQL语句
     * @param parameterValue: 对应的参数值
     * @return List
     * @throws SQLException 异常
     */
    List<Object> selectFirstFieldList(@NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 查询条数据,返回多条数据列表,每条数据为Map类型
     * @param sql: sql语句
     * @param parameterValue: 对应的参数值
     * @return List | null
     * @throws SQLException 异常
     */
    List<XJSONObject> selectListMap(@NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 查询条数据,返回多条数据列表,每条数据为Map类型,所有字段带表名
     * @param sql: SQL语句
     * @param parameterValue: 对应的参数值
     * @return List | null
     * @throws SQLException 异常
     */
    List<XJSONObject> selectListWithTableName(@NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 查询时并遍历查询结果,每次遍历执行回调函数
     * @param action: 每次遍历执行回调函数
     * @param sql: SQL语句
     * @param parameterValue: 对应的参数值
     * @throws SQLException 异常
     */
    void select(Consumer<? super ResultSet> action, @NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 查询或更新多次数据, 可多次设置条件并返回执行结果或执行回调函数
     * @param sql: SQL语句
     * @param action: 查询条件及结果或回调函数
     * @throws SQLException 异常
     */
    void prepareStatement(@NonNull String sql, Consumer<? super PreparedStatementVo> action) throws SQLException;

    /**
     * 使用statement进行链式操作
     * @param action: 执行的回调函数
     * @throws SQLException 异常
     */
    void statement(Consumer<? super StatementVo> action) throws SQLException;

    /**
     * 获得sql查询语句的字段名称
     * @param sql: SQL语句
     * @param parameterValue: 对应的参数值
     * @return List | null
     * @throws SQLException 异常
     */
    List<XJSONObject> getFieldNameFromSQL(@NonNull String sql, Object... parameterValue) throws SQLException;

    /**
     * 将查询结果转换为excel文件
     * @param titles: 字段标题数组
     * @param pathName: 文件绝对路径及名称
     * @param sql: sql语句
     * @param dict: 字典翻译配置
     * @param parameterValue: sql参数值
     * @return boolean
     * @throws SQLException 异常
     * @throws IOException 异常
     * @throws InvalidFormatException 异常
     */
    boolean selectListToExcel(@NonNull List<Object> titles, @NonNull String pathName, @NonNull String sql, @Nullable JSONObject dict, Object... parameterValue) throws SQLException, IOException, InvalidFormatException;

    /**
     * 执行SQL语句(支持插入/修改/删除)
     * @param sql: SQL语句
     * @param returnList: 插入时主键的返回值
     * @param parameterValue: SQL占位符对应的值
     * @return int
     * @throws SQLException 异常
     */
    int executeUpdate(String sql, List<Object> returnList, Object... parameterValue) throws SQLException;

    /**
     * 获得数据库服务器信息
     * @return List
     * @throws SQLException 异常
     */
    List<Map<String, Object>> getServerInfo() throws SQLException;

    /**
     * 判断表在当前数据库中是否存在
     * @param tableName: 表名
     * @return boolean
     * @throws SQLException 异常
     */
    boolean getTableExists(@NonNull String tableName) throws SQLException;

    /**
     * 判断表中的字段在当前数据库中是否存在
     * @param tableName: 表名
     * @param fieldName: 字段名
     * @return boolean
     * @throws SQLException 异常
     */
    boolean getTableFieldExists(@NonNull String tableName, @NonNull String fieldName) throws SQLException;

    /**
     * 获得指定表主键字段名称
     * @param tableName: 表名
     * @return String | null
     * @throws SQLException 异常
     */
    String getTablePrimaryFieldsName(@NonNull String tableName) throws SQLException;

    /**
     * 获得指定表主键字段信息
     * @param tableName: 表名
     * @return FieldInfo | null
     * @throws SQLException 异常
     */
    FieldInfo getTablePrimaryFieldsInfo(@NonNull String tableName) throws SQLException;

    /**
     * 获得指定表的所有索引
     * @param tableName: 表名
     * @return List
     * @throws SQLException 异常
     */
    List<XJSONObject> getTableIndex(String tableName) throws SQLException;

    /**
     * 获得指定表所有字段的结构信息
     * @param tableName: 表名
     * @return Map
     * @throws SQLException 异常
     */
    Map<String, FieldInfo> getTableFieldsInfo(@NonNull String tableName) throws SQLException;

    /**
     * 获得指定表所有字段的结构信息
     * @param tableName: 表名
     * @return List
     * @throws SQLException 异常
     */
    List<FieldInfo> getTableFieldsInfoByList(@NonNull String tableName) throws SQLException;

    /**
     * 获得所有表的名称
     * @return List
     * @throws SQLException 异常
     */
    List<String> getTablesName() throws SQLException;

    /**
     * 获得表所属模块列表并缓存
     * @param tableName: 表名
     * @return List
     * @throws SQLException 异常
     */
    List<String> getTableModule(@NonNull String tableName) throws SQLException;

    /**
     * 获得所有表的所有字段名称
     * @return Map
     * @throws SQLException 异常
     */
    Map<String, List<String>> getTablesNameFieldsName() throws SQLException;

    /**
     * 获得指定表的信息
     * @param tableName: 表名
     * @return XJSONObject
     * @throws SQLException 异常
     */
    XJSONObject getTableInfo(String tableName) throws SQLException;

    /**
     * 获得指定表所有字段名称
     * @param tableName: 表名
     * @return List
     * @throws SQLException 异常
     */
    ArrayFieldList getTableFieldsName(@NonNull String tableName) throws SQLException;

    /**
     * 创建表
     * @param tableName: 表名称
     * @param ddl: 创建表的sql语句
     *  @return boolean
     * @throws SQLException 异常
     */
    boolean createTable(@NonNull String tableName, @NonNull String ddl) throws SQLException;

    /**
     * 获得表的外键
     * @param tableName: 表名称
     * @return List
     * @throws SQLException 异常
     */
    List<XJSONObject> getForeignKeys(String tableName) throws SQLException;

    /**
     * 获得指定表的触发器
     * @param tableName: 表名称
     * @return List
     * @throws SQLException 异常
     */
    List<XJSONObject> getTriggers(String tableName) throws SQLException;

    /**
     * 获得当前数据库的视图
     * @return List
     * @throws SQLException 异常
     */
    List<XJSONObject> getViews() throws SQLException;

    /**
     * 缓存所有库的所有表或指定的表结构信息
     * @param tableNames: 表名,多个表名用逗号分隔,为null表示所有表
     */
    void cacheAllTableStructure(@Nullable String... tableNames);

    /**
     * 清除当前库的所有缓存
     */
    void removeAllCache();

    /**
     * 清除当前库指定表的缓存
     * @param tableName: 表名
     */
    void removeCache(@NonNull String tableName);

    /**
     * 对预处理SQL语句赋值
     * @param pstmt: PreparedStatement
     * @param parameterValue: 值
     * @throws SQLException 异常
     */
    static void setVal(PreparedStatement pstmt, Object... parameterValue) throws SQLException;

    /**
     * 从ResultSet中获取多行值
     * @param rs: ResultSet
     * @param closeResultSet: 是否关闭ResultSet
     * @return List
     * @throws SQLException 异常
     */
    static List<XJSONObject> getList(ResultSet rs, boolean closeResultSet) throws SQLException;

    /**
     * 从ResultSet中获取多行值
     * @param rs: ResultSet
     * @param closeResultSet: 是否关闭ResultSet
     * @return List
     * @throws SQLException 异常
     */
    static List<Object> getFirstFieldList(ResultSet rs, boolean closeResultSet) throws SQLException;

    /**
     * 从ResultSet中获取第一条记录的全部字段
     * @param rs: ResultSet
     * @param closeResultSet: 是否关闭ResultSet
     * @return Map
     * @throws SQLException 异常
     */
    static XJSONObject getMap(ResultSet rs, boolean closeResultSet) throws SQLException;

    /**
     * 将当前行转换为Map
     * @param rs: ResultSet结果集
     * @return XJSONObject
     * @throws SQLException 异常
     */
    static XJSONObject convertResult2Map(ResultSet rs) throws SQLException;

    /**
     * 从ResultSet中第一条记录的第一个字段值
     * @param rs: ResultSet
     * @param closeResultSet: 是否关闭ResultSet
     * @return Map | null
     * @throws SQLException 异常
     */
    static Object getFirstFieldValue(ResultSet rs, boolean closeResultSet) throws SQLException;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610

# mongdb接口

# 第一步 引入包

<dependency>
    <groupId>sei-cloud</groupId>
    <artifactId>datasource</artifactId>
</dependency>
1
2
3
4

# 第二步 引入接口

@Resource
    MongoTemplate mongoTemplate;
1
2

# elasticsearch接口

# 第一步 引入包

<dependency>
    <groupId>sei-cloud</groupId>
    <artifactId>datasource</artifactId>
</dependency>
1
2
3
4

# 第二步 引入接口

@Resource
    RestHighLevelClient restHighLevelClient;
1
2

# 操作日志

本日志指对数据库的增加/修改/删除/登录/退出等操作的日志,而非系统日志。

# 日志配置

日志默认表名为sys_log存储到mysql数据库中,可配置存储到任意数据库或者本地文件中。 例如配置存储到文件,则修改application.yml文件中的data-base选项。

sei:
  cloud:
    data-base:  #注意顺序,找表时根据顺序查找
      - mysql:
          include: "*" # 星号*代表所有表, 多个表逗号分隔
          exclude: "sys_log" # 要排除的表
      - mongodb:
          include: "" #将指定表数据保存到mongodb数据库,如果前面已经包含则以前面的为准
          exclude:
      - elasticsearch:
          include: "" #将指定表数据保存到mongodb数据库,如果前面已经包含则以前面的为准
          exclude:
      - hbase:
          include:
          exclude:
      - file:
          include: "sys_log" #要存储的表名称
          file-path: /Users/xiong/Desktop/temp # 数据文件的存放目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# 操作日志

	/**
	 * 用户操作日志
	 * @param moduleID: 模块编号
	 * @param table: 表名
	 * @param action: 操作
	 * @param info: 操作信息
	 * @param other: 其它信息
	 */
	public static void userLog(String action, String moduleID, String table, Object info, Object... other);

	/**
	 * 用户操作日志
	 * @param action: 操作
	 * @param operation 操作信息
	 */
	public static void userLog(String action, Object... operation);

	/**
	 * 用户操作日志
	 * @param action: 操作
	 * @param map: 操作信息
	 */
	public static void userLog(String action, Map<String, Object> map);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

# 表结构导出同步\表数据导入导出

/**
 * 数据表结构导出/同步及表数据导入导出
 */
public class SyncTable {

	/**
	 * 导出表结构为json文件
	 * @param con: 连接
	 * @param pathFileName: 存放的文件路径及名称
	 * @param tableNames: 表名,多个表使用逗号分隔
	 * @throws IOException 异常
	 * @throws SQLException 异常
	 */
	public void exportTable(Connection con, String pathFileName, String tableNames) throws IOException, SQLException;

	/**
	 * 从json文件中同步表结构
	 * @param con: 连接
	 * @param in: 文件流
	 * @return 新创建的表的列表
	 * @throws SQLException 异常
	 */
	public synchronized List<String> importTable(Connection con, InputStream in) throws SQLException;

	/**
	 * 导出表所有数据到json文件
	 * @param con: 连接
	 * @param pathFileName: 存放的文件路径及名称
	 * @param tableNames: 表名
	 * @throws SQLException 异常
	 * @throws IOException 异常
	 */
	public void exportTableData(Connection con, String pathFileName, String... tableNames) throws SQLException, IOException;

	/**
	 * 从json文件中导入表数据
	 * @param con: 连接
	 * @param in: 数据文件
	 * @throws SQLException 异常
	 * @throws IOException 异常
	 */
	public void importTableData(Connection con, InputStream in) throws SQLException, IOException;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44