#include "remotepackconfig.h" #include "globalinfo.h" #include #include RemotePackConfig::RemotePackConfig(QObject *parent) : QObject(parent) { connect(&_request,&HttpRequest::result,this,&RemotePackConfig::result); connect(&_WareRequest,&HttpRequest::result,this,&RemotePackConfig::WareResult); 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("A1000114",[this](const QJsonObject & obj){this->_config.pinZhong = this->getConfigStringList(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);}); parsefUNS.insert("A2000215",[this](const QJsonObject & obj){this->_config.morenRuKuMaDanFenShu = this->getConfigInt(obj);}); parsefUNS.insert("A2000216",[this](const QJsonObject & obj){this->_config.buDingZhongXianZhiFanWei = this->getConfigpAIR(obj);}); parsefUNS.insert("A2000217",[this](const QJsonObject & obj){this->_config.daBaoZhuangDaYinXiangDanFenShu = this->getConfigInt(obj);}); parsefUNS.insert("A2000218",[this](const QJsonObject & obj){this->_config.daBaoZhuangMaoZhongFanWei = this->getConfigInt(obj);}); parsefUNS.insert("A2000219",[this](const QJsonObject & obj){this->_config.ziDongDaBaoXiangZhongFanWei = this->getConfigInt(obj);}); parsefUNS.insert("A2000220",[this](const QJsonObject & obj){this->_config.zidongDaBaoMaoZhongFanWei = this->getConfigInt(obj);}); parsefUNS.insert("A3000300",[this](const QJsonObject & obj){this->_config.morenDaYinHuaMaDan = this->getConfigInt(obj);}); parsefUNS.insert("A3000301",[this](const QJsonObject & obj){this->_config.morenXiaoShouXianShiJinE = this->getConfigInt(obj);}); parsefUNS.insert("A3000302",[this](const QJsonObject & obj){this->_config.morenDayinXiaoShouMinXidan = this->getConfigInt(obj);}); parsefUNS.insert("A3000303",[this](const QJsonObject & obj){this->_config.morenDaYinXIaoShouDan = this->getConfigInt(obj);}); parsefUNS.insert("A3000304",[this](const QJsonObject & obj){this->_config.morenXianShiQianKuan = this->getConfigInt(obj);}); parsefUNS.insert("A3000305",[this](const QJsonObject & obj){this->_config.xiaoShouEJingDu = this->getConfigInt(obj);}); // parsefUNS.insert("A4000400",[this](const QJsonObject & obj){this->_config.diys = this->getDiys(obj);}); //TODO:http://doc.vanlai.net:3001/web/#/1?page_id=57 补全剩下 //http://erp.itwsw.cn/#/packageCon } QList RemotePackConfig::getDiys(const QJsonObject & data) { // TODO: QJsonArray value_array = data["value"].toArray(); DIYPackConfig DTYConfig; QList DTYConfigList; for(int i = 0;i RemotePackConfig::getPoys(const QJsonObject & data) { // TODO: QJsonArray value_array = data["value"].toArray(); POYPackConfig POYConfig; QList POYConfigList; for(int i = 0;iisNoLine()){ auto dt = PQ::CacheFile::readFile("config.cache"); auto obj = QJsonDocument::fromJson(dt).object(); result(200,obj); getDdengji = true; dt = PQ::CacheFile::readFile("dengjiList.cache"); obj = QJsonDocument::fromJson(dt).object(); result(200,obj); } // _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"; qDebug() << url; _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){ PQ::CacheFile::writeFile("config.cache",QJsonDocument(body).toJson()); 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); if(!GlobalInfo::this_()->isNoLine()){refDengJiList();} } else { // TODO: 解析等级列表 PQ::CacheFile::writeFile("dengjiList.cache",QJsonDocument(body).toJson()); QJsonArray object = body.value("data").toArray(); DengJiConfigItem dengJiConfig; for(int i = 0; iconfig()->baseUrl+"/v1/warehouse/list?is_disable=0&page=0&limit=999"; _WareRequest.setUserToken(QString::number(GlobalInfo::this_()->user().accountId),GlobalInfo::this_()->user().acessToken); _WareRequest.get(url); } void RemotePackConfig::WareResult(int code,const QJsonObject & body){ WarehouseConfig ware; if(code != 200){ return; } QJsonArray warelist = body.value("data").toArray(); for(int i = 0;iconfig()->baseUrl+"/v1/level/list"; _request.setUserToken(QString::number(GlobalInfo::this_()->user().accountId),GlobalInfo::this_()->user().acessToken); _request.get(url); } 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 RemotePackConfig::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; }