...
|
...
|
@@ -12,6 +12,7 @@ import ( |
|
|
"os"
|
|
|
"path"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
type SuMoneyController struct {
|
...
|
...
|
@@ -510,13 +511,149 @@ func (controller *SuMoneyController) ExportExchangeList() { |
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO 导出素币流水记录,选择导出(ids),增加导出失败信息
|
|
|
func (controller *SuMoneyController) ExportSuMoneyTransactionRecord() {
|
|
|
|
|
|
}
|
|
|
|
|
|
// TODO 导出员工素币情况列表,选择导出(ids),增加导出失败信息
|
|
|
// 导出素币流水
|
|
|
func (controller *SuMoneyController) ExportSuMoney() {
|
|
|
suMoneyService := service.NewSuMoneyService(nil)
|
|
|
exportTransactionRecordCommand := &command.ExportTransactionRecordCommand{}
|
|
|
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exportTransactionRecordCommand)
|
|
|
// 列标题
|
|
|
titles := []string{
|
|
|
"员工姓名","手机账号","当前素币",
|
|
|
}
|
|
|
// 列单元
|
|
|
cells := []string{
|
|
|
"A","B","C",
|
|
|
}
|
|
|
var response utils.JsonResponse
|
|
|
var data []map[string]interface{}
|
|
|
records, err := suMoneyService.ListSuMoneyTransactionRecordById(exportTransactionRecordCommand)
|
|
|
for _, record := range records {
|
|
|
p := map[string]interface{} {
|
|
|
"name": record.Employee.EmployeeName,
|
|
|
"account": record.Employee.EmployeeAccount,
|
|
|
"current_su_money": record.SuMoney,
|
|
|
}
|
|
|
data = append(data, p)
|
|
|
}
|
|
|
if err != nil {
|
|
|
response = utils.ResponseError(controller.Ctx, err)
|
|
|
controller.Data["json"] = response
|
|
|
controller.ServeJSON()
|
|
|
} else {
|
|
|
// 新建文件
|
|
|
f := excelize.NewFile()
|
|
|
// 新建工作簿
|
|
|
index := f.NewSheet("Sheet1")
|
|
|
//列标题赋值
|
|
|
for column, v := range titles {
|
|
|
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++
|
|
|
}
|
|
|
}
|
|
|
f.SetActiveSheet(index)
|
|
|
// 创建下载文件夹
|
|
|
mkErr :=os.Mkdir("download", os.ModePerm)
|
|
|
if err!=nil{
|
|
|
fmt.Println(mkErr)
|
|
|
}
|
|
|
//保存为文件
|
|
|
f.Path="download/素币流水.xlsx"
|
|
|
if err := f.Save(); err != nil {
|
|
|
fmt.Println(err)
|
|
|
}
|
|
|
controller.Ctx.Output.Download(f.Path,"素币流水.xlsx")
|
|
|
// 下载完成删除文件
|
|
|
removeErr := os.Remove(f.Path)
|
|
|
if err != nil {
|
|
|
fmt.Println(removeErr)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 导出素币流水记录
|
|
|
func (controller *SuMoneyController) ExportSuMoneyTransactionRecord() {
|
|
|
suMoneyService := service.NewSuMoneyService(nil)
|
|
|
exportTransactionRecordCommand := &command.ExportTransactionRecordCommand{}
|
|
|
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exportTransactionRecordCommand)
|
|
|
// 列标题
|
|
|
titles := []string{
|
|
|
"员工姓名","当前素币","素币流水","操作时间","操作人",
|
|
|
}
|
|
|
// 列单元
|
|
|
cells := []string{
|
|
|
"A","B","C","D","E",
|
|
|
}
|
|
|
var response utils.JsonResponse
|
|
|
var data []map[string]interface{}
|
|
|
records, err := suMoneyService.ListSuMoneyTransactionRecordById(exportTransactionRecordCommand)
|
|
|
for _, record := range records {
|
|
|
p := map[string]interface{} {
|
|
|
"name": record.Employee.EmployeeName,
|
|
|
"current_su_money": record.SuMoney,
|
|
|
"record": record.SuMoney,
|
|
|
"create_time": record.CreateTime,
|
|
|
"operator": record.Operator,
|
|
|
}
|
|
|
data = append(data, p)
|
|
|
}
|
|
|
if err != nil {
|
|
|
response = utils.ResponseError(controller.Ctx, err)
|
|
|
controller.Data["json"] = response
|
|
|
controller.ServeJSON()
|
|
|
} else {
|
|
|
// 新建文件
|
|
|
f := excelize.NewFile()
|
|
|
// 新建工作簿
|
|
|
index := f.NewSheet("Sheet1")
|
|
|
//列标题赋值
|
|
|
for column, v := range titles {
|
|
|
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) // 所有字段保存为字符串类型
|
|
|
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
|
|
|
case time.Time:
|
|
|
f.SetCellValue("Sheet1", sheetPosition, vv.(time.Time))
|
|
|
break
|
|
|
}
|
|
|
columnNum++
|
|
|
}
|
|
|
}
|
|
|
f.SetActiveSheet(index)
|
|
|
// 创建下载文件夹
|
|
|
mkErr :=os.Mkdir("download", os.ModePerm)
|
|
|
if err!=nil{
|
|
|
fmt.Println(mkErr)
|
|
|
}
|
|
|
//保存为文件
|
|
|
f.Path="download/素币流水记录.xlsx"
|
|
|
if err := f.Save(); err != nil {
|
|
|
fmt.Println(err)
|
|
|
}
|
|
|
controller.Ctx.Output.Download(f.Path,"素币流水记录.xlsx")
|
|
|
// 下载完成删除文件
|
|
|
removeErr := os.Remove(f.Path)
|
|
|
if err != nil {
|
|
|
fmt.Println(removeErr)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|