-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.go
75 lines (66 loc) · 1.56 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"strings"
"time"
"unicode"
"github.com/shopspring/decimal"
)
const (
SEARCH_DATE = iota
SEARCH_PROVIDER
SEARCH_CUSTOMER
)
type SearchCondition struct {
// SearchField int `json:"searchField"`
SearchKeys []string `json:"searchKeys"`
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
SortName string `json:"sortName"`
SortOrder string `json:"sortOrder"` // desc asc
nostatics bool
}
type Response struct {
// TotalNotFiltered int64 `json:"totalNotFiltered"`
Total int `json:"total"`
Rows interface{} `json:"rows"`
Error string
Static interface{}
}
func nextNDate(date string, n int) (nd string, err error) {
t, err := time.Parse(DATE_FORMAT, date)
if err != nil {
return "", err
}
return t.AddDate(0, 0, n).Format(DATE_FORMAT), nil
}
func structFieldName2DBCloumnName(s string) string {
var n strings.Builder
n.WriteRune(unicode.ToLower([]rune(s)[0]))
// log.Println("structFieldName2DBCloumnName", n.String())
for _, r := range s[1:] {
if unicode.IsUpper(r) {
n.WriteRune('_')
n.WriteRune(unicode.ToLower(r))
} else {
n.WriteRune(r)
}
}
// log.Println("structFieldName2DBCloumnName2", n.String())
return n.String()
}
func FloatSum(floats ...float64) float64 {
r := decimal.NewFromFloat(0)
for _, f := range floats {
r = r.Add(decimal.NewFromFloat(f))
}
f, _ := r.Float64()
return f
}
func FloatMul(floats ...float64) float64 {
r := decimal.NewFromFloat(1)
for _, f := range floats {
r = r.Mul(decimal.NewFromFloat(f))
}
f, _ := r.Float64()
return f
}