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('list_management')->execute();
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']);
} else {

View File

@ -108,7 +108,12 @@ class ControlLogsController extends Controller {
];
$listManagement->image = json_encode($images);
$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" => 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->image = json_encode($images);
$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" => 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->address = $data['address'];
$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;
}
}
@ -250,8 +260,13 @@ class ListManagementController extends Controller {
foreach ($images as $k => $v) {
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();
file_get_contents("http://localhost:2305/update-feature");
return true;
}
}
@ -271,7 +286,12 @@ class ListManagementController extends Controller {
}
$model->image = json_encode($features);
$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;
}
}
@ -295,9 +315,17 @@ class ListManagementController extends Controller {
foreach ($images as $k => $v) {
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();
}
}
if (count($data['lists']) > 10)
file_get_contents("http://localhost:2305/update-feature");
return true;
}
@ -385,6 +413,7 @@ class ListManagementController extends Controller {
public function actionSyncFeature() {
if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$totals = intval(Yii::$app->request->post("totals"));
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$ip = "dev-dc.beetai.com";
if ($server_ip)
@ -438,6 +467,13 @@ class ListManagementController extends Controller {
$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
]);
} else {
$model = new ListManagement();
$model->create([
@ -450,6 +486,13 @@ class ListManagementController extends Controller {
'telephone' => "",
'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];
}
@ -459,6 +502,7 @@ class ListManagementController extends Controller {
if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$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([
'http' => [
'header' => "Content-Type: application/json",
@ -494,6 +538,13 @@ class ListManagementController extends Controller {
$model->telephone = $value['telephone'];
$model->address = $value['department'];
$model->save();
if ($totals <= 10)
common::updateFeature([
"cmd" => "update",
"id" => $model->id,
"name" => common::convert_vi_to_en($model->name),
"features" => $model->allFeatures
]);
} else {
$model = new ListManagement();
$model->create([
@ -507,6 +558,13 @@ class ListManagementController extends Controller {
'address' => $value['department'],
'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];

View File

@ -116,4 +116,16 @@ class ListManagement extends \yii\db\ActiveRecord {
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) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
@ -191,4 +201,23 @@ class common extends \yii\db\ActiveRecord {
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

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