remotepackconfig.cpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #include "remotepackconfig.h"
  2. #include "globalinfo.h"
  3. RemotePackConfig::RemotePackConfig(QObject *parent) : QObject(parent)
  4. {
  5. connect(&_request,&HttpRequest::result,this,&RemotePackConfig::result);
  6. parsefUNS.insert("A1000100",[this](const QJsonObject & obj){this->_config.jitai = this->getConfigStringList(obj);});
  7. parsefUNS.insert("A1000101",[this](const QJsonObject & obj){this->_config.dangchegongbanci = this->getConfigStringList(obj);});
  8. parsefUNS.insert("A1000102",[this](const QJsonObject & obj){this->_config.daBaoGongBanCi = this->getConfigStringList(obj);});
  9. parsefUNS.insert("A1000103",[this](const QJsonObject & obj){this->_config.xiangzhong = this->getConfigStringDouble(obj);});
  10. parsefUNS.insert("A1000104",[this](const QJsonObject & obj){this->_config.tongZhong = this->getConfigStringDouble(obj);});
  11. parsefUNS.insert("A1000105",[this](const QJsonObject & obj){this->_config.guanse = this->getConfigStringList(obj);});
  12. parsefUNS.insert("A1000106",[this](const QJsonObject & obj){this->_config.nianxiang = this->getConfigStringList(obj);});
  13. parsefUNS.insert("A1000107",[this](const QJsonObject & obj){this->_config.zhixiang = this->getConfigStringList(obj);});
  14. parsefUNS.insert("A1000108",[this](const QJsonObject & obj){this->_config.mashu = this->getConfigStringInt(obj);});
  15. parsefUNS.insert("A1000109",[this](const QJsonObject & obj){this->_config.cheZhong = this->getConfigStringList(obj);});
  16. parsefUNS.insert("A1000110",[this](const QJsonObject & obj){this->_config.gangHao = this->getConfigStringList(obj);});
  17. parsefUNS.insert("A1000111",[this](const QJsonObject & obj){this->_config.xiangHaoXianShiGuiZe = this->getConfigInt(obj);});
  18. parsefUNS.insert("A1000112",[this](const QJsonObject & obj){this->_config.daBaoRuku = this->getConfigBool(obj);});
  19. parsefUNS.insert("A1000113",[this](const QJsonObject & obj){this->_config.daBaoRiQiXianShiFangShi = this->getConfigInt(obj);});
  20. parsefUNS.insert("A2000200",[this](const QJsonObject & obj){this->_config.ziDongDushu = this->getConfigBool(obj);});
  21. parsefUNS.insert("A2000201",[this](const QJsonObject & obj){this->_config.buDingZhongDaBaoXianzhi = this->getConfigBool(obj);});
  22. parsefUNS.insert("A2000202",[this](const QJsonObject & obj){this->_config.dingZhongDaBaoXianZhiKaiQi = this->getConfigBool(obj);});
  23. parsefUNS.insert("A2000203",[this](const QJsonObject & obj){this->_config.jiTaiBangDingMaDan = this->getConfigBool(obj);});
  24. parsefUNS.insert("A2000204",[this](const QJsonObject & obj){this->_config.morenTongZhongGUDing = this->getConfigBool(obj);});
  25. parsefUNS.insert("A2000205",[this](const QJsonObject & obj){this->_config.morenXiandhiMaoZhong = this->getConfigBool(obj);});
  26. parsefUNS.insert("A2000206",[this](const QJsonObject & obj){this->_config.morenDaYinRuKuMadan = this->getConfigBool(obj);});
  27. parsefUNS.insert("A2000207",[this](const QJsonObject & obj){this->_config.morenBudingZhongMaoZhongXianZhi = this->getConfigBool(obj);});
  28. parsefUNS.insert("A2000208",[this](const QJsonObject & obj){this->_config.daBaoZhuangLeiXingGuiZeKaiQi = this->getConfigBool(obj);});
  29. parsefUNS.insert("A2000209",[this](const QJsonObject & obj){this->_config.daBaoZhuangMaoZhongXianZhiKaiQi = this->getConfigBool(obj);});
  30. parsefUNS.insert("A2000210",[this](const QJsonObject & obj){this->_config.ziDongDaBaoKaiQi = this->getConfigBool(obj);});
  31. parsefUNS.insert("A2000211",[this](const QJsonObject & obj){this->_config.pingBanZiDongTongBuShuJu = this->getConfigBool(obj);});
  32. parsefUNS.insert("A2000212",[this](const QJsonObject & obj){
  33. auto jingdu = this->daBaoJingDu(obj);
  34. this->_config.chengZhongJIngDu = jingdu.first;
  35. this->_config.chengZhongJingDuMode = jingdu.second;
  36. });
  37. // parsefUNS.insert("A2000213",[this](const QJsonObject & obj){this->_config.buDingZhongTongShuFanWei = this->getConfigpAIR(obj);});
  38. // parsefUNS.insert("A2000214",[this](const QJsonObject & obj){this->_config.dingZhongTongShuFanwei = this->getConfigpAIR(obj);});
  39. //TODO:http://doc.vanlai.net:3001/web/#/1?page_id=57 补全剩下
  40. //http://erp.itwsw.cn/#/packageCon
  41. }
  42. QList<DIYPackConfig> RemotePackConfig::getDiys(const QJsonObject & data)
  43. {
  44. // TODO:
  45. }
  46. QList<POYPackConfig> RemotePackConfig::getPoys(const QJsonObject & data)
  47. {
  48. // TODO:
  49. }
  50. void RemotePackConfig::refConfig()
  51. {
  52. getDdengji = false;
  53. GlobalInfo * glo = GlobalInfo::this_();
  54. // _aid = QString::number(body["user_id"].toInt());
  55. // _token = body["access_token"].toString();
  56. _request.setUserToken(QString::number( glo->user().accountId) ,glo->user().acessToken);
  57. QString url = glo->config().baseUrl + "/v1/configuration";
  58. _request.get(url);
  59. }
  60. void RemotePackConfig::result(int code, const QJsonObject & body)
  61. {
  62. int ecode = body.value("code").toInt(404);
  63. if(ecode != 200){
  64. emit configUpdateError(ecode,body.value("message").toString(""));
  65. return;
  66. }
  67. if(!getDdengji){
  68. QJsonArray object = body.value("data").toArray();
  69. for(int i = 0; i < object.size(); ++ i){
  70. QJsonObject obj = object.at(i).toObject();
  71. QString key = obj.value("key").toString();
  72. auto handle = parsefUNS.value(key,[](const QJsonObject &){});
  73. handle(obj);
  74. }
  75. emit configUpdate(_config);
  76. refDengJiList();
  77. } else {
  78. // TODO: 解析等级列表
  79. }
  80. }
  81. void RemotePackConfig::refDengJiList()
  82. {
  83. // todo: http://doc.vanlai.net:3001/web/#/1?page_id=35
  84. }
  85. bool RemotePackConfig::getConfigBool(const QJsonObject & data)
  86. {
  87. QJsonArray value_array = data.value("value").toArray();
  88. int vSize = value_array.size();
  89. QString select;
  90. for(int i = 0; i < vSize; ++i){
  91. QJsonValue value_content = value_array.at(i);
  92. if(value_content.isObject()){
  93. QJsonObject value_object = value_content.toObject();
  94. if(value_object.value("selected").toBool(false)){
  95. select = value_object.value("name").toString();
  96. }
  97. }
  98. }
  99. // select = select.trimmed();
  100. if(select.contains("是") || select.contains("yes",Qt::CaseInsensitive))
  101. return true;
  102. return false;
  103. }
  104. QStringList RemotePackConfig::getConfigStringList(const QJsonObject & data)
  105. {
  106. QJsonArray value_array = data.value("value").toArray();
  107. QStringList list;
  108. int vSize = value_array.size();
  109. for(int i = 0; i < vSize; ++i){
  110. QJsonValue value_content = value_array.at(i);
  111. if(value_content.isObject()){
  112. QJsonObject value_object = value_content.toObject();
  113. list.append(value_object.value("value").toString());
  114. }
  115. }
  116. return list;
  117. }
  118. int RemotePackConfig::getConfigInt(const QJsonObject & data)
  119. {
  120. QJsonArray value_array = data.value("value").toArray();
  121. int list;
  122. int vSize = value_array.size();
  123. for(int i = 0; i < vSize; ++i){
  124. QJsonValue value_content = value_array.at(i);
  125. if(value_content.isObject()){
  126. QJsonObject value_object = value_content.toObject();
  127. if(value_content.isObject()){
  128. QJsonObject value_object = value_content.toObject();
  129. if(value_object.value("selected").toBool(false)){
  130. list = value_object.value("value").toInt();
  131. }
  132. }
  133. }
  134. }
  135. return list;
  136. }
  137. QPair<int,int> getConfigpAIR(const QJsonObject & data)
  138. {
  139. QJsonArray value_array = data.value("value").toArray();
  140. QPair<int,int> list;
  141. int vSize = value_array.size();
  142. bool frist = true;
  143. for(int i = 0; i < vSize; ++i){
  144. QJsonObject value_object = value_array.at(i).toObject();
  145. if(value_object.value("selected").toBool(false)){
  146. if(frist) {
  147. list.first = value_object.value("value").toInt();
  148. frist = false;
  149. } else {
  150. list.second = value_object.value("value").toInt();
  151. }
  152. }
  153. }
  154. return list;
  155. }
  156. QPair<int,int> RemotePackConfig::daBaoJingDu(const QJsonObject & data)
  157. {
  158. QJsonArray value_array = data.value("value").toArray();
  159. QPair<int,int> list;
  160. int vSize = value_array.size();
  161. bool frist = true;
  162. for(int i = 0; i < vSize; ++i){
  163. QJsonValue value_content = value_array.at(i);
  164. auto ary = value_content.toArray();
  165. for(int j = 0; j < ary.size(); ++j){
  166. QJsonObject value_object = ary.at(j).toObject();
  167. if(value_object.value("selected").toBool(false)){
  168. if(frist) {
  169. list.first = value_object.value("value").toInt();
  170. frist = false;
  171. } else {
  172. list.second = value_object.value("value").toInt();
  173. }
  174. }
  175. }
  176. }
  177. return list;
  178. }
  179. QList<double> RemotePackConfig::getConfigStringDouble(const QJsonObject & data)
  180. {
  181. QJsonArray value_array = data.value("value").toArray();
  182. QList<double> list;
  183. int vSize = value_array.size();
  184. for(int i = 0; i < vSize; ++i){
  185. QJsonValue value_content = value_array.at(i);
  186. if(value_content.isObject()){
  187. QJsonObject value_object = value_content.toObject();
  188. list.append(value_object.value("value").toDouble());
  189. }
  190. }
  191. return list;
  192. }
  193. QList<int> RemotePackConfig::getConfigStringInt(const QJsonObject & data)
  194. {
  195. QJsonArray value_array = data.value("value").toArray();
  196. QList<int> list;
  197. int vSize = value_array.size();
  198. for(int i = 0; i < vSize; ++i){
  199. QJsonValue value_content = value_array.at(i);
  200. if(value_content.isObject()){
  201. QJsonObject value_object = value_content.toObject();
  202. list.append(value_object.value("value").toInt());
  203. }
  204. }
  205. return list;
  206. }