Initial commit of akmon project
This commit is contained in:
44
insert_mock_devices_200.sql
Normal file
44
insert_mock_devices_200.sql
Normal file
@@ -0,0 +1,44 @@
|
||||
-- 批量插入200个模拟手环数据
|
||||
-- 从 ak_users 中选取尚未绑定 wristband 的用户
|
||||
-- watch_id 从 10000 开始递增
|
||||
-- device_name 格式为 "手环-10000"
|
||||
|
||||
WITH target_users AS (
|
||||
SELECT id
|
||||
FROM public.ak_users u
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM public.ak_devices d
|
||||
WHERE d.user_id = u.id
|
||||
AND d.device_type = 'wristband'
|
||||
)
|
||||
LIMIT 200
|
||||
),
|
||||
users_with_watch_id AS (
|
||||
SELECT
|
||||
id AS user_id,
|
||||
(ROW_NUMBER() OVER (ORDER BY id)) + 9999 AS watch_id
|
||||
FROM target_users
|
||||
)
|
||||
INSERT INTO public.ak_devices (
|
||||
id,
|
||||
user_id,
|
||||
device_type,
|
||||
device_name,
|
||||
device_mac,
|
||||
bind_time,
|
||||
status,
|
||||
extra,
|
||||
watch_id
|
||||
)
|
||||
SELECT
|
||||
gen_random_uuid(), -- 生成随机UUID作为设备ID
|
||||
user_id, -- 使用真实的用户ID
|
||||
'wristband',
|
||||
'手环-' || watch_id,
|
||||
'FAKE-MAC-' || watch_id,
|
||||
NOW(),
|
||||
'active',
|
||||
'{"note": "Generated for demo class", "source": "mock-seed"}'::jsonb,
|
||||
watch_id
|
||||
FROM users_with_watch_id;
|
||||
Reference in New Issue
Block a user