- 清理三个平台的门店商品批处理操作,部分失败返回失败条目

This commit is contained in:
gazebo
2019-07-21 16:08:37 +08:00
parent 0298f7de71
commit 414c359200
12 changed files with 597 additions and 179 deletions

View File

@@ -7,10 +7,11 @@ import (
)
type ErrorWithCode struct {
level int
errMsg string
code string
intCode int
level int
prefixList []string
errMsg string
code string
intCode int
}
func NewErrorCode(errMsg, code string, level ...int) *ErrorWithCode {
@@ -31,7 +32,11 @@ func NewErrorIntCode(errMsg string, code int, level ...int) *ErrorWithCode {
}
func (e *ErrorWithCode) Error() string {
return fmt.Sprintf("%s level:%d, code:%s", e.errMsg, e.level, e.code)
fullErrMsg := e.ErrMsg()
if len(e.prefixList) > 0 {
fullErrMsg = strings.Join(e.prefixList, ",") + ", " + fullErrMsg
}
return fmt.Sprintf("%s level:%d, code:%s", fullErrMsg, e.Level(), e.Code())
}
func (e *ErrorWithCode) String() string {
@@ -54,6 +59,10 @@ func (e *ErrorWithCode) ErrMsg() string {
return e.errMsg
}
func (e *ErrorWithCode) AddPrefixMsg(prefix string) {
e.prefixList = append(e.prefixList, prefix)
}
func IsErrMatch(err error, strCode string, strList []string) (isMatch bool) {
if err != nil {
if codeErr, ok := err.(*ErrorWithCode); ok {

View File

@@ -247,6 +247,13 @@ func Int64ToStr(value int64) string {
return strconv.FormatInt(value, 10)
}
func Int64ToStrNoZero(value int64) string {
if value == 0 {
return ""
}
return strconv.FormatInt(value, 10)
}
func Int2Str(value int) string {
return strconv.Itoa(value)
}
@@ -469,11 +476,48 @@ func Struct2FlatMap(obj interface{}) map[string]interface{} {
}
// !!! 此函数好像不支持struct是内嵌结构的
func Map2StructByJson(inObj interface{}, outObjAddr interface{}, weaklyTypedInput bool) (err error) {
func Map2Struct(inObj interface{}, outObjAddr interface{}, weaklyTypedInput bool, tagName string) (err error) {
if tagName == "" {
tagName = "json"
}
decoder, _ := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
TagName: "json",
TagName: tagName,
Result: outObjAddr,
WeaklyTypedInput: weaklyTypedInput,
})
return decoder.Decode(inObj)
}
func Map2StructByJson(inObj interface{}, outObjAddr interface{}, weaklyTypedInput bool) (err error) {
return Map2Struct(inObj, outObjAddr, weaklyTypedInput, "")
}
func Int64Slice2String(intList []int64) (outList []string) {
if len(intList) > 0 {
outList = make([]string, len(intList))
for k, v := range intList {
outList[k] = Int64ToStr(v)
}
}
return outList
}
func StringSlice2Int64(intList []string) (outList []int64) {
if len(intList) > 0 {
outList = make([]int64, len(intList))
for k, v := range intList {
outList[k] = Str2Int64WithDefault(v, 0)
}
}
return outList
}
func IntSlice2Int64(intList []int) (outList []int64) {
if len(intList) > 0 {
outList = make([]int64, len(intList))
for k, v := range intList {
outList[k] = int64(v)
}
}
return outList
}