Esempio n. 1
0
func (s *SendNewProductService) GetNewProductIds(n int) []int64 {
	query := productdao.EntityManager().Select("id").OrderBy("CreateTime", db.DESC).Limit(10)

	var results = []int64{}
	var value int64
	err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			if err2 := rows.Scan(&value); err2 != nil {
				panic(err2) // TODO a better way to solve this?
			}
			results = append(results, value)
			return true, nil
		},
	)
	if err != nil {
		panic(err)
	}
	return results
}
Esempio n. 2
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.")
}
Esempio n. 3
0
func (s *ProductService) EntityManager() *db.Entity {
	return productdao.EntityManager()
}