This commit is contained in:
GukSang.Jin
2026-02-04 09:58:56 +08:00
parent 2bb79e7738
commit 6f2a810e00
6 changed files with 224 additions and 50 deletions

View File

@@ -0,0 +1,23 @@
-- =====================================================
-- 数据库回滚脚本normaltemperature表移除联络单号和件号字段
-- 创建时间2026-02-04
-- 说明:如果升级出现问题,使用此脚本回滚
-- =====================================================
USE fullautowaterpressure;
-- 1. 删除索引
DROP INDEX IF EXISTS `idx_contact_number` ON `normaltemperature`;
DROP INDEX IF EXISTS `idx_item_number` ON `normaltemperature`;
-- 2. 删除新增字段
ALTER TABLE `normaltemperature`
DROP COLUMN IF EXISTS `ContactNumber`,
DROP COLUMN IF EXISTS `ItemNumber`;
-- 3. 验证回滚
DESCRIBE normaltemperature;
-- =====================================================
-- 回滚完成
-- =====================================================

View File

@@ -0,0 +1,50 @@
-- =====================================================
-- 数据库升级脚本normaltemperature表添加联络单号和件号字段
-- 创建时间2026-02-04
-- 说明将barcode字段拆分为ContactNumber和ItemNumber两个独立字段
-- =====================================================
USE fullautowaterpressure;
-- 1. 添加新字段
ALTER TABLE `normaltemperature`
ADD COLUMN `ContactNumber` VARCHAR(100) NULL COMMENT '联络单号' AFTER `barcode`,
ADD COLUMN `ItemNumber` VARCHAR(100) NULL COMMENT '件号' AFTER `ContactNumber`;
-- 2. 迁移现有数据假设barcode格式为"联络单号-件号"
-- 如果barcode包含"-",则拆分
UPDATE `normaltemperature`
SET
`ContactNumber` = SUBSTRING_INDEX(`barcode`, '-', 1),
`ItemNumber` = SUBSTRING_INDEX(`barcode`, '-', -1)
WHERE `barcode` IS NOT NULL AND `barcode` LIKE '%-%';
-- 如果barcode不包含"-",则全部作为联络单号
UPDATE `normaltemperature`
SET
`ContactNumber` = `barcode`,
`ItemNumber` = ''
WHERE `barcode` IS NOT NULL AND `barcode` NOT LIKE '%-%';
-- 3. 创建索引以提高查询性能
CREATE INDEX `idx_contact_number` ON `normaltemperature`(`ContactNumber`);
CREATE INDEX `idx_item_number` ON `normaltemperature`(`ItemNumber`);
-- 4. 验证数据迁移
SELECT
COUNT(*) as total_records,
COUNT(ContactNumber) as has_contact_number,
COUNT(ItemNumber) as has_item_number,
COUNT(CASE WHEN ContactNumber IS NOT NULL AND ItemNumber IS NOT NULL THEN 1 END) as both_fields
FROM normaltemperature;
-- 5. 显示示例数据
SELECT
Id, barcode, ContactNumber, ItemNumber, CreateTime
FROM normaltemperature
ORDER BY Id DESC
LIMIT 10;
-- =====================================================
-- 升级完成
-- =====================================================

View File

@@ -0,0 +1,88 @@
-- =====================================================
-- 验证脚本:检查联络单号和件号字段是否正确
-- 创建时间2026-02-04
-- =====================================================
USE fullautowaterpressure;
-- 1. 检查normaltemperature表结构
SHOW COLUMNS FROM normaltemperature LIKE '%Contact%';
SHOW COLUMNS FROM normaltemperature LIKE '%Item%';
-- 2. 检查scandata表结构
SHOW COLUMNS FROM scandata LIKE '%Contact%';
SHOW COLUMNS FROM scandata LIKE '%Item%';
-- 3. 检查索引
SHOW INDEX FROM normaltemperature WHERE Key_name LIKE 'idx_%';
SHOW INDEX FROM scandata WHERE Key_name LIKE 'idx_%';
-- 4. 统计normaltemperature表数据
SELECT
'报表数据统计' as ,
COUNT(*) as ,
COUNT(ContactNumber) as ,
COUNT(ItemNumber) as ,
COUNT(CASE WHEN ContactNumber IS NOT NULL AND ItemNumber IS NOT NULL THEN 1 END) as ,
COUNT(CASE WHEN ContactNumber IS NULL OR ItemNumber IS NULL THEN 1 END) as
FROM normaltemperature;
-- 5. 统计scandata表数据
SELECT
'扫码数据统计' as ,
COUNT(*) as ,
COUNT(ContactNumber) as ,
COUNT(ItemNumber) as ,
COUNT(CASE WHEN ContactNumber IS NOT NULL AND ItemNumber IS NOT NULL THEN 1 END) as ,
COUNT(CASE WHEN ContactNumber IS NULL OR ItemNumber IS NULL THEN 1 END) as
FROM scandata;
-- 6. 查看normaltemperature最新10条记录
SELECT
Id,
barcode as ,
ContactNumber as ,
ItemNumber as ,
CreateTime as
FROM normaltemperature
ORDER BY Id DESC
LIMIT 10;
-- 7. 查看scandata最新10条记录
SELECT
Id,
barcode as ,
ContactNumber as ,
ItemNumber as ,
CreateTime as
FROM scandata
ORDER BY Id DESC
LIMIT 10;
-- 8. 检查数据一致性barcode应该等于ContactNumber-ItemNumber
SELECT
'数据一致性检查' as ,
COUNT(*) as
FROM normaltemperature
WHERE barcode IS NOT NULL
AND ContactNumber IS NOT NULL
AND ItemNumber IS NOT NULL
AND barcode != CONCAT(ContactNumber, '-', ItemNumber);
-- 9. 查找可能有问题的数据
SELECT
Id,
barcode,
ContactNumber,
ItemNumber,
CONCAT(ContactNumber, '-', ItemNumber) as barcode
FROM normaltemperature
WHERE barcode IS NOT NULL
AND ContactNumber IS NOT NULL
AND ItemNumber IS NOT NULL
AND barcode != CONCAT(ContactNumber, '-', ItemNumber)
LIMIT 10;
-- =====================================================
-- 验证完成
-- =====================================================