修改系统问诊配置
This commit is contained in:
parent
eda63e716e
commit
a50b679e6e
@ -212,8 +212,54 @@ func (r *InquiryConfig) GetSystemInquiryConfig(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取系统问诊时间
|
||||
systemInquiryTimeDao := dao.SystemInquiryTimeDao{}
|
||||
systemInquiryTimes, err := systemInquiryTimeDao.GetSystemInquiryTimeListBySystemInquiryConfigId(systemInquiryConfigId)
|
||||
|
||||
// 处理返回值
|
||||
res := dto.GetSystemInquiryConfigDto(systemInquiryConfig)
|
||||
|
||||
// 加载系统问诊时间
|
||||
res.LoadSystemInquiryTime(systemInquiryTimes)
|
||||
|
||||
responses.OkWithData(res, c)
|
||||
}
|
||||
|
||||
// PutSystemInquiryConfig 修改系统问诊配置
|
||||
func (r *InquiryConfig) PutSystemInquiryConfig(c *gin.Context) {
|
||||
inquiryConfigRequest := requests.InquiryConfigRequest{}
|
||||
req := inquiryConfigRequest.PutSystemInquiryConfig
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
id := c.Param("system_inquiry_config_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
systemInquiryConfigId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
systemInquiryConfigService := service.SystemInquiryConfigService{}
|
||||
_, err = systemInquiryConfigService.PutSystemInquiryConfig(systemInquiryConfigId, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
72
api/dao/systemInquiryTime.go
Normal file
72
api/dao/systemInquiryTime.go
Normal file
@ -0,0 +1,72 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
type SystemInquiryTimeDao struct {
|
||||
}
|
||||
|
||||
// GetSystemInquiryTimeById 获取系统问诊时间数据列表-系统问诊时间id
|
||||
func (r *SystemInquiryTimeDao) GetSystemInquiryTimeById(systemInquiryConfigId int64) (m *model.SystemInquiryTime, err error) {
|
||||
err = global.Db.First(&m, systemInquiryConfigId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetSystemInquiryTimeListBySystemInquiryConfigId 获取系统问诊时间数据列表-系统问诊配置id
|
||||
func (r *SystemInquiryTimeDao) GetSystemInquiryTimeListBySystemInquiryConfigId(systemInquiryConfigId int64) (m []*model.SystemInquiryTime, err error) {
|
||||
err = global.Db.Where("system_inquiry_config_id = ?", systemInquiryConfigId).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteSystemInquiryTime 删除系统问诊时间
|
||||
func (r *SystemInquiryTimeDao) DeleteSystemInquiryTime(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.SystemInquiryTime{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditSystemInquiryTimeById 修改系统问诊时间-问诊配置id
|
||||
func (r *SystemInquiryTimeDao) EditSystemInquiryTimeById(tx *gorm.DB, inquiryTimeId int64, data interface{}) error {
|
||||
err := tx.Model(&model.SystemInquiryTime{}).Where("inquiry_time_id = ?", inquiryTimeId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSystemInquiryTimeList 获取系统问诊时间列表
|
||||
func (r *SystemInquiryTimeDao) GetSystemInquiryTimeList(maps interface{}) (m []*model.SystemInquiryTime, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddSystemInquiryTime 新增系统问诊时间
|
||||
func (r *SystemInquiryTimeDao) AddSystemInquiryTime(tx *gorm.DB, model *model.SystemInquiryTime) (*model.SystemInquiryTime, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetSystemInquiryTime 获取系统问诊时间
|
||||
func (r *SystemInquiryTimeDao) GetSystemInquiryTime(maps interface{}) (m *model.SystemInquiryTime, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
@ -17,6 +17,7 @@ type SystemInquiryConfigDto struct {
|
||||
Duration int `json:"duration"` // 沟通时长(分钟,0为不限制时长)
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
SystemInquiryTime []*SystemInquiryTimeDto `json:"system_inquiry_time"` // 系统问诊时间配置
|
||||
}
|
||||
|
||||
func GetSystemInquiryConfigDto(m *model.SystemInquiryConfig) *SystemInquiryConfigDto {
|
||||
@ -76,3 +77,11 @@ func GetSystemInquiryConfigListDto(m []*model.SystemInquiryConfig) []*SystemInqu
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadSystemInquiryTime 加载系统问诊时间
|
||||
func (r *SystemInquiryConfigDto) LoadSystemInquiryTime(m []*model.SystemInquiryTime) *SystemInquiryConfigDto {
|
||||
if len(m) > 0 {
|
||||
r.SystemInquiryTime = GetSystemInquiryTimeListDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
52
api/dto/SystemInquiryTime.go
Normal file
52
api/dto/SystemInquiryTime.go
Normal file
@ -0,0 +1,52 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hospital-admin-api/api/model"
|
||||
)
|
||||
|
||||
type SystemInquiryTimeDto struct {
|
||||
InquiryTimeId string `json:"inquiry_time_id"` // 主键id
|
||||
SystemInquiryConfigId string `json:"system_inquiry_config_id"` // 系统配置主键id;NOT NULL
|
||||
StartTime string `json:"start_time"` // 开始时间
|
||||
EndTime string `json:"end_time"` // 结束时间
|
||||
TimeInterval string `json:"time_interval"` // 时段(上午、中午、下午、夜间、全天)
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
}
|
||||
|
||||
func GetSystemInquiryTimeDto(m *model.SystemInquiryTime) *SystemInquiryTimeDto {
|
||||
return &SystemInquiryTimeDto{
|
||||
InquiryTimeId: fmt.Sprintf("%d", m.InquiryTimeId),
|
||||
SystemInquiryConfigId: fmt.Sprintf("%d", m.SystemInquiryConfigId),
|
||||
StartTime: m.StartTime[:2] + ":" + m.StartTime[2:],
|
||||
EndTime: m.EndTime[:2] + ":" + m.EndTime[2:],
|
||||
TimeInterval: m.TimeInterval,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func GetSystemInquiryTimeListDto(m []*model.SystemInquiryTime) []*SystemInquiryTimeDto {
|
||||
// 处理返回值
|
||||
responses := make([]*SystemInquiryTimeDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &SystemInquiryTimeDto{
|
||||
InquiryTimeId: fmt.Sprintf("%d", v.InquiryTimeId),
|
||||
SystemInquiryConfigId: fmt.Sprintf("%d", v.SystemInquiryConfigId),
|
||||
StartTime: v.StartTime[:2] + ":" + v.StartTime[2:],
|
||||
EndTime: v.EndTime[:2] + ":" + v.EndTime[2:],
|
||||
TimeInterval: v.TimeInterval,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
35
api/model/systemInquiryTime.go
Normal file
35
api/model/systemInquiryTime.go
Normal file
@ -0,0 +1,35 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
// SystemInquiryTime 系统问诊时间配置
|
||||
type SystemInquiryTime struct {
|
||||
InquiryTimeId int64 `gorm:"column:inquiry_time_id;type:bigint(19);primary_key;comment:主键id" json:"inquiry_time_id"`
|
||||
SystemInquiryConfigId int64 `gorm:"column:system_inquiry_config_id;type:bigint(19);comment:系统配置主键id;NOT NULL" json:"system_inquiry_config_id"`
|
||||
StartTime string `gorm:"column:start_time;type:varchar(30);comment:开始时间" json:"start_time"`
|
||||
EndTime string `gorm:"column:end_time;type:varchar(30);comment:结束时间" json:"end_time"`
|
||||
TimeInterval string `gorm:"column:time_interval;type:varchar(255);comment:时段(上午、中午、下午、夜间、全天)" json:"time_interval"`
|
||||
Model
|
||||
}
|
||||
|
||||
func (m *SystemInquiryTime) TableName() string {
|
||||
return "gdxz_system_inquiry_time"
|
||||
}
|
||||
|
||||
func (m *SystemInquiryTime) BeforeCreate(tx *gorm.DB) error {
|
||||
if m.InquiryTimeId == 0 {
|
||||
m.InquiryTimeId = 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
|
||||
}
|
||||
@ -5,6 +5,7 @@ type InquiryConfigRequest struct {
|
||||
PutDoctorInquiryConfig // 修改医生问诊配置
|
||||
AddDoctorInquiryConfig // 新增医生问诊配置
|
||||
GetSystemInquiryConfigPage // 获取系统问诊配置列表-分页
|
||||
PutSystemInquiryConfig // 修改系统问诊配置
|
||||
}
|
||||
|
||||
// GetDoctorInquiryConfigPage 获取开启问诊配置医生列表-分页
|
||||
@ -54,3 +55,20 @@ type GetSystemInquiryConfigPage struct {
|
||||
InquiryType *int `json:"inquiry_type" form:"inquiry_type" label:"问诊类型"` // 1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测
|
||||
InquiryMode *int `json:"inquiry_mode" form:"inquiry_mode" label:"问诊方式"` // 1:图文 2:视频 3:语音 4:电话 5:会员
|
||||
}
|
||||
|
||||
// PutSystemInquiryConfig 修改系统问诊配置
|
||||
type PutSystemInquiryConfig struct {
|
||||
MaxWorkNumDay int `json:"max_work_num_day" label:"每日最大接诊数量"`
|
||||
InquiryPrice string `json:"inquiry_price" label:"接诊价格"`
|
||||
MinInquiryPrice float64 `json:"min_inquiry_price" label:"最低接诊价格"`
|
||||
MaxInquiryPrice float64 `json:"max_inquiry_price" label:"最高接诊价格"`
|
||||
TimesNumber int `json:"times_number" label:"沟通次数(0为不限制次数)"`
|
||||
Duration int `json:"duration" label:"沟通时长(分钟,0为不限制时长)"`
|
||||
SystemInquiryTime []*SystemInquiryTime `json:"system_inquiry_time" label:"系统问诊时间配置"`
|
||||
}
|
||||
|
||||
// SystemInquiryTime 系统问诊时间配置
|
||||
type SystemInquiryTime struct {
|
||||
StartTime string `json:"start_time" label:"开始时间"`
|
||||
EndTime string `json:"end_time" label:"结束时间"`
|
||||
}
|
||||
|
||||
@ -497,7 +497,7 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
systemGroup.GET("/:system_inquiry_config_id", api.InquiryConfig.GetSystemInquiryConfig)
|
||||
|
||||
// 修改系统问诊配置
|
||||
systemGroup.PUT("/:inquiry_config_id", api.InquiryConfig.PutDoctorInquiryConfig)
|
||||
systemGroup.PUT("/:system_inquiry_config_id", api.InquiryConfig.PutSystemInquiryConfig)
|
||||
|
||||
// 新增系统问诊配置
|
||||
systemGroup.POST("", api.InquiryConfig.AddDoctorInquiryConfig)
|
||||
|
||||
@ -495,3 +495,125 @@ func (r *DoctorInquiryConfigService) AddDoctorInquiryConfig(req requests.AddDoct
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// PutSystemInquiryConfig 修改系统问诊配置
|
||||
func (r *SystemInquiryConfigService) PutSystemInquiryConfig(systemInquiryConfigId int64, req requests.PutSystemInquiryConfig) (bool, error) {
|
||||
// 获取系统问诊配置
|
||||
systemInquiryConfigDao := dao.SystemInquiryConfigDao{}
|
||||
systemInquiryConfig, err := systemInquiryConfigDao.GetSystemInquiryConfigById(systemInquiryConfigId)
|
||||
if err != nil || systemInquiryConfig == nil {
|
||||
return false, errors.New("数据错误")
|
||||
}
|
||||
|
||||
// 业务参数判断
|
||||
if req.MaxWorkNumDay == 0 {
|
||||
return false, errors.New("每日最大接诊数量应大于0")
|
||||
}
|
||||
|
||||
if req.Duration == 0 {
|
||||
return false, errors.New("沟通时长应大于0")
|
||||
}
|
||||
|
||||
if systemInquiryConfig.InquiryType == 1 && systemInquiryConfig.InquiryMode == 1 {
|
||||
if req.MaxInquiryPrice == 0 {
|
||||
return false, errors.New("最高接诊价格应大于0")
|
||||
}
|
||||
} else if systemInquiryConfig.InquiryType == 2 && systemInquiryConfig.InquiryMode == 1 {
|
||||
if req.InquiryPrice == "" {
|
||||
return false, errors.New("请设置问诊价格")
|
||||
}
|
||||
} else if systemInquiryConfig.InquiryType == 3 && systemInquiryConfig.InquiryMode == 1 {
|
||||
if req.InquiryPrice == "" {
|
||||
return false, errors.New("请设置问诊价格")
|
||||
}
|
||||
} else if systemInquiryConfig.InquiryType == 4 && systemInquiryConfig.InquiryMode == 1 {
|
||||
if req.InquiryPrice == "" {
|
||||
return false, errors.New("请设置问诊价格")
|
||||
}
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
// 修改系统问诊配置
|
||||
systemInquiryConfigData := make(map[string]interface{})
|
||||
if req.MaxWorkNumDay != systemInquiryConfig.MaxWorkNumDay {
|
||||
systemInquiryConfigData["max_work_num_day"] = req.MaxWorkNumDay
|
||||
}
|
||||
|
||||
if req.TimesNumber != systemInquiryConfig.TimesNumber {
|
||||
systemInquiryConfigData["times_number"] = req.TimesNumber
|
||||
}
|
||||
|
||||
if req.Duration != systemInquiryConfig.Duration {
|
||||
systemInquiryConfigData["duration"] = req.Duration
|
||||
}
|
||||
|
||||
if req.Duration != systemInquiryConfig.Duration {
|
||||
if systemInquiryConfig.InquiryType == 1 {
|
||||
systemInquiryConfigData["min_inquiry_price"] = req.MinInquiryPrice
|
||||
systemInquiryConfigData["max_inquiry_price"] = req.MaxInquiryPrice
|
||||
}
|
||||
}
|
||||
|
||||
if req.InquiryPrice != systemInquiryConfig.InquiryPrice {
|
||||
if systemInquiryConfig.InquiryType == 2 || systemInquiryConfig.InquiryType == 3 || systemInquiryConfig.InquiryType == 4 {
|
||||
systemInquiryConfigData["inquiry_price"] = req.InquiryPrice
|
||||
}
|
||||
}
|
||||
|
||||
if len(systemInquiryConfigData) > 0 {
|
||||
err = systemInquiryConfigDao.EditSystemInquiryConfigById(tx, systemInquiryConfigId, systemInquiryConfigData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("修改失败")
|
||||
}
|
||||
}
|
||||
|
||||
// 处理问诊时间
|
||||
if systemInquiryConfig.InquiryType == 2 || systemInquiryConfig.InquiryType == 4 {
|
||||
if len(req.SystemInquiryTime) > 0 {
|
||||
// 获取系统问诊时间。用以区分添加/删除
|
||||
systemInquiryTimeDao := dao.SystemInquiryTimeDao{}
|
||||
|
||||
systemInquiryTimes, _ := systemInquiryTimeDao.GetSystemInquiryTimeListBySystemInquiryConfigId(systemInquiryConfigId)
|
||||
if len(systemInquiryTimes) > 0 {
|
||||
// 删除系统全部问诊时间
|
||||
maps := make(map[string]interface{})
|
||||
maps["system_inquiry_config_id"] = systemInquiryConfigId
|
||||
err = systemInquiryTimeDao.DeleteSystemInquiryTime(tx, maps)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// 添加系统问诊时间
|
||||
for _, v := range req.SystemInquiryTime {
|
||||
startTime := strings.Replace(v.StartTime, ":", "", -1)
|
||||
endTime := strings.Replace(v.EndTime, ":", "", -1)
|
||||
|
||||
systemInquiryTime := &model.SystemInquiryTime{
|
||||
SystemInquiryConfigId: systemInquiryConfigId,
|
||||
StartTime: startTime,
|
||||
EndTime: endTime,
|
||||
TimeInterval: "",
|
||||
}
|
||||
|
||||
systemInquiryTime, err = systemInquiryTimeDao.AddSystemInquiryTime(tx, systemInquiryTime)
|
||||
if err != nil || systemInquiryTime == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user