From 8525e0263fd9af2eaf679f9d3ca9d9cdc7db4057 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Wed, 8 Jan 2025 13:44:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E4=BA=86=E7=AE=97=E4=B8=80?= =?UTF-8?q?=E7=AE=97app=E7=94=A8=E6=88=B7=E7=BB=91=E5=AE=9A=E3=80=82?= =?UTF-8?q?=E4=B8=BB=E8=A6=81=E6=B6=89=E5=8F=8A=E6=8E=A5=E5=8F=A3=E4=B8=BA?= =?UTF-8?q?=E7=99=BB=E9=99=86=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/Login.go | 94 +++----------------------------------- api/controller/Public.go | 2 + api/controller/User.go | 58 ----------------------- api/controller/UserCase.go | 44 +----------------- api/dao/Question.go | 2 - api/requests/Login.go | 10 ++-- api/requests/User.go | 3 +- api/router/router.go | 7 --- api/service/User.go | 72 ----------------------------- 9 files changed, 15 insertions(+), 277 deletions(-) diff --git a/api/controller/Login.go b/api/controller/Login.go index 596ff02..26c6537 100644 --- a/api/controller/Login.go +++ b/api/controller/Login.go @@ -9,7 +9,6 @@ import ( "hepa-calc-api/api/requests" "hepa-calc-api/api/responses" "hepa-calc-api/api/service" - "hepa-calc-api/config" "hepa-calc-api/global" "hepa-calc-api/utils" "time" @@ -32,36 +31,10 @@ func (r *Login) Login(c *gin.Context) { return } - // 公众号登录 - if req.Source == 2 { - if req.Mobile == "" || req.OpenId == "" { - responses.FailWithMessage("登陆失败", c) - return - } - } - // 检测参数 - if req.Mobile != "" { - // 检测验证码 - if config.C.Env != "dev" { - if req.Source == 2 { - if req.Code == "" { - responses.FailWithMessage("请输入手机号验证码", c) - return - } - - code, _ := global.Redis.Get(c, "login_code_"+req.Mobile).Result() - if code == "" { - responses.FailWithMessage("验证码失效", c) - return - } - - if req.Code != code { - responses.FailWithMessage("验证码错误", c) - return - } - } - } + if req.Source == 2 && req.OpenId == "" { + responses.FailWithMessage("登陆失败", c) + return } // 开始事务 @@ -75,13 +48,10 @@ func (r *Login) Login(c *gin.Context) { } }() - var userInfo *model.UserInfo - var err error - // 检测用户信息 userDao := dao.UserDao{} maps := make(map[string]interface{}) - maps["mobile"] = req.Mobile + maps["open_id"] = req.OpenId user, _ := userDao.GetUser(maps) // 新用户处理方式 if user == nil { @@ -100,9 +70,7 @@ func (r *Login) Login(c *gin.Context) { // 新增用户 user = &model.User{ - UserName: "", - AppIden: req.Uuid, - Mobile: req.Mobile, + UserName: req.UserName, RegisterSource: req.Source, OpenId: req.OpenId, UnionId: req.UnionId, @@ -124,7 +92,7 @@ func (r *Login) Login(c *gin.Context) { } // 新增用户详情 - userInfo = &model.UserInfo{ + userInfo := &model.UserInfo{ UserId: user.UserId, Height: "", Weight: "", @@ -146,58 +114,10 @@ func (r *Login) Login(c *gin.Context) { responses.FailWithMessage(err.Error(), c) return } - } else { - // 获取用户详情数据 - userInfoDao := dao.UserInfoDao{} - userInfo, err = userInfoDao.GetUserInfoByUserId(user.UserId) - if err != nil { - tx.Rollback() - responses.FailWithMessage(err.Error(), c) - return - } - - // 处理用户openid - if req.OpenId != "" { - userData := make(map[string]interface{}) - if req.OpenId != user.OpenId { - userData["open_id"] = req.OpenId - } - - err := userDao.EditUserById(tx, user.UserId, userData) - if err != nil { - tx.Rollback() - responses.FailWithMessage(err.Error(), c) - return - } - } - } - - // 处理app用户数据 - userService := service.UserService{} - err = userService.GetAppUserInfo(tx, user, userInfo) - if err != nil { - tx.Rollback() - responses.FailWithMessage(err.Error(), c) - return - } - - // 处理app用户病例数据 - err = userService.GetAppUserCase(tx, user) - if err != nil { - tx.Rollback() - responses.FailWithMessage(err.Error(), c) - return } tx.Commit() - // 获取用户信息 - user, err = userDao.GetUserById(user.UserId) - if err != nil { - responses.FailWithMessage(err.Error(), c) - return - } - // 下发token token := &utils.Token{ UserId: fmt.Sprintf("%d", user.UserId), @@ -211,7 +131,7 @@ func (r *Login) Login(c *gin.Context) { } // 处理返回值 - g := dto.LoginMobileDto(user) + g := dto.LoginWxDto(user) // 加载token g.LoadToken(jwt) diff --git a/api/controller/Public.go b/api/controller/Public.go index dab5475..edcb0fe 100644 --- a/api/controller/Public.go +++ b/api/controller/Public.go @@ -27,6 +27,8 @@ func (b *Public) GetCaptcha(c *gin.Context) { // GetPhoneCode 获取手机验证码 func (b *Public) GetPhoneCode(c *gin.Context) { + responses.Ok(c) + return publicRequest := requests.PublicRequest{} req := publicRequest.GetPhoneCode if err := c.ShouldBind(&req); err != nil { diff --git a/api/controller/User.go b/api/controller/User.go index a48f990..de5651a 100644 --- a/api/controller/User.go +++ b/api/controller/User.go @@ -170,61 +170,3 @@ func (r *User) PutBindUserName(c *gin.Context) { responses.Ok(c) } - -// GetUserCheck 检测用户数据绑定状态 -func (r *User) GetUserCheck(c *gin.Context) { - userRequest := requests.UserRequest{} - req := userRequest.GetUserCheck - if err := c.ShouldBind(&req); err != nil { - responses.FailWithMessage(err.Error(), c) - return - } - - // 参数验证 - if err := global.Validate.Struct(req); err != nil { - responses.FailWithMessage(utils.Translate(err), c) - return - } - - if req.Mobile == "" && req.OpenId == "" { - responses.FailWithMessage("缺少参数", c) - return - } - - g := &dto.UserCheckDto{} - - // 获取用户数据 - maps := make(map[string]interface{}) - if req.OpenId != "" { - maps["open_id"] = req.OpenId - } - - if req.Mobile != "" { - maps["mobile"] = req.Mobile - } - - userDao := dao.UserDao{} - user, err := userDao.GetUser(maps) - if err != nil || user == nil { - g.WxStatus = 0 - g.MobileStatus = 0 - responses.OkWithData(g, c) - return - } - - if user.UserStatus == 2 { - responses.FailWithMessage("用户已禁用", c) - return - } - - if user.Mobile != "" { - g.MobileStatus = 1 - g.Mobile = user.Mobile - } - - if user.OpenId != "" { - g.WxStatus = 1 - } - - responses.OkWithData(g, c) -} diff --git a/api/controller/UserCase.go b/api/controller/UserCase.go index 8056780..0e886d6 100644 --- a/api/controller/UserCase.go +++ b/api/controller/UserCase.go @@ -8,7 +8,6 @@ import ( "hepa-calc-api/api/requests" "hepa-calc-api/api/responses" "hepa-calc-api/api/service" - "hepa-calc-api/extend/app" "hepa-calc-api/global" "hepa-calc-api/utils" "strconv" @@ -62,14 +61,6 @@ func (r *UserCase) PutUserCase(c *gin.Context) { userId := c.GetInt64("UserId") - // 获取用户数据 - userDao := dao.UserDao{} - user, err := userDao.GetUserById(userId) - if err != nil { - responses.FailWithMessage("用户数据错误", c) - return - } - // 获取用户数据-病例 userCaseDao := dao.UserCaseDao{} userCase, err := userCaseDao.GetUserCaseByUserId(userId) @@ -79,17 +70,6 @@ func (r *UserCase) PutUserCase(c *gin.Context) { } userCaseData := make(map[string]interface{}) - appData := app.UpdateUserCaseRequest{ - IsAllergy: req.IsAllergyHistory, - AllergyInfo: req.AllergyHistory, - IsHospital: req.IsHospital, - IsMedication: req.IsMedication, - MedicationInfo: req.Medication, - LiverStatus: req.LiverStatus, - OtherDisease: req.ChronicDisease, - PatientUuid: user.AppIden, - DiseasesList: nil, - } // 是否医院就诊 if req.IsHospital != nil { @@ -163,9 +143,7 @@ func (r *UserCase) PutUserCase(c *gin.Context) { // 所患疾病列表 if len(req.UserCaseDiseaseItem) > 0 { baseDiseaseClassDao := dao.BaseDiseaseClassDao{} - diseasesLists := make([]*app.DiseasesListRequest, len(req.UserCaseDiseaseItem)) - - for i, item := range req.UserCaseDiseaseItem { + for _, item := range req.UserCaseDiseaseItem { diseaseClassId, err := strconv.ParseInt(item.DiseaseClassId, 10, 64) if err != nil { tx.Rollback() @@ -195,18 +173,7 @@ func (r *UserCase) PutUserCase(c *gin.Context) { responses.Fail(c) return } - - // app请求数据 - diseasesList := &app.DiseasesListRequest{ - Uuid: baseDiseaseClass.AppIden, - Year: &item.Duration, - Info: item.Genotype, - Name: baseDiseaseClass.DiseaseClassName, - } - diseasesLists[i] = diseasesList } - - appData.DiseasesList = diseasesLists } // 病例数据 @@ -228,15 +195,6 @@ func (r *UserCase) PutUserCase(c *gin.Context) { return } - // app数据 - appData.PatientUuid = user.AppIden - _, err = app.UpdateUserCase(appData) - if err != nil { - tx.Rollback() - responses.Fail(c) - return - } - tx.Commit() responses.Ok(c) } diff --git a/api/dao/Question.go b/api/dao/Question.go index e34b054..b2aac0e 100644 --- a/api/dao/Question.go +++ b/api/dao/Question.go @@ -2,7 +2,6 @@ package dao import ( "errors" - "fmt" "gorm.io/gorm" "gorm.io/gorm/clause" "hepa-calc-api/api/model" @@ -187,7 +186,6 @@ func (r *QuestionDao) GetQuestionPageSearch(req requests.GetQuestionPage, page, // 搜索关键字 if req.Keyword != "" { - fmt.Println(111) keyword := "%" + req.Keyword + "%" // // 标题 diff --git a/api/requests/Login.go b/api/requests/Login.go index 9d2c6bd..1c8f8ed 100644 --- a/api/requests/Login.go +++ b/api/requests/Login.go @@ -6,11 +6,9 @@ type LoginRequest struct { // Login 登录 type Login struct { - Mobile string `json:"mobile" form:"mobile" label:"手机号" validate:"required,Mobile"` - Code string `json:"code" form:"code" label:"验证码"` - Source int `json:"source" form:"source" label:"来源" validate:"required"` // (1:app 2:公众号) - OpenId string `json:"openid" form:"openid" label:"openid"` + Source int `json:"source" form:"source" label:"来源" validate:"required,oneof=2"` // (1:app 2:公众号) + OpenId string `json:"openid" form:"openid" label:"openid" validate:"required"` HeadImgUrl string `json:"headimgurl" form:"headimgurl" label:"头像"` - UnionId string `json:"unionid" form:"unionid" label:"unionid"` - Uuid string `json:"uuid" form:"uuid" label:"app唯一标识"` + UnionId string `json:"unionid" form:"unionid" label:"unionid" validate:"required"` + UserName string `json:"user_name" form:"user_name" label:"用户名称" validate:"required"` } diff --git a/api/requests/User.go b/api/requests/User.go index 0503812..c5404b5 100644 --- a/api/requests/User.go +++ b/api/requests/User.go @@ -30,6 +30,5 @@ type PutBindUserName struct { // GetUserCheck 检测用户数据绑定状态 type GetUserCheck struct { - Mobile string `json:"mobile" form:"mobile" label:"mobile"` - OpenId string `json:"openid" form:"openid" label:"openid"` + OpenId string `json:"openid" form:"openid" label:"openid" validate:"required"` } diff --git a/api/router/router.go b/api/router/router.go index 6021838..560f96c 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -79,13 +79,6 @@ func publicRouter(r *gin.Engine, api controller.Api) { loginGroup.POST("", api.Login.Login) } - // 用户 - centerGroup := r.Group("/user") - { - // 检测用户数据绑定状态 - centerGroup.GET("/check", api.User.GetUserCheck) - } - // 验证码 codeGroup := r.Group("/code") { diff --git a/api/service/User.go b/api/service/User.go index 7393a69..eedf3e3 100644 --- a/api/service/User.go +++ b/api/service/User.go @@ -642,21 +642,6 @@ func (r *UserService) PutUser(userId int64, req requests.PutUser) (bool, error) 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 { @@ -681,15 +666,6 @@ func (r *UserService) PutUser(userId int64, req requests.PutUser) (bool, error) userData["age"] = nil } - // 性别 - if req.Sex == 1 { - sex := 0 - appData.Sex = &sex - } else if req.Sex == 2 { - sex := 1 - appData.Sex = &sex - } - if user.Sex != nil { if req.Sex != *user.Sex { userData["sex"] = req.Sex @@ -741,51 +717,16 @@ func (r *UserService) PutUser(userId int64, req requests.PutUser) (bool, error) fmt.Println(req.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 { @@ -837,8 +778,6 @@ func (r *UserService) PutUser(userId int64, req requests.PutUser) (bool, error) return false, errors.New("省份错误") } - appData.ProvId = &provinceId - baseAreaDao := dao.BaseAreaDao{} baseArea, err := baseAreaDao.GetBaseAreaById(provinceId) if err != nil { @@ -861,8 +800,6 @@ func (r *UserService) PutUser(userId int64, req requests.PutUser) (bool, error) return false, errors.New("城市错误") } - appData.CityId = &cityId - baseArea, err = baseAreaDao.GetBaseAreaById(cityId) if err != nil { return false, errors.New("城市错误") @@ -884,7 +821,6 @@ func (r *UserService) PutUser(userId int64, req requests.PutUser) (bool, error) if err != nil { return false, errors.New("区县错误") } - appData.CountyId = &countyId baseArea, err = baseAreaDao.GetBaseAreaById(countyId) if err != nil { @@ -928,14 +864,6 @@ func (r *UserService) PutUser(userId int64, req requests.PutUser) (bool, error) } } - // app数据 - appData.PatientUuid = user.AppIden - _, err = app.UpdateInfo(appData) - if err != nil { - tx.Rollback() - return false, err - } - tx.Commit() return true, nil }