- CreatePromotion
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package dtask
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/gob"
|
||||
"errors"
|
||||
"reflect"
|
||||
@@ -10,6 +8,7 @@ import (
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/basesch"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
)
|
||||
@@ -93,7 +92,7 @@ func (m *DurableTaskMan) AddItem(taskID, objHint string, funcName string, params
|
||||
TaskIndex: d.data.TotalItem,
|
||||
FinishedAt: utils.DefaultTimeValue,
|
||||
}
|
||||
if item.Params, err = SerializeData(params); err == nil {
|
||||
if item.Params, err = jxutils.SerializeData(params); err == nil {
|
||||
db := dao.GetDB()
|
||||
if err = dao.CreateEntity(db, item); err == nil {
|
||||
_, err = dao.UpdateEntity(db, d.data, "TotalItem")
|
||||
@@ -116,7 +115,7 @@ func (m *DurableTaskMan) StartTask(taskID string) error {
|
||||
objValue := reflect.ValueOf(obj)
|
||||
func2Call := objValue.MethodByName(taskItem.FuncName)
|
||||
params := []interface{}{}
|
||||
DeSerializeData(taskItem.Params, ¶ms)
|
||||
jxutils.DeSerializeData(taskItem.Params, ¶ms)
|
||||
valueParams := make([]reflect.Value, len(params))
|
||||
|
||||
for k, v := range params {
|
||||
@@ -147,22 +146,3 @@ func (m *DurableTaskMan) StartTask(taskID string) error {
|
||||
func defObjCreator(objHint string) interface{} {
|
||||
return basesch.FixedBaseScheduler.GetPurchasePlatformFromVendorID(0)
|
||||
}
|
||||
|
||||
func SerializeData(data interface{}) (strValue string, err error) {
|
||||
var buf bytes.Buffer
|
||||
enc := gob.NewEncoder(&buf)
|
||||
if err = enc.Encode(data); err == nil {
|
||||
strValue = base64.StdEncoding.EncodeToString(buf.Bytes())
|
||||
return strValue, nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
func DeSerializeData(strValue string, dataPtr interface{}) (err error) {
|
||||
byteData, err := base64.StdEncoding.DecodeString(strValue)
|
||||
if err == nil {
|
||||
dec := gob.NewDecoder(bytes.NewReader(byteData))
|
||||
return dec.Decode(dataPtr)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package jxutils
|
||||
|
||||
import "reflect"
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/gob"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func CheckAndGetStructValue(item interface{}) *reflect.Value {
|
||||
value := reflect.ValueOf(item)
|
||||
@@ -20,3 +25,22 @@ func SetObjFieldByName(obj interface{}, fieldName string, value interface{}) {
|
||||
refValue := CheckAndGetStructValue(obj)
|
||||
refValue.FieldByName(fieldName).Set(reflect.ValueOf(value))
|
||||
}
|
||||
|
||||
func SerializeData(data interface{}) (strValue string, err error) {
|
||||
var buf bytes.Buffer
|
||||
enc := gob.NewEncoder(&buf)
|
||||
if err = enc.Encode(data); err == nil {
|
||||
strValue = base64.StdEncoding.EncodeToString(buf.Bytes())
|
||||
return strValue, nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
func DeSerializeData(strValue string, dataPtr interface{}) (err error) {
|
||||
byteData, err := base64.StdEncoding.DecodeString(strValue)
|
||||
if err == nil {
|
||||
dec := gob.NewDecoder(bytes.NewReader(byteData))
|
||||
return dec.Decode(dataPtr)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user