作者 Your Name

更新

  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "strings"
  6 +
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
  8 +)
  9 +
  10 +// 员工绩效-综合管理-导出绩效指标
  11 +
  12 +// excel表头部字段
  13 +type headerLevel struct {
  14 + Name string
  15 + Filter map[string]int
  16 + Child []headerLevel
  17 +}
  18 +
  19 +// 添加下一层级的字段
  20 +func (h *headerLevel) addChild(name string) (child *headerLevel) {
  21 + cIndex, ok := h.Filter[name]
  22 + if !ok {
  23 + h.Child = append(h.Child, headerLevel{
  24 + Name: name,
  25 + Filter: map[string]int{},
  26 + Child: []headerLevel{},
  27 + })
  28 + h.Filter[name] = len(h.Child) - 1
  29 + cIndex = h.Filter[name]
  30 + }
  31 + return &h.Child[cIndex]
  32 +}
  33 +
  34 +// 获取表头的所有列表名
  35 +func (h *headerLevel) collectAllColumn(all *[][]string) {
  36 + for _, v := range h.Child {
  37 + v.collectColumn(&v, all, nil)
  38 + }
  39 +}
  40 +
  41 +func (h *headerLevel) collectColumn(child *headerLevel, columns *[][]string, column *[]string) {
  42 + if column == nil {
  43 + column = &[]string{}
  44 + }
  45 + *column = append(*column, h.Name)
  46 + for _, v := range child.Child {
  47 + if len(v.Child) > 0 {
  48 + v.collectColumn(&v, columns, column)
  49 + }
  50 + if len(v.Child) == 0 {
  51 + item := make([]string, len(*column))
  52 + copy(item, *column)
  53 + item = append(item, v.Name)
  54 + *columns = append(*columns, item)
  55 + }
  56 + }
  57 +}
  58 +
  59 +type exportData struct {
  60 + userName []string //员工的名称列表 ,对应excel文件的多个sheet
  61 + usrIdMap map[string]string
  62 + userDayMap map[string][]string //每个员工对应的日期列表 key=员工名称 value= 日期列表
  63 + tableHeader map[string]*headerLevel //每个员工数据表格对应表头 key=员工名称
  64 + data map[string]*strings.Builder //每个员工表头对应的评估填写的数据 key=员工名称+日期+表头
  65 + data2 map[string]string //每个员工评估项的标准描述
  66 + data3 map[string]string //每个员工评估项的标准权重
  67 +}
  68 +
  69 +// 设置表格头部字段。和对应的员工列表
  70 +func (e *exportData) setCategoryNameList(param []dao.ContentCategoryName) {
  71 + for _, v := range param {
  72 + if _, ok := e.usrIdMap[v.TargetUserId]; !ok {
  73 + if _, ok := e.tableHeader[v.TargetUserName]; ok {
  74 + //出现重名,id不同但名称相同
  75 + uname := fmt.Sprintf("%s%d", v.TargetUserName, len(e.usrIdMap))
  76 + e.usrIdMap[v.TargetUserId] = uname
  77 + } else {
  78 + e.usrIdMap[v.TargetUserId] = v.TargetUserName
  79 + }
  80 + e.userName = append(e.userName, e.usrIdMap[v.TargetUserId])
  81 + }
  82 + userName := e.usrIdMap[v.TargetUserId]
  83 + if _, ok := e.tableHeader[userName]; !ok {
  84 + e.tableHeader[userName] = &headerLevel{
  85 + Name: "个人绩效评估等级统计表",
  86 + Filter: map[string]int{},
  87 + Child: []headerLevel{},
  88 + }
  89 + }
  90 + child := e.tableHeader[userName].addChild(v.Category) //第一级,"分类"
  91 + if v.Weight == 0 {
  92 + child = child.addChild("加分项") //第二级 '得分项' '加分项'
  93 + } else {
  94 + child = child.addChild("得分项") //第二级 '得分项' '加分项'
  95 + }
  96 + child.addChild(v.Name) //第三级 评估项名称
  97 + }
  98 +}
  99 +
  100 +func (e *exportData) setData(param []*dao.ExportData2) {
  101 + userName := ""
  102 + key := ""
  103 + userDay := map[string]struct{}{}
  104 + for _, v := range param {
  105 + //员工填写的评估内容
  106 + if _, ok := e.usrIdMap[v.TargetUserId]; !ok {
  107 + continue
  108 + }
  109 + userName = e.usrIdMap[v.TargetUserId]
  110 + if v.Weight == 0 {
  111 + key = fmt.Sprintf("%s-%s-加分项-%s-%s", userName, v.BeginDay, v.Category, v.ContentName)
  112 + e.data3[key] = ""
  113 + } else {
  114 + key = fmt.Sprintf("%s-%s-得分项-%s-%s", userName, v.BeginDay, v.Category, v.ContentName)
  115 + e.data3[key] = fmt.Sprintf("%.2f %%", v.Weight)
  116 + }
  117 + e.data[key] = &strings.Builder{}
  118 + e.data[key].WriteString(v.Value + "\n") //填写的等级
  119 + for _, vv := range v.Remark {
  120 + e.data[key].WriteString(vv.Definition + "\n")
  121 + e.data[key].WriteString(vv.RemarkText + "\n")
  122 + }
  123 + e.data2[key] = v.PromptText
  124 + if _, ok := userDay[userName+v.BeginDay]; !ok {
  125 + userDay[userName+v.BeginDay] = struct{}{}
  126 + e.userDayMap[userName] = append(e.userDayMap[userName], v.BeginDay)
  127 + }
  128 + }
  129 +}
@@ -615,11 +615,23 @@ func (srv StaffAssessServeice) ExportUserAssess2(param *query.SummaryCommand) (* @@ -615,11 +615,23 @@ func (srv StaffAssessServeice) ExportUserAssess2(param *query.SummaryCommand) (*
615 break 615 break
616 } 616 }
617 } 617 }
618 - assessDao := dao.NewStaffAssessDao(map[string]interface{}{  
619 - "transactionContext": transactionContext,  
620 - }) 618 + // assessDao := dao.NewStaffAssessDao(map[string]interface{}{
  619 + // "transactionContext": transactionContext,
  620 + // })
  621 + // 获取所有的评估项
  622 + // categoryNameList, err := assessDao.SearchContentCategoryName(param.CompanyId, param.CycleId, param.OperatorId, hrbp)
  623 + // if err != nil {
  624 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  625 + // }
  626 + // categoryNameTree := map[string]headerLevel{}
  627 + // userNameMap := map[string]struct{}{} //处理员工重名
  628 + // userIdMap := map[string]string{} //映射员工id和员工名称
  629 + // userNameList := []string{} //员工名称列表
621 if err := transactionContext.CommitTransaction(); err != nil { 630 if err := transactionContext.CommitTransaction(); err != nil {
622 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 631 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
623 } 632 }
  633 +
  634 + // tableHeader := excelTableHeader{}
  635 +
624 return nil, nil 636 return nil, nil
625 } 637 }
@@ -7,50 +7,3 @@ type excelTableHeader struct { @@ -7,50 +7,3 @@ type excelTableHeader struct {
7 Level3 string 7 Level3 string
8 Level4 string 8 Level4 string
9 } 9 }
10 -  
11 -// excel表头部字段  
12 -type HeaderLevel struct {  
13 - Name string  
14 - Filter map[string]int  
15 - Child []HeaderLevel  
16 -}  
17 -  
18 -// 添加下一层级的字段  
19 -func (h *HeaderLevel) AddChild(name string) (child *HeaderLevel) {  
20 - cIndex, ok := h.Filter[name]  
21 - if !ok {  
22 - h.Child = append(h.Child, HeaderLevel{  
23 - Name: name,  
24 - Filter: map[string]int{},  
25 - Child: []HeaderLevel{},  
26 - })  
27 - h.Filter[name] = len(h.Child) - 1  
28 - cIndex = h.Filter[name]  
29 - }  
30 - return &h.Child[cIndex]  
31 -}  
32 -  
33 -// 获取表头的所有列表名  
34 -func (h *HeaderLevel) CollectAllColumn(all *[][]string) {  
35 - for _, v := range h.Child {  
36 - v.collectColumn(&v, all, nil)  
37 - }  
38 -}  
39 -  
40 -func (h *HeaderLevel) collectColumn(child *HeaderLevel, columns *[][]string, column *[]string) {  
41 - if column == nil {  
42 - column = &[]string{}  
43 - }  
44 - *column = append(*column, h.Name)  
45 - for _, v := range child.Child {  
46 - if len(v.Child) > 0 {  
47 - v.collectColumn(&v, columns, column)  
48 - }  
49 - if len(v.Child) == 0 {  
50 - item := make([]string, len(*column))  
51 - copy(item, *column)  
52 - item = append(item, v.Name)  
53 - *columns = append(*columns, item)  
54 - }  
55 - }  
56 -}  
@@ -645,14 +645,14 @@ func (d *StaffAssessDao) CountAssessCycleMe(executorId int, companyId int) (int, @@ -645,14 +645,14 @@ func (d *StaffAssessDao) CountAssessCycleMe(executorId int, companyId int) (int,
645 645
646 // 评估的指标 646 // 评估的指标
647 type ContentCategoryName struct { 647 type ContentCategoryName struct {
648 - Category string //指标分类  
649 - Name string //指标名称  
650 - Weight string //指标权重  
651 - CycleId string //周期id  
652 - CycleName string //周期名称  
653 - TargetUserId string //评估的目标员工id  
654 - TargetUserName string //评估的目标员工名称  
655 - Cnt int //排序 648 + Category string //指标分类
  649 + Name string //指标名称
  650 + Weight float64 //指标权重
  651 + CycleId string //周期id
  652 + CycleName string //周期名称
  653 + TargetUserId string //评估的目标员工id
  654 + TargetUserName string //评估的目标员工名称
  655 + Cnt int //排序
656 } 656 }
657 657
658 // 员工绩效-综合管理-导出绩效指标 658 // 员工绩效-综合管理-导出绩效指标
@@ -710,7 +710,7 @@ type ExportData2 struct { @@ -710,7 +710,7 @@ type ExportData2 struct {
710 // cycleId int, 评估周期id 710 // cycleId int, 评估周期id
711 // userId int, 用户id,谁要查看数据 711 // userId int, 用户id,谁要查看数据
712 // hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否 712 // hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
713 -func (d *StaffAssessDao) ExportDataUserAssess2(companyId int, cycleId int, operaterId int, hrbp int) ([]ExportData1, error) { 713 +func (d *StaffAssessDao) ExportDataUserAssess2(companyId int, cycleId int, operaterId int, hrbp int) ([]*ExportData2, error) {
714 sqlStr := ` select 714 sqlStr := ` select
715 t_staff_assess_1.target_user_id, 715 t_staff_assess_1.target_user_id,
716 t_staff_assess_1.target_user_name, 716 t_staff_assess_1.target_user_name,
@@ -734,7 +734,7 @@ func (d *StaffAssessDao) ExportDataUserAssess2(companyId int, cycleId int, opera @@ -734,7 +734,7 @@ func (d *StaffAssessDao) ExportDataUserAssess2(companyId int, cycleId int, opera
734 sqlStr0 := d.useTStaffAssess(companyId, cycleId, operaterId, "", hrbp, 5000, 0, string(domain.AssessSelf)) 734 sqlStr0 := d.useTStaffAssess(companyId, cycleId, operaterId, "", hrbp, 5000, 0, string(domain.AssessSelf))
735 sqlStr = sqlStr0 + sqlStr 735 sqlStr = sqlStr0 + sqlStr
736 tx := d.transactionContext.PgTx 736 tx := d.transactionContext.PgTx
737 - var result []ExportData1 737 + result := []*ExportData2{}
738 _, err := tx.Query(&result, sqlStr, condition...) 738 _, err := tx.Query(&result, sqlStr, condition...)
739 return result, err 739 return result, err
740 } 740 }