ListController.class.php
7.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/10/11
* Time: 17:41
*/
namespace Apicp\Controller\UserData;
use Com\PackageValidate;
use Common\Common\Constant;
use Common\Common\User;
use Common\Common\ExamHelper;
use Common\Common\CourseHelper;
use Common\Model\CourseArticleModel;
use Common\Model\CourseCompleteModel;
use Common\Model\CourseStudyTimeModel;
class ListController extends \Apicp\Controller\AbstractController
{
/**
* List
* @author liyifei
* @desc 员工数据总览,列表接口
* @param Int page:1 当前页
* @param Int limit:20 当前页条数
* @param Array dp_ids 组织ID
* @param Array role_ids 角色ID
* @param Array job_ids 岗位ID
* @param String username 姓名
* @return array
array(
'page' => 1, // 当前页
'limit' => 20, // 当前页条数
'total' => 100, // 总条数
'list' => array( // 列表数据
array(
'uid' => 'B4B3B9D17F00000173E870DA9A855AE7', // 人员UID
'username' => '李四', // 姓名
'dp_names' => array('开发组', '测试组'), // 组织
'job' => '苹果系统工程师', // 岗位
'role' => 'leader', // 角色
'course_complete_total' => 15, // 课程已完成数
'course_total' => 20, // 课程可完成数
'course_complete_rate' => 80.88, // 课程完成率
'study_time' => 999, // 课程学习时长(秒)
'exam_pass_total' => 9, // 考试及格数
'exam_total' => 10, // 可考试总数
'exam_rate' => 99.99, // 考试及格率
'questionnaire_total' => 5, // 参加调研数
'train_total' => 10, // 参加培训次数
),
),
)
*/
public function Index_post()
{
// 验证规则
$rules = [
'page' => 'integer|gt:0',
'limit' => 'integer|gt:0',
'dp_ids' => 'array',
'role_ids' => 'array',
'job_ids' => 'array',
'username' => 'max:64',
];
// 验证请求数据
$postData = I('post.');
$validate = new PackageValidate();
$validate->postData = $postData;
$validate->validateParams($rules);
// 分页
$page = isset($postData['page']) ? $postData['page'] : Constant::PAGING_DEFAULT_PAGE;
$limit = isset($postData['limit']) ? $postData['limit'] : Constant::PAGING_DEFAULT_LIMIT;
// 组合搜索条件
$conds = [];
if (isset($postData['dp_ids'])) {
$conds['dpIdList'] = $postData['dp_ids'];
// 按部门条件查询时,表示部门是否递归查询人员 【0:不递归(默认值)、1:递归】
$conds['departmentChildrenFlag'] = 1;
}
if (isset($postData['role_ids'])) {
$conds['roleIdList'] = $postData['role_ids'];
}
if (isset($postData['job_ids'])) {
$conds['jobIdList'] = $postData['job_ids'];
}
if (isset($postData['username'])) {
$conds['memUsername'] = $postData['username'];
}
// 获取符合条件的人员UID
$list = [];
$userServ = &User::instance();
$userList = $userServ->listByConds($conds, $page, $limit);
if (isset($userList['list']) && !empty($userList['list'])) {
$uids = array_column($userList['list'], 'memUid');
// 调用西安代军完成考试、调研、培训数据方法
$examHelper = &ExamHelper::instance();
$examList = $examHelper->list_exam_train_questionnaire_data($userList['list']);
// 查询常规课程id集合
$course_article = new CourseArticleModel();
$course_article_list = $course_article->list_by_conds(['course_type' => Constant::COURSE_TYPE_NORMAL], null, [], 'article_id,data_id,article_type');
$articles = array_column($course_article_list,'article_id');
// 课程已完成数据
$completeModel = new CourseCompleteModel();
$completeList = $completeModel->completeTotalByUids($uids,$articles);
if (!empty($completeList)) {
$completeList = array_combine_by_key($completeList, 'uid');
}
// 课程学习时长
$studyTimeModel = new CourseStudyTimeModel();
$studyTimeList = $studyTimeModel->listStudyTimeByUids($uids,$articles);
if (!empty($studyTimeList)) {
$studyTimeList = array_combine_by_key($studyTimeList, 'uid');
}
// 可完成课程
$courseHelper = &CourseHelper::instance();
$userArticleIds = $courseHelper->articleCountByUsers($userList['list'],$articles);
foreach ($userList['list'] as $user) {
$uid = $user['memUid'];
// TODO liyifei 用户可完成课程数(逻辑是否可优化)
$articleIds = $userArticleIds[$user['memUid']];
// 课程完成率
$completeTotal = isset($completeList[$uid]['total']) ? (int)$completeList[$uid]['total'] : 0;
$courseTotal = count($articleIds);
$completeRate = $courseTotal > 0 ? round($completeTotal / $courseTotal * 100, 2) : 0;
// 考试及格率
$examPassTotal = isset($examList[$uid]['exam_pass_total']) ? $examList[$uid]['exam_pass_total'] : 0;
$examTotal = isset($examList[$uid]['exam_total']) ? $examList[$uid]['exam_total'] : 0;
$examRate = $examTotal > 0 ? round($examPassTotal / $examTotal * 100, 2) : 0;
$list[] = [
'uid' => $uid,
'username' => $user['memUsername'],
'dp_names' => isset($user['dpName']) && !empty($user['dpName']) ? array_column($user['dpName'], 'dpName') : [],
'job' => $user['memJob'],
'role' => $user['memRole'],
'course_complete_total' => $completeTotal,
'course_total' => $courseTotal,
'course_complete_rate' => $completeRate > 100 ? 100 : $completeRate,
'study_time' => isset($studyTimeList[$uid]['study_time']) ? intval($studyTimeList[$uid]['study_time']) : 0,
'exam_pass_total' => $examPassTotal,
'exam_total' => $examTotal,
'exam_rate' => $examRate,
'questionnaire_total' => isset($examList[$uid]['questionnaire_total']) ? $examList[$uid]['questionnaire_total'] : 0,
'train_total' => isset($examList[$uid]['train_total']) ? $examList[$uid]['train_total'] : 0,
];
}
}
$this->_result = [
'page' => $userList['pageNum'],
'limit' => $userList['pageSize'],
'total' => $userList['total'],
'list' => $list
];
}
}