diff --git a/b.csv b/help/b.csv similarity index 100% rename from b.csv rename to help/b.csv diff --git a/gotidy.sh b/help/gotidy.sh similarity index 100% rename from gotidy.sh rename to help/gotidy.sh diff --git a/gowork.sh b/help/gowork.sh similarity index 100% rename from gowork.sh rename to help/gowork.sh diff --git a/help/mock生成用户.sql b/help/mock生成用户.sql new file mode 100644 index 000000000..532022315 --- /dev/null +++ b/help/mock生成用户.sql @@ -0,0 +1,31 @@ +INSERT INTO base_sys_user ( + "createTime", + "updateTime", + deleted_at, + "departmentId", + username, + password, + "headImg", + email, + remark +) SELECT + -- 过去90天内的随机创建时间 + CURRENT_TIMESTAMP - (random() * 90 * 86400 || ' seconds')::interval, + -- updateTime初始与createTime一致 + CURRENT_TIMESTAMP - (random() * 90 * 86400 || ' seconds')::interval, + NULL, -- 未删除 + -- 随机部门ID(1-100) + floor(random() * 100) + 1, + -- 随机用户名(mock_前缀+8位随机串) + CONCAT('mock_', SUBSTRING(md5(random()::text), 1, 8)), + md5('123456'), -- 固定密码 + 'https://example.com/headimg/default.png', -- 统一默认头像 + -- 随机邮箱(mock_前缀+8位随机串+随机域名) + CONCAT( + 'mock_', + SUBSTRING(md5(random()::text), 1, 8), + '@', + (array['qq.com', '163.com', 'gmail.com'])[floor(random()*3)+1] + ), + '批量生成的测试用户' +FROM generate_series(1, 1000); -- 10万条 \ No newline at end of file diff --git a/report.md b/help/report.md similarity index 100% rename from report.md rename to help/report.md diff --git a/help/查询在线时长.sql b/help/查询在线时长.sql new file mode 100644 index 000000000..151dcc5c8 --- /dev/null +++ b/help/查询在线时长.sql @@ -0,0 +1,10 @@ +SELECT + player_id, + (data->>'online_time')::int AS online_time +FROM "player_info" +-- 替换?操作符,用jsonb_exists函数判断online_time字段是否存在 +WHERE + jsonb_exists(data, 'online_time') -- 等价于 data ? 'online_time',无占位符冲突 + AND (data->>'online_time')::int > 0 +-- 按在线时间降序排序 +ORDER BY online_time DESC; \ No newline at end of file diff --git a/help/给经验池增加.sql b/help/给经验池增加.sql new file mode 100644 index 000000000..754f45814 --- /dev/null +++ b/help/给经验池增加.sql @@ -0,0 +1,9 @@ +UPDATE "player_info" +SET data = jsonb_set( + data, + '{exp_pool}', + -- 直接复用查询中的计算逻辑,确保结果一致 + to_jsonb(COALESCE((data->>'exp_pool')::int, 0) + 50000000), + true -- 字段不存在时自动初始化为10 +) +WHERE player_id = 10001; \ No newline at end of file