Commit 78ba6991792bb5a79437432ca65eb352dc337feb

Authored by xu
1 parent b80f928e
Exists in master

app-ht

1. F筛选条件添加过滤空格
2. A OTA 和APP升级统计日志添加删除功能
3. F 上传文件包添加说明告知上传的时间较长
app-ht/controllers/BaseController.php
... ... @@ -103,4 +103,17 @@ class BaseController extends Controller
103 103 mkdir($downloadFilePath, 0777, true);
104 104 }
105 105 }
  106 +
  107 + /**
  108 + * 过滤空格
  109 + * @param $var
  110 + * @return mixed
  111 + */
  112 + public function filterVar($var)
  113 + {
  114 + $var = str_replace(" ", "", $var);
  115 + $var = str_replace("\t", "", $var);
  116 +
  117 + return $var;
  118 + }
106 119 }
... ...
app-ht/modules/datas/controllers/DeviceController.php
... ... @@ -10,6 +10,7 @@ use app\ht\controllers\BaseController;
10 10 use domain\device\CreateBatchRepository;
11 11 use domain\device\DeviceRepository;
12 12 use domain\device\DeviceStatus;
  13 +use function strtotime;
13 14  
14 15 /**
15 16 * 机器状态码管理
... ... @@ -41,6 +42,13 @@ class DeviceController extends BaseController
41 42 $modelName = $request->get('model_name');
42 43 $productionName = $request->get('production_name');
43 44 $batchName = $request->get('batch_no');
  45 +
  46 + $manufactureName = $this->filterVar($manufactureName);
  47 + $projectName = $this->filterVar($projectName);
  48 + $modelName = $this->filterVar($modelName);
  49 + $productionName = $this->filterVar($productionName);
  50 + $batchName = $this->filterVar($batchName);
  51 +
44 52 $gets = [
45 53 'manufacture_name' => $manufactureName,
46 54 'project_name' => $projectName,
... ...
app-ht/modules/datas/controllers/DeviceStatsController.php
... ... @@ -2,13 +2,12 @@
2 2  
3 3 namespace app\ht\modules\datas\controllers;
4 4  
5   -use domain\device\DeviceStatsRepository;
6 5 use Yii;
7 6 use yii\data\Pagination;
8   -use domain\upgrade\UpgradeLogRepository;
9   -use domain\upgrade\UpgradeStatus;
10 7 use app\ht\controllers\BaseController;
  8 +use domain\device\DeviceStatsRepository;
11 9  
  10 +use function strtotime;
12 11 /**
13 12 * 机器状态码管理
14 13 * Class DeviceStatsController
... ... @@ -36,13 +35,13 @@ class DeviceStatsController extends BaseController
36 35 $request = Yii::$app->request;
37 36 $createTime = $request->get('createTime');
38 37 $endTime = $request->get('endTime');
39   - $software_version = $request->get('software_version');
40   - $hardware_version = $request->get('hardware_version');
41   - $manufacture_name = $request->get('manufacture_name');
42   - $model_name = $request->get('model_name');
43   - $device_id = $request->get('device_id');
44   - $barcode = $request->get('barcode');
45   - $city = $request->get('city');
  38 + $software_version = $this->filterVar($request->get('software_version'));
  39 + $hardware_version = $this->filterVar($request->get('hardware_version'));
  40 + $manufacture_name = $this->filterVar($request->get('manufacture_name'));
  41 + $model_name = $this->filterVar($request->get('model_name'));
  42 + $device_id = $this->filterVar($request->get('device_id'));
  43 + $barcode = $this->filterVar($request->get('barcode'));
  44 + $city = $this->filterVar($request->get('city'));
46 45  
47 46 $gets = [
48 47 'createTime' => $createTime,
... ... @@ -59,11 +58,11 @@ class DeviceStatsController extends BaseController
59 58 $where = ['and'];
60 59 if ($createTime) {
61 60 $createTime = strtotime($createTime);
62   - $where[] = ['>=', 'ds.created_at', $createTime];
  61 + $where[] = ['>=', 'ds.timestamp', $createTime];
63 62 }
64 63 if ($endTime) {
65 64 $endTime = strtotime($endTime) + 86400;
66   - $where[] = ['<=', 'ds.created_at', $endTime];
  65 + $where[] = ['<=', 'ds.timestamp', $endTime];
67 66 }
68 67  
69 68 if ($software_version) {
... ...
app-ht/modules/datas/controllers/UpgradeLogController.php
... ... @@ -4,9 +4,13 @@ namespace app\ht\modules\datas\controllers;
4 4  
5 5 use Yii;
6 6 use yii\data\Pagination;
  7 +use app\ht\controllers\BaseController;
7 8 use domain\upgrade\UpgradeLogRepository;
8 9 use domain\upgrade\UpgradeStatus;
9   -use app\ht\controllers\BaseController;
  10 +use domain\upgrade\UpgradeLog;
  11 +use stdClass;
  12 +use function count;
  13 +use function strtotime;
10 14  
11 15 /**
12 16 * 版本日志管理
... ... @@ -32,19 +36,47 @@ class UpgradeLogController extends BaseController
32 36 */
33 37 protected function dataList($type = '')
34 38 {
  39 + $searchCondition = $this->searchWhere();
  40 + $where = $searchCondition[0];
  41 + $gets = $searchCondition[1];
  42 + if ($type == 0) {
  43 + $pageList = UpgradeLogRepository::getPageList($where, 0 , 0);
  44 + $pages = null;
  45 + } else {
  46 + $pageSize = 20;
  47 + $pages = new Pagination(['totalCount' => UpgradeLogRepository::getPageCount($where), 'pageSize' => $pageSize]);
  48 + $pageList = UpgradeLogRepository::getPageList($where, $pages->offset, $pages->limit);
  49 + }
  50 +
  51 + /**
  52 + * 数据整理
  53 + */
  54 + return [
  55 + 'listdata' => $pageList,
  56 + 'pages' => $pages,
  57 + 'gets' => $gets
  58 + ];
  59 + }
  60 +
  61 + private function searchWhere($requestType = 1)
  62 + {
35 63 $request = Yii::$app->request;
36   - $creatTime = $request->get('creatTime');
37   - $endTime = $request->get('endTime');
38   - $status = $request->get('status');
39   - $current_version = $request->get('current_version');
40   - $target_version = $request->get('target_version');
41   - $manufacture_name = $request->get('manufacture_name');
42   - $device_no = $request->get('device_no');
43   - $barcode = $request->get('barcode');
44   - $error_code = $request->get('error_code');
45   - $device_device_id = $request->get('device_device_id');
46   - $package_name = $request->get('package_name');
47   - $dataType = !empty($request->get('type')) ? $request->get('type') : UpgradeStatus::TYPE_APP;
  64 + $reqName = 'get';
  65 + if (2 == $requestType) {
  66 + $reqName = 'post';
  67 + }
  68 + $creatTime = $request->$reqName('creatTime');
  69 + $endTime = $request->$reqName('endTime');
  70 + $status = $request->$reqName('status');
  71 + $current_version = $this->filterVar($request->$reqName('current_version'));
  72 + $target_version = $this->filterVar($request->$reqName('target_version'));
  73 + $manufacture_name = $this->filterVar($request->$reqName('manufacture_name'));
  74 + $device_no = $this->filterVar($request->$reqName('device_no'));
  75 + $barcode = $this->filterVar($request->$reqName('barcode'));
  76 + $error_code = $request->$reqName('error_code');
  77 + $device_device_id = $request->$reqName('device_device_id');
  78 + $package_name = $this->filterVar($request->$reqName('package_name'));
  79 + $dataType = !empty($request->$reqName('type')) ? $request->$reqName('type') : UpgradeStatus::TYPE_APP;
48 80  
49 81 $gets = [
50 82 'creatTime' => $creatTime,
... ... @@ -100,23 +132,8 @@ class UpgradeLogController extends BaseController
100 132 if ($dataType) {
101 133 $where[] = ['=', 'ul.type', $dataType];
102 134 }
103   - if ($type == 0) {
104   - $pageList = UpgradeLogRepository::getPageList($where, 0 , 0);
105   - $pages = null;
106   - } else {
107   - $pageSize = 20;
108   - $pages = new Pagination(['totalCount' => UpgradeLogRepository::getPageCount($where), 'pageSize' => $pageSize]);
109   - $pageList = UpgradeLogRepository::getPageList($where, $pages->offset, $pages->limit);
110   - }
111 135  
112   - /**
113   - * 数据整理
114   - */
115   - return [
116   - 'listdata' => $pageList,
117   - 'pages' => $pages,
118   - 'gets' => $gets
119   - ];
  136 + return [$where, $gets];
120 137 }
121 138  
122 139 /**
... ... @@ -128,4 +145,69 @@ class UpgradeLogController extends BaseController
128 145 $params = $this->dataList(0);
129 146 return $this->renderPartial('export', $params);
130 147 }
  148 +
  149 + /**
  150 + * @return string
  151 + */
  152 + public function actionDelSearch()
  153 + {
  154 + $request = Yii::$app->request;
  155 + $e = new stdClass();
  156 + $e->success = false;
  157 + $e->message = '失败';
  158 +
  159 + $searchCondition = $this->searchWhere(2);
  160 + $where = $searchCondition[0];
  161 +
  162 + $post = $request->post();
  163 + if ((1 == count($post) && isset($post['type'])) || empty($post)) {
  164 + $e->message = '请录入搜索条件';
  165 + return $this->renderJson($e);
  166 + }
  167 +
  168 + $upgrades = UpgradeLogRepository::getPageList($where, 0 , 0);
  169 + $ids = [];
  170 + foreach($upgrades as $k => $v) {
  171 + if ($v) {
  172 + $ids[] = $v['id'];
  173 + }
  174 + }
  175 + if (!$ids) {
  176 + $e->message = '没有满足条件的记录';
  177 + return $this->renderJson($e);
  178 + }
  179 + $result = UpgradeLog::deleteAll(['id' => $ids]);
  180 + if ($result) {
  181 + $e->message = '成功删除'.count($ids).'记录';
  182 + $e->success = true;
  183 + return $this->renderJson($e);
  184 + } else {
  185 + $e->message = '删除失败';
  186 + return $this->renderJson($e);
  187 + }
  188 + }
  189 +
  190 + /**
  191 + * @return string
  192 + */
  193 + public function actionDelItem()
  194 + {
  195 + $request = Yii::$app->request;
  196 + $e = new stdClass();
  197 + $e->success = false;
  198 + $e->message = '失败';
  199 + $id = $request->post('id');
  200 + if (empty($id)) {
  201 + $e->message = 'ID为空,删除失败';
  202 + return $this->renderJson($e);
  203 + }
  204 + if (UpgradeLog::delete($id)) {
  205 + $e->message = '删除成功';
  206 + $e->success = true;
  207 + return $this->renderJson($e);
  208 + } else {
  209 + $e->message = 'ID为空,删除失败';
  210 + return $this->renderJson($e);
  211 + }
  212 + }
131 213 }
132 214 \ No newline at end of file
... ...
app-ht/modules/datas/views/device-stats/export.php
... ... @@ -28,8 +28,8 @@ $cnt = 0;
28 28 <tr>
29 29 <th width="10%">设备ID</th>
30 30 <th width="10%">Barcode</th>
31   - <th width="10%">硬件版本</th>
32 31 <th width="10%">软件版本</th>
  32 + <th width="10%">硬件版本</th>
33 33 <th width="10%">厂商</th>
34 34 <th width="10%">设备型号</th>
35 35 <th width="10%">所在城市</th>
... ... @@ -48,7 +48,7 @@ $cnt = 0;
48 48 <td style="padding:12px;"><?= (isset($item["model_name"]) ? $item["model_name"] : "") ?></td>
49 49 <td style="padding:12px;"><?= empty($item["city"])? '-':$item["city"]?></td>
50 50 <td style="padding:12px;"><?= $item["ip"]?></td>
51   - <td style="padding:12px;"><?= date("Y-m-d H:i:s", $item['created_at'])?></td>
  51 + <td style="padding:12px;"><?= date("Y-m-d H:i:s", $item['timestamp'])?></td>
52 52 </tr>
53 53 <?php
54 54 $cnt++;
... ...
app-ht/modules/datas/views/device-stats/index.php
... ... @@ -85,8 +85,8 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = &#39;机器状态统计&#39;;
85 85 <tr>
86 86 <th width="10%">设备ID</th>
87 87 <th width="10%">Barcode</th>
88   - <th width="10%">硬件版本</th>
89 88 <th width="10%">软件版本</th>
  89 + <th width="10%">硬件版本</th>
90 90 <th width="10%">厂商</th>
91 91 <th width="10%">设备型号</th>
92 92 <th width="10%">所在城市</th>
... ... @@ -107,7 +107,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = &#39;机器状态统计&#39;;
107 107 <td style="padding:12px;"><?= (isset($item["model_name"]) ? $item["model_name"] : "") ?></td>
108 108 <td style="padding:12px;"><?= empty($item["city"])? '-':$item["city"]?></td>
109 109 <td style="padding:12px;"><?= $item["ip"]?></td>
110   - <td style="padding:12px;"><?= date("Y-m-d H:i:s", $item['created_at'])?></td>
  110 + <td style="padding:12px;"><?= date("Y-m-d H:i:s", $item['timestamp'])?></td>
111 111 </tr>
112 112 <?php endforeach; ?>
113 113 <?php } else { ?>
... ...
app-ht/modules/datas/views/upgrade-log/index.php
... ... @@ -103,16 +103,17 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
103 103 <table class="table table-striped table-bordered" id="brand-table">
104 104 <thead>
105 105 <tr>
106   - <th width="10%">设备ID</th>
  106 + <th width="9%">设备ID</th>
107 107 <th width="8%">包名</th>
108 108 <th width="8%">当前版本</th>
109   - <th width="10%">目标版本</th>
110   - <th width="10%">厂商</th>
111   - <th width="10%">机器型号</th>
112   - <th width="10%">Barcode</th>
  109 + <th width="9%">目标版本</th>
  110 + <th width="9%">厂商</th>
  111 + <th width="9%">机器型号</th>
  112 + <th width="9%">Barcode</th>
113 113 <th width="7%">升级状态</th>
114   - <th width="10%">升级错误码</th>
115   - <th width="10%">时间</th>
  114 + <th width="9%">升级错误码</th>
  115 + <th width="9%">时间</th>
  116 + <th width="8%">操作</th>
116 117 </tr>
117 118 </thead>
118 119  
... ... @@ -130,6 +131,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
130 131 <td style="padding:12px;"><?= UpgradeLogStatus::statusLabel($item['status'])?></td>
131 132 <td style="padding:12px;"><?= (!empty($item["error_code"]) ? $item["error_code"] : "-") ?></td>
132 133 <td style="padding:12px;"><?= date("Y-m-d H:i:s", $item['created_at'])?></td>
  134 + <td style="padding:12px;"><a class="del-item-btn" href="javascript:void(0)" data-id="<?=$item['id']?>">删除</a></td>
133 135 </tr>
134 136 <?php endforeach; ?>
135 137 <?php } else { ?>
... ... @@ -141,6 +143,9 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
141 143 <?php } ?>
142 144 </tbody>
143 145 </table>
  146 + <div class="action-box">
  147 + <button class="btn btn-danger btn-sm btn_search_del" >删除搜索结果</button>
  148 + </div>
144 149 </div>
145 150  
146 151 <div class="panel-footer">
... ... @@ -153,6 +158,8 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
153 158 </div>
154 159 </div>
155 160 <script>
  161 + var delSearchURL = '<?=Url::to("del-search")?>';
  162 + var delItemURL = '<?=Url::to("del-item")?>';
156 163 window.queryParams = function(params) {
157 164 $("#search-form").find('input[name]').each(function () {
158 165 var val = $(this).val();
... ... @@ -163,7 +170,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
163 170 });
164 171 return params;
165 172 }
166   - $(document).ready(function () {
  173 + $(function () {
167 174 $('#btn-export').click(function(e){
168 175 var params = {};
169 176 window.queryParams(params);
... ... @@ -178,5 +185,57 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
178 185 window.location.href = "export" + $strQuery;
179 186 return false;
180 187 })
  188 +
  189 +
  190 + $('.btn_search_del').click(function(e){
  191 + var params = {};
  192 + window.queryParams(params);
  193 +
  194 + if (null == params || '' == params) {
  195 + alert('请录入搜索条件');
  196 + return false;
  197 + }
  198 +
  199 + var paramsLen = 0;
  200 + var keyName = '';
  201 + for(var key in params ) {
  202 + paramsLen++;
  203 + keyName = key;
  204 + }
  205 +
  206 + if (('type' == keyName && 1 == paramsLen) || '' == keyName) {
  207 + alert('请录入搜索条件');
  208 + return false;
  209 + }
  210 +
  211 + if (!confirm('确定删除么?')) {
  212 + return false;
  213 + }
  214 + $.post(delSearchURL, params, function(ajaxRes){
  215 + alert(ajaxRes.message);
  216 + if(ajaxRes.success) {
  217 + var _body = window.parent;
  218 + var _iframe1=_body.document.getElementById('x-iframe');
  219 + _iframe1.contentWindow.location.reload(true);
  220 + }
  221 + }, 'json')
  222 +
  223 + })
  224 +
  225 + $('.del-item-btn').click(function(e){
  226 + var id = $(this).attr('data-id');
  227 + if (!confirm('确定删除该条记录么?')) {
  228 + return false;
  229 + }
  230 + $.post(delItemURL, {id:id}, function(ajaxRes){
  231 + alert(ajaxRes.message);
  232 + if(ajaxRes.success) {
  233 + var _body = window.parent;
  234 + var _iframe1=_body.document.getElementById('x-iframe');
  235 + _iframe1.contentWindow.location.reload(true);
  236 + }
  237 + }, 'json')
  238 + })
  239 +
181 240 });
182 241 </script>
183 242 \ No newline at end of file
... ...
app-ht/modules/device/controllers/DeviceController.php
... ... @@ -58,13 +58,13 @@ class DeviceController extends BaseController
58 58 private function dataList($type, $delete = 0)
59 59 {
60 60 $request = Yii::$app->request;
61   - $serialNo = $request->get('serial_no');
62   - $mac = $request->get('mac');
63   - $project = $request->get('project');
64   - $model = $request->get('model');
65   - $production = $request->get('production');
66   - $manufacture = $request->get('manufacture');
67   - $deviceId = $request->get('device_id');
  61 + $serialNo = $this->filterVar($request->get('serial_no'));
  62 + $mac = $this->filterVar($request->get('mac'));
  63 + $project = $this->filterVar($request->get('project'));
  64 + $model = $this->filterVar($request->get('model'));
  65 + $production = $this->filterVar($request->get('production'));
  66 + $manufacture = $this->filterVar($request->get('manufacture'));
  67 + $deviceId = $this->filterVar($request->get('device_id'));
68 68 $status = $request->get('status');
69 69  
70 70 $startApplyAt = $request->get('start_apply_at');
... ... @@ -81,6 +81,7 @@ class DeviceController extends BaseController
81 81 'and',
82 82 ['=','a.is_delete', $delete]
83 83 ];
  84 +
84 85 if (!empty($serialNo)) {
85 86 $where[] = ['like', 'a.serial_no', $serialNo];
86 87 }
... ...
app-ht/modules/upgrade/controllers/UpgradeController.php
... ... @@ -553,8 +553,10 @@ class UpgradeController extends BaseController
553 553 ];
554 554  
555 555 // 上传OSS
  556 +
556 557 $fileService = new FileService();
557 558 $fileService->add($uploadPath, $savePath);
  559 +
558 560 // 删除服务器传成功的文件
559 561 //@unlink($uploadPath);
560 562  
... ...
app-ht/modules/upgrade/views/upgrade/create.php
... ... @@ -219,7 +219,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
219 219 '</div>' );
220 220 });
221 221 // 文件上传过程中创建进度条实时显示。
222   - uploader.on( 'uploadProgress', function( file, percentage ) {
  222 + uploader.on('uploadProgress', function( file, percentage ) {
223 223 var $li = $( '#'+file.id ),
224 224 $percent = $li.find('.progress .progress-bar');
225 225  
... ... @@ -231,7 +231,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
231 231 '</div>').appendTo( $li ).find('.progress-bar');
232 232 }
233 233  
234   - $li.find('p.state').text('上传中');
  234 + $li.find('p.state').text('上传中, 文件会先上传到缓存再传到远程服务器,600M大概是12分钟左右,请耐心等待');
235 235  
236 236 $percent.css( 'width', percentage * 100 + '%' );
237 237 });
... ...
app-ht/modules/upgrade/views/upgrade/edit.php
... ... @@ -222,7 +222,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
222 222 '</div>').appendTo( $li ).find('.progress-bar');
223 223 }
224 224  
225   - $li.find('p.state').text('上传中');
  225 + $li.find('p.state').text('上传中, 文件会先上传到缓存再传到远程服务器,600M大概是12分钟左右,请耐心等待');
226 226  
227 227 $percent.css( 'width', percentage * 100 + '%' );
228 228 });
... ...
domain/upgrade/UpgradeLog.php
... ... @@ -126,6 +126,19 @@ class UpgradeLog
126 126 return false;
127 127 }
128 128  
129   - return UpgradeLogModel::deleteAll(["id" => $id]);
  129 + return $upgradeModel->delete();
  130 + }
  131 +
  132 + /**
  133 + * @param $condition
  134 + * @return bool|int
  135 + */
  136 + public static function deleteAll($condition)
  137 + {
  138 + if (empty($condition)) {
  139 + return false;
  140 + }
  141 +
  142 + return UpgradeLogModel::deleteAll($condition);
130 143 }
131 144 }
132 145 \ No newline at end of file
... ...