#include "remotepackconfig.h" #include "globalinfo.h" RemotePackConfig::RemotePackConfig(QObject *parent) : QObject(parent) { connect(&_request,&HttpRequest::result,this,&RemotePackConfig::result); parsefUNS.insert("A1000100",[this](const QJsonObject & obj){this->_config.jitai = this->getConfigStringList(obj);}); parsefUNS.insert("A1000101",[this](const QJsonObject & obj){this->_config.dangchegongbanci = this->getConfigStringList(obj);}); parsefUNS.insert("A1000102",[this](const QJsonObject & obj){this->_config.daBaoGongBanCi = this->getConfigStringList(obj);}); parsefUNS.insert("A1000103",[this](const QJsonObject & obj){this->_config.xiangzhong = this->getConfigStringDouble(obj);}); parsefUNS.insert("A1000104",[this](const QJsonObject & obj){this->_config.tongZhong = this->getConfigStringDouble(obj);}); parsefUNS.insert("A1000105",[this](const QJsonObject & obj){this->_config.guanse = this->getConfigStringList(obj);}); parsefUNS.insert("A1000106",[this](const QJsonObject & obj){this->_config.nianxiang = this->getConfigStringList(obj);}); parsefUNS.insert("A1000107",[this](const QJsonObject & obj){this->_config.zhixiang = this->getConfigStringList(obj);}); parsefUNS.insert("A1000108",[this](const QJsonObject & obj){this->_config.mashu = this->getConfigStringInt(obj);}); parsefUNS.insert("A1000109",[this](const QJsonObject & obj){this->_config.cheZhong = this->getConfigStringList(obj);}); parsefUNS.insert("A1000110",[this](const QJsonObject & obj){this->_config.gangHao = this->getConfigStringList(obj);}); parsefUNS.insert("A1000111",[this](const QJsonObject & obj){this->_config.xiangHaoXianShiGuiZe = this->getConfigInt(obj);}); parsefUNS.insert("A1000112",[this](const QJsonObject & obj){this->_config.daBaoRuku = this->getConfigBool(obj);}); parsefUNS.insert("A1000113",[this](const QJsonObject & obj){this->_config.daBaoRiQiXianShiFangShi = this->getConfigInt(obj);}); parsefUNS.insert("A2000200",[this](const QJsonObject & obj){this->_config.ziDongDushu = this->getConfigBool(obj);}); parsefUNS.insert("A2000201",[this](const QJsonObject & obj){this->_config.buDingZhongDaBaoXianzhi = this->getConfigBool(obj);}); parsefUNS.insert("A2000202",[this](const QJsonObject & obj){this->_config.dingZhongDaBaoXianZhiKaiQi = this->getConfigBool(obj);}); parsefUNS.insert("A2000203",[this](const QJsonObject & obj){this->_config.jiTaiBangDingMaDan = this->getConfigBool(obj);}); parsefUNS.insert("A2000204",[this](const QJsonObject & obj){this->_config.morenTongZhongGUDing = this->getConfigBool(obj);}); parsefUNS.insert("A2000205",[this](const QJsonObject & obj){this->_config.morenXiandhiMaoZhong = this->getConfigBool(obj);}); parsefUNS.insert("A2000206",[this](const QJsonObject & obj){this->_config.morenDaYinRuKuMadan = this->getConfigBool(obj);}); parsefUNS.insert("A2000207",[this](const QJsonObject & obj){this->_config.morenBudingZhongMaoZhongXianZhi = this->getConfigBool(obj);}); parsefUNS.insert("A2000208",[this](const QJsonObject & obj){this->_config.daBaoZhuangLeiXingGuiZeKaiQi = this->getConfigBool(obj);}); parsefUNS.insert("A2000209",[this](const QJsonObject & obj){this->_config.daBaoZhuangMaoZhongXianZhiKaiQi = this->getConfigBool(obj);}); parsefUNS.insert("A2000210",[this](const QJsonObject & obj){this->_config.ziDongDaBaoKaiQi = this->getConfigBool(obj);}); parsefUNS.insert("A2000211",[this](const QJsonObject & obj){this->_config.pingBanZiDongTongBuShuJu = this->getConfigBool(obj);}); parsefUNS.insert("A2000212",[this](const QJsonObject & obj){ auto jingdu = this->daBaoJingDu(obj); this->_config.chengZhongJIngDu = jingdu.first; this->_config.chengZhongJingDuMode = jingdu.second; }); // parsefUNS.insert("A2000213",[this](const QJsonObject & obj){this->_config.buDingZhongTongShuFanWei = this->getConfigpAIR(obj);}); // parsefUNS.insert("A2000214",[this](const QJsonObject & obj){this->_config.dingZhongTongShuFanwei = this->getConfigpAIR(obj);}); //TODO:http://doc.vanlai.net:3001/web/#/1?page_id=57 补全剩下 //http://erp.itwsw.cn/#/packageCon } QList RemotePackConfig::getDiys(const QJsonObject & data) { // TODO: } QList RemotePackConfig::getPoys(const QJsonObject & data) { // TODO: } void RemotePackConfig::refConfig() { getDdengji = false; GlobalInfo * glo = GlobalInfo::this_(); // _aid = QString::number(body["user_id"].toInt()); // _token = body["access_token"].toString(); _request.setUserToken(QString::number( glo->user().accountId) ,glo->user().acessToken); QString url = glo->config().baseUrl + "/v1/configuration"; _request.get(url); } void RemotePackConfig::result(int code, const QJsonObject & body) { int ecode = body.value("code").toInt(404); if(ecode != 200){ emit configUpdateError(ecode,body.value("message").toString("")); return; } if(!getDdengji){ QJsonArray object = body.value("data").toArray(); for(int i = 0; i < object.size(); ++ i){ QJsonObject obj = object.at(i).toObject(); QString key = obj.value("key").toString(); auto handle = parsefUNS.value(key,[](const QJsonObject &){}); handle(obj); } emit configUpdate(_config); refDengJiList(); } else { // TODO: 解析等级列表 } } void RemotePackConfig::refDengJiList() { // todo: http://doc.vanlai.net:3001/web/#/1?page_id=35 } bool RemotePackConfig::getConfigBool(const QJsonObject & data) { QJsonArray value_array = data.value("value").toArray(); int vSize = value_array.size(); QString select; for(int i = 0; i < vSize; ++i){ QJsonValue value_content = value_array.at(i); if(value_content.isObject()){ QJsonObject value_object = value_content.toObject(); if(value_object.value("selected").toBool(false)){ select = value_object.value("name").toString(); } } } // select = select.trimmed(); if(select.contains("是") || select.contains("yes",Qt::CaseInsensitive)) return true; return false; } QStringList RemotePackConfig::getConfigStringList(const QJsonObject & data) { QJsonArray value_array = data.value("value").toArray(); QStringList list; int vSize = value_array.size(); for(int i = 0; i < vSize; ++i){ QJsonValue value_content = value_array.at(i); if(value_content.isObject()){ QJsonObject value_object = value_content.toObject(); list.append(value_object.value("value").toString()); } } return list; } int RemotePackConfig::getConfigInt(const QJsonObject & data) { QJsonArray value_array = data.value("value").toArray(); int list; int vSize = value_array.size(); for(int i = 0; i < vSize; ++i){ QJsonValue value_content = value_array.at(i); if(value_content.isObject()){ QJsonObject value_object = value_content.toObject(); if(value_content.isObject()){ QJsonObject value_object = value_content.toObject(); if(value_object.value("selected").toBool(false)){ list = value_object.value("value").toInt(); } } } } return list; } QPair getConfigpAIR(const QJsonObject & data) { QJsonArray value_array = data.value("value").toArray(); QPair list; int vSize = value_array.size(); bool frist = true; for(int i = 0; i < vSize; ++i){ QJsonObject value_object = value_array.at(i).toObject(); if(value_object.value("selected").toBool(false)){ if(frist) { list.first = value_object.value("value").toInt(); frist = false; } else { list.second = value_object.value("value").toInt(); } } } return list; } QPair RemotePackConfig::daBaoJingDu(const QJsonObject & data) { QJsonArray value_array = data.value("value").toArray(); QPair list; int vSize = value_array.size(); bool frist = true; for(int i = 0; i < vSize; ++i){ QJsonValue value_content = value_array.at(i); auto ary = value_content.toArray(); for(int j = 0; j < ary.size(); ++j){ QJsonObject value_object = ary.at(j).toObject(); if(value_object.value("selected").toBool(false)){ if(frist) { list.first = value_object.value("value").toInt(); frist = false; } else { list.second = value_object.value("value").toInt(); } } } } return list; } QList RemotePackConfig::getConfigStringDouble(const QJsonObject & data) { QJsonArray value_array = data.value("value").toArray(); QList list; int vSize = value_array.size(); for(int i = 0; i < vSize; ++i){ QJsonValue value_content = value_array.at(i); if(value_content.isObject()){ QJsonObject value_object = value_content.toObject(); list.append(value_object.value("value").toDouble()); } } return list; } QList RemotePackConfig::getConfigStringInt(const QJsonObject & data) { QJsonArray value_array = data.value("value").toArray(); QList list; int vSize = value_array.size(); for(int i = 0; i < vSize; ++i){ QJsonValue value_content = value_array.at(i); if(value_content.isObject()){ QJsonObject value_object = value_content.toObject(); list.append(value_object.value("value").toInt()); } } return list; }