1
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hospital-admin-api/api/model"
|
||||
)
|
||||
|
||||
type HealthPackageDto struct {
|
||||
PackageId string `json:"package_id"` // 主键id
|
||||
ServiceCount int `json:"service_count"` // 总服务次数
|
||||
MonthlyFrequency int `json:"monthly_frequency"` // 每月次数
|
||||
EffectiveDays string `json:"effective_days"` // 服务有效天数
|
||||
ServiceRate string `json:"service_rate"` // 服务费率。100为满值,表示1,正常费率。
|
||||
DiscountProductTotalAmount float64 `json:"discount_product_total_amount"` // 折扣商品总价格
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
HealthPackageProduct []*HealthPackageProductDto `json:"health_package_product"` // 健康包-关联商品
|
||||
}
|
||||
|
||||
func GetHealthPackageDto(m *model.HealthPackage) *HealthPackageDto {
|
||||
return &HealthPackageDto{
|
||||
PackageId: fmt.Sprintf("%d", m.PackageId),
|
||||
ServiceCount: m.ServiceCount,
|
||||
MonthlyFrequency: m.MonthlyFrequency,
|
||||
EffectiveDays: m.EffectiveDays,
|
||||
ServiceRate: m.ServiceRate,
|
||||
DiscountProductTotalAmount: m.DiscountProductTotalAmount,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
func GetHealthPackageListDto(m []*model.HealthPackage) []*HealthPackageDto {
|
||||
// 处理返回值
|
||||
responses := make([]*HealthPackageDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &HealthPackageDto{
|
||||
PackageId: fmt.Sprintf("%d", v.PackageId),
|
||||
ServiceCount: v.ServiceCount,
|
||||
MonthlyFrequency: v.MonthlyFrequency,
|
||||
EffectiveDays: v.EffectiveDays,
|
||||
ServiceRate: v.ServiceRate,
|
||||
DiscountProductTotalAmount: v.DiscountProductTotalAmount,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
if len(v.HealthPackageProduct) > 0 {
|
||||
response.LoadHealthPackageProduct(v.HealthPackageProduct)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadHealthPackageProduct 加载健康包-关联商品
|
||||
func (r *HealthPackageDto) LoadHealthPackageProduct(m []*model.HealthPackageProduct) *HealthPackageDto {
|
||||
if len(m) > 0 {
|
||||
r.HealthPackageProduct = GetHealthPackageProductListDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
Reference in New Issue
Block a user