1
This commit is contained in:
parent
cc1a26b982
commit
7c8ec429de
4
app.go
4
app.go
@ -28,11 +28,11 @@ func (this *App_) Init() {
|
|||||||
func (context interface{}) int64 {
|
func (context interface{}) int64 {
|
||||||
return q5.GetTickCount()
|
return q5.GetTickCount()
|
||||||
},
|
},
|
||||||
func (context interface{}, fixedTimierExecuteTimes int32, milliSeconds int32, tick int64) int64 {
|
func (context interface{}, isFirstAdd bool, milliSeconds int32, tick int64) int64 {
|
||||||
nowTime := time.Now().Unix()
|
nowTime := time.Now().Unix()
|
||||||
todayPassedSeconds := nowTime - q5.GetDaySeconds(nowTime)
|
todayPassedSeconds := nowTime - q5.GetDaySeconds(nowTime)
|
||||||
expires := (tick - todayPassedSeconds * 1000) + int64(milliSeconds)
|
expires := (tick - todayPassedSeconds * 1000) + int64(milliSeconds)
|
||||||
if fixedTimierExecuteTimes > 0 {
|
if isFirstAdd {
|
||||||
if expires <= tick {
|
if expires <= tick {
|
||||||
expires += 1000 * 3600 * 24
|
expires += 1000 * 3600 * 24
|
||||||
}
|
}
|
||||||
|
109
metamgr.go
109
metamgr.go
@ -6,6 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"reflect"
|
"reflect"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"q5"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/golang/protobuf/jsonpb"
|
"github.com/golang/protobuf/jsonpb"
|
||||||
@ -18,7 +19,6 @@ type MetaClass struct {
|
|||||||
WrapMeta interface{}
|
WrapMeta interface{}
|
||||||
PrimKey string
|
PrimKey string
|
||||||
SecKey string
|
SecKey string
|
||||||
IsObject bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MetaMgr struct {
|
type MetaMgr struct {
|
||||||
@ -75,51 +75,86 @@ func (this *MetaMgr) loadRawMetaTable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *MetaMgr) bindPrimKey() {
|
func (this *MetaMgr) bindPrimKey() {
|
||||||
for _, val := range *this.metaClasses {
|
bindFunc := func (metaClass *MetaClass, wrapMeta reflect.Value) {
|
||||||
wrapMetaList := reflect.ValueOf(this.wrapList[val.Idx])
|
primVal := wrapMeta.Elem().FieldByName(metaClass.PrimKey)
|
||||||
|
secVal := wrapMeta.Elem().FieldByName(metaClass.SecKey)
|
||||||
|
nameHash := this.wrapNameHash[metaClass.Idx]
|
||||||
|
idHash := this.wrapIdHash[metaClass.Idx]
|
||||||
|
if fieldVal, ok := primVal.Interface().(*string); ok {
|
||||||
|
if _, ok := nameHash[*fieldVal]; ok {
|
||||||
|
panic(fmt.Sprintf(
|
||||||
|
"bindPrimKey duplicated key error %s %s",
|
||||||
|
metaClass.FileName,
|
||||||
|
*fieldVal))
|
||||||
|
}
|
||||||
|
nameHash[*fieldVal] = wrapMeta
|
||||||
|
} else if fieldVal, ok := primVal.Interface().(*int32); ok {
|
||||||
|
if metaClass.SecKey == "" {
|
||||||
|
if _, ok := idHash[int64(*fieldVal)]; ok {
|
||||||
|
panic(fmt.Sprintf(
|
||||||
|
"bindPrimKey duplicated key error %s %s",
|
||||||
|
metaClass.FileName,
|
||||||
|
*fieldVal))
|
||||||
|
}
|
||||||
|
idHash[int64(*fieldVal)] = wrapMeta.Interface()
|
||||||
|
} else {
|
||||||
|
if subFieldVal, ok := secVal.Interface().(*int32); ok {
|
||||||
|
if _, ok := idHash[q5.MkInt64(*fieldVal, *subFieldVal)]; ok {
|
||||||
|
panic(fmt.Sprintf(
|
||||||
|
"bindPrimKey duplicated key error %s %s",
|
||||||
|
metaClass.FileName,
|
||||||
|
q5.MkInt64(*fieldVal, *subFieldVal)))
|
||||||
|
}
|
||||||
|
idHash[q5.MkInt64(*fieldVal, *subFieldVal)] = wrapMeta.Interface()
|
||||||
|
} else {
|
||||||
|
panic(fmt.Sprintf("bindPrimKey subField error %s", metaClass.FileName))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic(fmt.Sprintf("bindPrimKey primKey error %s", metaClass.FileName))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, metaClass := range *this.metaClasses {
|
||||||
|
wrapMetaList := reflect.ValueOf(this.wrapList[metaClass.Idx])
|
||||||
for i := 0; i < wrapMetaList.Len(); i++ {
|
for i := 0; i < wrapMetaList.Len(); i++ {
|
||||||
wrapMeta := wrapMetaList.Index(i)
|
wrapMeta := wrapMetaList.Index(i)
|
||||||
if val.PrimKey == "" {
|
if metaClass.PrimKey == "" {
|
||||||
this.wrapIdHash[val.Idx][int64(i + 1)] = wrapMeta.Interface()
|
this.wrapIdHash[metaClass.Idx][int64(i + 1)] = wrapMeta.Interface()
|
||||||
continue
|
} else {
|
||||||
}
|
bindFunc(&metaClass, wrapMeta)
|
||||||
primVal := wrapMeta.Elem().FieldByName(val.PrimKey)
|
|
||||||
secVal := wrapMeta.Elem().FieldByName(val.SecKey)
|
|
||||||
if fieldVal, ok := primVal.Interface().(*string); ok {
|
|
||||||
this.wrapNameHash[val.Idx][*fieldVal] = wrapMeta
|
|
||||||
} else if fieldVal, ok := primVal.Interface().(*int32); ok {
|
|
||||||
if val.SecKey == "" {
|
|
||||||
this.wrapIdHash[val.Idx][int64(*fieldVal)] = wrapMeta.Interface()
|
|
||||||
} else {
|
|
||||||
if subFieldVal, ok := secVal.Interface().(*int32); ok {
|
|
||||||
this.wrapIdHash[val.Idx][int64(*subFieldVal)] = wrapMeta.Interface()
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println("ok")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MetaMgr) loadJson(metaClass *MetaClass) (reflect.Value, error) {
|
func (this *MetaMgr) loadJson(metaClass *MetaClass) (reflect.Value, error) {
|
||||||
f, _ := os.Open(metaClass.FileName)
|
if f, err := os.Open(metaClass.FileName); err == nil {
|
||||||
data, _ := bufio.NewReader(f).ReadString(0)
|
data, _ := bufio.NewReader(f).ReadString(0)
|
||||||
if metaClass.IsObject {
|
switch q5.JsonStrType(data) {
|
||||||
data = "{\"values\":[" + data
|
case q5.JSON_ARRAY:
|
||||||
data += "]}"
|
data = "{\"values\":" + data + "}"
|
||||||
} else {
|
case q5.JSON_OBJECT:
|
||||||
data = "{\"values\":" + data
|
data = "{\"values\":[" + data + "]}"
|
||||||
data += "}"
|
default:
|
||||||
}
|
panic(fmt.Sprintf("error json format %s", metaClass.FileName))
|
||||||
|
}
|
||||||
|
|
||||||
u := jsonpb.Unmarshaler{AllowUnknownFields: true}
|
msgType := reflect.TypeOf(metaClass.RawMeta).Elem()
|
||||||
msgType := reflect.TypeOf(metaClass.RawMeta).Elem()
|
msg := reflect.New(msgType)
|
||||||
msg := reflect.New(msgType)
|
msgPb := msg.Interface().(proto.Message)
|
||||||
msgPb := msg.Interface().(proto.Message)
|
u := jsonpb.Unmarshaler{AllowUnknownFields: true}
|
||||||
err := u.Unmarshal(strings.NewReader(data), msgPb)
|
err := u.Unmarshal(strings.NewReader(data), msgPb)
|
||||||
return msg, err
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf(
|
||||||
|
"parse json error %s %s %s",
|
||||||
|
err,
|
||||||
|
metaClass.FileName,
|
||||||
|
msgType.Name()))
|
||||||
|
}
|
||||||
|
return msg, err
|
||||||
|
} else {
|
||||||
|
panic(fmt.Sprintf("open metafile error %s %s", metaClass.FileName, err))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *MetaMgr) GetMetaById(idx int, id int32) interface{} {
|
func (this *MetaMgr) GetMetaById(idx int, id int32) interface{} {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user