From f686acec98e4250f302e133bd97606a91a4bf106 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Tue, 10 Oct 2023 13:35:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=84=E7=90=86=E5=8C=BB?= =?UTF-8?q?=E7=94=9F=E9=97=AE=E8=AF=8A=E9=85=8D=E7=BD=AE=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E5=90=8E=E5=8F=B0=E5=A4=9A=E7=82=B9=E5=AE=A1=E6=A0=B8?= =?UTF-8?q?=E5=8C=BB=E7=94=9F=E6=97=B6=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=8C=BB?= =?UTF-8?q?=E7=94=9F=E9=97=AE=E8=AF=8A=E8=B4=AD=E8=8D=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/orderInquiry.go | 4 +- api/dao/doctorInquiryConfig.go | 63 +++++++++++++++++ api/dao/systemInquiryConfig.go | 63 +++++++++++++++++ api/model/doctorInquiryConfig.go | 38 +++++++++++ api/model/systemInquiryConfig.go | 39 +++++++++++ api/router/router.go | 6 +- api/service/InquiryConfig.go | 114 +++++++++++++++++++++++++++++++ api/service/userDoctor.go | 11 +++ 8 files changed, 333 insertions(+), 5 deletions(-) create mode 100644 api/dao/doctorInquiryConfig.go create mode 100644 api/dao/systemInquiryConfig.go create mode 100644 api/model/doctorInquiryConfig.go create mode 100644 api/model/systemInquiryConfig.go create mode 100644 api/service/InquiryConfig.go diff --git a/api/controller/orderInquiry.go b/api/controller/orderInquiry.go index d5df5ca..169b7e5 100644 --- a/api/controller/orderInquiry.go +++ b/api/controller/orderInquiry.go @@ -162,8 +162,8 @@ func (r *OrderInquiry) GetOrderInquiryRecordPage(c *gin.Context) { } result := make(map[string]interface{}) - result["page"] = req.GetOrderInquiryPage.Page - result["page_size"] = req.GetOrderInquiryPage.PageSize + result["page"] = req.GetOrderInquiryRecordPage.Page + result["page_size"] = req.GetOrderInquiryRecordPage.PageSize result["total"] = total result["data"] = GetOrderInquiryPageResponses responses.OkWithData(result, c) diff --git a/api/dao/doctorInquiryConfig.go b/api/dao/doctorInquiryConfig.go new file mode 100644 index 0000000..b854cf9 --- /dev/null +++ b/api/dao/doctorInquiryConfig.go @@ -0,0 +1,63 @@ +package dao + +import ( + "gorm.io/gorm" + "hospital-admin-api/api/model" + "hospital-admin-api/global" +) + +type DoctorInquiryConfigDao struct { +} + +// GetDoctorInquiryConfigListByDoctorId 获取医生问诊配置数据列表-医生id +func (r *DoctorInquiryConfigDao) GetDoctorInquiryConfigListByDoctorId(doctorId int64) (m []*model.DoctorInquiryConfig, err error) { + err = global.Db.Where("doctor_id = ?", doctorId).Find(&m).Error + if err != nil { + return nil, err + } + return m, nil +} + +// DeleteDoctorInquiryConfig 删除医生问诊配置 +func (r *DoctorInquiryConfigDao) DeleteDoctorInquiryConfig(tx *gorm.DB, maps interface{}) error { + err := tx.Where(maps).Delete(&model.DoctorInquiryConfig{}).Error + if err != nil { + return err + } + return nil +} + +// EditDoctorInquiryConfigById 修改医生问诊配置-问诊配置id +func (r *DoctorInquiryConfigDao) EditDoctorInquiryConfigById(tx *gorm.DB, inquiryConfigId int64, data interface{}) error { + err := tx.Model(&model.DoctorInquiryConfig{}).Where("inquiry_config_id = ?", inquiryConfigId).Updates(data).Error + if err != nil { + return err + } + return nil +} + +// GetDoctorInquiryConfigList 获取医生问诊配置列表 +func (r *DoctorInquiryConfigDao) GetDoctorInquiryConfigList(maps interface{}) (m []*model.DoctorInquiryConfig, err error) { + err = global.Db.Where(maps).Find(&m).Error + if err != nil { + return nil, err + } + return m, nil +} + +// AddDoctorInquiryConfig 新增医生问诊配置 +func (r *DoctorInquiryConfigDao) AddDoctorInquiryConfig(tx *gorm.DB, model *model.DoctorInquiryConfig) (*model.DoctorInquiryConfig, error) { + if err := tx.Create(model).Error; err != nil { + return nil, err + } + return model, nil +} + +// GetDoctorInquiryConfig 获取医生问诊配置 +func (r *DoctorInquiryConfigDao) GetDoctorInquiryConfig(maps interface{}) (m *model.DoctorInquiryConfig, err error) { + err = global.Db.Where(maps).First(&m).Error + if err != nil { + return nil, err + } + return m, nil +} diff --git a/api/dao/systemInquiryConfig.go b/api/dao/systemInquiryConfig.go new file mode 100644 index 0000000..1fed2d9 --- /dev/null +++ b/api/dao/systemInquiryConfig.go @@ -0,0 +1,63 @@ +package dao + +import ( + "gorm.io/gorm" + "hospital-admin-api/api/model" + "hospital-admin-api/global" +) + +type SystemInquiryConfigDao struct { +} + +// GetSystemInquiryConfigListByDoctorId 获取系统问诊配置数据列表-系统id +func (r *SystemInquiryConfigDao) GetSystemInquiryConfigListByDoctorId(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 +} diff --git a/api/model/doctorInquiryConfig.go b/api/model/doctorInquiryConfig.go new file mode 100644 index 0000000..dc63d8e --- /dev/null +++ b/api/model/doctorInquiryConfig.go @@ -0,0 +1,38 @@ +package model + +import ( + "gorm.io/gorm" + "hospital-admin-api/global" + "time" +) + +// DoctorInquiryConfig 医生接诊配置表 +type DoctorInquiryConfig struct { + InquiryConfigId int64 `gorm:"column:inquiry_config_id;type:bigint(19);primary_key;comment:主键id" json:"inquiry_config_id"` + DoctorId int64 `gorm:"column:doctor_id;type:bigint(19);comment:医生id" json:"doctor_id"` + InquiryType int `gorm:"column:inquiry_type;type:tinyint(1);default:1;comment:接诊类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药);NOT NULL" json:"inquiry_type"` + InquiryMode int `gorm:"column:inquiry_mode;type:tinyint(1);default:1;comment:接诊方式(1:图文 2:视频 3:语音 4:电话 5:会员);NOT NULL" json:"inquiry_mode"` + IsEnable int `gorm:"column:is_enable;type:tinyint(1);default:0;comment:是否启用(0:否 1:是)" json:"is_enable"` + LastEnableMethod int `gorm:"column:last_enable_method;type:tinyint(1);default:1;comment:最后开启方式(1:自己 2:后台)" json:"last_enable_method"` + WorkNumDay int `gorm:"column:work_num_day;type:int(10);default:0;comment:每日接诊数量" json:"work_num_day"` + InquiryPrice float64 `gorm:"column:inquiry_price;type:decimal(10,2);comment:接诊价格(专家问诊-公益问诊)" json:"inquiry_price"` + Model +} + +func (m *DoctorInquiryConfig) TableName() string { + return "gdxz_doctor_inquiry_config" +} + +func (m *DoctorInquiryConfig) BeforeCreate(tx *gorm.DB) error { + if m.InquiryConfigId == 0 { + m.InquiryConfigId = global.Snowflake.Generate().Int64() + } + + m.CreatedAt = LocalTime(time.Now()) + tx.Statement.SetColumn("CreatedAt", m.CreatedAt) + + m.UpdatedAt = LocalTime(time.Now()) + tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt) + + return nil +} diff --git a/api/model/systemInquiryConfig.go b/api/model/systemInquiryConfig.go new file mode 100644 index 0000000..a2846cd --- /dev/null +++ b/api/model/systemInquiryConfig.go @@ -0,0 +1,39 @@ +package model + +import ( + "gorm.io/gorm" + "hospital-admin-api/global" + "time" +) + +// SystemInquiryConfig 系统问诊配置 +type SystemInquiryConfig struct { + SystemInquiryConfigId int64 `gorm:"column:system_inquiry_config_id;type:bigint(19);primary_key;comment:主键id" json:"system_inquiry_config_id"` + InquiryType int `gorm:"column:inquiry_type;type:tinyint(1);comment:接诊类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测)" json:"inquiry_type"` + InquiryMode int `gorm:"column:inquiry_mode;type:tinyint(1);default:1;comment:接诊方式(1:图文 2:视频 3:语音 4:电话 5:会员)" json:"inquiry_mode"` + MaxWorkNumDay int `gorm:"column:max_work_num_day;type:int(11);default:0;comment:每日最大接诊数量" json:"max_work_num_day"` + InquiryPrice string `gorm:"column:inquiry_price;type:varchar(255);comment:接诊价格" json:"inquiry_price"` + MinInquiryPrice float64 `gorm:"column:min_inquiry_price;type:decimal(10,2);comment:最低接诊价格(专家问诊)" json:"min_inquiry_price"` + MaxInquiryPrice float64 `gorm:"column:max_inquiry_price;type:decimal(10,2);comment:最高接诊价格(专家问诊)" json:"max_inquiry_price"` + TimesNumber int `gorm:"column:times_number;type:int(11);default:0;comment:沟通次数(0为不限制次数)" json:"times_number"` + Duration int `gorm:"column:duration;type:int(11);default:0;comment:沟通时长(分钟,0为不限制时长)" json:"duration"` + Model +} + +func (m *SystemInquiryConfig) TableName() string { + return "gdxz_system_inquiry_config" +} + +func (m *SystemInquiryConfig) BeforeCreate(tx *gorm.DB) error { + if m.SystemInquiryConfigId == 0 { + m.SystemInquiryConfigId = global.Snowflake.Generate().Int64() + } + + m.CreatedAt = LocalTime(time.Now()) + tx.Statement.SetColumn("CreatedAt", m.CreatedAt) + + m.UpdatedAt = LocalTime(time.Now()) + tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt) + + return nil +} diff --git a/api/router/router.go b/api/router/router.go index 09c65b6..a4306a7 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -462,10 +462,10 @@ func privateRouter(r *gin.Engine, api controller.Api) { inquiryGroup := adminGroup.Group("/inquiry") { // 问诊配置 - settingGroup := inquiryGroup.Group("/setting") + configGroup := inquiryGroup.Group("/config") { // 医生问诊配置 - doctorGroup := settingGroup.Group("/doctor") + doctorGroup := configGroup.Group("/doctor") { // 获取开启问诊配置医生列表-分页 doctorGroup.GET("", api.UserDoctor.GetUserDoctor) @@ -481,7 +481,7 @@ func privateRouter(r *gin.Engine, api controller.Api) { } // 系统问诊配置 - systemGroup := settingGroup.Group("/system") + systemGroup := configGroup.Group("/config") { // 获取系统问诊配置列表-分页 systemGroup.GET("", api.UserDoctor.GetUserDoctorPage) diff --git a/api/service/InquiryConfig.go b/api/service/InquiryConfig.go new file mode 100644 index 0000000..9033c51 --- /dev/null +++ b/api/service/InquiryConfig.go @@ -0,0 +1,114 @@ +package service + +import ( + "errors" + "hospital-admin-api/api/dao" + "hospital-admin-api/api/model" + "hospital-admin-api/global" + "strconv" +) + +// InquiryConfigService 问诊配置 +type InquiryConfigService struct { + DoctorInquiryConfigService // 医生问诊配置 + SystemInquiryConfigService // 系统问诊配置 +} + +// DoctorInquiryConfigService 医生问诊配置 +type DoctorInquiryConfigService struct { +} + +// SystemInquiryConfigService 系统问诊配置 +type SystemInquiryConfigService struct { +} + +// HandleDoctorInquiryConfig 处理医生问诊配置 +func (r *DoctorInquiryConfigService) HandleDoctorInquiryConfig(doctorId int64, inquiryType, inquiryMode, isEnable, workNumDay int, inquiryPrice float64) (bool, error) { + var err error + + if inquiryType == 4 && inquiryMode == 1 { + // 获取系统配置-问诊购药类型 + systemInquiryConfigDao := dao.SystemInquiryConfigDao{} + + maps := make(map[string]interface{}) + maps["inquiry_type"] = inquiryType + maps["inquiry_mode"] = inquiryMode + systemInquiryConfig, _ := systemInquiryConfigDao.GetSystemInquiryConfig(maps) + if systemInquiryConfig == nil { + return false, errors.New("缺少系统配置") + } + + // 问诊人数 + workNumDay = systemInquiryConfig.MaxWorkNumDay + + // 问诊价格 + inquiryPrice, err = strconv.ParseFloat(systemInquiryConfig.InquiryPrice, 64) + if err != nil { + return false, errors.New("系统价格错误") + } + } + + // 开始事务 + tx := global.Db.Begin() + defer func() { + if r := recover(); r != nil { + tx.Rollback() + } + }() + + // 获取医生当前问诊配置 + doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{} + + maps := make(map[string]interface{}) + maps["doctor_id"] = doctorId + maps["inquiry_type"] = inquiryType + maps["inquiry_mode"] = inquiryMode + d, _ := doctorInquiryConfigDao.GetDoctorInquiryConfig(maps) + if d == nil { + // 新增 + m := &model.DoctorInquiryConfig{ + DoctorId: doctorId, + InquiryType: inquiryType, + InquiryMode: inquiryMode, + IsEnable: isEnable, + LastEnableMethod: 2, + WorkNumDay: workNumDay, + InquiryPrice: inquiryPrice, + } + + adminUser, _ := doctorInquiryConfigDao.AddDoctorInquiryConfig(tx, m) + if adminUser == nil { + tx.Rollback() + return false, errors.New("新增失败") + } + } else { + // 修改 + data := make(map[string]interface{}) + + if d.IsEnable != isEnable { + data["is_enable"] = isEnable + } + + if d.WorkNumDay != workNumDay { + data["work_num_day"] = workNumDay + } + + if d.InquiryPrice != inquiryPrice { + data["inquiry_price"] = inquiryPrice + } + + if len(data) > 0 { + if d.LastEnableMethod != 2 { + data["last_enable_method"] = 2 + } + + err := doctorInquiryConfigDao.EditDoctorInquiryConfigById(tx, d.InquiryConfigId, data) + if err != nil { + tx.Rollback() + return false, errors.New("修改失败") + } + } + } + + return true, nil +} diff --git a/api/service/userDoctor.go b/api/service/userDoctor.go index 4956640..b577bc9 100644 --- a/api/service/userDoctor.go +++ b/api/service/userDoctor.go @@ -1556,6 +1556,17 @@ func (r *UserDoctorService) PutMulti(doctorId int64, req requests.PutMulti) (boo return false, errors.New("审核失败") } + // 处理问诊配置数据 + if req.MultiPointStatus == 1 { + // 审核通过后,创建问诊购药问诊配置 + inquiryConfigService := InquiryConfigService{} + _, err = inquiryConfigService.HandleDoctorInquiryConfig(doctorId, 4, 1, 1, 0, 0) + if err != nil { + tx.Rollback() + return false, errors.New("审核失败") + } + + } tx.Commit() return true, nil }