func (s *ProductService) ListStocks(parser *db.QueryParser) ([]*model.Product, error) { // func FillProductStocksByIdSet(models []*model.Product) error { // if nil == models || len(models) == 0 { // return nil // } // var idset = map[int64]bool{} // for _, m := range models { // idset[int64(m.Id)] = true // } // if allstocks, err := GetAllStocksByIdSet(idset); err != nil { // return err // } else { // if nil != allstocks { // for _, m := range models { // if stock, ok := allstocks[int64(m.Id)]; ok { // m.Stocks = stock // m.Stock = stock.Total() // } // } // } // } // return nil // } if models, err := productdao.List(parser); err != nil { return nil, err } else { if err := inventorydao.FillProductStocksByIdSet(models); err != nil { return nil, err } return models, nil } }
func (s *ProductService) List(parser *db.QueryParser, withs Withs) ([]*model.Product, error) { if models, err := productdao.List(parser); err != nil { return nil, err } else { // TODO: Print warrning information when has unused withs. // fmt.Println("--------------------------------------------------------------------", withs) if withs&WITH_PRODUCT_DETAIL > 0 { if err := productdao.FillProductPropertiesByIdSet(models); err != nil { return nil, err } } if withs&WITH_PRODUCT_INVENTORY > 0 { if err := inventorydao.FillProductStocksByIdSet(models); err != nil { return nil, err } } return models, nil } }
func load() { cache = make(map[string]Items, 100) persons, err := persondao.ListAll("customer") // persons, err := personservice.ListCustomer() if err != nil { panic(err.Error()) } else { debug.Log("[suggest] load %v customers.", len(persons)) personItems := NewItems(len(persons)) for i, person := range persons { personItems[i] = &Item{ Id: person.Id, Text: person.Name, QuickString: parseQuickText(person.Name), Type: "1", } } sort.Sort(personItems) cache[Customer] = personItems } factories, err := persondao.ListAll("factory") // factories, err := personservice.ListFactory() if err != nil { panic(err.Error()) } else { debug.Log("[suggest] load %v factories.", len(factories)) factoryItems := NewItems(len(factories)) for i, factory := range factories { factoryItems[i] = &Item{ Id: factory.Id, Text: factory.Name, QuickString: parseQuickText(factory.Name), // TODO Type: "2", } } sort.Sort(factoryItems) cache[Factory] = factoryItems } // TODO: chagne to step load. parser := productdao.EntityManager().NewQueryParser().Where().Limit(10000) // all limit to 1w products, err := productdao.List(parser) if err != nil { panic(err.Error()) } // products := dal.ListProduct() debug.Log("[suggest] load %v products.", len(products)) productItems := NewItems(len(products)) for i, product := range products { productItems[i] = &Item{ Id: product.Id, SN: product.ProductId, Text: product.Name, QuickString: parseQuickText(product.Name), // TODO Type: "3", } } sort.Sort(productItems) cache[Product] = productItems debug.Log("Loading suggest done. Use 0.00 ms.") }