From 812de4749de87d8c7079aa0b0faa2fd38bfa860e Mon Sep 17 00:00:00 2001 From: xuzihui <895249214@qq.com> Date: Wed, 20 Nov 2019 22:18:56 +0800 Subject: [PATCH] =?UTF-8?q?#783=20=E3=80=90=E6=96=B0=E7=89=B9=E6=80=A7?= =?UTF-8?q?=E3=80=91=E6=95=B0=E7=BB=84=E6=A0=BC=E5=BC=8F=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/6pigxx_config.sql | 2 +- .../handler/JsonStringArrayTypeHandler.java | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/handler/JsonStringArrayTypeHandler.java diff --git a/db/6pigxx_config.sql b/db/6pigxx_config.sql index 6b73fa20c..99c5e8356 100644 --- a/db/6pigxx_config.sql +++ b/db/6pigxx_config.sql @@ -32,7 +32,7 @@ CREATE TABLE `config_info` ( -- Records of config_info -- ---------------------------- BEGIN; -INSERT INTO `config_info` VALUES (1, 'application-dev.yml', 'DEFAULT_GROUP', 'jasypt:\n encryptor:\n password: pigx\n \nspring:\n redis:\n host: pigx-redis\n servlet:\n multipart:\n max-file-size: 100MB\n max-request-size: 100MB\n cloud:\n sentinel:\n transport:\n dashboard: pigx-sentinel:5020\n \nmanagement:\n endpoints:\n web:\n exposure:\n include: \'*\'\n\nfeign:\n sentinel:\n enabled: true\n okhttp:\n enabled: true\n httpclient:\n enabled: false\n client:\n config:\n default:\n connectTimeout: 10000\n readTimeout: 10000\n compression:\n request:\n enabled: true\n response:\n enabled: true\n# hystrix If you need to use ThreadLocal bound variables in your RequestInterceptor`s\n# you will need to either set the thread isolation strategy for Hystrix to `SEMAPHORE or disable Hystrix in Feign.\nhystrix:\n command:\n default:\n execution:\n isolation:\n strategy: SEMAPHORE\n thread:\n timeoutInMilliseconds: 60000\n shareSecurityContext: true\n\n\nribbon:\n ReadTimeout: 10000\n ConnectTimeout: 10000\n\n\nmybatis-plus:\n tenant-enable: ture\n mapper-locations: classpath:/mapper/*Mapper.xml\n global-config:\n banner: false\n db-config:\n id-type: auto\n field-strategy: NOT_EMPTY\n\nswagger:\n title: PigX Swagger API\n license: Powered By PigX\n licenseUrl: https://pig4cloud.com/\n terms-of-service-url: https://pig4cloud.com/\n contact:\n email: wangiegie@gmail.com\n url: https://pig4cloud.com/about.html\n authorization:\n name: pigX OAuth\n auth-regex: ^.*$\n authorization-scope-list:\n - scope: server\n description: server all\n token-url-list:\n - http://${GATEWAY-HOST:pigx-gateway}:${GATEWAY-PORT:9999}/auth/oauth/token\n\nsecurity:\n oauth2:\n client:\n ignore-urls:\n - /actuator/**\n - /v2/api-docs\n resource:\n loadBalanced: true\n token-info-uri: http://pigx-auth/oauth/check_token', 'b1fc21da5a9139a2e89db40905b6242f', '2019-04-18 02:10:20', '2019-11-05 22:33:47', NULL, '127.0.0.1', '', '', '通用配置文件', 'null', 'null', 'yaml', 'null'); +INSERT INTO `config_info` VALUES (1, 'application-dev.yml', 'DEFAULT_GROUP', 'jasypt:\n encryptor:\n password: pigx\n \nspring:\n redis:\n host: pigx-redis\n servlet:\n multipart:\n max-file-size: 100MB\n max-request-size: 100MB\n cloud:\n sentinel:\n transport:\n dashboard: pigx-sentinel:5020\n \nmanagement:\n endpoints:\n web:\n exposure:\n include: \'*\'\n\nfeign:\n sentinel:\n enabled: true\n okhttp:\n enabled: true\n httpclient:\n enabled: false\n client:\n config:\n default:\n connectTimeout: 10000\n readTimeout: 10000\n compression:\n request:\n enabled: true\n response:\n enabled: true\n# hystrix If you need to use ThreadLocal bound variables in your RequestInterceptor`s\n# you will need to either set the thread isolation strategy for Hystrix to `SEMAPHORE or disable Hystrix in Feign.\nhystrix:\n command:\n default:\n execution:\n isolation:\n strategy: SEMAPHORE\n thread:\n timeoutInMilliseconds: 60000\n shareSecurityContext: true\n\n\nribbon:\n ReadTimeout: 10000\n ConnectTimeout: 10000\n\n\nmybatis-plus:\n tenant-enable: ture\n mapper-locations: classpath:/mapper/*Mapper.xml\n global-config:\n banner: false\n db-config:\n id-type: auto\n field-strategy: NOT_EMPTY\n type-handlers-package: com.pig4cloud.pigx.common.data.handler\n\nswagger:\n title: PigX Swagger API\n license: Powered By PigX\n licenseUrl: https://pig4cloud.com/\n terms-of-service-url: https://pig4cloud.com/\n contact:\n email: wangiegie@gmail.com\n url: https://pig4cloud.com/about.html\n authorization:\n name: pigX OAuth\n auth-regex: ^.*$\n authorization-scope-list:\n - scope: server\n description: server all\n token-url-list:\n - http://${GATEWAY-HOST:pigx-gateway}:${GATEWAY-PORT:9999}/auth/oauth/token\n\nsecurity:\n oauth2:\n client:\n ignore-urls:\n - /actuator/**\n - /v2/api-docs\n resource:\n loadBalanced: true\n token-info-uri: http://pigx-auth/oauth/check_token', 'b1fc21da5a9139a2e89db40905b6242f', '2019-04-18 02:10:20', '2019-11-05 22:33:47', NULL, '127.0.0.1', '', '', '通用配置文件', 'null', 'null', 'yaml', 'null'); INSERT INTO `config_info` VALUES (2, 'pigx-activiti-dev.yml', 'DEFAULT_GROUP', '## spring security 配置\nsecurity:\n oauth2:\n client:\n client-id: ENC(gPFcUOmJm8WqM3k3eSqS0Q==)\n client-secret: ENC(gPFcUOmJm8WqM3k3eSqS0Q==)\n scope: server\n ignore-urls:\n - \'/actuator/**\'\n - \'/v2/api-docs\'\n - \'/editor-app/**\'\n - \'/modeler.html\'\n - \'/ws/**\'\nspring:\n autoconfigure:\n exclude: org.activiti.spring.boot.SecurityAutoConfiguration\n activiti:\n check-process-definitions: false\n datasource:\n type: com.alibaba.druid.pool.DruidDataSource\n druid:\n driver-class-name: com.mysql.cj.jdbc.Driver\n username: ${MYSQL-USER:root}\n password: ${MYSQL-PWD:root}\n url: jdbc:mysql://${MYSQL-HOST:pigx-mysql}:${MYSQL-PORT:3306}/${MYSQL-DB:pigxx_ac}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true\n\n# 租户表维护\npigx:\n tenant:\n column: tenant_id\n tables:\n - oa_leave_bill', 'bb2ee29e458875b0334e9f204f958272', '2019-04-18 02:10:56', '2019-08-27 18:23:55', NULL, '127.0.0.1', '', '', '工作流配置文件', 'null', 'null', 'yaml', 'null'); INSERT INTO `config_info` VALUES (3, 'pigx-auth-dev.yml', 'DEFAULT_GROUP', '# 数据源\nspring:\n datasource:\n type: com.alibaba.druid.pool.DruidDataSource\n druid:\n driver-class-name: com.mysql.cj.jdbc.Driver\n username: ${MYSQL-USER:root}\n password: ${MYSQL-PWD:root}\n url: jdbc:mysql://${MYSQL-HOST:pigx-mysql}:${MYSQL-PORT:3306}/${MYSQL-DB:pigxx}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true\n freemarker:\n allow-request-override: false\n allow-session-override: false\n cache: true\n charset: UTF-8\n check-template-location: true\n content-type: text/html\n enabled: true\n expose-request-attributes: false\n expose-session-attributes: false\n expose-spring-macro-helpers: true\n prefer-file-system-access: true\n suffix: .ftl\n template-loader-path: classpath:/templates/', 'a6674e6747c1a0bb6c6d78e13706f8f0', '2019-04-18 02:11:32', '2019-08-27 18:24:04', NULL, '127.0.0.1', '', '', '认证中心配置文件', 'null', 'null', 'yaml', 'null'); INSERT INTO `config_info` VALUES (4, 'pigx-codegen-dev.yml', 'DEFAULT_GROUP', '## spring security 配置\nsecurity:\n oauth2:\n client:\n client-id: ENC(gPFcUOmJm8WqM3k3eSqS0Q==)\n client-secret: ENC(gPFcUOmJm8WqM3k3eSqS0Q==)\n scope: server\n# 数据源\nspring:\n datasource:\n type: com.alibaba.druid.pool.DruidDataSource\n druid:\n driver-class-name: com.mysql.cj.jdbc.Driver\n username: ${MYSQL-USER:root}\n password: ${MYSQL-PWD:root}\n url: jdbc:mysql://${MYSQL-HOST:pigx-mysql}:${MYSQL-PORT:3306}/${MYSQL-DB:pigxx_codegen}?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8&allowMultiQueries=true&allowPublicKeyRetrieval=true\n resources:\n static-locations: classpath:/static/,classpath:/views/\n\npigx:\n tenant:\n column: tenant_id\n tables:\n - sys_datasource_conf', 'b7d132a3ecdfac4252c994adbb65b23a', '2019-04-18 02:12:10', '2019-08-27 18:24:18', NULL, '127.0.0.1', '', '', '代码生成', 'null', 'null', 'yaml', 'null'); diff --git a/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/handler/JsonStringArrayTypeHandler.java b/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/handler/JsonStringArrayTypeHandler.java new file mode 100644 index 000000000..a9fe22a52 --- /dev/null +++ b/pigx-common/pigx-common-data/src/main/java/com/pig4cloud/pigx/common/data/handler/JsonStringArrayTypeHandler.java @@ -0,0 +1,53 @@ +package com.pig4cloud.pigx.common.data.handler; + +import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.StrUtil; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; +import org.apache.ibatis.type.MappedJdbcTypes; +import org.apache.ibatis.type.MappedTypes; + +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +/** + * Mybatis数组,符串互转 + *

+ * MappedJdbcTypes 数据库中的数据类型 + * MappedTypes java中的的数据类型 + * + * @author xuzihui + * @date 2019-11-20 + */ +@MappedTypes(value = {String[].class}) +@MappedJdbcTypes(value = JdbcType.VARCHAR) +public class JsonStringArrayTypeHandler extends BaseTypeHandler { + + @Override + public void setNonNullParameter(PreparedStatement ps, int i, String[] parameter, JdbcType jdbcType) + throws SQLException { + ps.setString(i, ArrayUtil.join(parameter, StrUtil.COMMA)); + } + + @Override + public String[] getNullableResult(ResultSet rs, String columnName) throws SQLException { + String reString = rs.getString(columnName); + return Convert.toStrArray(reString); + } + + @Override + public String[] getNullableResult(ResultSet rs, int columnIndex) throws SQLException { + String reString = rs.getString(columnIndex); + return Convert.toStrArray(reString); + } + + @Override + public String[] getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { + String reString = cs.getString(columnIndex); + return Convert.toStrArray(reString); + } + +}