开发喵星球

若依分离版集成达梦DM8数据库(193)

一、迁移数据

将数据库和表都迁移到达梦数据库中,详情可见官网:https://eco.dameng.com/document/dm/zh-cn/faq/faq-mysql-dm8-migrate.html
若发生问题页面弹出:不支持该类型数据,原因是日期值的问题,表示日期无法插入。


无法导入的数据可复制然后insert手动插入
需在每个表前后都加上set identity_insert模式.表名 [on|off],导入sys_job表时,有个\'转义符的问题报错,把\'需换成双引号

set identity_insert ry.sys_post on; -- 开启可插入自增列
INSERT INTO ry.sys_post (post_id, post_code, post_name, post_sort, status, create_by, create_time, update_by, update_time, remark) 
VALUES ('1', 'ceo', '董事长', '1', '0', 'admin', '2023-01-12 10:19:54', '', NULL, '');
set identity_insert ry.sys_post off; -- 插入完之后关闭

注意:把`这个符号都删了,并且执行插入语句前要加上开启可插入自增列

二、添加依赖

位置:ruoyi-admin模块下的pom.xml文件

<!--达梦数据库驱动-->
<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>

三、修改数据库配置

位置:ruoyi-admin模块下的application-druid.yml

datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driverClassName: dm.jdbc.driver.DmDriver
    druid:
        master:
            url: jdbc:dm://127.0.0.1
            username: ry
            password: 123456

四、修改分页配置

位置:ruoyi-admin模块下的application.yml

pagehelper: 
  helperDialect: oracle
  supportMethodsArguments: true
  params: count=countSql 

五、执行find_in_set函数

CREATE OR REPLACE
FUNCTION SYSDBA.FIND_IN_SET(piv_str1 varchar2, piv_str2 varchar2, p_sep varchar2 := ',')
    RETURN NUMBER IS
    l_idx number := 0; -- 用于计算 piv_str2 中分隔符的位置
    str varchar2(500); -- 根据分隔符截取的子字符串
    piv_str varchar2(500) := piv_str2; -- 将 piv_str2 赋值给 piv_str
    res number:=0; -- 返回结果
    BEGIN
    -- 如果 piv_str 中没有分割符,直接判断 piv_str1 和 piv_str 是否相等,相等res=1
    IF instr(piv_str, p_sep, 1) = 0 THEN
        IF piv_str = piv_str1 THEN
        res:= 1;
        END IF;
    ELSE
        -- 循环按分隔符截取 piv_str
        LOOP
            l_idx := instr(piv_str,p_sep);
            -- 当 piv_str 中还有分隔符时
            IF l_idx > 0 THEN
                -- 截取第一个分隔符前的字段 str
                str:= substr(piv_str,1,l_idx- 1);
                -- 判断 str 和 piv_str1 是否相等,相等 res=1 并结束循环判断
                IF str = piv_str1 THEN
                    res:= 1;
                    EXIT;
                END IF;
                piv_str := substr(piv_str,l_idx+length(p_sep));
            ELSE
                -- 当截取后的 piv_str 中不存在分割符时,判断 piv_str 和 piv_str1 是否相等,相等 res=1 
                IF piv_str = piv_str1 THEN
                    res:= 1;
                END IF;
                -- 无论最后是否相等,都跳出循环
                EXIT;
            END IF;
        END LOOP;
        -- 结束循环
    END IF;
    -- 返回 res
    RETURN res;
END FIND_IN_SET;

六、修改mapper

1、修改sysNoticeMapper.xml

ruoyi-system/src/main/resources/mapper/system/SysNoticeMapper.xml文件中的cast() 函数改成to_char()

<sql id="selectNoticeVo">
    select notice_id, notice_title, notice_type, to_char(notice_content) as notice_content, status, create_by, create_time, update_by, update_time, remark
    from sys_notice
</sql>

2、GenTableMapper.xml

位置:ruoyi-generator/src/main/resources/mapper/generator/GenTableMapper.xml
selectDbTableListselectDbTableListByNamesselectTableByName删除,替换成以下内容

<sql id="selectDamengTableVo">
    select
        a.*,
        b.commentas table_comment
    from
        (
            select
                SF_GET_SCHEMA_NAME_BY_ID(SCHID) AS schema_name,
                name as table_name,
                crtdate as create_time
            from
                sys.sysobjects
            where
                type = 'SCHOBJ'
                and subType$ = 'UTAB'
                <!-- select SF_GET_SCHEMA_ID_BY_NAME('模式名') 获取模式id -->
                <!-- and schid in (154875840) -->
                and schid = CURRENT_SCHID
        ) a
    left join
        sys.systablecomments b on a.schema_name = b.schname and a.table_name = b.tvname and b.table_type = 'TABLE'
</sql>

<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">
    <include refid="selectDamengTableVo"></include>
    where a.table_name NOT LIKE 'QRTZ_%' AND a.table_name NOT LIKE 'GEN_%'
    AND a.table_name NOT IN (select table_name from gen_table)
    <if test="tableSchema != null and tableSchema != ''">
        AND lower(a.table_schema) like lower(concat('%', #{tableSchema}, '%'))
    </if>
    <if test="tableName != null and tableName != ''">
        AND lower(a.table_name) like lower(concat('%', #{tableName}, '%'))
    </if>
    <if test="tableComment != null and tableComment != ''">
        AND lower(b.table_comment) like lower(concat('%', #{tableComment}, '%'))
    </if>
    <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
        AND date_format(a.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
    </if>
    <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
        AND date_format(a.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
    </if>
    order by create_time desc
</select>

<select id="selectDbTableListByNames" resultMap="GenTableResult">
    <include refid="selectDamengTableVo"></include>
    where a.table_name NOT LIKE 'QRTZ_%' and a.table_name NOT LIKE 'GEN_%' and a.schema_name = SF_GET_SCHEMA_NAME_BY_ID(CURRENT_SCHID)
    and a.table_name in
    <foreach collection="array" item="name" open="(" separator="," close=")">
        upper(#{name})
    </foreach> 
</select>

<select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
    <include refid="selectDamengTableVo"></include>
    where b.table_comment <![CDATA[ <> ]]> '' and a.table_schema = SF_GET_SCHEMA_NAME_BY_ID(CURRENT_SCHID)
    and a.table_name = #{tableName}
</select>

3、SysMenuMapper.xml 里把`符号全部删掉

位置: ruoyi-system/src/main/resources/mapper/system/SysMenuMapper.xml

4、GenTableColumnMapper.xml,修改模式名

位置: ruoyi-generator/src/main/resources/mapper/generator/GenTableColumnMapper.xml

<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.COMMENTcolumn_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 = 换成自己的模式名 and scc.TVNAME= so.NAME
  where
        so.TYPE='SCHOBJ' and so.SUBTYPE='UTAB' and so.PID = -1
        and SF_GET_SCHEMA_NAME_BY_ID(so.SCHID) = 换成自己的模式名
        and so.NAME = #{tableName}
</select>

sql.vm

位置:ruoyi-generator/src/main/resources/vm/sql/sql.vm

-- 菜单 SQL
insert into {tableSchema}.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 {tableSchema}.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{tableSchema}.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 {tableSchema}.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{tableSchema}.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 {tableSchema}.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;
   
分类:Java/OOP 作者:无限繁荣, 吴蓉 发表于:2024-04-29 00:33:51 阅读量:122
<<   >>


powered by kaifamiao