作者 tangxvhui

暂存

@@ -2,8 +2,10 @@ package service @@ -2,8 +2,10 @@ package service
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "strings"
5 6
6 "github.com/linmadan/egglib-go/core/application" 7 "github.com/linmadan/egglib-go/core/application"
  8 + "github.com/xuri/excelize/v2"
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter" 10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query" 11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
@@ -320,8 +322,20 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy @@ -320,8 +322,20 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy
320 level4[level4Key] = v.PromptText 322 level4[level4Key] = v.PromptText
321 } 323 }
322 } 324 }
323 - //汇总表头  
324 - headerList := []excelTableHeader{} 325 + //汇总表头,按列
  326 + headerList := []excelTableHeader{
  327 + {
  328 + Level1: "日期",
  329 + Level2: "",
  330 + Level3: "",
  331 + Level4: "评估标准",
  332 + }, {
  333 + Level1: "姓名",
  334 + Level2: "",
  335 + Level3: "",
  336 + Level4: "",
  337 + },
  338 + }
325 for _, v := range level1 { 339 for _, v := range level1 {
326 item := excelTableHeader{ 340 item := excelTableHeader{
327 Level1: v, 341 Level1: v,
@@ -347,7 +361,37 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy @@ -347,7 +361,37 @@ func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCy
347 } 361 }
348 } 362 }
349 } 363 }
350 - //  
351 - // tab 364 + //数据形式 进行 行列转换
  365 + tableRows := map[string]map[string]string{}
  366 + tableRowSort := []string{}
  367 + for _, v := range contentList {
  368 + if _, ok := tableRows[v.TargetUserId]; !ok {
  369 + tableRows[v.TargetUserId] = map[string]string{}
  370 + tableRowSort = append(tableRowSort, v.TargetUserId)
  371 + }
  372 + tableRows[v.TargetUserId]["TargetUserName"] = v.TargetUserName
  373 + tableRows[v.TargetUserId]["BeginDay"] = v.BeginDay
  374 + value := []string{v.Value}
  375 + for _, v2 := range v.Remark {
  376 + value = append(value, v2.RemarkText)
  377 + }
  378 + key := v.Category + "+" + v.ContentName
  379 + tableRows[v.TargetUserId][key] = strings.Join(value, "\n")
  380 + }
  381 + //将数据写入xlsx
  382 + xlsxFile := excelize.NewFile()
  383 + sheetIndex := xlsxFile.GetActiveSheetIndex()
  384 + sheetName := xlsxFile.GetSheetName(sheetIndex)
  385 + // 写入第一行
  386 + xlsxFile.SetCellStr(sheetName, "A1", "每日绩效汇总")
  387 + //写入二到五行
  388 + for k, v := range headerList {
  389 + colName, _ := excelize.ColumnNumberToName(k + 1)
  390 + xlsxFile.SetCellStr(sheetName, colName+"2", v.Level1)
  391 + xlsxFile.SetCellStr(sheetName, colName+"3", v.Level2)
  392 + xlsxFile.SetCellStr(sheetName, colName+"4", v.Level3)
  393 + xlsxFile.SetCellStr(sheetName, colName+"5", v.Level4)
  394 + }
  395 + //从第六行开始写入用户填写的评估数据
352 return nil, nil 396 return nil, nil
353 } 397 }