作者 郑周

综合管理-绩效导出-指标 1

... ... @@ -8,3 +8,15 @@ type MemberSummaryAdapter struct {
DepartmentNames []string `json:"departmentNames"` // 被评估人部门列表
PositionNames []string `json:"positionNames"` // 被评估人职位列表
}
// PerformanceIndicatorAdapter 综合管理-成员列表-绩效导出指标
type PerformanceIndicatorAdapter struct {
TargetUserId string `json:"targetUserId"` // 被评估人的id
TargetUserName string `json:"targetUserName"` // 被评估人的名称
PIContents []PIContent `json:"piContents"` // 被评估人的内容
}
type PIContent struct {
Category string `json:"category"` // 评估内容分类
Names []string `json:"names"` // 评估内容名称
}
... ...
... ... @@ -9,3 +9,12 @@ type MemberSummaryListCommand struct {
CompanyId int `cname:"公司ID" json:"companyId"`
OperatorId int `cname:"操作人ID" json:"operatorId"`
}
// MemberPerformanceIndicatorCommand 成员绩效导出-指标
type MemberPerformanceIndicatorCommand struct {
CycleId int `cname:"周期ID" json:"cycleId,string"`
UserName string `cname:"用户名称" json:"userName"`
UserIds []string `cname:"用户ID" json:"userIds"`
CompanyId int `cname:"公司ID" json:"companyId"`
OperatorId int `cname:"操作人ID" json:"operatorId"`
}
... ...
... ... @@ -217,3 +217,112 @@ func (srv StaffAssessServeice) QueryMemberSummary(in *query.MemberSummaryListCom
return tool_funs.SimpleWrapGridMap(int64(total), adapters), nil
}
func (srv StaffAssessServeice) QueryMemberPerformanceIndicator(in *query.MemberPerformanceIndicatorCommand) (map[string]interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
hrbp, err := srv.getHRBP(transactionContext, in.CompanyId, in.OperatorId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
list, err := assessDao.MemberPerformanceIndicator(
in.UserName,
in.CompanyId,
in.OperatorId,
in.CycleId,
hrbp,
string(domain.AssessSelf),
in.UserIds)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// (全部周期数据)筛选出第一个周期的数据,减少后续数据遍历
dupleMap := map[string]string{}
dupleList := make([]dao.PerformanceIndicatorAssess, 0)
for i := range list {
it := list[i]
if v, ok := dupleMap[it.TargetUserId]; ok {
if v == it.BeginDay {
dupleList = append(dupleList, it)
}
} else {
dupleMap[it.TargetUserId] = it.BeginDay
dupleList = append(dupleList, it)
}
}
piaMap := map[string]*adapter.PerformanceIndicatorAdapter{}
categoryMap := map[string]int{} // 内容分类
//categoryNameMap := map[string]int{} // 内容分类下的名称
adapterList := make([]*adapter.PerformanceIndicatorAdapter, 0)
for i := range dupleList {
it := dupleList[i]
var pia *adapter.PerformanceIndicatorAdapter
if v, ok := piaMap[it.TargetUserId]; ok {
pia = v
} else {
pia = &adapter.PerformanceIndicatorAdapter{
TargetUserId: it.TargetUserId,
TargetUserName: it.TargetUserName,
PIContents: make([]adapter.PIContent, 0),
}
piaMap[it.TargetUserId] = pia
adapterList = append(adapterList, pia)
}
// 分类名称有值才能合并分类数组
if len(it.ContentCategory) > 0 {
onlyKey1 := it.TargetUserId + it.ContentCategory
if _, ok := categoryMap[onlyKey1]; !ok {
categoryMap[onlyKey1] = 0
// 不存在分类时,创建分类内容
pia.PIContents = append(pia.PIContents, adapter.PIContent{
Category: it.ContentCategory,
Names: make([]string, 0),
})
}
// 内容名称有值合并到数组
if len(it.ContentName) > 0 {
// 周期筛选过的,不再需要唯一值验证判断,直接添加到对应的分类下
for index := range pia.PIContents {
piContent := &pia.PIContents[index]
if piContent.Category == it.ContentCategory {
piContent.Names = append(piContent.Names, it.ContentName)
break
}
}
//onlyKey2 := it.TargetUserId + it.ContentCategory + it.ContentName
//if _, ok := categoryNameMap[onlyKey2]; !ok {
// categoryNameMap[onlyKey2] = 0
//
// for index := range pia.PIContents {
// piContent := pia.PIContents[index]
// if piContent.Category == it.ContentCategory {
// piContent.Names = append(piContent.Names, it.ContentName)
// break
// }
// }
//}
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(int64(len(adapterList)), adapterList), nil
}
... ...
... ... @@ -652,6 +652,132 @@ func (d *StaffAssessDao) MemberSummaryList(likeUserName string, companyId int, o
return total, result, err
}
type PerformanceIndicatorAssess struct {
AssessId int `json:"assessId"` // ID
TargetUserId string `json:"targetUserId"` // 被评估人的id
TargetUserName string `json:"targetUserName"` // 被评估人的名称
BeginDay string `json:"beginDay"` // 评估的开始日期
CycleId int `json:"cycleId"` // 周期ID
ContentId int `json:"contentId"` // 评估内容ID
ContentCategory string `json:"contentCategory"` // 评估内容分类
ContentName string `json:"contentName"` // 评估内容名称
SortBy int `json:"sort_by"` // 评估内容排序
}
func (d *StaffAssessDao) MemberPerformanceIndicator(likeUserName string, companyId int, operatorId int, cycleId int, hrbp int, assessType string, userIds []string) ([]PerformanceIndicatorAssess, error) {
sqlString := `
set time zone 'PRC';
with t_user_department as (
select "user".id as user_id ,jsonb_array_elements_text ("user".department_id) as depart_id from "user"
where "user".company_id= %d and "user".deleted_at isnull
),
t_department as (
select department.id::text as depart_id from department where charge_user_ids @>'[%d]'
and "department".deleted_at isnull
),
-- 部门主管(所有下级用户ID)
t_user_1 as (
select t_user_department.user_id::text from t_user_department
join t_department on t_user_department.depart_id = t_department.depart_id
),
-- 如果是HRBP
t_project_1 as(
select evaluation_project.id as project_id
from evaluation_project
where evaluation_project.cycle_id =%d
and evaluation_project.hr_bp = %d
and evaluation_project.deleted_at isnull
),
-- 如果的项目管理员
t_project_2 as(
select evaluation_project.id as project_id
from evaluation_project
where evaluation_project.cycle_id =%d
and evaluation_project.pmp =1
and evaluation_project.pmp_ids @>'["%d"]'
and evaluation_project.deleted_at isnull
),
-- 合并数据
t_project_3 as (
select t_project_2.project_id from t_project_2
union
select t_project_1.project_id from t_project_1
),
-- 初步过滤数据
t_staff_assess_0 as (
select
staff_assess.id as assess_id,
staff_assess.cycle_id,
staff_assess.target_user->>'userId' as target_user_id,
staff_assess.target_user->>'userName' as target_user_name,
to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day,
staff_assess.evaluation_project_id
from staff_assess
join staff_assess_task on staff_assess.staff_assess_task_id = staff_assess_task.id
and staff_assess_task.deleted_at isnull
where
staff_assess.cycle_id = %d
and staff_assess.types ='%s'
),
-- 根据查看权限过滤合并数据
t_staff_assess_1 as (
( select
t_staff_assess_0.assess_id,
t_staff_assess_0.target_user_id,
t_staff_assess_0.target_user_name,
t_staff_assess_0.begin_day,
t_staff_assess_0.cycle_id
from t_staff_assess_0
join t_project_3 on t_staff_assess_0.evaluation_project_id = t_project_3.project_id
) union (
select
t_staff_assess_0.assess_id,
t_staff_assess_0.target_user_id,
t_staff_assess_0.target_user_name,
t_staff_assess_0.begin_day,
t_staff_assess_0.cycle_id
from t_staff_assess_0
join t_user_1 on t_staff_assess_0.target_user_id = t_user_1.user_id
)
)
`
params := []interface{}{companyId, operatorId, cycleId, hrbp, cycleId, operatorId, cycleId, assessType}
sqlString = fmt.Sprintf(sqlString, params...)
sqlString += ` select
t_staff_assess_1.target_user_id,
t_staff_assess_1.target_user_name,
t_staff_assess_1.begin_day,
t_staff_assess_1.cycle_id,
t_staff_assess_1.assess_id,
staff_assess_content.id as content_id,
staff_assess_content.name as content_name,
staff_assess_content.category as content_category,
staff_assess_content.sort_by
from t_staff_assess_1
left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
where 1=1
-- AND staff_assess_content.id NOTNULL 部分脏数据
`
condition := make([]interface{}, 0)
if len(likeUserName) > 0 {
sqlString += ` and t_staff_assess_1.target_user_name like ? `
condition = append(condition, "%"+likeUserName+"%")
}
if len(userIds) > 0 {
sqlString += ` and t_staff_assess_1.target_user_id in (?) `
condition = append(condition, pg.In(userIds))
}
sqlString += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'), staff_assess_content.sort_by`
tx := d.transactionContext.PgTx
var result = make([]PerformanceIndicatorAssess, 0)
_, err := tx.Query(&result, sqlString, condition...)
return result, err
}
type ExportData1 struct {
AssessId string
ContentId int
... ...
... ... @@ -389,6 +389,21 @@ func (c *StaffAssessController) QueryMemberSummary() {
}
}
// QueryMemberPerformanceIndicator 员工绩效-综合管理-绩效导出指标
func (c *StaffAssessController) QueryMemberPerformanceIndicator() {
srv := service.NewStaffAssessServeice()
in := &query.MemberPerformanceIndicatorCommand{}
if err := c.Unmarshal(in); err != nil {
c.Response(nil, application.ThrowError(application.ARG_ERROR, err.Error()))
} else {
if user := middlewares.GetUser(c.Ctx); user != nil {
in.CompanyId = int(user.CompanyId)
in.OperatorId = int(user.UserId)
}
c.Response(srv.QueryMemberPerformanceIndicator(in))
}
}
// 员工绩效-项目管理-矩阵分析
func (c *StaffAssessController) AnalysisData() {
srv := service.NewStaffAssessServeice()
... ...
... ... @@ -22,21 +22,15 @@ func init() {
assessNS := web.NewNamespace("/v1/staff-assess",
web.NSBefore(filters.AllowCors(), middlewares.CheckFontToken()),
web.NSCtrlPost("/self/me/list", (*controllers.StaffAssessController).AssessSelfMeList), //获取我的自评反馈列表
//web.NSCtrlPost("/self/me/info", (*controllers.StaffAssessController).GetAssessSelfMeInfo), //获取我的自评反馈详情
// web.NSCtrlPost("/me/invite-user", (*controllers.StaffAssessController).GetAssessMeInviteUser), //获取邀请的员工
web.NSCtrlPost("/me/save-invite-user", (*controllers.StaffAssessController).SaveAssessMeInviteUser), //保存我邀请的员工
web.NSCtrlPost("/me/invite-user/select", (*controllers.StaffAssessController).SelectAssessInviteUser), //选择我邀请的员工
//web.NSCtrlPost("/me/execute/invite/list", (*controllers.StaffAssessController).ListMeInviteUserAssess), //我要执行的360评估的用户列表
//web.NSCtrlPost("/me/execute/supper/list", (*controllers.StaffAssessController).ListMeSupperAssess), //我要执行的360评估的用户列表
web.NSCtrlPost("/info", (*controllers.StaffAssessController).GetAssessInfo), //通用获取员工评估的详情
web.NSCtrlPut("/info", (*controllers.StaffAssessController).SaveAssessInfo), //通用保存员工评估的详情
web.NSCtrlPut("/info-cache", (*controllers.StaffAssessController).SaveAssessCache), //通用保存员工评估的详情(缓存)
web.NSCtrlPost("/summary", (*controllers.StaffAssessController).QuerySummary), //员工绩效-项目管理-总览
web.NSCtrlPost("/summary/users", (*controllers.StaffAssessController).QueryMemberSummary), //员工绩效-综合管理-成员列表
// web.NSCtrlPost("/target-user/invite/list", (*controllers.StaffAssessController).ListTargetUserInviteAssess), //获取被评估员工360评估的列表
//web.NSCtrlPost("/me/target-user/supper/list", (*controllers.StaffAssessController).ListTargetUserMeSupperAssess), //获取我被上级评估的列表
// web.NSCtrlPost("/target-user/self/info", (*controllers.StaffAssessController).GetAssessTargetUserSelfInfo), //获取被评估员工的自评反馈详情
web.NSCtrlPost("/self/me/list", (*controllers.StaffAssessController).AssessSelfMeList), //获取我的自评反馈列表
web.NSCtrlPost("/me/save-invite-user", (*controllers.StaffAssessController).SaveAssessMeInviteUser), //保存我邀请的员工
web.NSCtrlPost("/me/invite-user/select", (*controllers.StaffAssessController).SelectAssessInviteUser), //选择我邀请的员工
web.NSCtrlPost("/info", (*controllers.StaffAssessController).GetAssessInfo), //通用获取员工评估的详情
web.NSCtrlPut("/info", (*controllers.StaffAssessController).SaveAssessInfo), //通用保存员工评估的详情
web.NSCtrlPut("/info-cache", (*controllers.StaffAssessController).SaveAssessCache), //通用保存员工评估的详情(缓存)
web.NSCtrlPost("/summary", (*controllers.StaffAssessController).QuerySummary), //员工绩效-项目管理-总览
web.NSCtrlPost("/summary/users", (*controllers.StaffAssessController).QueryMemberSummary), //员工绩效-综合管理-成员列表
web.NSCtrlPost("/summary/users-indicator", (*controllers.StaffAssessController).QueryMemberPerformanceIndicator), //员工绩效-综合管理-绩效导出指标
)
//v2 改版
assessTaskV2NS := web.NewNamespace("/v2/staff-assess-task",
... ...