新增im请求返回结构体
This commit is contained in:
parent
a5522bcb63
commit
82353bbd35
@ -184,13 +184,13 @@ func (r *UserDoctor) GetUserDoctorPendingPage(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理返回值
|
// 处理返回值
|
||||||
getUserDoctorPageResponses := userDoctorResponse.GetUserDoctorPendingPageResponse(userDoctor)
|
res := userDoctorResponse.GetUserDoctorPendingPageResponse(userDoctor)
|
||||||
|
|
||||||
result := make(map[string]interface{})
|
result := make(map[string]interface{})
|
||||||
result["page"] = userDoctorRequest.GetUserDoctorPage.Page
|
result["page"] = userDoctorRequest.GetUserDoctorPendingPage.Page
|
||||||
result["page_size"] = userDoctorRequest.GetUserDoctorPage.PageSize
|
result["page_size"] = userDoctorRequest.GetUserDoctorPendingPage.PageSize
|
||||||
result["total"] = total
|
result["total"] = total
|
||||||
result["data"] = getUserDoctorPageResponses
|
result["data"] = res
|
||||||
responses.OkWithData(result, c)
|
responses.OkWithData(result, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -783,6 +783,8 @@ func (r *UserDoctorService) AddUserDoctor(userId string, a requests.AddUserDocto
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 创建im账户
|
||||||
|
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
@ -1129,6 +1131,7 @@ func (r *UserDoctorService) PutUserDoctorPending(doctorId int64, req requests.Pu
|
|||||||
return false, errors.New("审核失败")
|
return false, errors.New("审核失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新医生im资料
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改医生数据
|
// 修改医生数据
|
||||||
|
|||||||
@ -13,6 +13,13 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 请求返回值
|
||||||
|
type responseData struct {
|
||||||
|
ActionStatus string `json:"actionStatus"` // 请求处理的结果,“OK” 表示处理成功,“FAIL” 表示失败
|
||||||
|
ErrorCode int `json:"errorCode"` // 错误码,0表示成功,非0表示失败
|
||||||
|
ErrorInfo string `json:"errorInfo"` // 详细错误信息
|
||||||
|
}
|
||||||
|
|
||||||
// GetUserSign 获取签名
|
// GetUserSign 获取签名
|
||||||
func GetUserSign(userId string) (string, error) {
|
func GetUserSign(userId string) (string, error) {
|
||||||
if userId == "" {
|
if userId == "" {
|
||||||
@ -51,9 +58,55 @@ func getRequestUrlParams(userId string) (bool, string) {
|
|||||||
return true, queryString
|
return true, queryString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// // 统一请求
|
||||||
|
// func postRequest(url string, requestBody []byte) (map[string]interface{}, error) {
|
||||||
|
// responseMap := make(map[string]interface{})
|
||||||
|
//
|
||||||
|
// // 发起 POST 请求
|
||||||
|
// resp, err := http.Post(url, "application/json", bytes.NewBuffer(requestBody))
|
||||||
|
// if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// defer func(Body io.ReadCloser) {
|
||||||
|
// _ = Body.Close()
|
||||||
|
// }(resp.Body)
|
||||||
|
//
|
||||||
|
// body, err := io.ReadAll(resp.Body)
|
||||||
|
// if err != nil {
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// err = json.Unmarshal([]byte(string(body)), &responseMap)
|
||||||
|
// if err != nil {
|
||||||
|
// // json解析失败
|
||||||
|
// return nil, err
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if responseMap == nil {
|
||||||
|
// return nil, errors.New("请求im失败")
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if _, ok := responseMap["ErrorCode"]; ok {
|
||||||
|
// errorCode := responseMap["ErrorCode"].(int)
|
||||||
|
// if errorCode != 0 {
|
||||||
|
// if errorInfo, ok := responseMap["ErrorInfo"].(string); ok {
|
||||||
|
// return nil, errors.New(errorInfo)
|
||||||
|
// } else {
|
||||||
|
// return nil, errors.New("请求im失败")
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// return nil, errors.New("请求im失败")
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return responseMap, nil
|
||||||
|
// }
|
||||||
|
|
||||||
// 统一请求
|
// 统一请求
|
||||||
func postRequest(url string, requestBody []byte) (map[string]interface{}, error) {
|
func postRequest(url string, requestBody []byte) (*responseData, error) {
|
||||||
responseMap := make(map[string]interface{})
|
var responseData responseData
|
||||||
|
|
||||||
// 发起 POST 请求
|
// 发起 POST 请求
|
||||||
resp, err := http.Post(url, "application/json", bytes.NewBuffer(requestBody))
|
resp, err := http.Post(url, "application/json", bytes.NewBuffer(requestBody))
|
||||||
@ -70,25 +123,19 @@ func postRequest(url string, requestBody []byte) (map[string]interface{}, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal([]byte(string(body)), &responseMap)
|
err = json.Unmarshal(body, &responseData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// json解析失败
|
// json解析失败
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if responseMap == nil {
|
if responseData.ErrorCode != 0 {
|
||||||
return nil, errors.New("请求im失败")
|
if responseData.ErrorInfo != "" {
|
||||||
}
|
return nil, errors.New(responseData.ErrorInfo)
|
||||||
|
} else {
|
||||||
if errorCode, ok := responseMap["ErrorCode"].(int); ok {
|
return nil, errors.New("请求im失败")
|
||||||
if errorCode != 0 {
|
|
||||||
if errorInfo, ok := responseMap["ErrorInfo"].(string); ok {
|
|
||||||
return nil, errors.New(errorInfo)
|
|
||||||
} else {
|
|
||||||
return nil, errors.New("请求im失败")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return responseMap, nil
|
return &responseData, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user