作者 tangxvhui
@@ -39,7 +39,7 @@ type EvaluationItemAdapter struct { @@ -39,7 +39,7 @@ type EvaluationItemAdapter struct {
39 Score string `json:"score"` //计算的评定得分 39 Score string `json:"score"` //计算的评定得分
40 Remark string `json:"remark"` //填写的内容反馈 40 Remark string `json:"remark"` //填写的内容反馈
41 EvaluatorId int `json:"evaluatorId"` //评估人id 41 EvaluatorId int `json:"evaluatorId"` //评估人id
42 - // 42 + EvaluatorName string `json:"evaluatorName"` //评估人名称
43 } 43 }
44 44
45 // 评级数量 45 // 评级数量
  1 +package adapter
  2 +
  3 +type TableHeader struct {
  4 + Key string `json:"key"`
  5 + Name string `json:"name"`
  6 +}
  7 +
  8 +type SummaryEvaluationAdapter struct {
  9 + TableHeader []TableHeader `json:"tableHeader"`
  10 + List []map[string]interface{} `json:"list"`
  11 + Total int `json:"total"`
  12 +}
  13 +
  14 +type SummaryEvaluationHRBPAdapter struct {
  15 + Id int `json:"id"` // 周期评估ID
  16 + TargetUserId int `json:"targetUserId"` // 目标用户ID
  17 + TargetUserName string `json:"targetUserName"` // 目标用户名称
  18 + Department string `json:"departmentVal"` // 部门(拼接文本)
  19 + Position string `json:"positionVal"` // 职位(拼接文本)
  20 + DutyTime string `json:"dutyTime"` // 入职时间(2006-01-02 15:04)
  21 + Status string `json:"statusVal"` // 完成状态(拼接文本)
  22 + EndTime string `json:"endTime"` // 截止时间(2006-01-02 15:04)
  23 + OverdueCount int `json:"overdueCount"` // 自评逾期次数
  24 +}
@@ -13,13 +13,19 @@ type QueryEvaluation struct { @@ -13,13 +13,19 @@ type QueryEvaluation struct {
13 } 13 }
14 14
15 type QueryEvaluation360 struct { 15 type QueryEvaluation360 struct {
16 - SummaryEvaluationId int `json:"summaryEvaluationId,string"` 16 + //SummaryEvaluationId int `json:"summaryEvaluationId,string"`
  17 + CycleId int `json:"cycleId,string"` // 周期ID
  18 + TargetUserId int `json:"targetUserId,string"` // 目标人ID
  19 + CompanyId int `json:"-"` // 公司ID
17 UserId int `json:"-"` // 用户ID 20 UserId int `json:"-"` // 用户ID
18 } 21 }
19 22
20 type QueryEvaluationHRBP struct { 23 type QueryEvaluationHRBP struct {
21 - SummaryEvaluationId int `json:"summaryEvaluationId,string"`  
22 - UserId int `json:"-"` // 用户ID 24 + //SummaryEvaluationId int `json:"summaryEvaluationId,string"`
  25 + //UserId int `json:"-"` // 用户ID
  26 + CycleId int `json:"cycleId,string"` // 周期ID
  27 + TargetUserId int `json:"targetUserId,string"` // 目标人ID
  28 + CompanyId int `json:"-"` // 公司ID
23 } 29 }
24 30
25 // 获取上级评估详情 31 // 获取上级评估详情
  1 +package command
  2 +
  3 +// QueryEvaluation360List 360综评列表
  4 +type QueryEvaluation360List struct {
  5 + CycleId int `cname:"周期ID" json:"cycleId,string" valid:"Required"`
  6 + PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
  7 + PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
  8 + SearchName string `cname:"用户名称" json:"searchName"`
  9 + CompanyId int `cname:"公司ID" json:"-"`
  10 + UserId int `cname:"用户ID" json:"-"`
  11 +}
  12 +
  13 +// QueryEvaluationHRList 人资综评列表
  14 +type QueryEvaluationHRList struct {
  15 + CycleId int `cname:"周期ID" json:"cycleId,string" valid:"Required"`
  16 + PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
  17 + PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
  18 + SearchName string `cname:"用户名称" json:"searchName"`
  19 + CompanyId int `cname:"公司ID" json:"-"`
  20 + UserId int `cname:"用户ID" json:"-"`
  21 +}
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "fmt"
4 "github.com/linmadan/egglib-go/core/application" 5 "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
5 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
6 service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role" 8 service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/adapter" 9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/adapter"
8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command" 10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 11 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  12 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
  13 + "strings"
10 "time" 14 "time"
11 ) 15 )
12 16
13 -// GetEvaluation360 获取360综评详情 17 +// Evaluation360List 获取360综评列表
  18 +func (srv *SummaryEvaluationService) Evaluation360List(param *command.QueryEvaluation360List) (*adapter.SummaryEvaluationAdapter, error) {
  19 + transactionContext, err := factory.ValidateStartTransaction(param)
  20 + if err != nil {
  21 + return nil, err
  22 + }
  23 + defer func() {
  24 + _ = transactionContext.RollbackTransaction()
  25 + }()
  26 +
  27 + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
  28 + evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
  29 + itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
  30 +
  31 + var searchTargetName string
  32 + if len(param.SearchName) > 0 {
  33 + searchTargetName = "%" + param.SearchName + "%"
  34 + } else {
  35 + searchTargetName = ""
  36 + }
  37 + limit := param.PageSize
  38 + offset := limit * (param.PageNumber - 1)
  39 + if offset < 0 {
  40 + offset = 0
  41 + }
  42 + count, list, err := evaluationRepo.Find(map[string]interface{}{
  43 + "companyId": param.CompanyId,
  44 + "cycleId": param.CycleId,
  45 + "executorId": param.UserId,
  46 + "types": domain.Evaluation360,
  47 + "targetUserName": searchTargetName,
  48 + "limit": limit,
  49 + "offset": offset,
  50 + })
  51 + if err != nil {
  52 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  53 + }
  54 +
  55 + ids := make([]int, 0)
  56 + projectIds := make([]int, 0)
  57 + for i := range list {
  58 + ids = append(ids, list[i].Id)
  59 + projectIds = append(projectIds, list[i].EvaluationProjectId)
  60 + }
  61 +
  62 + // 固定列
  63 + changeableHeader := []adapter.TableHeader{
  64 + {Key: "targetUserName", Name: "姓名"},
  65 + {Key: "statusVal", Name: "状态"},
  66 + {Key: "relation", Name: "360°评估关系"},
  67 + {Key: "endTime", Name: "360°评估截止日期"},
  68 + }
  69 + changeableRowMap := map[int]map[string]interface{}{} // k,v(用户ID -> 数据集合)行数据内容
  70 + itemMap := map[int][]*domain.EvaluationItemUsed{} // k,v(项目ID -> 评估数组)归类评估内容
  71 + valueMap := map[string]*domain.SummaryEvaluationValue{} // k,v(周期+评估 -> 提交值)
  72 + uniqueColumnsMap := map[string]string{} // 列名称唯一
  73 +
  74 + if len(ids) > 0 {
  75 + // 评估内容(注.使用自评模板,并过滤出360综评人的评估内容)
  76 + _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{"evaluationProjectIds": projectIds, "node_type": domain.LinkNodeSelfAssessment, "evaluatorId": param.UserId})
  77 + if err != nil {
  78 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  79 + }
  80 + // 填写值
  81 + _, valueList, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationIdList": ids})
  82 + if err != nil {
  83 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  84 + }
  85 +
  86 + if err := transactionContext.CommitTransaction(); err != nil {
  87 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  88 + }
  89 +
  90 + for i := range valueList {
  91 + key := fmt.Sprintf("%d-%d", valueList[i].SummaryEvaluationId, valueList[i].EvaluationItemId)
  92 + valueMap[key] = valueList[i]
  93 + }
  94 +
  95 + for i := range itemList {
  96 + item := itemList[i]
  97 + key := fmt.Sprintf("k%d", i)
  98 + name := fmt.Sprintf("%s-%s", item.Category, item.Name)
  99 + if _, ok := uniqueColumnsMap[name]; !ok {
  100 + changeableHeader = append(changeableHeader, adapter.TableHeader{Key: key, Name: name})
  101 + uniqueColumnsMap[name] = key
  102 + }
  103 +
  104 + if pList, ok := itemMap[item.EvaluationProjectId]; !ok {
  105 + pList = make([]*domain.EvaluationItemUsed, 0)
  106 + itemMap[item.EvaluationProjectId] = pList
  107 + } else {
  108 + pList = append(pList, item)
  109 + }
  110 + }
  111 + }
  112 +
  113 + now := time.Now().Local() // 当前时间
  114 + var rowMap map[string]interface{}
  115 + for i := range list {
  116 + v := list[i]
  117 + if rm, ok := changeableRowMap[v.TargetUser.UserId]; ok {
  118 + rowMap = rm
  119 + } else {
  120 + rowMap = map[string]interface{}{}
  121 + changeableRowMap[v.TargetUser.UserId] = rowMap
  122 + }
  123 +
  124 + endTime := v.EndTime.Local()
  125 + statusVal := ""
  126 + if v.Status == domain.EvaluationCompleted {
  127 + statusVal = "已完成"
  128 + } else {
  129 + if now.After(endTime) {
  130 + statusVal = "已逾期"
  131 + } else {
  132 + statusVal = "待完成"
  133 + }
  134 + }
  135 + rowMap["id"] = v.Id
  136 + rowMap["targetUserName"] = v.TargetUser.UserName
  137 + rowMap["statusVal"] = statusVal
  138 + rowMap["relation"] = "项目组员"
  139 + rowMap["endTime"] = endTime.Format("2006-01-02 15:04")
  140 +
  141 + // 当前项目所有评估内容
  142 + if pList, ok := itemMap[v.EvaluationProjectId]; ok {
  143 + for _, item := range pList {
  144 + name := fmt.Sprintf("%s-%s", item.Category, item.Name)
  145 + if key, ok := uniqueColumnsMap[name]; ok { // 动态列用name -> key
  146 + valueKey := fmt.Sprintf("%d-%d", v.Id, item.Id)
  147 + if it, ok := valueMap[valueKey]; ok {
  148 + rowMap[key] = it.Score
  149 + } else {
  150 + rowMap[key] = ""
  151 + }
  152 + }
  153 + }
  154 + }
  155 + }
  156 +
  157 + targetList := make([]map[string]interface{}, 0)
  158 + for _, v1 := range list {
  159 + rowMap := changeableRowMap[v1.TargetUser.UserId]
  160 + for _, v2 := range changeableHeader { // 填充部分动态列缺失字段
  161 + if _, ok := rowMap[v2.Key]; !ok {
  162 + rowMap[v2.Key] = ""
  163 + }
  164 + }
  165 + targetList = append(targetList, rowMap)
  166 + }
  167 + result := &adapter.SummaryEvaluationAdapter{
  168 + TableHeader: changeableHeader,
  169 + Total: count,
  170 + List: targetList,
  171 + }
  172 + return result, nil
  173 +}
  174 +
  175 +// GetEvaluation360 获取360综评详情(登录人作为评估人,评估内容)
14 func (srv *SummaryEvaluationService) GetEvaluation360(param *command.QueryEvaluation360) (*adapter.EvaluationInfoAdapter, error) { 176 func (srv *SummaryEvaluationService) GetEvaluation360(param *command.QueryEvaluation360) (*adapter.EvaluationInfoAdapter, error) {
15 transactionContext, err := factory.ValidateStartTransaction(param) 177 transactionContext, err := factory.ValidateStartTransaction(param)
16 if err != nil { 178 if err != nil {
@@ -24,12 +186,26 @@ func (srv *SummaryEvaluationService) GetEvaluation360(param *command.QueryEvalua @@ -24,12 +186,26 @@ func (srv *SummaryEvaluationService) GetEvaluation360(param *command.QueryEvalua
24 evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext}) 186 evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
25 itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext}) 187 itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
26 188
27 - sEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId}) 189 + //sEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
  190 + //if err != nil {
  191 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  192 + //}
  193 + _, evaluations, err := evaluationRepo.Find(map[string]interface{}{
  194 + "limit": 1,
  195 + "companyId": param.CompanyId,
  196 + "cycleId": param.CycleId,
  197 + "targetUserId": param.TargetUserId,
  198 + "types": domain.Evaluation360},
  199 + )
28 if err != nil { 200 if err != nil {
29 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 201 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
30 } 202 }
  203 + if len(evaluations) == 0 {
  204 + return nil, application.ThrowError(application.BUSINESS_ERROR, "数据不存在")
  205 + }
  206 + sEvaluation := evaluations[0]
31 207
32 - // 自评评估内容(自评模板、筛选项目评估人) 208 + // 360评估内容(自评模板、筛选项目评估人)
33 _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{ 209 _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
34 "evaluationProjectId": sEvaluation.EvaluationProjectId, 210 "evaluationProjectId": sEvaluation.EvaluationProjectId,
35 "nodeType": domain.LinkNodeSelfAssessment, 211 "nodeType": domain.LinkNodeSelfAssessment,
@@ -67,6 +243,98 @@ func (srv *SummaryEvaluationService) GetEvaluation360(param *command.QueryEvalua @@ -67,6 +243,98 @@ func (srv *SummaryEvaluationService) GetEvaluation360(param *command.QueryEvalua
67 return &result, nil 243 return &result, nil
68 } 244 }
69 245
  246 +// GetEvaluation360All 获取360综评详情-上级综评(所有的评估人,评估内容)
  247 +func (srv *SummaryEvaluationService) GetEvaluation360All(param *command.QueryEvaluation360) (*adapter.EvaluationInfoAdapter, error) {
  248 + transactionContext, err := factory.ValidateStartTransaction(param)
  249 + if err != nil {
  250 + return nil, err
  251 + }
  252 + defer func() {
  253 + _ = transactionContext.RollbackTransaction()
  254 + }()
  255 +
  256 + userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
  257 + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
  258 + evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
  259 + itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
  260 + _, evaluations, err := evaluationRepo.Find(map[string]interface{}{
  261 + "limit": 1,
  262 + "companyId": param.CompanyId,
  263 + "cycleId": param.CycleId,
  264 + "targetUserId": param.TargetUserId,
  265 + "types": domain.Evaluation360},
  266 + )
  267 + if err != nil {
  268 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  269 + }
  270 + if len(evaluations) == 0 {
  271 + return nil, application.ThrowError(application.BUSINESS_ERROR, "数据不存在")
  272 + }
  273 + sEvaluation := evaluations[0]
  274 +
  275 + // 360评估内容(自评模板)
  276 + _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
  277 + "evaluationProjectId": sEvaluation.EvaluationProjectId,
  278 + "nodeType": domain.LinkNodeSelfAssessment,
  279 + })
  280 + if err != nil {
  281 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  282 + }
  283 +
  284 + // 评估内容对应的分数
  285 + _, itemValues, err := itemValueRepo.Find(map[string]interface{}{"summaryEvaluationId": sEvaluation.Id})
  286 + if err != nil {
  287 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  288 + }
  289 +
  290 + // 评估人ID -> User
  291 + evaluatorMap := map[int]*domain.User{}
  292 + evaluatorIds := make([]int, 0)
  293 + filterItemList := make([]*domain.EvaluationItemUsed, 0) // 筛选有评估人的评估内容
  294 + for i := range itemList {
  295 + if itemList[i].EvaluatorId > 0 {
  296 + filterItemList = append(filterItemList, itemList[i])
  297 + evaluatorIds = append(evaluatorIds, itemList[i].EvaluatorId)
  298 + }
  299 + }
  300 + if len(evaluatorIds) > 0 {
  301 + _, users, err := userRepo.Find(map[string]interface{}{"ids": evaluatorIds})
  302 + if err != nil {
  303 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  304 + }
  305 + for i := range users {
  306 + evaluatorMap[int(users[i].Id)] = users[i]
  307 + }
  308 + }
  309 +
  310 + if err := transactionContext.CommitTransaction(); err != nil {
  311 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  312 + }
  313 +
  314 + itemValuesAdapter := srv.buildSummaryItemValue(filterItemList, itemValues)
  315 + for i := range itemValuesAdapter { // 评估人名称赋值
  316 + if user, ok := evaluatorMap[itemValuesAdapter[i].EvaluatorId]; ok {
  317 + itemValuesAdapter[i].EvaluatorName = user.Name
  318 + }
  319 + }
  320 +
  321 + result := adapter.EvaluationInfoAdapter{
  322 + SummaryEvaluationId: sEvaluation.Id,
  323 + CycleId: int(sEvaluation.CycleId),
  324 + CycleName: sEvaluation.CycleName,
  325 + EvaluationProjectId: sEvaluation.EvaluationProjectId,
  326 + EvaluationProjectName: sEvaluation.EvaluationProjectName,
  327 + LinkNodeId: sEvaluation.NodeId,
  328 + BeginTime: sEvaluation.BeginTime.Format("2006-01-02 15:04:05"),
  329 + EndTime: sEvaluation.EndTime.Format("2006-01-02 15:04:05"),
  330 + TargetUserId: sEvaluation.TargetUser.UserId,
  331 + TargetUserName: sEvaluation.TargetUser.UserName,
  332 + Status: string(sEvaluation.Status),
  333 + EvaluationItems: itemValuesAdapter,
  334 + }
  335 + return &result, nil
  336 +}
  337 +
70 // EditEvaluation360 编辑提交360综评 338 // EditEvaluation360 编辑提交360综评
71 func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) { 339 func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvaluationValue) (map[string][]adapter.EvaluationItemAdapter, error) {
72 transactionContext, err := factory.CreateTransactionContext(nil) 340 transactionContext, err := factory.CreateTransactionContext(nil)
@@ -166,6 +434,162 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua @@ -166,6 +434,162 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua
166 }, nil 434 }, nil
167 } 435 }
168 436
  437 +// EvaluationHRBPList 获取人资综评列表
  438 +func (srv *SummaryEvaluationService) EvaluationHRBPList(param *command.QueryEvaluationHRList) (map[string]interface{}, error) {
  439 + transactionContext, err := factory.ValidateStartTransaction(param)
  440 + if err != nil {
  441 + return nil, err
  442 + }
  443 + defer func() {
  444 + _ = transactionContext.RollbackTransaction()
  445 + }()
  446 +
  447 + // 必须是HRBP权限的人才能编辑操作
  448 + hrbp, err := service.GetHRBP(transactionContext, param.CompanyId, param.UserId)
  449 + if hrbp != 1 {
  450 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有操作权限")
  451 + }
  452 +
  453 + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
  454 + staffAssessDaoRepo := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
  455 + userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
  456 + positionRepo := factory.CreatePositionRepository(map[string]interface{}{"transactionContext": transactionContext})
  457 + var searchTargetName string
  458 + if len(param.SearchName) > 0 {
  459 + searchTargetName = "%" + param.SearchName + "%"
  460 + } else {
  461 + searchTargetName = ""
  462 + }
  463 + limit := param.PageSize
  464 + offset := limit * (param.PageNumber - 1)
  465 + if offset < 0 {
  466 + offset = 0
  467 + }
  468 + count, list, err := evaluationRepo.Find(map[string]interface{}{
  469 + "companyId": param.CompanyId,
  470 + "cycleId": param.CycleId,
  471 + "executorId": -1,
  472 + "types": domain.EvaluationHrbp,
  473 + "targetUserName": searchTargetName,
  474 + "limit": limit,
  475 + "offset": offset,
  476 + })
  477 + if err != nil {
  478 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  479 + }
  480 +
  481 + userIds := make([]int, 0)
  482 + positionIds := make([]int, 0)
  483 + projectIds := make([]int, 0)
  484 + projectCountMap := map[string]int{} // 自评逾期数量
  485 + userMap := map[int64]*domain.User{} // 用户
  486 + positionMap := map[int64]*domain.Position{} // 职位
  487 +
  488 + for i := range list {
  489 + it := list[i]
  490 + userIds = append(userIds, it.TargetUser.UserId)
  491 + projectIds = append(projectIds, list[i].EvaluationProjectId)
  492 + }
  493 + _, users, err := userRepo.Find(map[string]interface{}{"ids": userIds, "companyId": param.CompanyId})
  494 + if err != nil {
  495 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  496 + }
  497 + for i := range users {
  498 + userMap[users[i].Id] = users[i]
  499 + for _, pid := range users[i].PositionId {
  500 + positionIds = append(positionIds, pid)
  501 + }
  502 + }
  503 + _, positions, err := positionRepo.Find(map[string]interface{}{"ids": positionIds, "companyId": param.CompanyId})
  504 + if err != nil {
  505 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  506 + }
  507 + for i := range positions {
  508 + positionMap[positions[i].Id] = positions[i]
  509 + }
  510 +
  511 + if len(projectIds) > 0 {
  512 + targetCount, err := staffAssessDaoRepo.CountUncompletedSelfAssess(param.CompanyId, projectIds)
  513 + if err != nil {
  514 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  515 + }
  516 + for i := range targetCount {
  517 + key := fmt.Sprintf("%d-%d", targetCount[i].EvaluationProjectId, targetCount[i].TargetUserId)
  518 + projectCountMap[key] = targetCount[i].Cnt
  519 + }
  520 + }
  521 +
  522 + now := time.Now().Local() // 当前时间
  523 + resultList := make([]*adapter.SummaryEvaluationHRBPAdapter, 0)
  524 + for i := range list {
  525 + v := list[i]
  526 + endTime := v.EndTime.Local()
  527 + // 状态
  528 + statusVal := ""
  529 + if v.Status == domain.EvaluationCompleted {
  530 + statusVal = "已完成"
  531 + } else {
  532 + if now.After(endTime) {
  533 + statusVal = "已逾期"
  534 + } else {
  535 + statusVal = "待完成"
  536 + }
  537 + }
  538 +
  539 + // 部门拼接
  540 + var departmentBuild strings.Builder
  541 + departmentBuild.WriteString("")
  542 + for i2 := range v.TargetDepartment {
  543 + departmentBuild.WriteString(v.TargetDepartment[i2].DepartmentName)
  544 + if i2 != len(v.TargetDepartment)-1 {
  545 + departmentBuild.WriteString(",")
  546 + }
  547 + }
  548 + // 入职时间
  549 + entryTime := ""
  550 + // 职位拼接
  551 + var positionBuild strings.Builder
  552 + positionBuild.WriteString("")
  553 + if user, ok := userMap[int64(v.TargetUser.UserId)]; ok {
  554 + for i2 := range user.PositionId {
  555 + if position, ok := positionMap[int64(user.PositionId[i2])]; ok {
  556 + positionBuild.WriteString(position.Name)
  557 + if i2 != len(user.PositionId)-1 {
  558 + departmentBuild.WriteString(",")
  559 + }
  560 + }
  561 + }
  562 + entryTime = user.EntryTime
  563 + }
  564 +
  565 + // 自评逾期数量
  566 + overdueCount := 0
  567 + key := fmt.Sprintf("%d-%d", v.EvaluationProjectId, v.TargetUser.UserId)
  568 + if cnt, ok := projectCountMap[key]; ok {
  569 + overdueCount = cnt
  570 + }
  571 +
  572 + result := &adapter.SummaryEvaluationHRBPAdapter{
  573 + Id: v.Id,
  574 + TargetUserId: v.TargetUser.UserId,
  575 + TargetUserName: v.TargetUser.UserName,
  576 + Department: departmentBuild.String(),
  577 + Position: positionBuild.String(),
  578 + DutyTime: entryTime,
  579 + Status: statusVal,
  580 + EndTime: endTime.Format("2006-01-02 15:04"),
  581 + OverdueCount: overdueCount,
  582 + }
  583 + resultList = append(resultList, result)
  584 + }
  585 +
  586 + if err := transactionContext.CommitTransaction(); err != nil {
  587 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  588 + }
  589 +
  590 + return tool_funs.SimpleWrapGridMap(int64(count), resultList), nil
  591 +}
  592 +
169 // GetEvaluationHRBP 获取人资综评详情 593 // GetEvaluationHRBP 获取人资综评详情
170 func (srv *SummaryEvaluationService) GetEvaluationHRBP(param *command.QueryEvaluationHRBP) (*adapter.EvaluationInfoAdapter, error) { 594 func (srv *SummaryEvaluationService) GetEvaluationHRBP(param *command.QueryEvaluationHRBP) (*adapter.EvaluationInfoAdapter, error) {
171 transactionContext, err := factory.ValidateStartTransaction(param) 595 transactionContext, err := factory.ValidateStartTransaction(param)
@@ -180,10 +604,21 @@ func (srv *SummaryEvaluationService) GetEvaluationHRBP(param *command.QueryEvalu @@ -180,10 +604,21 @@ func (srv *SummaryEvaluationService) GetEvaluationHRBP(param *command.QueryEvalu
180 evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext}) 604 evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
181 itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext}) 605 itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
182 606
183 - sEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId}) 607 + _, evaluations, err := evaluationRepo.Find(map[string]interface{}{
  608 + "limit": 1,
  609 + "companyId": param.CompanyId,
  610 + "cycleId": param.CycleId,
  611 + "targetUserId": param.TargetUserId,
  612 + "types": domain.EvaluationHrbp},
  613 + )
  614 + // sEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
184 if err != nil { 615 if err != nil {
185 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 616 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
186 } 617 }
  618 + if len(evaluations) == 0 {
  619 + return nil, application.ThrowError(application.BUSINESS_ERROR, "数据不存在")
  620 + }
  621 + sEvaluation := evaluations[0]
187 622
188 // 自评评估内容(自评模板、筛选项目评估人) 623 // 自评评估内容(自评模板、筛选项目评估人)
189 _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{ 624 _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
@@ -1223,3 +1223,33 @@ group by level_value,category,"name" ` @@ -1223,3 +1223,33 @@ group by level_value,category,"name" `
1223 _, err := tx.Query(&result, sqlStr, condition...) 1223 _, err := tx.Query(&result, sqlStr, condition...)
1224 return result, err 1224 return result, err
1225 } 1225 }
  1226 +
  1227 +type CountUncompletedSelfAssess struct {
  1228 + EvaluationProjectId int
  1229 + TargetUserId int
  1230 + Cnt int
  1231 +}
  1232 +
  1233 +// CountUncompletedSelfAssess 统计整个项目周期内,相关人自评未完成数量
  1234 +func (d *StaffAssessDao) CountUncompletedSelfAssess(companyId int, projectIds []int) ([]CountUncompletedSelfAssess, error) {
  1235 + sqlStr := `
  1236 + SELECT
  1237 + staff_assess.evaluation_project_id,
  1238 + staff_assess.target_user ->> 'userId' AS target_user_id,
  1239 + COUNT ( staff_assess.ID ) AS cnt
  1240 + FROM
  1241 + staff_assess
  1242 + WHERE
  1243 + staff_assess.company_id = ?
  1244 + AND staff_assess.types = 'self'
  1245 + AND staff_assess.evaluation_project_id IN (?)
  1246 + AND staff_assess.status = 'uncompleted'
  1247 + GROUP BY
  1248 + evaluation_project_id, target_user_id`
  1249 +
  1250 + condition := []interface{}{companyId, pg.In(projectIds)}
  1251 + tx := d.transactionContext.PgTx
  1252 + result := make([]CountUncompletedSelfAssess, 0)
  1253 + _, err := tx.Query(&result, sqlStr, condition...)
  1254 + return result, err
  1255 +}
1 package repository 1 package repository
2 2
3 import ( 3 import (
  4 + "github.com/go-pg/pg/v10"
4 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
5 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models" 7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
@@ -84,6 +85,10 @@ func (repo *EvaluationItemUsedRepository) Find(queryOptions map[string]interface @@ -84,6 +85,10 @@ func (repo *EvaluationItemUsedRepository) Find(queryOptions map[string]interface
84 query.Where("evaluation_project_id=?", v) 85 query.Where("evaluation_project_id=?", v)
85 } 86 }
86 87
  88 + if v, ok := queryOptions["evaluationProjectIds"]; ok {
  89 + query.Where("evaluation_project_id in(?)", pg.In(v))
  90 + }
  91 +
87 if v, ok := queryOptions["nodeType"]; ok { 92 if v, ok := queryOptions["nodeType"]; ok {
88 query.Where("node_type=?", v) 93 query.Where("node_type=?", v)
89 } 94 }
@@ -128,6 +128,10 @@ func (repo *SummaryEvaluationRepository) Find(queryOptions map[string]interface{ @@ -128,6 +128,10 @@ func (repo *SummaryEvaluationRepository) Find(queryOptions map[string]interface{
128 query.Offset(v) 128 query.Offset(v)
129 } 129 }
130 130
  131 + if v, ok := queryOptions["companyId"]; ok {
  132 + query.Where("company_id=?", v)
  133 + }
  134 +
131 if v, ok := queryOptions["types"]; ok { 135 if v, ok := queryOptions["types"]; ok {
132 query.Where("types=?", v) 136 query.Where("types=?", v)
133 } 137 }
@@ -96,6 +96,40 @@ func (c *SummaryEvaluationController) GetTargetUserCycleList() { @@ -96,6 +96,40 @@ func (c *SummaryEvaluationController) GetTargetUserCycleList() {
96 c.Response(data, err) 96 c.Response(data, err)
97 } 97 }
98 98
  99 +// CountEvaluationSelfLevel 获取自评小结
  100 +func (c *SummaryEvaluationController) CountEvaluationSelfLevel() {
  101 + srv := service.NewSummaryEvaluationService()
  102 + paramReq := &command.QueryEvaluation{}
  103 + err := c.BindJSON(paramReq)
  104 + if err != nil {
  105 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  106 + c.Response(nil, e)
  107 + return
  108 + }
  109 + userReq := middlewares.GetUser(c.Ctx)
  110 + paramReq.UserId = int(userReq.UserId)
  111 + paramReq.CompanyId = int(userReq.CompanyId)
  112 + data, err := srv.CountEvaluationSelfLevel(paramReq)
  113 + c.Response(data, err)
  114 +
  115 +}
  116 +
  117 +func (c *SummaryEvaluationController) Evaluation360List() {
  118 + srv := service.NewSummaryEvaluationService()
  119 + in := &command.QueryEvaluation360List{}
  120 + err := c.BindJSON(in)
  121 + if err != nil {
  122 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  123 + c.Response(nil, e)
  124 + return
  125 + }
  126 + userReq := middlewares.GetUser(c.Ctx)
  127 + in.CompanyId = int(userReq.CompanyId)
  128 + in.UserId = int(userReq.UserId)
  129 + data, err := srv.Evaluation360List(in)
  130 + c.Response(data, err)
  131 +}
  132 +
99 func (c *SummaryEvaluationController) GetEvaluation360() { 133 func (c *SummaryEvaluationController) GetEvaluation360() {
100 srv := service.NewSummaryEvaluationService() 134 srv := service.NewSummaryEvaluationService()
101 in := &command.QueryEvaluation360{} 135 in := &command.QueryEvaluation360{}
@@ -106,27 +140,26 @@ func (c *SummaryEvaluationController) GetEvaluation360() { @@ -106,27 +140,26 @@ func (c *SummaryEvaluationController) GetEvaluation360() {
106 return 140 return
107 } 141 }
108 userReq := middlewares.GetUser(c.Ctx) 142 userReq := middlewares.GetUser(c.Ctx)
  143 + in.CompanyId = int(userReq.CompanyId)
109 in.UserId = int(userReq.UserId) 144 in.UserId = int(userReq.UserId)
110 data, err := srv.GetEvaluation360(in) 145 data, err := srv.GetEvaluation360(in)
111 c.Response(data, err) 146 c.Response(data, err)
112 } 147 }
113 148
114 -// CountEvaluationSelfLevel 获取自评小结  
115 -func (c *SummaryEvaluationController) CountEvaluationSelfLevel() { 149 +func (c *SummaryEvaluationController) GetEvaluation360All() {
116 srv := service.NewSummaryEvaluationService() 150 srv := service.NewSummaryEvaluationService()
117 - paramReq := &command.QueryEvaluation{}  
118 - err := c.BindJSON(paramReq) 151 + in := &command.QueryEvaluation360{}
  152 + err := c.BindJSON(in)
119 if err != nil { 153 if err != nil {
120 e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error()) 154 e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
121 c.Response(nil, e) 155 c.Response(nil, e)
122 return 156 return
123 } 157 }
124 userReq := middlewares.GetUser(c.Ctx) 158 userReq := middlewares.GetUser(c.Ctx)
125 - paramReq.UserId = int(userReq.UserId)  
126 - paramReq.CompanyId = int(userReq.CompanyId)  
127 - data, err := srv.CountEvaluationSelfLevel(paramReq) 159 + in.CompanyId = int(userReq.CompanyId)
  160 + in.UserId = int(userReq.UserId)
  161 + data, err := srv.GetEvaluation360All(in)
128 c.Response(data, err) 162 c.Response(data, err)
129 -  
130 } 163 }
131 164
132 func (c *SummaryEvaluationController) EditEvaluation360() { 165 func (c *SummaryEvaluationController) EditEvaluation360() {
@@ -145,6 +178,22 @@ func (c *SummaryEvaluationController) EditEvaluation360() { @@ -145,6 +178,22 @@ func (c *SummaryEvaluationController) EditEvaluation360() {
145 c.Response(data, err) 178 c.Response(data, err)
146 } 179 }
147 180
  181 +func (c *SummaryEvaluationController) EvaluationHRBPList() {
  182 + srv := service.NewSummaryEvaluationService()
  183 + in := &command.QueryEvaluationHRList{}
  184 + err := c.BindJSON(in)
  185 + if err != nil {
  186 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  187 + c.Response(nil, e)
  188 + return
  189 + }
  190 + userReq := middlewares.GetUser(c.Ctx)
  191 + in.CompanyId = int(userReq.CompanyId)
  192 + in.UserId = int(userReq.UserId)
  193 + data, err := srv.EvaluationHRBPList(in)
  194 + c.Response(data, err)
  195 +}
  196 +
148 func (c *SummaryEvaluationController) GetEvaluationHRBP() { 197 func (c *SummaryEvaluationController) GetEvaluationHRBP() {
149 srv := service.NewSummaryEvaluationService() 198 srv := service.NewSummaryEvaluationService()
150 in := &command.QueryEvaluationHRBP{} 199 in := &command.QueryEvaluationHRBP{}
@@ -155,7 +204,8 @@ func (c *SummaryEvaluationController) GetEvaluationHRBP() { @@ -155,7 +204,8 @@ func (c *SummaryEvaluationController) GetEvaluationHRBP() {
155 return 204 return
156 } 205 }
157 userReq := middlewares.GetUser(c.Ctx) 206 userReq := middlewares.GetUser(c.Ctx)
158 - in.UserId = int(userReq.UserId) 207 + //in.UserId = int(userReq.UserId)
  208 + in.CompanyId = int(userReq.CompanyId)
159 data, err := srv.GetEvaluationHRBP(in) 209 data, err := srv.GetEvaluationHRBP(in)
160 c.Response(data, err) 210 c.Response(data, err)
161 } 211 }
@@ -16,9 +16,12 @@ func init() { @@ -16,9 +16,12 @@ func init() {
16 web.NSCtrlPost("/evaluation-self", (*controllers.SummaryEvaluationController).GetEvaluationSelf), 16 web.NSCtrlPost("/evaluation-self", (*controllers.SummaryEvaluationController).GetEvaluationSelf),
17 web.NSCtrlPost("/evaluation-self/edit", (*controllers.SummaryEvaluationController).EditEvaluationSelf), 17 web.NSCtrlPost("/evaluation-self/edit", (*controllers.SummaryEvaluationController).EditEvaluationSelf),
18 web.NSCtrlPost("/evaluation-360", (*controllers.SummaryEvaluationController).GetEvaluation360), 18 web.NSCtrlPost("/evaluation-360", (*controllers.SummaryEvaluationController).GetEvaluation360),
  19 + web.NSCtrlPost("/evaluation-360all", (*controllers.SummaryEvaluationController).GetEvaluation360All),
19 web.NSCtrlPost("/evaluation-360/edit", (*controllers.SummaryEvaluationController).EditEvaluation360), 20 web.NSCtrlPost("/evaluation-360/edit", (*controllers.SummaryEvaluationController).EditEvaluation360),
  21 + web.NSCtrlPost("/evaluation-360/list", (*controllers.SummaryEvaluationController).Evaluation360List),
20 web.NSCtrlPost("/evaluation-hr", (*controllers.SummaryEvaluationController).GetEvaluationHRBP), 22 web.NSCtrlPost("/evaluation-hr", (*controllers.SummaryEvaluationController).GetEvaluationHRBP),
21 web.NSCtrlPost("/evaluation-hr/edit", (*controllers.SummaryEvaluationController).EditEvaluationHRBP), 23 web.NSCtrlPost("/evaluation-hr/edit", (*controllers.SummaryEvaluationController).EditEvaluationHRBP),
  24 + web.NSCtrlPost("/evaluation-hr/list", (*controllers.SummaryEvaluationController).EvaluationHRBPList),
22 web.NSCtrlPost("/self/summary", (*controllers.SummaryEvaluationController).CountEvaluationSelfLevel), 25 web.NSCtrlPost("/self/summary", (*controllers.SummaryEvaluationController).CountEvaluationSelfLevel),
23 web.NSCtrlPost("/evaluation-super", (*controllers.SummaryEvaluationController).GetEvaluationSuper), 26 web.NSCtrlPost("/evaluation-super", (*controllers.SummaryEvaluationController).GetEvaluationSuper),
24 web.NSCtrlPost("/evaluation-super/edit", (*controllers.SummaryEvaluationController).EditEvaluationSuper), 27 web.NSCtrlPost("/evaluation-super/edit", (*controllers.SummaryEvaluationController).EditEvaluationSuper),