JM-WechatMini/api/v1/system/hospital.go

122 lines
2.9 KiB
Go
Raw Permalink Normal View History

2023-11-02 04:34:46 +08:00
package system
import (
"github.com/gin-gonic/gin"
2024-01-11 16:03:51 +08:00
"go.uber.org/zap"
"miniapp/global"
2023-11-02 04:34:46 +08:00
"miniapp/model/common"
"miniapp/model/common/request"
r "miniapp/model/common/response"
"strconv"
)
type HospitalApi struct {
}
// GetHospitalList 获取医院列表
func (h HospitalApi) GetHospitalList(ctx *gin.Context) {
var p request.PageInfo
if err := ctx.ShouldBind(&p); err != nil {
r.FailWithMessage("参数错误"+err.Error(), ctx)
return
}
2023-11-10 09:30:29 +08:00
list, total, err := hospitalService.GetHospitalList(p)
2023-11-02 04:34:46 +08:00
if err != nil {
r.FailWithMessage("获取医院列表失败", ctx)
return
}
r.OkWithDetailed(r.PageResult{List: list, Total: total, Page: p.Page, PageSize: p.PageSize}, "获取成功", ctx)
}
// CreateHospital 创建医院
func (h HospitalApi) CreateHospital(ctx *gin.Context) {
var hospital common.Hospital
if err := ctx.ShouldBindJSON(&hospital); err != nil {
r.FailWithMessage("参数错误"+err.Error(), ctx)
return
}
2023-11-10 09:30:29 +08:00
err := hospitalService.CreateHospital(&hospital)
2023-11-02 04:34:46 +08:00
if err != nil {
r.FailWithMessage("创建失败"+err.Error(), ctx)
return
}
r.OkWithMessage("创建成功", ctx)
}
// UpdateHospital 更新医院
func (h HospitalApi) UpdateHospital(ctx *gin.Context) {
var hospital common.Hospital
if err := ctx.ShouldBindJSON(&hospital); err != nil {
r.FailWithMessage("参数错误"+err.Error(), ctx)
return
}
2023-11-10 09:30:29 +08:00
err := hospitalService.UpdateHospital(&hospital)
2023-11-02 04:34:46 +08:00
if err != nil {
r.FailWithMessage("更新失败"+err.Error(), ctx)
return
}
r.OkWithMessage("更新成功", ctx)
}
// DeleteHospital 删除医院
func (h HospitalApi) DeleteHospital(ctx *gin.Context) {
var hospital common.Hospital
if err := ctx.ShouldBind(&hospital); err != nil {
r.FailWithMessage("参数错误"+err.Error(), ctx)
return
}
err := hospitalService.DeleteHospital(&hospital)
if err != nil {
r.FailWithMessage("删除失败"+err.Error(), ctx)
return
}
r.OkWithMessage("删除成功", ctx)
}
// GetHospitalById 根据id获取医院
func (h HospitalApi) GetHospitalById(ctx *gin.Context) {
Id := ctx.Param("id")
if Id == "" {
r.FailWithMessage("参数错误", ctx)
return
}
// 参数转换 string -> int
id, _ := strconv.Atoi(Id)
2023-11-10 09:30:29 +08:00
hospitalResult, err := hospitalService.GetHospitalById(uint(id))
2023-11-02 04:34:46 +08:00
if err != nil {
r.FailWithMessage("获取失败"+err.Error(), ctx)
return
}
r.OkWithDetailed(hospitalResult, "获取成功", ctx)
}
2024-01-11 16:03:51 +08:00
// GetHospitalNotes 根据id获取医院注意事项
func (h HospitalApi) GetHospitalNotes(ctx *gin.Context) {
p := request.GetHospitalNotes{}
if err := ctx.ShouldBind(&p); err != nil {
global.GVA_LOG.Error("参数错误", zap.Error(err))
r.FailWithMessage("参数错误"+err.Error(), ctx)
return
}
notes, err := hospitalService.GetHospitalNotes(p)
if err != nil {
global.GVA_LOG.Error("获取医院注意事项失败", zap.Error(err))
r.FailWithMessage("获取医院注意事项失败"+err.Error(), ctx)
return
}
r.OkWithData(notes, ctx)
}