Commit f10cf669 by guanghui.cui

增加异常处理

parent f7536466
...@@ -69,6 +69,60 @@ JsonModule::~JsonModule() ...@@ -69,6 +69,60 @@ JsonModule::~JsonModule()
} }
const char* GetJsonStringSafe(rapidjson::Value& obj,const char* key)
{
if(obj.HasMember(key)){
rapidjson::Value& vObj = obj[key];
if(vObj.IsString()){
return vObj.GetString();
}
}
return "";
}
int GetJsonIntSafe(rapidjson::Value& obj,const char* key)
{
if(obj.HasMember(key)){
rapidjson::Value& vObj = obj[key];
if(vObj.IsInt()){
return vObj.GetInt();
}
}
return 0;
}
void JsonModule::jsonTest()
{
std::string json="{\"title\":\"PLAYER INFO\",\"num\":null,\"players\":[{ \"id\":123,\"name\":\"test\"}]}";
rapidjson::Document document; // 定义一个Document对象
document.Parse(json.data()); // 解析,Parse()无返回值,也不会抛异常
if (document.HasParseError()) // 通过HasParseError()来判断解析是否成功
{
// 可通过GetParseError()取得出错代码,
// 注意GetParseError()返回的是一个rapidjson::ParseErrorCode类型的枚举值
// 使用函数rapidjson::GetParseError_En()得到错误码的字符串说明,这里的En为English简写
// 函数GetErrorOffset()返回出错发生的位置
LOG(ERROR)<<"JSON parse error:"<<document.GetParseError()<<":"<<document.GetErrorOffset();
}
else
{
rapidjson::Value& vTitle = document["title"];
rapidjson::Value& vNum = document["num"];
LOG(INFO)<<"title:"<<GetJsonStringSafe(document,"title");
LOG(INFO)<<"num:"<<GetJsonStringSafe(document,"num");
rapidjson::Value& vPlayers = document["players"];
if(vPlayers.IsArray())
{
for(unsigned int i=0;i<vPlayers.Size();i++){
rapidjson::Value& players_obj = vPlayers[i];
LOG(INFO)<<"id:"<<GetJsonStringSafe(players_obj,"id");
LOG(INFO)<<"name:"<<GetJsonStringSafe(players_obj,"name");
}
}
}
}
bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order) bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order)
{ {
rapidjson::Document document; // 定义一个Document对象 rapidjson::Document document; // 定义一个Document对象
...@@ -92,145 +146,85 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order) ...@@ -92,145 +146,85 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order)
order.offline_bonus=offlinePoints.GetBool(); order.offline_bonus=offlinePoints.GetBool();
} }
GetJsonStringSafe(document,"token");
rapidjson::Value& token = document["token"]; GetJsonStringSafe(document,"ver");
token.GetString();
rapidjson::Value& ver = document["ver"];
ver.GetInt();
//配送信息 //配送信息
if(document.HasMember("delivery"))
{ {
rapidjson::Value& delivery_obj = document["delivery"]; rapidjson::Value& delivery_obj = document["delivery"];
if(delivery_obj.IsObject()) if(delivery_obj.IsObject())
{ {
if(delivery_obj.HasMember("customerAddress")) order.customerInfo.address=GetJsonStringSafe(delivery_obj,"customerAddress");
{ order.customerInfo.name=GetJsonStringSafe(delivery_obj,"customerName");
rapidjson::Value& customerAddress = delivery_obj["customerAddress"]; order.customerInfo.phone=GetJsonStringSafe(delivery_obj,"customerPhone");
order.customerInfo.address=customerAddress.GetString(); order.delivery_time=GetJsonStringSafe(delivery_obj,"deliveryTime");
} order.deliveryInfo.driver_name=GetJsonStringSafe(delivery_obj,"name");
if(delivery_obj.HasMember("customerName")) order.deliveryInfo.driver_phone=GetJsonStringSafe(delivery_obj,"phone");
{ order.deliveryInfo.type=GetJsonStringSafe(delivery_obj,"type");
rapidjson::Value& customerName = delivery_obj["customerName"];
order.customerInfo.name = customerName.GetString();
}
if(delivery_obj.HasMember("customerPhone"))
{
rapidjson::Value& customerPhone = delivery_obj["customerPhone"];
order.customerInfo.phone = customerPhone.GetString();
}
if(delivery_obj.HasMember("deliveryTime"))
{
rapidjson::Value& deliveryTime = delivery_obj["deliveryTime"];
order.delivery_time = deliveryTime.GetString();
}
if(delivery_obj.HasMember("name"))
{
rapidjson::Value& name = delivery_obj["name"];
order.deliveryInfo.driver_name = name.GetString();
}
if(delivery_obj.HasMember("phone"))
{
rapidjson::Value& phone = delivery_obj["phone"];
order.deliveryInfo.driver_phone = phone.GetString();
}
if(delivery_obj.HasMember("type"))
{
rapidjson::Value& type = delivery_obj["type"];
order.deliveryInfo.type = type.GetString();
}
} }
} }
//发票信息 //发票信息
if(document.HasMember("invoice"))
{ {
rapidjson::Value& invoice_obj = document["invoice"]; rapidjson::Value& invoice_obj = document["invoice"];
if(invoice_obj.IsObject()) if(invoice_obj.IsObject())
{ {
if(invoice_obj.HasMember("companyName")) GetJsonStringSafe(invoice_obj,"companyName");
{ GetJsonStringSafe(invoice_obj,"taxNum");
rapidjson::Value& companyName = invoice_obj["companyName"]; GetJsonStringSafe(invoice_obj,"title");
companyName.GetString(); order.invoice_pickup_code = GetJsonStringSafe(invoice_obj,"transNum");
}
if(invoice_obj.HasMember("invoiceType")) GetJsonIntSafe(invoice_obj,"invoiceType");
{ }
rapidjson::Value& invoiceType = invoice_obj["invoiceType"];
invoiceType.GetInt();
}
if(invoice_obj.HasMember("taxNum"))
{
rapidjson::Value& taxNum = invoice_obj["taxNum"];
taxNum.GetString();
}
if(invoice_obj.HasMember("title"))
{
rapidjson::Value& title = invoice_obj["title"];
title.GetString();
}
if(invoice_obj.HasMember("transNum"))
{
rapidjson::Value& transNum = invoice_obj["transNum"];
order.invoice_pickup_code = transNum.GetString();
}
}
} }
//订单内容 //订单内容
{ {
rapidjson::Value& orderContent_obj = document["orderContent"]; rapidjson::Value& orderContent_obj = document["orderContent"];
rapidjson::Value& createTime = orderContent_obj["createTime"]; order.create_time = GetJsonStringSafe(orderContent_obj,"createTime");
order.create_time = createTime.GetString();
//用户信息 //用户信息
//TODO 顾客信息为数组 因接口改版目前只有一个顾客信息 //TODO 顾客信息为数组 因接口改版目前只有一个顾客信息
rapidjson::Value& customer_array = orderContent_obj["customer"]; if(orderContent_obj.HasMember("customer"))
if(customer_array.IsArray())
{ {
for(unsigned int i=0;i<customer_array.Size();i++){ rapidjson::Value& customer_array = orderContent_obj["customer"];
rapidjson::Value& customer_obj = customer_array[i]; if(customer_array.IsArray())
{
rapidjson::Value& accountId = customer_obj["accountId"]; for(unsigned int i=0;i<customer_array.Size();i++){
order.customerInfo.account = accountId.GetString(); rapidjson::Value& customer_obj = customer_array[i];
rapidjson::Value& accountType= customer_obj["accountType"];
order.customerInfo.account_type = atoi(accountType.GetString());
rapidjson::Value& level = customer_obj["level"];
order.customerInfo.account_level = level.GetString();
order.customerInfo.account = GetJsonStringSafe(customer_obj,"accountId");
order.customerInfo.account_type = atoi(GetJsonStringSafe(customer_obj,"accountType"));
order.customerInfo.account_level = GetJsonStringSafe(customer_obj,"level");
}
} }
} }
rapidjson::Value& deliveryFee = orderContent_obj["deliveryFee"]; order.delivery_price = GetJsonIntSafe(orderContent_obj,"deliveryFee");
order.delivery_price = deliveryFee.GetInt();
//订单信息 //订单信息
if(orderContent_obj.HasMember("orders"))
{ {
rapidjson::Value& orders_obj = orderContent_obj["orders"]; rapidjson::Value& orders_obj = orderContent_obj["orders"];
rapidjson::Value& deliveryStatus = orders_obj["deliveryStatus"]; order.deliveryInfo.status = atoi(GetJsonStringSafe(orders_obj,"deliveryStatus"));
order.deliveryInfo.status = atoi(deliveryStatus.GetString()); order.deliveryInfo.status_desc = GetJsonStringSafe(orders_obj,"deliveryStatusDesc");
rapidjson::Value& deliveryStatusDesc = orders_obj["deliveryStatusDesc"]; order.order_id = GetJsonStringSafe(orders_obj,"orderId");
order.deliveryInfo.status_desc = deliveryStatusDesc.GetString(); order.pickup_code= GetJsonStringSafe(orders_obj,"pickupCode");
order.pickup_point = GetJsonStringSafe(orders_obj,"pickupPoint");
rapidjson::Value& orderId = orders_obj["orderId"];
order.order_id = orderId.GetString(); GetJsonStringSafe(orders_obj,"remark");
rapidjson::Value& pickupCode = orders_obj["pickupCode"];
order.pickup_code= pickupCode.GetString(); order.status = atoi(GetJsonStringSafe(orders_obj,"status"));
rapidjson::Value& pickupPoint = orders_obj["pickupPoint"];
order.pickup_point = pickupPoint.GetString();
rapidjson::Value& remark = orders_obj["remark"];
remark.GetString();
rapidjson::Value& status = orders_obj["status"];
order.status = atoi(status.GetString());
order.ods_status=order.status; order.ods_status=order.status;
rapidjson::Value& statusDesc = orders_obj["statusDesc"];
order.status_desc = statusDesc.GetString(); order.status_desc = GetJsonStringSafe(orders_obj,"statusDesc");
//订单商品 //订单商品
if(orders_obj.HasMember("products"))
{ {
rapidjson::Value& products_array = orders_obj["products"]; rapidjson::Value& products_array = orders_obj["products"];
if(products_array.IsArray()) if(products_array.IsArray())
...@@ -240,34 +234,18 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order) ...@@ -240,34 +234,18 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order)
productAttr structProduct; productAttr structProduct;
rapidjson::Value& attributes = product_obj["attributes"]; structProduct.pro.attributes = GetJsonStringSafe(product_obj,"attributes");
structProduct.pro.attributes = attributes.GetString(); structProduct.pro.combo_id = GetJsonStringSafe(product_obj,"catgId");
structProduct.pro.bom_id = GetJsonStringSafe(product_obj,"groupIndex");
rapidjson::Value& catgId= product_obj["catgId"]; structProduct.pro.name = GetJsonStringSafe(product_obj,"name");
structProduct.pro.combo_id = catgId.GetString(); structProduct.pro.price = GetJsonIntSafe(product_obj,"price");
GetJsonStringSafe(product_obj,"productType");
rapidjson::Value& groupIndex = product_obj["groupIndex"]; structProduct.pro.qty = GetJsonIntSafe(product_obj,"qty");
structProduct.pro.bom_id = groupIndex.GetString(); structProduct.pro.sku = GetJsonStringSafe(product_obj,"sku");
structProduct.pro.source = GetJsonStringSafe(product_obj,"source");
rapidjson::Value& name = product_obj["name"];
structProduct.pro.name = name.GetString();
rapidjson::Value& price= product_obj["price"];
structProduct.pro.price = price.GetInt();
rapidjson::Value& productType = product_obj["productType"];
productType.GetString();
rapidjson::Value& qty = product_obj["qty"];
structProduct.pro.qty = qty.GetInt();
rapidjson::Value& sku= product_obj["sku"];
structProduct.pro.sku = sku.GetString();
rapidjson::Value& source = product_obj["source"];
structProduct.pro.source = source.GetString();
//子商品信息 //子商品信息
if(product_obj.HasMember("specs"))
{ {
rapidjson::Value& specs_array = product_obj["specs"]; rapidjson::Value& specs_array = product_obj["specs"];
if(specs_array.IsArray()) if(specs_array.IsArray())
...@@ -276,18 +254,11 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order) ...@@ -276,18 +254,11 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order)
rapidjson::Value& specs_obj = specs_array[i]; rapidjson::Value& specs_obj = specs_array[i];
productSpec structProductSpec; productSpec structProductSpec;
structProductSpec.name = GetJsonStringSafe(specs_obj,"name");
structProductSpec.price = GetJsonIntSafe(specs_obj,"price");
structProductSpec.qty = GetJsonIntSafe(specs_obj,"qty");
structProductSpec.sku = GetJsonStringSafe(specs_obj,"sku");
rapidjson::Value& name = specs_obj["name"];
structProductSpec.name = name.GetString();
rapidjson::Value& price= specs_obj["price"];
structProductSpec.price = price.GetInt();
rapidjson::Value& qty = specs_obj["qty"];
structProductSpec.qty = qty.GetInt();
rapidjson::Value& sku = specs_obj["sku"];
structProductSpec.sku = sku.GetString();
structProduct.vecSpec.push_back(structProductSpec); structProduct.vecSpec.push_back(structProductSpec);
} }
} }
...@@ -298,8 +269,8 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order) ...@@ -298,8 +269,8 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order)
} }
} }
//支付信息 //支付信息
if(orderContent_obj.HasMember("payInfos"))
{ {
//TODO
//sumary未映射字段值 //sumary未映射字段值
rapidjson::Value& payInfos_array = orderContent_obj["payInfos"]; rapidjson::Value& payInfos_array = orderContent_obj["payInfos"];
if(payInfos_array.IsArray()) if(payInfos_array.IsArray())
...@@ -308,39 +279,30 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order) ...@@ -308,39 +279,30 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order)
rapidjson::Value& payInfos_obj = payInfos_array[i]; rapidjson::Value& payInfos_obj = payInfos_array[i];
paymentDetail detail; paymentDetail detail;
rapidjson::Value& amount= payInfos_obj["amount"]; detail.amount = GetJsonIntSafe(payInfos_obj,"amount");
detail.amount = amount.GetInt();
//支付类型需要拼接 channel+payType //支付类型需要拼接 channel+payType
rapidjson::Value& payType = payInfos_obj["payType"]; std::string _strType=order.channel+GetJsonStringSafe(payInfos_obj,"payType");
std::string _strType=order.channel+payType.GetString();
detail.type = atoi(_strType.data()); detail.type = atoi(_strType.data());
detail.trans_id = GetJsonStringSafe(payInfos_obj,"transNum");
rapidjson::Value& transNum = payInfos_obj["transNum"]; detail.account_id=GetJsonStringSafe(payInfos_obj,"accountId");
detail.trans_id = transNum.GetString();
if(payInfos_obj.HasMember("accountId")){
rapidjson::Value& accountId = payInfos_obj["accountId"];
if(!accountId.IsNull()){
detail.account_id=accountId.GetString();
}
}
order.payInfo.vecDetail.push_back(detail); order.payInfo.vecDetail.push_back(detail);
} }
} }
} }
rapidjson::Value& payType = orderContent_obj["payType"];
payType.GetString(); GetJsonStringSafe(orderContent_obj,"payType");
//积分信息 //积分信息
if(orderContent_obj.HasMember("points"))
{ {
rapidjson::Value& points_obj = orderContent_obj["points"]; rapidjson::Value& points_obj = orderContent_obj["points"];
if(points_obj.IsObject()) if(points_obj.IsObject())
{ {
rapidjson::Value& totalPoint= points_obj["totalPoint"]; order.bonusInfo.summary = std::to_string(GetJsonIntSafe(points_obj,"totalPoint"));
order.bonusInfo.summary = std::to_string(totalPoint.GetInt());
//积分信息详情 //积分信息详情
if(points_obj.HasMember("pointDetails"))
{ {
rapidjson::Value& pointDetails_array = points_obj["pointDetails"]; rapidjson::Value& pointDetails_array = points_obj["pointDetails"];
if(pointDetails_array.IsArray()) if(pointDetails_array.IsArray())
...@@ -349,26 +311,13 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order) ...@@ -349,26 +311,13 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order)
rapidjson::Value& pointDetails_obj = pointDetails_array[i]; rapidjson::Value& pointDetails_obj = pointDetails_array[i];
bonusDetail detail; bonusDetail detail;
rapidjson::Value& bomId= pointDetails_obj["bomId"]; GetJsonStringSafe(pointDetails_obj,"bomId");
bomId.GetString(); GetJsonStringSafe(pointDetails_obj,"comboId");
detail.desc = GetJsonStringSafe(pointDetails_obj,"desc");
rapidjson::Value& comboId = pointDetails_obj["comboId"]; GetJsonStringSafe(pointDetails_obj,"groupId");
comboId.GetString(); detail.point = GetJsonIntSafe(pointDetails_obj,"point");
detail.sku = GetJsonStringSafe(pointDetails_obj,"sku");
rapidjson::Value& desc = pointDetails_obj["desc"]; detail.type = atoi(GetJsonStringSafe(pointDetails_obj,"type"));
detail.desc = desc.GetString();
rapidjson::Value& groupId = pointDetails_obj["groupId"];
groupId.GetString();
rapidjson::Value& point = pointDetails_obj["point"];
detail.point = point.GetInt();
rapidjson::Value& sku = pointDetails_obj["sku"];
detail.sku = sku.GetString();
rapidjson::Value& type = pointDetails_obj["type"];
detail.type = atoi(type.GetString());
order.bonusInfo.vecDetail.push_back(detail); order.bonusInfo.vecDetail.push_back(detail);
} }
...@@ -378,18 +327,17 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order) ...@@ -378,18 +327,17 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order)
} }
//优惠信息 //优惠信息
if(orderContent_obj.HasMember("promotions"))
{ {
rapidjson::Value& promotions_obj = orderContent_obj["promotions"]; rapidjson::Value& promotions_obj = orderContent_obj["promotions"];
if(promotions_obj.IsObject()) if(promotions_obj.IsObject())
{ {
rapidjson::Value& totalDiscount= promotions_obj["totalDiscount"]; GetJsonIntSafe(promotions_obj,"totalDiscount");
totalDiscount.GetInt(); GetJsonIntSafe(promotions_obj,"totalOriginalPrice");
rapidjson::Value& totalOriginalPrice= promotions_obj["totalOriginalPrice"]; GetJsonIntSafe(promotions_obj,"totalPrmotionPrice");
totalOriginalPrice.GetInt();
rapidjson::Value& totalPrmotionPrice= promotions_obj["totalPrmotionPrice"];
totalPrmotionPrice.GetInt();
//优惠信息详情 //优惠信息详情
if(promotions_obj.HasMember("promtionDetails"))
{ {
rapidjson::Value& promtionDetails_array = promotions_obj["promtionDetails"]; rapidjson::Value& promtionDetails_array = promotions_obj["promtionDetails"];
if(promtionDetails_array.IsArray()) if(promtionDetails_array.IsArray())
...@@ -397,102 +345,54 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order) ...@@ -397,102 +345,54 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order)
for(unsigned int i=0;i<promtionDetails_array.Size();i++){ for(unsigned int i=0;i<promtionDetails_array.Size();i++){
rapidjson::Value& promtionDetails_obj = promtionDetails_array[i]; rapidjson::Value& promtionDetails_obj = promtionDetails_array[i];
rapidjson::Value& bomId= promtionDetails_obj["bomId"]; GetJsonStringSafe(promtionDetails_obj,"bomId");
bomId.GetString(); GetJsonStringSafe(promtionDetails_obj,"comboId");
GetJsonStringSafe(promtionDetails_obj,"desc");
rapidjson::Value& comboId = promtionDetails_obj["comboId"]; GetJsonIntSafe(promtionDetails_obj,"discount");
comboId.GetString(); GetJsonStringSafe(promtionDetails_obj,"groupId");
GetJsonIntSafe(promtionDetails_obj,"originalPrice");
rapidjson::Value& desc = promtionDetails_obj["desc"]; GetJsonStringSafe(promtionDetails_obj,"pcode");
desc.GetString(); GetJsonIntSafe(promtionDetails_obj,"prmotionPrice");
GetJsonStringSafe(promtionDetails_obj,"sku");
rapidjson::Value& discount = promtionDetails_obj["discount"]; GetJsonStringSafe(promtionDetails_obj,"type");
discount.GetInt();
rapidjson::Value& groupId = promtionDetails_obj["groupId"];
groupId.GetString();
rapidjson::Value& originalPrice = promtionDetails_obj["originalPrice"];
originalPrice.GetInt();
rapidjson::Value& pcode = promtionDetails_obj["pcode"];
pcode.GetString();
rapidjson::Value& prmotionPrice = promtionDetails_obj["prmotionPrice"];
prmotionPrice.GetInt();
rapidjson::Value& sku = promtionDetails_obj["sku"];
sku.GetString();
rapidjson::Value& type = promtionDetails_obj["type"];
type.GetString();
} }
} }
} }
} }
} }
rapidjson::Value& sessionId = orderContent_obj["sessionId"];
sessionId.GetString();
rapidjson::Value& totalAmount = orderContent_obj["totalAmount"]; GetJsonStringSafe(orderContent_obj,"sessionId");
order.total_price = totalAmount.GetInt(); order.total_price = GetJsonIntSafe(orderContent_obj,"totalAmount");
order.reduced_price = GetJsonIntSafe(orderContent_obj,"totalDiscount");
rapidjson::Value& totalDiscount = orderContent_obj["totalDiscount"];
order.reduced_price = totalDiscount.GetInt();
} }
//第三方商户信息 //第三方商户信息
if(document.HasMember("sellerInfo"))
{ {
rapidjson::Value& sellerInfo_obj = document["sellerInfo"]; rapidjson::Value& sellerInfo_obj = document["sellerInfo"];
if(sellerInfo_obj.IsObject()) if(sellerInfo_obj.IsObject())
{ {
if(sellerInfo_obj.HasMember("sellerId")) GetJsonStringSafe(sellerInfo_obj,"sellerId");
{ GetJsonStringSafe(sellerInfo_obj,"sellerName");
rapidjson::Value& sellerId = sellerInfo_obj["sellerId"];
sellerId.GetString();
}
if(sellerInfo_obj.HasMember("sellerName"))
{
rapidjson::Value& sellerName = sellerInfo_obj["sellerName"];
sellerName.GetString();
}
} }
} }
//门店信息 //门店信息
if(document.HasMember("shopInfo"))
{ {
rapidjson::Value& shopInfo_obj = document["shopInfo"]; rapidjson::Value& shopInfo_obj = document["shopInfo"];
if(shopInfo_obj.IsObject()){ if(shopInfo_obj.IsObject()){
if(shopInfo_obj.HasMember("barCounter")){ GetJsonStringSafe(shopInfo_obj,"barCounter");
rapidjson::Value& barCounter = shopInfo_obj["barCounter"]; GetJsonStringSafe(shopInfo_obj,"operator");
barCounter.GetString(); order.storeInfo.pos_id = GetJsonStringSafe(shopInfo_obj,"posId");
} order.storeInfo.store_id = GetJsonStringSafe(shopInfo_obj,"storeId");
if(shopInfo_obj.HasMember("operator")){
rapidjson::Value& vOperator = shopInfo_obj["operator"];
vOperator.GetString();
}
if(shopInfo_obj.HasMember("posId")){
rapidjson::Value& posId = shopInfo_obj["posId"];
order.storeInfo.pos_id = posId.GetString();
}
if(shopInfo_obj.HasMember("storeId")){
rapidjson::Value& storeId = shopInfo_obj["storeId"];
order.storeInfo.store_id = storeId.GetString();
}
//自助机信息 //自助机信息
rapidjson::Value& selfHelpMac_obj = shopInfo_obj["selfHelpMac"]; rapidjson::Value& selfHelpMac_obj = shopInfo_obj["selfHelpMac"];
if(selfHelpMac_obj.IsObject()){ if(selfHelpMac_obj.IsObject()){
rapidjson::Value& id = selfHelpMac_obj["id"]; order.storeInfo.vem_id = GetJsonStringSafe(selfHelpMac_obj,"id");
order.storeInfo.vem_id = id.GetString(); order.storeInfo.vem_shelf = GetJsonStringSafe(selfHelpMac_obj,"shelf");
rapidjson::Value& shelf = selfHelpMac_obj["shelf"];
order.storeInfo.vem_shelf = shelf.GetString();
} }
} }
} }
...@@ -732,21 +632,18 @@ std::string JsonModule::_convertToOrderOperationReponseJson(IN const char* json) ...@@ -732,21 +632,18 @@ std::string JsonModule::_convertToOrderOperationReponseJson(IN const char* json)
std::string code = document["code"].GetString(); std::string code = document["code"].GetString();
status_code=atoi(code.c_str()); status_code=atoi(code.c_str());
rapidjson::Value& message = document["message"]; msg = GetJsonStringSafe(document,"message");
if(!message.IsNull()){
msg=message.GetString();
}
if( !document.HasMember("status")){ if(document.HasMember("result"))
status=message.GetInt(); {
} rapidjson::Value& result_obj = document["result"];
if(result_obj.IsObject())
if( !document.HasMember("status_desc")){ {
rapidjson::Value& vStatus_desc = document["status_desc"]; status = atoi(GetJsonStringSafe(result_obj,"status"));
if(!vStatus_desc.IsNull()){ status_desc = GetJsonStringSafe(result_obj,"status_desc");
status_desc=vStatus_desc.GetString();
} }
} }
} }
rapidjson::StringBuffer buffer; rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
...@@ -1517,6 +1414,9 @@ std::string JsonModule::_convertPosOperationToOdsJson(orderOperationObj &operati ...@@ -1517,6 +1414,9 @@ std::string JsonModule::_convertPosOperationToOdsJson(orderOperationObj &operati
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
writer.StartObject(); writer.StartObject();
writer.Key("fm_cmd");
writer.Int(operation_obj.fm_cmd);
writer.Key("channel"); writer.Key("channel");
writer.String(operation_obj.channel.c_str()); writer.String(operation_obj.channel.c_str());
......
...@@ -13,6 +13,8 @@ class JsonModule ...@@ -13,6 +13,8 @@ class JsonModule
public: public:
JsonModule(); JsonModule();
~JsonModule(); ~JsonModule();
void jsonTest();
bool getPushOrders(IN const char* json,OUT orderObj &order); bool getPushOrders(IN const char* json,OUT orderObj &order);
......
...@@ -134,6 +134,7 @@ void* listen_pos_func(void* arg) ...@@ -134,6 +134,7 @@ void* listen_pos_func(void* arg)
// 将POS请求数据转换为中台可接受数据格式 // 将POS请求数据转换为中台可接受数据格式
if( jsonTool.convertDataPos2Ods(posRequestData, requestOdsData) ) if( jsonTool.convertDataPos2Ods(posRequestData, requestOdsData) )
{ {
LOG(INFO)<<"convert pos data to ods:"<<requestOdsData.data();
// 同步阻塞发送到ODS并等待返回 // 同步阻塞发送到ODS并等待返回
TCPClient ods; TCPClient ods;
if( ods.doConnect(ods_recv_port, ods_ip.c_str()) ) if( ods.doConnect(ods_recv_port, ods_ip.c_str()) )
...@@ -143,6 +144,7 @@ void* listen_pos_func(void* arg) ...@@ -143,6 +144,7 @@ void* listen_pos_func(void* arg)
std::string tmp; std::string tmp;
if( ods.receive(tmp) ) if( ods.receive(tmp) )
{ {
LOG(INFO)<<"receive ods back:"<<tmp.data();
jsonTool.getPosResponseData(tmp,posRequestData, responseData); jsonTool.getPosResponseData(tmp,posRequestData, responseData);
}else }else
{ {
...@@ -165,7 +167,7 @@ void* listen_pos_func(void* arg) ...@@ -165,7 +167,7 @@ void* listen_pos_func(void* arg)
} }
// TODO待加入重试机制 // TODO待加入重试机制
LOG(INFO) << "ODS response data:"<<responseData.data(); LOG(INFO) << "ODS response data send to pos:"<<responseData.data();
pos.write(responseData.c_str()); pos.write(responseData.c_str());
pos.close(); pos.close();
if(reqType==REQUEST_TYPE_INIT){ if(reqType==REQUEST_TYPE_INIT){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment