FrameInferData.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. if (doc.Parse<rapidjson::kParseCommentsFlag>(json.c_str()).HasParseError()) {
  37. return false;
  38. }
  39. // get members
  40. const auto end = doc.MemberEnd();
  41. // json_type
  42. if(end == doc.FindMember("ID") || !doc["ID"].IsString()) {
  43. return false;
  44. }else{
  45. ID = atoi(doc["ID"].GetString());
  46. }
  47. // json_type
  48. if(end == doc.FindMember("ClassId") || !doc["ClassId"].IsString()) {
  49. return false;
  50. }else{
  51. ClassId = atoi(doc["ClassId"].GetString());
  52. }
  53. if (end == doc.FindMember("Num") || !doc["Num"].IsString()) {
  54. return false;
  55. } else {
  56. Num = atoi(doc["Num"].GetString());
  57. }
  58. if(end == doc.FindMember("Remark") || !doc["Remark"].IsString()) {
  59. return false;
  60. }else{
  61. Remark = doc["Remark"].GetString();
  62. }
  63. if (end == doc.FindMember("ImageBase64") || !doc["ImageBase64"].IsString()) {
  64. return false;
  65. } else {
  66. ImageBase64 = doc["ImageBase64"].GetString();
  67. }
  68. if(end == doc.FindMember("WarningTime") || !doc["WarningTime"].IsString()) {
  69. return false;
  70. }else{
  71. WarningTime = doc["WarningTime"].GetString();
  72. }
  73. if(end == doc.FindMember("VideoPath") || !doc["VideoPath"].IsString()) {
  74. return false;
  75. }else{
  76. VideoPath = doc["VideoPath"].GetString();
  77. }
  78. if(end == doc.FindMember("attr1") || !doc["attr1"].IsString()) {
  79. return false;
  80. }else{
  81. attr1 = doc["attr1"].IsString();
  82. }
  83. if(end == doc.FindMember("attr2") || !doc["attr2"].IsString()) {
  84. return false;
  85. }else{
  86. attr2 = doc["attr2"].GetString();
  87. }
  88. if(end == doc.FindMember("attr3") || !doc["attr3"].IsString()) {
  89. return false;
  90. }else{
  91. attr2 = doc["attr3"].GetString();
  92. }
  93. if(end == doc.FindMember("Warn") || !doc["Warn"].IsString()) {
  94. return false;
  95. }else{
  96. attr2 = atoi(doc["Warn"].GetString());
  97. }
  98. if(end == doc.FindMember("uuid") || !doc["uuid"].IsString()) {
  99. return false;
  100. }else{
  101. uuid = doc["uuid"].GetString();
  102. }
  103. return true;
  104. }
  105. };