首页 > 数据库 >RuoYi-Vue切换达梦数据库(二)

RuoYi-Vue切换达梦数据库(二)

时间:2022-10-19 08:44:37浏览次数:81  
标签:Vue NAME create RuoYi so time table 达梦 name

一、JDBC依赖

代码部分适配 RuoYi-Vue v3.8.4前后端分离版

1、修改admin模块下的pom.xml文件

Maven仓库中存在,直接替换

注意jdbc包的版本:Dm7JdbcDriver18中7是DM数据库的版本,18是JDK版本。

<!--达梦数据库驱动-->
<dependency>
    <groupId>com.dameng</groupId>
    <artifactId>Dm8JdbcDriver18</artifactId>
    <version>8.1.1.49</version>
</dependency>
        
<!--达梦数据库方言-->
<dependency>
    <groupId>com.dameng</groupId>
    <artifactId>DmDialect-for-hibernate5.3</artifactId>
    <version>8.1.1.49</version>
</dependency>

二、更改数据库链接配置

更改driverClassName,url,username,password

spring:
    datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        driverClassName: dm.jdbc.driver.DmDriver
        druid:
            # 主库数据源
            master:
                url: jdbc:dm://localhost:5236
                username: RY_VUE
                password: 123456789

三、更改SQL函数

先运行起来、未发现什么报错

接下来就从登录开始每个功能都进行增删改查的操作

下面是需要调整的内容:

1、SysMenuMapper.xml文件

selectMenuVo、selectMenuTreeAll、selectMenuListByUserId、selectMenuTreeByUserId、updateMenu、insertMenu方法中的 `query`

用单引号括起,被当成字符串,报语法错误。可更改单引号为双引号或者直接去掉单引号。

2、SysDeptMapper.xml文件

selectChildrenDeptById方法中find_in_set函数,可替换成instr函数

// 原始
<select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult"> select * from sys_dept where find_in_set(#{deptId}, ancestors) </select>
// 修改后
<select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult"> select * from sys_dept where instr(','||ancestors||',' , ','|| #{deptId} || ',') </select>
3、SysNoticeMapper.xml文件

表SYS_NOTICE字段 NOTICE_CONTENT 在迁移过程中由mysql的 longblob类型 变成DM中的BLOB类型

selectNoticeVo函数中查询SQL将BLOG类型转换成char导致语法出错

可将类型BLOG改成CLOB,更改前将表中数据清空;

再更改SQL中的 cast 函数,用 TO_CHAR 代替

// 原始
<sql id="selectNoticeVo"> select notice_id, notice_title, notice_type, cast(notice_content as char) as notice_content, status, create_by, create_time, update_by, update_time, remark from sys_notice </sql>
// 修改后
<sql id="selectNoticeVo"> select notice_id, notice_title, notice_type, cast(notice_content as char) as notice_content, status, create_by, create_time, update_by, update_time, remark from sys_notice </sql>
4、GenTableMapper.xml 文件

代码生成功能改动较大,需要重写针对DM重新对表信息、字段信息的SQL

在DM中查询表和列定义信息的简要说明:

SYS.SYSOBJECTS,记录系统中所有对象的信息,表定义信息从这里获取;
SYS.SYSTABLECOMMENTS,记录表或视图的注释信息;
SYS.SYSCOLUMNS,记录列定义信息;
SYS.SYSCOLUMNCOMMENTS,记录列的注释信息;
获取当前模式名称:SELECT SF_GET_SCHEMA_NAME_BY_ID(CURRENT_SCHID);

a)selectDbTableList 方法
// 原始
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">   select table_name, table_comment, create_time, update_time from information_schema.tables   where table_schema = (select database())   AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'   AND table_name NOT IN (select table_name from gen_table)   <if test="tableName != null and tableName != ''">     AND lower(table_name) like lower(concat('%', #{tableName}, '%'))   </if>   <if test="tableComment != null and tableComment != ''">     AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))   </if>   <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->     AND date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')   </if>   <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->     AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')   </if>   order by create_time desc </select>
// 修改后
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">   select so.NAME table_name, st.COMMENT$ table_comment, so.CRTDATE create_time from SYS.SYSOBJECTS so left join SYS.SYSTABLECOMMENTS st on so.NAME = st.TVNAME and st.TABLE_TYPE = 'TABLE' and st.SCHNAME = (SELECT SF_GET_SCHEMA_NAME_BY_ID(CURRENT_SCHID))   where so.TYPE$='SCHOBJ' and so.SUBTYPE$='UTAB' and so.PID = -1 and INSTR(so.NAME,'##') = 0 and so.SCHID = (select ID from SYS.SYSOBJECTS where TYPE$='SCH' and NAME= (SELECT SF_GET_SCHEMA_NAME_BY_ID(CURRENT_SCHID))) and so.NAME NOT LIKE 'QRTZ_%' AND so.NAME NOT LIKE 'gen_%'   and so.NAME NOT IN (select table_name from gen_table)   <if test="tableName != null and tableName != ''">     and lower(so.NAME) like lower(concat('%', #{tableName}, '%'))   </if>   <if test="tableComment != null and tableComment != ''">     and lower(st.COMMENT$) like lower(concat('%', #{tableComment}, '%'))   </if>   order by so.CRTDATE desc </select>
b)selectDbTableListByNames 方法
// 原始
<select id="selectDbTableListByNames" resultMap="GenTableResult">   select table_name, table_comment, create_time, update_time from information_schema.tables   where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())   and table_name in   <foreach collection="array" item="name" open="(" separator="," close=")">     #{name}   </foreach> </select>
// 修改后
<select id="selectDbTableListByNames" resultMap="GenTableResult">   select so.NAME table_name, st.COMMENT$ table_comment, so.CRTDATE create_time from SYS.SYSOBJECTS so left join SYS.SYSTABLECOMMENTS st on so.NAME = st.TVNAME and st.TABLE_TYPE = 'TABLE' and st.SCHNAME = (SELECT SF_GET_SCHEMA_NAME_BY_ID(CURRENT_SCHID))   where so.TYPE$='SCHOBJ' and so.SUBTYPE$='UTAB' and so.PID = -1 and INSTR(so.NAME,'##') = 0 and so.SCHID = (select ID from SYS.SYSOBJECTS where TYPE$='SCH' and NAME= (SELECT SF_GET_SCHEMA_NAME_BY_ID(CURRENT_SCHID))) and so.NAME NOT LIKE 'qrtz_%' and so.NAME NOT LIKE 'gen_%'   and so.NAME in   <foreach collection="array" item="name" open="(" separator="," close=")">     #{name}   </foreach> </select>
c)selectTableByName 方法

......好像没用到,删掉

5、GenTableColumnMapper.xml 文件

selectDbTableColumnsByName 方法

// 原始
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">   select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type   from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})   order by ordinal_position </select>
// 修改后
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">   select sc.NAME column_name, (case when sc.INFO2 = 1 then '1' else '0' end) is_pk, sc.COLID sort, scc.COMMENT$ column_comment, (case when sc.INFO2 = 1 then '1' else '0' end) as is_increment, sc.TYPE$ column_type   from SYS.SYSCOLUMNS sc left join SYS.SYSOBJECTS so on sc.ID = so.ID left join SYS.SYSCOLUMNCOMMENTS SCC on sc.NAME = scc.COLNAME and scc.TABLE_TYPE = 'TABLE' and scc.SCHNAME = (select sys_context('USERENV','CURRENT_SCHEMA')) and scc.TVNAME= so.NAME   where so.TYPE$='SCHOBJ' and so.SUBTYPE$='UTAB' and so.PID = -1 and so.SCHID = (select ID from SYS.SYSOBJECTS where TYPE$='SCH' and NAME= (select sys_context('USERENV','CURRENT_SCHEMA'))) and so.NAME = #{tableName} </select>
6、sql.vm适配DM

适配模板中声明变量的方式,下面是完整内容:

-- 菜单 SQL
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 0, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', sysdate(), '', null, '${functionName}菜单');

DECLARE
-- 按钮父菜单ID
parentId BIGINT := @@IDENTITY;

BEGIN
-- 按钮 SQL
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}查询', parentId, '1',  '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:query','#', 'admin', sysdate(), '', null, '');

insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}新增', parentId, '2',  '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:add','#', 'admin', sysdate(), '', null, '');

insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}修改', parentId, '3',  '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:edit','#', 'admin', sysdate(), '', null, '');

insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}删除', parentId, '4',  '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:remove','#', 'admin', sysdate(), '', null, '');

insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('${functionName}导出', parentId, '5',  '#', '', 1, 0, 'F', '0', '0', '${permissionPrefix}:export','#', 'admin', sysdate(), '', null, '');
END;

 到现在基本上所有的功能都没报错了。可能会有遗漏也难免,遇到问题再解决吧。

参考

[1]. 解决达梦数据库如何查找表字段名。

[2]. RuoYi项目适配达梦数据库

标签:Vue,NAME,create,RuoYi,so,time,table,达梦,name
From: https://www.cnblogs.com/ryuug/p/16801973.html

相关文章

  • vue3+vite+ts自动引入api和组件
    安装cnpminstallunplugin-auto-importunplugin-vue-components-d配置//自动导入compositionapi和生成全局typescript说明importAutoImportfrom'unplugin-au......
  • 我的Vue之旅 07 Axios + Golang + Sqlite3 实现简单评论机制
    第三期·使用Vue3.1+Axios+Golang+Sqlite3实现简单评论机制效果图CommentArea.vue我们需要借助js的Data对象把毫秒时间戳转化成UTCString()。并在模板......
  • 我的Vue之旅 06 超详细、仿 itch.io 主页设计(Mobile)
    第二期·使用Vue3.1+TypeScript+Router+Tailwind.css仿itch.io平台主页。我的主题HapiGames是仿itch.io的indiegamehostingmarketplace。效果图......
  • 2022.10.18 - 前端Vue项目部署文件上线
    在terminal终端连接Linux服务器mac通过scp特定端口上传文件到linux服务器命令:scp-r-P10017/Users/yehudalee/Desktop/多测/portal-ui/dist/*[email protected].......
  • Vue 插件:VueRouter
    VueRouter是一个Vue插件,用于实现SPA(singlepagewebapplication)应用。SPA(singlepagewebapplication)应用,即单页面应用。整个应用只有一个.html文件,通常命名为......
  • vue 双向数据绑定
    vue.js是采用数据劫持结合发布者-订阅者模式的方式,通过Object.defineProperty()来劫持各个属性的setter,getter,在数据变动时发布消息给订阅者,触发相应的监听回调。具体步骤......
  • Vuex状态管理-mapState的基本用法详细介绍
    Vuex状态管理-mapState的基本用法详细介绍:https://blog.csdn.net/chenjie9230/article/details/108883055?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.......
  • 三阶段 vue 路由 $route 和 $router 的区别
    1.这是vue-router提供给我们的实例实例的两个属性(api)2.$route是路由对象,一般是获取动态参数|querythis.$route.params.idthis./$route.title ......
  • vue项目添加页面加载loding进度条效果
    Vue项目的优化过程中需要添加NProgress加载loding进度条效果一、进度条效果我们要实现的效果就是,当我们点击每一个菜单,加载相应的页面时,在页面顶部中间会有一个加载的......
  • Vue.nextTick核心原理
    相信大家在写vue项目的时候,一定会发现一个神奇的api,Vue.nextTick。为什么说它神奇呢,那是因为在你做某些操作不生效时,将操作写在Vue.nextTick内,就神奇的生效了。那这是什么......