141 lines
5.9 KiB
Go
141 lines
5.9 KiB
Go
package dto
|
|
|
|
import (
|
|
"fmt"
|
|
"hospital-admin-api/api/model"
|
|
"hospital-admin-api/utils"
|
|
)
|
|
|
|
type ProductDto struct {
|
|
ProductId string `json:"product_id"` // 主键id
|
|
ProductPlatformId string `json:"product_platform_id"` // 处方平台商品id
|
|
PharmacyId string `json:"pharmacy_id"` // 所属药房ID
|
|
PharmacyCode string `json:"pharmacy_code"` // 所属药房编码
|
|
PharmacyName string `json:"pharmacy_name"` // 所属药房名称
|
|
Pharmacy *PharmacyDto `json:"pharmacy"` // 所属药房详情
|
|
ProductStatus int `json:"product_status"` // 商品状态(1:正常 2:下架)
|
|
IsDelete int `json:"is_delete"` // 是否删除(0:否 1:是)
|
|
PrescriptionNum int `json:"prescription_num"` // 处方可开具的数量
|
|
ProductName string `json:"product_name"` // 商品名称
|
|
CommonName string `json:"common_name"` // 商品通用名
|
|
ProductPrice float64 `json:"product_price"` // 商品价格
|
|
MnemonicCode string `json:"mnemonic_code"` // 商品助记码(首字母简拼)
|
|
ProductType int `json:"product_type"` // 药品类型(0:未知 1:中成药 2:西药)
|
|
ProductPlatformCode string `json:"product_platform_code"` // 处方平台商品编码
|
|
ProductPharmacyCode string `json:"product_pharmacy_code"` // 第三方药店商品编码
|
|
ProductCoverImg string `json:"product_cover_img"` // 商品封面图
|
|
ProductSpec string `json:"product_spec"` // 商品规格
|
|
LicenseNumber string `json:"license_number"` // 批准文号
|
|
Manufacturer string `json:"manufacturer"` // 生产厂家
|
|
SingleUnit string `json:"single_unit"` // 单次剂量(例:1次1包)
|
|
SingleUse string `json:"single_use"` // 单次用法(例:口服)
|
|
PackagingUnit string `json:"packaging_unit"` // 基本包装单位(例:盒/瓶)
|
|
FrequencyUse string `json:"frequency_use"` // 使用频率(例:1天3次)
|
|
AvailableDays float64 `json:"available_days"` // 可用天数(3)
|
|
ProductRemarks string `json:"product_remarks"` // 商品备注
|
|
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
|
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
|
Stock uint `json:"stock"` // 现有库存
|
|
}
|
|
|
|
// GetProductDto 商品详情
|
|
func GetProductDto(m *model.Product) *ProductDto {
|
|
dto := &ProductDto{
|
|
ProductId: fmt.Sprintf("%d", m.ProductId),
|
|
ProductPlatformId: fmt.Sprintf("%d", m.ProductPlatformId),
|
|
PharmacyId: fmt.Sprintf("%d", m.PharmacyId),
|
|
PharmacyCode: m.PharmacyCode,
|
|
ProductStatus: m.ProductStatus,
|
|
IsDelete: m.IsDelete,
|
|
PrescriptionNum: m.PrescriptionNum,
|
|
ProductName: m.ProductName,
|
|
CommonName: m.CommonName,
|
|
ProductPrice: m.ProductPrice,
|
|
MnemonicCode: m.MnemonicCode,
|
|
ProductType: m.ProductType,
|
|
ProductPlatformCode: m.ProductPlatformCode,
|
|
ProductPharmacyCode: m.ProductPharmacyCode,
|
|
ProductCoverImg: utils.AddOssDomain(m.ProductCoverImg),
|
|
ProductSpec: m.ProductSpec,
|
|
LicenseNumber: m.LicenseNumber,
|
|
Manufacturer: m.Manufacturer,
|
|
SingleUnit: m.SingleUnit,
|
|
SingleUse: m.SingleUse,
|
|
PackagingUnit: m.PackagingUnit,
|
|
FrequencyUse: m.FrequencyUse,
|
|
AvailableDays: m.AvailableDays,
|
|
ProductRemarks: m.ProductRemarks,
|
|
CreatedAt: m.CreatedAt,
|
|
UpdatedAt: m.UpdatedAt,
|
|
}
|
|
|
|
if m.Pharmacy != nil {
|
|
dto.Pharmacy = GetPharmacyDto(m.Pharmacy)
|
|
dto.PharmacyName = m.Pharmacy.PharmacyName
|
|
}
|
|
|
|
return dto
|
|
}
|
|
|
|
// GetProductListDto 商品列表
|
|
func GetProductListDto(m []*model.Product) []*ProductDto {
|
|
// 处理返回值
|
|
responses := make([]*ProductDto, len(m))
|
|
|
|
if len(m) > 0 {
|
|
for i, v := range m {
|
|
response := &ProductDto{
|
|
ProductId: fmt.Sprintf("%d", v.ProductId),
|
|
ProductPlatformId: fmt.Sprintf("%d", v.ProductPlatformId),
|
|
PharmacyId: fmt.Sprintf("%d", v.PharmacyId),
|
|
PharmacyCode: v.PharmacyCode,
|
|
ProductStatus: v.ProductStatus,
|
|
IsDelete: v.IsDelete,
|
|
PrescriptionNum: v.PrescriptionNum,
|
|
ProductName: v.ProductName,
|
|
CommonName: v.CommonName,
|
|
ProductPrice: v.ProductPrice,
|
|
MnemonicCode: v.MnemonicCode,
|
|
ProductType: v.ProductType,
|
|
ProductPlatformCode: v.ProductPlatformCode,
|
|
ProductPharmacyCode: v.ProductPharmacyCode,
|
|
ProductCoverImg: utils.AddOssDomain(v.ProductCoverImg),
|
|
ProductSpec: v.ProductSpec,
|
|
LicenseNumber: v.LicenseNumber,
|
|
Manufacturer: v.Manufacturer,
|
|
SingleUnit: v.SingleUnit,
|
|
SingleUse: v.SingleUse,
|
|
PackagingUnit: v.PackagingUnit,
|
|
FrequencyUse: v.FrequencyUse,
|
|
AvailableDays: v.AvailableDays,
|
|
ProductRemarks: v.ProductRemarks,
|
|
CreatedAt: v.CreatedAt,
|
|
UpdatedAt: v.UpdatedAt,
|
|
}
|
|
|
|
if v.Pharmacy != nil {
|
|
response.Pharmacy = GetPharmacyDto(v.Pharmacy)
|
|
response.PharmacyName = v.Pharmacy.PharmacyName
|
|
}
|
|
|
|
// 加载商品库存
|
|
if v.ProductPlatformAmount != nil {
|
|
response = response.LoadProductAmount(v.ProductPlatformAmount)
|
|
}
|
|
|
|
// 将转换后的结构体添加到新切片中
|
|
responses[i] = response
|
|
}
|
|
}
|
|
|
|
return responses
|
|
}
|
|
|
|
// LoadProductAmount 加载商品库存
|
|
func (r *ProductDto) LoadProductAmount(m *model.ProductPlatformAmount) *ProductDto {
|
|
if m != nil {
|
|
r.Stock = m.Stock
|
|
}
|
|
return r
|
|
}
|