作者 tangxvhui

暂存

@@ -65,3 +65,6 @@ func (srv StaffAssessServeice) ListAllAssessCycleDay(param *query.ListAssessCycl @@ -65,3 +65,6 @@ func (srv StaffAssessServeice) ListAllAssessCycleDay(param *query.ListAssessCycl
65 } 65 }
66 return result, nil 66 return result, nil
67 } 67 }
  68 +
  69 +//根据周期id和日期获取 员工填写评估内容
  70 +// 有过滤查看权限
1 package dao 1 package dao
2 2
3 import ( 3 import (
  4 + "fmt"
4 "strconv" 5 "strconv"
5 6
6 "github.com/go-pg/pg/v10" 7 "github.com/go-pg/pg/v10"
@@ -152,149 +153,140 @@ func (d *StaffAssessDao) AllAssessCycleDayList(companyId int, cycleId int) ([]As @@ -152,149 +153,140 @@ func (d *StaffAssessDao) AllAssessCycleDayList(companyId int, cycleId int) ([]As
152 return result, err 153 return result, err
153 } 154 }
154 155
155 -//根据周期的id和日期获取员工填写的评估内容  
156 -  
157 -/**  
158 -with assess_list as(  
159 -select  
160 - staff_assess.id as staff_assess_id,  
161 - staff_assess.target_user ->>'userId' as target_user_id,  
162 - staff_assess.target_user ->>'userName' as target_user_name,  
163 - staff_assess.evaluation_project_id,  
164 - to_char( staff_assess.begin_time,'YYYY-MM-DD') as begin_day  
165 -from staff_assess  
166 -where staff_assess.cycle_id = 1594521861704650752  
167 -and to_char( staff_assess.begin_time,'YYYY-MM-DD') ='2022-11-22'  
168 -and staff_assess."types" ='self'  
169 -limit 5 offset 0  
170 -)  
171 -select  
172 -assess_list.target_user_id,  
173 -assess_list.target_user_name,  
174 -assess_list.begin_day,  
175 -assess_list.evaluation_project_id,  
176 -staff_assess_content.value ,  
177 -staff_assess_content.sort_by ,  
178 -staff_assess_content.category ,  
179 -staff_assess_content."name" ,  
180 -staff_assess_content.weight  
181 -from staff_assess_content  
182 -right join assess_list on assess_list.staff_assess_id = staff_assess_content.staff_assess_id  
183 -  
184 -**/  
185 -  
186 //获取员工填写评估内容 156 //获取员工填写评估内容
187 type UserAssessContent struct { 157 type UserAssessContent struct {
188 - TargetUserId string //被评估人的id  
189 - TargetUserName string //被评估人的名称  
190 - BeginDay string //评估的日期  
191 - EvaluationProjectId string //项目id  
192 - Value string //评估填写的值  
193 - SortBy int //评估项顺序  
194 - Category string //分类  
195 - Name string //名称  
196 - Weight int //权重 158 + TargetUserId string `json:"targetUserId"` //被评估人的id
  159 + TargetUserName string `json:"targetUserName"` //被评估人的名称
  160 + BeginDay string `json:"beginDay"` //评估的日期
  161 + EvaluationProjectId string `json:"evaluationProjectId"` //项目id
  162 + Value string `json:"value"` //评估填写的值
  163 + SortBy int `json:"sortBy"` //评估项顺序
  164 + Category string `json:"category"` //评估项分类
  165 + ContentName string `json:"contentName"` //评估项名称
  166 + Weight int `json:"weight"` //权重
197 } 167 }
198 168
199 type SearchConditin1 struct { 169 type SearchConditin1 struct {
200 - CycleId int //周期id  
201 - BeginDay string //评估的日期  
202 - UserName string //被评估人的名称  
203 - Limit int //分页  
204 - Offset int //分页  
205 - DepartmentId []int //  
206 - OperaterId int //用户的id是谁在搜索数据  
207 - IsHrBp bool // 170 + CompanyId int //公司id
  171 + CycleId int //周期id
  172 + BeginDay string //评估的日期
  173 + TargetUserName string //被评估人的名称
  174 + Limit int //分页
  175 + Offset int //分页
  176 + OperaterId int //用户的id是谁在搜索数据
  177 + Hrbp int //
208 } 178 }
209 179
210 //根据周期的id和日期获取员工填写的评估内容 180 //根据周期的id和日期获取员工填写的评估内容
211 -//cycleId 周期id  
212 -//beginDay 评估任务的生成日期  
213 -//userName 被评估的员工名称,  
214 -// limit offset 分页搜索 181 +//companyId int 公司id
  182 +//cycleId int, 评估周期id
  183 +//userId int, 用户id,谁要查看数据
  184 +//beginDay string, 周期中执行项目的时间
  185 +//hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
  186 +//limit int, 分页条数
  187 +//offset int 分页偏移
215 func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserAssessContent, error) { 188 func (d *StaffAssessDao) SearchUserAssessContent(param SearchConditin1) ([]UserAssessContent, error) {
216 - sqlStr := `with assess_list as(  
217 - select  
218 - staff_assess.id as staff_assess_id,  
219 - staff_assess.target_user ->>'userId' as target_user_id,  
220 - staff_assess.target_user ->>'userName' as target_user_name,  
221 - staff_assess.evaluation_project_id,  
222 - to_char( staff_assess.begin_time,'YYYY-MM-DD') as begin_day  
223 - from staff_assess  
224 - where staff_assess.cycle_id = ?  
225 - and to_char( staff_assess.begin_time,'YYYY-MM-DD') ='?'  
226 - and staff_assess."types" ='self'  
227 - and staff_assess.target_user ->>'userName' like '?'  
228 - limit ? offset ?  
229 - )  
230 - select  
231 - assess_list.target_user_id,  
232 - assess_list.target_user_name,  
233 - assess_list.begin_day,  
234 - assess_list.evaluation_project_id,  
235 - staff_assess_content.value ,  
236 - staff_assess_content.sort_by ,  
237 - staff_assess_content.category ,  
238 - staff_assess_content."name" ,  
239 - staff_assess_content.weight  
240 - from staff_assess_content  
241 - right join assess_list on assess_list.staff_assess_id = staff_assess_content.staff_assess_id  
242 - order by convert_to(assess_list.target_user_name,'GBK') `  
243 -  
244 - tx := d.transactionContext.PgTx  
245 - condition := []interface{}{  
246 - param.CycleId, param.BeginDay, "%" + param.UserName + "%", param.Limit, param.Offset, 189 + sqlStr := ` select
  190 + t_staff_assess_1.target_user_id,t_staff_assess_1.target_user_name,t_staff_assess_1.begin_day,
  191 + staff_assess_content.value ,staff_assess_content.sort_by ,
  192 + staff_assess_content.category ,staff_assess_content."name" as content_name ,
  193 + staff_assess_content.weight
  194 + from t_staff_assess_1
  195 + left join staff_assess_content on t_staff_assess_1.assess_id = staff_assess_content.staff_assess_id
  196 + `
  197 + condition := []interface{}{}
  198 + if len(param.TargetUserName) > 0 {
  199 + sqlStr += ` where t_staff_assess_1.target_user_name like ? `
  200 + condition = append(condition, param.TargetUserName)
247 } 201 }
  202 + //加入排序
  203 + sqlStr += ` order by convert_to(t_staff_assess_1.target_user_name,'GBK'),staff_assess_content.sort_by `
  204 + //获取前置sql语句
  205 + sqlStr0 := d.useTStaffAssess(param.CompanyId, param.CycleId, param.OperaterId, param.BeginDay, param.Hrbp, param.Limit, param.Offset)
  206 + sqlStr = sqlStr0 + sqlStr
  207 + tx := d.transactionContext.PgTx
248 var result []UserAssessContent 208 var result []UserAssessContent
249 _, err := tx.QueryOne(&result, sqlStr, condition...) 209 _, err := tx.QueryOne(&result, sqlStr, condition...)
250 return result, err 210 return result, err
251 } 211 }
252 212
253 -// 根据用户的查看权限 合并用户  
254 -// with t_user_department as (  
255 -// select "user".id as user_id ,jsonb_array_elements_text ("user".department_id) as depart_id from "user"  
256 -// where "user".company_id= 526  
257 -// ),  
258 -// t_department as (  
259 -// select department.id::text as depart_id from department where charge_user_ids @>'[3330208201102336]'  
260 -// ),  
261 -// -- 如果是部门管理员 获取用户列表  
262 -// t_user_1 as (  
263 -// select t_user_department.user_id from t_user_department  
264 -// join t_department on t_user_department.depart_id = t_department.depart_id  
265 -// ),  
266 -// -- 如果是hrbp  
267 -// t_user_2 as(  
268 -// select jsonb_array_elements_text (evaluation_project.recipients) as user_id  
269 -// from evaluation_project  
270 -// where evaluation_project.cycle_id =1592787960795762688  
271 -// and evaluation_project.hr_bp = 1  
272 -// ),  
273 -// -- 如果是项目管理员  
274 -// t_user_3 as(  
275 -// select jsonb_array_elements_text (evaluation_project.recipients) as user_id  
276 -// from evaluation_project  
277 -// where evaluation_project.cycle_id =1592787960795762688  
278 -// and evaluation_project.pmp =1  
279 -// and evaluation_project.pmp_ids @>'[3330208201102336]'  
280 -// ),  
281 -// -- 合并用户  
282 -// t_user_all as(  
283 -// select t_user_1.user_id::text from t_user_1  
284 -// union  
285 -// select t_user_2.user_id::text from t_user_2  
286 -// union  
287 -// select t_user_3.user_id::text from t_user_3  
288 -// ),  
289 -// -- 根据用户提取评估列表  
290 -// t_staff_assess as(  
291 -// select staff_assess.id as assess_id,  
292 -// staff_assess.target_user->>'userId' as user_id,  
293 -// staff_assess.target_user->>'userName' as user_name  
294 -// from staff_assess  
295 -// join t_user_all on staff_assess.target_user->>'userId'= t_user_all.user_id  
296 -// where staff_assess.cycle_id = 1592787960795762688  
297 -// and to_char(staff_assess.begin_time,'YYYY-MM-DD')='2022-11-24'  
298 -// and staff_assess."types" ='self'  
299 -// limit 1 offset 0  
300 -// ) 213 +//生成的sql 根据用户的查看权限 ,获取可查看的评估任务,
  214 +//companyId int 公司id
  215 +//cycleId int, 评估周期id
  216 +//userId int, 用户id,谁要查看数据
  217 +//beginDay string, 周期中执行项目的时间
  218 +//hrbp 是否搜索HRBP角色的用户可以查看,1:是;-1:否
  219 +//limit int, 分页条数
  220 +//offset int 分页偏移
  221 +func (d *StaffAssessDao) useTStaffAssess(companyId int, cycleId int, userId int, beginDay string, hrbp int, limit int, offset int) string {
  222 + sqlstr := `
  223 + with t_user_department as (
  224 + select "user".id as user_id ,jsonb_array_elements_text ("user".department_id) as depart_id from "user"
  225 + where "user".company_id= %d
  226 + ),
  227 + t_department as (
  228 + select department.id::text as depart_id from department where charge_user_ids @>'[%d]'
  229 + ),
  230 + -- 如果是部门管理员 获取用户列表
  231 + t_user_1 as (
  232 + select t_user_department.user_id::text from t_user_department
  233 + join t_department on t_user_department.depart_id = t_department.depart_id
  234 + ),
  235 + -- 如果是hrbp
  236 + t_project_1 as(
  237 + select evaluation_project.id as project_id
  238 + from evaluation_project
  239 + where evaluation_project.cycle_id =%d
  240 + and evaluation_project.hr_bp = %d
  241 + ),
  242 + -- 如果是项目管理员
  243 + t_project_2 as(
  244 + select evaluation_project.id as project_id
  245 + from evaluation_project
  246 + where evaluation_project.cycle_id =%d
  247 + and evaluation_project.pmp =1
  248 + and evaluation_project.pmp_ids @>'["%d"]'
  249 + ),
  250 + -- 合并数据
  251 + t_project_3 as (
  252 + select t_project_2.project_id from t_project_2
  253 + union
  254 + select t_project_1.project_id from t_project_1
  255 + ),
  256 + -- 初步过滤评估列表数据
  257 + t_staff_assess_0 as (
  258 + select staff_assess.id as assess_id,
  259 + staff_assess.target_user->>'userId' as target_user_id,
  260 + staff_assess.target_user->>'userName' as target_user_name,
  261 + to_char(staff_assess.begin_time,'YYYY-MM-DD') as begin_day,
  262 + staff_assess.evaluation_project_id
  263 + from staff_assess
  264 + where staff_assess.cycle_id = %d
  265 + and to_char(staff_assess.begin_time,'YYYY-MM-DD')='%s'
  266 + and staff_assess."types" ='self'
  267 + ),
  268 + -- 合并根据权限过滤后的数据
  269 + t_staff_assess_1 as (
  270 + (select t_staff_assess_0.assess_id,
  271 + t_staff_assess_0.target_user_id,
  272 + t_staff_assess_0.target_user_name,
  273 + t_staff_assess_0.begin_day
  274 + from t_staff_assess_0
  275 + join t_project_3 on t_staff_assess_0.evaluation_project_id = t_project_3.project_id
  276 + ) union (select t_staff_assess_0.assess_id,
  277 + t_staff_assess_0.target_user_id,
  278 + t_staff_assess_0.target_user_name,
  279 + t_staff_assess_0.begin_day
  280 + from t_staff_assess_0
  281 + join t_user_1 on t_staff_assess_0.target_user_id=t_user_1.user_id
  282 + )
  283 + limit %d offset %d
  284 + )
  285 + `
  286 + params := []interface{}{
  287 + companyId, userId, cycleId, hrbp, cycleId, userId, cycleId, beginDay, limit, offset,
  288 + }
  289 +
  290 + sqlstr = fmt.Sprintf(sqlstr, params...)
  291 + return sqlstr
  292 +}