776 lines
25 KiB
Go
776 lines
25 KiB
Go
package service
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"gorm.io/gorm"
|
|
"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 问诊配置
|
|
type InquiryConfigService struct {
|
|
DoctorInquiryConfigService // 医生问诊配置
|
|
SystemInquiryConfigService // 系统问诊配置
|
|
}
|
|
|
|
// DoctorInquiryConfigService 医生问诊配置
|
|
type DoctorInquiryConfigService struct {
|
|
}
|
|
|
|
// SystemInquiryConfigService 系统问诊配置
|
|
type SystemInquiryConfigService struct {
|
|
}
|
|
|
|
// HandleDoctorInquiryConfig 处理医生问诊配置
|
|
func (r *DoctorInquiryConfigService) HandleDoctorInquiryConfig(tx *gorm.DB, 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("系统价格错误")
|
|
}
|
|
}
|
|
|
|
// 获取医生当前问诊配置
|
|
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 {
|
|
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 {
|
|
return false, errors.New("修改失败")
|
|
}
|
|
}
|
|
}
|
|
|
|
return true, nil
|
|
}
|
|
|
|
// GetDoctorInquiryConfig 医生问诊配置详情
|
|
func (r *DoctorInquiryConfigService) GetDoctorInquiryConfig(req requests.GetDoctorInquiryConfig) (res *dto.DoctorInquiryConfigDto, err error) {
|
|
doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{}
|
|
|
|
// 获取医生问诊配置
|
|
maps := make(map[string]interface{})
|
|
if req.InquiryConfigId != "" {
|
|
maps["inquiry_config_id"] = req.InquiryConfigId
|
|
} else {
|
|
if req.DoctorId != "" {
|
|
maps["doctor_id"] = req.DoctorId
|
|
}
|
|
|
|
if req.InquiryType != nil {
|
|
maps["inquiry_type"] = req.InquiryType
|
|
}
|
|
|
|
if req.InquiryMode != nil {
|
|
maps["inquiry_mode"] = req.InquiryMode
|
|
}
|
|
}
|
|
|
|
if len(maps) <= 0 {
|
|
return nil, errors.New("参数错误")
|
|
}
|
|
|
|
doctorInquiryConfig, err := doctorInquiryConfigDao.GetDoctorInquiryConfig(maps)
|
|
if err != nil || doctorInquiryConfig == nil {
|
|
return nil, errors.New("获取失败")
|
|
}
|
|
|
|
// 获取医生数据
|
|
userDoctorDao := dao.UserDoctorDao{}
|
|
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorInquiryConfig.DoctorId)
|
|
if err != nil || userDoctor == nil {
|
|
return nil, errors.New("获取失败")
|
|
}
|
|
|
|
// 获取医生医院数据
|
|
hospitalDao := dao.HospitalDao{}
|
|
hospital, err := hospitalDao.GetHospitalById(userDoctor.HospitalID)
|
|
|
|
// 获取系统问诊配置
|
|
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 nil, errors.New("获取失败")
|
|
}
|
|
|
|
// 获取医生问诊时间
|
|
doctorInquiryTimeDao := dao.DoctorInquiryTimeDao{}
|
|
|
|
maps = make(map[string]interface{})
|
|
maps["doctor_id"] = doctorInquiryConfig.DoctorId
|
|
maps["inquiry_type"] = doctorInquiryConfig.InquiryType
|
|
maps["inquiry_mode"] = doctorInquiryConfig.InquiryMode
|
|
doctorInquiryTimes, err := doctorInquiryTimeDao.GetDoctorInquiryTimeList(maps)
|
|
|
|
// 处理返回值
|
|
res = dto.GetDoctorInquiryConfigDto(doctorInquiryConfig)
|
|
|
|
// 加载医生数据
|
|
res.LoadUserDoctor(userDoctor)
|
|
|
|
// 加载医生医院
|
|
if hospital != nil {
|
|
res.LoadUserDoctorHospital(hospital)
|
|
}
|
|
|
|
// 加载医生问诊时间
|
|
if userDoctor.IsPlatformDeepCooperation == 1 {
|
|
res.LoadDoctorInquiryTime(doctorInquiryTimes)
|
|
}
|
|
|
|
// 获取医生问诊配置-疑难问诊-服务设置
|
|
if doctorInquiryConfig.InquiryType == 1 && doctorInquiryConfig.InquiryMode == 6 {
|
|
doctorInquiryConfigServiceDao := dao.DoctorInquiryConfigServiceDao{}
|
|
|
|
maps = make(map[string]interface{})
|
|
maps["doctor_id"] = doctorInquiryConfig.DoctorId
|
|
maps["inquiry_type"] = doctorInquiryConfig.InquiryType
|
|
maps["inquiry_mode"] = doctorInquiryConfig.InquiryMode
|
|
doctorInquiryConfigService, err := doctorInquiryConfigServiceDao.GetDoctorInquiryConfigServiceFirst(maps)
|
|
if doctorInquiryConfigService != nil && err == nil {
|
|
res.LoadDoctorInquiryConfigService(doctorInquiryConfigService)
|
|
}
|
|
}
|
|
|
|
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.DoctorInquiryTime) <= 0 {
|
|
return false, errors.New("请填写坐班时间")
|
|
}
|
|
}
|
|
|
|
// 验证医生服务设置-疑难会诊
|
|
if doctorInquiryConfig.InquiryType == 1 && doctorInquiryConfig.InquiryMode == 6 {
|
|
if req.DoctorInquiryConfigService == nil {
|
|
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 req.InquiryType == 2 || req.InquiryType == 4 {
|
|
if userDoctor.IsPlatformDeepCooperation == 1 && len(req.DoctorInquiryTime) > 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.DoctorInquiryTime {
|
|
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())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 修改医生服务设置-疑难会诊
|
|
if doctorInquiryConfig.InquiryType == 1 && doctorInquiryConfig.InquiryMode == 6 {
|
|
// 获取医生服务设置-疑难会诊
|
|
doctorInquiryConfigServiceDao := dao.DoctorInquiryConfigServiceDao{}
|
|
|
|
maps = make(map[string]interface{})
|
|
maps["doctor_id"] = doctorInquiryConfig.DoctorId
|
|
maps["inquiry_type"] = doctorInquiryConfig.InquiryType
|
|
maps["inquiry_mode"] = doctorInquiryConfig.InquiryMode
|
|
doctorInquiryConfigService, err := doctorInquiryConfigServiceDao.GetDoctorInquiryConfigServiceFirst(maps)
|
|
if doctorInquiryConfigService != nil && err != nil {
|
|
doctorInquiryConfigServiceData := make(map[string]interface{})
|
|
|
|
if req.DoctorInquiryConfigService.ServiceContent != doctorInquiryConfigService.ServiceContent {
|
|
doctorInquiryConfigServiceData["service_content"] = req.DoctorInquiryConfigService.ServiceContent
|
|
}
|
|
|
|
if req.DoctorInquiryConfigService.ServiceProcess != doctorInquiryConfigService.ServiceProcess {
|
|
doctorInquiryConfigServiceData["service_process"] = req.DoctorInquiryConfigService.ServiceProcess
|
|
}
|
|
|
|
if req.DoctorInquiryConfigService.ServicePeriod != doctorInquiryConfigService.ServicePeriod {
|
|
doctorInquiryConfigServiceData["service_period"] = req.DoctorInquiryConfigService.ServicePeriod
|
|
}
|
|
|
|
if req.DoctorInquiryConfigService.ServiceRounds != doctorInquiryConfigService.ServiceRounds {
|
|
doctorInquiryConfigServiceData["service_rounds"] = req.DoctorInquiryConfigService.ServiceRounds
|
|
}
|
|
|
|
err := doctorInquiryConfigServiceDao.EditDoctorInquiryConfigServiceById(tx, doctorInquiryConfigService.ConfigServiceId, doctorInquiryConfigServiceData)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return false, errors.New("修改失败")
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
tx.Commit()
|
|
return true, nil
|
|
}
|
|
|
|
// AddDoctorInquiryConfig 新增医生问诊配置
|
|
func (r *DoctorInquiryConfigService) AddDoctorInquiryConfig(req requests.AddDoctorInquiryConfig) (bool, error) {
|
|
doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{}
|
|
|
|
// 获取医生问诊配置
|
|
maps := make(map[string]interface{})
|
|
maps["doctor_id"] = req.DoctorId
|
|
maps["inquiry_type"] = req.InquiryType
|
|
maps["inquiry_mode"] = req.InquiryMode
|
|
doctorInquiryConfig, err := doctorInquiryConfigDao.GetDoctorInquiryConfig(maps)
|
|
if doctorInquiryConfig != nil {
|
|
return false, errors.New("该医生已存在此类型问诊配置")
|
|
}
|
|
|
|
// 获取医生数据
|
|
doctorId, err := strconv.ParseInt(req.DoctorId, 10, 64)
|
|
if err != nil {
|
|
return false, errors.New("医院错误")
|
|
}
|
|
|
|
userDoctorDao := dao.UserDoctorDao{}
|
|
userDoctor, err := userDoctorDao.GetUserDoctorById(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("该医生未进行绑定结算银行卡")
|
|
}
|
|
|
|
if req.InquiryType == 4 && req.InquiryMode == 1 && req.IsEnable == 1 {
|
|
if userDoctor.MultiPointStatus != 1 {
|
|
return false, errors.New("该医生未进行多点认证")
|
|
}
|
|
}
|
|
|
|
// 获取系统问诊配置
|
|
systemInquiryConfigDao := dao.SystemInquiryConfigDao{}
|
|
|
|
maps = make(map[string]interface{})
|
|
maps["inquiry_type"] = req.InquiryType
|
|
maps["inquiry_mode"] = req.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 req.InquiryType == 1 {
|
|
if req.InquiryPrice > systemInquiryConfig.MaxInquiryPrice || req.InquiryPrice < systemInquiryConfig.MinInquiryPrice {
|
|
return false, errors.New("问诊价格填写错误")
|
|
}
|
|
}
|
|
|
|
// 验证问诊价格-快速问诊/问诊购药
|
|
if req.InquiryType == 2 || req.InquiryType == 4 {
|
|
inquiryPrice := strconv.FormatFloat(req.InquiryPrice, 'f', -1, 64)
|
|
if inquiryPrice != systemInquiryConfig.InquiryPrice {
|
|
return false, errors.New("问诊价格填写错误")
|
|
}
|
|
}
|
|
|
|
// 验证问诊价格-公益问诊
|
|
if req.InquiryType == 3 {
|
|
inquiryPrice := strconv.FormatFloat(req.InquiryPrice, 'f', -1, 64)
|
|
if !strings.Contains(systemInquiryConfig.InquiryPrice, inquiryPrice) {
|
|
return false, errors.New("问诊价格填写错误")
|
|
}
|
|
}
|
|
|
|
// 验证医生坐班时间
|
|
if req.InquiryType == 2 || req.InquiryType == 4 {
|
|
if userDoctor.IsPlatformDeepCooperation == 1 && len(req.DoctorInquiryTime) <= 0 {
|
|
return false, errors.New("请填写坐班时间")
|
|
}
|
|
}
|
|
|
|
// 开始事务
|
|
tx := global.Db.Begin()
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
fmt.Println(r)
|
|
tx.Rollback()
|
|
}
|
|
}()
|
|
|
|
// 新增医生问诊配置
|
|
doctorInquiryConfig = &model.DoctorInquiryConfig{
|
|
DoctorId: doctorId,
|
|
InquiryType: req.InquiryType,
|
|
InquiryMode: req.InquiryMode,
|
|
IsEnable: req.IsEnable,
|
|
LastEnableMethod: 2,
|
|
WorkNumDay: req.WorkNumDay,
|
|
InquiryPrice: &req.InquiryPrice,
|
|
}
|
|
|
|
doctorInquiryConfig, err = doctorInquiryConfigDao.AddDoctorInquiryConfig(tx, doctorInquiryConfig)
|
|
if err != nil || doctorInquiryConfig == nil {
|
|
tx.Rollback()
|
|
return false, errors.New("失败")
|
|
}
|
|
|
|
// 处理医生问诊时间
|
|
if req.InquiryType == 2 || req.InquiryType == 4 {
|
|
if userDoctor.IsPlatformDeepCooperation == 1 && len(req.DoctorInquiryTime) > 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.DoctorInquiryTime {
|
|
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())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 新增医生服务设置-疑难会诊
|
|
if req.InquiryType == 1 && req.InquiryMode == 6 {
|
|
doctorInquiryConfigServiceDao := dao.DoctorInquiryConfigServiceDao{}
|
|
|
|
doctorInquiryConfigService := &model.DoctorInquiryConfigService{
|
|
DoctorId: doctorId,
|
|
InquiryType: req.InquiryType,
|
|
InquiryMode: req.InquiryMode,
|
|
ServiceContent: req.DoctorInquiryConfigService.ServiceContent,
|
|
ServiceProcess: req.DoctorInquiryConfigService.ServiceProcess,
|
|
ServicePeriod: req.DoctorInquiryConfigService.ServicePeriod,
|
|
ServiceRounds: req.DoctorInquiryConfigService.ServiceRounds,
|
|
}
|
|
|
|
doctorInquiryConfigService, err = doctorInquiryConfigServiceDao.AddDoctorInquiryConfigService(tx, doctorInquiryConfigService)
|
|
if err != nil || doctorInquiryConfigService == nil {
|
|
tx.Rollback()
|
|
return false, errors.New(err.Error())
|
|
}
|
|
}
|
|
|
|
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.DefaultWorkNumDay < 0 {
|
|
return false, errors.New("默认每日接诊数量应大于等于0")
|
|
}
|
|
|
|
if req.Duration == 0 && systemInquiryConfig.InquiryType != 1 && systemInquiryConfig.InquiryMode != 6 {
|
|
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("请设置问诊价格")
|
|
}
|
|
} else if systemInquiryConfig.InquiryType == 1 && systemInquiryConfig.InquiryMode == 2 {
|
|
if req.MaxInquiryPrice == 0 {
|
|
return false, errors.New("最高接诊价格应大于0")
|
|
}
|
|
} else if systemInquiryConfig.InquiryType == 1 && systemInquiryConfig.InquiryMode == 6 {
|
|
if req.MaxInquiryPrice == 0 {
|
|
return false, errors.New("最高接诊价格应大于0")
|
|
}
|
|
}
|
|
|
|
// 开始事务
|
|
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.DefaultWorkNumDay != systemInquiryConfig.DefaultWorkNumDay {
|
|
systemInquiryConfigData["default_work_num_day"] = req.DefaultWorkNumDay
|
|
}
|
|
|
|
if req.TimesNumber != systemInquiryConfig.TimesNumber {
|
|
systemInquiryConfigData["times_number"] = req.TimesNumber
|
|
}
|
|
|
|
if req.Duration != systemInquiryConfig.Duration {
|
|
systemInquiryConfigData["duration"] = req.Duration
|
|
}
|
|
|
|
if req.MinInquiryPrice != systemInquiryConfig.MinInquiryPrice || req.MaxInquiryPrice != systemInquiryConfig.MaxInquiryPrice {
|
|
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
|
|
}
|
|
|
|
// GetSystemInquiryConfigDetail 系统问诊配置详情-条件
|
|
func (r *SystemInquiryConfigService) GetSystemInquiryConfigDetail(req requests.GetSystemInquiryConfigDetail) (res *dto.SystemInquiryConfigDto, err error) {
|
|
// 获取系统问诊配置
|
|
systemInquiryConfigDao := dao.SystemInquiryConfigDao{}
|
|
|
|
maps := make(map[string]interface{})
|
|
maps["inquiry_type"] = req.InquiryType
|
|
maps["inquiry_mode"] = req.InquiryMode
|
|
systemInquiryConfig, err := systemInquiryConfigDao.GetSystemInquiryConfig(maps)
|
|
if err != nil || systemInquiryConfig == nil {
|
|
return nil, errors.New("数据错误")
|
|
}
|
|
|
|
// 获取系统问诊时间
|
|
systemInquiryTimeDao := dao.SystemInquiryTimeDao{}
|
|
systemInquiryTimes, err := systemInquiryTimeDao.GetSystemInquiryTimeListBySystemInquiryConfigId(systemInquiryConfig.SystemInquiryConfigId)
|
|
|
|
// 处理返回值
|
|
res = dto.GetSystemInquiryConfigDto(systemInquiryConfig)
|
|
|
|
// 加载系统问诊时间
|
|
res.LoadSystemInquiryTime(systemInquiryTimes)
|
|
|
|
return res, nil
|
|
}
|