|
|
package dao
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"strconv"
|
|
|
|
|
|
"github.com/go-pg/pg/v10"
|
...
|
...
|
@@ -152,4 +153,173 @@ func (d *StaffAssessDao) AllAssessCycleDayList(companyId int, cycleId int) ([]As |
|
|
return result, err
|
|
|
}
|
|
|
|
|
|
//获取员工填写评估内容
|
|
|
type UserAssessContent struct {
|
|
|
TargetUserId string `json:"targetUserId"` //被评估人的id
|
|
|
TargetUserName string `json:"targetUserName"` //被评估人的名称
|
|
|
BeginDay string `json:"beginDay"` //评估的日期
|
|
|
EvaluationProjectId string `json:"evaluationProjectId"` //项目id
|
|
|
Value string `json:"value"` //评估填写的值
|
|
|
SortBy int `json:"sortBy"` //评估项顺序
|
|
|
Category string `json:"category"` //评估项分类
|
|
|
ContentName string `json:"contentName"` //评估项名称
|
|
|
Weight int `json:"weight"` //权重
|
|
|
}
|
|
|
|
|
|
type SearchConditin1 struct {
|
|
|
CompanyId int //公司id
|
|
|
CycleId int //周期id
|
|
|
BeginDay string //评估的日期
|
|
|
TargetUserName string //被评估人的名称
|
|
|
Limit int //分页
|
|
|
Offset int //分页
|
|
|
OperaterId int //用户的id是谁在搜索数据
|
|
|
Hrbp int //
|
|
|
}
|
|
|
|
|
|
//根据周期的id和日期获取员工填写的评估内容
|
|
|
//companyId int 公司id
|
|
|
//cycleId int, 评估周期id
|
|
|
//userId int, 用户id,谁要查看数据
|
|
|
//beginDay string, 周期中执行项目的时间
|
|
|
//hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
|
|
|
//limit int, 分页条数
|
|
|
//offset int 分页偏移
|
|
|
func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserAssessContent, error) {
|
|
|
sqlStr := ` select
|
|
|
t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day,
|
|
|
staff_assess_content.value ,staff_assess_content.sort_by ,
|
|
|
staff_assess_content.category ,staff_assess_content."name" as content_name ,
|
|
|
staff_assess_content.weight
|
|
|
from t_staff_assess_1
|
|
|
left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
|
|
|
`
|
|
|
condition := []interface{}{}
|
|
|
if len(param.TargetUserName) > 0 {
|
|
|
sqlStr += ` where t_staff_assess_1.target_user_name like ? `
|
|
|
condition = append(condition, param.TargetUserName)
|
|
|
}
|
|
|
//加入排序
|
|
|
sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `
|
|
|
//获取前置sql语句
|
|
|
sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, param.Limit, param.Offset)
|
|
|
sqlStr = sqlStr0 + sqlStr
|
|
|
tx := d.transactionContext.PgTx
|
|
|
var result []UserAssessContent
|
|
|
_, err := tx.QueryOne(&result, sqlStr, condition...)
|
|
|
return result, err
|
|
|
}
|
|
|
|
|
|
//根据周期的id和日期获取员工填写的评估内容,数量统计
|
|
|
//companyId int 公司id
|
|
|
//cycleId int, 评估周期id
|
|
|
//userId int, 用户id,谁要查看数据
|
|
|
//beginDay string, 周期中执行项目的时间
|
|
|
//hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
|
|
|
//limit int, 分页条数
|
|
|
//offset int 分页偏移
|
|
|
func (d *StaffAssessDao) CountUserAssess(param SearchConditin1) ([]UserAssessContent, error) {
|
|
|
sqlStr := ` select
|
|
|
t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day,
|
|
|
staff_assess_content.value ,staff_assess_content.sort_by ,
|
|
|
staff_assess_content.category ,staff_assess_content."name" as content_name ,
|
|
|
staff_assess_content.weight
|
|
|
from t_staff_assess_1
|
|
|
left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
|
|
|
`
|
|
|
condition := []interface{}{}
|
|
|
if len(param.TargetUserName) > 0 {
|
|
|
sqlStr += ` where t_staff_assess_1.target_user_name like ? `
|
|
|
condition = append(condition, param.TargetUserName)
|
|
|
}
|
|
|
//加入排序
|
|
|
sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `
|
|
|
//获取前置sql语句
|
|
|
sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, param.Limit, param.Offset)
|
|
|
sqlStr = sqlStr0 + sqlStr
|
|
|
tx := d.transactionContext.PgTx
|
|
|
var result []UserAssessContent
|
|
|
_, err := tx.QueryOne(&result, sqlStr, condition...)
|
|
|
return result, err
|
|
|
}
|
|
|
|
|
|
//生成的sql 根据用户的查看权限 ,获取可查看的评估任务,
|
|
|
//companyId int 公司id
|
|
|
//cycleId int, 评估周期id
|
|
|
//userId int, 用户id,谁要查看数据
|
|
|
//beginDay string, 周期中执行项目的时间
|
|
|
//hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
|
|
|
//limit int, 分页条数
|
|
|
//offset int 分页偏移
|
|
|
func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, beginDay string, hrbp int, limit int, offset int) string {
|
|
|
sqlstr := `
|
|
|
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
|
|
|
),
|
|
|
t_department as (
|
|
|
select department.id::text as depart_id from department where charge_user_ids @>'[%d]'
|
|
|
),
|
|
|
-- 如果是部门管理员 获取用户列表
|
|
|
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
|
|
|
),
|
|
|
-- 如果是项目管理员
|
|
|
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"]'
|
|
|
),
|
|
|
-- 合并数据
|
|
|
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.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
|
|
|
where staff_assess.cycle_id = %d
|
|
|
and to_char(staff_assess.begin_time,'YYYY-MM-DD')='%s'
|
|
|
and staff_assess."types" ='self'
|
|
|
),
|
|
|
-- 合并根据权限过滤后的数据
|
|
|
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
|
|
|
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
|
|
|
from t_staff_assess_0
|
|
|
join t_user_1 on t_staff_assess_0.target_user_id=t_user_1.user_id
|
|
|
)
|
|
|
limit %d offset %d
|
|
|
)
|
|
|
`
|
|
|
params := []interface{}{
|
|
|
companyId, userId, cycleId, hrbp, cycleId, userId, cycleId, beginDay, limit, offset,
|
|
|
}
|
|
|
|
|
|
sqlstr = fmt.Sprintf(sqlstr, params...)
|
|
|
return sqlstr
|
|
|
} |
...
|
...
|
|