feat(osi): 某人全部体检查询 JKTJ00002(T-306)

- osi.QueryHealthChecks(/auto/jktj/query,返回全部体检数组)
- contract.HealthCheckRecordSummary:驼峰 idCard(≠最近一次小写 idcard)、checkId 可空
- HTTP 端点 GET /api/health-check/all
- 单测含 null checkId 场景;实测端点已部署

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
ila
2026-07-08 22:14:39 +08:00
co-authored by Claude Opus 4.8
parent 00b02b76f6
commit f3c5e1bf8d
7 changed files with 117 additions and 4 deletions
+21
View File
@@ -36,6 +36,27 @@ func (h *HealthCheckHandler) Last(w http.ResponseWriter, r *http.Request) {
writeRawOrError(w, result, err)
}
// All 处理 GET /api/health-check/all?idCard=..|phrid=..|empiId=..
// 返回某人全部体检(JKTJ00002 数组)的平台完整响应;历史记录 checkId 可能为空。
func (h *HealthCheckHandler) All(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
writeJSONError(w, http.StatusMethodNotAllowed, "only GET is supported")
return
}
q := r.URL.Query()
query := osi.FindHealthCheckQuery{
IDCard: q.Get("idCard"),
PHRID: q.Get("phrid"),
EMPIID: q.Get("empiId"),
}
if query.IDCard == "" && query.PHRID == "" && query.EMPIID == "" {
writeJSONError(w, http.StatusBadRequest, "provide one of: idCard, phrid, empiId")
return
}
_, result, err := h.client.QueryHealthChecks(r.Context(), query)
writeRawOrError(w, result, err)
}
// List 处理 GET /api/health-check/list?checkYear=..&idCard=..&checkType=..&page=..&rows=..
// 返回某年度已检/未检人员名单的平台完整响应(名单,非体检明细,见 docs/04 §11.4)。
func (h *HealthCheckHandler) List(w http.ResponseWriter, r *http.Request) {
+30
View File
@@ -59,6 +59,36 @@ func TestHealthCheckLastRequiresIdentifier(t *testing.T) {
}
}
func TestHealthCheckAllReturnsArrayRaw(t *testing.T) {
client, seenPath := newTestClient(t, `{"code":"01","message":"操作成功","data":[{"checkId":"CHK-1","idCard":"TEST-1"},{"checkId":null,"idCard":"TEST-1"}]}`)
h := NewHealthCheckHandler(client)
req := httptest.NewRequest(http.MethodGet, "/api/health-check/all?idCard=TEST-1", nil)
rec := httptest.NewRecorder()
h.All(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d", rec.Code)
}
if *seenPath != "/osi/api/auto/jktj/query" {
t.Fatalf("osi path = %q", *seenPath)
}
body, _ := io.ReadAll(rec.Body)
if !strings.Contains(string(body), `"CHK-1"`) {
t.Fatalf("body missing records: %s", body)
}
}
func TestHealthCheckAllRequiresIdentifier(t *testing.T) {
h := NewHealthCheckHandler(nil)
req := httptest.NewRequest(http.MethodGet, "/api/health-check/all", nil)
rec := httptest.NewRecorder()
h.All(rec, req)
if rec.Code != http.StatusBadRequest {
t.Fatalf("status = %d, want 400", rec.Code)
}
}
func TestHealthCheckListRequiresCheckYear(t *testing.T) {
h := NewHealthCheckHandler(nil) // 缺 checkYear 在触达 client 前返回 400
req := httptest.NewRequest(http.MethodGet, "/api/health-check/list?idCard=TEST-1", nil)