修复部分bug,增加DB SUM函数,以及优化IN性能,增加分析接口
This commit is contained in:
parent
8337cdec0c
commit
8cac1f5393
@ -8,10 +8,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
//hotime的常用map
|
// hotime的常用map
|
||||||
type Map map[string]interface{}
|
type Map map[string]interface{}
|
||||||
|
|
||||||
//获取string
|
// 获取string
|
||||||
func (that Map) GetString(key string, err ...*Error) string {
|
func (that Map) GetString(key string, err ...*Error) string {
|
||||||
|
|
||||||
if len(err) != 0 {
|
if len(err) != 0 {
|
||||||
@ -26,7 +26,7 @@ func (that *Map) Pointer() *Map {
|
|||||||
return that
|
return that
|
||||||
}
|
}
|
||||||
|
|
||||||
//增加接口
|
// 增加接口
|
||||||
func (that Map) Put(key string, value interface{}) {
|
func (that Map) Put(key string, value interface{}) {
|
||||||
//if that==nil{
|
//if that==nil{
|
||||||
// that=Map{}
|
// that=Map{}
|
||||||
@ -34,13 +34,13 @@ func (that Map) Put(key string, value interface{}) {
|
|||||||
that[key] = value
|
that[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除接口
|
// 删除接口
|
||||||
func (that Map) Delete(key string) {
|
func (that Map) Delete(key string) {
|
||||||
delete(that, key)
|
delete(that, key)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取Int
|
// 获取Int
|
||||||
func (that Map) GetInt(key string, err ...*Error) int {
|
func (that Map) GetInt(key string, err ...*Error) int {
|
||||||
v := ObjToInt((that)[key], err...)
|
v := ObjToInt((that)[key], err...)
|
||||||
|
|
||||||
@ -48,35 +48,35 @@ func (that Map) GetInt(key string, err ...*Error) int {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取Int
|
// 获取Int
|
||||||
func (that Map) GetInt64(key string, err ...*Error) int64 {
|
func (that Map) GetInt64(key string, err ...*Error) int64 {
|
||||||
v := ObjToInt64((that)[key], err...)
|
v := ObjToInt64((that)[key], err...)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取向上取整Int64
|
// 获取向上取整Int64
|
||||||
func (that Map) GetCeilInt64(key string, err ...*Error) int64 {
|
func (that Map) GetCeilInt64(key string, err ...*Error) int64 {
|
||||||
v := ObjToCeilInt64((that)[key], err...)
|
v := ObjToCeilInt64((that)[key], err...)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取向上取整Int
|
// 获取向上取整Int
|
||||||
func (that Map) GetCeilInt(key string, err ...*Error) int {
|
func (that Map) GetCeilInt(key string, err ...*Error) int {
|
||||||
v := ObjToCeilInt((that)[key], err...)
|
v := ObjToCeilInt((that)[key], err...)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取向上取整float64
|
// 获取向上取整float64
|
||||||
func (that Map) GetCeilFloat64(key string, err ...*Error) float64 {
|
func (that Map) GetCeilFloat64(key string, err ...*Error) float64 {
|
||||||
v := ObjToCeilFloat64((that)[key], err...)
|
v := ObjToCeilFloat64((that)[key], err...)
|
||||||
return v
|
return v
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取Float64
|
// 获取Float64
|
||||||
func (that Map) GetFloat64(key string, err ...*Error) float64 {
|
func (that Map) GetFloat64(key string, err ...*Error) float64 {
|
||||||
|
|
||||||
v := ObjToFloat64((that)[key], err...)
|
v := ObjToFloat64((that)[key], err...)
|
||||||
@ -102,7 +102,7 @@ func (that Map) GetBool(key string, err ...*Error) bool {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that Map) GetTime(key string, err ...*Error) time.Time {
|
func (that Map) GetTime(key string, err ...*Error) *time.Time {
|
||||||
|
|
||||||
v := ObjToTime((that)[key], err...)
|
v := ObjToTime((that)[key], err...)
|
||||||
return v
|
return v
|
||||||
@ -149,7 +149,7 @@ func (that Map) Get(key string, err ...*Error) interface{} {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//请传递指针过来
|
// 请传递指针过来
|
||||||
func (that Map) ToStruct(stct interface{}) {
|
func (that Map) ToStruct(stct interface{}) {
|
||||||
|
|
||||||
data := reflect.ValueOf(stct).Elem()
|
data := reflect.ValueOf(stct).Elem()
|
||||||
|
@ -2,7 +2,7 @@ package common
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
//对象封装方便取用
|
// 对象封装方便取用
|
||||||
type Obj struct {
|
type Obj struct {
|
||||||
Data interface{}
|
Data interface{}
|
||||||
Error
|
Error
|
||||||
@ -20,7 +20,7 @@ func (that *Obj) ToInt(err ...Error) int {
|
|||||||
return ObjToInt(that.Data, &that.Error)
|
return ObjToInt(that.Data, &that.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that *Obj) ToTime(err ...Error) time.Time {
|
func (that *Obj) ToTime(err ...Error) *time.Time {
|
||||||
if len(err) != 0 {
|
if len(err) != 0 {
|
||||||
that.Error = err[0]
|
that.Error = err[0]
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ func (that *Obj) ToObj() interface{} {
|
|||||||
return that.Data
|
return that.Data
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取向上取整Int64
|
// 获取向上取整Int64
|
||||||
func (that *Obj) ToCeilInt64(err ...*Error) int64 {
|
func (that *Obj) ToCeilInt64(err ...*Error) int64 {
|
||||||
if len(err) != 0 {
|
if len(err) != 0 {
|
||||||
that.Error = *err[0]
|
that.Error = *err[0]
|
||||||
@ -92,7 +92,7 @@ func (that *Obj) ToCeilInt64(err ...*Error) int64 {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取向上取整Int
|
// 获取向上取整Int
|
||||||
func (that *Obj) ToCeilInt(err ...*Error) int {
|
func (that *Obj) ToCeilInt(err ...*Error) int {
|
||||||
if len(err) != 0 {
|
if len(err) != 0 {
|
||||||
that.Error = *err[0]
|
that.Error = *err[0]
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
//仅限于hotime.Slice
|
// 仅限于hotime.Slice
|
||||||
func ObjToMap(obj interface{}, e ...*Error) Map {
|
func ObjToMap(obj interface{}, e ...*Error) Map {
|
||||||
var err error
|
var err error
|
||||||
var v Map
|
var v Map
|
||||||
@ -60,7 +60,7 @@ func ObjToMapArray(obj interface{}, e ...*Error) []Map {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
//仅限于hotime.Slice
|
// 仅限于hotime.Slice
|
||||||
func ObjToSlice(obj interface{}, e ...*Error) Slice {
|
func ObjToSlice(obj interface{}, e ...*Error) Slice {
|
||||||
var err error
|
var err error
|
||||||
var v Slice
|
var v Slice
|
||||||
@ -98,7 +98,7 @@ func ObjToSlice(obj interface{}, e ...*Error) Slice {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
func ObjToTime(obj interface{}, e ...*Error) time.Time {
|
func ObjToTime(obj interface{}, e ...*Error) *time.Time {
|
||||||
|
|
||||||
tInt := ObjToInt64(obj)
|
tInt := ObjToInt64(obj)
|
||||||
//字符串类型,只支持标准mysql datetime格式
|
//字符串类型,只支持标准mysql datetime格式
|
||||||
@ -123,27 +123,27 @@ func ObjToTime(obj interface{}, e ...*Error) time.Time {
|
|||||||
if len(tStr) > 18 {
|
if len(tStr) > 18 {
|
||||||
t, e := time.Parse("2006-01-02 15:04:05", tStr)
|
t, e := time.Parse("2006-01-02 15:04:05", tStr)
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return t
|
return &t
|
||||||
}
|
}
|
||||||
} else if len(tStr) > 15 {
|
} else if len(tStr) > 15 {
|
||||||
t, e := time.Parse("2006-01-02 15:04", tStr)
|
t, e := time.Parse("2006-01-02 15:04", tStr)
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return t
|
return &t
|
||||||
}
|
}
|
||||||
} else if len(tStr) > 12 {
|
} else if len(tStr) > 12 {
|
||||||
t, e := time.Parse("2006-01-02 15", tStr)
|
t, e := time.Parse("2006-01-02 15", tStr)
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return t
|
return &t
|
||||||
}
|
}
|
||||||
} else if len(tStr) > 9 {
|
} else if len(tStr) > 9 {
|
||||||
t, e := time.Parse("2006-01-02", tStr)
|
t, e := time.Parse("2006-01-02", tStr)
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return t
|
return &t
|
||||||
}
|
}
|
||||||
} else if len(tStr) > 6 {
|
} else if len(tStr) > 6 {
|
||||||
t, e := time.Parse("2006-01", tStr)
|
t, e := time.Parse("2006-01", tStr)
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return t
|
return &t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,28 +151,32 @@ func ObjToTime(obj interface{}, e ...*Error) time.Time {
|
|||||||
|
|
||||||
//纳秒级别
|
//纳秒级别
|
||||||
if len(ObjToStr(tInt)) > 16 {
|
if len(ObjToStr(tInt)) > 16 {
|
||||||
t := time.Time{}.Add(time.Nanosecond * time.Duration(tInt))
|
//t := time.Time{}.Add(time.Nanosecond * time.Duration(tInt))
|
||||||
return t
|
t := time.UnixMicro(tInt / 1000)
|
||||||
|
return &t
|
||||||
//微秒级别
|
//微秒级别
|
||||||
} else if len(ObjToStr(tInt)) > 13 {
|
} else if len(ObjToStr(tInt)) > 13 {
|
||||||
t := time.Time{}.Add(time.Microsecond * time.Duration(tInt))
|
//t := time.Time{}.Add(time.Microsecond * time.Duration(tInt))
|
||||||
return t
|
t := time.UnixMicro(tInt)
|
||||||
|
return &t
|
||||||
//毫秒级别
|
//毫秒级别
|
||||||
} else if len(ObjToStr(tInt)) > 10 {
|
} else if len(ObjToStr(tInt)) > 10 {
|
||||||
t := time.Time{}.Add(time.Millisecond * time.Duration(tInt))
|
//t := time.Time{}.Add(time.Millisecond * time.Duration(tInt))
|
||||||
return t
|
t := time.UnixMilli(tInt)
|
||||||
|
return &t
|
||||||
//秒级别
|
//秒级别
|
||||||
} else if len(ObjToStr(tInt)) > 9 {
|
} else if len(ObjToStr(tInt)) > 9 {
|
||||||
t := time.Time{}.Add(time.Second * time.Duration(tInt))
|
//t := time.Time{}.Add(time.Second * time.Duration(tInt))
|
||||||
return t
|
t := time.Unix(tInt, 0)
|
||||||
|
return &t
|
||||||
} else if len(ObjToStr(tInt)) > 3 {
|
} else if len(ObjToStr(tInt)) > 3 {
|
||||||
t, e := time.Parse("2006", ObjToStr(tInt))
|
t, e := time.Parse("2006", ObjToStr(tInt))
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return t
|
return &t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return time.Time{}
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ObjToFloat64(obj interface{}, e ...*Error) float64 {
|
func ObjToFloat64(obj interface{}, e ...*Error) float64 {
|
||||||
@ -230,21 +234,21 @@ func ObjToFloat64(obj interface{}, e ...*Error) float64 {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
//向上取整
|
// 向上取整
|
||||||
func ObjToCeilInt64(obj interface{}, e ...*Error) int64 {
|
func ObjToCeilInt64(obj interface{}, e ...*Error) int64 {
|
||||||
f := ObjToCeilFloat64(obj, e...)
|
f := ObjToCeilFloat64(obj, e...)
|
||||||
return ObjToInt64(math.Ceil(f))
|
return ObjToInt64(math.Ceil(f))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//向上取整
|
// 向上取整
|
||||||
func ObjToCeilFloat64(obj interface{}, e ...*Error) float64 {
|
func ObjToCeilFloat64(obj interface{}, e ...*Error) float64 {
|
||||||
f := ObjToFloat64(obj, e...)
|
f := ObjToFloat64(obj, e...)
|
||||||
return math.Ceil(f)
|
return math.Ceil(f)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//向上取整
|
// 向上取整
|
||||||
func ObjToCeilInt(obj interface{}, e ...*Error) int {
|
func ObjToCeilInt(obj interface{}, e ...*Error) int {
|
||||||
f := ObjToCeilFloat64(obj, e...)
|
f := ObjToCeilFloat64(obj, e...)
|
||||||
return ObjToInt(f)
|
return ObjToInt(f)
|
||||||
@ -356,7 +360,7 @@ func ObjToStr(obj interface{}) string {
|
|||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
//转换为Map
|
// 转换为Map
|
||||||
func StrToMap(string string) Map {
|
func StrToMap(string string) Map {
|
||||||
data := Map{}
|
data := Map{}
|
||||||
data.JsonToMap(string)
|
data.JsonToMap(string)
|
||||||
@ -364,7 +368,7 @@ func StrToMap(string string) Map {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
//转换为Slice
|
// 转换为Slice
|
||||||
func StrToSlice(string string) Slice {
|
func StrToSlice(string string) Slice {
|
||||||
|
|
||||||
data := ObjToSlice(string)
|
data := ObjToSlice(string)
|
||||||
@ -372,7 +376,7 @@ func StrToSlice(string string) Slice {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
//字符串数组: a1,a2,a3转["a1","a2","a3"]
|
// 字符串数组: a1,a2,a3转["a1","a2","a3"]
|
||||||
func StrArrayToJsonStr(a string) string {
|
func StrArrayToJsonStr(a string) string {
|
||||||
|
|
||||||
if len(a) > 2 {
|
if len(a) > 2 {
|
||||||
@ -390,7 +394,7 @@ func StrArrayToJsonStr(a string) string {
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
//字符串数组: a1,a2,a3转["a1","a2","a3"]
|
// 字符串数组: a1,a2,a3转["a1","a2","a3"]
|
||||||
func JsonStrToStrArray(a string) string {
|
func JsonStrToStrArray(a string) string {
|
||||||
//a = strings.Replace(a, `"`, "", -1)
|
//a = strings.Replace(a, `"`, "", -1)
|
||||||
if len(a) != 0 {
|
if len(a) != 0 {
|
||||||
@ -400,7 +404,7 @@ func JsonStrToStrArray(a string) string {
|
|||||||
return "," + a + ","
|
return "," + a + ","
|
||||||
}
|
}
|
||||||
|
|
||||||
//字符串转int
|
// 字符串转int
|
||||||
func StrToInt(s string) (int, error) {
|
func StrToInt(s string) (int, error) {
|
||||||
i, err := strconv.Atoi(s)
|
i, err := strconv.Atoi(s)
|
||||||
return i, err
|
return i, err
|
||||||
|
@ -15,7 +15,7 @@ func (that Slice) GetString(key int, err ...*Error) string {
|
|||||||
return ObjToStr((that)[key])
|
return ObjToStr((that)[key])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (that Slice) GetTime(key int, err ...*Error) time.Time {
|
func (that Slice) GetTime(key int, err ...*Error) *time.Time {
|
||||||
|
|
||||||
v := ObjToTime((that)[key], err...)
|
v := ObjToTime((that)[key], err...)
|
||||||
return v
|
return v
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user