From a9e9e90b0c0a8fa7f0b78b29101a3dc13a021a5d Mon Sep 17 00:00:00 2001
From: pansen <pansen626@sina.com>
Date: 星期五, 04 一月 2019 11:01:50 +0800
Subject: [PATCH] Merge branch 'master' into Develop

---
 QiaoJiaSystem/DataManagerServer/http_configserver.cpp |  252 ++++++++++++++++++++++++++++----------------------
 1 files changed, 141 insertions(+), 111 deletions(-)

diff --git a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
index 5505ad3..65fdc9e 100644
--- a/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
+++ b/QiaoJiaSystem/DataManagerServer/http_configserver.cpp
@@ -21,6 +21,7 @@
 //#include "HcRecord.h"
 #include <time.h>
 #include <dirent.h>
+
 using namespace std;
 
 devHttpServer_c::devHttpServer_c()
@@ -2000,27 +2001,11 @@
             auto t_results = m_curlDownloadImg.download_jpeg(const_cast<char *>(img_url.c_str()));
             cvutil.buffer2CvMat(t_results.buffer, image);
         } else if (img_base64.size() > 0) {
-            img_url = "http://";
             auto str_img = base64.Decode(img_base64.c_str(), img_base64.size());
             std::vector<unsigned char> buffer(str_img.size());
             memcpy(buffer.data(), str_img.data(), str_img.size());
             cvutil.buffer2CvMat(buffer, image);
 
-
-            fdfsClient.rwLock.rdlock();
-            if (fdfsClient.fastFds != nullptr) {
-                img_url.append(fdfsClient.fastFds->getIp() + "/");
-                std::string t_strImg = "";
-                if (!fdfsClient.fastFds->uploadFile(buffer, t_strImg, "jpg")) {
-                    img_url = "upload image fail";
-                } else {
-                    img_url.append(t_strImg);
-                    img_url.clear();
-                    img_url = t_strImg;
-//                    img_url.append("/").append(t_strImg);
-                }
-            }
-            fdfsClient.rwLock.unlock();
         } else {
             response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"not found img\"}");
             return "";
@@ -2045,10 +2030,39 @@
 //            cv::imwrite(str_path, image);
             return "";
 //            return "{\"error\":\"not found face\"}";
+        } else if (faceResults.size() > 1) {
+            response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\" 浠呮敮鎸佸崟浜鸿劯鍥剧墖 \"}");
+            return "";
         }
 
         for (auto &item : faceResults) {
             feature_base64 = base64.Encode(item.feature.data(), item.feature.size());
+
+
+            int x = item.left;
+            int y = item.top;
+            int w = item.width;
+            int h = item.height;
+            cv::Rect t_rect = {x, y, w, h};
+            auto t_image = image(CvUtil::zoomRect(t_rect, 1.5, 1.5) & cv::Rect(0, 0, image.cols, image.rows)).clone();
+            std::vector<uchar> buffer;
+            cvutil.cvMat2Buffer(t_image, buffer);
+            img_url = "http://";
+            fdfsClient.rwLock.rdlock();
+            if (fdfsClient.fastFds != nullptr) {
+                img_url.append(fdfsClient.fastFds->getIp() + "/");
+                std::string t_strImg = "";
+                if (!fdfsClient.fastFds->uploadFile(buffer, t_strImg, "jpg")) {
+                    img_url = "upload image fail";
+                } else {
+                    img_url.append(t_strImg);
+                    img_url.clear();
+                    img_url = t_strImg;
+//                    img_url.append("/").append(t_strImg);
+                }
+            }
+            fdfsClient.rwLock.unlock();
+
         }
         auto size = feature_base64.size();
 //        std::string uuid = "";
@@ -2317,14 +2331,14 @@
             std::string picDate = value["picDate"].asString();
 
             //std::string path_uuid = videoPath;//value["path_uuid"].asString();
-            qint64 sub ;
-            std::string  path = getVideoPathByTime(picDate,devId,sub);
+            qint64 sub;
+            std::string path = getVideoPathByTime(picDate, devId, sub);
 
             if (path.empty()) {
                 ERR("{\"error\":\"not find path\"}");
                 return "{\"error\":\"鏈煡鍒拌棰戣矾寰刓"}";
             }
-            DBG("path="<<path);
+            DBG("path=" << path);
             videoPath.clear();
             videoPath = path;
 
@@ -2332,10 +2346,10 @@
 
             // sub = (dt.toMSecsSinceEpoch() - dtFile.toMSecsSinceEpoch());
             //#yanchi buchong
-           // sub = sub > 3000 ? sub - 3000 : 0000;
+            // sub = sub > 3000 ? sub - 3000 : 0000;
             //shijian yuejie buchang
-           // sub = sub < 0 ? 0000 : sub;
-           int haomiao = sub % 1000;
+            // sub = sub < 0 ? 0000 : sub;
+            int haomiao = (sub % 1000) > 50 ? ((sub % 1000) - 50) : 0;
             sub /= 1000;
             int m = sub;
             int shi, fen, miao;
@@ -2344,10 +2358,10 @@
                 shi = m / 3600;
                 fen = m / 60 % 60;
                 miao = m % 60;
-                sprintf(ch_time, "%02d:%02d:%02d.%03d", shi, fen, miao, haomiao);
-                cout << ch_time << endl;
-            } else printf("杈撳叆鏁板�煎お澶�");
+                sprintf(ch_time, "%02d:%02d:%02d.%02d", shi, fen, miao, haomiao / 10);
 
+            } else printf("杈撳叆鏁板�煎お澶�");
+            DBG("ch_time" << ch_time);
             std::string str_time(ch_time);
             //#todo 鎸夌収鏃堕棿鍛藉悕
             std::string str_imgName(AppUtil::getTimeString() + ".jpg");// = "test.jpg";
@@ -2359,7 +2373,7 @@
 
             if (str_time > str_tmpTime) {
                 ERR("{\"error\":\"Time error\"}" << str_time << " str_tmpTime " << str_tmpTime);
-                str_time = str_tmpTime.size() > 0 ? str_tmpTime.substr(0, str_tmpTime.rfind(".")) : str_time;
+                str_time = str_tmpTime.size() > 0 ? str_tmpTime : str_time;
 //            return "{\"error\":\"Time error\"}";
             }
 
@@ -2414,25 +2428,19 @@
     Json::Reader reader;
     Json::Value value;
 
-    if (reader.parse(content, value))
-    {
+    if (reader.parse(content, value)) {
         std::string devId = value["videoNum"].asString();
         std::string picDate = value["picDate"].asString();
-       qint64 sub;
-       std::string path=getVideoPathByTime(picDate,devId,sub);
-        if (path.empty())
-        {
+        qint64 sub;
+        std::string path = getVideoPathByTime(picDate, devId, sub);
+        if (path.empty()) {
 
             return "{\"ret_status\":\"鍐呭鏈夎锛岃妫�鏌ワ紒\"}";
-        }
-        else
-        {
+        } else {
             std::string result = "{\"file_path\":\"" + path + "\"}";
             return result;
         }
-    }
-    else
-    {
+    } else {
         return "{\"ret_status\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}";
     }
 }
@@ -2513,90 +2521,110 @@
     return true;
 }
 
- std::string devHttpServer_c::getVideoPathByTime(const std::string& time,const std::string& camId,qint64& sub)
- {
-     std::string t_FilePath = appConfig.getStringProperty("cutPath");
+std::string devHttpServer_c::getVideoPathByTime(const std::string &time, const std::string &camId, qint64 &sub) {
+    std::string t_FilePath = appConfig.getStringProperty("cutPath");
 
-     bool find=false;;
-     if (t_FilePath.back() != '/') {
-         t_FilePath.push_back('/');
-     }
+    bool find = false;;
+    if (t_FilePath.back() != '/') {
+        t_FilePath.push_back('/');
+    }
 
-     QDateTime dt = QDateTime::fromString(QString::fromStdString(time), "yyyy-MM-dd hh:mm:ss:zzz");
+    QDateTime dt = QDateTime::fromString(QString::fromStdString(time), "yyyy-MM-dd hh:mm:ss:zzz");
 
-      std::string t_strTime=dt.toString("yyyyMMddhh").toStdString();
-        //# ./camIndex/YYYYMM/DD/
-      t_FilePath.append(camId + "/" + t_strTime.substr(0, 6)+ "/" +t_strTime.substr(6, 2) + "/");
-      //YYYYMMDDHH
-       t_FilePath.append(t_strTime.substr(0,10) + "/");
+    std::string t_strTime = dt.toString("yyyyMMddhh").toStdString();
+    //# ./camIndex/YYYYMM/DD/
+    t_FilePath.append(camId + "/" + t_strTime.substr(0, 6) + "/" + t_strTime.substr(6, 2) + "/");
+    //YYYYMMDDHH
+    t_FilePath.append(t_strTime.substr(0, 10) + "/");
 
 
-     qint64 t=dt.toMSecsSinceEpoch();
-     std::vector<std::string> vec=forEachFile(t_FilePath);
-     std::sort(vec.begin(),vec.end());
-     DBG("t_FilePath" << t_FilePath);
-     DBG("vec.size()" << vec.size());
-     int size=vec.size();
-     for(int i=0;i<size;++i)
-     {
-         qint64 t1=QDateTime::fromString(QString::fromStdString(vec[i]), "yyyy-MM-dd hh:mm:ss:zzz").toMSecsSinceEpoch();
-         if(i+1<size)
-         {
-             qint64 t2=QDateTime::fromString(QString::fromStdString(vec[i+1]), "yyyy-MM-dd hh:mm:ss:zzz").toMSecsSinceEpoch();
-             if(t>=t1 && t<t2)
-             {
-                 DBG("path="<<vec[i]);
-                 t_FilePath+=vec[i]+".mp4";
-                 sub=t-t1;
-                 find=true;
-                 break;
-             }
+    qint64 t = dt.toMSecsSinceEpoch();
+    std::vector<std::string> vec = forEachFile(t_FilePath);
+    std::sort(vec.begin(), vec.end());
+    DBG("t_FilePath" << t_FilePath);
+    DBG("vec.size()" << vec.size());
+    int size = vec.size();
+    for (int i = 0; i < size; ++i) {
+        qint64 t1 = QDateTime::fromString(QString::fromStdString(vec[i]),
+                                          "yyyy-MM-dd hh:mm:ss:zzz").toMSecsSinceEpoch();
+        if (i + 1 < size) {
+            qint64 t2 = QDateTime::fromString(QString::fromStdString(vec[i + 1]),
+                                              "yyyy-MM-dd hh:mm:ss:zzz").toMSecsSinceEpoch();
+            if (t >= t1 && t < t2) {
+                DBG("path=" << vec[i]);
+                t_FilePath += vec[i] + ".mp4";
+                sub = t - t1;
+                find = sub < getVideoTime(t_FilePath);
+                break;
+            }
 
-         }
-         else
-         {
-             sub=t-t1;
-             if(t>=t1 && sub<=3000)
-             {
-                 DBG("path="<<vec[i]);
-                 t_FilePath+=vec[i]+".mp4";
-                 find=true;
-                 break;
-             }
-         }
+        } else {
+            sub = t - t1;
+            if (t >= t1) {
+                DBG("path=" << vec[i]);
+                t_FilePath += vec[i] + ".mp4";
+
+                find = sub < getVideoTime(t_FilePath);
+
+                DBG("find:" << find);
+                break;
+            }
+        }
 
 
-     }
-     DBG("sub="<<sub);
-     if(!find)
-     {
-         t_FilePath="";
-     }
-     return t_FilePath;
+    }
+    DBG("sub=" << sub);
+    if (!find) {
+        t_FilePath = "";
+    }
+    return t_FilePath;
 
- }
- std::vector<std::string> devHttpServer_c::forEachFile(const std::string &dir_name)
- {
-     std::vector<std::string> v;
-     auto dir = opendir(dir_name.data());
-     struct dirent *ent;
-     int len = 0;
-     if (dir) {
-         while ((ent = readdir(dir)) != NULL) {
-             std::string filename = std::string(ent->d_name);
-             std::string temp;
-             if(filename!="."&&filename!="..")
-             {
+}
 
-                 temp = filename.substr(0, filename.rfind('.'));
-                 v.push_back(temp);
-             }
+qint64 devHttpServer_c::getVideoTime(const std::string &videoPath) {
+    std::string cmd_getVideoFileTime(
+        " ffmpeg -i '" + videoPath + "' 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//");
 
-         }
-         closedir(dir);
-     }
-     return v;
- }
+    std::string str_tmpTime = AppUtil::getCmdResult(cmd_getVideoFileTime);
+    DBG("str_tmpTime:" << str_tmpTime);//00:00:06.89
+    qint64 len_ms = 0;
+
+    QStringList list = QString::fromStdString(str_tmpTime).split(":");
+    if (list.size() == 3) {
+        len_ms = list[0].toInt() * 60 * 60 * 1000;
+        len_ms += list[1].toInt() * 60 * 1000;
+
+        QStringList s = list[2].split(".");
+        if (s.size() == 2) {
+            len_ms += s[0].toInt() * 1000;
+            len_ms += s[1].toInt() * 10;
+        }
+
+    }
+    DBG("len_ms:" << len_ms);
+    return len_ms;
+}
+
+std::vector<std::string> devHttpServer_c::forEachFile(const std::string &dir_name) {
+    std::vector<std::string> v;
+    auto dir = opendir(dir_name.data());
+    struct dirent *ent;
+    int len = 0;
+    if (dir) {
+        while ((ent = readdir(dir)) != NULL) {
+            std::string filename = std::string(ent->d_name);
+            std::string temp;
+            if (filename != "." && filename != "..") {
+
+                temp = filename.substr(0, filename.rfind('.'));
+                v.push_back(temp);
+            }
+
+        }
+        closedir(dir);
+    }
+    return v;
+}
 
 std::string devHttpServer_c::addPersons(std::string ip, unsigned int port, std::string content, PResponse &response) {
     DBG("ip:" << ip << "; port:" << port);
@@ -2644,6 +2672,7 @@
         } else {
             str_result = "[]";
         }
+        erlangDbTool->sendMessage();
         return str_result;
     } else {
         response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}");
@@ -2778,6 +2807,7 @@
             str_res = "{\"result\":\"-1\",\"msg\":\"error\",\"existDataBase\":[]}";
             ERR(ex.what());
         }
+        erlangDbTool->sendMessage();
         return str_res;
     } else {
         response->write(SimpleWeb::StatusCode::server_error_not_implemented, "{\"error\":\"浼犺緭閿欒锛岃妫�鏌ワ紒\"}");

--
Gitblit v1.8.0