-- S1 MDP：补登记产品设计三实体（与 S1MdpEntityConfig 对齐）
-- 幂等：ON DUPLICATE KEY UPDATE

SET @tenant_id := 0;
SET @source_id := (SELECT id FROM mdp_source WHERE tenant_id = @tenant_id AND source_code = 'AIDOPDEV_MYSQL' LIMIT 1);

INSERT INTO mdp_entity
(tenant_id, source_id, entity_code, entity_name, entity_type, source_table_name, target_table_name, sync_mode, incr_column, batch_size, status, remark)
VALUES
(@tenant_id, @source_id, 'S1_PRODUCT_DESIGN', 'S1产品设计主表', 'TABLE', 'ado_product_design', 'mdp_stg_so', 'INCR', 'UpdateTime', 5000, 1, '产品设计主表，进入订单标准层'),
(@tenant_id, @source_id, 'S1_PRODUCT_DESIGN_BOM', 'S1产品设计BOM', 'TABLE', 'ado_product_design_bom', 'mdp_stg_so', 'INCR', 'UpdateTime', 5000, 1, '产品设计BOM，进入订单标准层'),
(@tenant_id, @source_id, 'S1_PRODUCT_DESIGN_ROUTING', 'S1产品设计工艺路线', 'TABLE', 'ado_product_design_routing', 'mdp_stg_so', 'INCR', 'UpdateTime', 5000, 1, '产品设计工艺路线，进入订单标准层')
ON DUPLICATE KEY UPDATE
    source_id = VALUES(source_id),
    entity_name = VALUES(entity_name),
    entity_type = VALUES(entity_type),
    source_table_name = VALUES(source_table_name),
    target_table_name = VALUES(target_table_name),
    sync_mode = VALUES(sync_mode),
    incr_column = VALUES(incr_column),
    batch_size = VALUES(batch_size),
    status = VALUES(status),
    remark = VALUES(remark),
    update_time = CURRENT_TIMESTAMP;
