作者 tangxvhui

更新 ,项目管理-成员列表导出

... ... @@ -16,7 +16,6 @@ type ExportAssessContentCycleDay struct {
CompanyId int `json:"companyId"`
OperaterId int `json:"operaterId"`
CycleId int `json:"cycleId,string"` //周期id
BeginDay string `json:"beginDay"` //评估开始的时间
BeginDayList []string `json:"beginDayList"` //评估开始的时间
TargetUserName string `json:"targetUserName"`
TargetUserId []string `json:"targetUserId"`
... ...
... ... @@ -2,8 +2,6 @@ package service
import (
"fmt"
"strconv"
"strings"
"github.com/linmadan/egglib-go/core/application"
"github.com/xuri/excelize/v2"
... ... @@ -211,223 +209,223 @@ func (srv StaffAssessServeice) ListUserAssessContentCycleDay(param *query.ListAs
return &result, nil
}
func (srv StaffAssessServeice) ExportUserAssess(param *query.ExportAssessContentCycleDay) (*excelize.File, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperaterId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
contentList, err := assessDao.ExportDataUserAssess(dao.SearchConditin1{
CompanyId: param.CompanyId,
CycleId: param.CycleId,
BeginDay: param.BeginDay,
TargetUserName: param.TargetUserName,
TargetUserId: param.TargetUserId,
Limit: 5000,
Offset: 0,
OperaterId: param.OperaterId,
Hrbp: hrbp,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取数据列表"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//选择导出的评估项
includeCol := map[string]struct{}{}
for _, v := range param.ExportItems {
includeCol[v.Category+"+"+v.Name] = struct{}{}
}
//处理查询到的数据
//汇总 Excel表格的表头描述
level1 := []string{} //分类
level3 := map[string][]string{} //key=分类+得分项类型 val=名称
level4 := map[string]string{} //key=分类+名称 val=评估标准
for _, v := range contentList {
if v.ContentId == 0 {
continue
}
if len(includeCol) > 0 {
if _, ok := includeCol[v.Category+"+"+v.ContentName]; !ok {
continue
}
}
level1Item := ""
for _, v1 := range level1 {
if v.Category == v1 {
level1Item = v1
}
}
if len(level1Item) == 0 {
level1 = append(level1, v.Category)
}
if v.Weight == 0 {
level3Key := v.Category + "-加分项"
if _, ok := level3[level3Key]; !ok {
level3[level3Key] = []string{}
}
level3Item := ""
for _, v3 := range level3[level3Key] {
if v3 == v.ContentName {
level3Item = v.ContentName
}
}
if len(level3Item) == 0 {
level3[level3Key] = append(level3[level3Key], v.ContentName)
}
}
if v.Weight > 0 {
level3Key := v.Category + "-得分项"
if _, ok := level3[level3Key]; !ok {
level3[level3Key] = []string{}
}
level3Item := ""
for _, v3 := range level3[level3Key] {
if v3 == v.ContentName {
level3Item = v.ContentName
}
}
if len(level3Item) == 0 {
level3[level3Key] = append(level3[level3Key], v.ContentName)
}
}
level4Key := v.Category + "+" + v.ContentName
if _, ok := level4[level4Key]; !ok {
level4[level4Key] = v.PromptText
}
}
//汇总表头,按列
headerList := []excelTableHeader{
{
Level1: "日期",
Level2: "",
Level3: "",
Level4: "评估标准",
}, {
Level1: "姓名",
Level2: "",
Level3: "",
Level4: "",
},
}
for _, v := range level1 {
item := excelTableHeader{
Level1: v,
}
level3Key := v + "-加分项"
if _, ok := level3[level3Key]; ok {
for _, v2 := range level3[level3Key] {
item.Level2 = "加分项"
item.Level3 = v2
level4Key := v + "+" + v2
item.Level4 = level4[level4Key]
headerList = append(headerList, item)
}
}
level3Key = v + "-得分项"
if _, ok := level3[level3Key]; ok {
for _, v2 := range level3[level3Key] {
item.Level2 = "得分项"
item.Level3 = v2
level4Key := v + "+" + v2
item.Level4 = level4[level4Key]
headerList = append(headerList, item)
}
}
}
//数据形式 进行 行列转换
tableRows := map[string]map[string]string{}
tableRowSort := []string{}
for _, v := range contentList {
if _, ok := tableRows[v.TargetUserId]; !ok {
tableRows[v.TargetUserId] = map[string]string{}
tableRowSort = append(tableRowSort, v.TargetUserId)
}
tableRows[v.TargetUserId]["TargetUserName"] = v.TargetUserName
tableRows[v.TargetUserId]["BeginDay"] = v.BeginDay
if v.ContentId > 0 {
if len(includeCol) > 0 {
if _, ok := includeCol[v.Category+"+"+v.ContentName]; !ok {
continue
}
}
value := []string{v.Value}
for _, v2 := range v.Remark {
value = append(value, v2.RemarkText)
}
key := v.Category + "+" + v.ContentName
tableRows[v.TargetUserId][key] = strings.Join(value, "\n")
}
}
//将数据写入xlsx
xlsxFile := excelize.NewFile()
sheetIndex := xlsxFile.GetActiveSheetIndex()
sheetName := xlsxFile.GetSheetName(sheetIndex)
//写入第一行
xlsxFile.SetCellStr(sheetName, "A1", "每日绩效汇总")
//写入二到五行
for k, v := range headerList {
colName, _ := excelize.ColumnNumberToName(k + 1)
xlsxFile.SetCellStr(sheetName, colName+"2", v.Level1)
xlsxFile.SetCellStr(sheetName, colName+"3", v.Level2)
xlsxFile.SetCellStr(sheetName, colName+"4", v.Level3)
xlsxFile.SetCellStr(sheetName, colName+"5", v.Level4)
}
//从第六行开始写入用户填写的评估数据
for k, v := range tableRowSort {
rowNum := strconv.Itoa(k + 6)
row := tableRows[v]
for k2, v2 := range headerList {
if k2 == 0 {
xlsxFile.SetCellStr(sheetName, "A"+rowNum, row["BeginDay"])
continue
}
if k2 == 1 {
xlsxFile.SetCellStr(sheetName, "B"+rowNum, row["TargetUserName"])
continue
}
colName, _ := excelize.ColumnNumberToName(k2 + 1)
key := v2.Level1 + "+" + v2.Level3
if mVal, ok := row[key]; ok {
xlsxFile.SetCellStr(sheetName, colName+rowNum, mVal)
}
}
}
//TODO 调整样式
xlsxFile.MergeCell(sheetName, "A2", "A4")
xlsxFile.MergeCell(sheetName, "B2", "B4")
xlsxFile.MergeCell(sheetName, "B5", "B5")
//设置行高
for i := range tableRowSort {
xlsxFile.SetRowHeight(sheetName, i+5, 50)
}
//设置列宽
for i := range headerList {
colName, _ := excelize.ColumnNumberToName(i + 1)
if i == 0 {
xlsxFile.SetColWidth(sheetName, colName, colName, 30)
}
}
return xlsxFile, nil
}
// func (srv StaffAssessServeice) ExportUserAssess(param *query.ExportAssessContentCycleDay) (*excelize.File, error) {
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
// hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperaterId)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// assessDao := dao.NewStaffAssessDao(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// contentList, err := assessDao.ExportDataUserAssess(dao.SearchConditin1{
// CompanyId: param.CompanyId,
// CycleId: param.CycleId,
// BeginDay: param.BeginDay,
// TargetUserName: param.TargetUserName,
// TargetUserId: param.TargetUserId,
// Limit: 5000,
// Offset: 0,
// OperaterId: param.OperaterId,
// Hrbp: hrbp,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取数据列表"+err.Error())
// }
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// //选择导出的评估项
// includeCol := map[string]struct{}{}
// for _, v := range param.ExportItems {
// includeCol[v.Category+"+"+v.Name] = struct{}{}
// }
// //处理查询到的数据
// //汇总 Excel表格的表头描述
// level1 := []string{} //分类
// level3 := map[string][]string{} //key=分类+得分项类型 val=名称
// level4 := map[string]string{} //key=分类+名称 val=评估标准
// for _, v := range contentList {
// if v.ContentId == 0 {
// continue
// }
// if len(includeCol) > 0 {
// if _, ok := includeCol[v.Category+"+"+v.ContentName]; !ok {
// continue
// }
// }
// level1Item := ""
// for _, v1 := range level1 {
// if v.Category == v1 {
// level1Item = v1
// }
// }
// if len(level1Item) == 0 {
// level1 = append(level1, v.Category)
// }
// if v.Weight == 0 {
// level3Key := v.Category + "-加分项"
// if _, ok := level3[level3Key]; !ok {
// level3[level3Key] = []string{}
// }
// level3Item := ""
// for _, v3 := range level3[level3Key] {
// if v3 == v.ContentName {
// level3Item = v.ContentName
// }
// }
// if len(level3Item) == 0 {
// level3[level3Key] = append(level3[level3Key], v.ContentName)
// }
// }
// if v.Weight > 0 {
// level3Key := v.Category + "-得分项"
// if _, ok := level3[level3Key]; !ok {
// level3[level3Key] = []string{}
// }
// level3Item := ""
// for _, v3 := range level3[level3Key] {
// if v3 == v.ContentName {
// level3Item = v.ContentName
// }
// }
// if len(level3Item) == 0 {
// level3[level3Key] = append(level3[level3Key], v.ContentName)
// }
// }
// level4Key := v.Category + "+" + v.ContentName
// if _, ok := level4[level4Key]; !ok {
// level4[level4Key] = v.PromptText
// }
// }
// //汇总表头,按列
// headerList := []excelTableHeader{
// {
// Level1: "日期",
// Level2: "",
// Level3: "",
// Level4: "评估标准",
// }, {
// Level1: "姓名",
// Level2: "",
// Level3: "",
// Level4: "",
// },
// }
// for _, v := range level1 {
// item := excelTableHeader{
// Level1: v,
// }
// level3Key := v + "-加分项"
// if _, ok := level3[level3Key]; ok {
// for _, v2 := range level3[level3Key] {
// item.Level2 = "加分项"
// item.Level3 = v2
// level4Key := v + "+" + v2
// item.Level4 = level4[level4Key]
// headerList = append(headerList, item)
// }
// }
// level3Key = v + "-得分项"
// if _, ok := level3[level3Key]; ok {
// for _, v2 := range level3[level3Key] {
// item.Level2 = "得分项"
// item.Level3 = v2
// level4Key := v + "+" + v2
// item.Level4 = level4[level4Key]
// headerList = append(headerList, item)
// }
// }
// }
// //数据形式 进行 行列转换
// tableRows := map[string]map[string]string{}
// tableRowSort := []string{}
// for _, v := range contentList {
// if _, ok := tableRows[v.TargetUserId]; !ok {
// tableRows[v.TargetUserId] = map[string]string{}
// tableRowSort = append(tableRowSort, v.TargetUserId)
// }
// tableRows[v.TargetUserId]["TargetUserName"] = v.TargetUserName
// tableRows[v.TargetUserId]["BeginDay"] = v.BeginDay
// if v.ContentId > 0 {
// if len(includeCol) > 0 {
// if _, ok := includeCol[v.Category+"+"+v.ContentName]; !ok {
// continue
// }
// }
// value := []string{v.Value}
// for _, v2 := range v.Remark {
// value = append(value, v2.RemarkText)
// }
// key := v.Category + "+" + v.ContentName
// tableRows[v.TargetUserId][key] = strings.Join(value, "\n")
// }
// }
// //将数据写入xlsx
// xlsxFile := excelize.NewFile()
// sheetIndex := xlsxFile.GetActiveSheetIndex()
// sheetName := xlsxFile.GetSheetName(sheetIndex)
// //写入第一行
// xlsxFile.SetCellStr(sheetName, "A1", "每日绩效汇总")
// //写入二到五行
// for k, v := range headerList {
// colName, _ := excelize.ColumnNumberToName(k + 1)
// xlsxFile.SetCellStr(sheetName, colName+"2", v.Level1)
// xlsxFile.SetCellStr(sheetName, colName+"3", v.Level2)
// xlsxFile.SetCellStr(sheetName, colName+"4", v.Level3)
// xlsxFile.SetCellStr(sheetName, colName+"5", v.Level4)
// }
// //从第六行开始写入用户填写的评估数据
// for k, v := range tableRowSort {
// rowNum := strconv.Itoa(k + 6)
// row := tableRows[v]
// for k2, v2 := range headerList {
// if k2 == 0 {
// xlsxFile.SetCellStr(sheetName, "A"+rowNum, row["BeginDay"])
// continue
// }
// if k2 == 1 {
// xlsxFile.SetCellStr(sheetName, "B"+rowNum, row["TargetUserName"])
// continue
// }
// colName, _ := excelize.ColumnNumberToName(k2 + 1)
// key := v2.Level1 + "+" + v2.Level3
// if mVal, ok := row[key]; ok {
// xlsxFile.SetCellStr(sheetName, colName+rowNum, mVal)
// }
// }
// }
// //TODO 调整样式
// xlsxFile.MergeCell(sheetName, "A2", "A4")
// xlsxFile.MergeCell(sheetName, "B2", "B4")
// xlsxFile.MergeCell(sheetName, "B5", "B5")
// //设置行高
// for i := range tableRowSort {
// xlsxFile.SetRowHeight(sheetName, i+5, 50)
// }
// //设置列宽
// for i := range headerList {
// colName, _ := excelize.ColumnNumberToName(i + 1)
// if i == 0 {
// xlsxFile.SetColWidth(sheetName, colName, colName, 30)
// }
// }
// return xlsxFile, nil
// }
//员工绩效-项目管理-矩阵分析
... ... @@ -710,7 +708,7 @@ func (srv StaffAssessServeice) QueryPerformanceIndicator(param *query.ListAssess
// 员工绩效-项目管理-成员列表导出
func (srv StaffAssessServeice) ExportUserAssess3(param *query.ExportAssessContentCycleDay) (*excelize.File, error) {
func (srv StaffAssessServeice) ExportUserAssess(param *query.ExportAssessContentCycleDay) (*excelize.File, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -733,7 +731,7 @@ func (srv StaffAssessServeice) ExportUserAssess3(param *query.ExportAssessConten
contentList, err := assessDao.ExportDataUserAssess(dao.SearchConditin1{
CompanyId: param.CompanyId,
CycleId: param.CycleId,
BeginDay: param.BeginDay,
BeginDay: "",
TargetUserName: param.TargetUserName,
TargetUserId: param.TargetUserId,
Limit: 5000,
... ... @@ -753,6 +751,10 @@ func (srv StaffAssessServeice) ExportUserAssess3(param *query.ExportAssessConten
for _, v := range param.ExportItems {
includeCol[v.Category+"+"+v.Name] = struct{}{}
}
includeBeginDay := map[string]struct{}{}
for _, v := range param.BeginDayList {
includeBeginDay[v] = struct{}{}
}
eData := newExportData2()
eData.setData(contentList)
... ... @@ -768,65 +770,74 @@ func (srv StaffAssessServeice) ExportUserAssess3(param *query.ExportAssessConten
xlsxFile.MergeCell(sheetName, "B2", "B4")
xlsxFile.SetCellStr(sheetName, "A5", "评估标准")
//填充1,2 列
//行数量
rowNum := 0
for _, v := range eData.rowSort.Child {
//纵向-索引-第一列-日期
if len(includeBeginDay) > 0 {
if _, ok := includeBeginDay[v.Name]; !ok {
continue
}
}
for _, v2 := range v.Child {
//纵向-索引-第二列-员工id
//填充1,2 列
rowNum++
axisNum := fmt.Sprintf("%d", rowNum+5)
userName := eData.userIdMap[v2.Name]
xlsxFile.SetCellStr(sheetName, "A"+axisNum, v.Name)
xlsxFile.SetCellStr(sheetName, "B"+axisNum, v2.Name)
xlsxFile.SetCellStr(sheetName, "B"+axisNum, userName)
}
}
//列数量
colNum := 0
for _, v := range eData.tableHeader.Child {
//横向-评估指标-分类
for _, v2 := range v.Child {
//横向-评估指标-加分项、得分项
for _, v3 := range v2.Child {
_ = v3
// 横向-评估指标-名称
//检查是否在指定的导出选项中
if len(includeCol) > 0 {
if _, ok := includeCol[v.Name+"+"+v3.Name]; !ok {
continue
}
}
colNum++
//第几列
colName, _ := excelize.ColumnNumberToName(colNum + 2)
//填充 分类
xlsxFile.SetCellStr(sheetName, colName+"2", v.Name)
// 填充 加分项、得分项
xlsxFile.SetCellStr(sheetName, colName+"3", v2.Name)
// 填充 名称
xlsxFile.SetCellStr(sheetName, colName+"4", v3.Name)
if len(v3.Child) > 0 {
//填充, 评估标准
xlsxFile.SetCellStr(sheetName, colName+"5", v3.Child[0].Name)
}
xlsxFile.SetColWidth(sheetName, colName, colName, 30)
rowNum = 0
for _, v4 := range eData.rowSort.Child {
//纵向-索引-第一列-日期
if len(includeBeginDay) > 0 {
if _, ok := includeBeginDay[v.Name]; !ok {
continue
}
}
for _, v5 := range v4.Child {
//纵向-索引-第二列-员工id
rowNum++
axis := fmt.Sprintf("%s%d", colName, rowNum+5)
key := eData.dataKey(v5.Name, v4.Name, v.Name, v3.Name)
if d, ok := eData.data[key]; ok {
xlsxFile.SetCellStr(sheetName, axis, d.String())
}
xlsxFile.SetRowHeight(sheetName, rowNum+5, 50)
}
}
}
}
}
//写入二到五行
// for k, v := range headerList {
// colName, _ := excelize.ColumnNumberToName(k + 1)
// xlsxFile.SetCellStr(sheetName, colName+"2", v.Level1)
// xlsxFile.SetCellStr(sheetName, colName+"3", v.Level2)
// xlsxFile.SetCellStr(sheetName, colName+"4", v.Level3)
// xlsxFile.SetCellStr(sheetName, colName+"5", v.Level4)
// }
//从第六行开始写入用户填写的评估数据
// for k, v := range tableRowSort {
// rowNum := strconv.Itoa(k + 6)
// row := tableRows[v]
// for k2, v2 := range headerList {
// if k2 == 0 {
// xlsxFile.SetCellStr(sheetName, "A"+rowNum, row["BeginDay"])
// continue
// }
// if k2 == 1 {
// xlsxFile.SetCellStr(sheetName, "B"+rowNum, row["TargetUserName"])
// continue
// }
// colName, _ := excelize.ColumnNumberToName(k2 + 1)
// key := v2.Level1 + "+" + v2.Level3
// if mVal, ok := row[key]; ok {
// xlsxFile.SetCellStr(sheetName, colName+rowNum, mVal)
// }
// }
// }
//TODO 调整样式
xlsxFile.MergeCell(sheetName, "A2", "A4")
xlsxFile.MergeCell(sheetName, "B2", "B4")
xlsxFile.MergeCell(sheetName, "B5", "B5")
// //设置行高
// for i := range tableRowSort {
// xlsxFile.SetRowHeight(sheetName, i+5, 50)
// }
// //设置列宽
// for i := range headerList {
// colName, _ := excelize.ColumnNumberToName(i + 1)
// if i == 0 {
// xlsxFile.SetColWidth(sheetName, colName, colName, 30)
// }
// }
return xlsxFile, nil
}
... ...
package controllers
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
... ... @@ -356,8 +354,7 @@ func (c *StaffAssessController) ExportAssessContentCycleDay() {
if err != nil {
c.Response(nil, err)
}
fileName := fmt.Sprintf("每日绩效汇总%s", paramReq.BeginDay)
c.Ctx.Output.Header("Content-Disposition", "attachment;filename="+fileName)
c.Ctx.Output.Header("Content-Disposition", "attachment;filename=每日绩效汇总")
c.Ctx.Output.Header("Content-Description", "FileTransfer")
c.Ctx.Output.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
c.Ctx.Output.Header("Content-Transfer-Encoding", "binary")
... ...