dieu chinh update tung doi tuong neu so luong <10

This commit is contained in:
dongpd 2020-12-25 15:58:02 +07:00
parent dc75b88bd8
commit ddcf67ba9c
6 changed files with 130 additions and 15 deletions

View File

@ -336,6 +336,7 @@ class ConfigController extends Controller {
\Yii::$app->db->createCommand()->truncateTable('capture_logs')->execute(); \Yii::$app->db->createCommand()->truncateTable('capture_logs')->execute();
\Yii::$app->db->createCommand()->truncateTable('list_management')->execute(); \Yii::$app->db->createCommand()->truncateTable('list_management')->execute();
array_map('unlink', glob("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/*.*")); array_map('unlink', glob("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/*.*"));
file_get_contents("http://localhost:2305/update-feature");
} }
return Url::to(['/config']); return Url::to(['/config']);
} else { } else {

View File

@ -108,7 +108,12 @@ class ControlLogsController extends Controller {
]; ];
$listManagement->image = json_encode($images); $listManagement->image = json_encode($images);
$listManagement->save(); $listManagement->save();
file_get_contents("http://localhost:2305/update-feature"); common::updateFeature([
"cmd" => "update",
"id" => $listManagement->id,
"name" => common::convert_vi_to_en($listManagement->name),
"features" => $listManagement->allFeatures
]);
return ["status" => true]; return ["status" => true];
} }
return ["status" => false, "text" => "Hình ảnh này đã được chọn làm mẫu cho đối tượng này!"]; return ["status" => false, "text" => "Hình ảnh này đã được chọn làm mẫu cho đối tượng này!"];

View File

@ -144,7 +144,12 @@ class ListManagementController extends Controller {
$listManagement->address = $data['address']; $listManagement->address = $data['address'];
$listManagement->image = json_encode($images); $listManagement->image = json_encode($images);
$listManagement->save(); $listManagement->save();
file_get_contents("http://localhost:2305/update-feature"); common::updateFeature([
"cmd" => "update",
"id" => $listManagement->id,
"name" => common::convert_vi_to_en($listManagement->name),
"features" => $listManagement->allFeatures
]);
return ["status" => true]; return ["status" => true];
} }
return ["status" => false, "text" => "Hình ảnh này đã được chọn làm mẫu cho đối tượng này!"]; return ["status" => false, "text" => "Hình ảnh này đã được chọn làm mẫu cho đối tượng này!"];
@ -237,7 +242,12 @@ class ListManagementController extends Controller {
$model->telephone = $data['telephone']; $model->telephone = $data['telephone'];
$model->address = $data['address']; $model->address = $data['address'];
$model->save(); $model->save();
file_get_contents("http://localhost:2305/update-feature"); common::updateFeature([
"cmd" => "update",
"id" => $model->id,
"name" => common::convert_vi_to_en($model->name),
"features" => $model->allFeatures
]);
return true; return true;
} }
} }
@ -250,8 +260,13 @@ class ListManagementController extends Controller {
foreach ($images as $k => $v) { foreach ($images as $k => $v) {
unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $v['url']); unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $v['url']);
} }
common::updateFeature([
"cmd" => "delete",
"id" => $model->id,
"name" => common::convert_vi_to_en($model->name),
"features" => []
]);
$model->delete(); $model->delete();
file_get_contents("http://localhost:2305/update-feature");
return true; return true;
} }
} }
@ -271,7 +286,12 @@ class ListManagementController extends Controller {
} }
$model->image = json_encode($features); $model->image = json_encode($features);
$model->save(); $model->save();
file_get_contents("http://localhost:2305/update-feature"); common::updateFeature([
"cmd" => "update",
"id" => $model->id,
"name" => common::convert_vi_to_en($model->name),
"features" => $model->allFeatures
]);
return true; return true;
} }
} }
@ -295,10 +315,18 @@ class ListManagementController extends Controller {
foreach ($images as $k => $v) { foreach ($images as $k => $v) {
unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $v['url']); unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $v['url']);
} }
if (count($data['lists']) <= 10)
common::updateFeature([
"cmd" => "delete",
"id" => $staff->id,
"name" => common::convert_vi_to_en($staff->name),
"features" => []
]);
$staff->delete(); $staff->delete();
} }
} }
file_get_contents("http://localhost:2305/update-feature"); if (count($data['lists']) > 10)
file_get_contents("http://localhost:2305/update-feature");
return true; return true;
} }
} }
@ -385,6 +413,7 @@ class ListManagementController extends Controller {
public function actionSyncFeature() { public function actionSyncFeature() {
if (Yii::$app->request->post()) { if (Yii::$app->request->post()) {
Yii::$app->response->format = "json"; Yii::$app->response->format = "json";
$totals = intval(Yii::$app->request->post("totals"));
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']); $server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$ip = "dev-dc.beetai.com"; $ip = "dev-dc.beetai.com";
if ($server_ip) if ($server_ip)
@ -438,6 +467,13 @@ class ListManagementController extends Controller {
$model->image = json_encode($ft); $model->image = json_encode($ft);
$model->last_modified = time(); $model->last_modified = time();
$model->save(); $model->save();
if ($totals <= 10)
common::updateFeature([
"cmd" => "update",
"id" => $model->id,
"name" => common::convert_vi_to_en($model->name),
"features" => $model->allFeatures
]);
} else { } else {
$model = new ListManagement(); $model = new ListManagement();
$model->create([ $model->create([
@ -450,6 +486,13 @@ class ListManagementController extends Controller {
'telephone' => "", 'telephone' => "",
'address' => $data['department'] 'address' => $data['department']
]); ]);
if ($totals <= 10)
common::updateFeature([
"cmd" => "create",
"id" => $model->id,
"name" => common::convert_vi_to_en($model->name),
"features" => $model->allFeatures
]);
} }
return ["status" => true]; return ["status" => true];
} }
@ -459,6 +502,7 @@ class ListManagementController extends Controller {
if (Yii::$app->request->post()) { if (Yii::$app->request->post()) {
Yii::$app->response->format = "json"; Yii::$app->response->format = "json";
$data = Yii::$app->request->post(); $data = Yii::$app->request->post();
$totals = intval($data['totals']);
$results = json_decode(file_get_contents("http://" . $data['ip'] . "/api/full-data", false, stream_context_create([ $results = json_decode(file_get_contents("http://" . $data['ip'] . "/api/full-data", false, stream_context_create([
'http' => [ 'http' => [
'header' => "Content-Type: application/json", 'header' => "Content-Type: application/json",
@ -494,6 +538,13 @@ class ListManagementController extends Controller {
$model->telephone = $value['telephone']; $model->telephone = $value['telephone'];
$model->address = $value['department']; $model->address = $value['department'];
$model->save(); $model->save();
if ($totals <= 10)
common::updateFeature([
"cmd" => "update",
"id" => $model->id,
"name" => common::convert_vi_to_en($model->name),
"features" => $model->allFeatures
]);
} else { } else {
$model = new ListManagement(); $model = new ListManagement();
$model->create([ $model->create([
@ -507,6 +558,13 @@ class ListManagementController extends Controller {
'address' => $value['department'], 'address' => $value['department'],
'time' => $value['time'] 'time' => $value['time']
]); ]);
if ($totals <= 10)
common::updateFeature([
"cmd" => "create",
"id" => $model->id,
"name" => common::convert_vi_to_en($model->name),
"features" => $model->allFeatures
]);
} }
} }
return ["status" => true]; return ["status" => true];
@ -514,11 +572,11 @@ class ListManagementController extends Controller {
} }
public function actionUpdateFeature() { public function actionUpdateFeature() {
if (Yii::$app->request->isAjax) { if (Yii::$app->request->isAjax) {
Yii::$app->response->format = "json"; Yii::$app->response->format = "json";
file_get_contents("http://localhost:2305/update-feature?total=" . ListManagement::find()->count()); file_get_contents("http://localhost:2305/update-feature?total=" . ListManagement::find()->count());
return ["status" => true]; return ["status" => true];
} }
} }
public function actionChooseStaff() { public function actionChooseStaff() {

View File

@ -116,4 +116,16 @@ class ListManagement extends \yii\db\ActiveRecord {
return $res; return $res;
} }
public function getAllFeatures() {
$features = json_decode($this->image, true);
$f = [];
foreach ($features as $k => $v) {
$f[] = $v['features'];
if (isset($v['features512']))
if (count($v['features512']))
$f[] = $v['features512'];
}
return $f;
}
} }

View File

@ -181,6 +181,16 @@ class common extends \yii\db\ActiveRecord {
])); ]));
} }
public static function updateFeature($datas) {
return file_get_contents("http://localhost:2305/update-person", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode($datas)
]
]));
}
public static function generateRandomString($length = 10) { public static function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters); $charactersLength = strlen($characters);
@ -191,4 +201,23 @@ class common extends \yii\db\ActiveRecord {
return $randomString; return $randomString;
} }
public static function convert_vi_to_en($str) {
$str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", "a", $str);
$str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", "e", $str);
$str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", "i", $str);
$str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", "o", $str);
$str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", "u", $str);
$str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", "y", $str);
$str = preg_replace("/(đ)/", "d", $str);
$str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", "A", $str);
$str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", "E", $str);
$str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", "I", $str);
$str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", "O", $str);
$str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", "U", $str);
$str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", "Y", $str);
$str = preg_replace("/(Đ)/", "D", $str);
//$str = str_replace(" ", "-", str_replace("&*#39;","",$str));
return $str;
}
} }

View File

@ -361,7 +361,7 @@ function _sync() {
} }
common.modalBlock(true); common.modalBlock(true);
$("#progress-totals").html(lists.length); $("#progress-totals").html(lists.length);
$("#progress-form").removeClass("hidden"); $("#progress-form").removeClass("hidden");
totals = lists.length; totals = lists.length;
syncFeatureFromDevice(lists[0], lists); syncFeatureFromDevice(lists[0], lists);
} }
@ -372,7 +372,8 @@ function syncFeatureFromDevice(id, fullData) {
type: 'POST', type: 'POST',
data: { data: {
id: id, id: id,
ip: $("input[name='SyncIP']").val() ip: $("input[name='SyncIP']").val(),
totals: totals
}, },
success: function (data) { success: function (data) {
console.log(data, progress); console.log(data, progress);
@ -384,8 +385,12 @@ function syncFeatureFromDevice(id, fullData) {
$("#progress").html(percent + "%"); $("#progress").html(percent + "%");
if (percent >= 100) { if (percent >= 100) {
common.modalBlock(false); common.modalBlock(false);
updateFeature(); if (totals > 10) {
progress = 0; updateFeature();
progress = 0;
} else {
window.location.reload(true);
}
} else { } else {
syncFeatureFromDevice(fullData[progress], fullData); syncFeatureFromDevice(fullData[progress], fullData);
} }
@ -434,7 +439,8 @@ function syncFeature(id, fullData) {
url: $("input[name='sync_feature_url']").val(), url: $("input[name='sync_feature_url']").val(),
type: 'POST', type: 'POST',
data: { data: {
id: id id: id,
totals: totals
}, },
success: function (data) { success: function (data) {
console.log(data, progress); console.log(data, progress);
@ -446,8 +452,12 @@ function syncFeature(id, fullData) {
$("#progress").html(percent + "%"); $("#progress").html(percent + "%");
if (percent >= 100) { if (percent >= 100) {
common.modalBlock(false); common.modalBlock(false);
updateFeature(); if (totals > 10) {
progress = 0; updateFeature();
progress = 0;
} else {
window.location.reload(true);
}
} else { } else {
syncFeature(fullData[progress], fullData); syncFeature(fullData[progress], fullData);
} }