作者 tangxvhui

日常保存

@@ -206,13 +206,6 @@ func (srv StaffAssessServeice) ListUserAssessContentCycleDay(param *query.ListAs @@ -206,13 +206,6 @@ func (srv StaffAssessServeice) ListUserAssessContentCycleDay(param *query.ListAs
206 return &result, nil 206 return &result, nil
207 } 207 }
208 208
209 -type excelTableHeader struct {  
210 - Level1 string  
211 - Level2 string  
212 - Level3 string  
213 - Level4 string  
214 -}  
215 -  
216 func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCycleDay) (*excelize.File, error) { 209 func (srv StaffAssessServeice) ExportUserAssess(param *query.ListAssessContentCycleDay) (*excelize.File, error) {
217 transactionContext, err := factory.CreateTransactionContext(nil) 210 transactionContext, err := factory.CreateTransactionContext(nil)
218 if err != nil { 211 if err != nil {
@@ -577,3 +570,56 @@ func (srv StaffAssessServeice) AnalysisData(param *query.ListAssessContentCycleD @@ -577,3 +570,56 @@ func (srv StaffAssessServeice) AnalysisData(param *query.ListAssessContentCycleD
577 } 570 }
578 return &result, nil 571 return &result, nil
579 } 572 }
  573 +
  574 +func (srv StaffAssessServeice) ExportUserAssess2(param *query.SummaryCommand) (*excelize.File, error) {
  575 + transactionContext, err := factory.CreateTransactionContext(nil)
  576 + if err != nil {
  577 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  578 + }
  579 + if err := transactionContext.StartTransaction(); err != nil {
  580 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  581 + }
  582 + defer func() {
  583 + _ = transactionContext.RollbackTransaction()
  584 + }()
  585 +
  586 + roleRepo := factory.CreateRoleRepository(map[string]interface{}{
  587 + "transactionContext": transactionContext,
  588 + })
  589 + roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{
  590 + "transactionContext": transactionContext,
  591 + })
  592 + _, roleList, err := roleRepo.Find(map[string]interface{}{
  593 + "type": domain.RoleTypeSystem,
  594 + "companyId": param.CompanyId,
  595 + })
  596 + if err != nil {
  597 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
  598 + }
  599 + _, userRoleList, err := roleUserRepo.Find(map[string]interface{}{
  600 + "companyId": param.CompanyId,
  601 + "userId": param.OperatorId,
  602 + })
  603 + if err != nil {
  604 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
  605 + }
  606 + hrbp := -1
  607 + for _, v := range userRoleList {
  608 + for _, v2 := range roleList {
  609 + if v.RoleId == v2.Id {
  610 + hrbp = 1
  611 + break
  612 + }
  613 + }
  614 + if hrbp == 1 {
  615 + break
  616 + }
  617 + }
  618 + assessDao := dao.NewStaffAssessDao(map[string]interface{}{
  619 + "transactionContext": transactionContext,
  620 + })
  621 + if err := transactionContext.CommitTransaction(); err != nil {
  622 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  623 + }
  624 + return nil, nil
  625 +}
  1 +package service
  2 +
  3 +// excel表头部字段
  4 +type excelTableHeader struct {
  5 + Level1 string
  6 + Level2 string
  7 + Level3 string
  8 + Level4 string
  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 +}
@@ -209,7 +209,6 @@ type UserAssessContent struct { @@ -209,7 +209,6 @@ type UserAssessContent struct {
209 209
210 type SearchConditin1 struct { 210 type SearchConditin1 struct {
211 CompanyId int //公司id 211 CompanyId int //公司id
212 - AssessId int //评估任务id  
213 CycleId int //周期id 212 CycleId int //周期id
214 BeginDay string //评估的日期 213 BeginDay string //评估的日期
215 TargetUserName string //被评估人的名称 214 TargetUserName string //被评估人的名称
@@ -289,14 +288,14 @@ func (d *StaffAssessDao) CountUserAssess(param SearchConditin1) (int, error) { @@ -289,14 +288,14 @@ func (d *StaffAssessDao) CountUserAssess(param SearchConditin1) (int, error) {
289 } 288 }
290 289
291 // 生成的sql 根据用户的查看权限 ,获取可查看的评估任务, 290 // 生成的sql 根据用户的查看权限 ,获取可查看的评估任务,
292 -// companyId int 公司id  
293 -// cycleId int, 评估周期id  
294 -// userId int, 用户id,谁要查看数据  
295 -// beginDay string, 周期中执行项目的时间  
296 -// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否  
297 -// limit int, 分页条数  
298 -// offset int 分页偏移  
299 -// assessType string 评估的类型 291 +// companyId int 公司id (必填)
  292 +// cycleId int, 评估周期id (必填)
  293 +// userId int, 用户id,谁要查看数据 (必填)
  294 +// beginDay string, 周期中执行项目的时间 (选填)
  295 +// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否 (必填)
  296 +// limit int, 分页条数 (必填)
  297 +// offset int 分页偏移 (必填)
  298 +// assessType string 评估的类型 (选填)
300 func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, beginDay string, hrbp int, limit int, offset int, assessType string) string { 299 func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, beginDay string, hrbp int, limit int, offset int, assessType string) string {
301 sqlstr := ` 300 sqlstr := `
302 set time zone 'PRC'; 301 set time zone 'PRC';
@@ -340,6 +339,7 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, @@ -340,6 +339,7 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int,
340 t_staff_assess_0 as ( 339 t_staff_assess_0 as (
341 select staff_assess.id as assess_id, 340 select staff_assess.id as assess_id,
342 staff_assess.cycle_id, 341 staff_assess.cycle_id,
  342 + staff_assess.cycle_name,
343 staff_assess.target_user->>'userId' as target_user_id, 343 staff_assess.target_user->>'userId' as target_user_id,
344 staff_assess.target_user->>'userName' as target_user_name, 344 staff_assess.target_user->>'userName' as target_user_name,
345 to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day, 345 to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day,
@@ -348,8 +348,8 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, @@ -348,8 +348,8 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int,
348 join staff_assess_task on staff_assess.staff_assess_task_id = staff_assess_task.id 348 join staff_assess_task on staff_assess.staff_assess_task_id = staff_assess_task.id
349 and staff_assess_task.deleted_at isnull 349 and staff_assess_task.deleted_at isnull
350 where staff_assess.cycle_id = %d 350 where staff_assess.cycle_id = %d
351 - and to_char(staff_assess.begin_time,'YYYY-MM-DD')='%s'  
352 - and staff_assess."types" ='%s' 351 + %s
  352 + -- 根据条件拼接查询条件
353 ), 353 ),
354 -- 根据查看权限过滤合并数据 354 -- 根据查看权限过滤合并数据
355 t_staff_assess_1 as ( 355 t_staff_assess_1 as (
@@ -357,6 +357,7 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, @@ -357,6 +357,7 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int,
357 t_staff_assess_0.target_user_id, 357 t_staff_assess_0.target_user_id,
358 t_staff_assess_0.target_user_name, 358 t_staff_assess_0.target_user_name,
359 t_staff_assess_0.begin_day, 359 t_staff_assess_0.begin_day,
  360 + t_staff_assess_0.cycle_name,
360 t_staff_assess_0.cycle_id 361 t_staff_assess_0.cycle_id
361 from t_staff_assess_0 362 from t_staff_assess_0
362 join t_project_3 on t_staff_assess_0.evaluation_project_id = t_project_3.project_id 363 join t_project_3 on t_staff_assess_0.evaluation_project_id = t_project_3.project_id
@@ -364,6 +365,7 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, @@ -364,6 +365,7 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int,
364 t_staff_assess_0.target_user_id, 365 t_staff_assess_0.target_user_id,
365 t_staff_assess_0.target_user_name, 366 t_staff_assess_0.target_user_name,
366 t_staff_assess_0.begin_day, 367 t_staff_assess_0.begin_day,
  368 + t_staff_assess_0.cycle_name,
367 t_staff_assess_0.cycle_id 369 t_staff_assess_0.cycle_id
368 from t_staff_assess_0 370 from t_staff_assess_0
369 join t_user_1 on t_staff_assess_0.target_user_id=t_user_1.user_id 371 join t_user_1 on t_staff_assess_0.target_user_id=t_user_1.user_id
@@ -371,10 +373,25 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, @@ -371,10 +373,25 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int,
371 limit %d offset %d 373 limit %d offset %d
372 ) 374 )
373 ` 375 `
  376 + //根据条件拼接查询条件
  377 + staffAssessWhere := map[string]string{
  378 + "beginDay": ` and to_char(staff_assess.begin_time,'YYYY-MM-DD') like '%s' `,
  379 + "assessType": ` and staff_assess."types" ='%s' `,
  380 + }
374 params := []interface{}{ 381 params := []interface{}{
375 - companyId, userId, cycleId, hrbp, cycleId, userId, cycleId, beginDay, assessType, limit, offset, 382 + companyId, userId, cycleId, hrbp, cycleId, userId, cycleId,
376 } 383 }
377 384
  385 + if len(beginDay) > 0 {
  386 + str := fmt.Sprintf(staffAssessWhere["beginDay"]+"\n", beginDay)
  387 + params = append(params, str)
  388 + }
  389 +
  390 + if len(assessType) > 0 {
  391 + str := fmt.Sprintf(staffAssessWhere["assessType"]+"\n", assessType)
  392 + params = append(params, str)
  393 + }
  394 + params = append(params, limit, offset)
378 sqlstr = fmt.Sprintf(sqlstr, params...) 395 sqlstr = fmt.Sprintf(sqlstr, params...)
379 return sqlstr 396 return sqlstr
380 } 397 }
@@ -505,6 +522,8 @@ func (d *StaffAssessDao) SummaryAssess(companyId int, operatorId int, cycleId in @@ -505,6 +522,8 @@ func (d *StaffAssessDao) SummaryAssess(companyId int, operatorId int, cycleId in
505 type ExportData1 struct { 522 type ExportData1 struct {
506 AssessId string 523 AssessId string
507 ContentId int 524 ContentId int
  525 + CycleId string //周期id
  526 + CycleName string //周期名称
508 TargetUserId string //被评估人的id 527 TargetUserId string //被评估人的id
509 TargetUserName string //被评估人的名称 528 TargetUserName string //被评估人的名称
510 BeginDay string //评估的日期 529 BeginDay string //评估的日期
@@ -527,11 +546,20 @@ func (d *StaffAssessDao) ExportDataUserAssess(param SearchConditin1) ([]ExportDa @@ -527,11 +546,20 @@ func (d *StaffAssessDao) ExportDataUserAssess(param SearchConditin1) ([]ExportDa
527 param.Limit = 5000 546 param.Limit = 5000
528 } 547 }
529 sqlStr := ` select 548 sqlStr := ` select
530 - t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day,  
531 - t_staff_assess_1.assess_id,staff_assess_content.id as content_id,  
532 - staff_assess_content.value ,staff_assess_content.sort_by ,  
533 - staff_assess_content.category ,staff_assess_content."name" as content_name ,  
534 - staff_assess_content.weight,staff_assess_content.prompt_text ,staff_assess_content.remark 549 + t_staff_assess_1.target_user_id,
  550 + t_staff_assess_1.target_user_name,
  551 + t_staff_assess_1.begin_day,
  552 + t_staff_assess_1.assess_id,
  553 + t_staff_assess_1.cycle_id,
  554 + t_staff_assess_1.cycle_name,
  555 + staff_assess_content.id as content_id,
  556 + staff_assess_content.value ,
  557 + staff_assess_content.sort_by ,
  558 + staff_assess_content.category ,
  559 + staff_assess_content."name" as content_name ,
  560 + staff_assess_content.weight,
  561 + staff_assess_content.prompt_text ,
  562 + staff_assess_content.remark
535 from t_staff_assess_1 563 from t_staff_assess_1
536 left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id 564 left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
537 where 1=1 565 where 1=1
@@ -614,3 +642,99 @@ func (d *StaffAssessDao) CountAssessCycleMe(executorId int, companyId int) (int, @@ -614,3 +642,99 @@ func (d *StaffAssessDao) CountAssessCycleMe(executorId int, companyId int) (int,
614 _, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...) 642 _, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...)
615 return result, err 643 return result, err
616 } 644 }
  645 +
  646 +// 评估的指标
  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 //排序
  656 +}
  657 +
  658 +// 员工绩效-综合管理-导出绩效指标
  659 +// 抽取出评估的指标
  660 +func (d *StaffAssessDao) SearchContentCategoryName(companyId int, cycleId int, userId int, hrbp int) ([]ContentCategoryName, error) {
  661 + sqlStr := `
  662 + select
  663 + staff_assess_content.category,
  664 + staff_assess_content."name" ,
  665 + staff_assess_content.weight ,
  666 + staff_assess.cycle_id ,
  667 + staff_assess.cycle_name,
  668 + t_staff_assess_1.target_user_id,
  669 + t_staff_assess_1.target_user_name,
  670 + sum(
  671 + case
  672 + when staff_assess_content.value isnull then 0
  673 + when staff_assess_content.value='' then 0
  674 + ELSE 1
  675 + END) as cnt
  676 + from staff_assess_content
  677 + join t_staff_assess_1 on staff_assess_content.staff_assess_id = t_staff_assess_1.id
  678 + group by staff_assess_content.category,
  679 + staff_assess_content."name" ,
  680 + staff_assess.cycle_id ,
  681 + staff_assess.cycle_name,
  682 + staff_assess_content.weight ,
  683 + target_user_id,target_user_name
  684 + order by cnt desc,user_id
  685 + `
  686 + sqlStr0 := d.useTStaffAssess(companyId, cycleId, userId, "", hrbp, 0, 5000, string(domain.AssessSelf))
  687 + sqlStr = sqlStr0 + sqlStr
  688 + tx := d.transactionContext.PgTx
  689 + result := []ContentCategoryName{}
  690 + _, err := tx.Query(&result, sqlStr)
  691 + return result, err
  692 +}
  693 +
  694 +type ExportData2 struct {
  695 + CycleId string `pg:"cycle_id"` //周期id
  696 + CycleName string `pg:"cycle_name"` //周期名称
  697 + TargetUserId string `pg:"target_user_id"` //被评估人的id
  698 + TargetUserName string `pg:"target_user_name"` //被评估人的名称
  699 + BeginDay string `pg:"begin_day"` //评估的日期
  700 + Value string `pg:"value"` //评估填写的值
  701 + Category string `pg:"category"` //评估项分类
  702 + ContentName string `pg:"content_name"` //评估项名称
  703 + Weight float64 `pg:"weight"` //权重
  704 + PromptText string `pg:"prompt_text"` //评估标准
  705 + Remark []domain.AssessContemtRemark `pg:"remark"`
  706 +}
  707 +
  708 +// 员工绩效-综合管理-导出绩效指标
  709 +// companyId int 公司id
  710 +// cycleId int, 评估周期id
  711 +// userId int, 用户id,谁要查看数据
  712 +// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
  713 +func (d *StaffAssessDao) ExportDataUserAssess2(companyId int, cycleId int, operaterId int, hrbp int) ([]ExportData1, error) {
  714 + sqlStr := ` select
  715 + t_staff_assess_1.target_user_id,
  716 + t_staff_assess_1.target_user_name,
  717 + t_staff_assess_1.begin_day,
  718 + t_staff_assess_1.cycle_id,
  719 + t_staff_assess_1.cycle_name,
  720 + staff_assess_content.value ,
  721 + staff_assess_content.category ,
  722 + staff_assess_content."name" as content_name ,
  723 + staff_assess_content.weight,
  724 + staff_assess_content.prompt_text ,
  725 + staff_assess_content.remark
  726 + from t_staff_assess_1
  727 + left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
  728 + where 1=1
  729 + `
  730 + condition := []interface{}{}
  731 + //加入排序
  732 + sqlStr += ` order by t_staff_assess_1.begin_day`
  733 + //获取前置sql语句
  734 + sqlStr0 := d.useTStaffAssess(companyId, cycleId, operaterId, "", hrbp, 5000, 0, string(domain.AssessSelf))
  735 + sqlStr = sqlStr0 + sqlStr
  736 + tx := d.transactionContext.PgTx
  737 + var result []ExportData1
  738 + _, err := tx.Query(&result, sqlStr, condition...)
  739 + return result, err
  740 +}