新增了 医生健康包配置
This commit is contained in:
parent
1ad5c29520
commit
895a53b51c
@ -70,8 +70,9 @@ type orderPrescriptionManage struct {
|
||||
|
||||
// 问诊管理
|
||||
type inquiryManage struct {
|
||||
InquiryConfig // 问诊配置
|
||||
HealthPackage // 系统健康包配置
|
||||
InquiryConfig // 问诊配置
|
||||
HealthPackage // 系统健康包配置
|
||||
DoctorConfigHealthPackage // 医生健康包配置
|
||||
}
|
||||
|
||||
// ca管理
|
||||
|
||||
162
api/controller/doctorConfigHealthPackage.go
Normal file
162
api/controller/doctorConfigHealthPackage.go
Normal file
@ -0,0 +1,162 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/dto"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/api/responses"
|
||||
"hospital-admin-api/api/service"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type DoctorConfigHealthPackage struct{}
|
||||
|
||||
// GetDoctorHealthPage 获取开启健康包服务的医生-分页
|
||||
func (r *DoctorConfigHealthPackage) GetDoctorHealthPage(c *gin.Context) {
|
||||
doctorConfigHealthPackageRequest := requests.DoctorConfigHealthPackageRequest{}
|
||||
req := doctorConfigHealthPackageRequest.GetDoctorHealthPage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
doctorConfigHealthPackageDao := dao.DoctorConfigHealthPackageDao{}
|
||||
doctorConfigHealthPackage, total, err := doctorConfigHealthPackageDao.GetDoctorHealthPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
res := dto.GetDoctorConfigHealthPackageListDto(doctorConfigHealthPackage)
|
||||
|
||||
doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{}
|
||||
for _, v := range res {
|
||||
maps := make(map[string]interface{})
|
||||
maps["doctor_id"] = v.DoctorId
|
||||
maps["inquiry_type"] = 1
|
||||
maps["inquiry_mode"] = 8
|
||||
doctorInquiryConfig, err := doctorInquiryConfigDao.GetDoctorInquiryConfig(maps)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
v.LoadDoctorInquiryConfig(doctorInquiryConfig)
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = res
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// GetDoctorHealth 医生健康包配置详情
|
||||
func (r *DoctorConfigHealthPackage) GetDoctorHealth(c *gin.Context) {
|
||||
id := c.Param("health_package_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
healthPackageId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
doctorConfigHealthPackageService := service.DoctorConfigHealthPackageService{}
|
||||
getUserDoctorResponses, err := doctorConfigHealthPackageService.GetDoctorHealth(healthPackageId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(getUserDoctorResponses, c)
|
||||
}
|
||||
|
||||
// PutDoctorHealth 修改医生健康包配置
|
||||
func (r *DoctorConfigHealthPackage) PutDoctorHealth(c *gin.Context) {
|
||||
doctorConfigHealthPackageRequest := requests.DoctorConfigHealthPackageRequest{}
|
||||
req := doctorConfigHealthPackageRequest.PutDoctorHealth
|
||||
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("health_package_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
healthPackageId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
doctorConfigHealthPackageService := service.DoctorConfigHealthPackageService{}
|
||||
_, err = doctorConfigHealthPackageService.PutDoctorHealth(healthPackageId, req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
// AddDoctorHealth 新增医生健康包配置
|
||||
func (r *DoctorConfigHealthPackage) AddDoctorHealth(c *gin.Context) {
|
||||
doctorConfigHealthPackageRequest := requests.DoctorConfigHealthPackageRequest{}
|
||||
req := doctorConfigHealthPackageRequest.AddDoctorHealth
|
||||
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
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
doctorConfigHealthPackageService := service.DoctorConfigHealthPackageService{}
|
||||
_, err := doctorConfigHealthPackageService.AddDoctorHealth(req)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.Ok(c)
|
||||
}
|
||||
131
api/dao/doctorConfigHealthPackage.go
Normal file
131
api/dao/doctorConfigHealthPackage.go
Normal file
@ -0,0 +1,131 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
type DoctorConfigHealthPackageDao struct {
|
||||
}
|
||||
|
||||
// GetDoctorConfigHealthPackageListByDoctorId 获取列表-医生id
|
||||
func (r *DoctorConfigHealthPackageDao) GetDoctorConfigHealthPackageListByDoctorId(doctorId int64) (m []*model.DoctorConfigHealthPackage, err error) {
|
||||
err = global.Db.Where("doctor_id = ?", doctorId).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetDoctorConfigHealthPackageById 获取医生健康包配置数据-问诊配置id
|
||||
func (r *DoctorConfigHealthPackageDao) GetDoctorConfigHealthPackageById(healthPackageId int64) (m *model.DoctorConfigHealthPackage, err error) {
|
||||
err = global.Db.First(&m, healthPackageId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// DeleteDoctorConfigHealthPackage 删除医生健康包配置
|
||||
func (r *DoctorConfigHealthPackageDao) DeleteDoctorConfigHealthPackage(tx *gorm.DB, maps interface{}) error {
|
||||
err := tx.Where(maps).Delete(&model.DoctorConfigHealthPackage{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditDoctorConfigHealthPackageById 修改医生健康包配置-健康包配置id
|
||||
func (r *DoctorConfigHealthPackageDao) EditDoctorConfigHealthPackageById(tx *gorm.DB, healthPackageId int64, data interface{}) error {
|
||||
err := tx.Model(&model.DoctorConfigHealthPackage{}).Where("health_package_id = ?", healthPackageId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetDoctorConfigHealthPackageList 获取医生健康包配置列表
|
||||
func (r *DoctorConfigHealthPackageDao) GetDoctorConfigHealthPackageList(maps interface{}) (m []*model.DoctorConfigHealthPackage, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddDoctorConfigHealthPackage 新增医生健康包配置
|
||||
func (r *DoctorConfigHealthPackageDao) AddDoctorConfigHealthPackage(tx *gorm.DB, model *model.DoctorConfigHealthPackage) (*model.DoctorConfigHealthPackage, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetDoctorConfigHealthPackage 获取医生健康包配置
|
||||
func (r *DoctorConfigHealthPackageDao) GetDoctorConfigHealthPackage(maps interface{}) (m *model.DoctorConfigHealthPackage, err error) {
|
||||
err = global.Db.Where(maps).First(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetDoctorHealthPageSearch 获取开启健康包服务的医生-分页
|
||||
func (r *DoctorConfigHealthPackageDao) GetDoctorHealthPageSearch(req requests.GetDoctorHealthPage, page, pageSize int) (m []*model.DoctorConfigHealthPackage, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.DoctorConfigHealthPackage{})
|
||||
|
||||
// 医生
|
||||
query = query.Preload("UserDoctor", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Omit("open_id", "union_id", "wx_session_key")
|
||||
})
|
||||
|
||||
// 健康包表
|
||||
query = query.Preload("HealthPackage")
|
||||
|
||||
// 用户表
|
||||
query = query.Preload("UserDoctor.User", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Omit("user_password", "salt")
|
||||
})
|
||||
|
||||
// 手机号
|
||||
if req.Mobile != "" {
|
||||
// 医生
|
||||
doctorUserSubQuery := global.Db.Model(&model.User{}).
|
||||
Select("user_id").
|
||||
Where("mobile = ?", req.Mobile)
|
||||
|
||||
doctorSubQuery := global.Db.Model(&model.UserDoctor{}).
|
||||
Select("doctor_id").
|
||||
Where(gorm.Expr("user_id IN (?)", doctorUserSubQuery))
|
||||
|
||||
query = query.Where("doctor_id IN (?)", doctorSubQuery)
|
||||
}
|
||||
|
||||
// 医生姓名
|
||||
if req.DoctorName != "" {
|
||||
subQuery := global.Db.Model(&model.UserDoctor{}).
|
||||
Select("doctor_id").
|
||||
Where("user_name LIKE ?", "%"+req.DoctorName+"%")
|
||||
|
||||
query = query.Where("doctor_id IN (?)", subQuery)
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
93
api/dto/DoctorConfigHealthPackage.go
Normal file
93
api/dto/DoctorConfigHealthPackage.go
Normal file
@ -0,0 +1,93 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hospital-admin-api/api/model"
|
||||
)
|
||||
|
||||
// DoctorConfigHealthPackageDto 医生配置-健康包
|
||||
type DoctorConfigHealthPackageDto struct {
|
||||
HealthPackageId string `json:"health_package_id"` // 主键id
|
||||
DoctorId string `json:"doctor_id"` // 医生id
|
||||
PackageId string `json:"package_id"` // 健康包配置id
|
||||
ServicePrice float64 `json:"service_price"` // 服务价格(根据图文问诊价格计算)
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
HealthPackage *HealthPackageDto `json:"health_package"` // 健康包
|
||||
UserDoctor *UserDoctorDto `json:"user_doctor"` // 医生数据
|
||||
DoctorInquiryConfig *DoctorInquiryConfigDto `json:"doctor_inquiry_config"` // 医生问诊配置数据
|
||||
}
|
||||
|
||||
func GetDoctorConfigHealthPackageDto(m *model.DoctorConfigHealthPackage) *DoctorConfigHealthPackageDto {
|
||||
return &DoctorConfigHealthPackageDto{
|
||||
HealthPackageId: fmt.Sprintf("%d", m.HealthPackageId),
|
||||
DoctorId: fmt.Sprintf("%d", m.DoctorId),
|
||||
PackageId: fmt.Sprintf("%d", m.PackageId),
|
||||
ServicePrice: m.ServicePrice,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func GetDoctorConfigHealthPackageListDto(m []*model.DoctorConfigHealthPackage) []*DoctorConfigHealthPackageDto {
|
||||
// 处理返回值
|
||||
responses := make([]*DoctorConfigHealthPackageDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &DoctorConfigHealthPackageDto{
|
||||
HealthPackageId: fmt.Sprintf("%d", v.HealthPackageId),
|
||||
DoctorId: fmt.Sprintf("%d", v.DoctorId),
|
||||
PackageId: fmt.Sprintf("%d", v.PackageId),
|
||||
ServicePrice: v.ServicePrice,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
if v.HealthPackage != nil {
|
||||
response.LoadHealthPackage(v.HealthPackage)
|
||||
}
|
||||
|
||||
if v.UserDoctor != nil {
|
||||
response.LoadUserDoctor(v.UserDoctor)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadHealthPackage 加载健康包
|
||||
func (r *DoctorConfigHealthPackageDto) LoadHealthPackage(m *model.HealthPackage) *DoctorConfigHealthPackageDto {
|
||||
if m != nil {
|
||||
r.HealthPackage = GetHealthPackageDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadUserDoctor 加载医生数据
|
||||
func (r *DoctorConfigHealthPackageDto) LoadUserDoctor(m *model.UserDoctor) *DoctorConfigHealthPackageDto {
|
||||
if m != nil {
|
||||
r.UserDoctor = GetUserDoctorDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadUserDoctorHospital 加载医生医院数据
|
||||
func (r *DoctorConfigHealthPackageDto) LoadUserDoctorHospital(m *model.Hospital) *DoctorConfigHealthPackageDto {
|
||||
if m != nil && r.UserDoctor != nil {
|
||||
r.UserDoctor.Hospital = GetHospitalDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadDoctorInquiryConfig 加载医生问诊配置
|
||||
func (r *DoctorConfigHealthPackageDto) LoadDoctorInquiryConfig(m *model.DoctorInquiryConfig) *DoctorConfigHealthPackageDto {
|
||||
if m != nil {
|
||||
r.DoctorInquiryConfig = GetDoctorInquiryConfigDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
@ -36,7 +36,7 @@ func GetDoctorInquiryConfigDto(m *model.DoctorInquiryConfig) *DoctorInquiryConfi
|
||||
IsEnable: m.IsEnable,
|
||||
LastEnableMethod: m.LastEnableMethod,
|
||||
WorkNumDay: m.WorkNumDay,
|
||||
InquiryPrice: m.InquiryPrice,
|
||||
InquiryPrice: *m.InquiryPrice,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
@ -56,7 +56,7 @@ func GetDoctorInquiryConfigListDto(m []*model.DoctorInquiryConfig) []*DoctorInqu
|
||||
IsEnable: v.IsEnable,
|
||||
LastEnableMethod: v.LastEnableMethod,
|
||||
WorkNumDay: v.WorkNumDay,
|
||||
InquiryPrice: v.InquiryPrice,
|
||||
InquiryPrice: *v.InquiryPrice,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
@ -13,6 +13,8 @@ type DoctorConfigHealthPackage struct {
|
||||
PackageId int64 `gorm:"column:package_id;type:bigint(19);comment:健康包配置id;NOT NULL" json:"package_id"`
|
||||
ServicePrice float64 `gorm:"column:service_price;type:decimal(10,2);comment:服务价格(根据图文问诊价格计算)" json:"service_price"`
|
||||
Model
|
||||
UserDoctor *UserDoctor `gorm:"foreignKey:DoctorId;references:doctor_id" json:"user_doctor"` // 医生
|
||||
HealthPackage *HealthPackage `gorm:"foreignKey:PackageId;references:package_id" json:"health_package"`
|
||||
}
|
||||
|
||||
func (m *DoctorConfigHealthPackage) TableName() string {
|
||||
|
||||
@ -15,7 +15,7 @@ type DoctorInquiryConfig struct {
|
||||
IsEnable int `gorm:"column:is_enable;type:tinyint(1);default:0;comment:是否启用(0:否 1:是)" json:"is_enable"`
|
||||
LastEnableMethod int `gorm:"column:last_enable_method;type:tinyint(1);default:1;comment:最后开启方式(1:自己 2:后台)" json:"last_enable_method"`
|
||||
WorkNumDay int `gorm:"column:work_num_day;type:int(10);default:0;comment:每日接诊数量" json:"work_num_day"`
|
||||
InquiryPrice float64 `gorm:"column:inquiry_price;type:decimal(10,2);comment:接诊价格(专家问诊-公益问诊)" json:"inquiry_price"`
|
||||
InquiryPrice *float64 `gorm:"column:inquiry_price;type:decimal(10,2);comment:接诊价格(专家问诊-公益问诊)" json:"inquiry_price"`
|
||||
UserDoctor *UserDoctor `gorm:"foreignKey:DoctorId;references:doctor_id" json:"user_doctor"` // 医生
|
||||
Model
|
||||
}
|
||||
|
||||
30
api/requests/doctorConfigHealthPackage.go
Normal file
30
api/requests/doctorConfigHealthPackage.go
Normal file
@ -0,0 +1,30 @@
|
||||
package requests
|
||||
|
||||
type DoctorConfigHealthPackageRequest struct {
|
||||
GetDoctorHealthPage // 获取医生账户列表-分页
|
||||
PutDoctorHealth // 修改医生健康包配置
|
||||
AddDoctorHealth // 新增医生健康包配置
|
||||
}
|
||||
|
||||
// GetDoctorHealthPage 获取医生账户列表-分页
|
||||
type GetDoctorHealthPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
Mobile string `json:"mobile" form:"mobile" label:"手机号"`
|
||||
DoctorName string `json:"doctor_name" form:"doctor_name" label:"医生姓名"`
|
||||
}
|
||||
|
||||
// PutDoctorHealth 修改医生健康包配置
|
||||
type PutDoctorHealth struct {
|
||||
PackageId string `json:"package_id" form:"package_id" label:"健康包配置id" validate:"required"`
|
||||
ServicePrice string `json:"service_price" form:"service_price" label:"服务价格" validate:"required,min=1"`
|
||||
IsEnable int `json:"is_enable" form:"is_enable" validate:"oneof=0 1" label:"是否启用"` // 0:否 1:是
|
||||
}
|
||||
|
||||
// AddDoctorHealth 新增医生健康包配置
|
||||
type AddDoctorHealth struct {
|
||||
DoctorId string `json:"doctor_id" form:"doctor_id" label:"医生id" validate:"required"`
|
||||
PackageId string `json:"package_id" form:"package_id" label:"健康包配置id" validate:"required"`
|
||||
ServicePrice string `json:"service_price" form:"service_price" label:"服务价格" validate:"required,min=1"`
|
||||
IsEnable int `json:"is_enable" form:"is_enable" validate:"oneof=0 1" label:"是否启用"` // 0:否 1:是
|
||||
}
|
||||
@ -526,6 +526,22 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
|
||||
// 新增医生问诊配置
|
||||
doctorGroup.POST("", api.InquiryConfig.AddDoctorInquiryConfig)
|
||||
|
||||
// 医生健康包配置
|
||||
healthGroup := doctorGroup.Group("/health")
|
||||
{
|
||||
// 获取开启健康包服务的医生-分页
|
||||
healthGroup.GET("", api.DoctorConfigHealthPackage.GetDoctorHealthPage)
|
||||
|
||||
// 医生健康包配置详情
|
||||
healthGroup.GET("/:health_package_id", api.DoctorConfigHealthPackage.GetDoctorHealth)
|
||||
|
||||
// 修改医生健康包配置
|
||||
healthGroup.PUT("/:health_package_id", api.DoctorConfigHealthPackage.PutDoctorHealth)
|
||||
|
||||
// 新增医生健康包配置
|
||||
healthGroup.POST("", api.DoctorConfigHealthPackage.AddDoctorHealth)
|
||||
}
|
||||
}
|
||||
|
||||
// 系统问诊配置
|
||||
|
||||
@ -70,7 +70,7 @@ func (r *DoctorInquiryConfigService) HandleDoctorInquiryConfig(tx *gorm.DB, doct
|
||||
IsEnable: isEnable,
|
||||
LastEnableMethod: 2,
|
||||
WorkNumDay: workNumDay,
|
||||
InquiryPrice: inquiryPrice,
|
||||
InquiryPrice: &inquiryPrice,
|
||||
}
|
||||
|
||||
adminUser, _ := doctorInquiryConfigDao.AddDoctorInquiryConfig(tx, m)
|
||||
@ -89,7 +89,7 @@ func (r *DoctorInquiryConfigService) HandleDoctorInquiryConfig(tx *gorm.DB, doct
|
||||
data["work_num_day"] = workNumDay
|
||||
}
|
||||
|
||||
if d.InquiryPrice != inquiryPrice {
|
||||
if d.InquiryPrice != &inquiryPrice {
|
||||
data["inquiry_price"] = inquiryPrice
|
||||
}
|
||||
|
||||
@ -286,7 +286,7 @@ func (r *DoctorInquiryConfigService) PutDoctorInquiryConfig(inquiryConfigId int6
|
||||
doctorInquiryConfigData["work_num_day"] = req.WorkNumDay
|
||||
}
|
||||
|
||||
if req.InquiryPrice != doctorInquiryConfig.InquiryPrice {
|
||||
if req.InquiryPrice != *doctorInquiryConfig.InquiryPrice {
|
||||
doctorInquiryConfigData["inquiry_price"] = req.InquiryPrice
|
||||
}
|
||||
|
||||
@ -500,7 +500,7 @@ func (r *DoctorInquiryConfigService) AddDoctorInquiryConfig(req requests.AddDoct
|
||||
IsEnable: req.IsEnable,
|
||||
LastEnableMethod: 2,
|
||||
WorkNumDay: req.WorkNumDay,
|
||||
InquiryPrice: req.InquiryPrice,
|
||||
InquiryPrice: &req.InquiryPrice,
|
||||
}
|
||||
|
||||
doctorInquiryConfig, err = doctorInquiryConfigDao.AddDoctorInquiryConfig(tx, doctorInquiryConfig)
|
||||
|
||||
267
api/service/doctorConfigHealthPackage.go
Normal file
267
api/service/doctorConfigHealthPackage.go
Normal file
@ -0,0 +1,267 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"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"
|
||||
)
|
||||
|
||||
type DoctorConfigHealthPackageService struct {
|
||||
}
|
||||
|
||||
// GetDoctorHealth 医生健康包配置详情
|
||||
func (r *DoctorConfigHealthPackageService) GetDoctorHealth(healthPackageId int64) (res *dto.DoctorConfigHealthPackageDto, err error) {
|
||||
doctorConfigHealthPackageDao := dao.DoctorConfigHealthPackageDao{}
|
||||
|
||||
doctorConfigHealthPackage, err := doctorConfigHealthPackageDao.GetDoctorConfigHealthPackageById(healthPackageId)
|
||||
if err != nil || doctorConfigHealthPackage == nil {
|
||||
return nil, errors.New("获取失败")
|
||||
}
|
||||
|
||||
// 获取医生数据
|
||||
userDoctorDao := dao.UserDoctorDao{}
|
||||
userDoctor, err := userDoctorDao.GetUserDoctorById(doctorConfigHealthPackage.DoctorId)
|
||||
if err != nil || userDoctor == nil {
|
||||
return nil, errors.New("获取失败")
|
||||
}
|
||||
|
||||
// 获取服务包数据
|
||||
healthPackageDao := dao.HealthPackageDao{}
|
||||
healthPackage, err := healthPackageDao.GetHealthPackageById(doctorConfigHealthPackage.PackageId)
|
||||
if err != nil || healthPackage == nil {
|
||||
return nil, errors.New("获取失败")
|
||||
}
|
||||
|
||||
// 获取医生医院数据
|
||||
hospitalDao := dao.HospitalDao{}
|
||||
hospital, err := hospitalDao.GetHospitalById(userDoctor.HospitalID)
|
||||
|
||||
// 获取医生问诊配置
|
||||
doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{}
|
||||
maps := make(map[string]interface{})
|
||||
maps["doctor_id"] = doctorConfigHealthPackage.DoctorId
|
||||
maps["inquiry_type"] = 1
|
||||
maps["inquiry_mode"] = 8
|
||||
doctorInquiryConfig, err := doctorInquiryConfigDao.GetDoctorInquiryConfig(maps)
|
||||
if err != nil {
|
||||
return nil, errors.New("获取失败")
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
res = dto.GetDoctorConfigHealthPackageDto(doctorConfigHealthPackage)
|
||||
|
||||
// 加载医生数据
|
||||
res.LoadUserDoctor(userDoctor)
|
||||
|
||||
// 加载医生医院
|
||||
if hospital != nil {
|
||||
res.LoadUserDoctorHospital(hospital)
|
||||
}
|
||||
|
||||
// 获取医生问诊配置
|
||||
res.LoadDoctorInquiryConfig(doctorInquiryConfig)
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// PutDoctorHealth 修改医生健康包配置
|
||||
func (r *DoctorConfigHealthPackageService) PutDoctorHealth(healthPackageId int64, req requests.PutDoctorHealth) (bool, error) {
|
||||
doctorConfigHealthPackageDao := dao.DoctorConfigHealthPackageDao{}
|
||||
|
||||
doctorConfigHealthPackage, err := doctorConfigHealthPackageDao.GetDoctorConfigHealthPackageById(healthPackageId)
|
||||
if err != nil || doctorConfigHealthPackage == nil {
|
||||
return false, errors.New("修改失败")
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
doctorConfigHealthPackageData := make(map[string]interface{})
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
packageId, err := strconv.ParseInt(req.PackageId, 10, 64)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("修改失败")
|
||||
}
|
||||
|
||||
if packageId != doctorConfigHealthPackage.PackageId {
|
||||
doctorConfigHealthPackageData["package_id"] = packageId
|
||||
}
|
||||
|
||||
servicePrice, err := strconv.ParseFloat(req.ServicePrice, 64)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("修改失败")
|
||||
}
|
||||
|
||||
if servicePrice != doctorConfigHealthPackage.ServicePrice {
|
||||
doctorConfigHealthPackageData["service_price"] = servicePrice
|
||||
}
|
||||
|
||||
if len(doctorConfigHealthPackageData) > 0 {
|
||||
err := doctorConfigHealthPackageDao.EditDoctorConfigHealthPackageById(tx, healthPackageId, doctorConfigHealthPackageData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("修改失败")
|
||||
}
|
||||
}
|
||||
|
||||
// 处理问诊配置
|
||||
// 获取医生问诊配置
|
||||
doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{}
|
||||
maps := make(map[string]interface{})
|
||||
maps["doctor_id"] = doctorConfigHealthPackage.DoctorId
|
||||
maps["inquiry_type"] = 1
|
||||
maps["inquiry_mode"] = 8
|
||||
doctorInquiryConfig, _ := doctorInquiryConfigDao.GetDoctorInquiryConfig(maps)
|
||||
if doctorInquiryConfig == nil {
|
||||
// 新增医生问诊配置
|
||||
doctorInquiryConfig = &model.DoctorInquiryConfig{
|
||||
DoctorId: doctorConfigHealthPackage.DoctorId,
|
||||
InquiryType: 1,
|
||||
InquiryMode: 8,
|
||||
IsEnable: req.IsEnable,
|
||||
LastEnableMethod: 2,
|
||||
WorkNumDay: 0,
|
||||
InquiryPrice: nil,
|
||||
}
|
||||
|
||||
doctorInquiryConfig, err = doctorInquiryConfigDao.AddDoctorInquiryConfig(tx, doctorInquiryConfig)
|
||||
if err != nil || doctorInquiryConfig == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
} else {
|
||||
// 修改医生问诊配置
|
||||
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 len(doctorInquiryConfigData) > 0 {
|
||||
err = doctorInquiryConfigDao.EditDoctorInquiryConfigById(tx, doctorInquiryConfig.InquiryConfigId, doctorInquiryConfigData)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("修改失败")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// AddDoctorHealth 新增医生健康包配置
|
||||
func (r *DoctorConfigHealthPackageService) AddDoctorHealth(req requests.AddDoctorHealth) (bool, error) {
|
||||
// 将 id 转换为 int64 类型
|
||||
packageId, err := strconv.ParseInt(req.PackageId, 10, 64)
|
||||
if err != 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("医生错误")
|
||||
}
|
||||
|
||||
doctorConfigHealthPackageDao := dao.DoctorConfigHealthPackageDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["doctor_id"] = doctorId
|
||||
doctorConfigHealthPackage, err := doctorConfigHealthPackageDao.GetDoctorConfigHealthPackage(maps)
|
||||
if doctorConfigHealthPackage != nil {
|
||||
return false, errors.New("该医生存在健康包配置,请勿重复添加")
|
||||
}
|
||||
|
||||
// 获取健康包配置
|
||||
healthPackageDao := dao.HealthPackageDao{}
|
||||
healthPackage, err := healthPackageDao.GetHealthPackagePreloadById(packageId)
|
||||
if err != nil {
|
||||
return false, errors.New("健康包错误")
|
||||
}
|
||||
|
||||
// 获取专家图文问诊价格
|
||||
maps = make(map[string]interface{})
|
||||
maps["doctor_id"] = req.DoctorId
|
||||
maps["inquiry_type"] = 1
|
||||
maps["inquiry_mode"] = 1
|
||||
|
||||
doctorInquiryConfigDao := dao.DoctorInquiryConfigDao{}
|
||||
doctorInquiryConfig, err := doctorInquiryConfigDao.GetDoctorInquiryConfig(maps)
|
||||
if err != nil && req.IsEnable == 1 {
|
||||
return false, errors.New("本服务需设置图文问诊的价格,才可开启")
|
||||
}
|
||||
|
||||
// 价格计算
|
||||
// 重新价格计算(专家图文问诊价格*费率+30盒35元的干爽颗粒)
|
||||
serviceRate, err := strconv.ParseFloat(healthPackage.ServiceRate, 64)
|
||||
if err != nil {
|
||||
return false, errors.New("修改失败")
|
||||
}
|
||||
|
||||
inquiryPrice := *doctorInquiryConfig.InquiryPrice
|
||||
servicePrice := inquiryPrice*serviceRate/100*6 + healthPackage.DiscountProductTotalAmount
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
// 创建医生健康包
|
||||
doctorConfigHealthPackage = &model.DoctorConfigHealthPackage{
|
||||
DoctorId: doctorId,
|
||||
PackageId: packageId,
|
||||
ServicePrice: servicePrice,
|
||||
}
|
||||
|
||||
doctorConfigHealthPackage, err = doctorConfigHealthPackageDao.AddDoctorConfigHealthPackage(tx, doctorConfigHealthPackage)
|
||||
if err != nil || doctorConfigHealthPackage == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 增加医生问诊配置
|
||||
if req.IsEnable == 1 {
|
||||
doctorInquiryConfig = &model.DoctorInquiryConfig{
|
||||
DoctorId: doctorId,
|
||||
InquiryType: 1,
|
||||
InquiryMode: 8,
|
||||
IsEnable: req.IsEnable,
|
||||
LastEnableMethod: 2,
|
||||
WorkNumDay: 0,
|
||||
InquiryPrice: nil,
|
||||
}
|
||||
|
||||
doctorInquiryConfig, err = doctorInquiryConfigDao.AddDoctorInquiryConfig(tx, doctorInquiryConfig)
|
||||
if err != nil || doctorInquiryConfig == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
return true, nil
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user