修改了手机号登录
This commit is contained in:
parent
9a3a6bbb2e
commit
3fcc745e83
@ -56,6 +56,9 @@ func (r *Login) LoginPhone(c *gin.Context) {
|
||||
}
|
||||
}()
|
||||
|
||||
var userInfo *model.UserInfo
|
||||
var err error
|
||||
|
||||
// 检测用户信息
|
||||
userDao := dao.UserDao{}
|
||||
maps := make(map[string]interface{})
|
||||
@ -88,7 +91,7 @@ func (r *Login) LoginPhone(c *gin.Context) {
|
||||
loginAt := model.LocalTime(time.Now())
|
||||
user.LoginAt = &loginAt
|
||||
|
||||
user, err := userDao.AddUser(tx, user)
|
||||
user, err = userDao.AddUser(tx, user)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
@ -96,7 +99,7 @@ func (r *Login) LoginPhone(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 新增用户详情
|
||||
userInfo := &model.UserInfo{
|
||||
userInfo = &model.UserInfo{
|
||||
UserId: user.UserId,
|
||||
Height: "",
|
||||
Weight: "",
|
||||
@ -118,34 +121,32 @@ func (r *Login) LoginPhone(c *gin.Context) {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理app用户数据
|
||||
userService := service.UserService{}
|
||||
err = userService.HandleAppUserInfo(tx, user, userInfo)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
} else {
|
||||
// 获取用户详情数据
|
||||
userInfoDao := dao.UserInfoDao{}
|
||||
userInfo, err := userInfoDao.GetUserInfoByUserId(user.UserId)
|
||||
userInfo, err = userInfoDao.GetUserInfoByUserId(user.UserId)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 处理app用户数据
|
||||
userService := service.UserService{}
|
||||
err = userService.HandleAppUserInfo(tx, user, userInfo)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
// 处理app用户数据
|
||||
userService := service.UserService{}
|
||||
err = userService.HandleAppUserInfo(tx, user, userInfo)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理app用户病例数据
|
||||
err = userService.HandleAppUserCase(tx, user)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
@ -162,13 +163,6 @@ func (r *Login) LoginPhone(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取用户数据
|
||||
user, err = userDao.GetUser(maps)
|
||||
if err != nil {
|
||||
responses.FailWithMessage("登陆失败", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g := dto.LoginMobileDto(user)
|
||||
|
||||
@ -261,13 +255,6 @@ func (r *Login) LoginWx(c *gin.Context) {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 获取app用户信息
|
||||
//var result *string
|
||||
//if result == nil {
|
||||
// // 新增app用户信息
|
||||
//}
|
||||
|
||||
tx.Commit()
|
||||
}
|
||||
|
||||
|
||||
117
api/dao/BaseDiseaseClass.go
Normal file
117
api/dao/BaseDiseaseClass.go
Normal file
@ -0,0 +1,117 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hepa-calc-api/api/model"
|
||||
"hepa-calc-api/global"
|
||||
)
|
||||
|
||||
type BaseDiseaseClassDao struct {
|
||||
}
|
||||
|
||||
// GetBaseDiseaseClassById 获取数据-id
|
||||
func (r *BaseDiseaseClassDao) GetBaseDiseaseClassById(id int64) (m *model.BaseDiseaseClass, err error) {
|
||||
err = global.Db.First(&m, id).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetBaseDiseaseClassPreloadById 获取数据-加载全部关联-id
|
||||
func (r *BaseDiseaseClassDao) GetBaseDiseaseClassPreloadById(id int64) (m *model.BaseDiseaseClass, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, id).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetBaseDiseaseClassByAppIden 获取数据-app_iden
|
||||
func (r *BaseDiseaseClassDao) GetBaseDiseaseClassByAppIden(appIden string) (m *model.BaseDiseaseClass, err error) {
|
||||
err = global.Db.Where("app_iden = ?", appIden).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteBaseDiseaseClass 删除
|
||||
func (r *BaseDiseaseClassDao) DeleteBaseDiseaseClass(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.BaseDiseaseClass{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteBaseDiseaseClassById 删除-id
|
||||
func (r *BaseDiseaseClassDao) DeleteBaseDiseaseClassById(tx *gorm.DB, id int64) error {
|
||||
if err := tx.Delete(&model.BaseDiseaseClass{}, id).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditBaseDiseaseClass 修改
|
||||
func (r *BaseDiseaseClassDao) EditBaseDiseaseClass(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.BaseDiseaseClass{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditBaseDiseaseClassById 修改-id
|
||||
func (r *BaseDiseaseClassDao) EditBaseDiseaseClassById(tx *gorm.DB, id int64, data interface{}) error {
|
||||
err := tx.Model(&model.BaseDiseaseClass{}).Where("id = ?", id).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBaseDiseaseClassList 获取列表
|
||||
func (r *BaseDiseaseClassDao) GetBaseDiseaseClassList(maps interface{}) (m []*model.BaseDiseaseClass, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetBaseDiseaseClassCount 获取数量
|
||||
func (r *BaseDiseaseClassDao) GetBaseDiseaseClassCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.BaseDiseaseClass{}).Where(maps).Count(&total).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetBaseDiseaseClassListRand 获取列表-随机
|
||||
func (r *BaseDiseaseClassDao) GetBaseDiseaseClassListRand(maps interface{}, limit int) (m []*model.BaseDiseaseClass, err error) {
|
||||
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddBaseDiseaseClass 新增
|
||||
func (r *BaseDiseaseClassDao) AddBaseDiseaseClass(tx *gorm.DB, model *model.BaseDiseaseClass) (*model.BaseDiseaseClass, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetBaseDiseaseClass 获取
|
||||
func (r *BaseDiseaseClassDao) GetBaseDiseaseClass(maps interface{}) (m *model.BaseDiseaseClass, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
@ -28,6 +28,15 @@ func (r *UserCaseDao) GetUserCasePreloadById(UserCaseId int64) (m *model.UserCas
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetUserCaseByUserId 获取数据-user_id
|
||||
func (r *UserCaseDao) GetUserCaseByUserId(userId int64) (m *model.UserCase, err error) {
|
||||
err = global.Db.Where("user_id = ?", userId).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteUserCase 删除
|
||||
func (r *UserCaseDao) DeleteUserCase(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.UserCase{}).Error
|
||||
|
||||
117
api/dao/UserCaseDiseaseItem.go
Normal file
117
api/dao/UserCaseDiseaseItem.go
Normal file
@ -0,0 +1,117 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hepa-calc-api/api/model"
|
||||
"hepa-calc-api/global"
|
||||
)
|
||||
|
||||
type UserCaseDiseaseItemDao struct {
|
||||
}
|
||||
|
||||
// GetUserCaseDiseaseItemById 获取数据-id
|
||||
func (r *UserCaseDiseaseItemDao) GetUserCaseDiseaseItemById(itemId int64) (m *model.UserCaseDiseaseItem, err error) {
|
||||
err = global.Db.First(&m, itemId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetUserCaseDiseaseItemPreloadById 获取数据-加载全部关联-id
|
||||
func (r *UserCaseDiseaseItemDao) GetUserCaseDiseaseItemPreloadById(itemId int64) (m *model.UserCaseDiseaseItem, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, itemId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetUserCaseDiseaseItemByUserCaseId 获取数据-user_case_id
|
||||
func (r *UserCaseDiseaseItemDao) GetUserCaseDiseaseItemByUserCaseId(userCaseId int64) (m *model.UserCaseDiseaseItem, err error) {
|
||||
err = global.Db.Where("user_case_id = ?", userCaseId).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteUserCaseDiseaseItem 删除
|
||||
func (r *UserCaseDiseaseItemDao) DeleteUserCaseDiseaseItem(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.UserCaseDiseaseItem{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteUserCaseDiseaseItemById 删除-id
|
||||
func (r *UserCaseDiseaseItemDao) DeleteUserCaseDiseaseItemById(tx *gorm.DB, UserCaseDiseaseItemId int64) error {
|
||||
if err := tx.Delete(&model.UserCaseDiseaseItem{}, UserCaseDiseaseItemId).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditUserCaseDiseaseItem 修改
|
||||
func (r *UserCaseDiseaseItemDao) EditUserCaseDiseaseItem(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.UserCaseDiseaseItem{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditUserCaseDiseaseItemById 修改-id
|
||||
func (r *UserCaseDiseaseItemDao) EditUserCaseDiseaseItemById(tx *gorm.DB, itemId int64, data interface{}) error {
|
||||
err := tx.Model(&model.UserCaseDiseaseItem{}).Where("item_id = ?", itemId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetUserCaseDiseaseItemList 获取列表
|
||||
func (r *UserCaseDiseaseItemDao) GetUserCaseDiseaseItemList(maps interface{}) (m []*model.UserCaseDiseaseItem, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetUserCaseDiseaseItemCount 获取数量
|
||||
func (r *UserCaseDiseaseItemDao) GetUserCaseDiseaseItemCount(maps interface{}) (total int64, err error) {
|
||||
err = global.Db.Model(&model.UserCaseDiseaseItem{}).Where(maps).Count(&total).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return total, nil
|
||||
}
|
||||
|
||||
// GetUserCaseDiseaseItemListRand 获取列表-随机
|
||||
func (r *UserCaseDiseaseItemDao) GetUserCaseDiseaseItemListRand(maps interface{}, limit int) (m []*model.UserCaseDiseaseItem, err error) {
|
||||
err = global.Db.Where(maps).Order("rand()").Limit(limit).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddUserCaseDiseaseItem 新增
|
||||
func (r *UserCaseDiseaseItemDao) AddUserCaseDiseaseItem(tx *gorm.DB, model *model.UserCaseDiseaseItem) (*model.UserCaseDiseaseItem, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetUserCaseDiseaseItem 获取
|
||||
func (r *UserCaseDiseaseItemDao) GetUserCaseDiseaseItem(maps interface{}) (m *model.UserCaseDiseaseItem, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
34
api/model/BaseDiseaseClass.go
Normal file
34
api/model/BaseDiseaseClass.go
Normal file
@ -0,0 +1,34 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hepa-calc-api/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// BaseDiseaseClass 基础-疾病分类
|
||||
type BaseDiseaseClass struct {
|
||||
DiseaseClassId int64 `gorm:"column:disease_class_id;type:bigint(19);primary_key;comment:主键id" json:"disease_class_id"`
|
||||
AppIden string `gorm:"column:app_iden;type:varchar(50);comment:app唯一标识" json:"app_iden"`
|
||||
DiseaseClassName string `gorm:"column:disease_class_name;type:varchar(255);comment:疾病分类名称" json:"disease_class_name"`
|
||||
Sort int `gorm:"column:sort;type:int(5);default:0;comment:排序值" json:"sort"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *BaseDiseaseClass) TableName() string {
|
||||
return "base_disease_class"
|
||||
}
|
||||
|
||||
func (m *BaseDiseaseClass) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.DiseaseClassId == 0 {
|
||||
m.DiseaseClassId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -1,5 +1,11 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hepa-calc-api/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// UserCase 用户表-病例
|
||||
type UserCase struct {
|
||||
UserCaseId int64 `gorm:"column:user_case_id;type:bigint(19);primary_key;comment:主键id" json:"user_case_id"`
|
||||
@ -8,7 +14,7 @@ type UserCase struct {
|
||||
LiverStatus string `gorm:"column:liver_status;type:varchar(30);comment:肝脏状态" json:"liver_status"`
|
||||
IsMedication *int `gorm:"column:is_medication;type:tinyint(1);comment:是否服药(0:否 1:是)" json:"is_medication"`
|
||||
Medication string `gorm:"column:medication;type:varchar(20);comment:服药名称" json:"medication"`
|
||||
Disease string `gorm:"column:disease;type:varchar(500);comment:慢性疾病名称(逗号分隔)" json:"disease"`
|
||||
ChronicDisease string `gorm:"column:chronic_disease;type:varchar(500);comment:慢性疾病名称(逗号分隔)" json:"chronic_disease"`
|
||||
IsAllergyHistory *int `gorm:"column:is_allergy_history;type:tinyint(1);comment:过敏史(0:否 1:是)" json:"is_allergy_history"`
|
||||
AllergyHistory string `gorm:"column:allergy_history;type:varchar(100);comment:过敏史描述" json:"allergy_history"`
|
||||
Model
|
||||
@ -17,3 +23,17 @@ type UserCase struct {
|
||||
func (m *UserCase) TableName() string {
|
||||
return "user_case"
|
||||
}
|
||||
|
||||
func (m *UserCase) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.UserCaseId == 0 {
|
||||
m.UserCaseId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
36
api/model/UserCaseDiseaseItem.go
Normal file
36
api/model/UserCaseDiseaseItem.go
Normal file
@ -0,0 +1,36 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hepa-calc-api/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// UserCaseDiseaseItem 用户-病例-所患疾病列表
|
||||
type UserCaseDiseaseItem struct {
|
||||
ItemId int64 `gorm:"column:item_id;type:bigint(19);primary_key;comment:主键id" json:"item_id"`
|
||||
UserCaseId int64 `gorm:"column:user_case_id;type:bigint(19);comment:用户病例id" json:"user_case_id"`
|
||||
DiseaseClassId int64 `gorm:"column:disease_class_id;type:bigint(19);comment:疾病分类id" json:"disease_class_id"`
|
||||
AppIden string `gorm:"column:app_iden;type:varchar(50);comment:app唯一标识" json:"app_iden"`
|
||||
Duration *int `gorm:"column:duration;type:int(5);comment:患病时长(年)" json:"duration"`
|
||||
Genotype string `gorm:"column:genotype;type:varchar(20);comment:基因型(仅丙肝存在)" json:"genotype"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *UserCaseDiseaseItem) TableName() string {
|
||||
return "user_case_disease_item"
|
||||
}
|
||||
|
||||
func (m *UserCaseDiseaseItem) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.ItemId == 0 {
|
||||
m.ItemId = global.Snowflake.Generate().Int64()
|
||||
}
|
||||
|
||||
m.CreatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
||||
|
||||
m.UpdatedAt = LocalTime(time.Now())
|
||||
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -169,7 +169,7 @@ func (r *UserService) HandleAppUserInfo(tx *gorm.DB, user *model.User, userInfo
|
||||
// 出生日期/年龄
|
||||
if appUserInfo.Data.Birthday != "" {
|
||||
if user.Birthday != nil {
|
||||
birthday := time.Time(*user.Birthday).Format("2006-01-02 15:04:05")
|
||||
birthday := time.Time(*user.Birthday).Format("2006-01-02")
|
||||
if appUserInfo.Data.Birthday != birthday {
|
||||
userData["birthday"] = appUserInfo.Data.Birthday
|
||||
}
|
||||
@ -213,8 +213,8 @@ func (r *UserService) HandleAppUserInfo(tx *gorm.DB, user *model.User, userInfo
|
||||
}
|
||||
|
||||
// 体重
|
||||
if appUserInfo.Data.Weight != nil {
|
||||
weight := fmt.Sprintf("%f", appUserInfo.Data.Weight)
|
||||
if appUserInfo.Data.Weight != nil && *appUserInfo.Data.Weight != 0 {
|
||||
weight := fmt.Sprintf("%d", *appUserInfo.Data.Weight)
|
||||
|
||||
if userInfo.Weight != "" {
|
||||
if weight != userInfo.Weight {
|
||||
@ -225,6 +225,19 @@ func (r *UserService) HandleAppUserInfo(tx *gorm.DB, user *model.User, userInfo
|
||||
}
|
||||
}
|
||||
|
||||
// 身高
|
||||
if appUserInfo.Data.Height != nil && *appUserInfo.Data.Height != 0 {
|
||||
height := fmt.Sprintf("%d", *appUserInfo.Data.Height)
|
||||
|
||||
if userInfo.Height != "" {
|
||||
if height != userInfo.Height {
|
||||
userInfoData["height"] = height
|
||||
}
|
||||
} else {
|
||||
userInfoData["height"] = height
|
||||
}
|
||||
}
|
||||
|
||||
// 省份 id
|
||||
if appUserInfo.Data.ProvinceID != nil {
|
||||
// 获取省份数据
|
||||
@ -237,7 +250,7 @@ func (r *UserService) HandleAppUserInfo(tx *gorm.DB, user *model.User, userInfo
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
userInfoData["province_name"] = baseArea.Name
|
||||
userInfoData["province"] = baseArea.Name
|
||||
}
|
||||
} else {
|
||||
userInfoData["province_id"] = appUserInfo.Data.ProvinceID
|
||||
@ -246,7 +259,7 @@ func (r *UserService) HandleAppUserInfo(tx *gorm.DB, user *model.User, userInfo
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
userInfoData["province_name"] = baseArea.Name
|
||||
userInfoData["province"] = baseArea.Name
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,20 +271,20 @@ func (r *UserService) HandleAppUserInfo(tx *gorm.DB, user *model.User, userInfo
|
||||
if *appUserInfo.Data.CityID != *userInfo.CityId {
|
||||
userInfoData["city_id"] = appUserInfo.Data.CityID
|
||||
|
||||
baseArea, err := baseAreaDao.GetBaseAreaById(int64(*appUserInfo.Data.ProvinceID))
|
||||
baseArea, err := baseAreaDao.GetBaseAreaById(int64(*appUserInfo.Data.CityID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
userInfoData["city_name"] = baseArea.Name
|
||||
userInfoData["city"] = baseArea.Name
|
||||
}
|
||||
} else {
|
||||
userInfoData["city_id"] = appUserInfo.Data.CityID
|
||||
|
||||
baseArea, err := baseAreaDao.GetBaseAreaById(int64(*appUserInfo.Data.ProvinceID))
|
||||
baseArea, err := baseAreaDao.GetBaseAreaById(int64(*appUserInfo.Data.CityID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
userInfoData["city_name"] = baseArea.Name
|
||||
userInfoData["city"] = baseArea.Name
|
||||
}
|
||||
}
|
||||
|
||||
@ -283,20 +296,20 @@ func (r *UserService) HandleAppUserInfo(tx *gorm.DB, user *model.User, userInfo
|
||||
if *appUserInfo.Data.CountyID != *userInfo.CountyId {
|
||||
userInfoData["county_id"] = appUserInfo.Data.CountyID
|
||||
|
||||
baseArea, err := baseAreaDao.GetBaseAreaById(int64(*appUserInfo.Data.ProvinceID))
|
||||
baseArea, err := baseAreaDao.GetBaseAreaById(int64(*appUserInfo.Data.CountyID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
userInfoData["county_name"] = baseArea.Name
|
||||
userInfoData["county"] = baseArea.Name
|
||||
}
|
||||
} else {
|
||||
userInfoData["county_id"] = appUserInfo.Data.CountyID
|
||||
|
||||
baseArea, err := baseAreaDao.GetBaseAreaById(int64(*appUserInfo.Data.ProvinceID))
|
||||
baseArea, err := baseAreaDao.GetBaseAreaById(int64(*appUserInfo.Data.CountyID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
userInfoData["county_name"] = baseArea.Name
|
||||
userInfoData["county"] = baseArea.Name
|
||||
}
|
||||
}
|
||||
|
||||
@ -382,3 +395,195 @@ func (r *UserService) HandleAppUserInfo(tx *gorm.DB, user *model.User, userInfo
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// HandleAppUserCase 处理app用户病例数据
|
||||
func (r *UserService) HandleAppUserCase(tx *gorm.DB, user *model.User) error {
|
||||
appUserCase, err := app.GetUserCaseByAppIden(user.AppIden)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 用户无病例数据
|
||||
if appUserCase.Data == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 获取用户病例数据
|
||||
userCaseDao := dao.UserCaseDao{}
|
||||
userCase, _ := userCaseDao.GetUserCaseByUserId(user.UserId)
|
||||
if userCase == nil {
|
||||
// 未添加用户病例数据
|
||||
userCase = &model.UserCase{}
|
||||
userCase.UserId = user.UserId
|
||||
|
||||
// 是否过敏史
|
||||
if appUserCase.Data.IsAllergy != nil {
|
||||
userCase.IsAllergyHistory = appUserCase.Data.IsAllergy
|
||||
|
||||
// 过敏史描述
|
||||
if appUserCase.Data.AllergyInfo != "" {
|
||||
userCase.AllergyHistory = appUserCase.Data.AllergyInfo
|
||||
}
|
||||
}
|
||||
|
||||
// 是否服药
|
||||
if appUserCase.Data.IsMedication != nil {
|
||||
userCase.IsMedication = appUserCase.Data.IsMedication
|
||||
|
||||
// 服药名称
|
||||
if appUserCase.Data.MedicationInfo != "" {
|
||||
userCase.Medication = appUserCase.Data.MedicationInfo
|
||||
}
|
||||
}
|
||||
|
||||
// 是否去医院
|
||||
if appUserCase.Data.IsHospital != nil {
|
||||
userCase.IsHospital = appUserCase.Data.IsHospital
|
||||
}
|
||||
|
||||
// 慢性疾病
|
||||
if appUserCase.Data.OtherDisease != "" {
|
||||
userCase.ChronicDisease = appUserCase.Data.OtherDisease
|
||||
}
|
||||
|
||||
// 目前肝脏状态
|
||||
if appUserCase.Data.LiverStatus != "" {
|
||||
userCase.LiverStatus = appUserCase.Data.LiverStatus
|
||||
}
|
||||
|
||||
userCase, err = userCaseDao.AddUserCase(tx, userCase)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// 对比处理用户数据
|
||||
userCaseData := make(map[string]interface{}) // 用户病例数据
|
||||
|
||||
// 是否过敏史
|
||||
if appUserCase.Data.IsAllergy != nil {
|
||||
if userCase.IsAllergyHistory != nil {
|
||||
if *appUserCase.Data.IsAllergy != *userCase.IsAllergyHistory {
|
||||
userCaseData["is_allergy_history"] = appUserCase.Data.IsAllergy
|
||||
}
|
||||
} else {
|
||||
userCaseData["is_allergy_history"] = appUserCase.Data.IsAllergy
|
||||
}
|
||||
|
||||
// 过敏史描述
|
||||
if appUserCase.Data.AllergyInfo != "" {
|
||||
if userCase.AllergyHistory != "" {
|
||||
if appUserCase.Data.AllergyInfo != userCase.AllergyHistory {
|
||||
userCaseData["allergy_history"] = appUserCase.Data.AllergyInfo
|
||||
}
|
||||
} else {
|
||||
userCaseData["allergy_history"] = appUserCase.Data.AllergyInfo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 是否服药
|
||||
if appUserCase.Data.IsMedication != nil {
|
||||
if userCase.IsMedication != nil {
|
||||
if *appUserCase.Data.IsMedication != *userCase.IsMedication {
|
||||
userCaseData["is_medication"] = appUserCase.Data.IsMedication
|
||||
}
|
||||
} else {
|
||||
userCaseData["is_medication"] = appUserCase.Data.IsMedication
|
||||
}
|
||||
|
||||
// 服药名称
|
||||
if appUserCase.Data.MedicationInfo != "" {
|
||||
if userCase.Medication != "" {
|
||||
if appUserCase.Data.MedicationInfo != userCase.Medication {
|
||||
userCaseData["medication"] = appUserCase.Data.MedicationInfo
|
||||
}
|
||||
} else {
|
||||
userCaseData["medication"] = appUserCase.Data.MedicationInfo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 是否去医院
|
||||
if appUserCase.Data.IsHospital != nil {
|
||||
if userCase.IsHospital != nil {
|
||||
if *appUserCase.Data.IsHospital != *userCase.IsHospital {
|
||||
userCaseData["is_hospital"] = appUserCase.Data.IsHospital
|
||||
}
|
||||
} else {
|
||||
userCaseData["is_hospital"] = appUserCase.Data.IsHospital
|
||||
}
|
||||
}
|
||||
|
||||
// 慢性疾病
|
||||
if appUserCase.Data.OtherDisease != "" {
|
||||
if userCase.ChronicDisease != "" {
|
||||
if appUserCase.Data.OtherDisease != userCase.ChronicDisease {
|
||||
userCaseData["chronic_disease"] = appUserCase.Data.OtherDisease
|
||||
}
|
||||
} else {
|
||||
userCaseData["chronic_disease"] = appUserCase.Data.OtherDisease
|
||||
}
|
||||
}
|
||||
|
||||
// 目前肝脏状态
|
||||
if appUserCase.Data.LiverStatus != "" {
|
||||
if userCase.LiverStatus != "" {
|
||||
if appUserCase.Data.LiverStatus != userCase.LiverStatus {
|
||||
userCaseData["liver_status"] = appUserCase.Data.LiverStatus
|
||||
}
|
||||
} else {
|
||||
userCaseData["liver_status"] = appUserCase.Data.LiverStatus
|
||||
}
|
||||
}
|
||||
|
||||
// 修改用户病例数据
|
||||
if len(userCaseData) > 0 {
|
||||
err := userCaseDao.EditUserCaseById(tx, userCase.UserCaseId, userCaseData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if len(appUserCase.Data.DiseasesList) > 0 {
|
||||
userCaseDiseaseItemDao := dao.UserCaseDiseaseItemDao{}
|
||||
|
||||
// 删除所患疾病列表
|
||||
maps := make(map[string]interface{})
|
||||
maps["user_case_id"] = userCase.UserCaseId
|
||||
err := userCaseDiseaseItemDao.DeleteUserCaseDiseaseItem(tx, maps)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 所患疾病列表
|
||||
if len(appUserCase.Data.DiseasesList) > 0 {
|
||||
for _, data := range appUserCase.Data.DiseasesList {
|
||||
userCaseDiseaseItemDao := dao.UserCaseDiseaseItemDao{}
|
||||
baseDiseaseClassDao := dao.BaseDiseaseClassDao{}
|
||||
|
||||
// 获取基础数据-疾病分类
|
||||
baseDiseaseClass, err := baseDiseaseClassDao.GetBaseDiseaseClassByAppIden(data.UUID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 新增所患疾病列表
|
||||
userCaseDiseaseItem := &model.UserCaseDiseaseItem{
|
||||
UserCaseId: userCase.UserCaseId,
|
||||
DiseaseClassId: baseDiseaseClass.DiseaseClassId,
|
||||
AppIden: data.UUID,
|
||||
Duration: data.Year,
|
||||
Genotype: data.Info,
|
||||
}
|
||||
|
||||
userCaseDiseaseItem, err = userCaseDiseaseItemDao.AddUserCaseDiseaseItem(tx, userCaseDiseaseItem)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
132
extend/app/userCase.go
Normal file
132
extend/app/userCase.go
Normal file
@ -0,0 +1,132 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"hepa-calc-api/utils"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// GetUserCaseByAppIdenRequest 根据app唯一标识获取用户病例信息-请求数据
|
||||
type GetUserCaseByAppIdenRequest struct {
|
||||
PatientUuid string `json:"patientUuid"` // 患者 uuid
|
||||
Platform string `json:"platform"` // 所属平台
|
||||
Timestamp string `json:"timestamp"` // 当前时间戳(10位)
|
||||
}
|
||||
|
||||
// GetUserCaseByAppIdenResponse 根据app唯一标识获取用户病例信息-返回数据
|
||||
type GetUserCaseByAppIdenResponse struct {
|
||||
Code int `json:"code"` // 接口调用状态。200:正常;其它值:调用出错
|
||||
Msg string `json:"msg"` // 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok
|
||||
Data *GetUserCaseByAppIdenData `json:"data"` // 接口返回结果,各个接口自定义,数据结构参考具体文档说明
|
||||
Success bool `json:"success"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// GetUserCaseByAppIdenData 根据app唯一标识获取用户病例信息-data详细数据
|
||||
type GetUserCaseByAppIdenData struct {
|
||||
AllergyInfo string `json:"allergyInfo" description:"过敏史详情"`
|
||||
PatientUUID string `json:"patientUuid" description:"患者 uuid"`
|
||||
DiseasesList []*DiseaseData `json:"diseasesList" description:"所患疾病列表"`
|
||||
MedicationInfo string `json:"medicationInfo" description:"正在服用的药物"`
|
||||
OtherDisease string `json:"otherDisease" description:"合并其他慢性疾病 (多个英文逗号分隔拼接)"`
|
||||
IsMedication *int `json:"isMedication" description:"是否服药 0否 1是"`
|
||||
IsHospital *int `json:"isHospital" description:"是否去医院 0否 1是"`
|
||||
IsAllergy *int `json:"isAllergy" description:"是否过敏史 0否 1是"`
|
||||
LiverStatus string `json:"liverStatus" description:"目前肝脏状态"`
|
||||
}
|
||||
|
||||
// DiseaseData 所患疾病数据
|
||||
type DiseaseData struct {
|
||||
UUID string `json:"uuid" description:"疾病 uuid"`
|
||||
Year *int `json:"year" description:"患病时长"`
|
||||
Info string `json:"info" description:"丙肝基因型(仅针对丙肝)"`
|
||||
Name string `json:"name" description:"疾病名称"`
|
||||
}
|
||||
|
||||
// GetUserCaseByAppIden 根据app唯一标识获取用户病例信息
|
||||
func GetUserCaseByAppIden(appIden string) (g *GetUserCaseByAppIdenResponse, err error) {
|
||||
// 准备要发送的 JSON 数据
|
||||
requestData := GetUserCaseByAppIdenRequest{
|
||||
PatientUuid: appIden,
|
||||
Platform: platform,
|
||||
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
|
||||
}
|
||||
|
||||
// 将 JSON 数据编码为字节数组
|
||||
jsonData, err := json.Marshal(requestData)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
err = json.Unmarshal(jsonData, &maps)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 获取请求签名
|
||||
sign, err := GenSignature(maps)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 准备请求体
|
||||
requestBody := bytes.NewBuffer(jsonData)
|
||||
|
||||
// 设置请求 URL
|
||||
url := apiUrl + "/patient-api/getDiseaseInfo"
|
||||
|
||||
// 创建 POST 请求
|
||||
req, err := http.NewRequest("POST", url, requestBody)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("sign", sign)
|
||||
|
||||
// 发送请求
|
||||
client := &http.Client{}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
_ = Body.Close()
|
||||
}(resp.Body)
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return g, err
|
||||
}
|
||||
|
||||
// 检查响应状态码
|
||||
if resp.StatusCode != 200 {
|
||||
return g, errors.New("失败")
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, &g)
|
||||
if err != nil {
|
||||
// json解析失败
|
||||
return g, err
|
||||
}
|
||||
|
||||
utils.LogJsonInfo("获取app数据返回", g)
|
||||
|
||||
if g.Code != 200 {
|
||||
if g.Msg != "" {
|
||||
return g, errors.New(g.Msg)
|
||||
} else {
|
||||
return g, errors.New("失败")
|
||||
}
|
||||
}
|
||||
|
||||
return g, nil
|
||||
}
|
||||
@ -29,23 +29,23 @@ type GetInfoByMobileResponse struct {
|
||||
|
||||
// GetInfoByMobileData 根据手机号获取用户信息-data详细数据
|
||||
type GetInfoByMobileData struct {
|
||||
Birthday string `json:"birthday" description:"出生日期"`
|
||||
IsPregnant *int `json:"isPregnant" description:"是否怀孕 1无计划 2计划中 3已怀孕 4家有宝宝"`
|
||||
Sex *int `json:"sex" description:"性别 0男 1女"`
|
||||
Mobile string `json:"mobile" description:"手机号"`
|
||||
Photo string `json:"photo" description:"头像地址"`
|
||||
Weight *float64 `json:"weight" description:"体重 KG"`
|
||||
CityID *int `json:"cityId" description:"城市 id"`
|
||||
ExpectedDateOfChildbirth string `json:"expectedDateOfChildbirth" description:"预产期"`
|
||||
CountyID *int `json:"countyId" description:"市区 id"`
|
||||
IsHBV *int `json:"isHbv" description:"有无 肝硬化或肝癌家族史 0无1有2未知"`
|
||||
NationUUID string `json:"nationUuid" description:"民族 uuid"`
|
||||
PatientUUID string `json:"patientUuid" description:"患者 uuid"`
|
||||
Name string `json:"name" description:"姓名"`
|
||||
ProvinceID *int `json:"provId" description:"省份 id"`
|
||||
Height *float64 `json:"height" description:"身高 cm"`
|
||||
OpenId string `json:"openid" description:"openid"`
|
||||
UnionId string `json:"unionid" description:"unionid"`
|
||||
Birthday string `json:"birthday" description:"出生日期"`
|
||||
IsPregnant *int `json:"isPregnant" description:"是否怀孕 1无计划 2计划中 3已怀孕 4家有宝宝"`
|
||||
Sex *int `json:"sex" description:"性别 0男 1女"`
|
||||
Mobile string `json:"mobile" description:"手机号"`
|
||||
Photo string `json:"photo" description:"头像地址"`
|
||||
Weight *int `json:"weight" description:"体重 KG"`
|
||||
CityID *int `json:"cityId" description:"城市 id"`
|
||||
ExpectedDateOfChildbirth string `json:"expectedDateOfChildbirth" description:"预产期"`
|
||||
CountyID *int `json:"countyId" description:"市区 id"`
|
||||
IsHBV *int `json:"isHbv" description:"有无 肝硬化或肝癌家族史 0无1有2未知"`
|
||||
NationUUID string `json:"nationUuid" description:"民族 uuid"`
|
||||
PatientUUID string `json:"patientUuid" description:"患者 uuid"`
|
||||
Name string `json:"name" description:"姓名"`
|
||||
ProvinceID *int `json:"provId" description:"省份 id"`
|
||||
Height *int `json:"height" description:"身高 cm"`
|
||||
OpenId string `json:"openid" description:"openid"`
|
||||
UnionId string `json:"unionid" description:"unionid"`
|
||||
}
|
||||
|
||||
// GetInfoByMobile 根据手机号获取用户信息
|
||||
|
||||
@ -1,11 +1,6 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gen2brain/go-fitz"
|
||||
"image/jpeg"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -45,50 +40,10 @@ func ComputeIndividualIncomeTax(income float64) float64 {
|
||||
return incomeTax
|
||||
}
|
||||
|
||||
// ConvertPDFToImages converts a PDF file to images and saves them in the specified output directory.
|
||||
func ConvertPDFToImages(pdfPath string, outputDir string, filename string) error {
|
||||
// Open the PDF file
|
||||
doc, err := fitz.New(pdfPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open PDF file: %v", err)
|
||||
}
|
||||
defer doc.Close()
|
||||
|
||||
// Ensure the output directory exists
|
||||
if err := os.MkdirAll(outputDir, os.ModePerm); err != nil {
|
||||
return fmt.Errorf("failed to create output directory: %v", err)
|
||||
}
|
||||
|
||||
// Iterate over each page in the PDF
|
||||
for i := 0; i < doc.NumPage(); i++ {
|
||||
// Render the page to an image
|
||||
img, err := doc.Image(i)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to render page %d: %v", i, err)
|
||||
}
|
||||
|
||||
// Create the output file
|
||||
outputFile := filepath.Join(outputDir, filename)
|
||||
file, err := os.Create(outputFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create output file: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
// Encode the image as JPEG and save it to the file
|
||||
opts := &jpeg.Options{Quality: 80}
|
||||
if err := jpeg.Encode(file, img, opts); err != nil {
|
||||
return fmt.Errorf("failed to encode image: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CalculateAge 计算年龄
|
||||
func CalculateAge(birthdate string) (int, error) {
|
||||
// 解析出生日期字符串
|
||||
layout := "2006-01-02 15:04:05"
|
||||
layout := "2006-01-02"
|
||||
birthTime, err := time.Parse(layout, birthdate)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user