65 lines
2.3 KiB
Go
65 lines
2.3 KiB
Go
package dto
|
||
|
||
import (
|
||
"fmt"
|
||
"hepa-calc-api/api/model"
|
||
"time"
|
||
)
|
||
|
||
// UserInfoDto 用户表-基础信息
|
||
type UserInfoDto struct {
|
||
UserInfoId string `json:"user_info_id"` // 主键id
|
||
UserId string `json:"user_id"` // 用户id
|
||
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:家有宝宝)
|
||
ExpectedDate *string `json:"expected_date"` // 预产期
|
||
ProvinceId string `json:"province_id"` // 省份id
|
||
Province string `json:"province"` // 省份
|
||
CityId string `json:"city_id"` // 城市id
|
||
City string `json:"city"` // 城市
|
||
CountyId string `json:"county_id"` // 区县id
|
||
County string `json:"county"` // 区县
|
||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||
}
|
||
|
||
// GetUserInfoDto 用户基础信息详情
|
||
func GetUserInfoDto(m *model.UserInfo) *UserInfoDto {
|
||
return &UserInfoDto{
|
||
UserInfoId: fmt.Sprintf("%d", m.UserInfoId),
|
||
UserId: fmt.Sprintf("%d", m.UserInfoId),
|
||
IsFamilyHistory: m.IsFamilyHistory,
|
||
IsPregnant: m.IsPregnant,
|
||
ProvinceId: m.ProvinceId,
|
||
Province: m.Province,
|
||
CityId: m.CityId,
|
||
City: m.City,
|
||
CountyId: m.CountyId,
|
||
County: m.County,
|
||
CreatedAt: m.CreatedAt,
|
||
UpdatedAt: m.UpdatedAt,
|
||
}
|
||
}
|
||
|
||
// LoadExpectedDate 加载数据-预产期
|
||
func (r *UserInfoDto) LoadExpectedDate(expectedDate *model.LocalTime) *UserInfoDto {
|
||
if expectedDate != nil {
|
||
t := time.Time(*expectedDate).Format("2006-01-02")
|
||
r.ExpectedDate = &t
|
||
}
|
||
|
||
return r
|
||
}
|
||
|
||
// LoadNationId 加载数据-民族
|
||
func (r *UserInfoDto) LoadNationId(nationId *int64) *UserInfoDto {
|
||
if nationId != nil {
|
||
r.NationId = fmt.Sprintf("%d", *nationId)
|
||
}
|
||
|
||
return r
|
||
}
|