处理 GORM 0 的bug
This commit is contained in:
@@ -3,6 +3,7 @@ package dto
|
||||
import (
|
||||
"fmt"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/global"
|
||||
)
|
||||
|
||||
type DoctorPharmacyDto struct {
|
||||
@@ -39,6 +40,12 @@ func GetDoctorPharmacyDto(m *model.DoctorPharmacy) *DoctorPharmacyDto {
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
if m.Pharmacy == nil {
|
||||
var ph model.Pharmacy
|
||||
if err := global.Db.Where("pharmacy_id = ?", m.PharmacyId).First(&ph).Error; err == nil {
|
||||
m.Pharmacy = &ph
|
||||
}
|
||||
}
|
||||
if m.Pharmacy != nil {
|
||||
dto.PharmacyName = m.Pharmacy.PharmacyName
|
||||
dto.PharmacyCode = m.Pharmacy.PharmacyCode
|
||||
|
||||
+21
-1
@@ -9,6 +9,10 @@ import (
|
||||
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"` // 处方可开具的数量
|
||||
@@ -36,9 +40,11 @@ type ProductDto struct {
|
||||
|
||||
// GetProductDto 商品详情
|
||||
func GetProductDto(m *model.Product) *ProductDto {
|
||||
return &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,
|
||||
@@ -62,6 +68,13 @@ func GetProductDto(m *model.Product) *ProductDto {
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
|
||||
if m.Pharmacy != nil {
|
||||
dto.Pharmacy = GetPharmacyDto(m.Pharmacy)
|
||||
dto.PharmacyName = m.Pharmacy.PharmacyName
|
||||
}
|
||||
|
||||
return dto
|
||||
}
|
||||
|
||||
// GetProductListDto 商品列表
|
||||
@@ -74,6 +87,8 @@ func GetProductListDto(m []*model.Product) []*ProductDto {
|
||||
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,
|
||||
@@ -98,6 +113,11 @@ func GetProductListDto(m []*model.Product) []*ProductDto {
|
||||
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)
|
||||
|
||||
@@ -12,6 +12,7 @@ type ProductPlatformDto struct {
|
||||
ProductType int `json:"product_type"` // 药品类型(0:未知 1:中成药 2:西药)
|
||||
ProductPlatformCode string `json:"product_platform_code"` // 处方平台商品编码
|
||||
ProductPharmacyCode string `json:"product_pharmacy_code"` // 第三方药店商品编码
|
||||
PharmacyCode string `json:"pharmacy_code"` // 第三方药房编码
|
||||
ProductSpec string `json:"product_spec"` // 商品规格
|
||||
LicenseNumber string `json:"license_number"` // 批准文号
|
||||
Manufacturer string `json:"manufacturer"` // 生产厂家
|
||||
@@ -33,6 +34,7 @@ func GetProductPlatformDto(m *model.ProductPlatform) *ProductPlatformDto {
|
||||
ProductType: m.ProductType,
|
||||
ProductPlatformCode: m.ProductPlatformCode,
|
||||
ProductPharmacyCode: m.ProductPharmacyCode,
|
||||
PharmacyCode: m.PharmacyCode,
|
||||
ProductSpec: m.ProductSpec,
|
||||
LicenseNumber: m.LicenseNumber,
|
||||
Manufacturer: m.Manufacturer,
|
||||
@@ -59,6 +61,7 @@ func GetProductPlatformListDto(m []*model.ProductPlatform) []*ProductPlatformDto
|
||||
ProductType: v.ProductType,
|
||||
ProductPlatformCode: v.ProductPlatformCode,
|
||||
ProductPharmacyCode: v.ProductPharmacyCode,
|
||||
PharmacyCode: v.PharmacyCode,
|
||||
ProductSpec: v.ProductSpec,
|
||||
LicenseNumber: v.LicenseNumber,
|
||||
Manufacturer: v.Manufacturer,
|
||||
|
||||
Reference in New Issue
Block a user