处理 GORM 0 的bug
This commit is contained in:
@@ -24,6 +24,28 @@ func (r *DoctorPharmacyDao) GetDoctorPharmacyListByDoctorId(doctorId int64) (m [
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// GORM 在外键为 0 时会自动跳过 Preload,因此针对未能预加载的记录进行兜底补全
|
||||
var zeroPharmacy *model.Pharmacy
|
||||
for _, dp := range m {
|
||||
if dp.Pharmacy == nil {
|
||||
if dp.PharmacyId == 0 {
|
||||
if zeroPharmacy == nil {
|
||||
var ph model.Pharmacy
|
||||
if err := global.Db.Where("pharmacy_id = 0").First(&ph).Error; err == nil {
|
||||
zeroPharmacy = &ph
|
||||
}
|
||||
}
|
||||
dp.Pharmacy = zeroPharmacy
|
||||
} else {
|
||||
var ph model.Pharmacy
|
||||
if err := global.Db.Where("pharmacy_id = ?", dp.PharmacyId).First(&ph).Error; err == nil {
|
||||
dp.Pharmacy = &ph
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
|
||||
+59
-6
@@ -15,10 +15,16 @@ type ProductDao struct {
|
||||
|
||||
// GetProductById 获取商品数据-商品id
|
||||
func (r *ProductDao) GetProductById(productId int64) (m *model.Product, err error) {
|
||||
err = global.Db.First(&m, productId).Error
|
||||
err = global.Db.Preload("Pharmacy").First(&m, productId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if m != nil && m.Pharmacy == nil && m.PharmacyId == 0 {
|
||||
var ph model.Pharmacy
|
||||
if err := global.Db.Where("pharmacy_id = 0").First(&ph).Error; err == nil {
|
||||
m.Pharmacy = &ph
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
@@ -85,7 +91,7 @@ func (r *ProductDao) GetProductPageSearch(req requests.GetProductPage, page, pag
|
||||
// 库存表
|
||||
query = query.Preload("ProductPlatformAmount", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("amount_id", "product_platform_id", "product_platform_code", "stock")
|
||||
})
|
||||
}).Preload("Pharmacy")
|
||||
|
||||
// 商品名称
|
||||
if req.ProductName != "" {
|
||||
@@ -132,6 +138,16 @@ func (r *ProductDao) GetProductPageSearch(req requests.GetProductPage, page, pag
|
||||
query = query.Where("product_pharmacy_code LIKE ?", "%"+req.ProductPharmacyCode+"%")
|
||||
}
|
||||
|
||||
// 所属药房ID
|
||||
if req.PharmacyId != "" {
|
||||
query = query.Where("gdxz_product.pharmacy_id = ?", req.PharmacyId)
|
||||
}
|
||||
|
||||
// 所属药房编码
|
||||
if req.PharmacyCode != "" {
|
||||
query = query.Where("gdxz_product.pharmacy_code LIKE ?", "%"+req.PharmacyCode+"%")
|
||||
}
|
||||
|
||||
// 批准文号
|
||||
if req.LicenseNumber != "" {
|
||||
query = query.Where("license_number LIKE ?", "%"+req.LicenseNumber+"%")
|
||||
@@ -171,6 +187,7 @@ func (r *ProductDao) GetProductPageSearch(req requests.GetProductPage, page, pag
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
fillZeroPharmacy(m)
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
@@ -182,7 +199,7 @@ func (r *ProductDao) GetProductExportListSearch(req requests.ProductExportList)
|
||||
// 库存表
|
||||
query = query.Preload("ProductPlatformAmount", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("amount_id", "product_platform_id", "product_platform_code", "stock")
|
||||
})
|
||||
}).Preload("Pharmacy")
|
||||
|
||||
// 当前搜索数据
|
||||
if req.Type == 1 {
|
||||
@@ -226,6 +243,16 @@ func (r *ProductDao) GetProductExportListSearch(req requests.ProductExportList)
|
||||
query = query.Where("product_pharmacy_code LIKE ?", "%"+req.ProductPharmacyCode+"%")
|
||||
}
|
||||
|
||||
// 所属药房ID
|
||||
if req.PharmacyId != "" {
|
||||
query = query.Where("gdxz_product.pharmacy_id = ?", req.PharmacyId)
|
||||
}
|
||||
|
||||
// 所属药房编码
|
||||
if req.PharmacyCode != "" {
|
||||
query = query.Where("gdxz_product.pharmacy_code LIKE ?", "%"+req.PharmacyCode+"%")
|
||||
}
|
||||
|
||||
// 批准文号
|
||||
if req.LicenseNumber != "" {
|
||||
query = query.Where("license_number LIKE ?", "%"+req.LicenseNumber+"%")
|
||||
@@ -259,7 +286,7 @@ func (r *ProductDao) GetProductExportListSearch(req requests.ProductExportList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fillZeroPharmacy(m)
|
||||
return m, nil
|
||||
}
|
||||
|
||||
@@ -271,7 +298,7 @@ func (r *ProductDao) GetProductListSearch(req requests.GetProductList) (m []*mod
|
||||
// 库存表
|
||||
query = query.Preload("ProductPlatformAmount", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Select("amount_id", "product_platform_id", "product_platform_code", "stock")
|
||||
})
|
||||
}).Preload("Pharmacy")
|
||||
|
||||
// 商品id
|
||||
if req.ProductId != "" {
|
||||
@@ -323,6 +350,16 @@ func (r *ProductDao) GetProductListSearch(req requests.GetProductList) (m []*mod
|
||||
query = query.Where("product_pharmacy_code LIKE ?", "%"+req.ProductPharmacyCode+"%")
|
||||
}
|
||||
|
||||
// 所属药房ID
|
||||
if req.PharmacyId != "" {
|
||||
query = query.Where("gdxz_product.pharmacy_id = ?", req.PharmacyId)
|
||||
}
|
||||
|
||||
// 所属药房编码
|
||||
if req.PharmacyCode != "" {
|
||||
query = query.Where("gdxz_product.pharmacy_code LIKE ?", "%"+req.PharmacyCode+"%")
|
||||
}
|
||||
|
||||
// 批准文号
|
||||
if req.LicenseNumber != "" {
|
||||
query = query.Where("license_number LIKE ?", "%"+req.LicenseNumber+"%")
|
||||
@@ -348,6 +385,22 @@ func (r *ProductDao) GetProductListSearch(req requests.GetProductList) (m []*mod
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fillZeroPharmacy(m)
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// fillZeroPharmacy 补全因 GORM 零值跳过预加载的 pharmacy_id = 0 药房实体
|
||||
func fillZeroPharmacy(products []*model.Product) {
|
||||
var zeroPharmacy *model.Pharmacy
|
||||
for _, p := range products {
|
||||
if p.Pharmacy == nil && p.PharmacyId == 0 {
|
||||
if zeroPharmacy == nil {
|
||||
var ph model.Pharmacy
|
||||
if err := global.Db.Where("pharmacy_id = 0").First(&ph).Error; err == nil {
|
||||
zeroPharmacy = &ph
|
||||
}
|
||||
}
|
||||
p.Pharmacy = zeroPharmacy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +90,11 @@ func (r *ProductPlatformDao) GetPlatformProductPageSearch(req requests.GetPlatfo
|
||||
query = query.Where("product_pharmacy_code LIKE ?", "%"+req.ProductPharmacyCode+"%")
|
||||
}
|
||||
|
||||
// 第三方药房编码
|
||||
if req.PharmacyCode != "" {
|
||||
query = query.Where("pharmacy_code LIKE ?", "%"+req.PharmacyCode+"%")
|
||||
}
|
||||
|
||||
// 批准文号
|
||||
if req.LicenseNumber != "" {
|
||||
query = query.Where("license_number LIKE ?", "%"+req.LicenseNumber+"%")
|
||||
@@ -140,6 +145,11 @@ func (r *ProductPlatformDao) GetPlatformProductListSearch(req requests.GetPlatfo
|
||||
query = query.Where("product_pharmacy_code LIKE ?", "%"+req.ProductPharmacyCode+"%")
|
||||
}
|
||||
|
||||
// 第三方药房编码
|
||||
if req.PharmacyCode != "" {
|
||||
query = query.Where("pharmacy_code LIKE ?", "%"+req.PharmacyCode+"%")
|
||||
}
|
||||
|
||||
// 批准文号
|
||||
if req.LicenseNumber != "" {
|
||||
query = query.Where("license_number LIKE ?", "%"+req.LicenseNumber+"%")
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
type Product struct {
|
||||
ProductId int64 `gorm:"column:product_id;type:bigint(19);primary_key;comment:主键id" json:"product_id"`
|
||||
ProductPlatformId int64 `gorm:"column:product_platform_id;type:bigint(19);comment:处方平台商品id" json:"product_platform_id"`
|
||||
PharmacyId int64 `gorm:"column:pharmacy_id;type:bigint(20) unsigned;default:0;comment:所属药房ID" json:"pharmacy_id"`
|
||||
PharmacyCode string `gorm:"column:pharmacy_code;type:varchar(64);default:'';comment:所属药房编码" json:"pharmacy_code"`
|
||||
ProductStatus int `gorm:"column:product_status;type:tinyint(1);default:1;comment:商品状态(1:正常 2:下架)" json:"product_status"`
|
||||
IsDelete int `gorm:"column:is_delete;type:tinyint(1);default:0;comment:是否删除(0:否 1:是)" json:"is_delete"`
|
||||
PrescriptionNum int `gorm:"column:prescription_num;type:int(11);default:5;comment:处方可开具的数量" json:"prescription_num"`
|
||||
@@ -32,6 +34,7 @@ type Product struct {
|
||||
AvailableDays float64 `gorm:"column:available_days;type:float(10,2);comment:可用天数(3)" json:"available_days"`
|
||||
ProductRemarks string `gorm:"column:product_remarks;type:varchar(255);comment:商品备注" json:"product_remarks"`
|
||||
ProductPlatformAmount *ProductPlatformAmount `gorm:"foreignKey:ProductPlatformId;references:product_platform_id" json:"product_platform_amount"` // 库存
|
||||
Pharmacy *Pharmacy `gorm:"foreignKey:PharmacyId;references:pharmacy_id" json:"pharmacy"` // 所属药房
|
||||
Model
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ type ProductPlatform struct {
|
||||
ProductType int `gorm:"column:product_type;type:tinyint(4);default:1;comment:药品类型(0:未知 1:中成药 2:西药)" json:"product_type"`
|
||||
ProductPlatformCode string `gorm:"column:product_platform_code;type:varchar(100);comment:处方平台商品编码" json:"product_platform_code"`
|
||||
ProductPharmacyCode string `gorm:"column:product_pharmacy_code;type:varchar(100);comment:第三方药店商品编码" json:"product_pharmacy_code"`
|
||||
PharmacyCode string `gorm:"column:pharmacy_code;type:varchar(64);default:'';comment:第三方药房编码" json:"pharmacy_code"`
|
||||
ProductSpec string `gorm:"column:product_spec;type:varchar(255);comment:商品规格" json:"product_spec"`
|
||||
LicenseNumber string `gorm:"column:license_number;type:varchar(255);comment:批准文号" json:"license_number"`
|
||||
Manufacturer string `gorm:"column:manufacturer;type:varchar(255);comment:生产厂家" json:"manufacturer"`
|
||||
|
||||
@@ -19,6 +19,7 @@ type GetPlatformProductPage struct {
|
||||
ProductType *int `json:"product_type" form:"product_type" label:"药品类型"` // 药品类型(0:未知 1:中成药 2:西药)
|
||||
ProductPlatformCode string `json:"product_platform_code" form:"product_platform_code" label:"处方平台编码"` // 处方平台商品编码
|
||||
ProductPharmacyCode string `json:"product_pharmacy_code" form:"product_pharmacy_code" label:"药店编码"` // 第三方药店商品编码
|
||||
PharmacyCode string `json:"pharmacy_code" form:"pharmacy_code" label:"第三方药房编码"` // 第三方药房编码
|
||||
LicenseNumber string `json:"license_number" form:"license_number" label:"批准文号"` // 批准文号
|
||||
Manufacturer string `json:"manufacturer" form:"manufacturer" label:"生产厂家"` // 生产厂家
|
||||
}
|
||||
@@ -29,6 +30,7 @@ type GetPlatformProductList struct {
|
||||
ProductType *int `json:"product_type" form:"product_type" label:"药品类型"` // 药品类型(0:未知 1:中成药 2:西药)
|
||||
ProductPlatformCode string `json:"product_platform_code" form:"product_platform_code" label:"处方平台编码"` // 处方平台商品编码
|
||||
ProductPharmacyCode string `json:"product_pharmacy_code" form:"product_pharmacy_code" label:"药店编码"` // 第三方药店商品编码
|
||||
PharmacyCode string `json:"pharmacy_code" form:"pharmacy_code" label:"第三方药房编码"` // 第三方药房编码
|
||||
LicenseNumber string `json:"license_number" form:"license_number" label:"批准文号"` // 批准文号
|
||||
Manufacturer string `json:"manufacturer" form:"manufacturer" label:"生产厂家"` // 生产厂家
|
||||
}
|
||||
@@ -45,6 +47,8 @@ type GetProductPage struct {
|
||||
ProductPlatformId string `json:"product_platform_id" form:"product_platform_id" label:"平台商品id"` // 处方平台商品id
|
||||
ProductPlatformCode string `json:"product_platform_code" form:"product_platform_code" label:"处方平台编码"` // 处方平台商品编码
|
||||
ProductPharmacyCode string `json:"product_pharmacy_code" form:"product_pharmacy_code" label:"药店编码"` // 第三方药店商品编码
|
||||
PharmacyId string `json:"pharmacy_id" form:"pharmacy_id" label:"所属药房ID"` // 所属药房ID
|
||||
PharmacyCode string `json:"pharmacy_code" form:"pharmacy_code" label:"所属药房编码"` // 所属药房编码
|
||||
LicenseNumber string `json:"license_number" form:"license_number" label:"批准文号"` // 批准文号
|
||||
Manufacturer string `json:"manufacturer" form:"manufacturer" label:"生产厂家"` // 生产厂家
|
||||
ProductRemarks string `json:"product_remarks" form:"product_remarks" label:"商品备注"` // 商品备注
|
||||
@@ -63,6 +67,8 @@ type GetProductList struct {
|
||||
ProductPlatformId string `json:"product_platform_id" form:"product_platform_id" label:"平台商品id"` // 处方平台商品id
|
||||
ProductPlatformCode string `json:"product_platform_code" form:"product_platform_code" label:"处方平台编码"` // 处方平台商品编码
|
||||
ProductPharmacyCode string `json:"product_pharmacy_code" form:"product_pharmacy_code" label:"药店编码"` // 第三方药店商品编码
|
||||
PharmacyId string `json:"pharmacy_id" form:"pharmacy_id" label:"所属药房ID"` // 所属药房ID
|
||||
PharmacyCode string `json:"pharmacy_code" form:"pharmacy_code" label:"所属药房编码"` // 所属药房编码
|
||||
LicenseNumber string `json:"license_number" form:"license_number" label:"批准文号"` // 批准文号
|
||||
Manufacturer string `json:"manufacturer" form:"manufacturer" label:"生产厂家"` // 生产厂家
|
||||
ProductRemarks string `json:"product_remarks" form:"product_remarks" label:"商品备注"` // 商品备注
|
||||
@@ -85,6 +91,8 @@ type AddProduct struct {
|
||||
IsMajing *int `json:"is_majing" form:"is_majing" label:"是否麻精药品"` // 是否麻精药品(0:否 1:是)
|
||||
ProductPlatformCode string `json:"product_platform_code" form:"product_platform_code" label:"处方平台商品编码" validate:"required"` // 处方平台商品编码
|
||||
ProductPharmacyCode string `json:"product_pharmacy_code" form:"product_pharmacy_code" label:"第三方药店商品编码" validate:"required"` // 第三方药店商品编码
|
||||
PharmacyId string `json:"pharmacy_id" form:"pharmacy_id" label:"所属药房ID"` // 所属药房ID
|
||||
PharmacyCode string `json:"pharmacy_code" form:"pharmacy_code" label:"所属药房编码"` // 所属药房编码
|
||||
ProductCoverImg string `json:"product_cover_img" form:"product_cover_img" label:"商品封面图"` // 商品封面图
|
||||
ProductSpec string `json:"product_spec" form:"product_spec" label:"商品规格" validate:"required"` // 商品规格
|
||||
LicenseNumber string `json:"license_number" form:"license_number" label:"批准文号" validate:"required"` // 批准文号
|
||||
@@ -128,6 +136,8 @@ type ProductExportList struct {
|
||||
ProductPlatformId string `json:"product_platform_id" form:"product_platform_id" label:"平台商品id"` // 处方平台商品id
|
||||
ProductPlatformCode string `json:"product_platform_code" form:"product_platform_code" label:"处方平台编码"` // 处方平台商品编码
|
||||
ProductPharmacyCode string `json:"product_pharmacy_code" form:"product_pharmacy_code" label:"药店编码"` // 第三方药店商品编码
|
||||
PharmacyId string `json:"pharmacy_id" form:"pharmacy_id" label:"所属药房ID"` // 所属药房ID
|
||||
PharmacyCode string `json:"pharmacy_code" form:"pharmacy_code" label:"所属药房编码"` // 所属药房编码
|
||||
LicenseNumber string `json:"license_number" form:"license_number" label:"批准文号"` // 批准文号
|
||||
Manufacturer string `json:"manufacturer" form:"manufacturer" label:"生产厂家"` // 生产厂家
|
||||
ProductRemarks string `json:"product_remarks" form:"product_remarks" label:"商品备注"` // 商品备注
|
||||
|
||||
@@ -375,6 +375,8 @@ type ProductData struct {
|
||||
FrequencyUse string // 使用频率(例:1天3次)
|
||||
AvailableDays float64 // 可用天数(3)
|
||||
ProductRemarks string // 商品备注
|
||||
PharmacyName string // 所属药房
|
||||
PharmacyCode string // 所属药房编码
|
||||
CreatedAt string // 创建时间
|
||||
}
|
||||
|
||||
@@ -1974,11 +1976,22 @@ func (r *ExportService) Product(d []*model.Product) (string, error) {
|
||||
{Value: "使用频率(例:1天3次)", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "可用天数(3)", CellType: "float64", NumberFmt: "0.0000", ColWidth: 18},
|
||||
{Value: "商品备注", CellType: "string", NumberFmt: "", ColWidth: 40},
|
||||
{Value: "所属药房", CellType: "string", NumberFmt: "", ColWidth: 30},
|
||||
{Value: "所属药房编码", CellType: "string", NumberFmt: "", ColWidth: 30},
|
||||
{Value: "创建时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30},
|
||||
}
|
||||
|
||||
var dataSlice []interface{}
|
||||
for _, v := range d {
|
||||
pharmacyName := ""
|
||||
pharmacyCode := v.PharmacyCode
|
||||
if v.Pharmacy != nil {
|
||||
pharmacyName = v.Pharmacy.PharmacyName
|
||||
if pharmacyCode == "" {
|
||||
pharmacyCode = v.Pharmacy.PharmacyCode
|
||||
}
|
||||
}
|
||||
|
||||
data := ProductData{
|
||||
ProductName: v.ProductName,
|
||||
CommonName: v.CommonName,
|
||||
@@ -2000,6 +2013,8 @@ func (r *ExportService) Product(d []*model.Product) (string, error) {
|
||||
FrequencyUse: v.FrequencyUse,
|
||||
AvailableDays: v.AvailableDays,
|
||||
ProductRemarks: v.ProductRemarks,
|
||||
PharmacyName: pharmacyName,
|
||||
PharmacyCode: pharmacyCode,
|
||||
}
|
||||
|
||||
if v.ProductPlatformAmount != nil {
|
||||
|
||||
+41
-2
@@ -94,16 +94,53 @@ func (r *ProductService) AddProduct(userId string, req requests.AddProduct) (boo
|
||||
return false, errors.New("平台商品不存在")
|
||||
}
|
||||
|
||||
// 检测商品是否重复
|
||||
// 确定所属药房信息
|
||||
pharmacyDao := dao.PharmacyDao{}
|
||||
var pharmacyId int64 = 0
|
||||
var pharmacyCode string = ""
|
||||
|
||||
if req.PharmacyId != "" {
|
||||
pId, err := strconv.ParseInt(req.PharmacyId, 10, 64)
|
||||
if err == nil && pId >= 0 {
|
||||
pharmacyId = pId
|
||||
pharmacy, _ := pharmacyDao.GetPharmacyById(pharmacyId)
|
||||
if pharmacy != nil {
|
||||
pharmacyCode = pharmacy.PharmacyCode
|
||||
}
|
||||
}
|
||||
} else if req.PharmacyCode != "" {
|
||||
pharmacyCode = req.PharmacyCode
|
||||
pharmacy, _ := pharmacyDao.GetPharmacyByCode(pharmacyCode)
|
||||
if pharmacy != nil {
|
||||
pharmacyId = pharmacy.PharmacyId
|
||||
}
|
||||
} else if productPlatform.PharmacyCode != "" {
|
||||
pharmacyCode = productPlatform.PharmacyCode
|
||||
pharmacy, _ := pharmacyDao.GetPharmacyByCode(pharmacyCode)
|
||||
if pharmacy != nil {
|
||||
pharmacyId = pharmacy.PharmacyId
|
||||
}
|
||||
}
|
||||
|
||||
// 若仍无编码,查询对应药房编码(如默认药房 0)
|
||||
if pharmacyCode == "" {
|
||||
pharmacy, _ := pharmacyDao.GetPharmacyById(pharmacyId)
|
||||
if pharmacy != nil {
|
||||
pharmacyCode = pharmacy.PharmacyCode
|
||||
}
|
||||
}
|
||||
|
||||
// 检测同一药房下商品是否重复
|
||||
maps := make(map[string]interface{})
|
||||
maps["product_platform_id"] = req.ProductPlatformId
|
||||
maps["pharmacy_id"] = pharmacyId
|
||||
products, err := productDao.GetProductList(maps)
|
||||
if err != nil {
|
||||
return false, errors.New("商品重复添加")
|
||||
}
|
||||
|
||||
if len(products) != 0 {
|
||||
return false, errors.New("商品重复添加")
|
||||
return false, errors.New("该药房已添加此商品,请勿重复添加")
|
||||
}
|
||||
|
||||
// 处理图片
|
||||
@@ -120,6 +157,8 @@ func (r *ProductService) AddProduct(userId string, req requests.AddProduct) (boo
|
||||
// 新增商品表
|
||||
product := &model.Product{
|
||||
ProductPlatformId: productPlatform.ProductPlatformId,
|
||||
PharmacyId: pharmacyId,
|
||||
PharmacyCode: pharmacyCode,
|
||||
ProductStatus: *req.ProductStatus,
|
||||
ProductName: req.ProductName,
|
||||
CommonName: req.CommonName,
|
||||
|
||||
Reference in New Issue
Block a user