166 lines
4.6 KiB
Go
166 lines
4.6 KiB
Go
package service
|
|
|
|
import (
|
|
"errors"
|
|
"gorm.io/gorm"
|
|
"hospital-admin-api/api/dao"
|
|
"hospital-admin-api/api/dto"
|
|
"hospital-admin-api/api/model"
|
|
"strconv"
|
|
)
|
|
|
|
// 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(inquiryConfigId int64) (res *dto.DoctorInquiryConfigDto, err error) {
|
|
doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{}
|
|
|
|
// 获取医生问诊配置
|
|
doctorInquiryConfig, err := doctorInquiryConfigDao.GetDoctorInquiryConfigById(inquiryConfigId)
|
|
if err != nil || doctorInquiryConfig == nil {
|
|
return nil, errors.New(err.Error())
|
|
}
|
|
|
|
// 获取医生数据
|
|
userDoctorDao := dao.UserDoctorDao{}
|
|
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorInquiryConfig.DoctorId)
|
|
if err != nil || userDoctor == nil {
|
|
return nil, errors.New(err.Error())
|
|
}
|
|
|
|
// 获取医生医院数据
|
|
hospitalDao := dao.Hospital{}
|
|
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(err.Error())
|
|
}
|
|
|
|
// 获取医生问诊时间
|
|
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)
|
|
}
|
|
|
|
return res, nil
|
|
}
|