ExportController.class.php
3.34 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
<?php
/**
* Created by PhpStorm.
* User: zhonglei
* Date: 17/7/27
* Time: 17:12
*/
namespace Apicp\Controller\Customtask;
use Com\PackageValidate;
use Com\PythonExcel;
use Common\Common\Constant;
use Common\Common\ExportDownload;
use Common\Common\TaskHelper;
use Common\Service\CustomtaskService;
class ExportController extends \Apicp\Controller\AbstractController
{
/**
* Export
* @author zhonglei
* @desc 导出常规任务完成情况接口
* @param Int customtask_id:true 常规任务ID
* @param Array dp_ids 部门ID数组
* @param Array job_ids 岗位ID数组
* @param Array role_ids 角色ID数组
* @param String username 姓名
* @param Int status:true 完成情况(1=未参与;2=执行中;3=已完成)
* @return void
*/
public function Index_post()
{
// 请求数据
$post_data = I('post.');
// 验证规则
$rules = [
'customtask_id' => 'require|integer',
'dp_ids' => 'array',
'job_ids' => 'array',
'role_ids' => 'array',
'username' => 'max:50',
'status' => 'require|in:1,2,3',
];
// 验证请求数据
$validate = new PackageValidate();
$validate->postData = $post_data;
$validate->validateParams($rules);
// 获取任务数据
$taskServ = new CustomtaskService();
$customtask = $taskServ->get($post_data['customtask_id']);
if (empty($customtask)) {
E('_ERR_CUSTOMTASK_NOT_FOUND');
}
// 获取人员列表
$taskHelper = &TaskHelper::instance();
$result = $taskHelper->listCustomtaskUser($post_data);
$rows = [];
foreach ($result['list'] as $v) {
$task_status = '';
switch ($v['complete_status']) {
case Constant::USER_TASK_COMPLETE_STATUS_UNSTART:
$task_status = '未参与';
break;
case Constant::USER_TASK_COMPLETE_STATUS_PROCESS:
$task_status = '执行中';
break;
case Constant::USER_TASK_COMPLETE_STATUS_COMPLETE:
$task_status = '已完成';
break;
}
$rows[] = [
$v['username'],
implode(';', $v['dp_names']),
$v['job'],
$v['role'],
$task_status,
"{$v['progress']}%",
$v['update_time'] > 0 ? rgmdate($v['update_time']) : '',
];
}
$file_name = $customtask['task_name'] . '完成详情';
$file_path = ExportDownload::get_down_dir($this->_login->user['eaId'].microtime(true)) . $file_name.'.xls';
$columns = ['姓名', '组织', '岗位', '角色', '完成情况', '进度', '最后完成时间'];
$ret = PythonExcel::instance()->write($file_path, $columns, $rows);
if ($ret) {
$conditon = [
'title' => $file_name,
'ea_id' => $this->_login->user['eaId'],
'username' => $this->_login->user['eaRealname'],
'type' => ExportDownload::EXCEL_TYPE,
'url' => $file_path,
'app_dir' => APP_DIR
];
ExportDownload::insert_down_load($conditon);
}
}
}