示例#1
0
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.")
}
示例#2
0
func ListFactory() ([]*model.Person, error) {
	return persondao.ListAll("customer")
}
示例#3
0
// return list of person
func (s *PersonService) GetPersons(t person.Type) ([]*model.Person, error) {
	return persondao.ListAll(string(t))
}
示例#4
0
func List(personType string) ([]*model.Person, error) {
	return persondao.ListAll(personType)
}