作者 tangxvhui

日常保存

... ... @@ -5,10 +5,10 @@ import (
"github.com/xuri/excelize/v2"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
)
//数据导出
// 数据导出
func (srv *StaffAssessServeice) ExportUserAssess2V2(param *query.ExportUserAssess2Commad) (*excelize.File, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -20,18 +20,59 @@ func (srv *StaffAssessServeice) ExportUserAssess2V2(param *query.ExportUserAsses
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperatorId)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// 按照cycleId 获取项目
// 按照项目获取指标项
hrbp, err := srv.getHRBP(transactionContext, param.CompanyId, param.OperatorId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
assessDao := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
// 按照cycleId获取项目的指标项
evaluationItemList, err := assessDao.SearchEvaluationItemUsed2(param.CompanyId,
param.CycleId, param.OperatorId, hrbp, param.ExportUserId)
// 按照项目获取填写的内容
assessContentList, err := assessDao.SearchEvaluationItemUsed2(param.CompanyId,
param.CycleId, param.OperatorId, hrbp, param.ExportUserId)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil, nil
}
// 处理原始数据,方便进行 excel导出
type exportData3 struct {
sheetList []string //excel的sheet列表
tableHeader map[string]*HeaderLevel //表头数据
}
func (e *exportData3) FormatTableHead(param []dao.DataEvaluationItemUsed2) {
userNameMap := map[string]struct{}{} //员工名字过滤
userProjcetMap := map[string]map[string]string{}
userIdName := map[string]string{} //员工id=> 员工名称
sheetMap := HeaderLevel{}
for _, val := range param {
// child := sheetMap.addChild(val.TargetUserId)
// _ = child.addChild(val.EvaluationProjectId)
if _, ok := userNameMap[val.TargetUserId]; !ok {
userProjcetMap[val.TargetUserId] = map[string]string{}
}
userProjcetMap[val.TargetUserId][val.EvaluationProjectId] = ""
if _, ok := userIdName[val.TargetUserId]; !ok {
userIdName[val.TargetUserId] = val.TargetUserName
userNameMap[val.TargetUserName] = struct{}{}
}
}
for _, val := range sheetMap.Child {
}
}
func (e *exportData3) FormatListValue(param []dao.DataStaffAssessContent2) {
}
func (e *exportData3) DataKey(userName string, projectId string, beginDay string, category string, weight string, contentName string) string {
return ""
}
... ...
... ... @@ -131,10 +131,6 @@ func (e *exportData) weightDesc(weight float64) string {
}
}
// func (e *exportData) userDayKey(userName string) string {
// return userName
// }
type exportData2 struct {
tableHeader HeaderLevel //数据表格对应表头
userIdMap map[string]string //员工id 对应的名称
... ...
package dao
// SearchStaffAssessByCycle 按照周期id获取评估任务,并进行人员可查看权限的过滤
// companyId 公司id
import (
"fmt"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type DataStaffAssessContent2 struct {
CycleId string `pg:"cycle_id"` //周期id
CycleName string `pg:"cycle_name"` //周期名称
EvaluationProjectId string `pg:"evaluation_project_id"` //
TargetUserId string `pg:"target_user_id"` //被评估人的id
TargetUserName string `pg:"target_user_name"` //被评估人的名称
BeginDay string `pg:"begin_day"` //评估的日期
Value string `pg:"value"` //评估填写的值
Category string `pg:"category"` //评估项分类
ContentName string `pg:"content_name"` //评估项名称
Weight float64 `pg:"weight"` //权重
PromptText string `pg:"prompt_text"` //评估标准
Remark []domain.AssessContemtRemark `pg:"remark"`
}
// SearchStaffAssessContent2 用于员工绩效-综合管理-导出绩效-个人
// 获取所有评估的填写内容
// companyId 公司id
// cycleId 周期id
// operaterId 操作人、查看人的id
// hrbp 操作人、查看人是否hrbp 1:是;-1:否
func (d *StaffAssessDao) SearchStaffAssessByCycle(companyId int, cycleId int, operaterId int, hrbp int, exportUserIds []string) {
func (d *StaffAssessDao) SearchStaffAssessContent2(companyId int, cycleId int, operaterId int, hrbp int, exportUserIds []string) (
[]DataStaffAssessContent2, error) {
withSql := d.catchProjectIdByPermission(companyId, cycleId, operaterId, hrbp)
sqlStr := ` select
staff_assess.target_user ->>'userId' as target_user_id,
staff_assess.evaluation_project_id,
staff_assess.target_user ->>'userName' as target_user_name,
to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day,
staff_assess.cycle_id,
staff_assess.cycle_name,
staff_assess_content.value ,
staff_assess_content.category ,
staff_assess_content."name" as content_name ,
staff_assess_content.weight,
staff_assess_content.prompt_text ,
staff_assess_content.remark
from staff_assess
join staff_assess_content on staff_assess.id = staff_assess_content.staff_assess_id
where 1=1
and staff_assess.cycle_id =? and "types" ='self'
and staff_assess.evaluation_project_id in (
select t_project_4.project_id from t_project_4
) `
condition := []interface{}{cycleId}
if len(exportUserIds) > 0 {
sqlStr += ` and staff_assess.target_user->>'userId' in(?) `
condition = append(condition, pg.In(exportUserIds))
}
sqlStr = withSql + sqlStr
result := []DataStaffAssessContent2{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
type DataEvaluationItemUsed2 struct {
CycleId string `pg:"cycle_id"` //周期id
CycleName string `pg:"cycle_name"` //周期名称
EvaluationProjectId string `pg:"evaluation_project_id"` //评估的项目
TargetUserId string `pg:"target_user_id"` //被评估人的id
TargetUserName string `pg:"target_user_name"` //被评估人的名称
BeginDay string `pg:"begin_day"` //评估的日期
Category string `pg:"category"` //评估项分类
ContentName string `pg:"content_name"` //评估项名称
Weight float64 `pg:"weight"` //权重
PromptText string `pg:"prompt_text"` //评估标准
}
// SearchEvaluationItemUsed2 用于员工绩效-综合管理-导出绩效-个人
// 获取所有评估的填写项
// companyId 公司id
// cycleId 周期id
// operaterId 操作人、查看人的id
// hrbp 操作人、查看人是否hrbp 1:是;-1:否
func (d *StaffAssessDao) SearchEvaluationItemUsed2(companyId int, cycleId int, operaterId int, hrbp int, exportUserIds []string) (
[]DataEvaluationItemUsed2, error) {
withSql := d.catchProjectIdByPermission(companyId, cycleId, operaterId, hrbp)
sqlStr := `select
staff_assess.target_user ->>'userId' as target_user_id,
staff_assess.evaluation_project_id ,
staff_assess.target_user ->>'userName' as target_user_name,
to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day,
staff_assess.cycle_id,
staff_assess.cycle_name,
evaluation_item_used.category ,
evaluation_item_used."name" as content_name ,
evaluation_item_used.weight,
evaluation_item_used.prompt_text
from staff_assess
join evaluation_item_used on evaluation_item_used.evaluation_project_id = staff_assess.evaluation_project_id
where 1=1
and staff_assess.cycle_id =? and "types" ='self'
and staff_assess.evaluation_project_id in (
select evaluation_project.id from evaluation_project limit 10
) `
condition := []interface{}{cycleId}
if len(exportUserIds) > 0 {
sqlStr += ` and staff_assess.target_user->>'userId' in(?) `
condition = append(condition, pg.In(exportUserIds))
}
sqlStr = withSql + sqlStr
result := []DataEvaluationItemUsed2{}
tx := d.transactionContext.PgTx
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
// sql 语句片段
// 按照人员可查看权限的过滤
func (d *StaffAssessDao) catchProjectByPermission(companyId int, cycleId int, operaterId int, hrbp int) string {
return ""
// companyId int 公司id (必填)
// cycleId int, 评估周期id (必填)
// userId int, 用户id,谁要查看数据 (必填)
// hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否 (必填)
func (d *StaffAssessDao) catchProjectIdByPermission(companyId int, cycleId int, operaterId int, hrbp int) string {
withSql := `
with
t_project_0 as(
select evaluation_project.id as project_id,
jsonb_array_elements_text(evaluation_project.recipients) as target_user_id,
evaluation_project.pmp,
evaluation_project.pmp_ids,
evaluation_project.hr_bp
from evaluation_project
where evaluation_project.cycle_id =%d
and evaluation_project.deleted_at isnull
),
-- 查我的下级员工
t_user_1 as (
select "user".id::text as user_id from "user"
where "user".parent_id =%d and company_id=%d
),
-- 如果是HRBP
t_project_1 as(
select t_project_0.project_id,t_project_0.target_user_id
from t_project_0
where t_project_0.hr_bp =%d
),
-- 如果的项目管理员
t_project_2 as(
select t_project_0.project_id,t_project_0.target_user_id
from t_project_0
where t_project_0.pmp =1
and t_project_0.pmp_ids @>'["%d"]'
),
-- 如果是上级员工
t_project_3 as (
select t_project_0.project_id,t_project_0.target_user_id
from t_project_0
join t_user_1 on t_user_1.user_id = t_project_0.target_user_id
),
-- 合并数据
t_project_4 as (
select t_project_2.project_id,t_project_2.target_user_id from t_project_2
union
select t_project_1.project_id,t_project_1.target_user_id from t_project_1
union
select t_project_3.project_id,t_project_3.target_user_id from t_project_3
)`
params := []interface{}{cycleId, operaterId, companyId, hrbp, operaterId}
return fmt.Sprintf(withSql, params...)
}
... ...