跟新结构体切片

This commit is contained in:
ayflying
2025-02-11 14:26:06 +08:00
parent 9461ad77ed
commit 4862dcd1d8
3 changed files with 26 additions and 17 deletions

View File

@@ -93,7 +93,7 @@ func (s *Excel) itemsFormat(list []interface{}, Items []string) []interface{} {
for k3, v3 := range v2.(g.Map) {
if gstr.InArray(Items, k3) {
if _, ok := v3.(string); ok {
list[k2].(g.Map)[k3] = s.Spilt2Item(v3.(string))
list[k2].(g.Map)[k3] = Spilt2Item(v3.(string))
} else {
g.Log().Errorf(gctx.New(), "当前类型断言失败:%v,list=%v", v3, v2)
}
@@ -108,7 +108,7 @@ func (s *Excel) itemsMapFormat(list []interface{}, Items []string) []interface{}
for k3, v3 := range v2.(g.Map) {
if gstr.InArray(Items, k3) {
if _, ok := v3.(string); ok {
get := s.Spilt2Item(v3.(string))
get := Spilt2Item(v3.(string))
list[k2].(g.Map)[k3] = s.Items2Map(get)
} else {
g.Log().Errorf(gctx.New(), "当前类型断言失败:%v,list=%v", v3, v2)

View File

@@ -26,7 +26,7 @@ func Excel2Slice(filePath string, _sheet ...string) [][]string {
}
// 字符串转道具类型
func (s *Excel) Spilt2Item(str string) (result [][]int64) {
func Spilt2Item(str string) (result [][]int64) {
var shadiao = []string{","}
for _, v := range shadiao {
str = strings.ReplaceAll(str, v, "|")
@@ -39,20 +39,6 @@ func (s *Excel) Spilt2Item(str string) (result [][]int64) {
parts = []string{str}
}
//var parts []string
//for _, v := range parts1 {
// parts = append(parts, strings.Split(v, ",")...) // 分割字符串
//}
//for _, v := range parts1 {
// parts2 := strings.Split(v, ",") // 分割字符串
// if parts2 == nil {
// parts = append(parts, v)
// } else {
// parts = append(parts, parts2...)
// }
//}
for i := 0; i < len(parts)-1; i += 2 {
num1, _ := strconv.ParseInt(parts[i], 10, 64)
num2, _ := strconv.ParseInt(parts[i+1], 10, 64)

View File

@@ -55,9 +55,32 @@ func (m *tools) GetDay(t1 *gtime.Time, t2 *gtime.Time) int {
return int(t1.Sub(t2).Hours() / 24)
}
//// 字符串转道具类型
//func (m *tools) Spilt2Item(str string) (result [][]int64) {
// parts := strings.Split(str, "|") // 分割字符串
//
// for i := 0; i < len(parts)-1; i += 2 {
// num1, _ := strconv.ParseInt(parts[i], 10, 64)
// num2, _ := strconv.ParseInt(parts[i+1], 10, 64)
//
// pair := []int64{num1, num2}
// result = append(result, pair)
// }
// return
//}
// 字符串转道具类型
func (m *tools) Spilt2Item(str string) (result [][]int64) {
var shadiao = []string{","}
for _, v := range shadiao {
str = strings.ReplaceAll(str, v, "|")
}
//var parts []string
parts := strings.Split(str, "|") // 分割字符串
if parts == nil {
parts = []string{str}
}
for i := 0; i < len(parts)-1; i += 2 {
num1, _ := strconv.ParseInt(parts[i], 10, 64)