医生绑定药房
This commit is contained in:
@@ -35,6 +35,7 @@ type sysSetting struct {
|
||||
type userDoctorManage struct {
|
||||
UserDoctor // 医生列表
|
||||
DoctorAccount
|
||||
DoctorPharmacy // 医生药房管理
|
||||
}
|
||||
|
||||
// Basic 基础数据
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/api/responses"
|
||||
"hospital-admin-api/api/service"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type DoctorPharmacy struct{}
|
||||
|
||||
// GetDoctorPharmacies 获取指定医生绑定的药房列表
|
||||
func (r *DoctorPharmacy) GetDoctorPharmacies(c *gin.Context) {
|
||||
id := c.Param("doctor_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
doctorId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
doctorPharmacyService := service.DoctorPharmacyService{}
|
||||
list, err := doctorPharmacyService.GetDoctorPharmacies(doctorId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(list, c)
|
||||
}
|
||||
|
||||
// BindDoctorPharmacies 批量设置/覆盖医生绑定的药房列表
|
||||
func (r *DoctorPharmacy) BindDoctorPharmacies(c *gin.Context) {
|
||||
id := c.Param("doctor_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
doctorId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
req := requests.BindDoctorPharmacies{}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
doctorPharmacyService := service.DoctorPharmacyService{}
|
||||
_, err = doctorPharmacyService.BindDoctorPharmacies(doctorId, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// AddDoctorPharmacy 为医生新增单个药房绑定
|
||||
func (r *DoctorPharmacy) AddDoctorPharmacy(c *gin.Context) {
|
||||
id := c.Param("doctor_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
doctorId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
req := requests.AddDoctorPharmacy{}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
doctorPharmacyService := service.DoctorPharmacyService{}
|
||||
_, err = doctorPharmacyService.AddDoctorPharmacy(doctorId, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// UnbindDoctorPharmacy 解除医生与指定药房的绑定
|
||||
func (r *DoctorPharmacy) UnbindDoctorPharmacy(c *gin.Context) {
|
||||
docId := c.Param("doctor_id")
|
||||
pharId := c.Param("pharmacy_id")
|
||||
if docId == "" || pharId == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
doctorId, err := strconv.ParseInt(docId, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
pharmacyId, err := strconv.ParseInt(pharId, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
doctorPharmacyService := service.DoctorPharmacyService{}
|
||||
_, err = doctorPharmacyService.UnbindDoctorPharmacy(doctorId, pharmacyId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// SetDefaultDoctorPharmacy 设为医生的默认药房
|
||||
func (r *DoctorPharmacy) SetDefaultDoctorPharmacy(c *gin.Context) {
|
||||
docId := c.Param("doctor_id")
|
||||
pharId := c.Param("pharmacy_id")
|
||||
if docId == "" || pharId == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
doctorId, err := strconv.ParseInt(docId, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
pharmacyId, err := strconv.ParseInt(pharId, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
doctorPharmacyService := service.DoctorPharmacyService{}
|
||||
_, err = doctorPharmacyService.SetDefaultPharmacy(doctorId, pharmacyId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
Reference in New Issue
Block a user