INSERT INTO wh_warehouse (warehouse_code, warehouse_name, warehouse_type, manager_employee_id, status, remark)
SELECT 'WH-SCRAP-01', '废料库', 'SCRAP', NULL, 'ACTIVE', '生产废料、边角料、委外废料、报废品等废料库存'
WHERE NOT EXISTS (SELECT 1 FROM wh_warehouse WHERE warehouse_code = 'WH-SCRAP-01');

UPDATE wh_warehouse
SET warehouse_name = '废料库',
    warehouse_type = 'SCRAP',
    status = 'ACTIVE',
    remark = '生产废料、边角料、委外废料、报废品等废料库存'
WHERE warehouse_code = 'WH-SCRAP-01';

INSERT INTO wh_location (
  warehouse_id,
  location_code,
  location_name,
  zone_name,
  is_default,
  is_locked,
  status,
  remark
)
SELECT
  (SELECT id FROM wh_warehouse WHERE warehouse_code = 'WH-SCRAP-01'),
  'SCR-E-01',
  '废料暂存位',
  'E区',
  1,
  0,
  'ACTIVE',
  '废料库默认库位'
WHERE NOT EXISTS (
  SELECT 1
  FROM wh_location
  WHERE warehouse_id = (SELECT id FROM wh_warehouse WHERE warehouse_code = 'WH-SCRAP-01')
    AND location_code = 'SCR-E-01'
);

UPDATE wh_location
SET location_name = '废料暂存位',
    zone_name = 'E区',
    is_default = 1,
    is_locked = 0,
    status = 'ACTIVE',
    remark = '废料库默认库位'
WHERE warehouse_id = (SELECT id FROM wh_warehouse WHERE warehouse_code = 'WH-SCRAP-01')
  AND location_code = 'SCR-E-01';
