From 7a7b0e6cc9b0a598c6f9b5d770e55cc3e5451214 Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Wed, 28 Feb 2024 11:57:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E6=95=B0=E6=8D=AE=E6=8A=BD=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1096897488453632]表单实例数据抽离 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1096897488453632 --- .../changelog/2024-02-23/neatlogic_tenant.sql | 136 ++++++------------ 1 file changed, 47 insertions(+), 89 deletions(-) diff --git a/src/main/resources/neatlogic/resources/framework/changelog/2024-02-23/neatlogic_tenant.sql b/src/main/resources/neatlogic/resources/framework/changelog/2024-02-23/neatlogic_tenant.sql index 795225a1d..8872b885a 100644 --- a/src/main/resources/neatlogic/resources/framework/changelog/2024-02-23/neatlogic_tenant.sql +++ b/src/main/resources/neatlogic/resources/framework/changelog/2024-02-23/neatlogic_tenant.sql @@ -1,18 +1,27 @@ -CREATE TABLE IF NOT EXISTS `form_attribute_data` ( - `id` bigint NOT NULL COMMENT 'id', - `form_uuid` char(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '表单uuid', - `handler` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '类型', - `attribute_label` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '属性名', - `attribute_uuid` char(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '属性uuid', - `data` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '属性值,json格式', +ALTER TABLE `processtask_formattribute_data` + ADD COLUMN `id` BIGINT NOT NULL AUTO_INCREMENT FIRST, + ADD KEY(`id`), +AUTO_INCREMENT=0; + +DROP TABLE IF EXISTS `form_attribute_data`; + +CREATE TABLE `form_attribute_data` ( + `id` BIGINT NOT NULL COMMENT 'id', + `form_uuid` CHAR(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '表单uuid', + `handler` VARCHAR(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '类型', + `attribute_label` VARCHAR(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '属性名', + `attribute_uuid` CHAR(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '属性uuid', + `data` MEDIUMTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '属性值,json格式', PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='表单实例属性当前值'; +) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='表单实例属性当前值'; -CREATE TABLE IF NOT EXISTS `processtask_formattribute` ( - `processtask_id` bigint NOT NULL COMMENT '工单id', - `form_attribute_data_id` bigint NOT NULL COMMENT '表单属性值id', +DROP TABLE IF EXISTS `processtask_formattribute`; + +CREATE TABLE `processtask_formattribute` ( + `processtask_id` BIGINT NOT NULL COMMENT '工单id', + `form_attribute_data_id` BIGINT NOT NULL COMMENT '表单属性值id', PRIMARY KEY (`processtask_id`,`form_attribute_data_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='工单与表单属性值关系表'; +) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='工单与表单属性值关系表'; DROP FUNCTION IF EXISTS `generateSnowflakeId`; @@ -60,84 +69,29 @@ DROP PROCEDURE IF EXISTS `handleProcessTaskFormAttributeData`; DELIMITER $$ CREATE PROCEDURE handleProcessTaskFormAttributeData() BEGIN - DECLARE rowNum BIGINT DEFAULT 0; - DECLARE currentPage INT DEFAULT 1; - DECLARE pageSize INT DEFAULT 100; - DECLARE pageCount INT DEFAULT 0; - - SELECT COUNT(1) INTO rowNum FROM `processtask_formattribute_data`; - IF rowNum > 0 THEN - SET @lastStamp = -1; - SET @sequence = 0; + DECLARE v_id BIGINT DEFAULT generateSnowflakeId(); + + UPDATE `processtask_formattribute_data` SET `id` = `id` + v_id; + + INSERT INTO `form_attribute_data` (`id`, `form_uuid`, `handler`, `attribute_label`, `attribute_uuid`, `data`) + SELECT + a.`id`, + b.`form_uuid`, + IFNULL(a.`type`, ''), + IFNULL(a.`attribute_label`, ''), + a.`attribute_uuid`, + IFNULL(a.`data`, '') + FROM `processtask_formattribute_data` a + JOIN `processtask_form` b ON b.`processtask_id` = a.`processtask_id` + ORDER BY a.`processtask_id`, a.`sort`; + + INSERT INTO `processtask_formattribute` (`processtask_id`, `form_attribute_data_id`) + SELECT + a.`processtask_id`, + a.`id` + FROM `processtask_formattribute_data` a + ORDER BY a.`processtask_id`, a.`sort`; - SET pageCount = CEIL(rowNum / pageSize); - WHILE currentPage <= pageCount DO - BEGIN - DECLARE done INT DEFAULT FALSE; - - DECLARE v_id BIGINT; - DECLARE v_processTaskId BIGINT; - DECLARE v_type VARCHAR(50); - DECLARE v_attributeLabel VARCHAR(50); - DECLARE v_attributeUuid CHAR(32); - DECLARE v_formUuid CHAR(32); - DECLARE v_data MEDIUMTEXT; - - DECLARE startNum INT DEFAULT (currentPage - 1) * pageSize; - - DECLARE cur CURSOR FOR SELECT a.`processtask_id`, a.`type`, a.`attribute_label`, a.`attribute_uuid`, a.`data`, b.`form_uuid` - FROM `processtask_formattribute_data` a - JOIN `processtask_form` b ON b.`processtask_id` = a.`processtask_id` - ORDER BY a.`processtask_id`, a.`sort` - LIMIT startNum, pageSize; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - - SET @batchInsertSql_form_attribute_data = NULL; - SET @batchInsertSql_processtask_formattribute = NULL; - - OPEN cur; - read_loop: LOOP - FETCH cur INTO v_processTaskId, v_type, v_attributeLabel, v_attributeUuid, v_data, v_formUuid; - IF done THEN - LEAVE read_loop; - END IF; - IF v_type IS NULL THEN - SET v_type = ''; - END IF; - IF v_attributeLabel IS NULL THEN - SET v_attributeLabel = ''; - END IF; - IF v_data IS NULL THEN - SET v_data = ''; - END IF; - SET v_id = generateSnowflakeId(); - IF @batchInsertSql_form_attribute_data IS NULL THEN - SET @batchInsertSql_form_attribute_data = CONCAT('INSERT INTO `form_attribute_data` (`id`, `form_uuid`, `handler`, `attribute_label`, `attribute_uuid`, `data`) VALUES', ' (', v_id, ', \'', v_formUuid, '\', \'', v_type, '\', \'', v_attributeLabel, '\', \'', v_attributeUuid, '\', \'', v_data, '\')'); - ELSE - SET @batchInsertSql_form_attribute_data = CONCAT(@batchInsertSql_form_attribute_data, ', (', v_id, ', \'', v_formUuid, '\', \'', v_type, '\', \'', v_attributeLabel, '\', \'', v_attributeUuid, '\', \'', v_data, '\')'); - END IF; - IF @batchInsertSql_processtask_formattribute IS NULL THEN - SET @batchInsertSql_processtask_formattribute = CONCAT('INSERT INTO `processtask_formattribute` (`processtask_id`, `form_attribute_data_id`) VALUES', ' (', v_processTaskId, ',', v_id, ')'); - ELSE - SET @batchInsertSql_processtask_formattribute = CONCAT(@batchInsertSql_processtask_formattribute, ', (', v_processTaskId, ',', v_id, ')'); - END IF; - END LOOP; - CLOSE cur; - - PREPARE stmt_1 FROM @batchInsertSql_form_attribute_data; - EXECUTE stmt_1; - DEALLOCATE PREPARE stmt_1; - PREPARE stmt_2 FROM @batchInsertSql_processtask_formattribute; - EXECUTE stmt_2; - DEALLOCATE PREPARE stmt_2; - - SET @batchInsertSql_form_attribute_data = NULL; - SET @batchInsertSql_processtask_formattribute = NULL; - END; - SET currentPage = currentPage + 1; - END WHILE; - END IF; END $$ DELIMITER ; @@ -146,3 +100,7 @@ CALL handleProcessTaskFormAttributeData(); DROP PROCEDURE `handleProcessTaskFormAttributeData`; DROP FUNCTION `generateSnowflakeId`; + +ALTER TABLE `processtask_formattribute_data` +DROP COLUMN `id`, +DROP INDEX `id`; -- Gitee From b117930534cd78374892dbeeb536a6e8ed708bf9 Mon Sep 17 00:00:00 2001 From: linbangquan <1437892690@qq.com> Date: Wed, 28 Feb 2024 11:58:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E6=95=B0=E6=8D=AE=E6=8A=BD=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1096897488453632]表单实例数据抽离 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1096897488453632 --- .../changelog/{2024-02-23 => 2024-02-22}/neatlogic_tenant.sql | 0 .../framework/changelog/{2024-02-23 => 2024-02-22}/version.json | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/main/resources/neatlogic/resources/framework/changelog/{2024-02-23 => 2024-02-22}/neatlogic_tenant.sql (100%) rename src/main/resources/neatlogic/resources/framework/changelog/{2024-02-23 => 2024-02-22}/version.json (100%) diff --git a/src/main/resources/neatlogic/resources/framework/changelog/2024-02-23/neatlogic_tenant.sql b/src/main/resources/neatlogic/resources/framework/changelog/2024-02-22/neatlogic_tenant.sql similarity index 100% rename from src/main/resources/neatlogic/resources/framework/changelog/2024-02-23/neatlogic_tenant.sql rename to src/main/resources/neatlogic/resources/framework/changelog/2024-02-22/neatlogic_tenant.sql diff --git a/src/main/resources/neatlogic/resources/framework/changelog/2024-02-23/version.json b/src/main/resources/neatlogic/resources/framework/changelog/2024-02-22/version.json similarity index 100% rename from src/main/resources/neatlogic/resources/framework/changelog/2024-02-23/version.json rename to src/main/resources/neatlogic/resources/framework/changelog/2024-02-22/version.json -- Gitee