90 lines
3.1 KiB
Go
90 lines
3.1 KiB
Go
package dao
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
"hospital-admin-api/api/model"
|
|
"hospital-admin-api/global"
|
|
)
|
|
|
|
type OrderPrescriptionProductDao struct {
|
|
}
|
|
|
|
// GetOrderPrescriptionProductById 获取处方关联药品数据-处方关联药品id
|
|
func (r *OrderPrescriptionProductDao) GetOrderPrescriptionProductById(PrescriptionProductId int64) (m *model.OrderPrescriptionProduct, err error) {
|
|
err = global.Db.First(&m, PrescriptionProductId).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
func (r *OrderPrescriptionProductDao) GetOrderPrescriptionProductByOrderPrescriptionId(orderPrescriptionId int64) (m *model.OrderPrescriptionProduct, err error) {
|
|
err = global.Db.Where("order_prescription_id = ?", orderPrescriptionId).First(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
func (r *OrderPrescriptionProductDao) GetOrderPrescriptionProductListByOrderPrescriptionId(orderPrescriptionId int64) (m []*model.OrderPrescriptionProduct, err error) {
|
|
err = global.Db.Where("order_prescription_id = ?", orderPrescriptionId).Find(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// GetOrderPrescriptionProductPreloadById 获取处方关联药品数据-加载全部关联-处方关联药品id
|
|
func (r *OrderPrescriptionProductDao) GetOrderPrescriptionProductPreloadById(PrescriptionProductId int64) (m *model.OrderPrescriptionProduct, err error) {
|
|
err = global.Db.Preload(clause.Associations).First(&m, PrescriptionProductId).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// DeleteOrderPrescriptionProduct 删除处方关联药品
|
|
func (r *OrderPrescriptionProductDao) DeleteOrderPrescriptionProduct(tx *gorm.DB, maps interface{}) error {
|
|
err := tx.Where(maps).Delete(&model.OrderPrescriptionProduct{}).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EditOrderPrescriptionProduct 修改处方关联药品
|
|
func (r *OrderPrescriptionProductDao) EditOrderPrescriptionProduct(tx *gorm.DB, maps interface{}, data interface{}) error {
|
|
err := tx.Model(&model.OrderPrescriptionProduct{}).Where(maps).Updates(data).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EditOrderPrescriptionProductByOrderPrescriptionId 修改处方关联药品-处方关联药品id
|
|
func (r *OrderPrescriptionProductDao) EditOrderPrescriptionProductByOrderPrescriptionId(tx *gorm.DB, PrescriptionProductId int64, data interface{}) error {
|
|
err := tx.Model(&model.OrderPrescriptionProduct{}).Where("prescription_product_id = ?", PrescriptionProductId).Updates(data).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetOrderPrescriptionProductList 获取处方关联药品列表
|
|
func (r *OrderPrescriptionProductDao) GetOrderPrescriptionProductList(maps interface{}) (m []*model.OrderPrescriptionProduct, err error) {
|
|
err = global.Db.Where(maps).Find(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// AddOrderPrescriptionProduct 新增处方关联药品
|
|
func (r *OrderPrescriptionProductDao) AddOrderPrescriptionProduct(tx *gorm.DB, model *model.OrderPrescriptionProduct) (*model.OrderPrescriptionProduct, error) {
|
|
if err := tx.Create(model).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return model, nil
|
|
}
|