generated from container/tmpl
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
185 lines
7.0 KiB
185 lines
7.0 KiB
2 years ago
|
def querystring_user_procinst_duration(start, end, except_senior, department):
|
||
|
filter_user = "and u.name not in ('刘文峰', '金亮', '姜珍', '余莎莎', '张阳根', '唐国华', '刘国勇', '刘会连', '肖琥')" if except_senior else ""
|
||
|
filter_department = "and department_name='{}'".format(department) if department else ""
|
||
|
return '''
|
||
|
select department_name,
|
||
|
user_name,
|
||
|
procinst_id,
|
||
|
sum(duration_in_minutes) as procinst_duration_in_minutes
|
||
|
from (
|
||
|
select distinct d.id as department_id,
|
||
|
d.name as department_name,
|
||
|
u.id as user_id,
|
||
|
u.name as user_name,
|
||
|
wp.name as process_name,
|
||
|
wpa.procinst_id as procinst_id,
|
||
|
wpa.task_id as taskinst_id,
|
||
|
wpa.task_name as task_name,
|
||
|
wpa.start_time as start_time,
|
||
|
wpa.end_time as end_time,
|
||
|
wpa.total_minutes as duration_in_minutes
|
||
|
from workflow_process_achievements as wpa
|
||
|
inner join workflow_process_history as wph on wpa.procinst_id=wph.procinst_id
|
||
|
inner join workflow_process_version as wpv on wph.version_id=wpv.id
|
||
|
inner join workflow_process as wp on wpv.process_id=wp.id
|
||
|
inner join user as u on wpa.deal_user_id=u.id
|
||
|
inner join department_user as du on u.id=du."user"
|
||
|
inner join department as d on du.department=d.id
|
||
|
where wpa.end_time >='{}' and wpa.end_time < '{}' and wp.deleted=false and wp.is_enable=true and d.delete=0 and u.delete=0 and u.state=1 and u.active_status=1
|
||
|
{} {}
|
||
|
) as r
|
||
|
group by department_name, user_name, procinst_id
|
||
|
'''.format(start, end, filter_user, filter_department)
|
||
|
|
||
|
|
||
|
def querystring_senior_procinst_duration(start, end):
|
||
|
return '''
|
||
|
SELECT user_name,
|
||
|
ROUND(AVG(procinst_duration_in_minutes) /60, 2) as procinst_duration_in_hours_by_user
|
||
|
from (
|
||
|
select user_name,
|
||
|
procinst_id,
|
||
|
sum(duration_in_minutes) as procinst_duration_in_minutes
|
||
|
from (
|
||
|
select distinct u.id as user_id,
|
||
|
u.name as user_name,
|
||
|
wp.name as process_name,
|
||
|
wpa.procinst_id as procinst_id,
|
||
|
wpa.task_id as taskinst_id,
|
||
|
wpa.task_name as task_name,
|
||
|
wpa.start_time as start_time,
|
||
|
wpa.end_time as end_time,
|
||
|
wpa.total_minutes as duration_in_minutes
|
||
|
from workflow_process_achievements as wpa
|
||
|
inner join workflow_process_history as wph on wpa.procinst_id=wph.procinst_id
|
||
|
inner join workflow_process_version as wpv on wph.version_id=wpv.id
|
||
|
inner join workflow_process as wp on wpv.process_id=wp.id
|
||
|
inner join user as u on wpa.deal_user_id=u.id
|
||
|
where wpa.end_time >='{}' and wpa.end_time < '{}' and wp.deleted=false and wp.is_enable=true and u.delete=0 and u.state=1 and u.active_status=1
|
||
|
and u.name in ('刘文峰', '金亮', '姜珍', '余莎莎', '张阳根', '唐国华', '刘国勇', '刘会连', '肖琥')
|
||
|
) as r
|
||
|
group by user_name, procinst_id
|
||
|
) as r2
|
||
|
GROUP by r2.user_name
|
||
|
'''.format(start, end)
|
||
|
|
||
|
|
||
|
# 按月统计项企平台使用人数
|
||
|
def querystring_user_count(start, end):
|
||
|
return '''
|
||
|
select count(distinct deal_user_id) as pep_using_user_count
|
||
|
from workflow_process_achievements as wpa
|
||
|
inner join user as u on wpa.deal_user_id=u.id
|
||
|
where wpa.end_time >='{}' and wpa.end_time < '{}' and u.delete=0 and u.state=1 and u.active_status=1
|
||
|
'''.format(start, end)
|
||
|
|
||
|
|
||
|
# 个人处理流程平均耗时
|
||
|
def querystring_procinst_duration_by_company(start, end):
|
||
|
return '''
|
||
|
SELECT ROUND(AVG(procinst_duration_in_minutes_by_user) /60, 2) as procinst_duration_in_hours from (
|
||
|
SELECT user_name,
|
||
|
ROUND(AVG(procinst_duration_in_minutes), 2) as procinst_duration_in_minutes_by_user
|
||
|
from ({}) as r2
|
||
|
GROUP by r2.user_name
|
||
|
) as r3
|
||
|
'''.format(querystring_user_procinst_duration(start, end, False, ''))
|
||
|
|
||
|
|
||
|
# 部门数(高于公司平均数)
|
||
|
def querystring_department_count_gt_avg(start, end, avg):
|
||
|
return '''
|
||
|
SELECT count(*) from (
|
||
|
SELECT department_name,
|
||
|
ROUND(AVG(procinst_duration_in_hours_by_user), 2) as procinst_duration_in_hours_by_department
|
||
|
from (
|
||
|
SELECT department_name,
|
||
|
user_name,
|
||
|
ROUND(AVG(procinst_duration_in_minutes) /60, 2) as procinst_duration_in_hours_by_user
|
||
|
from ({}) as r2
|
||
|
GROUP by r2.department_name, r2.user_name
|
||
|
) as r3
|
||
|
GROUP by r3.department_name
|
||
|
) as r4
|
||
|
WHERE procinst_duration_in_hours_by_department > {}
|
||
|
'''.format(querystring_user_procinst_duration(start, end, True, ''), avg)
|
||
|
|
||
|
|
||
|
# 用户数(高于公司平均数)
|
||
|
def querystring_user_count_gt_avg(start, end, avg):
|
||
|
return '''
|
||
|
SELECT count(*) from (
|
||
|
SELECT user_name,
|
||
|
ROUND(AVG(procinst_duration_in_minutes) /60, 2) as procinst_duration_in_hours_by_user
|
||
|
from ({}) as r2
|
||
|
group by r2.user_name
|
||
|
) as r3
|
||
|
WHERE r3.procinst_duration_in_hours_by_user > {}
|
||
|
'''.format(querystring_user_procinst_duration(start, end, False, ''), avg)
|
||
|
|
||
|
|
||
|
# 部门处理流程平均耗时
|
||
|
def querystring_procinst_duration_by_department(start, end):
|
||
|
return """
|
||
|
SELECT department_name,
|
||
|
ROUND(AVG(procinst_duration_in_hours_by_user), 2) as procinst_duration_in_hours_by_department
|
||
|
from (
|
||
|
SELECT department_name,
|
||
|
user_name,
|
||
|
ROUND(AVG(procinst_duration_in_minutes) /60, 2) as procinst_duration_in_hours_by_user
|
||
|
from ({}) as r2
|
||
|
GROUP by r2.department_name, r2.user_name
|
||
|
) as r3
|
||
|
GROUP by r3.department_name
|
||
|
order by procinst_duration_in_hours_by_department DESC
|
||
|
""".format(querystring_user_procinst_duration(start, end, True, ''))
|
||
|
|
||
|
|
||
|
# 部门处理流程平均耗时(高管)
|
||
|
def querystring_procinst_duration_by_senior(start, end):
|
||
|
return '''
|
||
|
SELECT ROUND(AVG(procinst_duration_in_hours_by_user), 2) as procinst_duration_in_hours_by_department
|
||
|
from ({}) as r3
|
||
|
'''.format(querystring_senior_procinst_duration(start, end))
|
||
|
|
||
|
|
||
|
# 用户单流程处理耗时(高管)
|
||
|
def querystring_procinst_duration_by_user_senior(start, end):
|
||
|
return '''
|
||
|
{}
|
||
|
order by procinst_duration_in_hours_by_user DESC
|
||
|
'''.format(querystring_senior_procinst_duration(start, end))
|
||
|
|
||
|
|
||
|
# 各部门耗时较长用户(高管)
|
||
|
def querystring_user_gt_senior_avg(start, end, avg):
|
||
|
return '''
|
||
|
SELECT * from ({}) as r3
|
||
|
WHERE r3.procinst_duration_in_hours_by_user > {}
|
||
|
order by procinst_duration_in_hours_by_user DESC
|
||
|
'''.format(querystring_senior_procinst_duration(start, end), avg)
|
||
|
|
||
|
|
||
|
# 各部门耗时较长用户
|
||
|
def querystring_user_gt_department_avg(start, end, department, avg):
|
||
|
return """
|
||
|
SELECT * from (
|
||
|
SELECT user_name,
|
||
|
ROUND(AVG(procinst_duration_in_minutes) /60, 2) as procinst_duration_in_hours_by_user
|
||
|
from ({}) as r2
|
||
|
group by r2.user_name
|
||
|
) as r3
|
||
|
WHERE r3.procinst_duration_in_hours_by_user > {}
|
||
|
order by procinst_duration_in_hours_by_user desc
|
||
|
""".format(querystring_user_procinst_duration(start, end, True, department), avg)
|
||
|
|
||
|
|
||
|
# 按部门统计用户单流程处理耗时
|
||
|
def querystring_procinst_duration_by_user(start, end, department):
|
||
|
return """
|
||
|
SELECT user_name,
|
||
|
ROUND(AVG(procinst_duration_in_minutes) /60, 2) as procinst_duration_in_hours_by_user
|
||
|
from ({}) as r2
|
||
|
group by r2.user_name
|
||
|
""".format(querystring_user_procinst_duration(start, end, True, department))
|