新增修改用户数据-基本信息
This commit is contained in:
+3
-3
@@ -16,11 +16,11 @@ type UserInfoDto struct {
|
||||
IsFamilyHistory *int `json:"is_family_history"` // 是否存在家族病史(0:未知 1:是 2:否)
|
||||
IsPregnant *int `json:"is_pregnant"` // 是否怀孕(1:无计划 2:计划中 3:已怀孕 4:家有宝宝)
|
||||
ExpectedDate *string `json:"expected_date"` // 预产期
|
||||
ProvinceId *int `json:"province_id"` // 省份id
|
||||
ProvinceId *int64 `json:"province_id"` // 省份id
|
||||
Province string `json:"province"` // 省份
|
||||
CityId *int `json:"city_id"` // 城市id
|
||||
CityId *int64 `json:"city_id"` // 城市id
|
||||
City string `json:"city"` // 城市
|
||||
CountyId *int `json:"county_id"` // 区县id
|
||||
CountyId *int64 `json:"county_id"` // 区县id
|
||||
County string `json:"county"` // 区县
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
|
||||
@@ -16,11 +16,11 @@ type UserInfo struct {
|
||||
IsFamilyHistory *int `gorm:"column:is_family_history;type:tinyint(1);comment:是否存在家族病史(0:未知 1:是 2:否)" json:"is_family_history"`
|
||||
IsPregnant *int `gorm:"column:is_pregnant;type:tinyint(1);comment:是否怀孕(1:无计划 2:计划中 3:已怀孕 4:家有宝宝)" json:"is_pregnant"`
|
||||
ExpectedDate *LocalTime `gorm:"column:expected_date;type:datetime;comment:预产期" json:"expected_date"`
|
||||
ProvinceId *int `gorm:"column:province_id;type:int(11);comment:省份id" json:"province_id"`
|
||||
ProvinceId *int64 `gorm:"column:province_id;type:int(11);comment:省份id" json:"province_id"`
|
||||
Province string `gorm:"column:province;type:varchar(40);comment:省份" json:"province"`
|
||||
CityId *int `gorm:"column:city_id;type:int(11);comment:城市id" json:"city_id"`
|
||||
CityId *int64 `gorm:"column:city_id;type:int(11);comment:城市id" json:"city_id"`
|
||||
City string `gorm:"column:city;type:varchar(50);comment:城市" json:"city"`
|
||||
CountyId *int `gorm:"column:county_id;type:int(11);comment:区县id" json:"county_id"`
|
||||
CountyId *int64 `gorm:"column:county_id;type:int(11);comment:区县id" json:"county_id"`
|
||||
County string `gorm:"column:county;type:varchar(255);comment:区县" json:"county"`
|
||||
Model
|
||||
}
|
||||
|
||||
+8
-12
@@ -7,20 +7,16 @@ type UserRequest struct {
|
||||
// PutUser 修改用户数据-基本信息
|
||||
type PutUser struct {
|
||||
UserName string `json:"user_name" form:"user_name" label:"用户名称" validate:"required"`
|
||||
RegisterSource int `json:"register_source" form:"register_source" label:"注册来源" validate:"required,oneof=1 2"`
|
||||
Birthday string `json:"birthday" form:"birthday" label:"出生日期" validate:"required,min=1,max=120"`
|
||||
Sex int `json:"sex" form:"sex" label:"性别" validate:"required,oneof=1 2"`
|
||||
Sex int `json:"sex" form:"sex" label:"性别" validate:"omitempty,oneof=0 1 2"`
|
||||
Avatar string `json:"avatar" form:"avatar" label:"头像"`
|
||||
Height string `json:"height" form:"height" label:"身高(cm)"`
|
||||
Weight string `json:"weight" form:"weight" label:"体重(kg)"`
|
||||
NationId string `json:"nation_id" form:"nation_id" label:"民族id"` // 从int64转换为可选字符串
|
||||
IsFamilyHistory *int `json:"is_family_history" form:"is_family_history" label:"是否存在家族病史" validate:"omitempty,oneof=0 1 2"`
|
||||
IsPregnant *int `json:"is_pregnant" form:"is_pregnant" label:"是否怀孕"`
|
||||
Height *int `json:"height" form:"height" label:"身高(cm)"`
|
||||
Weight *int `json:"weight" form:"weight" label:"体重(kg)"`
|
||||
NationId string `json:"nation_id" form:"nation_id" label:"民族id"` // 从int64转换为可选字符串
|
||||
IsFamilyHistory *int `json:"is_family_history" form:"is_family_history" label:"是否存在家族病史" validate:"omitempty,oneof=0 1 2"` // 是否存在家族病史(0:位置 1:是 2:否)
|
||||
IsPregnant *int `json:"is_pregnant" form:"is_pregnant" label:"是否怀孕" validate:"omitempty,oneof=1 2 3 4"`
|
||||
ExpectedDate string `json:"expected_date" form:"expected_date" label:"预产期"` // 假设转换为可选字符串
|
||||
ProvinceId string `json:"province_id" form:"province_id" label:"省份id" validate:"required"` // 从int转换为可选字符串
|
||||
Province string `json:"province" form:"province" label:"省份" validate:"required"`
|
||||
CityId string `json:"city_id" form:"city_id" label:"城市id" validate:"required"` // 从int转换为可选字符串
|
||||
City string `json:"city" form:"city" label:"城市" validate:"required"`
|
||||
CountyId string `json:"county_id" form:"county_id" label:"区县id"` // 从int转换为可选字符串
|
||||
County string `json:"county" form:"county" label:"区县"`
|
||||
CityId string `json:"city_id" form:"city_id" label:"城市id" validate:"required"` // 从int转换为可选字符串
|
||||
CountyId string `json:"county_id" form:"county_id" label:"区县id" validate:"required"` // 从int转换为可选字符串
|
||||
}
|
||||
|
||||
+284
-53
@@ -14,6 +14,7 @@ import (
|
||||
"io"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -617,59 +618,263 @@ func (r *UserService) HandleAppUserCase(tx *gorm.DB, user *model.User) error {
|
||||
|
||||
// PutUser 修改用户数据-基本信息
|
||||
func (r *UserService) PutUser(userId int64, req requests.PutUser) (bool, error) {
|
||||
//// 获取用户数据
|
||||
//userDao := dao.UserDao{}
|
||||
//user, err := userDao.GetUserById(userId)
|
||||
//if err != nil {
|
||||
// return false, errors.New("用户数据错误")
|
||||
//}
|
||||
//
|
||||
//// 获取用户数据
|
||||
//userInfoDao := dao.UserInfoDao{}
|
||||
//userInfo, err := userInfoDao.GetUserInfoByUserId(userId)
|
||||
//if err != nil {
|
||||
// return false, errors.New("用户数据错误")
|
||||
//}
|
||||
//
|
||||
//userData := make(map[string]interface{})
|
||||
//userInfoData := make(map[string]interface{})
|
||||
//appUserData := make(map[string]interface{})
|
||||
//
|
||||
//// 用户名称
|
||||
//if req.UserName != user.UserName {
|
||||
// userData["user_name"] = req.UserName
|
||||
// appUserData["name"] = req.UserName
|
||||
//}
|
||||
//
|
||||
//// 注册来源
|
||||
//if req.RegisterSource != user.RegisterSource {
|
||||
// userData["register_source"] = req.UserName
|
||||
//}
|
||||
//
|
||||
//// 出生日期
|
||||
//birthday := time.Time(*user.Birthday).Format("2006-01-02")
|
||||
//if req.Birthday != birthday {
|
||||
// userData["birthday"] = req.Birthday
|
||||
// appUserData["birthday"] = req.Birthday
|
||||
//
|
||||
// // 年龄
|
||||
// age, err := utils.CalculateAge(req.Birthday)
|
||||
// if err != nil {
|
||||
// return false, errors.New("年龄错误")
|
||||
// }
|
||||
// userData["age"] = age
|
||||
//}
|
||||
//
|
||||
//// 性别
|
||||
//if req.Sex != *user.Sex {
|
||||
// userData["sex"] = req.Sex
|
||||
//
|
||||
// if req.Sex == 1 {
|
||||
// appUserData["sex"] = 0
|
||||
// } else if req.Sex == 2 {
|
||||
// appUserData["sex"] = 1
|
||||
// }
|
||||
//}
|
||||
// 获取用户数据
|
||||
userDao := dao.UserDao{}
|
||||
user, err := userDao.GetUserById(userId)
|
||||
if err != nil {
|
||||
return false, errors.New("用户数据错误")
|
||||
}
|
||||
|
||||
// 获取用户数据
|
||||
userInfoDao := dao.UserInfoDao{}
|
||||
userInfo, err := userInfoDao.GetUserInfoByUserId(userId)
|
||||
if err != nil {
|
||||
return false, errors.New("用户数据错误")
|
||||
}
|
||||
|
||||
userData := make(map[string]interface{})
|
||||
userInfoData := make(map[string]interface{})
|
||||
appData := app.UpdateInfoRequest{
|
||||
Birthday: req.Birthday,
|
||||
IsPegnant: req.IsPregnant,
|
||||
Sex: nil,
|
||||
Weight: req.Weight,
|
||||
ExpectedDateOfChildbirth: req.ExpectedDate,
|
||||
IsHbv: nil,
|
||||
NationUuid: "",
|
||||
PatientUuid: "",
|
||||
Name: req.UserName,
|
||||
ProvId: nil,
|
||||
CityId: nil,
|
||||
CountyId: nil,
|
||||
Height: req.Height,
|
||||
}
|
||||
|
||||
// 用户名称
|
||||
if req.UserName != user.UserName {
|
||||
userData["user_name"] = req.UserName
|
||||
}
|
||||
|
||||
// 出生日期
|
||||
if user.Birthday != nil {
|
||||
birthday := time.Time(*user.Birthday).Format("2006-01-02")
|
||||
if req.Birthday != birthday {
|
||||
userData["birthday"] = req.Birthday
|
||||
|
||||
// 年龄
|
||||
age, err := utils.CalculateAge(req.Birthday)
|
||||
if err != nil {
|
||||
return false, errors.New("年龄错误")
|
||||
}
|
||||
userData["age"] = age
|
||||
}
|
||||
} else {
|
||||
userData["birthday"] = req.Birthday
|
||||
userData["age"] = nil
|
||||
}
|
||||
|
||||
// 性别
|
||||
if req.Sex == 1 {
|
||||
sex := 0
|
||||
appData.Sex = &sex
|
||||
} else if req.Sex == 2 {
|
||||
sex := 1
|
||||
appData.Sex = &sex
|
||||
}
|
||||
|
||||
if req.Sex != *user.Sex {
|
||||
userData["sex"] = req.Sex
|
||||
}
|
||||
|
||||
// 身高
|
||||
if req.Height != nil {
|
||||
height := fmt.Sprintf("%d", *req.Height)
|
||||
if height != userInfo.Height {
|
||||
userInfoData["height"] = req.Height
|
||||
}
|
||||
} else {
|
||||
userInfoData["height"] = nil
|
||||
}
|
||||
|
||||
// 体重
|
||||
if req.Weight != nil {
|
||||
weight := fmt.Sprintf("%d", *req.Weight)
|
||||
if weight != userInfo.Weight {
|
||||
userInfoData["weight"] = req.Weight
|
||||
}
|
||||
} else {
|
||||
userInfoData["weight"] = nil
|
||||
}
|
||||
|
||||
// 民族id
|
||||
if req.NationId != "" {
|
||||
if userInfo.NationId != nil {
|
||||
nationId := fmt.Sprintf("%d", *userInfo.NationId)
|
||||
if req.NationId != nationId {
|
||||
userInfoData["nation_id"] = req.NationId
|
||||
|
||||
// 获取民族数据
|
||||
baseNationDao := dao.BaseNationDao{}
|
||||
maps := make(map[string]interface{})
|
||||
maps["nation_id"] = req.NationId
|
||||
baseNation, err := baseNationDao.GetBaseNation(maps)
|
||||
if err != nil {
|
||||
return false, errors.New("民族错误")
|
||||
}
|
||||
appData.NationUuid = baseNation.AppIden
|
||||
}
|
||||
} else {
|
||||
userInfoData["nation_id"] = req.NationId
|
||||
|
||||
// 获取民族数据
|
||||
baseNationDao := dao.BaseNationDao{}
|
||||
maps := make(map[string]interface{})
|
||||
maps["nation_id"] = req.NationId
|
||||
baseNation, err := baseNationDao.GetBaseNation(maps)
|
||||
if err != nil {
|
||||
return false, errors.New("民族错误")
|
||||
}
|
||||
appData.NationUuid = baseNation.AppIden
|
||||
}
|
||||
} else {
|
||||
if userInfo.NationId != nil {
|
||||
userInfoData["nation_id"] = nil
|
||||
appData.NationUuid = ""
|
||||
}
|
||||
}
|
||||
|
||||
// 是否存在家族病史
|
||||
// 有无 肝硬化或肝癌家族史 0无1有2未知
|
||||
// 是否存在家族病史(0:未知 1:是 2:否)
|
||||
// 转换双方状态
|
||||
var isHbv int
|
||||
if *req.IsFamilyHistory == 0 {
|
||||
isHbv = 2
|
||||
} else if *req.IsFamilyHistory == 1 {
|
||||
isHbv = 1
|
||||
} else if *req.IsFamilyHistory == 2 {
|
||||
isHbv = 0
|
||||
}
|
||||
|
||||
appData.IsHbv = &isHbv
|
||||
if req.IsFamilyHistory != nil {
|
||||
if userInfo.IsFamilyHistory != nil {
|
||||
if *req.IsFamilyHistory != *userInfo.IsFamilyHistory {
|
||||
userInfoData["is_family_history"] = req.IsFamilyHistory
|
||||
}
|
||||
} else {
|
||||
userInfoData["is_family_history"] = req.IsFamilyHistory
|
||||
}
|
||||
} else {
|
||||
if userInfo.IsFamilyHistory != nil {
|
||||
userInfoData["is_family_history"] = nil
|
||||
}
|
||||
}
|
||||
|
||||
// 是否怀孕 (1:无计划 2:计划中 3:已怀孕 4:家有宝宝)'
|
||||
if req.IsPregnant != nil {
|
||||
if userInfo.IsPregnant != nil {
|
||||
if *req.IsPregnant != *userInfo.IsPregnant {
|
||||
userInfoData["is_pregnant"] = *req.IsPregnant
|
||||
}
|
||||
} else {
|
||||
userInfoData["is_pregnant"] = *req.IsPregnant
|
||||
}
|
||||
} else {
|
||||
if userInfo.IsPregnant != nil {
|
||||
userInfoData["is_pregnant"] = nil
|
||||
}
|
||||
}
|
||||
|
||||
// 预产期
|
||||
if req.ExpectedDate != "" {
|
||||
if userInfo.ExpectedDate != nil {
|
||||
expectedDate := time.Time(*userInfo.ExpectedDate).Format("2006-01-02")
|
||||
if req.ExpectedDate != expectedDate {
|
||||
userInfoData["expected_date"] = req.ExpectedDate
|
||||
}
|
||||
} else {
|
||||
userInfoData["expected_date"] = req.ExpectedDate
|
||||
}
|
||||
} else {
|
||||
if userInfo.ExpectedDate != nil {
|
||||
userInfoData["expected_date"] = nil
|
||||
}
|
||||
}
|
||||
|
||||
// 省份id
|
||||
provinceId, err := strconv.ParseInt(req.ProvinceId, 10, 64)
|
||||
if err != nil {
|
||||
return false, errors.New("省份错误")
|
||||
}
|
||||
|
||||
appData.ProvId = &provinceId
|
||||
|
||||
baseAreaDao := dao.BaseAreaDao{}
|
||||
baseArea, err := baseAreaDao.GetBaseAreaById(provinceId)
|
||||
if err != nil {
|
||||
return false, errors.New("省份错误")
|
||||
}
|
||||
|
||||
if userInfo.ProvinceId != nil {
|
||||
if provinceId != *userInfo.ProvinceId {
|
||||
userInfoData["province_id"] = provinceId
|
||||
userInfoData["province"] = baseArea.Name
|
||||
}
|
||||
} else {
|
||||
userInfoData["province_id"] = provinceId
|
||||
userInfoData["province"] = baseArea.Name
|
||||
}
|
||||
|
||||
// 城市id
|
||||
cityId, err := strconv.ParseInt(req.CityId, 10, 64)
|
||||
if err != nil {
|
||||
return false, errors.New("城市错误")
|
||||
}
|
||||
|
||||
appData.CityId = &cityId
|
||||
|
||||
baseArea, err = baseAreaDao.GetBaseAreaById(cityId)
|
||||
if err != nil {
|
||||
return false, errors.New("城市错误")
|
||||
}
|
||||
|
||||
if userInfo.CityId != nil {
|
||||
if cityId != *userInfo.CityId {
|
||||
userInfoData["city_id"] = cityId
|
||||
|
||||
userInfoData["city"] = baseArea.Name
|
||||
}
|
||||
} else {
|
||||
userInfoData["city_id"] = cityId
|
||||
userInfoData["city"] = baseArea.Name
|
||||
appData.CityId = &cityId
|
||||
}
|
||||
|
||||
// 区县id
|
||||
countyId, err := strconv.ParseInt(req.CountyId, 10, 64)
|
||||
if err != nil {
|
||||
return false, errors.New("城市错误")
|
||||
}
|
||||
|
||||
appData.CountyId = &countyId
|
||||
|
||||
baseArea, err = baseAreaDao.GetBaseAreaById(countyId)
|
||||
if err != nil {
|
||||
return false, errors.New("城市错误")
|
||||
}
|
||||
|
||||
if userInfo.CountyId != nil {
|
||||
if countyId != *userInfo.CountyId {
|
||||
userInfoData["county_id"] = countyId
|
||||
|
||||
userInfoData["county"] = baseArea.Name
|
||||
}
|
||||
} else {
|
||||
userInfoData["county_id"] = countyId
|
||||
userInfoData["county"] = baseArea.Name
|
||||
appData.CountyId = &countyId
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
@@ -679,6 +884,32 @@ func (r *UserService) PutUser(userId int64, req requests.PutUser) (bool, error)
|
||||
}
|
||||
}()
|
||||
|
||||
// 用户数据
|
||||
if len(userData) > 0 {
|
||||
err = userDao.EditUserById(tx, userId, userData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
// 用户详情数据
|
||||
if len(userInfoData) > 0 {
|
||||
err = userInfoDao.EditUserInfoById(tx, userInfo.UserInfoId, userInfoData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
// app数据
|
||||
appData.PatientUuid = user.AppIden
|
||||
_, err = app.UpdateInfo(appData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, err
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user