• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            積木

            No sub title

              C++博客 :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
              140 Posts :: 1 Stories :: 11 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(1)

            我參與的團(tuán)隊(duì)

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            直接上代碼
              1 #include "stdafx.h"
              2 #include <fstream>
              3 #include "Json.h"
              4 
              5 #include "ShopLogic.h"
              6 #include "src/FileCsv/WebUrlConfig.h"
              7 #include "src/support/GlobalDefine.h"
              8 
              9 using namespace std;
             10 
             11 const char *g_pcszWebDataSaveFile = "shopWebData_";
             12 
             13 ///////////////////////////////////////////////////////////////////////////////
             14 /// class CShopData
             15 /// 
             16 CShopData *getShopData() {
             17     return ChaSingleton<CShopData>::singleton();
             18 }
             19 
             20 CShopData::CShopData() {
             21 
             22 }
             23 
             24 CShopData::~CShopData() {
             25 
             26 }
             27 
             28 /// 
             29 /// Add by (jacc.kim) [2014-10-16 17:01]
             30 /// 將從web下發(fā)的商品列表數(shù)據(jù)保存到本地配置中.注意:如果列表為空,則不保存,
             31 /// 同時(shí)舊有的本地?cái)?shù)據(jù)也不清空。
             32 /// 
             33 void CShopData::saveShopWebItems(const TShopWebDataVec &vecItems) {
             34     if (vecItems.empty()) {
             35         return ;
             36     }
             37     ShopWebDataLog("========================================================");
             38     ShopWebDataLog("準(zhǔn)備保存寶石商店數(shù)據(jù)到本地文件.");
             39     std::string strFileName("");
             40     this->generateWebDataSaveFileName(strFileName);
             41     ShopWebDataLog("保存數(shù)據(jù)文件名稱: %s", strFileName.c_str());
             42     ofstream fout;
             43     fout.open(strFileName.c_str());
             44     if (!fout.is_open()) {
             45         ShopWebDataLog("打開或創(chuàng)建文件失敗");
             46         return ;
             47     }
             48     Json::Value jRoot;
             49     Json::Value jArray;
             50     Json::Value jItem;
             51     Json::Value jHttpData;
             52     Json::Value jTreasureInfo;
             53     typedef Json::Value::Int        TJInt;
             54 
             55     CShopHttpDataTotal *pWebDataItem = NULL;
             56     const TShopWebDataVec::size_type nAmount = vecItems.size();
             57     for (TShopWebDataVec::size_type nIdx = 0; nIdx < nAmount; ++nIdx) {
             58         pWebDataItem = vecItems[nIdx];
             59         if (NULL == pWebDataItem) {
             60             continue ;
             61         }
             62         // 保存 網(wǎng)絡(luò)商店的數(shù)據(jù)(即:CShopHttpData) 數(shù)據(jù)
             63         jHttpData["pc_id"= pWebDataItem->httpData.pc_id.c_str();
             64         jHttpData["pc_name"= pWebDataItem->httpData.pc_name.c_str();
             65         jHttpData["pc_point"= (TJInt)pWebDataItem->httpData.pc_point;
             66         jHttpData["pc_type"= pWebDataItem->httpData.pc_type.c_str();
             67         jHttpData["pc_flag"= (TJInt)pWebDataItem->httpData.pc_flag;
             68         jHttpData["pc_credit_rate"= pWebDataItem->httpData.pc_credit_rate.c_str();
             69         jHttpData["pcc_price_usd"= pWebDataItem->httpData.pcc_price_usd.c_str();
             70         jHttpData["pcc_price_cfg"= pWebDataItem->httpData.pcc_price_cfg.c_str();
             71         jHttpData["pcc_memo"= pWebDataItem->httpData.pcc_memo.c_str();
             72         jHttpData["pc_free_point"= (TJInt)pWebDataItem->httpData.pc_free_point;
             73         jHttpData["ppc_end_time"= pWebDataItem->httpData.ppc_end_time.c_str();
             74 #ifdef ORDERS_PROMOTIONS
             75         jHttpData["pcc_presen_count"= (TJInt)pWebDataItem->httpData.pcc_presen_count;
             76 #else //#ifdef ORDERS_PROMOTIONS
             77         jHttpData["pcc_presen_count"= (TJInt)0;
             78 #endif//#ifdef ORDERS_PROMOTIONS
             79 
             80         // 保存 商城財(cái)產(chǎn)相關(guān)信息(即:TreasureInfo) 數(shù)據(jù)
             81         jTreasureInfo["nIconStatus"= (TJInt)pWebDataItem->localData.nIconStatus;
             82         jTreasureInfo["nTextStatus"= (TJInt)pWebDataItem->localData.nTextStatus;
             83         jTreasureInfo["nBuyType"= (TJInt)pWebDataItem->localData.nBuyType;
             84         jTreasureInfo["nCostType"= (TJInt)pWebDataItem->localData.nCostType;
             85         jTreasureInfo["nBuyNumber"= (TJInt)pWebDataItem->localData.nBuyNumber;
             86         jTreasureInfo["nCostNumber"= (TJInt)pWebDataItem->localData.nCostNumber;
             87         jTreasureInfo["nCapacityPercentage"= (TJInt)pWebDataItem->localData.nCapacityPercentage;
             88         jTreasureInfo["strName"= pWebDataItem->localData.strName.c_str();
             89         jTreasureInfo["strTitleTid"= pWebDataItem->localData.strTitleTid.c_str();
             90         jTreasureInfo["strIconAddress"= pWebDataItem->localData.strIconAddress.c_str();
             91         jTreasureInfo["nCooling"= (TJInt)pWebDataItem->localData.nCooling;
             92 
             93         jItem["CShopHttpData"= jHttpData;
             94         jItem["TreasureInfo"= jTreasureInfo;
             95         jArray.append(jItem);
             96     }
             97     ShopWebDataLog("待保存的寶石商店數(shù)據(jù): %d 條, 實(shí)際保存成功: %d 條"
             98         , static_cast<int>(nAmount), static_cast<int>(jArray.size()));
             99     jRoot["CShopHttpDataTotal"= jArray;
            100     fout << jRoot.toStyledString() << endl;
            101     fout.close();
            102 }
            103 
            104 /// 
            105 /// Add by (jacc.kim) [2014-10-16 17:02]
            106 /// 從本地加載web商品列表數(shù)據(jù).并返回.注意:剛進(jìn)入接口內(nèi)部時(shí),參數(shù)列表必被清空.
            107 /// 然后再?gòu)谋镜匚募屑虞d.
            108 /// 
            109 void CShopData::getLocalShopWebItems(TShopWebDataVec &vecOutItems) {
            110     ShopWebDataLog("--------------------------------------------------------");
            111     ShopWebDataLog("準(zhǔn)備從本地提取數(shù)據(jù)寶石商店數(shù)據(jù).");
            112     vecOutItems.clear();
            113     std::string strFileName("");
            114     this->generateWebDataSaveFileName(strFileName);
            115     ShopWebDataLog("本地?cái)?shù)據(jù)源文件名稱: %s", strFileName.c_str());
            116     ifstream fin;
            117     fin.open(strFileName.c_str());
            118     if (!fin.is_open()) {
            119         ShopWebDataLog("本地?cái)?shù)據(jù)源文件不存在或已損壞,打開失敗");
            120         return ;
            121     }
            122     Json::Reader jReader;
            123     Json::Value jRoot;
            124     Json::Value jHttpData;
            125     Json::Value jTreasureInfo;
            126     if (!jReader.parse(fin, jRoot)) {
            127         ShopWebDataLog("本地?cái)?shù)據(jù)源文件糟破壞,解析失敗");
            128         return ;
            129     }
            130     CShopHttpDataTotal *pWebDataItem = NULL;
            131     const int nAmount = static_cast<int>(jRoot["CShopHttpDataTotal"].size());
            132     for (int nIdx = 0; nIdx < nAmount; ++nIdx) {
            133         pWebDataItem = new CShopHttpDataTotal();
            134         if (NULL == pWebDataItem) {
            135             break ;
            136         }
            137         jHttpData = jRoot["CShopHttpDataTotal"][nIdx]["CShopHttpData"];
            138         pWebDataItem->httpData.pc_id            = jHttpData["pc_id"].asString();
            139         pWebDataItem->httpData.pc_name          = jHttpData["pc_name"].asString();
            140         pWebDataItem->httpData.pc_point         = jHttpData["pc_point"].asInt();
            141         pWebDataItem->httpData.pc_type          = jHttpData["pc_type"].asString();
            142         pWebDataItem->httpData.pc_flag          = jHttpData["pc_flag"].asInt();
            143         pWebDataItem->httpData.pc_credit_rate   = jHttpData["pc_credit_rate"].asString();
            144         pWebDataItem->httpData.pcc_price_usd    = jHttpData["pcc_price_usd"].asString();
            145         pWebDataItem->httpData.pcc_price_cfg    = jHttpData["pcc_price_cfg"].asString();
            146         pWebDataItem->httpData.pcc_memo         = jHttpData["pcc_memo"].asString();
            147         pWebDataItem->httpData.pc_free_point    = jHttpData["pc_free_point"].asInt();
            148         pWebDataItem->httpData.ppc_end_time     = jHttpData["ppc_end_time"].asString();
            149 #ifdef ORDERS_PROMOTIONS
            150         pWebDataItem->httpData.pcc_presen_count = jHttpData["pcc_presen_count"].asInt();
            151 #else //#ifdef ORDERS_PROMOTIONS
            152         // do nothing here..
            153 #endif//#ifdef ORDERS_PROMOTIONS
            154 
            155         jTreasureInfo = jRoot["CShopHttpDataTotal"][nIdx]["TreasureInfo"];
            156         pWebDataItem->localData.nIconStatus         = jTreasureInfo["nIconStatus"].asInt();
            157         pWebDataItem->localData.nTextStatus         = jTreasureInfo["nTextStatus"].asInt();
            158         pWebDataItem->localData.nBuyType            = jTreasureInfo["nBuyType"].asInt();
            159         pWebDataItem->localData.nCostType           = jTreasureInfo["nCostType"].asInt();
            160         pWebDataItem->localData.nBuyNumber          = jTreasureInfo["nBuyNumber"].asInt();
            161         pWebDataItem->localData.nCostNumber         = jTreasureInfo["nCostNumber"].asInt();
            162         pWebDataItem->localData.nCapacityPercentage = jTreasureInfo["nCapacityPercentage"].asInt();
            163         pWebDataItem->localData.strName             = jTreasureInfo["strName"].asString();
            164         pWebDataItem->localData.strTitleTid         = jTreasureInfo["strTitleTid"].asString();
            165         pWebDataItem->localData.strIconAddress      = jTreasureInfo["strIconAddress"].asString();
            166         pWebDataItem->localData.nCooling            = jTreasureInfo["nCooling"].asInt();
            167 
            168         vecOutItems.push_back(pWebDataItem);
            169     }
            170     ShopWebDataLog("本地?cái)?shù)據(jù)源共: %d 條數(shù)據(jù), 實(shí)際解析成功: %d 條"
            171         , nAmount, static_cast<int>(vecOutItems.size()));
            172     fin.close();
            173 }
            174 
            175 void CShopData::generateWebDataSaveFileName(std::string &strFileName) {
            176     strFileName = g_pcszWebDataSaveFile;
            177     CWebUrlConfig *pUrlCfg = CWebUrlConfigInstance::singleton();
            178     std::string strGameId = pUrlCfg->getWebUrlAddress("gameid");
            179     strFileName = strFileName + strGameId + ".json";
            180 }


            posted on 2014-10-21 09:49 Jacc.Kim 閱讀(3622) 評(píng)論(0)  編輯 收藏 引用 所屬分類: VC / C++
            影音先锋女人AV鲁色资源网久久 | 国内精品久久久久| 久久精品亚洲精品国产色婷 | 精品久久久久久中文字幕| 精品久久久久久亚洲精品 | 香蕉久久影院| 亚洲AV无码久久寂寞少妇| 国产精品对白刺激久久久| 国产三级观看久久| 亚洲日韩欧美一区久久久久我| 一本综合久久国产二区| 国产精品久久网| 久久精品日日躁夜夜躁欧美| 久久这里只有精品首页| 香蕉久久av一区二区三区| 久久伊人五月天论坛| 久久精品国产福利国产秒| 国内高清久久久久久| 国产一区二区三精品久久久无广告| 成人午夜精品无码区久久| 久久久久综合中文字幕| 久久无码av三级| 久久精品人人做人人爽电影蜜月| 婷婷久久综合九色综合绿巨人| 久久综合丁香激情久久| 国产亚洲精久久久久久无码| 国产欧美久久久精品影院| 精品久久久久中文字| 香蕉久久一区二区不卡无毒影院| 免费精品久久久久久中文字幕| 久久综合给合久久狠狠狠97色69| 国产精品久久久久久久app| 久久人人爽人人精品视频| 99久久国产综合精品五月天喷水| www.久久热.com| AV狠狠色丁香婷婷综合久久| 欧美一区二区三区久久综| 欧洲人妻丰满av无码久久不卡| 精品熟女少妇a∨免费久久| 久久不见久久见免费视频7| 少妇精品久久久一区二区三区|