作者 陈志颖

fix:修复导出excel字段顺序问题

... ... @@ -59,12 +59,12 @@ func (repository *ExchangeCashPersonListRepository) FindById(queryOptions map[st
var exchangeCashListModels []*models.ExchangeCashPersonList
exchangeCashPeople := make([]*domain.ExchangeCashPersonList, 0)
query := tx.Model(&exchangeCashListModels)
//if iDs, ok := queryOptions["iDs"]; ok && len(iDs.([]int)) != 0 {
// query = query.Where("exchange_cash_person_list.id IN (?)", pg.In(iDs.([]int)) )
//}
if iDs, ok := queryOptions["iDs"]; ok {
if iDs, ok := queryOptions["iDs"]; ok && len(iDs.([]int)) != 0 {
query = query.Where("exchange_cash_person_list.id IN (?)", pg.In(iDs.([]int)) )
}
//if iDs, ok := queryOptions["iDs"]; ok {
// query = query.Where("exchange_cash_person_list.id IN (?)", pg.In(iDs.([]int)) )
//}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, exchangeCashPeople, err
} else {
... ...
... ... @@ -12,7 +12,6 @@ import (
"os"
"path"
"strconv"
"time"
)
type SuMoneyController struct {
... ... @@ -446,6 +445,7 @@ func (controller *SuMoneyController) ExchangeCashListRanking() {
controller.ServeJSON()
}
// 导出素币兑换清单,选择导出(ids),增加导出失败信息
func (controller *SuMoneyController) ExportExchangeList() {
cashPoolService := service.NewCashPoolService(nil)
... ... @@ -483,25 +483,30 @@ func (controller *SuMoneyController) ExportExchangeList() {
index := f.NewSheet("Sheet1")
//列标题赋值
for column, v := range titles {
f.SetCellValue("Sheet1", cells[column]+"1", v)
f.SetCellValue("Sheet1", cells[column] + "1", v)
}
for lineNum, v := range data { //行数 lineNum 行内容 v
columnNum := 0 //列数
for _, vv := range v {
sheetPosition := cells[columnNum] + strconv.Itoa(lineNum+2)
f.SetCellValue("Sheet1", sheetPosition, vv.(string)) // 所有字段保存为字符串类型
//switch vv.(type) {
//case string:
// f.SetCellValue("Sheet1", sheetPosition, vv.(string))
// break
//case int:
// f.SetCellValue("Sheet1", sheetPosition, vv.(int))
// break
//case float64:
// f.SetCellValue("Sheet1", sheetPosition, vv.(float64))
// break
//}
columnNum++
for columnNum := 0; columnNum < len(v); columnNum ++ {
cell := cells[columnNum]
row := strconv.Itoa(lineNum + 2)
switch cell {
case "A":
sheetPosition := cell + row
f.SetCellValue("Sheet1", sheetPosition, v["name"])
break
case "B":
sheetPosition := cell + row
f.SetCellValue("Sheet1", sheetPosition, v["account"])
break
case "C":
sheetPosition := cell + row
f.SetCellValue("Sheet1", sheetPosition, v["exchanged_cash"])
break
case "D":
sheetPosition := cell + row
f.SetCellValue("Sheet1", sheetPosition, v["exchanged_su_money"])
break
}
}
}
f.SetActiveSheet(index)
... ... @@ -562,11 +567,23 @@ func (controller *SuMoneyController) ExportSuMoney() {
f.SetCellValue("Sheet1", cells[column]+"1", v)
}
for lineNum, v := range data { //行数 lineNum 行内容 v
columnNum := 0 //列数
for _, vv := range v {
sheetPosition := cells[columnNum] + strconv.Itoa(lineNum+2)
f.SetCellValue("Sheet1", sheetPosition, vv) // 所有字段保存为字符串类型
columnNum++
for columnNum := 0; columnNum < len(v); columnNum ++ {
cell := cells[columnNum]
row := strconv.Itoa(lineNum + 2)
switch cell {
case "A":
sheetPosition := cell + row
f.SetCellValue("Sheet1", sheetPosition, v["name"])
break
case "B":
sheetPosition := cell + row
f.SetCellValue("Sheet1", sheetPosition, v["account"])
break
case "C":
sheetPosition := cell + row
f.SetCellValue("Sheet1", sheetPosition, v["current_su_money"])
break
}
}
}
f.SetActiveSheet(index)
... ... @@ -606,13 +623,16 @@ func (controller *SuMoneyController) ExportSuMoneyTransactionRecord() {
var data []map[string]interface{}
records, err := suMoneyService.ListSuMoneyTransactionRecordById(exportTransactionRecordCommand)
for _, record := range records {
timString := record.CreateTime.Format("2006/01/02 15:04:05")
p := map[string]interface{} {
"name": record.Employee.EmployeeName,
"current_su_money": record.CurrentSuMoney,
"record": record.SuMoney,
"create_time": record.CreateTime,
"operator": record.Operator,
"create_time": timString,
"operator": record.Operator.EmployeeName,
}
data = append(data, p)
}
if err != nil {
... ... @@ -629,25 +649,31 @@ func (controller *SuMoneyController) ExportSuMoneyTransactionRecord() {
f.SetCellValue("Sheet1", cells[column]+"1", v)
}
for lineNum, v := range data { //行数 lineNum 行内容 v
columnNum := 0 //列数
for _, vv := range v {
sheetPosition := cells[columnNum] + strconv.Itoa(lineNum+2)
switch vv.(type) {
case string:
f.SetCellValue("Sheet1", sheetPosition, vv.(string))
for columnNum := 0; columnNum < len(v); columnNum ++ {
cell := cells[columnNum]
row := strconv.Itoa(lineNum + 2)
switch cell {
case "A":
sheetPosition := cell + row
f.SetCellValue("Sheet1", sheetPosition, v["name"])
break
case "B":
sheetPosition := cell + row
f.SetCellValue("Sheet1", sheetPosition, v["current_su_money"])
break
case int:
f.SetCellValue("Sheet1", sheetPosition, vv.(int))
case "C":
sheetPosition := cell + row
f.SetCellValue("Sheet1", sheetPosition, v["record"])
break
case float64:
f.SetCellValue("Sheet1", sheetPosition, vv.(float64))
case "D":
sheetPosition := cell + row
f.SetCellValue("Sheet1", sheetPosition, v["create_time"])
break
// TODO 时间类型和格式转换
case time.Time:
f.SetCellValue("Sheet1", sheetPosition, vv)
case "E":
sheetPosition := cell + row
f.SetCellValue("Sheet1", sheetPosition, v["operator"])
break
}
columnNum++
}
}
f.SetActiveSheet(index)
... ...