作者 tangxvhui

日常保存

@@ -5,10 +5,10 @@ import ( @@ -5,10 +5,10 @@ import (
5 "github.com/xuri/excelize/v2" 5 "github.com/xuri/excelize/v2"
6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query" 7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
  8 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
8 ) 9 )
9 10
10 -//数据导出  
11 - 11 +// 数据导出
12 func (srv *StaffAssessServeice) ExportUserAssess2V2(param *query.ExportUserAssess2Commad) (*excelize.File, error) { 12 func (srv *StaffAssessServeice) ExportUserAssess2V2(param *query.ExportUserAssess2Commad) (*excelize.File, error) {
13 transactionContext, err := factory.CreateTransactionContext(nil) 13 transactionContext, err := factory.CreateTransactionContext(nil)
14 if err != nil { 14 if err != nil {
@@ -20,18 +20,59 @@ func (srv *StaffAssessServeice) ExportUserAssess2V2(param *query.ExportUserAsses @@ -20,18 +20,59 @@ func (srv *StaffAssessServeice) ExportUserAssess2V2(param *query.ExportUserAsses
20 defer func() { 20 defer func() {
21 _ = transactionContext.RollbackTransaction() 21 _ = transactionContext.RollbackTransaction()
22 }() 22 }()
23 - // hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperatorId)  
24 - // if err != nil {  
25 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
26 - // }  
27 -  
28 - // 按照cycleId 获取项目  
29 -  
30 - // 按照项目获取指标项 23 + hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperatorId)
  24 + if err != nil {
  25 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  26 + }
  27 + assessDao := dao.NewStaffAssessDao(map[string]interface{}{
  28 + "transactionContext": transactionContext,
  29 + })
  30 + // 按照cycleId获取项目的指标项
  31 + evaluationItemList, err := assessDao.SearchEvaluationItemUsed2(param.CompanyId,
  32 + param.CycleId, param.OperatorId, hrbp, param.ExportUserId)
31 // 按照项目获取填写的内容 33 // 按照项目获取填写的内容
32 - 34 + assessContentList, err := assessDao.SearchEvaluationItemUsed2(param.CompanyId,
  35 + param.CycleId, param.OperatorId, hrbp, param.ExportUserId)
33 if err := transactionContext.CommitTransaction(); err != nil { 36 if err := transactionContext.CommitTransaction(); err != nil {
34 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 37 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
35 } 38 }
  39 +
36 return nil, nil 40 return nil, nil
37 } 41 }
  42 +
  43 +// 处理原始数据,方便进行 excel导出
  44 +type exportData3 struct {
  45 + sheetList []string //excel的sheet列表
  46 + tableHeader map[string]*HeaderLevel //表头数据
  47 +}
  48 +
  49 +func (e *exportData3) FormatTableHead(param []dao.DataEvaluationItemUsed2) {
  50 + userNameMap := map[string]struct{}{} //员工名字过滤
  51 + userProjcetMap := map[string]map[string]string{}
  52 + userIdName := map[string]string{} //员工id=> 员工名称
  53 + sheetMap := HeaderLevel{}
  54 + for _, val := range param {
  55 + // child := sheetMap.addChild(val.TargetUserId)
  56 + // _ = child.addChild(val.EvaluationProjectId)
  57 + if _, ok := userNameMap[val.TargetUserId]; !ok {
  58 + userProjcetMap[val.TargetUserId] = map[string]string{}
  59 + }
  60 + userProjcetMap[val.TargetUserId][val.EvaluationProjectId] = ""
  61 + if _, ok := userIdName[val.TargetUserId]; !ok {
  62 + userIdName[val.TargetUserId] = val.TargetUserName
  63 + userNameMap[val.TargetUserName] = struct{}{}
  64 + }
  65 + }
  66 +
  67 + for _, val := range sheetMap.Child {
  68 +
  69 + }
  70 +}
  71 +
  72 +func (e *exportData3) FormatListValue(param []dao.DataStaffAssessContent2) {
  73 +
  74 +}
  75 +
  76 +func (e *exportData3) DataKey(userName string, projectId string, beginDay string, category string, weight string, contentName string) string {
  77 + return ""
  78 +}
@@ -131,10 +131,6 @@ func (e *exportData) weightDesc(weight float64) string { @@ -131,10 +131,6 @@ func (e *exportData) weightDesc(weight float64) string {
131 } 131 }
132 } 132 }
133 133
134 -// func (e *exportData) userDayKey(userName string) string {  
135 -// return userName  
136 -// }  
137 -  
138 type exportData2 struct { 134 type exportData2 struct {
139 tableHeader HeaderLevel //数据表格对应表头 135 tableHeader HeaderLevel //数据表格对应表头
140 userIdMap map[string]string //员工id 对应的名称 136 userIdMap map[string]string //员工id 对应的名称
1 package dao 1 package dao
2 2
3 -// SearchStaffAssessByCycle 按照周期id获取评估任务,并进行人员可查看权限的过滤  
4 -// companyId 公司id 3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/go-pg/pg/v10"
  7 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  8 +)
  9 +
  10 +type DataStaffAssessContent2 struct {
  11 + CycleId string `pg:"cycle_id"` //周期id
  12 + CycleName string `pg:"cycle_name"` //周期名称
  13 + EvaluationProjectId string `pg:"evaluation_project_id"` //
  14 + TargetUserId string `pg:"target_user_id"` //被评估人的id
  15 + TargetUserName string `pg:"target_user_name"` //被评估人的名称
  16 + BeginDay string `pg:"begin_day"` //评估的日期
  17 + Value string `pg:"value"` //评估填写的值
  18 + Category string `pg:"category"` //评估项分类
  19 + ContentName string `pg:"content_name"` //评估项名称
  20 + Weight float64 `pg:"weight"` //权重
  21 + PromptText string `pg:"prompt_text"` //评估标准
  22 + Remark []domain.AssessContemtRemark `pg:"remark"`
  23 +}
  24 +
  25 +// SearchStaffAssessContent2 用于员工绩效-综合管理-导出绩效-个人
  26 +// 获取所有评估的填写内容
  27 +// companyId 公司id
5 // cycleId 周期id 28 // cycleId 周期id
6 // operaterId 操作人、查看人的id 29 // operaterId 操作人、查看人的id
7 // hrbp 操作人、查看人是否hrbp 1:是;-1:否 30 // hrbp 操作人、查看人是否hrbp 1:是;-1:否
8 -func (d *StaffAssessDao) SearchStaffAssessByCycle(companyId int, cycleId int, operaterId int, hrbp int, exportUserIds []string) { 31 +func (d *StaffAssessDao) SearchStaffAssessContent2(companyId int, cycleId int, operaterId int, hrbp int, exportUserIds []string) (
  32 + []DataStaffAssessContent2, error) {
  33 + withSql := d.catchProjectIdByPermission(companyId, cycleId, operaterId, hrbp)
  34 + sqlStr := ` select
  35 + staff_assess.target_user ->>'userId' as target_user_id,
  36 + staff_assess.evaluation_project_id,
  37 + staff_assess.target_user ->>'userName' as target_user_name,
  38 + to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day,
  39 + staff_assess.cycle_id,
  40 + staff_assess.cycle_name,
  41 + staff_assess_content.value ,
  42 + staff_assess_content.category ,
  43 + staff_assess_content."name" as content_name ,
  44 + staff_assess_content.weight,
  45 + staff_assess_content.prompt_text ,
  46 + staff_assess_content.remark
  47 +from staff_assess
  48 +join staff_assess_content on staff_assess.id = staff_assess_content.staff_assess_id
  49 +where 1=1
  50 +and staff_assess.cycle_id =? and "types" ='self'
  51 +and staff_assess.evaluation_project_id in (
  52 + select t_project_4.project_id from t_project_4
  53 +) `
  54 +
  55 + condition := []interface{}{cycleId}
  56 + if len(exportUserIds) > 0 {
  57 + sqlStr += ` and staff_assess.target_user->>'userId' in(?) `
  58 + condition = append(condition, pg.In(exportUserIds))
  59 + }
  60 +
  61 + sqlStr = withSql + sqlStr
  62 + result := []DataStaffAssessContent2{}
  63 + tx := d.transactionContext.PgTx
  64 + _, err := tx.Query(&result, sqlStr, condition...)
  65 + return result, err
  66 +}
9 67
  68 +type DataEvaluationItemUsed2 struct {
  69 + CycleId string `pg:"cycle_id"` //周期id
  70 + CycleName string `pg:"cycle_name"` //周期名称
  71 + EvaluationProjectId string `pg:"evaluation_project_id"` //评估的项目
  72 + TargetUserId string `pg:"target_user_id"` //被评估人的id
  73 + TargetUserName string `pg:"target_user_name"` //被评估人的名称
  74 + BeginDay string `pg:"begin_day"` //评估的日期
  75 + Category string `pg:"category"` //评估项分类
  76 + ContentName string `pg:"content_name"` //评估项名称
  77 + Weight float64 `pg:"weight"` //权重
  78 + PromptText string `pg:"prompt_text"` //评估标准
  79 +}
  80 +
  81 +// SearchEvaluationItemUsed2 用于员工绩效-综合管理-导出绩效-个人
  82 +// 获取所有评估的填写项
  83 +// companyId 公司id
  84 +// cycleId 周期id
  85 +// operaterId 操作人、查看人的id
  86 +// hrbp 操作人、查看人是否hrbp 1:是;-1:否
  87 +func (d *StaffAssessDao) SearchEvaluationItemUsed2(companyId int, cycleId int, operaterId int, hrbp int, exportUserIds []string) (
  88 + []DataEvaluationItemUsed2, error) {
  89 + withSql := d.catchProjectIdByPermission(companyId, cycleId, operaterId, hrbp)
  90 + sqlStr := `select
  91 + staff_assess.target_user ->>'userId' as target_user_id,
  92 + staff_assess.evaluation_project_id ,
  93 + staff_assess.target_user ->>'userName' as target_user_name,
  94 + to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day,
  95 + staff_assess.cycle_id,
  96 + staff_assess.cycle_name,
  97 + evaluation_item_used.category ,
  98 + evaluation_item_used."name" as content_name ,
  99 + evaluation_item_used.weight,
  100 + evaluation_item_used.prompt_text
  101 +from staff_assess
  102 +join evaluation_item_used on evaluation_item_used.evaluation_project_id = staff_assess.evaluation_project_id
  103 +where 1=1
  104 +and staff_assess.cycle_id =? and "types" ='self'
  105 +and staff_assess.evaluation_project_id in (
  106 + select evaluation_project.id from evaluation_project limit 10
  107 +) `
  108 + condition := []interface{}{cycleId}
  109 + if len(exportUserIds) > 0 {
  110 + sqlStr += ` and staff_assess.target_user->>'userId' in(?) `
  111 + condition = append(condition, pg.In(exportUserIds))
  112 + }
  113 + sqlStr = withSql + sqlStr
  114 + result := []DataEvaluationItemUsed2{}
  115 + tx := d.transactionContext.PgTx
  116 + _, err := tx.Query(&result, sqlStr, condition...)
  117 + return result, err
10 } 118 }
11 119
12 // sql 语句片段 120 // sql 语句片段
13 // 按照人员可查看权限的过滤 121 // 按照人员可查看权限的过滤
14 -func (d *StaffAssessDao) catchProjectByPermission(companyId int, cycleId int, operaterId int, hrbp int) string {  
15 - return "" 122 +// companyId int 公司id (必填)
  123 +// cycleId int, 评估周期id (必填)
  124 +// userId int, 用户id,谁要查看数据 (必填)
  125 +// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否 (必填)
  126 +func (d *StaffAssessDao) catchProjectIdByPermission(companyId int, cycleId int, operaterId int, hrbp int) string {
  127 + withSql := `
  128 + with
  129 + t_project_0 as(
  130 + select evaluation_project.id as project_id,
  131 + jsonb_array_elements_text(evaluation_project.recipients) as target_user_id,
  132 + evaluation_project.pmp,
  133 + evaluation_project.pmp_ids,
  134 + evaluation_project.hr_bp
  135 + from evaluation_project
  136 + where evaluation_project.cycle_id =%d
  137 + and evaluation_project.deleted_at isnull
  138 + ),
  139 + -- 查我的下级员工
  140 + t_user_1 as (
  141 + select "user".id::text as user_id from "user"
  142 + where "user".parent_id =%d and company_id=%d
  143 + ),
  144 + -- 如果是HRBP
  145 + t_project_1 as(
  146 + select t_project_0.project_id,t_project_0.target_user_id
  147 + from t_project_0
  148 + where t_project_0.hr_bp =%d
  149 + ),
  150 + -- 如果的项目管理员
  151 + t_project_2 as(
  152 + select t_project_0.project_id,t_project_0.target_user_id
  153 + from t_project_0
  154 + where t_project_0.pmp =1
  155 + and t_project_0.pmp_ids @>'["%d"]'
  156 + ),
  157 + -- 如果是上级员工
  158 + t_project_3 as (
  159 + select t_project_0.project_id,t_project_0.target_user_id
  160 + from t_project_0
  161 + join t_user_1 on t_user_1.user_id = t_project_0.target_user_id
  162 + ),
  163 + -- 合并数据
  164 + t_project_4 as (
  165 + select t_project_2.project_id,t_project_2.target_user_id from t_project_2
  166 + union
  167 + select t_project_1.project_id,t_project_1.target_user_id from t_project_1
  168 + union
  169 + select t_project_3.project_id,t_project_3.target_user_id from t_project_3
  170 + )`
  171 + params := []interface{}{cycleId, operaterId, companyId, hrbp, operaterId}
  172 +
  173 + return fmt.Sprintf(withSql, params...)
16 } 174 }