hospital-admin-api/api/dto/DoctorBankCard.go

111 lines
3.5 KiB
Go

package dto
import (
"fmt"
"hospital-admin-api/api/model"
"hospital-admin-api/utils"
)
type DoctorBankCardDto struct {
BankCardId string `json:"bank_card_id"` // 主键id
DoctorId string `json:"doctor_id"` // 医生id
BankId string `json:"bank_id"` // 银行id
BankCardCodeMask string `json:"bank_card_code_mask"` // 银行卡号(掩码)
ProvinceId int `json:"province_id"` // 省份id
Province string `json:"province"` // 省份
CityId int `json:"city_id"` // 城市id
City string `json:"city"` // 城市
CountyId int `json:"county_id"` // 区县id
County string `json:"county"` // 区县
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
DoctorName string `json:"doctor_name"` // 医生姓名
BankName string `json:"bank_name"` // 银行名称
DoctorMobileMask string `json:"doctor_mobile_mask"` // 医生手机号(掩码)
}
func GetDoctorBankCardDto(m *model.DoctorBankCard) *DoctorBankCardDto {
return &DoctorBankCardDto{
BankCardId: fmt.Sprintf("%d", m.BankCardId),
DoctorId: fmt.Sprintf("%d", m.DoctorId),
BankId: fmt.Sprintf("%d", m.BankId),
BankCardCodeMask: m.BankCardCodeMask,
ProvinceId: m.ProvinceId,
Province: m.Province,
CityId: m.CityId,
City: m.City,
CountyId: m.CountyId,
County: m.County,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
func GetDoctorBankCardListDto(m []*model.DoctorBankCard) []DoctorBankCardDto {
// 处理返回值
responses := make([]DoctorBankCardDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := DoctorBankCardDto{
BankCardId: fmt.Sprintf("%d", v.BankCardId),
DoctorId: fmt.Sprintf("%d", v.DoctorId),
BankId: fmt.Sprintf("%d", v.BankId),
BankCardCodeMask: v.BankCardCodeMask,
ProvinceId: v.ProvinceId,
Province: v.Province,
CityId: v.CityId,
City: v.City,
CountyId: v.CountyId,
County: v.County,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 加载银行名称
if v.BasicBank != nil {
response.LoadBankName(v.BasicBank)
}
// 加载医生名称
if v.UserDoctor != nil {
response.LoadDoctorName(v.UserDoctor)
// 加载医生手机号(掩码)
if v.UserDoctor.User != nil {
response.LoadDoctorMobileMask(v.UserDoctor.User)
}
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// LoadDoctorName 加载医生名称
func (r *DoctorBankCardDto) LoadDoctorName(m *model.UserDoctor) *DoctorBankCardDto {
if m != nil {
r.DoctorName = m.UserName
}
return r
}
// LoadBankName 加载银行名称
func (r *DoctorBankCardDto) LoadBankName(m *model.BasicBank) *DoctorBankCardDto {
if m != nil {
r.BankName = m.BankName
}
return r
}
// LoadDoctorMobileMask 加载医生手机号(掩码)
func (r *DoctorBankCardDto) LoadDoctorMobileMask(m *model.User) *DoctorBankCardDto {
if m != nil {
r.DoctorMobileMask = utils.MaskPhoneStr(m.Mobile)
}
return r
}