作者 郑周

1. 新增项目管理-总览

package adapter
import "time"
type SummaryBlock struct {
Name string `json:"name"` // 数据名称
Total int `json:"total"` // 总数量
Completed int `json:"completed"` // 完成数量
EndTime *time.Time `json:"endTime"` // 截止时间
}
... ...
package query
// SummaryCommand 查询项目管理-总览
type SummaryCommand struct {
CycleId int `cname:"周期ID" json:"cycleId,string"`
BeginDay string `cname:"日期" json:"beginDay"`
CompanyId int `cname:"公司ID" json:"companyId"`
OperatorId int `cname:"操作人ID" json:"operatorId"`
}
... ...
... ... @@ -3,7 +3,11 @@ package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
)
//调试用,手动调用CreateStaffAssessTask
... ... @@ -28,3 +32,98 @@ func (srv StaffAssessServeice) InvokCreateStaffAssessTask(param *command.CreateS
}
return data, nil
}
func (srv StaffAssessServeice) QuerySummary(in *query.SummaryCommand) (map[string]interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
roleRepo := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
roleUserRepo := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, roleList, err := roleRepo.Find(map[string]interface{}{"type": domain.RoleTypeSystem, "companyId": in.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取角色信息列表"+err.Error())
}
_, userRoleList, err := roleUserRepo.Find(map[string]interface{}{"companyId": in.CompanyId, "userId": in.OperatorId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
}
// 拥有HRBP权限
hrbp := -1
for _, v := range userRoleList {
for _, v2 := range roleList {
if v.RoleId == v2.Id {
hrbp = 1
break
}
}
if hrbp == 1 {
break
}
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{"transactionContext": transactionContext})
data, err := assessDao.SummaryAssess(in.CompanyId, in.OperatorId, in.CycleId, in.BeginDay, hrbp)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取用户的角色信息列表"+err.Error())
}
self := adapter.SummaryBlock{Name: "填写反馈自评"}
invite := adapter.SummaryBlock{Name: "360°邀请"}
inviteAssess := adapter.SummaryBlock{Name: "360°评估"}
supper := adapter.SummaryBlock{Name: "上级评估"}
inviteTargetIdMap := map[string]int{} // 过滤相同的目标用户ID
for i := range data {
d := data[i]
d.EndTime = d.EndTime.Local() // 输出本地时间
switch d.Types {
case domain.AssessSelf:
self.Total++
if d.Status == domain.StaffAssessCompleted {
self.Completed++
}
if self.EndTime == nil {
self.EndTime = &d.EndTime
}
invite.Total++ // 发起360邀请的人数 = 自评人数
if invite.EndTime == nil {
invite.EndTime = &d.EndTime
}
break
case domain.AssessSuper:
supper.Total++
if d.Status == domain.StaffAssessCompleted {
supper.Completed++
}
if supper.EndTime == nil {
supper.EndTime = &d.EndTime
}
break
case domain.AssessInviteDiffSuper, domain.AssessInviteSameSuper:
inviteAssess.Total++
if d.Status == domain.StaffAssessCompleted {
inviteAssess.Completed++
}
if inviteAssess.EndTime == nil {
inviteAssess.EndTime = &d.EndTime
}
inviteTargetIdMap[d.TargetUserId] = 0 // 360评估类型都是被人邀请的评估,过滤相同的目标用户后,就是完成邀请的数量
break
}
}
invite.Completed = len(inviteTargetIdMap)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return map[string]interface{}{"list": []adapter.SummaryBlock{self, invite, inviteAssess, supper}}, nil
}
... ...
... ... @@ -3,6 +3,7 @@ package dao
import (
"fmt"
"strconv"
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
... ... @@ -378,6 +379,129 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int,
return sqlstr
}
type SummaryAssess struct {
AssessId string `json:"assessId"`
TargetUserId string `json:"targetUserId"` // 被评估人的id
TargetUserName string `json:"targetUserName"` // 被评估人的名称
BeginDay string `json:"beginDay"` // 评估的开始日期
EndTime time.Time `json:"endTime"` // 评估的截止日期
EvaluationProjectId string `json:"evaluationProjectId"` // 项目id
CycleId string `json:"cycleId"` // 周期id
Types domain.StaffAssessType `json:"types"` // 评估类型
Status domain.StaffAssessStatus `json:"status"` // 评估状态
}
func (d *StaffAssessDao) SummaryAssess(companyId int, operatorId int, cycleId int, beginDay string, hrbp int) ([]SummaryAssess, 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,
staff_assess.types,
staff_assess.status,
staff_assess.end_time
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 to_char(staff_assess.begin_time,'YYYY-MM-DD')='%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,
t_staff_assess_0.evaluation_project_id,
t_staff_assess_0.types,
t_staff_assess_0.status,
t_staff_assess_0.end_time
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,
t_staff_assess_0.evaluation_project_id,
t_staff_assess_0.types,
t_staff_assess_0.status,
t_staff_assess_0.end_time
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, beginDay}
sqlString = fmt.Sprintf(sqlString, params...)
sqlString = 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,
t_staff_assess_1.evaluation_project_id,
t_staff_assess_1.types,
t_staff_assess_1.status,
t_staff_assess_1.end_time
from t_staff_assess_1
where 1=1
`
tx := d.transactionContext.PgTx
var result = make([]SummaryAssess, 0)
_, err := tx.Query(&result, sqlString)
return result, err
}
type ExportData1 struct {
AssessId string
ContentId int
... ...
... ... @@ -359,6 +359,21 @@ func (c *StaffAssessController) SaveAssessCache() {
}
}
// QuerySummary 项目管理-查询总览
func (c *StaffAssessController) QuerySummary() {
srv := service.NewStaffAssessServeice()
in := &query.SummaryCommand{}
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.QuerySummary(in))
}
}
// 员工绩效-项目管理-矩阵分析
func (c *StaffAssessController) AnalysisData() {
srv := service.NewStaffAssessServeice()
... ...
... ... @@ -32,6 +32,7 @@ func init() {
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("/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), //获取被评估员工的自评反馈详情
... ...