FrameInferData.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #pragma once
  2. #include <iostream>
  3. #include <memory>
  4. #include "Util/SqlPool.h"
  5. using namespace toolkit;
  6. using namespace std;
  7. class FrameInferData
  8. {
  9. public:
  10. using Ptr = std::shared_ptr<FrameInferData>;
  11. public:
  12. int ID;
  13. int ClassId;
  14. int Num;
  15. string Remark;
  16. string ImageBase64;
  17. string WarningTime;
  18. string VideoPath;
  19. string attr1;
  20. string attr2;
  21. string attr3;
  22. int Warn = 0;
  23. std::string uuid;
  24. public:
  25. FrameInferData(){}
  26. ~FrameInferData(){}
  27. std::string ObjectToSql(){
  28. SqlStream sqlStream("insert into gsdDB.`InferData` (ClassId, Num, Remark, ImageBase64, WarningTime, VideoPath, attr1, attr2,attr3,Warn,uuid, ISDELETE)\
  29. values ('?','?','?','?','?', '?','?','?','?','?','?', 0)");
  30. sqlStream << ClassId << Num << Remark << ImageBase64 << WarningTime << VideoPath << attr1 << attr2 << attr3 << Warn << uuid;
  31. return (std::string)sqlStream;
  32. }
  33. // Json转为对象
  34. bool JsonToObject(std::string& json){
  35. rapidjson::Document doc;
  36. doc.Parse(json.c_str());
  37. if(!doc.IsObject()){
  38. return false;
  39. }
  40. // get members
  41. const auto end = doc.MemberEnd();
  42. // json_type
  43. if(end == doc.FindMember("ID") || !doc["ID"].IsString()) {
  44. return false;
  45. }else{
  46. ID = atoi(doc["ID"].GetString());
  47. }
  48. // json_type
  49. if(end == doc.FindMember("ClassId") || !doc["ClassId"].IsString()) {
  50. return false;
  51. }else{
  52. ClassId = atoi(doc["ClassId"].GetString());
  53. }
  54. if (end == doc.FindMember("Num") || !doc["Num"].IsString()) {
  55. return false;
  56. } else {
  57. Num = atoi(doc["Num"].GetString());
  58. }
  59. if(end == doc.FindMember("Remark") || !doc["Remark"].IsString()) {
  60. return false;
  61. }else{
  62. Remark = doc["Remark"].GetString();
  63. }
  64. if (end == doc.FindMember("ImageBase64") || !doc["ImageBase64"].IsString()) {
  65. return false;
  66. } else {
  67. ImageBase64 = doc["ImageBase64"].GetString();
  68. }
  69. if(end == doc.FindMember("WarningTime") || !doc["WarningTime"].IsString()) {
  70. return false;
  71. }else{
  72. WarningTime = doc["WarningTime"].GetString();
  73. }
  74. if(end == doc.FindMember("VideoPath") || !doc["VideoPath"].IsString()) {
  75. return false;
  76. }else{
  77. VideoPath = doc["VideoPath"].GetString();
  78. }
  79. if(end == doc.FindMember("attr1") || !doc["attr1"].IsString()) {
  80. return false;
  81. }else{
  82. attr1 = doc["attr1"].IsString();
  83. }
  84. if(end == doc.FindMember("attr2") || !doc["attr2"].IsString()) {
  85. return false;
  86. }else{
  87. attr2 = doc["attr2"].GetString();
  88. }
  89. if(end == doc.FindMember("attr3") || !doc["attr3"].IsString()) {
  90. return false;
  91. }else{
  92. attr2 = doc["attr3"].GetString();
  93. }
  94. if(end == doc.FindMember("Warn") || !doc["Warn"].IsString()) {
  95. return false;
  96. }else{
  97. attr2 = atoi(doc["Warn"].GetString());
  98. }
  99. if(end == doc.FindMember("uuid") || !doc["uuid"].IsString()) {
  100. return false;
  101. }else{
  102. uuid = doc["uuid"].GetString();
  103. }
  104. return true;
  105. }
  106. };