修改系统问诊配置
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user