PBConfigData.cpp 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // PBConfigData.cpp
  3. // merge6
  4. //
  5. // Created by Black Homles on 2024/9/24.
  6. //
  7. #include "PBConfigData.hpp"
  8. #include "rapidcsv.h"
  9. PBConfigData* PBConfigData::_gPBConfigData = nullptr;
  10. PBConfigData::PBConfigData() {
  11. }
  12. PBConfigData::~PBConfigData() {
  13. }
  14. PBConfigData* PBConfigData::getInstance() {
  15. if (_gPBConfigData == nullptr || !_gPBConfigData) {
  16. _gPBConfigData = new (std::nothrow) PBConfigData();
  17. }
  18. return _gPBConfigData;
  19. }
  20. void PBConfigData::initData(std::string cfgFN) {
  21. string fileName = cfgFN;
  22. _bannerInfoList.clear();
  23. if (!FileUtils::getInstance()->isFileExist(fileName)) {
  24. return;
  25. }
  26. std::string fullfiledata = FileUtils::getInstance()->getStringFromFile(fileName);
  27. std::stringstream sstream(fullfiledata);
  28. rapidcsv::Document tempDoc(sstream);
  29. int rowcount = (int)tempDoc.GetRowCount();
  30. for (int irow = 0; irow < rowcount; irow++) {
  31. bannerInfo tmpinfo;
  32. tmpinfo.bannerName = tempDoc.GetCell<string>("名称",irow);
  33. tmpinfo.bannerDes = tempDoc.GetCell<string>("描述",irow);
  34. tmpinfo.bannerType = tempDoc.GetCell<string>("类型",irow);
  35. tmpinfo.bannerFile = tempDoc.GetCell<string>("文件名称",irow);
  36. tmpinfo.bannerTitle = tempDoc.GetCell<string>("标题",irow);
  37. tmpinfo.bannerPlist = tempDoc.GetCell<string>("图集名称",irow);
  38. tmpinfo.bannerBGSp = tempDoc.GetCell<string>("背景图片",irow);
  39. tmpinfo.bannerPID = tempDoc.GetCell<string>("商品ID",irow);
  40. tmpinfo.bannerCutCount = tempDoc.GetCell<string>("折扣数字",irow);
  41. tmpinfo.bannerPrice = tempDoc.GetCell<string>("价格数字",irow);
  42. tmpinfo.bannerBtnStr = tempDoc.GetCell<string>("按钮文字",irow);
  43. tmpinfo.bannerTime = tempDoc.GetCell<int>("有效时间秒",irow);
  44. tmpinfo.item1ID = tempDoc.GetCell<string>("物品1ID",irow);
  45. tmpinfo.item1Type = tempDoc.GetCell<string>("物品1类型",irow);
  46. tmpinfo.item1Count = tempDoc.GetCell<int>("物品1数量",irow);
  47. tmpinfo.item1PNG = tempDoc.GetCell<string>("物品1图片",irow);
  48. tmpinfo.item2ID = tempDoc.GetCell<string>("物品2ID",irow);
  49. tmpinfo.item2Type = tempDoc.GetCell<string>("物品2类型",irow);
  50. tmpinfo.item2Count = tempDoc.GetCell<int>("物品2数量",irow);
  51. tmpinfo.item2PNG = tempDoc.GetCell<string>("物品2图片",irow);
  52. tmpinfo.item3ID = tempDoc.GetCell<string>("物品3ID",irow);
  53. tmpinfo.item3Type = tempDoc.GetCell<string>("物品3类型",irow);
  54. tmpinfo.item3Count = tempDoc.GetCell<int>("物品3数量",irow);
  55. tmpinfo.item3PNG = tempDoc.GetCell<string>("物品3图片",irow);
  56. tmpinfo.item3Des = tempDoc.GetCell<string>("物品3描述",irow);
  57. _bannerInfoList.push_back(tmpinfo);
  58. }
  59. //view config
  60. string fileName2 = "bannerViewConfig.csv";
  61. _bResList.clear();
  62. if (!FileUtils::getInstance()->isFileExist(fileName2)) {
  63. return;
  64. }
  65. std::string fullfiledata2 = FileUtils::getInstance()->getStringFromFile(fileName2);
  66. std::stringstream sstream2(fullfiledata2);
  67. rapidcsv::Document tempDoc2(sstream2);
  68. int rowcount2 = (int)tempDoc2.GetRowCount();
  69. for (int lopp = 1; lopp < rowcount2; lopp++) {
  70. string tmpstr = tempDoc2.GetCell<string>("资源名称",lopp);
  71. _bResList.push_back(tmpstr);
  72. }
  73. _thisDotcfg.sepWidth = tempDoc2.GetCell<int>("圆点宽度",0);
  74. _thisDotcfg.yStart = tempDoc2.GetCell<int>("圆点高度",0);
  75. _thisDotcfg.highSp = tempDoc2.GetCell<string>("圆点亮图",0);
  76. _thisDotcfg.normalSp = tempDoc2.GetCell<string>("圆点暗图",0);
  77. }
  78. PBConfigData::bannerInfo PBConfigData::getBannerInfo(string bName) {
  79. bannerInfo tmpinfo;
  80. for (int lopp = 0; lopp < _bannerInfoList.size(); lopp++) {
  81. if (_bannerInfoList[lopp].bannerName == bName) {
  82. tmpinfo = _bannerInfoList[lopp];
  83. break;
  84. }
  85. }
  86. return tmpinfo;
  87. }
  88. PBConfigData::sPBDotCfg PBConfigData::getViewDot() {
  89. return _thisDotcfg;
  90. }