fix(osi): 校准机构查询请求契约

This commit is contained in:
ila
2026-07-13 20:02:19 +08:00
parent d60b979785
commit d30ff01c35
6 changed files with 44 additions and 13 deletions
+6 -3
View File
@@ -39,15 +39,18 @@ type Drug struct {
}
type OrgQuery struct {
OrganizCode string `json:"organizCode,omitempty"`
ParentID string `json:"parentId,omitempty"`
// docx 二者均标必填;联调验证通过的请求是两 key 都在(organizCode + parentId 可为 "")。
// 不加 omitempty,确保 parentId="" 也上送,避免像网格地址那样必填空值被丢导致平台 NPE(code=02)。
OrganizCode string `json:"organizCode"`
ParentID string `json:"parentId"`
}
type Org struct {
OrganizCode string `json:"organizCode"`
OrganizName string `json:"organizName"`
OrganizType string `json:"organizType"`
OrganizType string `json:"organizType"` // A医院/B社区中心(站)/C卫生院/D门诊诊所村室/D6村卫生室/R市卫生局
ParentID string `json:"parentId"`
RegionCode string `json:"regionCode"` // 机构所在网格码;联调实测可为 null(→"")
}
func (c *Client) QueryGridAddress(ctx context.Context, query GridAddressQuery) ([]GridAddress, Result, error) {
+25 -2
View File
@@ -132,7 +132,7 @@ func TestQueryOrgsCallsCXJG00002(t *testing.T) {
if err := json.NewDecoder(r.Body).Decode(&seenPayload); err != nil {
t.Fatalf("decode request: %v", err)
}
_, _ = w.Write([]byte(`{"code":"01","message":"操作成功","data":[{"organizCode":"441625001","organizName":"测试机构","organizType":"1","parentId":"441625"}]}`))
_, _ = w.Write([]byte(`{"code":"01","message":"操作成功","data":[{"organizCode":"441625001","organizName":"测试机构","organizType":"1","parentId":"441625","regionCode":"441625000000"}]}`))
}))
defer server.Close()
@@ -157,7 +157,30 @@ func TestQueryOrgsCallsCXJG00002(t *testing.T) {
if baseInfo["organizCode"] != "441625001" || baseInfo["parentId"] != "441625" {
t.Fatalf("baseInfo = %#v", baseInfo)
}
if len(rows) != 1 || rows[0].OrganizCode != "441625001" || rows[0].OrganizName != "测试机构" || rows[0].OrganizType != "1" || rows[0].ParentID != "441625" {
if len(rows) != 1 || rows[0].OrganizCode != "441625001" || rows[0].OrganizName != "测试机构" || rows[0].OrganizType != "1" || rows[0].ParentID != "441625" || rows[0].RegionCode != "441625000000" {
t.Fatalf("rows = %#v", rows)
}
}
func TestQueryOrgsSendsEmptyRequiredKeys(t *testing.T) {
var seenPayload map[string]any
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if err := json.NewDecoder(r.Body).Decode(&seenPayload); err != nil {
t.Fatalf("decode request: %v", err)
}
_, _ = w.Write([]byte(`{"code":"01","message":"操作成功","data":[]}`))
}))
defer server.Close()
client := newTestJKDAClient(t, server.URL)
if _, _, err := client.QueryOrgs(context.Background(), OrgQuery{}); err != nil {
t.Fatalf("QueryOrgs: %v", err)
}
baseInfo := seenPayload["uploadinfo"].(map[string]any)["baseInfo"].(map[string]any)
if _, ok := baseInfo["organizCode"]; !ok || baseInfo["organizCode"] != "" {
t.Fatalf("organizCode should be present and empty: %#v", baseInfo)
}
if _, ok := baseInfo["parentId"]; !ok || baseInfo["parentId"] != "" {
t.Fatalf("parentId should be present and empty: %#v", baseInfo)
}
}