From a0935a2ce5a4e0f26377bc083bccb8f952208e3e Mon Sep 17 00:00:00 2001 From: xu Date: Tue, 5 Nov 2019 21:17:46 +0800 Subject: [PATCH] 1. F 数据统计添加多个统计维度 2. F 数据统计添加导出 --- app-ht/modules/datas/controllers/DeviceController.php | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- app-ht/modules/datas/views/device/batch-export.php | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app-ht/modules/datas/views/device/device-list.php | 28 +++++++++++++++++++++++++++- app-ht/modules/datas/views/device/export.php | 30 ++++++++++++++++++------------ app-ht/modules/datas/views/device/fail-list-export.php | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app-ht/modules/datas/views/device/fail-list.php | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ app-ht/modules/datas/views/device/index.php | 33 ++++++++++++++++++--------------- app-ht/modules/device/controllers/DeviceController.php | 5 +++-- domain/device/CreateBatchRepository.php | 20 ++++++++++++++------ 9 files changed, 522 insertions(+), 50 deletions(-) create mode 100644 app-ht/modules/datas/views/device/batch-export.php create mode 100644 app-ht/modules/datas/views/device/fail-list-export.php create mode 100644 app-ht/modules/datas/views/device/fail-list.php diff --git a/app-ht/modules/datas/controllers/DeviceController.php b/app-ht/modules/datas/controllers/DeviceController.php index b278268..c37a858 100644 --- a/app-ht/modules/datas/controllers/DeviceController.php +++ b/app-ht/modules/datas/controllers/DeviceController.php @@ -2,6 +2,7 @@ namespace app\ht\modules\datas\controllers; +use domain\device\DeviceAuthFailRepository; use Yii; use yii\data\Pagination; use app\ht\controllers\BaseController; @@ -96,6 +97,16 @@ class DeviceController extends BaseController */ public function actionDeviceList() { + $params = $this->batchDataList(1); + return $this->render('device-list', $params); + } + + /** + * @param $type + * @return mixed + */ + private function batchDataList($type) + { $request = Yii::$app->request; $serialNo = $request->get('serial_no'); $mac = $request->get('mac'); @@ -146,23 +157,32 @@ class DeviceController extends BaseController if (0 >= $page) { $page = 1; } - $pageSize = 20; - $page = ($page -1) * $pageSize; - - $deviceData = DeviceRepository::getList($where, $pageSize, $page); - $pages = new Pagination(['totalCount' => DeviceRepository::getListCount($where), 'pageSize' => $pageSize]); $statusList = DeviceStatus::statusLabels(); // - if (empty($deviceData)) { - $batchInfo = CreateBatchRepository::getBatchInfo($batchId); + if (1 == $type) { + $pageSize = 20; + $page = ($page -1) * $pageSize; + $deviceData = DeviceRepository::getList($where, $pageSize, $page); + $pages = new Pagination(['totalCount' => DeviceRepository::getListCount($where), 'pageSize' => $pageSize]); + + if (empty($deviceData)) { + $where = ['a.id' => $batchId]; + $batchInfo = CreateBatchRepository::getBatchInfo($where); + } else { + $batchInfo = $deviceData[0]; + } + $project = $batchInfo['project']; + $production = $batchInfo['production']; + $model = $batchInfo['model']; + $manufacture = $batchInfo['manufacture']; + $batchNo = $batchInfo['batch_no']; + } else { - $batchInfo = $deviceData[0]; + $deviceData = DeviceRepository::getList($where, 0, 0); + $pages = null; + $project = $production = $model = $manufacture = $batchNo = null; } - $project = $batchInfo['project']; - $production = $batchInfo['production']; - $model = $batchInfo['model']; - $manufacture = $batchInfo['manufacture']; - $batchNo = $batchInfo['batch_no']; + $params['statusList'] = $statusList; $params['deviceList'] = $deviceData; $params['pages'] = $pages; @@ -183,6 +203,108 @@ class DeviceController extends BaseController 'status' => $status ]; - return $this->render('device-list', $params); + return $params; + } + + + /** + * 导出某个批次的数据 + * @return string + */ + public function actionBatchExport() + { + $params = $this->batchDataList(0); + return $this->renderPartial('batch-export', $params); + } + + /** + * @param $type + * @return mixed + */ + private function batchFailDataList($type) + { + $request = Yii::$app->request; + $batchNo = $request->get('batch_no'); + $deviceId = $request->get('device_id'); + $startApplyAt = $request->get('start_apply_at'); + $endApplyAt = $request->get('end_apply_at'); + + $page = $request->get('page'); + $where = [ + 'and', + ['=','a.is_delete', 0], + ['=','concat(a.manufacture_no,a.project_no,a.model_no,a.production_no)', $batchNo] + ]; + + + if (!empty($deviceId)) { + $where[] = ['like', 'a.device_id', $deviceId]; + } + + if (!empty($startApplyAt)) { + $where[] = ['>=', 'a.apply_at', strtotime($startApplyAt)]; + } + if (!empty($endApplyAt)) { + $where[] = ['<=', 'a.apply_at', strtotime($endApplyAt) + 3600 * 24]; + } + + + if (0 >= $page) { + $page = 1; + } + + if (1 == $type) { + $pageSize = 20; + $page = ($page -1) * $pageSize; + $deviceData = DeviceAuthFailRepository::getList($where, $pageSize, $page); + $pages = new Pagination(['totalCount' => DeviceAuthFailRepository::getListCount($where), 'pageSize' => $pageSize]); + + $batchInfo = CreateBatchRepository::getBatchInfo(['a.batch_no' => $batchNo]); + $project = $batchInfo['project']; + $production = $batchInfo['production']; + $model = $batchInfo['model']; + $manufacture = $batchInfo['manufacture']; + $batchNo = $batchInfo['batch_no']; + + } else { + $deviceData = DeviceAuthFailRepository::getList($where, 0, 0); + $pages = null; + $project = $production = $model = $manufacture = $batchNo = null; + } + + $params['deviceList'] = $deviceData; + $params['pages'] = $pages; + $params["gets"] = [ + + 'project' => $project, + 'model' => $model, + 'device_id' => $deviceId, + 'batch_no' => $batchNo, + 'production' => $production, + 'manufacture' => $manufacture, + 'start_apply_at' => $startApplyAt, + 'end_apply_at' => $endApplyAt, + + ]; + + return $params; + } + + /** + * @return string + */ + public function actionFailList() + { + $params = $this->batchFailDataList(1); + return $this->render('fail-list', $params); + } + + /** + * @return string + */ + public function actionFailListExport() + { + $params = $this->batchFailDataList(0); + return $this->renderPartial('fail-list-export', $params); } } \ No newline at end of file diff --git a/app-ht/modules/datas/views/device/batch-export.php b/app-ht/modules/datas/views/device/batch-export.php new file mode 100644 index 0000000..0d427a5 --- /dev/null +++ b/app-ht/modules/datas/views/device/batch-export.php @@ -0,0 +1,75 @@ + + + + + + + + + +
+ + + + + + + + + + + + + + $item) : ?> + + + + + + + + + + + + +
批次编码序列号MAC地址设备ID申请时间授权时间状态
+ + +
+
+ + + + + + + + + +
+
+ + \ No newline at end of file diff --git a/app-ht/modules/datas/views/device/device-list.php b/app-ht/modules/datas/views/device/device-list.php index 1b529a1..56f0131 100644 --- a/app-ht/modules/datas/views/device/device-list.php +++ b/app-ht/modules/datas/views/device/device-list.php @@ -55,7 +55,8 @@ $this->params['breadcrumbs'][] = $this->title;
- +
+ 导出数据
@@ -131,5 +132,30 @@ $this->params['breadcrumbs'][] = $this->title; \ No newline at end of file diff --git a/app-ht/modules/datas/views/device/export.php b/app-ht/modules/datas/views/device/export.php index 964e510..7293893 100644 --- a/app-ht/modules/datas/views/device/export.php +++ b/app-ht/modules/datas/views/device/export.php @@ -22,18 +22,21 @@ $cnt = 0;
- +
- - - - - - - - - + + + + + + + + + + + + @@ -44,10 +47,13 @@ $cnt = 0; - + + - + + + + + + + + + + + +
+
编码厂商项目型号生产日期生成总数授权总数授权失败数未授权数编码厂商项目型号生产日期预 | 总生成已删除已授权未授权授权失败(超出)已处理(超出)授权失败(系统)
|
+ + + + + + + + + + + + + + + + $item) : ?> + + + + + + + + + + + + + + + +
ID批次编码厂商项目设备型号生产日期设备ID申请时间状态
+ + + + + + + + + + + + + + + + + 超出 +
+
+ + \ No newline at end of file diff --git a/app-ht/modules/datas/views/device/fail-list.php b/app-ht/modules/datas/views/device/fail-list.php new file mode 100644 index 0000000..0da68ef --- /dev/null +++ b/app-ht/modules/datas/views/device/fail-list.php @@ -0,0 +1,146 @@ +title = '授权失败管理'; +$this->params['breadcrumbs'][] = '数据统计'; +$this->params['breadcrumbs'][] = ['label' => '批次列表', 'url' => ['/datas/device/index']]; +$this->params['breadcrumbs'][] = $this->title; +?> + +
+
+
+ +
+ + +
+ +
+ + +
+ - + +
+
+ +
+ +
+
+
+
+
+
厂商: 项目: 型号: 生产日期: + 批次编号: +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ID批次编码厂商项目设备型号生产日期设备ID申请时间状态
+ + + + + + + + + + + + + + + + + 超出 +
+
暂无记录
+
+
+ + +
+ + \ No newline at end of file diff --git a/app-ht/modules/datas/views/device/index.php b/app-ht/modules/datas/views/device/index.php index 0c7dfe4..39fea58 100644 --- a/app-ht/modules/datas/views/device/index.php +++ b/app-ht/modules/datas/views/device/index.php @@ -49,7 +49,7 @@ $this->params['breadcrumbs'][] = $this->title; ">重    置 - 导出数据    + 导出数据    @@ -63,17 +63,18 @@ $this->params['breadcrumbs'][] = $this->title; - - - - - - - - - - - + + + + + + + + + + + + @@ -86,12 +87,14 @@ $this->params['breadcrumbs'][] = $this->title; - + - - + + + + diff --git a/app-ht/modules/device/controllers/DeviceController.php b/app-ht/modules/device/controllers/DeviceController.php index ecf051d..d6a7a8a 100644 --- a/app-ht/modules/device/controllers/DeviceController.php +++ b/app-ht/modules/device/controllers/DeviceController.php @@ -705,7 +705,7 @@ class DeviceController extends BaseController if ($needGen) { $trans = Yii::$app->getDb()->beginTransaction(); try { - $genDeviceModel = Device::createWithMacSerialNo($batchId, $batchNo, $deviceId, $tt, 0, DeviceStatus::HAS_AUTH); + $genDeviceModel = Device::createWithMacSerialNo($batchId, $batchNo, $deviceId, $tt, 1, DeviceStatus::HAS_AUTH); $deviceFailModel->is_delete = 1; $deviceFailModel->save(); $trans->commit(); @@ -732,6 +732,7 @@ class DeviceController extends BaseController $newDeviceModel->apply_at = $tt ; $newDeviceModel->auth_at = $tt; $newDeviceModel->save(); + $deviceFailModel->is_delete = 1; $deviceFailModel->save(); $trans->commit(); @@ -800,7 +801,7 @@ class DeviceController extends BaseController if ($needGen) { $trans = Yii::$app->getDb()->beginTransaction(); try { - $genDeviceModel = Device::createWithMacSerialNo($batchId, $batchNo, $deviceId, $tt, 0, DeviceStatus::HAS_AUTH); + $genDeviceModel = Device::createWithMacSerialNo($batchId, $batchNo, $deviceId, $tt, 1, DeviceStatus::HAS_AUTH); $deviceFailModel->is_delete = 1; $deviceFailModel->save(); $trans->commit(); diff --git a/domain/device/CreateBatchRepository.php b/domain/device/CreateBatchRepository.php index 4b8482e..5a0e04a 100644 --- a/domain/device/CreateBatchRepository.php +++ b/domain/device/CreateBatchRepository.php @@ -2,15 +2,16 @@ namespace domain\device; +use domain\device\models\CreateBatch; use yii\db\Expression; use yii\db\Query; use domain\device\models\CreateBatch as CreateBatchModel; use domain\device\models\Device as DeviceModel; -use domain\device\models\DeviceStats; use domain\manufacturer\models\Manufacturer as ManufacturerModel; use domain\model\models\Model as ModelModel; use domain\production\models\Production as ProductionModel; use domain\project\models\Project as ProjectModel; +use domain\device\models\DeviceAuthFail as DeviceAuthFailModel; class CreateBatchRepository @@ -78,14 +79,21 @@ class CreateBatchRepository */ static function getPageList($where, $offset = 0, $limit = 0) { + $totalNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.batch_id = a.id and dd.is_delete = 0) as total_num"); $hasAuthNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.status =".DeviceStatus::HAS_AUTH.' and dd.batch_id = a.id and dd.is_delete = 0) as has_auth_num'); - $noAuthNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.status =".DeviceStatus::NO_AUTH.' and dd.batch_id = a.id and dd.is_delete = 0) as del_num'); - + $noAuthNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.status =".DeviceStatus::NO_AUTH.' and dd.batch_id = a.id and dd.is_delete = 0) as no_auth_num'); $delNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.is_delete = 1 and dd.batch_id = a.id) as del_num"); + $outOfLimitExpress = new Expression("(select count(*) from ".DeviceAuthFailModel::tableName(). "as dd where concat(dd.manufacture_no, dd.project_no, dd.model_no, dd.production_no) = a.batch_no and dd.is_delete = 0) as out_of_num"); + $sysFailNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.status =".DeviceStatus::FAIL_AUTH." and dd.is_delete = 0 and dd.batch_id = a.id) as auth_fail_num"); + $handleAuthFailNumExpress = new Expression("(select count(*) from ".DeviceModel::tableName(). "as dd where dd.batch_id = a.id and dd.has_re_auth = 1 and dd.is_delete = 0) as handle_auth_fail_num"); $batchModelFind = CreateBatchModel::find(); $batchModelFind->alias('a'); - $batchModelFind->select(['a.*','m.name as manufacture_name','pro.name as project_name','mo.name as model_name','prod.name as production_name', $hasAuthNumExpress, $noAuthNumExpress, $delNumExpress]); + $batchModelFind->select([ + 'a.*', + 'm.name as manufacture_name','pro.name as project_name','mo.name as model_name','prod.name as production_name', + $totalNumExpress, $hasAuthNumExpress, $noAuthNumExpress, $delNumExpress, $outOfLimitExpress, $sysFailNumExpress, $handleAuthFailNumExpress + ]); $batchModelFind->leftJoin(ManufacturerModel::tableName(). ' m', 'm.id = a.manufacture_id'); $batchModelFind->leftJoin(ProjectModel::tableName(). ' pro', 'pro.id = a.project_id'); $batchModelFind->leftJoin(ModelModel::tableName(). ' mo', 'mo.id = a.model_id'); @@ -126,7 +134,7 @@ class CreateBatchRepository * @param $batchId * @return array|null|\yii\db\ActiveRecord */ - static function getBatchInfo($batchId) + static function getBatchInfo($where) { $batchModelFind = CreateBatchModel::find(); $batchModelFind->alias('a'); @@ -135,7 +143,7 @@ class CreateBatchRepository $batchModelFind->leftJoin(ProjectModel::tableName(). ' pro', 'pro.id = a.project_id'); $batchModelFind->leftJoin(ModelModel::tableName(). ' mo', 'mo.id = a.model_id'); $batchModelFind->leftJoin(ProductionModel::tableName(). ' prod', 'prod.id = a.production_id'); - $batchModelFind->where(['a.id' => $batchId]); + $batchModelFind->where($where); $batchModelFind->asArray(); $info = $batchModelFind->one(); -- libgit2 0.21.0
编码厂商项目型号生产日期生成总数删除数授权总数超出总数授权失败数未授权数编码厂商项目型号生产日期预 | 总生成已删除已授权未授权授权失败(超出)已处理(超出)授权失败(系统)
| 4