From a4255c5404b14c6493a7b18c408b3e7905fa3766 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Tue, 12 Sep 2023 09:56:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=82=A3=E8=80=85=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/dao/orderProduct.go | 15 ++++--- api/model/orderProduct.go | 1 + api/model/userPatient.go | 40 +++++++++++++++++++ .../orderInquiryResponse/orderInquiry.go | 3 +- .../orderProductResponse/orderProduct.go | 2 + 5 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 api/model/userPatient.go diff --git a/api/dao/orderProduct.go b/api/dao/orderProduct.go index 118828c..603aa45 100644 --- a/api/dao/orderProduct.go +++ b/api/dao/orderProduct.go @@ -87,11 +87,6 @@ func (r *OrderProductDao) GetOrderProductPageSearch(req requests.GetOrderProduct return db.Omit("open_id", "union_id", "wx_session_key") }) - // 问诊订单 - query = query.Preload("OrderInquiry", func(db *gorm.DB) *gorm.DB { - return db.Select("order_inquiry_id", "patient_name_mask", "patient_sex", "patient_age") - }) - // 医生姓名 if req.DoctorName != "" { subQuery := global.Db.Model(&model.UserDoctor{}). @@ -101,6 +96,16 @@ func (r *OrderProductDao) GetOrderProductPageSearch(req requests.GetOrderProduct query = query.Where(gorm.Expr("doctor_id IN (?)", subQuery)) } + // 问诊订单 + query = query.Preload("OrderInquiry", func(db *gorm.DB) *gorm.DB { + return db.Select("order_inquiry_id", "patient_name_mask", "patient_sex", "patient_age") + }) + + // 患者名称 + query = query.Preload("UserPatient.User", func(db *gorm.DB) *gorm.DB { + return db.Select("user_id", "user_name", "mobile") + }) + // 患者姓名-就诊人 if req.PatientName != "" { subQuery := global.Db.Model(&model.OrderInquiry{}). diff --git a/api/model/orderProduct.go b/api/model/orderProduct.go index a78e410..002929c 100644 --- a/api/model/orderProduct.go +++ b/api/model/orderProduct.go @@ -50,6 +50,7 @@ type OrderProduct struct { ConsigneeTelMask string `gorm:"column:consignee_tel_mask;type:varchar(50);comment:收货人电话(掩码)" json:"consignee_tel_mask"` UserDoctor *UserDoctor `gorm:"foreignKey:DoctorId;references:doctor_id" json:"user_doctor"` // 医生 OrderInquiry *OrderInquiry `gorm:"foreignKey:OrderInquiryId;references:order_inquiry_id" json:"order_inquiry"` // 问诊 + UserPatient *UserPatient `gorm:"foreignKey:PatientId;references:patient_id" json:"user_patient"` // 患者 Model } diff --git a/api/model/userPatient.go b/api/model/userPatient.go new file mode 100644 index 0000000..23815f0 --- /dev/null +++ b/api/model/userPatient.go @@ -0,0 +1,40 @@ +package model + +import ( + "gorm.io/gorm" + "hospital-admin-api/global" + "time" +) + +// UserPatient 用户-患者表 +type UserPatient struct { + PatientId int64 `gorm:"column:patient_id;type:bigint(19);primary_key;comment:主键id" json:"patient_id"` + UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"` + UserName string `gorm:"column:user_name;type:varchar(100);comment:用户名称" json:"user_name"` + OpenId string `gorm:"column:open_id;type:varchar(100);comment:微信open_id" json:"open_id"` + UnionId string `gorm:"column:union_id;type:varchar(100);comment:微信开放平台唯一标识" json:"union_id"` + WxSessionKey string `gorm:"column:wx_session_key;type:varchar(255);comment:微信会话密钥" json:"wx_session_key"` + Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(0:禁用 1:正常 2:删除)" json:"status"` + IdcardStatus int `gorm:"column:idcard_status;type:tinyint(1);default:0;comment:实名认证状态(0:未认证 1:认证通过 2:认证失败)" json:"idcard_status"` + Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"` + User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"` // 用户 + Model +} + +func (m *UserPatient) TableName() string { + return "gdxz_user_patient" +} + +func (m *UserPatient) BeforeCreate(tx *gorm.DB) error { + if m.PatientId == 0 { + m.PatientId = global.Snowflake.Generate().Int64() + } + + m.CreatedAt = LocalTime(time.Now()) + tx.Statement.SetColumn("CreatedAt", m.CreatedAt) + + m.UpdatedAt = LocalTime(time.Now()) + tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt) + + return nil +} diff --git a/api/responses/orderInquiryResponse/orderInquiry.go b/api/responses/orderInquiryResponse/orderInquiry.go index b4022d7..6503350 100644 --- a/api/responses/orderInquiryResponse/orderInquiry.go +++ b/api/responses/orderInquiryResponse/orderInquiry.go @@ -8,7 +8,6 @@ import ( "hospital-admin-api/api/responses/orderInquiryCouponResponse" "hospital-admin-api/api/responses/orderInquiryRefundResponse" "hospital-admin-api/api/responses/userDoctorResponse" - "hospital-admin-api/utils" ) // getOrderInquiryPage 获取医生列表-分页 @@ -135,7 +134,7 @@ func GetOrderInquiryPageResponse(orderInquiry []*model.OrderInquiry) []getOrderI PatientNameMask: v.PatientNameMask, PatientSex: v.PatientSex, PatientAge: v.PatientAge, - PatientMobile: utils.MaskPhoneStr(v.User.Mobile), + PatientMobile: v.User.Mobile, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, } diff --git a/api/responses/orderProductResponse/orderProduct.go b/api/responses/orderProductResponse/orderProduct.go index fc962d0..ac8b017 100644 --- a/api/responses/orderProductResponse/orderProduct.go +++ b/api/responses/orderProductResponse/orderProduct.go @@ -41,6 +41,7 @@ type getOrderProductPage struct { PatientNameMask string `json:"patient_name_mask"` // 患者姓名-就诊人(掩码) PatientSex int `json:"patient_sex"` // 患者性别-就诊人(0:未知 1:男 2:女) PatientAge int `json:"patient_age"` // 患者年龄-就诊人 + PatientMobile string `json:"patient_mobile"` // 患者电话 CreatedAt model.LocalTime `json:"created_at"` // 创建时间 UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间 } @@ -136,6 +137,7 @@ func GetOrderProductPageResponse(orderProduct []*model.OrderProduct) []getOrderP ReportPreStatus: v.ReportPreStatus, ConsigneeNameMask: v.ConsigneeNameMask, ConsigneeTelMask: v.ConsigneeTelMask, + PatientMobile: v.UserPatient.User.Mobile, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, }