作者 tangxvhui

更新查询

@@ -582,30 +582,108 @@ func (srv *StaffAssessServeice) ExportUserAssess(param *query.ExportAssessConten @@ -582,30 +582,108 @@ func (srv *StaffAssessServeice) ExportUserAssess(param *query.ExportAssessConten
582 582
583 // 根据周期id和日期获取 员工填写评估内容;项目管理-成员列表 583 // 根据周期id和日期获取 员工填写评估内容;项目管理-成员列表
584 // 有过滤查看权限 584 // 有过滤查看权限
585 -// func (srv StaffAssessServeice) ListUserAssessContentCycleDayV2(param *query.ListAssessContentCycleDay) (*adapter.ListUserAssessContent, error) {  
586 -// transactionContext, err := factory.CreateTransactionContext(nil)  
587 -// if err != nil {  
588 -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
589 -// }  
590 -// if err := transactionContext.StartTransaction(); err != nil {  
591 -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
592 -// }  
593 -// defer func() {  
594 -// _ = transactionContext.RollbackTransaction()  
595 -// }()  
596 -// hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperaterId)  
597 -// if err != nil {  
598 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
599 -// } 585 +func (srv StaffAssessServeice) ListUserAssessContentCycleDayV2(param *query.ListAssessContentCycleDay) (*adapter.ListUserAssessContent, error) {
  586 + transactionContext, err := factory.CreateTransactionContext(nil)
  587 + if err != nil {
  588 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  589 + }
  590 + if err := transactionContext.StartTransaction(); err != nil {
  591 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  592 + }
  593 + defer func() {
  594 + _ = transactionContext.RollbackTransaction()
  595 + }()
  596 + hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperaterId)
  597 + if err != nil {
  598 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  599 + }
  600 +
  601 + assessDao := dao.NewStaffAssessDao(map[string]interface{}{
  602 + "transactionContext": transactionContext,
  603 + })
600 604
601 -// assessDao := dao.NewStaffAssessDao(map[string]interface{}{  
602 -// "transactionContext": transactionContext,  
603 -// }) 605 + limit := param.PageSize
  606 + offset := (param.PageNumber - 1) * limit
  607 + if offset < 0 {
  608 + offset = 0
  609 + }
  610 + // 总数----------
  611 + cnt, err := assessDao.CountUserSelfStaffAssess(dao.SearchConditin3{
  612 + CompanyId: param.CompanyId,
  613 + CycleId: param.CycleId,
  614 + BeginDay: param.BeginDay,
  615 + TargetUserName: param.TargetUserName,
  616 + OperaterId: param.OperaterId,
  617 + Hrbp: hrbp,
  618 + Status: "",
  619 + })
  620 + if err != nil {
  621 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "统计总数"+err.Error())
  622 + }
  623 + contentList, err := assessDao.SearchUserAssessContentV2(dao.SearchConditin3{
  624 + CompanyId: param.CompanyId,
  625 + CycleId: param.CycleId,
  626 + BeginDay: param.BeginDay,
  627 + TargetUserName: param.TargetUserName,
  628 + Limit: limit,
  629 + Offset: offset,
  630 + OperaterId: param.OperaterId,
  631 + Hrbp: hrbp,
  632 + })
  633 + if err != nil {
  634 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取数据列表"+err.Error())
  635 + }
  636 + if err := transactionContext.CommitTransaction(); err != nil {
  637 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  638 + }
  639 + log.Logger.Debug(fmt.Sprintf("获取到的数据列表%d", len(contentList)))
  640 + //可变的表格列
  641 + changeableHeader := []adapter.ListTableHeader{
  642 + {Key: "targetUserName", Name: "姓名"}, //固定列
  643 + }
  644 + //过滤重复的列
  645 + headerMap := map[string]string{}
  646 + // 获取已经填报的内容
  647 + changeableRows := map[string]map[string]interface{}{}
  648 + tableSort := []string{} //确定列表行数据的顺序
  649 + for i, v := range contentList {
  650 + if _, ok := changeableRows[v.TargetUserId]; !ok {
  651 + changeableRows[v.TargetUserId] = map[string]interface{}{}
  652 + tableSort = append(tableSort, v.TargetUserId)
  653 + }
  654 + changeableRows[v.TargetUserId]["targetUserName"] = v.TargetUserName
  655 + changeableRows[v.TargetUserId]["targetUserId"] = v.TargetUserId
  656 + changeableRows[v.TargetUserId]["assessId"] = v.AssessId
  657 + changeableRows[v.TargetUserId]["cycleId"] = v.CycleId
  658 + changeableRows[v.TargetUserId]["beginDay"] = v.BeginDay
  659 + if v.ContentId > 0 {
  660 + name := fmt.Sprintf("%s-%s", v.Category, v.ContentName)
  661 + key := fmt.Sprintf("k%d", i)
  662 + if _, ok := headerMap[name]; !ok {
  663 + changeableHeader = append(changeableHeader, adapter.ListTableHeader{
  664 + Key: key, Name: name,
  665 + })
  666 + headerMap[name] = key
  667 + }
  668 + key = headerMap[name]
  669 + changeableRows[v.TargetUserId][key] = v.Value
  670 + }
  671 + }
  672 + list := []map[string]interface{}{}
  673 + for _, v := range tableSort {
  674 + for _, v2 := range changeableHeader {
  675 + if _, ok := changeableRows[v][v2.Key]; ok {
  676 + continue
  677 + }
  678 + changeableRows[v][v2.Key] = ""
  679 + }
  680 + list = append(list, changeableRows[v])
  681 + }
  682 + result := adapter.ListUserAssessContent{
  683 + TableHeader: changeableHeader,
  684 + Total: cnt,
  685 + List: list,
  686 + }
604 687
605 -// limit := param.PageSize  
606 -// offset := (param.PageNumber - 1) * limit  
607 -// if err := transactionContext.CommitTransaction(); err != nil {  
608 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
609 -// }  
610 -// return nil, nil  
611 -// } 688 + return &result, nil
  689 +}
@@ -330,7 +330,7 @@ type SearchConditin3 struct { @@ -330,7 +330,7 @@ type SearchConditin3 struct {
330 // hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否 330 // hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
331 // limit int, 分页条数 331 // limit int, 分页条数
332 // offset int 分页偏移 332 // offset int 分页偏移
333 -func (d *StaffAssessDao) SearchUserSelfStaffAssess(param SearchConditin3) ([]UserSelfStaffAssess, error) { 333 +func (d *StaffAssessDao) SearchUserAssessContentV2(param SearchConditin3) ([]UserAssessContent, error) {
334 withSql := d.catchProjectIdByPermission(param.CompanyId, param.CycleId, param.OperaterId, param.Hrbp) 334 withSql := d.catchProjectIdByPermission(param.CompanyId, param.CycleId, param.OperaterId, param.Hrbp)
335 sqlStr := `select 335 sqlStr := `select
336 staff_assess.cycle_id , 336 staff_assess.cycle_id ,
@@ -363,9 +363,27 @@ func (d *StaffAssessDao) SearchUserSelfStaffAssess(param SearchConditin3) ([]Use @@ -363,9 +363,27 @@ func (d *StaffAssessDao) SearchUserSelfStaffAssess(param SearchConditin3) ([]Use
363 condition = append(condition, param.Limit, param.Offset) 363 condition = append(condition, param.Limit, param.Offset)
364 sqlStr += ` order by convert_to(staff_assess.target_user ->>'userName','GBK') limit ? offset ? ` 364 sqlStr += ` order by convert_to(staff_assess.target_user ->>'userName','GBK') limit ? offset ? `
365 365
366 - sqlStr2 := withSql + withSql 366 + withSql2 := withSql + `,t_staff_assess_1 as( ` + sqlStr + ` )`
  367 + sqlStr2 := `select
  368 + t_staff_assess_1.target_user_id,
  369 + t_staff_assess_1.target_user_name,
  370 + t_staff_assess_1.begin_day,
  371 + t_staff_assess_1.assess_id,
  372 + t_staff_assess_1.cycle_id,
  373 + staff_assess_content.id as content_id,
  374 + staff_assess_content.value ,
  375 + evaluation_item_used.sort_by ,
  376 + evaluation_item_used.category ,
  377 + evaluation_item_used."name" as content_name ,
  378 + evaluation_item_used.weight,
  379 + staff_assess_content.level_value,
  380 + evaluation_item_used."rule"
  381 + from t_staff_assess_1
  382 + left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
  383 + where 1=1`
  384 + sqlStr2 = withSql2 + sqlStr2
367 tx := d.transactionContext.PgTx 385 tx := d.transactionContext.PgTx
368 - var result []UserSelfStaffAssess 386 + var result []UserAssessContent
369 _, err := tx.Query(&result, sqlStr2, condition...) 387 _, err := tx.Query(&result, sqlStr2, condition...)
370 return result, err 388 return result, err
371 } 389 }