97 lines
2.8 KiB
Go
97 lines
2.8 KiB
Go
package dao
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"hospital-admin-api/api/model"
|
|
"hospital-admin-api/api/requests"
|
|
"hospital-admin-api/global"
|
|
)
|
|
|
|
type SystemInquiryConfigDao struct {
|
|
}
|
|
|
|
// GetSystemInquiryConfigById 获取系统问诊配置数据列表-系统问诊配置id
|
|
func (r *SystemInquiryConfigDao) GetSystemInquiryConfigById(systemInquiryConfigId int64) (m *model.SystemInquiryConfig, err error) {
|
|
err = global.Db.First(&m, systemInquiryConfigId).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// DeleteSystemInquiryConfig 删除系统问诊配置
|
|
func (r *SystemInquiryConfigDao) DeleteSystemInquiryConfig(tx *gorm.DB, maps interface{}) error {
|
|
err := tx.Where(maps).Delete(&model.SystemInquiryConfig{}).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EditSystemInquiryConfigById 修改系统问诊配置-问诊配置id
|
|
func (r *SystemInquiryConfigDao) EditSystemInquiryConfigById(tx *gorm.DB, systemInquiryConfigId int64, data interface{}) error {
|
|
err := tx.Model(&model.SystemInquiryConfig{}).Where("system_inquiry_config_id = ?", systemInquiryConfigId).Updates(data).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetSystemInquiryConfigList 获取系统问诊配置列表
|
|
func (r *SystemInquiryConfigDao) GetSystemInquiryConfigList(maps interface{}) (m []*model.SystemInquiryConfig, err error) {
|
|
err = global.Db.Where(maps).Find(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// AddSystemInquiryConfig 新增系统问诊配置
|
|
func (r *SystemInquiryConfigDao) AddSystemInquiryConfig(tx *gorm.DB, model *model.SystemInquiryConfig) (*model.SystemInquiryConfig, error) {
|
|
if err := tx.Create(model).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return model, nil
|
|
}
|
|
|
|
// GetSystemInquiryConfig 获取系统问诊配置
|
|
func (r *SystemInquiryConfigDao) GetSystemInquiryConfig(maps interface{}) (m *model.SystemInquiryConfig, err error) {
|
|
err = global.Db.Where(maps).First(&m).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return m, nil
|
|
}
|
|
|
|
// GetSystemInquiryConfigPageSearch 获取系统问诊配置列表-分页
|
|
func (r *SystemInquiryConfigDao) GetSystemInquiryConfigPageSearch(req requests.GetSystemInquiryConfigPage, page, pageSize int) (m []*model.SystemInquiryConfig, total int64, err error) {
|
|
var totalRecords int64
|
|
|
|
// 构建查询条件
|
|
query := global.Db.Model(&model.SystemInquiryConfig{})
|
|
|
|
// 问诊类型
|
|
if req.InquiryType != nil {
|
|
query = query.Where("inquiry_type = ?", req.InquiryType)
|
|
}
|
|
|
|
// 问诊方式
|
|
if req.InquiryMode != nil {
|
|
query = query.Where("inquiry_mode = ?", req.InquiryMode)
|
|
}
|
|
|
|
// 排序
|
|
query = query.Order("created_at desc")
|
|
|
|
// 查询总数量
|
|
if err := query.Count(&totalRecords).Error; err != nil {
|
|
return nil, 0, err
|
|
}
|
|
|
|
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
return m, totalRecords, nil
|
|
}
|