예제 #1
0
func ListPersonByIdSet(ids ...int64) (map[int64]*model.Person, error) {
	if nil == ids || len(ids) == 0 {
		return nil, nil
	}
	var query *db.QueryParser
	parser := em.Select().Where()
	query = parser.InInt64(em.PK, ids...).OrderBy(em.PK, db.DESC)

	models := make([]*model.Person, 0)
	if err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			p := new(model.Person)
			err := rows.Scan(
				&p.Id, &p.Name, &p.Type, &p.Phone, &p.City, &p.Address, &p.PostalCode, &p.QQ,
				&p.Website, &p.Note, &p.AccountBallance, &p.CreateTime, &p.UpdateTime,
			)
			models = append(models, p)
			return true, err
		},
	); err != nil {
		return nil, err
	}
	// return the map
	var resultmap = map[int64]*model.Person{}
	for _, u := range models {
		resultmap[int64(u.Id)] = u
	}
	return resultmap, nil
}
예제 #2
0
// the last part, read the list from rows
func _list(query *db.QueryParser) ([]*model.Const, error) {
	models := make([]*model.Const, 0)
	if err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			m := &model.Const{}
			err := rows.Scan(&m.Id, &m.Name, &m.Key, &m.Value, &m.FloatValue, &m.Time)
			models = append(models, m)
			return true, err
		},
	); err != nil {
		return nil, err
	}
	return models, nil
}
예제 #3
0
// list_incoming is an common function that accept a query and query a list of result, and error.
func list_incoming(query *db.QueryParser) ([]*model.AccountIncoming, error) {
	incomings := make([]*model.AccountIncoming, 0)
	err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			p := new(model.AccountIncoming)
			err := rows.Scan(&p.Id, &p.CustomeId, &p.Incoming, &p.Time)
			incomings = append(incomings, p)
			return true, err
		},
	)
	if err != nil {
		return nil, err
	}
	return incomings, nil
}
예제 #4
0
// only return the first result;
func _one(query *db.QueryParser) (*model.Person, error) {
	m := &model.Person{}
	if err := query.Query( // TODO: change to QueryOne
		func(rows *sql.Rows) (bool, error) {
			err := rows.Scan(
				&m.Id, &m.Name, &m.Type, &m.Phone, &m.City, &m.Address, &m.PostalCode, &m.QQ,
				&m.Website, &m.Note, &m.AccountBallance, &m.CreateTime, &m.UpdateTime,
			)
			return false, err // don't fetch the second line. first is enough;
		},
	); err != nil {
		return nil, err
	}
	return m, nil
}
예제 #5
0
// the last part, read the list from rows
func _listUserAction(query *db.QueryParser) ([]*model.UserAction, error) {
	models := make([]*model.UserAction, 0)
	if err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			m := &model.UserAction{}
			err := rows.Scan(
				&m.Id, &m.UserId, &m.Action, &m.Context, &m.CreateTime,
			)
			models = append(models, m)
			return true, err
		},
	); err != nil {
		return nil, err
	}
	return models, nil
}
예제 #6
0
// the last part, read the list from rows
func _list(query *db.QueryParser) ([]*model.Person, error) {
	models := make([]*model.Person, 0)
	if err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			m := &model.Person{}
			err := rows.Scan(
				&m.Id, &m.Name, &m.Type, &m.Phone, &m.City, &m.Address, &m.PostalCode, &m.QQ,
				&m.Website, &m.Note, &m.AccountBallance, &m.CreateTime, &m.UpdateTime,
			)
			models = append(models, m)
			return true, err
		},
	); err != nil {
		return nil, err
	}
	return models, nil
}
예제 #7
0
func _list(query *db.QueryParser) ([]*model.Product, error) {
	models := make([]*model.Product, 0)
	if err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			m := &model.Product{}
			err := rows.Scan(
				&m.Id, &m.Name, &m.ProductId, &m.Status, &m.Brand, &m.Price, &m.Supplier, &m.FactoryPrice,
				&m.Stock, &m.ShelfNo, &m.Capital, &m.Note, &m.Pictures, &m.CreateTime, &m.UpdateTime,
			)
			models = append(models, m)
			return true, err
		},
	); err != nil {
		return nil, err
	}
	return models, nil
}
예제 #8
0
func _list(query *db.QueryParser) ([]*model.User, error) {
	models := make([]*model.User, 0)
	if err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			p := &model.User{}
			err := rows.Scan(
				&p.Id, &p.Username, &p.Password, &p.Gender, &p.QQ, &p.Mobile, &p.City, &p.Role,
				&p.Store, &p.CreateTime, &p.UpdateTime,
			)
			models = append(models, p)
			return true, err
		},
	); err != nil {
		return nil, err
	}
	return models, nil
}
예제 #9
0
// the last part, read the list from rows
func _list(query *db.QueryParser) ([]*model.FactorySettleAccount, error) {
	models := make([]*model.FactorySettleAccount, 0)
	if err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			m := &model.FactorySettleAccount{}
			err := rows.Scan(
				&m.Id, &m.FactoryId, &m.GoodsDescription, &m.FromTime, &m.SettleTime,
				&m.ShouldPay, &m.Paid, &m.Note, &m.Operator,
			)
			models = append(models, m)
			return true, err
		},
	); err != nil {
		return nil, err
	}
	return models, nil
}
예제 #10
0
// the last part, read the list from rows
func _list(query *db.QueryParser) ([]*model.InventoryTrackItem, error) {
	models := make([]*model.InventoryTrackItem, 0)
	if err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			m := &model.InventoryTrackItem{}
			err := rows.Scan(
				&m.Id, &m.ProductId, &m.Color, &m.Size, &m.StockChagneTo, &m.OldStock, &m.Delta,
				&m.UserId, &m.UserId, &m.Reason, &m.Context, &m.Time,
			)
			models = append(models, m)
			return true, err
		},
	); err != nil {
		return nil, err
	}
	return models, nil
}
예제 #11
0
func _one(query *db.QueryParser) (*model.Product, error) {
	m := new(model.Product)
	err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			return false, rows.Scan(
				&m.Id, &m.Name, &m.ProductId, &m.Status, &m.Brand, &m.Price, &m.Supplier, &m.FactoryPrice,
				&m.Stock, &m.ShelfNo, &m.Capital, &m.Note, &m.Pictures, &m.CreateTime, &m.UpdateTime,
			)
		},
	)
	if err != nil {
		return nil, err
	}
	if m.Id > 0 {
		return m, nil
	}
	return nil, nil
}
예제 #12
0
// the last part, read the list from rows
func _list(query *db.QueryParser) ([]*model.InventoryGroup, error) {
	models := make([]*model.InventoryGroup, 0)
	if err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			m := &model.InventoryGroup{}
			err := rows.Scan(
				&m.Id, &m.Status, &m.Type, &m.Note, &m.ProviderId, &m.OperatorId,
				&m.Summary, &m.TotalQuantity, &m.SendTime, &m.ReceiveTime, &m.CreateTime, &m.UpdateTime,
			)
			models = append(models, m)
			return true, err
		},
	); err != nil {
		return nil, err
	}

	return models, nil
}
예제 #13
0
func _one(query *db.QueryParser) (*model.InventoryGroup, error) {
	m := new(model.InventoryGroup)
	err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			return false, rows.Scan(
				&m.Id, &m.Status, &m.Type, &m.Note, &m.ProviderId, &m.OperatorId,
				&m.Summary, &m.TotalQuantity, &m.SendTime, &m.ReceiveTime, &m.CreateTime, &m.UpdateTime,
			)
		},
	)
	if err != nil {
		return nil, err
	}
	if m.Id > 0 {
		return m, nil
	}
	return nil, nil
}
예제 #14
0
// list_incoming is an common function that accept a query and query a list of result, and error.
func list_account_changelog(query *db.QueryParser) ([]*model.AccountChangeLog, error) {
	changeLogs := make([]*model.AccountChangeLog, 0)
	err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			p := new(model.AccountChangeLog)
			err := rows.Scan(
				&p.Id, &p.CustomerId, &p.Delta, &p.Account, &p.Type,
				&p.RelatedOrderTN, &p.Reason, &p.Time,
			)
			changeLogs = append(changeLogs, p)
			return true, err
		},
	)
	if err != nil {
		return nil, err
	}
	return changeLogs, nil
}
예제 #15
0
func _one(query *db.QueryParser) (*model.User, error) {
	p := new(model.User)
	err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			return false, rows.Scan(
				&p.Id, &p.Username, &p.Password, &p.Gender, &p.QQ, &p.Mobile, &p.City, &p.Role,
				&p.Store, &p.CreateTime, &p.UpdateTime,
			)
		},
	)
	if err != nil {
		return nil, err
	}
	if p.Id > 0 {
		return p, nil
	}
	return nil, nil
}
예제 #16
0
func _listOrder(query *db.QueryParser) ([]*model.Order, error) {
	orders := make([]*model.Order, 0)
	if err := query.Query(
		func(rows *sql.Rows) (bool, error) {
			p := new(model.Order)
			err := rows.Scan(
				&p.Id, &p.TrackNumber, &p.Status, &p.Type, &p.CustomerId,
				&p.DeliveryMethod, &p.DeliveryTrackingNumber, &p.ExpressFee, &p.ShippingAddress,
				&p.TotalPrice, &p.TotalCount, &p.PriceCut, &p.Accumulated,
				&p.Note, &p.ParentTrackNumber,
				&p.CreateTime, &p.UpdateTime, &p.CloseTime,
			)
			orders = append(orders, p)
			return true, err
		},
	); err != nil {
		return nil, err
	}
	return orders, nil
}