diff --git a/controllers/ListManagementController.php b/controllers/ListManagementController.php index 860c5e1e..7ca2cc6c 100644 --- a/controllers/ListManagementController.php +++ b/controllers/ListManagementController.php @@ -150,6 +150,7 @@ class ListManagementController extends Controller { ]; $listManagement->type = $data['type']; $listManagement->name = $data['name']; + $listManagement->abbreviated_name = $data['abbreviated_name']; $listManagement->gender = $data['gender']; $listManagement->birthday = $data['birthday'] === "" ? 0 : date_format(date_create_from_format('d/m/Y', $data['birthday']), 'U'); $listManagement->telephone = $data['telephone']; @@ -206,6 +207,7 @@ class ListManagementController extends Controller { "type" => $ListManagement->type, "code" => $ListManagement->code, "name" => $ListManagement->name, + "abbreviated_name" => $ListManagement->abbreviated_name, "gender" => $ListManagement->gender, "birthday" => date("d/m/Y", $ListManagement->birthday), "telephone" => $ListManagement->telephone, @@ -250,6 +252,7 @@ class ListManagementController extends Controller { $model->code = $data['code']; $model->type = $data['type']; $model->name = $data['name']; + $model->abbreviated_name = $data['abbreviated_name']; $model->gender = $data['gender']; $model->birthday = $data['birthday'] === "" ? 0 : date_format(date_create_from_format('d/m/Y', $data['birthday']), 'U'); $model->telephone = $data['telephone']; @@ -440,107 +443,101 @@ class ListManagementController extends Controller { return $time[1] + $time[0]; } + public function extractFeature($images, $staff_id) { + $extractFeature = []; + $ft = []; + foreach ($images as $key => $value) { + if ($key < Yii::$app->params['maxPicture']) { + $fileName = "face_" . $staff_id . "_" . common::generateRandomString() . "_" . time() . ".png"; + $start = $this->getCurrentTime(); + $img = false; + try { + $img = file_get_contents(str_replace("&", "&", $value)); + } catch (\Exception $e) { + + } + $finish = $this->getCurrentTime(); + $temp["getIMG"] = round(($finish - $start), 4); + if ($img && $img !== "null") { + $fileTarget = $targetPath . "/" . $fileName; + $start = $this->getCurrentTime(); + if (!$this->resizeImg($img, $fileTarget)) { + file_put_contents($fileTarget, $img); + } + $finish = $this->getCurrentTime(); + $temp["saveIMG"] = round(($finish - $start), 4); + $start = $this->getCurrentTime(); + $features = json_decode(common::requestToEngine("/get-feature", [ + "image_paths" => [ + ["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"] + ], + "type" => "128" + ]), true); + $finish = $this->getCurrentTime(); + $temp["extract"] = round(($finish - $start), 4); + $ft[] = [ + "url" => $fileName, + "urlOld" => $fileName, + "features" => $features['results'][0]['feature'], + "features512" => []//isset($features['results'][0]['feature512']) ? $features['results'][0]['feature512'] : [] + ]; + } + $extractFeature[] = $temp; + } + } + return [ + "time" => $extractFeature, + "features" => $ft + ]; + } + public function actionSyncFeature() { if (Yii::$app->request->post()) { Yii::$app->response->format = "json"; $processTime = []; $totalStart = $this->getCurrentTime(); $totals = intval(Yii::$app->request->post("totals")); -// $server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']); -// $ip = "https://dev-dc.beetai.com"; -// if ($server_ip) -// $ip = $server_ip->data; -// $device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']); -// $id_camera = 209; -// if ($device_id) -// $id_camera = intval($device_id->data); -// $start = $this->getCurrentTime(); -// $res = json_decode(file_get_contents($ip . "/api/oem/get_all_image", false, stream_context_create([ -// 'http' => [ -// 'header' => "Content-Type: application/json", -// 'method' => "POST", -// 'content' => json_encode([ -// "id_camera" => $id_camera, -// "ids_staff" => [strval(Yii::$app->request->post("id"))] -// ]) -// ] -// ])), true); -// $finish = $this->getCurrentTime(); -// $processTime["requestToAPI"] = round(($finish - $start), 4); $data = Yii::$app->request->post("id"); //$res['data'][0]; - $ft = []; $RootFolder = Yii::getAlias('@webroot') . "/data/uploads"; $targetPath = $RootFolder . "/face"; FileHelper::createDirectory($targetPath, 0777); - $extractFeature = []; - if (isset($data['images'])) { - foreach ($data['images'] as $key => $value) { - if ($key < Yii::$app->params['maxPicture']) { - $fileName = "face_" . common::generateRandomString() . "_" . time() . ".png"; - $start = $this->getCurrentTime(); - $img = false; - try { - $img = file_get_contents(str_replace("&", "&", $value)); -// $img = file_get_contents($value); - } catch (\Exception $e) { - - } - $finish = $this->getCurrentTime(); - $temp["getIMG"] = round(($finish - $start), 4); - if ($img && $img !== "null") { - $fileTarget = $targetPath . "/" . $fileName; - $start = $this->getCurrentTime(); - if (!$this->resizeImg($img, $fileTarget)) { - file_put_contents($fileTarget, $img); - } - $finish = $this->getCurrentTime(); - $temp["saveIMG"] = round(($finish - $start), 4); - $start = $this->getCurrentTime(); - $features = json_decode(common::requestToEngine("/get-feature", [ - "image_paths" => [ - ["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"] - ], - "type" => "128" - ]), true); - $finish = $this->getCurrentTime(); - $temp["extract"] = round(($finish - $start), 4); - $ft[] = [ - "url" => $fileName, - "urlOld" => $fileName, - "features" => $features['results'][0]['feature'], - "features512" => []//isset($features['results'][0]['feature512']) ? $features['results'][0]['feature512'] : [] - ]; - } - $extractFeature[] = $temp; - } - } - } - $processTime["extractFeature"] = $extractFeature; + $start = $this->getCurrentTime(); - $model = ListManagement::findOne(['code' => $data['idStaff']]); + $model = ListManagement::findOne(['staff_id' => $data['id']]); $finish = $this->getCurrentTime(); $processTime["getLM"] = round(($finish - $start), 4); if ($model) { + $model->abbreviated_name = $data['abbreviated_name']; + $model->code = $data['code']; $model->name = $data['name']; $model->address = $data['department']; - $model->image = json_encode($ft); +// $model->image = json_encode($ft); $model->last_modified = time(); $model->save(); - if ($totals <= 10) - common::updateFeature([ - "cmd" => "update", - "id" => $model->id, - "name" => common::convert_vi_to_en($model->name), - "features" => $model->allFeatures - ]); +// if ($totals <= 10) +// common::updateFeature([ +// "cmd" => "update", +// "id" => $model->id, +// "name" => common::convert_vi_to_en($model->name), +// "features" => $model->allFeatures +// ]); } else { + $ft = []; + if (isset($data['images'])) { + $extractFeature = $this->extractFeature($data['images'], $data['id']); + $processTime["extractFeature"] = $extractFeature['time']; + $ft = $extractFeature['features']; + } + $start = $this->getCurrentTime(); $model = new ListManagement(); $model->create([ - 'code' => strval($data['idStaff']), + 'code' => strval($data['code']), 'type' => "wl", 'name' => $data['name'], + 'abbreviated_name' => $data['abbreviated_name'], + 'staff_id' => $data['id'], 'image' => json_encode($ft), 'gender' => "Male", 'birthday' => "", @@ -549,17 +546,17 @@ class ListManagementController extends Controller { ]); $finish = $this->getCurrentTime(); $processTime["insertDB"] = round(($finish - $start), 4); - if ($totals <= 10) - common::updateFeature([ - "cmd" => "create", - "id" => $model->id, - "name" => common::convert_vi_to_en($model->name), - "features" => $model->allFeatures - ]); +// if ($totals <= 10) +// common::updateFeature([ +// "cmd" => "create", +// "id" => $model->id, +// "name" => common::convert_vi_to_en($model->name), +// "features" => $model->allFeatures +// ]); } $totalFinish = $this->getCurrentTime(); $processTime["total"] = round(($totalFinish - $totalStart), 4); - $processTime["id"] = strval($data['idStaff']); + $processTime["id"] = strval($data['code']); return $processTime; //["status" => true]; } } @@ -656,7 +653,8 @@ class ListManagementController extends Controller { "gender" => $staff->gender, "birthday" => date("d/m/Y", $staff->birthday), "telephone" => $staff->telephone, - "department" => $staff->address + "department" => $staff->address, + "abbreviated_name" => $staff->abbreviated_name ]; } } @@ -695,14 +693,21 @@ class ListManagementController extends Controller { $lsImgs = json_decode($StaffInfo->image, true); $images = []; foreach ($lsImgs as $key => $value) { - try { - $images[] = base64_encode(file_get_contents("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $value['url'])); - } catch (\Exception $e) { - + if (!isset($value['serverKey']) || (isset($value['serverKey']) && $value['serverKey'] == "")) { + try { + $images[] = base64_encode(file_get_contents("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $value['url'])); + } catch (\Exception $e) { + + } } } + if (count($images) == 0) + return ["status" => true, "text" => "Dữ liệu không đổi"]; + $items = [ + "id" => $StaffInfo->staff_id, "name" => $StaffInfo->name, + "abbreviated_name" => $StaffInfo->abbreviated_name, "code" => $StaffInfo->code, "department" => $StaffInfo->address, "birthday" => date("Y-m-d", $StaffInfo->birthday), @@ -722,6 +727,14 @@ class ListManagementController extends Controller { ]) ] ])), true); + if ($res['status'] == 10000) { + $resData = $res['data']; + for ($i = 0; $i < count($lsImgs); $i++) { + $lsImgs[$i]['serverKey'] = isset($resData[$i]) ? $resData[$i] : ""; + } + $StaffInfo->image = json_encode($lsImgs); + $StaffInfo->save(); + } } catch (\Exception $e) { } diff --git a/db/app.db b/db/app.db index 562c876d..9a17c0c8 100644 Binary files a/db/app.db and b/db/app.db differ diff --git a/models/ListManagement.php b/models/ListManagement.php index eb0f9121..77df9907 100644 --- a/models/ListManagement.php +++ b/models/ListManagement.php @@ -8,9 +8,11 @@ use Yii; * This is the model class for table "list_management". * * @property int $id + * @property string $staff_id * @property string $code * @property string $type * @property string $name + * @property string $abbreviated_name * @property string $image * @property string $gender * @property int $birthday @@ -33,7 +35,7 @@ class ListManagement extends \yii\db\ActiveRecord { */ public function rules() { return [ - [['type', 'name', 'gender', 'telephone', 'address', 'image', 'code'], 'string'], + [['type', 'name', 'gender', 'telephone', 'address', 'image', 'code', 'abbreviated_name', 'staff_id'], 'string'], [['birthday', 'time', 'last_modified'], 'integer'], ]; } @@ -53,12 +55,15 @@ class ListManagement extends \yii\db\ActiveRecord { 'telephone' => 'Điện thoại', 'address' => 'Đơn vị', 'time' => 'Thời gian đăng kí', - 'last_modified' => 'Last Modified' + 'last_modified' => 'Last Modified', + 'abbreviated_name' => 'Tên hiển thị', + 'staff_id' => 'ID' ]; } public function create($data) { $r = $this->load([ + 'staff_id' => $data['staff_id'], 'code' => $data['code'], 'type' => $data['type'], 'name' => $data['name'], @@ -67,6 +72,7 @@ class ListManagement extends \yii\db\ActiveRecord { 'birthday' => $data['birthday'] === "" ? 0 : date_format(date_create_from_format('d/m/Y', $data['birthday']), 'U'), 'telephone' => $data['telephone'], 'address' => $data['address'], + 'abbreviated_name' => $data['abbreviated_name'], 'time' => time(), 'last_modified' => time() ], ''); @@ -102,7 +108,7 @@ class ListManagement extends \yii\db\ActiveRecord { $res = []; $ls = self::find()->all(); foreach ($ls as $key => $value) { - $res[] = $value->code; + $res[] = $value->staff_id; } return $res; } diff --git a/views/capture-logs/index.tpl b/views/capture-logs/index.tpl index 18e03004..b7dfbb65 100644 --- a/views/capture-logs/index.tpl +++ b/views/capture-logs/index.tpl @@ -128,6 +128,12 @@ +
+
Tên hiển thị
+
+ +
+
Giới tính
diff --git a/views/list-management/index.tpl b/views/list-management/index.tpl index 5dc00695..b6a406cb 100644 --- a/views/list-management/index.tpl +++ b/views/list-management/index.tpl @@ -66,7 +66,10 @@ ], [ 'attribute' => 'name', - 'contentOptions' => ['class' => 'text-center'], + 'headerOptions' => ['class' => 'text-center'] + ], + [ + 'attribute' => 'abbreviated_name', 'headerOptions' => ['class' => 'text-center'] ], [ @@ -86,12 +89,6 @@ 'headerOptions' => ['class' => 'text-center'], 'value' => \app\helpers\ListManagementGrid::time() ], - [ - 'attribute' => 'birthday', - 'contentOptions' => ['class' => 'text-center'], - 'headerOptions' => ['class' => 'text-center'], - 'value' => \app\helpers\ListManagementGrid::birthday() - ], [ 'attribute' => 'telephone', 'contentOptions' => ['class' => 'text-center'], @@ -218,22 +215,22 @@
-