feat: 全系统优化 — 并发控制 + 冗余清理 + 数据流修复 + 全面测试
核心修复: - 状态机加 SELECT FOR UPDATE 行锁,消除并发竞态 - hss_md_staff 加 role 列,登录从数据库读取真实角色 - 申请重复校验排除自身,全流程 20 步闭环通过 - 派单 SQL 修复 + 支付状态机过渡 + 完成服务 plan_item_id 修复 并发控制新增: - RedisLockService (SET NX PX + Lua 安全解锁) - RateLimiterService (Redis 滑动窗口 + API 拦截器) - TransactionIsolationConfig (SERIALIZABLE for 支付回调) - MqttPublisher (异步队列 + JDK TCP 探测) - ObjectStorageService (AWS SigV4 预签名, 纯 JDK) 冗余清理: - 删除 6 个死代码文件 (~620 行) - hutool-all → JDK MessageDigest, 去 MapStruct, 去 jsr310 - haversine 提取到 GeoUtil, count/round 提取到 JdbcUtil - 创建 platform layout 组件 前端修复: - 登录页移除角色选择器, 由后端 JWT 返回 - 移除 ClientOnly 包裹, 页面正常渲染 - SPA fallback Nginx 配置修复 Docker: 运行时镜像 eclipse-temurin:17-jre-jammy (缩小 ~300MB) 文档: 新增系统实现与修复报告.md Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
76
hss-home-service/website/tests/load/k6-load-test.js
Normal file
76
hss-home-service/website/tests/load/k6-load-test.js
Normal file
@@ -0,0 +1,76 @@
|
||||
import http from 'k6/http';
|
||||
import { check, sleep, group } from 'k6';
|
||||
|
||||
const BASE = 'http://172.31.12.249';
|
||||
const API = BASE + ':18080/api/hss';
|
||||
const WEB = BASE + ':3080';
|
||||
|
||||
export const options = {
|
||||
stages: [
|
||||
{ duration: '10s', target: 5 }, // Ramp up to 5 users
|
||||
{ duration: '30s', target: 20 }, // Ramp up to 20 users
|
||||
{ duration: '30s', target: 20 }, // Stay at 20 users
|
||||
{ duration: '10s', target: 0 }, // Ramp down
|
||||
],
|
||||
thresholds: {
|
||||
http_req_duration: ['p(95)<2000'], // 95% requests < 2s
|
||||
http_req_failed: ['rate<0.05'], // < 5% error rate
|
||||
},
|
||||
};
|
||||
|
||||
const H = {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Tenant-Id': '1', 'X-Org-Id': '1', 'X-User-Role': 'ADMIN',
|
||||
};
|
||||
|
||||
export default function () {
|
||||
group('Marketing Pages', () => {
|
||||
for (const p of ['/', '/demo', '/solution', '/contact', '/about', '/capabilities', '/service-loop']) {
|
||||
const r = http.get(WEB + p);
|
||||
check(r, { [`${p} is 200`]: (r) => r.status === 200 });
|
||||
}
|
||||
});
|
||||
|
||||
group('Platform Pages', () => {
|
||||
for (const p of ['/platform/login', '/platform']) {
|
||||
const r = http.get(WEB + p);
|
||||
check(r, { [`${p} is 200`]: (r) => r.status === 200 || r.status === 301 || r.status === 302 });
|
||||
}
|
||||
});
|
||||
|
||||
group('API - Dashboard', () => {
|
||||
const r = http.get(API + '/admin/dashboard', { headers: H });
|
||||
check(r, { 'dashboard 200': (r) => r.status === 200 });
|
||||
});
|
||||
|
||||
group('API - Analytics', () => {
|
||||
for (const ep of ['/analytics/summary', '/analytics/quality', '/capacity/dashboard', '/performance/ranking']) {
|
||||
const r = http.get(API + ep, { headers: H });
|
||||
check(r, { [`${ep} 200`]: (r) => r.status === 200 });
|
||||
}
|
||||
});
|
||||
|
||||
group('API - Lists', () => {
|
||||
const r = http.get(API + '/applications?page=1&size=10', { headers: H });
|
||||
check(r, { 'applications 200': (r) => r.status === 200 });
|
||||
|
||||
const r2 = http.get(API + '/admin/work-orders?page=1&size=10', { headers: H });
|
||||
check(r2, { 'work-orders 200': (r) => r.status === 200 });
|
||||
});
|
||||
|
||||
group('API - Master Data', () => {
|
||||
for (const ep of ['/master/service-items', '/master/price-rules', '/master/regions', '/master/staff']) {
|
||||
const r = http.get(API + ep, { headers: H });
|
||||
check(r, { [`${ep} 200`]: (r) => r.status === 200 });
|
||||
}
|
||||
});
|
||||
|
||||
group('API - POST Leads', () => {
|
||||
const r = http.post(API + '/leads', JSON.stringify({
|
||||
type: 'demo', name: 'K6 Load', orgName: 'LoadTest', phone: '13800000000', source: 'k6'
|
||||
}), { headers: { ...H, 'Idempotency-Key': 'k6-' + __VU + '-' + __ITER + '-' + Date.now() } });
|
||||
check(r, { 'leads 200': (r) => r.status === 200 });
|
||||
});
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
32
hss-home-service/website/tests/load/k6-stress-test.js
Normal file
32
hss-home-service/website/tests/load/k6-stress-test.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import http from 'k6/http';
|
||||
import { check, sleep } from 'k6';
|
||||
|
||||
const API = 'http://172.31.12.249:18080/api/hss';
|
||||
const H = { 'Content-Type': 'application/json', 'X-Tenant-Id': '1', 'X-Org-Id': '1', 'X-User-Role': 'ADMIN' };
|
||||
|
||||
// Stress test: 50 concurrent users creating applications
|
||||
export const options = {
|
||||
scenarios: {
|
||||
create_applications: {
|
||||
executor: 'constant-arrival-rate',
|
||||
rate: 10, // 10 requests per second
|
||||
timeUnit: '1s',
|
||||
duration: '30s',
|
||||
preAllocatedVUs: 50,
|
||||
maxVUs: 100,
|
||||
},
|
||||
},
|
||||
thresholds: {
|
||||
http_req_duration: ['p(95)<3000', 'p(99)<5000'],
|
||||
http_req_failed: ['rate<0.10'],
|
||||
},
|
||||
};
|
||||
|
||||
export default function () {
|
||||
const idemKey = 'stress-' + __VU + '-' + __ITER + '-' + Date.now();
|
||||
const r = http.post(API + '/applications', JSON.stringify({
|
||||
patientId: '2001', serviceType: 'HOME_CARE', channel: 'WECHAT',
|
||||
contactName: 'Stress', contactPhone: '13800000000', address: '梅江区', regionCode: '441402001'
|
||||
}), { headers: { ...H, 'Idempotency-Key': idemKey } });
|
||||
check(r, { 'create 200': (r) => r.status === 200 });
|
||||
}
|
||||
65
hss-home-service/website/tests/load/load-test.mjs
Normal file
65
hss-home-service/website/tests/load/load-test.mjs
Normal file
@@ -0,0 +1,65 @@
|
||||
// Node.js 并发负载测试(替代 k6)
|
||||
const BASE = 'http://172.31.12.249:18080/api/hss';
|
||||
const H = { 'Content-Type': 'application/json', 'X-Tenant-Id': '1', 'X-Org-Id': '1', 'X-User-Role': 'ADMIN' };
|
||||
|
||||
let total = 0, passed = 0, failed = 0;
|
||||
const start = Date.now();
|
||||
const startMem = process.memoryUsage().heapUsed;
|
||||
|
||||
async function req(path, method = 'GET', body = null) {
|
||||
const headers = { ...H, 'Idempotency-Key': 'load-' + Math.random().toString(36).slice(2,10) };
|
||||
const r = await fetch(BASE + path, { method, headers, body: body ? JSON.stringify(body) : undefined });
|
||||
return r.status;
|
||||
}
|
||||
|
||||
// 阶段1: 阶梯负载 (5 → 20 → 0 并发)
|
||||
const stages = [
|
||||
{ duration: 5000, concurrency: 5 },
|
||||
{ duration: 10000, concurrency: 10 },
|
||||
{ duration: 15000, concurrency: 20 },
|
||||
{ duration: 10000, concurrency: 10 },
|
||||
{ duration: 5000, concurrency: 5 },
|
||||
];
|
||||
|
||||
async function runStage(concurrency, durationMs) {
|
||||
const endTime = Date.now() + durationMs;
|
||||
const tasks = [];
|
||||
while (Date.now() < endTime) {
|
||||
for (let i = 0; i < concurrency; i++) {
|
||||
tasks.push((async () => {
|
||||
total++;
|
||||
try {
|
||||
const paths = ['/admin/dashboard', '/analytics/summary', '/master/service-items',
|
||||
'/applications?page=1&size=10', '/admin/work-orders?page=1&size=10'];
|
||||
const status = await req(paths[Math.floor(Math.random() * paths.length)]);
|
||||
if (status === 200) passed++; else failed++;
|
||||
} catch (e) { failed++; }
|
||||
})());
|
||||
}
|
||||
if (tasks.length > 500) {
|
||||
await Promise.all(tasks.splice(0, 200));
|
||||
}
|
||||
await new Promise(r => setTimeout(r, 1000 / concurrency));
|
||||
}
|
||||
await Promise.all(tasks);
|
||||
const elapsed = ((Date.now() - start) / 1000).toFixed(1);
|
||||
console.log(` [${elapsed}s] concurrency=${concurrency} passed=${passed} failed=${failed} total=${total}`);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('=== 负载测试:阶梯并发 5→10→20→10→5 ===\n');
|
||||
for (const s of stages) {
|
||||
await runStage(s.concurrency, s.duration);
|
||||
}
|
||||
|
||||
const elapsed = ((Date.now() - start) / 1000).toFixed(1);
|
||||
const rps = (total / elapsed).toFixed(1);
|
||||
const passRate = total > 0 ? (passed / total * 100).toFixed(1) : '0';
|
||||
const memUsed = ((process.memoryUsage().heapUsed - startMem) / 1024 / 1024).toFixed(1);
|
||||
|
||||
console.log(`\n=== 结果 ===`);
|
||||
console.log(`总请求: ${total} 通过: ${passed} 失败: ${failed} 通过率: ${passRate}%`);
|
||||
console.log(`耗时: ${elapsed}s RPS: ${rps} 内存: ${memUsed}MB`);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
51
hss-home-service/website/tests/load/stress-test.mjs
Normal file
51
hss-home-service/website/tests/load/stress-test.mjs
Normal file
@@ -0,0 +1,51 @@
|
||||
// Node.js 压力测试:50 并发持续创建申请
|
||||
const BASE = 'http://172.31.12.249:18080/api/hss';
|
||||
const H = { 'Content-Type': 'application/json', 'X-Tenant-Id': '1', 'X-Org-Id': '1', 'X-User-Role': 'ADMIN' };
|
||||
|
||||
let total = 0, p200 = 0, p422 = 0, p4xx = 0, p5xx = 0;
|
||||
const start = Date.now();
|
||||
const CONCURRENCY = 50;
|
||||
const DURATION_MS = 15000;
|
||||
|
||||
async function createApplication() {
|
||||
const key = 'stress-' + Math.random().toString(36).slice(2, 12);
|
||||
try {
|
||||
const r = await fetch(BASE + '/applications', {
|
||||
method: 'POST',
|
||||
headers: { ...H, 'Idempotency-Key': key },
|
||||
body: JSON.stringify({ patientId: '2001', serviceType: 'HOME_CARE', channel: 'WECHAT',
|
||||
contactName: 'StressTest', contactPhone: '13800000000', address: '梅江区', regionCode: '441402001' })
|
||||
});
|
||||
total++;
|
||||
if (r.status === 200) p200++;
|
||||
else if (r.status === 422) p422++;
|
||||
else if (r.status >= 400 && r.status < 500) p4xx++;
|
||||
else p5xx++;
|
||||
} catch (e) { total++; p5xx++; }
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log(`=== 压力测试: ${CONCURRENCY}并发 持续${DURATION_MS/1000}s 创建申请 ===\n`);
|
||||
const endTime = Date.now() + DURATION_MS;
|
||||
const tasks = [];
|
||||
|
||||
while (Date.now() < endTime) {
|
||||
for (let i = 0; i < CONCURRENCY; i++) {
|
||||
tasks.push(createApplication());
|
||||
}
|
||||
if (tasks.length > 500) {
|
||||
await Promise.all(tasks.splice(0, 200));
|
||||
}
|
||||
await new Promise(r => setTimeout(r, 50));
|
||||
}
|
||||
await Promise.all(tasks);
|
||||
|
||||
const elapsed = ((Date.now() - start) / 1000).toFixed(1);
|
||||
const rps = (total / elapsed).toFixed(1);
|
||||
|
||||
console.log(`\n=== 压力测试结果 ===`);
|
||||
console.log(`总请求: ${total} 200: ${p200} 422(重复校验): ${p422} 其他4xx: ${p4xx} 5xx: ${p5xx}`);
|
||||
console.log(`耗时: ${elapsed}s RPS: ${rps} 成功率: ${(p200/total*100).toFixed(1)}%`);
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
Reference in New Issue
Block a user