作者 yangfu

fix: decimal problem

... ... @@ -110,7 +110,7 @@ func (tableService *TableService) FieldOptionalValues(ctx *domain.Context, cmd *
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
values := dataTable.OptionalValue(cmd.Match)
values := dataTable.OptionalValue(cmd.Match, field.SQLType)
return map[string]interface{}{
"values": values,
"total": len(values),
... ...
... ... @@ -55,16 +55,24 @@ type Condition struct {
func (t *DataTable) OptionalValue(args ...string) []string {
var values = make([]string, 0)
match:=""
if len(args)>0{
match := ""
filedType := ""
if len(args) > 0 {
match = args[0]
}
if len(args) > 1 {
filedType = args[1]
}
if len(t.Data) > 0 && len(t.Data[0]) == 1 {
for i := range t.Data {
if len(t.Data[i]) == 0 {
continue
}
if len(match)>0 && !strings.Contains(t.Data[i][0],match){
if len(match) > 0 && !strings.Contains(t.Data[i][0], match) {
continue
}
if filedType == Float.ToString() {
values = append(values, RoundFieldValue(&Field{SQLType: filedType}, t.Data[i][0]))
continue
}
values = append(values, t.Data[i][0])
... ...
... ... @@ -125,8 +125,8 @@ var (
Int SQLType = "INT"
BigInt SQLType = "BIGINT"
Float SQLType = "FLOAT"
DECIMALV2 SQLType = "DECIMALV2"
DECIMAL279 SQLType = "DECIMAL(27,9)"
DECIMALV2 SQLType = "DECIMAL(20,15)" //"DECIMALV2"
DECIMAL279 SQLType = "DECIMAL(20,15)"
Date SQLType = "DATE"
Datetime SQLType = "DATETIME"
)
... ...
... ... @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/linmadan/egglib-go/utils/xtime"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
"strconv"
"strings"
)
... ... @@ -244,6 +245,13 @@ func ToFieldData(fields []*Field, data [][]string, byName bool, configs ...bool)
// RoundFieldValue 字段值精度处理
func RoundFieldValue(f *Field, v string) string {
if f.SQLType == Float.ToString() {
fv, err := strconv.ParseFloat(v, 64)
if err != nil {
return v
}
return fmt.Sprintf("%v", fv)
}
return v
//if f.SQLType != DECIMALV2.ToString() {
// return v
... ...