|
@@ -4,6 +4,7 @@ import ( |
|
@@ -4,6 +4,7 @@ import ( |
4
|
"fmt"
|
4
|
"fmt"
|
5
|
"github.com/linmadan/egglib-go/utils/xtime"
|
5
|
"github.com/linmadan/egglib-go/utils/xtime"
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/utils"
|
|
|
7
|
+ "strconv"
|
7
|
"strings"
|
8
|
"strings"
|
8
|
)
|
9
|
)
|
9
|
|
10
|
|
|
@@ -221,7 +222,8 @@ func ToFieldData(fields []*Field, data [][]string, byName bool, configs ...bool) |
|
@@ -221,7 +222,8 @@ func ToFieldData(fields []*Field, data [][]string, byName bool, configs ...bool) |
221
|
continue
|
222
|
continue
|
222
|
}
|
223
|
}
|
223
|
if len(d) >= j {
|
224
|
if len(d) >= j {
|
224
|
- item[key] = d[j]
|
225
|
+ // 处理精度问题
|
|
|
226
|
+ item[key] = RoundFieldValue(f, d[j]) //d[j]
|
225
|
} else {
|
227
|
} else {
|
226
|
item[key] = ""
|
228
|
item[key] = ""
|
227
|
}
|
229
|
}
|
|
@@ -231,6 +233,19 @@ func ToFieldData(fields []*Field, data [][]string, byName bool, configs ...bool) |
|
@@ -231,6 +233,19 @@ func ToFieldData(fields []*Field, data [][]string, byName bool, configs ...bool) |
231
|
return result
|
233
|
return result
|
232
|
}
|
234
|
}
|
233
|
|
235
|
|
|
|
236
|
+// RoundFieldValue 字段值精度处理
|
|
|
237
|
+func RoundFieldValue(f *Field, v string) string {
|
|
|
238
|
+ if f.SQLType != Float.ToString() {
|
|
|
239
|
+ return v
|
|
|
240
|
+ }
|
|
|
241
|
+ fv, err := strconv.ParseFloat(v, 64)
|
|
|
242
|
+ if err != nil {
|
|
|
243
|
+ return v
|
|
|
244
|
+ }
|
|
|
245
|
+ fv = utils.Round(fv, 6)
|
|
|
246
|
+ return fmt.Sprintf("%v", fv)
|
|
|
247
|
+}
|
|
|
248
|
+
|
234
|
func GripData(data []map[string]string, total int64) map[string]interface{} {
|
249
|
func GripData(data []map[string]string, total int64) map[string]interface{} {
|
235
|
if len(data) == 0 {
|
250
|
if len(data) == 0 {
|
236
|
data = make([]map[string]string, 0)
|
251
|
data = make([]map[string]string, 0)
|
|
@@ -257,6 +272,10 @@ func MakeToInterfaces(fields []*Field) func([]string) []interface{} { |
|
@@ -257,6 +272,10 @@ func MakeToInterfaces(fields []*Field) func([]string) []interface{} { |
257
|
output := make([]interface{}, len(input))
|
272
|
output := make([]interface{}, len(input))
|
258
|
for i, v := range input {
|
273
|
for i, v := range input {
|
259
|
if i < len(fields) {
|
274
|
if i < len(fields) {
|
|
|
275
|
+ // 处理精度问题
|
|
|
276
|
+ if fields[i].SQLType == Float.ToString() {
|
|
|
277
|
+ v = RoundFieldValue(fields[i], v)
|
|
|
278
|
+ }
|
260
|
convValue, err := ValueToType(v, fields[i].SQLType)
|
279
|
convValue, err := ValueToType(v, fields[i].SQLType)
|
261
|
if err == nil {
|
280
|
if err == nil {
|
262
|
output[i] = convValue
|
281
|
output[i] = convValue
|