新增了获取患者列表-限制条数

This commit is contained in:
wucongxing8150 2024-06-05 14:06:00 +08:00
parent eab9e413f7
commit 9f6b54a6c4
4 changed files with 95 additions and 0 deletions

View File

@ -118,3 +118,31 @@ func (r *UserPatient) PutUserDoctorStatus(c *gin.Context) {
responses.Ok(c)
}
// GetUserPatientList 获取患者列表-限制条数
func (r *UserPatient) GetUserPatientList(c *gin.Context) {
userPatientRequest := requests.UserPatientRequest{}
req := userPatientRequest.GetUserPatientList
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
}
userPatientDao := dao.UserPatientDao{}
userPatient, err := userPatientDao.GetUserPatientListSearch(req)
if err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 处理返回值
getUserPatientListResponses := dto.GetUserPatientListDto(userPatient)
responses.OkWithData(getUserPatientListResponses, c)
}

View File

@ -244,3 +244,58 @@ func (r *UserPatientDao) GetUserPatientByUserId(userId int64) (m *model.UserPati
}
return m, nil
}
// GetUserPatientListSearch 获取患者列表-限制条数
func (r *UserPatientDao) GetUserPatientListSearch(req requests.GetUserPatientList) (m []*model.UserPatient, err error) {
// 构建查询条件
query := global.Db.Model(&model.UserPatient{}).Omit("open_id", "union_id", "wx_session_key")
// 用户
query = query.Preload("User", func(db *gorm.DB) *gorm.DB {
return db.Omit("user_password", "salt")
})
// 用户名称
if req.UserName != "" {
query = query.Where("user_name LIKE ?", "%"+req.UserName+"%")
}
// 手机号
if req.Mobile != "" {
subQuery := global.Db.Model(&model.User{}).
Select("user_id").
Where("mobile = ?", req.Mobile)
query = query.Where(gorm.Expr("user_id IN (?)", subQuery))
}
// 用户状态
if req.Status != nil {
query = query.Where("status = ?", req.Status)
}
// 注册时间
if req.CreatedAt != "" {
cancelTime := strings.Split(req.CreatedAt, "&")
if len(cancelTime) == 2 {
startTime, _ := time.Parse("2006-01-02", cancelTime[0])
endTime, _ := time.Parse("2006-01-02", cancelTime[1])
if startTime == endTime {
endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
}
query = query.Where("created_at BETWEEN ? AND ?", startTime, endTime)
}
}
// 排序
query = query.Order("created_at desc")
err = query.Limit(10).Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}

View File

@ -4,6 +4,7 @@ type UserPatientRequest struct {
GetUserPatientPage // 获取患者列表-分页
PutUserDoctorStatus // 修改患者状态
UserPatientExportList // 患者列表-导出
GetUserPatientList // 获取患者列表-限制条数
}
// GetUserPatientPage 获取患者列表-分页
@ -31,3 +32,11 @@ type UserPatientExportList struct {
Mobile string `json:"mobile" form:"mobile" label:"手机号"`
CreatedAt string `json:"created_at" form:"created_at" label:"注册时间"` // 时间区间数组形式下标0为开始时间下标1为结束时间
}
// GetUserPatientList 获取患者列表-限制条数
type GetUserPatientList struct {
UserName string `json:"user_name" form:"user_name" label:"用户名称"`
Status *int `json:"status" form:"status" label:"状态"` // 0:禁用 1:正常 2:删除)
Mobile string `json:"mobile" form:"mobile" label:"手机号"`
CreatedAt string `json:"created_at" form:"created_at" label:"注册时间"` // 时间区间数组形式下标0为开始时间下标1为结束时间
}

View File

@ -482,6 +482,9 @@ func privateRouter(r *gin.Engine, api controller.Api) {
// 获取患者列表-分页
patientGroup.GET("", api.UserPatient.GetUserPatientPage)
// 获取患者列表-限制条数
patientGroup.GET("/list", api.UserPatient.GetUserPatientList)
// 患者详情
patientGroup.GET("/:patient_id", api.UserPatient.GetUserPatient)