作者 tangxvhui
... ... @@ -13,7 +13,7 @@ type MemberSummaryListCommand struct {
// MemberPerformanceIndicatorCommand 成员绩效导出-指标
type MemberPerformanceIndicatorCommand struct {
CycleId int `cname:"周期ID" json:"cycleId,string"`
UserName string `cname:"用户名称" json:"userName"`
UserName string `cname:"搜索用户名称" json:"userName"`
UserIds []string `cname:"用户ID" json:"userIds"`
CompanyId int `cname:"公司ID" json:"companyId"`
OperatorId int `cname:"操作人ID" json:"operatorId"`
... ...
... ... @@ -231,105 +231,250 @@ func (srv StaffAssessServeice) QueryMemberPerformanceIndicator(in *query.MemberP
transactionContext.RollbackTransaction()
}()
hrbp, err := srv.getHRBP(transactionContext, in.CompanyId, in.OperatorId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
var projectItemUsed = map[int][]*domain.EvaluationItemUsed{} // 项目ID-> 评估内容项
var userProjectMap = map[int][]*dao.IndicatorUserProject{} // 用户ID-> 用户评估的项目(用户在周期内可能有多个项目模板,激活状态只能是1个)
var projectIds = make([]int, 0)
if len(in.UserIds) > 0 {
staffAssessRepository := factory.CreateStaffAssessRepository(map[string]interface{}{"transactionContext": transactionContext})
_, assessList, err := staffAssessRepository.Find(map[string]interface{}{
"cycleId": in.CycleId,
"targetUserIds": in.UserIds,
"types": domain.AssessSelf,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
projectIdsMap := map[int]int{}
for i := range assessList {
it := assessList[i]
projectIdsMap[it.EvaluationProjectId] = it.EvaluationProjectId
// 用户存在多个项目模板
array, ok := userProjectMap[it.TargetUser.UserId]
if !ok {
array = make([]*dao.IndicatorUserProject, 0)
}
userProjectMap[it.TargetUser.UserId] = append(array, &dao.IndicatorUserProject{
AssessId: it.Id,
EvaluationProjectId: it.EvaluationProjectId,
TargetUserId: it.TargetUser.UserId,
TargetUserName: it.TargetUser.UserName,
})
}
for k, _ := range projectIdsMap {
projectIds = append(projectIds, k)
}
} else {
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.MemberAllProjectId(
in.CompanyId,
in.UserName,
in.OperatorId,
in.CycleId,
hrbp)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
projectIdsMap := map[int]int{}
for i := range list {
it := list[i]
projectIdsMap[it.EvaluationProjectId] = it.EvaluationProjectId
// 用户存在多个项目模板
array, ok := userProjectMap[it.TargetUserId]
if !ok {
array = make([]*dao.IndicatorUserProject, 0)
}
userProjectMap[it.TargetUserId] = append(array, &it)
}
for k, _ := range projectIdsMap {
projectIds = append(projectIds, k)
}
}
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 {
// 项目ID->查询所有评估项
if len(projectIds) > 0 {
itemUsedRepository := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
_, itemList, err := itemUsedRepository.Find(map[string]interface{}{"evaluationProjectIds": projectIds, "nodeType": domain.LinkNodeSelfAssessment})
if err != nil {
return nil, err
}
for i := range itemList {
it := itemList[i]
array, ok := projectItemUsed[it.EvaluationProjectId]
if !ok {
array = make([]*domain.EvaluationItemUsed, 0)
}
projectItemUsed[it.EvaluationProjectId] = append(array, it)
}
}
if err := transactionContext.CommitTransaction(); 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)
adapterList := make([]*adapter.PerformanceIndicatorAdapter, 0)
categoryMap := map[string]int{} // 内容分类
for i := range in.UserIds {
userId := in.UserIds[i]
userIdInt, err := strconv.Atoi(userId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
iupArray, ok := userProjectMap[userIdInt]
if !ok {
continue
}
var pia = &adapter.PerformanceIndicatorAdapter{
TargetUserId: userId,
TargetUserName: iupArray[0].TargetUserName,
PIContents: make([]adapter.PIContent, 0),
}
adapterList = append(adapterList, pia)
for _, assess := range iupArray {
items, ok := projectItemUsed[assess.EvaluationProjectId]
if !ok {
continue
}
} else {
// 有内容分类,才算正常数据,反之不显示
if len(it.ContentCategory) > 0 {
dupleMap[it.TargetUserId] = it.BeginDay
dupleList = append(dupleList, it)
for _, item := range items {
if len(item.Category) == 0 {
continue
}
onlyKey1 := userId + item.Category
if _, ok := categoryMap[onlyKey1]; !ok {
categoryMap[onlyKey1] = 0
// 不存在分类时,创建分类内容
pia.PIContents = append(pia.PIContents, adapter.PIContent{
Category: item.Category,
Names: make([]string, 0),
})
}
// 内容名称有值合并到数组
if len(item.Name) > 0 {
for index := range pia.PIContents {
piContent := &pia.PIContents[index]
if piContent.Category == item.Category {
piContent.Names = append(piContent.Names, item.Name)
break
}
}
}
}
}
}
piaMap := map[string]*adapter.PerformanceIndicatorAdapter{}
categoryMap := map[string]int{} // 内容分类
//categoryNameMap := map[string]int{} // 内容分类下的名称
/*
// 旧版(如果未填写自评会出现数据评估项丢失的BUG)
hrbp, err := srv.getHRBP(transactionContext, in.CompanyId, in.OperatorId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
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),
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 {
// 有内容分类,才算正常数据,反之不显示
if len(it.ContentCategory) > 0 {
dupleMap[it.TargetUserId] = it.BeginDay
dupleList = append(dupleList, it)
}
}
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),
})
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.ContentName) > 0 {
// 周期筛选过的,不再需要唯一值验证判断,直接添加到对应的分类下
for index := range pia.PIContents {
piContent := &pia.PIContents[index]
if piContent.Category == it.ContentCategory {
piContent.Names = append(piContent.Names, it.ContentName)
break
// 分类名称有值才能合并分类数组
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
// }
// }
//}
}
//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())
}
}
*/
//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
}
... ... @@ -374,8 +519,7 @@ func (srv StaffAssessServeice) ExportPerformanceIndicator(in *query.ExportPerfor
for i := range list {
it := list[i]
if v, ok := selectedMap[it.TargetUserId]; ok {
v.UserName = it.TargetUserName
//v.UserName = it.TargetUserName
if v.Category == it.ContentCategory && v.Name == it.ContentName {
conditionList = append(conditionList, it)
conditionMap[it.TargetUserId+it.BeginDay] = it
... ...
... ... @@ -383,7 +383,8 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int,
t_staff_assess_0.target_user_name,
t_staff_assess_0.begin_day,
t_staff_assess_0.cycle_name,
t_staff_assess_0.cycle_id
t_staff_assess_0.cycle_id,
t_staff_assess_0.evaluation_project_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,
... ... @@ -391,7 +392,8 @@ func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int,
t_staff_assess_0.target_user_name,
t_staff_assess_0.begin_day,
t_staff_assess_0.cycle_name,
t_staff_assess_0.cycle_id
t_staff_assess_0.cycle_id,
t_staff_assess_0.evaluation_project_id
from t_staff_assess_0
join t_user_1 on t_staff_assess_0.target_user_id=t_user_1.user_id
)
... ... @@ -804,6 +806,38 @@ func (d *StaffAssessDao) MemberPerformanceIndicator(likeUserName string, company
}
type IndicatorUserProject struct {
AssessId int `json:"assessId"` // ID
TargetUserId int `json:"targetUserId"` // 目标用户ID
TargetUserName string `json:"targetUserName"` // 目标用户名称
EvaluationProjectId int `json:"evaluationProjectId"` // 项目ID
}
func (d *StaffAssessDao) MemberAllProjectId(companyId int, likeUserName string, operatorId int, cycleId int, hrbp int) ([]IndicatorUserProject, error) {
sqlStr := ` select
t_staff_assess_1.evaluation_project_id,
t_staff_assess_1.target_user_id,
t_staff_assess_1.target_user_name,
t_staff_assess_1.assess_id
from t_staff_assess_1
where 1=1
`
var condition []interface{}
if len(likeUserName) > 0 {
sqlStr += ` and t_staff_assess_1.target_user_name like ? `
condition = append(condition, "%"+likeUserName+"%")
}
// 获取前置sql语句
sqlStr0 := d.useTStaffAssess(companyId, cycleId, operatorId, "", hrbp, 0, 5000, string(domain.AssessSelf))
sqlStr = sqlStr0 + sqlStr
tx := d.transactionContext.PgTx
var result []IndicatorUserProject
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
type ExportPerformanceIndicator struct {
AssessId int `json:"assessId"` // ID
TargetUserId string `json:"targetUserId"` // 被评估人的id
... ...
... ... @@ -128,9 +128,15 @@ func (repo *StaffAssessRepository) Find(queryOptions map[string]interface{}) (in
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
}
if v, ok := queryOptions["id"]; ok {
query.Where("staff_assess.id=?", v)
}
if v, ok := queryOptions["targetUserId"]; ok {
query.Where(`staff_assess.target_user->>'userId'='?'`, v)
}
if v, ok := queryOptions["targetUserIds"]; ok {
query.Where(`staff_assess.target_user->>'userId' in(?)`, pg.In(v))
}
if v, ok := queryOptions["targetUserName"].(string); ok {
query.Where(`staff_assess.target_user->>'userName' like ?`, fmt.Sprintf("%%%v%%", v))
... ... @@ -138,16 +144,14 @@ func (repo *StaffAssessRepository) Find(queryOptions map[string]interface{}) (in
if v, ok := queryOptions["executorId"]; ok {
query.Where(`staff_assess.executor->>'userId'='?'`, v)
}
if v, ok := queryOptions["cycleId"]; ok {
query.Where(`staff_assess.cycle_id=?`, v)
}
if v, ok := queryOptions["staffAssessTaskId"]; ok {
query.Where(`staff_assess.staff_assess_task_id=?`, v)
}
if v, ok := queryOptions["id"]; ok {
query.Where("staff_assess.id=?", v)
if v, ok := queryOptions["types"]; ok {
query.Where(`staff_assess.types=?`, v)
}
if v, ok := queryOptions["typesList"].([]string); ok {
query.Where("staff_assess.types in(?)", pg.In(v))
... ...