-- 订单类型字典：1 出库单 2 入库单 3 调拨单 等，可在【系统-数据字典】中维护
-- value = 内部编码（out/in/transfer），label = 显示名称；API 的 orderType 1/2/3 在代码中映射为 out/in/transfer

INSERT INTO `sys_dict_type` (`code`, `name`, `description`, `status`, `deleted`, `tenant_id`, `create_by`, `create_time`, `update_by`, `update_time`, `memo`)
SELECT 'sys_order_type', '订单类型', '出库单/入库单/调拨单等，与 wk_order.type 对应', 1, 0, 1, NULL, NOW(), NULL, NOW(), NULL
FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM sys_dict_type WHERE code = 'sys_order_type' LIMIT 1);

INSERT INTO `sys_dict_data` (`dict_type_id`, `dict_type_code`, `value`, `label`, `sort`, `status`, `deleted`, `tenant_id`, `create_by`, `create_time`, `update_by`, `update_time`, `memo`)
SELECT t.id, 'sys_order_type', v.val, v.lbl, v.srt, 1, 0, 1, NULL, NOW(), NULL, NOW(), NULL
FROM sys_dict_type t
CROSS JOIN (
  SELECT 'out' AS val, '出库单' AS lbl, 1 AS srt
  UNION ALL SELECT 'in', '入库单', 2
  UNION ALL SELECT 'transfer', '调拨单', 3
  UNION ALL SELECT 'revise', '库存调整', 4
  UNION ALL SELECT 'check', '盘点单', 5
) v
WHERE t.code = 'sys_order_type'
  AND NOT EXISTS (SELECT 1 FROM sys_dict_data d WHERE d.dict_type_code = 'sys_order_type' AND d.value = v.val LIMIT 1);
