feat(osi): 实现公开字典查询接口(T-101)
This commit is contained in:
@@ -8,6 +8,10 @@ import (
|
||||
const (
|
||||
ServiceIDJKDAFind = "JKDA00002"
|
||||
ServiceIDJKDAFindRqbj = "JKDA00005"
|
||||
ServiceIDGridAddress = "WGDZ00001"
|
||||
ServiceIDDoctors = "ZRYS00001"
|
||||
ServiceIDDrugs = "YPML00001"
|
||||
ServiceIDOrgs = "CXJG00002"
|
||||
)
|
||||
|
||||
const codeRetryableTimeout = "405"
|
||||
@@ -15,6 +19,10 @@ const codeRetryableTimeout = "405"
|
||||
var servicePaths = map[string]string{
|
||||
ServiceIDJKDAFind: "/auto/jkda/find",
|
||||
ServiceIDJKDAFindRqbj: "/jkda/findrqbj",
|
||||
ServiceIDGridAddress: "/auto/wgdzcx/query",
|
||||
ServiceIDDoctors: "/auto/zryscx/query",
|
||||
ServiceIDDrugs: "/auto/ypmlcx/query",
|
||||
ServiceIDOrgs: "/auto/cxjg/query",
|
||||
}
|
||||
|
||||
func PathOf(serviceID string) (string, error) {
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package osi
|
||||
|
||||
import "context"
|
||||
|
||||
type GridAddressQuery struct {
|
||||
ParentCode string `json:"parentCode,omitempty"`
|
||||
PageNo int `json:"pageNo,omitempty"`
|
||||
OperateUser string `json:"operateUser,omitempty"`
|
||||
}
|
||||
|
||||
type GridAddress struct {
|
||||
RegionCode string `json:"regionCode"`
|
||||
RegionName string `json:"regionName"`
|
||||
IsFamily string `json:"isFamily"`
|
||||
}
|
||||
|
||||
type DoctorQuery struct {
|
||||
ManaUnitID string `json:"manaUnitId,omitempty"`
|
||||
OperateUser string `json:"operateUser,omitempty"`
|
||||
}
|
||||
|
||||
type Doctor struct {
|
||||
PersonID string `json:"personId"`
|
||||
PersonName string `json:"personName"`
|
||||
}
|
||||
|
||||
type DrugQuery struct {
|
||||
PageNo int `json:"pageNo,omitempty"`
|
||||
YPMC string `json:"ypmc,omitempty"`
|
||||
PYM string `json:"pym,omitempty"`
|
||||
}
|
||||
|
||||
type Drug struct {
|
||||
YPMC string `json:"ypmc"`
|
||||
YPDW string `json:"ypdw"`
|
||||
YPGG string `json:"ypgg"`
|
||||
JLDW string `json:"jldw"`
|
||||
}
|
||||
|
||||
type OrgQuery struct {
|
||||
OrganizCode string `json:"organizCode,omitempty"`
|
||||
ParentID string `json:"parentId,omitempty"`
|
||||
}
|
||||
|
||||
type Org struct {
|
||||
OrganizCode string `json:"organizCode"`
|
||||
OrganizName string `json:"organizName"`
|
||||
OrganizType string `json:"organizType"`
|
||||
ParentID string `json:"parentId"`
|
||||
}
|
||||
|
||||
func (c *Client) QueryGridAddress(ctx context.Context, query GridAddressQuery) ([]GridAddress, Result, error) {
|
||||
var rows []GridAddress
|
||||
result, err := c.Call(ctx, ServiceIDGridAddress, query, &rows)
|
||||
return rows, result, err
|
||||
}
|
||||
|
||||
func (c *Client) QueryDoctors(ctx context.Context, query DoctorQuery) ([]Doctor, Result, error) {
|
||||
var rows []Doctor
|
||||
result, err := c.Call(ctx, ServiceIDDoctors, query, &rows)
|
||||
return rows, result, err
|
||||
}
|
||||
|
||||
func (c *Client) QueryDrugs(ctx context.Context, query DrugQuery) ([]Drug, Result, error) {
|
||||
var rows []Drug
|
||||
result, err := c.Call(ctx, ServiceIDDrugs, query, &rows)
|
||||
return rows, result, err
|
||||
}
|
||||
|
||||
func (c *Client) QueryOrgs(ctx context.Context, query OrgQuery) ([]Org, Result, error) {
|
||||
var rows []Org
|
||||
result, err := c.Call(ctx, ServiceIDOrgs, query, &rows)
|
||||
return rows, result, err
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package osi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestQueryGridAddressCallsWGDZ00001(t *testing.T) {
|
||||
var seenPath string
|
||||
var seenPayload map[string]any
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
seenPath = r.URL.Path
|
||||
if err := json.NewDecoder(r.Body).Decode(&seenPayload); err != nil {
|
||||
t.Fatalf("decode request: %v", err)
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"code":"01","message":"操作成功","data":[{"regionCode":"441625000000","regionName":"测试网格","isFamily":"1"}]}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := newTestJKDAClient(t, server.URL)
|
||||
rows, result, err := client.QueryGridAddress(context.Background(), GridAddressQuery{
|
||||
ParentCode: "441625",
|
||||
PageNo: 1,
|
||||
OperateUser: "712041",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("QueryGridAddress: %v", err)
|
||||
}
|
||||
if !result.Success || result.Code != "01" {
|
||||
t.Fatalf("result = %#v", result)
|
||||
}
|
||||
if seenPath != "/osi/api/auto/wgdzcx/query" {
|
||||
t.Fatalf("path = %q", seenPath)
|
||||
}
|
||||
if seenPayload["serviceId"] != ServiceIDGridAddress {
|
||||
t.Fatalf("serviceId = %v", seenPayload["serviceId"])
|
||||
}
|
||||
baseInfo := seenPayload["uploadinfo"].(map[string]any)["baseInfo"].(map[string]any)
|
||||
if baseInfo["parentCode"] != "441625" || baseInfo["pageNo"] != float64(1) || baseInfo["operateUser"] != "712041" {
|
||||
t.Fatalf("baseInfo = %#v", baseInfo)
|
||||
}
|
||||
if len(rows) != 1 || rows[0].RegionCode != "441625000000" || rows[0].RegionName != "测试网格" || rows[0].IsFamily != "1" {
|
||||
t.Fatalf("rows = %#v", rows)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryDoctorsCallsZRYS00001(t *testing.T) {
|
||||
var seenPath string
|
||||
var seenPayload map[string]any
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
seenPath = r.URL.Path
|
||||
if err := json.NewDecoder(r.Body).Decode(&seenPayload); err != nil {
|
||||
t.Fatalf("decode request: %v", err)
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"code":"01","message":"操作成功","data":[{"personId":"doc-001","personName":"测试医生"}]}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := newTestJKDAClient(t, server.URL)
|
||||
rows, result, err := client.QueryDoctors(context.Background(), DoctorQuery{
|
||||
ManaUnitID: "441625001",
|
||||
OperateUser: "712041",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("QueryDoctors: %v", err)
|
||||
}
|
||||
if !result.Success || result.Code != "01" {
|
||||
t.Fatalf("result = %#v", result)
|
||||
}
|
||||
if seenPath != "/osi/api/auto/zryscx/query" {
|
||||
t.Fatalf("path = %q", seenPath)
|
||||
}
|
||||
if seenPayload["serviceId"] != ServiceIDDoctors {
|
||||
t.Fatalf("serviceId = %v", seenPayload["serviceId"])
|
||||
}
|
||||
baseInfo := seenPayload["uploadinfo"].(map[string]any)["baseInfo"].(map[string]any)
|
||||
if baseInfo["manaUnitId"] != "441625001" || baseInfo["operateUser"] != "712041" {
|
||||
t.Fatalf("baseInfo = %#v", baseInfo)
|
||||
}
|
||||
if len(rows) != 1 || rows[0].PersonID != "doc-001" || rows[0].PersonName != "测试医生" {
|
||||
t.Fatalf("rows = %#v", rows)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryDrugsCallsYPML00001(t *testing.T) {
|
||||
var seenPath string
|
||||
var seenPayload map[string]any
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
seenPath = r.URL.Path
|
||||
if err := json.NewDecoder(r.Body).Decode(&seenPayload); err != nil {
|
||||
t.Fatalf("decode request: %v", err)
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"code":"01","message":"操作成功","data":[{"ypmc":"测试药品","ypdw":"盒","ypgg":"10mg","jldw":"片"}]}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := newTestJKDAClient(t, server.URL)
|
||||
rows, result, err := client.QueryDrugs(context.Background(), DrugQuery{
|
||||
PageNo: 1,
|
||||
YPMC: "测试",
|
||||
PYM: "CS",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("QueryDrugs: %v", err)
|
||||
}
|
||||
if !result.Success || result.Code != "01" {
|
||||
t.Fatalf("result = %#v", result)
|
||||
}
|
||||
if seenPath != "/osi/api/auto/ypmlcx/query" {
|
||||
t.Fatalf("path = %q", seenPath)
|
||||
}
|
||||
if seenPayload["serviceId"] != ServiceIDDrugs {
|
||||
t.Fatalf("serviceId = %v", seenPayload["serviceId"])
|
||||
}
|
||||
baseInfo := seenPayload["uploadinfo"].(map[string]any)["baseInfo"].(map[string]any)
|
||||
if baseInfo["pageNo"] != float64(1) || baseInfo["ypmc"] != "测试" || baseInfo["pym"] != "CS" {
|
||||
t.Fatalf("baseInfo = %#v", baseInfo)
|
||||
}
|
||||
if len(rows) != 1 || rows[0].YPMC != "测试药品" || rows[0].YPDW != "盒" || rows[0].YPGG != "10mg" || rows[0].JLDW != "片" {
|
||||
t.Fatalf("rows = %#v", rows)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryOrgsCallsCXJG00002(t *testing.T) {
|
||||
var seenPath string
|
||||
var seenPayload map[string]any
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
seenPath = r.URL.Path
|
||||
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"}]}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := newTestJKDAClient(t, server.URL)
|
||||
rows, result, err := client.QueryOrgs(context.Background(), OrgQuery{
|
||||
OrganizCode: "441625001",
|
||||
ParentID: "441625",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("QueryOrgs: %v", err)
|
||||
}
|
||||
if !result.Success || result.Code != "01" {
|
||||
t.Fatalf("result = %#v", result)
|
||||
}
|
||||
if seenPath != "/osi/api/auto/cxjg/query" {
|
||||
t.Fatalf("path = %q", seenPath)
|
||||
}
|
||||
if seenPayload["serviceId"] != ServiceIDOrgs {
|
||||
t.Fatalf("serviceId = %v", seenPayload["serviceId"])
|
||||
}
|
||||
baseInfo := seenPayload["uploadinfo"].(map[string]any)["baseInfo"].(map[string]any)
|
||||
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" {
|
||||
t.Fatalf("rows = %#v", rows)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user