作者 Your Name

更新

package service
import (
"fmt"
"strings"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
)
// 员工绩效-综合管理-导出绩效指标
// excel表头部字段
type headerLevel struct {
Name string
Filter map[string]int
Child []headerLevel
}
// 添加下一层级的字段
func (h *headerLevel) addChild(name string) (child *headerLevel) {
cIndex, ok := h.Filter[name]
if !ok {
h.Child = append(h.Child, headerLevel{
Name: name,
Filter: map[string]int{},
Child: []headerLevel{},
})
h.Filter[name] = len(h.Child) - 1
cIndex = h.Filter[name]
}
return &h.Child[cIndex]
}
// 获取表头的所有列表名
func (h *headerLevel) collectAllColumn(all *[][]string) {
for _, v := range h.Child {
v.collectColumn(&v, all, nil)
}
}
func (h *headerLevel) collectColumn(child *headerLevel, columns *[][]string, column *[]string) {
if column == nil {
column = &[]string{}
}
*column = append(*column, h.Name)
for _, v := range child.Child {
if len(v.Child) > 0 {
v.collectColumn(&v, columns, column)
}
if len(v.Child) == 0 {
item := make([]string, len(*column))
copy(item, *column)
item = append(item, v.Name)
*columns = append(*columns, item)
}
}
}
type exportData struct {
userName []string //员工的名称列表 ,对应excel文件的多个sheet
usrIdMap map[string]string
userDayMap map[string][]string //每个员工对应的日期列表 key=员工名称 value= 日期列表
tableHeader map[string]*headerLevel //每个员工数据表格对应表头 key=员工名称
data map[string]*strings.Builder //每个员工表头对应的评估填写的数据 key=员工名称+日期+表头
data2 map[string]string //每个员工评估项的标准描述
data3 map[string]string //每个员工评估项的标准权重
}
// 设置表格头部字段。和对应的员工列表
func (e *exportData) setCategoryNameList(param []dao.ContentCategoryName) {
for _, v := range param {
if _, ok := e.usrIdMap[v.TargetUserId]; !ok {
if _, ok := e.tableHeader[v.TargetUserName]; ok {
//出现重名,id不同但名称相同
uname := fmt.Sprintf("%s%d", v.TargetUserName, len(e.usrIdMap))
e.usrIdMap[v.TargetUserId] = uname
} else {
e.usrIdMap[v.TargetUserId] = v.TargetUserName
}
e.userName = append(e.userName, e.usrIdMap[v.TargetUserId])
}
userName := e.usrIdMap[v.TargetUserId]
if _, ok := e.tableHeader[userName]; !ok {
e.tableHeader[userName] = &headerLevel{
Name: "个人绩效评估等级统计表",
Filter: map[string]int{},
Child: []headerLevel{},
}
}
child := e.tableHeader[userName].addChild(v.Category) //第一级,"分类"
if v.Weight == 0 {
child = child.addChild("加分项") //第二级 '得分项' '加分项'
} else {
child = child.addChild("得分项") //第二级 '得分项' '加分项'
}
child.addChild(v.Name) //第三级 评估项名称
}
}
func (e *exportData) setData(param []*dao.ExportData2) {
userName := ""
key := ""
userDay := map[string]struct{}{}
for _, v := range param {
//员工填写的评估内容
if _, ok := e.usrIdMap[v.TargetUserId]; !ok {
continue
}
userName = e.usrIdMap[v.TargetUserId]
if v.Weight == 0 {
key = fmt.Sprintf("%s-%s-加分项-%s-%s", userName, v.BeginDay, v.Category, v.ContentName)
e.data3[key] = ""
} else {
key = fmt.Sprintf("%s-%s-得分项-%s-%s", userName, v.BeginDay, v.Category, v.ContentName)
e.data3[key] = fmt.Sprintf("%.2f %%", v.Weight)
}
e.data[key] = &strings.Builder{}
e.data[key].WriteString(v.Value + "\n") //填写的等级
for _, vv := range v.Remark {
e.data[key].WriteString(vv.Definition + "\n")
e.data[key].WriteString(vv.RemarkText + "\n")
}
e.data2[key] = v.PromptText
if _, ok := userDay[userName+v.BeginDay]; !ok {
userDay[userName+v.BeginDay] = struct{}{}
e.userDayMap[userName] = append(e.userDayMap[userName], v.BeginDay)
}
}
}
... ...
... ... @@ -615,11 +615,23 @@ func (srv StaffAssessServeice) ExportUserAssess2(param *query.SummaryCommand) (*
break
}
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
// assessDao := dao.NewStaffAssessDao(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// 获取所有的评估项
// categoryNameList, err := assessDao.SearchContentCategoryName(param.CompanyId, param.CycleId, param.OperatorId, hrbp)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// categoryNameTree := map[string]headerLevel{}
// userNameMap := map[string]struct{}{} //处理员工重名
// userIdMap := map[string]string{} //映射员工id和员工名称
// userNameList := []string{} //员工名称列表
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// tableHeader := excelTableHeader{}
return nil, nil
}
... ...
... ... @@ -7,50 +7,3 @@ type excelTableHeader struct {
Level3 string
Level4 string
}
// excel表头部字段
type HeaderLevel struct {
Name string
Filter map[string]int
Child []HeaderLevel
}
// 添加下一层级的字段
func (h *HeaderLevel) AddChild(name string) (child *HeaderLevel) {
cIndex, ok := h.Filter[name]
if !ok {
h.Child = append(h.Child, HeaderLevel{
Name: name,
Filter: map[string]int{},
Child: []HeaderLevel{},
})
h.Filter[name] = len(h.Child) - 1
cIndex = h.Filter[name]
}
return &h.Child[cIndex]
}
// 获取表头的所有列表名
func (h *HeaderLevel) CollectAllColumn(all *[][]string) {
for _, v := range h.Child {
v.collectColumn(&v, all, nil)
}
}
func (h *HeaderLevel) collectColumn(child *HeaderLevel, columns *[][]string, column *[]string) {
if column == nil {
column = &[]string{}
}
*column = append(*column, h.Name)
for _, v := range child.Child {
if len(v.Child) > 0 {
v.collectColumn(&v, columns, column)
}
if len(v.Child) == 0 {
item := make([]string, len(*column))
copy(item, *column)
item = append(item, v.Name)
*columns = append(*columns, item)
}
}
}
... ...
... ... @@ -647,7 +647,7 @@ func (d *StaffAssessDao) CountAssessCycleMe(executorId int, companyId int) (int,
type ContentCategoryName struct {
Category string //指标分类
Name string //指标名称
Weight string //指标权重
Weight float64 //指标权重
CycleId string //周期id
CycleName string //周期名称
TargetUserId string //评估的目标员工id
... ... @@ -710,7 +710,7 @@ type ExportData2 struct {
// cycleId int, 评估周期id
// userId int, 用户id,谁要查看数据
// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
func (d *StaffAssessDao) ExportDataUserAssess2(companyId int, cycleId int, operaterId int, hrbp int) ([]ExportData1, error) {
func (d *StaffAssessDao) ExportDataUserAssess2(companyId int, cycleId int, operaterId int, hrbp int) ([]*ExportData2, error) {
sqlStr := ` select
t_staff_assess_1.target_user_id,
t_staff_assess_1.target_user_name,
... ... @@ -734,7 +734,7 @@ func (d *StaffAssessDao) ExportDataUserAssess2(companyId int, cycleId int, opera
sqlStr0 := d.useTStaffAssess(companyId, cycleId, operaterId, "", hrbp, 5000, 0, string(domain.AssessSelf))
sqlStr = sqlStr0 + sqlStr
tx := d.transactionContext.PgTx
var result []ExportData1
result := []*ExportData2{}
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
... ...