作者 郑周

1. HR综评列表(自评逾期数量)

2. 获取详情-360综评 接口字段修改
2. 获取详情-人资综评 接口字段修改
@@ -10,3 +10,15 @@ type SummaryEvaluationAdapter struct { @@ -10,3 +10,15 @@ type SummaryEvaluationAdapter struct {
10 List []map[string]interface{} `json:"list"` 10 List []map[string]interface{} `json:"list"`
11 Total int `json:"total"` 11 Total int `json:"total"`
12 } 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,11 +13,17 @@ type QueryEvaluation struct { @@ -13,11 +13,17 @@ 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 }
@@ -12,8 +12,10 @@ type QueryEvaluation360List struct { @@ -12,8 +12,10 @@ type QueryEvaluation360List struct {
12 12
13 // QueryEvaluationHRList 人资综评列表 13 // QueryEvaluationHRList 人资综评列表
14 type QueryEvaluationHRList struct { 14 type QueryEvaluationHRList struct {
15 - CycleId int `json:"cycleId,string"` // 周期ID  
16 - SearchName string `json:"searchName"` // 模糊搜索(用户名称)  
17 - CompanyId int `json:"-"` // 公司ID  
18 - UserId int `json:"-"` // 用户ID 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:"-"`
19 } 21 }
@@ -3,14 +3,18 @@ package service @@ -3,14 +3,18 @@ package service
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 "github.com/linmadan/egglib-go/core/application" 5 "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory" 7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
7 service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role" 8 service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
8 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/adapter" 9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/adapter"
9 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command" 10 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
10 "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"
11 "time" 14 "time"
12 ) 15 )
13 16
  17 +// Evaluation360List 获取360综评列表
14 func (srv *SummaryEvaluationService) Evaluation360List(param *command.QueryEvaluation360List) (*adapter.SummaryEvaluationAdapter, error) { 18 func (srv *SummaryEvaluationService) Evaluation360List(param *command.QueryEvaluation360List) (*adapter.SummaryEvaluationAdapter, error) {
15 transactionContext, err := factory.ValidateStartTransaction(param) 19 transactionContext, err := factory.ValidateStartTransaction(param)
16 if err != nil { 20 if err != nil {
@@ -182,10 +186,24 @@ func (srv *SummaryEvaluationService) GetEvaluation360(param *command.QueryEvalua @@ -182,10 +186,24 @@ func (srv *SummaryEvaluationService) GetEvaluation360(param *command.QueryEvalua
182 evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext}) 186 evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
183 itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext}) 187 itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
184 188
185 - 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 + )
186 if err != nil { 200 if err != nil {
187 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 201 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
188 } 202 }
  203 + if len(evaluations) == 0 {
  204 + return nil, application.ThrowError(application.BUSINESS_ERROR, "数据不存在")
  205 + }
  206 + sEvaluation := evaluations[0]
189 207
190 // 自评评估内容(自评模板、筛选项目评估人) 208 // 自评评估内容(自评模板、筛选项目评估人)
191 _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{ 209 _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
@@ -324,6 +342,156 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua @@ -324,6 +342,156 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua
324 }, nil 342 }, nil
325 } 343 }
326 344
  345 +// EvaluationHRBPList 获取人资综评列表
  346 +func (srv *SummaryEvaluationService) EvaluationHRBPList(param *command.QueryEvaluationHRList) (map[string]interface{}, error) {
  347 + transactionContext, err := factory.ValidateStartTransaction(param)
  348 + if err != nil {
  349 + return nil, err
  350 + }
  351 + defer func() {
  352 + _ = transactionContext.RollbackTransaction()
  353 + }()
  354 +
  355 + evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
  356 + staffAssessDaoRepo := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
  357 + userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
  358 + positionRepo := factory.CreatePositionRepository(map[string]interface{}{"transactionContext": transactionContext})
  359 + var searchTargetName string
  360 + if len(param.SearchName) > 0 {
  361 + searchTargetName = "%" + param.SearchName + "%"
  362 + } else {
  363 + searchTargetName = ""
  364 + }
  365 + limit := param.PageSize
  366 + offset := limit * (param.PageNumber - 1)
  367 + if offset < 0 {
  368 + offset = 0
  369 + }
  370 + count, list, err := evaluationRepo.Find(map[string]interface{}{
  371 + "companyId": param.CompanyId,
  372 + "cycleId": param.CycleId,
  373 + "executorId": -1,
  374 + "types": domain.EvaluationHrbp,
  375 + "searchTargetName": searchTargetName,
  376 + "limit": limit,
  377 + "offset": offset,
  378 + })
  379 + if err != nil {
  380 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  381 + }
  382 +
  383 + userIds := make([]int, 0)
  384 + positionIds := make([]int, 0)
  385 + projectIds := make([]int, 0)
  386 + projectCountMap := map[string]int{} // 自评逾期数量
  387 + userMap := map[int64]*domain.User{} // 用户
  388 + positionMap := map[int64]*domain.Position{} // 职位
  389 +
  390 + for i := range list {
  391 + it := list[i]
  392 + userIds = append(userIds, it.TargetUser.UserId)
  393 + projectIds = append(projectIds, list[i].EvaluationProjectId)
  394 + }
  395 + _, users, err := userRepo.Find(map[string]interface{}{"ids": userIds, "companyId": param.CompanyId})
  396 + if err != nil {
  397 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  398 + }
  399 + for i := range users {
  400 + userMap[users[i].Id] = users[i]
  401 + for _, pid := range users[i].PositionId {
  402 + positionIds = append(positionIds, pid)
  403 + }
  404 + }
  405 + _, positions, err := positionRepo.Find(map[string]interface{}{"ids": positionIds, "companyId": param.CompanyId})
  406 + if err != nil {
  407 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  408 + }
  409 + for i := range positions {
  410 + positionMap[positions[i].Id] = positions[i]
  411 + }
  412 +
  413 + if len(projectIds) > 0 {
  414 + targetCount, err := staffAssessDaoRepo.CountUncompletedSelfAssess(param.CompanyId, projectIds)
  415 + if err != nil {
  416 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  417 + }
  418 + for i := range targetCount {
  419 + key := fmt.Sprintf("%d-%d", targetCount[i].EvaluationProjectId, targetCount[i].TargetUserId)
  420 + projectCountMap[key] = targetCount[i].Cnt
  421 + }
  422 + }
  423 +
  424 + now := time.Now().Local() // 当前时间
  425 + resultList := make([]*adapter.SummaryEvaluationHRBPAdapter, 0)
  426 + for i := range list {
  427 + v := list[i]
  428 + endTime := v.EndTime.Local()
  429 + // 状态
  430 + statusVal := ""
  431 + if v.Status == domain.EvaluationCompleted {
  432 + statusVal = "已完成"
  433 + } else {
  434 + if now.After(endTime) {
  435 + statusVal = "已逾期"
  436 + } else {
  437 + statusVal = "待完成"
  438 + }
  439 + }
  440 +
  441 + // 部门拼接
  442 + var departmentBuild strings.Builder
  443 + departmentBuild.WriteString("")
  444 + for i2 := range v.TargetDepartment {
  445 + departmentBuild.WriteString(v.TargetDepartment[i2].DepartmentName)
  446 + if i2 != len(v.TargetDepartment)-1 {
  447 + departmentBuild.WriteString(",")
  448 + }
  449 + }
  450 + // 入职时间
  451 + entryTime := ""
  452 + // 职位拼接
  453 + var positionBuild strings.Builder
  454 + positionBuild.WriteString("")
  455 + if user, ok := userMap[int64(v.TargetUser.UserId)]; ok {
  456 + for i2 := range user.PositionId {
  457 + if position, ok := positionMap[int64(user.PositionId[i2])]; ok {
  458 + positionBuild.WriteString(position.Name)
  459 + if i2 != len(user.PositionId)-1 {
  460 + departmentBuild.WriteString(",")
  461 + }
  462 + }
  463 + }
  464 + entryTime = user.EntryTime
  465 + }
  466 +
  467 + // 自评逾期数量
  468 + overdueCount := 0
  469 + key := fmt.Sprintf("%d-%d", v.EvaluationProjectId, v.TargetUser.UserId)
  470 + if cnt, ok := projectCountMap[key]; ok {
  471 + overdueCount = cnt
  472 + }
  473 +
  474 + result := &adapter.SummaryEvaluationHRBPAdapter{
  475 + Id: v.Id,
  476 + TargetUserId: v.TargetUser.UserId,
  477 + TargetUserName: v.TargetUser.UserName,
  478 + Department: departmentBuild.String(),
  479 + Position: positionBuild.String(),
  480 + DutyTime: entryTime,
  481 + Status: statusVal,
  482 + EndTime: endTime.Format("2006-01-02 15:04"),
  483 + OverdueCount: overdueCount,
  484 + }
  485 + resultList = append(resultList, result)
  486 + }
  487 +
  488 + if err := transactionContext.CommitTransaction(); err != nil {
  489 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  490 + }
  491 +
  492 + return tool_funs.SimpleWrapGridMap(int64(count), resultList), nil
  493 +}
  494 +
327 // GetEvaluationHRBP 获取人资综评详情 495 // GetEvaluationHRBP 获取人资综评详情
328 func (srv *SummaryEvaluationService) GetEvaluationHRBP(param *command.QueryEvaluationHRBP) (*adapter.EvaluationInfoAdapter, error) { 496 func (srv *SummaryEvaluationService) GetEvaluationHRBP(param *command.QueryEvaluationHRBP) (*adapter.EvaluationInfoAdapter, error) {
329 transactionContext, err := factory.ValidateStartTransaction(param) 497 transactionContext, err := factory.ValidateStartTransaction(param)
@@ -338,10 +506,21 @@ func (srv *SummaryEvaluationService) GetEvaluationHRBP(param *command.QueryEvalu @@ -338,10 +506,21 @@ func (srv *SummaryEvaluationService) GetEvaluationHRBP(param *command.QueryEvalu
338 evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext}) 506 evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
339 itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext}) 507 itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
340 508
341 - sEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId}) 509 + _, evaluations, err := evaluationRepo.Find(map[string]interface{}{
  510 + "limit": 1,
  511 + "companyId": param.CompanyId,
  512 + "cycleId": param.CycleId,
  513 + "targetUserId": param.TargetUserId,
  514 + "types": domain.EvaluationHrbp},
  515 + )
  516 + // sEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
342 if err != nil { 517 if err != nil {
343 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 518 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
344 } 519 }
  520 + if len(evaluations) == 0 {
  521 + return nil, application.ThrowError(application.BUSINESS_ERROR, "数据不存在")
  522 + }
  523 + sEvaluation := evaluations[0]
345 524
346 // 自评评估内容(自评模板、筛选项目评估人) 525 // 自评评估内容(自评模板、筛选项目评估人)
347 _, itemList, err := evaluationItemRepo.Find(map[string]interface{}{ 526 _, 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 +}
@@ -139,6 +139,7 @@ func (c *SummaryEvaluationController) GetEvaluation360() { @@ -139,6 +139,7 @@ func (c *SummaryEvaluationController) GetEvaluation360() {
139 return 139 return
140 } 140 }
141 userReq := middlewares.GetUser(c.Ctx) 141 userReq := middlewares.GetUser(c.Ctx)
  142 + in.CompanyId = int(userReq.CompanyId)
142 in.UserId = int(userReq.UserId) 143 in.UserId = int(userReq.UserId)
143 data, err := srv.GetEvaluation360(in) 144 data, err := srv.GetEvaluation360(in)
144 c.Response(data, err) 145 c.Response(data, err)
@@ -160,6 +161,22 @@ func (c *SummaryEvaluationController) EditEvaluation360() { @@ -160,6 +161,22 @@ func (c *SummaryEvaluationController) EditEvaluation360() {
160 c.Response(data, err) 161 c.Response(data, err)
161 } 162 }
162 163
  164 +func (c *SummaryEvaluationController) EvaluationHRBPList() {
  165 + srv := service.NewSummaryEvaluationService()
  166 + in := &command.QueryEvaluationHRList{}
  167 + err := c.BindJSON(in)
  168 + if err != nil {
  169 + e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
  170 + c.Response(nil, e)
  171 + return
  172 + }
  173 + userReq := middlewares.GetUser(c.Ctx)
  174 + in.CompanyId = int(userReq.CompanyId)
  175 + in.UserId = int(userReq.UserId)
  176 + data, err := srv.EvaluationHRBPList(in)
  177 + c.Response(data, err)
  178 +}
  179 +
163 func (c *SummaryEvaluationController) GetEvaluationHRBP() { 180 func (c *SummaryEvaluationController) GetEvaluationHRBP() {
164 srv := service.NewSummaryEvaluationService() 181 srv := service.NewSummaryEvaluationService()
165 in := &command.QueryEvaluationHRBP{} 182 in := &command.QueryEvaluationHRBP{}
@@ -170,7 +187,8 @@ func (c *SummaryEvaluationController) GetEvaluationHRBP() { @@ -170,7 +187,8 @@ func (c *SummaryEvaluationController) GetEvaluationHRBP() {
170 return 187 return
171 } 188 }
172 userReq := middlewares.GetUser(c.Ctx) 189 userReq := middlewares.GetUser(c.Ctx)
173 - in.UserId = int(userReq.UserId) 190 + //in.UserId = int(userReq.UserId)
  191 + in.CompanyId = int(userReq.CompanyId)
174 data, err := srv.GetEvaluationHRBP(in) 192 data, err := srv.GetEvaluationHRBP(in)
175 c.Response(data, err) 193 c.Response(data, err)
176 } 194 }
@@ -20,6 +20,7 @@ func init() { @@ -20,6 +20,7 @@ func init() {
20 web.NSCtrlPost("/evaluation-360/list", (*controllers.SummaryEvaluationController).Evaluation360List), 20 web.NSCtrlPost("/evaluation-360/list", (*controllers.SummaryEvaluationController).Evaluation360List),
21 web.NSCtrlPost("/evaluation-hr", (*controllers.SummaryEvaluationController).GetEvaluationHRBP), 21 web.NSCtrlPost("/evaluation-hr", (*controllers.SummaryEvaluationController).GetEvaluationHRBP),
22 web.NSCtrlPost("/evaluation-hr/edit", (*controllers.SummaryEvaluationController).EditEvaluationHRBP), 22 web.NSCtrlPost("/evaluation-hr/edit", (*controllers.SummaryEvaluationController).EditEvaluationHRBP),
  23 + web.NSCtrlPost("/evaluation-hr/list", (*controllers.SummaryEvaluationController).EvaluationHRBPList),
23 web.NSCtrlPost("/self/summary", (*controllers.SummaryEvaluationController).CountEvaluationSelfLevel), 24 web.NSCtrlPost("/self/summary", (*controllers.SummaryEvaluationController).CountEvaluationSelfLevel),
24 ) 25 )
25 web.AddNamespace(summaryNS) 26 web.AddNamespace(summaryNS)