remotepackconfig.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. #include "remotepackconfig.h"
  2. #include "globalinfo.h"
  3. #include <pqQtlib/utils/pqfileutils.h>
  4. #include <QJsonDocument>
  5. RemotePackConfig::RemotePackConfig(QObject *parent) : QObject(parent)
  6. {
  7. connect(&_request,&HttpRequest::result,this,&RemotePackConfig::result);
  8. connect(&_WareRequest,&HttpRequest::result,this,&RemotePackConfig::WareResult);
  9. parsefUNS.insert("A1000100",[this](const QJsonObject & obj){this->_config.jitai = this->getConfigStringList(obj);});
  10. parsefUNS.insert("A1000101",[this](const QJsonObject & obj){this->_config.dangchegongbanci = this->getConfigStringList(obj);});
  11. parsefUNS.insert("A1000102",[this](const QJsonObject & obj){this->_config.daBaoGongBanCi = this->getConfigStringList(obj);});
  12. parsefUNS.insert("A1000103",[this](const QJsonObject & obj){this->_config.xiangzhong = this->getConfigStringDouble(obj);});
  13. parsefUNS.insert("A1000104",[this](const QJsonObject & obj){this->_config.tongZhong = this->getConfigStringDouble(obj);});
  14. parsefUNS.insert("A1000105",[this](const QJsonObject & obj){this->_config.guanse = this->getConfigStringList(obj);});
  15. parsefUNS.insert("A1000106",[this](const QJsonObject & obj){this->_config.nianxiang = this->getConfigStringList(obj);});
  16. parsefUNS.insert("A1000107",[this](const QJsonObject & obj){this->_config.zhixiang = this->getConfigStringList(obj);});
  17. parsefUNS.insert("A1000108",[this](const QJsonObject & obj){this->_config.mashu = this->getConfigStringInt(obj);});
  18. // parsefUNS.insert("A1000109",[this](const QJsonObject & obj){this->_config.cheZhong = this->getConfigStringList(obj);});
  19. // parsefUNS.insert("A1000110",[this](const QJsonObject & obj){this->_config.gangHao = this->getConfigStringList(obj);});
  20. parsefUNS.insert("A1000111",[this](const QJsonObject & obj){this->_config.xiangHaoXianShiGuiZe = this->getConfigInt(obj);});
  21. parsefUNS.insert("A1000112",[this](const QJsonObject & obj){this->_config.daBaoRuku = this->getConfigBool(obj);});
  22. parsefUNS.insert("A1000113",[this](const QJsonObject & obj){this->_config.daBaoRiQiXianShiFangShi = this->getConfigInt(obj);});
  23. parsefUNS.insert("A1000114",[this](const QJsonObject & obj){this->_config.pinZhong = this->getConfigStringList(obj);});
  24. parsefUNS.insert("A2000200",[this](const QJsonObject & obj){this->_config.ziDongDushu = this->getConfigBool(obj);});
  25. parsefUNS.insert("A2000201",[this](const QJsonObject & obj){this->_config.buDingZhongDaBaoXianzhi = this->getConfigBool(obj);});
  26. parsefUNS.insert("A2000202",[this](const QJsonObject & obj){this->_config.dingZhongDaBaoXianZhiKaiQi = this->getConfigBool(obj);});
  27. parsefUNS.insert("A2000203",[this](const QJsonObject & obj){this->_config.jiTaiBangDingMaDan = this->getConfigBool(obj);});
  28. parsefUNS.insert("A2000204",[this](const QJsonObject & obj){this->_config.morenTongZhongGUDing = this->getConfigBool(obj);});
  29. parsefUNS.insert("A2000205",[this](const QJsonObject & obj){this->_config.morenXiandhiMaoZhong = this->getConfigBool(obj);});
  30. parsefUNS.insert("A2000206",[this](const QJsonObject & obj){this->_config.morenDaYinRuKuMadan = this->getConfigBool(obj);});
  31. parsefUNS.insert("A2000207",[this](const QJsonObject & obj){this->_config.morenBudingZhongMaoZhongXianZhi = this->getConfigBool(obj);});
  32. parsefUNS.insert("A2000208",[this](const QJsonObject & obj){this->_config.daBaoZhuangLeiXingGuiZeKaiQi = this->getConfigBool(obj);});
  33. parsefUNS.insert("A2000209",[this](const QJsonObject & obj){this->_config.daBaoZhuangMaoZhongXianZhiKaiQi = this->getConfigBool(obj);});
  34. parsefUNS.insert("A2000210",[this](const QJsonObject & obj){this->_config.ziDongDaBaoKaiQi = this->getConfigBool(obj);});
  35. parsefUNS.insert("A2000211",[this](const QJsonObject & obj){this->_config.pingBanZiDongTongBuShuJu = this->getConfigBool(obj);});
  36. parsefUNS.insert("A2000212",[this](const QJsonObject & obj){
  37. auto jingdu = this->daBaoJingDu(obj);
  38. this->_config.chengZhongJIngDu = jingdu.first;
  39. this->_config.chengZhongJingDuMode = jingdu.second;
  40. });
  41. parsefUNS.insert("A2000213",[this](const QJsonObject & obj){this->_config.buDingZhongTongShuFanWei = this->getConfigpAIR(obj);});
  42. parsefUNS.insert("A2000214",[this](const QJsonObject & obj){this->_config.dingZhongTongShuFanwei = this->getConfigpAIR(obj);});
  43. parsefUNS.insert("A2000215",[this](const QJsonObject & obj){this->_config.morenRuKuMaDanFenShu = this->getConfigInt(obj);});
  44. parsefUNS.insert("A2000216",[this](const QJsonObject & obj){this->_config.buDingZhongXianZhiFanWei = this->getConfigpAIR(obj);});
  45. parsefUNS.insert("A2000217",[this](const QJsonObject & obj){this->_config.daBaoZhuangDaYinXiangDanFenShu = this->getConfigInt(obj);});
  46. parsefUNS.insert("A2000218",[this](const QJsonObject & obj){this->_config.daBaoZhuangMaoZhongFanWei = this->getConfigInt(obj);});
  47. parsefUNS.insert("A2000219",[this](const QJsonObject & obj){this->_config.ziDongDaBaoXiangZhongFanWei = this->getConfigInt(obj);});
  48. parsefUNS.insert("A2000220",[this](const QJsonObject & obj){this->_config.zidongDaBaoMaoZhongFanWei = this->getConfigInt(obj);});
  49. parsefUNS.insert("A3000300",[this](const QJsonObject & obj){this->_config.morenDaYinHuaMaDan = this->getConfigInt(obj);});
  50. parsefUNS.insert("A3000301",[this](const QJsonObject & obj){this->_config.morenXiaoShouXianShiJinE = this->getConfigInt(obj);});
  51. parsefUNS.insert("A3000302",[this](const QJsonObject & obj){this->_config.morenDayinXiaoShouMinXidan = this->getConfigInt(obj);});
  52. parsefUNS.insert("A3000303",[this](const QJsonObject & obj){this->_config.morenDaYinXIaoShouDan = this->getConfigInt(obj);});
  53. parsefUNS.insert("A3000304",[this](const QJsonObject & obj){this->_config.morenXianShiQianKuan = this->getConfigInt(obj);});
  54. parsefUNS.insert("A3000305",[this](const QJsonObject & obj){this->_config.xiaoShouEJingDu = this->getConfigInt(obj);});
  55. // parsefUNS.insert("A4000400",[this](const QJsonObject & obj){this->_config.diys = this->getDiys(obj);});
  56. //TODO:http://doc.vanlai.net:3001/web/#/1?page_id=57 补全剩下
  57. //http://erp.itwsw.cn/#/packageCon
  58. }
  59. QList<DIYPackConfig> RemotePackConfig::getDiys(const QJsonObject & data)
  60. {
  61. // TODO:
  62. QJsonArray value_array = data["value"].toArray();
  63. DIYPackConfig DTYConfig;
  64. QList<DIYPackConfig> DTYConfigList;
  65. for(int i = 0;i<value_array.size();i++){
  66. QJsonObject obj = value_array.at(i).toObject();
  67. DTYConfig.type = obj["packaging_type"].toInt();
  68. DTYConfig.danDianXiaXian = obj["danding_lower_limit"].toInt();
  69. DTYConfig.danDianShangXian = obj["danding_upper_limit"].toInt();
  70. DTYConfig.jingZhongXiaXian = obj["net_weight_lower_limit"].toInt();
  71. DTYConfig.jingZhongShangXian = obj["net_weight_upper_limit"].toInt();
  72. DTYConfigList.append(DTYConfig);
  73. }
  74. return DTYConfigList;
  75. }
  76. QList<POYPackConfig> RemotePackConfig::getPoys(const QJsonObject & data)
  77. {
  78. // TODO:
  79. QJsonArray value_array = data["value"].toArray();
  80. POYPackConfig POYConfig;
  81. QList<POYPackConfig> POYConfigList;
  82. for(int i = 0;i<value_array.size();i++){
  83. QJsonObject obj = value_array.at(i).toObject();
  84. POYConfig.type = obj["packaging_type"].toInt();
  85. POYConfig.jingZhongXiaXian = obj["net_weight_lower_limit"].toInt();
  86. POYConfig.jingZhongShangXian = obj["net_weight_upper_limit"].toInt();
  87. POYConfigList.append(POYConfig);
  88. }
  89. return POYConfigList;
  90. }
  91. void RemotePackConfig::refConfig()
  92. {
  93. getDdengji = false;
  94. GlobalInfo * glo = GlobalInfo::this_();
  95. if(glo->isNoLine()){
  96. auto dt = PQ::CacheFile::readFile("config.cache");
  97. auto obj = QJsonDocument::fromJson(dt).object();
  98. result(200,obj);
  99. getDdengji = true;
  100. dt = PQ::CacheFile::readFile("dengjiList.cache");
  101. obj = QJsonDocument::fromJson(dt).object();
  102. result(200,obj);
  103. }
  104. // _aid = QString::number(body["user_id"].toInt());
  105. // _token = body["access_token"].toString();
  106. _request.setUserToken(QString::number( glo->user().accountId) ,glo->user().acessToken);
  107. QString url = glo->config()->baseUrl+"/v1/configuration";
  108. qDebug() << url;
  109. _request.get(url);
  110. }
  111. void RemotePackConfig::result(int code, const QJsonObject & body)
  112. {
  113. int ecode = body.value("code").toInt(404);
  114. if(ecode != 200){
  115. emit configUpdateError(ecode,body.value("message").toString(""));
  116. return;
  117. }
  118. if(!getDdengji){
  119. PQ::CacheFile::writeFile("config.cache",QJsonDocument(body).toJson());
  120. QJsonArray object = body.value("data").toArray();
  121. for(int i = 0; i < object.size(); ++ i){
  122. QJsonObject obj = object.at(i).toObject();
  123. QString key = obj.value("key").toString();
  124. auto handle = parsefUNS.value(key,[](const QJsonObject &){});
  125. handle(obj);
  126. }
  127. emit configUpdate(_config);
  128. if(!GlobalInfo::this_()->isNoLine()){refDengJiList();}
  129. } else {
  130. // TODO: 解析等级列表
  131. PQ::CacheFile::writeFile("dengjiList.cache",QJsonDocument(body).toJson());
  132. QJsonArray object = body.value("data").toArray();
  133. DengJiConfigItem dengJiConfig;
  134. for(int i = 0; i<object.size();i++){
  135. QJsonObject obj = object.at(i).toObject();
  136. dengJiConfig.id = obj.value("level_id").toInt();
  137. dengJiConfig.value = obj.value("name").toString();
  138. dengJiConfig.isEnable = obj.value("is_disable").toBool();
  139. dengji.append(dengJiConfig);
  140. }
  141. emit dengJIConfigUp(dengji);
  142. refWarehouse();
  143. }
  144. }
  145. void RemotePackConfig::refWarehouse()
  146. {
  147. QString url = GlobalInfo::this_()->config()->baseUrl+"/v1/warehouse/list?is_disable=0&page=0&limit=999";
  148. _WareRequest.setUserToken(QString::number(GlobalInfo::this_()->user().accountId),GlobalInfo::this_()->user().acessToken);
  149. _WareRequest.get(url);
  150. }
  151. void RemotePackConfig::WareResult(int code,const QJsonObject & body){
  152. WarehouseConfig ware;
  153. if(code != 200){
  154. return;
  155. }
  156. QJsonArray warelist = body.value("data").toArray();
  157. for(int i = 0;i<warelist.size();i++){
  158. QJsonObject obj = warelist.at(i).toObject();
  159. ware.warehouse_id = obj.value("warehouse_id").toInt();
  160. ware.serial_number = obj.value("serial_number").toString();
  161. ware.name = obj.value("name").toString();
  162. ware.factory_id = obj.value("factory_id").toInt();
  163. ware.factory_name = obj.value("factory_name").toString();
  164. ware.remark = obj.value("remark").toString();
  165. ware.is_disable = obj.value("is_disable").toInt();
  166. ware.create_time = obj.value("create_time").toInt();
  167. ware.modified_time = obj.value("modified_time").toInt();
  168. Warehouse.append(ware);
  169. }
  170. emit wareConfigUp(Warehouse);
  171. }
  172. void RemotePackConfig::refDengJiList()
  173. {
  174. getDdengji = true;
  175. // todo: http://doc.vanlai.net:3001/web/#/1?page_id=35
  176. QString url = GlobalInfo::this_()->config()->baseUrl+"/v1/level/list";
  177. _request.setUserToken(QString::number(GlobalInfo::this_()->user().accountId),GlobalInfo::this_()->user().acessToken);
  178. _request.get(url);
  179. }
  180. bool RemotePackConfig::getConfigBool(const QJsonObject & data)
  181. {
  182. QJsonArray value_array = data.value("value").toArray();
  183. int vSize = value_array.size();
  184. QString select;
  185. for(int i = 0; i < vSize; ++i){
  186. QJsonValue value_content = value_array.at(i);
  187. if(value_content.isObject()){
  188. QJsonObject value_object = value_content.toObject();
  189. if(value_object.value("selected").toBool(false)){
  190. select = value_object.value("name").toString();
  191. }
  192. }
  193. }
  194. // select = select.trimmed();
  195. if(select.contains("是") || select.contains("yes",Qt::CaseInsensitive))
  196. return true;
  197. return false;
  198. }
  199. QStringList RemotePackConfig::getConfigStringList(const QJsonObject & data)
  200. {
  201. QJsonArray value_array = data.value("value").toArray();
  202. QStringList list;
  203. int vSize = value_array.size();
  204. for(int i = 0; i < vSize; ++i){
  205. QJsonValue value_content = value_array.at(i);
  206. if(value_content.isObject()){
  207. QJsonObject value_object = value_content.toObject();
  208. list.append(value_object.value("value").toString());
  209. }
  210. }
  211. return list;
  212. }
  213. int RemotePackConfig::getConfigInt(const QJsonObject & data)
  214. {
  215. QJsonArray value_array = data.value("value").toArray();
  216. int list;
  217. int vSize = value_array.size();
  218. for(int i = 0; i < vSize; ++i){
  219. QJsonValue value_content = value_array.at(i);
  220. if(value_content.isObject()){
  221. QJsonObject value_object = value_content.toObject();
  222. if(value_content.isObject()){
  223. QJsonObject value_object = value_content.toObject();
  224. if(value_object.value("selected").toBool(false)){
  225. list = value_object.value("value").toInt();
  226. }
  227. }
  228. }
  229. }
  230. return list;
  231. }
  232. QPair<int,int> RemotePackConfig::getConfigpAIR(const QJsonObject & data)
  233. {
  234. QJsonArray value_array = data.value("value").toArray();
  235. QPair<int,int> list;
  236. int vSize = value_array.size();
  237. bool frist = true;
  238. for(int i = 0; i < vSize; ++i){
  239. QJsonObject value_object = value_array.at(i).toObject();
  240. // if(value_object.value("selected").toBool(false)){
  241. if(frist) {
  242. list.first = value_object.value("value").toInt();
  243. frist = false;
  244. } else {
  245. list.second = value_object.value("value").toInt();
  246. }
  247. // }
  248. }
  249. return list;
  250. }
  251. QPair<int,int> RemotePackConfig::daBaoJingDu(const QJsonObject & data)
  252. {
  253. QJsonArray value_array = data.value("value").toArray();
  254. QPair<int,int> list;
  255. int vSize = value_array.size();
  256. bool frist = true;
  257. for(int i = 0; i < vSize; ++i){
  258. QJsonValue value_content = value_array.at(i);
  259. auto ary = value_content.toArray();
  260. for(int j = 0; j < ary.size(); ++j){
  261. QJsonObject value_object = ary.at(j).toObject();
  262. if(value_object.value("selected").toBool(false)){
  263. if(frist) {
  264. list.first = value_object.value("value").toInt();
  265. frist = false;
  266. } else {
  267. list.second = value_object.value("value").toInt();
  268. }
  269. }
  270. }
  271. }
  272. return list;
  273. }
  274. QList<double> RemotePackConfig::getConfigStringDouble(const QJsonObject & data)
  275. {
  276. QJsonArray value_array = data.value("value").toArray();
  277. QList<double> list;
  278. int vSize = value_array.size();
  279. for(int i = 0; i < vSize; ++i){
  280. QJsonValue value_content = value_array.at(i);
  281. if(value_content.isObject()){
  282. QJsonObject value_object = value_content.toObject();
  283. list.append(value_object.value("value").toDouble());
  284. }
  285. }
  286. return list;
  287. }
  288. QList<int> RemotePackConfig::getConfigStringInt(const QJsonObject & data)
  289. {
  290. QJsonArray value_array = data.value("value").toArray();
  291. QList<int> list;
  292. int vSize = value_array.size();
  293. for(int i = 0; i < vSize; ++i){
  294. QJsonValue value_content = value_array.at(i);
  295. if(value_content.isObject()){
  296. QJsonObject value_object = value_content.toObject();
  297. list.append(value_object.value("value").toInt());
  298. }
  299. }
  300. return list;
  301. }