This commit is contained in:
wucongxing8150 2024-08-22 09:52:40 +08:00
parent 6901e97a59
commit c7b9542f95
4 changed files with 39 additions and 5 deletions

View File

@ -55,6 +55,14 @@ func (r *User) GetUserInfo(c *gin.Context) {
// 加载数据-预产期
g.LoadExpectedDate(userInfo.ExpectedDate)
// 处理身高
h, err := utils.StrToFloat64(userInfo.Height)
g.Height = h
// 处理体重
w, err := utils.StrToFloat64(userInfo.Weight)
g.Height = w
responses.OkWithData(g, c)
}

View File

@ -35,7 +35,7 @@ type UserCheckDto struct {
NameStatus int `json:"name_status"` // 昵称填写状态0:否 1:是)
}
// GetUserDto 详情-问题
// GetUserDto 详情
func GetUserDto(m *model.User) *UserDto {
return &UserDto{
UserId: fmt.Sprintf("%d", m.UserId),

View File

@ -10,8 +10,8 @@ import (
type UserInfoDto struct {
UserInfoId string `json:"user_info_id"` // 主键id
UserId string `json:"user_id"` // 用户id
Height string `json:"height"` // 身高cm
Weight string `json:"weight"` // 体重kg
Height *float64 `json:"height"` // 身高cm
Weight *float64 `json:"weight"` // 体重kg
NationId string `json:"nation_id"` // 民族id
IsFamilyHistory *int `json:"is_family_history"` // 是否存在家族病史0:未知 1:是 2:否)
IsPregnant *int `json:"is_pregnant"` // 是否怀孕(1:无计划 2:计划中 3:已怀孕 4:家有宝宝)
@ -31,8 +31,6 @@ func GetUserInfoDto(m *model.UserInfo) *UserInfoDto {
return &UserInfoDto{
UserInfoId: fmt.Sprintf("%d", m.UserInfoId),
UserId: fmt.Sprintf("%d", m.UserInfoId),
Height: m.Height,
Weight: m.Weight,
NationId: fmt.Sprintf("%d", m.NationId),
IsFamilyHistory: m.IsFamilyHistory,
IsPregnant: m.IsPregnant,

28
utils/type.go Normal file
View File

@ -0,0 +1,28 @@
package utils
import (
"strconv"
)
// StrToFloat32 字符串转float32
func StrToFloat32(s string) (f *float32, err error) {
f64, err := strconv.ParseFloat(s, 32)
if err != nil {
return nil, err
}
// 将float64转换为float32
f32 := float32(f64)
return &f32, nil
}
// StrToFloat64 字符串转float64
func StrToFloat64(s string) (f *float64, err error) {
f64, err := strconv.ParseFloat(s, 64)
if err != nil {
return nil, err
}
return &f64, nil
}