285 lines
6.3 KiB
Go
285 lines
6.3 KiB
Go
package controller
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"hospital-admin-api/api/dao"
|
|
"hospital-admin-api/api/dto"
|
|
"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 Pharmacy struct{}
|
|
|
|
// GetPharmacyPage 获取药房列表-分页
|
|
func (r *Pharmacy) GetPharmacyPage(c *gin.Context) {
|
|
pharmacyRequest := requests.PharmacyRequest{}
|
|
req := pharmacyRequest.GetPharmacyPage
|
|
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
|
|
}
|
|
|
|
if req.Page <= 0 {
|
|
req.Page = 1
|
|
}
|
|
|
|
if req.PageSize <= 0 {
|
|
req.PageSize = 20
|
|
}
|
|
|
|
pharmacyDao := dao.PharmacyDao{}
|
|
pharmacies, total, err := pharmacyDao.GetPharmacyPageSearch(req, req.Page, req.PageSize)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
resList := dto.GetPharmacyListDto(pharmacies)
|
|
|
|
result := make(map[string]interface{})
|
|
result["page"] = req.Page
|
|
result["page_size"] = req.PageSize
|
|
result["total"] = total
|
|
result["data"] = resList
|
|
responses.OkWithData(result, c)
|
|
}
|
|
|
|
// GetPharmacyList 获取药房列表(下拉/限制条件)
|
|
func (r *Pharmacy) GetPharmacyList(c *gin.Context) {
|
|
pharmacyRequest := requests.PharmacyRequest{}
|
|
req := pharmacyRequest.GetPharmacyList
|
|
if err := c.ShouldBind(&req); err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
maps := make(map[string]interface{})
|
|
if req.PharmacyName != "" {
|
|
maps["pharmacy_name"] = req.PharmacyName
|
|
}
|
|
if req.PharmacyCode != "" {
|
|
maps["pharmacy_code"] = req.PharmacyCode
|
|
}
|
|
if req.Status != nil {
|
|
maps["status"] = *req.Status
|
|
} else {
|
|
maps["status"] = 1 // 默认只查正常启用的
|
|
}
|
|
if req.IsPickup != nil {
|
|
maps["is_pickup"] = *req.IsPickup
|
|
}
|
|
|
|
pharmacyDao := dao.PharmacyDao{}
|
|
pharmacies, err := pharmacyDao.GetPharmacyList(maps)
|
|
if err != nil {
|
|
responses.Ok(c)
|
|
return
|
|
}
|
|
|
|
resList := dto.GetPharmacyListDto(pharmacies)
|
|
responses.OkWithData(resList, c)
|
|
}
|
|
|
|
// GetPharmacy 获取药房详情
|
|
func (r *Pharmacy) GetPharmacy(c *gin.Context) {
|
|
id := c.Param("pharmacy_id")
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少参数", c)
|
|
return
|
|
}
|
|
|
|
pharmacyId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
pharmacyService := service.PharmacyService{}
|
|
pharmacyDto, err := pharmacyService.GetPharmacy(pharmacyId)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
responses.OkWithData(pharmacyDto, c)
|
|
}
|
|
|
|
// AddPharmacy 新增药房
|
|
func (r *Pharmacy) AddPharmacy(c *gin.Context) {
|
|
pharmacyRequest := requests.PharmacyRequest{}
|
|
req := pharmacyRequest.AddPharmacy
|
|
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
|
|
}
|
|
|
|
pharmacyService := service.PharmacyService{}
|
|
_, err := pharmacyService.AddPharmacy(req)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
responses.Ok(c)
|
|
}
|
|
|
|
// PutPharmacy 修改药房
|
|
func (r *Pharmacy) PutPharmacy(c *gin.Context) {
|
|
pharmacyRequest := requests.PharmacyRequest{}
|
|
req := pharmacyRequest.PutPharmacy
|
|
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
|
|
}
|
|
|
|
id := c.Param("pharmacy_id")
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少参数", c)
|
|
return
|
|
}
|
|
|
|
pharmacyId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
pharmacyService := service.PharmacyService{}
|
|
_, err = pharmacyService.PutPharmacy(pharmacyId, req)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
responses.Ok(c)
|
|
}
|
|
|
|
// PutPharmacyStatus 修改药房状态
|
|
func (r *Pharmacy) PutPharmacyStatus(c *gin.Context) {
|
|
pharmacyRequest := requests.PharmacyRequest{}
|
|
req := pharmacyRequest.PutPharmacyStatus
|
|
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
|
|
}
|
|
|
|
id := c.Param("pharmacy_id")
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少参数", c)
|
|
return
|
|
}
|
|
|
|
pharmacyId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
pharmacyService := service.PharmacyService{}
|
|
_, err = pharmacyService.PutPharmacyStatus(pharmacyId, req)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
responses.Ok(c)
|
|
}
|
|
|
|
// DeletePharmacy 删除药房
|
|
func (r *Pharmacy) DeletePharmacy(c *gin.Context) {
|
|
id := c.Param("pharmacy_id")
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少参数", c)
|
|
return
|
|
}
|
|
|
|
pharmacyId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
pharmacyService := service.PharmacyService{}
|
|
_, err = pharmacyService.DeletePharmacy(pharmacyId)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
responses.Ok(c)
|
|
}
|
|
|
|
// GetPharmacyDoctorPage 获取药房绑定的医生列表-分页
|
|
func (r *Pharmacy) GetPharmacyDoctorPage(c *gin.Context) {
|
|
req := requests.GetPharmacyDoctorPage{}
|
|
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
|
|
}
|
|
|
|
pharmacyService := service.PharmacyService{}
|
|
result, err := pharmacyService.GetPharmacyDoctorPage(req)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
responses.OkWithData(result, c)
|
|
}
|
|
|
|
// GetPharmacyDoctorList 获取药房绑定的医生列表
|
|
func (r *Pharmacy) GetPharmacyDoctorList(c *gin.Context) {
|
|
id := c.Param("pharmacy_id")
|
|
if id == "" {
|
|
id = c.Param("id")
|
|
}
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少药房ID参数", c)
|
|
return
|
|
}
|
|
|
|
pharmacyId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
pharmacyService := service.PharmacyService{}
|
|
list, err := pharmacyService.GetPharmacyDoctorList(pharmacyId)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
responses.OkWithData(list, c)
|
|
}
|