修改适配达梦数据源

This commit is contained in:
lvleigang 2024-05-31 16:45:13 +08:00
parent 22e1047fd9
commit 303e4f1340
7 changed files with 98 additions and 114 deletions

View File

@ -8,13 +8,16 @@ logging:
# 日志保存路径
path: /Users/apple/Desktop/log/local
spring:
flyway:
# 启动flyway migration, 默认为true
enabled: false
datasource:
dynamic:
druid:
filters: stat,log4j2
datasource:
master:
url: jdbc:dm://hzya.ufyct.com:9040?schema=businesscenter&characterEncoding=UTF-8
url: jdbc:dm://hzya.ufyct.com:9040?schema=businesscenter&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&compatibleMode=oracle
username: hzyazt
password: 62e4295b615a30dbf3b8ee96f41c820b
driver-class-name: dm.jdbc.driver.DmDriver

View File

@ -8,15 +8,19 @@ logging:
# 日志保存路径
path: E:\yongansystem\log
spring:
flyway:
# 启动flyway migration, 默认为true
enabled: false
datasource:
dynamic:
druid:
filters: stat,log4j2
datasource:
master:
url: jdbc:mysql://hzya.ufyct.com:9014/businesscenter?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowLoadLocalInfile=false&autoReconnect=true&failOverReadOnly=false&connectTimeout=30000&socketTimeout=30000&autoReconnectForPools=true
username: root
url: jdbc:dm://hzya.ufyct.com:9040?schema=businesscenter&characterEncoding=UTF-8
username: hzyazt
password: 62e4295b615a30dbf3b8ee96f41c820b
driver-class-name: com.mysql.jdbc.Driver # 3.2.0开始支持SPI可省略此配置
driver-class-name: dm.jdbc.driver.DmDriver
savefile:
# 文件保存路径
path: E:/yongansystem/webservice/zt/file

View File

@ -11,6 +11,7 @@ import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Component;
@ -26,103 +27,10 @@ import java.util.Properties;
* @Date: 2020/3/31 10:25
* 数据源工具类
*/
//@Component
//@Lazy(value = false)
@Component
public class DataSourceUtil {
//DATASOURCECODE
public static final ThreadLocal<BaseEntity> myContextThreadLocal = new ThreadLocal<>();
private static final Logger logger = LoggerFactory.getLogger(DataSourceUtil.class);
//SqlSessionFactory容器
private static final Map<String, SqlSessionFactory> SQLSESSIONFACTORYMAP = new HashMap<>();
//dataSource容器
private final Map<String, DruidDataSource> DATASOURCEMAP = new HashMap<>();
// 通过依赖注入获取 DynamicRoutingDataSource 对象
@Resource
private DynamicRoutingDataSource ds;
/****
* 根据dataSourceKey 打开 SqlSession ,如果获取不到SqlSessionFactory 会抛出异常
* @content:
* @author 👻👻👻👻👻👻👻👻 gjh
* @date 2024-02-22 14:50
* @param
* @return org.apache.ibatis.session.SqlSession
**/
public synchronized static SqlSession getSqlSession() {
String dsKey = "master"; // 根据业务逻辑确定要使用的数据源名称
BaseEntity entity = DataSourceUtil.myContextThreadLocal.get();
if(null != entity ){
dsKey = entity.getDataSourceCode();
}
// 通过 DynamicRoutingDataSource 获取当前数据源
// ds.getDataSource(dsKey);
SqlSessionFactory factory = getSqlSessionFactoryByCache(dsKey);
if (null == factory) {
throw new BaseSystemException("根据dataSourceKey获取SqlSessionFactory 失败!请联系管理员");
} else {
return factory.openSession();
}
}
/****
* 根据dataSourceKey获取缓存内的SqlSessionFactory,如果获取不到会抛出异常信息
* @content:
* @author 👻👻👻👻👻👻👻👻 gjh
* @date 2024-02-22 14:44
* @param
* @return org.apache.ibatis.session.SqlSessionFactory
**/
public static SqlSessionFactory getSqlSessionFactoryByCache(String dataSourceKey) {
SqlSessionFactory sqlSessionFactory = SQLSESSIONFACTORYMAP.get(dataSourceKey);
if (null == sqlSessionFactory) {
throw new BaseSystemException("根据当前dataSourceKey获取SqlSessionFactory失败,请联系系统管理员dataSourceKey:" + dataSourceKey);
}
return sqlSessionFactory;
}
/****
* 根据 dataSource 创建SqlSessionFactory,并放入map缓存 dataSourceKey
* @content:
* @author 👻👻👻👻👻👻👻👻 gjh
* @date 2024-02-22 14:38
* @param
* @return org.apache.ibatis.session.SqlSessionFactory
**/
public static SqlSessionFactory createSqlSessionFactoryToCache(String dataSourceKey, DataSource dataSource) {
SqlSessionFactory sqlSessionFactory = createSqlSessionFactory(dataSource);
SQLSESSIONFACTORYMAP.put(dataSourceKey, sqlSessionFactory);
return sqlSessionFactory;
}
//创建sqlSessionFactory
public static SqlSessionFactory createSqlSessionFactory(DataSource dataSource) throws BaseSystemException {
try {
if (null != dataSource) {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
//数据源
sqlSessionFactoryBean.setDataSource(dataSource);
//mybatis的config文件
PathMatchingResourcePatternResolver configLocationResolver = new PathMatchingResourcePatternResolver();
sqlSessionFactoryBean.setConfigLocation(configLocationResolver.getResource("classpath:mybatis/mybatis-config.xml"));
//xml
PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
sqlSessionFactoryBean.setMapperLocations(resourcePatternResolver.getResources("classpath*:com/hzya/**/*.xml"));
sqlSessionFactoryBean.setDatabaseIdProvider(getDatabaseIdProvider());
return sqlSessionFactoryBean.getObject();
} else {
logger.info("======================创建sqlSessionFactory失败===========================");
throw new BaseSystemException("创建sqlSessionFactory失败");
}
} catch (Exception e) {
logger.info("======================创建sqlSessionFactory失败===========================");
throw new BaseSystemException("创建sqlSessionFactory失败" + e.getMessage());
}
}
public static DatabaseIdProvider getDatabaseIdProvider() {
@Bean
public DatabaseIdProvider getDatabaseIdProvider() {
//DBMS 后缀
//Oracle oracle
//DB2 db2
@ -144,9 +52,4 @@ public class DataSourceUtil {
dbProvider.setProperties(setPro);
return dbProvider;
}
public Map<String, DruidDataSource> getDataSourceMap() {
return DATASOURCEMAP;
}
}

View File

@ -74,7 +74,7 @@ WHERE
<!-- 查询 采用==查询 -->
<select id="sevenerrornum" resultType="com.hzya.frame.home.entity.HomeEntity" parameterType="com.hzya.frame.home.entity.HomeEntity">
<select id="sevenerrornum" databaseId="mysql" resultType="com.hzya.frame.home.entity.HomeEntity" parameterType="com.hzya.frame.home.entity.HomeEntity">
SELECT
count( id ) as abnormalNum,
DATE_FORMAT( create_time, '%Y-%m-%d' ) as name
@ -90,7 +90,23 @@ WHERE
'%Y-%m-%d')
</select>
<!-- 查询 采用==查询 -->
<select id="sevensuccessnum" resultType="com.hzya.frame.home.entity.HomeEntity" parameterType="com.hzya.frame.home.entity.HomeEntity">
<select id="sevenerrornum" databaseId="oracle" resultType="com.hzya.frame.home.entity.HomeEntity" parameterType="com.hzya.frame.home.entity.HomeEntity">
SELECT
count( id ) as abnormalNum,
DATE_FORMAT( create_time, '%Y-%m-%d' ) as name
FROM
sys_message_manage_log
WHERE sts = 'Y' and status = '4' and
create_time between add_days( NOW(), -6 ) AND NOW()
GROUP BY
DATE_FORMAT( create_time, '%Y-%m-%d' )
ORDER BY
DATE_FORMAT(
create_time,
'%Y-%m-%d')
</select>
<!-- 查询 采用==查询 -->
<select id="sevensuccessnum" databaseId="mysql" resultType="com.hzya.frame.home.entity.HomeEntity" parameterType="com.hzya.frame.home.entity.HomeEntity">
SELECT
count( id ) as normalNum,
DATE_FORMAT( create_time, '%Y-%m-%d' ) as name
@ -105,5 +121,21 @@ WHERE
create_time,
'%Y-%m-%d')
</select>
<!-- 查询 采用==查询 -->
<select id="sevensuccessnum" databaseId="oracle" resultType="com.hzya.frame.home.entity.HomeEntity" parameterType="com.hzya.frame.home.entity.HomeEntity">
SELECT
count( id ) as normalNum,
DATE_FORMAT( create_time, '%Y-%m-%d' ) as name
FROM
sys_message_manage_log_success
WHERE sts = 'Y' and status = '3' and
create_time between add_days( NOW(), -6 ) AND NOW()
GROUP BY
DATE_FORMAT( create_time, '%Y-%m-%d' )
ORDER BY
DATE_FORMAT(
create_time,
'%Y-%m-%d')
</select>
</mapper>

View File

@ -56,7 +56,7 @@
<include refid="FileDownloadEntity_Base_Column_List" />
from sys_file
<trim prefix="where" prefixOverrides="and">
<if test="id != null ">id=#{id}</if>
<if test="id != null and id !='' ">id=#{id}</if>
<if test="filename != null and filename !='' "> and filename = #{filename}</if>
<if test="filesavename != null and filesavename !='' "> and filesavename = #{filesavename}</if>
<if test="type != null and type !='' "> and type = #{type}</if>

View File

@ -702,7 +702,7 @@ where id = #{id}
<!-- </trim>-->
<!-- order by a.sorts asc-->
<!-- </select>-->
<select id="queryVoList" resultType="com.hzya.frame.sysnew.application.api.entity.SysApplicationApiVo" parameterType="com.hzya.frame.sysnew.application.api.entity.SysApplicationApiEntity">
<select id="queryVoList" databaseId="mysql" resultType="com.hzya.frame.sysnew.application.api.entity.SysApplicationApiVo" parameterType="com.hzya.frame.sysnew.application.api.entity.SysApplicationApiEntity">
select
a.id,
a.catalogue_id AS catalogueId,
@ -744,6 +744,48 @@ where id = #{id}
</trim>
order by a.sorts asc
</select>
<select id="queryVoList" databaseId="oracle" resultType="com.hzya.frame.sysnew.application.api.entity.SysApplicationApiVo" parameterType="com.hzya.frame.sysnew.application.api.entity.SysApplicationApiEntity">
select
a.id,
a.catalogue_id AS catalogueId,
(
SELECT
b.NAME
FROM
sys_application_api_type b
WHERE
b.sts = 'Y'
AND b.id = a.catalogue_id
) AS catalogueName,
a.api_name AS apiName,
a.api_code AS apiCode,
a.api_path AS apiPath,
a.destination_address AS destinationAddress,
a.api_remark AS apiRemark,
0 AS errorCount,
a.api_status AS apiStatus,
(
SELECT
WM_CONCAT( d.tripartite_system_id )
FROM
sys_application_api_auth_detail d
WHERE
d.app_id = a.app_id
AND d.api_id = a.id
and d.sts = 'Y'
) as authDetail
FROM
sys_application_api a
<trim prefix="where" prefixOverrides="and">
<if test="appId != null and appId != ''">and a.app_id = #{appId}</if>
<if test="catalogueId != null and catalogueId != ''">and a.catalogue_id = #{catalogueId}</if>
<if test="nameOrRemark != null and nameOrRemark != ''">and (a.api_name like concat('%',#{nameOrRemark},'%')
or a.api_remark like concat('%',#{nameOrRemark},'%') )
</if>
and a.sts='Y'
</trim>
order by a.sorts asc
</select>
<!-- 查询 采用==查询 -->
<select id="queryBaseName" resultMap="get-SysApplicationApiEntity-result"

View File

@ -11,9 +11,9 @@ import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.sql.DataSource;
@Configuration
@RequiredArgsConstructor
@EnableTransactionManagement
//@Configuration
//@RequiredArgsConstructor
//@EnableTransactionManagement
public class FlywayConfig {
@Value("${spring.flyway.enabled}")
@ -46,7 +46,7 @@ public class FlywayConfig {
private DataSource dataSource;
@PostConstruct
//@PostConstruct
public void migrateOrder() {
String pwd = AESUtil.decrypt(password);
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;