func UpdateSupplierRels(product string, suppliers []string) string { beego.Debug("UpdateSupplierRels:", product, " ", suppliers) query := `SELECT * FROM supplier_product WHERE product = ?` st, vs := wbo.DbQueryValues(query, product) if st != stat.Success { return st } oldRelMaps := make(map[string]map[string]interface{}) for _, v := range vs { supplier, _ := v[s.Supplier] beego.Debug("UpdateSupplierRels oldRels:", supplier) oldRelMaps[supplier.(string)] = v } for _, supplier := range suppliers { if _, ok := oldRelMaps[supplier]; ok { delete(oldRelMaps, supplier) } else { // 新增 beego.Debug("UpdateSupplierRels", t.Params{s.Supplier: supplier, s.Product: product}) svc.Add("supplier_product", t.Params{s.Supplier: supplier, s.Product: product}) } } for _, oldRel := range oldRelMaps { if sn, ok := oldRel[s.Sn]; ok { DelSupplierRel(sn.(string)) } } return stat.Success }
func GetAll(item string) (string, []map[string]interface{}) { sql := `SELECT * FROM ` + item return wbo.DbQueryValues(sql) }
func GetSupplierListByProductSn(sn string) (string, []map[string]interface{}) { query := `select supplier.* from supplier as supplier, supplier_product as rel WHERE supplier.sn = rel.supplier AND rel.product = ?` return wbo.DbQueryValues(query, sn) }