修改医生问诊配置
This commit is contained in:
parent
73b6d7d6b7
commit
0d93a7bffb
@ -84,39 +84,39 @@ func (r *InquiryConfig) GetDoctorInquiryConfig(c *gin.Context) {
|
||||
|
||||
// PutDoctorInquiryConfig 修改医生问诊配置
|
||||
func (r *InquiryConfig) PutDoctorInquiryConfig(c *gin.Context) {
|
||||
// inquiryConfigRequest := requests.InquiryConfigRequest{}
|
||||
// req := inquiryConfigRequest.PutDoctorInquiryConfig
|
||||
// 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("doctor_id")
|
||||
// if id == "" {
|
||||
// responses.FailWithMessage("缺少参数", c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // 将 id 转换为 int64 类型
|
||||
// doctorId, err := strconv.ParseInt(id, 10, 64)
|
||||
// if err != nil {
|
||||
// responses.Fail(c)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // 业务处理
|
||||
// userDoctorService := service.UserDoctorService{}
|
||||
// _, err = userDoctorService.PutUserDoctor(doctorId, req)
|
||||
// if err != nil {
|
||||
// responses.FailWithMessage(err.Error(), c)
|
||||
// return
|
||||
// }
|
||||
inquiryConfigRequest := requests.InquiryConfigRequest{}
|
||||
req := inquiryConfigRequest.PutDoctorInquiryConfig
|
||||
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("inquiry_config_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
inquiryConfigId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
doctorInquiryConfigService := service.DoctorInquiryConfigService{}
|
||||
_, err = doctorInquiryConfigService.PutDoctorInquiryConfig(inquiryConfigId, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package requests
|
||||
|
||||
type InquiryConfigRequest struct {
|
||||
GetDoctorInquiryConfigPage // 获取开启问诊配置医生列表-分页
|
||||
PutDoctorInquiryConfig // 修改医生问诊配置
|
||||
}
|
||||
|
||||
// GetDoctorInquiryConfigPage 获取开启问诊配置医生列表-分页
|
||||
@ -18,10 +19,11 @@ type GetDoctorInquiryConfigPage struct {
|
||||
// PutDoctorInquiryConfig 修改医生问诊配置
|
||||
type PutDoctorInquiryConfig struct {
|
||||
DoctorId int `json:"doctor_id" form:"doctor_id"` // 医生id
|
||||
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:会员
|
||||
WorkNumDay *int `json:"work_num_day" label:"每日接诊数量"`
|
||||
IsEnable *int `json:"is_enable" form:"is_enable" label:"是否启用"` // 0:否 1:是
|
||||
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:会员
|
||||
WorkNumDay int `json:"work_num_day" label:"每日接诊数量"`
|
||||
InquiryPrice float64 `json:"inquiry_price" label:"接诊价格"`
|
||||
IsEnable int `json:"is_enable" form:"is_enable" label:"是否启用"` // 0:否 1:是
|
||||
PutDoctorInquiryTime []*putDoctorInquiryTime `json:"doctor_inquiry_time" form:"doctor_inquiry_time" label:"医生问诊配置-时间配置"`
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,11 @@ import (
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/dto"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/global"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// InquiryConfigService 问诊配置
|
||||
@ -163,3 +167,167 @@ func (r *DoctorInquiryConfigService) GetDoctorInquiryConfig(inquiryConfigId int6
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// PutDoctorInquiryConfig 修改医生问诊配置
|
||||
func (r *DoctorInquiryConfigService) PutDoctorInquiryConfig(inquiryConfigId int64, req requests.PutDoctorInquiryConfig) (bool, error) {
|
||||
doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{}
|
||||
|
||||
// 获取医生问诊配置
|
||||
doctorInquiryConfig, err := doctorInquiryConfigDao.GetDoctorInquiryConfigById(inquiryConfigId)
|
||||
if err != nil || doctorInquiryConfig == nil {
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 获取医生数据
|
||||
userDoctorDao := dao.UserDoctorDao{}
|
||||
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorInquiryConfig.DoctorId)
|
||||
if err != nil || userDoctor == nil {
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 判断医生数据
|
||||
if userDoctor.IdcardStatus != 1 {
|
||||
return false, errors.New("请先进行实名认证")
|
||||
}
|
||||
|
||||
if userDoctor.IdenAuthStatus != 1 {
|
||||
return false, errors.New("请先进行身份认证")
|
||||
}
|
||||
|
||||
if userDoctor.IsBindBank != 1 {
|
||||
return false, errors.New("请先进行绑定结算银行卡")
|
||||
}
|
||||
|
||||
// 获取系统问诊配置
|
||||
systemInquiryConfigDao := dao.SystemInquiryConfigDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["inquiry_type"] = doctorInquiryConfig.InquiryType
|
||||
maps["inquiry_mode"] = doctorInquiryConfig.InquiryMode
|
||||
systemInquiryConfig, err := systemInquiryConfigDao.GetSystemInquiryConfig(maps)
|
||||
if err != nil || systemInquiryConfig == nil {
|
||||
return false, errors.New("系统问诊配置错误")
|
||||
}
|
||||
|
||||
// 验证问诊数量
|
||||
if req.WorkNumDay > systemInquiryConfig.MaxWorkNumDay {
|
||||
return false, errors.New("超出每日最大接诊数量")
|
||||
}
|
||||
|
||||
// 验证问诊价格-在线问诊
|
||||
if doctorInquiryConfig.InquiryType == 1 {
|
||||
if req.InquiryPrice > systemInquiryConfig.MaxInquiryPrice || req.InquiryPrice < systemInquiryConfig.MinInquiryPrice {
|
||||
return false, errors.New("问诊价格填写错误")
|
||||
}
|
||||
}
|
||||
|
||||
// 验证问诊价格-快速问诊/问诊购药
|
||||
if doctorInquiryConfig.InquiryType == 2 || doctorInquiryConfig.InquiryType == 4 {
|
||||
inquiryPrice := strconv.FormatFloat(req.InquiryPrice, 'f', -1, 64)
|
||||
if inquiryPrice != systemInquiryConfig.InquiryPrice {
|
||||
return false, errors.New("问诊价格填写错误")
|
||||
}
|
||||
}
|
||||
|
||||
// 验证问诊价格-公益问诊
|
||||
if doctorInquiryConfig.InquiryType == 3 {
|
||||
inquiryPrice := strconv.FormatFloat(req.InquiryPrice, 'f', -1, 64)
|
||||
if !strings.Contains(systemInquiryConfig.InquiryPrice, inquiryPrice) {
|
||||
return false, errors.New("问诊价格填写错误")
|
||||
}
|
||||
}
|
||||
|
||||
// 验证医生坐班时间
|
||||
if doctorInquiryConfig.InquiryType == 2 || doctorInquiryConfig.InquiryType == 4 {
|
||||
if userDoctor.IsPlatformDeepCooperation == 1 && len(req.PutDoctorInquiryTime) <= 0 {
|
||||
return false, errors.New("请填写坐班时间")
|
||||
}
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
// 修改医生问诊配置
|
||||
doctorInquiryConfigData := make(map[string]interface{})
|
||||
if req.IsEnable != doctorInquiryConfig.IsEnable {
|
||||
doctorInquiryConfigData["is_enable"] = req.IsEnable
|
||||
if req.IsEnable == 1 {
|
||||
doctorInquiryConfigData["last_enable_method"] = 2
|
||||
}
|
||||
}
|
||||
|
||||
if req.WorkNumDay != doctorInquiryConfig.WorkNumDay {
|
||||
doctorInquiryConfigData["work_num_day"] = req.WorkNumDay
|
||||
}
|
||||
|
||||
if req.InquiryPrice != doctorInquiryConfig.InquiryPrice {
|
||||
doctorInquiryConfigData["inquiry_price"] = req.InquiryPrice
|
||||
}
|
||||
|
||||
if len(doctorInquiryConfigData) > 0 {
|
||||
err = doctorInquiryConfigDao.EditDoctorInquiryConfigById(tx, doctorInquiryConfig.InquiryConfigId, doctorInquiryConfigData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("修改失败")
|
||||
}
|
||||
}
|
||||
|
||||
// 处理医生问诊时间
|
||||
if userDoctor.IsPlatformDeepCooperation == 1 && len(req.PutDoctorInquiryTime) > 0 {
|
||||
// 获取医生问诊时间-获取一条即可,用以区分添加/删除
|
||||
doctorInquiryTimeDao := dao.DoctorInquiryTimeDao{}
|
||||
|
||||
maps = make(map[string]interface{})
|
||||
maps["doctor_id"] = doctorInquiryConfig.DoctorId
|
||||
maps["inquiry_type"] = doctorInquiryConfig.InquiryType
|
||||
maps["inquiry_mode"] = doctorInquiryConfig.InquiryMode
|
||||
doctorInquiryTime, _ := doctorInquiryTimeDao.GetDoctorInquiryTime(maps)
|
||||
if doctorInquiryTime != nil {
|
||||
// 删除医生全部问诊时间
|
||||
maps = make(map[string]interface{})
|
||||
maps["doctor_id"] = doctorInquiryConfig.DoctorId
|
||||
maps["inquiry_type"] = doctorInquiryConfig.InquiryType
|
||||
maps["inquiry_mode"] = doctorInquiryConfig.InquiryMode
|
||||
err = doctorInquiryTimeDao.DeleteDoctorInquiryTime(tx, maps)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// 添加医生问诊时间
|
||||
for _, v := range req.PutDoctorInquiryTime {
|
||||
inquiryDate, err := time.Parse("2006-01-02", v.InquiryDate)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
startTime := strings.Replace(v.StartTime, ":", "", -1)
|
||||
endTime := strings.Replace(v.EndTime, ":", "", -1)
|
||||
|
||||
doctorInquiryTime = &model.DoctorInquiryTime{
|
||||
DoctorId: userDoctor.DoctorId,
|
||||
InquiryType: req.InquiryType,
|
||||
InquiryMode: req.InquiryMode,
|
||||
InquiryDate: model.LocalTime(inquiryDate),
|
||||
StartTime: startTime,
|
||||
EndTime: endTime,
|
||||
}
|
||||
|
||||
doctorInquiryTime, err = doctorInquiryTimeDao.AddDoctorInquiryTime(tx, doctorInquiryTime)
|
||||
if err != nil || doctorInquiryTime == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user