|
|
package service
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"github.com/xuri/excelize/v2"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
|
...
|
...
|
@@ -10,6 +12,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
// 调试用,手动调用CreateStaffAssessTask
|
...
|
...
|
@@ -326,3 +329,150 @@ func (srv StaffAssessServeice) QueryMemberPerformanceIndicator(in *query.MemberP |
|
|
|
|
|
return tool_funs.SimpleWrapGridMap(int64(len(adapterList)), adapterList), nil
|
|
|
}
|
|
|
|
|
|
func (srv StaffAssessServeice) ExportPerformanceIndicator(in *query.ExportPerformanceIndicatorCommand) (*excelize.File, error) {
|
|
|
transactionContext, err := factory.ValidateStartTransaction(in)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
hrbp, err := srv.getHRBP(transactionContext, in.CompanyId, in.OperatorId)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 用户ID
|
|
|
userIds := make([]string, 0)
|
|
|
selectedMap := map[string]*query.ExportSelected{}
|
|
|
for i := range in.Selected {
|
|
|
userIds = append(userIds, in.Selected[i].UserId)
|
|
|
selectedMap[in.Selected[i].UserId] = &in.Selected[i]
|
|
|
}
|
|
|
assessDao := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
|
|
|
list, err := assessDao.ExportPerformanceIndicator(
|
|
|
in.CompanyId,
|
|
|
in.OperatorId,
|
|
|
in.CycleId,
|
|
|
hrbp,
|
|
|
string(domain.AssessSelf),
|
|
|
userIds)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
// 过滤当前选中的分类和指标
|
|
|
conditionMap := map[string]dao.ExportPerformanceIndicator{}
|
|
|
conditionList := make([]dao.ExportPerformanceIndicator, 0)
|
|
|
for i := range list {
|
|
|
it := list[i]
|
|
|
if v, ok := selectedMap[it.TargetUserId]; ok {
|
|
|
v.UserName = it.TargetUserName
|
|
|
|
|
|
if v.Category == it.ContentCategory && v.Name == it.ContentName {
|
|
|
conditionList = append(conditionList, it)
|
|
|
conditionMap[it.TargetUserId+it.BeginDay] = it
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取的所有的日期行
|
|
|
rowDayMap := map[string]int{}
|
|
|
rowDayList := make([]string, 0)
|
|
|
for i := range conditionList {
|
|
|
it := conditionList[i]
|
|
|
if _, ok := rowDayMap[it.BeginDay]; !ok {
|
|
|
rowDayMap[it.BeginDay] = 0
|
|
|
rowDayList = append(rowDayList, it.BeginDay)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
sheetName := "个人绩效指标"
|
|
|
f := excelize.NewFile()
|
|
|
f.SetSheetName("Sheet1", sheetName)
|
|
|
|
|
|
f.SetCellStr(sheetName, "A1", in.Title)
|
|
|
f.SetRowHeight(sheetName, 1, 40) // 设置第1行高度
|
|
|
styleId1, _ := f.NewStyle(&excelize.Style{
|
|
|
Font: &excelize.Font{
|
|
|
Bold: true,
|
|
|
Size: 20,
|
|
|
Color: "#000000",
|
|
|
},
|
|
|
Alignment: &excelize.Alignment{
|
|
|
Horizontal: "center",
|
|
|
Vertical: "center",
|
|
|
},
|
|
|
})
|
|
|
f.SetCellStyle(sheetName, "A1", "A1", styleId1)
|
|
|
f.MergeCell(sheetName, "A1", "P1") // 合并第一行
|
|
|
|
|
|
f.SetCellStr(sheetName, "A2", "注:红色部分为林董标识:")
|
|
|
f.SetRowHeight(sheetName, 2, 22) // 设置第2行高度
|
|
|
styleId2, _ := f.NewStyle(&excelize.Style{
|
|
|
Font: &excelize.Font{
|
|
|
Size: 14,
|
|
|
Color: "#FF0000",
|
|
|
},
|
|
|
})
|
|
|
f.SetCellStyle(sheetName, "A2", "A2", styleId2)
|
|
|
|
|
|
// 内容居中自动换行样式
|
|
|
styleId100, _ := f.NewStyle(&excelize.Style{
|
|
|
Alignment: &excelize.Alignment{
|
|
|
Horizontal: "center",
|
|
|
Vertical: "center",
|
|
|
WrapText: true,
|
|
|
},
|
|
|
})
|
|
|
|
|
|
f.SetCellStr(sheetName, "A3", "日期")
|
|
|
for i := range rowDayList {
|
|
|
var rowIndex = 4 + (i * 3)
|
|
|
axisStart := fmt.Sprintf("A%d", rowIndex)
|
|
|
axisEnd := fmt.Sprintf("A%d", rowIndex+2)
|
|
|
|
|
|
f.SetCellStr(sheetName, axisStart, rowDayList[i]) // 设置日期
|
|
|
f.MergeCell(sheetName, axisStart, axisEnd) // 合并三行
|
|
|
f.SetCellStyle(sheetName, axisStart, axisEnd, styleId100)
|
|
|
}
|
|
|
|
|
|
var columnIndex = 'B'
|
|
|
for i := range in.Selected {
|
|
|
axis := fmt.Sprintf("%v3", string(columnIndex))
|
|
|
f.SetCellStr(sheetName, axis, in.Selected[i].UserName) // 设置名称
|
|
|
columnIndex += 1
|
|
|
}
|
|
|
|
|
|
// 填写反馈内容
|
|
|
for i := range rowDayList {
|
|
|
var columnIndex = 'B' // 从B4开始填充数据内容
|
|
|
var rowIndex = 4 + (i * 3)
|
|
|
|
|
|
for j := range in.Selected {
|
|
|
axisStart := fmt.Sprintf("%v%v", string(columnIndex), rowIndex)
|
|
|
axisEnd := fmt.Sprintf("%v%v", string(columnIndex), rowIndex+2)
|
|
|
|
|
|
key := in.Selected[j].UserId + rowDayList[i] // key = 用户ID+日期
|
|
|
if v, ok := conditionMap[key]; ok {
|
|
|
var builder strings.Builder
|
|
|
for _, r := range v.Remark {
|
|
|
builder.WriteString(r.RemarkText)
|
|
|
}
|
|
|
f.SetCellStr(sheetName, axisStart, builder.String()) // 设置反馈内容
|
|
|
}
|
|
|
f.MergeCell(sheetName, axisStart, axisEnd) // 合并三行
|
|
|
f.SetCellStyle(sheetName, axisStart, axisEnd, styleId100)
|
|
|
|
|
|
columnIndex += 1
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
|
|
|
return f, nil
|
|
|
} |
...
|
...
|
|