作者 陈志颖

test:导入逻辑

... ... @@ -71,3 +71,32 @@ func InsertSlice(index int, newstr []string, src []string) (ns []string) {
ns = append(ns, src[index:]...)
return
}
//RankPeriodCheckTime 设置赛季时检查时间范围的合法性
//func RankPeriodCheckTime(rankTypeId int64, beginTime int64, endTime int64, idNot int64) bool {
// sql := `SELECT count(*) FROM rank_period
// WHERE rank_type_id = %d
// AND id <> %d
// AND
// (
// (UNIX_TIMESTAMP(begin_time) BETWEEN %d AND %d)
// OR
// (UNIX_TIMESTAMP(end_time) BETWEEN %d AND %d)
// OR
// (%d BETWEEN UNIX_TIMESTAMP(begin_time) AND UNIX_TIMESTAMP(end_time))
// OR
// (%d BETWEEN UNIX_TIMESTAMP(begin_time) AND UNIX_TIMESTAMP(end_time))
// )
// LIMIT 1 `
// sql = fmt.Sprintf(sql, rankTypeId, idNot, beginTime, endTime, beginTime, endTime, beginTime, endTime)
// var cnt int
// err := utils.ExecuteQueryOne(&cnt, sql)
// if err != nil {
// log.Error("SQL Execute err:%s", err)
// return false
// }
// if cnt > 0 {
// return false
// }
// return true
//}
\ No newline at end of file
... ...
... ... @@ -10,6 +10,7 @@ import (
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/command"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/query"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/suMoney/service"
utils_tool "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/utils"
"os"
"path"
"strconv"
... ... @@ -427,6 +428,7 @@ func (controller *SuMoneyController) ImportExchangeList () {
return
}
// 打开文件
xlsx, err := excelize.OpenReader(file)
if err != nil {
fmt.Println(err)
... ... @@ -436,8 +438,6 @@ func (controller *SuMoneyController) ImportExchangeList () {
// 文件行数校验
rows, _ := xlsx.GetRows("Sheet1")
fmt.Print(len(rows), "\n")
// 表格超行判断
if len(rows) > 302 {
err := &application.ServiceError{
Code: 500,
... ... @@ -461,48 +461,53 @@ func (controller *SuMoneyController) ImportExchangeList () {
return
}
// 空字段判断
//newstr := []string{"null"}
// 单元格校验
newstr := []string{"null"}
//nullChar := []string{"单元格包含空字符"}
nullLine := make([]interface{}, 0)
for i, row := range rows {
if i > 2 {
fmt.Print(len(row), "\n")
// 头部、中间空
if len(row) == 3 {
for j, cell := range row {
fmt.Print(cell, "\n")
if cell == "" {
utils_tool.InsertSlice(j, newstr, row)
row = append(row, "单元格包含空字符")
nullLine = append(nullLine, row)
}
}
}
// 尾空
if len(row) < 3 {
for j, cell := range row {
fmt.Print(cell, "\n")
if cell == "" {
utils_tool.InsertSlice(j, row, newstr)
row = append(row, "单元格包含空字符")
nullLine = append(nullLine, row)
}
}
}
}
}
//nullLine := make([]interface{}, 0)
//for i, row := range rows {
// if i > 2 {
// if len(row) < 3 {
// r2, _ := strconv.ParseFloat(row[2], 64)
// if row[0] == "" {
// utils_tool.InsertSlice(0, row, newstr)
// } else if row[1] == "" {
// utils_tool.InsertSlice(1, row, newstr)
// } else if r2 == 0 {
// utils_tool.InsertSlice(2, row, newstr)
// }
//
// //for j, cell := range row {
// // if cell == "" {
// // utils_tool.InsertSlice(j, row, newstr)
// // }
// //}
// //utils_tool.InsertSlice(1, row, nullChar)
// row = append(row, "单元格包含空字符")
// nullLine = append(nullLine, row)
// }
// }
//}
//
//if len(nullLine) > 0 {
// ret = map[string]interface{}{
// "successCount": 0,
// "fail": map[string]interface{}{
// "tableHeader": tableHeader,
// "tableData": nullLine,
// },
// }
// response = utils.ResponseData(controller.Ctx, ret)
// controller.Data["json"] = response
// controller.ServeJSON()
// return
//}
if len(nullLine) > 0 {
ret = map[string]interface{}{
"successCount": 0,
"fail": map[string]interface{}{
"tableHeader": tableHeader,
"tableData": nullLine,
},
}
response = utils.ResponseData(controller.Ctx, ret)
controller.Data["json"] = response
controller.ServeJSON()
return
}
// 新增失败记录
failureDataList := make([]interface{}, 0)
... ...