82 lines
2.3 KiB
Go
82 lines
2.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 OrderPrescription struct{}
|
|
|
|
// GetOrderPrescriptionPage 获取处方列表-分页
|
|
func (r *OrderPrescription) GetOrderPrescriptionPage(c *gin.Context) {
|
|
req := requests.OrderPrescriptionRequest{}
|
|
if err := c.ShouldBind(&req.GetOrderPrescriptionPage); err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
// 参数验证
|
|
if err := global.Validate.Struct(req.GetOrderPrescriptionPage); err != nil {
|
|
responses.FailWithMessage(utils.Translate(err), c)
|
|
return
|
|
}
|
|
|
|
if req.GetOrderPrescriptionPage.Page == 0 {
|
|
req.GetOrderPrescriptionPage.Page = 1
|
|
}
|
|
|
|
if req.GetOrderPrescriptionPage.PageSize == 0 {
|
|
req.GetOrderPrescriptionPage.PageSize = 20
|
|
}
|
|
|
|
orderPrescriptionDao := dao.OrderPrescriptionDao{}
|
|
orderPrescription, total, err := orderPrescriptionDao.GetOrderPrescriptionPageSearch(req.GetOrderPrescriptionPage, req.GetOrderPrescriptionPage.Page, req.GetOrderPrescriptionPage.PageSize)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
// 处理返回值
|
|
GetOrderPrescriptionPage := dto.GetOrderPrescriptionListDto(orderPrescription)
|
|
|
|
result := make(map[string]interface{})
|
|
result["page"] = req.GetOrderPrescriptionPage.Page
|
|
result["page_size"] = req.GetOrderPrescriptionPage.PageSize
|
|
result["total"] = total
|
|
result["data"] = GetOrderPrescriptionPage
|
|
responses.OkWithData(result, c)
|
|
}
|
|
|
|
// GetOrderPrescription 处方详情
|
|
func (r *OrderPrescription) GetOrderPrescription(c *gin.Context) {
|
|
id := c.Param("order_prescription_id")
|
|
if id == "" {
|
|
responses.FailWithMessage("缺少参数", c)
|
|
return
|
|
}
|
|
|
|
// 将 id 转换为 int64 类型
|
|
orderPrescriptionId, err := strconv.ParseInt(id, 10, 64)
|
|
if err != nil {
|
|
responses.Fail(c)
|
|
return
|
|
}
|
|
|
|
// 业务处理
|
|
orderPrescriptionService := service.OrderPrescriptionService{}
|
|
getPrescriptionResponse, err := orderPrescriptionService.GetOrderPrescription(orderPrescriptionId)
|
|
if err != nil {
|
|
responses.FailWithMessage(err.Error(), c)
|
|
return
|
|
}
|
|
|
|
responses.OkWithData(getPrescriptionResponse, c)
|
|
}
|