处理 GORM 0 的bug
This commit is contained in:
@@ -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