-- 1.0.262: 再补关键对象 *_API（B3/B4 收口）
INSERT INTO mdp_entity
  (tenant_id, source_id, entity_code, entity_name, entity_type,
   source_table_name, source_api_path, target_table_name,
   sync_mode, batch_size, response_data_path, dedup_key_path, biz_key_expr,
   status, remark, create_time, update_time)
SELECT 0, (SELECT id FROM mdp_source WHERE source_code='WMS_API'),
       v.code, v.name, 'API', v.src_tbl, v.path, v.stg,
       'INCREMENTAL', 1000, 'data.list', 'bizKey', v.biz,
       1, '1.0.262 API pair', NOW(), NOW()
FROM (
  SELECT 'S1_CONTRACT_REVIEW_API' code, 'S1合同评审API' name, 'ado_contract_review' src_tbl, '/api/contract-review' path, 'mdp_stg_so' stg, 'BillNo' biz
  UNION ALL SELECT 'S1_SHIPPING_PLAN_API','S1发货计划API','ShippingPlan','/api/shipping-plan','mdp_stg_ship_trans','LotSerial'
  UNION ALL SELECT 'S2_WORK_ORDER_DETAIL_API','S2工单明细API','WorkOrdDetail','/api/work-order-detail','mdp_stg_schedule','Domain,WorkOrd,Op,ItemNum'
  UNION ALL SELECT 'S2_WORK_ORDER_ROUTING_API','S2工单工艺API','WorkOrdRouting','/api/work-order-routing','mdp_stg_schedule','Domain,WorkOrd,OP'
  UNION ALL SELECT 'S3_PURCHASE_ORDER_MASTER_API','S3采购订单主API','PurOrdMaster','/api/purchase-order-master','mdp_stg_purchase_order','Domain,PurOrd'
  UNION ALL SELECT 'S3_SHIPPER_MASTER_API','S3发货主API','scm_shd','/api/shipper-master','mdp_stg_delivery','shddh'
  UNION ALL SELECT 'S3_RECEIPT_MASTER_API','S3收货主API','PurOrdRctMaster','/api/s3-receipt-master','mdp_stg_receipt','Domain,Receiver'
) v
WHERE NOT EXISTS (SELECT 1 FROM mdp_entity e WHERE e.entity_code=v.code);
