• <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++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              140 Posts :: 1 Stories :: 11 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(1)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            直接上代碼
              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下發的商品列表數據保存到本地配置中.注意:如果列表為空,則不保存,
             31 /// 同時舊有的本地數據也不清空。
             32 /// 
             33 void CShopData::saveShopWebItems(const TShopWebDataVec &vecItems) {
             34     if (vecItems.empty()) {
             35         return ;
             36     }
             37     ShopWebDataLog("========================================================");
             38     ShopWebDataLog("準備保存寶石商店數據到本地文件.");
             39     std::string strFileName("");
             40     this->generateWebDataSaveFileName(strFileName);
             41     ShopWebDataLog("保存數據文件名稱: %s", strFileName.c_str());
             42     ofstream fout;
             43     fout.open(strFileName.c_str());
             44     if (!fout.is_open()) {
             45         ShopWebDataLog("打開或創建文件失敗");
             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         // 保存 網絡商店的數據(即:CShopHttpData) 數據
             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         // 保存 商城財產相關信息(即:TreasureInfo) 數據
             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("待保存的寶石商店數據: %d 條, 實際保存成功: %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商品列表數據.并返回.注意:剛進入接口內部時,參數列表必被清空.
            107 /// 然后再從本地文件中加載.
            108 /// 
            109 void CShopData::getLocalShopWebItems(TShopWebDataVec &vecOutItems) {
            110     ShopWebDataLog("--------------------------------------------------------");
            111     ShopWebDataLog("準備從本地提取數據寶石商店數據.");
            112     vecOutItems.clear();
            113     std::string strFileName("");
            114     this->generateWebDataSaveFileName(strFileName);
            115     ShopWebDataLog("本地數據源文件名稱: %s", strFileName.c_str());
            116     ifstream fin;
            117     fin.open(strFileName.c_str());
            118     if (!fin.is_open()) {
            119         ShopWebDataLog("本地數據源文件不存在或已損壞,打開失敗");
            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("本地數據源文件糟破壞,解析失敗");
            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("本地數據源共: %d 條數據, 實際解析成功: %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 閱讀(3606) 評論(0)  編輯 收藏 引用 所屬分類: VC / C++
            久久久久久久亚洲精品| 久久精品国产亚洲AV麻豆网站| 成人精品一区二区久久久| 久久国产免费| 亚洲中文久久精品无码| 国产精品久久久天天影视| 久久久精品国产Sm最大网站| 亚洲αv久久久噜噜噜噜噜| 久久精品中文字幕久久| 亚洲国产天堂久久久久久| 精品久久无码中文字幕| 久久综合五月丁香久久激情| AAA级久久久精品无码片| 久久午夜福利电影| 国产午夜久久影院| 久久成人国产精品免费软件| 久久久国产精品| 久久99热国产这有精品| 婷婷五月深深久久精品| 思思久久99热免费精品6| 2020最新久久久视精品爱| 久久丫精品国产亚洲av不卡| 久久无码人妻精品一区二区三区 | 亚洲欧美精品一区久久中文字幕| 久久天天躁狠狠躁夜夜avapp| 欧洲国产伦久久久久久久| 国产激情久久久久影院老熟女| 久久精品国产亚洲AV无码偷窥| 久久久久无码国产精品不卡| 久久亚洲高清观看| 国产精品久久影院| 久久伊人精品青青草原高清| 天天爽天天狠久久久综合麻豆| 久久精品人人做人人爽电影 | 无码人妻久久一区二区三区免费| 亚洲va久久久久| 亚洲国产成人精品91久久久 | 久久天天躁狠狠躁夜夜躁2014| 色8激情欧美成人久久综合电| 久久er国产精品免费观看8| 国产亚州精品女人久久久久久|