苏州瑞玛APS项目web后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB

  1. package grmi
  2. import (
  3. "strings"
  4. )
  5. type Condition struct {
  6. *Paging
  7. Items map[string]ConditionItem
  8. OrderByFields []Field
  9. }
  10. func NewCondition(items map[string]ConditionItem, paging *Paging) Condition {
  11. orderByFields := make([]Field, 0, 10)
  12. conditionItems := make(map[string]ConditionItem, 0)
  13. for key, item := range items {
  14. if item.OrderBy {
  15. orderByFields = append(orderByFields, item.Field)
  16. }
  17. valueParser, ok := valueParsers[item.Field.GoType]
  18. if ok {
  19. item.valueParser = valueParser
  20. conditionItems[key] = item
  21. }
  22. }
  23. return Condition{Items: conditionItems, Paging: paging, OrderByFields: orderByFields}
  24. }
  25. func (self *Condition) BuildPredicates(urlParameters map[string]string) ([]Predicate, error) {
  26. predicates := make([]Predicate, 0, len(urlParameters))
  27. for name, value := range urlParameters {
  28. item, ok := self.Items[strings.ToLower(name)]
  29. if !ok {
  30. continue
  31. }
  32. predicateValue, err := item.valueParser(value)
  33. if err != nil {
  34. return nil, NewRequestError(err)
  35. }
  36. predicates = append(predicates, item.NewPredicate(item.PredicateType, predicateValue))
  37. }
  38. return predicates, nil
  39. }