Files
yinnihailiang_one/lms/docs/testing/need-empty-axis/prepare-production-sb-points.sql

44 lines
2.1 KiB
MySQL
Raw Normal View History

-- 目标服务器:10.100.9.6。请先在数据库客户端选中实际生产业务库。
-- 已确认规则:空轴位=point_code_K,满轴位=point_code_M。
-- 只补缺失编码;不修改已有编码、库存状态或ACS开关。
-- 分段执行:先检查并导出待修改记录作为备份,再执行更新,核验后提交。
-- 1. 确认当前连接与待修改记录。主点位为空的记录无法自动补齐。
SELECT @@hostname AS server_hostname, @@port AS server_port, DATABASE() AS database_name;
SELECT point_id, point_code, empty_point_code, full_point_code
FROM st_ivt_sbpointivt
WHERE empty_point_code IS NULL OR TRIM(empty_point_code)=''
OR full_point_code IS NULL OR TRIM(full_point_code)='';
-- 2. 在同一连接开启事务并更新。
START TRANSACTION;
UPDATE st_ivt_sbpointivt
SET empty_point_code=CASE WHEN empty_point_code IS NULL OR TRIM(empty_point_code)=''
THEN CONCAT(point_code,'_K') ELSE empty_point_code END,
full_point_code=CASE WHEN full_point_code IS NULL OR TRIM(full_point_code)=''
THEN CONCAT(point_code,'_M') ELSE full_point_code END
WHERE point_code IS NOT NULL AND TRIM(point_code)<>''
AND (empty_point_code IS NULL OR TRIM(empty_point_code)=''
OR full_point_code IS NULL OR TRIM(full_point_code)='');
SELECT ROW_COUNT() AS updated_devices;
-- 3. 核验缺失数和明细。
SELECT COUNT(*) AS total,
SUM(empty_point_code IS NULL OR TRIM(empty_point_code)='') AS missing_empty,
SUM(full_point_code IS NULL OR TRIM(full_point_code)='') AS missing_full
FROM st_ivt_sbpointivt;
SELECT point_id,point_code,empty_point_code,full_point_code
FROM st_ivt_sbpointivt ORDER BY point_code;
-- 检查空轴/满轴编码是否重复;正常应无结果。
SELECT axis_code,COUNT(*) AS occurrences FROM (
SELECT empty_point_code AS axis_code FROM st_ivt_sbpointivt
UNION ALL
SELECT full_point_code AS axis_code FROM st_ivt_sbpointivt
) codes WHERE axis_code IS NOT NULL AND TRIM(axis_code)<>''
GROUP BY axis_code HAVING COUNT(*)>1;
-- 4. 核验通过后,在同一连接单独执行 COMMIT;异常则执行 ROLLBACK。
-- COMMIT;
-- ROLLBACK;