forked from free-lancers/electricity_bill_calc_service
feat(park):基本完成园区功能接口的迁移。
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/mozillazg/go-pinyin"
|
||||
"github.com/samber/lo"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
func ContainsInsensitive(element string, slice []string) bool {
|
||||
@@ -86,3 +87,27 @@ func CondFn[T, R any](exprFn func(val T) bool, value T, trueValue, falseValue R)
|
||||
func CondOr[T any](exprFn func(val T) bool, value, elseValue T) T {
|
||||
return CondFn(exprFn, value, value, elseValue)
|
||||
}
|
||||
|
||||
// 将指定的字符串指针解析为一个可空的`decimal.NullDecimal`类型的值。
|
||||
func NewNullDecimalFromString(val *string) (decimal.NullDecimal, error) {
|
||||
if val == nil {
|
||||
return decimal.NullDecimal{Valid: false}, nil
|
||||
}
|
||||
nd, err := decimal.NewFromString(*val)
|
||||
if err != nil {
|
||||
return decimal.NullDecimal{Valid: false}, err
|
||||
}
|
||||
return decimal.NullDecimal{Decimal: nd, Valid: true}, nil
|
||||
}
|
||||
|
||||
// 将指定的字符串指针解析为一个`decimal.Decimal`类型的值,必须提供一个默认值,以用来替换解析失败以及空指针的情况。
|
||||
func NewDecimalFromString(val *string, defaultValue decimal.Decimal) decimal.Decimal {
|
||||
if val == nil {
|
||||
return defaultValue
|
||||
}
|
||||
nd, err := decimal.NewFromString(*val)
|
||||
if err != nil {
|
||||
return defaultValue
|
||||
}
|
||||
return nd
|
||||
}
|
||||
|
Reference in New Issue
Block a user