作者 郑周

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

2. 获取详情-360综评 接口字段修改
2. 获取详情-人资综评 接口字段修改
... ... @@ -10,3 +10,15 @@ type SummaryEvaluationAdapter struct {
List []map[string]interface{} `json:"list"`
Total int `json:"total"`
}
type SummaryEvaluationHRBPAdapter struct {
Id int `json:"id"` // 周期评估ID
TargetUserId int `json:"targetUserId"` // 目标用户ID
TargetUserName string `json:"targetUserName"` // 目标用户名称
Department string `json:"departmentVal"` // 部门(拼接文本)
Position string `json:"positionVal"` // 职位(拼接文本)
DutyTime string `json:"dutyTime"` // 入职时间(2006-01-02 15:04)
Status string `json:"statusVal"` // 完成状态(拼接文本)
EndTime string `json:"endTime"` // 截止时间(2006-01-02 15:04)
OverdueCount int `json:"overdueCount"` // 自评逾期次数
}
... ...
... ... @@ -13,11 +13,17 @@ type QueryEvaluation struct {
}
type QueryEvaluation360 struct {
SummaryEvaluationId int `json:"summaryEvaluationId,string"`
UserId int `json:"-"` // 用户ID
//SummaryEvaluationId int `json:"summaryEvaluationId,string"`
CycleId int `json:"cycleId,string"` // 周期ID
TargetUserId int `json:"targetUserId,string"` // 目标人ID
CompanyId int `json:"-"` // 公司ID
UserId int `json:"-"` // 用户ID
}
type QueryEvaluationHRBP struct {
SummaryEvaluationId int `json:"summaryEvaluationId,string"`
UserId int `json:"-"` // 用户ID
//SummaryEvaluationId int `json:"summaryEvaluationId,string"`
//UserId int `json:"-"` // 用户ID
CycleId int `json:"cycleId,string"` // 周期ID
TargetUserId int `json:"targetUserId,string"` // 目标人ID
CompanyId int `json:"-"` // 公司ID
}
... ...
... ... @@ -12,8 +12,10 @@ type QueryEvaluation360List struct {
// QueryEvaluationHRList 人资综评列表
type QueryEvaluationHRList struct {
CycleId int `json:"cycleId,string"` // 周期ID
SearchName string `json:"searchName"` // 模糊搜索(用户名称)
CompanyId int `json:"-"` // 公司ID
UserId int `json:"-"` // 用户ID
CycleId int `cname:"周期ID" json:"cycleId,string" valid:"Required"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
SearchName string `cname:"用户名称" json:"searchName"`
CompanyId int `cname:"公司ID" json:"-"`
UserId int `cname:"用户ID" json:"-"`
}
... ...
... ... @@ -3,14 +3,18 @@ package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
"strings"
"time"
)
// Evaluation360List 获取360综评列表
func (srv *SummaryEvaluationService) Evaluation360List(param *command.QueryEvaluation360List) (*adapter.SummaryEvaluationAdapter, error) {
transactionContext, err := factory.ValidateStartTransaction(param)
if err != nil {
... ... @@ -182,10 +186,24 @@ func (srv *SummaryEvaluationService) GetEvaluation360(param *command.QueryEvalua
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
sEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
//sEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
_, evaluations, err := evaluationRepo.Find(map[string]interface{}{
"limit": 1,
"companyId": param.CompanyId,
"cycleId": param.CycleId,
"targetUserId": param.TargetUserId,
"types": domain.Evaluation360},
)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluations) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "数据不存在")
}
sEvaluation := evaluations[0]
// 自评评估内容(自评模板、筛选项目评估人)
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
... ... @@ -324,6 +342,156 @@ func (srv *SummaryEvaluationService) EditEvaluation360(param *command.EditEvalua
}, nil
}
// EvaluationHRBPList 获取人资综评列表
func (srv *SummaryEvaluationService) EvaluationHRBPList(param *command.QueryEvaluationHRList) (map[string]interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(param)
if err != nil {
return nil, err
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{"transactionContext": transactionContext})
staffAssessDaoRepo := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
positionRepo := factory.CreatePositionRepository(map[string]interface{}{"transactionContext": transactionContext})
var searchTargetName string
if len(param.SearchName) > 0 {
searchTargetName = "%" + param.SearchName + "%"
} else {
searchTargetName = ""
}
limit := param.PageSize
offset := limit * (param.PageNumber - 1)
if offset < 0 {
offset = 0
}
count, list, err := evaluationRepo.Find(map[string]interface{}{
"companyId": param.CompanyId,
"cycleId": param.CycleId,
"executorId": -1,
"types": domain.EvaluationHrbp,
"searchTargetName": searchTargetName,
"limit": limit,
"offset": offset,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
userIds := make([]int, 0)
positionIds := make([]int, 0)
projectIds := make([]int, 0)
projectCountMap := map[string]int{} // 自评逾期数量
userMap := map[int64]*domain.User{} // 用户
positionMap := map[int64]*domain.Position{} // 职位
for i := range list {
it := list[i]
userIds = append(userIds, it.TargetUser.UserId)
projectIds = append(projectIds, list[i].EvaluationProjectId)
}
_, users, err := userRepo.Find(map[string]interface{}{"ids": userIds, "companyId": param.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range users {
userMap[users[i].Id] = users[i]
for _, pid := range users[i].PositionId {
positionIds = append(positionIds, pid)
}
}
_, positions, err := positionRepo.Find(map[string]interface{}{"ids": positionIds, "companyId": param.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range positions {
positionMap[positions[i].Id] = positions[i]
}
if len(projectIds) > 0 {
targetCount, err := staffAssessDaoRepo.CountUncompletedSelfAssess(param.CompanyId, projectIds)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range targetCount {
key := fmt.Sprintf("%d-%d", targetCount[i].EvaluationProjectId, targetCount[i].TargetUserId)
projectCountMap[key] = targetCount[i].Cnt
}
}
now := time.Now().Local() // 当前时间
resultList := make([]*adapter.SummaryEvaluationHRBPAdapter, 0)
for i := range list {
v := list[i]
endTime := v.EndTime.Local()
// 状态
statusVal := ""
if v.Status == domain.EvaluationCompleted {
statusVal = "已完成"
} else {
if now.After(endTime) {
statusVal = "已逾期"
} else {
statusVal = "待完成"
}
}
// 部门拼接
var departmentBuild strings.Builder
departmentBuild.WriteString("")
for i2 := range v.TargetDepartment {
departmentBuild.WriteString(v.TargetDepartment[i2].DepartmentName)
if i2 != len(v.TargetDepartment)-1 {
departmentBuild.WriteString(",")
}
}
// 入职时间
entryTime := ""
// 职位拼接
var positionBuild strings.Builder
positionBuild.WriteString("")
if user, ok := userMap[int64(v.TargetUser.UserId)]; ok {
for i2 := range user.PositionId {
if position, ok := positionMap[int64(user.PositionId[i2])]; ok {
positionBuild.WriteString(position.Name)
if i2 != len(user.PositionId)-1 {
departmentBuild.WriteString(",")
}
}
}
entryTime = user.EntryTime
}
// 自评逾期数量
overdueCount := 0
key := fmt.Sprintf("%d-%d", v.EvaluationProjectId, v.TargetUser.UserId)
if cnt, ok := projectCountMap[key]; ok {
overdueCount = cnt
}
result := &adapter.SummaryEvaluationHRBPAdapter{
Id: v.Id,
TargetUserId: v.TargetUser.UserId,
TargetUserName: v.TargetUser.UserName,
Department: departmentBuild.String(),
Position: positionBuild.String(),
DutyTime: entryTime,
Status: statusVal,
EndTime: endTime.Format("2006-01-02 15:04"),
OverdueCount: overdueCount,
}
resultList = append(resultList, result)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(int64(count), resultList), nil
}
// GetEvaluationHRBP 获取人资综评详情
func (srv *SummaryEvaluationService) GetEvaluationHRBP(param *command.QueryEvaluationHRBP) (*adapter.EvaluationInfoAdapter, error) {
transactionContext, err := factory.ValidateStartTransaction(param)
... ... @@ -338,10 +506,21 @@ func (srv *SummaryEvaluationService) GetEvaluationHRBP(param *command.QueryEvalu
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{"transactionContext": transactionContext})
sEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
_, evaluations, err := evaluationRepo.Find(map[string]interface{}{
"limit": 1,
"companyId": param.CompanyId,
"cycleId": param.CycleId,
"targetUserId": param.TargetUserId,
"types": domain.EvaluationHrbp},
)
// sEvaluation, err := evaluationRepo.FindOne(map[string]interface{}{"id": param.SummaryEvaluationId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluations) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "数据不存在")
}
sEvaluation := evaluations[0]
// 自评评估内容(自评模板、筛选项目评估人)
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
... ...
... ... @@ -1223,3 +1223,33 @@ group by level_value,category,"name" `
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
type CountUncompletedSelfAssess struct {
EvaluationProjectId int
TargetUserId int
Cnt int
}
// CountUncompletedSelfAssess 统计整个项目周期内,相关人自评未完成数量
func (d *StaffAssessDao) CountUncompletedSelfAssess(companyId int, projectIds []int) ([]CountUncompletedSelfAssess, error) {
sqlStr := `
SELECT
staff_assess.evaluation_project_id,
staff_assess.target_user ->> 'userId' AS target_user_id,
COUNT ( staff_assess.ID ) AS cnt
FROM
staff_assess
WHERE
staff_assess.company_id = ?
AND staff_assess.types = 'self'
AND staff_assess.evaluation_project_id IN (?)
AND staff_assess.status = 'uncompleted'
GROUP BY
evaluation_project_id, target_user_id`
condition := []interface{}{companyId, pg.In(projectIds)}
tx := d.transactionContext.PgTx
result := make([]CountUncompletedSelfAssess, 0)
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
... ...
... ... @@ -139,6 +139,7 @@ func (c *SummaryEvaluationController) GetEvaluation360() {
return
}
userReq := middlewares.GetUser(c.Ctx)
in.CompanyId = int(userReq.CompanyId)
in.UserId = int(userReq.UserId)
data, err := srv.GetEvaluation360(in)
c.Response(data, err)
... ... @@ -160,6 +161,22 @@ func (c *SummaryEvaluationController) EditEvaluation360() {
c.Response(data, err)
}
func (c *SummaryEvaluationController) EvaluationHRBPList() {
srv := service.NewSummaryEvaluationService()
in := &command.QueryEvaluationHRList{}
err := c.BindJSON(in)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
in.CompanyId = int(userReq.CompanyId)
in.UserId = int(userReq.UserId)
data, err := srv.EvaluationHRBPList(in)
c.Response(data, err)
}
func (c *SummaryEvaluationController) GetEvaluationHRBP() {
srv := service.NewSummaryEvaluationService()
in := &command.QueryEvaluationHRBP{}
... ... @@ -170,7 +187,8 @@ func (c *SummaryEvaluationController) GetEvaluationHRBP() {
return
}
userReq := middlewares.GetUser(c.Ctx)
in.UserId = int(userReq.UserId)
//in.UserId = int(userReq.UserId)
in.CompanyId = int(userReq.CompanyId)
data, err := srv.GetEvaluationHRBP(in)
c.Response(data, err)
}
... ...
... ... @@ -20,6 +20,7 @@ func init() {
web.NSCtrlPost("/evaluation-360/list", (*controllers.SummaryEvaluationController).Evaluation360List),
web.NSCtrlPost("/evaluation-hr", (*controllers.SummaryEvaluationController).GetEvaluationHRBP),
web.NSCtrlPost("/evaluation-hr/edit", (*controllers.SummaryEvaluationController).EditEvaluationHRBP),
web.NSCtrlPost("/evaluation-hr/list", (*controllers.SummaryEvaluationController).EvaluationHRBPList),
web.NSCtrlPost("/self/summary", (*controllers.SummaryEvaluationController).CountEvaluationSelfLevel),
)
web.AddNamespace(summaryNS)
... ...