Commit 60a92707 by guanghui.cui

兼容windows系统

parent b80a20e5
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -144,7 +144,7 @@ struct bonus ...@@ -144,7 +144,7 @@ struct bonus
std::string desc; //优惠明细 std::string desc; //优惠明细
std::string name; //名称 std::string name; //名称
std::string sku; //商品编号 std::string sku; //商品编号
int bonus=0; //获得积分 int bonusNum=0; //获得积分
}; };
//电子点标 //电子点标
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
port=24446 port=24446
[ODS] [ODS]
ip=10.0.100.70 ip=172.16.13.71
pushPort=30001 pushPort=30001
recvPort=30002 recvPort=30002
socketTimeout=60 socketTimeout=60
......

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "familyMart_takeaway_vs", "familyMart_takeaway_vs\familyMart_takeaway_vs.vcxproj", "{B24A017B-387C-49C2-A321-3554AD9A1D48}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B24A017B-387C-49C2-A321-3554AD9A1D48}.Debug|x64.ActiveCfg = Debug|x64
{B24A017B-387C-49C2-A321-3554AD9A1D48}.Debug|x64.Build.0 = Debug|x64
{B24A017B-387C-49C2-A321-3554AD9A1D48}.Debug|x86.ActiveCfg = Debug|Win32
{B24A017B-387C-49C2-A321-3554AD9A1D48}.Debug|x86.Build.0 = Debug|Win32
{B24A017B-387C-49C2-A321-3554AD9A1D48}.Release|x64.ActiveCfg = Release|x64
{B24A017B-387C-49C2-A321-3554AD9A1D48}.Release|x64.Build.0 = Release|x64
{B24A017B-387C-49C2-A321-3554AD9A1D48}.Release|x86.ActiveCfg = Release|Win32
{B24A017B-387C-49C2-A321-3554AD9A1D48}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{B24A017B-387C-49C2-A321-3554AD9A1D48}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>familyMart_takeaway_vs</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>..\bin\</OutDir>
<TargetName>takeaway_d</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>..\bin\</OutDir>
<TargetName>takeaway</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;_WINSOCK_DEPRECATED_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\3rdParty\easylogging\easylogging++.h" />
<ClInclude Include="..\3rdParty\sqlite3.h" />
<ClInclude Include="..\base\BaseDefine.h" />
<ClInclude Include="..\base\CommonStruct.h" />
<ClInclude Include="..\src\JsonModule.h" />
<ClInclude Include="..\src\SocketModule.h" />
<ClInclude Include="..\utility\utility.h" />
<ClInclude Include="..\utility\zini.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\3rdParty\easylogging\easylogging++.cc" />
<ClCompile Include="..\src\JsonModule.cpp" />
<ClCompile Include="..\src\main.cpp" />
<ClCompile Include="..\src\SocketModule.cpp" />
<ClCompile Include="..\utility\utility.cpp" />
<ClCompile Include="..\utility\zini.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="src">
<UniqueIdentifier>{f026061c-2527-4601-b8fd-c6720f565996}</UniqueIdentifier>
</Filter>
<Filter Include="3rdParty">
<UniqueIdentifier>{e1eb3e6e-1a4a-4466-98e5-44ef77ad9be9}</UniqueIdentifier>
</Filter>
<Filter Include="base">
<UniqueIdentifier>{1bb94267-1d9b-4a6e-8e89-a5597f87fd90}</UniqueIdentifier>
</Filter>
<Filter Include="utility">
<UniqueIdentifier>{3ae8a881-cfaf-4ddf-a4e5-a94426e3de79}</UniqueIdentifier>
</Filter>
<Filter Include="3rdParty\easylogging">
<UniqueIdentifier>{019baaa1-711f-4d47-a3fa-ed33aa42276c}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\3rdParty\sqlite3.h">
<Filter>3rdParty</Filter>
</ClInclude>
<ClInclude Include="..\3rdParty\easylogging\easylogging++.h">
<Filter>3rdParty\easylogging</Filter>
</ClInclude>
<ClInclude Include="..\base\BaseDefine.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\base\CommonStruct.h">
<Filter>base</Filter>
</ClInclude>
<ClInclude Include="..\utility\utility.h">
<Filter>utility</Filter>
</ClInclude>
<ClInclude Include="..\utility\zini.h">
<Filter>utility</Filter>
</ClInclude>
<ClInclude Include="..\src\JsonModule.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="..\src\SocketModule.h">
<Filter>src</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\3rdParty\easylogging\easylogging++.cc">
<Filter>3rdParty\easylogging</Filter>
</ClCompile>
<ClCompile Include="..\utility\utility.cpp">
<Filter>utility</Filter>
</ClCompile>
<ClCompile Include="..\utility\zini.cpp">
<Filter>utility</Filter>
</ClCompile>
<ClCompile Include="..\src\JsonModule.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\src\main.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\src\SocketModule.cpp">
<Filter>src</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
#include "JsonModule.h" #include "JsonModule.h"
#include "../utility/utility.h" #include "../utility/utility.h"
#include "../3rdParty/rapidjson/rapidjson.h" #include "../3rdParty/rapidjson/rapidjson.h"
#include "../3rdParty/rapidjson/document.h" #include "../3rdParty/rapidjson/document.h"
...@@ -380,7 +380,7 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order) ...@@ -380,7 +380,7 @@ bool JsonModule::getPushOrders(IN const char* json,OUT orderObj &order)
bonus detail; bonus detail;
detail.pcode = GetJsonStringSafe(pointDetails_obj,"pcode"); detail.pcode = GetJsonStringSafe(pointDetails_obj,"pcode");
detail.desc = GetJsonStringSafe(pointDetails_obj,"desc"); detail.desc = GetJsonStringSafe(pointDetails_obj,"desc");
detail.bonus = GetJsonIntSafe(pointDetails_obj,"point"); detail.bonusNum = GetJsonIntSafe(pointDetails_obj,"point");
detail.name = GetJsonStringSafe(pointDetails_obj, "name"); detail.name = GetJsonStringSafe(pointDetails_obj, "name");
detail.sku = GetJsonStringSafe(pointDetails_obj,"sku"); detail.sku = GetJsonStringSafe(pointDetails_obj,"sku");
detail.proType = GetJsonStringSafe(pointDetails_obj,"type"); detail.proType = GetJsonStringSafe(pointDetails_obj,"type");
...@@ -1121,7 +1121,7 @@ std::string JsonModule::_convertToNewOrderJson(orderObj &obj) ...@@ -1121,7 +1121,7 @@ std::string JsonModule::_convertToNewOrderJson(orderObj &obj)
writer.String(obj.vecBonus[i].sku.c_str()); writer.String(obj.vecBonus[i].sku.c_str());
writer.Key("bonus"); writer.Key("bonus");
writer.Int(obj.vecBonus[i].bonus); writer.Int(obj.vecBonus[i].bonusNum);
writer.EndObject(); writer.EndObject();
} }
...@@ -1869,7 +1869,7 @@ bool JsonModule::_getCommonWarnResponseJson(IN const std::string& posResponse, I ...@@ -1869,7 +1869,7 @@ bool JsonModule::_getCommonWarnResponseJson(IN const std::string& posResponse, I
writer.Int(status_code); writer.Int(status_code);
writer.Key("pk_id"); writer.Key("pk_id");
writer.Int(pk_id); writer.Int64(pk_id);
writer.EndObject(); writer.EndObject();
result = buffer.GetString(); result = buffer.GetString();
...@@ -1994,5 +1994,10 @@ std::string JsonModule::_getPickupCodeString(std::string &channel,std::string &p ...@@ -1994,5 +1994,10 @@ std::string JsonModule::_getPickupCodeString(std::string &channel,std::string &p
else if("208"==channel){ else if("208"==channel){
rlt="京东到家"+pickup_code+"号"; rlt="京东到家"+pickup_code+"号";
} }
//vs默认编码是gbk,如果是windows系统,需要转换为utf8编码
#ifdef WIN32
rlt = charset_g2u(rlt);
#endif // WIN32
return rlt; return rlt;
} }
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "../utility/utility.h" #include "../utility/utility.h"
#include "../3rdParty/easylogging/easylogging++.h" #include "../3rdParty/easylogging/easylogging++.h"
#define BUFFER_SIZE 1024 //缓冲区大小 #define BUFFER_SIZE 1024
SQLite::SQLite() SQLite::SQLite()
{ {
...@@ -17,17 +17,16 @@ SQLite::~SQLite() ...@@ -17,17 +17,16 @@ SQLite::~SQLite()
bool SQLite::initSQLite() bool SQLite::initSQLite()
{ {
std::string strDbFileName; //*.db 名称 std::string strDbFileName; //*.db name
std::string strPath = GetProcDir(); std::string strPath = GetProcDir();
strPath.append("fmdata.db"); strPath.append("fmdata.db");
strDbFileName = strPath; strDbFileName = strPath;
//打开一个数据库,如果改数据库不存在,则创建一个名字为databaseName的数据库文件
int res = sqlite3_open(strDbFileName.c_str(), &pDB); int res = sqlite3_open(strDbFileName.c_str(), &pDB);
LOG(INFO)<<"DbFileName:"<<strDbFileName.c_str(); LOG(INFO)<<"DbFileName:"<<strDbFileName.c_str();
if(res != SQLITE_OK) if(res != SQLITE_OK)
{ {
LOG(ERROR)<<"打开数据库失败:"<<strDbFileName.data(); LOG(ERROR)<<"open db file failed:"<<strDbFileName.data();
return false; return false;
} }
try try
...@@ -36,7 +35,7 @@ bool SQLite::initSQLite() ...@@ -36,7 +35,7 @@ bool SQLite::initSQLite()
} }
catch(std::exception &ex) catch(std::exception &ex)
{ {
LOG(ERROR)<<"创建表异常:"<<ex.what(); LOG(ERROR)<<"create table exception:"<<ex.what();
return false; return false;
} }
return true; return true;
...@@ -44,10 +43,6 @@ bool SQLite::initSQLite() ...@@ -44,10 +43,6 @@ bool SQLite::initSQLite()
bool SQLite::_createTable() bool SQLite::_createTable()
{ {
//插入一个表,返回值为SQLITE_OK为成功,否则输出出错信息
//函数参数:第一个为操作数据库的指针,第二句为SQL命令字符串
//第三个参数为callback函数,这里没有用,第四个参数为callback函数
//中的第一个参数,第五个为出错信息
bool rlt=true; bool rlt=true;
std::string strTableName="fmOrderFailed"; std::string strTableName="fmOrderFailed";
if(!isTableExist(pDB,strTableName)){ if(!isTableExist(pDB,strTableName)){
...@@ -57,12 +52,11 @@ bool SQLite::_createTable() ...@@ -57,12 +52,11 @@ bool SQLite::_createTable()
logtime TIMESTAMP default (datetime('now', 'localtime')),\ logtime TIMESTAMP default (datetime('now', 'localtime')),\
PRIMARY KEY (id))",strTableName.c_str()); PRIMARY KEY (id))",strTableName.c_str());
if(!_execSql(szCreate)){ if(!_execSql(szCreate)){
//执行失败,退出
exit(0); exit(0);
} }
} }
else{ else{
LOG(INFO)<<strTableName.data()<<"已存在"; LOG(INFO)<<strTableName.data()<<" has exist";
} }
return rlt; return rlt;
...@@ -74,7 +68,6 @@ void SQLite::closeSQLite() ...@@ -74,7 +68,6 @@ void SQLite::closeSQLite()
sqlite3_close(pDB); sqlite3_close(pDB);
} }
//查看表是否存在
bool SQLite::isTableExist(sqlite3 *sqDb, std::string strTableName) bool SQLite::isTableExist(sqlite3 *sqDb, std::string strTableName)
{ {
char szQuery[1024] = {0}; char szQuery[1024] = {0};
...@@ -112,7 +105,7 @@ bool SQLite::_execSql(const char* sql) ...@@ -112,7 +105,7 @@ bool SQLite::_execSql(const char* sql)
int res = sqlite3_exec(pDB,sql, 0, 0, &errMsg); int res = sqlite3_exec(pDB,sql, 0, 0, &errMsg);
if(res != SQLITE_OK) if(res != SQLITE_OK)
{ {
LOG(ERROR)<<"执行sql失败:"<<sql<<" 失败信息:"<<errMsg; LOG(ERROR)<<"exec sql failed:"<<sql<<" failed info:"<<errMsg;
rlt=false; rlt=false;
} }
return rlt; return rlt;
...@@ -146,7 +139,7 @@ int callbackQuery(void* data,int n_columns,char** column_values,char** column_na ...@@ -146,7 +139,7 @@ int callbackQuery(void* data,int n_columns,char** column_values,char** column_na
} }
catch(std::exception &ex) catch(std::exception &ex)
{ {
LOG(ERROR)<<"读取数据失败:"<<ex.what(); LOG(ERROR)<<"read data failed:"<<ex.what();
return -1; return -1;
} }
...@@ -159,9 +152,9 @@ void SQLite::query(const char* sql,std::vector<orderSendFailedObj> &vecFailedOrd ...@@ -159,9 +152,9 @@ void SQLite::query(const char* sql,std::vector<orderSendFailedObj> &vecFailedOrd
int rlt = sqlite3_exec(pDB,sql,callbackQuery, 0, &errMsg); int rlt = sqlite3_exec(pDB,sql,callbackQuery, 0, &errMsg);
if(rlt!= SQLITE_OK) if(rlt!= SQLITE_OK)
{ {
LOG(ERROR)<<"查询数据执行失败:"<<errMsg; LOG(ERROR)<<"query failed:"<<errMsg;
} }
else{ else{
vecFailedOrders.assign(vecOrders.begin(), vecOrders.end()); vecFailedOrders.assign(vecOrders.begin(), vecOrders.end());
} }
} }
\ No newline at end of file
#ifndef SQLITE_MODULE_H #ifndef SQLITE_MODULE_H
#define SQLITE_MODULE_H #define SQLITE_MODULE_H
#include <iostream> #include <iostream>
#include <sqlite3.h>
#include <vector> #include <vector>
#include "../base/CommonStruct.h" #include "../base/CommonStruct.h"
#ifdef WIN32
#include "../3rdParty/sqlite3.h"
#else
#include <sqlite3.h>
#endif // WIN32
class SQLite class SQLite
{ {
public: public:
......
...@@ -4,8 +4,14 @@ ...@@ -4,8 +4,14 @@
TCPSocket::TCPSocket(): m_sockfd(-1){} TCPSocket::TCPSocket(): m_sockfd(-1){}
TCPSocket::~TCPSocket() TCPSocket::~TCPSocket()
{ {
if ( m_sockfd != -1 ) if ( m_sockfd != -1 ){
#ifdef WIN32
closesocket(m_sockfd);
#else
::close(m_sockfd); ::close(m_sockfd);
#endif
}
} }
bool TCPSocket::create() bool TCPSocket::create()
...@@ -71,6 +77,8 @@ bool TCPSocket::setNonBlocking(bool flag) const ...@@ -71,6 +77,8 @@ bool TCPSocket::setNonBlocking(bool flag) const
{ {
if ( m_sockfd == -1 ) if ( m_sockfd == -1 )
return false; return false;
#ifdef WIN32
#else
int opt = fcntl(m_sockfd, F_GETFL, 0); int opt = fcntl(m_sockfd, F_GETFL, 0);
if (opt == -1) if (opt == -1)
return false; return false;
...@@ -80,6 +88,7 @@ bool TCPSocket::setNonBlocking(bool flag) const ...@@ -80,6 +88,7 @@ bool TCPSocket::setNonBlocking(bool flag) const
opt &= ~O_NONBLOCK; opt &= ~O_NONBLOCK;
if (fcntl(m_sockfd, F_SETFL, opt) == -1) if (fcntl(m_sockfd, F_SETFL, opt) == -1)
return false; return false;
#endif
return true; return true;
} }
bool TCPSocket::reuseaddr() const bool TCPSocket::reuseaddr() const
...@@ -88,7 +97,7 @@ bool TCPSocket::reuseaddr() const ...@@ -88,7 +97,7 @@ bool TCPSocket::reuseaddr() const
return false; return false;
int on = 1; int on = 1;
if (setsockopt(m_sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) if (setsockopt(m_sockfd, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof(on)) == -1)
return false; return false;
return true; return true;
} }
...@@ -96,7 +105,11 @@ bool TCPSocket::close() ...@@ -96,7 +105,11 @@ bool TCPSocket::close()
{ {
if ( m_sockfd == -1 ) if ( m_sockfd == -1 )
return false; return false;
::close(m_sockfd); #ifdef WIN32
closesocket(m_sockfd);
#else
::close(m_sockfd);
#endif
m_sockfd = -1; m_sockfd = -1;
return true; return true;
} }
...@@ -140,10 +153,15 @@ bool TCPClient::doConnect(unsigned short port, const char *ip) ...@@ -140,10 +153,15 @@ bool TCPClient::doConnect(unsigned short port, const char *ip)
void TCPClient::setSocketTimeout(int timeout) void TCPClient::setSocketTimeout(int timeout)
{ {
#ifdef WIN32
int iTimeOut = timeout * 1000;
setsockopt(m_sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&iTimeOut, sizeof(iTimeOut));
#else
struct timeval vtime; struct timeval vtime;
vtime.tv_sec = timeout; vtime.tv_sec = timeout;
vtime.tv_usec = 0; vtime.tv_usec = 0;
setsockopt(m_sockfd, SOL_SOCKET, SO_RCVTIMEO, &vtime, sizeof(struct timeval)); setsockopt(m_sockfd, SOL_SOCKET, SO_RCVTIMEO, (char*)&vtime, sizeof(struct timeval));
#endif // WIN32
} }
//send //send
...@@ -194,7 +212,12 @@ bool TCPClient::receive(std::string &message) ...@@ -194,7 +212,12 @@ bool TCPClient::receive(std::string &message)
bool TCPClient::read(void *buf, size_t count) bool TCPClient::read(void *buf, size_t count)
{ {
#ifdef WIN32
ssize_t readBytes= ::recv(m_sockfd, (char*)buf, count,0);
#else
ssize_t readBytes = ::read(m_sockfd, buf, count); ssize_t readBytes = ::read(m_sockfd, buf, count);
#endif
if (readBytes == -1) if (readBytes == -1)
{ {
m_bValid = false; m_bValid = false;
...@@ -205,7 +228,12 @@ bool TCPClient::read(void *buf, size_t count) ...@@ -205,7 +228,12 @@ bool TCPClient::read(void *buf, size_t count)
bool TCPClient::write(const char *msg) bool TCPClient::write(const char *msg)
{ {
if( ::write(m_sockfd, msg, strlen(msg)) == -1 ) #ifdef WIN32
ssize_t writeBytes= ::send(m_sockfd, msg, strlen(msg),0);
#else
ssize_t writeBytes= ::write(m_sockfd, msg, strlen(msg));
#endif
if( writeBytes == -1 )
{ {
m_bValid = false; m_bValid = false;
return false; return false;
...@@ -222,7 +250,12 @@ static ssize_t readn(int fd, void *buf, size_t count) ...@@ -222,7 +250,12 @@ static ssize_t readn(int fd, void *buf, size_t count)
char *pBuf = (char *)buf; char *pBuf = (char *)buf;
while (nLeft > 0) while (nLeft > 0)
{ {
if ((nRead = read(fd, pBuf, nLeft)) < 0) #ifdef WIN32
nRead= ::recv(fd, (char*)pBuf, nLeft,0);
#else
nRead = ::read(fd, pBuf, nLeft);
#endif
if (nRead < 0)
{ {
//如果读取操作是被信号打断了, 则说明还可以继续读 //如果读取操作是被信号打断了, 则说明还可以继续读
if (errno == EINTR) if (errno == EINTR)
...@@ -248,7 +281,12 @@ static ssize_t writen(int fd, const void *buf, size_t count) ...@@ -248,7 +281,12 @@ static ssize_t writen(int fd, const void *buf, size_t count)
char *pBuf = (char *)buf; char *pBuf = (char *)buf;
while (nLeft > 0) while (nLeft > 0)
{ {
if ((nWritten = write(fd, pBuf, nLeft)) < 0) #ifdef WIN32
nWritten= ::send(fd, pBuf, nLeft,0);
#else
nWritten= ::write(fd, pBuf, nLeft);
#endif
if (nWritten < 0)
{ {
//如果写入操作是被信号打断了, 则说明还可以继续写入 //如果写入操作是被信号打断了, 则说明还可以继续写入
if (errno == EINTR) if (errno == EINTR)
......
...@@ -5,12 +5,19 @@ ...@@ -5,12 +5,19 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef WIN32
#include <Winsock2.h>
#pragma comment(lib,"ws2_32.lib")
#define ssize_t int
#else
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#endif
#define BUF_SIZE 1024*6 #define BUF_SIZE 1024*6
...@@ -57,7 +64,7 @@ public: ...@@ -57,7 +64,7 @@ public:
void setSocketTimeout(int timeout); void setSocketTimeout(int timeout);
bool isValid(){ return m_bValid; } bool isValid(){ return m_bValid; }
bool setValid(bool valid){ m_bValid=valid; } void setValid(bool valid){ m_bValid=valid; }
private: private:
bool m_bValid; bool m_bValid;
}; };
......
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <pthread.h>
#include "JsonModule.h" #include "JsonModule.h"
#include "SocketModule.h" #include "SocketModule.h"
#include "../utility/utility.h" #include "../utility/utility.h"
#include "../utility/zini.h" #include "../utility/zini.h"
#include "SQLiteModule.h" //#include "SQLiteModule.h"
#ifdef WIN32
#include <Windows.h>
//#pragma comment(lib,"../bin/sqlite3.lib")
#else
#include <pthread.h>
#endif
#define ELPP_NO_DEFAULT_LOG_FILE #define ELPP_NO_DEFAULT_LOG_FILE
#include "../3rdParty/easylogging/easylogging++.h" #include "../3rdParty/easylogging/easylogging++.h"
...@@ -45,8 +51,11 @@ void logRolloutHandler(const char* filename, std::size_t size) ...@@ -45,8 +51,11 @@ void logRolloutHandler(const char* filename, std::size_t size)
ss << "mv " << filename << " "<<filename<<"_bk"; ss << "mv " << filename << " "<<filename<<"_bk";
system(ss.str().c_str()); system(ss.str().c_str());
} }
#ifdef WIN32
void* listen_pos_func(void* arg) DWORD WINAPI listen_pos_func(LPVOID lpParamter)
#else
void* listen_pos_func(void* arg)
#endif // WIN32
{ {
TCPServer server; TCPServer server;
JsonModule jsonTool; JsonModule jsonTool;
...@@ -98,7 +107,7 @@ void* listen_pos_func(void* arg) ...@@ -98,7 +107,7 @@ void* listen_pos_func(void* arg)
} }
else{ else{
LOG(INFO)<<"wait for ods init back data"; LOG(INFO)<<"wait for ods init back data";
sleep(3); os_sleep(3);
} }
} }
jsonTool.setInitData(posRequestData.data()); //把初始化数据暂存起来 jsonTool.setInitData(posRequestData.data()); //把初始化数据暂存起来
...@@ -122,7 +131,7 @@ void* listen_pos_func(void* arg) ...@@ -122,7 +131,7 @@ void* listen_pos_func(void* arg)
} }
else{ else{
LOG(INFO)<<"wait for ods priority back data"; LOG(INFO)<<"wait for ods priority back data";
sleep(1); os_sleep(1);
} }
} }
...@@ -191,6 +200,9 @@ void* listen_pos_func(void* arg) ...@@ -191,6 +200,9 @@ void* listen_pos_func(void* arg)
LOG(INFO) << "accept pos connect failed"; LOG(INFO) << "accept pos connect failed";
} }
} }
#ifdef WIN32
return 0;
#endif // WIN32
} }
// //发送POS订单失败,重新发送线程 // //发送POS订单失败,重新发送线程
...@@ -232,8 +244,13 @@ int main() ...@@ -232,8 +244,13 @@ int main()
* 与ODS通信全部加数据头(长度) * 与ODS通信全部加数据头(长度)
* 与POS通信全部不加数据头 * 与POS通信全部不加数据头
* end*/ * end*/
#ifdef WIN32
WSADATA transData;
WSAStartup(MAKEWORD(2, 2), &transData);
//ShowWindow(GetConsoleWindow(), SW_HIDE); //隐藏窗口,后台运行
#else
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
#endif
// 初始化日志 // 初始化日志
el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck); el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
...@@ -277,13 +294,18 @@ int main() ...@@ -277,13 +294,18 @@ int main()
<< "-listen port: " << pos_listen_port; << "-listen port: " << pos_listen_port;
LOG(INFO) << "[Local]listen port: " << client_listen_port; LOG(INFO) << "[Local]listen port: " << client_listen_port;
//end //end
// 监听POS请求的线程
pthread_t listen_pos_id;
/*创建 listen_pos 线程*/ #ifdef WIN32
if(pthread_create(&listen_pos_id,NULL,listen_pos_func,NULL)) HANDLE hTakeway = CreateThread(NULL, 0, listen_pos_func, NULL, 0, NULL);
LOG(INFO) << "create listen_pos thread failed"; #else
// 监听POS请求的线程
pthread_t listen_pos_id;
/*创建 listen_pos 线程*/
if (pthread_create(&listen_pos_id, NULL, listen_pos_func, NULL))
LOG(INFO) << "create listen_pos thread failed";
#endif // WIN32
TCPClient ods; TCPClient ods;
JsonModule jsonTool; JsonModule jsonTool;
...@@ -318,10 +340,10 @@ int main() ...@@ -318,10 +340,10 @@ int main()
LOG(INFO)<<"wait for init done"; LOG(INFO)<<"wait for init done";
if( !ods.isValid() ){ if( !ods.isValid() ){
LOG(INFO)<<"ods is not valid"; LOG(INFO)<<"ods is not valid";
sleep(1); os_sleep(1); //防止在ods挂掉后狂刷日志
break; break;
} }
sleep(1); os_sleep(1);
count++; count++;
//如果10s没有初始化完成,则跳出循环,重新连接 //如果10s没有初始化完成,则跳出循环,重新连接
if(10==count){ if(10==count){
...@@ -350,13 +372,13 @@ int main() ...@@ -350,13 +372,13 @@ int main()
else{ else{
LOG(INFO)<<"Haven't receive init data"; LOG(INFO)<<"Haven't receive init data";
} }
sleep(3); os_sleep(3);
continue; continue;
} }
}else }else
{ {
LOG(INFO) << "connect ODS failed"; LOG(INFO) << "connect ODS failed";
sleep(5); os_sleep(5);
continue; continue;
} }
} }
...@@ -418,6 +440,9 @@ int main() ...@@ -418,6 +440,9 @@ int main()
} }
/// 注销回调函数 /// 注销回调函数
el::Helpers::uninstallPreRollOutCallback(); el::Helpers::uninstallPreRollOutCallback();
#ifdef WIN32
WSACleanup();
#endif
//sqlite.closeSQLite(); //sqlite.closeSQLite();
return 0; return 0;
} }
......
...@@ -3,14 +3,15 @@ ...@@ -3,14 +3,15 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <iostream> #include <iostream>
#include <iconv.h>
#include <string.h> #include <string.h>
#include <sys/time.h>
#include <chrono> #include <chrono>
#ifdef WIN32 #ifdef WIN32
#include <Windows.h> #include <Windows.h>
#include <ctime>
#else #else
#include <iconv.h>
#include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#endif #endif
...@@ -20,6 +21,19 @@ std::string GetProcDir() ...@@ -20,6 +21,19 @@ std::string GetProcDir()
{ {
std::string strDir; std::string strDir;
#ifdef WIN32 #ifdef WIN32
int curPos;
char pathBuf[MAX_PATH] = { 0 };
::GetModuleFileNameA(NULL, pathBuf, MAX_PATH);
curPos = strlen(pathBuf) - 1;
while('\\' != pathBuf[curPos])
{
curPos--;
}
curPos++;
pathBuf[curPos] = '\0';
strDir=pathBuf;
#else #else
char szBuffer[256]; char szBuffer[256];
int npos = 0; int npos = 0;
...@@ -42,6 +56,8 @@ std::string GetProcDir() ...@@ -42,6 +56,8 @@ std::string GetProcDir()
int charset_convert(const char* charset_from, const char* charset_to, const std::string& string_from, std::string& string_to) int charset_convert(const char* charset_from, const char* charset_to, const std::string& string_from, std::string& string_to)
{ {
#ifdef WIN32
#else
iconv_t cd = iconv_open(charset_to, charset_from); iconv_t cd = iconv_open(charset_to, charset_from);
if (!cd) if (!cd)
{ {
...@@ -72,24 +88,67 @@ int charset_convert(const char* charset_from, const char* charset_to, const std: ...@@ -72,24 +88,67 @@ int charset_convert(const char* charset_from, const char* charset_to, const std:
{ {
return -1; return -1;
} }
#endif
return 0; return 0;
} }
//GB2312码转为UNICODE码 #ifdef WIN32
std::string GBKToUTF8(const std::string& strGBK)
{
std::string strOutUTF8;
WCHAR* str1;
int n = MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, NULL, 0);
str1 = new WCHAR[n];
MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, str1, n);
n = WideCharToMultiByte(CP_UTF8, 0, str1, -1, NULL, 0, NULL, NULL);
char * str2 = new char[n];
WideCharToMultiByte(CP_UTF8, 0, str1, -1, str2, n, NULL, NULL);
strOutUTF8 = str2;
delete[]str1;
delete[]str2;
return strOutUTF8;
}
std::string UTF8ToGBK(const std::string& strUTF8)
{
std::string strOutGBK;
int len = MultiByteToWideChar(CP_UTF8, 0, strUTF8.data(), -1, NULL, 0);
wchar_t* wstr = new wchar_t[len + 1];
memset(wstr, 0, len + 1);
MultiByteToWideChar(CP_UTF8, 0, strUTF8.data(), -1, wstr, len);
len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
char* str = new char[len + 1];
memset(str, 0, len + 1);
WideCharToMultiByte(CP_ACP, 0, wstr, -1, str, len, NULL, NULL);
strOutGBK = str;
delete[] wstr;
delete[] str;
return strOutGBK;
}
#endif
//GB2312码转为utf8码
std::string charset_g2u(const std::string& gb2312) std::string charset_g2u(const std::string& gb2312)
{ {
std::string utf8; std::string utf8;
#ifdef WIN32
utf8 = GBKToUTF8(gb2312);
#else
charset_convert("gb2312", "utf-8", gb2312, utf8); charset_convert("gb2312", "utf-8", gb2312, utf8);
#endif
//std::cout<<"convert res:"<<i<<std::endl; //std::cout<<"convert res:"<<i<<std::endl;
return utf8; return utf8;
} }
//UNICODE码转为GB2312码 //utf8码转为GB2312码
std::string charset_u2g(const std::string& utf8) std::string charset_u2g(const std::string& utf8)
{ {
std::string gb2312; std::string gb2312;
#ifdef WIN32
gb2312 = UTF8ToGBK(utf8);
#else
charset_convert( "utf-8","gb2312", utf8, gb2312); charset_convert( "utf-8","gb2312", utf8, gb2312);
#endif
//std::cout<<"convert res:"<<i<<std::endl; //std::cout<<"convert res:"<<i<<std::endl;
return gb2312; return gb2312;
} }
...@@ -97,16 +156,28 @@ std::string charset_u2g(const std::string& utf8) ...@@ -97,16 +156,28 @@ std::string charset_u2g(const std::string& utf8)
//获取时间戳(毫秒) //获取时间戳(毫秒)
int64_t timestamps_milliseconds() int64_t timestamps_milliseconds()
{ {
#ifdef WIN32
std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds> tp = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
auto tmp = std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch());
return tmp.count();
#else
struct timeval tv; struct timeval tv;
gettimeofday(&tv,NULL); gettimeofday(&tv,NULL);
return (int64_t)tv.tv_sec*1000 + tv.tv_usec/1000; return (int64_t)tv.tv_sec*1000 + tv.tv_usec/1000;
#endif
} }
//获取时间戳(秒) //获取时间戳(秒)
int64_t timestamp_seconds() int64_t timestamp_seconds()
{ {
#ifdef WIN32
std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> tp = std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now());
auto tmp = std::chrono::duration_cast<std::chrono::seconds>(tp.time_since_epoch());
return tmp.count();
#else
struct timeval tv; struct timeval tv;
gettimeofday(&tv,NULL); gettimeofday(&tv,NULL);
return tv.tv_sec; return tv.tv_sec;
#endif
} }
std::string getdatetime(int64_t timestamp) std::string getdatetime(int64_t timestamp)
...@@ -121,4 +192,13 @@ std::string getdatetime(int64_t timestamp) ...@@ -121,4 +192,13 @@ std::string getdatetime(int64_t timestamp)
sprintf(datetime,"%4d%02d%02d%02d%02d%02d",now->tm_year+1900,now->tm_mon+1,now->tm_mday,now->tm_hour,now->tm_min,now->tm_sec); sprintf(datetime,"%4d%02d%02d%02d%02d%02d",now->tm_year+1900,now->tm_mon+1,now->tm_mday,now->tm_hour,now->tm_min,now->tm_sec);
strDate=datetime; strDate=datetime;
return strDate; return strDate;
} }
\ No newline at end of file
void os_sleep(int seconds)
{
#ifdef WIN32
Sleep(seconds*1000);
#else
sleep(seconds);
#endif
}
...@@ -19,7 +19,10 @@ int64_t timestamp_seconds(); ...@@ -19,7 +19,10 @@ int64_t timestamp_seconds();
//获取时间戳(毫秒) //获取时间戳(毫秒)
int64_t timestamps_milliseconds(); int64_t timestamps_milliseconds();
//根据时间戳获取时间 //根据时间戳(毫秒)获取时间
std::string getdatetime(int64_t timestamp); std::string getdatetime(int64_t timestamp);
#endif //延时秒数
\ No newline at end of file void os_sleep(int seconds);
#endif
/////////////////////////////////////////////////////////////// #include "zini.h"
// Name: ZIni
// Version: 0.1
// Author: zhaobinjie
// Email: zhaobinjie1984@163.com
// Date: 2010-04-29
//
// Description:
// This class provides static functions for writing and
// reading INI files.
///////////////////////////////////////////////////////////////
#include "zini.h"
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <cctype> #include <cctype>
......
///////////////////////////////////////////////////////////////
// Name: ZIni
// Version: 0.1
// Author: zhaobinjie
// Email: zhaobinjie1984@163.com
// Date: 2010-04-29
//
// Description:
// This class provides static functions for writing and
// reading INI files.
///////////////////////////////////////////////////////////////
#ifndef ZINI_H #ifndef ZINI_H
#define ZINI_H #define ZINI_H
......
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