diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/flyway/sql/mysql/V3.9.2_40__mes_xsl_raw_material_entry_fix.sql b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/flyway/sql/mysql/V3.9.2_40__mes_xsl_raw_material_entry_fix.sql new file mode 100644 index 0000000..a037765 --- /dev/null +++ b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/flyway/sql/mysql/V3.9.2_40__mes_xsl_raw_material_entry_fix.sql @@ -0,0 +1,81 @@ +-- 原料入场记录字段修正:字段类型调整 + 字典新增/更新(幂等) + +-- ===================== 1. 字段类型修正 ===================== +-- stock_balance: decimal → varchar(2)(是/否字典) +SET @col1 := (SELECT DATA_TYPE FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'mes_xsl_raw_material_entry' AND COLUMN_NAME = 'stock_balance'); +SET @ddl1 := IF(@col1 != 'varchar', + 'ALTER TABLE `mes_xsl_raw_material_entry` MODIFY COLUMN `stock_balance` varchar(2) DEFAULT NULL COMMENT ''入库结存(字典 yn:1是 0否)''', + 'SELECT 1'); +PREPARE s1 FROM @ddl1; EXECUTE s1; DEALLOCATE PREPARE s1; + +-- test_result: text → varchar(10)(检测结果字典) +SET @col2 := (SELECT COLUMN_TYPE FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'mes_xsl_raw_material_entry' AND COLUMN_NAME = 'test_result'); +SET @ddl2 := IF(@col2 = 'text', + 'ALTER TABLE `mes_xsl_raw_material_entry` MODIFY COLUMN `test_result` varchar(10) DEFAULT NULL COMMENT ''检测结果(字典 xslmes_test_result:0未检 1合格 2不合格)''', + 'SELECT 1'); +PREPARE s2 FROM @ddl2; EXECUTE s2; DEALLOCATE PREPARE s2; + +-- print_flag: varchar(2) → varchar(10)(打印标记字典) +SET @col3 := (SELECT CHARACTER_MAXIMUM_LENGTH FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'mes_xsl_raw_material_entry' AND COLUMN_NAME = 'print_flag'); +SET @ddl3 := IF(@col3 < 10, + 'ALTER TABLE `mes_xsl_raw_material_entry` MODIFY COLUMN `print_flag` varchar(10) DEFAULT NULL COMMENT ''打印标记(字典 xslmes_print_flag:1已打印 0未打印)''', + 'SELECT 1'); +PREPARE s3 FROM @ddl3; EXECUTE s3; DEALLOCATE PREPARE s3; + +-- ===================== 2. 检测结果字典(新增)===================== +INSERT INTO `sys_dict` (`id`, `dict_name`, `dict_code`, `description`, `del_flag`, `create_by`, `create_time`, `type`, `tenant_id`) +SELECT REPLACE(UUID(), '-', ''), 'MES检测结果', 'xslmes_test_result', '原料入场检测结果:未检/合格/不合格', 0, 'admin', NOW(), 0, 1002 +WHERE NOT EXISTS (SELECT 1 FROM `sys_dict` WHERE `dict_code` = 'xslmes_test_result' AND `del_flag` = 0); + +INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`) +SELECT REPLACE(UUID(), '-', ''), d.id, '未检', '0', 1, 1, 'admin', NOW() +FROM `sys_dict` d WHERE d.`dict_code` = 'xslmes_test_result' + AND NOT EXISTS (SELECT 1 FROM `sys_dict_item` i WHERE i.`dict_id` = d.id AND i.`item_value` = '0'); + +INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`) +SELECT REPLACE(UUID(), '-', ''), d.id, '合格', '1', 2, 1, 'admin', NOW() +FROM `sys_dict` d WHERE d.`dict_code` = 'xslmes_test_result' + AND NOT EXISTS (SELECT 1 FROM `sys_dict_item` i WHERE i.`dict_id` = d.id AND i.`item_value` = '1'); + +INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`) +SELECT REPLACE(UUID(), '-', ''), d.id, '不合格', '2', 3, 1, 'admin', NOW() +FROM `sys_dict` d WHERE d.`dict_code` = 'xslmes_test_result' + AND NOT EXISTS (SELECT 1 FROM `sys_dict_item` i WHERE i.`dict_id` = d.id AND i.`item_value` = '2'); + +-- ===================== 3. 检测状态字典(更新为送样/已批准)===================== +-- 删除旧值,插入新值 +DELETE i FROM `sys_dict_item` i +INNER JOIN `sys_dict` d ON d.id = i.dict_id +WHERE d.`dict_code` = 'xslmes_test_status' + AND i.`item_value` IN ('0', '1', '2'); + +UPDATE `sys_dict` SET `description` = '原料入场检测状态:送样/已批准' +WHERE `dict_code` = 'xslmes_test_status' AND `del_flag` = 0; + +INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`) +SELECT REPLACE(UUID(), '-', ''), d.id, '送样', '0', 1, 1, 'admin', NOW() +FROM `sys_dict` d WHERE d.`dict_code` = 'xslmes_test_status' + AND NOT EXISTS (SELECT 1 FROM `sys_dict_item` i WHERE i.`dict_id` = d.id AND i.`item_value` = '0'); + +INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`) +SELECT REPLACE(UUID(), '-', ''), d.id, '已批准', '1', 2, 1, 'admin', NOW() +FROM `sys_dict` d WHERE d.`dict_code` = 'xslmes_test_status' + AND NOT EXISTS (SELECT 1 FROM `sys_dict_item` i WHERE i.`dict_id` = d.id AND i.`item_value` = '1'); + +-- ===================== 4. 打印标记字典(新增)===================== +INSERT INTO `sys_dict` (`id`, `dict_name`, `dict_code`, `description`, `del_flag`, `create_by`, `create_time`, `type`, `tenant_id`) +SELECT REPLACE(UUID(), '-', ''), 'MES打印标记', 'xslmes_print_flag', '原料入场打印标记:已打印/未打印', 0, 'admin', NOW(), 0, 1002 +WHERE NOT EXISTS (SELECT 1 FROM `sys_dict` WHERE `dict_code` = 'xslmes_print_flag' AND `del_flag` = 0); + +INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`) +SELECT REPLACE(UUID(), '-', ''), d.id, '已打印', '1', 1, 1, 'admin', NOW() +FROM `sys_dict` d WHERE d.`dict_code` = 'xslmes_print_flag' + AND NOT EXISTS (SELECT 1 FROM `sys_dict_item` i WHERE i.`dict_id` = d.id AND i.`item_value` = '1'); + +INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`) +SELECT REPLACE(UUID(), '-', ''), d.id, '未打印', '0', 2, 1, 'admin', NOW() +FROM `sys_dict` d WHERE d.`dict_code` = 'xslmes_print_flag' + AND NOT EXISTS (SELECT 1 FROM `sys_dict_item` i WHERE i.`dict_id` = d.id AND i.`item_value` = '0'); diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/flyway/sql/mysql/V3.9.2_41__mes_xsl_raw_material_entry_fix2.sql b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/flyway/sql/mysql/V3.9.2_41__mes_xsl_raw_material_entry_fix2.sql new file mode 100644 index 0000000..fb05ba4 --- /dev/null +++ b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/flyway/sql/mysql/V3.9.2_41__mes_xsl_raw_material_entry_fix2.sql @@ -0,0 +1,84 @@ +-- 修复 V40 中 stock_balance decimal→varchar(2) 因数据截断失败的问题 +-- decimal 类型的 '0.00' 转字符串为 4 位,超出 varchar(2) 限制 +-- 解决方案:先清空 decimal 数据,再 ALTER;其余 V40 步骤幂等重跑 + +-- ===================== 1. 清空 stock_balance 中无效的 decimal 值 ===================== +UPDATE `mes_xsl_raw_material_entry` SET `stock_balance` = NULL; + +-- ===================== 2. stock_balance: decimal → varchar(2) ===================== +SET @col1 := (SELECT DATA_TYPE FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'mes_xsl_raw_material_entry' AND COLUMN_NAME = 'stock_balance'); +SET @ddl1 := IF(@col1 != 'varchar', + 'ALTER TABLE `mes_xsl_raw_material_entry` MODIFY COLUMN `stock_balance` varchar(2) DEFAULT NULL COMMENT ''入库结存(字典 yn:1是 0否)''', + 'SELECT 1'); +PREPARE s1 FROM @ddl1; EXECUTE s1; DEALLOCATE PREPARE s1; + +-- ===================== 3. test_result: text → varchar(10) ===================== +SET @col2 := (SELECT COLUMN_TYPE FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'mes_xsl_raw_material_entry' AND COLUMN_NAME = 'test_result'); +SET @ddl2 := IF(@col2 = 'text', + 'ALTER TABLE `mes_xsl_raw_material_entry` MODIFY COLUMN `test_result` varchar(10) DEFAULT NULL COMMENT ''检测结果(字典 xslmes_test_result:0未检 1合格 2不合格)''', + 'SELECT 1'); +PREPARE s2 FROM @ddl2; EXECUTE s2; DEALLOCATE PREPARE s2; + +-- ===================== 4. print_flag: varchar(2) → varchar(10) ===================== +SET @col3 := (SELECT CHARACTER_MAXIMUM_LENGTH FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'mes_xsl_raw_material_entry' AND COLUMN_NAME = 'print_flag'); +SET @ddl3 := IF(@col3 IS NOT NULL AND @col3 < 10, + 'ALTER TABLE `mes_xsl_raw_material_entry` MODIFY COLUMN `print_flag` varchar(10) DEFAULT NULL COMMENT ''打印标记(字典 xslmes_print_flag:1已打印 0未打印)''', + 'SELECT 1'); +PREPARE s3 FROM @ddl3; EXECUTE s3; DEALLOCATE PREPARE s3; + +-- ===================== 5. xslmes_test_result 字典(幂等)===================== +INSERT INTO `sys_dict` (`id`, `dict_name`, `dict_code`, `description`, `del_flag`, `create_by`, `create_time`, `type`, `tenant_id`) +SELECT REPLACE(UUID(), '-', ''), 'MES检测结果', 'xslmes_test_result', '原料入场检测结果:未检/合格/不合格', 0, 'admin', NOW(), 0, 1002 +WHERE NOT EXISTS (SELECT 1 FROM `sys_dict` WHERE `dict_code` = 'xslmes_test_result' AND `del_flag` = 0); + +INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`) +SELECT REPLACE(UUID(), '-', ''), d.id, '未检', '0', 1, 1, 'admin', NOW() +FROM `sys_dict` d WHERE d.`dict_code` = 'xslmes_test_result' + AND NOT EXISTS (SELECT 1 FROM `sys_dict_item` i WHERE i.`dict_id` = d.id AND i.`item_value` = '0'); + +INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`) +SELECT REPLACE(UUID(), '-', ''), d.id, '合格', '1', 2, 1, 'admin', NOW() +FROM `sys_dict` d WHERE d.`dict_code` = 'xslmes_test_result' + AND NOT EXISTS (SELECT 1 FROM `sys_dict_item` i WHERE i.`dict_id` = d.id AND i.`item_value` = '1'); + +INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`) +SELECT REPLACE(UUID(), '-', ''), d.id, '不合格', '2', 3, 1, 'admin', NOW() +FROM `sys_dict` d WHERE d.`dict_code` = 'xslmes_test_result' + AND NOT EXISTS (SELECT 1 FROM `sys_dict_item` i WHERE i.`dict_id` = d.id AND i.`item_value` = '2'); + +-- ===================== 6. xslmes_test_status 字典更新(送样/已批准,幂等)===================== +DELETE i FROM `sys_dict_item` i +INNER JOIN `sys_dict` d ON d.id = i.dict_id +WHERE d.`dict_code` = 'xslmes_test_status' + AND i.`item_value` IN ('0', '1', '2'); + +UPDATE `sys_dict` SET `description` = '原料入场检测状态:送样/已批准' +WHERE `dict_code` = 'xslmes_test_status' AND `del_flag` = 0; + +INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`) +SELECT REPLACE(UUID(), '-', ''), d.id, '送样', '0', 1, 1, 'admin', NOW() +FROM `sys_dict` d WHERE d.`dict_code` = 'xslmes_test_status' + AND NOT EXISTS (SELECT 1 FROM `sys_dict_item` i WHERE i.`dict_id` = d.id AND i.`item_value` = '0'); + +INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`) +SELECT REPLACE(UUID(), '-', ''), d.id, '已批准', '1', 2, 1, 'admin', NOW() +FROM `sys_dict` d WHERE d.`dict_code` = 'xslmes_test_status' + AND NOT EXISTS (SELECT 1 FROM `sys_dict_item` i WHERE i.`dict_id` = d.id AND i.`item_value` = '1'); + +-- ===================== 7. xslmes_print_flag 字典(幂等)===================== +INSERT INTO `sys_dict` (`id`, `dict_name`, `dict_code`, `description`, `del_flag`, `create_by`, `create_time`, `type`, `tenant_id`) +SELECT REPLACE(UUID(), '-', ''), 'MES打印标记', 'xslmes_print_flag', '原料入场打印标记:已打印/未打印', 0, 'admin', NOW(), 0, 1002 +WHERE NOT EXISTS (SELECT 1 FROM `sys_dict` WHERE `dict_code` = 'xslmes_print_flag' AND `del_flag` = 0); + +INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`) +SELECT REPLACE(UUID(), '-', ''), d.id, '已打印', '1', 1, 1, 'admin', NOW() +FROM `sys_dict` d WHERE d.`dict_code` = 'xslmes_print_flag' + AND NOT EXISTS (SELECT 1 FROM `sys_dict_item` i WHERE i.`dict_id` = d.id AND i.`item_value` = '1'); + +INSERT INTO `sys_dict_item` (`id`, `dict_id`, `item_text`, `item_value`, `sort_order`, `status`, `create_by`, `create_time`) +SELECT REPLACE(UUID(), '-', ''), d.id, '未打印', '0', 2, 1, 'admin', NOW() +FROM `sys_dict` d WHERE d.`dict_code` = 'xslmes_print_flag' + AND NOT EXISTS (SELECT 1 FROM `sys_dict_item` i WHERE i.`dict_id` = d.id AND i.`item_value` = '0');