65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package dao
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
"hospital-admin-api/api/model"
|
|
"hospital-admin-api/global"
|
|
)
|
|
|
|
type PopupDao struct {
|
|
}
|
|
|
|
// GetPopupById 获取数据-id
|
|
func (r *PopupDao) GetPopupById(popupId int64) (m *model.Popup, err error) {
|
|
err = global.Db.First(&m, popupId).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// GetPopupPreloadById 获取数据-加载全部关联-id
|
|
func (r *PopupDao) GetPopupPreloadById(popupId int64) (m *model.Popup, err error) {
|
|
err = global.Db.Preload(clause.Associations).First(&m, popupId).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// EditPopup 修改
|
|
func (r *PopupDao) EditPopup(tx *gorm.DB, maps interface{}, data interface{}) error {
|
|
err := tx.Model(&model.Popup{}).Where(maps).Updates(data).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EditPopupByOrderServicePackageId 修改-id
|
|
func (r *PopupDao) EditPopupByOrderServicePackageId(tx *gorm.DB, popupId int64, data interface{}) error {
|
|
err := tx.Model(&model.Popup{}).Where("popup_id = ?", popupId).Updates(data).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetPopupList 获取列表
|
|
func (r *PopupDao) GetPopupList(maps interface{}) (m []*model.Popup, err error) {
|
|
err = global.Db.Where(maps).Find(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// AddPopup 新增
|
|
func (r *PopupDao) AddPopup(tx *gorm.DB, model *model.Popup) (*model.Popup, error) {
|
|
if err := tx.Create(model).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return model, nil
|
|
}
|