This commit is contained in:
苏尹岚
2021-01-27 13:36:59 +08:00
parent 0226aab316
commit 8ec5e4f3c6
3 changed files with 68 additions and 10 deletions

View File

@@ -485,3 +485,46 @@ func GetVendorCategoryMap(db *DaoDB, parentID, level, vendorID int, vendorOrgCod
}
return vendorMaps, err
}
type GetVendorCategoryMapExtResult struct {
model.VendorCategoryMap
VendorThingID string `orm:"column(vendor_thing_id)" json:"vendorThingID"`
}
func GetVendorCategoryMapExt(db *DaoDB, parentID, level, vendorID int, vendorOrgCode string, categoryID int) (vendorMaps []*GetVendorCategoryMapExtResult, err error) {
sql := `
SELECT a.*, b.vendor_thing_id
FROM vendor_category_map a
JOIN thing_map b ON b.thing_id = a.category_id AND b.thing_type = ?
WHERE a.deleted_at = ?
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
}
if parentID >= 0 {
sql += " AND a.parent_id = ?"
sqlParams = append(sqlParams, parentID)
}
if level > 0 {
sql += " AND a.level = ?"
sqlParams = append(sqlParams, level)
}
if vendorID != -1 {
sql += " AND a.vendor_id = ?"
sqlParams = append(sqlParams, vendorID)
}
if vendorOrgCode != "" {
sql += " AND a.vendor_org_code = ?"
sqlParams = append(sqlParams, vendorOrgCode)
}
if categoryID > 0 {
sql += " AND a.category_id = ?"
sqlParams = append(sqlParams, categoryID)
}
sql += " ORDER BY a.vendor_category_seq"
err = GetRows(db, &vendorMaps, sql, sqlParams)
if err != nil {
return nil, err
}
return vendorMaps, err
}